request.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /** **************************************************************************
  2. * request.h
  3. *
  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 of the License.
  11. *
  12. * In addition, as a special exception, the copyright holders give
  13. * permission to link the code of this library and its programs with the
  14. * OpenSSL library, and distribute linked combinations including the two.
  15. *
  16. * libs3 is distributed in the hope that it will be useful, but WITHOUT ANY
  17. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * version 3 along with libs3, in a file named COPYING. If not, see
  23. * <http://www.gnu.org/licenses/>.
  24. *
  25. ************************************************************************** **/
  26. #ifndef REQUEST_H
  27. #define REQUEST_H
  28. #include "libs3.h"
  29. #include "error_parser.h"
  30. #include "response_headers_handler.h"
  31. #include "util.h"
  32. // Describes a type of HTTP request (these are our supported HTTP "verbs")
  33. typedef enum
  34. {
  35. HttpRequestTypeGET,
  36. HttpRequestTypeHEAD,
  37. HttpRequestTypePUT,
  38. HttpRequestTypeCOPY,
  39. HttpRequestTypeDELETE,
  40. HttpRequestTypePOST,
  41. HttpRequestTypeInvalid
  42. } HttpRequestType;
  43. // This completely describes a request. A RequestParams is not required to be
  44. // allocated from the heap and its lifetime is not assumed to extend beyond
  45. // the lifetime of the function to which it has been passed.
  46. typedef struct RequestParams
  47. {
  48. // Request type, affects the HTTP verb used
  49. HttpRequestType httpRequestType;
  50. // Bucket context for request
  51. S3BucketContext bucketContext;
  52. // Key, if any
  53. const char *key;
  54. // Query params - ready to append to URI (i.e. ?p1=v1?p2=v2)
  55. const char *queryParams;
  56. // sub resource, like ?acl, ?location, ?torrent, ?logging
  57. const char *subResource;
  58. // If this is a copy operation, this gives the source bucket
  59. const char *copySourceBucketName;
  60. // If this is a copy operation, this gives the source key
  61. const char *copySourceKey;
  62. // Get conditions
  63. const S3GetConditions *getConditions;
  64. // Start byte
  65. size_t startByte;
  66. // Byte count
  67. size_t byteCount;
  68. // Put properties
  69. const S3PutProperties *putProperties;
  70. // Callback to be made when headers are available. Might not be called.
  71. S3ResponsePropertiesCallback *propertiesCallback;
  72. // Callback to be made to supply data to send to S3. Might not be called.
  73. S3PutObjectDataCallback *toS3Callback;
  74. // Number of bytes total that readCallback will supply
  75. int64_t toS3CallbackTotalSize;
  76. // Callback to be made that supplies data read from S3.
  77. // Might not be called.
  78. S3GetObjectDataCallback *fromS3Callback;
  79. // Callback to be made when request is complete. This will *always* be
  80. // called.
  81. S3ResponseCompleteCallback *completeCallback;
  82. // Data passed to the callbacks
  83. void *callbackData;
  84. // Request timeout. If 0, no timeout will be enforced
  85. int timeoutMs;
  86. } RequestParams;
  87. // This is the stuff associated with a request that needs to be on the heap
  88. // (and thus live while a curl_multi is in use).
  89. typedef struct Request
  90. {
  91. #ifdef WINSCP
  92. struct S3RequestContext *requestContext;
  93. #else
  94. // These put the request on a doubly-linked list of requests in a
  95. // request context, *if* the request is in a request context (else these
  96. // will both be 0)
  97. struct Request *prev, *next;
  98. #endif
  99. // The status of this Request, as will be reported to the user via the
  100. // complete callback
  101. S3Status status;
  102. // The HTTP code returned by the S3 server, if it is known. Would rather
  103. // not have to keep track of this but S3 doesn't always indicate its
  104. // errors the same way
  105. int httpResponseCode;
  106. ne_session *NeonSession; // WINSCP (neon)
  107. ne_request *NeonRequest;
  108. // libcurl requires that the uri be stored outside of the curl handle
  109. char uri[MAX_URI_SIZE + 1];
  110. // Callback to be made when headers are available. Might not be called.
  111. S3ResponsePropertiesCallback *propertiesCallback;
  112. // Callback to be made to supply data to send to S3. Might not be called.
  113. S3PutObjectDataCallback *toS3Callback;
  114. // Number of bytes total that readCallback has left to supply
  115. int64_t toS3CallbackBytesRemaining;
  116. // Callback to be made that supplies data read from S3.
  117. // Might not be called.
  118. S3GetObjectDataCallback *fromS3Callback;
  119. // Callback to be made when request is complete. This will *always* be
  120. // called.
  121. S3ResponseCompleteCallback *completeCallback;
  122. // Data passed to the callbacks
  123. void *callbackData;
  124. // Handler of response headers
  125. ResponseHeadersHandler responseHeadersHandler;
  126. // This is set to nonzero after the properties callback has been made
  127. int propertiesCallbackMade;
  128. // Parser of errors
  129. ErrorParser errorParser;
  130. string_buffer(statusMessage, 1024); // WINSCP
  131. } Request;
  132. // Request functions
  133. // ----------------------------------------------------------------------------
  134. // Initialize the API
  135. S3Status request_api_initialize(const char *userAgentInfo, int flags,
  136. const char *hostName);
  137. // Deinitialize the API
  138. void request_api_deinitialize();
  139. // Perform a request; if context is 0, performs the request immediately;
  140. // otherwise, sets it up to be performed by context.
  141. void request_perform(const RequestParams *params, S3RequestContext *context);
  142. // Called by the internal request code or internal request context code when a
  143. // curl has finished the request
  144. void request_finish(Request *request);
  145. S3Status request_neon_code_to_status(NeonCode code); // WINSCP (neon)
  146. #endif /* REQUEST_H */