Skip to content

Commit

Permalink
move to config init
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK committed Dec 10, 2024
1 parent c3f1c3e commit 7f7a2a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 72 deletions.
72 changes: 0 additions & 72 deletions source/s3_auto_ranged_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,78 +313,6 @@ static struct aws_s3_meta_request_vtable s_s3_auto_ranged_put_vtable = {
.pause = s_s3_auto_ranged_put_pause,
};

static int s_init_and_verify_checksum_config_from_headers(
struct checksum_config_storage *checksum_config,
const struct aws_http_message *message,
const void *log_id) {
/* Check if the checksum header was set from the message */
struct aws_http_headers *headers = aws_http_message_get_headers(message);
enum aws_s3_checksum_algorithm header_algo = AWS_SCA_NONE;
struct aws_byte_cursor header_value;
AWS_ZERO_STRUCT(header_value);

for (size_t i = 0; i < AWS_ARRAY_SIZE(s_checksum_algo_priority_list); i++) {
enum aws_s3_checksum_algorithm algorithm = s_checksum_algo_priority_list[i];
const struct aws_byte_cursor algorithm_header_name =
aws_get_http_header_name_from_checksum_algorithm(algorithm);
if (aws_http_headers_get(headers, algorithm_header_name, &header_value) == AWS_OP_SUCCESS) {
if (header_algo == AWS_SCA_NONE) {
header_algo = algorithm;
} else {
/* If there are multiple checksum headers set, it's malformed request */
AWS_LOGF_ERROR(
AWS_LS_S3_META_REQUEST,
"id=%p Could not create auto-ranged-put meta request; multiple checksum headers has been set",
log_id);
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
}
}
if (header_algo == AWS_SCA_NONE) {
/* No checksum header found, done */
return AWS_OP_SUCCESS;
}

/* Found the full object checksum from the header, check if it matches the explicit setting from config */
if (checksum_config->checksum_algorithm != AWS_SCA_NONE && checksum_config->checksum_algorithm != header_algo) {
AWS_LOGF_ERROR(
AWS_LS_S3_META_REQUEST,
"id=%p: Could not create auto-ranged-put meta request; checksum config mismatch the checksum from header.",
log_id);
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
if (checksum_config->has_full_object_checksum) {
/* If the full object checksum has been set, it's malformed request */
AWS_LOGF_ERROR(
AWS_LS_S3_META_REQUEST,
"id=%p: Could not create auto-ranged-put meta request; full object checksum is set from multiple ways.",
log_id);
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}

AWS_LOGF_DEBUG(
AWS_LS_S3_META_REQUEST,
"id=%p: Setting the full-object checksum from header; algorithm: " PRInSTR ", value: " PRInSTR ".",
log_id,
AWS_BYTE_CURSOR_PRI(aws_get_checksum_algorithm_name(header_algo)),
AWS_BYTE_CURSOR_PRI(header_value));
/* Set algo */
checksum_config->checksum_algorithm = header_algo;
if (checksum_config->location == AWS_SCL_NONE) {
/* Set the checksum location to trailer for the parts, complete MPU will still have the checksum in the header.
* But to keep the data integrity for the parts, we need to set the checksum location to trailer to send the
* parts level checksums.
*/
checksum_config->location = AWS_SCL_TRAILER;
}

/* Set full object checksum from the header value. */
aws_byte_buf_init_copy_from_cursor(
&checksum_config->full_object_checksum, checksum_config->allocator, header_value);
checksum_config->has_full_object_checksum = true;
return AWS_OP_SUCCESS;
}

/* Allocate a new auto-ranged put meta request */
struct aws_s3_meta_request *aws_s3_meta_request_auto_ranged_put_new(
struct aws_allocator *allocator,
Expand Down
9 changes: 9 additions & 0 deletions source/s3_checksums.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ static int s_init_and_verify_checksum_config_from_headers(
return AWS_OP_SUCCESS;
}

if (checksum_config->has_full_object_checksum) {
/* If the full object checksum has been set, it's malformed request */
AWS_LOGF_ERROR(
AWS_LS_S3_META_REQUEST,
"id=%p: Could not create auto-ranged-put meta request; full object checksum is set from multiple ways.",
log_id);
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}

AWS_LOGF_DEBUG(
AWS_LS_S3_META_REQUEST,
"id=%p Setting the full-object checksum from header; algorithm: " PRInSTR ", value: " PRInSTR ".",
Expand Down

0 comments on commit 7f7a2a9

Please sign in to comment.