corrected version (with typedef struct IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE;) included in the sources

Dependents:   STM32F746_iothub_client_sample_mqtt

Fork of iothub_client by Azure IoT

Committer:
AzureIoTClient
Date:
Tue Sep 15 21:47:12 2015 -0700
Revision:
0:e393db310d89
Child:
18:1e9adb15c645
Automatic build commit

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 0:e393db310d89 5 #ifdef _CRTDBG_MAP_ALLOC
AzureIoTClient 0:e393db310d89 6 #include <crtdbg.h>
AzureIoTClient 0:e393db310d89 7 #endif
AzureIoTClient 0:e393db310d89 8 #include "gballoc.h"
AzureIoTClient 0:e393db310d89 9
AzureIoTClient 0:e393db310d89 10 #include "iothub_message.h"
AzureIoTClient 0:e393db310d89 11 #include "iot_logging.h"
AzureIoTClient 0:e393db310d89 12 #include "buffer_.h"
AzureIoTClient 0:e393db310d89 13
AzureIoTClient 0:e393db310d89 14 DEFINE_ENUM_STRINGS(IOTHUB_MESSAGE_RESULT, IOTHUB_MESSAGE_RESULT_VALUES);
AzureIoTClient 0:e393db310d89 15 DEFINE_ENUM_STRINGS(IOTHUBMESSAGE_CONTENT_TYPE, IOTHUBMESSAGE_CONTENT_TYPE_VALUES);
AzureIoTClient 0:e393db310d89 16
AzureIoTClient 0:e393db310d89 17 #define LOG_IOTHUB_MESSAGE_ERROR() \
AzureIoTClient 0:e393db310d89 18 LogError("(result = %s)\r\n", ENUM_TO_STRING(IOTHUB_MESSAGE_RESULT, result));
AzureIoTClient 0:e393db310d89 19
AzureIoTClient 0:e393db310d89 20 typedef struct IOTHUB_MESSAGE_HANDLE_DATA_TAG
AzureIoTClient 0:e393db310d89 21 {
AzureIoTClient 0:e393db310d89 22 IOTHUBMESSAGE_CONTENT_TYPE contentType;
AzureIoTClient 0:e393db310d89 23 union
AzureIoTClient 0:e393db310d89 24 {
AzureIoTClient 0:e393db310d89 25 BUFFER_HANDLE byteArray;
AzureIoTClient 0:e393db310d89 26 STRING_HANDLE string;
AzureIoTClient 0:e393db310d89 27 } value;
AzureIoTClient 0:e393db310d89 28 MAP_HANDLE properties;
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 0:e393db310d89 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 0:e393db310d89 54 result = __LINE__;
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 0:e393db310d89 66 result = malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA));
AzureIoTClient 0:e393db310d89 67 if (result == NULL)
AzureIoTClient 0:e393db310d89 68 {
AzureIoTClient 0:e393db310d89 69 LogError("unable to malloc\r\n");
AzureIoTClient 0:e393db310d89 70 /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */
AzureIoTClient 0:e393db310d89 71 /*let it go through*/
AzureIoTClient 0:e393db310d89 72 }
AzureIoTClient 0:e393db310d89 73 else
AzureIoTClient 0:e393db310d89 74 {
AzureIoTClient 0:e393db310d89 75 const unsigned char* source;
AzureIoTClient 0:e393db310d89 76 unsigned char temp = 0x00;
AzureIoTClient 0:e393db310d89 77 if (size != 0)
AzureIoTClient 0:e393db310d89 78 {
AzureIoTClient 0:e393db310d89 79 /*Codes_SRS_IOTHUBMESSAGE_06_002: [If size is NOT zero then byteArray MUST NOT be NULL*/
AzureIoTClient 0:e393db310d89 80 if (byteArray == NULL)
AzureIoTClient 0:e393db310d89 81 {
AzureIoTClient 0:e393db310d89 82 LogError("Attempted to create a Hub Message from a NULL pointer!\r\n");
AzureIoTClient 0:e393db310d89 83 free(result);
AzureIoTClient 0:e393db310d89 84 result = NULL;
AzureIoTClient 0:e393db310d89 85 source = NULL;
AzureIoTClient 0:e393db310d89 86 }
AzureIoTClient 0:e393db310d89 87 else
AzureIoTClient 0:e393db310d89 88 {
AzureIoTClient 0:e393db310d89 89 source = byteArray;
AzureIoTClient 0:e393db310d89 90 }
AzureIoTClient 0:e393db310d89 91 }
AzureIoTClient 0:e393db310d89 92 else
AzureIoTClient 0:e393db310d89 93 {
AzureIoTClient 0:e393db310d89 94 /*Codes_SRS_IOTHUBMESSAGE_06_001: [If size is zero then byteArray may be NULL.]*/
AzureIoTClient 0:e393db310d89 95 source = &temp;
AzureIoTClient 0:e393db310d89 96 }
AzureIoTClient 0:e393db310d89 97 if (result != NULL)
AzureIoTClient 0:e393db310d89 98 {
AzureIoTClient 0:e393db310d89 99 /*Codes_SRS_IOTHUBMESSAGE_02_022: [IoTHubMessage_CreateFromByteArray shall call BUFFER_create passing byteArray and size as parameters.] */
AzureIoTClient 0:e393db310d89 100 if ((result->value.byteArray = BUFFER_create(source, size)) == NULL)
AzureIoTClient 0:e393db310d89 101 {
AzureIoTClient 0:e393db310d89 102 LogError("BUFFER_create failed\r\n");
AzureIoTClient 0:e393db310d89 103 /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */
AzureIoTClient 0:e393db310d89 104 free(result);
AzureIoTClient 0:e393db310d89 105 result = NULL;
AzureIoTClient 0:e393db310d89 106 }
AzureIoTClient 0:e393db310d89 107 /*Codes_SRS_IOTHUBMESSAGE_02_023: [IoTHubMessage_CreateFromByteArray shall call Map_Create to create the message properties.] */
AzureIoTClient 0:e393db310d89 108 else if ((result->properties = Map_Create(ValidateAsciiCharactersFilter)) == NULL)
AzureIoTClient 0:e393db310d89 109 {
AzureIoTClient 0:e393db310d89 110 LogError("Map_Create failed\r\n");
AzureIoTClient 0:e393db310d89 111 /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */
AzureIoTClient 0:e393db310d89 112 BUFFER_delete(result->value.byteArray);
AzureIoTClient 0:e393db310d89 113 free(result);
AzureIoTClient 0:e393db310d89 114 result = NULL;
AzureIoTClient 0:e393db310d89 115 }
AzureIoTClient 0:e393db310d89 116 else
AzureIoTClient 0:e393db310d89 117 {
AzureIoTClient 0:e393db310d89 118 /*Codes_SRS_IOTHUBMESSAGE_02_025: [Otherwise, IoTHubMessage_CreateFromByteArray shall return a non-NULL handle.] */
AzureIoTClient 0:e393db310d89 119 /*Codes_SRS_IOTHUBMESSAGE_02_026: [The type of the new message shall be IOTHUBMESSAGE_BYTEARRAY.] */
AzureIoTClient 0:e393db310d89 120 result->contentType = IOTHUBMESSAGE_BYTEARRAY;
AzureIoTClient 0:e393db310d89 121 /*all is fine, return result*/
AzureIoTClient 0:e393db310d89 122 }
AzureIoTClient 0:e393db310d89 123 }
AzureIoTClient 0:e393db310d89 124 }
AzureIoTClient 0:e393db310d89 125 return result;
AzureIoTClient 0:e393db310d89 126 }
AzureIoTClient 0:e393db310d89 127 IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromString(const char* source)
AzureIoTClient 0:e393db310d89 128 {
AzureIoTClient 0:e393db310d89 129 IOTHUB_MESSAGE_HANDLE_DATA* result;
AzureIoTClient 0:e393db310d89 130 result = malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA));
AzureIoTClient 0:e393db310d89 131 if (result == NULL)
AzureIoTClient 0:e393db310d89 132 {
AzureIoTClient 0:e393db310d89 133 LogError("malloc failed\r\n");
AzureIoTClient 0:e393db310d89 134 /*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 135 /*let it go through*/
AzureIoTClient 0:e393db310d89 136 }
AzureIoTClient 0:e393db310d89 137 else
AzureIoTClient 0:e393db310d89 138 {
AzureIoTClient 0:e393db310d89 139 /*Codes_SRS_IOTHUBMESSAGE_02_027: [IoTHubMessage_CreateFromString shall call STRING_construct passing source as parameter.] */
AzureIoTClient 0:e393db310d89 140 if ((result->value.string = STRING_construct(source)) == NULL)
AzureIoTClient 0:e393db310d89 141 {
AzureIoTClient 0:e393db310d89 142 LogError("STRING_construct failed\r\n");
AzureIoTClient 0:e393db310d89 143 /*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 144 free(result);
AzureIoTClient 0:e393db310d89 145 result = NULL;
AzureIoTClient 0:e393db310d89 146 }
AzureIoTClient 0:e393db310d89 147 /*Codes_SRS_IOTHUBMESSAGE_02_028: [IoTHubMessage_CreateFromString shall call Map_Create to create the message properties.] */
AzureIoTClient 0:e393db310d89 148 else if ((result->properties = Map_Create(ValidateAsciiCharactersFilter)) == NULL)
AzureIoTClient 0:e393db310d89 149 {
AzureIoTClient 0:e393db310d89 150 LogError("Map_Create failed\r\n");
AzureIoTClient 0:e393db310d89 151 /*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 152 STRING_delete(result->value.string);
AzureIoTClient 0:e393db310d89 153 free(result);
AzureIoTClient 0:e393db310d89 154 result = NULL;
AzureIoTClient 0:e393db310d89 155 }
AzureIoTClient 0:e393db310d89 156 else
AzureIoTClient 0:e393db310d89 157 {
AzureIoTClient 0:e393db310d89 158 /*Codes_SRS_IOTHUBMESSAGE_02_031: [Otherwise, IoTHubMessage_CreateFromString shall return a non-NULL handle.] */
AzureIoTClient 0:e393db310d89 159 /*Codes_SRS_IOTHUBMESSAGE_02_032: [The type of the new message shall be IOTHUBMESSAGE_STRING.] */
AzureIoTClient 0:e393db310d89 160 result->contentType = IOTHUBMESSAGE_STRING;
AzureIoTClient 0:e393db310d89 161 }
AzureIoTClient 0:e393db310d89 162 }
AzureIoTClient 0:e393db310d89 163 return result;
AzureIoTClient 0:e393db310d89 164 }
AzureIoTClient 0:e393db310d89 165
AzureIoTClient 0:e393db310d89 166 /*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 167 IOTHUB_MESSAGE_HANDLE IoTHubMessage_Clone(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 0:e393db310d89 168 {
AzureIoTClient 0:e393db310d89 169 IOTHUB_MESSAGE_HANDLE_DATA* result;
AzureIoTClient 0:e393db310d89 170 const IOTHUB_MESSAGE_HANDLE_DATA* source = (const IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 171 /* Codes_SRS_IOTHUBMESSAGE_03_005: [IoTHubMessage_Clone shall return NULL if iotHubMessageHandle is NULL.] */
AzureIoTClient 0:e393db310d89 172 if (source == NULL)
AzureIoTClient 0:e393db310d89 173 {
AzureIoTClient 0:e393db310d89 174 result = NULL;
AzureIoTClient 0:e393db310d89 175 LogError("iotHubMessageHandle parameter cannot be NULL for IoTHubMessage_Clone\r\n");
AzureIoTClient 0:e393db310d89 176 }
AzureIoTClient 0:e393db310d89 177 else
AzureIoTClient 0:e393db310d89 178 {
AzureIoTClient 0:e393db310d89 179 result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA));
AzureIoTClient 0:e393db310d89 180 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 0:e393db310d89 181 if (result == NULL)
AzureIoTClient 0:e393db310d89 182 {
AzureIoTClient 0:e393db310d89 183 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 0:e393db310d89 184 /*do nothing and return as is*/
AzureIoTClient 0:e393db310d89 185 LogError("unable to malloc\r\n");
AzureIoTClient 0:e393db310d89 186 }
AzureIoTClient 0:e393db310d89 187 else
AzureIoTClient 0:e393db310d89 188 {
AzureIoTClient 0:e393db310d89 189 if (source->contentType == IOTHUBMESSAGE_BYTEARRAY)
AzureIoTClient 0:e393db310d89 190 {
AzureIoTClient 0:e393db310d89 191 /*Codes_SRS_IOTHUBMESSAGE_02_006: [IoTHubMessage_Clone shall clone to content by a call to BUFFER_clone] */
AzureIoTClient 0:e393db310d89 192 if ((result->value.byteArray = BUFFER_clone(source->value.byteArray)) == NULL)
AzureIoTClient 0:e393db310d89 193 {
AzureIoTClient 0:e393db310d89 194 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 0:e393db310d89 195 LogError("unable to BUFFER_clone\r\n");
AzureIoTClient 0:e393db310d89 196 free(result);
AzureIoTClient 0:e393db310d89 197 result = NULL;
AzureIoTClient 0:e393db310d89 198 }
AzureIoTClient 0:e393db310d89 199 /*Codes_SRS_IOTHUBMESSAGE_02_005: [IoTHubMessage_Clone shall clone the properties map by using Map_Clone.] */
AzureIoTClient 0:e393db310d89 200 else if ((result->properties = Map_Clone(source->properties)) == NULL)
AzureIoTClient 0:e393db310d89 201 {
AzureIoTClient 0:e393db310d89 202 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 0:e393db310d89 203 LogError("unable to Map_Clone\r\n");
AzureIoTClient 0:e393db310d89 204 BUFFER_delete(result->value.byteArray);
AzureIoTClient 0:e393db310d89 205 free(result);
AzureIoTClient 0:e393db310d89 206 result = NULL;
AzureIoTClient 0:e393db310d89 207 }
AzureIoTClient 0:e393db310d89 208 else
AzureIoTClient 0:e393db310d89 209 {
AzureIoTClient 0:e393db310d89 210 result->contentType = IOTHUBMESSAGE_BYTEARRAY;
AzureIoTClient 0:e393db310d89 211 /*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 212 /*return as is, this is a good result*/
AzureIoTClient 0:e393db310d89 213 }
AzureIoTClient 0:e393db310d89 214 }
AzureIoTClient 0:e393db310d89 215 else /*can only be STRING*/
AzureIoTClient 0:e393db310d89 216 {
AzureIoTClient 0:e393db310d89 217 /*Codes_SRS_IOTHUBMESSAGE_02_006: [IoTHubMessage_Clone shall clone the content by a call to BUFFER_clone or STRING_clone] */
AzureIoTClient 0:e393db310d89 218 if ((result->value.string = STRING_clone(source->value.string)) == NULL)
AzureIoTClient 0:e393db310d89 219 {
AzureIoTClient 0:e393db310d89 220 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 0:e393db310d89 221 free(result);
AzureIoTClient 0:e393db310d89 222 result = NULL;
AzureIoTClient 0:e393db310d89 223 LogError("failed to STRING_clone\r\n");
AzureIoTClient 0:e393db310d89 224 }
AzureIoTClient 0:e393db310d89 225 /*Codes_SRS_IOTHUBMESSAGE_02_005: [IoTHubMessage_Clone shall clone the properties map by using Map_Clone.] */
AzureIoTClient 0:e393db310d89 226 else if ((result->properties = Map_Clone(source->properties)) == NULL)
AzureIoTClient 0:e393db310d89 227 {
AzureIoTClient 0:e393db310d89 228 /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
AzureIoTClient 0:e393db310d89 229 LogError("unable to Map_Clone\r\n");
AzureIoTClient 0:e393db310d89 230 STRING_delete(result->value.string);
AzureIoTClient 0:e393db310d89 231 free(result);
AzureIoTClient 0:e393db310d89 232 result = NULL;
AzureIoTClient 0:e393db310d89 233 }
AzureIoTClient 0:e393db310d89 234 else
AzureIoTClient 0:e393db310d89 235 {
AzureIoTClient 0:e393db310d89 236 result->contentType = IOTHUBMESSAGE_STRING;
AzureIoTClient 0:e393db310d89 237 /*all is fine*/
AzureIoTClient 0:e393db310d89 238 }
AzureIoTClient 0:e393db310d89 239 }
AzureIoTClient 0:e393db310d89 240 }
AzureIoTClient 0:e393db310d89 241 }
AzureIoTClient 0:e393db310d89 242 return result;
AzureIoTClient 0:e393db310d89 243 }
AzureIoTClient 0:e393db310d89 244
AzureIoTClient 0:e393db310d89 245 IOTHUB_MESSAGE_RESULT IoTHubMessage_GetByteArray(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const unsigned char** buffer, size_t* size)
AzureIoTClient 0:e393db310d89 246 {
AzureIoTClient 0:e393db310d89 247 IOTHUB_MESSAGE_RESULT result;
AzureIoTClient 0:e393db310d89 248 if (
AzureIoTClient 0:e393db310d89 249 (iotHubMessageHandle == NULL) ||
AzureIoTClient 0:e393db310d89 250 (buffer == NULL) ||
AzureIoTClient 0:e393db310d89 251 (size == NULL)
AzureIoTClient 0:e393db310d89 252 )
AzureIoTClient 0:e393db310d89 253 {
AzureIoTClient 0:e393db310d89 254 /*Codes_SRS_IOTHUBMESSAGE_01_014: [If any of the arguments passed to IoTHubMessage_GetByteArray is NULL IoTHubMessage_GetByteArray shall return IOTHUBMESSAGE_INVALID_ARG.] */
AzureIoTClient 0:e393db310d89 255 LogError("invalid parameter (NULL) to IoTHubMessage_GetByteArray IOTHUB_MESSAGE_HANDLE iotHubMessageHandle=%p, const unsigned char** buffer=%p, size_t* size=%p\r\n", iotHubMessageHandle, buffer, size);
AzureIoTClient 0:e393db310d89 256 result = IOTHUB_MESSAGE_INVALID_ARG;
AzureIoTClient 0:e393db310d89 257 }
AzureIoTClient 0:e393db310d89 258 else
AzureIoTClient 0:e393db310d89 259 {
AzureIoTClient 0:e393db310d89 260 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 261 if (handleData->contentType != IOTHUBMESSAGE_BYTEARRAY)
AzureIoTClient 0:e393db310d89 262 {
AzureIoTClient 0:e393db310d89 263 /*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 264 result = IOTHUB_MESSAGE_INVALID_ARG;
AzureIoTClient 0:e393db310d89 265 LogError("invalid type of message %s\r\n", ENUM_TO_STRING(IOTHUBMESSAGE_CONTENT_TYPE, handleData->contentType));
AzureIoTClient 0:e393db310d89 266 }
AzureIoTClient 0:e393db310d89 267 else
AzureIoTClient 0:e393db310d89 268 {
AzureIoTClient 0:e393db310d89 269 /*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 270 *buffer = BUFFER_u_char(handleData->value.byteArray);
AzureIoTClient 0:e393db310d89 271 /*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 272 *size = BUFFER_length(handleData->value.byteArray);
AzureIoTClient 0:e393db310d89 273 result = IOTHUB_MESSAGE_OK;
AzureIoTClient 0:e393db310d89 274 }
AzureIoTClient 0:e393db310d89 275 }
AzureIoTClient 0:e393db310d89 276 return result;
AzureIoTClient 0:e393db310d89 277 }
AzureIoTClient 0:e393db310d89 278
AzureIoTClient 0:e393db310d89 279 const char* IoTHubMessage_GetString(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 0:e393db310d89 280 {
AzureIoTClient 0:e393db310d89 281 const char* result;
AzureIoTClient 0:e393db310d89 282 if (iotHubMessageHandle == NULL)
AzureIoTClient 0:e393db310d89 283 {
AzureIoTClient 0:e393db310d89 284 /*Codes_SRS_IOTHUBMESSAGE_02_016: [If any parameter is NULL then IoTHubMessage_GetString shall return NULL.] */
AzureIoTClient 0:e393db310d89 285 result = NULL;
AzureIoTClient 0:e393db310d89 286 }
AzureIoTClient 0:e393db310d89 287 else
AzureIoTClient 0:e393db310d89 288 {
AzureIoTClient 0:e393db310d89 289 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 290 if (handleData->contentType != IOTHUBMESSAGE_STRING)
AzureIoTClient 0:e393db310d89 291 {
AzureIoTClient 0:e393db310d89 292 /*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 293 result = NULL;
AzureIoTClient 0:e393db310d89 294 }
AzureIoTClient 0:e393db310d89 295 else
AzureIoTClient 0:e393db310d89 296 {
AzureIoTClient 0:e393db310d89 297 /*Codes_SRS_IOTHUBMESSAGE_02_018: [IoTHubMessage_GetStringData shall return the currently stored null terminated string.] */
AzureIoTClient 0:e393db310d89 298 result = STRING_c_str(handleData->value.string);
AzureIoTClient 0:e393db310d89 299 }
AzureIoTClient 0:e393db310d89 300 }
AzureIoTClient 0:e393db310d89 301 return result;
AzureIoTClient 0:e393db310d89 302 }
AzureIoTClient 0:e393db310d89 303
AzureIoTClient 0:e393db310d89 304 IOTHUBMESSAGE_CONTENT_TYPE IoTHubMessage_GetContentType(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 0:e393db310d89 305 {
AzureIoTClient 0:e393db310d89 306 IOTHUBMESSAGE_CONTENT_TYPE result;
AzureIoTClient 0:e393db310d89 307 /*Codes_SRS_IOTHUBMESSAGE_02_008: [If any parameter is NULL then IoTHubMessage_GetContentType shall return IOTHUBMESSAGE_UNKNOWN.] */
AzureIoTClient 0:e393db310d89 308 if (iotHubMessageHandle == NULL)
AzureIoTClient 0:e393db310d89 309 {
AzureIoTClient 0:e393db310d89 310 result = IOTHUBMESSAGE_UNKNOWN;
AzureIoTClient 0:e393db310d89 311 }
AzureIoTClient 0:e393db310d89 312 else
AzureIoTClient 0:e393db310d89 313 {
AzureIoTClient 0:e393db310d89 314 /*Codes_SRS_IOTHUBMESSAGE_02_009: [Otherwise IoTHubMessage_GetContentType shall return the type of the message.] */
AzureIoTClient 0:e393db310d89 315 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 316 result = handleData->contentType;
AzureIoTClient 0:e393db310d89 317 }
AzureIoTClient 0:e393db310d89 318 return result;
AzureIoTClient 0:e393db310d89 319 }
AzureIoTClient 0:e393db310d89 320
AzureIoTClient 0:e393db310d89 321 MAP_HANDLE IoTHubMessage_Properties(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 0:e393db310d89 322 {
AzureIoTClient 0:e393db310d89 323 MAP_HANDLE result;
AzureIoTClient 0:e393db310d89 324 /*Codes_SRS_IOTHUBMESSAGE_02_001: [If iotHubMessageHandle is NULL then IoTHubMessage_Properties shall return NULL.]*/
AzureIoTClient 0:e393db310d89 325 if (iotHubMessageHandle == NULL)
AzureIoTClient 0:e393db310d89 326 {
AzureIoTClient 0:e393db310d89 327 LogError("invalid arg (NULL) passed to IoTHubMessage_Properties\r\n")
AzureIoTClient 0:e393db310d89 328 result = NULL;
AzureIoTClient 0:e393db310d89 329 }
AzureIoTClient 0:e393db310d89 330 else
AzureIoTClient 0:e393db310d89 331 {
AzureIoTClient 0:e393db310d89 332 /*Codes_SRS_IOTHUBMESSAGE_02_002: [Otherwise, for any non-NULL iotHubMessageHandle it shall return a non-NULL MAP_HANDLE.]*/
AzureIoTClient 0:e393db310d89 333 IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 334 result = handleData->properties;
AzureIoTClient 0:e393db310d89 335 }
AzureIoTClient 0:e393db310d89 336 return result;
AzureIoTClient 0:e393db310d89 337 }
AzureIoTClient 0:e393db310d89 338
AzureIoTClient 0:e393db310d89 339 void IoTHubMessage_Destroy(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
AzureIoTClient 0:e393db310d89 340 {
AzureIoTClient 0:e393db310d89 341 /*Codes_SRS_IOTHUBMESSAGE_01_004: [If iotHubMessageHandle is NULL, IoTHubMessage_Destroy shall do nothing.] */
AzureIoTClient 0:e393db310d89 342 if (iotHubMessageHandle != NULL)
AzureIoTClient 0:e393db310d89 343 {
AzureIoTClient 0:e393db310d89 344 /*Codes_SRS_IOTHUBMESSAGE_01_003: [IoTHubMessage_Destroy shall free all resources associated with iotHubMessageHandle.] */
AzureIoTClient 0:e393db310d89 345 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
AzureIoTClient 0:e393db310d89 346 if (handleData->contentType == IOTHUBMESSAGE_BYTEARRAY)
AzureIoTClient 0:e393db310d89 347 {
AzureIoTClient 0:e393db310d89 348 BUFFER_delete(handleData->value.byteArray);
AzureIoTClient 0:e393db310d89 349 }
AzureIoTClient 0:e393db310d89 350 else
AzureIoTClient 0:e393db310d89 351 {
AzureIoTClient 0:e393db310d89 352 /*can only be STRING*/
AzureIoTClient 0:e393db310d89 353 STRING_delete(handleData->value.string);
AzureIoTClient 0:e393db310d89 354 }
AzureIoTClient 0:e393db310d89 355 Map_Destroy(handleData->properties);
AzureIoTClient 0:e393db310d89 356 free(handleData);
AzureIoTClient 0:e393db310d89 357 }
AzureIoTClient 0:e393db310d89 358 }