libs3.h 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659
  1. /** **************************************************************************
  2. * @file libs3.h
  3. * @details
  4. * Copyright 2008 Bryan Ischo <[email protected]>
  5. *
  6. * This file is part of libs3.
  7. *
  8. * libs3 is free software: you can redistribute it and/or modify it under the
  9. * terms of the GNU Lesser General Public License as published by the Free
  10. * Software Foundation, version 3 or above of the License. You can also
  11. * redistribute and/or modify it under the terms of the GNU General Public
  12. * License, version 2 or above of the License.
  13. *
  14. * In addition, as a special exception, the copyright holders give
  15. * permission to link the code of this library and its programs with the
  16. * OpenSSL library, and distribute linked combinations including the two.
  17. *
  18. * libs3 is distributed in the hope that it will be useful, but WITHOUT ANY
  19. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  21. * details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public License
  24. * version 3 along with libs3, in a file named COPYING. If not, see
  25. * <https://www.gnu.org/licenses/>.
  26. *
  27. * You should also have received a copy of the GNU General Public License
  28. * version 2 along with libs3, in a file named COPYING-GPLv2. If not, see
  29. * <https://www.gnu.org/licenses/>.
  30. *
  31. ************************************************************************** **/
  32. #ifndef LIBS3_H
  33. #define LIBS3_H
  34. #include <stdint.h>
  35. #ifndef WINSCP
  36. #include <sys/select.h>
  37. #endif
  38. #ifdef WINSCP
  39. #define LIBS3_VER_MAJOR "4"
  40. #define LIBS3_VER_MINOR "1"
  41. #endif
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /** **************************************************************************
  46. * @mainpage
  47. * Overview
  48. * --------
  49. *
  50. * This library provides an API for using Amazon's S3 service (see
  51. * https://s3.amazonaws.com/). Its design goals are:
  52. *
  53. * - To provide a simple and straightforward API for accessing all of S3's
  54. * functionality
  55. * - To not require the developer using libs3 to need to know anything about:
  56. * - HTTP
  57. * - XML
  58. * - SSL
  59. *
  60. * In other words, this API is meant to stand on its own, without requiring
  61. * any implicit knowledge of how S3 services are accessed using HTTP
  62. * protocols.
  63. *
  64. * - To be usable from multithreaded code
  65. * - To be usable by code which wants to process multiple S3 requests
  66. * simultaneously from a single thread
  67. * - To be usable in the simple, straightforward way using sequentialized
  68. * blocking requests
  69. *
  70. * The general usage pattern of libs3 is:
  71. *
  72. * - Initialize libs3 once per program by calling S3_initialize() at program
  73. * start up time
  74. * - Make any number of requests to S3 for getting, putting, or listing
  75. * S3 buckets or objects, or modifying the ACLs associated with buckets
  76. * or objects, using one of three general approaches:
  77. * 1. Simple blocking requests, one at a time
  78. * 2. Multiple threads each making simple blocking requests
  79. * 3. From a single thread, managing multiple S3 requests simultaneously
  80. * using file descriptors and a select()/poll() loop
  81. * - Shut down libs3 at program exit time by calling S3_deinitialize()
  82. *
  83. * All functions which send requests to S3 return their results via a set of
  84. * callback functions which must be supplied to libs3 at the time that the
  85. * request is initiated. libs3 will call these functions back in the thread
  86. * calling the libs3 function if blocking requests are made (i.e., if the
  87. * S3RequestContext for the function invocation is passed in as NULL).
  88. * If an S3RequestContext is used to drive multiple S3 requests
  89. * simultaneously, then the callbacks will be made from the thread which
  90. * calls S3_runall_request_context() or S3_runonce_request_context(), or
  91. * possibly from the thread which calls S3_destroy_request_context(), if
  92. * S3 requests are in progress at the time that this function is called.
  93. *
  94. * NOTE: Response headers from Amazon S3 are limited to 4K (2K of metas is all
  95. * that Amazon supports, and libs3 allows Amazon an additional 2K of headers).
  96. *
  97. * NOTE: Because HTTP and the S3 REST protocol are highly under-specified,
  98. * libs3 must make some assumptions about the maximum length of certain HTTP
  99. * elements (such as headers) that it will accept. While efforts have been
  100. * made to enforce maximums which are beyond that expected to be needed by any
  101. * user of S3, it is always possible that these maximums may be too low in
  102. * some rare circumstances. Bug reports should this unlikely situation occur
  103. * would be most appreciated.
  104. *
  105. * Threading Rules
  106. * ---------------
  107. *
  108. * 1. All arguments passed to any function must not be modified directly until
  109. * the function returns.
  110. * 2. All S3RequestContext and S3Request arguments passed to all functions may
  111. * not be passed to any other libs3 function by any other thread until the
  112. * function returns.
  113. * 3. All functions may be called simultaneously by multiple threads as long
  114. * as (1) and (2) are observed, EXCEPT for S3_initialize(), which must be
  115. * called from one thread at a time only.
  116. * 4. All callbacks will be made in the thread of the caller of the function
  117. * which invoked them, so the caller of all libs3 functions should not hold
  118. * locks that it would try to re-acquire in a callback, as this may
  119. * deadlock.
  120. ************************************************************************** **/
  121. /** **************************************************************************
  122. * Constants
  123. ************************************************************************** **/
  124. /**
  125. * S3_MAX_HOSTNAME_SIZE is the maximum size we allow for a host name
  126. **/
  127. #define S3_MAX_HOSTNAME_SIZE 255
  128. /**
  129. * This is the default hostname that is being used for the S3 requests
  130. **/
  131. #define S3_DEFAULT_HOSTNAME "s3.amazonaws.com"
  132. /**
  133. * S3_MAX_BUCKET_NAME_SIZE is the maximum size of a bucket name.
  134. **/
  135. #define S3_MAX_BUCKET_NAME_SIZE 255
  136. /**
  137. * S3_MAX_KEY_SIZE is the maximum size of keys that Amazon S3 supports.
  138. **/
  139. #define S3_MAX_KEY_SIZE 1024
  140. /**
  141. * S3_MAX_METADATA_SIZE is the maximum number of bytes allowed for
  142. * x-amz-meta header names and values in any request passed to Amazon S3
  143. **/
  144. #define S3_MAX_METADATA_SIZE 2048
  145. /**
  146. * S3_METADATA_HEADER_NAME_PREFIX is the prefix of an S3 "meta header"
  147. **/
  148. #define S3_METADATA_HEADER_NAME_PREFIX "x-amz-meta-"
  149. /**
  150. * S3_MAX_METADATA_COUNT is the maximum number of x-amz-meta- headers that
  151. * could be included in a request to S3. The smallest meta header is
  152. * "x-amz-meta-n: v". Since S3 doesn't count the ": " against the total, the
  153. * smallest amount of data to count for a header would be the length of
  154. * "x-amz-meta-nv".
  155. **/
  156. #define S3_MAX_METADATA_COUNT \
  157. (S3_MAX_METADATA_SIZE / (sizeof(S3_METADATA_HEADER_NAME_PREFIX "nv") - 1))
  158. /**
  159. * S3_MAX_ACL_GRANT_COUNT is the maximum number of ACL grants that may be
  160. * set on a bucket or object at one time. It is also the maximum number of
  161. * ACL grants that the XML ACL parsing routine will parse.
  162. **/
  163. #define S3_MAX_ACL_GRANT_COUNT 100
  164. /**
  165. * This is the maximum number of characters (including terminating \0) that
  166. * libs3 supports in an ACL grantee email address.
  167. **/
  168. #define S3_MAX_GRANTEE_EMAIL_ADDRESS_SIZE 128
  169. /**
  170. * This is the maximum number of characters (including terminating \0) that
  171. * libs3 supports in an ACL grantee user id.
  172. **/
  173. #define S3_MAX_GRANTEE_USER_ID_SIZE 128
  174. /**
  175. * This is the maximum number of characters (including terminating \0) that
  176. * libs3 supports in an ACL grantee user display name.
  177. **/
  178. #define S3_MAX_GRANTEE_DISPLAY_NAME_SIZE 128
  179. /**
  180. * This is the maximum number of characters that will be stored in the
  181. * return buffer for the utility function which computes an HTTP authenticated
  182. * query string
  183. **/
  184. #define S3_MAX_AUTHENTICATED_QUERY_STRING_SIZE \
  185. (sizeof("https:///") + S3_MAX_HOSTNAME_SIZE + (S3_MAX_KEY_SIZE * 3) + \
  186. sizeof("?AWSAccessKeyId=") + 32 + sizeof("&Expires=") + 32 + \
  187. sizeof("&Signature=") + 28 + 1)
  188. /**
  189. * This constant is used by the S3_initialize() function, to specify that
  190. * the winsock library should be initialized by libs3; only relevent on
  191. * Microsoft Windows platforms.
  192. **/
  193. #define S3_INIT_WINSOCK 1
  194. /**
  195. * This constant is used by the S3_initialize() function, to enable peer SSL
  196. * certificate by default for all requests. If this is not set in the
  197. * flags passed to S3_initialize(), then the SSL certificate of the peer
  198. * will NOT be verified by default (but can still be enabled on a per request
  199. * basis by calling S3_set_request_context_verify_peer).
  200. */
  201. #define S3_INIT_VERIFY_PEER 2
  202. /**
  203. * This convenience constant is used by the S3_initialize() function to
  204. * indicate that all libraries required by libs3 should be initialized.
  205. **/
  206. #define S3_INIT_ALL (S3_INIT_WINSOCK)
  207. /**
  208. * The default region identifier used to scope the signing key
  209. */
  210. #define S3_DEFAULT_REGION "us-east-1"
  211. /** **************************************************************************
  212. * Enumerations
  213. ************************************************************************** **/
  214. /**
  215. * S3Status is a status code as returned by a libs3 function. The meaning of
  216. * each status code is defined in the comments for each function which returns
  217. * that status.
  218. **/
  219. typedef enum
  220. {
  221. S3StatusOK ,
  222. /**
  223. * Errors that prevent the S3 request from being issued or response from
  224. * being read
  225. **/
  226. S3StatusInternalError ,
  227. S3StatusOutOfMemory ,
  228. S3StatusInterrupted ,
  229. S3StatusInvalidBucketNameTooLong ,
  230. S3StatusInvalidBucketNameFirstCharacter ,
  231. S3StatusInvalidBucketNameCharacter ,
  232. S3StatusInvalidBucketNameCharacterSequence ,
  233. S3StatusInvalidBucketNameTooShort ,
  234. S3StatusInvalidBucketNameDotQuadNotation ,
  235. S3StatusQueryParamsTooLong ,
  236. S3StatusFailedToInitializeRequest ,
  237. S3StatusMetaDataHeadersTooLong ,
  238. S3StatusBadMetaData ,
  239. S3StatusBadContentType ,
  240. S3StatusContentTypeTooLong ,
  241. S3StatusBadMD5 ,
  242. S3StatusMD5TooLong ,
  243. S3StatusBadCacheControl ,
  244. S3StatusCacheControlTooLong ,
  245. S3StatusBadContentDispositionFilename ,
  246. S3StatusContentDispositionFilenameTooLong ,
  247. S3StatusBadContentEncoding ,
  248. S3StatusContentEncodingTooLong ,
  249. S3StatusBadIfMatchETag ,
  250. S3StatusIfMatchETagTooLong ,
  251. S3StatusBadIfNotMatchETag ,
  252. S3StatusIfNotMatchETagTooLong ,
  253. S3StatusHeadersTooLong ,
  254. S3StatusKeyTooLong ,
  255. S3StatusUriTooLong ,
  256. S3StatusXmlParseFailure ,
  257. S3StatusEmailAddressTooLong ,
  258. S3StatusUserIdTooLong ,
  259. S3StatusUserDisplayNameTooLong ,
  260. S3StatusGroupUriTooLong ,
  261. S3StatusPermissionTooLong ,
  262. S3StatusTargetBucketTooLong ,
  263. S3StatusTargetPrefixTooLong ,
  264. S3StatusTooManyGrants ,
  265. S3StatusBadGrantee ,
  266. S3StatusBadPermission ,
  267. S3StatusXmlDocumentTooLarge ,
  268. S3StatusNameLookupError ,
  269. S3StatusFailedToConnect ,
  270. S3StatusServerFailedVerification ,
  271. S3StatusConnectionFailed ,
  272. S3StatusAbortedByCallback ,
  273. S3StatusNotSupported ,
  274. /**
  275. * Errors from the S3 service
  276. **/
  277. S3StatusErrorAccessDenied ,
  278. S3StatusErrorAccountProblem ,
  279. S3StatusErrorAmbiguousGrantByEmailAddress ,
  280. S3StatusErrorBadDigest ,
  281. S3StatusErrorBucketAlreadyExists ,
  282. S3StatusErrorBucketAlreadyOwnedByYou ,
  283. S3StatusErrorBucketNotEmpty ,
  284. S3StatusErrorCredentialsNotSupported ,
  285. S3StatusErrorCrossLocationLoggingProhibited ,
  286. S3StatusErrorEntityTooSmall ,
  287. S3StatusErrorEntityTooLarge ,
  288. S3StatusErrorExpiredToken ,
  289. S3StatusErrorIllegalVersioningConfigurationException ,
  290. S3StatusErrorIncompleteBody ,
  291. S3StatusErrorIncorrectNumberOfFilesInPostRequest ,
  292. S3StatusErrorInlineDataTooLarge ,
  293. S3StatusErrorInternalError ,
  294. S3StatusErrorInvalidAccessKeyId ,
  295. S3StatusErrorInvalidAddressingHeader ,
  296. S3StatusErrorInvalidArgument ,
  297. S3StatusErrorInvalidBucketName ,
  298. S3StatusErrorInvalidBucketState ,
  299. S3StatusErrorInvalidDigest ,
  300. S3StatusErrorInvalidEncryptionAlgorithmError ,
  301. S3StatusErrorInvalidLocationConstraint ,
  302. S3StatusErrorInvalidObjectState ,
  303. S3StatusErrorInvalidPart ,
  304. S3StatusErrorInvalidPartOrder ,
  305. S3StatusErrorInvalidPayer ,
  306. S3StatusErrorInvalidPolicyDocument ,
  307. S3StatusErrorInvalidRange ,
  308. S3StatusErrorInvalidRequest ,
  309. S3StatusErrorInvalidSecurity ,
  310. S3StatusErrorInvalidSOAPRequest ,
  311. S3StatusErrorInvalidStorageClass ,
  312. S3StatusErrorInvalidTargetBucketForLogging ,
  313. S3StatusErrorInvalidToken ,
  314. S3StatusErrorInvalidURI ,
  315. S3StatusErrorKeyTooLong ,
  316. S3StatusErrorMalformedACLError ,
  317. S3StatusErrorMalformedPOSTRequest ,
  318. S3StatusErrorMalformedXML ,
  319. S3StatusErrorMaxMessageLengthExceeded ,
  320. S3StatusErrorMaxPostPreDataLengthExceededError ,
  321. S3StatusErrorMetadataTooLarge ,
  322. S3StatusErrorMethodNotAllowed ,
  323. S3StatusErrorMissingAttachment ,
  324. S3StatusErrorMissingContentLength ,
  325. S3StatusErrorMissingRequestBodyError ,
  326. S3StatusErrorMissingSecurityElement ,
  327. S3StatusErrorMissingSecurityHeader ,
  328. S3StatusErrorNoLoggingStatusForKey ,
  329. S3StatusErrorNoSuchBucket ,
  330. S3StatusErrorNoSuchKey ,
  331. S3StatusErrorNoSuchLifecycleConfiguration ,
  332. S3StatusErrorNoSuchUpload ,
  333. S3StatusErrorNoSuchVersion ,
  334. S3StatusErrorNotImplemented ,
  335. S3StatusErrorNotSignedUp ,
  336. S3StatusErrorNoSuchBucketPolicy ,
  337. S3StatusErrorOperationAborted ,
  338. S3StatusErrorPermanentRedirect ,
  339. S3StatusErrorPreconditionFailed ,
  340. S3StatusErrorRedirect ,
  341. S3StatusErrorRestoreAlreadyInProgress ,
  342. S3StatusErrorRequestIsNotMultiPartContent ,
  343. S3StatusErrorRequestTimeout ,
  344. S3StatusErrorRequestTimeTooSkewed ,
  345. S3StatusErrorRequestTorrentOfBucketError ,
  346. S3StatusErrorSignatureDoesNotMatch ,
  347. S3StatusErrorServiceUnavailable ,
  348. S3StatusErrorSlowDown ,
  349. S3StatusErrorTemporaryRedirect ,
  350. S3StatusErrorTokenRefreshRequired ,
  351. S3StatusErrorTooManyBuckets ,
  352. S3StatusErrorUnexpectedContent ,
  353. S3StatusErrorUnresolvableGrantByEmailAddress ,
  354. S3StatusErrorUserKeyMustBeSpecified ,
  355. S3StatusErrorQuotaExceeded ,
  356. S3StatusErrorAuthorizationHeaderMalformed , // WINSCP
  357. S3StatusErrorUnknown ,
  358. /**
  359. * The following are HTTP errors returned by S3 without enough detail to
  360. * distinguish any of the above S3StatusError conditions
  361. **/
  362. S3StatusHttpErrorMovedTemporarily ,
  363. S3StatusHttpErrorBadRequest ,
  364. S3StatusHttpErrorForbidden ,
  365. S3StatusHttpErrorNotFound ,
  366. S3StatusHttpErrorConflict ,
  367. S3StatusHttpErrorUnknown
  368. } S3Status;
  369. /**
  370. * S3Protocol represents a protocol that may be used for communicating a
  371. * request to the Amazon S3 service.
  372. *
  373. * In general, HTTPS is greatly preferred (and should be the default of any
  374. * application using libs3) because it protects any data being sent to or
  375. * from S3 using strong encryption. However, HTTPS is much more CPU intensive
  376. * than HTTP, and if the caller is absolutely certain that it is OK for the
  377. * data to be viewable by anyone in transit, then HTTP can be used.
  378. **/
  379. typedef enum
  380. {
  381. S3ProtocolHTTPS = 0,
  382. S3ProtocolHTTP = 1
  383. } S3Protocol;
  384. /**
  385. * S3UriStyle defines the form that an Amazon S3 URI identifying a bucket or
  386. * object can take. They are of these forms:
  387. *
  388. * Virtual Host: ${protocol}://${bucket}.s3.amazonaws.com/[${key}]
  389. * Path: ${protocol}://s3.amazonaws.com/${bucket}/[${key}]
  390. *
  391. * It is generally better to use the Virual Host URI form, because it ensures
  392. * that the bucket name used is compatible with normal HTTP GETs and POSTs of
  393. * data to/from the bucket. However, if DNS lookups for the bucket are too
  394. * slow or unreliable for some reason, Path URI form may be used.
  395. **/
  396. typedef enum
  397. {
  398. S3UriStyleVirtualHost = 0,
  399. S3UriStylePath = 1
  400. } S3UriStyle;
  401. /**
  402. * S3GranteeType defines the type of Grantee used in an S3 ACL Grant.
  403. * Amazon Customer By Email - identifies the Grantee using their Amazon S3
  404. * account email address
  405. * Canonical User - identifies the Grantee by S3 User ID and Display Name,
  406. * which can only be obtained by making requests to S3, for example, by
  407. * listing owned buckets
  408. * All AWS Users - identifies all authenticated AWS users
  409. * All Users - identifies all users
  410. * Log Delivery - identifies the Amazon group responsible for writing
  411. * server access logs into buckets
  412. **/
  413. typedef enum
  414. {
  415. S3GranteeTypeAmazonCustomerByEmail = 0,
  416. S3GranteeTypeCanonicalUser = 1,
  417. S3GranteeTypeAllAwsUsers = 2,
  418. S3GranteeTypeAllUsers = 3,
  419. S3GranteeTypeLogDelivery = 4
  420. } S3GranteeType;
  421. /**
  422. * This is an individual permission granted to a grantee in an S3 ACL Grant.
  423. * Read permission gives the Grantee the permission to list the bucket, or
  424. * read the object or its metadata
  425. * Write permission gives the Grantee the permission to create, overwrite, or
  426. * delete any object in the bucket, and is not supported for objects
  427. * ReadACP permission gives the Grantee the permission to read the ACP for
  428. * the bucket or object; the owner of the bucket or object always has
  429. * this permission implicitly
  430. * WriteACP permission gives the Grantee the permission to overwrite the ACP
  431. * for the bucket or object; the owner of the bucket or object always has
  432. * this permission implicitly
  433. * FullControl permission gives the Grantee all permissions specified by the
  434. * Read, Write, ReadACP, and WriteACP permissions
  435. **/
  436. typedef enum
  437. {
  438. S3PermissionRead = 0,
  439. S3PermissionWrite = 1,
  440. S3PermissionReadACP = 2,
  441. S3PermissionWriteACP = 3,
  442. S3PermissionFullControl = 4
  443. } S3Permission;
  444. /**
  445. * S3CannedAcl is an ACL that can be specified when an object is created or
  446. * updated. Each canned ACL has a predefined value when expanded to a full
  447. * set of S3 ACL Grants.
  448. * Private canned ACL gives the owner FULL_CONTROL and no other permissions
  449. * are issued
  450. * Public Read canned ACL gives the owner FULL_CONTROL and all users Read
  451. * permission
  452. * Public Read Write canned ACL gives the owner FULL_CONTROL and all users
  453. * Read and Write permission
  454. * AuthenticatedRead canned ACL gives the owner FULL_CONTROL and authenticated
  455. * S3 users Read permission
  456. **/
  457. typedef enum
  458. {
  459. S3CannedAclPrivate = 0, /* private */
  460. S3CannedAclPublicRead = 1, /* public-read */
  461. S3CannedAclPublicReadWrite = 2, /* public-read-write */
  462. S3CannedAclAuthenticatedRead = 3, /* authenticated-read */
  463. S3CannedAclBucketOwnerFullControl = 4 /* bucket-owner-full-control */
  464. } S3CannedAcl;
  465. /** **************************************************************************
  466. * Data Types
  467. ************************************************************************** **/
  468. /**
  469. * An S3RequestContext manages multiple S3 requests simultaneously; see the
  470. * S3_XXX_request_context functions below for details
  471. **/
  472. typedef struct S3RequestContext S3RequestContext;
  473. /**
  474. * S3NameValue represents a single Name - Value pair, used to represent either
  475. * S3 metadata associated with a key, or S3 error details.
  476. **/
  477. typedef struct S3NameValue
  478. {
  479. /**
  480. * The name part of the Name - Value pair
  481. **/
  482. const char *name;
  483. /**
  484. * The value part of the Name - Value pair
  485. **/
  486. const char *value;
  487. } S3NameValue;
  488. /**
  489. * S3ResponseProperties is passed to the properties callback function which is
  490. * called when the complete response properties have been received. Some of
  491. * the fields of this structure are optional and may not be provided in the
  492. * response, and some will always be provided in the response.
  493. **/
  494. typedef struct S3ResponseProperties
  495. {
  496. /**
  497. * This optional field identifies the request ID and may be used when
  498. * reporting problems to Amazon.
  499. **/
  500. const char *requestId;
  501. /**
  502. * This optional field identifies the request ID and may be used when
  503. * reporting problems to Amazon.
  504. **/
  505. const char *requestId2;
  506. /**
  507. * This optional field is the content type of the data which is returned
  508. * by the request. If not provided, the default can be assumed to be
  509. * "binary/octet-stream".
  510. **/
  511. const char *contentType;
  512. /**
  513. * This optional field is the content length of the data which is returned
  514. * in the response. A negative value means that this value was not
  515. * provided in the response. A value of 0 means that there is no content
  516. * provided. A positive value gives the number of bytes in the content of
  517. * the response.
  518. **/
  519. uint64_t contentLength;
  520. /**
  521. * This optional field names the server which serviced the request.
  522. **/
  523. const char *server;
  524. /**
  525. * This optional field provides a string identifying the unique contents
  526. * of the resource identified by the request, such that the contents can
  527. * be assumed not to be changed if the same eTag is returned at a later
  528. * time decribing the same resource. This is an MD5 sum of the contents.
  529. **/
  530. const char *eTag;
  531. /**
  532. * This optional field provides the last modified time, relative to the
  533. * Unix epoch, of the contents. If this value is < 0, then the last
  534. * modified time was not provided in the response. If this value is >= 0,
  535. * then the last modified date of the contents are available as a number
  536. * of seconds since the UNIX epoch.
  537. *
  538. **/
  539. int64_t lastModified;
  540. /**
  541. * This is the number of user-provided meta data associated with the
  542. * resource.
  543. **/
  544. int metaDataCount;
  545. /**
  546. * These are the meta data associated with the resource. In each case,
  547. * the name will not include any S3-specific header prefixes
  548. * (i.e. x-amz-meta- will have been removed from the beginning), and
  549. * leading and trailing whitespace will have been stripped from the value.
  550. **/
  551. const S3NameValue *metaData;
  552. /**
  553. * This optional field provides an indication of whether or not
  554. * server-side encryption was used for the object. This field is only
  555. * meaningful if the request was an object put, copy, get, or head
  556. * request.
  557. * If this value is 0, then server-side encryption is not in effect for
  558. * the object (or the request was one for which server-side encryption is
  559. * not a meaningful value); if this value is non-zero, then server-side
  560. * encryption is in effect for the object.
  561. **/
  562. char usesServerSideEncryption;
  563. } S3ResponseProperties;
  564. /**
  565. * S3AclGrant identifies a single grant in the ACL for a bucket or object. An
  566. * ACL is composed of any number of grants, which specify a grantee and the
  567. * permissions given to that grantee. S3 does not normalize ACLs in any way,
  568. * so a redundant ACL specification will lead to a redundant ACL stored in S3.
  569. **/
  570. typedef struct S3AclGrant
  571. {
  572. /**
  573. * The granteeType gives the type of grantee specified by this grant.
  574. **/
  575. S3GranteeType granteeType;
  576. /**
  577. * The identifier of the grantee that is set is determined by the
  578. * granteeType:
  579. *
  580. * S3GranteeTypeAmazonCustomerByEmail - amazonCustomerByEmail.emailAddress
  581. * S3GranteeTypeCanonicalUser - canonicalUser.id, canonicalUser.displayName
  582. * S3GranteeTypeAllAwsUsers - none
  583. * S3GranteeTypeAllUsers - none
  584. **/
  585. union
  586. {
  587. /**
  588. * This structure is used iff the granteeType is
  589. * S3GranteeTypeAmazonCustomerByEmail.
  590. **/
  591. struct
  592. {
  593. /**
  594. * This is the email address of the Amazon Customer being granted
  595. * permissions by this S3AclGrant.
  596. **/
  597. char emailAddress[S3_MAX_GRANTEE_EMAIL_ADDRESS_SIZE];
  598. } amazonCustomerByEmail;
  599. /**
  600. * This structure is used iff the granteeType is
  601. * S3GranteeTypeCanonicalUser.
  602. **/
  603. struct
  604. {
  605. /**
  606. * This is the CanonicalUser ID of the grantee
  607. **/
  608. char id[S3_MAX_GRANTEE_USER_ID_SIZE];
  609. /**
  610. * This is the display name of the grantee
  611. **/
  612. char displayName[S3_MAX_GRANTEE_DISPLAY_NAME_SIZE];
  613. } canonicalUser;
  614. } grantee;
  615. /**
  616. * This is the S3Permission to be granted to the grantee
  617. **/
  618. S3Permission permission;
  619. } S3AclGrant;
  620. /**
  621. * A context for working with objects within a bucket. A bucket context holds
  622. * all information necessary for working with a bucket, and may be used
  623. * repeatedly over many consecutive (or simultaneous) calls into libs3 bucket
  624. * operation functions.
  625. **/
  626. typedef struct S3BucketContext
  627. {
  628. /**
  629. * The name of the host to connect to when making S3 requests. If set to
  630. * NULL, the default S3 hostname passed in to S3_initialize will be used.
  631. **/
  632. // WINSCP: Can contain port number
  633. const char *hostName;
  634. /**
  635. * The name of the bucket to use in the bucket context
  636. **/
  637. const char *bucketName;
  638. /**
  639. * The protocol to use when accessing the bucket
  640. **/
  641. S3Protocol protocol;
  642. /**
  643. * The URI style to use for all URIs sent to Amazon S3 while working with
  644. * this bucket context
  645. **/
  646. S3UriStyle uriStyle;
  647. /**
  648. * The Amazon Access Key ID to use for access to the bucket
  649. **/
  650. const char *accessKeyId;
  651. /**
  652. * The Amazon Secret Access Key to use for access to the bucket
  653. **/
  654. const char *secretAccessKey;
  655. /**
  656. * The Amazon Security Token used to generate Temporary Security Credentials
  657. **/
  658. const char *securityToken;
  659. /**
  660. * The AWS region to which to scope the signing key used for authorization.
  661. * If NULL, the default region ("us-east-1") will be used.
  662. */
  663. const char *authRegion;
  664. } S3BucketContext;
  665. /**
  666. * This is a single entry supplied to the list bucket callback by a call to
  667. * S3_list_bucket. It identifies a single matching key from the list
  668. * operation.
  669. **/
  670. typedef struct S3ListBucketContent
  671. {
  672. /**
  673. * This is the next key in the list bucket results.
  674. **/
  675. const char *key;
  676. /**
  677. * This is the number of seconds since UNIX epoch of the last modified
  678. * date of the object identified by the key.
  679. **/
  680. int64_t lastModified;
  681. /**
  682. * This gives a tag which gives a signature of the contents of the object,
  683. * which is the MD5 of the contents of the object.
  684. **/
  685. const char *eTag;
  686. /**
  687. * This is the size of the object in bytes.
  688. **/
  689. uint64_t size;
  690. /**
  691. * This is the ID of the owner of the key; it is present only if access
  692. * permissions allow it to be viewed.
  693. **/
  694. const char *ownerId;
  695. /**
  696. * This is the display name of the owner of the key; it is present only if
  697. * access permissions allow it to be viewed.
  698. **/
  699. const char *ownerDisplayName;
  700. } S3ListBucketContent;
  701. /**
  702. * This is a single entry supplied to the list bucket callback by a call to
  703. * S3_list_bucket. It identifies a single matching key from the list
  704. * operation.
  705. **/
  706. typedef struct S3ListMultipartUpload
  707. {
  708. /**
  709. * This is the next key in the list bucket results.
  710. **/
  711. const char *key;
  712. const char *uploadId;
  713. const char *initiatorId;
  714. const char *initiatorDisplayName;
  715. /**
  716. * This is the ID of the owner of the key; it is present only if access
  717. * permissions allow it to be viewed.
  718. **/
  719. const char *ownerId;
  720. /**
  721. * This is the display name of the owner of the key; it is present only if
  722. * access permissions allow it to be viewed.
  723. **/
  724. const char *ownerDisplayName;
  725. const char *storageClass;
  726. /**
  727. * This is the number of seconds since UNIX epoch of the last modified
  728. * date of the object identified by the key.
  729. **/
  730. int64_t initiated;
  731. } S3ListMultipartUpload;
  732. typedef struct S3ListPart
  733. {
  734. const char *eTag;
  735. /**
  736. * This is the number of seconds since UNIX epoch of the last modified
  737. * date of the object identified by the key.
  738. **/
  739. int64_t lastModified;
  740. uint64_t partNumber;
  741. uint64_t size;
  742. } S3ListPart;
  743. /**
  744. * S3PutProperties is the set of properties that may optionally be set by the
  745. * user when putting objects to S3. Each field of this structure is optional
  746. * and may or may not be present.
  747. **/
  748. typedef struct S3PutProperties
  749. {
  750. /**
  751. * If present, this is the Content-Type that should be associated with the
  752. * object. If not provided, S3 defaults to "binary/octet-stream".
  753. **/
  754. const char *contentType;
  755. /**
  756. * If present, this provides the MD5 signature of the contents, and is
  757. * used to validate the contents. This is highly recommended by Amazon
  758. * but not required. Its format is as a base64-encoded MD5 sum.
  759. **/
  760. const char *md5;
  761. /**
  762. * If present, this gives a Cache-Control header string to be supplied to
  763. * HTTP clients which download this
  764. **/
  765. const char *cacheControl;
  766. /**
  767. * If present, this gives the filename to save the downloaded file to,
  768. * whenever the object is downloaded via a web browser. This is only
  769. * relevent for objects which are intended to be shared to users via web
  770. * browsers and which is additionally intended to be downloaded rather
  771. * than viewed.
  772. **/
  773. const char *contentDispositionFilename;
  774. /**
  775. * If present, this identifies the content encoding of the object. This
  776. * is only applicable to encoded (usually, compressed) content, and only
  777. * relevent if the object is intended to be downloaded via a browser.
  778. **/
  779. const char *contentEncoding;
  780. /**
  781. * If >= 0, this gives an expiration date for the content. This
  782. * information is typically only delivered to users who download the
  783. * content via a web browser.
  784. **/
  785. int64_t expires;
  786. /**
  787. * This identifies the "canned ACL" that should be used for this object.
  788. * The default (0) gives only the owner of the object access to it.
  789. **/
  790. S3CannedAcl cannedAcl;
  791. /**
  792. * This is the number of values in the metaData field.
  793. **/
  794. int metaDataCount;
  795. /**
  796. * These are the meta data to pass to S3. In each case, the name part of
  797. * the Name - Value pair should not include any special S3 HTTP header
  798. * prefix (i.e., should be of the form 'foo', NOT 'x-amz-meta-foo').
  799. **/
  800. const S3NameValue *metaData;
  801. /**
  802. * This a boolean value indicating whether or not the object should be
  803. * stored by Amazon S3 using server-side encryption, wherein the data is
  804. * encrypted by Amazon before being stored on permanent medium.
  805. * Server-side encryption does not affect the data as it is sent to or
  806. * received by Amazon, the encryption is applied by Amazon when objects
  807. * are put and then de-encryption is applied when the objects are read by
  808. * clients.
  809. * If this value is 0, then server-side encryption is not used; if this
  810. * value is non-zero, then server-side encryption is used. Note that the
  811. * encryption status of the object can be checked by ensuring that the put
  812. * response has the usesServerSideEncryption flag set.
  813. **/
  814. char useServerSideEncryption;
  815. } S3PutProperties;
  816. /**
  817. * S3GetConditions is used for the get_object operation, and specifies
  818. * conditions which the object must meet in order to be successfully returned.
  819. **/
  820. typedef struct S3GetConditions
  821. {
  822. /**
  823. * The request will be processed if the Last-Modification header of the
  824. * object is greater than or equal to this value, specified as a number of
  825. * seconds since Unix epoch. If this value is less than zero, it will not
  826. * be used in the conditional.
  827. **/
  828. int64_t ifModifiedSince;
  829. /**
  830. * The request will be processed if the Last-Modification header of the
  831. * object is less than this value, specified as a number of seconds since
  832. * Unix epoch. If this value is less than zero, it will not be used in
  833. * the conditional.
  834. **/
  835. int64_t ifNotModifiedSince;
  836. /**
  837. * If non-NULL, this gives an eTag header value which the object must
  838. * match in order to be returned. Note that altough the eTag is simply an
  839. * MD5, this must be presented in the S3 eTag form, which typically
  840. * includes double-quotes.
  841. **/
  842. const char *ifMatchETag;
  843. /**
  844. * If non-NULL, this gives an eTag header value which the object must not
  845. * match in order to be returned. Note that altough the eTag is simply an
  846. * MD5, this must be presented in the S3 eTag form, which typically
  847. * includes double-quotes.
  848. **/
  849. const char *ifNotMatchETag;
  850. } S3GetConditions;
  851. /**
  852. * S3ErrorDetails provides detailed information describing an S3 error. This
  853. * is only presented when the error is an S3-generated error (i.e. one of the
  854. * S3StatusErrorXXX values).
  855. **/
  856. typedef struct S3ErrorDetails
  857. {
  858. /**
  859. * This is the human-readable message that Amazon supplied describing the
  860. * error
  861. **/
  862. const char *message;
  863. /**
  864. * This identifies the resource for which the error occurred
  865. **/
  866. const char *resource;
  867. /**
  868. * This gives human-readable further details describing the specifics of
  869. * this error
  870. **/
  871. const char *furtherDetails;
  872. /**
  873. * This gives the number of S3NameValue pairs present in the extraDetails
  874. * array
  875. **/
  876. int extraDetailsCount;
  877. /**
  878. * S3 can provide extra details in a freeform Name - Value pair format.
  879. * Each error can have any number of these, and this array provides these
  880. * additional extra details.
  881. **/
  882. S3NameValue *extraDetails;
  883. } S3ErrorDetails;
  884. /** **************************************************************************
  885. * Callback Signatures
  886. ************************************************************************** **/
  887. /**
  888. * This callback is made whenever the response properties become available for
  889. * any request.
  890. *
  891. * @param properties are the properties that are available from the response
  892. * @param callbackData is the callback data as specified when the request
  893. * was issued.
  894. * @return S3StatusOK to continue processing the request, anything else to
  895. * immediately abort the request with a status which will be
  896. * passed to the S3ResponseCompleteCallback for this request.
  897. * Typically, this will return either S3StatusOK or
  898. * S3StatusAbortedByCallback.
  899. **/
  900. typedef S3Status (S3ResponsePropertiesCallback)
  901. (const S3ResponseProperties *properties, void *callbackData);
  902. /**
  903. * This callback is made when the response has been completely received, or an
  904. * error has occurred which has prematurely aborted the request, or one of the
  905. * other user-supplied callbacks returned a value intended to abort the
  906. * request. This callback is always made for every request, as the very last
  907. * callback made for that request.
  908. *
  909. * @param status gives the overall status of the response, indicating success
  910. * or failure; use S3_status_is_retryable() as a simple way to detect
  911. * whether or not the status indicates that the request failed but may
  912. * be retried.
  913. * @param errorDetails if non-NULL, gives details as returned by the S3
  914. * service, describing the error
  915. * @param callbackData is the callback data as specified when the request
  916. * was issued.
  917. **/
  918. typedef void (S3ResponseCompleteCallback)(S3Status status,
  919. const S3ErrorDetails *errorDetails,
  920. void *callbackData);
  921. /**
  922. * This callback is made for each bucket resulting from a list service
  923. * operation.
  924. *
  925. * @param ownerId is the ID of the owner of the bucket
  926. * @param ownerDisplayName is the owner display name of the owner of the bucket
  927. * @param bucketName is the name of the bucket
  928. * @param creationDateSeconds if < 0 indicates that no creation date was
  929. * supplied for the bucket; if >= 0 indicates the number of seconds
  930. * since UNIX Epoch of the creation date of the bucket
  931. * @param callbackData is the callback data as specified when the request
  932. * was issued.
  933. * @return S3StatusOK to continue processing the request, anything else to
  934. * immediately abort the request with a status which will be
  935. * passed to the S3ResponseCompleteCallback for this request.
  936. * Typically, this will return either S3StatusOK or
  937. * S3StatusAbortedByCallback.
  938. **/
  939. typedef S3Status (S3ListServiceCallback)(const char *ownerId,
  940. const char *ownerDisplayName,
  941. const char *bucketName,
  942. int64_t creationDateSeconds,
  943. void *callbackData);
  944. /**
  945. * This callback is made repeatedly as a list bucket operation progresses.
  946. * The contents reported via this callback are only reported once per list
  947. * bucket operation, but multiple calls to this callback may be necessary to
  948. * report all items resulting from the list bucket operation.
  949. *
  950. * @param isTruncated is true if the list bucket request was truncated by the
  951. * S3 service, in which case the remainder of the list may be obtained
  952. * by querying again using the Marker parameter to start the query
  953. * after this set of results
  954. * @param nextMarker if present, gives the largest (alphabetically) key
  955. * returned in the response, which, if isTruncated is true, may be used
  956. * as the marker in a subsequent list buckets operation to continue
  957. * listing
  958. * @param contentsCount is the number of ListBucketContent structures in the
  959. * contents parameter
  960. * @param contents is an array of ListBucketContent structures, each one
  961. * describing an object in the bucket
  962. * @param commonPrefixesCount is the number of common prefixes strings in the
  963. * commonPrefixes parameter
  964. * @param commonPrefixes is an array of strings, each specifing one of the
  965. * common prefixes as returned by S3
  966. * @param callbackData is the callback data as specified when the request
  967. * was issued.
  968. * @return S3StatusOK to continue processing the request, anything else to
  969. * immediately abort the request with a status which will be
  970. * passed to the S3ResponseCompleteCallback for this request.
  971. * Typically, this will return either S3StatusOK or
  972. * S3StatusAbortedByCallback.
  973. **/
  974. typedef S3Status (S3ListBucketCallback)(int isTruncated,
  975. const char *nextMarker,
  976. int contentsCount,
  977. const S3ListBucketContent *contents,
  978. int commonPrefixesCount,
  979. const char **commonPrefixes,
  980. void *callbackData);
  981. /**
  982. * This callback is made during a put object operation, to obtain the next
  983. * chunk of data to put to the S3 service as the contents of the object. This
  984. * callback is made repeatedly, each time acquiring the next chunk of data to
  985. * write to the service, until a negative or 0 value is returned.
  986. *
  987. * @param bufferSize gives the maximum number of bytes that may be written
  988. * into the buffer parameter by this callback
  989. * @param buffer gives the buffer to fill with at most bufferSize bytes of
  990. * data as the next chunk of data to send to S3 as the contents of this
  991. * object
  992. * @param callbackData is the callback data as specified when the request
  993. * was issued.
  994. * @return < 0 to abort the request with the S3StatusAbortedByCallback, which
  995. * will be pased to the response complete callback for this request, or
  996. * 0 to indicate the end of data, or > 0 to identify the number of
  997. * bytes that were written into the buffer by this callback
  998. **/
  999. typedef int (S3PutObjectDataCallback)(int bufferSize, char *buffer,
  1000. void *callbackData);
  1001. /**
  1002. * This callback is made during a get object operation, to provide the next
  1003. * chunk of data available from the S3 service constituting the contents of
  1004. * the object being fetched. This callback is made repeatedly, each time
  1005. * providing the next chunk of data read, until the complete object contents
  1006. * have been passed through the callback in this way, or the callback
  1007. * returns an error status.
  1008. *
  1009. * @param bufferSize gives the number of bytes in buffer
  1010. * @param buffer is the data being passed into the callback
  1011. * @param callbackData is the callback data as specified when the request
  1012. * was issued.
  1013. * @return S3StatusOK to continue processing the request, anything else to
  1014. * immediately abort the request with a status which will be
  1015. * passed to the S3ResponseCompleteCallback for this request.
  1016. * Typically, this will return either S3StatusOK or
  1017. * S3StatusAbortedByCallback.
  1018. **/
  1019. typedef S3Status (S3GetObjectDataCallback)(int bufferSize, const char *buffer,
  1020. void *callbackData);
  1021. /**
  1022. * This callback is made after initiation of a multipart upload operation. It
  1023. * indicates that the multi part upload has been created and provides the
  1024. * id that can be used to associate multi upload parts with the multi upload
  1025. * operation
  1026. *
  1027. * @param upload_id is the unique identifier if this multi part upload
  1028. * operation, to be used in calls to S3_upload_part and
  1029. * S3_complete_multipart_upload
  1030. * @param callbackData is the callback data as specified when the request
  1031. * was issued.
  1032. * @return S3StatusOK to continue processing the request, anything else to
  1033. * immediately abort the request with a status which will be
  1034. * passed to the S3ResponseCompleteCallback for this request.
  1035. * Typically, this will return either S3StatusOK or
  1036. * S3StatusAbortedByCallback.
  1037. **/
  1038. typedef S3Status (S3MultipartInitialResponseCallback)(const char *upload_id,
  1039. void *callbackData);
  1040. /**
  1041. * This callback is made after completion of a part of a multipart upload
  1042. * operation. It is a status callback indicating that the multipart upload is
  1043. * in progress and that some sub-set of the parts have completed upload. The
  1044. * multipart upload is not considered fully complete in total until the commit
  1045. * response callback is made.
  1046. *
  1047. * @param isTruncated is ??? someone document this please
  1048. * @param nextKeyMarker is ??? someone document this please
  1049. * @param nextUploadIdMarker is ??? someone document this please
  1050. * @param uploadsCount is the number of elements in the [uploads] array
  1051. * @param uploads is an array of ??? someone document this please
  1052. * @param commonPrefixesCount is the number of elements in the
  1053. * [commonPrefixes] array
  1054. * @param commonPrefixes is ??? someone document this please
  1055. * @param callbackData is the callback data as specified when the request
  1056. * was issued.
  1057. * @return S3StatusOK to continue processing the request, anything else to
  1058. * immediately abort the request with a status which will be
  1059. * passed to the S3ResponseCompleteCallback for this request.
  1060. * Typically, this will return either S3StatusOK or
  1061. * S3StatusAbortedByCallback.
  1062. **/
  1063. typedef S3Status (S3ListMultipartUploadsResponseCallback)
  1064. (int isTruncated, const char *nextKeyMarker,
  1065. const char *nextUploadIdMarker, int uploadsCount,
  1066. const S3ListMultipartUpload *uploads, int commonPrefixesCount,
  1067. const char **commonPrefixes, void *callbackData);
  1068. /**
  1069. * This callback is made with the result of a succesful "list parts" request
  1070. * to list the parts of a multi part upload (in progress???).
  1071. *
  1072. * @param isTruncated is ??? someone document this please
  1073. * @param nextPartNumberMarker is ??? someone document this please
  1074. * @param intiatorId is ??? someone document this please
  1075. * @param initiatorDisplayName is ??? someone document this please
  1076. * @param ownerId is ??? someone document this please
  1077. * @param ownerDisplayName is ??? someone document this please
  1078. * @param storageClass is ??? someone document this please
  1079. * @param partsCount is ??? someone document this please
  1080. * @param lastPartNumber is ??? someone document this please
  1081. * @param parts is ??? someone document this please
  1082. * @param callbackData is the callback data as specified when the request
  1083. * was issued.
  1084. * @return S3StatusOK to continue processing the request, anything else to
  1085. * immediately abort the request with a status which will be
  1086. * passed to the S3ResponseCompleteCallback for this request.
  1087. * Typically, this will return either S3StatusOK or
  1088. * S3StatusAbortedByCallback.
  1089. **/
  1090. typedef S3Status (S3ListPartsResponseCallback)
  1091. (int isTruncated, const char *nextPartNumberMarker,
  1092. const char *initiatorId, const char *initiatorDisplayName,
  1093. const char *ownerId, const char *ownerDisplayName,
  1094. const char *storageClass, int partsCount, int lastPartNumber,
  1095. const S3ListPart *parts, void *callbackData);
  1096. /**
  1097. * This callback is made after commit of a multipart upload operation. It
  1098. * indicates that the data uploaded via the multipart upload operation has
  1099. * been committed.
  1100. *
  1101. * @param location is ??? someone please document this
  1102. * @param etag is the S3 etag of the complete object after the multipart
  1103. * upload
  1104. * @param callbackData is the callback data as specified when the request
  1105. * was issued.
  1106. * @return S3StatusOK to continue processing the request, anything else to
  1107. * immediately abort the request with a status which will be
  1108. * passed to the S3ResponseCompleteCallback for this request.
  1109. * Typically, this will return either S3StatusOK or
  1110. * S3StatusAbortedByCallback.
  1111. **/
  1112. typedef S3Status (S3MultipartCommitResponseCallback)(const char *location,
  1113. const char *etag,
  1114. void *callbackData);
  1115. /**
  1116. * Mechanism for S3 application to customize each CURL easy request
  1117. * associated with the given S3 request context.
  1118. *
  1119. * This callback can be optinally configured using S3_create_request_context_ex
  1120. * and will be invoked every time a new CURL request is created in the
  1121. * context of the given CURLM handle. Invocation will occur after
  1122. * libs3 has finished configuring its own options of CURL, but before
  1123. * CURL is started.
  1124. *
  1125. * @param curl_multi is the CURLM handle associated with this context.
  1126. * @param curl_easy is the CURL request being created.
  1127. * @param setupData is the setupCurlCallbackData parameter passed to
  1128. * S3_create_request_context_ex.
  1129. * @return S3StatusOK to continue processing the request, anything else to
  1130. * immediately abort the request and pass this status
  1131. * to the S3ResponseCompleteCallback for this request.
  1132. **/
  1133. typedef S3Status (*S3SetupCurlCallback)(void *curlMulti, void *curlEasy,
  1134. void *setupData);
  1135. /** **************************************************************************
  1136. * Callback Structures
  1137. ************************************************************************** **/
  1138. /**
  1139. * An S3ResponseHandler defines the callbacks which are made for any
  1140. * request.
  1141. **/
  1142. typedef struct S3ResponseHandler
  1143. {
  1144. /**
  1145. * The propertiesCallback is made when the response properties have
  1146. * successfully been returned from S3. This function may not be called
  1147. * if the response properties were not successfully returned from S3.
  1148. **/
  1149. S3ResponsePropertiesCallback *propertiesCallback;
  1150. /**
  1151. * The completeCallback is always called for every request made to S3,
  1152. * regardless of the outcome of the request. It provides the status of
  1153. * the request upon its completion, as well as extra error details in the
  1154. * event of an S3 error.
  1155. **/
  1156. S3ResponseCompleteCallback *completeCallback;
  1157. } S3ResponseHandler;
  1158. /**
  1159. * An S3ListServiceHandler defines the callbacks which are made for
  1160. * list_service requests.
  1161. **/
  1162. typedef struct S3ListServiceHandler
  1163. {
  1164. /**
  1165. * responseHandler provides the properties and complete callback
  1166. **/
  1167. S3ResponseHandler responseHandler;
  1168. /**
  1169. * The listServiceCallback is called as items are reported back from S3 as
  1170. * responses to the request
  1171. **/
  1172. S3ListServiceCallback *listServiceCallback;
  1173. } S3ListServiceHandler;
  1174. /**
  1175. * An S3ListBucketHandler defines the callbacks which are made for
  1176. * list_bucket requests.
  1177. **/
  1178. typedef struct S3ListBucketHandler
  1179. {
  1180. /**
  1181. * responseHandler provides the properties and complete callback
  1182. **/
  1183. S3ResponseHandler responseHandler;
  1184. /**
  1185. * The listBucketCallback is called as items are reported back from S3 as
  1186. * responses to the request. This may be called more than one time per
  1187. * list bucket request, each time providing more items from the list
  1188. * operation.
  1189. **/
  1190. S3ListBucketCallback *listBucketCallback;
  1191. } S3ListBucketHandler;
  1192. /**
  1193. * An S3PutObjectHandler defines the callbacks which are made for
  1194. * put_object requests.
  1195. **/
  1196. typedef struct S3PutObjectHandler
  1197. {
  1198. /**
  1199. * responseHandler provides the properties and complete callback
  1200. **/
  1201. S3ResponseHandler responseHandler;
  1202. /**
  1203. * The putObjectDataCallback is called to acquire data to send to S3 as
  1204. * the contents of the put_object request. It is made repeatedly until it
  1205. * returns a negative number (indicating that the request should be
  1206. * aborted), or 0 (indicating that all data has been supplied).
  1207. **/
  1208. S3PutObjectDataCallback *putObjectDataCallback;
  1209. } S3PutObjectHandler;
  1210. /**
  1211. * An S3GetObjectHandler defines the callbacks which are made for
  1212. * get_object requests.
  1213. **/
  1214. typedef struct S3GetObjectHandler
  1215. {
  1216. /**
  1217. * responseHandler provides the properties and complete callback
  1218. **/
  1219. S3ResponseHandler responseHandler;
  1220. /**
  1221. * The getObjectDataCallback is called as data is read from S3 as the
  1222. * contents of the object being read in the get_object request. It is
  1223. * called repeatedly until there is no more data provided in the request,
  1224. * or until the callback returns an error status indicating that the
  1225. * request should be aborted.
  1226. **/
  1227. S3GetObjectDataCallback *getObjectDataCallback;
  1228. } S3GetObjectHandler;
  1229. typedef struct S3MultipartInitialHandler {
  1230. /**
  1231. * responseHandler provides the properties and complete callback
  1232. **/
  1233. S3ResponseHandler responseHandler;
  1234. S3MultipartInitialResponseCallback *responseXmlCallback;
  1235. } S3MultipartInitialHandler;
  1236. typedef struct S3MultipartCommitHandler
  1237. {
  1238. /**
  1239. * responseHandler provides the properties and complete callback
  1240. **/
  1241. S3ResponseHandler responseHandler;
  1242. /**
  1243. * The putObjectDataCallback is called to acquire data to send to S3 as
  1244. * the contents of the put_object request. It is made repeatedly until it
  1245. * returns a negative number (indicating that the request should be
  1246. * aborted), or 0 (indicating that all data has been supplied).
  1247. **/
  1248. S3PutObjectDataCallback *putObjectDataCallback;
  1249. S3MultipartCommitResponseCallback *responseXmlCallback;
  1250. } S3MultipartCommitHandler;
  1251. typedef struct S3ListMultipartUploadsHandler
  1252. {
  1253. /**
  1254. * responseHandler provides the properties and complete callback
  1255. **/
  1256. S3ResponseHandler responseHandler;
  1257. S3ListMultipartUploadsResponseCallback *responseXmlCallback;
  1258. } S3ListMultipartUploadsHandler;
  1259. typedef struct S3ListPartsHandler
  1260. {
  1261. /**
  1262. * responseHandler provides the properties and complete callback
  1263. **/
  1264. S3ResponseHandler responseHandler;
  1265. S3ListPartsResponseCallback *responseXmlCallback;
  1266. } S3ListPartsHandler;
  1267. typedef struct S3AbortMultipartUploadHandler
  1268. {
  1269. /**
  1270. * responseHandler provides the properties and complete callback
  1271. **/
  1272. S3ResponseHandler responseHandler;
  1273. } S3AbortMultipartUploadHandler;
  1274. /** **************************************************************************
  1275. * General Library Functions
  1276. ************************************************************************** **/
  1277. /**
  1278. * Initializes libs3 for use. This function must be called before any other
  1279. * libs3 function is called. It may be called multiple times, with the same
  1280. * effect as calling it once, as long as S3_deinitialize() is called an
  1281. * equal number of times when the program has finished. This function is NOT
  1282. * thread-safe and must only be called by one thread at a time.
  1283. *
  1284. * @param userAgentInfo is a string that will be included in the User-Agent
  1285. * header of every request made to the S3 service. You may provide
  1286. * NULL or the empty string if you don't care about this. The value
  1287. * will not be copied by this function and must remain unaltered by the
  1288. * caller until S3_deinitialize() is called.
  1289. * @param flags is a bitmask of some combination of S3_INIT_XXX flag, or
  1290. * S3_INIT_ALL, indicating which of the libraries that libs3 depends
  1291. * upon should be initialized by S3_initialize(). Only if your program
  1292. * initializes one of these dependency libraries itself should anything
  1293. * other than S3_INIT_ALL be passed in for this bitmask.
  1294. *
  1295. * You should pass S3_INIT_WINSOCK if and only if your application does
  1296. * not initialize winsock elsewhere. On non-Microsoft Windows
  1297. * platforms it has no effect.
  1298. *
  1299. * As a convenience, the macro S3_INIT_ALL is provided, which will do
  1300. * all necessary initialization; however, be warned that things may
  1301. * break if your application re-initializes the dependent libraries
  1302. * later.
  1303. * @param defaultS3HostName is a string the specifies the default S3 server
  1304. * hostname to use when making S3 requests; this value is used
  1305. * whenever the hostName of an S3BucketContext is NULL. If NULL is
  1306. * passed here then the default of S3_DEFAULT_HOSTNAME will be used.
  1307. * @return One of:
  1308. * S3StatusOK on success
  1309. * S3StatusUriTooLong if the defaultS3HostName is longer than
  1310. * S3_MAX_HOSTNAME_SIZE
  1311. * S3StatusInternalError if dependent libraries could not be
  1312. * initialized
  1313. * S3StatusOutOfMemory on failure due to out of memory
  1314. **/
  1315. S3Status S3_initialize(const char *userAgentInfo, int flags,
  1316. const char *defaultS3HostName);
  1317. /**
  1318. * Must be called once per program for each call to libs3_initialize(). After
  1319. * this call is complete, no libs3 function may be called except
  1320. * S3_initialize().
  1321. **/
  1322. void S3_deinitialize();
  1323. /**
  1324. * Returns a string with the textual name of an S3Status code
  1325. *
  1326. * @param status is S3Status code for which the textual name will be returned
  1327. * @return a string with the textual name of an S3Status code
  1328. **/
  1329. const char *S3_get_status_name(S3Status status);
  1330. /**
  1331. * This function may be used to validate an S3 bucket name as being in the
  1332. * correct form for use with the S3 service. Amazon S3 limits the allowed
  1333. * characters in S3 bucket names, as well as imposing some additional rules on
  1334. * the length of bucket names and their structure. There are actually two
  1335. * limits; one for bucket names used only in path-style URIs, and a more
  1336. * strict limit used for bucket names used in virtual-host-style URIs. It is
  1337. * advisable to use only bucket names which meet the more strict requirements
  1338. * regardless of how the bucket expected to be used.
  1339. *
  1340. * This method does NOT validate that the bucket is available for use in the
  1341. * S3 service, so the return value of this function cannot be used to decide
  1342. * whether or not a bucket with the give name already exists in Amazon S3 or
  1343. * is accessible by the caller. It merely validates that the bucket name is
  1344. * valid for use with S3.
  1345. *
  1346. * @param bucketName is the bucket name to validate
  1347. * @param uriStyle gives the URI style to validate the bucket name against.
  1348. * It is advisable to always use S3UriStyleVirtuallHost.
  1349. * @return One of:
  1350. * S3StatusOK if the bucket name was validates successfully
  1351. * S3StatusConnectionFailed if the socket connection to the server
  1352. * failed
  1353. * S3StatusServerFailedVerification if the SSL certificate of the
  1354. * server could not be verified.
  1355. * S3StatusInvalidBucketNameTooLong if the bucket name exceeded the
  1356. * length limitation for the URI style, which is 255 bytes for
  1357. * path style URIs and 63 bytes for virtual host type URIs
  1358. * S3StatusInvalidBucketNameTooShort if the bucket name is less than
  1359. * 3 characters
  1360. * S3StatusInvalidBucketNameFirstCharacter if the bucket name as an
  1361. * invalid first character, which is anything other than
  1362. * an alphanumeric character
  1363. * S3StatusInvalidBucketNameCharacterSequence if the bucket name
  1364. * includes an invalid character sequence, which for virtual host
  1365. * style buckets is ".-" or "-."
  1366. * S3StatusInvalidBucketNameCharacter if the bucket name includes an
  1367. * invalid character, which is anything other than alphanumeric,
  1368. * '-', '.', or for path style URIs only, '_'.
  1369. * S3StatusInvalidBucketNameDotQuadNotation if the bucket name is in
  1370. * dot-quad notation, i.e. the form of an IP address, which is
  1371. * not allowed by Amazon S3.
  1372. **/
  1373. S3Status S3_validate_bucket_name(const char *bucketName, S3UriStyle uriStyle);
  1374. /**
  1375. * Converts an XML representation of an ACL to a libs3 structured
  1376. * representation. This method is not strictly necessary for working with
  1377. * ACLs using libs3, but may be convenient for users of the library who read
  1378. * ACLs from elsewhere in XML format and need to use these ACLs with libs3.
  1379. *
  1380. * @param aclXml is the XML representation of the ACL. This must be a
  1381. * zero-terminated character string.
  1382. * @param ownerId will be filled in with the Owner ID specified in the XML.
  1383. * At most MAX_GRANTEE_USER_ID_SIZE bytes will be stored at this
  1384. * location.
  1385. * @param ownerDisplayName will be filled in with the Owner Display Name
  1386. * specified in the XML. At most MAX_GRANTEE_DISPLAY_NAME_SIZE bytes
  1387. * will be stored at this location.
  1388. * @param aclGrantCountReturn returns the number of S3AclGrant structures
  1389. * returned in the aclGrantsReturned array
  1390. * @param aclGrants must be passed in as an array of at least S3_ACL_MAXCOUNT
  1391. * structures, and on return from this function, the first
  1392. * aclGrantCountReturn structures will be filled in with the ACLs
  1393. * represented by the input XML.
  1394. * @return One of:
  1395. * S3StatusOK on successful conversion of the ACL
  1396. * S3StatusInternalError on internal error representing a bug in the
  1397. * libs3 library
  1398. * S3StatusXmlParseFailure if the XML document was malformed
  1399. **/
  1400. S3Status S3_convert_acl(char *aclXml, char *ownerId, char *ownerDisplayName,
  1401. int *aclGrantCountReturn, S3AclGrant *aclGrants);
  1402. /**
  1403. * Returns nonzero if the status indicates that the request should be
  1404. * immediately retried, because the status indicates an error of a nature that
  1405. * is likely due to transient conditions on the local system or S3, such as
  1406. * network failures, or internal retryable errors reported by S3. Returns
  1407. * zero otherwise.
  1408. *
  1409. * @param status is the status to evaluate
  1410. * @return nonzero if the status indicates a retryable error, 0 otherwise
  1411. **/
  1412. int S3_status_is_retryable(S3Status status);
  1413. /** **************************************************************************
  1414. * Request Context Management Functions
  1415. ************************************************************************** **/
  1416. /**
  1417. * An S3RequestContext allows muliple requests to be serviced by the same
  1418. * thread simultaneously. It is an optional parameter to all libs3 request
  1419. * functions, and if provided, the request is managed by the S3RequestContext;
  1420. * if not, the request is handled synchronously and is complete when the libs3
  1421. * request function has returned.
  1422. *
  1423. * @param requestContextReturn returns the newly-created S3RequestContext
  1424. * structure, which if successfully returned, must be destroyed via a
  1425. * call to S3_destroy_request_context when it is no longer needed. If
  1426. * an error status is returned from this function, then
  1427. * requestContextReturn will not have been filled in, and
  1428. * S3_destroy_request_context should not be called on it
  1429. * @return One of:
  1430. * S3StatusOK if the request context was successfully created
  1431. * S3StatusOutOfMemory if the request context could not be created due
  1432. * to an out of memory error
  1433. **/
  1434. S3Status S3_create_request_context(S3RequestContext **requestContextReturn);
  1435. /**
  1436. * Extended version of S3_create_request_context used to create S3RequestContext
  1437. * for curl_multi_socket_action CURLM handles that will be managed by libs3 user.
  1438. * This type of handles offer better performance for applications with large
  1439. * number of simultaneous connections. For details, see MULTI_SOCKET chapter here:
  1440. * https://curl.haxx.se/libcurl/c/libcurl-multi.html
  1441. *
  1442. * In this mode libs3 user will
  1443. * - create its own CURLM using curl_multi_init()
  1444. * - configure it for its own handlers using
  1445. * CURLMOPT_SOCKETFUNCTION/CURLMOPT_TIMERFUNCTION/etc
  1446. * - use S3_create_request_context_ex to create S3RequestContext
  1447. * for the above CURLM handle
  1448. * - start S3 request
  1449. * - every time setupCurlCallback is called, will configure new CURL
  1450. * object with its own handlers using
  1451. * CURLOPT_OPENSOCKETFUNCTION/CURLOPT_CLOSESOCKETFUNCTION/etc
  1452. * - the moment libs3 adds CURL object to CURLM handle, curl will start
  1453. * communicating directly with libs3 user to drive socket operations,
  1454. * where libs3 user will be responsible for calling curl_multi_socket_action
  1455. * when necessary.
  1456. * - whenever curl_multi_socket_action indicates change in running_handles
  1457. * libs3 user should call S3_process_request_context to let libs3 process
  1458. * any completed curl transfers and notify back to libs3 user if that was
  1459. * the final transfer for a given S3 request.
  1460. *
  1461. * @param requestContextReturn returns the newly-created S3RequestContext
  1462. * structure, which if successfully returned, must be destroyed via a
  1463. * call to S3_destroy_request_context when it is no longer needed. If
  1464. * an error status is returned from this function, then
  1465. * requestContextReturn will not have been filled in, and
  1466. * S3_destroy_request_context should not be called on it
  1467. * @param curlMulti is the CURLM handle to be associated with this context.
  1468. * @param setupCurlCallback is an optional callback routine to be invoked
  1469. * by libs3 every time another CURL request is being created for
  1470. * use in this context.
  1471. * @param setupCurlCallbackData is an opaque data to be passed to
  1472. * setupCurlCallback.
  1473. **/
  1474. S3Status S3_create_request_context_ex(S3RequestContext **requestContextReturn,
  1475. void *curlMulti,
  1476. S3SetupCurlCallback setupCurlCallback,
  1477. void *setupCurlCallbackData);
  1478. /**
  1479. * Destroys an S3RequestContext which was created with
  1480. * S3_create_request_context. Any requests which are currently being
  1481. * processed by the S3RequestContext will immediately be aborted and their
  1482. * request completed callbacks made with the status S3StatusInterrupted.
  1483. *
  1484. * @param requestContext is the S3RequestContext to destroy
  1485. **/
  1486. void S3_destroy_request_context(S3RequestContext *requestContext);
  1487. #ifdef WINSCP
  1488. struct ne_session_s;
  1489. typedef void (S3SessionCallback)(ne_session_s *session, void *callbackData);
  1490. void S3_set_request_context_session_callback(S3RequestContext *requestContext,
  1491. S3SessionCallback sessionCallback,
  1492. void * sessionCallbackData);
  1493. struct ne_ssl_certificate_s;
  1494. typedef int (S3SslCallback)(int failures, const ne_ssl_certificate_s *certificate, void *callbackData);
  1495. void S3_set_request_context_ssl_callback(S3RequestContext *requestContext,
  1496. S3SslCallback sslCallback,
  1497. void * sslCallbackData);
  1498. typedef void (S3ResponseDataCallback)(const char *data, size_t size, void *callbackData);
  1499. void S3_set_request_context_response_data_callback(S3RequestContext *requestContext,
  1500. S3ResponseDataCallback responseDataCallback,
  1501. void * responseDataCallbackData);
  1502. #else
  1503. /**
  1504. * Runs the S3RequestContext until all requests within it have completed,
  1505. * or until an error occurs.
  1506. *
  1507. * @param requestContext is the S3RequestContext to run until all requests
  1508. * within it have completed or until an error occurs
  1509. * @return One of:
  1510. * S3StatusOK if all requests were successfully run to completion
  1511. * S3StatusConnectionFailed if the socket connection to the server
  1512. * failed
  1513. * S3StatusServerFailedVerification if the SSL certificate of the
  1514. * server could not be verified.
  1515. * S3StatusInternalError if an internal error prevented the
  1516. * S3RequestContext from running one or more requests
  1517. * S3StatusOutOfMemory if requests could not be run to completion
  1518. * due to an out of memory error
  1519. **/
  1520. S3Status S3_runall_request_context(S3RequestContext *requestContext);
  1521. /**
  1522. * Does some processing of requests within the S3RequestContext. One or more
  1523. * requests may have callbacks made on them and may complete. This function
  1524. * processes any requests which have immediately available I/O, and will not
  1525. * block waiting for I/O on any request. This function would normally be used
  1526. * with S3_get_request_context_fdsets.
  1527. *
  1528. * @param requestContext is the S3RequestContext to process
  1529. * @param requestsRemainingReturn returns the number of requests remaining
  1530. * and not yet completed within the S3RequestContext after this
  1531. * function returns.
  1532. * @return One of:
  1533. * S3StatusOK if request processing proceeded without error
  1534. * S3StatusConnectionFailed if the socket connection to the server
  1535. * failed
  1536. * S3StatusServerFailedVerification if the SSL certificate of the
  1537. * server could not be verified.
  1538. * S3StatusInternalError if an internal error prevented the
  1539. * S3RequestContext from running one or more requests
  1540. * S3StatusOutOfMemory if requests could not be processed due to
  1541. * an out of memory error
  1542. **/
  1543. S3Status S3_runonce_request_context(S3RequestContext *requestContext,
  1544. int *requestsRemainingReturn);
  1545. /**
  1546. * Extract and finish requests completed by curl multi handle mechanism
  1547. * in curl_multi_socket_action mode. Should be called by libs3 user when
  1548. * curl_multi_socket_action indicates a change in running_handles.
  1549. *
  1550. * @param requestContext is the S3RequestContext to process
  1551. * @return One of:
  1552. * S3StatusOK if request processing proceeded without error
  1553. * S3StatusConnectionFailed if the socket connection to the server
  1554. * failed
  1555. * S3StatusServerFailedVerification if the SSL certificate of the
  1556. * server could not be verified.
  1557. * S3StatusInternalError if an internal error prevented the
  1558. * S3RequestContext from running one or more requests
  1559. * S3StatusOutOfMemory if requests could not be processed due to
  1560. * an out of memory error
  1561. **/
  1562. S3Status S3_process_request_context(S3RequestContext *requestContext);
  1563. /**
  1564. * This function, in conjunction allows callers to manually manage a set of
  1565. * requests using an S3RequestContext. This function returns the set of file
  1566. * descriptors which the caller can watch (typically using select()), along
  1567. * with any other file descriptors of interest to the caller, and using
  1568. * whatever timeout (if any) the caller wishes, until one or more file
  1569. * descriptors in the returned sets become ready for I/O, at which point
  1570. * S3_runonce_request_context can be called to process requests with available
  1571. * I/O.
  1572. *
  1573. * @param requestContext is the S3RequestContext to get fd_sets from
  1574. * @param readFdSet is a pointer to an fd_set which will have all file
  1575. * descriptors to watch for read events for the requests in the
  1576. * S3RequestContext set into it upon return. Should be zero'd out
  1577. * (using FD_ZERO) before being passed into this function.
  1578. * @param writeFdSet is a pointer to an fd_set which will have all file
  1579. * descriptors to watch for write events for the requests in the
  1580. * S3RequestContext set into it upon return. Should be zero'd out
  1581. * (using FD_ZERO) before being passed into this function.
  1582. * @param exceptFdSet is a pointer to an fd_set which will have all file
  1583. * descriptors to watch for exception events for the requests in the
  1584. * S3RequestContext set into it upon return. Should be zero'd out
  1585. * (using FD_ZERO) before being passed into this function.
  1586. * @param maxFd returns the highest file descriptor set into any of the
  1587. * fd_sets, or -1 if no file descriptors were set
  1588. * @return One of:
  1589. * S3StatusOK if all fd_sets were successfully set
  1590. * S3StatusInternalError if an internal error prevented this function
  1591. * from completing successfully
  1592. **/
  1593. S3Status S3_get_request_context_fdsets(S3RequestContext *requestContext,
  1594. fd_set *readFdSet, fd_set *writeFdSet,
  1595. fd_set *exceptFdSet, int *maxFd);
  1596. /**
  1597. * This function returns the maximum number of milliseconds that the caller of
  1598. * S3_runonce_request_context should wait on the fdsets obtained via a call to
  1599. * S3_get_request_context_fdsets. In other words, this is essentially the
  1600. * select() timeout that needs to be used (shorter values are OK, but no
  1601. * longer than this) to ensure that internal timeout code of libs3 can work
  1602. * properly. This function should be called right before select() each time
  1603. * select() on the request_context fdsets are to be performed by the libs3
  1604. * user.
  1605. *
  1606. * @param requestContext is the S3RequestContext to get the timeout from
  1607. * @return the maximum number of milliseconds to select() on fdsets. Callers
  1608. * could wait a shorter time if they wish, but not longer.
  1609. **/
  1610. int64_t S3_get_request_context_timeout(S3RequestContext *requestContext);
  1611. /**
  1612. * This function enables SSL peer certificate verification on a per-request
  1613. * context basis. If this is called, the context's value of verifyPeer will
  1614. * be used when processing requests. Otherwise, the default set by the
  1615. * flags to S3_initialize() are used.
  1616. *
  1617. * @param requestContext the S3RequestContext to set the verifyPeer flag on.
  1618. * @param verifyPeer a boolean value indicating whether to verify the peer
  1619. * certificate or not.
  1620. */
  1621. void S3_set_request_context_verify_peer(S3RequestContext *requestContext,
  1622. int verifyPeer);
  1623. #endif
  1624. /** **************************************************************************
  1625. * S3 Utility Functions
  1626. ************************************************************************** **/
  1627. #ifndef WINSCP
  1628. /**
  1629. * Generates an HTTP authenticated query string, which may then be used by
  1630. * a browser (or other web client) to issue the request. The request is
  1631. * implicitly a GET request; Amazon S3 is documented to only support this type
  1632. * of authenticated query string request.
  1633. *
  1634. * @param buffer is the output buffer for the authenticated query string.
  1635. * It must be at least S3_MAX_AUTHENTICATED_QUERY_STRING_SIZE bytes in
  1636. * length.
  1637. * @param bucketContext gives the bucket and associated parameters for the
  1638. * request to generate.
  1639. * @param key gives the key which the authenticated request will GET.
  1640. * @param expires gives the number of seconds since Unix epoch for the
  1641. * expiration date of the request; after this time, the request will
  1642. * no longer be valid. If this value is negative, the largest
  1643. * expiration interval possible is used (one week).
  1644. * @param resource gives a sub-resource to be fetched for the request, or NULL
  1645. * for none. This should be of the form "?<resource>", i.e.
  1646. * "?torrent".
  1647. * @param httpMethod the HTTP request method that will be used with the
  1648. * generated query string (e.g. "GET").
  1649. * @return One of:
  1650. * S3StatusUriTooLong if, due to an internal error, the generated URI
  1651. * is longer than S3_MAX_AUTHENTICATED_QUERY_STRING_SIZE bytes in
  1652. * length and thus will not fit into the supplied buffer
  1653. * S3StatusOK on success
  1654. **/
  1655. S3Status S3_generate_authenticated_query_string
  1656. (char *buffer, const S3BucketContext *bucketContext,
  1657. const char *key, int expires, const char *resource,
  1658. const char *httpMethod);
  1659. #endif
  1660. /** **************************************************************************
  1661. * Service Functions
  1662. ************************************************************************** **/
  1663. /**
  1664. * Lists all S3 buckets belonging to the access key id.
  1665. *
  1666. * @param protocol gives the protocol to use for this request
  1667. * @param accessKeyId gives the Amazon Access Key ID for which to list owned
  1668. * buckets
  1669. * @param secretAccessKey gives the Amazon Secret Access Key for which to list
  1670. * owned buckets
  1671. * @param securityToken gives the security token used to generate the Temporary
  1672. * Security Credentials
  1673. * @param hostName is the S3 host name to use; if NULL is passed in, the
  1674. * default S3 host as provided to S3_initialize() will be used.
  1675. * @param authRegion is the AWS region to use for the authorization signature
  1676. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  1677. * request to, and does not perform the request immediately. If NULL,
  1678. * performs the request immediately and synchronously.
  1679. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  1680. * @param handler gives the callbacks to call as the request is processed and
  1681. * completed
  1682. * @param callbackData will be passed in as the callbackData parameter to
  1683. * all callbacks for this request
  1684. **/
  1685. void S3_list_service(S3Protocol protocol, const char *accessKeyId,
  1686. const char *secretAccessKey, const char *securityToken,
  1687. const char *hostName, const char *authRegion,
  1688. int maxkeys, // WINSCP
  1689. S3RequestContext *requestContext,
  1690. int timeoutMs,
  1691. const S3ListServiceHandler *handler, void *callbackData);
  1692. /** **************************************************************************
  1693. * Bucket Functions
  1694. ************************************************************************** **/
  1695. /**
  1696. * Tests the existence of an S3 bucket, additionally returning the bucket's
  1697. * location if it exists and is accessible.
  1698. *
  1699. * @param protocol gives the protocol to use for this request
  1700. * @param uriStyle gives the URI style to use for this request
  1701. * @param accessKeyId gives the Amazon Access Key ID for which to list owned
  1702. * buckets
  1703. * @param secretAccessKey gives the Amazon Secret Access Key for which to list
  1704. * owned buckets
  1705. * @param securityToken gives the security token used to generate the Temporary
  1706. * Security Credentials
  1707. * @param hostName is the S3 host name to use; if NULL is passed in, the
  1708. * default S3 host as provided to S3_initialize() will be used.
  1709. * @param bucketName is the bucket name to test
  1710. * @param authRegion is the AWS region to use for the authorization signature
  1711. * @param locationConstraintReturnSize gives the number of bytes in the
  1712. * locationConstraintReturn parameter
  1713. * @param locationConstraintReturn provides the location into which to write
  1714. * the name of the location constraint naming the geographic location
  1715. * of the S3 bucket. This must have at least as many characters in it
  1716. * as specified by locationConstraintReturn, and should start out
  1717. * NULL-terminated. On successful completion of this request, this
  1718. * will be set to the name of the geographic location of S3 bucket, or
  1719. * will be left as a zero-length string if no location was available.
  1720. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  1721. * request to, and does not perform the request immediately. If NULL,
  1722. * performs the request immediately and synchronously.
  1723. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  1724. * @param handler gives the callbacks to call as the request is processed and
  1725. * completed
  1726. * @param callbackData will be passed in as the callbackData parameter to
  1727. * all callbacks for this request
  1728. **/
  1729. void S3_test_bucket(S3Protocol protocol, S3UriStyle uriStyle,
  1730. const char *accessKeyId, const char *secretAccessKey,
  1731. const char *securityToken, const char *hostName,
  1732. const char *bucketName, const char *authRegion,
  1733. int locationConstraintReturnSize,
  1734. char *locationConstraintReturn,
  1735. S3RequestContext *requestContext,
  1736. int timeoutMs,
  1737. const S3ResponseHandler *handler, void *callbackData);
  1738. /**
  1739. * Creates a new bucket.
  1740. *
  1741. * @param protocol gives the protocol to use for this request
  1742. * @param accessKeyId gives the Amazon Access Key ID for which to list owned
  1743. * buckets
  1744. * @param secretAccessKey gives the Amazon Secret Access Key for which to list
  1745. * owned buckets
  1746. * @param securityToken gives the security token used to generate the Temporary
  1747. * Security Credentials
  1748. * @param hostName is the S3 host name to use; if NULL is passed in, the
  1749. * default S3 host as provided to S3_initialize() will be used.
  1750. * @param bucketName is the name of the bucket to be created
  1751. * @param authRegion is the AWS region to use for the authorization signature
  1752. * @param cannedAcl gives the "REST canned ACL" to use for the created bucket
  1753. * @param locationConstraint if non-NULL, gives the geographic location for
  1754. * the bucket to create.
  1755. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  1756. * request to, and does not perform the request immediately. If NULL,
  1757. * performs the request immediately and synchronously.
  1758. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  1759. * @param handler gives the callbacks to call as the request is processed and
  1760. * completed
  1761. * @param callbackData will be passed in as the callbackData parameter to
  1762. * all callbacks for this request
  1763. **/
  1764. void S3_create_bucket(S3Protocol protocol, const char *accessKeyId,
  1765. const char *secretAccessKey, const char *securityToken,
  1766. const char *hostName, const char *bucketName,
  1767. const char *authRegion, S3CannedAcl cannedAcl,
  1768. const char *locationConstraint,
  1769. S3RequestContext *requestContext,
  1770. int timeoutMs,
  1771. const S3ResponseHandler *handler, void *callbackData);
  1772. /**
  1773. * Deletes a bucket. The bucket must be empty, or the status
  1774. * S3StatusErrorBucketNotEmpty will result.
  1775. *
  1776. * @param protocol gives the protocol to use for this request
  1777. * @param uriStyle gives the URI style to use for this request
  1778. * @param accessKeyId gives the Amazon Access Key ID for which to list owned
  1779. * buckets
  1780. * @param secretAccessKey gives the Amazon Secret Access Key for which to list
  1781. * owned buckets
  1782. * @param securityToken gives the security token used to generate the Temporary
  1783. * Security Credentials
  1784. * @param hostName is the S3 host name to use; if NULL is passed in, the
  1785. * default S3 host as provided to S3_initialize() will be used.
  1786. * @param bucketName is the name of the bucket to be deleted
  1787. * @param authRegion is the AWS region to use for the authorization signature
  1788. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  1789. * request to, and does not perform the request immediately. If NULL,
  1790. * performs the request immediately and synchronously.
  1791. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  1792. * @param handler gives the callbacks to call as the request is processed and
  1793. * completed
  1794. * @param callbackData will be passed in as the callbackData parameter to
  1795. * all callbacks for this request
  1796. **/
  1797. void S3_delete_bucket(S3Protocol protocol, S3UriStyle uriStyle,
  1798. const char *accessKeyId, const char *secretAccessKey,
  1799. const char *securityToken, const char *hostName,
  1800. const char *bucketName, const char *authRegion,
  1801. S3RequestContext *requestContext,
  1802. int timeoutMs,
  1803. const S3ResponseHandler *handler, void *callbackData);
  1804. /**
  1805. * Lists keys within a bucket.
  1806. *
  1807. * @param bucketContext gives the bucket and associated parameters for this
  1808. * request
  1809. * @param prefix if present and non-empty, gives a prefix for matching keys
  1810. * @param marker if present and non-empty, only keys occuring after this value
  1811. * will be listed
  1812. * @param delimiter if present and non-empty, causes keys that contain the
  1813. * same string between the prefix and the first occurrence of the
  1814. * delimiter to be rolled up into a single result element
  1815. * @param maxkeys is the maximum number of keys to return
  1816. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  1817. * request to, and does not perform the request immediately. If NULL,
  1818. * performs the request immediately and synchronously.
  1819. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  1820. * @param handler gives the callbacks to call as the request is processed and
  1821. * completed
  1822. * @param callbackData will be passed in as the callbackData parameter to
  1823. * all callbacks for this request
  1824. **/
  1825. void S3_list_bucket(const S3BucketContext *bucketContext,
  1826. const char *prefix, const char *marker,
  1827. const char *delimiter, int maxkeys,
  1828. S3RequestContext *requestContext,
  1829. int timeoutMs,
  1830. const S3ListBucketHandler *handler, void *callbackData);
  1831. /** **************************************************************************
  1832. * Object Functions
  1833. ************************************************************************** **/
  1834. /**
  1835. * Puts object data to S3. This overwrites any existing object at that key;
  1836. * note that S3 currently only supports full-object upload. The data to
  1837. * upload will be acquired by calling the handler's putObjectDataCallback.
  1838. *
  1839. * @param bucketContext gives the bucket and associated parameters for this
  1840. * request
  1841. * @param key is the key of the object to put to
  1842. * @param contentLength is required and gives the total number of bytes that
  1843. * will be put
  1844. * @param putProperties optionally provides additional properties to apply to
  1845. * the object that is being put to
  1846. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  1847. * request to, and does not perform the request immediately. If NULL,
  1848. * performs the request immediately and synchronously.
  1849. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  1850. * @param handler gives the callbacks to call as the request is processed and
  1851. * completed
  1852. * @param callbackData will be passed in as the callbackData parameter to
  1853. * all callbacks for this request
  1854. **/
  1855. void S3_put_object(const S3BucketContext *bucketContext, const char *key,
  1856. uint64_t contentLength,
  1857. const S3PutProperties *putProperties,
  1858. S3RequestContext *requestContext,
  1859. int timeoutMs,
  1860. const S3PutObjectHandler *handler, void *callbackData);
  1861. /**
  1862. * Copies an object from one location to another. The object may be copied
  1863. * back to itself, which is useful for replacing metadata without changing
  1864. * the object.
  1865. *
  1866. * @param bucketContext gives the source bucket and associated parameters for
  1867. * this request
  1868. * @param key is the source key
  1869. * @param destinationBucket gives the destination bucket into which to copy
  1870. * the object. If NULL, the source bucket will be used.
  1871. * @param destinationKey gives the destination key into which to copy the
  1872. * object. If NULL, the source key will be used.
  1873. * @param putProperties optionally provides properties to apply to the object
  1874. * that is being put to. If not supplied (i.e. NULL is passed in),
  1875. * then the copied object will retain the metadata of the copied
  1876. * object.
  1877. * @param lastModifiedReturn returns the last modified date of the copied
  1878. * object
  1879. * @param eTagReturnSize specifies the number of bytes provided in the
  1880. * eTagReturn buffer
  1881. * @param eTagReturn is a buffer into which the resulting eTag of the copied
  1882. * object will be written
  1883. * @param handler gives the callbacks to call as the request is processed and
  1884. * completed
  1885. * @param callbackData will be passed in as the callbackData parameter to
  1886. * all callbacks for this request
  1887. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  1888. * request to, and does not perform the request immediately. If NULL,
  1889. * performs the request immediately and synchronously.
  1890. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  1891. * @param handler gives the callbacks to call as the request is processed and
  1892. * completed
  1893. * @param callbackData will be passed in as the callbackData parameter to
  1894. * all callbacks for this request
  1895. **/
  1896. void S3_copy_object(const S3BucketContext *bucketContext,
  1897. const char *key, const char *destinationBucket,
  1898. const char *destinationKey,
  1899. const S3PutProperties *putProperties,
  1900. int64_t *lastModifiedReturn, int eTagReturnSize,
  1901. char *eTagReturn, S3RequestContext *requestContext,
  1902. int timeoutMs,
  1903. const S3ResponseHandler *handler, void *callbackData);
  1904. /**
  1905. * Copies portion of an object from one location to another. The object may
  1906. * be copied back to itself, which is useful for replacing metadata without
  1907. * changing the object. Required when doing >5GB object copies.
  1908. *
  1909. * @param bucketContext gives the source bucket and associated parameters for
  1910. * this request
  1911. * @param key is the source key
  1912. * @param destinationBucket gives the destination bucket into which to copy
  1913. * the object. If NULL, the source bucket will be used.
  1914. * @param destinationKey gives the destination key into which to copy the
  1915. * object. If NULL, the source key will be used.
  1916. * @param partNo is the sequence numebr of any multipart upload, 0 = non-multipart
  1917. * @param uploadId is the ID returned for a multipart initialize request, ignored
  1918. * if partNo = 0
  1919. * @param startOffset is the starting point in original object to copy.
  1920. * @param count is the number of bytes starting at startOffset in original
  1921. * object to copy. 0 indicates no-range (i.e. all)
  1922. * @param putProperties optionally provides properties to apply to the object
  1923. * that is being put to. If not supplied (i.e. NULL is passed in),
  1924. * then the copied object will retain the metadata of the copied
  1925. * object.
  1926. * @param lastModifiedReturn returns the last modified date of the copied
  1927. * object
  1928. * @param eTagReturnSize specifies the number of bytes provided in the
  1929. * eTagReturn buffer
  1930. * @param eTagReturn is a buffer into which the resulting eTag of the copied
  1931. * object will be written
  1932. * @param handler gives the callbacks to call as the request is processed and
  1933. * completed
  1934. * @param callbackData will be passed in as the callbackData parameter to
  1935. * all callbacks for this request
  1936. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  1937. * request to, and does not perform the request immediately. If NULL,
  1938. * performs the request immediately and synchronously.
  1939. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  1940. * @param handler gives the callbacks to call as the request is processed and
  1941. * completed
  1942. * @param callbackData will be passed in as the callbackData parameter to
  1943. * all callbacks for this request
  1944. **/
  1945. void S3_copy_object_range(const S3BucketContext *bucketContext,
  1946. const char *key, const char *destinationBucket,
  1947. const char *destinationKey,
  1948. const int partNo, const char *uploadId,
  1949. const unsigned long startOffset, const unsigned long count,
  1950. const S3PutProperties *putProperties,
  1951. int64_t *lastModifiedReturn, int eTagReturnSize,
  1952. char *eTagReturn, S3RequestContext *requestContext,
  1953. int timeoutMs,
  1954. const S3ResponseHandler *handler, void *callbackData);
  1955. /**
  1956. * Gets an object from S3. The contents of the object are returned in the
  1957. * handler's getObjectDataCallback.
  1958. *
  1959. * @param bucketContext gives the bucket and associated parameters for this
  1960. * request
  1961. * @param key is the key of the object to get
  1962. * @param getConditions if non-NULL, gives a set of conditions which must be
  1963. * met in order for the request to succeed
  1964. * @param startByte gives the start byte for the byte range of the contents
  1965. * to be returned
  1966. * @param byteCount gives the number of bytes to return; a value of 0
  1967. * indicates that the contents up to the end should be returned
  1968. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  1969. * request to, and does not perform the request immediately. If NULL,
  1970. * performs the request immediately and synchronously.
  1971. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  1972. * @param handler gives the callbacks to call as the request is processed and
  1973. * completed
  1974. * @param callbackData will be passed in as the callbackData parameter to
  1975. * all callbacks for this request
  1976. **/
  1977. void S3_get_object(const S3BucketContext *bucketContext, const char *key,
  1978. const S3GetConditions *getConditions,
  1979. uint64_t startByte, uint64_t byteCount,
  1980. S3RequestContext *requestContext,
  1981. int timeoutMs,
  1982. const S3GetObjectHandler *handler, void *callbackData);
  1983. /**
  1984. * Gets the response properties for the object, but not the object contents.
  1985. *
  1986. * @param bucketContext gives the bucket and associated parameters for this
  1987. * request
  1988. * @param key is the key of the object to get the properties of
  1989. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  1990. * request to, and does not perform the request immediately. If NULL,
  1991. * performs the request immediately and synchronously.
  1992. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  1993. * @param handler gives the callbacks to call as the request is processed and
  1994. * completed
  1995. * @param callbackData will be passed in as the callbackData parameter to
  1996. * all callbacks for this request
  1997. **/
  1998. void S3_head_object(const S3BucketContext *bucketContext, const char *key,
  1999. S3RequestContext *requestContext,
  2000. int timeoutMs,
  2001. const S3ResponseHandler *handler, void *callbackData);
  2002. /**
  2003. * Deletes an object from S3.
  2004. *
  2005. * @param bucketContext gives the bucket and associated parameters for this
  2006. * request
  2007. * @param key is the key of the object to delete
  2008. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2009. * request to, and does not perform the request immediately. If NULL,
  2010. * performs the request immediately and synchronously.
  2011. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2012. * @param handler gives the callbacks to call as the request is processed and
  2013. * completed
  2014. * @param callbackData will be passed in as the callbackData parameter to
  2015. * all callbacks for this request
  2016. **/
  2017. void S3_delete_object(const S3BucketContext *bucketContext, const char *key,
  2018. S3RequestContext *requestContext,
  2019. int timeoutMs,
  2020. const S3ResponseHandler *handler, void *callbackData);
  2021. /** **************************************************************************
  2022. * Access Control List Functions
  2023. ************************************************************************** **/
  2024. /**
  2025. * Gets the ACL for the given bucket or object.
  2026. *
  2027. * @param bucketContext gives the bucket and associated parameters for this
  2028. * request
  2029. * @param key is the key of the object to get the ACL of; or NULL to get the
  2030. * ACL of the bucket
  2031. * @param ownerId must be supplied as a buffer of at least
  2032. * S3_MAX_GRANTEE_USER_ID_SIZE bytes, and will be filled in with the
  2033. * owner ID of the object/bucket
  2034. * @param ownerDisplayName must be supplied as a buffer of at least
  2035. * S3_MAX_GRANTEE_DISPLAY_NAME_SIZE bytes, and will be filled in with
  2036. * the display name of the object/bucket
  2037. * @param aclGrantCountReturn returns the number of S3AclGrant structures
  2038. * returned in the aclGrants parameter
  2039. * @param aclGrants must be passed in as an array of at least
  2040. * S3_MAX_ACL_GRANT_COUNT S3AclGrant structures, which will be filled
  2041. * in with the grant information for the ACL
  2042. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2043. * request to, and does not perform the request immediately. If NULL,
  2044. * performs the request immediately and synchronously.
  2045. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2046. * @param handler gives the callbacks to call as the request is processed and
  2047. * completed
  2048. * @param callbackData will be passed in as the callbackData parameter to
  2049. * all callbacks for this request
  2050. **/
  2051. void S3_get_acl(const S3BucketContext *bucketContext, const char *key,
  2052. char *ownerId, char *ownerDisplayName,
  2053. int *aclGrantCountReturn, S3AclGrant *aclGrants,
  2054. S3RequestContext *requestContext,
  2055. int timeoutMs,
  2056. const S3ResponseHandler *handler, void *callbackData);
  2057. /**
  2058. * Sets the ACL for the given bucket or object.
  2059. *
  2060. * @param bucketContext gives the bucket and associated parameters for this
  2061. * request
  2062. * @param key is the key of the object to set the ACL for; or NULL to set the
  2063. * ACL for the bucket
  2064. * @param ownerId is the owner ID of the object/bucket. Unfortunately, S3
  2065. * requires this to be valid and thus it must have been fetched by a
  2066. * previous S3 request, such as a list_buckets request.
  2067. * @param ownerDisplayName is the owner display name of the object/bucket.
  2068. * Unfortunately, S3 requires this to be valid and thus it must have
  2069. * been fetched by a previous S3 request, such as a list_buckets
  2070. * request.
  2071. * @param aclGrantCount is the number of ACL grants to set for the
  2072. * object/bucket
  2073. * @param aclGrants are the ACL grants to set for the object/bucket
  2074. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2075. * request to, and does not perform the request immediately. If NULL,
  2076. * performs the request immediately and synchronously.
  2077. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2078. * @param handler gives the callbacks to call as the request is processed and
  2079. * completed
  2080. * @param callbackData will be passed in as the callbackData parameter to
  2081. * all callbacks for this request
  2082. **/
  2083. void S3_set_acl(const S3BucketContext *bucketContext, const char *key,
  2084. const char *ownerId, const char *ownerDisplayName,
  2085. int aclGrantCount, const S3AclGrant *aclGrants,
  2086. S3RequestContext *requestContext,
  2087. int timeoutMs,
  2088. const S3ResponseHandler *handler, void *callbackData);
  2089. /** **************************************************************************
  2090. * Lifecycle Control Functions
  2091. ************************************************************************** **/
  2092. /**
  2093. * Gets the lifecycle for the given bucket
  2094. *
  2095. * @param bucketContext gives the bucket and associated parameters for this
  2096. * request
  2097. * @param lifecycleXmlDocumentReturn buffer for lifecycle XML document
  2098. * @param lifecycleXmlDocumentBufferSize size of the buffer
  2099. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2100. * request to, and does not perform the request immediately. If NULL,
  2101. * performs the request immediately and synchronously.
  2102. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2103. * @param handler gives the callbacks to call as the request is processed and
  2104. * completed
  2105. * @param callbackData will be passed in as the callbackData parameter to
  2106. * all callbacks for this request
  2107. **/
  2108. void S3_get_lifecycle(const S3BucketContext *bucketContext,
  2109. char *lifecycleXmlDocumentReturn, int lifecycleXmlDocumentBufferSize,
  2110. S3RequestContext *requestContext,
  2111. int timeoutMs,
  2112. const S3ResponseHandler *handler, void *callbackData);
  2113. /**
  2114. * Sets the lifecycle for the given bucket
  2115. *
  2116. * @param bucketContext gives the bucket and associated parameters for this
  2117. * request
  2118. * @param lifecycleXmlDocument Lifecycle configuration as an XML document
  2119. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2120. * request to, and does not perform the request immediately. If NULL,
  2121. * performs the request immediately and synchronously.
  2122. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2123. * @param handler gives the callbacks to call as the request is processed and
  2124. * completed
  2125. * @param callbackData will be passed in as the callbackData parameter to
  2126. * all callbacks for this request
  2127. **/
  2128. void S3_set_lifecycle(const S3BucketContext *bucketContext,
  2129. const char *lifecycleXmlDocument,
  2130. S3RequestContext *requestContext,
  2131. int timeoutMs,
  2132. const S3ResponseHandler *handler, void *callbackData);
  2133. /** **************************************************************************
  2134. * Server Access Log Functions
  2135. ************************************************************************** **/
  2136. /**
  2137. * Gets the service access logging settings for a bucket. The service access
  2138. * logging settings specify whether or not the S3 service will write service
  2139. * access logs for requests made for the given bucket, and if so, several
  2140. * settings controlling how these logs will be written.
  2141. *
  2142. * @param bucketContext gives the bucket and associated parameters for this
  2143. * request; this is the bucket for which service access logging is
  2144. * being requested
  2145. * @param targetBucketReturn must be passed in as a buffer of at least
  2146. * (S3_MAX_BUCKET_NAME_SIZE + 1) bytes in length, and will be filled
  2147. * in with the target bucket name for access logging for the given
  2148. * bucket, which is the bucket into which access logs for the specified
  2149. * bucket will be written. This is returned as an empty string if
  2150. * service access logging is not enabled for the given bucket.
  2151. * @param targetPrefixReturn must be passed in as a buffer of at least
  2152. * (S3_MAX_KEY_SIZE + 1) bytes in length, and will be filled in
  2153. * with the key prefix for server access logs for the given bucket,
  2154. * or the empty string if no such prefix is specified.
  2155. * @param aclGrantCountReturn returns the number of ACL grants that are
  2156. * associated with the server access logging for the given bucket.
  2157. * @param aclGrants must be passed in as an array of at least
  2158. * S3_MAX_ACL_GRANT_COUNT S3AclGrant structures, and these will be
  2159. * filled in with the target grants associated with the server access
  2160. * logging for the given bucket, whose number is returned in the
  2161. * aclGrantCountReturn parameter. These grants will be applied to the
  2162. * ACL of any server access logging log files generated by the S3
  2163. * service for the given bucket.
  2164. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2165. * request to, and does not perform the request immediately. If NULL,
  2166. * performs the request immediately and synchronously.
  2167. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2168. * @param handler gives the callbacks to call as the request is processed and
  2169. * completed
  2170. * @param callbackData will be passed in as the callbackData parameter to
  2171. * all callbacks for this request
  2172. **/
  2173. void S3_get_server_access_logging(const S3BucketContext *bucketContext,
  2174. char *targetBucketReturn,
  2175. char *targetPrefixReturn,
  2176. int *aclGrantCountReturn,
  2177. S3AclGrant *aclGrants,
  2178. S3RequestContext *requestContext,
  2179. int timeoutMs,
  2180. const S3ResponseHandler *handler,
  2181. void *callbackData);
  2182. /**
  2183. * Sets the service access logging settings for a bucket. The service access
  2184. * logging settings specify whether or not the S3 service will write service
  2185. * access logs for requests made for the given bucket, and if so, several
  2186. * settings controlling how these logs will be written.
  2187. *
  2188. * @param bucketContext gives the bucket and associated parameters for this
  2189. * request; this is the bucket for which service access logging is
  2190. * being set
  2191. * @param targetBucket gives the target bucket name for access logging for the
  2192. * given bucket, which is the bucket into which access logs for the
  2193. * specified bucket will be written.
  2194. * @param targetPrefix is an option parameter which specifies the key prefix
  2195. * for server access logs for the given bucket, or NULL if no such
  2196. * prefix is to be used.
  2197. * @param aclGrantCount specifies the number of ACL grants that are to be
  2198. * associated with the server access logging for the given bucket.
  2199. * @param aclGrants is as an array of S3AclGrant structures, whose number is
  2200. * given by the aclGrantCount parameter. These grants will be applied
  2201. * to the ACL of any server access logging log files generated by the
  2202. * S3 service for the given bucket.
  2203. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2204. * request to, and does not perform the request immediately. If NULL,
  2205. * performs the request immediately and synchronously.
  2206. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2207. * @param handler gives the callbacks to call as the request is processed and
  2208. * completed
  2209. * @param callbackData will be passed in as the callbackData parameter to
  2210. * all callbacks for this request
  2211. **/
  2212. void S3_set_server_access_logging(const S3BucketContext *bucketContext,
  2213. const char *targetBucket,
  2214. const char *targetPrefix, int aclGrantCount,
  2215. const S3AclGrant *aclGrants,
  2216. S3RequestContext *requestContext,
  2217. int timeoutMs,
  2218. const S3ResponseHandler *handler,
  2219. void *callbackData);
  2220. /**
  2221. * This operation initiates a multipart upload and returns an upload ID.
  2222. * This upload ID is used to associate all the parts in the specific
  2223. * multipart upload. You specify this upload ID in each of your subsequent
  2224. * upload part requests
  2225. *
  2226. * @param bucketContext gives the bucket and associated parameters for this
  2227. * request; this is the bucket for which service access logging is
  2228. * being set
  2229. * @param key is the source key
  2230. * @param putProperties optionally provides additional properties to apply to
  2231. * the object that is being put to
  2232. * @param handler gives the callbacks to call as the request is processed and
  2233. * completed
  2234. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2235. * request to, and does not perform the request immediately. If NULL,
  2236. * performs the request immediately and synchronously.
  2237. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2238. * @param callbackData will be passed in as the callbackData parameter to
  2239. * all callbacks for this request
  2240. **/
  2241. void S3_initiate_multipart(S3BucketContext *bucketContext, const char *key,
  2242. S3PutProperties *putProperties,
  2243. S3MultipartInitialHandler *handler,
  2244. S3RequestContext *requestContext,
  2245. int timeoutMs,
  2246. void *callbackData);
  2247. /**
  2248. * This operation uploads a part in a multipart upload.
  2249. *
  2250. * @param bucketContext gives the bucket and associated parameters for this
  2251. * request; this is the bucket for which service access logging is
  2252. * being set
  2253. * @param key is the source key
  2254. * @param putProperties optionally provides additional properties to apply to
  2255. * the object that is being put to
  2256. * @param handler gives the callbacks to call as the request is processed and
  2257. * completed
  2258. * @param seq is a part number uniquely identifies a part and also
  2259. * defines its position within the object being created.
  2260. * @param upload_id get from S3_initiate_multipart return
  2261. * @param partContentLength gives the size of the part, in bytes
  2262. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2263. * request to, and does not perform the request immediately. If NULL,
  2264. * performs the request immediately and synchronously.
  2265. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2266. * @param callbackData will be passed in as the callbackData parameter to
  2267. * all callbacks for this request
  2268. **/
  2269. void S3_upload_part(S3BucketContext *bucketContext, const char *key,
  2270. S3PutProperties * putProperties,
  2271. S3PutObjectHandler *handler,
  2272. int seq, const char *upload_id, int partContentLength,
  2273. S3RequestContext *requestContext,
  2274. int timeoutMs,
  2275. void *callbackData);
  2276. /**
  2277. * This operation completes a multipart upload by assembling previously
  2278. * uploaded parts.
  2279. *
  2280. * @param bucketContext gives the bucket and associated parameters for this
  2281. * request; this is the bucket for which service access logging is
  2282. * being set
  2283. * @param key is the source key
  2284. * @param handler gives the callbacks to call as the request is processed and
  2285. * completed
  2286. * @param upload_id get from S3_initiate_multipart return
  2287. * @param contentLength gives the total size of the commit message, in bytes
  2288. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2289. * request to, and does not perform the request immediately. If NULL,
  2290. * performs the request immediately and synchronously.
  2291. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2292. * @param callbackData will be passed in as the callbackData parameter to
  2293. * all callbacks for this request
  2294. **/
  2295. void S3_complete_multipart_upload(S3BucketContext *bucketContext,
  2296. const char *key,
  2297. S3MultipartCommitHandler *handler,
  2298. const char *upload_id,
  2299. int contentLength,
  2300. S3RequestContext *requestContext,
  2301. int timeoutMs,
  2302. void *callbackData);
  2303. /**
  2304. * This operation lists the parts that have been uploaded for a specific
  2305. * multipart upload.
  2306. *
  2307. * @param bucketContext gives the bucket and associated parameters for this
  2308. * request; this is the bucket for which service access logging is
  2309. * being set
  2310. * @param key is the source key
  2311. * @param partnumbermarker if present and non-empty, specifies the part after
  2312. * which listing should begin. Only parts with higher part numbers
  2313. * will be listed.
  2314. * @param uploadid identifying the multipart upload whose parts are being
  2315. * listed.
  2316. * @param encodingtype if present and non-empty, requests Amazon S3 to encode
  2317. * the response and specifies the encoding method to use.
  2318. * @param maxparts Sets the maximum number of parts to return in the response
  2319. * body. Default: 1,000
  2320. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2321. * request to, and does not perform the request immediately. If NULL,
  2322. * performs the request immediately and synchronously.
  2323. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2324. * @param handler gives the callbacks to call as the request is processed and
  2325. * completed
  2326. * @param callbackData will be passed in as the callbackData parameter to
  2327. * all callbacks for this request
  2328. **/
  2329. void S3_list_parts(S3BucketContext *bucketContext, const char *key,
  2330. const char *partnumbermarker,
  2331. const char *uploadid, const char *encodingtype,
  2332. int maxparts, S3RequestContext *requestContext,
  2333. int timeoutMs,
  2334. const S3ListPartsHandler *handler, void *callbackData);
  2335. /**
  2336. * This operation aborts a multipart upload. After a multipart upload is
  2337. * aborted, no additional parts can be uploaded using that upload ID.
  2338. *
  2339. * @param bucketContext gives the bucket and associated parameters for this
  2340. * request; this is the bucket for which service access logging is
  2341. * being set
  2342. * @param key is the source key
  2343. * @param uploadId identifying the multipart upload whose parts are being
  2344. * listed.
  2345. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2346. * @param handler gives the callbacks to call as the request is processed and
  2347. * completed
  2348. **/
  2349. void S3_abort_multipart_upload(S3BucketContext *bucketContext, const char *key,
  2350. const char *uploadId,
  2351. int timeoutMs,
  2352. S3AbortMultipartUploadHandler *handler,
  2353. S3RequestContext *requestContext, // WINSCP
  2354. void *callbackData); // WINSCP
  2355. /**
  2356. * This operation lists in-progress multipart uploads. An in-progress
  2357. * multipart upload is a multipart upload that has been initiated,
  2358. * using the Initiate Multipart Upload request, but has not yet been
  2359. * completed or aborted.
  2360. *
  2361. * @param bucketContext gives the bucket and associated parameters for this
  2362. * request; this is the bucket for which service access logging is
  2363. * being set
  2364. * @param prefix if present and non-empty, lists in-progress uploads only for
  2365. * those keys that begin with the specified prefix.
  2366. * @param keymarker if present and non-empty, together with upload-id-marker,
  2367. * this parameter specifies the multipart upload after which listing
  2368. * should begin.
  2369. * @param uploadidmarker if present and non-empty, together with key-marker,
  2370. * specifies the multipart upload after which listing should begin.
  2371. * @param encodingtype if present and non-empty, requests Amazon S3 to encode
  2372. * the response and specifies the encoding method to use.
  2373. * @param delimiter if present and non-empty, is the character you use to
  2374. * group keys.
  2375. * @param maxuploads sets the maximum number of multipart uploads,
  2376. * from 1 to 1,000, to return in the response body.
  2377. * @param requestContext if non-NULL, gives the S3RequestContext to add this
  2378. * request to, and does not perform the request immediately. If NULL,
  2379. * performs the request immediately and synchronously.
  2380. * @param timeoutMs if not 0 contains total request timeout in milliseconds
  2381. * @param handler gives the callbacks to call as the request is processed and
  2382. * completed
  2383. * @param callbackData will be passed in as the callbackData parameter to
  2384. * all callbacks for this request
  2385. **/
  2386. void S3_list_multipart_uploads(S3BucketContext *bucketContext,
  2387. const char *prefix, const char *keymarker,
  2388. const char *uploadidmarker,
  2389. const char *encodingtype, const char *delimiter,
  2390. int maxuploads, S3RequestContext *requestContext,
  2391. int timeoutMs,
  2392. const S3ListMultipartUploadsHandler *handler,
  2393. void *callbackData);
  2394. #ifdef WINSCP
  2395. int snprintf_S(char * s, size_t n, const char * format, size_t len, const char * data);
  2396. #endif
  2397. #ifdef __cplusplus
  2398. }
  2399. #endif
  2400. #endif /* LIBS3_H */