From 1ab7de174ef1f2481c09276c23298c828f0a9084 Mon Sep 17 00:00:00 2001 From: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> Date: Fri, 28 Aug 2020 17:15:42 -0700 Subject: [PATCH] Make AZ_RETURN_IF... internal. (#1160) --- sdk/inc/azure/core/az_result.h | 25 ------ .../azure/core/internal/az_result_internal.h | 53 ++++++++++++ sdk/samples/iot/iot_sample_common.c | 34 ++++---- sdk/samples/iot/iot_sample_common.h | 78 +++++++++++------ .../iot/paho_iot_hub_pnp_component_sample.c | 20 ++--- sdk/samples/iot/paho_iot_hub_pnp_sample.c | 80 ++++++++--------- sdk/samples/iot/paho_iot_hub_twin_sample.c | 28 +++--- .../iot/pnp/pnp_device_info_component.c | 85 ++++++++++++------- sdk/samples/iot/pnp/pnp_mqtt_message.c | 2 +- sdk/samples/iot/pnp/pnp_protocol.c | 70 +++++++-------- .../iot/pnp/pnp_thermostat_component.c | 49 ++++++----- .../iot/pnp/pnp_thermostat_component.h | 1 + sdk/src/azure/core/az_aad.c | 49 +++++------ .../azure/core/az_credential_client_secret.c | 15 ++-- sdk/src/azure/core/az_http_policy.c | 7 +- sdk/src/azure/core/az_http_policy_logging.c | 29 ++++--- sdk/src/azure/core/az_http_policy_retry.c | 22 ++--- sdk/src/azure/core/az_http_request.c | 7 +- sdk/src/azure/core/az_http_response.c | 27 +++--- sdk/src/azure/core/az_json_reader.c | 27 +++--- sdk/src/azure/core/az_json_token.c | 5 +- sdk/src/azure/core/az_json_writer.c | 52 ++++++------ sdk/src/azure/core/az_precondition.c | 4 +- sdk/src/azure/core/az_span.c | 19 +++-- sdk/src/azure/iot/az_iot_common.c | 5 +- sdk/src/azure/iot/az_iot_hub_client.c | 7 +- sdk/src/azure/iot/az_iot_hub_client_c2d.c | 5 +- sdk/src/azure/iot/az_iot_hub_client_methods.c | 6 +- sdk/src/azure/iot/az_iot_hub_client_sas.c | 40 ++++----- .../azure/iot/az_iot_hub_client_telemetry.c | 8 +- sdk/src/azure/iot/az_iot_hub_client_twin.c | 24 +++--- .../azure/iot/az_iot_provisioning_client.c | 54 ++++++------ .../iot/az_iot_provisioning_client_sas.c | 36 ++++---- sdk/src/azure/platform/az_curl.c | 74 ++++++++-------- .../storage/az_storage_blobs_blob_client.c | 17 ++-- sdk/tests/core/test_az_json.c | 55 ++++++------ 36 files changed, 621 insertions(+), 498 deletions(-) create mode 100644 sdk/inc/azure/core/internal/az_result_internal.h diff --git a/sdk/inc/azure/core/az_result.h b/sdk/inc/azure/core/az_result.h index 1dca92a6758..c925c6ae2dc 100644 --- a/sdk/inc/azure/core/az_result.h +++ b/sdk/inc/azure/core/az_result.h @@ -41,31 +41,6 @@ enum #define _az_RESULT_MAKE_SUCCESS(facility, code) \ ((int32_t)(((int32_t)(facility) << 16) | (int32_t)(code))) -/** - * @brief Convenience macro to return if an operation failed. - */ -#define AZ_RETURN_IF_FAILED(exp) \ - do \ - { \ - az_result const _result = (exp); \ - if (az_result_failed(_result)) \ - { \ - return _result; \ - } \ - } while (0) - -/** - * @brief Convenience macro to return if the provided span is not of the expected, required size. - */ -#define AZ_RETURN_IF_NOT_ENOUGH_SIZE(span, required_size) \ - do \ - { \ - if (az_span_size(span) < required_size || required_size < 0) \ - { \ - return AZ_ERROR_INSUFFICIENT_SPAN_SIZE; \ - } \ - } while (0) - // az_result Bits: // - 31 Severity (0 - success, 1 - failure). // - 16..30 Facility. diff --git a/sdk/inc/azure/core/internal/az_result_internal.h b/sdk/inc/azure/core/internal/az_result_internal.h new file mode 100644 index 00000000000..83137cafcc5 --- /dev/null +++ b/sdk/inc/azure/core/internal/az_result_internal.h @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @file + * + * @brief Definition of #az_result related internal helper functions. + * + * @note You MUST NOT use any symbols (macros, functions, structures, enums, etc.) + * prefixed with an underscore ('_') directly in your application code. These symbols + * are part of Azure SDK's internal implementation; we do not document these symbols + * and they are subject to change in future versions of the SDK which would break your code. + */ + +#ifndef _az_RESULT_INTERNAL_H +#define _az_RESULT_INTERNAL_H + +#include +#include + +#include + +#include + +/** + * @brief Convenience macro to return if an operation failed. + */ +#define _az_RETURN_IF_FAILED(exp) \ + do \ + { \ + az_result const _az_result = (exp); \ + if (az_result_failed(_az_result)) \ + { \ + return _az_result; \ + } \ + } while (0) + +/** + * @brief Convenience macro to return if the provided span is not of the expected, required size. + */ +#define _az_RETURN_IF_NOT_ENOUGH_SIZE(span, required_size) \ + do \ + { \ + int32_t const _az_req_sz = (required_size); \ + if (az_span_size(span) < _az_req_sz || _az_req_sz < 0) \ + { \ + return AZ_ERROR_INSUFFICIENT_SPAN_SIZE; \ + } \ + } while (0) + +#include + +#endif // _az_RESULT_INTERNAL_H diff --git a/sdk/samples/iot/iot_sample_common.c b/sdk/samples/iot/iot_sample_common.c index 564426e94cb..2dd32de4f76 100644 --- a/sdk/samples/iot/iot_sample_common.c +++ b/sdk/samples/iot/iot_sample_common.c @@ -82,7 +82,7 @@ static az_result read_configuration_entry( (void)printf("%s = %s\n", env_name, hide_value ? "***" : env_value); az_span env_span = az_span_create_from_str(env_value); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(destination, az_span_size(env_span)); + IOT_SAMPLE_RETURN_IF_NOT_ENOUGH_SIZE(destination, az_span_size(env_span)); az_span_copy(destination, env_span); *out_env_value = az_span_slice(destination, 0, az_span_size(env_span)); } @@ -105,7 +105,7 @@ az_result iot_sample_read_environment_variables( if (type == PAHO_IOT_HUB) { out_env_vars->hub_hostname = AZ_SPAN_FROM_BUFFER(iot_sample_hub_hostname_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_HUB_HOSTNAME, NULL, false, @@ -121,7 +121,7 @@ az_result iot_sample_read_environment_variables( case PAHO_IOT_HUB_TELEMETRY_SAMPLE: case PAHO_IOT_HUB_TWIN_SAMPLE: out_env_vars->hub_device_id = AZ_SPAN_FROM_BUFFER(iot_sample_hub_device_id_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_HUB_DEVICE_ID, NULL, false, @@ -130,7 +130,7 @@ az_result iot_sample_read_environment_variables( out_env_vars->x509_cert_pem_file_path = AZ_SPAN_FROM_BUFFER(iot_sample_x509_cert_pem_file_path_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_DEVICE_X509_CERT_PEM_FILE_PATH, NULL, false, @@ -140,7 +140,7 @@ az_result iot_sample_read_environment_variables( case PAHO_IOT_HUB_SAS_TELEMETRY_SAMPLE: out_env_vars->hub_device_id = AZ_SPAN_FROM_BUFFER(iot_sample_hub_device_id_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_HUB_SAS_DEVICE_ID, NULL, false, @@ -148,7 +148,7 @@ az_result iot_sample_read_environment_variables( &(out_env_vars->hub_device_id))); out_env_vars->hub_sas_key = AZ_SPAN_FROM_BUFFER(iot_sample_hub_sas_key_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_HUB_SAS_KEY, NULL, true, @@ -157,9 +157,10 @@ az_result iot_sample_read_environment_variables( char duration_buffer[IOT_SAMPLE_SAS_KEY_DURATION_TIME_DIGITS]; az_span duration = AZ_SPAN_FROM_BUFFER(duration_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_SAS_KEY_DURATION_MINUTES, "120", false, duration, &duration)); - AZ_RETURN_IF_FAILED(az_span_atou32(duration, &(out_env_vars->sas_key_duration_minutes))); + IOT_SAMPLE_RETURN_IF_FAILED( + az_span_atou32(duration, &(out_env_vars->sas_key_duration_minutes))); break; default: @@ -171,7 +172,7 @@ az_result iot_sample_read_environment_variables( { out_env_vars->provisioning_id_scope = AZ_SPAN_FROM_BUFFER(iot_sample_provisioning_id_scope_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_PROVISIONING_ID_SCOPE, NULL, false, @@ -183,7 +184,7 @@ az_result iot_sample_read_environment_variables( case PAHO_IOT_PROVISIONING_SAMPLE: out_env_vars->provisioning_registration_id = AZ_SPAN_FROM_BUFFER(iot_sample_provisioning_registration_id_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_PROVISIONING_REGISTRATION_ID, NULL, false, @@ -192,7 +193,7 @@ az_result iot_sample_read_environment_variables( out_env_vars->x509_cert_pem_file_path = AZ_SPAN_FROM_BUFFER(iot_sample_x509_cert_pem_file_path_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_DEVICE_X509_CERT_PEM_FILE_PATH, NULL, false, @@ -203,7 +204,7 @@ az_result iot_sample_read_environment_variables( case PAHO_IOT_PROVISIONING_SAS_SAMPLE: out_env_vars->provisioning_registration_id = AZ_SPAN_FROM_BUFFER(iot_sample_provisioning_registration_id_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_PROVISIONING_SAS_REGISTRATION_ID, NULL, false, @@ -212,7 +213,7 @@ az_result iot_sample_read_environment_variables( out_env_vars->provisioning_sas_key = AZ_SPAN_FROM_BUFFER(iot_sample_provisioning_sas_key_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_PROVISIONING_SAS_KEY, NULL, true, @@ -221,9 +222,10 @@ az_result iot_sample_read_environment_variables( char duration_buffer[IOT_SAMPLE_SAS_KEY_DURATION_TIME_DIGITS]; az_span duration = AZ_SPAN_FROM_BUFFER(duration_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_SAS_KEY_DURATION_MINUTES, "120", false, duration, &duration)); - AZ_RETURN_IF_FAILED(az_span_atou32(duration, &(out_env_vars->sas_key_duration_minutes))); + IOT_SAMPLE_RETURN_IF_FAILED( + az_span_atou32(duration, &(out_env_vars->sas_key_duration_minutes))); break; default: @@ -239,7 +241,7 @@ az_result iot_sample_read_environment_variables( out_env_vars->x509_trust_pem_file_path = AZ_SPAN_FROM_BUFFER(iot_sample_x509_trust_pem_file_path_buffer); - AZ_RETURN_IF_FAILED(read_configuration_entry( + IOT_SAMPLE_RETURN_IF_FAILED(read_configuration_entry( IOT_SAMPLE_ENV_DEVICE_X509_TRUST_PEM_FILE_PATH, "", false, diff --git a/sdk/samples/iot/iot_sample_common.h b/sdk/samples/iot/iot_sample_common.h index 8159a3d5d9a..5cfd6aa8e3a 100644 --- a/sdk/samples/iot/iot_sample_common.h +++ b/sdk/samples/iot/iot_sample_common.h @@ -18,42 +18,65 @@ // // Logging // -#define IOT_SAMPLE_LOG_ERROR(...) \ - do \ - { \ +#define IOT_SAMPLE_LOG_ERROR(...) \ + do \ + { \ (void)fprintf(stderr, "ERROR:\t\t%s:%s():%d: ", __FILE__, __func__, __LINE__); \ - (void)fprintf(stderr, __VA_ARGS__); \ - (void)fprintf(stderr, "\n"); \ - fflush(stdout); \ - fflush(stderr); \ + (void)fprintf(stderr, __VA_ARGS__); \ + (void)fprintf(stderr, "\n"); \ + fflush(stdout); \ + fflush(stderr); \ } while (0) #define IOT_SAMPLE_LOG_SUCCESS(...) \ - do \ - { \ - (void)printf("SUCCESS:\t"); \ - (void)printf(__VA_ARGS__); \ - (void)printf("\n"); \ + do \ + { \ + (void)printf("SUCCESS:\t"); \ + (void)printf(__VA_ARGS__); \ + (void)printf("\n"); \ } while (0) -#define IOT_SAMPLE_LOG(...) \ - do \ - { \ - (void)printf("\t\t"); \ +#define IOT_SAMPLE_LOG(...) \ + do \ + { \ + (void)printf("\t\t"); \ (void)printf(__VA_ARGS__); \ - (void)printf("\n"); \ + (void)printf("\n"); \ } while (0) -#define IOT_SAMPLE_LOG_AZ_SPAN(span_description, span) \ - do \ - { \ - (void)printf("\t\t%s ", span_description); \ - char* buffer = (char*)az_span_ptr(span); \ +#define IOT_SAMPLE_LOG_AZ_SPAN(span_description, span) \ + do \ + { \ + (void)printf("\t\t%s ", span_description); \ + char* buffer = (char*)az_span_ptr(span); \ for (int32_t az_span_i = 0; az_span_i < az_span_size(span); az_span_i++) \ - { \ - putchar(*buffer++); \ - } \ - (void)printf("\n"); \ + { \ + putchar(*buffer++); \ + } \ + (void)printf("\n"); \ + } while (0) + +// +// Error handling +// +#define IOT_SAMPLE_RETURN_IF_FAILED(exp) \ + do \ + { \ + az_result const _iot_sample_result = (exp); \ + if (az_result_failed(_iot_sample_result)) \ + { \ + return _iot_sample_result; \ + } \ + } while (0) + +#define IOT_SAMPLE_RETURN_IF_NOT_ENOUGH_SIZE(span, required_size) \ + do \ + { \ + int32_t _iot_sample_req_sz = (required_size); \ + if (az_span_size(span) < _iot_sample_req_sz || _iot_sample_req_sz < 0) \ + { \ + return AZ_ERROR_INSUFFICIENT_SPAN_SIZE; \ + } \ } while (0) // @@ -137,7 +160,8 @@ typedef enum * @return An #az_result value indicating the result of the operation. * @retval #AZ_OK All required environment variables successfully read-in. * @retval #AZ_ERROR_ARG Sample type or name is undefined, or environment variable is not set. - * @retval #AZ_RETURN_IF_NOT_ENOUGH_SIZE Not enough space set aside to store environment variable. + * @retval #AZ_ERROR_INSUFFICIENT_SPAN_SIZE Not enough space set aside to store environment + * variable. */ az_result iot_sample_read_environment_variables( iot_sample_type type, diff --git a/sdk/samples/iot/paho_iot_hub_pnp_component_sample.c b/sdk/samples/iot/paho_iot_hub_pnp_component_sample.c index 727ddf4193d..0a901f21a52 100644 --- a/sdk/samples/iot/paho_iot_hub_pnp_component_sample.c +++ b/sdk/samples/iot/paho_iot_hub_pnp_component_sample.c @@ -25,9 +25,9 @@ #include #include -#include "pnp/pnp_protocol.h" #include "pnp/pnp_device_info_component.h" #include "pnp/pnp_mqtt_message.h" +#include "pnp/pnp_protocol.h" #include "pnp/pnp_thermostat_component.h" #define SAMPLE_TYPE PAHO_IOT_HUB @@ -910,11 +910,11 @@ static az_result temp_controller_get_telemetry_message(pnp_mqtt_message* message // Build the telemetry message. az_json_writer jw; - AZ_RETURN_IF_FAILED(az_json_writer_init(&jw, message->payload_span, NULL)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, working_set_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_int32(&jw, working_set_ram_in_kibibytes)); - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_init(&jw, message->payload_span, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, working_set_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_int32(&jw, working_set_ram_in_kibibytes)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); message->out_payload_span = az_json_writer_get_bytes_used_in_destination(&jw); return rc; @@ -935,14 +935,14 @@ static az_result append_json_token_callback(az_json_writer* jw, void* value) switch (value_token.kind) { case AZ_JSON_TOKEN_NUMBER: - AZ_RETURN_IF_FAILED(az_json_token_get_double(&value_token, &value_as_double)); - AZ_RETURN_IF_FAILED( + IOT_SAMPLE_RETURN_IF_FAILED(az_json_token_get_double(&value_token, &value_as_double)); + IOT_SAMPLE_RETURN_IF_FAILED( az_json_writer_append_double(jw, value_as_double, DOUBLE_DECIMAL_PLACE_DIGITS)); break; case AZ_JSON_TOKEN_STRING: - AZ_RETURN_IF_FAILED(az_json_token_get_string( + IOT_SAMPLE_RETURN_IF_FAILED(az_json_token_get_string( &value_token, property_scratch_buffer, sizeof(property_scratch_buffer), &string_length)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string( + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_string( jw, az_span_create((uint8_t*)property_scratch_buffer, string_length))); break; default: diff --git a/sdk/samples/iot/paho_iot_hub_pnp_sample.c b/sdk/samples/iot/paho_iot_hub_pnp_sample.c index f9a2137bc67..53fbb506156 100644 --- a/sdk/samples/iot/paho_iot_hub_pnp_sample.c +++ b/sdk/samples/iot/paho_iot_hub_pnp_sample.c @@ -614,8 +614,8 @@ static az_result parse_device_twin_desired_temperature_property( { az_json_reader jr; - AZ_RETURN_IF_FAILED(az_json_reader_init(&jr, twin_message_span, NULL)); - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_init(&jr, twin_message_span, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_BEGIN_OBJECT) { return AZ_ERROR_UNEXPECTED_CHAR; @@ -625,21 +625,21 @@ static az_result parse_device_twin_desired_temperature_property( bool desired_found = false; if (is_twin_get) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); while (jr.token.kind != AZ_JSON_TOKEN_END_OBJECT) { if (az_json_token_is_text_equal(&jr.token, twin_desired_name)) { desired_found = true; - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); break; } else { - AZ_RETURN_IF_FAILED(az_json_reader_skip_children(&jr)); // Ignore children tokens. + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_skip_children(&jr)); // Ignore children tokens. } - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); // Check next sibling token. + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); // Check next sibling token. } if (!desired_found) @@ -654,26 +654,26 @@ static az_result parse_device_twin_desired_temperature_property( bool temp_found = false; bool version_found = false; - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); while (!(temp_found && version_found) && (jr.token.kind != AZ_JSON_TOKEN_END_OBJECT)) { if (az_json_token_is_text_equal(&jr.token, twin_desired_temp_property_name)) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); - AZ_RETURN_IF_FAILED(az_json_token_get_double(&jr.token, parsed_temp)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_token_get_double(&jr.token, parsed_temp)); temp_found = true; } else if (az_json_token_is_text_equal(&jr.token, twin_version_name)) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); - AZ_RETURN_IF_FAILED(az_json_token_get_uint32(&jr.token, (uint32_t*)version_number)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_token_get_uint32(&jr.token, (uint32_t*)version_number)); version_found = true; } else { - AZ_RETURN_IF_FAILED(az_json_reader_skip_children(&jr)); // Ignore children tokens. + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_skip_children(&jr)); // Ignore children tokens. } - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); // Check next sibling token. + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); // Check next sibling token. } if (!(temp_found && version_found)) @@ -845,9 +845,9 @@ static az_result invoke_getMaxMinReport( az_json_reader jr; // Parse the "since" field in the payload. - AZ_RETURN_IF_FAILED(az_json_reader_init(&jr, payload, NULL)); - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); - AZ_RETURN_IF_FAILED(az_json_token_get_string( + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_init(&jr, payload, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_token_get_string( &jr.token, command_start_time_value_buffer, sizeof(command_start_time_value_buffer), @@ -943,24 +943,25 @@ static az_result build_property_payload( { az_json_writer jw; - AZ_RETURN_IF_FAILED(az_json_writer_init(&jw, payload_destination, NULL)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_init(&jw, payload_destination, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); for (uint8_t i = 0; i < property_count; i++) { - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, names[i])); - AZ_RETURN_IF_FAILED(az_json_writer_append_double(&jw, values[i], DOUBLE_DECIMAL_PLACE_DIGITS)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, names[i])); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_double(&jw, values[i], DOUBLE_DECIMAL_PLACE_DIGITS)); } if (times != NULL) { - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, command_start_time_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, times[0])); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, command_end_time_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, times[1])); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, command_start_time_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_string(&jw, times[0])); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, command_end_time_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_string(&jw, times[1])); } - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); *payload_out = az_json_writer_get_bytes_used_in_destination(&jw); return AZ_OK; @@ -977,20 +978,21 @@ static az_result build_property_payload_with_status( { az_json_writer jw; - AZ_RETURN_IF_FAILED(az_json_writer_init(&jw, payload_destination, NULL)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, twin_value_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_double(&jw, value, DOUBLE_DECIMAL_PLACE_DIGITS)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, twin_ack_code_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_int32(&jw, ack_code_value)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, twin_ack_version_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_int32(&jw, ack_version_value)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, twin_ack_description_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, ack_description_value)); - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_init(&jw, payload_destination, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, twin_value_name)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_double(&jw, value, DOUBLE_DECIMAL_PLACE_DIGITS)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, twin_ack_code_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_int32(&jw, ack_code_value)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, twin_ack_version_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_int32(&jw, ack_version_value)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, twin_ack_description_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_string(&jw, ack_description_value)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); *payload_out = az_json_writer_get_bytes_used_in_destination(&jw); diff --git a/sdk/samples/iot/paho_iot_hub_twin_sample.c b/sdk/samples/iot/paho_iot_hub_twin_sample.c index 4e90aa37dfb..58fd16bdb5c 100644 --- a/sdk/samples/iot/paho_iot_hub_twin_sample.c +++ b/sdk/samples/iot/paho_iot_hub_twin_sample.c @@ -455,11 +455,12 @@ static az_result build_reported_property( { az_json_writer json_writer; - AZ_RETURN_IF_FAILED(az_json_writer_init(&json_writer, reported_property_payload, NULL)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&json_writer)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&json_writer, reported_property_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_int32(&json_writer, reported_property_value)); - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&json_writer)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_init(&json_writer, reported_property_payload, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&json_writer)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_property_name(&json_writer, reported_property_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_int32(&json_writer, reported_property_value)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&json_writer)); *out_reported_property_payload = az_json_writer_get_bytes_used_in_destination(&json_writer); @@ -472,15 +473,15 @@ static az_result update_local_property(az_span desired_payload, bool* out_proper // Parse desired property payload. az_json_reader json_reader; - AZ_RETURN_IF_FAILED(az_json_reader_init(&json_reader, desired_payload, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_init(&json_reader, desired_payload, NULL)); - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&json_reader)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&json_reader)); if (json_reader.token.kind != AZ_JSON_TOKEN_BEGIN_OBJECT) { return AZ_ERROR_UNEXPECTED_CHAR; } - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&json_reader)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&json_reader)); // Update property locally if found. while (json_reader.token.kind != AZ_JSON_TOKEN_END_OBJECT) @@ -488,8 +489,9 @@ static az_result update_local_property(az_span desired_payload, bool* out_proper if (az_json_token_is_text_equal(&json_reader.token, reported_property_name)) { // Move to the value token and store value. - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&json_reader)); - AZ_RETURN_IF_FAILED(az_json_token_get_int32(&json_reader.token, &reported_property_value)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&json_reader)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_token_get_int32(&json_reader.token, &reported_property_value)); IOT_SAMPLE_LOG_SUCCESS( "Client updated \"%.*s\" locally to %d.", az_span_size(reported_property_name), @@ -505,10 +507,12 @@ static az_result update_local_property(az_span desired_payload, bool* out_proper } else { - AZ_RETURN_IF_FAILED(az_json_reader_skip_children(&json_reader)); // Ignore children tokens. + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_reader_skip_children(&json_reader)); // Ignore children tokens. } - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&json_reader)); // Check next sibling token. + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_reader_next_token(&json_reader)); // Check next sibling token. } IOT_SAMPLE_LOG( diff --git a/sdk/samples/iot/pnp/pnp_device_info_component.c b/sdk/samples/iot/pnp/pnp_device_info_component.c index b66f5a0cb81..a25f178b2c7 100644 --- a/sdk/samples/iot/pnp/pnp_device_info_component.c +++ b/sdk/samples/iot/pnp/pnp_device_info_component.c @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT +#include + #include "pnp_device_info_component.h" #include "pnp_mqtt_message.h" @@ -12,18 +14,27 @@ #define DOUBLE_DECIMAL_PLACE_DIGITS 2 /* Reported property keys and values */ -static const az_span pnp_device_info_software_version_property_name = AZ_SPAN_LITERAL_FROM_STR("swVersion"); -static const az_span pnp_device_info_software_version_property_value = AZ_SPAN_LITERAL_FROM_STR("1.0.0.0"); -static const az_span pnp_device_info_manufacturer_property_name = AZ_SPAN_LITERAL_FROM_STR("manufacturer"); -static const az_span pnp_device_info_manufacturer_property_value = AZ_SPAN_LITERAL_FROM_STR("Sample-Manufacturer"); +static const az_span pnp_device_info_software_version_property_name + = AZ_SPAN_LITERAL_FROM_STR("swVersion"); +static const az_span pnp_device_info_software_version_property_value + = AZ_SPAN_LITERAL_FROM_STR("1.0.0.0"); +static const az_span pnp_device_info_manufacturer_property_name + = AZ_SPAN_LITERAL_FROM_STR("manufacturer"); +static const az_span pnp_device_info_manufacturer_property_value + = AZ_SPAN_LITERAL_FROM_STR("Sample-Manufacturer"); static const az_span pnp_device_info_model_property_name = AZ_SPAN_LITERAL_FROM_STR("model"); -static const az_span pnp_device_info_model_property_value = AZ_SPAN_LITERAL_FROM_STR("pnp-sample-Model-123"); +static const az_span pnp_device_info_model_property_value + = AZ_SPAN_LITERAL_FROM_STR("pnp-sample-Model-123"); static const az_span pnp_device_info_os_name_property_name = AZ_SPAN_LITERAL_FROM_STR("osName"); static const az_span pnp_device_info_os_name_property_value = AZ_SPAN_LITERAL_FROM_STR("Contoso"); -static const az_span pnp_device_info_processor_architecture_property_name = AZ_SPAN_LITERAL_FROM_STR("processorArchitecture"); -static const az_span pnp_device_info_processor_architecture_property_value = AZ_SPAN_LITERAL_FROM_STR("Contoso-Arch-64bit"); -static const az_span pnp_device_info_processor_manufacturer_property_name = AZ_SPAN_LITERAL_FROM_STR("processorManufacturer"); -static const az_span pnp_device_info_processor_manufacturer_property_value = AZ_SPAN_LITERAL_FROM_STR("Processor Manufacturer(TM)"); +static const az_span pnp_device_info_processor_architecture_property_name + = AZ_SPAN_LITERAL_FROM_STR("processorArchitecture"); +static const az_span pnp_device_info_processor_architecture_property_value + = AZ_SPAN_LITERAL_FROM_STR("Contoso-Arch-64bit"); +static const az_span pnp_device_info_processor_manufacturer_property_name + = AZ_SPAN_LITERAL_FROM_STR("processorManufacturer"); +static const az_span pnp_device_info_processor_manufacturer_property_value + = AZ_SPAN_LITERAL_FROM_STR("Processor Manufacturer(TM)"); static const az_span pnp_device_info_total_storage_property_name = AZ_SPAN_LITERAL_FROM_STR("totalStorage"); static const double pnp_device_info_total_storage_property_value = 1024.0; @@ -36,30 +47,46 @@ az_result pnp_device_info_get_report_data( pnp_mqtt_message* mqtt_message) { az_json_writer jw; - AZ_RETURN_IF_FAILED(az_json_writer_init(&jw, mqtt_message->payload_span, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_init(&jw, mqtt_message->payload_span, NULL)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, pnp_device_info_manufacturer_property_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, pnp_device_info_manufacturer_property_value)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, pnp_device_info_model_property_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, pnp_device_info_model_property_value)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, pnp_device_info_software_version_property_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, pnp_device_info_software_version_property_value)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, pnp_device_info_os_name_property_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, pnp_device_info_os_name_property_value)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, pnp_device_info_processor_architecture_property_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, pnp_device_info_processor_architecture_property_value)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, pnp_device_info_processor_manufacturer_property_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, pnp_device_info_processor_manufacturer_property_value)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, pnp_device_info_total_storage_property_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_double(&jw, pnp_device_info_total_storage_property_value, DOUBLE_DECIMAL_PLACE_DIGITS)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, pnp_device_info_total_memory_property_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_double(&jw, pnp_device_info_total_memory_property_value, DOUBLE_DECIMAL_PLACE_DIGITS)); - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_property_name(&jw, pnp_device_info_manufacturer_property_name)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_string(&jw, pnp_device_info_manufacturer_property_value)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_property_name(&jw, pnp_device_info_model_property_name)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_string(&jw, pnp_device_info_model_property_value)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_property_name(&jw, pnp_device_info_software_version_property_name)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_string(&jw, pnp_device_info_software_version_property_value)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_property_name(&jw, pnp_device_info_os_name_property_name)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_string(&jw, pnp_device_info_os_name_property_value)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name( + &jw, pnp_device_info_processor_architecture_property_name)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_string(&jw, pnp_device_info_processor_architecture_property_value)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name( + &jw, pnp_device_info_processor_manufacturer_property_name)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_string(&jw, pnp_device_info_processor_manufacturer_property_value)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_property_name(&jw, pnp_device_info_total_storage_property_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_double( + &jw, pnp_device_info_total_storage_property_value, DOUBLE_DECIMAL_PLACE_DIGITS)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_property_name(&jw, pnp_device_info_total_memory_property_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_double( + &jw, pnp_device_info_total_memory_property_value, DOUBLE_DECIMAL_PLACE_DIGITS)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); mqtt_message->out_payload_span = az_json_writer_get_bytes_used_in_destination(&jw); - AZ_RETURN_IF_FAILED(az_iot_hub_client_twin_patch_get_publish_topic( + IOT_SAMPLE_RETURN_IF_FAILED(az_iot_hub_client_twin_patch_get_publish_topic( client, get_request_id(), mqtt_message->topic, diff --git a/sdk/samples/iot/pnp/pnp_mqtt_message.c b/sdk/samples/iot/pnp/pnp_mqtt_message.c index 26fd13d60ef..e1197435c16 100644 --- a/sdk/samples/iot/pnp/pnp_mqtt_message.c +++ b/sdk/samples/iot/pnp/pnp_mqtt_message.c @@ -16,7 +16,7 @@ static char request_id_buf[10]; static char publish_topic[128]; static char publish_payload[512]; - void pnp_mqtt_message_init(pnp_mqtt_message* mqtt_message) +void pnp_mqtt_message_init(pnp_mqtt_message* mqtt_message) { if (mqtt_message == NULL) { diff --git a/sdk/samples/iot/pnp/pnp_protocol.c b/sdk/samples/iot/pnp/pnp_protocol.c index 7b79afacdd6..d97508ee270 100644 --- a/sdk/samples/iot/pnp/pnp_protocol.c +++ b/sdk/samples/iot/pnp/pnp_protocol.c @@ -160,15 +160,15 @@ az_result pnp_get_telemetry_topic( { properties = &pnp_properties; - AZ_RETURN_IF_FAILED(az_iot_message_properties_init( + IOT_SAMPLE_RETURN_IF_FAILED(az_iot_message_properties_init( properties, AZ_SPAN_FROM_BUFFER(pnp_properties_buffer), 0)); } - AZ_RETURN_IF_FAILED(az_iot_message_properties_append( + IOT_SAMPLE_RETURN_IF_FAILED(az_iot_message_properties_append( properties, component_telemetry_prop_span, component_name)); } - AZ_RETURN_IF_FAILED(az_iot_hub_client_telemetry_get_publish_topic( + IOT_SAMPLE_RETURN_IF_FAILED(az_iot_hub_client_telemetry_get_publish_topic( client, az_span_ptr(component_name) != NULL ? properties : NULL, mqtt_topic, @@ -208,27 +208,27 @@ az_result pnp_create_reported_property( az_span* out_span) { az_json_writer jw; - AZ_RETURN_IF_FAILED(az_json_writer_init(&jw, json_buffer, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_init(&jw, json_buffer, NULL)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); if (az_span_ptr(component_name) != NULL) { - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, component_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, component_specifier_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, component_specifier_value)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, component_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, component_specifier_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_string(&jw, component_specifier_value)); } - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, property_name)); - AZ_RETURN_IF_FAILED(append_callback(&jw, context)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, property_name)); + IOT_SAMPLE_RETURN_IF_FAILED(append_callback(&jw, context)); if (az_span_ptr(component_name) != NULL) { - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); } - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); *out_span = az_json_writer_get_bytes_used_in_destination(&jw); @@ -249,38 +249,40 @@ az_result pnp_create_reported_property_with_status( { az_json_writer jw; - AZ_RETURN_IF_FAILED(az_json_writer_init(&jw, json_buffer, NULL)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_init(&jw, json_buffer, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); if (az_span_ptr(component_name) != NULL) { - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, component_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, component_specifier_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, component_specifier_value)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, component_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, component_specifier_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_string(&jw, component_specifier_value)); } - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, property_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, desired_temp_response_value_name)); - AZ_RETURN_IF_FAILED(append_callback(&jw, context)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, desired_temp_ack_code_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_int32(&jw, ack_code)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, desired_temp_ack_version_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_int32(&jw, ack_version)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, property_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_property_name(&jw, desired_temp_response_value_name)); + IOT_SAMPLE_RETURN_IF_FAILED(append_callback(&jw, context)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, desired_temp_ack_code_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_int32(&jw, ack_code)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_property_name(&jw, desired_temp_ack_version_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_int32(&jw, ack_version)); if (az_span_ptr(ack_description) != NULL) { - AZ_RETURN_IF_FAILED( + IOT_SAMPLE_RETURN_IF_FAILED( az_json_writer_append_property_name(&jw, desired_temp_ack_description_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, ack_description)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_string(&jw, ack_description)); } - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); if (az_span_ptr(component_name) != NULL) { - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); } *out_span = az_json_writer_get_bytes_used_in_destination(&jw); @@ -302,8 +304,8 @@ az_result pnp_process_device_twin_message( int32_t version; int32_t index; - AZ_RETURN_IF_FAILED(az_json_reader_init(&jr, twin_message_span, NULL)); - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_init(&jr, twin_message_span, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (!is_partial && az_result_failed(json_child_token_move(&jr, iot_hub_twin_desired))) { diff --git a/sdk/samples/iot/pnp/pnp_thermostat_component.c b/sdk/samples/iot/pnp/pnp_thermostat_component.c index c8c49c203c2..87ec5543dea 100644 --- a/sdk/samples/iot/pnp/pnp_thermostat_component.c +++ b/sdk/samples/iot/pnp/pnp_thermostat_component.c @@ -8,8 +8,9 @@ #endif #include -#include "pnp_protocol.h" + #include "pnp_mqtt_message.h" +#include "pnp_protocol.h" #include "pnp_thermostat_component.h" @@ -60,21 +61,23 @@ static az_result build_command_response_payload( // Build the command response payload az_json_writer jw; - AZ_RETURN_IF_FAILED(az_json_writer_init(&jw, payload, NULL)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, report_max_temp_name_span)); - AZ_RETURN_IF_FAILED(az_json_writer_append_double( + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_init(&jw, payload, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, report_max_temp_name_span)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_double( &jw, thermostat_component->max_temperature, DOUBLE_DECIMAL_PLACE_DIGITS)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, report_min_temp_name_span)); - AZ_RETURN_IF_FAILED(az_json_writer_append_double( + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, report_min_temp_name_span)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_double( &jw, thermostat_component->min_temperature, DOUBLE_DECIMAL_PLACE_DIGITS)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, report_avg_temp_name_span)); - AZ_RETURN_IF_FAILED(az_json_writer_append_double(&jw, avg_temp, DOUBLE_DECIMAL_PLACE_DIGITS)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, report_start_time_name_span)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, start_time_span)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, report_end_time_name_span)); - AZ_RETURN_IF_FAILED(az_json_writer_append_string(&jw, end_time_span)); - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, report_avg_temp_name_span)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_double(&jw, avg_temp, DOUBLE_DECIMAL_PLACE_DIGITS)); + IOT_SAMPLE_RETURN_IF_FAILED( + az_json_writer_append_property_name(&jw, report_start_time_name_span)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_string(&jw, start_time_span)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, report_end_time_name_span)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_string(&jw, end_time_span)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); *out_payload = az_json_writer_get_bytes_used_in_destination(&jw); @@ -87,12 +90,12 @@ static az_result build_telemetry_message( az_span* out_payload) { az_json_writer jw; - AZ_RETURN_IF_FAILED(az_json_writer_init(&jw, payload, NULL)); - AZ_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); - AZ_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, telemetry_name)); - AZ_RETURN_IF_FAILED(az_json_writer_append_double( + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_init(&jw, payload, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_begin_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_property_name(&jw, telemetry_name)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_double( &jw, thermostat_component->current_temperature, DOUBLE_DECIMAL_PLACE_DIGITS)); - AZ_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_writer_append_end_object(&jw)); *out_payload = az_json_writer_get_bytes_used_in_destination(&jw); return AZ_OK; @@ -110,10 +113,10 @@ static az_result invoke_getMaxMinReport( // Parse the "since" field in the payload. az_span start_time_span = AZ_SPAN_NULL; az_json_reader jr; - AZ_RETURN_IF_FAILED(az_json_reader_init(&jr, payload, NULL)); - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_init(&jr, payload, NULL)); + IOT_SAMPLE_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); int32_t incoming_since_value_buffer_len; - AZ_RETURN_IF_FAILED(az_json_token_get_string( + IOT_SAMPLE_RETURN_IF_FAILED(az_json_token_get_string( &jr.token, incoming_since_value_buffer, sizeof(incoming_since_value_buffer), @@ -136,7 +139,7 @@ static az_result invoke_getMaxMinReport( size_t len = strftime(end_time_buffer, sizeof(end_time_buffer), iso_spec_time_format, timeinfo); az_span end_time_span = az_span_create((uint8_t*)end_time_buffer, (int32_t)len); - AZ_RETURN_IF_FAILED(build_command_response_payload( + IOT_SAMPLE_RETURN_IF_FAILED(build_command_response_payload( thermostat_component, start_time_span, end_time_span, response, out_response)); return AZ_OK; diff --git a/sdk/samples/iot/pnp/pnp_thermostat_component.h b/sdk/samples/iot/pnp/pnp_thermostat_component.h index 2fd28ad8187..df34dc80b76 100644 --- a/sdk/samples/iot/pnp/pnp_thermostat_component.h +++ b/sdk/samples/iot/pnp/pnp_thermostat_component.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include diff --git a/sdk/src/azure/core/az_aad.c b/sdk/src/azure/core/az_aad.c index 947f75092ef..dec27e7eda2 100644 --- a/sdk/src/azure/core/az_aad.c +++ b/sdk/src/azure/core/az_aad.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -18,17 +19,17 @@ AZ_NODISCARD az_result _az_aad_build_url(az_span url, az_span authority, az_span tenant_id, az_span* out_url) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(url, az_span_size(authority)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(url, az_span_size(authority)); az_span remainder = az_span_copy(url, authority); { int32_t url_length = 0; - AZ_RETURN_IF_FAILED(_az_span_url_encode(remainder, tenant_id, &url_length)); + _az_RETURN_IF_FAILED(_az_span_url_encode(remainder, tenant_id, &url_length)); remainder = az_span_slice_to_end(remainder, url_length); } az_span const oath_token = AZ_SPAN_FROM_STR("/oauth2/v2.0/token"); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(oath_token)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(oath_token)); remainder = az_span_copy(remainder, oath_token); *out_url = az_span_slice(url, 0, _az_span_diff(remainder, url)); @@ -46,30 +47,30 @@ AZ_NODISCARD az_result _az_aad_build_body( { az_span const grant_type_and_client_id_key = AZ_SPAN_FROM_STR("grant_type=client_credentials&client_id="); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(body, az_span_size(grant_type_and_client_id_key)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(body, az_span_size(grant_type_and_client_id_key)); az_span remainder = az_span_copy(body, grant_type_and_client_id_key); int32_t body_length = 0; - AZ_RETURN_IF_FAILED(_az_span_url_encode(remainder, client_id, &body_length)); + _az_RETURN_IF_FAILED(_az_span_url_encode(remainder, client_id, &body_length)); remainder = az_span_slice_to_end(remainder, body_length); az_span const scope_key = AZ_SPAN_FROM_STR("&scope="); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(scope_key)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(scope_key)); remainder = az_span_copy(remainder, scope_key); - AZ_RETURN_IF_FAILED(_az_span_url_encode(remainder, scopes, &body_length)); + _az_RETURN_IF_FAILED(_az_span_url_encode(remainder, scopes, &body_length)); remainder = az_span_slice_to_end(remainder, body_length); if (az_span_size(client_secret) > 0) { az_span const client_secret_key = AZ_SPAN_FROM_STR("&client_secret="); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(client_secret_key)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(client_secret_key)); remainder = az_span_copy(remainder, client_secret_key); - AZ_RETURN_IF_FAILED(_az_span_url_encode(remainder, client_secret, &body_length)); + _az_RETURN_IF_FAILED(_az_span_url_encode(remainder, client_secret, &body_length)); remainder = az_span_slice_to_end(remainder, body_length); } @@ -83,9 +84,9 @@ AZ_NODISCARD static az_result _az_parse_json_payload( az_json_token* json_access_token) { az_json_reader jr; - AZ_RETURN_IF_FAILED(az_json_reader_init(&jr, body, NULL)); + _az_RETURN_IF_FAILED(az_json_reader_init(&jr, body, NULL)); - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_BEGIN_OBJECT) { return AZ_ERROR_UNEXPECTED_CHAR; @@ -94,28 +95,28 @@ AZ_NODISCARD static az_result _az_parse_json_payload( bool found_expires_in = false; bool found_access_token = false; - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); while (jr.token.kind != AZ_JSON_TOKEN_END_OBJECT) { if (az_json_token_is_text_equal(&jr.token, AZ_SPAN_FROM_STR("expires_in"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); - AZ_RETURN_IF_FAILED(az_json_token_get_int64(&jr.token, expires_in_seconds)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_token_get_int64(&jr.token, expires_in_seconds)); found_expires_in = true; } else if (az_json_token_is_text_equal(&jr.token, AZ_SPAN_FROM_STR("access_token"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); *json_access_token = jr.token; found_access_token = true; } else { // ignore other tokens - AZ_RETURN_IF_FAILED(az_json_reader_skip_children(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_skip_children(&jr)); } - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); } if (!found_expires_in || !found_access_token) @@ -128,14 +129,14 @@ AZ_NODISCARD static az_result _az_parse_json_payload( AZ_NODISCARD az_result _az_aad_request_token(az_http_request* request, _az_token* out_token) { - AZ_RETURN_IF_FAILED(az_http_request_append_header( + _az_RETURN_IF_FAILED(az_http_request_append_header( request, AZ_SPAN_FROM_STR("Content-Type"), AZ_SPAN_FROM_STR("application/x-www-form-urlencoded"))); uint8_t response_buf[_az_AAD_RESPONSE_BUFFER_SIZE] = { 0 }; az_http_response response = { 0 }; - AZ_RETURN_IF_FAILED(az_http_response_init(&response, AZ_SPAN_FROM_BUFFER(response_buf))); + _az_RETURN_IF_FAILED(az_http_response_init(&response, AZ_SPAN_FROM_BUFFER(response_buf))); az_http_policy_retry_options retry_options = _az_http_policy_retry_options_default(); retry_options.max_retries = 7; @@ -156,11 +157,11 @@ AZ_NODISCARD az_result _az_aad_request_token(az_http_request* request, _az_token }, }; - AZ_RETURN_IF_FAILED(az_http_pipeline_process(&pipeline, request, &response)); + _az_RETURN_IF_FAILED(az_http_pipeline_process(&pipeline, 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)); + _az_RETURN_IF_FAILED(az_http_response_get_status_line(&response, &status_line)); if (status_line.status_code != AZ_HTTP_STATUS_CODE_OK) { return AZ_ERROR_HTTP_AUTHENTICATION_FAILED; @@ -168,11 +169,11 @@ AZ_NODISCARD az_result _az_aad_request_token(az_http_request* request, _az_token // We successfully got the token, let's parse the body. az_span body = { 0 }; - AZ_RETURN_IF_FAILED(az_http_response_get_body(&response, &body)); + _az_RETURN_IF_FAILED(az_http_response_get_body(&response, &body)); int64_t expires_in_seconds = 0; az_json_token json_access_token = { 0 }; - AZ_RETURN_IF_FAILED(_az_parse_json_payload(body, &expires_in_seconds, &json_access_token)); + _az_RETURN_IF_FAILED(_az_parse_json_payload(body, &expires_in_seconds, &json_access_token)); // We'll assume the token expires 3 minutes prior to its actual expiration. int64_t const expires_in_msec = ((expires_in_seconds) - (3 * _az_TIME_SECONDS_PER_MINUTE)) @@ -190,7 +191,7 @@ AZ_NODISCARD az_result _az_aad_request_token(az_http_request* request, _az_token az_span remainder = az_span_copy(new_token_span, AZ_SPAN_FROM_STR("Bearer ")); int32_t bytes_written = 0; - AZ_RETURN_IF_FAILED(az_json_token_get_string( + _az_RETURN_IF_FAILED(az_json_token_get_string( &json_access_token, (char*)az_span_ptr(remainder), az_span_size(remainder), &bytes_written)); new_token._internal.token_length diff --git a/sdk/src/azure/core/az_credential_client_secret.c b/sdk/src/azure/core/az_credential_client_secret.c index 3014fcffbc0..6d4c9b707db 100644 --- a/sdk/src/azure/core/az_credential_client_secret.c +++ b/sdk/src/azure/core/az_credential_client_secret.c @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -25,12 +26,12 @@ static AZ_NODISCARD az_result _az_credential_client_secret_request_token( az_span url_span = AZ_SPAN_FROM_BUFFER(url_buf); az_span url; - AZ_RETURN_IF_FAILED(_az_aad_build_url( + _az_RETURN_IF_FAILED(_az_aad_build_url( url_span, credential->_internal.authority, credential->_internal.tenant_id, &url)); uint8_t body_buf[_az_AAD_REQUEST_BODY_BUFFER_SIZE] = { 0 }; az_span body = AZ_SPAN_FROM_BUFFER(body_buf); - AZ_RETURN_IF_FAILED(_az_aad_build_body( + _az_RETURN_IF_FAILED(_az_aad_build_body( body, credential->_internal.client_id, credential->_internal.scopes, @@ -39,7 +40,7 @@ static AZ_NODISCARD az_result _az_credential_client_secret_request_token( uint8_t header_buf[_az_AAD_REQUEST_HEADER_BUFFER_SIZE]; az_http_request request = { 0 }; - AZ_RETURN_IF_FAILED(az_http_request_init( + _az_RETURN_IF_FAILED(az_http_request_init( &request, context, az_http_method_post(), @@ -61,21 +62,21 @@ static AZ_NODISCARD az_result _az_credential_client_secret_apply_policy( az_http_response* response) { _az_token token = { 0 }; - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( _az_credential_token_get_token(&credential->_internal.token_credential, &token)); if (_az_token_expired(&token)) { - AZ_RETURN_IF_FAILED(_az_credential_client_secret_request_token( + _az_RETURN_IF_FAILED(_az_credential_client_secret_request_token( credential, ref_request->_internal.context, &token)); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( _az_credential_token_set_token(&credential->_internal.token_credential, &token)); } int16_t const token_length = token._internal.token_length; - AZ_RETURN_IF_FAILED(az_http_request_append_header( + _az_RETURN_IF_FAILED(az_http_request_append_header( ref_request, _az_auth_header_name, az_span_create(token._internal.token, token_length))); return _az_http_pipeline_nextpolicy(policies, ref_request, response); diff --git a/sdk/src/azure/core/az_http_policy.c b/sdk/src/azure/core/az_http_policy.c index 751e8e16e64..b739a923e43 100644 --- a/sdk/src/azure/core/az_http_policy.c +++ b/sdk/src/azure/core/az_http_policy.c @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -25,13 +26,13 @@ AZ_NODISCARD az_result az_http_pipeline_policy_apiversion( { case _az_http_policy_apiversion_option_location_header: // Add the version as a header - AZ_RETURN_IF_FAILED(az_http_request_append_header( + _az_RETURN_IF_FAILED(az_http_request_append_header( ref_request, options->_internal.name, options->_internal.version)); break; case _az_http_policy_apiversion_option_location_queryparameter: // Add the version as a query parameter. This value doesn't need url-encoding. Use `true` for // url-encode to avoid encoding. - AZ_RETURN_IF_FAILED(az_http_request_set_query_parameter( + _az_RETURN_IF_FAILED(az_http_request_set_query_parameter( ref_request, options->_internal.name, options->_internal.version, true)); break; default: @@ -50,7 +51,7 @@ AZ_NODISCARD az_result az_http_pipeline_policy_telemetry( _az_http_policy_telemetry_options* options = (_az_http_policy_telemetry_options*)(ref_options); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( az_http_request_append_header(ref_request, AZ_HTTP_HEADER_USER_AGENT, options->os)); return _az_http_pipeline_nextpolicy(ref_policies, ref_request, ref_response); diff --git a/sdk/src/azure/core/az_http_policy_logging.c b/sdk/src/azure/core/az_http_policy_logging.c index acdf1901f31..9b36496b823 100644 --- a/sdk/src/azure/core/az_http_policy_logging.c +++ b/sdk/src/azure/core/az_http_policy_logging.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -72,7 +73,7 @@ static az_result _az_http_policy_logging_append_http_request_msg( required_length = az_span_size(request->_internal.method) + request->_internal.url_length + 1; } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*ref_log_msg, required_length); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*ref_log_msg, required_length); az_span remainder = az_span_copy(*ref_log_msg, http_request_string); @@ -96,7 +97,7 @@ static az_result _az_http_policy_logging_append_http_request_msg( for (int32_t index = 0; index < headers_count; ++index) { az_pair header = { 0 }; - AZ_RETURN_IF_FAILED(az_http_request_get_header(request, index, &header)); + _az_RETURN_IF_FAILED(az_http_request_get_header(request, index, &header)); required_length = az_span_size(new_line_tab_string) + az_span_size(header.key); if (az_span_size(header.value) > 0) @@ -104,7 +105,7 @@ static az_result _az_http_policy_logging_append_http_request_msg( required_length += _az_LOG_LENGTHY_VALUE_MAX_LENGTH + az_span_size(colon_separator_string); } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, required_length); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, required_length); remainder = az_span_copy(remainder, new_line_tab_string); remainder = az_span_copy(remainder, header.key); @@ -127,19 +128,19 @@ static az_result _az_http_policy_logging_append_http_response_msg( az_span* ref_log_msg) { az_span http_response_string = AZ_SPAN_FROM_STR("HTTP Response ("); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*ref_log_msg, az_span_size(http_response_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*ref_log_msg, az_span_size(http_response_string)); az_span remainder = az_span_copy(*ref_log_msg, http_response_string); - AZ_RETURN_IF_FAILED(az_span_i64toa(remainder, duration_msec, &remainder)); + _az_RETURN_IF_FAILED(az_span_i64toa(remainder, duration_msec, &remainder)); az_span ms_string = AZ_SPAN_FROM_STR("ms)"); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(ms_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(ms_string)); remainder = az_span_copy(remainder, ms_string); if (ref_response == NULL || az_span_size(ref_response->_internal.http_response) == 0) { az_span is_empty_string = AZ_SPAN_FROM_STR(" is empty"); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(is_empty_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(is_empty_string)); remainder = az_span_copy(remainder, is_empty_string); *ref_log_msg = az_span_slice(*ref_log_msg, 0, _az_span_diff(remainder, *ref_log_msg)); @@ -147,14 +148,14 @@ static az_result _az_http_policy_logging_append_http_response_msg( } az_span colon_separator_string = AZ_SPAN_FROM_STR(" : "); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(colon_separator_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(colon_separator_string)); remainder = az_span_copy(remainder, colon_separator_string); az_http_response_status_line status_line = { 0 }; - AZ_RETURN_IF_FAILED(az_http_response_get_status_line(ref_response, &status_line)); - AZ_RETURN_IF_FAILED(az_span_u64toa(remainder, (uint64_t)status_line.status_code, &remainder)); + _az_RETURN_IF_FAILED(az_http_response_get_status_line(ref_response, &status_line)); + _az_RETURN_IF_FAILED(az_span_u64toa(remainder, (uint64_t)status_line.status_code, &remainder)); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(status_line.reason_phrase) + 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(status_line.reason_phrase) + 1); remainder = az_span_copy_u8(remainder, ' '); remainder = az_span_copy(remainder, status_line.reason_phrase); @@ -170,7 +171,7 @@ static az_result _az_http_policy_logging_append_http_response_msg( required_length += _az_LOG_LENGTHY_VALUE_MAX_LENGTH + az_span_size(colon_separator_string); } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, required_length); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, required_length); remainder = az_span_copy(remainder, new_line_tab_string); remainder = az_span_copy(remainder, header.key); @@ -191,13 +192,13 @@ static az_result _az_http_policy_logging_append_http_response_msg( az_span new_lines_string = AZ_SPAN_FROM_STR("\n\n"); az_span arrow_separator_string = AZ_SPAN_FROM_STR(" -> "); int32_t required_length = az_span_size(new_lines_string) + az_span_size(arrow_separator_string); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, required_length); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, required_length); remainder = az_span_copy(remainder, new_lines_string); remainder = az_span_copy(remainder, arrow_separator_string); az_span append_request = remainder; - AZ_RETURN_IF_FAILED(_az_http_policy_logging_append_http_request_msg(request, &append_request)); + _az_RETURN_IF_FAILED(_az_http_policy_logging_append_http_request_msg(request, &append_request)); *ref_log_msg = az_span_slice( *ref_log_msg, 0, _az_span_diff(remainder, *ref_log_msg) + az_span_size(append_request)); diff --git a/sdk/src/azure/core/az_http_policy_retry.c b/sdk/src/azure/core/az_http_policy_retry.c index 6a113828f45..72af1c38a9c 100644 --- a/sdk/src/azure/core/az_http_policy_retry.c +++ b/sdk/src/azure/core/az_http_policy_retry.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -41,19 +42,19 @@ AZ_INLINE az_result _az_http_policy_retry_append_http_retry_msg( az_span* ref_log_msg) { az_span retry_count_string = AZ_SPAN_FROM_STR("HTTP Retry attempt #"); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*ref_log_msg, az_span_size(retry_count_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*ref_log_msg, az_span_size(retry_count_string)); az_span remainder = az_span_copy(*ref_log_msg, retry_count_string); - AZ_RETURN_IF_FAILED(az_span_i32toa(remainder, attempt, &remainder)); + _az_RETURN_IF_FAILED(az_span_i32toa(remainder, attempt, &remainder)); az_span infix_string = AZ_SPAN_FROM_STR(" will be made in "); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(infix_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(infix_string)); remainder = az_span_copy(remainder, infix_string); - AZ_RETURN_IF_FAILED(az_span_i32toa(remainder, delay_msec, &remainder)); + _az_RETURN_IF_FAILED(az_span_i32toa(remainder, delay_msec, &remainder)); az_span suffix_string = AZ_SPAN_FROM_STR("ms."); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(suffix_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(suffix_string)); remainder = az_span_copy(remainder, suffix_string); *ref_log_msg = az_span_slice(*ref_log_msg, 0, _az_span_diff(remainder, *ref_log_msg)); @@ -89,7 +90,7 @@ AZ_INLINE AZ_NODISCARD az_result _az_http_policy_retry_get_retry_after( int32_t* retry_after_msec) { az_http_response_status_line status_line = { 0 }; - AZ_RETURN_IF_FAILED(az_http_response_get_status_line(ref_response, &status_line)); + _az_RETURN_IF_FAILED(az_http_response_get_status_line(ref_response, &status_line)); az_http_status_code const response_code = status_line.status_code; for (; *status_codes != AZ_HTTP_STATUS_CODE_END_OF_LIST; ++status_codes) @@ -159,7 +160,7 @@ AZ_NODISCARD az_result az_http_pipeline_policy_retry( int32_t const max_retry_delay_msec = retry_options->max_retry_delay_msec; az_http_status_code const* const status_codes = retry_options->status_codes; - AZ_RETURN_IF_FAILED(_az_http_request_mark_retry_headers_start(ref_request)); + _az_RETURN_IF_FAILED(_az_http_request_mark_retry_headers_start(ref_request)); az_context* const context = ref_request->_internal.context; @@ -168,8 +169,9 @@ AZ_NODISCARD az_result az_http_pipeline_policy_retry( int32_t attempt = 1; while (true) { - AZ_RETURN_IF_FAILED(az_http_response_init(ref_response, ref_response->_internal.http_response)); - AZ_RETURN_IF_FAILED(_az_http_request_remove_retry_headers(ref_request)); + _az_RETURN_IF_FAILED( + az_http_response_init(ref_response, ref_response->_internal.http_response)); + _az_RETURN_IF_FAILED(_az_http_request_remove_retry_headers(ref_request)); result = _az_http_pipeline_nextpolicy(ref_policies, ref_request, ref_response); @@ -182,7 +184,7 @@ AZ_NODISCARD az_result az_http_pipeline_policy_retry( int32_t retry_after_msec = -1; bool should_retry = false; az_http_response response_copy = *ref_response; - AZ_RETURN_IF_FAILED(_az_http_policy_retry_get_retry_after( + _az_RETURN_IF_FAILED(_az_http_policy_retry_get_retry_after( &response_copy, status_codes, &should_retry, &retry_after_msec)); if (!should_retry) diff --git a/sdk/src/azure/core/az_http_request.c b/sdk/src/azure/core/az_http_request.c index 67ba0778445..deec1eb6726 100644 --- a/sdk/src/azure/core/az_http_request.c +++ b/sdk/src/azure/core/az_http_request.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -83,7 +84,7 @@ AZ_NODISCARD az_result az_http_request_set_query_parameter( int32_t required_length = 2 + az_span_size(name) + (is_value_url_encoded ? az_span_size(value) : _az_span_url_encode_calc_length(value)); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(url_remainder, required_length); + _az_RETURN_IF_NOT_ENOUGH_SIZE(url_remainder, required_length); // Append either '?' or '&' uint8_t separator = '&'; @@ -109,7 +110,7 @@ AZ_NODISCARD az_result az_http_request_set_query_parameter( else { int32_t encoding_size = 0; - AZ_RETURN_IF_FAILED(_az_span_url_encode(url_remainder, value, &encoding_size)); + _az_RETURN_IF_FAILED(_az_span_url_encode(url_remainder, value, &encoding_size)); } ref_request->_internal.url_length += required_length; @@ -134,7 +135,7 @@ az_http_request_append_header(az_http_request* ref_request, az_span key, az_span az_span headers = ref_request->_internal.headers; az_pair header_to_append = az_pair_init(key, value); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(headers, (int32_t)sizeof header_to_append); + _az_RETURN_IF_NOT_ENOUGH_SIZE(headers, (int32_t)sizeof header_to_append); az_span_copy( az_span_slice_to_end( diff --git a/sdk/src/azure/core/az_http_response.c b/sdk/src/azure/core/az_http_response.c index 5ba935aa7e9..222702b54ae 100644 --- a/sdk/src/azure/core/az_http_response.c +++ b/sdk/src/azure/core/az_http_response.c @@ -8,6 +8,7 @@ #include "az_span_private.h" #include #include +#include #include #include @@ -60,25 +61,25 @@ _az_get_http_status_line(az_span* ref_span, az_http_response_status_line* out_st az_span const space = AZ_SPAN_FROM_STR(" "); // parse and move reader if success - AZ_RETURN_IF_FAILED(_az_is_expected_span(ref_span, start)); - AZ_RETURN_IF_FAILED(_az_get_digit(ref_span, &out_status_line->major_version)); - AZ_RETURN_IF_FAILED(_az_is_expected_span(ref_span, dot)); - AZ_RETURN_IF_FAILED(_az_get_digit(ref_span, &out_status_line->minor_version)); + _az_RETURN_IF_FAILED(_az_is_expected_span(ref_span, start)); + _az_RETURN_IF_FAILED(_az_get_digit(ref_span, &out_status_line->major_version)); + _az_RETURN_IF_FAILED(_az_is_expected_span(ref_span, dot)); + _az_RETURN_IF_FAILED(_az_get_digit(ref_span, &out_status_line->minor_version)); // SP = " " - AZ_RETURN_IF_FAILED(_az_is_expected_span(ref_span, space)); + _az_RETURN_IF_FAILED(_az_is_expected_span(ref_span, space)); // status-code = 3DIGIT { uint64_t code = 0; - AZ_RETURN_IF_FAILED(az_span_atou64(az_span_create(az_span_ptr(*ref_span), 3), &code)); + _az_RETURN_IF_FAILED(az_span_atou64(az_span_create(az_span_ptr(*ref_span), 3), &code)); out_status_line->status_code = (az_http_status_code)code; // move reader *ref_span = az_span_slice_to_end(*ref_span, 3); } // SP - AZ_RETURN_IF_FAILED(_az_is_expected_span(ref_span, space)); + _az_RETURN_IF_FAILED(_az_is_expected_span(ref_span, space)); // get a pointer to read response until end of reason-phrase is found // reason-phrase = *(HTAB / SP / VCHAR / obs-text) @@ -105,7 +106,7 @@ _az_get_http_status_line(az_span* ref_span, az_http_response_status_line* out_st // move position of reader after reason-phrase (parsed done) *ref_span = az_span_slice_to_end(*ref_span, offset + 1); // CR LF - // AZ_RETURN_IF_FAILED(_az_is_expected_span(response, AZ_SPAN_FROM_STR("\r\n"))); + // _az_RETURN_IF_FAILED(_az_is_expected_span(response, AZ_SPAN_FROM_STR("\r\n"))); return AZ_OK; } @@ -121,7 +122,7 @@ AZ_NODISCARD az_result az_http_response_get_status_line( ref_response->_internal.parser.remaining = ref_response->_internal.http_response; // read an HTTP status line. - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( _az_get_http_status_line(&ref_response->_internal.parser.remaining, out_status_line)); // set state.kind of the next HTTP response value. @@ -157,7 +158,7 @@ az_http_response_get_next_header(az_http_response* ref_response, az_pair* out_he // We keep state to Headers if current char is not '\r' (there is another header) if (az_span_ptr(ref_response->_internal.parser.remaining)[0] == '\r') { - AZ_RETURN_IF_FAILED(_az_is_expected_span(reader, AZ_SPAN_FROM_STR("\r\n"))); + _az_RETURN_IF_FAILED(_az_is_expected_span(reader, AZ_SPAN_FROM_STR("\r\n"))); ref_response->_internal.parser.next_kind = _az_HTTP_RESPONSE_KIND_BODY; return AZ_ERROR_HTTP_END_OF_HEADERS; } @@ -258,7 +259,7 @@ az_http_response_get_next_header(az_http_response* ref_response, az_pair* out_he out_header->value = _az_span_trim_whitespace_from_end(out_header->value); } - AZ_RETURN_IF_FAILED(_az_is_expected_span(reader, AZ_SPAN_FROM_STR("\n"))); + _az_RETURN_IF_FAILED(_az_is_expected_span(reader, AZ_SPAN_FROM_STR("\n"))); return AZ_OK; } @@ -278,7 +279,7 @@ AZ_NODISCARD az_result az_http_response_get_body(az_http_response* ref_response, { // Reset parser and get status line az_http_response_status_line ignore = { 0 }; - AZ_RETURN_IF_FAILED(az_http_response_get_status_line(ref_response, &ignore)); + _az_RETURN_IF_FAILED(az_http_response_get_status_line(ref_response, &ignore)); // update current parsing section current_parsing_section = ref_response->_internal.parser.next_kind; } @@ -321,7 +322,7 @@ AZ_NODISCARD az_result az_http_response_append(az_http_response* ref_response, a az_span remaining = _az_http_response_get_remaining(ref_response); int32_t write_size = az_span_size(source); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining, write_size); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining, write_size); remaining = az_span_copy(remaining, source); ref_response->_internal.written += write_size; diff --git a/sdk/src/azure/core/az_json_reader.c b/sdk/src/azure/core/az_json_reader.c index 70e08286181..dc81106b8bf 100644 --- a/sdk/src/azure/core/az_json_reader.c +++ b/sdk/src/azure/core/az_json_reader.c @@ -4,6 +4,7 @@ #include "az_json_private.h" #include "az_span_private.h" #include +#include #include #include @@ -252,7 +253,7 @@ AZ_NODISCARD static az_result _az_json_reader_process_string(az_json_reader* ref if (remaining_size < 1) { - AZ_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); + _az_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); remaining_size = az_span_size(token); } @@ -277,7 +278,7 @@ AZ_NODISCARD static az_result _az_json_reader_process_string(az_json_reader* ref string_length++; if (current_index >= remaining_size) { - AZ_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); + _az_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); current_index = 0; token_ptr = az_span_ptr(token); remaining_size = az_span_size(token); @@ -294,7 +295,7 @@ AZ_NODISCARD static az_result _az_json_reader_process_string(az_json_reader* ref { if (current_index > remaining_size) { - AZ_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); + _az_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); current_index = 0; token_ptr = az_span_ptr(token); remaining_size = az_span_size(token); @@ -336,7 +337,7 @@ AZ_NODISCARD static az_result _az_json_reader_process_string(az_json_reader* ref if (current_index >= remaining_size) { - AZ_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); + _az_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); current_index = 0; token_ptr = az_span_ptr(token); remaining_size = az_span_size(token); @@ -360,7 +361,7 @@ AZ_NODISCARD static az_result _az_json_reader_process_string(az_json_reader* ref AZ_NODISCARD static az_result _az_json_reader_process_property_name(az_json_reader* ref_json_reader) { - AZ_RETURN_IF_FAILED(_az_json_reader_process_string(ref_json_reader)); + _az_RETURN_IF_FAILED(_az_json_reader_process_string(ref_json_reader)); az_span json = _az_json_reader_skip_whitespace(ref_json_reader); @@ -485,7 +486,7 @@ AZ_NODISCARD static az_result _az_validate_next_byte_is_digit( az_span current = az_span_slice_to_end(*remaining_number, *current_consumed); if (az_span_size(current) < 1) { - AZ_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, remaining_number, false)); + _az_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, remaining_number, false)); current = *remaining_number; *current_consumed = 0; } @@ -512,7 +513,7 @@ AZ_NODISCARD static az_result _az_json_reader_process_number(az_json_reader* ref current_consumed++; // A negative sign must be followed by at least one digit. - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( _az_validate_next_byte_is_digit(ref_json_reader, &token, ¤t_consumed)); next_byte = az_span_ptr(token)[current_consumed]; @@ -601,7 +602,7 @@ AZ_NODISCARD static az_result _az_json_reader_process_number(az_json_reader* ref current_consumed++; // A decimal point must be followed by at least one digit. - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( _az_validate_next_byte_is_digit(ref_json_reader, &token, ¤t_consumed)); // Integer part after decimal @@ -647,7 +648,7 @@ AZ_NODISCARD static az_result _az_json_reader_process_number(az_json_reader* ref // The 'e'/'E' character must be followed by a sign or at least one digit. if (current_consumed >= az_span_size(token)) { - AZ_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); + _az_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); current_consumed = 0; } @@ -658,7 +659,7 @@ AZ_NODISCARD static az_result _az_json_reader_process_number(az_json_reader* ref current_consumed++; // A sign must be followed by at least one digit. - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( _az_validate_next_byte_is_digit(ref_json_reader, &token, ¤t_consumed)); } @@ -733,7 +734,7 @@ AZ_NODISCARD static az_result _az_json_reader_process_literal( } // If there is no more data, return EOF because the token is smaller than the expected literal. - AZ_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); + _az_RETURN_IF_FAILED(_az_json_reader_get_next_buffer(ref_json_reader, &token, false)); } _az_json_reader_update_state( @@ -940,7 +941,7 @@ AZ_NODISCARD az_result az_json_reader_skip_children(az_json_reader* ref_json_rea if (ref_json_reader->token.kind == AZ_JSON_TOKEN_PROPERTY_NAME) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(ref_json_reader)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(ref_json_reader)); } az_json_token_kind const token_kind = ref_json_reader->token.kind; @@ -950,7 +951,7 @@ AZ_NODISCARD az_result az_json_reader_skip_children(az_json_reader* ref_json_rea int32_t const depth = ref_json_reader->_internal.bit_stack._internal.current_depth; do { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(ref_json_reader)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(ref_json_reader)); } while (depth <= ref_json_reader->_internal.bit_stack._internal.current_depth); } return AZ_OK; diff --git a/sdk/src/azure/core/az_json_token.c b/sdk/src/azure/core/az_json_token.c index d4f999fdcb0..d19f29fdd83 100644 --- a/sdk/src/azure/core/az_json_token.c +++ b/sdk/src/azure/core/az_json_token.c @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MIT #include +#include #include #include "az_json_private.h" @@ -391,7 +392,7 @@ AZ_NODISCARD az_result az_json_token_get_string( // Contiguous token if (az_span_ptr(token_slice) != NULL) { - AZ_RETURN_IF_FAILED(_az_json_token_get_string_helper( + _az_RETURN_IF_FAILED(_az_json_token_get_string_helper( token_slice, destination, destination_max_size, &dest_idx, &next_char_escaped)); } else @@ -411,7 +412,7 @@ AZ_NODISCARD az_result az_json_token_get_string( source = az_span_slice(source, 0, json_token->_internal.end_buffer_offset); } - AZ_RETURN_IF_FAILED(_az_json_token_get_string_helper( + _az_RETURN_IF_FAILED(_az_json_token_get_string_helper( source, destination, destination_max_size, &dest_idx, &next_char_escaped)); } } diff --git a/sdk/src/azure/core/az_json_writer.c b/sdk/src/azure/core/az_json_writer.c index f8829c25f22..21e1b506daa 100644 --- a/sdk/src/azure/core/az_json_writer.c +++ b/sdk/src/azure/core/az_json_writer.c @@ -5,7 +5,9 @@ #include "az_json_private.h" #include "az_span_private.h" #include +#include #include + #include #include @@ -421,7 +423,7 @@ static AZ_NODISCARD az_result az_json_writer_span_copy_chunked( value = az_span_slice_to_end(value, az_span_size(value_slice_that_fits)); *remaining_json = _get_remaining_span(ref_json_writer, _az_MINIMUM_STRING_CHUNK_SIZE); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); } } return AZ_OK; @@ -445,7 +447,7 @@ az_json_writer_append_string_small(az_json_writer* ref_json_writer, az_span valu _az_PRECONDITION(required_size <= _az_MINIMUM_STRING_CHUNK_SIZE); az_span remaining_json = _get_remaining_span(ref_json_writer, required_size); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); if (ref_json_writer->_internal.need_comma) { @@ -482,7 +484,7 @@ az_json_writer_append_string_chunked(az_json_writer* ref_json_writer, az_span va _az_PRECONDITION(az_span_size(value) > _az_MAX_UNESCAPED_STRING_SIZE_PER_CHUNK); az_span remaining_json = _get_remaining_span(ref_json_writer, _az_MINIMUM_STRING_CHUNK_SIZE); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); int32_t required_size = 2; // For the surrounding quotes. if (ref_json_writer->_internal.need_comma) @@ -505,7 +507,7 @@ az_json_writer_append_string_chunked(az_json_writer* ref_json_writer, az_span va // No character needed to be escaped, copy the whole string as is. if (index_of_first_escaped_char == -1) { - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( az_json_writer_span_copy_chunked(ref_json_writer, &remaining_json, value_slice)); consumed += az_span_size(value_slice); } @@ -513,7 +515,7 @@ az_json_writer_append_string_chunked(az_json_writer* ref_json_writer, az_span va { // Bulk copy the characters that didn't need to be escaped before dropping to the byte-by-byte // encode and copy. - AZ_RETURN_IF_FAILED(az_json_writer_span_copy_chunked( + _az_RETURN_IF_FAILED(az_json_writer_span_copy_chunked( ref_json_writer, &remaining_json, az_span_slice(value_slice, 0, index_of_first_escaped_char))); @@ -524,7 +526,7 @@ az_json_writer_append_string_chunked(az_json_writer* ref_json_writer, az_span va uint8_t const ch = value_ptr[index_of_first_escaped_char]; remaining_json = _get_remaining_span(ref_json_writer, _az_MINIMUM_STRING_CHUNK_SIZE); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); int32_t written = _az_json_writer_escape_next_byte_and_copy(&remaining_json, ch); ref_json_writer->_internal.bytes_written += written; @@ -538,7 +540,7 @@ az_json_writer_append_string_chunked(az_json_writer* ref_json_writer, az_span va } while (consumed < az_span_size(value)); remaining_json = _get_remaining_span(ref_json_writer, _az_MINIMUM_STRING_CHUNK_SIZE); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); az_span_copy_u8(remaining_json, '"'); ref_json_writer->_internal.bytes_written++; @@ -588,7 +590,7 @@ az_json_writer_append_property_name_small(az_json_writer* ref_json_writer, az_sp _az_PRECONDITION(required_size <= _az_MINIMUM_STRING_CHUNK_SIZE); az_span remaining_json = _get_remaining_span(ref_json_writer, required_size); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); if (ref_json_writer->_internal.need_comma) { @@ -626,7 +628,7 @@ az_json_writer_append_property_name_chunked(az_json_writer* ref_json_writer, az_ _az_PRECONDITION(az_span_size(value) > _az_MAX_UNESCAPED_STRING_SIZE_PER_CHUNK); az_span remaining_json = _get_remaining_span(ref_json_writer, _az_MINIMUM_STRING_CHUNK_SIZE); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); int32_t required_size = 3; // For the surrounding quotes and the key:value separator colon. if (ref_json_writer->_internal.need_comma) @@ -649,7 +651,7 @@ az_json_writer_append_property_name_chunked(az_json_writer* ref_json_writer, az_ // No character needed to be escaped, copy the whole string as is. if (index_of_first_escaped_char == -1) { - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( az_json_writer_span_copy_chunked(ref_json_writer, &remaining_json, value_slice)); consumed += az_span_size(value_slice); } @@ -657,7 +659,7 @@ az_json_writer_append_property_name_chunked(az_json_writer* ref_json_writer, az_ { // Bulk copy the characters that didn't need to be escaped before dropping to the byte-by-byte // encode and copy. - AZ_RETURN_IF_FAILED(az_json_writer_span_copy_chunked( + _az_RETURN_IF_FAILED(az_json_writer_span_copy_chunked( ref_json_writer, &remaining_json, az_span_slice(value_slice, 0, index_of_first_escaped_char))); @@ -668,7 +670,7 @@ az_json_writer_append_property_name_chunked(az_json_writer* ref_json_writer, az_ uint8_t const ch = value_ptr[index_of_first_escaped_char]; remaining_json = _get_remaining_span(ref_json_writer, _az_MINIMUM_STRING_CHUNK_SIZE); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); int32_t written = _az_json_writer_escape_next_byte_and_copy(&remaining_json, ch); ref_json_writer->_internal.bytes_written += written; @@ -682,7 +684,7 @@ az_json_writer_append_property_name_chunked(az_json_writer* ref_json_writer, az_ } while (consumed < az_span_size(value)); remaining_json = _get_remaining_span(ref_json_writer, _az_MINIMUM_STRING_CHUNK_SIZE); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); remaining_json = az_span_copy_u8(remaining_json, '"'); remaining_json = az_span_copy_u8(remaining_json, ':'); @@ -725,10 +727,10 @@ static AZ_NODISCARD az_result _az_validate_json( _az_PRECONDITION_NOT_NULL(first_token_kind); az_json_reader reader = { 0 }; - AZ_RETURN_IF_FAILED(az_json_reader_init(&reader, json_text, NULL)); + _az_RETURN_IF_FAILED(az_json_reader_init(&reader, json_text, NULL)); az_result result = az_json_reader_next_token(&reader); - AZ_RETURN_IF_FAILED(result); + _az_RETURN_IF_FAILED(result); // This is guaranteed not to be a property name or end object/array. // The first token of a valid JSON must either be a value or start object/array. @@ -764,7 +766,7 @@ az_json_writer_append_json_text(az_json_writer* ref_json_writer, az_span json_te // This runtime validation is necessary since the input could be user defined and malformed. // This cannot be caught at dev time by a precondition, especially since they can be turned off. - AZ_RETURN_IF_FAILED(_az_validate_json(json_text, &first_token_kind, &last_token_kind)); + _az_RETURN_IF_FAILED(_az_validate_json(json_text, &first_token_kind, &last_token_kind)); // It is guaranteed that first_token_kind is NOT: // AZ_JSON_TOKEN_NONE, AZ_JSON_TOKEN_END_ARRAY, AZ_JSON_TOKEN_END_OBJECT, @@ -783,9 +785,9 @@ az_json_writer_append_json_text(az_json_writer* ref_json_writer, az_span json_te } az_span remaining_json = _get_remaining_span(ref_json_writer, _az_MINIMUM_STRING_CHUNK_SIZE); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, _az_MINIMUM_STRING_CHUNK_SIZE); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( az_json_writer_span_copy_chunked(ref_json_writer, &remaining_json, json_text)); // We only need to add a comma if the last token we append is a value or end of object/array. @@ -821,7 +823,7 @@ static AZ_NODISCARD az_result _az_json_writer_append_literal( } az_span remaining_json = _get_remaining_span(ref_json_writer, required_size); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); if (ref_json_writer->_internal.need_comma) { @@ -869,7 +871,7 @@ AZ_NODISCARD az_result az_json_writer_append_int32(az_json_writer* ref_json_writ } az_span remaining_json = _get_remaining_span(ref_json_writer, required_size); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); if (ref_json_writer->_internal.need_comma) { @@ -880,7 +882,7 @@ AZ_NODISCARD az_result az_json_writer_append_int32(az_json_writer* ref_json_writ // AZ_ERROR_INSUFFICIENT_SPAN_SIZE. Still checking the returned az_result, for other potential // failure cases. az_span leftover; - AZ_RETURN_IF_FAILED(az_span_i32toa(remaining_json, value, &leftover)); + _az_RETURN_IF_FAILED(az_span_i32toa(remaining_json, value, &leftover)); // We already accounted for the maximum size needed in required_size, so subtract that to get the // actual bytes written. @@ -910,7 +912,7 @@ AZ_NODISCARD az_result az_json_writer_append_double( } az_span remaining_json = _get_remaining_span(ref_json_writer, required_size); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); if (ref_json_writer->_internal.need_comma) { @@ -921,7 +923,7 @@ AZ_NODISCARD az_result az_json_writer_append_double( // AZ_ERROR_INSUFFICIENT_SPAN_SIZE. Still checking the returned az_result, for other potential // failure cases. az_span leftover; - AZ_RETURN_IF_FAILED(az_span_dtoa(remaining_json, value, fractional_digits, &leftover)); + _az_RETURN_IF_FAILED(az_span_dtoa(remaining_json, value, fractional_digits, &leftover)); // We already accounted for the maximum size needed in required_size, so subtract that to get the // actual bytes written. @@ -956,7 +958,7 @@ static AZ_NODISCARD az_result _az_json_writer_append_container_start( } az_span remaining_json = _get_remaining_span(ref_json_writer, required_size); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); if (ref_json_writer->_internal.need_comma) { @@ -1002,7 +1004,7 @@ static AZ_NODISCARD az_result az_json_writer_append_container_end( int32_t required_size = 1; // For the end object or array byte. az_span remaining_json = _get_remaining_span(ref_json_writer, required_size); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remaining_json, required_size); remaining_json = az_span_copy_u8(remaining_json, byte); diff --git a/sdk/src/azure/core/az_precondition.c b/sdk/src/azure/core/az_precondition.c index 4b17ec5c4b0..c88578343b6 100644 --- a/sdk/src/azure/core/az_precondition.c +++ b/sdk/src/azure/core/az_precondition.c @@ -9,7 +9,9 @@ static void az_precondition_failed_default() { /* By default, when a precondition fails the calling thread spins forever */ - while (1) {} + while (1) + { + } } az_precondition_failed_fn _az_precondition_failed_callback = az_precondition_failed_default; diff --git a/sdk/src/azure/core/az_span.c b/sdk/src/azure/core/az_span.c index 7880f67005b..71198ed26d5 100644 --- a/sdk/src/azure/core/az_span.c +++ b/sdk/src/azure/core/az_span.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -558,7 +559,7 @@ AZ_INLINE uint8_t _az_decimal_to_ascii(uint8_t d) { return (uint8_t)(('0' + d) & static AZ_NODISCARD az_result _az_span_builder_append_uint64(az_span* ref_span, uint64_t n) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*ref_span, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*ref_span, 1); if (n == 0) { @@ -575,7 +576,7 @@ static AZ_NODISCARD az_result _az_span_builder_append_uint64(az_span* ref_span, digit_count--; } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*ref_span, digit_count); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*ref_span, digit_count); while (div > 1) { @@ -605,7 +606,7 @@ AZ_NODISCARD az_result az_span_i64toa(az_span destination, int64_t source, az_sp if (source < 0) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(destination, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(destination, 1); *out_span = az_span_copy_u8(destination, '-'); return _az_span_builder_append_uint64(out_span, (uint64_t)-source); } @@ -619,7 +620,7 @@ AZ_NODISCARD az_result az_span_i64toa(az_span destination, int64_t source, az_sp static AZ_NODISCARD az_result _az_span_builder_append_u32toa(az_span destination, uint32_t n, az_span* out_span) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(destination, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(destination, 1); if (n == 0) { @@ -636,7 +637,7 @@ _az_span_builder_append_u32toa(az_span destination, uint32_t n, az_span* out_spa digit_count--; } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(destination, digit_count); + _az_RETURN_IF_NOT_ENOUGH_SIZE(destination, digit_count); *out_span = destination; @@ -670,7 +671,7 @@ AZ_NODISCARD az_result az_span_i32toa(az_span destination, int32_t source, az_sp if (source < 0) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*out_span, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*out_span, 1); *out_span = az_span_copy_u8(*out_span, '-'); source = -source; } @@ -697,7 +698,7 @@ az_span_dtoa(az_span destination, double source, int32_t fractional_digits, az_s if (source < 0) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*out_span, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*out_span, 1); *out_span = az_span_copy_u8(*out_span, '-'); source = -source; } @@ -712,7 +713,7 @@ az_span_dtoa(az_span destination, double source, int32_t fractional_digits, az_s // The double to uint64_t cast should be safe without loss of precision. // Append the integer part. - AZ_RETURN_IF_FAILED(_az_span_builder_append_uint64(out_span, (uint64_t)integer_part)); + _az_RETURN_IF_FAILED(_az_span_builder_append_uint64(out_span, (uint64_t)integer_part)); // Only print decimal digits if the user asked for at least one to be printed. // Or if the decimal part is non-zero. @@ -768,7 +769,7 @@ az_span_dtoa(az_span destination, double source, int32_t fractional_digits, az_s fractional_part /= 10; } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*out_span, 1 + leading_zeros); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*out_span, 1 + leading_zeros); *out_span = az_span_copy_u8(*out_span, '.'); for (int32_t z = 0; z < leading_zeros; z++) diff --git a/sdk/src/azure/iot/az_iot_common.c b/sdk/src/azure/iot/az_iot_common.c index fc98ffdafd4..4027dcfdd42 100644 --- a/sdk/src/azure/iot/az_iot_common.c +++ b/sdk/src/azure/iot/az_iot_common.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,7 @@ az_iot_message_properties_append(az_iot_message_properties* properties, az_span required_length += 1; } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, required_length); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, required_length); if (prop_length > 0) { @@ -212,7 +213,7 @@ AZ_NODISCARD az_result _az_span_copy_url_encode(az_span destination, az_span source, az_span* out_remainder) { int32_t length; - AZ_RETURN_IF_FAILED(_az_span_url_encode(destination, source, &length)); + _az_RETURN_IF_FAILED(_az_span_url_encode(destination, source, &length)); *out_remainder = az_span_slice(destination, length, az_span_size(destination)); return AZ_OK; } diff --git a/sdk/src/azure/iot/az_iot_hub_client.c b/sdk/src/azure/iot/az_iot_hub_client.c index 4fb98ba32aa..34ae95bca8b 100644 --- a/sdk/src/azure/iot/az_iot_hub_client.c +++ b/sdk/src/azure/iot/az_iot_hub_client.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -86,7 +87,7 @@ AZ_NODISCARD az_result az_iot_hub_client_get_user_name( + az_span_size(hub_client_param_equals_span); } - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( mqtt_user_name_span, required_length + (int32_t)sizeof(null_terminator)); az_span remainder = az_span_copy(mqtt_user_name_span, client->_internal.iot_hub_hostname); @@ -120,7 +121,7 @@ AZ_NODISCARD az_result az_iot_hub_client_get_user_name( remainder = az_span_copy(remainder, hub_digital_twin_model_id); remainder = az_span_copy_u8(remainder, *az_span_ptr(hub_client_param_equals_span)); - AZ_RETURN_IF_FAILED(_az_span_copy_url_encode(remainder, *model_id, &remainder)); + _az_RETURN_IF_FAILED(_az_span_copy_url_encode(remainder, *model_id, &remainder)); } if (az_span_size(remainder) > 0) { @@ -160,7 +161,7 @@ AZ_NODISCARD az_result az_iot_hub_client_get_client_id( required_length += az_span_size(*module_id) + (int32_t)sizeof(hub_client_forward_slash); } - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( mqtt_client_id_span, required_length + (int32_t)sizeof(null_terminator)); az_span remainder = az_span_copy(mqtt_client_id_span, client->_internal.device_id); diff --git a/sdk/src/azure/iot/az_iot_hub_client_c2d.c b/sdk/src/azure/iot/az_iot_hub_client_c2d.c index 6918b414fd1..5bc43d561db 100644 --- a/sdk/src/azure/iot/az_iot_hub_client_c2d.c +++ b/sdk/src/azure/iot/az_iot_hub_client_c2d.c @@ -3,10 +3,11 @@ #include -#include #include #include +#include #include +#include #include #include @@ -35,7 +36,7 @@ AZ_NODISCARD az_result az_iot_hub_client_c2d_parse_received_topic( _az_LOG_WRITE(AZ_LOG_MQTT_RECEIVED_TOPIC, received_topic); token = _az_span_token(reminder, c2d_topic_suffix, &reminder); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( az_iot_message_properties_init(&out_request->properties, token, az_span_size(token))); return AZ_OK; diff --git a/sdk/src/azure/iot/az_iot_hub_client_methods.c b/sdk/src/azure/iot/az_iot_hub_client_methods.c index 219a5914774..914300fe939 100644 --- a/sdk/src/azure/iot/az_iot_hub_client_methods.c +++ b/sdk/src/azure/iot/az_iot_hub_client_methods.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -91,12 +92,13 @@ AZ_NODISCARD az_result az_iot_hub_client_methods_response_get_publish_topic( + az_span_size(methods_response_topic_result) + _az_iot_u32toa_size(status) + az_span_size(methods_response_topic_properties) + az_span_size(request_id); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_topic_span, required_length + (int32_t)sizeof(null_terminator)); + _az_RETURN_IF_NOT_ENOUGH_SIZE( + mqtt_topic_span, required_length + (int32_t)sizeof(null_terminator)); az_span remainder = az_span_copy(mqtt_topic_span, methods_topic_prefix); remainder = az_span_copy(remainder, methods_response_topic_result); - AZ_RETURN_IF_FAILED(az_span_u32toa(remainder, (uint32_t)status, &remainder)); + _az_RETURN_IF_FAILED(az_span_u32toa(remainder, (uint32_t)status, &remainder)); remainder = az_span_copy(remainder, methods_response_topic_properties); remainder = az_span_copy(remainder, request_id); diff --git a/sdk/src/azure/iot/az_iot_hub_client_sas.c b/sdk/src/azure/iot/az_iot_hub_client_sas.c index 8d025899f21..dbfe3b36e08 100644 --- a/sdk/src/azure/iot/az_iot_hub_client_sas.c +++ b/sdk/src/azure/iot/az_iot_hub_client_sas.c @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -46,31 +47,32 @@ AZ_NODISCARD az_result az_iot_hub_client_sas_get_signature( az_span remainder = signature; int32_t signature_size = az_span_size(signature); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( _az_span_copy_url_encode(remainder, client->_internal.iot_hub_hostname, &remainder)); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(devices_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(devices_string)); remainder = az_span_copy(remainder, devices_string); - AZ_RETURN_IF_FAILED(_az_span_copy_url_encode(remainder, client->_internal.device_id, &remainder)); + _az_RETURN_IF_FAILED( + _az_span_copy_url_encode(remainder, client->_internal.device_id, &remainder)); if (az_span_size(client->_internal.options.module_id) > 0) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(modules_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(modules_string)); remainder = az_span_copy(remainder, modules_string); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( _az_span_copy_url_encode(remainder, client->_internal.options.module_id, &remainder)); } - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( remainder, 1 + // LF _az_iot_u64toa_size(token_expiration_epoch_time)); remainder = az_span_copy_u8(remainder, LF); - AZ_RETURN_IF_FAILED(az_span_u64toa(remainder, token_expiration_epoch_time, &remainder)); + _az_RETURN_IF_FAILED(az_span_u64toa(remainder, token_expiration_epoch_time, &remainder)); *out_signature = az_span_slice(signature, 0, signature_size - az_span_size(remainder)); _az_LOG_WRITE(AZ_LOG_IOT_SAS_TOKEN, *out_signature); @@ -99,55 +101,55 @@ AZ_NODISCARD az_result az_iot_hub_client_sas_get_password( az_span mqtt_password_span = az_span_create((uint8_t*)mqtt_password, (int32_t)mqtt_password_size); // SharedAccessSignature - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, az_span_size(sr_string) + 1 /* EQUAL_SIGN */); + _az_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, az_span_size(sr_string) + 1 /* EQUAL_SIGN */); mqtt_password_span = az_span_copy(mqtt_password_span, sr_string); mqtt_password_span = az_span_copy_u8(mqtt_password_span, EQUAL_SIGN); - AZ_RETURN_IF_FAILED(_az_span_copy_url_encode( + _az_RETURN_IF_FAILED(_az_span_copy_url_encode( mqtt_password_span, client->_internal.iot_hub_hostname, &mqtt_password_span)); // Device ID - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, az_span_size(devices_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, az_span_size(devices_string)); mqtt_password_span = az_span_copy(mqtt_password_span, devices_string); - AZ_RETURN_IF_FAILED(_az_span_copy_url_encode( + _az_RETURN_IF_FAILED(_az_span_copy_url_encode( mqtt_password_span, client->_internal.device_id, &mqtt_password_span)); // Module ID if (az_span_size(client->_internal.options.module_id) > 0) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, az_span_size(modules_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, az_span_size(modules_string)); mqtt_password_span = az_span_copy(mqtt_password_span, modules_string); - AZ_RETURN_IF_FAILED(_az_span_copy_url_encode( + _az_RETURN_IF_FAILED(_az_span_copy_url_encode( mqtt_password_span, client->_internal.options.module_id, &mqtt_password_span)); } // Signature - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( mqtt_password_span, 1 /* AMPERSAND */ + az_span_size(sig_string) + 1 /* EQUAL_SIGN */); mqtt_password_span = az_span_copy_u8(mqtt_password_span, AMPERSAND); mqtt_password_span = az_span_copy(mqtt_password_span, sig_string); mqtt_password_span = az_span_copy_u8(mqtt_password_span, EQUAL_SIGN); - AZ_RETURN_IF_FAILED(_az_span_copy_url_encode( + _az_RETURN_IF_FAILED(_az_span_copy_url_encode( mqtt_password_span, base64_hmac_sha256_signature, &mqtt_password_span)); // Expiration - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( mqtt_password_span, 1 /* AMPERSAND */ + az_span_size(se_string) + 1 /* EQUAL_SIGN */); mqtt_password_span = az_span_copy_u8(mqtt_password_span, AMPERSAND); mqtt_password_span = az_span_copy(mqtt_password_span, se_string); mqtt_password_span = az_span_copy_u8(mqtt_password_span, EQUAL_SIGN); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( az_span_u64toa(mqtt_password_span, token_expiration_epoch_time, &mqtt_password_span)); if (az_span_size(key_name) > 0) { // Key Name - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( mqtt_password_span, 1 /* AMPERSAND */ + az_span_size(skn_string) + 1 /* EQUAL_SIGN */ + az_span_size(key_name)); mqtt_password_span = az_span_copy_u8(mqtt_password_span, AMPERSAND); @@ -156,7 +158,7 @@ AZ_NODISCARD az_result az_iot_hub_client_sas_get_password( mqtt_password_span = az_span_copy(mqtt_password_span, key_name); } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, 1 /* NULL TERMINATOR */); + _az_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, 1 /* NULL TERMINATOR */); mqtt_password_span = az_span_copy_u8(mqtt_password_span, STRING_NULL_TERMINATOR); diff --git a/sdk/src/azure/iot/az_iot_hub_client_telemetry.c b/sdk/src/azure/iot/az_iot_hub_client_telemetry.c index fda07510cfe..c628cd86cf9 100644 --- a/sdk/src/azure/iot/az_iot_hub_client_telemetry.c +++ b/sdk/src/azure/iot/az_iot_hub_client_telemetry.c @@ -1,14 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT -#include - #include #include #include #include +#include #include +#include + #include static const uint8_t null_terminator = '\0'; @@ -42,7 +43,8 @@ AZ_NODISCARD az_result az_iot_hub_client_telemetry_get_publish_topic( required_length += properties->_internal.properties_written; } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_topic_span, required_length + (int32_t)sizeof(null_terminator)); + _az_RETURN_IF_NOT_ENOUGH_SIZE( + mqtt_topic_span, required_length + (int32_t)sizeof(null_terminator)); az_span remainder = az_span_copy(mqtt_topic_span, telemetry_topic_prefix); remainder = az_span_copy(remainder, client->_internal.device_id); diff --git a/sdk/src/azure/iot/az_iot_hub_client_twin.c b/sdk/src/azure/iot/az_iot_hub_client_twin.c index a7d99beb8dd..c856fecc867 100644 --- a/sdk/src/azure/iot/az_iot_hub_client_twin.c +++ b/sdk/src/azure/iot/az_iot_hub_client_twin.c @@ -6,11 +6,11 @@ #include #include #include -#include -#include - #include #include +#include +#include +#include #include @@ -47,7 +47,8 @@ AZ_NODISCARD az_result az_iot_hub_client_twin_document_get_publish_topic( + az_span_size(az_iot_hub_client_request_id_span) + (int32_t)sizeof(az_iot_hub_client_twin_equals) + az_span_size(request_id); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_topic_span, required_length + (int32_t)sizeof(null_terminator)); + _az_RETURN_IF_NOT_ENOUGH_SIZE( + mqtt_topic_span, required_length + (int32_t)sizeof(null_terminator)); az_span remainder = az_span_copy(mqtt_topic_span, az_iot_hub_twin_topic_prefix); remainder = az_span_copy(remainder, az_iot_hub_twin_get_pub_topic); @@ -85,7 +86,8 @@ AZ_NODISCARD az_result az_iot_hub_client_twin_patch_get_publish_topic( + az_span_size(az_iot_hub_client_request_id_span) + (int32_t)sizeof(az_iot_hub_client_twin_equals) + az_span_size(request_id); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_topic_span, required_length + (int32_t)sizeof(null_terminator)); + _az_RETURN_IF_NOT_ENOUGH_SIZE( + mqtt_topic_span, required_length + (int32_t)sizeof(null_terminator)); az_span remainder = az_span_copy(mqtt_topic_span, az_iot_hub_twin_topic_prefix); remainder = az_span_copy(remainder, az_iot_hub_twin_patch_pub_topic); @@ -140,22 +142,22 @@ AZ_NODISCARD az_result az_iot_hub_client_twin_parse_received_topic( // Get status and convert to enum uint32_t status_int; - AZ_RETURN_IF_FAILED(az_span_atou32(status_str, &status_int)); + _az_RETURN_IF_FAILED(az_span_atou32(status_str, &status_int)); out_twin_response->status = (az_iot_status)status_int; // Get request id prop value az_iot_message_properties props; az_span prop_span = az_span_slice(remainder, 1, az_span_size(remainder)); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( az_iot_message_properties_init(&props, prop_span, az_span_size(prop_span))); - AZ_RETURN_IF_FAILED(az_iot_message_properties_find( + _az_RETURN_IF_FAILED(az_iot_message_properties_find( &props, az_iot_hub_client_request_id_span, &out_twin_response->request_id)); if (out_twin_response->status == AZ_IOT_STATUS_NO_CONTENT) { // Is a reported prop response out_twin_response->response_type = AZ_IOT_CLIENT_TWIN_RESPONSE_TYPE_REPORTED_PROPERTIES; - AZ_RETURN_IF_FAILED(az_iot_message_properties_find( + _az_RETURN_IF_FAILED(az_iot_message_properties_find( &props, az_iot_hub_twin_version_prop, &out_twin_response->version)); } else @@ -178,9 +180,9 @@ AZ_NODISCARD az_result az_iot_hub_client_twin_parse_received_topic( twin_feature_index + az_span_size(az_iot_hub_twin_patch_sub_topic) + (int32_t)sizeof(az_iot_hub_client_twin_question), az_span_size(received_topic)); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( az_iot_message_properties_init(&props, prop_span, az_span_size(prop_span))); - AZ_RETURN_IF_FAILED(az_iot_message_properties_find( + _az_RETURN_IF_FAILED(az_iot_message_properties_find( &props, az_iot_hub_twin_version_prop, &out_twin_response->version)); out_twin_response->response_type = AZ_IOT_CLIENT_TWIN_RESPONSE_TYPE_DESIRED_PROPERTIES; diff --git a/sdk/src/azure/iot/az_iot_provisioning_client.c b/sdk/src/azure/iot/az_iot_provisioning_client.c index fd616721323..41ad409f897 100644 --- a/sdk/src/azure/iot/az_iot_provisioning_client.c +++ b/sdk/src/azure/iot/az_iot_provisioning_client.c @@ -4,13 +4,13 @@ #include #include #include +#include +#include +#include #include #include #include -#include -#include - #include static const az_span str_put_iotdps_register @@ -93,7 +93,7 @@ AZ_NODISCARD az_result az_iot_provisioning_client_get_user_name( required_length += az_span_size(user_agent_version_prefix) + az_span_size(*user_agent); } - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( mqtt_user_name_span, required_length + (int32_t)sizeof((uint8_t)'\0')); az_span remainder = az_span_copy(mqtt_user_name_span, client->_internal.id_scope); @@ -133,7 +133,7 @@ AZ_NODISCARD az_result az_iot_provisioning_client_get_client_id( int32_t required_length = az_span_size(client->_internal.registration_id); - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( mqtt_client_id_span, required_length + (int32_t)sizeof((uint8_t)'\0')); az_span remainder = az_span_copy(mqtt_client_id_span, client->_internal.registration_id); @@ -166,7 +166,7 @@ AZ_NODISCARD az_result az_iot_provisioning_client_register_get_publish_topic( int32_t required_length = az_span_size(str_dps_registrations) + az_span_size(str_put_iotdps_register); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_topic_span, required_length + (int32_t)sizeof((uint8_t)'\0')); + _az_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_topic_span, required_length + (int32_t)sizeof((uint8_t)'\0')); az_span remainder = az_span_copy(mqtt_topic_span, str_dps_registrations); remainder = az_span_copy(remainder, str_put_iotdps_register); @@ -204,7 +204,7 @@ AZ_NODISCARD az_result az_iot_provisioning_client_query_status_get_publish_topic + az_span_size(str_get_iotdps_get_operationstatus) + az_span_size(register_response->operation_id); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_topic_span, required_length + (int32_t)sizeof((uint8_t)'\0')); + _az_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_topic_span, required_length + (int32_t)sizeof((uint8_t)'\0')); az_span remainder = az_span_copy(mqtt_topic_span, str_dps_registrations); remainder = az_span_copy(remainder, str_get_iotdps_get_operationstatus); @@ -256,8 +256,8 @@ AZ_INLINE az_result _az_iot_provisioning_client_parse_payload_error_code( { if (az_json_token_is_text_equal(&jr->token, AZ_SPAN_FROM_STR("errorCode"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(jr)); - AZ_RETURN_IF_FAILED(az_json_token_get_uint32(&jr->token, &out_state->extended_error_code)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(jr)); + _az_RETURN_IF_FAILED(az_json_token_get_uint32(&jr->token, &out_state->extended_error_code)); out_state->error_code = _az_iot_status_from_extended_status(out_state->extended_error_code); return AZ_OK; @@ -284,7 +284,7 @@ AZ_INLINE az_result _az_iot_provisioning_client_payload_registration_result_pars { if (az_json_token_is_text_equal(&jr->token, AZ_SPAN_FROM_STR("assignedHub"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(jr)); if (jr->token.kind != AZ_JSON_TOKEN_STRING) { return AZ_ERROR_ITEM_NOT_FOUND; @@ -294,7 +294,7 @@ AZ_INLINE az_result _az_iot_provisioning_client_payload_registration_result_pars } else if (az_json_token_is_text_equal(&jr->token, AZ_SPAN_FROM_STR("deviceId"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(jr)); if (jr->token.kind != AZ_JSON_TOKEN_STRING) { return AZ_ERROR_ITEM_NOT_FOUND; @@ -304,7 +304,7 @@ AZ_INLINE az_result _az_iot_provisioning_client_payload_registration_result_pars } else if (az_json_token_is_text_equal(&jr->token, AZ_SPAN_FROM_STR("errorMessage"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(jr)); if (jr->token.kind != AZ_JSON_TOKEN_STRING) { return AZ_ERROR_ITEM_NOT_FOUND; @@ -313,7 +313,7 @@ AZ_INLINE az_result _az_iot_provisioning_client_payload_registration_result_pars } else if (az_json_token_is_text_equal(&jr->token, AZ_SPAN_FROM_STR("lastUpdatedDateTimeUtc"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(jr)); if (jr->token.kind != AZ_JSON_TOKEN_STRING) { return AZ_ERROR_ITEM_NOT_FOUND; @@ -328,7 +328,7 @@ AZ_INLINE az_result _az_iot_provisioning_client_payload_registration_result_pars else { // ignore other tokens - AZ_RETURN_IF_FAILED(az_json_reader_skip_children(jr)); + _az_RETURN_IF_FAILED(az_json_reader_skip_children(jr)); } } @@ -346,9 +346,9 @@ AZ_INLINE az_result az_iot_provisioning_client_parse_payload( { // Parse the payload: az_json_reader jr; - AZ_RETURN_IF_FAILED(az_json_reader_init(&jr, received_payload, NULL)); + _az_RETURN_IF_FAILED(az_json_reader_init(&jr, received_payload, NULL)); - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_BEGIN_OBJECT) { return AZ_ERROR_UNEXPECTED_CHAR; @@ -365,7 +365,7 @@ AZ_INLINE az_result az_iot_provisioning_client_parse_payload( { if (az_json_token_is_text_equal(&jr.token, AZ_SPAN_FROM_STR("operationId"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_STRING) { return AZ_ERROR_ITEM_NOT_FOUND; @@ -375,7 +375,7 @@ AZ_INLINE az_result az_iot_provisioning_client_parse_payload( } else if (az_json_token_is_text_equal(&jr.token, AZ_SPAN_FROM_STR("status"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_STRING) { return AZ_ERROR_ITEM_NOT_FOUND; @@ -385,13 +385,13 @@ AZ_INLINE az_result az_iot_provisioning_client_parse_payload( } else if (az_json_token_is_text_equal(&jr.token, AZ_SPAN_FROM_STR("registrationState"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); - AZ_RETURN_IF_FAILED(_az_iot_provisioning_client_payload_registration_result_parse( + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(_az_iot_provisioning_client_payload_registration_result_parse( &jr, &out_response->registration_result)); } else if (az_json_token_is_text_equal(&jr.token, AZ_SPAN_FROM_STR("trackingId"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_STRING) { return AZ_ERROR_ITEM_NOT_FOUND; @@ -400,7 +400,7 @@ AZ_INLINE az_result az_iot_provisioning_client_parse_payload( } else if (az_json_token_is_text_equal(&jr.token, AZ_SPAN_FROM_STR("message"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_STRING) { return AZ_ERROR_ITEM_NOT_FOUND; @@ -409,7 +409,7 @@ AZ_INLINE az_result az_iot_provisioning_client_parse_payload( } else if (az_json_token_is_text_equal(&jr.token, AZ_SPAN_FROM_STR("timestampUtc"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_STRING) { return AZ_ERROR_ITEM_NOT_FOUND; @@ -424,7 +424,7 @@ AZ_INLINE az_result az_iot_provisioning_client_parse_payload( else { // ignore other tokens - AZ_RETURN_IF_FAILED(az_json_reader_skip_children(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_skip_children(&jr)); } } @@ -493,7 +493,7 @@ AZ_NODISCARD az_result az_iot_provisioning_client_parse_received_topic_and_paylo az_span remainder = az_span_slice_to_end(received_topic, az_span_size(str_dps_registrations_res)); az_span int_slice = _az_span_token(remainder, AZ_SPAN_FROM_STR("/"), &remainder); - AZ_RETURN_IF_FAILED(az_span_atou32(int_slice, (uint32_t*)(&out_response->status))); + _az_RETURN_IF_FAILED(az_span_atou32(int_slice, (uint32_t*)(&out_response->status))); // Parse the optional retry-after= field. az_span retry_after = AZ_SPAN_FROM_STR("retry-after="); @@ -503,14 +503,14 @@ AZ_NODISCARD az_result az_iot_provisioning_client_parse_received_topic_and_paylo remainder = az_span_slice_to_end(remainder, idx + az_span_size(retry_after)); int_slice = _az_span_token(remainder, AZ_SPAN_FROM_STR("&"), &remainder); - AZ_RETURN_IF_FAILED(az_span_atou32(int_slice, &out_response->retry_after_seconds)); + _az_RETURN_IF_FAILED(az_span_atou32(int_slice, &out_response->retry_after_seconds)); } else { out_response->retry_after_seconds = 0; } - AZ_RETURN_IF_FAILED(az_iot_provisioning_client_parse_payload(received_payload, out_response)); + _az_RETURN_IF_FAILED(az_iot_provisioning_client_parse_payload(received_payload, out_response)); return AZ_OK; } diff --git a/sdk/src/azure/iot/az_iot_provisioning_client_sas.c b/sdk/src/azure/iot/az_iot_provisioning_client_sas.c index 82b4ef4034b..77ac9c9e2d4 100644 --- a/sdk/src/azure/iot/az_iot_provisioning_client_sas.c +++ b/sdk/src/azure/iot/az_iot_provisioning_client_sas.c @@ -3,13 +3,13 @@ #include #include +#include +#include +#include #include #include #include -#include -#include - #include #include @@ -49,18 +49,18 @@ AZ_NODISCARD az_result az_iot_provisioning_client_sas_get_signature( az_span remainder = signature; int32_t signature_size = az_span_size(signature); - AZ_RETURN_IF_FAILED(_az_span_copy_url_encode(remainder, client->_internal.id_scope, &remainder)); + _az_RETURN_IF_FAILED(_az_span_copy_url_encode(remainder, client->_internal.id_scope, &remainder)); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(resources_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, az_span_size(resources_string)); remainder = az_span_copy(remainder, resources_string); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( _az_span_copy_url_encode(remainder, client->_internal.registration_id, &remainder)); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(remainder, 1 /* LF */); + _az_RETURN_IF_NOT_ENOUGH_SIZE(remainder, 1 /* LF */); remainder = az_span_copy_u8(remainder, LF); - AZ_RETURN_IF_FAILED(az_span_u64toa(remainder, token_expiration_epoch_time, &remainder)); + _az_RETURN_IF_FAILED(az_span_u64toa(remainder, token_expiration_epoch_time, &remainder)); *out_signature = az_span_slice(signature, 0, signature_size - az_span_size(remainder)); _az_LOG_WRITE(AZ_LOG_IOT_SAS_TOKEN, *out_signature); @@ -93,46 +93,46 @@ AZ_NODISCARD az_result az_iot_provisioning_client_sas_get_password( az_span mqtt_password_span = az_span_create((uint8_t*)mqtt_password, (int32_t)mqtt_password_size); // SharedAccessSignature - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, az_span_size(sr_string) + 1 /* EQUAL SIGN */); + _az_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, az_span_size(sr_string) + 1 /* EQUAL SIGN */); mqtt_password_span = az_span_copy(mqtt_password_span, sr_string); mqtt_password_span = az_span_copy_u8(mqtt_password_span, EQUAL_SIGN); // Resource string - AZ_RETURN_IF_FAILED(_az_span_copy_url_encode( + _az_RETURN_IF_FAILED(_az_span_copy_url_encode( mqtt_password_span, client->_internal.id_scope, &mqtt_password_span)); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, az_span_size(resources_string)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, az_span_size(resources_string)); mqtt_password_span = az_span_copy(mqtt_password_span, resources_string); - AZ_RETURN_IF_FAILED(_az_span_copy_url_encode( + _az_RETURN_IF_FAILED(_az_span_copy_url_encode( mqtt_password_span, client->_internal.registration_id, &mqtt_password_span)); // Signature - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( mqtt_password_span, 1 /* AMPERSAND */ + az_span_size(sig_string) + 1 /* EQUAL_SIGN */); mqtt_password_span = az_span_copy_u8(mqtt_password_span, AMPERSAND); mqtt_password_span = az_span_copy(mqtt_password_span, sig_string); mqtt_password_span = az_span_copy_u8(mqtt_password_span, EQUAL_SIGN); - AZ_RETURN_IF_FAILED(_az_span_copy_url_encode( + _az_RETURN_IF_FAILED(_az_span_copy_url_encode( mqtt_password_span, base64_hmac_sha256_signature, &mqtt_password_span)); // Expiration - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( mqtt_password_span, 1 /* AMPERSAND */ + az_span_size(se_string) + 1 /* EQUAL_SIGN */ + _az_iot_u64toa_size(token_expiration_epoch_time)); mqtt_password_span = az_span_copy_u8(mqtt_password_span, AMPERSAND); mqtt_password_span = az_span_copy(mqtt_password_span, se_string); mqtt_password_span = az_span_copy_u8(mqtt_password_span, EQUAL_SIGN); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( az_span_u64toa(mqtt_password_span, token_expiration_epoch_time, &mqtt_password_span)); if (az_span_size(key_name) > 0) { // Key Name - AZ_RETURN_IF_NOT_ENOUGH_SIZE( + _az_RETURN_IF_NOT_ENOUGH_SIZE( mqtt_password_span, 1 // AMPERSAND + az_span_size(skn_string) + 1 // EQUAL_SIGN @@ -144,7 +144,7 @@ AZ_NODISCARD az_result az_iot_provisioning_client_sas_get_password( mqtt_password_span = az_span_copy(mqtt_password_span, key_name); } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, 1 /* NULL TERMINATOR */); + _az_RETURN_IF_NOT_ENOUGH_SIZE(mqtt_password_span, 1 /* NULL TERMINATOR */); mqtt_password_span = az_span_copy_u8(mqtt_password_span, STRING_NULL_TERMINATOR); if (out_mqtt_password_length != NULL) diff --git a/sdk/src/azure/platform/az_curl.c b/sdk/src/azure/platform/az_curl.c index 94f24e6aff6..c858e8d48a1 100644 --- a/sdk/src/azure/platform/az_curl.c +++ b/sdk/src/azure/platform/az_curl.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -58,7 +59,8 @@ static AZ_NODISCARD az_result _az_http_client_curl_code_to_result(CURLcode code) } // returning AZ error on CURL Error -#define AZ_RETURN_IF_CURL_FAILED(exp) AZ_RETURN_IF_FAILED(_az_http_client_curl_code_to_result(exp)) +#define _az_RETURN_IF_CURL_FAILED(exp) \ + _az_RETURN_IF_FAILED(_az_http_client_curl_code_to_result(exp)) AZ_NODISCARD AZ_INLINE az_result _az_http_client_curl_init(CURL** out) { @@ -91,7 +93,7 @@ _az_span_append_header_to_buffer(az_span writable_buffer, az_pair header, az_spa int32_t required_length = az_span_size(header.key) + az_span_size(separator) + az_span_size(header.value) + 1; - AZ_RETURN_IF_NOT_ENOUGH_SIZE(writable_buffer, required_length); + _az_RETURN_IF_NOT_ENOUGH_SIZE(writable_buffer, required_length); writable_buffer = az_span_copy(writable_buffer, header.key); writable_buffer = az_span_copy(writable_buffer, separator); @@ -142,7 +144,7 @@ static AZ_NODISCARD az_result _az_http_client_curl_add_header_to_curl_list( int32_t const buffer_size = az_span_size(header.key) + az_span_size(separator) + az_span_size(header.value) + 1 /*one for 0 terminated*/; - AZ_RETURN_IF_FAILED(_az_span_malloc(buffer_size, &writable_buffer)); + _az_RETURN_IF_FAILED(_az_span_malloc(buffer_size, &writable_buffer)); } // write buffer @@ -193,9 +195,9 @@ _az_http_client_curl_add_expect_header(CURL* ref_curl, struct curl_slist** ref_l _az_PRECONDITION_NOT_NULL(ref_list); // Append header to current custom headers list - AZ_RETURN_IF_FAILED(_az_http_client_curl_slist_append(ref_list, "Expect:")); + _az_RETURN_IF_FAILED(_az_http_client_curl_slist_append(ref_list, "Expect:")); // Update the reference to curl custom list (in case it gets moved in memory due to appending) - AZ_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_HTTPHEADER, *ref_list)); + _az_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_HTTPHEADER, *ref_list)); return AZ_OK; } @@ -214,8 +216,8 @@ _az_http_client_curl_build_headers(az_http_request const* request, struct curl_s az_pair header; for (int32_t offset = 0; offset < az_http_request_headers_count(request); ++offset) { - AZ_RETURN_IF_FAILED(az_http_request_get_header(request, offset, &header)); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED(az_http_request_get_header(request, offset, &header)); + _az_RETURN_IF_FAILED( _az_http_client_curl_add_header_to_curl_list(header, ref_headers, AZ_SPAN_FROM_STR(":"))); } @@ -233,7 +235,7 @@ _az_http_client_curl_build_headers(az_http_request const* request, struct curl_s static AZ_NODISCARD az_result _az_http_client_curl_append_url(az_span writable_buffer, az_span url_from_request) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(writable_buffer, az_span_size(url_from_request) + 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(writable_buffer, az_span_size(url_from_request) + 1); az_span remainder = az_span_copy(writable_buffer, url_from_request); az_span_copy_u8(remainder, 0); @@ -282,7 +284,7 @@ static AZ_NODISCARD az_result _az_http_client_curl_send_get_request(CURL* ref_cu _az_PRECONDITION_NOT_NULL(ref_curl); // send - AZ_RETURN_IF_CURL_FAILED(curl_easy_perform(ref_curl)); + _az_RETURN_IF_CURL_FAILED(curl_easy_perform(ref_curl)); return AZ_OK; } @@ -294,10 +296,10 @@ static AZ_NODISCARD az_result _az_http_client_curl_send_delete_request(CURL* ref { _az_PRECONDITION_NOT_NULL(ref_curl); - AZ_RETURN_IF_FAILED(_az_http_client_curl_code_to_result( + _az_RETURN_IF_FAILED(_az_http_client_curl_code_to_result( curl_easy_setopt(ref_curl, CURLOPT_CUSTOMREQUEST, "DELETE"))); - AZ_RETURN_IF_FAILED(_az_http_client_curl_code_to_result(curl_easy_perform(ref_curl))); + _az_RETURN_IF_FAILED(_az_http_client_curl_code_to_result(curl_easy_perform(ref_curl))); return AZ_OK; } @@ -313,11 +315,11 @@ _az_http_client_curl_send_post_request(CURL* ref_curl, az_http_request const* re // Method az_span request_body = { 0 }; - AZ_RETURN_IF_FAILED(az_http_request_get_body(request, &request_body)); + _az_RETURN_IF_FAILED(az_http_request_get_body(request, &request_body)); az_span body = { 0 }; int32_t const required_length = az_span_size(request_body) + az_span_size(AZ_SPAN_FROM_STR("\0")); - AZ_RETURN_IF_FAILED(_az_span_malloc(required_length, &body)); + _az_RETURN_IF_FAILED(_az_span_malloc(required_length, &body)); char* b = (char*)az_span_ptr(body); az_span_to_str(b, required_length, request_body); @@ -330,7 +332,7 @@ _az_http_client_curl_send_post_request(CURL* ref_curl, az_http_request const* re } _az_span_free(&body); - AZ_RETURN_IF_FAILED(res_code); + _az_RETURN_IF_FAILED(res_code); return AZ_OK; } @@ -397,23 +399,23 @@ _az_http_client_curl_send_upload_request(CURL* ref_curl, az_http_request const* _az_PRECONDITION_NOT_NULL(request); az_span body = { 0 }; - AZ_RETURN_IF_FAILED(az_http_request_get_body(request, &body)); + _az_RETURN_IF_FAILED(az_http_request_get_body(request, &body)); - AZ_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_UPLOAD, 1L)); - AZ_RETURN_IF_CURL_FAILED( + _az_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_UPLOAD, 1L)); + _az_RETURN_IF_CURL_FAILED( curl_easy_setopt(ref_curl, CURLOPT_READFUNCTION, _az_http_client_curl_upload_read_callback)); // Setup the request to pass body into the read callback // The read callback receives the address of body - AZ_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_READDATA, &body)); + _az_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_READDATA, &body)); // Set the size of the upload - AZ_RETURN_IF_CURL_FAILED( + _az_RETURN_IF_CURL_FAILED( curl_easy_setopt(ref_curl, CURLOPT_INFILESIZE, (curl_off_t)az_span_size(body))); // Do the curl work // curl_easy_perform does not return until the CURLOPT_READFUNCTION callbacks complete. - AZ_RETURN_IF_CURL_FAILED(curl_easy_perform(ref_curl)); + _az_RETURN_IF_CURL_FAILED(curl_easy_perform(ref_curl)); return AZ_OK; } @@ -441,9 +443,9 @@ static AZ_NODISCARD az_result _az_http_client_curl_setup_headers( } // build headers into a slist as curl is expecting - AZ_RETURN_IF_FAILED(_az_http_client_curl_build_headers(request, ref_list)); + _az_RETURN_IF_FAILED(_az_http_client_curl_build_headers(request, ref_list)); // set all headers from slist - AZ_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_HTTPHEADER, *ref_list)); + _az_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_HTTPHEADER, *ref_list)); return AZ_OK; } @@ -463,7 +465,7 @@ _az_http_client_curl_setup_url(CURL* ref_curl, az_http_request const* request) az_span request_url = { 0 }; // get request_url. It will have the size of what it has written in it only - AZ_RETURN_IF_FAILED(az_http_request_get_url(request, &request_url)); + _az_RETURN_IF_FAILED(az_http_request_get_url(request, &request_url)); // Note: the url from request is already url-encoded. int32_t request_url_size = az_span_size(request_url); @@ -473,7 +475,7 @@ _az_http_client_curl_setup_url(CURL* ref_curl, az_http_request const* request) int32_t const url_final_size = request_url_size + 1; // allocate buffer to add \0 - AZ_RETURN_IF_FAILED(_az_span_malloc(url_final_size, &writable_buffer)); + _az_RETURN_IF_FAILED(_az_span_malloc(url_final_size, &writable_buffer)); } // write url in buffer (will add \0 at the end) @@ -506,15 +508,15 @@ _az_http_client_curl_setup_response_redirect(CURL* ref_curl, az_http_response* r { _az_PRECONDITION_NOT_NULL(ref_curl); - AZ_RETURN_IF_CURL_FAILED( + _az_RETURN_IF_CURL_FAILED( curl_easy_setopt(ref_curl, CURLOPT_HEADERFUNCTION, _az_http_client_curl_write_to_span)); - AZ_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_HEADERDATA, (void*)response)); + _az_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_HEADERDATA, (void*)response)); - AZ_RETURN_IF_CURL_FAILED( + _az_RETURN_IF_CURL_FAILED( curl_easy_setopt(ref_curl, CURLOPT_WRITEFUNCTION, _az_http_client_curl_write_to_span)); - AZ_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_WRITEDATA, (void*)response)); + _az_RETURN_IF_CURL_FAILED(curl_easy_setopt(ref_curl, CURLOPT_WRITEDATA, (void*)response)); return AZ_OK; } @@ -540,14 +542,14 @@ static AZ_NODISCARD az_result _az_http_client_curl_send_request_impl_process( az_result result = AZ_ERROR_ARG; struct curl_slist* list = NULL; - AZ_RETURN_IF_FAILED(_az_http_client_curl_setup_headers(ref_curl, &list, request)); + _az_RETURN_IF_FAILED(_az_http_client_curl_setup_headers(ref_curl, &list, request)); - AZ_RETURN_IF_FAILED(_az_http_client_curl_setup_url(ref_curl, request)); + _az_RETURN_IF_FAILED(_az_http_client_curl_setup_url(ref_curl, request)); - AZ_RETURN_IF_FAILED(_az_http_client_curl_setup_response_redirect(ref_curl, ref_response)); + _az_RETURN_IF_FAILED(_az_http_client_curl_setup_response_redirect(ref_curl, ref_response)); az_http_method method; - AZ_RETURN_IF_FAILED(az_http_request_get_method(request, &method)); + _az_RETURN_IF_FAILED(az_http_request_get_method(request, &method)); if (az_span_is_content_equal(method, az_http_method_get())) { @@ -559,14 +561,14 @@ static AZ_NODISCARD az_result _az_http_client_curl_send_request_impl_process( } else if (az_span_is_content_equal(method, az_http_method_post())) { - AZ_RETURN_IF_FAILED(_az_http_client_curl_add_expect_header(ref_curl, &list)); + _az_RETURN_IF_FAILED(_az_http_client_curl_add_expect_header(ref_curl, &list)); result = _az_http_client_curl_send_post_request(ref_curl, request); } else if (az_span_is_content_equal(method, az_http_method_put())) { // As of CURL 7.12.1 CURLOPT_PUT is deprecated. PUT requests should be made using // CURLOPT_UPLOAD - AZ_RETURN_IF_FAILED(_az_http_client_curl_add_expect_header(ref_curl, &list)); + _az_RETURN_IF_FAILED(_az_http_client_curl_add_expect_header(ref_curl, &list)); result = _az_http_client_curl_send_upload_request(ref_curl, request); } else @@ -596,14 +598,14 @@ az_http_client_send_request(az_http_request const* request, az_http_response* re CURL* curl = NULL; // init curl - AZ_RETURN_IF_FAILED(_az_http_client_curl_init(&curl)); + _az_RETURN_IF_FAILED(_az_http_client_curl_init(&curl)); // process request az_result process_result = _az_http_client_curl_send_request_impl_process(curl, request, ref_response); // no matter if error or not, call curl done before returning to let curl clean everything - AZ_RETURN_IF_FAILED(_az_http_client_curl_done(&curl)); + _az_RETURN_IF_FAILED(_az_http_client_curl_done(&curl)); return process_result; } diff --git a/sdk/src/azure/storage/az_storage_blobs_blob_client.c b/sdk/src/azure/storage/az_storage_blobs_blob_client.c index 78f552f5c11..478f2878944 100644 --- a/sdk/src/azure/storage/az_storage_blobs_blob_client.c +++ b/sdk/src/azure/storage/az_storage_blobs_blob_client.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -118,11 +119,11 @@ AZ_NODISCARD az_result az_storage_blobs_blob_client_init( // Copy url to client buffer so customer can re-use buffer on his/her side int32_t const uri_size = az_span_size(endpoint); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(out_client->_internal.endpoint, uri_size); + _az_RETURN_IF_NOT_ENOUGH_SIZE(out_client->_internal.endpoint, uri_size); az_span_copy(out_client->_internal.endpoint, endpoint); out_client->_internal.endpoint = az_span_slice(out_client->_internal.endpoint, 0, uri_size); - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( _az_credential_set_scopes(cred, AZ_SPAN_FROM_STR("https://storage.azure.com/.default"))); return AZ_OK; @@ -151,7 +152,7 @@ AZ_NODISCARD az_result az_storage_blobs_blob_upload( az_span request_url_span = AZ_SPAN_FROM_BUFFER(url_buffer); // copy url from client int32_t uri_size = az_span_size(ref_client->_internal.endpoint); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(request_url_span, uri_size); + _az_RETURN_IF_NOT_ENOUGH_SIZE(request_url_span, uri_size); az_span_copy(request_url_span, ref_client->_internal.endpoint); uint8_t headers_buffer[_az_STORAGE_HTTP_REQUEST_HEADER_BUFFER_SIZE]; @@ -159,7 +160,7 @@ AZ_NODISCARD az_result az_storage_blobs_blob_upload( // create request az_http_request request; - AZ_RETURN_IF_FAILED(az_http_request_init( + _az_RETURN_IF_FAILED(az_http_request_init( &request, opt.context, az_http_method_put(), @@ -169,22 +170,22 @@ AZ_NODISCARD az_result az_storage_blobs_blob_upload( content)); // add blob type to request - AZ_RETURN_IF_FAILED(az_http_request_append_header( + _az_RETURN_IF_FAILED(az_http_request_append_header( &request, AZ_STORAGE_BLOBS_BLOB_HEADER_X_MS_BLOB_TYPE, AZ_STORAGE_BLOBS_BLOB_TYPE_BLOCKBLOB)); uint8_t content_length[_az_INT64_AS_STR_BUFFER_SIZE] = { 0 }; az_span content_length_span = AZ_SPAN_FROM_BUFFER(content_length); az_span remainder; - AZ_RETURN_IF_FAILED(az_span_i64toa(content_length_span, az_span_size(content), &remainder)); + _az_RETURN_IF_FAILED(az_span_i64toa(content_length_span, az_span_size(content), &remainder)); content_length_span = az_span_slice(content_length_span, 0, _az_span_diff(remainder, content_length_span)); // add Content-Length to request - AZ_RETURN_IF_FAILED( + _az_RETURN_IF_FAILED( az_http_request_append_header(&request, AZ_HTTP_HEADER_CONTENT_LENGTH, content_length_span)); // add blob type to request - AZ_RETURN_IF_FAILED(az_http_request_append_header( + _az_RETURN_IF_FAILED(az_http_request_append_header( &request, AZ_HTTP_HEADER_CONTENT_TYPE, AZ_SPAN_FROM_STR("text/plain"))); // start pipeline diff --git a/sdk/tests/core/test_az_json.c b/sdk/tests/core/test_az_json.c index d1079f418c4..b6894dd5692 100644 --- a/sdk/tests/core/test_az_json.c +++ b/sdk/tests/core/test_az_json.c @@ -3,6 +3,7 @@ #include "az_test_definitions.h" #include +#include #include #include @@ -1271,7 +1272,7 @@ az_result read_write_token( { case AZ_JSON_TOKEN_NULL: { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, 4); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, 4); *output = az_span_copy(*output, AZ_SPAN_FROM_STR("null")); *written += 4; return AZ_OK; @@ -1279,7 +1280,7 @@ az_result read_write_token( case AZ_JSON_TOKEN_TRUE: { int32_t required_length = 4; - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, required_length); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, required_length); *output = az_span_copy(*output, AZ_SPAN_FROM_STR("true")); *written += required_length; return AZ_OK; @@ -1287,14 +1288,14 @@ az_result read_write_token( case AZ_JSON_TOKEN_FALSE: { int32_t required_length = 5; - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, required_length); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, required_length); *output = az_span_copy(*output, AZ_SPAN_FROM_STR("false")); *written += required_length; return AZ_OK; } case AZ_JSON_TOKEN_NUMBER: { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); *output = az_span_copy_u8(*output, '0'); *written += 1; return AZ_OK; @@ -1305,21 +1306,21 @@ az_result read_write_token( } case AZ_JSON_TOKEN_BEGIN_OBJECT: { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); *output = az_span_copy_u8(*output, '{'); *written += 1; bool need_comma = false; while (true) { az_result const result = az_json_reader_next_token(state); - AZ_RETURN_IF_FAILED(result); + _az_RETURN_IF_FAILED(result); if (state->token.kind != AZ_JSON_TOKEN_PROPERTY_NAME) { break; } if (need_comma) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); *output = az_span_copy_u8(*output, ','); *written += 1; } @@ -1327,36 +1328,36 @@ az_result read_write_token( { need_comma = true; } - AZ_RETURN_IF_FAILED(write_str(*output, state->token.slice, output, written)); - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); + _az_RETURN_IF_FAILED(write_str(*output, state->token.slice, output, written)); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); *output = az_span_copy_u8(*output, ':'); *written += 1; - AZ_RETURN_IF_FAILED(az_json_reader_next_token(state)); - AZ_RETURN_IF_FAILED(read_write_token(output, written, o, state, state->token)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(state)); + _az_RETURN_IF_FAILED(read_write_token(output, written, o, state, state->token)); } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); *output = az_span_copy_u8(*output, '}'); *written += 1; return AZ_OK; } case AZ_JSON_TOKEN_BEGIN_ARRAY: { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); *output = az_span_copy_u8(*output, '['); *written += 1; bool need_comma = false; while (true) { az_result const result = az_json_reader_next_token(state); - AZ_RETURN_IF_FAILED(result); + _az_RETURN_IF_FAILED(result); if (state->token.kind == AZ_JSON_TOKEN_END_ARRAY) { break; } if (need_comma) { - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); *output = az_span_copy_u8(*output, ','); *written += 1; } @@ -1364,9 +1365,9 @@ az_result read_write_token( { need_comma = true; } - AZ_RETURN_IF_FAILED(read_write_token(output, written, o, state, state->token)); + _az_RETURN_IF_FAILED(read_write_token(output, written, o, state, state->token)); } - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*output, 1); *output = az_span_copy_u8(*output, ']'); *written += 1; return AZ_OK; @@ -1381,10 +1382,10 @@ az_result read_write(az_span input, az_span* output, int32_t* o) { az_json_reader reader = { 0 }; TEST_EXPECT_SUCCESS(az_json_reader_init(&reader, input, NULL)); - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&reader)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&reader)); int32_t written = 0; az_span output_copy = *output; - AZ_RETURN_IF_FAILED(read_write_token(&output_copy, &written, o, &reader, reader.token)); + _az_RETURN_IF_FAILED(read_write_token(&output_copy, &written, o, &reader, reader.token)); *output = az_span_slice(*output, 0, written); return AZ_OK; } @@ -1394,7 +1395,7 @@ az_result write_str(az_span span, az_span s, az_span* out, int32_t* written) *out = span; int32_t required_length = az_span_size(s) + 2; - AZ_RETURN_IF_NOT_ENOUGH_SIZE(*out, required_length); + _az_RETURN_IF_NOT_ENOUGH_SIZE(*out, required_length); *out = az_span_copy_u8(*out, '"'); *out = az_span_copy(*out, s); *out = az_span_copy_u8(*out, '"'); @@ -2658,9 +2659,9 @@ static az_result _az_process_json(az_span* input, int32_t number_of_buffers, mod az_span scratch_span = AZ_SPAN_FROM_BUFFER(available_scratch); az_json_reader jr = { 0 }; - AZ_RETURN_IF_FAILED(az_json_reader_chunked_init(&jr, input, number_of_buffers, NULL)); + _az_RETURN_IF_FAILED(az_json_reader_chunked_init(&jr, input, number_of_buffers, NULL)); - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_BEGIN_OBJECT) { return AZ_ERROR_UNEXPECTED_CHAR; @@ -2671,7 +2672,7 @@ static az_result _az_process_json(az_span* input, int32_t number_of_buffers, mod { if (az_json_token_is_text_equal(&jr.token, AZ_SPAN_FROM_STR("name"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_STRING) { return AZ_ERROR_ITEM_NOT_FOUND; @@ -2680,22 +2681,22 @@ static az_result _az_process_json(az_span* input, int32_t number_of_buffers, mod az_json_token_copy_into_span(&jr.token, az_span_slice(scratch_span, 0, jr.token.size)); output->name_value_span = az_span_slice(scratch_span, 0, jr.token.size); - AZ_RETURN_IF_FAILED(az_json_token_get_string( + _az_RETURN_IF_FAILED(az_json_token_get_string( &jr.token, output->name_string, output->name_length, &output->name_length)); } else if (az_json_token_is_text_equal(&jr.token, AZ_SPAN_FROM_STR("code"))) { - AZ_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_next_token(&jr)); if (jr.token.kind != AZ_JSON_TOKEN_NUMBER) { return AZ_ERROR_ITEM_NOT_FOUND; } - AZ_RETURN_IF_FAILED(az_json_token_get_int32(&jr.token, &output->code)); + _az_RETURN_IF_FAILED(az_json_token_get_int32(&jr.token, &output->code)); } else { // ignore other tokens - AZ_RETURN_IF_FAILED(az_json_reader_skip_children(&jr)); + _az_RETURN_IF_FAILED(az_json_reader_skip_children(&jr)); } }