Skip to content

Commit 40d1c65

Browse files
authored
Use new helpers in aws-c-common (#282)
* hex-to-num table moved to aws-c-common * use new aws_string_new_from_cursor() helper fn
1 parent 4ca98b8 commit 40d1c65

File tree

6 files changed

+8
-32
lines changed

6 files changed

+8
-32
lines changed

source/connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ int aws_http_client_connect_internal(
908908
AWS_FATAL_ASSERT(options.proxy_options == NULL);
909909

910910
/* bootstrap_new() functions requires a null-terminated c-str */
911-
host_name = aws_string_new_from_array(options.allocator, options.host_name.ptr, options.host_name.len);
911+
host_name = aws_string_new_from_cursor(options.allocator, &options.host_name);
912912
if (!host_name) {
913913
goto error;
914914
}

source/connection_manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ struct aws_http_connection_manager *aws_http_connection_manager_new(
787787
aws_linked_list_init(&manager->idle_connections);
788788
aws_linked_list_init(&manager->pending_acquisitions);
789789

790-
manager->host = aws_string_new_from_array(allocator, options->host.ptr, options->host.len);
790+
manager->host = aws_string_new_from_cursor(allocator, &options->host);
791791
if (manager->host == NULL) {
792792
goto on_error;
793793
}

source/h2_decoder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ static struct aws_h2err s_process_header_field(
12581258
/* Buffer up pseudo-headers, we'll deliver them later once they're all validated. */
12591259
current_block->pseudoheader_compression[pseudoheader_enum] = header_field->compression;
12601260
current_block->pseudoheader_values[pseudoheader_enum] =
1261-
aws_string_new_from_array(decoder->alloc, header_field->value.ptr, header_field->value.len);
1261+
aws_string_new_from_cursor(decoder->alloc, &header_field->value);
12621262
if (!current_block->pseudoheader_values[pseudoheader_enum]) {
12631263
return aws_h2err_from_last_error();
12641264
}

source/proxy_connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct aws_http_proxy_user_data *aws_http_proxy_user_data_new(
7171
user_data->state = AWS_PBS_SOCKET_CONNECT;
7272
user_data->error_code = AWS_ERROR_SUCCESS;
7373

74-
user_data->original_host = aws_string_new_from_array(allocator, options->host_name.ptr, options->host_name.len);
74+
user_data->original_host = aws_string_new_from_cursor(allocator, &options->host_name);
7575
if (user_data->original_host == NULL) {
7676
goto on_error;
7777
}

source/request_response.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static int s_set_string_from_cursor(
343343
/* If the cursor is empty, set dst to NULL */
344344
struct aws_string *new_str;
345345
if (cursor.len) {
346-
new_str = aws_string_new_from_array(alloc, cursor.ptr, cursor.len);
346+
new_str = aws_string_new_from_cursor(alloc, &cursor);
347347
if (!new_str) {
348348
return AWS_OP_ERR;
349349
}

source/strutil.c

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,6 @@
44
*/
55
#include <aws/http/private/strutil.h>
66

7-
/* Lookup from '0' -> 0, 'f' -> 0xf, 'F' -> 0xF, etc
8-
* invalid characters have value 255 */
9-
/* clang-format off */
10-
static const uint8_t s_ascii_to_num_table[256] = {
11-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
12-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
13-
255, 255,
14-
/* 0 - 9 */
15-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
16-
255, 255, 255, 255, 255, 255, 255,
17-
/* A - F */
18-
0xA, 0xB, 0xC, 0xD, 0xE, 0xF,
19-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
20-
255, 255, 255,
21-
/* a - f */
22-
0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
23-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
24-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
25-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
26-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
27-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
28-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
29-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
30-
};
31-
/* clang-format on */
32-
337
static int s_read_unsigned(struct aws_byte_cursor cursor, uint64_t *dst, uint8_t base) {
348
uint64_t val = 0;
359
*dst = 0;
@@ -38,10 +12,12 @@ static int s_read_unsigned(struct aws_byte_cursor cursor, uint64_t *dst, uint8_t
3812
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
3913
}
4014

15+
const uint8_t *hex_to_num_table = aws_lookup_table_hex_to_num_get();
16+
4117
/* read from left to right */
4218
for (size_t i = 0; i < cursor.len; ++i) {
4319
const uint8_t c = cursor.ptr[i];
44-
const uint8_t cval = s_ascii_to_num_table[c];
20+
const uint8_t cval = hex_to_num_table[c];
4521
if (cval >= base) {
4622
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
4723
}

0 commit comments

Comments
 (0)