libs3.h 116 KB

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