libs3.h 111 KB

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