Skip to content

Commit

Permalink
update to GA code (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
danewalton-msft authored Nov 14, 2022
1 parent 64a7933 commit 517139d
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 62 deletions.
20 changes: 4 additions & 16 deletions examples/Azure_IoT_Adu_ESP32/Azure_IoT_Adu_ESP32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -641,22 +641,10 @@ static void process_device_property_message(
{
if (adu_update_request.workflow.action == AZ_IOT_ADU_CLIENT_SERVICE_ACTION_APPLY_DEPLOYMENT)
{
rc = az_json_string_unescape(
adu_update_request.update_manifest,
(char*)adu_manifest_unescape_buffer,
sizeof(adu_manifest_unescape_buffer),
&out_manifest_size);

if (az_result_failed(rc))
{
Logger.Error("az_json_string_unescape failed" + String(rc));
return;
}
adu_update_request.update_manifest = az_json_string_unescape(
adu_update_request.update_manifest, adu_update_request.update_manifest);

az_span manifest_unescaped
= az_span_create((uint8_t*)adu_manifest_unescape_buffer, out_manifest_size);

rc = az_json_reader_init(&jr_adu_manifest, manifest_unescaped, NULL);
rc = az_json_reader_init(&jr_adu_manifest, adu_update_request.update_manifest, NULL);

if (az_result_failed(rc))
{
Expand All @@ -676,7 +664,7 @@ static void process_device_property_message(
Logger.Info("Parsed Azure device update manifest.");

rc = SampleJWS::ManifestAuthenticate(
manifest_unescaped,
adu_update_request.update_manifest,
adu_update_request.update_manifest_signature,
&xADURootKeys[0],
sizeof(xADURootKeys) / sizeof(xADURootKeys[0]),
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=Azure SDK for C
version=1.1.0-beta.3
version=1.1.0
author=Microsoft Corporation
maintainer=Microsoft Corporation <[email protected]>
sentence=Azure SDK for C library for Arduino.
paragraph=This is an Arduino port of the Azure SDK for C (1.4.0-beta.2). It allows you to use your Arduino device with Azure services like Azure IoT Hub and Azure Device Provisioning Service. See README.md for more details. Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
paragraph=This is an Arduino port of the Azure SDK for C (1.4.0). It allows you to use your Arduino device with Azure services like Azure IoT Hub and Azure Device Provisioning Service. See README.md for more details. Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
category=Communication
url=https://github.com/Azure/azure-sdk-for-c-arduino/releases
architectures=*
Expand Down
2 changes: 1 addition & 1 deletion src/az_iot_adu_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ AZ_NODISCARD az_result az_iot_adu_client_parse_update_manifest(
}
}
/*
* C SDK will not support delta updates at this time, so relatedFiles,
* Embedded C SDK will not support delta updates at this time, so relatedFiles,
* downloadHandler, and mimeType are not exposed or processed.
*/
else if (az_json_token_is_text_equal(
Expand Down
2 changes: 2 additions & 0 deletions src/az_iot_adu_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ typedef struct
/**
* @brief Details of a file referenced in the update request.
*
* @note C SDK will not support delta updates at this time, so relatedFiles,
* downloadHandler, and mimeType are not exposed or processed.
*/
typedef struct
{
Expand Down
6 changes: 5 additions & 1 deletion src/az_iot_adu_internal.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT

/*
/**
* @file
*
* @brief Defines internal macros used by the ADU client.
*
* @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
Expand Down
32 changes: 14 additions & 18 deletions src/az_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,28 +796,24 @@ AZ_NODISCARD az_result az_json_reader_skip_children(az_json_reader* ref_json_rea
* @brief Unescapes the JSON string within the provided #az_span.
*
* @param[in] json_string The #az_span that contains the string to be unescaped.
* @param destination Pointer to the buffer that will contain the output.
* @param[in] destination_max_size The maximum available space within the buffer referred to by
* \p destination.
* @param[out] out_string_length __[nullable]__ Contains the number of bytes written to the
* \p destination which denote the length of the unescaped string. If `NULL` is passed, the
* \p parameter is ignored.
* @param destination The destination buffer used to write the unescaped output into.
*
* @return An #az_result value indicating the result of the operation.
* @retval #AZ_OK The string is returned.
* @retval #AZ_ERROR_NOT_ENOUGH_SPACE \p destination does not have enough size.
* @return An #az_span that is a slice of the \p destination #az_span containing the unescaped JSON
* string, which denotes the length of the unescaped string.
*
* @remarks The buffer referred to by \p destination must have a size that is at least 1 byte bigger
* than the \p json_string #az_span for the \p destination string to be zero-terminated.
* Content is copied from the source buffer, while unescaping and then `\0` is added at the end.
* @remarks For user-defined or unknown input, the buffer referred to by \p destination must be at
* least as large as the \p json_string #az_span. Content is copied from the source buffer, while
* unescaping.
*
* @remarks This API can also be used to perform in place unescaping.
* @remarks This function assumes that the \p json_string input is well-formed JSON.
*
* @remarks This function assumes that the \p destination has a large enough size to hold the
* unescaped \p json_string.
*
* @remarks This API can also be used to perform in place unescaping. However, doing so, is
* destructive and the input JSON may no longer be valid or parsable.
*/
AZ_NODISCARD az_result az_json_string_unescape(
az_span json_string,
char* destination,
int32_t destination_max_size,
int32_t* out_string_length);
AZ_NODISCARD az_span az_json_string_unescape(az_span json_string, az_span destination);

#include <_az_cfg_suffix.h>

Expand Down
40 changes: 18 additions & 22 deletions src/az_json_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,19 @@ AZ_NODISCARD static az_result _az_json_token_get_string_helper(
return AZ_OK;
}

AZ_NODISCARD az_result az_json_string_unescape(
az_span json_string,
char* destination,
int32_t destination_max_size,
int32_t* out_string_length)
AZ_NODISCARD az_span az_json_string_unescape(az_span json_string, az_span destination)
{
_az_PRECONDITION_VALID_SPAN(json_string, 1, false);
_az_PRECONDITION_NOT_NULL(destination);
// The destination needs to be larger than the input, for null terminator.
_az_PRECONDITION(destination_max_size > az_span_size(json_string));

int32_t position = 0;
int32_t span_size = az_span_size(json_string);

// The destination needs to be at least as large as the input, in the worst case.
_az_PRECONDITION_VALID_SPAN(destination, span_size, false);

int32_t position = 0;
uint8_t* span_ptr = az_span_ptr(json_string);
uint8_t* destination_ptr = az_span_ptr(destination);
int32_t destination_size = az_span_size(destination);
for (int32_t i = 0; i < span_size; i++)
{
uint8_t current_char = span_ptr[i];
Expand All @@ -353,32 +352,29 @@ AZ_NODISCARD az_result az_json_string_unescape(
}
else
{
return AZ_ERROR_UNEXPECTED_CHAR;
// We assume that the input json is well-formed, but stop processing, in-case it isn't.
return az_span_slice(destination, 0, position);
}
}
else if (current_char == '\\')
{
// At this point, we are at the last character, i == span_size - 1
return AZ_ERROR_UNEXPECTED_END;
// We assume that the input json is well-formed, but stop processing, in-case it isn't.
return az_span_slice(destination, 0, position);
}

if (position > destination_max_size)
if (position > destination_size)
{
return AZ_ERROR_NOT_ENOUGH_SPACE;
// We assume that the destination buffer is large enough, but stop processing, in-case it
// isn't.
return az_span_slice(destination, 0, position);
}

destination[position] = (char)current_char;
destination_ptr[position] = current_char;
position++;
}

destination[position] = 0;

if (out_string_length != NULL)
{
*out_string_length = position;
}

return AZ_OK;
return az_span_slice(destination, 0, position);
}

AZ_NODISCARD az_result az_json_token_get_string(
Expand Down
5 changes: 3 additions & 2 deletions src/az_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/// The version in string format used for telemetry following the `semver.org` standard
/// (https://semver.org).
#define AZ_SDK_VERSION_STRING "1.4.0-beta.2"
#define AZ_SDK_VERSION_STRING "1.4.0"

/// Major numeric identifier.
#define AZ_SDK_VERSION_MAJOR 1
Expand All @@ -29,6 +29,7 @@
#define AZ_SDK_VERSION_PATCH 0

/// Optional pre-release identifier. SDK is in a pre-release state when present.
#define AZ_SDK_VERSION_PRERELEASE "beta.2"
#define AZ_SDK_VERSION_PRERELEASE
#undef AZ_SDK_VERSION_PRERELEASE

#endif //_az_VERSION_H

0 comments on commit 517139d

Please sign in to comment.