request.h 6.3 KB

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