diff options
author | Bryan Ischo <bryan@ischo.com> | 2008-07-12 12:08:34 +0000 |
---|---|---|
committer | Bryan Ischo <bryan@ischo.com> | 2008-07-12 12:08:34 +0000 |
commit | 26a9aad80885a9e8f65c6c37ca562fc7c6d5d4d3 (patch) | |
tree | 4a39519b24ad6b202ff447d46fa022b76640a7e4 /inc | |
parent | 037783a33a3c2f02307511bdadd4c85486217a40 (diff) | |
download | ceph-libs3-26a9aad80885a9e8f65c6c37ca562fc7c6d5d4d3.tar.gz |
* Work in progress: put object now works
Diffstat (limited to 'inc')
-rw-r--r-- | inc/libs3.h | 52 | ||||
-rw-r--r-- | inc/request.h | 59 | ||||
-rw-r--r-- | inc/response_headers_handler.h | 2 | ||||
-rw-r--r-- | inc/util.h | 16 |
4 files changed, 59 insertions, 70 deletions
diff --git a/inc/libs3.h b/inc/libs3.h index 495fe0e..30eb07b 100644 --- a/inc/libs3.h +++ b/inc/libs3.h @@ -55,16 +55,43 @@ ************************************************************************** **/ /** + * This is the hostname that all S3 requests will go through; virtual-host + * style requests will prepend the bucket name to this host name, and + * path-style requests will use this hostname directly + **/ +#define S3_HOSTNAME "s3.amazonaws.com" + + +/** * S3_MAX_KEY_SIZE is the maximum size of keys that Amazon S3 supports. **/ #define S3_MAX_KEY_SIZE 1024 + /** * S3_MAX_META_HEADERS_SIZE is the maximum number of bytes allowed for * x-amz-meta header names and values in any request passed to Amazon S3 **/ #define S3_MAX_META_HEADER_SIZE 2048 + +/** + * S3_META_HEADER_NAME_PREFIX is the prefix of an S3 "meta header" + **/ +#define S3_META_HEADER_NAME_PREFIX "x-amz-meta-" + + +/** + * S3_MAX_META_HEADER_COUNT is the maximum number of x-amz-meta- headers that + * could be included in a request to S3. The smallest meta header is + * "x-amz-meta-n: v". Since S3 doesn't count the ": " against the total, the + * smallest amount of data to count for a header would be the length of + * "x-amz-meta-nv". + **/ +#define S3_MAX_META_HEADER_COUNT \ + (S3_MAX_META_HEADER_SIZE / (sizeof(S3_META_HEADER_NAME_PREFIX "nv") - 1)) + + /** * S3_ACL_GRANT_MAXCOUNT is the maximum number of ACL grants that may be * set on a bucket or object at one time. It is also the maximum number of @@ -516,11 +543,11 @@ typedef struct S3RequestHeaders **/ const char *contentEncoding; /** - * If present, this gives an expiration date for the content. This + * If >= 0, this gives an expiration date for the content. This * information is typically only delivered to users who download the * content via a web browser. **/ - const time_t *expires; + time_t expires; /** * This identifies the "canned ACL" that should be used for this object. * The default (0) gives only the owner of the object access to it. @@ -545,13 +572,9 @@ typedef struct S3RequestHeaders **/ int metaHeadersCount; /** - * Each zero-terminated string here is a single metadata header to be - * applied to the object. Each of these must be of the form - * x-amz-meta-${METANAME}:${VALUE}, where the ${METANAME} and ${VALUE} are - * entirely up to the application. + * These are the meta headers to pass to S3. **/ - // xxx todo - convert to an array of S3MetaHeader structures - const char **metaHeaders; + const S3NameValue *metaHeaders; } S3RequestHeaders; @@ -673,9 +696,8 @@ typedef S3Status (S3ListBucketCallback)(int isTruncated, * service as the contents of the object being put * @return S3Status??? **/ -typedef S3Status (S3PutObjectCallback)(int *bufferSizeReturn, - const char **bufferReturn, - void *callbackData); +typedef int (S3PutObjectDataCallback)(int bufferSize, char *buffer, + void *callbackData); /** @@ -691,8 +713,8 @@ typedef S3Status (S3PutObjectCallback)(int *bufferSizeReturn, * @param bufferSize gives the number of bytes in buffer * @param buffer is the data being passed into the callback **/ -typedef S3Status (S3GetObjectCallback)(int bufferSize, const char *buffer, - void *callbackData); +typedef S3Status (S3GetObjectDataCallback)(int bufferSize, const char *buffer, + void *callbackData); /** ************************************************************************** @@ -861,7 +883,7 @@ typedef struct S3PutObjectHandler { S3ResponseHandler responseHandler; - S3PutObjectCallback *putObjectCallback; + S3PutObjectDataCallback *putObjectDataCallback; } S3PutObjectHandler; @@ -869,7 +891,7 @@ typedef struct S3GetObjectHandler { S3ResponseHandler responseHandler; - S3GetObjectCallback *getObjectCallback; + S3GetObjectDataCallback *getObjectDataCallback; } S3GetObjectHandler; diff --git a/inc/request.h b/inc/request.h index e63f162..a5ed101 100644 --- a/inc/request.h +++ b/inc/request.h @@ -30,32 +30,6 @@ #include "response_headers_handler.h" #include "util.h" -/** - * Any return value other than S3StatusOK will stop the request processing - * immediately - **/ -typedef S3Status (RequestHeadersCallback) - (const S3ResponseHeaders *responseHeaders, void *callbackData); - -/** - * As a 'read' function: - * - Fill [buffer] with up to [bufferSize] bytes, return the number of - * bytes actually filled; returning 0 means EOF. - * - * As a 'write' function: - * - [bufferSize] bytes are supplied in [buffer]. Return anything other - * than [bufferSize] to stop the request processing immediately - **/ -typedef int (RequestDataCallback) - (char *buffer, int bufferSize, void *callbackData); - -/** - **/ -typedef void (RequestCompleteCallback) - (S3Status requestStatus, int httpResponseCode, - const S3ErrorDetails *s3ErrorDetails, void *callbackData); - - // Describes a type of HTTP request (these are our supported HTTP "verbs") typedef enum { @@ -102,21 +76,22 @@ typedef struct RequestParams // Request headers const S3RequestHeaders *requestHeaders; - // Callback to be made when headers are available. May not be called. - RequestHeadersCallback *headersCallback; + // Callback to be made when headers are available. Might not be called. + S3ResponseHeadersCallback *headersCallback; - // Callback to be made to supply data to send to S3. May not be called. - RequestDataCallback *toS3Callback; + // Callback to be made to supply data to send to S3. Might not be called. + S3PutObjectDataCallback *toS3Callback; // Number of bytes total that readCallback will supply int64_t toS3CallbackTotalSize; - // Callback to be made that supplies data read from S3. May not be called. - RequestDataCallback *fromS3Callback; + // Callback to be made that supplies data read from S3. + // Might not be called. + S3GetObjectDataCallback *fromS3Callback; // Callback to be made when request is complete. This will *always* be // called. - RequestCompleteCallback *completeCallback; + S3ResponseCompleteCallback *completeCallback; // Data passed to the callbacks void *callbackData; @@ -143,18 +118,22 @@ typedef struct Request // The HTTP response code that S3 sent back for this request int httpResponseCode; - // Callback to be made when headers are available. May not be called. - RequestHeadersCallback *headersCallback; + // Callback to be made when headers are available. Might not be called. + S3ResponseHeadersCallback *headersCallback; + + // Callback to be made to supply data to send to S3. Might not be called. + S3PutObjectDataCallback *toS3Callback; - // Callback to be made to supply data to send to S3. May not be called. - RequestDataCallback *toS3Callback; + // Number of bytes total that readCallback will supply + int64_t toS3CallbackTotalSize; - // Callback to be made that supplies data read from S3. May not be called. - RequestDataCallback *fromS3Callback; + // Callback to be made that supplies data read from S3. + // Might not be called. + S3GetObjectDataCallback *fromS3Callback; // Callback to be made when request is complete. This will *always* be // called. - RequestCompleteCallback *completeCallback; + S3ResponseCompleteCallback *completeCallback; // Data passed to the callbacks void *callbackData; diff --git a/inc/response_headers_handler.h b/inc/response_headers_handler.h index 817a1fc..917fa32 100644 --- a/inc/response_headers_handler.h +++ b/inc/response_headers_handler.h @@ -47,7 +47,7 @@ typedef struct ResponseHeadersHandler COMPACTED_META_HEADER_BUFFER_SIZE); // Response meta headers - S3NameValue responseMetaHeaders[MAX_META_HEADER_COUNT]; + S3NameValue responseMetaHeaders[S3_MAX_META_HEADER_COUNT]; } ResponseHeadersHandler; @@ -30,24 +30,12 @@ #include "libs3.h" -// As specified in S3 documntation -#define META_HEADER_NAME_PREFIX "x-amz-meta-" -#define HOSTNAME "s3.amazonaws.com" - - // Derived from S3 documentation -// This is the maximum number of x-amz-meta- headers that could be included in -// a request to S3. The smallest meta header is" x-amz-meta-n: v". Since S3 -// doesn't count the ": " against the total, the smallest amount of data to -// count for a header would be the length of "x-amz-meta-nv". -#define MAX_META_HEADER_COUNT \ - (S3_MAX_META_HEADER_SIZE / (sizeof(META_HEADER_NAME_PREFIX "nv") - 1)) - // This is the maximum number of bytes needed in a "compacted meta header" // buffer, which is a buffer storing all of the compacted meta headers. #define COMPACTED_META_HEADER_BUFFER_SIZE \ - (MAX_META_HEADER_COUNT * sizeof(META_HEADER_NAME_PREFIX "n: v")) + (S3_MAX_META_HEADER_COUNT * sizeof(S3_META_HEADER_NAME_PREFIX "n: v")) // Maximum url encoded key size; since every single character could require // URL encoding, it's 3 times the size of a key (since each url encoded @@ -58,7 +46,7 @@ // https://s3.amazonaws.com/${BUCKET}/${KEY}?acl // 255 is the maximum bucket length #define MAX_URI_SIZE \ - ((sizeof("https://" HOSTNAME "/") - 1) + 255 + 1 + \ + ((sizeof("https://" S3_HOSTNAME "/") - 1) + 255 + 1 + \ MAX_URLENCODED_KEY_SIZE + (sizeof("?torrent" - 1)) + 1) // Maximum size of a canonicalized resource |