Browse Source

Resetting differences to official libs3 that are no longer needed

All were for compatibility with the classic C++Builder compiler (dynamic size arrays, snprintf, signed/unsigned comparison)

Source commit: 5f37a025339cd46c76c6f54def71a27187d7cce1
Martin Prikryl 1 week ago
parent
commit
16c17ab34b

+ 0 - 5
libs/libs3/inc/libs3.h

@@ -43,7 +43,6 @@
 #define LIBS3_VER_MINOR "1"
 #endif
 
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -2660,10 +2659,6 @@ void S3_list_multipart_uploads(S3BucketContext *bucketContext,
                                const S3ListMultipartUploadsHandler *handler,
                                void *callbackData);
 
-#ifdef WINSCP
-int snprintf_S(char * s, size_t n, const char * format, size_t len, const char * data);
-#endif
-
 #ifdef __cplusplus
 }
 #endif

+ 3 - 2
libs/libs3/inc/string_buffer.h

@@ -54,7 +54,7 @@
 // 0 if it did not
 #define string_buffer_append(sb, str, len, all_fit)                     \
     do {                                                                \
-        sb##Len += snprintf_S(&(sb[sb##Len]), sizeof(sb) - sb##Len - 1,   \
+        sb##Len += snprintf(&(sb[sb##Len]), sizeof(sb) - sb##Len - 1,   \
                             "%.*s", (int) (len), str);                  \
         if (sb##Len > (int) (sizeof(sb) - 1)) {                         \
             sb##Len = sizeof(sb) - 1;                                   \
@@ -65,6 +65,7 @@
         }                                                               \
     } while (0)
 
+
 // Declare a string multibuffer with the given name of the given maximum size
 #define string_multibuffer(name, size)                                  \
     char name[size];                                                    \
@@ -86,7 +87,7 @@
 // Adds a new string to the string_multibuffer
 #define string_multibuffer_add(smb, str, len, all_fit)                  \
     do {                                                                \
-        smb##Size += (snprintf_S(&(smb[smb##Size]),                       \
+        smb##Size += (snprintf(&(smb[smb##Size]),                       \
                                sizeof(smb) - smb##Size,                 \
                                "%.*s", (int) (len), str) + 1);          \
         if (smb##Size > (int) sizeof(smb)) {                            \

+ 5 - 8
libs/libs3/src/bucket.c

@@ -484,7 +484,7 @@ static S3Status make_list_bucket_callback(ListBucketData *lbData)
                        !strcmp(lbData->isTruncated, "1")) ? 1 : 0;
 
     // Convert the contents
-    S3ListBucketContent * contents = new S3ListBucketContent[lbData->contentsCount]; // WINSCP (heap allocation)
+    S3ListBucketContent contents[lbData->contentsCount];
 
     int contentsCount = lbData->contentsCount;
     for (i = 0; i < contentsCount; i++) {
@@ -504,18 +504,15 @@ static S3Status make_list_bucket_callback(ListBucketData *lbData)
 
     // Make the common prefixes array
     int commonPrefixesCount = lbData->commonPrefixesCount;
-    char **commonPrefixes = new char*[commonPrefixesCount]; // WINSCP (heap allocation)
+    char *commonPrefixes[commonPrefixesCount];
     for (i = 0; i < commonPrefixesCount; i++) {
         commonPrefixes[i] = lbData->commonPrefixes[i];
     }
 
-    S3Status status = (*(lbData->listBucketCallback))
+    return (*(lbData->listBucketCallback))
         (isTruncated, lbData->nextMarker,
          contentsCount, contents, commonPrefixesCount,
          (const char **) commonPrefixes, lbData->callbackData);
-    delete[] contents; // WINSCP (heap allocation)
-    delete[] commonPrefixes;
-    return status;
 }
 
 
