diff --git a/sdk/core/core/inc/az_http.h b/sdk/core/core/inc/az_http.h index abfffc9d42..225c360139 100644 --- a/sdk/core/core/inc/az_http.h +++ b/sdk/core/core/inc/az_http.h @@ -7,6 +7,7 @@ #include #include +#include #include #include <_az_cfg_prefix.h> @@ -170,7 +171,7 @@ az_http_request_append_header(az_http_request * p_request, az_span key, az_span * - `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_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, @@ -189,6 +190,7 @@ typedef struct { } parser; } _internal; } az_http_response; + /////////////////////////////////////////////// typedef enum { @@ -196,7 +198,7 @@ typedef enum { AZ_HTTP_STATUS_CODE_CONTINUE = 100, AZ_HTTP_STATUS_CODE_SWITCHING_PROTOCOLS = 101, AZ_HTTP_STATUS_CODE_PROCESSING = 102, - AZ_HTTP_STATUS_CODE_EARLYPROCESSING = 103, + AZ_HTTP_STATUS_CODE_EARLY_HINTS = 103, // 2xx (successful) Status Codes: AZ_HTTP_STATUS_CODE_OK = 200, @@ -234,28 +236,24 @@ typedef enum { AZ_HTTP_STATUS_CODE_GONE = 410, AZ_HTTP_STATUS_CODE_LENGTH_REQUIRED = 411, AZ_HTTP_STATUS_CODE_PRECONDITION_FAILED = 412, - AZ_HTTP_STATUS_CODE_REQUEST_ENTITY_TOO_LARGE = 413, - AZ_HTTP_STATUS_CODE_REQUEST_URI_TOO_LONG = 414, + 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_REQUESTED_RANGE_NOT_SATISFIABLE = 416, + AZ_HTTP_STATUS_CODE_RANGE_NOT_SATISFIABLE = 416, AZ_HTTP_STATUS_CODE_EXPECTATION_FAILED = 417, - AZ_HTTP_STATUS_CODE_IM_A_TEAPOT = 418, - AZ_HTTP_STATUS_CODE_ENHANCE_YOUR_CALM = 420, + 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_CODEPRECONDITION_REQUIRED_ = 428, + 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_NO_RESPONSE = 444, - AZ_HTTP_STATUS_CODE_RETRY_WITH = 449, - AZ_HTTP_STATUS_CODE_BLOCKED_BY_wINDOWS_PARENTAL_cONTROLS = 450, AZ_HTTP_STATUS_CODE_UNAVAILABLE_FOR_LEGAL_REASONS = 451, - AZ_HTTP_STATUS_CODE_CLIENT_CLOSED_REQUEST = 499, - // 5xx (SERVER error) Status Codes: - AZ_HTTP_STATUS_CODE_INTERLAN_SERVER_ERROR = 500, + // 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, @@ -264,11 +262,8 @@ typedef enum { 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_BANDWIDTH_LIMIT_EXCEEDED = 509, AZ_HTTP_STATUS_CODE_NOT_EXTENDED = 510, AZ_HTTP_STATUS_CODE_NETWORK_AUTHENTICATION_REQUIRED = 511, - AZ_HTTP_STATUS_CODE_NETWORK_READ_TIMEOUT_ERROR = 598, - AZ_HTTP_STATUS_CODE_NETWORK_CONNECT_TIMEOUT_ERROR = 599, } az_http_status_code; /** @@ -285,10 +280,16 @@ typedef struct { AZ_NODISCARD AZ_INLINE az_result az_http_response_init(az_http_response * self, az_span http_response) { - *self = (az_http_response){ ._internal - = { .http_response = http_response, - .parser = { .remaining = az_span_null(), - .next_kind = AZ_HTTP_RESPONSE_KIND_STATUS_LINE } } }; + *self = (az_http_response){ + ._internal = { + .http_response = http_response, + .parser = { + .remaining = az_span_null(), + .next_kind = AZ_HTTP_RESPONSE_KIND_STATUS_LINE, + }, + }, + }; + return AZ_OK; } @@ -334,6 +335,7 @@ AZ_NODISCARD AZ_INLINE az_result az_http_response_reset(az_http_response * self) az_span_ptr(self->_internal.http_response), 0, az_span_capacity(self->_internal.http_response)); + return AZ_OK; } diff --git a/sdk/core/core/inc/az_json.h b/sdk/core/core/inc/az_json.h index 9e0fd1a324..a5fc3bc3e2 100644 --- a/sdk/core/core/inc/az_json.h +++ b/sdk/core/core/inc/az_json.h @@ -8,6 +8,7 @@ #include #include +#include #include <_az_cfg_prefix.h> @@ -110,8 +111,8 @@ AZ_NODISCARD AZ_INLINE az_result az_json_builder_init(az_json_builder * self, az return AZ_OK; } -AZ_NODISCARD AZ_INLINE az_span az_json_builder_span_get(az_json_builder self) { - return self._internal.json; +AZ_NODISCARD AZ_INLINE az_span az_json_builder_span_get(az_json_builder const * self) { + return self->_internal.json; } AZ_NODISCARD az_result az_json_builder_append_token(az_json_builder * self, az_json_token token); diff --git a/sdk/core/core/inc/az_log.h b/sdk/core/core/inc/az_log.h index 89850aff44..a0073bbd36 100644 --- a/sdk/core/core/inc/az_log.h +++ b/sdk/core/core/inc/az_log.h @@ -7,7 +7,6 @@ #include #include -#include #include #include diff --git a/sdk/core/core/inc/az_pal.h b/sdk/core/core/inc/az_pal.h index 163cc5e628..af7195227d 100644 --- a/sdk/core/core/inc/az_pal.h +++ b/sdk/core/core/inc/az_pal.h @@ -12,9 +12,9 @@ #include <_az_cfg_prefix.h> // TODO - move this into the PAL layer -az_result _az_pal_os_get(az_span * os) { +AZ_INLINE AZ_NODISCARD az_result _az_pal_os_get(az_span * out_os) { - *os = AZ_SPAN_FROM_STR("Unknown OS"); + *out_os = AZ_SPAN_FROM_STR("Unknown OS"); // Add specific implementations for each PAL implementation // // os = AZ_STR("Unix 1.0.0.0"); @@ -22,6 +22,7 @@ az_result _az_pal_os_get(az_span * os) { return AZ_OK; } + #include <_az_cfg_suffix.h> -#endif \ No newline at end of file +#endif diff --git a/sdk/core/core/inc/az_result.h b/sdk/core/core/inc/az_result.h index c406e2ca5c..7759a27f8a 100644 --- a/sdk/core/core/inc/az_result.h +++ b/sdk/core/core/inc/az_result.h @@ -6,7 +6,6 @@ #include #include -#include #include <_az_cfg_prefix.h> diff --git a/sdk/core/core/inc/az_span.h b/sdk/core/core/inc/az_span.h index a88e2ff475..3ecd9eebc4 100644 --- a/sdk/core/core/inc/az_span.h +++ b/sdk/core/core/inc/az_span.h @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -55,7 +54,7 @@ AZ_NODISCARD AZ_INLINE az_span az_span_null() { return (az_span){ 0 }; } // A size of the string literal. // Details: to make sure that `S` is a `string literal`, we are appending `""` // to `S`. -#define AZ_STRING_LITERAL_LEN(S) (sizeof(S "") - 1) +#define _az_STRING_LITERAL_LEN(S) (sizeof(S "") - 1) /** * Creates a az_span literal which can be used to initialize a constant. For example @@ -64,11 +63,11 @@ AZ_NODISCARD AZ_INLINE az_span az_span_null() { return (az_span){ 0 }; } */ #define AZ_SPAN_LITERAL_FROM_STR(STRING_LITERAL) \ { \ - ._internal \ - = {.ptr = (uint8_t *)STRING_LITERAL, \ - .length = AZ_STRING_LITERAL_LEN(STRING_LITERAL), \ - .capacity = AZ_STRING_LITERAL_LEN(STRING_LITERAL), \ - } \ + ._internal = { \ + .ptr = (uint8_t *)STRING_LITERAL, \ + .length = _az_STRING_LITERAL_LEN(STRING_LITERAL), \ + .capacity = _az_STRING_LITERAL_LEN(STRING_LITERAL), \ + }, \ } /** @@ -84,7 +83,7 @@ AZ_NODISCARD AZ_INLINE az_span az_span_null() { return (az_span){ 0 }; } * */ AZ_NODISCARD AZ_INLINE az_span az_span_init(uint8_t * ptr, int32_t length, int32_t capacity) { - return (az_span){ ._internal = { .ptr = ptr, .length = length, .capacity = capacity } }; + return (az_span){ ._internal = { .ptr = ptr, .length = length, .capacity = capacity, }, }; } /** @@ -104,10 +103,11 @@ AZ_NODISCARD AZ_INLINE az_span az_span_from_str(char * str) { */ #define AZ_SPAN_LITERAL_FROM_BUFFER(BYTE_BUFFER) \ { \ - ._internal \ - = {.ptr = BYTE_BUFFER, \ - .length = 0, \ - .capacity = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])) } \ + ._internal = { \ + .ptr = BYTE_BUFFER, \ + .length = 0, \ + .capacity = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])), \ + }, \ } #define AZ_SPAN_FROM_BUFFER(BYTE_BUFFER) (az_span) AZ_SPAN_LITERAL_FROM_BUFFER(BYTE_BUFFER) @@ -120,10 +120,11 @@ AZ_NODISCARD AZ_INLINE az_span az_span_from_str(char * str) { */ #define AZ_SPAN_LITERAL_FROM_INITIALIZED_BUFFER(BYTE_BUFFER) \ { \ - ._internal \ - = {.ptr = BYTE_BUFFER, \ - .length = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])), \ - .capacity = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])) } \ + ._internal = { \ + .ptr = BYTE_BUFFER, \ + .length = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])), \ + .capacity = (sizeof(BYTE_BUFFER) / sizeof(BYTE_BUFFER[0])), \ + }, \ } #define AZ_SPAN_FROM_INITIALIZED_BUFFER(BYTE_BUFFER) \ @@ -178,7 +179,6 @@ AZ_NODISCARD az_result az_span_copy(az_span dst, az_span src, az_span * out); AZ_NODISCARD az_result az_span_copy_url_encode(az_span dst, az_span src, az_span * out); -// TODO: this will become az_span_append once we remove actions .... /** * @brief append az_span if there is enough capacity for it * @@ -188,18 +188,8 @@ AZ_NODISCARD az_result az_span_copy_url_encode(az_span dst, az_span src, az_span */ AZ_NODISCARD az_result az_span_append(az_span self, az_span span, az_span * out); -// TODO: remove this signature/function once actions are GONE /** - * @brief append az_span if there is enough capacity for it - * - * @param self src span where to append - * @param span content to be appended - * @return AZ_NODISCARD az_span_append_ - */ -// AZ_NODISCARD az_result az_span_append_(az_span * self, az_span span); - -/** - * @brief converts @b src span to zero-terminated srt. Content is copied to @b buffer and then \0 is + * @brief converts @b src span to zero-terminated str. Content is copied to @b buffer and then \0 is * addeed at the end. Then out_result will be created out of buffer * * @param s buffer where to write str diff --git a/sdk/core/core/internal/az_contract_internal.h b/sdk/core/core/internal/az_contract_internal.h index 3e377328e9..c52be97b1c 100644 --- a/sdk/core/core/internal/az_contract_internal.h +++ b/sdk/core/core/internal/az_contract_internal.h @@ -4,9 +4,9 @@ #ifndef _az_CONTRACT_INTERNAL_H #define _az_CONTRACT_INTERNAL_H -#include #include +#include #include #include <_az_cfg_prefix.h> diff --git a/sdk/core/core/internal/az_log_internal.h b/sdk/core/core/internal/az_log_internal.h index 1450159a37..e7382344f1 100644 --- a/sdk/core/core/internal/az_log_internal.h +++ b/sdk/core/core/internal/az_log_internal.h @@ -7,6 +7,8 @@ #include #include +#include + #include <_az_cfg_prefix.h> void az_log_write(az_log_classification classification, az_span message); diff --git a/sdk/core/core/src/az_http_request_builder.c b/sdk/core/core/src/az_http_request_builder.c index 3cae4917e4..0047ee4fb2 100644 --- a/sdk/core/core/src/az_http_request_builder.c +++ b/sdk/core/core/src/az_http_request_builder.c @@ -123,7 +123,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 * p_hrb, int32_t index, az_pair * out_result) { +az_http_request_get_header(az_http_request const * p_hrb, int32_t index, az_pair * out_result) { AZ_CONTRACT_ARG_NOT_NULL(p_hrb); AZ_CONTRACT_ARG_NOT_NULL(out_result); diff --git a/sdk/core/core/src/az_span.c b/sdk/core/core/src/az_span.c index 5eba06ca31..39affb68c9 100644 --- a/sdk/core/core/src/az_span.c +++ b/sdk/core/core/src/az_span.c @@ -179,7 +179,7 @@ void az_span_swap(az_span a, az_span b) { } /** - * @brief converts @b src span to zero-terminated srt. Content is copied to @b buffer and then \0 is + * @brief converts @b src span to zero-terminated str. Content is copied to @b buffer and then \0 is * addeed at the end. Then out_result will be created out of buffer * * @param buffer diff --git a/sdk/core/core/test/az_test.h b/sdk/core/core/test/az_test.h index 79a640a16c..7e020d2809 100644 --- a/sdk/core/core/test/az_test.h +++ b/sdk/core/core/test/az_test.h @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MIT #include +#include extern int exit_code; diff --git a/sdk/core/core/test/test_log.c b/sdk/core/core/test/test_log.c index 8c77a73858..bfd5c19a4e 100644 --- a/sdk/core/core/test/test_log.c +++ b/sdk/core/core/test/test_log.c @@ -20,7 +20,7 @@ static inline void _reset_log_invocation_status() { } static void _log_listener(az_log_classification classification, az_span message) { - // fprintf(stderr, "%.*s\n", (unsigned int)message.size, message.begin); + // fprintf(stderr, "%.*s\n", (unsigned int)az_span_length(message), az_span_ptr(message)); switch (classification) { case AZ_LOG_HTTP_REQUEST: _log_invoked_for_http_request = true; diff --git a/sdk/keyvault/keyvault/inc/az_keyvault.h b/sdk/keyvault/keyvault/inc/az_keyvault.h index d1494863a1..c357c27b2c 100644 --- a/sdk/keyvault/keyvault/inc/az_keyvault.h +++ b/sdk/keyvault/keyvault/inc/az_keyvault.h @@ -4,7 +4,6 @@ #ifndef _az_KEYVAULT_H #define _az_KEYVAULT_H -#include #include #include #include @@ -12,8 +11,6 @@ #include #include -#include -#include #include #include <_az_cfg_prefix.h> @@ -62,6 +59,7 @@ AZ_NODISCARD az_result az_keyvault_keys_client_init( az_keyvault_keys_client_options * options); typedef az_span json_web_key_type; + AZ_NODISCARD AZ_INLINE json_web_key_type az_keyvault_web_key_type_ec() { return AZ_SPAN_FROM_STR("EC"); } diff --git a/sdk/keyvault/keyvault/src/az_keyvault_client.c b/sdk/keyvault/keyvault/src/az_keyvault_client.c index c97da8cbdd..2aa03419ee 100644 --- a/sdk/keyvault/keyvault/src/az_keyvault_client.c +++ b/sdk/keyvault/keyvault/src/az_keyvault_client.c @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT +#include #include #include #include diff --git a/sdk/keyvault/keyvault/test/client_key_poc.c b/sdk/keyvault/keyvault/test/client_key_poc.c index 4e235541b4..13e97d02b6 100644 --- a/sdk/keyvault/keyvault/test/client_key_poc.c +++ b/sdk/keyvault/keyvault/test/client_key_poc.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include <_az_cfg.h> diff --git a/sdk/storage/blobs/inc/az_storage_blobs.h b/sdk/storage/blobs/inc/az_storage_blobs.h index da6996cc9f..9196610ca1 100644 --- a/sdk/storage/blobs/inc/az_storage_blobs.h +++ b/sdk/storage/blobs/inc/az_storage_blobs.h @@ -4,13 +4,14 @@ #ifndef _az_STORAGE_BLOBS_H #define _az_STORAGE_BLOBS_H -#include #include #include #include #include #include +#include + #include <_az_cfg_prefix.h> static az_span const AZ_STORAGE_API_VERSION = AZ_SPAN_LITERAL_FROM_STR("2019-02-02"); 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 e9ed2622ef..8f955263d8 100644 --- a/sdk/storage/blobs/src/az_storage_blobs_blob_client.c +++ b/sdk/storage/blobs/src/az_storage_blobs_blob_client.c @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT +#include #include #include #include @@ -19,8 +20,8 @@ static az_span const AZ_STORAGE_BLOBS_BLOB_TYPE_BLOCKBLOB = AZ_SPAN_LITERAL_FROM static az_span const AZ_HTTP_HEADER_CONTENT_LENGTH = AZ_SPAN_LITERAL_FROM_STR("Content-Length"); static az_span const AZ_HTTP_HEADER_CONTENT_TYPE = AZ_SPAN_LITERAL_FROM_STR("Content-Type"); -AZ_NODISCARD az_storage_blobs_blob_client_options -az_storage_blobs_blob_client_options_default(az_http_transport_options const * http_transport_options) { +AZ_NODISCARD az_storage_blobs_blob_client_options az_storage_blobs_blob_client_options_default( + az_http_transport_options const * http_transport_options) { az_storage_blobs_blob_client_options options = { ._internal = { .http_transport_options = *http_transport_options, .api_version = az_http_policy_apiversion_options_default(), @@ -141,14 +142,14 @@ AZ_NODISCARD az_result az_storage_blobs_blob_upload( // AZ_RETURN_IF_FAILED(az_http_request_append_header( // &hrb, AZ_HTTP_HEADER_X_MS_DATE, AZ_SPAN_FROM_STR("Fri, 03 Jan 2020 21:33:15 GMT"))); - char str[256] = { 0 }; - // TODO: remove snprintf - snprintf(str, sizeof str, "%d", az_span_length(content)); - az_span content_length = az_span_from_str(str); + // Longest span (excluding 0 terminator) for any int32_t decimal value to be represented. + uint8_t content_length_buf[sizeof("-2147483648") - 1] = { 0 }; + az_span content_length_span = AZ_SPAN_FROM_BUFFER(content_length_buf); + AZ_RETURN_IF_FAILED(az_span_append_int64(&content_length_span, az_span_length(content))); // add Content-Length to request AZ_RETURN_IF_FAILED( - az_http_request_append_header(&hrb, AZ_HTTP_HEADER_CONTENT_LENGTH, content_length)); + az_http_request_append_header(&hrb, AZ_HTTP_HEADER_CONTENT_LENGTH, content_length_span)); // add blob type to request AZ_RETURN_IF_FAILED(az_http_request_append_header( diff --git a/sdk/storage/blobs/test/storage_blobs_poc.c b/sdk/storage/blobs/test/storage_blobs_poc.c index 8dd7ff5f4f..d842bb3a8c 100644 --- a/sdk/storage/blobs/test/storage_blobs_poc.c +++ b/sdk/storage/blobs/test/storage_blobs_poc.c @@ -6,6 +6,7 @@ #include #include +#include #include #include <_az_cfg.h> diff --git a/sdk/transport_policies/curl/src/az_curl.c b/sdk/transport_policies/curl/src/az_curl.c index 5c7eaaea59..1e331d18a0 100644 --- a/sdk/transport_policies/curl/src/az_curl.c +++ b/sdk/transport_policies/curl/src/az_curl.c @@ -22,14 +22,14 @@ #define AZ_CONTRACT_ARG_NOT_NULL(arg) AZ_CONTRACT((arg) != NULL, AZ_ERROR_ARG) -static AZ_NODISCARD az_result _az_span_malloc(size_t size, az_span * out) { +static AZ_NODISCARD az_result _az_span_malloc(int32_t size, az_span * out) { AZ_CONTRACT_ARG_NOT_NULL(out); - uint8_t * const p = (uint8_t *)malloc(size); + uint8_t * const p = (uint8_t *)malloc((size_t)size); if (p == NULL) { return AZ_ERROR_OUT_OF_MEMORY; } - *out = az_span_init(p, 0, (int32_t)size); + *out = az_span_init(p, 0, size); return AZ_OK; } @@ -116,9 +116,8 @@ static AZ_NODISCARD az_result _az_http_client_curl_add_header_to_curl_list( // allocate a buffer for header az_span writable_buffer; { - size_t const buffer_size = (size_t)az_span_length(header.key) - + (size_t)az_span_length(separator) + (size_t)az_span_length(header.value) - + (size_t)az_span_length(AZ_SPAN_FROM_STR("\0")); + int32_t const buffer_size = az_span_length(header.key) + az_span_length(separator) + + az_span_length(header.value) + az_span_length(AZ_SPAN_FROM_STR("\0")); AZ_RETURN_IF_FAILED(_az_span_malloc(buffer_size, &writable_buffer)); } @@ -376,9 +375,8 @@ _az_http_client_curl_setup_url(CURL * p_curl, az_http_request const * p_request) az_span writable_buffer; { - // set URL as 0-terminated str - size_t const url_final_size - = az_span_length(p_request->_internal.url) + az_span_length(AZ_SPAN_FROM_STR("\0")); + // Add 1 for 0-terminated str + int32_t const url_final_size = az_span_length(p_request->_internal.url) + 1; // allocate buffer to add \0 AZ_RETURN_IF_FAILED(_az_span_malloc(url_final_size, &writable_buffer));