diff options
author | Bryan Ischo <bryan@ischo.com> | 2008-10-08 11:26:47 +0000 |
---|---|---|
committer | Bryan Ischo <bryan@ischo.com> | 2008-10-08 11:26:47 +0000 |
commit | 3ed71a2e4f658bec7f0c886909bc3475778b7741 (patch) | |
tree | 68a3894dd3f13d4ff86c6e9ce685ee7c6abad042 /src | |
parent | 8cc18cbb67d459076d6d3df08b02c531d5ccc08f (diff) | |
download | ceph-libs3-3ed71a2e4f658bec7f0c886909bc3475778b7741.tar.gz |
* Added -Wextra and -Wshadow compiler options, to enforce extra warnings, and
fixed the code necessary to comply with these flags
* Fixed a bug introduced in the 1.0 release, that caused last modified time
not to be reported to callbacks
* Changed the semantics of the put data callback, to only make the callback
enough times to get enough data to satisfy the content length
* Fixed the error status when curl doesn't get a valid HTTP response from
S3 to be S3StatusConnectionFailed instead of S3StatusHttpErrorUnknown
* Fixed a bug where S3_runall_request_context would stop even though a
callback had added another request
* libs3.h doesn't need sys/time.h anymore, it just needs sys/select.h
* Some minor documentation enhancements
Diffstat (limited to 'src')
-rw-r--r-- | src/bucket.c | 2 | ||||
-rw-r--r-- | src/request.c | 51 | ||||
-rw-r--r-- | src/request_context.c | 3 | ||||
-rw-r--r-- | src/response_headers_handler.c | 6 | ||||
-rw-r--r-- | src/s3.c | 153 | ||||
-rw-r--r-- | src/simplexml.c | 10 | ||||
-rw-r--r-- | src/testsimplexml.c | 2 |
7 files changed, 133 insertions, 94 deletions
diff --git a/src/bucket.c b/src/bucket.c index a2446df..ccedd0b 100644 --- a/src/bucket.c +++ b/src/bucket.c @@ -532,7 +532,7 @@ static S3Status listBucketXmlCallback(const char *elementPath, lbData->commonPrefixLens[which] - 1, "%.*s", dataLen, data); if (lbData->commonPrefixLens[which] >= - sizeof(lbData->commonPrefixes[which])) { + (int) sizeof(lbData->commonPrefixes[which])) { return S3StatusXmlParseFailure; } } diff --git a/src/request.c b/src/request.c index 79837fa..33eac35 100644 --- a/src/request.c +++ b/src/request.c @@ -172,19 +172,31 @@ static size_t curl_read_func(void *ptr, size_t size, size_t nmemb, void *data) return CURL_READFUNC_ABORT; } - if (request->toS3Callback) { - int ret = (*(request->toS3Callback)) - (len, (char *) ptr, request->callbackData); - if (ret < 0) { - request->status = S3StatusAbortedByCallback; - return CURL_READFUNC_ABORT; - } - else { - return ret; - } + // If there is no data callback, or the data callback has already returned + // contentLength bytes, return 0; + if (!request->toS3Callback || !request->toS3CallbackBytesRemaining) { + return 0; + } + + // Don't tell the callback that we are willing to accept more data than we + // really are + if (len > request->toS3CallbackBytesRemaining) { + len = request->toS3CallbackBytesRemaining; + } + + // Otherwise, make the data callback + int ret = (*(request->toS3Callback)) + (len, (char *) ptr, request->callbackData); + if (ret < 0) { + request->status = S3StatusAbortedByCallback; + return CURL_READFUNC_ABORT; } else { - return 0; + if (ret > request->toS3CallbackBytesRemaining) { + ret = request->toS3CallbackBytesRemaining; + } + request->toS3CallbackBytesRemaining -= ret; + return ret; } } @@ -253,7 +265,7 @@ static S3Status compose_amz_headers(const RequestParams *params, len += snprintf(&(values->amzHeadersRaw[len]), \ sizeof(values->amzHeadersRaw) - len, \ format, __VA_ARGS__); \ - if (len >= sizeof(values->amzHeadersRaw)) { \ + if (len >= (int) sizeof(values->amzHeadersRaw)) { \ return S3StatusMetaDataHeadersTooLong; \ } \ while ((len > 0) && (values->amzHeadersRaw[len - 1] == ' ')) { \ @@ -266,7 +278,7 @@ static S3Status compose_amz_headers(const RequestParams *params, do { \ values->amzHeaders[values->amzHeadersCount++] = \ &(values->amzHeadersRaw[len]); \ - if ((len + l) >= sizeof(values->amzHeadersRaw)) { \ + if ((len + l) >= (int) sizeof(values->amzHeadersRaw)) { \ return S3StatusMetaDataHeadersTooLong; \ } \ int todo = l; \ @@ -362,7 +374,7 @@ static S3Status compose_standard_headers(const RequestParams *params, /* Compose header, make sure it all fit */ \ int len = snprintf(values-> destField, \ sizeof(values-> destField), fmt, val); \ - if (len >= sizeof(values-> destField)) { \ + if (len >= (int) sizeof(values-> destField)) { \ return tooLongError; \ } \ /* Now remove the whitespace at the end */ \ @@ -392,7 +404,7 @@ static S3Status compose_standard_headers(const RequestParams *params, /* Compose header, make sure it all fit */ \ int len = snprintf(values-> destField, \ sizeof(values-> destField), fmt, val); \ - if (len >= sizeof(values-> destField)) { \ + if (len >= (int) sizeof(values-> destField)) { \ return tooLongError; \ } \ /* Now remove the whitespace at the end */ \ @@ -732,7 +744,7 @@ static S3Status compose_uri(Request *request, const RequestParams *params, len += snprintf(&(request->uri[len]), \ sizeof(request->uri) - len, \ fmt, __VA_ARGS__); \ - if (len >= sizeof(request->uri)) { \ + if (len >= (int) sizeof(request->uri)) { \ return S3StatusUriTooLong; \ } \ } while (0) @@ -990,6 +1002,8 @@ static S3Status request_get(const RequestParams *params, request->toS3Callback = params->toS3Callback; + request->toS3CallbackBytesRemaining = params->toS3CallbackTotalSize; + request->fromS3Callback = params->fromS3Callback; request->completeCallback = params->completeCallback; @@ -1186,6 +1200,11 @@ void request_finish(Request *request) ((request->httpResponseCode < 200) || (request->httpResponseCode > 299))) { switch (request->httpResponseCode) { + case 0: + // This happens if the request never got any HTTP response + // headers at all, we call this a ConnectionFailed error + request->status = S3StatusConnectionFailed; + break; case 100: // Some versions of libcurl erroneously set HTTP // status to this break; diff --git a/src/request_context.c b/src/request_context.c index d049778..bc6af99 100644 --- a/src/request_context.c +++ b/src/request_context.c @@ -160,6 +160,9 @@ S3Status S3_runonce_request_context(S3RequestContext *requestContext, // Finish the request, ensuring that all callbacks have been made, // and also releases the request request_finish(request); + // Now, since a callback was made, there may be new requests + // queued up to be performed immediately, so do so + status = CURLM_CALL_MULTI_PERFORM; } } while (status == CURLM_CALL_MULTI_PERFORM); diff --git a/src/response_headers_handler.c b/src/response_headers_handler.c index cbaa4bf..14e14a0 100644 --- a/src/response_headers_handler.c +++ b/src/response_headers_handler.c @@ -195,10 +195,10 @@ void response_headers_handler_done(ResponseHeadersHandler *handler, CURL *curl) { // Now get the last modification time from curl, since it's easiest to let // curl parse it + time_t lastModified; if (curl_easy_getinfo - (curl, CURLINFO_FILETIME, - &(handler->responseProperties.lastModified)) != CURLE_OK) { - handler->responseProperties.lastModified = -1; + (curl, CURLINFO_FILETIME, &lastModified) == CURLE_OK) { + handler->responseProperties.lastModified = lastModified; } handler->done = 1; @@ -546,7 +546,7 @@ static int convert_simple_acl(char *aclXml, char *ownerId, } while (0) #define COPY_STRING(field) \ - COPY_STRING_MAXLEN(field, (sizeof(field) - 1)) + COPY_STRING_MAXLEN(field, (int) (sizeof(field) - 1)) while (1) { SKIP_SPACE(0); @@ -674,6 +674,8 @@ static struct option longOptionsG[] = static S3Status responsePropertiesCallback (const S3ResponseProperties *properties, void *callbackData) { + (void) callbackData; + if (!showResponsePropertiesG) { return S3StatusOK; } @@ -719,6 +721,8 @@ static void responseCompleteCallback(S3Status status, const S3ErrorDetails *error, void *callbackData) { + (void) callbackData; + statusG = status; // Compose the error details message now, although we might not use it. // Can't just save a pointer to [error] since it's not guaranteed to last @@ -846,18 +850,18 @@ static void list_service(int allDetails) // test bucket --------------------------------------------------------------- -static void test_bucket(int argc, char **argv, int optind) +static void test_bucket(int argc, char **argv, int optindex) { // test bucket - if (optind == argc) { + if (optindex == argc) { fprintf(stderr, "\nERROR: Missing parameter: bucket\n"); usageExit(stderr); } - const char *bucketName = argv[optind++]; + const char *bucketName = argv[optindex++]; - if (optind != argc) { - fprintf(stderr, "\nERROR: Extraneous parameter: %s\n", argv[optind]); + if (optindex != argc) { + fprintf(stderr, "\nERROR: Extraneous parameter: %s\n", argv[optindex]); usageExit(stderr); } @@ -910,14 +914,14 @@ static void test_bucket(int argc, char **argv, int optind) // create bucket ------------------------------------------------------------- -static void create_bucket(int argc, char **argv, int optind) +static void create_bucket(int argc, char **argv, int optindex) { - if (optind == argc) { + if (optindex == argc) { fprintf(stderr, "\nERROR: Missing parameter: bucket\n"); usageExit(stderr); } - const char *bucketName = argv[optind++]; + const char *bucketName = argv[optindex++]; if (!forceG && (S3_validate_bucket_name (bucketName, S3UriStyleVirtualHost) != S3StatusOK)) { @@ -931,8 +935,8 @@ static void create_bucket(int argc, char **argv, int optind) const char *locationConstraint = 0; S3CannedAcl cannedAcl = S3CannedAclPrivate; - while (optind < argc) { - char *param = argv[optind++]; + while (optindex < argc) { + char *param = argv[optindex++]; if (!strncmp(param, LOCATION_PREFIX, LOCATION_PREFIX_LEN)) { locationConstraint = &(param[LOCATION_PREFIX_LEN]); } @@ -987,17 +991,17 @@ static void create_bucket(int argc, char **argv, int optind) // delete bucket ------------------------------------------------------------- -static void delete_bucket(int argc, char **argv, int optind) +static void delete_bucket(int argc, char **argv, int optindex) { - if (optind == argc) { + if (optindex == argc) { fprintf(stderr, "\nERROR: Missing parameter: bucket\n"); usageExit(stderr); } - const char *bucketName = argv[optind++]; + const char *bucketName = argv[optindex++]; - if (optind != argc) { - fprintf(stderr, "\nERROR: Extraneous parameter: %s\n", argv[optind]); + if (optindex != argc) { + fprintf(stderr, "\nERROR: Extraneous parameter: %s\n", argv[optindex]); usageExit(stderr); } @@ -1205,9 +1209,9 @@ static void list_bucket(const char *bucketName, const char *prefix, } -static void list(int argc, char **argv, int optind) +static void list(int argc, char **argv, int optindex) { - if (optind == argc) { + if (optindex == argc) { list_service(0); return; } @@ -1216,8 +1220,8 @@ static void list(int argc, char **argv, int optind) const char *prefix = 0, *marker = 0, *delimiter = 0; int maxkeys = 0, allDetails = 0; - while (optind < argc) { - char *param = argv[optind++]; + while (optindex < argc) { + char *param = argv[optindex++]; if (!strncmp(param, PREFIX_PREFIX, PREFIX_PREFIX_LEN)) { prefix = &(param[PREFIX_PREFIX_LEN]); } @@ -1261,10 +1265,12 @@ static void list(int argc, char **argv, int optind) // delete object ------------------------------------------------------------- -static void delete_object(int argc, char **argv, int optind) +static void delete_object(int argc, char **argv, int optindex) { + (void) argc; + // Split bucket/key - char *slash = argv[optind]; + char *slash = argv[optindex]; // We know there is a slash in there, put_object is only called if so while (*slash && (*slash != '/')) { @@ -1272,7 +1278,7 @@ static void delete_object(int argc, char **argv, int optind) } *slash++ = 0; - const char *bucketName = argv[optind++]; + const char *bucketName = argv[optindex++]; const char *key = slash; S3_init(); @@ -1325,8 +1331,8 @@ static int putObjectDataCallback(int bufferSize, char *buffer, int ret = 0; if (data->contentLength) { - int toRead = ((data->contentLength > bufferSize) ? - bufferSize : data->contentLength); + int toRead = ((data->contentLength > (unsigned) bufferSize) ? + (unsigned) bufferSize : data->contentLength); if (data->gb) { growbuffer_read(&(data->gb), toRead, &ret, buffer); } @@ -1352,26 +1358,26 @@ static int putObjectDataCallback(int bufferSize, char *buffer, } -static void put_object(int argc, char **argv, int optind) +static void put_object(int argc, char **argv, int optindex) { - if (optind == argc) { + if (optindex == argc) { fprintf(stderr, "\nERROR: Missing parameter: bucket/key\n"); usageExit(stderr); } // Split bucket/key - char *slash = argv[optind]; + char *slash = argv[optindex]; while (*slash && (*slash != '/')) { slash++; } if (!*slash || !*(slash + 1)) { fprintf(stderr, "\nERROR: Invalid bucket/key name: %s\n", - argv[optind]); + argv[optindex]); usageExit(stderr); } *slash++ = 0; - const char *bucketName = argv[optind++]; + const char *bucketName = argv[optindex++]; const char *key = slash; const char *filename = 0; @@ -1384,8 +1390,8 @@ static void put_object(int argc, char **argv, int optind) S3NameValue metaProperties[S3_MAX_METADATA_COUNT]; int noStatus = 0; - while (optind < argc) { - char *param = argv[optind++]; + while (optindex < argc) { + char *param = argv[optindex++]; if (!strncmp(param, FILENAME_PREFIX, FILENAME_PREFIX_LEN)) { filename = &(param[FILENAME_PREFIX_LEN]); } @@ -1523,7 +1529,7 @@ static void put_object(int argc, char **argv, int optind) exit(-1); } contentLength += amtRead; - if (amtRead < sizeof(buffer)) { + if (amtRead < (int) sizeof(buffer)) { break; } } @@ -1591,47 +1597,47 @@ static void put_object(int argc, char **argv, int optind) // copy object --------------------------------------------------------------- -static void copy_object(int argc, char **argv, int optind) +static void copy_object(int argc, char **argv, int optindex) { - if (optind == argc) { + if (optindex == argc) { fprintf(stderr, "\nERROR: Missing parameter: source bucket/key\n"); usageExit(stderr); } // Split bucket/key - char *slash = argv[optind]; + char *slash = argv[optindex]; while (*slash && (*slash != '/')) { slash++; } if (!*slash || !*(slash + 1)) { fprintf(stderr, "\nERROR: Invalid source bucket/key name: %s\n", - argv[optind]); + argv[optindex]); usageExit(stderr); } *slash++ = 0; - const char *sourceBucketName = argv[optind++]; + const char *sourceBucketName = argv[optindex++]; const char *sourceKey = slash; - if (optind == argc) { + if (optindex == argc) { fprintf(stderr, "\nERROR: Missing parameter: " "destination bucket/key\n"); usageExit(stderr); } // Split bucket/key - slash = argv[optind]; + slash = argv[optindex]; while (*slash && (*slash != '/')) { slash++; } if (!*slash || !*(slash + 1)) { fprintf(stderr, "\nERROR: Invalid destination bucket/key name: %s\n", - argv[optind]); + argv[optindex]); usageExit(stderr); } *slash++ = 0; - const char *destinationBucketName = argv[optind++]; + const char *destinationBucketName = argv[optindex++]; const char *destinationKey = slash; const char *cacheControl = 0, *contentType = 0; @@ -1642,8 +1648,8 @@ static void copy_object(int argc, char **argv, int optind) S3NameValue metaProperties[S3_MAX_METADATA_COUNT]; int anyPropertiesSet = 0; - while (optind < argc) { - char *param = argv[optind++]; + while (optindex < argc) { + char *param = argv[optindex++]; if (!strncmp(param, CACHE_CONTROL_PREFIX, CACHE_CONTROL_PREFIX_LEN)) { cacheControl = &(param[CACHE_CONTROL_PREFIX_LEN]); @@ -1790,30 +1796,31 @@ static S3Status getObjectDataCallback(int bufferSize, const char *buffer, size_t wrote = fwrite(buffer, 1, bufferSize, outfile); - return (wrote < bufferSize) ? S3StatusAbortedByCallback : S3StatusOK; + return ((wrote < (size_t) bufferSize) ? + S3StatusAbortedByCallback : S3StatusOK); } -static void get_object(int argc, char **argv, int optind) +static void get_object(int argc, char **argv, int optindex) { - if (optind == argc) { + if (optindex == argc) { fprintf(stderr, "\nERROR: Missing parameter: bucket/key\n"); usageExit(stderr); } // Split bucket/key - char *slash = argv[optind]; + char *slash = argv[optindex]; while (*slash && (*slash != '/')) { slash++; } if (!*slash || !*(slash + 1)) { fprintf(stderr, "\nERROR: Invalid bucket/key name: %s\n", - argv[optind]); + argv[optindex]); usageExit(stderr); } *slash++ = 0; - const char *bucketName = argv[optind++]; + const char *bucketName = argv[optindex++]; const char *key = slash; const char *filename = 0; @@ -1821,8 +1828,8 @@ static void get_object(int argc, char **argv, int optind) const char *ifMatch = 0, *ifNotMatch = 0; uint64_t startByte = 0, byteCount = 0; - while (optind < argc) { - char *param = argv[optind++]; + while (optindex < argc) { + char *param = argv[optindex++]; if (!strncmp(param, FILENAME_PREFIX, FILENAME_PREFIX_LEN)) { filename = &(param[FILENAME_PREFIX_LEN]); } @@ -1946,9 +1953,9 @@ static void get_object(int argc, char **argv, int optind) // head object --------------------------------------------------------------- -static void head_object(int argc, char **argv, int optind) +static void head_object(int argc, char **argv, int optindex) { - if (optind == argc) { + if (optindex == argc) { fprintf(stderr, "\nERROR: Missing parameter: bucket/key\n"); usageExit(stderr); } @@ -1957,23 +1964,23 @@ static void head_object(int argc, char **argv, int optind) showResponsePropertiesG = 1; // Split bucket/key - char *slash = argv[optind]; + char *slash = argv[optindex]; while (*slash && (*slash != '/')) { slash++; } if (!*slash || !*(slash + 1)) { fprintf(stderr, "\nERROR: Invalid bucket/key name: %s\n", - argv[optind]); + argv[optindex]); usageExit(stderr); } *slash++ = 0; - const char *bucketName = argv[optind++]; + const char *bucketName = argv[optindex++]; const char *key = slash; - if (optind != argc) { - fprintf(stderr, "\nERROR: Extraneous parameter: %s\n", argv[optind]); + if (optindex != argc) { + fprintf(stderr, "\nERROR: Extraneous parameter: %s\n", argv[optindex]); usageExit(stderr); } @@ -2009,18 +2016,18 @@ static void head_object(int argc, char **argv, int optind) // get acl ------------------------------------------------------------------- -void get_acl(int argc, char **argv, int optind) +void get_acl(int argc, char **argv, int optindex) { - if (optind == argc) { + if (optindex == argc) { fprintf(stderr, "\nERROR: Missing parameter: bucket[/key]\n"); usageExit(stderr); } - const char *bucketName = argv[optind]; + const char *bucketName = argv[optindex]; const char *key = 0; // Split bucket/key - char *slash = argv[optind++]; + char *slash = argv[optindex++]; while (*slash && (*slash != '/')) { slash++; } @@ -2034,8 +2041,8 @@ void get_acl(int argc, char **argv, int optind) const char *filename = 0; - while (optind < argc) { - char *param = argv[optind++]; + while (optindex < argc) { + char *param = argv[optindex++]; if (!strncmp(param, FILENAME_PREFIX, FILENAME_PREFIX_LEN)) { filename = &(param[FILENAME_PREFIX_LEN]); } @@ -2172,18 +2179,18 @@ void get_acl(int argc, char **argv, int optind) // set acl ------------------------------------------------------------------- -void set_acl(int argc, char **argv, int optind) +void set_acl(int argc, char **argv, int optindex) { - if (optind == argc) { + if (optindex == argc) { fprintf(stderr, "\nERROR: Missing parameter: bucket[/key]\n"); usageExit(stderr); } - const char *bucketName = argv[optind]; + const char *bucketName = argv[optindex]; const char *key = 0; // Split bucket/key - char *slash = argv[optind++]; + char *slash = argv[optindex++]; while (*slash && (*slash != '/')) { slash++; } @@ -2197,8 +2204,8 @@ void set_acl(int argc, char **argv, int optind) const char *filename = 0; - while (optind < argc) { - char *param = argv[optind++]; + while (optindex < argc) { + char *param = argv[optindex++]; if (!strncmp(param, FILENAME_PREFIX, FILENAME_PREFIX_LEN)) { filename = &(param[FILENAME_PREFIX_LEN]); } @@ -2276,8 +2283,8 @@ int main(int argc, char **argv) { // Parse args while (1) { - int index = 0; - int c = getopt_long(argc, argv, "fhusr:", longOptionsG, &index); + int idx = 0; + int c = getopt_long(argc, argv, "fhusr:", longOptionsG, &idx); if (c == -1) { // End of options diff --git a/src/simplexml.c b/src/simplexml.c index 12eda26..bd8616b 100644 --- a/src/simplexml.c +++ b/src/simplexml.c @@ -47,6 +47,8 @@ static xmlEntityPtr saxGetEntity(void *user_data, const xmlChar *name) { + (void) user_data; + return xmlGetPredefinedEntity(name); } @@ -54,6 +56,8 @@ static xmlEntityPtr saxGetEntity(void *user_data, const xmlChar *name) static void saxStartElement(void *user_data, const xmlChar *nameUtf8, const xmlChar **attr) { + (void) attr; + SimpleXml *simpleXml = (SimpleXml *) user_data; if (simpleXml->status != S3StatusOK) { @@ -67,7 +71,7 @@ static void saxStartElement(void *user_data, const xmlChar *nameUtf8, int len = strlen(name); if ((simpleXml->elementPathLen + len + 1) >= - sizeof(simpleXml->elementPath)) { + (int) sizeof(simpleXml->elementPath)) { // Cannot handle this element, stop! simpleXml->status = S3StatusXmlParseFailure; return; @@ -83,6 +87,8 @@ static void saxStartElement(void *user_data, const xmlChar *nameUtf8, static void saxEndElement(void *user_data, const xmlChar *name) { + (void) name; + SimpleXml *simpleXml = (SimpleXml *) user_data; if (simpleXml->status != S3StatusOK) { @@ -117,6 +123,8 @@ static void saxCharacters(void *user_data, const xmlChar *ch, int len) static void saxError(void *user_data, const char *msg, ...) { + (void) msg; + SimpleXml *simpleXml = (SimpleXml *) user_data; if (simpleXml->status != S3StatusOK) { diff --git a/src/testsimplexml.c b/src/testsimplexml.c index 7210074..57fba7d 100644 --- a/src/testsimplexml.c +++ b/src/testsimplexml.c @@ -33,6 +33,8 @@ static S3Status simpleXmlCallback(const char *elementPath, const char *data, int dataLen, void *callbackData) { + (void) callbackData; + printf("[%s]: [%.*s]\n", elementPath, dataLen, data); return S3StatusOK; |