| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include "test_signable.h" |
| 7 |
|
| 8 |
#include <aws/auth/signable.h> |
| 9 |
#include <aws/common/string.h> |
| 10 |
|
| 11 |
struct aws_signable_test_impl { |
| 12 |
struct aws_input_stream *payload; |
| 13 |
struct aws_array_list headers; |
| 14 |
struct aws_byte_cursor uri; |
| 15 |
struct aws_byte_cursor method; |
| 16 |
}; |
| 17 |
|
| 18 |
static int s_aws_signable_test_get_property( |
| 19 |
const struct aws_signable *signable, |
| 20 |
const struct aws_string *name, |
| 21 |
struct aws_byte_cursor *out_value) { |
| 22 |
|
| 23 |
struct aws_signable_test_impl *impl = signable->impl; |
| 24 |
|
| 25 |
AWS_ZERO_STRUCT(*out_value); |
| 26 |
|
| 27 |
if (aws_string_eq(name, g_aws_http_uri_property_name)) { |
| 28 |
*out_value = impl->uri; |
| 29 |
} else if (aws_string_eq(name, g_aws_http_method_property_name)) { |
| 30 |
*out_value = impl->method; |
| 31 |
} else { |
| 32 |
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 33 |
} |
| 34 |
|
| 35 |
return AWS_OP_SUCCESS; |
| 36 |
} |
| 37 |
|
| 38 |
static int s_aws_signable_test_get_property_list( |
| 39 |
const struct aws_signable *signable, |
| 40 |
const struct aws_string *name, |
| 41 |
struct aws_array_list **out_list) { |
| 42 |
|
| 43 |
struct aws_signable_test_impl *impl = signable->impl; |
| 44 |
|
| 45 |
*out_list = NULL; |
| 46 |
|
| 47 |
if (aws_string_eq(name, g_aws_http_headers_property_list_name)) { |
| 48 |
*out_list = &impl->headers; |
| 49 |
} else { |
| 50 |
return aws_raise_error(AWS_ERROR_UNSUPPORTED_OPERATION); |
| 51 |
} |
| 52 |
|
| 53 |
return AWS_OP_SUCCESS; |
| 54 |
} |
| 55 |
|
| 56 |
static int s_aws_signable_test_get_payload_stream( |
| 57 |
const struct aws_signable *signable, |
| 58 |
struct aws_input_stream **out_input_stream) { |
| 59 |
struct aws_signable_test_impl *impl = signable->impl; |
| 60 |
|
| 61 |
*out_input_stream = impl->payload; |
| 62 |
|
| 63 |
return AWS_OP_SUCCESS; |
| 64 |
} |
| 65 |
|
| 66 |
static void s_aws_signable_test_destroy(struct aws_signable *signable) { |
| 67 |
if (signable == NULL) { |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
struct aws_signable_test_impl *impl = signable->impl; |
| 72 |
if (impl != NULL) { |
| 73 |
aws_array_list_clean_up(&impl->headers); |
| 74 |
} |
| 75 |
|
| 76 |
aws_mem_release(signable->allocator, signable); |
| 77 |
} |
| 78 |
|
| 79 |
static struct aws_signable_vtable s_signable_test_vtable = { |
| 80 |
.get_property = s_aws_signable_test_get_property, |
| 81 |
.get_property_list = s_aws_signable_test_get_property_list, |
| 82 |
.get_payload_stream = s_aws_signable_test_get_payload_stream, |
| 83 |
.destroy = s_aws_signable_test_destroy, |
| 84 |
}; |
| 85 |
|
| 86 |
struct aws_signable *aws_signable_new_test( |
| 87 |
struct aws_allocator *allocator, |
| 88 |
struct aws_byte_cursor *method, |
| 89 |
struct aws_byte_cursor *uri, |
| 90 |
struct aws_signable_property_list_pair *headers, |
| 91 |
size_t header_count, |
| 92 |
struct aws_input_stream *body_stream) { |
| 93 |
|
| 94 |
struct aws_signable *signable = NULL; |
| 95 |
struct aws_signable_test_impl *impl = NULL; |
| 96 |
aws_mem_acquire_many( |
| 97 |
allocator, 2, &signable, sizeof(struct aws_signable), &impl, sizeof(struct aws_signable_test_impl)); |
| 98 |
|
| 99 |
AWS_ZERO_STRUCT(*signable); |
| 100 |
AWS_ZERO_STRUCT(*impl); |
| 101 |
|
| 102 |
signable->allocator = allocator; |
| 103 |
signable->vtable = &s_signable_test_vtable; |
| 104 |
signable->impl = impl; |
| 105 |
|
| 106 |
if (aws_array_list_init_dynamic( |
| 107 |
&impl->headers, allocator, header_count, sizeof(struct aws_signable_property_list_pair))) { |
| 108 |
goto on_error; |
| 109 |
} |
| 110 |
|
| 111 |
for (size_t i = 0; i < header_count; ++i) { |
| 112 |
aws_array_list_push_back(&impl->headers, &headers[i]); |
| 113 |
} |
| 114 |
|
| 115 |
impl->payload = body_stream; |
| 116 |
impl->method = *method; |
| 117 |
impl->uri = *uri; |
| 118 |
|
| 119 |
return signable; |
| 120 |
|
| 121 |
on_error: |
| 122 |
|
| 123 |
aws_signable_destroy(signable); |
| 124 |
|
| 125 |
return NULL; |
| 126 |
} |