@@ -572,7 +569,7 @@ static S3Status listBucketXmlCallback(const char *elementPath,
             int which = lbData->commonPrefixesCount;
             size_t oldLen = lbData->commonPrefixLens[which];
             lbData->commonPrefixLens[which] +=
-                snprintf_S(lbData->commonPrefixes[which]+oldLen,
+                snprintf(lbData->commonPrefixes[which]+oldLen,
                          sizeof(lbData->commonPrefixes[which]) -
                          oldLen - 1,
                          "%.*s", dataLen, data);
@@ -710,7 +707,7 @@ void S3_list_bucket(const S3BucketContext *bucketContext, const char *prefix,
 
 
     int amp = 0;
-    if (prefix) {
+    if (prefix) { // WINSCP
         safe_append("prefix", prefix);
     }
     if (marker && *marker) {

+ 1 - 1
libs/libs3/src/error_parser.c

@@ -89,7 +89,7 @@ static S3Status errorXmlCallback(const char *elementPath, const char *data,
         }
         // OK, must add another unknown error element, if it will fit.
         if (errorParser->s3ErrorDetails.extraDetailsCount ==
-            (int)sizeof(errorParser->extraDetails)) { // WINSCP (cast)
+            sizeof(errorParser->extraDetails)) {
             // Won't fit.  Ignore this one.
             return S3StatusOK;
         }

+ 2 - 33
libs/libs3/src/general.c

@@ -307,7 +307,7 @@ static S3Status convertAclXmlCallback(const char *elementPath,
     if (data) {
         if (!strcmp(elementPath, "AccessControlPolicy/Owner/ID")) {
             caData->ownerIdLen +=
-                snprintf_S(&(caData->ownerId[caData->ownerIdLen]),
+                snprintf(&(caData->ownerId[caData->ownerIdLen]),
                          S3_MAX_GRANTEE_USER_ID_SIZE - caData->ownerIdLen - 1,
                          "%.*s", dataLen, data);
             if (caData->ownerIdLen >= S3_MAX_GRANTEE_USER_ID_SIZE) {
@@ -317,7 +317,7 @@ static S3Status convertAclXmlCallback(const char *elementPath,
         else if (!strcmp(elementPath, "AccessControlPolicy/Owner/"
                          "DisplayName")) {
             caData->ownerDisplayNameLen +=
-                snprintf_S(&(caData->ownerDisplayName
+                snprintf(&(caData->ownerDisplayName
                            [caData->ownerDisplayNameLen]),
                          S3_MAX_GRANTEE_DISPLAY_NAME_SIZE -
                          caData->ownerDisplayNameLen - 1,
@@ -496,34 +496,3 @@ int S3_status_is_retryable(S3Status status)
         return 0;
     }
 }
-
-#include <assert.h>
-
-// CodeGuard compatible implementation of snprintf with "%.*s" format
-int snprintf_S(char * s, size_t n, const char * format, size_t len, const char * data)
-{
-    int result;
-    if (strcmp(format, "%.*s") == 0)
-    {
-        result = len;
-        while ((n > 1) && (len > 0) && (*data != '\0'))
-        {
-            *s = *data;
-            ++s;
-            ++data;
-            --len;
-            --n;
-        }
-
-        if (n > 0)
-        {
-            *s = '\0';
-        }
-    }
-    else
-    {
-        assert(false);
-        result = snprintf(s, n, format, len, data);
-    }
-    return result;
-}

+ 5 - 11
libs/libs3/src/multipart.c

@@ -553,7 +553,7 @@ static S3Status make_list_multipart_callback(ListMultipartData *lmData)
                        !strcmp(lmData->isTruncated, "1")) ? 1 : 0;
 
     // Convert the contents
-    S3ListMultipartUpload * uploads = new S3ListMultipartUpload[lmData->uploadsCount]; // WINSCP (heap allocation)
+    S3ListMultipartUpload uploads[lmData->uploadsCount];
 
     int uploadsCount = lmData->uploadsCount;
     for (i = 0; i < uploadsCount; i++) {
@@ -573,18 +573,15 @@ static S3Status make_list_multipart_callback(ListMultipartData *lmData)
 
     // Make the common prefixes array
     int commonPrefixesCount = lmData->commonPrefixesCount;
-    char **commonPrefixes = new char*[commonPrefixesCount]; // WINSCP (heap allocation)
+    char *commonPrefixes[commonPrefixesCount];
     for (i = 0; i < commonPrefixesCount; i++) {
         commonPrefixes[i] = lmData->commonPrefixes[i];
     }
 
-    S3Status status = (*(lmData->listMultipartCallback))
+    return (*(lmData->listMultipartCallback))
         (isTruncated, lmData->nextKeyMarker, lmData->nextUploadIdMarker,
          uploadsCount, uploads, commonPrefixesCount,
          (const char **) commonPrefixes, lmData->callbackData);
-    delete[] uploads; // WINSCP (heap allocation)
-    delete[] commonPrefixes;
-    return status;
 }
 
 
@@ -597,7 +594,7 @@ static S3Status make_list_parts_callback(ListPartsData *lpData)
                        !strcmp(lpData->isTruncated, "1")) ? 1 : 0;
 
     // Convert the contents
-    S3ListPart * Parts = new S3ListPart[lpData->partsCount]; // WINSCP (heap allocation)
+    S3ListPart Parts[lpData->partsCount];
     int partsCount = lpData->partsCount;
     for (i = 0; i < partsCount; i++) {
         S3ListPart *partDest = &(Parts[i]);
@@ -608,14 +605,11 @@ static S3Status make_list_parts_callback(ListPartsData *lpData)
         partDest->lastModified = parseIso8601Time(partSrc->lastModified);
     }
 
-    S3Status status =
-        (*(lpData->listPartsCallback))
+    return (*(lpData->listPartsCallback))
         (isTruncated, lpData->nextPartNumberMarker, lpData->initiatorId,
          lpData->initiatorDisplayName, lpData->ownerId,
          lpData->ownerDisplayName, lpData->storageClass, partsCount,
          lpData->handlePartsStart, Parts, lpData->callbackData);
-    delete[] Parts; // WINSCP (heap allocation)
-    return status;
 }
 
 

+ 1 - 1
libs/libs3/src/object.c

@@ -115,7 +115,7 @@ static S3Status copyObjectXmlCallback(const char *elementPath,
         else if (!strcmp(elementPath, "CopyObjectResult/ETag")) {
             if (coData->eTagReturnSize && coData->eTagReturn) {
                 coData->eTagReturnLen +=
-                    snprintf_S(&(coData->eTagReturn[coData->eTagReturnLen]),
+                    snprintf(&(coData->eTagReturn[coData->eTagReturnLen]),
                              coData->eTagReturnSize -
                              coData->eTagReturnLen - 1,
                              "%.*s", dataLen, data);

+ 14 - 32
libs/libs3/src/request.c

@@ -664,9 +664,7 @@ static int headerle(const char *s1, const char *s2, char delim)
         }
         s1++, s2++;
     }
-#ifndef WINSCP
     return 0;
-#endif
 }
 
 
@@ -830,7 +828,7 @@ static void sort_query_string(const char *queryString, char *result,
         tmp++;
     }
 
-    const char** params = new const char*[numParams]; // WINSCP (heap allocation)
+    const char* params[numParams];
 
     // Where did strdup go?!??
     int queryStringLen = strlen(queryString);
@@ -868,7 +866,6 @@ static void sort_query_string(const char *queryString, char *result,
     }
 #undef append
 
-    delete[] params; // WINSCP (heap allocation)
     free(buf);
 }
 
@@ -885,12 +882,10 @@ static void canonicalize_query_string(const char *queryParams,
 #define append(str) len += snprintf(&(buffer[len]), buffer_size - len, "%s", str)
 
     if (queryParams && queryParams[0]) {
-        int sortedLen = strlen(queryParams) * 2;
-        char * sorted = new char[sortedLen]; // WINSCP (heap allocation)
+        char sorted[strlen(queryParams) * 2];
         sorted[0] = '\0';
-        sort_query_string(queryParams, sorted, sortedLen);
+        sort_query_string(queryParams, sorted, sizeof(sorted));
         append(sorted);
-        delete[] sorted; // WINSCP (heap allocation)
     }
 
     if (subResource && subResource[0]) {
@@ -967,15 +962,13 @@ static S3Status compose_auth_header(const RequestParams *params,
 
     int len = 0;
 
-    char * canonicalRequest = new char[canonicalRequestLen]; // WINSCP (heap allocation)
+    char canonicalRequest[canonicalRequestLen];
 
-// WINSCP (heap allocation)
 #define buf_append(buf, format, ...)                    \
-    len += snprintf(&(buf[len]), size - len,     \
+    len += snprintf(&(buf[len]), sizeof(buf) - len,     \
                     format, __VA_ARGS__)
 
     canonicalRequest[0] = '\0';
-    int size = canonicalRequestLen; // WINSCP
     buf_append(canonicalRequest, "%s\n", httpMethod);
     buf_append(canonicalRequest, "%s\n", values->canonicalURI);
     buf_append(canonicalRequest, "%s\n", values->canonicalQueryString);
@@ -996,9 +989,7 @@ static S3Status compose_auth_header(const RequestParams *params,
     const unsigned char *rqstData = (const unsigned char*) canonicalRequest;
     SHA256(rqstData, strlen(canonicalRequest), canonicalRequestHash);
 #endif
-    delete[] canonicalRequest; // WINSCP
     char canonicalRequestHashHex[2 * S3_SHA256_DIGEST_LENGTH + 1];
-    size = sizeof(canonicalRequestHashHex); // WINSCP
     canonicalRequestHashHex[0] = '\0';
     int i = 0;
     for (; i < S3_SHA256_DIGEST_LENGTH; i++) {
@@ -1010,15 +1001,14 @@ static S3Status compose_auth_header(const RequestParams *params,
         awsRegion = params->bucketContext.authRegion;
     }
     const char * service = (params->bucketContext.service != NULL) ? params->bucketContext.service : S3_SERVICE; // WINSCP
-    int scopeSize = 8 + strlen(awsRegion) + strlen(service) + sizeof("///aws4_request"); // WINSCP
-    char * scope = new char[scopeSize]; // WINSCP
-    snprintf(scope, scopeSize, "%.8s/%s/%s/aws4_request",
+    int scopeSize = 8 + strlen(awsRegion) + strlen(service) + sizeof("///aws4_request") + 1; // WINSCP
+    char scope[scopeSize]; // WINSCP
+    snprintf(scope, sizeof(scope), "%.8s/%s/%s/aws4_request",
              values->requestDateISO8601, awsRegion, service); // WINSCP
 
-    const int stringToSignLen = 17 + 17 + sizeof(values->requestDateISO8601) +
-        scopeSize - 1 + sizeof(canonicalRequestHashHex) + 1; // WINSCP (heap allocation)
-    char * stringToSign = new char[stringToSignLen];
-    snprintf(stringToSign, stringToSignLen, "AWS4-HMAC-SHA256\n%s\n%s\n%s",
+    char stringToSign[17 + 17 + sizeof(values->requestDateISO8601) +
+                      sizeof(scope) + sizeof(canonicalRequestHashHex) + 1];
+    snprintf(stringToSign, sizeof(stringToSign), "AWS4-HMAC-SHA256\n%s\n%s\n%s",
              values->requestDateISO8601, scope, canonicalRequestHashHex);
 
 #ifdef SIGNATURE_DEBUG
@@ -1026,9 +1016,8 @@ static S3Status compose_auth_header(const RequestParams *params,
 #endif
 
     const char *secretAccessKey = params->bucketContext.secretAccessKey;
-    const int accessKeyLen = strlen(secretAccessKey) + 5; // WINSCP (heap allocation)
-    char * accessKey = new char[accessKeyLen];
-    snprintf(accessKey, accessKeyLen, "AWS4%s", secretAccessKey);
+    char accessKey[strlen(secretAccessKey) + 5];
+    snprintf(accessKey, sizeof(accessKey), "AWS4%s", secretAccessKey);
 
 #ifdef __APPLE__
     unsigned char dateKey[S3_SHA256_DIGEST_LENGTH];
@@ -1071,11 +1060,8 @@ static S3Status compose_auth_header(const RequestParams *params,
          (const unsigned char*) stringToSign, strlen(stringToSign),
          finalSignature, NULL);
 #endif
-    delete[] accessKey; // WINSCP
-    delete[] stringToSign; // WINSCP
 
     len = 0;
-    size = sizeof(values->requestSignatureHex); // WINSCP
     values->requestSignatureHex[0] = '\0';
     for (i = 0; i < S3_SHA256_DIGEST_LENGTH; i++) {
         buf_append(values->requestSignatureHex, "%02x", finalSignature[i]);
@@ -1084,7 +1070,6 @@ static S3Status compose_auth_header(const RequestParams *params,
     snprintf(values->authCredential, sizeof(values->authCredential),
              "%s/%.8s/%s/%s/aws4_request", params->bucketContext.accessKeyId,
              values->requestDateISO8601, awsRegion, service); // WINSCP
-    delete[] scope; // WINSCP
 
     snprintf(values->authorizationHeader,
              sizeof(values->authorizationHeader),
@@ -1823,11 +1808,8 @@ S3Status S3_generate_authenticated_query_string
         expires = MAX_EXPIRES;
     }
 
-    // WinSCP
     RequestParams params =
-    { http_request_method_to_type(httpMethod),
-        { bucketContext->hostName, bucketContext->bucketName, bucketContext->protocol, bucketContext->uriStyle, bucketContext->accessKeyId, bucketContext->secretAccessKey, bucketContext->securityToken, bucketContext->authRegion },
-        key, NULL,
+    { http_request_method_to_type(httpMethod), *bucketContext, key, NULL,
         resource,
         NULL, NULL, NULL, 0, 0, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0};
 

+ 2 - 2
libs/libs3/src/response_headers_handler.c

@@ -75,7 +75,7 @@ void response_headers_handler_add(ResponseHeadersHandler *handler,
     // This sucks, but it shouldn't happen - S3 should not be sending back
     // really long headers.
     if (handler->responsePropertyStringsSize == 
-        (int)(sizeof(handler->responsePropertyStrings) - 1)) { // WINSCP (cast)
+        (sizeof(handler->responsePropertyStrings) - 1)) {
         return;
     }
 
@@ -128,7 +128,7 @@ void response_headers_handler_add(ResponseHeadersHandler *handler,
                       sizeof(S3_METADATA_HEADER_NAME_PREFIX) - 1)) {
         // Make sure there is room for another x-amz-meta header
         if (handler->responseProperties.metaDataCount ==
-            (int)sizeof(handler->responseMetaData)) { // WINSCP (cast)
+            sizeof(handler->responseMetaData)) {
             return;
         }
         // Copy the name in

+ 2 - 2
libs/libs3/src/service_access_logging.c

@@ -67,7 +67,7 @@ static S3Status convertBlsXmlCallback(const char *elementPath,
         if (!strcmp(elementPath, "BucketLoggingStatus/LoggingEnabled/"
                     "TargetBucket")) {
             caData->targetBucketReturnLen +=
-                snprintf_S(&(caData->targetBucketReturn
+                snprintf(&(caData->targetBucketReturn
                            [caData->targetBucketReturnLen]),
                          255 - caData->targetBucketReturnLen - 1,
                          "%.*s", dataLen, data);
@@ -78,7 +78,7 @@ static S3Status convertBlsXmlCallback(const char *elementPath,
         else if (!strcmp(elementPath, "BucketLoggingStatus/LoggingEnabled/"
                     "TargetPrefix")) {
             caData->targetPrefixReturnLen +=
-                snprintf_S(&(caData->targetPrefixReturn
+                snprintf(&(caData->targetPrefixReturn
                            [caData->targetPrefixReturnLen]),
                          255 - caData->targetPrefixReturnLen - 1,
                          "%.*s", dataLen, data);