From 5aae49f5c9c6b26aee0e6c84bc004549e0e8d830 Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Wed, 12 Feb 2020 16:22:24 -0800 Subject: [PATCH] Victor/http/move request to internal (#347) * http request moved to internal * moving http request methods to internal headers * rename status code with underscore * make all private functions have _ as starting * remove unused include --- sdk/core/core/CMakeLists.txt | 4 +- sdk/core/core/inc/az_credentials.h | 2 +- sdk/core/core/inc/az_http.h | 316 +++++++----------- sdk/core/core/inc/az_http_transport.h | 42 +++ sdk/core/core/internal/az_http_internal.h | 165 +++++++++ .../core/internal/az_http_pipeline_internal.h | 107 ------ sdk/core/core/src/az_aad.c | 16 +- sdk/core/core/src/az_aad_private.h | 2 +- sdk/core/core/src/az_credentials.c | 6 +- sdk/core/core/src/az_http_pipeline.c | 13 +- sdk/core/core/src/az_http_policy.c | 49 +-- sdk/core/core/src/az_http_private.h | 4 +- ...tp_request_builder.c => az_http_request.c} | 53 +-- ...p_response_parser.c => az_http_response.c} | 2 +- sdk/core/core/src/az_json_builder.c | 6 +- sdk/core/core/src/az_json_data.c | 10 +- sdk/core/core/src/az_json_get.c | 6 +- sdk/core/core/src/az_json_parser.c | 2 +- sdk/core/core/src/az_json_pointer.c | 4 +- sdk/core/core/src/az_json_string.c | 4 +- sdk/core/core/src/az_json_string_private.h | 8 +- sdk/core/core/src/az_log.c | 9 +- sdk/core/core/src/az_log_private.h | 4 +- sdk/core/core/src/az_span.c | 6 +- sdk/core/core/src/az_span_private.h | 6 +- sdk/core/core/test/main.c | 6 +- .../test/test_http_response_read_and_parse.c | 4 +- sdk/core/core/test/test_json_pointer.c | 46 +-- sdk/core/core/test/test_json_string.c | 20 +- sdk/core/core/test/test_log.c | 4 +- sdk/core/core/test/test_mut_span.c | 4 +- .../core/test/test_span_builder_replace.c | 32 +- sdk/keyvault/keyvault/inc/az_keyvault.h | 3 +- .../keyvault/src/az_keyvault_client.c | 110 +++--- sdk/storage/blobs/inc/az_storage_blobs.h | 3 +- .../blobs/src/az_storage_blobs_blob_client.c | 118 ++++--- sdk/storage/blobs/test/storage_blobs_poc.c | 6 +- sdk/transport_policies/curl/CMakeLists.txt | 2 +- sdk/transport_policies/curl/src/az_curl.c | 18 +- 39 files changed, 652 insertions(+), 570 deletions(-) create mode 100644 sdk/core/core/inc/az_http_transport.h create mode 100644 sdk/core/core/internal/az_http_internal.h delete mode 100644 sdk/core/core/internal/az_http_pipeline_internal.h rename sdk/core/core/src/{az_http_request_builder.c => az_http_request.c} (66%) rename sdk/core/core/src/{az_http_response_parser.c => az_http_response.c} (99%) diff --git a/sdk/core/core/CMakeLists.txt b/sdk/core/core/CMakeLists.txt index ccb1e3a8e6..99771f568d 100644 --- a/sdk/core/core/CMakeLists.txt +++ b/sdk/core/core/CMakeLists.txt @@ -13,8 +13,8 @@ add_library ( src/az_credentials.c src/az_http_pipeline.c src/az_http_policy.c - src/az_http_request_builder.c - src/az_http_response_parser.c + src/az_http_request.c + src/az_http_response.c src/az_json_builder.c src/az_json_get.c src/az_json_parser.c diff --git a/sdk/core/core/inc/az_credentials.h b/sdk/core/core/inc/az_credentials.h index 625c6b2d24..b1710ce039 100644 --- a/sdk/core/core/inc/az_credentials.h +++ b/sdk/core/core/inc/az_credentials.h @@ -25,7 +25,7 @@ typedef struct { } _az_token; typedef AZ_NODISCARD az_result ( - *_az_credential_apply_fn)(void * credential_options, az_http_request * ref_request); + *_az_credential_apply_fn)(void * credential_options, _az_http_request * ref_request); typedef AZ_NODISCARD az_result (*_az_credential_set_scopes_fn)(void * credential, az_span scopes); diff --git a/sdk/core/core/inc/az_http.h b/sdk/core/core/inc/az_http.h index 225c360139..91bfb5297e 100644 --- a/sdk/core/core/inc/az_http.h +++ b/sdk/core/core/inc/az_http.h @@ -16,6 +16,60 @@ enum { AZ_HTTP_URL_MAX_SIZE = 1024 * 2, }; +typedef az_span az_http_method; + +typedef struct { + struct { + az_http_method method; + az_span url; + int32_t query_start; + az_span headers; + int32_t max_headers; + int32_t retry_headers_start_byte_offset; + az_span body; + } _internal; +} _az_http_request; + +typedef enum { + AZ_HTTP_RESPONSE_KIND_STATUS_LINE = 0, + AZ_HTTP_RESPONSE_KIND_HEADER = 1, + AZ_HTTP_RESPONSE_KIND_BODY = 2, + AZ_HTTP_RESPONSE_KIND_EOF = 3, +} az_http_response_kind; + +typedef struct { + struct { + az_span http_response; + struct { + az_span remaining; // the remaining un-parsed portion of the original http_response. + az_http_response_kind next_kind; // after parsing an element, this is set to the next kind of + // thing we will be parsing. + } parser; + } _internal; +} az_http_response; + +// Required to define az_http_policy for using it to create policy process definition +typedef struct _az_http_policy _az_http_policy; + +typedef AZ_NODISCARD az_result (*_az_http_policy_process_fn)( + _az_http_policy * p_policies, + void * p_options, + _az_http_request * p_request, + az_http_response * p_response); + +struct _az_http_policy { + struct { + _az_http_policy_process_fn process; + void * p_options; + } _internal; +}; + +typedef struct { + struct { + _az_http_policy p_policies[10]; + } _internal; +} _az_http_pipeline; + typedef struct { // Services pass API versions in the header or in query parameters // true: api version is passed via headers @@ -59,212 +113,78 @@ AZ_NODISCARD AZ_INLINE az_http_policy_retry_options az_http_policy_retry_options }; } -typedef az_span az_http_method; - -typedef struct { - struct { - az_http_method method; - az_span url; - int32_t query_start; - az_span headers; - int32_t max_headers; - int32_t retry_headers_start_byte_offset; - // int32_t headers_end; - az_span body; - } _internal; -} az_http_request; - -AZ_INLINE az_http_method az_http_method_get() { return AZ_SPAN_FROM_STR("GET"); } -AZ_INLINE az_http_method az_http_method_head() { return AZ_SPAN_FROM_STR("HEAD"); } -AZ_INLINE az_http_method az_http_method_post() { return AZ_SPAN_FROM_STR("POST"); } -AZ_INLINE az_http_method az_http_method_put() { return AZ_SPAN_FROM_STR("PUT"); } -AZ_INLINE az_http_method az_http_method_delete() { return AZ_SPAN_FROM_STR("DELETE"); } -AZ_INLINE az_http_method az_http_method_patch() { return AZ_SPAN_FROM_STR("PATCH"); } - -/** - * @brief Format buffer as a http request containing URL and header spans. - * - * @param p_request HTTP request builder to initialize. - * @param method HTTP verb: `"GET"`, `"POST"`, etc. - * @param url Maximum URL length (see @ref az_http_request_builder_set_query_parameter). - * @param headers_buffer HTTP verb: `"GET"`, `"POST"`, etc. - * @param body URL. - * - * @return - * - *`AZ_OK`* success. - * - *`AZ_ERROR_BUFFER_OVERFLOW`* `buffer` does not have enough space to fit the `max_url_size`. - * - *`AZ_ERROR_ARG`* - * - `p_request` is _NULL_. - * - `buffer`, `method_verb`, or `initial_url` are invalid spans (see @ref az_span_is_valid). - * - `max_url_size` is less than `initial_url.size`. - */ -AZ_NODISCARD az_result az_http_request_init( - az_http_request * p_request, - az_http_method method, - az_span url, - az_span headers_buffer, - az_span body); - -/** - * @brief Adds path to url request. - * For instance, if url in request is `http://example.net?qp=1` and this function is called with - * path equals to `test`, then request url will be updated to `http://example.net/test?qp=1`. - * - * - * @param p_request http request builder reference - * @param path span to a path to be appended into url - * @return AZ_NODISCARD az_http_request_builder_append_path - */ -AZ_NODISCARD az_result az_http_request_append_path(az_http_request * p_request, az_span path); - -/** - * @brief Set query parameter. - * - * @param p_request HTTP request builder that holds the URL to set the query parameter to. - * @param name URL parameter name. - * @param value URL parameter value. - * - * @return - * - *`AZ_OK`* success. - * - *`AZ_ERROR_BUFFER_OVERFLOW`* the `URL` would grow past the `max_url_size`, should the - * parameter gets set. - * - *`AZ_ERROR_ARG`* - * - `p_request` is _NULL_. - * - `name` or `value` are invalid spans (see @ref az_span_is_valid). - * - `name` or `value` are empty. - * - `name`'s or `value`'s buffer overlap resulting `url`'s buffer. - */ -AZ_NODISCARD az_result -az_http_request_set_query_parameter(az_http_request * p_request, az_span name, az_span value); - -/** - * @brief Add a new HTTP header for the request. - * - * @param p_request HTTP request builder that holds the URL to set the query parameter to. - * @param key Header name (e.g. `"Content-Type"`). - * @param value Header value (e.g. `"application/x-www-form-urlencoded"`). - * - * @return - * - *`AZ_OK`* success. - * - *`AZ_ERROR_BUFFER_OVERFLOW`* there isn't enough space in the `p_request->buffer` to add a - * header. - * - *`AZ_ERROR_ARG`* - * - `p_request` is _NULL_. - * - `key` or `value` are invalid spans (see @ref az_span_is_valid). - * - `key` or `value` are empty. - * - `name`'s or `value`'s buffer overlap resulting `url`'s buffer. - */ -AZ_NODISCARD az_result -az_http_request_append_header(az_http_request * p_request, az_span key, az_span value); - -/** - * @brief Get the HTTP header by index. - * - * @param p_request HTTP request builder. - * @param index Index of the HTTP header to get from the builder. - * @param out_result Pointer to write the result to. - * - * @return - * - *`AZ_OK`* success. - * - *`AZ_ERROR_ARG`* - * - `p_request` or `out_result` are _NULL_. - * - `index` is out of range. - */ -AZ_NODISCARD az_result -az_http_request_get_header(az_http_request const * p_request, int32_t index, az_pair * out_result); - -typedef enum { - AZ_HTTP_RESPONSE_KIND_STATUS_LINE = 0, - AZ_HTTP_RESPONSE_KIND_HEADER = 1, - AZ_HTTP_RESPONSE_KIND_BODY = 2, - AZ_HTTP_RESPONSE_KIND_EOF = 3, -} az_http_response_kind; - -typedef struct { - struct { - az_span http_response; - struct { - az_span remaining; // the remaining un-parsed portion of the original http_response. - az_http_response_kind next_kind; // after parsing an element, this is set to the next kind of - // thing we will be parsing. - } parser; - } _internal; -} az_http_response; - -/////////////////////////////////////////////// - typedef enum { // 1xx (information) Status Codes: - AZ_HTTP_STATUS_CODE_CONTINUE = 100, - AZ_HTTP_STATUS_CODE_SWITCHING_PROTOCOLS = 101, - AZ_HTTP_STATUS_CODE_PROCESSING = 102, - AZ_HTTP_STATUS_CODE_EARLY_HINTS = 103, + _AZ_HTTP_STATUS_CODE_CONTINUE = 100, + _AZ_HTTP_STATUS_CODE_SWITCHING_PROTOCOLS = 101, + _AZ_HTTP_STATUS_CODE_PROCESSING = 102, + _AZ_HTTP_STATUS_CODE_EARLY_HINTS = 103, // 2xx (successful) Status Codes: - AZ_HTTP_STATUS_CODE_OK = 200, - AZ_HTTP_STATUS_CODE_CREATED = 201, - AZ_HTTP_STATUS_CODE_ACCEPTED = 202, - AZ_HTTP_STATUS_CODE_NON_AUTHORITATIVE_INFORMATION = 203, - AZ_HTTP_STATUS_CODE_NO_CONTENT = 204, - AZ_HTTP_STATUS_CODE_RESET_CONTENT = 205, - AZ_HTTP_STATUS_CODE_PARTIAL_CONTENT = 206, - AZ_HTTP_STATUS_CODE_MULTI_STATUS = 207, - AZ_HTTP_STATUS_CODE_ALREADY_REPORTED = 208, - AZ_HTTP_STATUS_CODE_IM_USED = 226, + _AZ_HTTP_STATUS_CODE_OK = 200, + _AZ_HTTP_STATUS_CODE_CREATED = 201, + _AZ_HTTP_STATUS_CODE_ACCEPTED = 202, + _AZ_HTTP_STATUS_CODE_NON_AUTHORITATIVE_INFORMATION = 203, + _AZ_HTTP_STATUS_CODE_NO_CONTENT = 204, + _AZ_HTTP_STATUS_CODE_RESET_CONTENT = 205, + _AZ_HTTP_STATUS_CODE_PARTIAL_CONTENT = 206, + _AZ_HTTP_STATUS_CODE_MULTI_STATUS = 207, + _AZ_HTTP_STATUS_CODE_ALREADY_REPORTED = 208, + _AZ_HTTP_STATUS_CODE_IM_USED = 226, // 3xx (redirection) Status Codes: - AZ_HTTP_STATUS_CODE_MULTIPLE_CHOICES = 300, - AZ_HTTP_STATUS_CODE_MOVED_PERMANENTLY = 301, - AZ_HTTP_STATUS_CODE_FOUND = 302, - AZ_HTTP_STATUS_CODE_SEE_OTHER = 303, - AZ_HTTP_STATUS_CODE_NOT_MODIFIED = 304, - AZ_HTTP_STATUS_CODE_USE_PROXY = 305, - AZ_HTTP_STATUS_CODE_TEMPORARY_REDIRECT = 307, - AZ_HTTP_STATUS_CODE_PERMANENT_REDIRECT = 308, + _AZ_HTTP_STATUS_CODE_MULTIPLE_CHOICES = 300, + _AZ_HTTP_STATUS_CODE_MOVED_PERMANENTLY = 301, + _AZ_HTTP_STATUS_CODE_FOUND = 302, + _AZ_HTTP_STATUS_CODE_SEE_OTHER = 303, + _AZ_HTTP_STATUS_CODE_NOT_MODIFIED = 304, + _AZ_HTTP_STATUS_CODE_USE_PROXY = 305, + _AZ_HTTP_STATUS_CODE_TEMPORARY_REDIRECT = 307, + _AZ_HTTP_STATUS_CODE_PERMANENT_REDIRECT = 308, // 4xx (client error) Status Codes: - AZ_HTTP_STATUS_CODE_BAD_REQUEST = 400, - AZ_HTTP_STATUS_CODE_UNAUTHORIZED = 401, - AZ_HTTP_STATUS_CODE_PAYMENT_REQUIRED = 402, - AZ_HTTP_STATUS_CODE_FORBIDDEN = 403, - AZ_HTTP_STATUS_CODE_NOT_FOUND = 404, - AZ_HTTP_STATUS_CODE_METHOD_NOT_ALLOWED = 405, - AZ_HTTP_STATUS_CODE_NOT_ACCEPTABLE = 406, - AZ_HTTP_STATUS_CODE_PROXY_AUTHENTICATION_REQUIRED = 407, - AZ_HTTP_STATUS_CODE_REQUEST_TIMEOUT = 408, - AZ_HTTP_STATUS_CODE_CONFLICT = 409, - AZ_HTTP_STATUS_CODE_GONE = 410, - AZ_HTTP_STATUS_CODE_LENGTH_REQUIRED = 411, - AZ_HTTP_STATUS_CODE_PRECONDITION_FAILED = 412, - AZ_HTTP_STATUS_CODE_PAYLOAD_TOO_LARGE = 413, - AZ_HTTP_STATUS_CODE_URI_TOO_LONG = 414, - AZ_HTTP_STATUS_CODE_UNSUPPORTED_MEDIA_TYPE = 415, - AZ_HTTP_STATUS_CODE_RANGE_NOT_SATISFIABLE = 416, - AZ_HTTP_STATUS_CODE_EXPECTATION_FAILED = 417, - AZ_HTTP_STATUS_CODE_MISDIRECTED_REQUEST = 421, - AZ_HTTP_STATUS_CODE_UNPROCESSABLE_ENTITY = 422, - AZ_HTTP_STATUS_CODE_LOCKED = 423, - AZ_HTTP_STATUS_CODE_FAILED_DEPENDENCY = 424, - AZ_HTTP_STATUS_CODE_TOO_EARLY = 425, - AZ_HTTP_STATUS_CODE_UPGRADE_REQUIRED = 426, - AZ_HTTP_STATUS_CODE_PRECONDITION_REQUIRED = 428, - AZ_HTTP_STATUS_CODE_TOO_MANY_REQUESTS = 429, - AZ_HTTP_STATUS_CODE_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, - AZ_HTTP_STATUS_CODE_UNAVAILABLE_FOR_LEGAL_REASONS = 451, + _AZ_HTTP_STATUS_CODE_BAD_REQUEST = 400, + _AZ_HTTP_STATUS_CODE_UNAUTHORIZED = 401, + _AZ_HTTP_STATUS_CODE_PAYMENT_REQUIRED = 402, + _AZ_HTTP_STATUS_CODE_FORBIDDEN = 403, + _AZ_HTTP_STATUS_CODE_NOT_FOUND = 404, + _AZ_HTTP_STATUS_CODE_METHOD_NOT_ALLOWED = 405, + _AZ_HTTP_STATUS_CODE_NOT_ACCEPTABLE = 406, + _AZ_HTTP_STATUS_CODE_PROXY_AUTHENTICATION_REQUIRED = 407, + _AZ_HTTP_STATUS_CODE_REQUEST_TIMEOUT = 408, + _AZ_HTTP_STATUS_CODE_CONFLICT = 409, + _AZ_HTTP_STATUS_CODE_GONE = 410, + _AZ_HTTP_STATUS_CODE_LENGTH_REQUIRED = 411, + _AZ_HTTP_STATUS_CODE_PRECONDITION_FAILED = 412, + _AZ_HTTP_STATUS_CODE_PAYLOAD_TOO_LARGE = 413, + _AZ_HTTP_STATUS_CODE_URI_TOO_LONG = 414, + _AZ_HTTP_STATUS_CODE_UNSUPPORTED_MEDIA_TYPE = 415, + _AZ_HTTP_STATUS_CODE_RANGE_NOT_SATISFIABLE = 416, + _AZ_HTTP_STATUS_CODE_EXPECTATION_FAILED = 417, + _AZ_HTTP_STATUS_CODE_MISDIRECTED_REQUEST = 421, + _AZ_HTTP_STATUS_CODE_UNPROCESSABLE_ENTITY = 422, + _AZ_HTTP_STATUS_CODE_LOCKED = 423, + _AZ_HTTP_STATUS_CODE_FAILED_DEPENDENCY = 424, + _AZ_HTTP_STATUS_CODE_TOO_EARLY = 425, + _AZ_HTTP_STATUS_CODE_UPGRADE_REQUIRED = 426, + _AZ_HTTP_STATUS_CODE_PRECONDITION_REQUIRED = 428, + _AZ_HTTP_STATUS_CODE_TOO_MANY_REQUESTS = 429, + _AZ_HTTP_STATUS_CODE_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, + _AZ_HTTP_STATUS_CODE_UNAVAILABLE_FOR_LEGAL_REASONS = 451, // 5xx (server error) Status Codes: - AZ_HTTP_STATUS_CODE_INTERNAL_SERVER_ERROR = 500, - AZ_HTTP_STATUS_CODE_NOT_IMPLEMENTED = 501, - AZ_HTTP_STATUS_CODE_BAD_GATEWAY = 502, - AZ_HTTP_STATUS_CODE_SERVICE_UNAVAILABLE = 503, - AZ_HTTP_STATUS_CODE_GATEWAY_TIMEOUT = 504, - AZ_HTTP_STATUS_CODE_HTTP_VERSION_NOT_SUPPORTED = 505, - AZ_HTTP_STATUS_CODE_VARIANT_ALSO_NEGOTIATES = 506, - AZ_HTTP_STATUS_CODE_INSUFFICIENT_STORAGE = 507, - AZ_HTTP_STATUS_CODE_LOOP_DETECTED = 508, - AZ_HTTP_STATUS_CODE_NOT_EXTENDED = 510, - AZ_HTTP_STATUS_CODE_NETWORK_AUTHENTICATION_REQUIRED = 511, -} az_http_status_code; + _AZ_HTTP_STATUS_CODE_INTERNAL_SERVER_ERROR = 500, + _AZ_HTTP_STATUS_CODE_NOT_IMPLEMENTED = 501, + _AZ_HTTP_STATUS_CODE_BAD_GATEWAY = 502, + _AZ_HTTP_STATUS_CODE_SERVICE_UNAVAILABLE = 503, + _AZ_HTTP_STATUS_CODE_GATEWAY_TIMEOUT = 504, + _AZ_HTTP_STATUS_CODE_HTTP_VERSION_NOT_SUPPORTED = 505, + _AZ_HTTP_STATUS_CODE_VARIANT_ALSO_NEGOTIATES = 506, + _AZ_HTTP_STATUS_CODE_INSUFFICIENT_STORAGE = 507, + _AZ_HTTP_STATUS_CODE_LOOP_DETECTED = 508, + _AZ_HTTP_STATUS_CODE_NOT_EXTENDED = 510, + _AZ_HTTP_STATUS_CODE_NETWORK_AUTHENTICATION_REQUIRED = 511, +} _az_http_status_code; /** * An HTTP response status line @@ -274,7 +194,7 @@ typedef enum { typedef struct { uint8_t major_version; uint8_t minor_version; - az_http_status_code status_code; + _az_http_status_code status_code; az_span reason_phrase; } az_http_response_status_line; @@ -340,7 +260,7 @@ AZ_NODISCARD AZ_INLINE az_result az_http_response_reset(az_http_response * self) } typedef AZ_NODISCARD az_result ( - *az_http_client_send_request_fn)(az_http_request * p_request, az_http_response * p_response); + *az_http_client_send_request_fn)(_az_http_request * p_request, az_http_response * p_response); typedef struct { struct { diff --git a/sdk/core/core/inc/az_http_transport.h b/sdk/core/core/inc/az_http_transport.h new file mode 100644 index 0000000000..fe627d65c5 --- /dev/null +++ b/sdk/core/core/inc/az_http_transport.h @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#ifndef _az_HTTP_TRANSPORT_H +#define _az_HTTP_TRANSPORT_H + +#include + +#include <_az_cfg_prefix.h> + +AZ_INLINE az_http_method az_http_method_get() { return AZ_SPAN_FROM_STR("GET"); } +AZ_INLINE az_http_method az_http_method_head() { return AZ_SPAN_FROM_STR("HEAD"); } +AZ_INLINE az_http_method az_http_method_post() { return AZ_SPAN_FROM_STR("POST"); } +AZ_INLINE az_http_method az_http_method_put() { return AZ_SPAN_FROM_STR("PUT"); } +AZ_INLINE az_http_method az_http_method_delete() { return AZ_SPAN_FROM_STR("DELETE"); } +AZ_INLINE az_http_method az_http_method_patch() { return AZ_SPAN_FROM_STR("PATCH"); } + +/** + * @brief Get the HTTP header by index. + * + * @param p_request HTTP request builder. + * @param index Index of the HTTP header to get from the builder. + * @param out_result Pointer to write the result to. + * + * @return + * - *`AZ_OK`* success. + * - *`AZ_ERROR_ARG`* + * - `p_request` or `out_result` are _NULL_. + * - `index` is out of range. + */ +AZ_NODISCARD az_result +az_http_request_get_header(_az_http_request * p_request, int32_t index, az_pair * out_result); + +AZ_NODISCARD az_result az_http_request_get_parts( + _az_http_request * p_request, + az_http_method * out_method, + az_span * out_url, + az_span * body); + +#include <_az_cfg_suffix.h> + +#endif diff --git a/sdk/core/core/internal/az_http_internal.h b/sdk/core/core/internal/az_http_internal.h new file mode 100644 index 0000000000..da622e48cc --- /dev/null +++ b/sdk/core/core/internal/az_http_internal.h @@ -0,0 +1,165 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#ifndef _az_HTTP_INTERNAL_H +#define _az_HTTP_INTERNAL_H + +#include +#include + +#include <_az_cfg_prefix.h> + +// PipelinePolicies +// Policies are non-allocating caveat the TransportPolicy +// Transport p_policies can only allocate if the transport layer they call allocates +// Client -> +// ===HttpPipelinePolicies=== +// UniqueRequestID +// Retry +// Authentication +// Logging +// Buffer Response +// Distributed Tracing +// TransportPolicy +// ===Transport Layer=== +// PipelinePolicies must implement the process function +// + +// Start the pipeline +AZ_NODISCARD az_result az_http_pipeline_process( + _az_http_pipeline * pipeline, + _az_http_request * p_request, + az_http_response * p_response); + +AZ_NODISCARD az_result az_http_pipeline_policy_apiversion( + _az_http_policy * p_policies, + void * p_data, + _az_http_request * p_request, + az_http_response * p_response); + +AZ_NODISCARD az_result az_http_pipeline_policy_uniquerequestid( + _az_http_policy * p_policies, + void * p_data, + _az_http_request * p_request, + az_http_response * p_response); + +AZ_NODISCARD az_result az_http_pipeline_policy_telemetry( + _az_http_policy * p_policies, + void * p_options, + _az_http_request * p_request, + az_http_response * p_response); + +AZ_NODISCARD az_result az_http_pipeline_policy_retry( + _az_http_policy * p_policies, + void * p_data, + _az_http_request * p_request, + az_http_response * p_response); + +AZ_NODISCARD az_result az_http_pipeline_policy_credential( + _az_http_policy * p_policies, + void * p_data, + _az_http_request * p_request, + az_http_response * p_response); + +AZ_NODISCARD az_result az_http_pipeline_policy_logging( + _az_http_policy * p_policies, + void * p_data, + _az_http_request * p_request, + az_http_response * p_response); + +AZ_NODISCARD az_result az_http_pipeline_policy_bufferresponse( + _az_http_policy * p_policies, + void * p_data, + _az_http_request * p_request, + az_http_response * p_response); + +AZ_NODISCARD az_result az_http_pipeline_policy_distributedtracing( + _az_http_policy * p_policies, + void * p_data, + _az_http_request * p_request, + az_http_response * p_response); + +AZ_NODISCARD az_result az_http_pipeline_policy_transport( + _az_http_policy * p_policies, + void * p_data, + _az_http_request * p_request, + az_http_response * p_response); + +/** + * @brief Format buffer as a http request containing URL and header spans. + * + * @param p_request HTTP request builder to initialize. + * @param method HTTP verb: `"GET"`, `"POST"`, etc. + * @param url Maximum URL length (see @ref az_http_request_builder_set_query_parameter). + * @param headers_buffer HTTP verb: `"GET"`, `"POST"`, etc. + * @param body URL. + * + * @return + * - *`AZ_OK`* success. + * - *`AZ_ERROR_BUFFER_OVERFLOW`* `buffer` does not have enough space to fit the `max_url_size`. + * - *`AZ_ERROR_ARG`* + * - `p_request` is _NULL_. + * - `buffer`, `method_verb`, or `initial_url` are invalid spans (see @ref az_span_is_valid). + * - `max_url_size` is less than `initial_url.size`. + */ +AZ_NODISCARD az_result az_http_request_init( + _az_http_request * p_request, + az_http_method method, + az_span url, + az_span headers_buffer, + az_span body); + +/** + * @brief Adds path to url request. + * For instance, if url in request is `http://example.net?qp=1` and this function is called with + * path equals to `test`, then request url will be updated to `http://example.net/test?qp=1`. + * + * + * @param p_request http request builder reference + * @param path span to a path to be appended into url + * @return AZ_NODISCARD az_http_request_builder_append_path + */ +AZ_NODISCARD az_result az_http_request_append_path(_az_http_request * p_request, az_span path); + +/** + * @brief Set query parameter. + * + * @param p_request HTTP request builder that holds the URL to set the query parameter to. + * @param name URL parameter name. + * @param value URL parameter value. + * + * @return + * - *`AZ_OK`* success. + * - *`AZ_ERROR_BUFFER_OVERFLOW`* the `URL` would grow past the `max_url_size`, should the + * parameter gets set. + * - *`AZ_ERROR_ARG`* + * - `p_request` is _NULL_. + * - `name` or `value` are invalid spans (see @ref az_span_is_valid). + * - `name` or `value` are empty. + * - `name`'s or `value`'s buffer overlap resulting `url`'s buffer. + */ +AZ_NODISCARD az_result +az_http_request_set_query_parameter(_az_http_request * p_request, az_span name, az_span value); + +/** + * @brief Add a new HTTP header for the request. + * + * @param p_request HTTP request builder that holds the URL to set the query parameter to. + * @param key Header name (e.g. `"Content-Type"`). + * @param value Header value (e.g. `"application/x-www-form-urlencoded"`). + * + * @return + * - *`AZ_OK`* success. + * - *`AZ_ERROR_BUFFER_OVERFLOW`* there isn't enough space in the `p_request->buffer` to add a + * header. + * - *`AZ_ERROR_ARG`* + * - `p_request` is _NULL_. + * - `key` or `value` are invalid spans (see @ref az_span_is_valid). + * - `key` or `value` are empty. + * - `name`'s or `value`'s buffer overlap resulting `url`'s buffer. + */ +AZ_NODISCARD az_result +az_http_request_append_header(_az_http_request * p_request, az_span key, az_span value); + +#include <_az_cfg_suffix.h> +#endif diff --git a/sdk/core/core/internal/az_http_pipeline_internal.h b/sdk/core/core/internal/az_http_pipeline_internal.h deleted file mode 100644 index 34c55fef76..0000000000 --- a/sdk/core/core/internal/az_http_pipeline_internal.h +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// SPDX-License-Identifier: MIT - -#ifndef _az_HTTP_PIPELINE_INTERNAL_H -#define _az_HTTP_PIPELINE_INTERNAL_H - -#include -#include - -#include <_az_cfg_prefix.h> - -// PipelinePolicies -// Policies are non-allocating caveat the TransportPolicy -// Transport p_policies can only allocate if the transport layer they call allocates -// Client -> -// ===HttpPipelinePolicies=== -// UniqueRequestID -// Retry -// Authentication -// Logging -// Buffer Response -// Distributed Tracing -// TransportPolicy -// ===Transport Layer=== -// PipelinePolicies must implement the process function -// - -// Required to define az_http_policy for using it to create policy process definition -typedef struct az_http_policy az_http_policy; - -typedef AZ_NODISCARD az_result (*az_http_policy_process_fn)( - az_http_policy * p_policies, - void * p_options, - az_http_request * p_request, - az_http_response * p_response); - -struct az_http_policy { - az_http_policy_process_fn process; - void * p_options; -}; - -typedef struct { - az_http_policy p_policies[10]; -} az_http_pipeline; - -// Start the pipeline -AZ_NODISCARD az_result az_http_pipeline_process( - az_http_pipeline * pipeline, - az_http_request * p_request, - az_http_response * p_response); - -AZ_NODISCARD az_result az_http_pipeline_policy_apiversion( - az_http_policy * p_policies, - void * p_data, - az_http_request * p_request, - az_http_response * p_response); - -AZ_NODISCARD az_result az_http_pipeline_policy_uniquerequestid( - az_http_policy * p_policies, - void * p_data, - az_http_request * p_request, - az_http_response * p_response); - -AZ_NODISCARD az_result az_http_pipeline_policy_telemetry( - az_http_policy * p_policies, - void * p_options, - az_http_request * p_request, - az_http_response * p_response); - -AZ_NODISCARD az_result az_http_pipeline_policy_retry( - az_http_policy * p_policies, - void * p_data, - az_http_request * p_request, - az_http_response * p_response); - -AZ_NODISCARD az_result az_http_pipeline_policy_credential( - az_http_policy * p_policies, - void * p_data, - az_http_request * p_request, - az_http_response * p_response); - -AZ_NODISCARD az_result az_http_pipeline_policy_logging( - az_http_policy * p_policies, - void * p_data, - az_http_request * p_request, - az_http_response * p_response); - -AZ_NODISCARD az_result az_http_pipeline_policy_bufferresponse( - az_http_policy * p_policies, - void * p_data, - az_http_request * p_request, - az_http_response * p_response); - -AZ_NODISCARD az_result az_http_pipeline_policy_distributedtracing( - az_http_policy * p_policies, - void * p_data, - az_http_request * p_request, - az_http_response * p_response); - -AZ_NODISCARD az_result az_http_pipeline_policy_transport( - az_http_policy * p_policies, - void * p_data, - az_http_request * p_request, - az_http_response * p_response); - -#include <_az_cfg_suffix.h> -#endif diff --git a/sdk/core/core/src/az_aad.c b/sdk/core/core/src/az_aad.c index 25ea15c22d..6d20291e92 100644 --- a/sdk/core/core/src/az_aad.c +++ b/sdk/core/core/src/az_aad.c @@ -2,7 +2,8 @@ // SPDX-License-Identifier: MIT #include "az_aad_private.h" -#include +#include +#include #include #include #include @@ -85,7 +86,7 @@ AZ_NODISCARD az_result _az_aad_build_body( AZ_NODISCARD az_result _az_aad_request_token( az_http_transport_options * http_transport_options, - az_http_request * ref_request, + _az_http_request * ref_request, _az_token * out_token) { // FIXME: If you uncomment the line below, we'll start getting HTTP 400 Bad Request instead of 200 // OK. I suspect, it is because there's a bug in the code that adds headers. Could be something @@ -100,19 +101,20 @@ AZ_NODISCARD az_result _az_aad_request_token( AZ_RETURN_IF_FAILED(az_http_response_init(&response, AZ_SPAN_FROM_BUFFER(response_buf))); // Make a HTTP request to get token - az_http_pipeline pipeline = { + _az_http_pipeline pipeline = (_az_http_pipeline){ ._internal ={ .p_policies = { - { .process = az_http_pipeline_policy_retry, .p_options = NULL }, - { .process = az_http_pipeline_policy_logging, .p_options = NULL }, - { .process = az_http_pipeline_policy_transport, .p_options = http_transport_options }, + {._internal = { .process = az_http_pipeline_policy_retry, .p_options = NULL }}, + {._internal = { .process = az_http_pipeline_policy_logging, .p_options = NULL }}, + {._internal = { .process = az_http_pipeline_policy_transport, .p_options = http_transport_options }}, }, + } }; AZ_RETURN_IF_FAILED(az_http_pipeline_process(&pipeline, ref_request, &response)); // If we failed to get the token, we return failure/ az_http_response_status_line status_line = { 0 }; AZ_RETURN_IF_FAILED(az_http_response_get_status_line(&response, &status_line)); - if (status_line.status_code != AZ_HTTP_STATUS_CODE_OK) { + if (status_line.status_code != _AZ_HTTP_STATUS_CODE_OK) { return AZ_ERROR_HTTP_AUTHENTICATION_FAILED; } diff --git a/sdk/core/core/src/az_aad_private.h b/sdk/core/core/src/az_aad_private.h index 14fe8260a4..adb6e8cfe4 100644 --- a/sdk/core/core/src/az_aad_private.h +++ b/sdk/core/core/src/az_aad_private.h @@ -31,7 +31,7 @@ AZ_NODISCARD az_result _az_aad_build_body( AZ_NODISCARD az_result _az_aad_request_token( az_http_transport_options * http_transport_options, - az_http_request * request, + _az_http_request * request, _az_token * out_token); AZ_NODISCARD bool _az_token_expired(_az_token const * token); diff --git a/sdk/core/core/src/az_credentials.c b/sdk/core/core/src/az_credentials.c index c762f6aee8..1fe9da2fdd 100644 --- a/sdk/core/core/src/az_credentials.c +++ b/sdk/core/core/src/az_credentials.c @@ -4,6 +4,8 @@ #include "az_aad_private.h" #include #include +#include +#include #include @@ -25,7 +27,7 @@ _az_client_secret_credential_request_token(az_client_secret_credential * credent &body)); uint8_t header_buf[_az_AAD_REQUEST_HEADER_BUF_SIZE]; - az_http_request request = { 0 }; + _az_http_request request = { 0 }; AZ_RETURN_IF_FAILED(az_http_request_init( &request, az_http_method_post(), url, AZ_SPAN_FROM_BUFFER(header_buf), body)); @@ -38,7 +40,7 @@ _az_client_secret_credential_request_token(az_client_secret_credential * credent // This gets called from the http credential policy static AZ_NODISCARD az_result _az_client_secret_credential_apply( az_client_secret_credential * credential, - az_http_request * ref_request) { + _az_http_request * ref_request) { if (_az_token_expired(&(credential->_internal.token))) { AZ_RETURN_IF_FAILED(_az_client_secret_credential_request_token(credential)); diff --git a/sdk/core/core/src/az_http_pipeline.c b/sdk/core/core/src/az_http_pipeline.c index 814be57689..e7550eb22c 100644 --- a/sdk/core/core/src/az_http_pipeline.c +++ b/sdk/core/core/src/az_http_pipeline.c @@ -3,18 +3,21 @@ #include #include -#include +#include #include <_az_cfg.h> AZ_NODISCARD az_result az_http_pipeline_process( - az_http_pipeline * pipeline, - az_http_request * p_request, + _az_http_pipeline * pipeline, + _az_http_request * p_request, az_http_response * p_response) { AZ_CONTRACT_ARG_NOT_NULL(p_request); AZ_CONTRACT_ARG_NOT_NULL(p_response); AZ_CONTRACT_ARG_NOT_NULL(pipeline); - return pipeline->p_policies[0].process( - &(pipeline->p_policies[1]), pipeline->p_policies[0].p_options, p_request, p_response); + return pipeline->_internal.p_policies[0]._internal.process( + &(pipeline->_internal.p_policies[1]), + pipeline->_internal.p_policies[0]._internal.p_options, + p_request, + p_response); } diff --git a/sdk/core/core/src/az_http_policy.c b/sdk/core/core/src/az_http_policy.c index 7460a9e6c3..c22073b9f2 100644 --- a/sdk/core/core/src/az_http_policy.c +++ b/sdk/core/core/src/az_http_policy.c @@ -4,7 +4,7 @@ #include "az_log_private.h" #include #include -#include +#include #include #include #include @@ -15,25 +15,26 @@ #include <_az_cfg.h> AZ_NODISCARD AZ_INLINE az_result az_http_pipeline_nextpolicy( - az_http_policy * p_policies, - az_http_request * p_request, + _az_http_policy * p_policies, + _az_http_request * p_request, az_http_response * p_response) { // Transport Policy is the last policy in the pipeline // it returns without calling nextpolicy - if (p_policies[0].process == NULL) { + if (p_policies[0]._internal.process == NULL) { return AZ_ERROR_HTTP_PIPELINE_INVALID_POLICY; } - return p_policies[0].process(&(p_policies[1]), p_policies[0].p_options, p_request, p_response); + return p_policies[0]._internal.process( + &(p_policies[1]), p_policies[0]._internal.p_options, p_request, p_response); } static const az_span AZ_MS_CLIENT_REQUESTID = AZ_SPAN_LITERAL_FROM_STR("x-ms-client-request-id"); static const az_span AZ_HTTP_HEADER_USER_AGENT = AZ_SPAN_LITERAL_FROM_STR("User-Agent"); AZ_NODISCARD az_result az_http_pipeline_policy_apiversion( - az_http_policy * p_policies, + _az_http_policy * p_policies, void * p_options, - az_http_request * p_request, + _az_http_request * p_request, az_http_response * p_response) { _az_http_policy_apiversion_options * options = (_az_http_policy_apiversion_options *)(p_options); @@ -50,9 +51,9 @@ AZ_NODISCARD az_result az_http_pipeline_policy_apiversion( } AZ_NODISCARD az_result az_http_pipeline_policy_uniquerequestid( - az_http_policy * p_policies, + _az_http_policy * p_policies, void * p_options, - az_http_request * p_request, + _az_http_request * p_request, az_http_response * p_response) { (void)p_options; @@ -67,9 +68,9 @@ AZ_NODISCARD az_result az_http_pipeline_policy_uniquerequestid( } AZ_NODISCARD az_result az_http_pipeline_policy_telemetry( - az_http_policy * p_policies, + _az_http_policy * p_policies, void * p_options, - az_http_request * p_request, + _az_http_request * p_request, az_http_response * p_response) { _az_http_policy_telemetry_options * options = (_az_http_policy_telemetry_options *)(p_options); @@ -81,9 +82,9 @@ AZ_NODISCARD az_result az_http_pipeline_policy_telemetry( } AZ_NODISCARD az_result az_http_pipeline_policy_retry( - az_http_policy * p_policies, + _az_http_policy * p_policies, void * p_options, - az_http_request * p_request, + _az_http_request * p_request, az_http_response * p_response) { (void)p_options; @@ -94,23 +95,23 @@ AZ_NODISCARD az_result az_http_pipeline_policy_retry( } AZ_INLINE AZ_NODISCARD az_result -_az_apply_credential(_az_credential * credential, az_http_request * ref_request) { +_az_apply_credential(_az_credential * credential, _az_http_request * ref_request) { return (credential->_internal.apply_credential)(credential, ref_request); } AZ_NODISCARD az_result az_http_pipeline_policy_credential( - az_http_policy * policies, + _az_http_policy * policies, void * options, - az_http_request * ref_request, + _az_http_request * ref_request, az_http_response * out_response) { AZ_RETURN_IF_FAILED(_az_apply_credential((_az_credential *)options, ref_request)); return az_http_pipeline_nextpolicy(policies, ref_request, out_response); } AZ_NODISCARD az_result az_http_pipeline_policy_logging( - az_http_policy * p_policies, + _az_http_policy * p_policies, void * p_options, - az_http_request * p_request, + _az_http_request * p_request, az_http_response * p_response) { (void)p_options; if (az_log_should_write(AZ_LOG_HTTP_REQUEST)) { @@ -132,9 +133,9 @@ AZ_NODISCARD az_result az_http_pipeline_policy_logging( } AZ_NODISCARD az_result az_http_pipeline_policy_bufferresponse( - az_http_policy * p_policies, + _az_http_policy * p_policies, void * p_options, - az_http_request * p_request, + _az_http_request * p_request, az_http_response * p_response) { (void)p_options; @@ -144,9 +145,9 @@ AZ_NODISCARD az_result az_http_pipeline_policy_bufferresponse( } AZ_NODISCARD az_result az_http_pipeline_policy_distributedtracing( - az_http_policy * p_policies, + _az_http_policy * p_policies, void * p_options, - az_http_request * p_request, + _az_http_request * p_request, az_http_response * p_response) { (void)p_options; @@ -155,9 +156,9 @@ AZ_NODISCARD az_result az_http_pipeline_policy_distributedtracing( } AZ_NODISCARD az_result az_http_pipeline_policy_transport( - az_http_policy * p_policies, + _az_http_policy * p_policies, void * p_options, - az_http_request * p_request, + _az_http_request * p_request, az_http_response * p_response) { (void)p_policies; // this is the last policy in the pipeline, we just void it diff --git a/sdk/core/core/src/az_http_private.h b/sdk/core/core/src/az_http_private.h index d6e07a35ee..62f67ecea5 100644 --- a/sdk/core/core/src/az_http_private.h +++ b/sdk/core/core/src/az_http_private.h @@ -23,13 +23,13 @@ * - *`AZ_ERROR_ARG`* `p_hrb` is _NULL_. */ AZ_NODISCARD AZ_INLINE az_result -_az_http_request_mark_retry_headers_start(az_http_request * p_hrb) { +_az_http_request_mark_retry_headers_start(_az_http_request * p_hrb) { AZ_CONTRACT_ARG_NOT_NULL(p_hrb); p_hrb->_internal.retry_headers_start_byte_offset = az_span_length(p_hrb->_internal.headers); return AZ_OK; } -AZ_NODISCARD AZ_INLINE az_result az_http_request_remove_retry_headers(az_http_request * p_hrb) { +AZ_NODISCARD AZ_INLINE az_result _az_http_request_remove_retry_headers(_az_http_request * p_hrb) { AZ_CONTRACT_ARG_NOT_NULL(p_hrb); az_span * headers_ptr = &p_hrb->_internal.headers; diff --git a/sdk/core/core/src/az_http_request_builder.c b/sdk/core/core/src/az_http_request.c similarity index 66% rename from sdk/core/core/src/az_http_request_builder.c rename to sdk/core/core/src/az_http_request.c index 0047ee4fb2..edec2e9680 100644 --- a/sdk/core/core/src/az_http_request_builder.c +++ b/sdk/core/core/src/az_http_request.c @@ -6,6 +6,7 @@ #include #include +#include #include @@ -16,7 +17,7 @@ AZ_NODISCARD az_result _az_is_question_mark(az_span slice) { } AZ_NODISCARD az_result az_http_request_init( - az_http_request * p_hrb, + _az_http_request * p_hrb, az_span method, az_span url, az_span headers_buffer, @@ -29,24 +30,25 @@ AZ_NODISCARD az_result az_http_request_init( int32_t query_start = 0; az_result url_with_query = _az_scan_until(url, _az_is_question_mark, &query_start); - *p_hrb = (az_http_request){ ._internal = { - .method = method, - .url = url, - /* query start is set to 0 if there is not a question mark so the - next time query parameter is appended, a question mark will be - added at url length */ - .query_start - = url_with_query == AZ_ERROR_ITEM_NOT_FOUND ? 0 : query_start, - .headers = headers_buffer, - .max_headers = az_span_capacity(headers_buffer) / sizeof(az_pair), - .retry_headers_start_byte_offset = 0, - .body = body, - } }; + *p_hrb + = (_az_http_request){ ._internal = { + .method = method, + .url = url, + /* query start is set to 0 if there is not a question mark so the + next time query parameter is appended, a question mark will be + added at url length */ + .query_start + = url_with_query == AZ_ERROR_ITEM_NOT_FOUND ? 0 : query_start, + .headers = headers_buffer, + .max_headers = az_span_capacity(headers_buffer) / sizeof(az_pair), + .retry_headers_start_byte_offset = 0, + .body = body, + } }; return AZ_OK; } -AZ_NODISCARD az_result az_http_request_append_path(az_http_request * p_hrb, az_span path) { +AZ_NODISCARD az_result az_http_request_append_path(_az_http_request * p_hrb, az_span path) { AZ_CONTRACT_ARG_NOT_NULL(p_hrb); // get the query starting point. @@ -60,9 +62,9 @@ AZ_NODISCARD az_result az_http_request_append_path(az_http_request * p_hrb, az_s * memory. */ AZ_RETURN_IF_FAILED( - az_span_replace(&p_hrb->_internal.url, query_start, query_start, AZ_SPAN_FROM_STR("/"))); + _az_span_replace(&p_hrb->_internal.url, query_start, query_start, AZ_SPAN_FROM_STR("/"))); query_start += 1; // a size of "/" - AZ_RETURN_IF_FAILED(az_span_replace(&p_hrb->_internal.url, query_start, query_start, path)); + AZ_RETURN_IF_FAILED(_az_span_replace(&p_hrb->_internal.url, query_start, query_start, path)); query_start += az_span_length(path); // update query start @@ -74,7 +76,7 @@ AZ_NODISCARD az_result az_http_request_append_path(az_http_request * p_hrb, az_s } AZ_NODISCARD az_result -az_http_request_set_query_parameter(az_http_request * p_hrb, az_span name, az_span value) { +az_http_request_set_query_parameter(_az_http_request * p_hrb, az_span name, az_span value) { AZ_CONTRACT_ARG_NOT_NULL(p_hrb); AZ_CONTRACT_ARG_VALID_SPAN(name); AZ_CONTRACT_ARG_VALID_SPAN(value); @@ -106,7 +108,7 @@ az_http_request_set_query_parameter(az_http_request * p_hrb, az_span name, az_sp } AZ_NODISCARD az_result -az_http_request_append_header(az_http_request * p_hrb, az_span key, az_span value) { +az_http_request_append_header(_az_http_request * p_hrb, az_span key, az_span value) { AZ_CONTRACT_ARG_NOT_NULL(p_hrb); AZ_CONTRACT_ARG_VALID_SPAN(key); AZ_CONTRACT_ARG_VALID_SPAN(value); @@ -123,7 +125,7 @@ az_http_request_append_header(az_http_request * p_hrb, az_span key, az_span valu } AZ_NODISCARD az_result -az_http_request_get_header(az_http_request const * p_hrb, int32_t index, az_pair * out_result) { +az_http_request_get_header(_az_http_request * p_hrb, int32_t index, az_pair * out_result) { AZ_CONTRACT_ARG_NOT_NULL(p_hrb); AZ_CONTRACT_ARG_NOT_NULL(out_result); @@ -134,3 +136,14 @@ az_http_request_get_header(az_http_request const * p_hrb, int32_t index, az_pair *out_result = ((az_pair *)az_span_ptr(p_hrb->_internal.headers))[index]; return AZ_OK; } + +AZ_NODISCARD az_result az_http_request_get_parts( + _az_http_request * p_request, + az_http_method * out_method, + az_span * out_url, + az_span * body) { + *out_method = p_request->_internal.method; + *out_url = p_request->_internal.url; + *body = p_request->_internal.body; + return AZ_OK; +} diff --git a/sdk/core/core/src/az_http_response_parser.c b/sdk/core/core/src/az_http_response.c similarity index 99% rename from sdk/core/core/src/az_http_response_parser.c rename to sdk/core/core/src/az_http_response.c index 45a930a44e..19fe247d13 100644 --- a/sdk/core/core/src/az_http_response_parser.c +++ b/sdk/core/core/src/az_http_response.c @@ -75,7 +75,7 @@ _az_get_http_status_line(az_span * self, az_http_response_status_line * out) { { uint64_t code = 0; AZ_RETURN_IF_FAILED(az_span_to_uint64(az_span_init(az_span_ptr(*self), 3, 3), &code)); - out->status_code = (az_http_status_code)code; + out->status_code = (_az_http_status_code)code; // move reader AZ_RETURN_IF_FAILED(az_span_slice(*self, 3, -1, self)); } diff --git a/sdk/core/core/src/az_json_builder.c b/sdk/core/core/src/az_json_builder.c index cbbf87577e..3ab6ce1948 100644 --- a/sdk/core/core/src/az_json_builder.c +++ b/sdk/core/core/src/az_json_builder.c @@ -31,7 +31,7 @@ AZ_NODISCARD az_result az_json_builder_write_span(az_json_builder * self, az_spa // check if the character has to be escaped. { - az_span const esc = az_json_esc_encode(c); + az_span const esc = _az_json_esc_encode(c); if (az_span_length(esc)) { AZ_RETURN_IF_FAILED(az_span_append(*json, esc, json)); continue; @@ -89,9 +89,7 @@ AZ_NODISCARD az_result az_json_builder_append_token(az_json_builder * self, az_j self->_internal.need_comma = true; return az_json_builder_write_span(self, token.value.span); } - default: { - return AZ_ERROR_ARG; - } + default: { return AZ_ERROR_ARG; } } } diff --git a/sdk/core/core/src/az_json_data.c b/sdk/core/core/src/az_json_data.c index b0d805c987..4eefb7ffcc 100644 --- a/sdk/core/core/src/az_json_data.c +++ b/sdk/core/core/src/az_json_data.c @@ -66,7 +66,7 @@ _az_span_aligned_append(az_span * builder, _az_data data, void const ** out) { // alignment. { uint8_t * const p = az_span_ptr(*builder) + az_span_length(*builder); - AZ_RETURN_IF_FAILED(az_span_append_zeros(builder, _az_align_ceil(p, data.type.align) - p)); + AZ_RETURN_IF_FAILED(_az_span_append_zeros(builder, _az_align_ceil(p, data.type.align) - p)); } *out = az_span_ptr(*builder) + az_span_length(*builder); return az_span_append(*builder, _az_data_get_span(data), builder); @@ -116,7 +116,7 @@ AZ_NODISCARD az_result _az_span_top_array_revert( = az_span_take(az_span_drop(buffer, offset + i * item_type.size), item_type.size); az_span const b = az_span_take( az_span_drop(buffer, offset + (item_count - i - 1) * item_type.size), item_type.size); - az_span_swap(a, b); + _az_span_swap(a, b); } // 3. move it to front. @@ -221,11 +221,7 @@ AZ_NODISCARD az_result _az_span_write_json_value( *out = az_json_data_array((az_json_array){ ._internal = { .begin = p, .size = i } }); break; } - default: { - return AZ_ERROR_JSON_INVALID_STATE; - } - } - return AZ_OK; + default: { return AZ_ERROR_JSON_INVALID_STATE; } } AZ_NODISCARD az_result az_json_to_data(az_span json, az_span buffer, az_json_data const ** out) { diff --git a/sdk/core/core/src/az_json_get.c b/sdk/core/core/src/az_json_get.c index 34d731b5e1..652d175c07 100644 --- a/sdk/core/core/src/az_json_get.c +++ b/sdk/core/core/src/az_json_get.c @@ -12,9 +12,9 @@ AZ_NODISCARD bool az_json_pointer_token_eq_json_string(az_span pointer_token, az az_span js_reader = json_string; while (true) { uint32_t pt_c = { 0 }; - az_result const pt_result = az_span_reader_read_json_pointer_token_char(&pt_reader, &pt_c); + az_result const pt_result = _az_span_reader_read_json_pointer_token_char(&pt_reader, &pt_c); uint32_t js_c = { 0 }; - az_result const js_result = az_span_reader_read_json_string_char(&js_reader, &js_c); + az_result const js_result = _az_span_reader_read_json_string_char(&js_reader, &js_c); if (js_result == AZ_ERROR_ITEM_NOT_FOUND && pt_result == AZ_ERROR_ITEM_NOT_FOUND) { return true; } @@ -78,7 +78,7 @@ az_json_parse_by_pointer(az_span json, az_span pointer, az_json_token * out_toke // read the pointer token. { az_result const result - = az_span_reader_read_json_pointer_token(&pointer_parser, &pointer_token); + = _az_span_reader_read_json_pointer_token(&pointer_parser, &pointer_token); // no more pointer tokens so we found the JSON value. if (result == AZ_ERROR_ITEM_NOT_FOUND) { return AZ_OK; diff --git a/sdk/core/core/src/az_json_parser.c b/sdk/core/core/src/az_json_parser.c index 8ce849d3ba..6bdca55bbd 100644 --- a/sdk/core/core/src/az_json_parser.c +++ b/sdk/core/core/src/az_json_parser.c @@ -248,7 +248,7 @@ AZ_NODISCARD static az_result az_span_reader_get_json_string_rest( uint8_t * p_reader = az_span_ptr(*self); while (true) { uint32_t ignore = { 0 }; - az_result const result = az_span_reader_read_json_string_char(self, &ignore); + az_result const result = _az_span_reader_read_json_string_char(self, &ignore); switch (result) { case AZ_ERROR_JSON_STRING_END: { int32_t read_count = reader_initial_length - az_span_capacity(*self); diff --git a/sdk/core/core/src/az_json_pointer.c b/sdk/core/core/src/az_json_pointer.c index fd5e551a7a..0da4f22a7a 100644 --- a/sdk/core/core/src/az_json_pointer.c +++ b/sdk/core/core/src/az_json_pointer.c @@ -55,7 +55,7 @@ AZ_NODISCARD static az_result az_span_reader_read_json_pointer_char( } } -AZ_NODISCARD az_result az_span_reader_read_json_pointer_token(az_span * self, az_span * out) { +AZ_NODISCARD az_result _az_span_reader_read_json_pointer_token(az_span * self, az_span * out) { AZ_CONTRACT_ARG_NOT_NULL(self); AZ_CONTRACT_ARG_NOT_NULL(out); @@ -98,7 +98,7 @@ AZ_NODISCARD az_result az_span_reader_read_json_pointer_token(az_span * self, az } } -AZ_NODISCARD az_result az_span_reader_read_json_pointer_token_char(az_span * self, uint32_t * out) { +AZ_NODISCARD az_result _az_span_reader_read_json_pointer_token_char(az_span * self, uint32_t * out) { AZ_CONTRACT_ARG_NOT_NULL(self); AZ_CONTRACT_ARG_NOT_NULL(out); diff --git a/sdk/core/core/src/az_json_string.c b/sdk/core/core/src/az_json_string.c index ba8e54da06..d28e0713ae 100644 --- a/sdk/core/core/src/az_json_string.c +++ b/sdk/core/core/src/az_json_string.c @@ -57,7 +57,7 @@ AZ_NODISCARD AZ_INLINE az_result az_json_esc_decode(uint8_t c, uint8_t * out) { return AZ_OK; } -AZ_NODISCARD az_span az_json_esc_encode(uint8_t c) { +AZ_NODISCARD az_span _az_json_esc_encode(uint8_t c) { switch (c) { case '\\': { return AZ_SPAN_FROM_STR("\\\\"); @@ -84,7 +84,7 @@ AZ_NODISCARD az_span az_json_esc_encode(uint8_t c) { } } -AZ_NODISCARD az_result az_span_reader_read_json_string_char(az_span * self, uint32_t * out) { +AZ_NODISCARD az_result _az_span_reader_read_json_string_char(az_span * self, uint32_t * out) { AZ_CONTRACT_ARG_NOT_NULL(self); int32_t reader_length = az_span_length(*self); diff --git a/sdk/core/core/src/az_json_string_private.h b/sdk/core/core/src/az_json_string_private.h index 7b929645d2..c2bfd921e2 100644 --- a/sdk/core/core/src/az_json_string_private.h +++ b/sdk/core/core/src/az_json_string_private.h @@ -15,13 +15,13 @@ * Encodes the given character into a JSON escape sequence. The function returns an empty span if * the given character doesn't require to be escaped. */ -AZ_NODISCARD az_span az_json_esc_encode(uint8_t c); +AZ_NODISCARD az_span _az_json_esc_encode(uint8_t c); /** * TODO: this function and JSON pointer read functions should return proper UNICODE * code-point to be compatible. */ -AZ_NODISCARD az_result az_span_reader_read_json_string_char(az_span * self, uint32_t * out); +AZ_NODISCARD az_result _az_span_reader_read_json_string_char(az_span * self, uint32_t * out); /** * Returns a next reference token in the JSON pointer. The JSON pointer parser is @var @@ -29,12 +29,12 @@ AZ_NODISCARD az_result az_span_reader_read_json_string_char(az_span * self, uint * * See https://tools.ietf.org/html/rfc6901 */ -AZ_NODISCARD az_result az_span_reader_read_json_pointer_token(az_span * self, az_span * out); +AZ_NODISCARD az_result _az_span_reader_read_json_pointer_token(az_span * self, az_span * out); /** * Returns a next character in the given span reader of JSON pointer reference token. */ -AZ_NODISCARD az_result az_span_reader_read_json_pointer_token_char(az_span * self, uint32_t * out); +AZ_NODISCARD az_result _az_span_reader_read_json_pointer_token_char(az_span * self, uint32_t * out); #include <_az_cfg_suffix.h> diff --git a/sdk/core/core/src/az_log.c b/sdk/core/core/src/az_log.c index b8db9b4b70..75c6f27dcf 100644 --- a/sdk/core/core/src/az_log.c +++ b/sdk/core/core/src/az_log.c @@ -4,6 +4,7 @@ #include "az_log_private.h" #include "az_span_private.h" #include +#include #include #include #include @@ -93,7 +94,7 @@ static az_result _az_log_value_msg(az_span * log_msg_bldr, az_span value) { static az_result _az_log_http_request_msg( az_span * log_msg_bldr, - az_http_request * hrb, + _az_http_request * hrb, uint8_t indent) { for (uint8_t ntabs = 0; ntabs < indent; ++ntabs) { AZ_RETURN_IF_FAILED(az_span_append(*log_msg_bldr, AZ_SPAN_FROM_STR("\t"), log_msg_bldr)); @@ -135,7 +136,7 @@ static az_result _az_log_http_response_msg( az_span * log_msg_bldr, az_http_response * response, int64_t duration_msec, - az_http_request * hrb) { + _az_http_request * hrb) { AZ_RETURN_IF_FAILED( az_span_append(*log_msg_bldr, AZ_SPAN_FROM_STR("HTTP Response ("), log_msg_bldr)); AZ_RETURN_IF_FAILED(az_span_append_int64(log_msg_bldr, duration_msec)); @@ -170,7 +171,7 @@ static az_result _az_log_http_response_msg( return _az_log_http_request_msg(log_msg_bldr, hrb, 1); } -void _az_log_http_request(az_http_request * hrb) { +void _az_log_http_request(_az_http_request * hrb) { uint8_t log_msg_buf[_az_LOG_MSG_BUF_SIZE] = { 0 }; az_span log_msg_bldr = AZ_SPAN_FROM_BUFFER(log_msg_buf); @@ -183,7 +184,7 @@ void _az_log_http_request(az_http_request * hrb) { void _az_log_http_response( az_http_response * response, int64_t duration_msec, - az_http_request * hrb) { + _az_http_request * hrb) { uint8_t log_msg_buf[_az_LOG_MSG_BUF_SIZE] = { 0 }; az_span log_msg_bldr = AZ_SPAN_FROM_BUFFER(log_msg_buf); diff --git a/sdk/core/core/src/az_log_private.h b/sdk/core/core/src/az_log_private.h index 5eb5c2860d..25b8660f35 100644 --- a/sdk/core/core/src/az_log_private.h +++ b/sdk/core/core/src/az_log_private.h @@ -11,12 +11,12 @@ #include <_az_cfg_prefix.h> -void _az_log_http_request(az_http_request * hrb); +void _az_log_http_request(_az_http_request * hrb); void _az_log_http_response( az_http_response * response, int64_t duration_msec, - az_http_request * hrb); + _az_http_request * hrb); #include <_az_cfg_suffix.h> diff --git a/sdk/core/core/src/az_span.c b/sdk/core/core/src/az_span.c index 39affb68c9..9608a12fdc 100644 --- a/sdk/core/core/src/az_span.c +++ b/sdk/core/core/src/az_span.c @@ -169,7 +169,7 @@ AZ_INLINE void _az_uint8_swap(uint8_t * a, uint8_t * b) { * @param a source/destination span * @param b destination/source span */ -void az_span_swap(az_span a, az_span b) { +void _az_span_swap(az_span a, az_span b) { uint8_t * pa = az_span_ptr(a); uint8_t * pb = az_span_ptr(b); for (int32_t i = _az_size_min(az_span_length(a), az_span_length(b)); i > 0; ++pa, ++pb) { @@ -241,7 +241,7 @@ AZ_NODISCARD az_result az_span_append(az_span self, az_span span, az_span * out) * @param size number of zeros to be appended * @return AZ_NODISCARD az_span_append_zeros */ -AZ_NODISCARD az_result az_span_append_zeros(az_span * self, int32_t size) { +AZ_NODISCARD az_result _az_span_append_zeros(az_span * self, int32_t size) { AZ_CONTRACT_ARG_NOT_NULL(self); int32_t current_size = az_span_length(*self); @@ -265,7 +265,7 @@ AZ_NODISCARD az_result az_span_append_zeros(az_span * self, int32_t size) { * @param span content to use for replacement * @return AZ_NODISCARD az_span_replace */ -AZ_NODISCARD az_result az_span_replace(az_span * self, int32_t start, int32_t end, az_span span) { +AZ_NODISCARD az_result _az_span_replace(az_span * self, int32_t start, int32_t end, az_span span) { AZ_CONTRACT_ARG_NOT_NULL(self); int32_t const current_size = az_span_length(*self); diff --git a/sdk/core/core/src/az_span_private.h b/sdk/core/core/src/az_span_private.h index 0a5ee40f7f..3a7d31bdad 100644 --- a/sdk/core/core/src/az_span_private.h +++ b/sdk/core/core/src/az_span_private.h @@ -79,7 +79,7 @@ AZ_NODISCARD AZ_INLINE az_span az_span_from_single_item(uint8_t * ptr) { * @param a source/destination span * @param b destination/source span */ -void az_span_swap(az_span a, az_span b); +void _az_span_swap(az_span a, az_span b); /** * @brief Append @b size number of zeros to @b self if there is enough capacity for it @@ -88,7 +88,7 @@ void az_span_swap(az_span a, az_span b); * @param size number of zeros to be appended * @return AZ_NODISCARD az_span_append_zeros */ -AZ_NODISCARD az_result az_span_append_zeros(az_span * self, int32_t size); +AZ_NODISCARD az_result _az_span_append_zeros(az_span * self, int32_t size); /** * @brief Replace all contents from a starting position to an end position with the content of a @@ -100,7 +100,7 @@ AZ_NODISCARD az_result az_span_append_zeros(az_span * self, int32_t size); * @param span content to use for replacement * @return AZ_NODISCARD az_span_replace */ -AZ_NODISCARD az_result az_span_replace(az_span * self, int32_t start, int32_t end, az_span span); +AZ_NODISCARD az_result _az_span_replace(az_span * self, int32_t start, int32_t end, az_span span); typedef az_result (*_az_predicate)(az_span slice); diff --git a/sdk/core/core/test/main.c b/sdk/core/core/test/main.c index fb214c5a94..9c2467b8e8 100644 --- a/sdk/core/core/test/main.c +++ b/sdk/core/core/test/main.c @@ -2,6 +2,8 @@ // SPDX-License-Identifier: MIT #include +#include +#include #include #include @@ -428,7 +430,7 @@ int main() { az_span url_span = AZ_SPAN_FROM_BUFFER(buf); TEST_EXPECT_SUCCESS(az_span_append(url_span, hrb_url, &url_span)); az_span header_span = AZ_SPAN_FROM_BUFFER(header_buf); - az_http_request hrb; + _az_http_request hrb; TEST_EXPECT_SUCCESS( az_http_request_init(&hrb, az_http_method_get(), url_span, header_span, az_span_null())); @@ -472,7 +474,7 @@ int main() { TEST_ASSERT(az_span_is_equal(header.value, expected_headers1[i].value)); } - TEST_EXPECT_SUCCESS(az_http_request_remove_retry_headers(&hrb)); + TEST_EXPECT_SUCCESS(_az_http_request_remove_retry_headers(&hrb)); TEST_ASSERT(hrb._internal.retry_headers_start_byte_offset == sizeof(az_pair)); TEST_EXPECT_SUCCESS(az_http_request_append_header( diff --git a/sdk/core/core/test/test_http_response_read_and_parse.c b/sdk/core/core/test/test_http_response_read_and_parse.c index adcde90549..b3a1b813ca 100644 --- a/sdk/core/core/test/test_http_response_read_and_parse.c +++ b/sdk/core/core/test/test_http_response_read_and_parse.c @@ -30,7 +30,7 @@ void test_http_response() { TEST_ASSERT(result == AZ_OK); TEST_ASSERT(status_line.major_version == 1); TEST_ASSERT(status_line.minor_version == 2); - TEST_ASSERT(status_line.status_code == AZ_HTTP_STATUS_CODE_NOT_FOUND); + TEST_ASSERT(status_line.status_code == _AZ_HTTP_STATUS_CODE_NOT_FOUND); TEST_ASSERT( az_span_is_equal(status_line.reason_phrase, AZ_SPAN_FROM_STR("We removed the\tpage!"))); } @@ -68,7 +68,7 @@ void test_http_response() { TEST_ASSERT(result == AZ_OK); TEST_ASSERT(status_line.major_version == 2); TEST_ASSERT(status_line.minor_version == 0); - TEST_ASSERT(status_line.status_code == AZ_HTTP_STATUS_CODE_RESET_CONTENT); + TEST_ASSERT(status_line.status_code == _AZ_HTTP_STATUS_CODE_RESET_CONTENT); TEST_ASSERT(az_span_is_equal(status_line.reason_phrase, AZ_SPAN_FROM_STR(""))); } // read a header1 diff --git a/sdk/core/core/test/test_json_pointer.c b/sdk/core/core/test/test_json_pointer.c index fe101c0ff8..eb985eab60 100644 --- a/sdk/core/core/test/test_json_pointer.c +++ b/sdk/core/core/test/test_json_pointer.c @@ -12,18 +12,18 @@ void test_json_pointer() { { az_span parser = AZ_SPAN_FROM_STR(""); az_span p; - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_ITEM_NOT_FOUND); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_ITEM_NOT_FOUND); } { az_span parser = AZ_SPAN_FROM_STR("Hello"); az_span p; TEST_ASSERT( - az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_PARSER_UNEXPECTED_CHAR); + _az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_PARSER_UNEXPECTED_CHAR); } { az_span parser = AZ_SPAN_FROM_STR("/abc"); az_span p; - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); TEST_ASSERT(az_span_is_equal(p, AZ_SPAN_FROM_STR("abc"))); // test az_json_pointer_token_parser_get { @@ -33,7 +33,7 @@ void test_json_pointer() { while (true) { uint32_t code_point; az_result const result - = az_span_reader_read_json_pointer_token_char(&token_parser, &code_point); + = _az_span_reader_read_json_pointer_token_char(&token_parser, &code_point); if (result == AZ_ERROR_ITEM_NOT_FOUND) { break; } @@ -44,12 +44,12 @@ void test_json_pointer() { az_span const b = az_span_init(buffer, i, i); TEST_ASSERT(az_span_is_equal(b, AZ_SPAN_FROM_STR("abc"))); } - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_ITEM_NOT_FOUND); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_ITEM_NOT_FOUND); } { az_span parser = AZ_SPAN_FROM_STR("/abc//dffgg21"); az_span p; - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); TEST_ASSERT(az_span_is_equal(p, AZ_SPAN_FROM_STR("abc"))); // test az_json_pointer_token_parser_get { @@ -59,7 +59,7 @@ void test_json_pointer() { while (true) { uint32_t code_point; az_result const result - = az_span_reader_read_json_pointer_token_char(&token_parser, &code_point); + = _az_span_reader_read_json_pointer_token_char(&token_parser, &code_point); if (result == AZ_ERROR_ITEM_NOT_FOUND) { break; } @@ -70,16 +70,16 @@ void test_json_pointer() { az_span const b = az_span_init(buffer, i, i); TEST_ASSERT(az_span_is_equal(b, AZ_SPAN_FROM_STR("abc"))); } - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); TEST_ASSERT(az_span_is_equal(p, AZ_SPAN_FROM_STR(""))); - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); TEST_ASSERT(az_span_is_equal(p, AZ_SPAN_FROM_STR("dffgg21"))); - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_ITEM_NOT_FOUND); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_ITEM_NOT_FOUND); } { az_span parser = AZ_SPAN_FROM_STR("/ab~1c/dff~0x"); az_span p; - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); TEST_ASSERT(az_span_is_equal(p, AZ_SPAN_FROM_STR("ab~1c"))); // test az_json_pointer_token_parser_get { @@ -89,7 +89,7 @@ void test_json_pointer() { while (true) { uint32_t code_point; az_result const result - = az_span_reader_read_json_pointer_token_char(&token_parser, &code_point); + = _az_span_reader_read_json_pointer_token_char(&token_parser, &code_point); if (result == AZ_ERROR_ITEM_NOT_FOUND) { break; } @@ -100,7 +100,7 @@ void test_json_pointer() { az_span const b = az_span_init(buffer, i, i); TEST_ASSERT(az_span_is_equal(b, AZ_SPAN_FROM_STR("ab/c"))); } - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); TEST_ASSERT(az_span_is_equal(p, AZ_SPAN_FROM_STR("dff~0x"))); // test az_json_pointer_token_parser_get { @@ -110,7 +110,7 @@ void test_json_pointer() { while (true) { uint32_t code_point; az_result const result - = az_span_reader_read_json_pointer_token_char(&token_parser, &code_point); + = _az_span_reader_read_json_pointer_token_char(&token_parser, &code_point); if (result == AZ_ERROR_ITEM_NOT_FOUND) { break; } @@ -121,42 +121,42 @@ void test_json_pointer() { az_span const b = az_span_init(buffer, i, i); TEST_ASSERT(az_span_is_equal(b, AZ_SPAN_FROM_STR("dff~x"))); } - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_ITEM_NOT_FOUND); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_ITEM_NOT_FOUND); } { az_span parser = AZ_SPAN_FROM_STR("/ab~1c/dff~x"); az_span p; - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); TEST_ASSERT(az_span_is_equal(p, AZ_SPAN_FROM_STR("ab~1c"))); TEST_ASSERT( - az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_PARSER_UNEXPECTED_CHAR); + _az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_PARSER_UNEXPECTED_CHAR); } { az_span parser = AZ_SPAN_FROM_STR("/ab~1c/dff~"); az_span p; - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_OK); TEST_ASSERT(az_span_is_equal(p, AZ_SPAN_FROM_STR("ab~1c"))); - TEST_ASSERT(az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_EOF); + TEST_ASSERT(_az_span_reader_read_json_pointer_token(&parser, &p) == AZ_ERROR_EOF); } // test az_json_pointer_token_parser_get { az_span token_parser = AZ_SPAN_FROM_STR("~"); uint32_t c; - TEST_ASSERT(az_span_reader_read_json_pointer_token_char(&token_parser, &c) == AZ_ERROR_EOF); + TEST_ASSERT(_az_span_reader_read_json_pointer_token_char(&token_parser, &c) == AZ_ERROR_EOF); } // test az_json_pointer_token_parser_get { az_span token_parser = AZ_SPAN_FROM_STR(""); uint32_t c; TEST_ASSERT( - az_span_reader_read_json_pointer_token_char(&token_parser, &c) == AZ_ERROR_ITEM_NOT_FOUND); + _az_span_reader_read_json_pointer_token_char(&token_parser, &c) == AZ_ERROR_ITEM_NOT_FOUND); } // test az_json_pointer_token_parser_get { az_span token_parser = AZ_SPAN_FROM_STR("/"); uint32_t c; TEST_ASSERT( - az_span_reader_read_json_pointer_token_char(&token_parser, &c) + _az_span_reader_read_json_pointer_token_char(&token_parser, &c) == AZ_ERROR_PARSER_UNEXPECTED_CHAR); } // test az_json_pointer_token_parser_get @@ -164,7 +164,7 @@ void test_json_pointer() { az_span token_parser = AZ_SPAN_FROM_STR("~2"); uint32_t c; TEST_ASSERT( - az_span_reader_read_json_pointer_token_char(&token_parser, &c) + _az_span_reader_read_json_pointer_token_char(&token_parser, &c) == AZ_ERROR_PARSER_UNEXPECTED_CHAR); } } diff --git a/sdk/core/core/test/test_json_string.c b/sdk/core/core/test/test_json_string.c index 577347f7f5..b7081a613a 100644 --- a/sdk/core/core/test/test_json_string.c +++ b/sdk/core/core/test/test_json_string.c @@ -12,32 +12,32 @@ void test_json_string() { az_span const s = AZ_SPAN_FROM_STR("tr\\\"ue\\t"); az_span reader = s; uint32_t c; - TEST_ASSERT(az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); TEST_ASSERT(c == 't'); - TEST_ASSERT(az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); TEST_ASSERT(c == 'r'); - TEST_ASSERT(az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); TEST_ASSERT(c == '\"'); - TEST_ASSERT(az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); TEST_ASSERT(c == 'u'); - TEST_ASSERT(az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); TEST_ASSERT(c == 'e'); - TEST_ASSERT(az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); TEST_ASSERT(c == '\t'); - TEST_ASSERT(az_span_reader_read_json_string_char(&reader, &c) == AZ_ERROR_ITEM_NOT_FOUND); + TEST_ASSERT(_az_span_reader_read_json_string_char(&reader, &c) == AZ_ERROR_ITEM_NOT_FOUND); } { az_span const s = AZ_SPAN_FROM_STR("\\uFf0F"); az_span reader = s; uint32_t c = { 0 }; - TEST_ASSERT(az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); + TEST_ASSERT(_az_span_reader_read_json_string_char(&reader, &c) == AZ_OK); TEST_ASSERT(c == 0xFF0F); - TEST_ASSERT(az_span_reader_read_json_string_char(&reader, &c) == AZ_ERROR_ITEM_NOT_FOUND); + TEST_ASSERT(_az_span_reader_read_json_string_char(&reader, &c) == AZ_ERROR_ITEM_NOT_FOUND); } { az_span const s = AZ_SPAN_FROM_STR("\\uFf0"); az_span reader = s; uint32_t c; - TEST_ASSERT(az_span_reader_read_json_string_char(&reader, &c) == AZ_ERROR_EOF); + TEST_ASSERT(_az_span_reader_read_json_string_char(&reader, &c) == AZ_ERROR_EOF); } } diff --git a/sdk/core/core/test/test_log.c b/sdk/core/core/test/test_log.c index bfd5c19a4e..e6678cf8f3 100644 --- a/sdk/core/core/test/test_log.c +++ b/sdk/core/core/test/test_log.c @@ -2,7 +2,9 @@ // SPDX-License-Identifier: MIT #include +#include #include +#include #include #include #include @@ -56,7 +58,7 @@ void test_log() { // Set up test values etc. // uint8_t hrb_buf[4 * 1024] = { 0 }; uint8_t headers[4 * 1024] = { 0 }; - az_http_request hrb = { 0 }; + _az_http_request hrb = { 0 }; TEST_EXPECT_SUCCESS(az_http_request_init( &hrb, az_http_method_get(), diff --git a/sdk/core/core/test/test_mut_span.c b/sdk/core/core/test/test_mut_span.c index 320f4ce2d3..16117f78d2 100644 --- a/sdk/core/core/test/test_mut_span.c +++ b/sdk/core/core/test/test_mut_span.c @@ -15,7 +15,7 @@ void test_mut_span() { uint8_t b_array[] = "Goodbye!"; az_span const a = AZ_SPAN_FROM_INITIALIZED_BUFFER(a_array); az_span const b = AZ_SPAN_FROM_INITIALIZED_BUFFER(b_array); - az_span_swap(a, b); + _az_span_swap(a, b); TEST_ASSERT(az_span_is_equal(a, AZ_SPAN_FROM_STR("Goodbye!\0ld!\0"))); TEST_ASSERT(az_span_is_equal(b, AZ_SPAN_FROM_STR("Hello wor"))); } @@ -24,7 +24,7 @@ void test_mut_span() { uint8_t a_array[] = "Hello world!"; az_span const a = AZ_SPAN_FROM_INITIALIZED_BUFFER(a_array); az_span const b = { 0 }; - az_span_swap(a, b); + _az_span_swap(a, b); TEST_ASSERT(az_span_is_equal(a, AZ_SPAN_FROM_STR("Hello world!\0"))); TEST_ASSERT(az_span_is_equal(b, AZ_SPAN_FROM_STR(""))); } diff --git a/sdk/core/core/test/test_span_builder_replace.c b/sdk/core/core/test/test_span_builder_replace.c index 5f42ffb407..beab40c248 100644 --- a/sdk/core/core/test/test_span_builder_replace.c +++ b/sdk/core/core/test/test_span_builder_replace.c @@ -17,7 +17,7 @@ void test_span_builder_replace() { az_span expected = AZ_SPAN_FROM_STR("1X78"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 1, 6, AZ_SPAN_FROM_STR("X")) == AZ_OK); + TEST_ASSERT(_az_span_replace(&builder, 1, 6, AZ_SPAN_FROM_STR("X")) == AZ_OK); az_span const result = builder; TEST_ASSERT(az_span_is_equal(result, expected)); @@ -30,7 +30,7 @@ void test_span_builder_replace() { az_span expected = AZ_SPAN_FROM_STR("12X345678"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 2, 2, AZ_SPAN_FROM_STR("X")) == AZ_OK); + TEST_ASSERT(_az_span_replace(&builder, 2, 2, AZ_SPAN_FROM_STR("X")) == AZ_OK); az_span const result = builder; TEST_ASSERT(az_span_is_equal(result, expected)); @@ -43,7 +43,7 @@ void test_span_builder_replace() { az_span expected = AZ_SPAN_FROM_STR("1234567890"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 8, 8, AZ_SPAN_FROM_STR("90")) == AZ_OK); + TEST_ASSERT(_az_span_replace(&builder, 8, 8, AZ_SPAN_FROM_STR("90")) == AZ_OK); az_span const result = builder; TEST_ASSERT(az_span_is_equal(result, expected)); @@ -56,7 +56,7 @@ void test_span_builder_replace() { az_span expected = AZ_SPAN_FROM_STR("X"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 0, 8, AZ_SPAN_FROM_STR("X")) == AZ_OK); + TEST_ASSERT(_az_span_replace(&builder, 0, 8, AZ_SPAN_FROM_STR("X")) == AZ_OK); az_span const result = builder; TEST_ASSERT(az_span_is_equal(result, expected)); @@ -69,7 +69,7 @@ void test_span_builder_replace() { az_span expected = AZ_SPAN_FROM_STR("X12345678X"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 0, 8, AZ_SPAN_FROM_STR("X12345678X")) == AZ_OK); + TEST_ASSERT(_az_span_replace(&builder, 0, 8, AZ_SPAN_FROM_STR("X12345678X")) == AZ_OK); az_span const result = builder; TEST_ASSERT(az_span_is_equal(result, expected)); @@ -82,7 +82,7 @@ void test_span_builder_replace() { az_span expected = AZ_SPAN_FROM_STR("XXX12345678"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 0, 0, AZ_SPAN_FROM_STR("XXX")) == AZ_OK); + TEST_ASSERT(_az_span_replace(&builder, 0, 0, AZ_SPAN_FROM_STR("XXX")) == AZ_OK); az_span const result = builder; TEST_ASSERT(az_span_is_equal(result, expected)); @@ -95,7 +95,7 @@ void test_span_builder_replace() { az_span expected = AZ_SPAN_FROM_STR("2"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 0, 1, AZ_SPAN_FROM_STR("2")) == AZ_OK); + TEST_ASSERT(_az_span_replace(&builder, 0, 1, AZ_SPAN_FROM_STR("2")) == AZ_OK); az_span const result = builder; TEST_ASSERT(az_span_is_equal(result, expected)); @@ -108,7 +108,7 @@ void test_span_builder_replace() { az_span expected = AZ_SPAN_FROM_STR("4321"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 0, 4, AZ_SPAN_FROM_STR("4321")) == AZ_OK); + TEST_ASSERT(_az_span_replace(&builder, 0, 4, AZ_SPAN_FROM_STR("4321")) == AZ_OK); az_span const result = builder; TEST_ASSERT(az_span_is_equal(result, expected)); @@ -121,7 +121,7 @@ void test_span_builder_replace() { az_span expected = AZ_SPAN_FROM_STR("1X34AB"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_EXPECT_SUCCESS(az_span_replace(&builder, 1, 2, AZ_SPAN_FROM_STR("X"))); + TEST_EXPECT_SUCCESS(_az_span_replace(&builder, 1, 2, AZ_SPAN_FROM_STR("X"))); TEST_EXPECT_SUCCESS(az_span_append(builder, AZ_SPAN_FROM_STR("AB"), &builder)); @@ -136,7 +136,7 @@ void test_span_builder_replace() { az_span expected = AZ_SPAN_FROM_STR("1234"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_EXPECT_SUCCESS(az_span_replace(&builder, 3, 3, AZ_SPAN_FROM_STR("4"))); + TEST_EXPECT_SUCCESS(_az_span_replace(&builder, 3, 3, AZ_SPAN_FROM_STR("4"))); az_span const result = builder; TEST_ASSERT(az_span_is_equal(result, expected)); @@ -148,19 +148,19 @@ void test_span_builder_replace() { az_span initial_state = AZ_SPAN_FROM_STR("1234"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 0, 4, AZ_SPAN_FROM_STR("4321X")) == AZ_ERROR_ARG); + TEST_ASSERT(_az_span_replace(&builder, 0, 4, AZ_SPAN_FROM_STR("4321X")) == AZ_ERROR_ARG); } { // Fail on builder empty -> try to replace content from empty builder uint8_t array[200]; az_span builder = AZ_SPAN_FROM_BUFFER(array); - TEST_ASSERT(az_span_replace(&builder, 0, 1, AZ_SPAN_FROM_STR("2")) == AZ_ERROR_ARG); + TEST_ASSERT(_az_span_replace(&builder, 0, 1, AZ_SPAN_FROM_STR("2")) == AZ_ERROR_ARG); } { // Replace content on empty builder -> insert at the end uint8_t array[200]; az_span builder = AZ_SPAN_FROM_BUFFER(array); - TEST_ASSERT(az_span_replace(&builder, 0, 0, AZ_SPAN_FROM_STR("2")) == AZ_OK); + TEST_ASSERT(_az_span_replace(&builder, 0, 0, AZ_SPAN_FROM_STR("2")) == AZ_OK); az_span const result = builder; az_span const expected = AZ_SPAN_FROM_STR("2"); TEST_ASSERT(az_span_is_equal(result, expected)); @@ -172,7 +172,7 @@ void test_span_builder_replace() { az_span initial_state = AZ_SPAN_FROM_STR("1234"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 30, 31, AZ_SPAN_FROM_STR("4321X")) == AZ_ERROR_ARG); + TEST_ASSERT(_az_span_replace(&builder, 30, 31, AZ_SPAN_FROM_STR("4321X")) == AZ_ERROR_ARG); } { // Fail when trying to replace out of bounds -> end position out @@ -181,7 +181,7 @@ void test_span_builder_replace() { az_span initial_state = AZ_SPAN_FROM_STR("1234"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 4, 5, AZ_SPAN_FROM_STR("4321X")) == AZ_ERROR_ARG); + TEST_ASSERT(_az_span_replace(&builder, 4, 5, AZ_SPAN_FROM_STR("4321X")) == AZ_ERROR_ARG); } { // Fail when start is greater than end @@ -190,6 +190,6 @@ void test_span_builder_replace() { az_span initial_state = AZ_SPAN_FROM_STR("1234"); TEST_EXPECT_SUCCESS(az_span_append(builder, initial_state, &builder)); - TEST_ASSERT(az_span_replace(&builder, 3, 1, AZ_SPAN_FROM_STR("4321X")) == AZ_ERROR_ARG); + TEST_ASSERT(_az_span_replace(&builder, 3, 1, AZ_SPAN_FROM_STR("4321X")) == AZ_ERROR_ARG); } } diff --git a/sdk/keyvault/keyvault/inc/az_keyvault.h b/sdk/keyvault/keyvault/inc/az_keyvault.h index c357c27b2c..86fb18d301 100644 --- a/sdk/keyvault/keyvault/inc/az_keyvault.h +++ b/sdk/keyvault/keyvault/inc/az_keyvault.h @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -46,7 +45,7 @@ typedef struct { uint8_t url_buffer[AZ_HTTP_URL_MAX_SIZE]; // this url will point to url_buffer az_span uri; - az_http_pipeline pipeline; + _az_http_pipeline pipeline; az_keyvault_keys_client_options options; _az_credential * credential; } _internal; diff --git a/sdk/keyvault/keyvault/src/az_keyvault_client.c b/sdk/keyvault/keyvault/src/az_keyvault_client.c index 3373e8a245..782fb20f0f 100644 --- a/sdk/keyvault/keyvault/src/az_keyvault_client.c +++ b/sdk/keyvault/keyvault/src/az_keyvault_client.c @@ -3,7 +3,9 @@ #include #include -#include +#include +#include +#include #include #include #include @@ -72,47 +74,67 @@ AZ_NODISCARD az_result az_keyvault_keys_client_init( .uri = AZ_SPAN_FROM_BUFFER(self->_internal.url_buffer), .options = *options, .credential = cred, - .pipeline = (az_http_pipeline) { - .p_policies = { - { - .process = az_http_pipeline_policy_apiversion, - .p_options = &self->_internal.options._internal.api_version, + .pipeline = (_az_http_pipeline){ + ._internal = { + .p_policies = { + { + ._internal = { + .process = az_http_pipeline_policy_apiversion, + .p_options= &self->_internal.options._internal.api_version, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_uniquerequestid, + .p_options = NULL, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_telemetry, + .p_options = &self->_internal.options._internal._telemetry_options, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_retry, + .p_options = &self->_internal.options.retry, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_credential, + .p_options = cred, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_logging, + .p_options = NULL, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_bufferresponse, + .p_options = NULL, + }, + }, + { + ._internal = { + .process= az_http_pipeline_policy_distributedtracing, + .p_options = NULL, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_transport, + .p_options= &self->_internal.options._internal.http_transport_options, + }, + }, }, - { - .process = az_http_pipeline_policy_uniquerequestid, - .p_options = NULL, - }, - { - .process = az_http_pipeline_policy_telemetry, - .p_options = &self->_internal.options._internal._telemetry_options, - }, - { - .process = az_http_pipeline_policy_retry, - .p_options = &self->_internal.options.retry, - }, - { - .process = az_http_pipeline_policy_credential, - .p_options = cred, - }, - { - .process = az_http_pipeline_policy_logging, - .p_options = NULL, - }, - { - .process = az_http_pipeline_policy_bufferresponse, - .p_options = NULL, - }, - { - .process = az_http_pipeline_policy_distributedtracing, - .p_options = NULL, - }, - { - .process = az_http_pipeline_policy_transport, - .p_options = &self->_internal.options._internal.http_transport_options, - }, - }, - }, - }, + } + } + } }; // Copy url to client buffer so customer can re-use buffer on his/her side @@ -223,7 +245,7 @@ AZ_NODISCARD az_result az_keyvault_keys_key_create( az_span const created_body = json_builder; // create request - az_http_request hrb; + _az_http_request hrb; AZ_RETURN_IF_FAILED(az_http_request_init( &hrb, az_http_method_post(), request_url_span, request_headers_span, created_body)); @@ -269,7 +291,7 @@ AZ_NODISCARD az_result az_keyvault_keys_key_get( AZ_RETURN_IF_FAILED(az_span_copy(request_url_span, client->_internal.uri, &request_url_span)); // create request - az_http_request hrb; + _az_http_request hrb; AZ_RETURN_IF_FAILED(az_http_request_init( &hrb, az_http_method_get(), request_url_span, request_headers_span, az_span_null())); @@ -303,7 +325,7 @@ AZ_NODISCARD az_result az_keyvault_keys_key_delete( // create request // TODO: define max URL size - az_http_request hrb; + _az_http_request hrb; AZ_RETURN_IF_FAILED(az_http_request_init( &hrb, az_http_method_delete(), request_url_span, request_headers_span, az_span_null())); diff --git a/sdk/storage/blobs/inc/az_storage_blobs.h b/sdk/storage/blobs/inc/az_storage_blobs.h index 9196610ca1..eabf44d343 100644 --- a/sdk/storage/blobs/inc/az_storage_blobs.h +++ b/sdk/storage/blobs/inc/az_storage_blobs.h @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -31,7 +30,7 @@ typedef struct { uint8_t url_buffer[AZ_HTTP_URL_MAX_SIZE]; // this url will point to url_buffer az_span uri; - az_http_pipeline pipeline; + _az_http_pipeline pipeline; az_storage_blobs_blob_client_options options; _az_credential * credential; } _internal; diff --git a/sdk/storage/blobs/src/az_storage_blobs_blob_client.c b/sdk/storage/blobs/src/az_storage_blobs_blob_client.c index 8f955263d8..7382985cef 100644 --- a/sdk/storage/blobs/src/az_storage_blobs_blob_client.c +++ b/sdk/storage/blobs/src/az_storage_blobs_blob_client.c @@ -4,7 +4,8 @@ #include #include #include -#include +#include +#include #include #include @@ -37,67 +38,86 @@ AZ_NODISCARD az_storage_blobs_blob_client_options az_storage_blobs_blob_client_o } AZ_NODISCARD az_result az_storage_blobs_blob_client_init( - az_storage_blobs_blob_client * client, + az_storage_blobs_blob_client * self, az_span uri, void * credential, az_storage_blobs_blob_client_options * options) { - AZ_CONTRACT_ARG_NOT_NULL(client); + AZ_CONTRACT_ARG_NOT_NULL(self); AZ_CONTRACT_ARG_NOT_NULL(options); _az_credential * const cred = (_az_credential *)credential; - cred->_internal.http_transport_options - = client->_internal.options._internal.http_transport_options; + cred->_internal.http_transport_options = self->_internal.options._internal.http_transport_options; - *client = (az_storage_blobs_blob_client) { + *self = (az_storage_blobs_blob_client) { ._internal = { - .uri = AZ_SPAN_FROM_BUFFER(client->_internal.url_buffer), + .uri = AZ_SPAN_FROM_BUFFER(self->_internal.url_buffer), .options = *options, .credential = cred, - .pipeline = (az_http_pipeline) { - .p_policies = { - { - .process = az_http_pipeline_policy_apiversion, - .p_options = &client->_internal.options._internal.api_version, - }, - { - .process = az_http_pipeline_policy_uniquerequestid, - .p_options = NULL, - }, - { - .process = az_http_pipeline_policy_telemetry, - .p_options = &client->_internal.options._internal._telemetry_options, - }, - { - .process = az_http_pipeline_policy_retry, - .p_options = &client->_internal.options.retry, - }, - { - .process = az_http_pipeline_policy_credential, - .p_options = cred, - }, - { - .process = az_http_pipeline_policy_logging, - .p_options = NULL, - }, - { - .process = az_http_pipeline_policy_bufferresponse, - .p_options = NULL, - }, - { - .process = az_http_pipeline_policy_distributedtracing, - .p_options = NULL, - }, - { - .process = az_http_pipeline_policy_transport, - .p_options = &client->_internal.options._internal.http_transport_options, + .pipeline = (_az_http_pipeline){ + ._internal = { + .p_policies = { + { + ._internal = { + .process = az_http_pipeline_policy_apiversion, + .p_options= &self->_internal.options._internal.api_version, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_uniquerequestid, + .p_options = NULL, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_telemetry, + .p_options = &self->_internal.options._internal._telemetry_options, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_retry, + .p_options = &self->_internal.options.retry, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_credential, + .p_options = cred, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_logging, + .p_options = NULL, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_bufferresponse, + .p_options = NULL, + }, + }, + { + ._internal = { + .process= az_http_pipeline_policy_distributedtracing, + .p_options = NULL, + }, + }, + { + ._internal = { + .process = az_http_pipeline_policy_transport, + .p_options= &self->_internal.options._internal.http_transport_options, + }, + }, }, - }, - }, - }, + } + } + } }; // Copy url to client buffer so customer can re-use buffer on his/her side - AZ_RETURN_IF_FAILED(az_span_copy(client->_internal.uri, uri, &client->_internal.uri)); + AZ_RETURN_IF_FAILED(az_span_copy(self->_internal.uri, uri, &self->_internal.uri)); AZ_RETURN_IF_FAILED( _az_credential_set_scopes(cred, AZ_SPAN_FROM_STR("https://storage.azure.net/.default"))); @@ -130,7 +150,7 @@ AZ_NODISCARD az_result az_storage_blobs_blob_upload( // create request // TODO: define max URL size - az_http_request hrb; + _az_http_request hrb; AZ_RETURN_IF_FAILED(az_http_request_init( &hrb, az_http_method_get(), request_url_span, request_headers_span, content)); diff --git a/sdk/storage/blobs/test/storage_blobs_poc.c b/sdk/storage/blobs/test/storage_blobs_poc.c index d842bb3a8c..c6f4365bf0 100644 --- a/sdk/storage/blobs/test/storage_blobs_poc.c +++ b/sdk/storage/blobs/test/storage_blobs_poc.c @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include @@ -39,7 +41,7 @@ az_storage_blobs_blob_download(az_storage_blobs_blob_client * client, az_http_re // create request // TODO: define max URL size - az_http_request hrb; + _az_http_request hrb; AZ_RETURN_IF_FAILED(az_http_request_init( &hrb, az_http_method_get(), request_url_span, request_headers_span, az_span_null())); @@ -61,7 +63,7 @@ az_storage_blobs_blob_delete(az_storage_blobs_blob_client * client, az_http_resp // create request // TODO: define max URL size - az_http_request hrb; + _az_http_request hrb; AZ_RETURN_IF_FAILED(az_http_request_init( &hrb, az_http_method_get(), request_url_span, request_headers_span, az_span_null())); diff --git a/sdk/transport_policies/curl/CMakeLists.txt b/sdk/transport_policies/curl/CMakeLists.txt index 981d35012d..34aae5ae3a 100644 --- a/sdk/transport_policies/curl/CMakeLists.txt +++ b/sdk/transport_policies/curl/CMakeLists.txt @@ -38,7 +38,7 @@ endif() target_include_directories (az_curl PUBLIC $ $) -target_link_libraries(az_curl PUBLIC az_core) +target_link_libraries(az_curl PUBLIC az_core az_core_internal) # make sure that users can consume the project as a library. add_library (az::curl ALIAS az_curl) diff --git a/sdk/transport_policies/curl/src/az_curl.c b/sdk/transport_policies/curl/src/az_curl.c index 1e331d18a0..1abe2cc33a 100644 --- a/sdk/transport_policies/curl/src/az_curl.c +++ b/sdk/transport_policies/curl/src/az_curl.c @@ -2,11 +2,11 @@ // SPDX-License-Identifier: MIT #include +#include #include #include -#include #include #include <_az_cfg.h> @@ -144,7 +144,7 @@ static AZ_NODISCARD az_result _az_http_client_curl_add_header_to_curl_list( * @return az_result */ static AZ_NODISCARD az_result -_az_http_client_curl_build_headers(az_http_request * p_request, struct curl_slist ** p_headers) { +_az_http_client_curl_build_headers(_az_http_request * p_request, struct curl_slist ** p_headers) { AZ_CONTRACT_ARG_NOT_NULL(p_request); az_pair header; @@ -219,7 +219,7 @@ static AZ_NODISCARD az_result _az_http_client_curl_send_get_request(CURL * p_cur * handles DELETE request */ static AZ_NODISCARD az_result -_az_http_client_curl_send_delete_request(CURL * p_curl, az_http_request const * p_request) { +_az_http_client_curl_send_delete_request(CURL * p_curl, _az_http_request const * p_request) { AZ_CONTRACT_ARG_NOT_NULL(p_curl); AZ_CONTRACT_ARG_NOT_NULL(p_request); @@ -235,7 +235,7 @@ _az_http_client_curl_send_delete_request(CURL * p_curl, az_http_request const * * handles POST request. It handles seting up a body for request */ static AZ_NODISCARD az_result -_az_http_client_curl_send_post_request(CURL * p_curl, az_http_request const * p_request) { +_az_http_client_curl_send_post_request(CURL * p_curl, _az_http_request const * p_request) { AZ_CONTRACT_ARG_NOT_NULL(p_curl); AZ_CONTRACT_ARG_NOT_NULL(p_request); @@ -288,7 +288,7 @@ static int32_t _az_http_client_curl_upload_read_callback( * handles POST request. It handles seting up a body for request */ static AZ_NODISCARD az_result -_az_http_client_curl_send_upload_request(CURL * p_curl, az_http_request const * p_request) { +_az_http_client_curl_send_upload_request(CURL * p_curl, _az_http_request const * p_request) { AZ_CONTRACT_ARG_NOT_NULL(p_curl); AZ_CONTRACT_ARG_NOT_NULL(p_request); @@ -342,7 +342,7 @@ _az_http_client_curl_send_upload_request(CURL * p_curl, az_http_request const * * @return az_result */ static AZ_NODISCARD az_result -_az_http_client_curl_setup_headers(CURL * p_curl, az_http_request * p_request) { +_az_http_client_curl_setup_headers(CURL * p_curl, _az_http_request * p_request) { AZ_CONTRACT_ARG_NOT_NULL(p_curl); AZ_CONTRACT_ARG_NOT_NULL(p_request); @@ -369,7 +369,7 @@ _az_http_client_curl_setup_headers(CURL * p_curl, az_http_request * p_request) { * @return az_result */ static AZ_NODISCARD az_result -_az_http_client_curl_setup_url(CURL * p_curl, az_http_request const * p_request) { +_az_http_client_curl_setup_url(CURL * p_curl, _az_http_request const * p_request) { AZ_CONTRACT_ARG_NOT_NULL(p_curl); AZ_CONTRACT_ARG_NOT_NULL(p_request); @@ -433,7 +433,7 @@ _az_http_client_curl_setup_response_redirect(CURL * p_curl, az_span * response_b */ static AZ_NODISCARD az_result _az_http_client_curl_send_request_impl_process( CURL * p_curl, - az_http_request * p_request, + _az_http_request * p_request, az_http_response * response) { az_result result = AZ_ERROR_ARG; @@ -474,7 +474,7 @@ static AZ_NODISCARD az_result _az_http_client_curl_send_request_impl_process( * @return az_result */ static AZ_NODISCARD az_result -_az_http_client_curl_send_request(az_http_request * p_request, az_http_response * p_response) { +_az_http_client_curl_send_request(_az_http_request * p_request, az_http_response * p_response) { AZ_CONTRACT_ARG_NOT_NULL(p_request); AZ_CONTRACT_ARG_NOT_NULL(p_response);