Microsoft Azure IoTHub client MQTT transport

Dependents:   STM32F746_iothub_client_sample_mqtt FXOS8700CQ_To_Azure_IoT f767zi_mqtt FXOS8700CQ_To_Azure_IoT ... more

Revision:
23:84f4c36da8c1
Parent:
22:07fec4d325b6
Child:
24:4096249decf1
--- a/iothubtransport_mqtt_common.c	Mon May 08 10:50:18 2017 -0700
+++ b/iothubtransport_mqtt_common.c	Mon May 22 10:34:57 2017 -0700
@@ -804,6 +804,7 @@
     const char* const* propertyKeys;
     const char* const* propertyValues;
     size_t propertyCount;
+    size_t index = 0;
 
     // Construct Properties
     MAP_HANDLE properties_map = IoTHubMessage_Properties(iothub_message_handle);
@@ -819,11 +820,11 @@
         {
             if (propertyCount != 0)
             {
-                size_t index = 0;
                 for (index = 0; index < propertyCount && result != NULL; index++)
                 {
                     if (STRING_sprintf(result, "%s=%s%s", propertyKeys[index], propertyValues[index], propertyCount - 1 == index ? "" : PROPERTY_SEPARATOR) != 0)
                     {
+                        LogError("Failed construting property string.");
                         STRING_delete(result);
                         result = NULL;
                     }
@@ -831,6 +832,37 @@
             }
         }
     }
+
+    /* Codes_SRS_IOTHUB_TRANSPORT_MQTT_COMMON_07_052: [ IoTHubTransport_MQTT_Common_DoWork shall check for the CorrelationId property and if found add the value as a system property in the format of $.cid=<id> ] */
+    if (result != NULL)
+    {
+        const char* correlation_id = IoTHubMessage_GetCorrelationId(iothub_message_handle);
+        if (correlation_id != NULL)
+        {
+            if (STRING_sprintf(result, "%s%%24.cid=%s", index == 0 ? "" : PROPERTY_SEPARATOR, correlation_id) != 0)
+            {
+                LogError("Failed setting correlation_id.");
+                STRING_delete(result);
+                result = NULL;
+            }
+            index++;
+        }
+    }
+
+    /* Codes_SRS_IOTHUB_TRANSPORT_MQTT_COMMON_07_053: [ IoTHubTransport_MQTT_Common_DoWork shall check for the MessageId property and if found add the value as a system property in the format of $.mid=<id> ] */
+    if (result != NULL)
+    {
+        const char* msg_id = IoTHubMessage_GetMessageId(iothub_message_handle);
+        if (msg_id != NULL)
+        {
+            if (STRING_sprintf(result, "%s%%24.mid=%s", index == 0 ? "" : PROPERTY_SEPARATOR, msg_id) != 0)
+            {
+                LogError("Failed setting correlation_id.");
+                STRING_delete(result);
+                result = NULL;
+            }
+        }
+    }
     return result;
 }