diff options
author | Bryan Ischo <bryan@ischo.com> | 2008-06-27 05:01:07 +0000 |
---|---|---|
committer | Bryan Ischo <bryan@ischo.com> | 2008-06-27 05:01:07 +0000 |
commit | 096ceede486da2b1ce298148f29153cc242f1b80 (patch) | |
tree | 5321ce5d912263ea8c9f174859d8ba9771048338 /src/general.c | |
parent | 3237ccc393b8f7bcd36d04aecc31f7c3829f387b (diff) | |
download | ceph-libs3-096ceede486da2b1ce298148f29153cc242f1b80.tar.gz |
* Work in progress, about to rework some
Diffstat (limited to 'src/general.c')
-rw-r--r-- | src/general.c | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/src/general.c b/src/general.c index 762d68b..aa6d692 100644 --- a/src/general.c +++ b/src/general.c @@ -99,16 +99,18 @@ void mutex_destroy(struct S3Mutex *mutex) return (*mutexDestroyCallbackG)(mutex); } -PrivateData *create_private_data(S3RequestHandler *handler, +PrivateData *create_private_data(CURL *curl, + S3RequestHandler *handler, S3ListServiceCallback *listServiceCallback, S3ListBucketCallback *listBucketCallback, S3PutObjectCallback *putObjectCallback, S3GetObjectCallback *getObjectCallback, void *data) { - PrivateData *ret = (PrivateData *) malloc(sizeof(PrivateData)); + PrivateData *ret = (PrivateData *) calloc(sizeof(PrivateData)); if (ret) { + ret->curl = curl; ret->headersCallback = handler->headersCallback; ret->errorCallback = handler->errorCallback; ret->completeCallback = handler->completeCallback; @@ -150,6 +152,63 @@ S3Status handle_easy_request(CurlRequest *request) } } +size_t curl_header_func(void *ptr, size_t size, size_t nmemb, void *fstream) +{ + PrivateData *pd = (PrivateData *) fstream; + S3ResponseHeadersPrivate *responseHeaders = &(pd->responseHeaders); + + // Curl might call back the header function after the body has been + // received, for 'chunked encoded' contents. We don't handle this as of + // yet, and it's not clear that it would ever be useful. + if (pd->headersCallbackMade) { + return; + } + + // If we haven't gotten the result code yet, attempt to get it now. It + // should be available as soon as the first header is available. + if (!responseHeaders->resultCodeSet) { + responseHeaders->resultCodeSet = 1; + if (curl_easy_getinfo(pd->curl, CURLINFO_RESPONSE_CODE, + &(responseHeaders->resultCode)) != CURLE_OK) { + // Weird, couldn't get the status. Set it to 0 + responseHeaders->resultCode = 0; + } + } + + // The header must end in \r\n, so we can set the \r to 0 to terminate it + size_t len = size * nmemb; + char *header = (char *) ptr; + header[len - 2] = 0; + + // Find the colon to split the header up + char *colon = header; + while (*colon && (*colon != ':')) { + colon++; + } + + int namelen = colon - header; + + if (!strncmp(header, "RequestId", namelen)) { + } + else if (!strncmp(header, "RequestId2", namelen)) { + } + else if (!strncmp(header, "ContentType", namelen)) { + } + else if (!strncmp(header, "ContentLength", namelen)) { + } + else if (!strncmp(header, "Server", namelen)) { + } + else if (!strncmp(header, "ETag", namelen)) { + } + else if (!strncmp(header, "LastModified", namelen)) { + } + else if (!strncmp(header, "x-amz-meta-", + (namelen > strlen("x-amz-meta-") ? + strlen("x-amz-meta-") : namelen))) { + + } +} + S3Status S3_initialize(const char *userAgentInfo, S3ThreadSelfCallback *threadSelfCallback, S3MutexCreateCallback *mutexCreateCallback, |