1 /** **************************************************************************
4 * Copyright 2008 Bryan Ischo <bryan@ischo.com>
6 * This file is part of libs3.
8 * libs3 is free software: you can redistribute it and/or modify it under the
9 * terms of the GNU General Public License as published by the Free Software
10 * Foundation, version 3 of the License.
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.
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
21 * You should have received a copy of the GNU General Public License version 3
22 * along with libs3, in a file named COPYING. If not, see
23 * <http://www.gnu.org/licenses/>.
25 ************************************************************************** **/
31 #include "error_parser.h"
32 #include "response_headers_handler.h"
35 // Describes a type of HTTP request (these are our supported HTTP "verbs")
46 // This completely describes a request. A RequestParams is not required to be
47 // allocated from the heap and its lifetime is not assumed to extend beyond
48 // the lifetime of the function to which it has been passed.
49 typedef struct RequestParams
51 // Request type, affects the HTTP verb used
52 HttpRequestType httpRequestType;
54 // Bucket context for request
55 S3BucketContext bucketContext;
60 // Query params - ready to append to URI (i.e. ?p1=v1?p2=v2)
61 const char *queryParams;
63 // sub resource, like ?acl, ?location, ?torrent, ?logging
64 const char *subResource;
66 // If this is a copy operation, this gives the source bucket
67 const char *copySourceBucketName;
69 // If this is a copy operation, this gives the source key
70 const char *copySourceKey;
73 const S3GetConditions *getConditions;
82 const S3PutProperties *putProperties;
84 // Callback to be made when headers are available. Might not be called.
85 S3ResponsePropertiesCallback *propertiesCallback;
87 // Callback to be made to supply data to send to S3. Might not be called.
88 S3PutObjectDataCallback *toS3Callback;
90 // Number of bytes total that readCallback will supply
91 int64_t toS3CallbackTotalSize;
93 // Callback to be made that supplies data read from S3.
94 // Might not be called.
95 S3GetObjectDataCallback *fromS3Callback;
97 // Callback to be made when request is complete. This will *always* be
99 S3ResponseCompleteCallback *completeCallback;
101 // Data passed to the callbacks
106 // This is the stuff associated with a request that needs to be on the heap
107 // (and thus live while a curl_multi is in use).
108 typedef struct Request
110 // These put the request on a doubly-linked list of requests in a
111 // request context, *if* the request is in a request context (else these
113 struct Request *prev, *next;
115 // The status of this Request, as will be reported to the user via the
119 // The HTTP code returned by the S3 server, if it is known. Would rather
120 // not have to keep track of this but S3 doesn't always indicate its
121 // errors the same way
122 int httpResponseCode;
124 // The HTTP headers to use for the curl request
125 struct curl_slist *headers;
127 // The CURL structure driving the request
130 // libcurl requires that the uri be stored outside of the curl handle
131 char uri[MAX_URI_SIZE + 1];
133 // Callback to be made when headers are available. Might not be called.
134 S3ResponsePropertiesCallback *propertiesCallback;
136 // Callback to be made to supply data to send to S3. Might not be called.
137 S3PutObjectDataCallback *toS3Callback;
139 // Number of bytes total that readCallback has left to supply
140 int64_t toS3CallbackBytesRemaining;
142 // Callback to be made that supplies data read from S3.
143 // Might not be called.
144 S3GetObjectDataCallback *fromS3Callback;
146 // Callback to be made when request is complete. This will *always* be
148 S3ResponseCompleteCallback *completeCallback;
150 // Data passed to the callbacks
153 // Handler of response headers
154 ResponseHeadersHandler responseHeadersHandler;
156 // This is set to nonzero after the properties callback has been made
157 int propertiesCallbackMade;
160 ErrorParser errorParser;
165 // ----------------------------------------------------------------------------
167 // Initialize the API
168 S3Status request_api_initialize(const char *userAgentInfo, int flags);
170 // Deinitialize the API
171 void request_api_deinitialize();
173 // Perform a request; if context is 0, performs the request immediately;
174 // otherwise, sets it up to be performed by context.
175 void request_perform(const RequestParams *params, S3RequestContext *context);
177 // Called by the internal request code or internal request context code when a
178 // curl has finished the request
179 void request_finish(Request *request);
181 // Convert a CURLE code to an S3Status
182 S3Status request_curl_code_to_status(CURLcode code);
185 #endif /* REQUEST_H */