Microsoft Azure IoTHub client libraries

Dependents:   sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more

This library implements the Microsoft Azure IoTHub client library. The code is replicated from https://github.com/Azure/azure-iot-sdks

Committer:
AzureIoTClient
Date:
Fri Mar 10 11:47:36 2017 -0800
Revision:
61:8b85a4e797cf
Parent:
60:41648c4e7036
Child:
74:ea0021abecf7
1.1.9

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 0:e393db310d89 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 0:e393db310d89 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 0:e393db310d89 3
AzureIoTClient 0:e393db310d89 4 #include <stdlib.h>
AzureIoTClient 60:41648c4e7036 5 #include "azure_c_shared_utility/optimize_size.h"
Azure.IoT Build 38:a05929a75111 6 #include "azure_c_shared_utility/gballoc.h"
Azure.IoT Build 45:54c11b1b1407 7 #include "azure_c_shared_utility/xlogging.h"
Azure.IoT Build 38:a05929a75111 8 #include "azure_c_shared_utility/buffer_.h"
AzureIoTClient 0:e393db310d89 9
AzureIoTClient 0:e393db310d89 10 #include "iothub_message.h"
AzureIoTClient 0:e393db310d89 11
AzureIoTClient 0:e393db310d89 12 DEFINE_ENUM_STRINGS(IOTHUB_MESSAGE_RESULT, IOTHUB_MESSAGE_RESULT_VALUES);
AzureIoTClient 0:e393db310d89 13 DEFINE_ENUM_STRINGS(IOTHUBMESSAGE_CONTENT_TYPE, IOTHUBMESSAGE_CONTENT_TYPE_VALUES);
AzureIoTClient 0:e393db310d89 14
AzureIoTClient 0:e393db310d89 15 #define LOG_IOTHUB_MESSAGE_ERROR() \
AzureIoTClient 39:2719651a5bee 16 LogError("(result = %s)", ENUM_TO_STRING(IOTHUB_MESSAGE_RESULT, result));
AzureIoTClient 0:e393db310d89 17
AzureIoTClient 0:e393db310d89 18 typedef struct IOTHUB_MESSAGE_HANDLE_DATA_TAG
AzureIoTClient 0:e393db310d89 19 {
AzureIoTClient 0:e393db310d89 20 IOTHUBMESSAGE_CONTENT_TYPE contentType;
AzureIoTClient 0:e393db310d89 21 union
AzureIoTClient 0:e393db310d89 22 {
AzureIoTClient 0:e393db310d89 23 BUFFER_HANDLE byteArray;
AzureIoTClient 0:e393db310d89 24 STRING_HANDLE string;
AzureIoTClient 0:e393db310d89 25 } value;
AzureIoTClient 0:e393db310d89 26 MAP_HANDLE properties;
AzureIoTClient 18:1e9adb15c645 27 char* messageId;
AzureIoTClient 18:1e9adb15c645 28 char* correlationId;
AzureIoTClient 0:e393db310d89 29 }IOTHUB_MESSAGE_HANDLE_DATA;
AzureIoTClient 0:e393db310d89 30
AzureIoTClient 0:e393db310d89 31 static bool ContainsOnlyUsAscii(const char* asciiValue)
AzureIoTClient 0:e393db310d89 32 {
AzureIoTClient 21:3c90c2262ce4 33 bool result = true;
AzureIoTClient 0:e393db310d89 34 const char* iterator = asciiValue;
AzureIoTClient 0:e393db310d89 35 while (iterator != NULL && *iterator != '\0')
AzureIoTClient 0:e393db310d89 36 {
AzureIoTClient 0:e393db310d89 37 // Allow only printable ascii char
AzureIoTClient 0:e393db310d89 38 if (*iterator < ' ' || *iterator > '~')
AzureIoTClient 0:e393db310d89 39 {
AzureIoTClient 0:e393db310d89 40 result = false;
AzureIoTClient 0:e393db310d89 41 break;
AzureIoTClient 0:e393db310d89 42 }
AzureIoTClient 0:e393db310d89 43 iterator++;
AzureIoTClient 0:e393db310d89 44 }
AzureIoTClient 0:e393db310d89 45 return result;
AzureIoTClient 0:e393db310d89 46 }
AzureIoTClient 0:e393db310d89 47
AzureIoTClient 0:e393db310d89 48 /* Codes_SRS_IOTHUBMESSAGE_07_008: [ValidateAsciiCharactersFilter shall loop through the mapKey and mapValue strings to ensure that they only contain valid US-Ascii characters Ascii value 32 - 126.] */
AzureIoTClient 0:e393db310d89 49 static int ValidateAsciiCharactersFilter(const char* mapKey, const char* mapValue)
AzureIoTClient 0:e393db310d89 50 {
AzureIoTClient 0:e393db310d89 51 int result;
AzureIoTClient 0:e393db310d89 52 if (!ContainsOnlyUsAscii(mapKey) || !ContainsOnlyUsAscii(mapValue) )
AzureIoTClient 0:e393db310d89 53 {
AzureIoTClient 60:41648c4e7036 54 result = __FAILURE__;
AzureIoTClient 0:e393db310d89 55 }
AzureIoTClient 0:e393db310d89 56 else
AzureIoTClient 0:e393db310d89 57 {
AzureIoTClient 0:e393db310d89 58 result = 0;
AzureIoTClient 0:e393db310d89 59 }
AzureIoTClient 0:e393db310d89 60 return result;
AzureIoTClient 0:e393db310d89 61 }
AzureIoTClient 0:e393db310d89 62
AzureIoTClient 0:e393db310d89 63 IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromByteArray(const unsigned char* byteArray, size_t size)
AzureIoTClient 0:e393db310d89 64 {
AzureIoTClient 0:e393db310d89 65 IOTHUB_MESSAGE_HANDLE_DATA* result;
AzureIoTClient 61:8b85a4e797cf 66 if ((byteArray == NULL) && (size != 0))
AzureIoTClient 0:e393db310d89 67 {
AzureIoTClient 61:8b85a4e797cf 68 LogError("Invalid argument - byteArray is NULL");
AzureIoTClient 61:8b85a4e797cf 69 result = NULL;
AzureIoTClient 0:e393db310d89 70 }
AzureIoTClient 0:e393db310d89 71 else
AzureIoTClient 0:e393db310d89 72 {
AzureIoTClient 61:8b85a4e797cf 73 result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA));
AzureIoTClient 61:8b85a4e797cf 74 if (result == NULL)
AzureIoTClient 61:8b85a4e797cf 75 {
AzureIoTClient 61:8b85a4e797cf 76 LogError("unable to malloc");
AzureIoTClient 61:8b85a4e797cf 77 /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */
AzureIoTClient 61:8b85a4e797cf 78 /*let it go through*/
AzureIoTClient 61:8b85a4e797cf 79 }
AzureIoTClient 61:8b85a4e797cf 80 else
AzureIoTClient 0:e393db310d89 81 {
AzureIoTClient 61:8b85a4e797cf 82 const unsigned char* source;
AzureIoTClient 61:8b85a4e797cf 83 unsigned char temp = 0x00;
AzureIoTClient 61:8b85a4e797cf 84 if (size != 0)
AzureIoTClient 0:e393db310d89 85 {
AzureIoTClient 61:8b85a4e797cf 86 /*Codes_SRS_IOTHUBMESSAGE_06_002: [If size is NOT zero then byteArray MUST NOT be NULL*/
AzureIoTClient 61:8b85a4e797cf 87 if (byteArray == NULL)
AzureIoTClient 61:8b85a4e797cf 88 {
AzureIoTClient 61:8b85a4e797cf 89 LogError("Attempted to create a Hub Message from a NULL pointer!");
AzureIoTClient 61:8b85a4e797cf 90 free(result);
AzureIoTClient 61:8b85a4e797cf 91 result = NULL;
AzureIoTClient 61:8b85a4e797cf 92 source = NULL;
AzureIoTClient 61:8b85a4e797cf 93 }
AzureIoTClient 61:8b85a4e797cf 94 else
AzureIoTClient 61:8b85a4e797cf 95 {
AzureIoTClient 61:8b85a4e797cf 96 source = byteArray;
AzureIoTClient 61:8b85a4e797cf 97 }
AzureIoTClient 0:e393db310d89 98 }
AzureIoTClient 0:e393db310d89 99 else
AzureIoTClient 0:e393db310d89 100 {
AzureIoTClient 61:8b85a4e797cf 101 /*Codes_SRS_IOTHUBMESSAGE_06_001: [If size is zero then byteArray may be NULL.]*/
AzureIoTClient 61:8b85a4e797cf 102 source = &temp;
AzureIoTClient 0:e393db310d89 103 }
AzureIoTClient 61:8b85a4e797cf 104 if (result != NULL)
AzureIoTClient 61:8b85a4e797cf 105 {
AzureIoTClient 61:8b85a4e797cf 106 /*Codes_SRS_IOTHUBMESSAGE_02_022: [IoTHubMessage_CreateFromByteArray shall call BUFFER_create passing byteArray and size as parameters.] */
AzureIoTClient 61:8b85a4e797cf 107 if ((result->value.byteArray = BUFFER_create(source, size)) == NULL)
AzureIoTClient 61:8b85a4e797cf 108 {
AzureIoTClient 61:8b85a4e797cf 109 LogError("BUFFER_create failed");
AzureIoTClient 61:8b85a4e797cf 110 /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */
AzureIoTClient 61:8b85a4e797cf 111 free(result);
AzureIoTClient 61:8b85a4e797cf 112 result = NULL;
AzureIoTClient 61:8b85a4e797cf 113 }
AzureIoTClient 61:8b85a4e797cf 114 /*Codes_SRS_IOTHUBMESSAGE_02_023: [IoTHubMessage_CreateFromByteArray shall call Map_Create to create the message properties.] */
AzureIoTClient 61:8b85a4e797cf 115 else if ((result->properties = Map_Create(ValidateAsciiCharactersFilter)) == NULL)
AzureIoTClient 61:8b85a4e797cf 116 {
AzureIoTClient 61:8b85a4e797cf 117 LogError("Map_Create failed");
AzureIoTClient 61:8b85a4e797cf 118 /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */
AzureIoTClient 61:8b85a4e797cf 119 BUFFER_delete(result->value.byteArray);
AzureIoTClient 61:8b85a4e797cf 120 free(result);
AzureIoTClient 61:8b85a4e797cf 121 result = NULL;
AzureIoTClient 61:8b85a4e797cf 122 }
AzureIoTClient 61:8b85a4e797cf 123 else
AzureIoTClient 61:8b85a4e797cf 124 {
AzureIoTClient 61:8b85a4e797cf 125 /*Codes_SRS_IOTHUBMESSAGE_02_025: [Otherwise, IoTHubMessage_CreateFromByteArray shall return a non-NULL handle.] */
AzureIoTClient 61:8b85a4e797cf 126 /*Codes_SRS_IOTHUBMESSAGE_02_026: [The type of the new message shall be IOTHUBMESSAGE_BYTEARRAY.] */
AzureIoTClient 61:8b85a4e797cf 127 result->contentType = IOTHUBMESSAGE_BYTEARRAY;
AzureIoTClient 61:8b85a4e797cf 128 result->messageId = NULL;
AzureIoTClient 61:8b85a4e797cf 129 result->correlationId = NULL;
AzureIoTClient 61:8b85a4e797cf 130 /*all is fine, return result*/
AzureIoTClient 61:8b85a4e797cf 131 }
AzureIoTClient 61:8b85a4e797cf 132 }
AzureIoTClient 61:8b85a4e797cf 133 }
AzureIoTClient 61:8b85a4e797cf 134 }
AzureIoTClient 61:8b85a4e797cf 135 return result;
AzureIoTClient 61:8b85a4e797cf 136 }
AzureIoTClient 61:8b85a4e797cf 137
AzureIoTClient 61:8b85a4e797cf 138 IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromString(const char* source)
AzureIoTClient 61:8b85a4e797cf 139 {
AzureIoTClient 61:8b85a4e797cf 140 IOTHUB_MESSAGE_HANDLE_DATA* result;
AzureIoTClient 61:8b85a4e797cf 141 if (source == NULL)
AzureIoTClient 61:8b85a4e797cf 142 {
AzureIoTClient 61:8b85a4e797cf 143 LogError("Invalid argument - source is NULL");
AzureIoTClient 61:8b85a4e797cf 144 result = NULL;
AzureIoTClient 61:8b85a4e797cf 145 }
AzureIoTClient 61:8b85a4e797cf 146 else
AzureIoTClient 61:8b85a4e797cf 147 {
AzureIoTClient 61:8b85a4e797cf 148 result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA));
AzureIoTClient 61:8b85a4e797cf 149 if (result == NULL)
AzureIoTClient 61:8b85a4e797cf 150 {
AzureIoTClient 61:8b85a4e797cf 151 LogError("malloc failed");
AzureIoTClient 61:8b85a4e797cf 152 /*Codes_SRS_IOTHUBMESSAGE_02_029: [If there are any encountered in the execution of IoTHubMessage_CreateFromString then IoTHubMessage_CreateFromString shall return NULL.] */
AzureIoTClient 61:8b85a4e797cf 153 /*let it go through*/
AzureIoTClient 0:e393db310d89 154 }
AzureIoTClient 0:e393db310d89 155 else
AzureIoTClient 0:e393db310d89 156 {
AzureIoTClient 61:8b85a4e797cf 157 /*Codes_SRS_IOTHUBMESSAGE_02_027: [IoTHubMessage_CreateFromString shall call STRING_construct passing source as parameter.] */
AzureIoTClient 61:8b85a4e797cf 158 if ((result->value.string = STRING_construct(source)) == NULL)
AzureIoTClient 0:e393db310d89 159 {
AzureIoTClient 61:8b85a4e797cf 160 LogError("STRING_construct failed");
AzureIoTClient 61:8b85a4e797cf 161 /*Codes_SRS_IOTHUBMESSAGE_02_029: [If there are any encountered in the execution of IoTHubMessage_CreateFromString then IoTHubMessage_CreateFromString shall return NULL.] */
AzureIoTClient 0:e393db310d89 162 free(result);
AzureIoTClient 0:e393db310d89 163 result = NULL;
AzureIoTClient 0:e393db310d89 164 }
AzureIoTClient 61:8b85a4e797cf 165 /*Codes_SRS_IOTHUBMESSAGE_02_028: [IoTHubMessage_CreateFromString shall call Map_Create to create the message properties.] */
AzureIoTClient 0:e393db310d89 166 else if ((result->properties = Map_Create(ValidateAsciiCharactersFilter)) == NULL)
AzureIoTClient 0:e393db310d89 167 {
AzureIoTClient 39:2719651a5bee 168 LogError("Map_Create failed");
AzureIoTClient 61:8b85a4e797cf 169 /*Codes_SRS_IOTHUBMESSAGE_02_029: [If there are any encountered in the execution of IoTHubMessage_CreateFromString then IoTHubMessage_CreateFromString shall return NULL.] */
AzureIoTClient 61:8b85a4e797cf 170 STRING_delete(result->value.string);
AzureIoTClient 0:e393db310d89 171 free(result);
AzureIoTClient 0:e393db310d89 172 result = NULL;
AzureIoTClient 0:e393db310d89 173 }
AzureIoTClient 0:e393db310d89 174 else
AzureIoTClient 0:e393db310d89 175 {
AzureIoTClient 61:8b85a4e797cf 176 /*Codes_SRS_IOTHUBMESSAGE_02_031: [Otherwise, IoTHubMessage_CreateFromString shall return a non-NULL handle.] */
AzureIoTClient 61:8b85a4e797cf 177 /*Codes_SRS_IOTHUBMESSAGE_02_032: [The type of the new message shall be IOTHUBMESSAGE_STRING.] */
AzureIoTClient 61:8b85a4e797cf 178 result->contentType = IOTHUBMESSAGE_STRING;
AzureIoTClient 18:1e9adb15c645 179 result->messageId = NULL;
AzureIoTClient 18:1e9adb15c645 180 result->correlationId = NULL;
AzureIoTClient 0:e393db310d89 181 }
AzureIoTClient 0:e393db310d89 182 }
AzureIoTClient 0:e393db310d89 183 }
AzureIoTClient 0:e393db310d89 184 return result;
AzureIoTClient 0:e393db310d89 185 }
AzureIoTClient 0:e393db310d89 186
AzureIoTClient 0:e393db310d89 187 /*Codes_SRS_IOTHUBMESSAGE_03_001: [IoTHubMessage_Clone shall create a new IoT hub message with data content identical to that of the iotHubMessageHandle parameter.]*/
AzureIoTClient 0:e393db310d89 188 IOTHUB_MESSAGE_HANDLE IoTHubMessage_Clone(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 0:e393db310d89 189 {
AzureIoTClient 0:e393db310d89 190 IOTHUB_MESSAGE_HANDLE_DATA* result;
AzureIoTClient 0:e393db310d89 191 const IOTHUB_MESSAGE_HANDLE_DATA* source = (const IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 192 /* Codes_SRS_IOTHUBMESSAGE_03_005: [IoTHubMessage_Clone shall return NULL if iotHubMessageHandle is NULL.] */
AzureIoTClient 0:e393db310d89 193 if (source == NULL)
AzureIoTClient 0:e393db310d89 194 {
AzureIoTClient 0:e393db310d89 195 result = NULL;
AzureIoTClient 39:2719651a5bee 196 LogError("iotHubMessageHandle parameter cannot be NULL for IoTHubMessage_Clone");
AzureIoTClient 0:e393db310d89 197 }
AzureIoTClient 0:e393db310d89 198 else
AzureIoTClient 0:e393db310d89 199 {
AzureIoTClient 0:e393db310d89 200 result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA));
AzureIoTClient 0:e393db310d89 201 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 0:e393db310d89 202 if (result == NULL)
AzureIoTClient 0:e393db310d89 203 {
AzureIoTClient 0:e393db310d89 204 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 0:e393db310d89 205 /*do nothing and return as is*/
AzureIoTClient 39:2719651a5bee 206 LogError("unable to malloc");
AzureIoTClient 0:e393db310d89 207 }
AzureIoTClient 0:e393db310d89 208 else
AzureIoTClient 0:e393db310d89 209 {
AzureIoTClient 18:1e9adb15c645 210 result->messageId = NULL;
AzureIoTClient 18:1e9adb15c645 211 result->correlationId = NULL;
AzureIoTClient 18:1e9adb15c645 212 if (source->messageId != NULL && mallocAndStrcpy_s(&result->messageId, source->messageId) != 0)
AzureIoTClient 18:1e9adb15c645 213 {
AzureIoTClient 39:2719651a5bee 214 LogError("unable to Copy messageId");
AzureIoTClient 18:1e9adb15c645 215 free(result);
AzureIoTClient 18:1e9adb15c645 216 result = NULL;
AzureIoTClient 18:1e9adb15c645 217 }
AzureIoTClient 18:1e9adb15c645 218 else if (source->correlationId != NULL && mallocAndStrcpy_s(&result->correlationId, source->correlationId) != 0)
AzureIoTClient 18:1e9adb15c645 219 {
AzureIoTClient 39:2719651a5bee 220 LogError("unable to Copy correlationId");
AzureIoTClient 18:1e9adb15c645 221 if (result->messageId != NULL)
AzureIoTClient 18:1e9adb15c645 222 {
AzureIoTClient 18:1e9adb15c645 223 free(result->messageId);
AzureIoTClient 18:1e9adb15c645 224 result->messageId = NULL;
AzureIoTClient 18:1e9adb15c645 225 }
AzureIoTClient 18:1e9adb15c645 226 free(result);
AzureIoTClient 18:1e9adb15c645 227 result = NULL;
AzureIoTClient 18:1e9adb15c645 228 }
AzureIoTClient 18:1e9adb15c645 229 else if (source->contentType == IOTHUBMESSAGE_BYTEARRAY)
AzureIoTClient 0:e393db310d89 230 {
AzureIoTClient 0:e393db310d89 231 /*Codes_SRS_IOTHUBMESSAGE_02_006: [IoTHubMessage_Clone shall clone to content by a call to BUFFER_clone] */
AzureIoTClient 0:e393db310d89 232 if ((result->value.byteArray = BUFFER_clone(source->value.byteArray)) == NULL)
AzureIoTClient 0:e393db310d89 233 {
AzureIoTClient 0:e393db310d89 234 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 39:2719651a5bee 235 LogError("unable to BUFFER_clone");
AzureIoTClient 18:1e9adb15c645 236 if (result->messageId)
AzureIoTClient 18:1e9adb15c645 237 {
AzureIoTClient 18:1e9adb15c645 238 free(result->messageId);
AzureIoTClient 18:1e9adb15c645 239 result->messageId = NULL;
AzureIoTClient 18:1e9adb15c645 240 }
AzureIoTClient 18:1e9adb15c645 241 if (result->correlationId != NULL)
AzureIoTClient 18:1e9adb15c645 242 {
AzureIoTClient 18:1e9adb15c645 243 free(result->correlationId);
AzureIoTClient 18:1e9adb15c645 244 result->correlationId = NULL;
AzureIoTClient 18:1e9adb15c645 245 }
AzureIoTClient 0:e393db310d89 246 free(result);
AzureIoTClient 0:e393db310d89 247 result = NULL;
AzureIoTClient 0:e393db310d89 248 }
AzureIoTClient 0:e393db310d89 249 /*Codes_SRS_IOTHUBMESSAGE_02_005: [IoTHubMessage_Clone shall clone the properties map by using Map_Clone.] */
AzureIoTClient 0:e393db310d89 250 else if ((result->properties = Map_Clone(source->properties)) == NULL)
AzureIoTClient 0:e393db310d89 251 {
AzureIoTClient 0:e393db310d89 252 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 39:2719651a5bee 253 LogError("unable to Map_Clone");
AzureIoTClient 0:e393db310d89 254 BUFFER_delete(result->value.byteArray);
AzureIoTClient 18:1e9adb15c645 255 if (result->messageId)
AzureIoTClient 18:1e9adb15c645 256 {
AzureIoTClient 18:1e9adb15c645 257 free(result->messageId);
AzureIoTClient 18:1e9adb15c645 258 result->messageId = NULL;
AzureIoTClient 18:1e9adb15c645 259 }
AzureIoTClient 18:1e9adb15c645 260 if (result->correlationId != NULL)
AzureIoTClient 18:1e9adb15c645 261 {
AzureIoTClient 18:1e9adb15c645 262 free(result->correlationId);
AzureIoTClient 18:1e9adb15c645 263 result->correlationId = NULL;
AzureIoTClient 18:1e9adb15c645 264 }
AzureIoTClient 0:e393db310d89 265 free(result);
AzureIoTClient 0:e393db310d89 266 result = NULL;
AzureIoTClient 0:e393db310d89 267 }
AzureIoTClient 0:e393db310d89 268 else
AzureIoTClient 0:e393db310d89 269 {
AzureIoTClient 0:e393db310d89 270 result->contentType = IOTHUBMESSAGE_BYTEARRAY;
AzureIoTClient 0:e393db310d89 271 /*Codes_SRS_IOTHUBMESSAGE_03_002: [IoTHubMessage_Clone shall return upon success a non-NULL handle to the newly created IoT hub message.]*/
AzureIoTClient 0:e393db310d89 272 /*return as is, this is a good result*/
AzureIoTClient 0:e393db310d89 273 }
AzureIoTClient 0:e393db310d89 274 }
AzureIoTClient 0:e393db310d89 275 else /*can only be STRING*/
AzureIoTClient 0:e393db310d89 276 {
AzureIoTClient 0:e393db310d89 277 /*Codes_SRS_IOTHUBMESSAGE_02_006: [IoTHubMessage_Clone shall clone the content by a call to BUFFER_clone or STRING_clone] */
AzureIoTClient 0:e393db310d89 278 if ((result->value.string = STRING_clone(source->value.string)) == NULL)
AzureIoTClient 0:e393db310d89 279 {
AzureIoTClient 0:e393db310d89 280 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 18:1e9adb15c645 281 if (result->messageId)
AzureIoTClient 18:1e9adb15c645 282 {
AzureIoTClient 18:1e9adb15c645 283 free(result->messageId);
AzureIoTClient 18:1e9adb15c645 284 result->messageId = NULL;
AzureIoTClient 18:1e9adb15c645 285 }
AzureIoTClient 18:1e9adb15c645 286 if (result->correlationId != NULL)
AzureIoTClient 18:1e9adb15c645 287 {
AzureIoTClient 18:1e9adb15c645 288 free(result->correlationId);
AzureIoTClient 18:1e9adb15c645 289 result->correlationId = NULL;
AzureIoTClient 18:1e9adb15c645 290 }
AzureIoTClient 0:e393db310d89 291 free(result);
AzureIoTClient 0:e393db310d89 292 result = NULL;
AzureIoTClient 39:2719651a5bee 293 LogError("failed to STRING_clone");
AzureIoTClient 0:e393db310d89 294 }
AzureIoTClient 0:e393db310d89 295 /*Codes_SRS_IOTHUBMESSAGE_02_005: [IoTHubMessage_Clone shall clone the properties map by using Map_Clone.] */
AzureIoTClient 0:e393db310d89 296 else if ((result->properties = Map_Clone(source->properties)) == NULL)
AzureIoTClient 0:e393db310d89 297 {
AzureIoTClient 0:e393db310d89 298 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 39:2719651a5bee 299 LogError("unable to Map_Clone");
AzureIoTClient 0:e393db310d89 300 STRING_delete(result->value.string);
AzureIoTClient 18:1e9adb15c645 301 if (result->messageId)
AzureIoTClient 18:1e9adb15c645 302 {
AzureIoTClient 18:1e9adb15c645 303 free(result->messageId);
AzureIoTClient 18:1e9adb15c645 304 result->messageId = NULL;
AzureIoTClient 18:1e9adb15c645 305 }
AzureIoTClient 18:1e9adb15c645 306 if (result->correlationId != NULL)
AzureIoTClient 18:1e9adb15c645 307 {
AzureIoTClient 18:1e9adb15c645 308 free(result->correlationId);
AzureIoTClient 18:1e9adb15c645 309 result->correlationId = NULL;
AzureIoTClient 18:1e9adb15c645 310 }
AzureIoTClient 0:e393db310d89 311 free(result);
AzureIoTClient 0:e393db310d89 312 result = NULL;
AzureIoTClient 0:e393db310d89 313 }
AzureIoTClient 0:e393db310d89 314 else
AzureIoTClient 0:e393db310d89 315 {
AzureIoTClient 0:e393db310d89 316 result->contentType = IOTHUBMESSAGE_STRING;
AzureIoTClient 0:e393db310d89 317 /*all is fine*/
AzureIoTClient 0:e393db310d89 318 }
AzureIoTClient 0:e393db310d89 319 }
AzureIoTClient 0:e393db310d89 320 }
AzureIoTClient 0:e393db310d89 321 }
AzureIoTClient 0:e393db310d89 322 return result;
AzureIoTClient 0:e393db310d89 323 }
AzureIoTClient 0:e393db310d89 324
AzureIoTClient 0:e393db310d89 325 IOTHUB_MESSAGE_RESULT IoTHubMessage_GetByteArray(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const unsigned char** buffer, size_t* size)
AzureIoTClient 0:e393db310d89 326 {
AzureIoTClient 0:e393db310d89 327 IOTHUB_MESSAGE_RESULT result;
AzureIoTClient 0:e393db310d89 328 if (
AzureIoTClient 0:e393db310d89 329 (iotHubMessageHandle == NULL) ||
AzureIoTClient 0:e393db310d89 330 (buffer == NULL) ||
AzureIoTClient 0:e393db310d89 331 (size == NULL)
AzureIoTClient 0:e393db310d89 332 )
AzureIoTClient 0:e393db310d89 333 {
AzureIoTClient 0:e393db310d89 334 /*Codes_SRS_IOTHUBMESSAGE_01_014: [If any of the arguments passed to IoTHubMessage_GetByteArray is NULL IoTHubMessage_GetByteArray shall return IOTHUBMESSAGE_INVALID_ARG.] */
AzureIoTClient 39:2719651a5bee 335 LogError("invalid parameter (NULL) to IoTHubMessage_GetByteArray IOTHUB_MESSAGE_HANDLE iotHubMessageHandle=%p, const unsigned char** buffer=%p, size_t* size=%p", iotHubMessageHandle, buffer, size);
AzureIoTClient 0:e393db310d89 336 result = IOTHUB_MESSAGE_INVALID_ARG;
AzureIoTClient 0:e393db310d89 337 }
AzureIoTClient 0:e393db310d89 338 else
AzureIoTClient 0:e393db310d89 339 {
AzureIoTClient 0:e393db310d89 340 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 341 if (handleData->contentType != IOTHUBMESSAGE_BYTEARRAY)
AzureIoTClient 0:e393db310d89 342 {
AzureIoTClient 0:e393db310d89 343 /*Codes_SRS_IOTHUBMESSAGE_02_021: [If iotHubMessageHandle is not a iothubmessage containing BYTEARRAY data, then IoTHubMessage_GetData shall write in *buffer NULL and shall set *size to 0.] */
AzureIoTClient 0:e393db310d89 344 result = IOTHUB_MESSAGE_INVALID_ARG;
AzureIoTClient 39:2719651a5bee 345 LogError("invalid type of message %s", ENUM_TO_STRING(IOTHUBMESSAGE_CONTENT_TYPE, handleData->contentType));
AzureIoTClient 0:e393db310d89 346 }
AzureIoTClient 0:e393db310d89 347 else
AzureIoTClient 0:e393db310d89 348 {
AzureIoTClient 0:e393db310d89 349 /*Codes_SRS_IOTHUBMESSAGE_01_011: [The pointer shall be obtained by using BUFFER_u_char and it shall be copied in the buffer argument.]*/
AzureIoTClient 0:e393db310d89 350 *buffer = BUFFER_u_char(handleData->value.byteArray);
AzureIoTClient 0:e393db310d89 351 /*Codes_SRS_IOTHUBMESSAGE_01_012: [The size of the associated data shall be obtained by using BUFFER_length and it shall be copied to the size argument.]*/
AzureIoTClient 0:e393db310d89 352 *size = BUFFER_length(handleData->value.byteArray);
AzureIoTClient 0:e393db310d89 353 result = IOTHUB_MESSAGE_OK;
AzureIoTClient 0:e393db310d89 354 }
AzureIoTClient 0:e393db310d89 355 }
AzureIoTClient 0:e393db310d89 356 return result;
AzureIoTClient 0:e393db310d89 357 }
AzureIoTClient 0:e393db310d89 358
AzureIoTClient 0:e393db310d89 359 const char* IoTHubMessage_GetString(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 0:e393db310d89 360 {
AzureIoTClient 0:e393db310d89 361 const char* result;
AzureIoTClient 0:e393db310d89 362 if (iotHubMessageHandle == NULL)
AzureIoTClient 0:e393db310d89 363 {
AzureIoTClient 0:e393db310d89 364 /*Codes_SRS_IOTHUBMESSAGE_02_016: [If any parameter is NULL then IoTHubMessage_GetString shall return NULL.] */
AzureIoTClient 0:e393db310d89 365 result = NULL;
AzureIoTClient 0:e393db310d89 366 }
AzureIoTClient 0:e393db310d89 367 else
AzureIoTClient 0:e393db310d89 368 {
AzureIoTClient 0:e393db310d89 369 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 370 if (handleData->contentType != IOTHUBMESSAGE_STRING)
AzureIoTClient 0:e393db310d89 371 {
AzureIoTClient 0:e393db310d89 372 /*Codes_SRS_IOTHUBMESSAGE_02_017: [IoTHubMessage_GetString shall return NULL if the iotHubMessageHandle does not refer to a IOTHUBMESSAGE of type STRING.] */
AzureIoTClient 0:e393db310d89 373 result = NULL;
AzureIoTClient 0:e393db310d89 374 }
AzureIoTClient 0:e393db310d89 375 else
AzureIoTClient 0:e393db310d89 376 {
AzureIoTClient 0:e393db310d89 377 /*Codes_SRS_IOTHUBMESSAGE_02_018: [IoTHubMessage_GetStringData shall return the currently stored null terminated string.] */
AzureIoTClient 0:e393db310d89 378 result = STRING_c_str(handleData->value.string);
AzureIoTClient 0:e393db310d89 379 }
AzureIoTClient 0:e393db310d89 380 }
AzureIoTClient 0:e393db310d89 381 return result;
AzureIoTClient 0:e393db310d89 382 }
AzureIoTClient 0:e393db310d89 383
AzureIoTClient 0:e393db310d89 384 IOTHUBMESSAGE_CONTENT_TYPE IoTHubMessage_GetContentType(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 0:e393db310d89 385 {
AzureIoTClient 0:e393db310d89 386 IOTHUBMESSAGE_CONTENT_TYPE result;
AzureIoTClient 0:e393db310d89 387 /*Codes_SRS_IOTHUBMESSAGE_02_008: [If any parameter is NULL then IoTHubMessage_GetContentType shall return IOTHUBMESSAGE_UNKNOWN.] */
AzureIoTClient 0:e393db310d89 388 if (iotHubMessageHandle == NULL)
AzureIoTClient 0:e393db310d89 389 {
AzureIoTClient 0:e393db310d89 390 result = IOTHUBMESSAGE_UNKNOWN;
AzureIoTClient 0:e393db310d89 391 }
AzureIoTClient 0:e393db310d89 392 else
AzureIoTClient 0:e393db310d89 393 {
AzureIoTClient 0:e393db310d89 394 /*Codes_SRS_IOTHUBMESSAGE_02_009: [Otherwise IoTHubMessage_GetContentType shall return the type of the message.] */
AzureIoTClient 0:e393db310d89 395 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 396 result = handleData->contentType;
AzureIoTClient 0:e393db310d89 397 }
AzureIoTClient 0:e393db310d89 398 return result;
AzureIoTClient 0:e393db310d89 399 }
AzureIoTClient 0:e393db310d89 400
AzureIoTClient 0:e393db310d89 401 MAP_HANDLE IoTHubMessage_Properties(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 0:e393db310d89 402 {
AzureIoTClient 0:e393db310d89 403 MAP_HANDLE result;
AzureIoTClient 0:e393db310d89 404 /*Codes_SRS_IOTHUBMESSAGE_02_001: [If iotHubMessageHandle is NULL then IoTHubMessage_Properties shall return NULL.]*/
AzureIoTClient 0:e393db310d89 405 if (iotHubMessageHandle == NULL)
AzureIoTClient 0:e393db310d89 406 {
AzureIoTClient 39:2719651a5bee 407 LogError("invalid arg (NULL) passed to IoTHubMessage_Properties");
AzureIoTClient 18:1e9adb15c645 408 result = NULL;
AzureIoTClient 0:e393db310d89 409 }
AzureIoTClient 0:e393db310d89 410 else
AzureIoTClient 0:e393db310d89 411 {
AzureIoTClient 0:e393db310d89 412 /*Codes_SRS_IOTHUBMESSAGE_02_002: [Otherwise, for any non-NULL iotHubMessageHandle it shall return a non-NULL MAP_HANDLE.]*/
AzureIoTClient 0:e393db310d89 413 IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 414 result = handleData->properties;
AzureIoTClient 0:e393db310d89 415 }
AzureIoTClient 0:e393db310d89 416 return result;
AzureIoTClient 0:e393db310d89 417 }
AzureIoTClient 0:e393db310d89 418
AzureIoTClient 18:1e9adb15c645 419 const char* IoTHubMessage_GetCorrelationId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 18:1e9adb15c645 420 {
AzureIoTClient 18:1e9adb15c645 421 const char* result;
AzureIoTClient 18:1e9adb15c645 422 /* Codes_SRS_IOTHUBMESSAGE_07_016: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetCorrelationId shall return a NULL value.] */
AzureIoTClient 18:1e9adb15c645 423 if (iotHubMessageHandle == NULL)
AzureIoTClient 18:1e9adb15c645 424 {
AzureIoTClient 39:2719651a5bee 425 LogError("invalid arg (NULL) passed to IoTHubMessage_GetCorrelationId");
AzureIoTClient 18:1e9adb15c645 426 result = NULL;
AzureIoTClient 18:1e9adb15c645 427 }
AzureIoTClient 18:1e9adb15c645 428 else
AzureIoTClient 18:1e9adb15c645 429 {
AzureIoTClient 18:1e9adb15c645 430 /* Codes_SRS_IOTHUBMESSAGE_07_017: [IoTHubMessage_GetCorrelationId shall return the correlationId as a const char*.] */
AzureIoTClient 18:1e9adb15c645 431 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 18:1e9adb15c645 432 result = handleData->correlationId;
AzureIoTClient 18:1e9adb15c645 433 }
AzureIoTClient 18:1e9adb15c645 434 return result;
AzureIoTClient 18:1e9adb15c645 435 }
AzureIoTClient 18:1e9adb15c645 436
AzureIoTClient 18:1e9adb15c645 437 IOTHUB_MESSAGE_RESULT IoTHubMessage_SetCorrelationId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* correlationId)
AzureIoTClient 18:1e9adb15c645 438 {
AzureIoTClient 18:1e9adb15c645 439 IOTHUB_MESSAGE_RESULT result;
AzureIoTClient 18:1e9adb15c645 440 /* Codes_SRS_IOTHUBMESSAGE_07_018: [if any of the parameters are NULL then IoTHubMessage_SetCorrelationId shall return a IOTHUB_MESSAGE_INVALID_ARG value.]*/
AzureIoTClient 18:1e9adb15c645 441 if (iotHubMessageHandle == NULL || correlationId == NULL)
AzureIoTClient 18:1e9adb15c645 442 {
AzureIoTClient 39:2719651a5bee 443 LogError("invalid arg (NULL) passed to IoTHubMessage_SetCorrelationId");
AzureIoTClient 18:1e9adb15c645 444 result = IOTHUB_MESSAGE_INVALID_ARG;
AzureIoTClient 18:1e9adb15c645 445 }
AzureIoTClient 18:1e9adb15c645 446 else
AzureIoTClient 18:1e9adb15c645 447 {
AzureIoTClient 18:1e9adb15c645 448 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 18:1e9adb15c645 449 /* Codes_SRS_IOTHUBMESSAGE_07_019: [If the IOTHUB_MESSAGE_HANDLE correlationId is not NULL, then the IOTHUB_MESSAGE_HANDLE correlationId will be deallocated.] */
AzureIoTClient 18:1e9adb15c645 450 if (handleData->correlationId != NULL)
AzureIoTClient 18:1e9adb15c645 451 {
AzureIoTClient 18:1e9adb15c645 452 free(handleData->correlationId);
AzureIoTClient 18:1e9adb15c645 453 }
AzureIoTClient 18:1e9adb15c645 454
AzureIoTClient 18:1e9adb15c645 455 if (mallocAndStrcpy_s(&handleData->correlationId, correlationId) != 0)
AzureIoTClient 18:1e9adb15c645 456 {
AzureIoTClient 18:1e9adb15c645 457 /* Codes_SRS_IOTHUBMESSAGE_07_020: [If the allocation or the copying of the correlationId fails, then IoTHubMessage_SetCorrelationId shall return IOTHUB_MESSAGE_ERROR.] */
AzureIoTClient 18:1e9adb15c645 458 result = IOTHUB_MESSAGE_ERROR;
AzureIoTClient 18:1e9adb15c645 459 }
AzureIoTClient 18:1e9adb15c645 460 else
AzureIoTClient 18:1e9adb15c645 461 {
AzureIoTClient 18:1e9adb15c645 462 /* Codes_SRS_IOTHUBMESSAGE_07_021: [IoTHubMessage_SetCorrelationId finishes successfully it shall return IOTHUB_MESSAGE_OK.] */
AzureIoTClient 18:1e9adb15c645 463 result = IOTHUB_MESSAGE_OK;
AzureIoTClient 18:1e9adb15c645 464 }
AzureIoTClient 18:1e9adb15c645 465 }
AzureIoTClient 18:1e9adb15c645 466 return result;
AzureIoTClient 18:1e9adb15c645 467 }
AzureIoTClient 18:1e9adb15c645 468
AzureIoTClient 18:1e9adb15c645 469 IOTHUB_MESSAGE_RESULT IoTHubMessage_SetMessageId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* messageId)
AzureIoTClient 18:1e9adb15c645 470 {
AzureIoTClient 18:1e9adb15c645 471 IOTHUB_MESSAGE_RESULT result;
AzureIoTClient 18:1e9adb15c645 472 /* Codes_SRS_IOTHUBMESSAGE_07_012: [if any of the parameters are NULL then IoTHubMessage_SetMessageId shall return a IOTHUB_MESSAGE_INVALID_ARG value.] */
AzureIoTClient 18:1e9adb15c645 473 if (iotHubMessageHandle == NULL || messageId == NULL)
AzureIoTClient 18:1e9adb15c645 474 {
AzureIoTClient 39:2719651a5bee 475 LogError("invalid arg (NULL) passed to IoTHubMessage_SetMessageId");
AzureIoTClient 18:1e9adb15c645 476 result = IOTHUB_MESSAGE_INVALID_ARG;
AzureIoTClient 18:1e9adb15c645 477 }
AzureIoTClient 18:1e9adb15c645 478 else
AzureIoTClient 18:1e9adb15c645 479 {
AzureIoTClient 18:1e9adb15c645 480 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 18:1e9adb15c645 481 /* Codes_SRS_IOTHUBMESSAGE_07_013: [If the IOTHUB_MESSAGE_HANDLE messageId is not NULL, then the IOTHUB_MESSAGE_HANDLE messageId will be freed] */
AzureIoTClient 18:1e9adb15c645 482 if (handleData->messageId != NULL)
AzureIoTClient 18:1e9adb15c645 483 {
AzureIoTClient 18:1e9adb15c645 484 free(handleData->messageId);
AzureIoTClient 18:1e9adb15c645 485 }
AzureIoTClient 18:1e9adb15c645 486
AzureIoTClient 18:1e9adb15c645 487 /* Codes_SRS_IOTHUBMESSAGE_07_014: [If the allocation or the copying of the messageId fails, then IoTHubMessage_SetMessageId shall return IOTHUB_MESSAGE_ERROR.] */
AzureIoTClient 18:1e9adb15c645 488 if (mallocAndStrcpy_s(&handleData->messageId, messageId) != 0)
AzureIoTClient 18:1e9adb15c645 489 {
AzureIoTClient 18:1e9adb15c645 490 result = IOTHUB_MESSAGE_ERROR;
AzureIoTClient 18:1e9adb15c645 491 }
AzureIoTClient 18:1e9adb15c645 492 else
AzureIoTClient 18:1e9adb15c645 493 {
AzureIoTClient 18:1e9adb15c645 494 result = IOTHUB_MESSAGE_OK;
AzureIoTClient 18:1e9adb15c645 495 }
AzureIoTClient 18:1e9adb15c645 496 }
AzureIoTClient 18:1e9adb15c645 497 return result;
AzureIoTClient 18:1e9adb15c645 498 }
AzureIoTClient 18:1e9adb15c645 499
AzureIoTClient 18:1e9adb15c645 500 const char* IoTHubMessage_GetMessageId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 18:1e9adb15c645 501 {
AzureIoTClient 18:1e9adb15c645 502 const char* result;
AzureIoTClient 18:1e9adb15c645 503 /* Codes_SRS_IOTHUBMESSAGE_07_010: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_MessageId shall return a NULL value.] */
AzureIoTClient 18:1e9adb15c645 504 if (iotHubMessageHandle == NULL)
AzureIoTClient 18:1e9adb15c645 505 {
AzureIoTClient 39:2719651a5bee 506 LogError("invalid arg (NULL) passed to IoTHubMessage_GetMessageId");
AzureIoTClient 18:1e9adb15c645 507 result = NULL;
AzureIoTClient 18:1e9adb15c645 508 }
AzureIoTClient 18:1e9adb15c645 509 else
AzureIoTClient 18:1e9adb15c645 510 {
AzureIoTClient 18:1e9adb15c645 511 /* Codes_SRS_IOTHUBMESSAGE_07_011: [IoTHubMessage_MessageId shall return the messageId as a const char*.] */
AzureIoTClient 18:1e9adb15c645 512 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 18:1e9adb15c645 513 result = handleData->messageId;
AzureIoTClient 18:1e9adb15c645 514 }
AzureIoTClient 18:1e9adb15c645 515 return result;
AzureIoTClient 18:1e9adb15c645 516 }
AzureIoTClient 18:1e9adb15c645 517
AzureIoTClient 0:e393db310d89 518 void IoTHubMessage_Destroy(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 0:e393db310d89 519 {
AzureIoTClient 0:e393db310d89 520 /*Codes_SRS_IOTHUBMESSAGE_01_004: [If iotHubMessageHandle is NULL, IoTHubMessage_Destroy shall do nothing.] */
AzureIoTClient 0:e393db310d89 521 if (iotHubMessageHandle != NULL)
AzureIoTClient 0:e393db310d89 522 {
AzureIoTClient 0:e393db310d89 523 /*Codes_SRS_IOTHUBMESSAGE_01_003: [IoTHubMessage_Destroy shall free all resources associated with iotHubMessageHandle.] */
AzureIoTClient 0:e393db310d89 524 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 525 if (handleData->contentType == IOTHUBMESSAGE_BYTEARRAY)
AzureIoTClient 0:e393db310d89 526 {
AzureIoTClient 0:e393db310d89 527 BUFFER_delete(handleData->value.byteArray);
AzureIoTClient 0:e393db310d89 528 }
AzureIoTClient 61:8b85a4e797cf 529 else if (handleData->contentType == IOTHUBMESSAGE_STRING)
AzureIoTClient 61:8b85a4e797cf 530 {
AzureIoTClient 61:8b85a4e797cf 531 STRING_delete(handleData->value.string);
AzureIoTClient 61:8b85a4e797cf 532 }
AzureIoTClient 0:e393db310d89 533 else
AzureIoTClient 0:e393db310d89 534 {
AzureIoTClient 61:8b85a4e797cf 535 LogError("Unknown contentType in IoTHubMessage");
AzureIoTClient 0:e393db310d89 536 }
AzureIoTClient 0:e393db310d89 537 Map_Destroy(handleData->properties);
AzureIoTClient 18:1e9adb15c645 538 free(handleData->messageId);
AzureIoTClient 18:1e9adb15c645 539 handleData->messageId = NULL;
AzureIoTClient 18:1e9adb15c645 540 free(handleData->correlationId);
AzureIoTClient 18:1e9adb15c645 541 handleData->correlationId = NULL;
AzureIoTClient 0:e393db310d89 542 free(handleData);
AzureIoTClient 0:e393db310d89 543 }
AzureIoTClient 53:1e5a1ca1f274 544 }