| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/auth/signable.h> |
| 7 |
#include <aws/common/string.h> |
| 8 |
#include <aws/http/request_response.h> |
| 9 |
|
| 10 |
struct aws_signable_trailing_headers_impl { |
| 11 |
struct aws_http_headers *trailing_headers; |
| 12 |
struct aws_array_list headers; |
| 13 |
struct aws_string *previous_signature; |
| 14 |
}; |
| 15 |
|
| 16 |
static int s_aws_signable_trailing_headers_get_property( |
| 17 |
const struct aws_signable *signable, |
| 18 |
const struct aws_string *name, |
| 19 |
struct aws_byte_cursor *out_value) { |
| 20 |
|
| 21 |
struct aws_signable_trailing_headers_impl *impl = signable->impl; |
| 22 |
|
| 23 |
AWS_ZERO_STRUCT(*out_value); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
if (aws_string_eq(name, g_aws_previous_signature_property_name)) { |
| 29 |
*out_value = aws_byte_cursor_from_string(impl->previous_signature); |
| 30 |
} else { |
| 31 |
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 32 |
} |
| 33 |
return AWS_OP_SUCCESS; |
| 34 |
} |
| 35 |
|
| 36 |
static int s_aws_signable_trailing_headers_get_property_list( |
| 37 |
const struct aws_signable *signable, |
| 38 |
const struct aws_string *name, |
| 39 |
struct aws_array_list **out_list) { |
| 40 |
(void)signable; |
| 41 |
(void)name; |
| 42 |
(void)out_list; |
| 43 |
|
| 44 |
struct aws_signable_trailing_headers_impl *impl = signable->impl; |
| 45 |
|
| 46 |
*out_list = NULL; |
| 47 |
|
| 48 |
if (aws_string_eq(name, g_aws_http_headers_property_list_name)) { |
| 49 |
*out_list = &impl->headers; |
| 50 |
} else { |
| 51 |
return aws_raise_error(AWS_ERROR_UNSUPPORTED_OPERATION); |
| 52 |
} |
| 53 |
|
| 54 |
return AWS_OP_SUCCESS; |
| 55 |
} |
| 56 |
|
| 57 |
static int s_aws_signable_trailing_headers_get_payload_stream( |
| 58 |
const struct aws_signable *signable, |
| 59 |
struct aws_input_stream **out_input_stream) { |
| 60 |
(void)signable; |
| 61 |
*out_input_stream = NULL; |
| 62 |
|
| 63 |
return AWS_OP_SUCCESS; |
| 64 |
} |
| 65 |
|
| 66 |
static void s_aws_signable_trailing_headers_destroy(struct aws_signable *signable) { |
| 67 |
if (signable == NULL) { |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
struct aws_signable_trailing_headers_impl *impl = signable->impl; |
| 72 |
if (impl == NULL) { |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
aws_http_headers_release(impl->trailing_headers); |
| 77 |
aws_string_destroy(impl->previous_signature); |
| 78 |
aws_array_list_clean_up(&impl->headers); |
| 79 |
aws_mem_release(signable->allocator, signable); |
| 80 |
} |
| 81 |
|
| 82 |
static struct aws_signable_vtable s_signable_trailing_headers_vtable = { |
| 83 |
.get_property = s_aws_signable_trailing_headers_get_property, |
| 84 |
.get_property_list = s_aws_signable_trailing_headers_get_property_list, |
| 85 |
.get_payload_stream = s_aws_signable_trailing_headers_get_payload_stream, |
| 86 |
.destroy = s_aws_signable_trailing_headers_destroy, |
| 87 |
}; |
| 88 |
|
| 89 |
struct aws_signable *aws_signable_new_trailing_headers( |
| 90 |
struct aws_allocator *allocator, |
| 91 |
struct aws_http_headers *trailing_headers, |
| 92 |
struct aws_byte_cursor previous_signature) { |
| 93 |
|
| 94 |
struct aws_signable *signable = NULL; |
| 95 |
struct aws_signable_trailing_headers_impl *impl = NULL; |
| 96 |
aws_mem_acquire_many( |
| 97 |
allocator, 2, &signable, sizeof(struct aws_signable), &impl, sizeof(struct aws_signable_trailing_headers_impl)); |
| 98 |
|
| 99 |
AWS_ZERO_STRUCT(*signable); |
| 100 |
AWS_ZERO_STRUCT(*impl); |
| 101 |
|
| 102 |
|
| 103 |
aws_http_headers_acquire(trailing_headers); |
| 104 |
impl->trailing_headers = trailing_headers; |
| 105 |
signable->allocator = allocator; |
| 106 |
signable->vtable = &s_signable_trailing_headers_vtable; |
| 107 |
signable->impl = impl; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
size_t header_count = aws_http_headers_count(trailing_headers); |
| 113 |
if (aws_array_list_init_dynamic( |
| 114 |
&impl->headers, allocator, header_count, sizeof(struct aws_signable_property_list_pair))) { |
| 115 |
goto on_error; |
| 116 |
} |
| 117 |
|
| 118 |
for (size_t i = 0; i < header_count; ++i) { |
| 119 |
struct aws_http_header header; |
| 120 |
aws_http_headers_get_index(trailing_headers, i, &header); |
| 121 |
|
| 122 |
struct aws_signable_property_list_pair property = {.name = header.name, .value = header.value}; |
| 123 |
aws_array_list_push_back(&impl->headers, &property); |
| 124 |
} |
| 125 |
|
| 126 |
impl->previous_signature = aws_string_new_from_array(allocator, previous_signature.ptr, previous_signature.len); |
| 127 |
if (impl->previous_signature == NULL) { |
| 128 |
goto on_error; |
| 129 |
} |
| 130 |
|
| 131 |
return signable; |
| 132 |
|
| 133 |
on_error: |
| 134 |
|
| 135 |
aws_signable_destroy(signable); |
| 136 |
|
| 137 |
return NULL; |
| 138 |
} |