libs3.h 116 KB

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