1
0

libs3.h 116 KB

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