1
0

libs3.h 114 KB

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