Debian Codegraph @

crt/aws-c-sdkutils/include/aws/sdkutils/private/endpoints_util.h

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #ifndef AWS_SDKUTILS_ENDPOINTS_EVAL_UTIL_H
7 #define AWS_SDKUTILS_ENDPOINTS_EVAL_UTIL_H
8
9 #include <aws/sdkutils/sdkutils.h>
10
11 struct aws_string;
12 struct aws_byte_buf;
13 struct aws_json_value;
14
15 /* Cursor that optionally owns underlying memory. */
16 struct aws_owning_cursor {
17 struct aws_byte_cursor cur;
18 struct aws_string *string;
19 };
20
21 /* Clones string and wraps it in owning cursor. */
22 AWS_SDKUTILS_API struct aws_owning_cursor aws_endpoints_owning_cursor_create(
23 struct aws_allocator *allocator,
24 const struct aws_string *str);
25 /* Creates new cursor that takes ownership of created string. */
26 AWS_SDKUTILS_API struct aws_owning_cursor aws_endpoints_owning_cursor_from_string(struct aws_string *str);
27 /* Clones memory pointer to by cursor and wraps in owning cursor */
28 AWS_SDKUTILS_API struct aws_owning_cursor aws_endpoints_owning_cursor_from_cursor(
29 struct aws_allocator *allocator,
30 const struct aws_byte_cursor cur);
31 /* Creates owning cursor with memory pointer set to NULL */
32 AWS_SDKUTILS_API struct aws_owning_cursor aws_endpoints_non_owning_cursor_create(struct aws_byte_cursor cur);
33
34 /* Cleans up memory associated with the cursor */
35 AWS_SDKUTILS_API void aws_owning_cursor_clean_up(struct aws_owning_cursor *cursor);
36
37 /*
38 * Determine whether label is a valid host label.
39 */
40 AWS_SDKUTILS_API bool aws_is_valid_host_label(struct aws_byte_cursor label, bool allow_subdomains);
41
42 /*
43 * Normalize uri path - make sure it starts and ends with /
44 * Will initialize out_normalized_path.
45 * In cases of error out_normalized_path will be uninitialized.
46 */
47 AWS_SDKUTILS_API int aws_byte_buf_init_from_normalized_uri_path(
48 struct aws_allocator *allocator,
49 struct aws_byte_cursor path,
50 struct aws_byte_buf *out_normalized_path);
51
52 /*
53 * Creates new string from json value.
54 * NULL in cases of error.
55 */
56 AWS_SDKUTILS_API struct aws_string *aws_string_new_from_json(
57 struct aws_allocator *allocator,
58 const struct aws_json_value *value);
59
60 /*
61 * Convenience helper for comparing byte cursors.
62 * Typeless for use with hash tables.
63 */
64 AWS_SDKUTILS_API bool aws_endpoints_byte_cursor_eq(const void *a, const void *b);
65
66 /*
67 * Helpers to do deep clean up of array list.
68 * TODO: move to aws-c-common?
69 */
70 typedef void(aws_array_callback_clean_up_fn)(void *value);
71 AWS_SDKUTILS_API void aws_array_list_deep_clean_up(
72 struct aws_array_list *array,
73 aws_array_callback_clean_up_fn on_clean_up_element);
74
75 /* Function that resolves template. */
76 typedef int(aws_endpoints_template_resolve_fn)(
77 struct aws_byte_cursor template_cursor,
78 void *user_data,
79 struct aws_owning_cursor *out_resolved);
80
81 /*
82 * Resolve templated string and write it out to buf.
83 * Will parse templated values (i.e. values enclosed in {}) and replace them with
84 * the value returned from resolve_callback.
85 * Note: callback must be able to support syntax for pathing through value (path
86 * provided after #).
87 * Will replace escaped template delimiters ({{ and }}) with single chars.
88 * Supports replacing templated values inside json strings (controlled by
89 * is_json), by ignoring json { and } chars.
90 */
91 AWS_SDKUTILS_API int aws_byte_buf_init_from_resolved_templated_string(
92 struct aws_allocator *allocator,
93 struct aws_byte_buf *out_buf,
94 struct aws_byte_cursor string,
95 aws_endpoints_template_resolve_fn resolve_callback,
96 void *user_data,
97 bool is_json);
98
99 /*
100 * Path through json structure and return final json node in out_value.
101 * In cases of error, error is returned and out_value is set to NULL.
102 * Array access out of bounds returns success, but set out_value to NULL (to be
103 * consistent with spec).
104 *
105 * Path is defined as a string of '.' delimited fields names, that can optionally
106 * end with [] to indicate indexing.
107 * Note: only last element can be indexed.
108 * ex. path "a.b.c[5]" results in going through a, b and then c and finally
109 * taking index of 5.
110 */
111 AWS_SDKUTILS_API int aws_path_through_json(
112 struct aws_allocator *allocator,
113 const struct aws_json_value *root,
114 struct aws_byte_cursor path,
115 const struct aws_json_value **out_value);
116
117 #endif /* AWS_SDKUTILS_ENDPOINTS_EVAL_UTIL_H */