Azure IoT common library

Dependents:   STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more

Revision:
48:81866008bba4
Parent:
33:810f9cff537a
Child:
49:6bb8b9a66642
--- a/uuid.c	Thu Jul 12 18:10:56 2018 -0700
+++ b/uuid.c	Tue Sep 11 11:15:08 2018 -0700
@@ -14,7 +14,7 @@
 #define __SUCCESS__                 0
 #define UUID_FORMAT_STRING          "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
 
-int UUID_from_string(const char* uuid_string, UUID* uuid)
+int UUID_from_string(const char* uuid_string, UUID_T* uuid)
 {
     int result;
 
@@ -75,20 +75,20 @@
     return result;
 }
 
-char* UUID_to_string(UUID* uuid)
+char* UUID_to_string(UUID_T* uuid)
 {
     char* result;
 
-    // Codes_SRS_UUID_09_011: [ If `uuid` is NULL, UUID_to_string shall return a non-zero value ]  
+    // Codes_SRS_UUID_09_011: [ If `uuid` is NULL, UUID_to_string shall return a non-zero value ]
     if (uuid == NULL)
     {
         LogError("Invalid argument (uuid is NULL)");
         result = NULL;
     }
-    // Codes_SRS_UUID_09_012: [ UUID_to_string shall allocate a valid UUID string (`uuid_string`) as per RFC 4122 ]  
+    // Codes_SRS_UUID_09_012: [ UUID_to_string shall allocate a valid UUID string (`uuid_string`) as per RFC 4122 ]
     else if ((result = (char*)malloc(sizeof(char) * UUID_STRING_SIZE)) == NULL)
     {
-        // Codes_SRS_UUID_09_013: [ If `uuid_string` fails to be allocated, UUID_to_string shall return NULL ]  
+        // Codes_SRS_UUID_09_013: [ If `uuid_string` fails to be allocated, UUID_to_string shall return NULL ]
         LogError("Failed allocating UUID string");
     }
     else
@@ -99,16 +99,12 @@
         uuid_bytes = (unsigned char*)uuid;
 
         // Codes_SRS_UUID_09_014: [ Each character in `uuid` shall be written in the respective positions of `uuid_string` as a 2-digit HEX value ]  
-        number_of_chars_written = sprintf(result, UUID_FORMAT_STRING,
-            uuid_bytes[0], uuid_bytes[1], uuid_bytes[2], uuid_bytes[3],
-            uuid_bytes[4], uuid_bytes[5],
-            uuid_bytes[6], uuid_bytes[7],
-            uuid_bytes[8], uuid_bytes[9],
-            uuid_bytes[10], uuid_bytes[11], uuid_bytes[12], uuid_bytes[13], uuid_bytes[14], uuid_bytes[15]);
+        number_of_chars_written = sprintf(result, "%" PRI_UUID,
+            UUID_FORMAT_VALUES(uuid_bytes));
 
         if (number_of_chars_written != UUID_STRING_LENGTH)
         {
-            // Tests_SRS_UUID_09_015: [ If `uuid_string` fails to be set, UUID_to_string shall return NULL ] 
+            // Tests_SRS_UUID_09_015: [ If `uuid_string` fails to be set, UUID_to_string shall return NULL ]
             LogError("Failed encoding UUID string");
             free(result);
             result = NULL;
@@ -119,7 +115,7 @@
     return result;
 }
 
-int UUID_generate(UUID* uuid)
+int UUID_generate(UUID_T* uuid)
 {
     int result;
 
@@ -141,7 +137,7 @@
         }
         else
         {
-            memset(uuid_string, 0, sizeof(char) * UUID_STRING_SIZE);
+            (void)memset(uuid_string, 0, sizeof(char) * UUID_STRING_SIZE);
 
             // Codes_SRS_UUID_09_002: [ UUID_generate shall obtain an UUID string from UniqueId_Generate ]
             if (UniqueId_Generate(uuid_string, UUID_STRING_SIZE) != UNIQUEID_OK)
@@ -150,7 +146,7 @@
                 LogError("Failed generating UUID");
                 result = __FAILURE__;
             }
-            // Codes_SRS_UUID_09_004: [ The UUID string shall be parsed into an UUID type (16 unsigned char array) and filled in `uuid` ]  
+            // Codes_SRS_UUID_09_004: [ The UUID string shall be parsed into an UUID_T type (16 unsigned char array) and filled in `uuid` ]
             else if (UUID_from_string(uuid_string, uuid) != 0)
             {
                 // Codes_SRS_UUID_09_005: [ If `uuid` fails to be set, UUID_generate shall fail and return a non-zero value ]