libs3.h 116 KB

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