S3Status S3_convert_acl(char *aclXml, char *ownerId, char *ownerDisplayName, int *aclGrantCountReturn, S3AclGrant *aclGrants) { ConvertAclData data; data.ownerId = ownerId; data.ownerIdLen = 0; data.ownerId[0] = 0; data.ownerDisplayName = ownerDisplayName; data.ownerDisplayNameLen = 0; data.ownerDisplayName[0] = 0; data.aclGrantCountReturn = aclGrantCountReturn; data.aclGrants = aclGrants; *aclGrantCountReturn = 0; string_buffer_initialize(data.emailAddress); string_buffer_initialize(data.userId); string_buffer_initialize(data.userDisplayName); string_buffer_initialize(data.groupUri); string_buffer_initialize(data.permission); // Use a simplexml parser SimpleXml simpleXml; simplexml_initialize(&simpleXml, &convertAclXmlCallback, &data); S3Status status = simplexml_add(&simpleXml, aclXml, strlen(aclXml)); simplexml_deinitialize(&simpleXml); return status; }
void S3_copy_object(const S3BucketContext *bucketContext, const char *key, const char *destinationBucket, const char *destinationKey, const S3PutProperties *putProperties, int64_t *lastModifiedReturn, int eTagReturnSize, char *eTagReturn, S3RequestContext *requestContext, const S3ResponseHandler *handler, void *callbackData) { // Create the callback data CopyObjectData *data = (CopyObjectData *) malloc(sizeof(CopyObjectData)); if (!data) { (*(handler->completeCallback))(S3StatusOutOfMemory, 0, callbackData); return; } simplexml_initialize(&(data->simpleXml), ©ObjectXmlCallback, data); data->responsePropertiesCallback = handler->propertiesCallback; data->responseCompleteCallback = handler->completeCallback; data->callbackData = callbackData; data->lastModifiedReturn = lastModifiedReturn; data->eTagReturnSize = eTagReturnSize; data->eTagReturn = eTagReturn; if (data->eTagReturnSize && data->eTagReturn) { data->eTagReturn[0] = 0; } data->eTagReturnLen = 0; string_buffer_initialize(data->lastModified); // Set up the RequestParams RequestParams params = { HttpRequestTypeCOPY, // httpRequestType { destinationBucket ? destinationBucket : bucketContext->bucketName, // bucketName bucketContext->protocol, // protocol bucketContext->uriStyle, // uriStyle bucketContext->accessKeyId, // accessKeyId bucketContext->secretAccessKey }, // secretAccessKey destinationKey ? destinationKey : key, // key 0, // queryParams 0, // subResource bucketContext->bucketName, // copySourceBucketName key, // copySourceKey 0, // getConditions 0, // startByte 0, // byteCount putProperties, // putProperties ©ObjectPropertiesCallback, // propertiesCallback 0, // toS3Callback 0, // toS3CallbackTotalSize ©ObjectDataCallback, // fromS3Callback ©ObjectCompleteCallback, // completeCallback data // callbackData }; // Perform the request request_perform(¶ms, requestContext); }
static S3Status convert_bls(char *blsXml, char *targetBucketReturn, char *targetPrefixReturn, int *aclGrantCountReturn, S3AclGrant *aclGrants) { ConvertBlsData data; data.targetBucketReturn = targetBucketReturn; data.targetBucketReturn[0] = 0; data.targetBucketReturnLen = 0; data.targetPrefixReturn = targetPrefixReturn; data.targetPrefixReturn[0] = 0; data.targetPrefixReturnLen = 0; data.aclGrantCountReturn = aclGrantCountReturn; data.aclGrants = aclGrants; *aclGrantCountReturn = 0; string_buffer_initialize(data.emailAddress); string_buffer_initialize(data.userId); string_buffer_initialize(data.userDisplayName); string_buffer_initialize(data.groupUri); string_buffer_initialize(data.permission); // Use a simplexml parser SimpleXml simpleXml; simplexml_initialize(&simpleXml, &convertBlsXmlCallback, &data); S3Status status = simplexml_add(&simpleXml, blsXml, strlen(blsXml)); simplexml_deinitialize(&simpleXml); return status; }
void S3_list_service(S3Protocol protocol, S3STSDate stsDate, const char *accessKeyId, const char *secretAccessKey, const char *securityToken, const char *hostName, S3RequestContext *requestContext, const S3ListServiceHandler *handler, void *callbackData) { // Create and set up the callback data XmlCallbackData *data = (XmlCallbackData *) malloc(sizeof(XmlCallbackData)); if (!data) { (*(handler->responseHandler.completeCallback)) (S3StatusOutOfMemory, 0, callbackData); return; } simplexml_initialize(&(data->simpleXml), &xmlCallback, data); data->responsePropertiesCallback = handler->responseHandler.propertiesCallback; data->listServiceCallback = handler->listServiceCallback; data->responseCompleteCallback = handler->responseHandler.completeCallback; data->callbackData = callbackData; string_buffer_initialize(data->ownerId); string_buffer_initialize(data->ownerDisplayName); string_buffer_initialize(data->bucketName); string_buffer_initialize(data->creationDate); // Set up the RequestParams RequestParams params = { HttpRequestTypeGET, // httpRequestType { hostName, // hostName 0, // bucketName protocol, // protocol S3UriStylePath, // uriStyle accessKeyId, // accessKeyId secretAccessKey, // secretAccessKey securityToken, // securityToken stsDate }, // stsDate 0, // key 0, // queryParams 0, // subResource 0, // copySourceBucketName 0, // copySourceKey 0, // getConditions 0, // startByte 0, // byteCount 0, // requestProperties &propertiesCallback, // propertiesCallback 0, // toS3Callback 0, // toS3CallbackTotalSize &dataCallback, // fromS3Callback &completeCallback, // completeCallback data // callbackData }; // Perform the request request_perform(¶ms, requestContext); }
void S3_test_bucket(S3Protocol protocol, S3UriStyle uriStyle, const char *accessKeyId, const char *secretAccessKey, const char *securityToken, const char *hostName, const char *bucketName, int locationConstraintReturnSize, char *locationConstraintReturn, S3RequestContext *requestContext, const S3ResponseHandler *handler, void *callbackData) { // Create the callback data TestBucketData *tbData = (TestBucketData *) malloc(sizeof(TestBucketData)); if (!tbData) { (*(handler->completeCallback))(S3StatusOutOfMemory, 0, callbackData); return; } simplexml_initialize(&(tbData->simpleXml), &testBucketXmlCallback, tbData); tbData->responsePropertiesCallback = handler->propertiesCallback; tbData->responseCompleteCallback = handler->completeCallback; tbData->callbackData = callbackData; tbData->locationConstraintReturnSize = locationConstraintReturnSize; tbData->locationConstraintReturn = locationConstraintReturn; string_buffer_initialize(tbData->locationConstraint); // Set up the RequestParams RequestParams params = { HttpRequestTypeGET, // httpRequestType { hostName, // hostName bucketName, // bucketName protocol, // protocol uriStyle, // uriStyle accessKeyId, // accessKeyId secretAccessKey, // secretAccessKey securityToken }, // securityToken 0, // key 0, // queryParams "location", // subResource 0, // copySourceBucketName 0, // copySourceKey 0, // getConditions 0, // startByte 0, // byteCount 0, // putProperties &testBucketPropertiesCallback, // propertiesCallback 0, // toS3Callback 0, // toS3CallbackTotalSize &testBucketDataCallback, // fromS3Callback &testBucketCompleteCallback, // completeCallback tbData // callbackData }; // Perform the request request_perform(¶ms, requestContext); }
void S3_complete_multipart_upload(S3BucketContext *bucketContext, const char *key, S3MultipartCommitHandler *handler, const char *upload_id, int contentLength, S3RequestContext *requestContext, void *callbackData) { char subResource[512]; snprintf(subResource, 512, "uploadId=%s", upload_id); CommitMultiPartData *data = (CommitMultiPartData *) malloc(sizeof(CommitMultiPartData)); data->userdata = callbackData; data->handler = handler; string_buffer_initialize(data->location); string_buffer_initialize(data->etag); simplexml_initialize(&(data->simplexml), commitMultipartResponseXMLcallback, data); RequestParams params = { HttpRequestTypePOST, // httpRequestType { bucketContext->hostName, // hostName bucketContext->bucketName, // bucketName bucketContext->protocol, // protocol bucketContext->uriStyle, // uriStyle bucketContext->accessKeyId, // accessKeyId bucketContext->secretAccessKey, //secretAccessKey bucketContext->securityToken }, // secretToken key, // key 0, // queryParams subResource, // subResource 0, // copySourceBucketName 0, // copySourceKey 0, // getConditions 0, // startByte 0, // byteCount 0, // putProperties commitMultipartPropertiesCallback, // propertiesCallback commitMultipartPutObject, // toS3Callback contentLength, // toS3CallbackTotalSize commitMultipartCallback, // fromS3Callback commitMultipartCompleteCallback, // completeCallback data // callbackData }; request_perform(¶ms, requestContext); }
void S3_initiate_multipart(S3BucketContext *bucketContext, const char *key, S3PutProperties *putProperties, S3MultipartInitialHandler *handler, S3RequestContext *requestContext, void *callbackData) { InitialMultipartData *mdata = (InitialMultipartData *) malloc(sizeof(InitialMultipartData)); simplexml_initialize(&(mdata->simpleXml), &initialMultipartXmlCallback, mdata); string_buffer_initialize(mdata->upload_id); mdata->handler= handler; mdata->userdata = callbackData; RequestParams params = { HttpRequestTypePOST, // httpRequestType { bucketContext->hostName, // hostName bucketContext->bucketName, // bucketName bucketContext->protocol, // protocol bucketContext->uriStyle, // uriStyle bucketContext->accessKeyId, // accessKeyId bucketContext->secretAccessKey, //secretAccessKey bucketContext->securityToken }, // secretToken key, // key 0, // queryParams "uploads", // subResource 0, // copySourceBucketName 0, // copySourceKey 0, // getConditions 0, // startByte 0, // byteCount putProperties, // putProperties handler->responseHandler.propertiesCallback, // propertiesCallback 0, // toS3Callback 0, // toS3CallbackTotalSize InitialMultipartCallback, // fromS3Callback InitialMultipartCompleteCallback, // completeCallback mdata // callbackData }; // Perform the request request_perform(¶ms, requestContext); }
void S3_copy_object_range(const S3BucketContext *bucketContext, const char *key, const char *destinationBucket, const char *destinationKey, const int partNo, const char *uploadId, const unsigned long startOffset, const unsigned long count, const S3PutProperties *putProperties, int64_t *lastModifiedReturn, int eTagReturnSize, char *eTagReturn, S3RequestContext *requestContext, const S3ResponseHandler *handler, void *callbackData) { // Create the callback data CopyObjectData *data = (CopyObjectData *) malloc(sizeof(CopyObjectData)); if (!data) { (*(handler->completeCallback))(S3StatusOutOfMemory, 0, callbackData); return; } simplexml_initialize(&(data->simpleXml), ©ObjectXmlCallback, data); data->responsePropertiesCallback = handler->propertiesCallback; data->responseCompleteCallback = handler->completeCallback; data->callbackData = callbackData; data->lastModifiedReturn = lastModifiedReturn; data->eTagReturnSize = eTagReturnSize; data->eTagReturn = eTagReturn; if (data->eTagReturnSize && data->eTagReturn) { data->eTagReturn[0] = 0; } data->eTagReturnLen = 0; string_buffer_initialize(data->lastModified); // If there's a sequence ID > 0 then add a subResource, OTW pass in NULL char subResource[512]; char *subRsrc = NULL; if (partNo > 0) { snprintf(subResource, 512, "partNumber=%d&uploadId=%s", partNo, uploadId); subRsrc = subResource; } // Set up the RequestParams RequestParams params = { HttpRequestTypeCOPY, // httpRequestType { bucketContext->hostName, // hostName destinationBucket ? destinationBucket : bucketContext->bucketName, // bucketName bucketContext->protocol, // protocol bucketContext->uriStyle, // uriStyle bucketContext->accessKeyId, // accessKeyId bucketContext->secretAccessKey, // secretAccessKey bucketContext->securityToken }, // securityToken destinationKey ? destinationKey : key, // key 0, // queryParams subRsrc, // subResource bucketContext->bucketName, // copySourceBucketName key, // copySourceKey 0, // getConditions startOffset, // startByte count, // byteCount putProperties, // putProperties ©ObjectPropertiesCallback, // propertiesCallback 0, // toS3Callback 0, // toS3CallbackTotalSize ©ObjectDataCallback, // fromS3Callback ©ObjectCompleteCallback, // completeCallback data // callbackData }; // Perform the request request_perform(¶ms, requestContext); }
void S3_list_bucket(const S3BucketContext *bucketContext, const char *prefix, const char *marker, const char *delimiter, int maxkeys, S3RequestContext *requestContext, const S3ListBucketHandler *handler, void *callbackData) { // Compose the query params string_buffer(queryParams, 4096); string_buffer_initialize(queryParams); #define safe_append(name, value) \ do { \ int fit; \ if (amp) { \ string_buffer_append(queryParams, "&", 1, fit); \ if (!fit) { \ (*(handler->responseHandler.completeCallback)) \ (S3StatusQueryParamsTooLong, 0, callbackData); \ return; \ } \ } \ string_buffer_append(queryParams, name "=", \ sizeof(name "=") - 1, fit); \ if (!fit) { \ (*(handler->responseHandler.completeCallback)) \ (S3StatusQueryParamsTooLong, 0, callbackData); \ return; \ } \ amp = 1; \ char encoded[3 * 1024]; \ if (!urlEncode(encoded, value, 1024)) { \ (*(handler->responseHandler.completeCallback)) \ (S3StatusQueryParamsTooLong, 0, callbackData); \ return; \ } \ string_buffer_append(queryParams, encoded, strlen(encoded), \ fit); \ if (!fit) { \ (*(handler->responseHandler.completeCallback)) \ (S3StatusQueryParamsTooLong, 0, callbackData); \ return; \ } \ } while (0) int amp = 0; if (prefix) { safe_append("prefix", prefix); } if (marker) { safe_append("marker", marker); } if (delimiter) { safe_append("delimiter", delimiter); } if (maxkeys) { char maxKeysString[64]; snprintf(maxKeysString, sizeof(maxKeysString), "%d", maxkeys); safe_append("max-keys", maxKeysString); } ListBucketData *lbData = (ListBucketData *) malloc(sizeof(ListBucketData)); if (!lbData) { (*(handler->responseHandler.completeCallback)) (S3StatusOutOfMemory, 0, callbackData); return; } simplexml_initialize(&(lbData->simpleXml), &listBucketXmlCallback, lbData); lbData->responsePropertiesCallback = handler->responseHandler.propertiesCallback; lbData->listBucketCallback = handler->listBucketCallback; lbData->responseCompleteCallback = handler->responseHandler.completeCallback; lbData->callbackData = callbackData; string_buffer_initialize(lbData->isTruncated); string_buffer_initialize(lbData->nextMarker); initialize_list_bucket_data(lbData); // Set up the RequestParams RequestParams params = { HttpRequestTypeGET, // httpRequestType { bucketContext->hostName, // hostName bucketContext->bucketName, // bucketName bucketContext->protocol, // protocol bucketContext->uriStyle, // uriStyle bucketContext->accessKeyId, // accessKeyId bucketContext->secretAccessKey, // secretAccessKey bucketContext->securityToken }, // securityToken 0, // key queryParams[0] ? queryParams : 0, // queryParams 0, // subResource 0, // copySourceBucketName 0, // copySourceKey 0, // getConditions 0, // startByte 0, // byteCount 0, // putProperties &listBucketPropertiesCallback, // propertiesCallback 0, // toS3Callback 0, // toS3CallbackTotalSize &listBucketDataCallback, // fromS3Callback &listBucketCompleteCallback, // completeCallback lbData // callbackData }; // Perform the request request_perform(¶ms, requestContext); }
void S3_list_parts(S3BucketContext *bucketContext, const char *key, const char *partnumbermarker, const char *uploadid, const char *encodingtype, int maxparts, S3RequestContext *requestContext, const S3ListPartsHandler *handler, void *callbackData) { // Compose the query params string_buffer(queryParams, 4096); string_buffer_initialize(queryParams); #define safe_append(name, value) \ do { \ int fit; \ if (amp) { \ string_buffer_append(queryParams, "&", 1, fit); \ if (!fit) { \ (*(handler->responseHandler.completeCallback)) \ (S3StatusQueryParamsTooLong, 0, callbackData); \ return; \ } \ } \ string_buffer_append(queryParams, name "=", \ sizeof(name "=") - 1, fit); \ if (!fit) { \ (*(handler->responseHandler.completeCallback)) \ (S3StatusQueryParamsTooLong, 0, callbackData); \ return; \ } \ amp = 1; \ char encoded[3 * 1024]; \ if (!urlEncode(encoded, value, 1024)) { \ (*(handler->responseHandler.completeCallback)) \ (S3StatusQueryParamsTooLong, 0, callbackData); \ return; \ } \ string_buffer_append(queryParams, encoded, strlen(encoded), \ fit); \ if (!fit) { \ (*(handler->responseHandler.completeCallback)) \ (S3StatusQueryParamsTooLong, 0, callbackData); \ return; \ } \ } while (0) char subResource[512]; snprintf(subResource, 512, "uploadId=%s", uploadid); int amp = 0; if (partnumbermarker && *partnumbermarker) { safe_append("part-number-marker", partnumbermarker); } if (encodingtype && *encodingtype) { safe_append("encoding-type", encodingtype); } if (maxparts) { char maxPartsString[64]; snprintf(maxPartsString, sizeof(maxPartsString), "%d", maxparts); safe_append("max-parts", maxPartsString); } ListPartsData *lpData = (ListPartsData *) malloc(sizeof(ListPartsData)); if (!lpData) { (*(handler->responseHandler.completeCallback)) (S3StatusOutOfMemory, 0, callbackData); return; } simplexml_initialize(&(lpData->simpleXml), &listPartsXmlCallback, lpData); lpData->responsePropertiesCallback = handler->responseHandler.propertiesCallback; lpData->listPartsCallback = handler->responseXmlCallback; lpData->responseCompleteCallback = handler->responseHandler.completeCallback; lpData->callbackData = callbackData; string_buffer_initialize(lpData->isTruncated); string_buffer_initialize(lpData->nextPartNumberMarker); string_buffer_initialize(lpData->initiatorId); string_buffer_initialize(lpData->initiatorDisplayName); string_buffer_initialize(lpData->ownerId); string_buffer_initialize(lpData->ownerDisplayName); string_buffer_initialize(lpData->storageClass); initialize_list_parts_data(lpData); lpData->handlePartsStart = 0; // Set up the RequestParams RequestParams params = { HttpRequestTypeGET, // httpRequestType { bucketContext->hostName, // hostName bucketContext->bucketName, // bucketName bucketContext->protocol, // protocol bucketContext->uriStyle, // uriStyle bucketContext->accessKeyId, // accessKeyId bucketContext->secretAccessKey, // secretAccessKey bucketContext->securityToken }, // securityToken key, // key queryParams[0] ? queryParams : 0, // queryParams subResource, // subResource 0, // copySourceBucketName 0, // copySourceKey 0, // getConditions 0, // startByte 0, // byteCount 0, // putProperties &listPartsPropertiesCallback, // propertiesCallback 0, // toS3Callback 0, // toS3CallbackTotalSize &listPartsDataCallback, // fromS3Callback &listPartsCompleteCallback, // completeCallback lpData // callbackData }; // Perform the request request_perform(¶ms, requestContext); }