Skip to content

Commit 517139d

Browse files
update to GA code (#42)
1 parent 64a7933 commit 517139d

File tree

8 files changed

+49
-62
lines changed

8 files changed

+49
-62
lines changed

examples/Azure_IoT_Adu_ESP32/Azure_IoT_Adu_ESP32.ino

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -641,22 +641,10 @@ static void process_device_property_message(
641641
{
642642
if (adu_update_request.workflow.action == AZ_IOT_ADU_CLIENT_SERVICE_ACTION_APPLY_DEPLOYMENT)
643643
{
644-
rc = az_json_string_unescape(
645-
adu_update_request.update_manifest,
646-
(char*)adu_manifest_unescape_buffer,
647-
sizeof(adu_manifest_unescape_buffer),
648-
&out_manifest_size);
649-
650-
if (az_result_failed(rc))
651-
{
652-
Logger.Error("az_json_string_unescape failed" + String(rc));
653-
return;
654-
}
644+
adu_update_request.update_manifest = az_json_string_unescape(
645+
adu_update_request.update_manifest, adu_update_request.update_manifest);
655646

656-
az_span manifest_unescaped
657-
= az_span_create((uint8_t*)adu_manifest_unescape_buffer, out_manifest_size);
658-
659-
rc = az_json_reader_init(&jr_adu_manifest, manifest_unescaped, NULL);
647+
rc = az_json_reader_init(&jr_adu_manifest, adu_update_request.update_manifest, NULL);
660648

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

678666
rc = SampleJWS::ManifestAuthenticate(
679-
manifest_unescaped,
667+
adu_update_request.update_manifest,
680668
adu_update_request.update_manifest_signature,
681669
&xADURootKeys[0],
682670
sizeof(xADURootKeys) / sizeof(xADURootKeys[0]),

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Azure SDK for C
2-
version=1.1.0-beta.3
2+
version=1.1.0
33
author=Microsoft Corporation
44
maintainer=Microsoft Corporation <[email protected]>
55
sentence=Azure SDK for C library for Arduino.
6-
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.
6+
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.
77
category=Communication
88
url=https://github.com/Azure/azure-sdk-for-c-arduino/releases
99
architectures=*

src/az_iot_adu_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ AZ_NODISCARD az_result az_iot_adu_client_parse_update_manifest(
811811
}
812812
}
813813
/*
814-
* C SDK will not support delta updates at this time, so relatedFiles,
814+
* Embedded C SDK will not support delta updates at this time, so relatedFiles,
815815
* downloadHandler, and mimeType are not exposed or processed.
816816
*/
817817
else if (az_json_token_is_text_equal(

src/az_iot_adu_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ typedef struct
380380
/**
381381
* @brief Details of a file referenced in the update request.
382382
*
383+
* @note C SDK will not support delta updates at this time, so relatedFiles,
384+
* downloadHandler, and mimeType are not exposed or processed.
383385
*/
384386
typedef struct
385387
{

src/az_iot_adu_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
/*
4+
/**
5+
* @file
6+
*
7+
* @brief Defines internal macros used by the ADU client.
8+
*
59
* @note You MUST NOT use any symbols (macros, functions, structures, enums, etc.)
610
* prefixed with an underscore ('_') directly in your application code. These symbols
711
* are part of Azure SDK's internal implementation; we do not document these symbols

src/az_json.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -796,28 +796,24 @@ AZ_NODISCARD az_result az_json_reader_skip_children(az_json_reader* ref_json_rea
796796
* @brief Unescapes the JSON string within the provided #az_span.
797797
*
798798
* @param[in] json_string The #az_span that contains the string to be unescaped.
799-
* @param destination Pointer to the buffer that will contain the output.
800-
* @param[in] destination_max_size The maximum available space within the buffer referred to by
801-
* \p destination.
802-
* @param[out] out_string_length __[nullable]__ Contains the number of bytes written to the
803-
* \p destination which denote the length of the unescaped string. If `NULL` is passed, the
804-
* \p parameter is ignored.
799+
* @param destination The destination buffer used to write the unescaped output into.
805800
*
806-
* @return An #az_result value indicating the result of the operation.
807-
* @retval #AZ_OK The string is returned.
808-
* @retval #AZ_ERROR_NOT_ENOUGH_SPACE \p destination does not have enough size.
801+
* @return An #az_span that is a slice of the \p destination #az_span containing the unescaped JSON
802+
* string, which denotes the length of the unescaped string.
809803
*
810-
* @remarks The buffer referred to by \p destination must have a size that is at least 1 byte bigger
811-
* than the \p json_string #az_span for the \p destination string to be zero-terminated.
812-
* Content is copied from the source buffer, while unescaping and then `\0` is added at the end.
804+
* @remarks For user-defined or unknown input, the buffer referred to by \p destination must be at
805+
* least as large as the \p json_string #az_span. Content is copied from the source buffer, while
806+
* unescaping.
813807
*
814-
* @remarks This API can also be used to perform in place unescaping.
808+
* @remarks This function assumes that the \p json_string input is well-formed JSON.
809+
*
810+
* @remarks This function assumes that the \p destination has a large enough size to hold the
811+
* unescaped \p json_string.
812+
*
813+
* @remarks This API can also be used to perform in place unescaping. However, doing so, is
814+
* destructive and the input JSON may no longer be valid or parsable.
815815
*/
816-
AZ_NODISCARD az_result az_json_string_unescape(
817-
az_span json_string,
818-
char* destination,
819-
int32_t destination_max_size,
820-
int32_t* out_string_length);
816+
AZ_NODISCARD az_span az_json_string_unescape(az_span json_string, az_span destination);
821817

822818
#include <_az_cfg_suffix.h>
823819

src/az_json_token.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -325,20 +325,19 @@ AZ_NODISCARD static az_result _az_json_token_get_string_helper(
325325
return AZ_OK;
326326
}
327327

328-
AZ_NODISCARD az_result az_json_string_unescape(
329-
az_span json_string,
330-
char* destination,
331-
int32_t destination_max_size,
332-
int32_t* out_string_length)
328+
AZ_NODISCARD az_span az_json_string_unescape(az_span json_string, az_span destination)
333329
{
334330
_az_PRECONDITION_VALID_SPAN(json_string, 1, false);
335-
_az_PRECONDITION_NOT_NULL(destination);
336-
// The destination needs to be larger than the input, for null terminator.
337-
_az_PRECONDITION(destination_max_size > az_span_size(json_string));
338331

339-
int32_t position = 0;
340332
int32_t span_size = az_span_size(json_string);
333+
334+
// The destination needs to be at least as large as the input, in the worst case.
335+
_az_PRECONDITION_VALID_SPAN(destination, span_size, false);
336+
337+
int32_t position = 0;
341338
uint8_t* span_ptr = az_span_ptr(json_string);
339+
uint8_t* destination_ptr = az_span_ptr(destination);
340+
int32_t destination_size = az_span_size(destination);
342341
for (int32_t i = 0; i < span_size; i++)
343342
{
344343
uint8_t current_char = span_ptr[i];
@@ -353,32 +352,29 @@ AZ_NODISCARD az_result az_json_string_unescape(
353352
}
354353
else
355354
{
356-
return AZ_ERROR_UNEXPECTED_CHAR;
355+
// We assume that the input json is well-formed, but stop processing, in-case it isn't.
356+
return az_span_slice(destination, 0, position);
357357
}
358358
}
359359
else if (current_char == '\\')
360360
{
361361
// At this point, we are at the last character, i == span_size - 1
362-
return AZ_ERROR_UNEXPECTED_END;
362+
// We assume that the input json is well-formed, but stop processing, in-case it isn't.
363+
return az_span_slice(destination, 0, position);
363364
}
364365

365-
if (position > destination_max_size)
366+
if (position > destination_size)
366367
{
367-
return AZ_ERROR_NOT_ENOUGH_SPACE;
368+
// We assume that the destination buffer is large enough, but stop processing, in-case it
369+
// isn't.
370+
return az_span_slice(destination, 0, position);
368371
}
369372

370-
destination[position] = (char)current_char;
373+
destination_ptr[position] = current_char;
371374
position++;
372375
}
373376

374-
destination[position] = 0;
375-
376-
if (out_string_length != NULL)
377-
{
378-
*out_string_length = position;
379-
}
380-
381-
return AZ_OK;
377+
return az_span_slice(destination, 0, position);
382378
}
383379

384380
AZ_NODISCARD az_result az_json_token_get_string(

src/az_version.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

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

2222
/// Major numeric identifier.
2323
#define AZ_SDK_VERSION_MAJOR 1
@@ -29,6 +29,7 @@
2929
#define AZ_SDK_VERSION_PATCH 0
3030

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

3435
#endif //_az_VERSION_H

0 commit comments

Comments
 (0)