libs3.h 116 KB

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