1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
3 |
|
---|
4 | #include <stdlib.h>
|
---|
5 | #include "azure_c_shared_utility/optimize_size.h"
|
---|
6 | #include "azure_c_shared_utility/gballoc.h"
|
---|
7 | #include "azure_c_shared_utility/xlogging.h"
|
---|
8 | #include "azure_c_shared_utility/buffer_.h"
|
---|
9 |
|
---|
10 | #include "iothub_message.h"
|
---|
11 |
|
---|
12 | MU_DEFINE_ENUM_STRINGS_WITHOUT_INVALID(IOTHUB_MESSAGE_RESULT, IOTHUB_MESSAGE_RESULT_VALUES);
|
---|
13 | MU_DEFINE_ENUM_STRINGS_WITHOUT_INVALID(IOTHUBMESSAGE_CONTENT_TYPE, IOTHUBMESSAGE_CONTENT_TYPE_VALUES);
|
---|
14 |
|
---|
15 | static const char* SECURITY_CLIENT_JSON_ENCODING = "application/json";
|
---|
16 |
|
---|
17 | typedef struct IOTHUB_MESSAGE_HANDLE_DATA_TAG
|
---|
18 | {
|
---|
19 | IOTHUBMESSAGE_CONTENT_TYPE contentType;
|
---|
20 | union
|
---|
21 | {
|
---|
22 | BUFFER_HANDLE byteArray;
|
---|
23 | STRING_HANDLE string;
|
---|
24 | } value;
|
---|
25 | MAP_HANDLE properties;
|
---|
26 | char* messageId;
|
---|
27 | char* correlationId;
|
---|
28 | char* userDefinedContentType;
|
---|
29 | char* contentEncoding;
|
---|
30 | char* outputName;
|
---|
31 | char* inputName;
|
---|
32 | char* connectionModuleId;
|
---|
33 | char* connectionDeviceId;
|
---|
34 | IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE diagnosticData;
|
---|
35 | bool is_security_message;
|
---|
36 | char* creationTimeUtc;
|
---|
37 | char* userId;
|
---|
38 | }IOTHUB_MESSAGE_HANDLE_DATA;
|
---|
39 |
|
---|
40 | static bool ContainsValidUsAscii(const char* asciiValue)
|
---|
41 | {
|
---|
42 | bool result = true;
|
---|
43 | const char* iterator = asciiValue;
|
---|
44 | while (iterator != NULL && *iterator != '\0')
|
---|
45 | {
|
---|
46 | // Union of all allowed ASCII characters for the different protocols (HTTPS, MQTT, AMQP) is [dec 32, dec 126].
|
---|
47 | if (*iterator < ' ' || *iterator > '~')
|
---|
48 | {
|
---|
49 | result = false;
|
---|
50 | break;
|
---|
51 | }
|
---|
52 | iterator++;
|
---|
53 | }
|
---|
54 |
|
---|
55 | return result;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /* Codes_SRS_IOTHUBMESSAGE_07_008: [ValidateAsciiCharactersFilter shall loop through the mapKey and mapValue strings to ensure that they only contain valid US-Ascii characters.*/
|
---|
59 | static int ValidateAsciiCharactersFilter(const char* mapKey, const char* mapValue)
|
---|
60 | {
|
---|
61 | int result;
|
---|
62 | if (!ContainsValidUsAscii(mapKey) || !ContainsValidUsAscii(mapValue))
|
---|
63 | {
|
---|
64 | result = MU_FAILURE;
|
---|
65 | }
|
---|
66 | else
|
---|
67 | {
|
---|
68 | result = 0;
|
---|
69 | }
|
---|
70 | return result;
|
---|
71 | }
|
---|
72 |
|
---|
73 | static void DestroyDiagnosticPropertyData(IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE diagnosticHandle)
|
---|
74 | {
|
---|
75 | if (diagnosticHandle != NULL)
|
---|
76 | {
|
---|
77 | free(diagnosticHandle->diagnosticId);
|
---|
78 | free(diagnosticHandle->diagnosticCreationTimeUtc);
|
---|
79 | }
|
---|
80 | free(diagnosticHandle);
|
---|
81 | }
|
---|
82 |
|
---|
83 | static void DestroyMessageData(IOTHUB_MESSAGE_HANDLE_DATA* handleData)
|
---|
84 | {
|
---|
85 | if (handleData->contentType == IOTHUBMESSAGE_BYTEARRAY)
|
---|
86 | {
|
---|
87 | BUFFER_delete(handleData->value.byteArray);
|
---|
88 | }
|
---|
89 | else if (handleData->contentType == IOTHUBMESSAGE_STRING)
|
---|
90 | {
|
---|
91 | STRING_delete(handleData->value.string);
|
---|
92 | }
|
---|
93 |
|
---|
94 | Map_Destroy(handleData->properties);
|
---|
95 | free(handleData->messageId);
|
---|
96 | handleData->messageId = NULL;
|
---|
97 | free(handleData->correlationId);
|
---|
98 | handleData->correlationId = NULL;
|
---|
99 | free(handleData->userDefinedContentType);
|
---|
100 | free(handleData->contentEncoding);
|
---|
101 | DestroyDiagnosticPropertyData(handleData->diagnosticData);
|
---|
102 | free(handleData->outputName);
|
---|
103 | free(handleData->inputName);
|
---|
104 | free(handleData->connectionModuleId);
|
---|
105 | free(handleData->connectionDeviceId);
|
---|
106 | free(handleData->creationTimeUtc);
|
---|
107 | free(handleData->userId);
|
---|
108 | free(handleData);
|
---|
109 | }
|
---|
110 |
|
---|
111 | static int set_content_encoding(IOTHUB_MESSAGE_HANDLE_DATA* handleData, const char* encoding)
|
---|
112 | {
|
---|
113 | int result;
|
---|
114 | char* tmp_encoding;
|
---|
115 |
|
---|
116 | if (mallocAndStrcpy_s(&tmp_encoding, encoding) != 0)
|
---|
117 | {
|
---|
118 | LogError("Failed saving a copy of contentEncoding");
|
---|
119 | // Codes_SRS_IOTHUBMESSAGE_09_008: [If the allocation or the copying of `contentEncoding` fails, then IoTHubMessage_SetContentEncodingSystemProperty shall return IOTHUB_MESSAGE_ERROR.]
|
---|
120 | result = MU_FAILURE;
|
---|
121 | }
|
---|
122 | else
|
---|
123 | {
|
---|
124 | // Codes_SRS_IOTHUBMESSAGE_09_007: [If the IOTHUB_MESSAGE_HANDLE `contentEncoding` is not NULL it shall be deallocated.]
|
---|
125 | if (handleData->contentEncoding != NULL)
|
---|
126 | {
|
---|
127 | free(handleData->contentEncoding);
|
---|
128 | }
|
---|
129 | handleData->contentEncoding = tmp_encoding;
|
---|
130 | result = 0;
|
---|
131 | }
|
---|
132 | return result;
|
---|
133 | }
|
---|
134 |
|
---|
135 | static int set_message_creation_time(IOTHUB_MESSAGE_HANDLE_DATA* handleData, const char* messageCreationTimeUtc)
|
---|
136 | {
|
---|
137 | int result;
|
---|
138 | char* tmp_message_creation_time;
|
---|
139 |
|
---|
140 | if (handleData->creationTimeUtc != NULL)
|
---|
141 | {
|
---|
142 | free(handleData->creationTimeUtc);
|
---|
143 | handleData->creationTimeUtc = NULL;
|
---|
144 | }
|
---|
145 |
|
---|
146 | if (mallocAndStrcpy_s(&tmp_message_creation_time, messageCreationTimeUtc) != 0)
|
---|
147 | {
|
---|
148 | LogError("Failed saving a copy of messageCreationTimeUtc");
|
---|
149 | result = MU_FAILURE;
|
---|
150 | }
|
---|
151 | else
|
---|
152 | {
|
---|
153 | handleData->creationTimeUtc = tmp_message_creation_time;
|
---|
154 | result = 0;
|
---|
155 | }
|
---|
156 | return result;
|
---|
157 | }
|
---|
158 |
|
---|
159 | static int set_message_user_id(IOTHUB_MESSAGE_HANDLE_DATA* handleData, const char* userId)
|
---|
160 | {
|
---|
161 | int result;
|
---|
162 | char* tmp_message_user_id;
|
---|
163 |
|
---|
164 | if (handleData->userId != NULL)
|
---|
165 | {
|
---|
166 | free(handleData->userId);
|
---|
167 | handleData->userId = NULL;
|
---|
168 | }
|
---|
169 |
|
---|
170 | if (mallocAndStrcpy_s(&tmp_message_user_id, userId) != 0)
|
---|
171 | {
|
---|
172 | LogError("Failed saving a copy of userId");
|
---|
173 | result = MU_FAILURE;
|
---|
174 | }
|
---|
175 | else
|
---|
176 | {
|
---|
177 | handleData->userId = tmp_message_user_id;
|
---|
178 | result = 0;
|
---|
179 | }
|
---|
180 | return result;
|
---|
181 | }
|
---|
182 |
|
---|
183 | static IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE CloneDiagnosticPropertyData(const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* source)
|
---|
184 | {
|
---|
185 | IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE result = NULL;
|
---|
186 | if (source == NULL)
|
---|
187 | {
|
---|
188 | LogError("Invalid argument - source is NULL");
|
---|
189 | }
|
---|
190 | else
|
---|
191 | {
|
---|
192 | result = (IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE)malloc(sizeof(IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA));
|
---|
193 | if (result == NULL)
|
---|
194 | {
|
---|
195 | LogError("malloc failed");
|
---|
196 | }
|
---|
197 | else
|
---|
198 | {
|
---|
199 | result->diagnosticCreationTimeUtc = NULL;
|
---|
200 | result->diagnosticId = NULL;
|
---|
201 | if (source->diagnosticCreationTimeUtc != NULL && mallocAndStrcpy_s(&result->diagnosticCreationTimeUtc, source->diagnosticCreationTimeUtc) != 0)
|
---|
202 | {
|
---|
203 | LogError("mallocAndStrcpy_s for diagnosticCreationTimeUtc failed");
|
---|
204 | free(result);
|
---|
205 | result = NULL;
|
---|
206 | }
|
---|
207 | else if (source->diagnosticId != NULL && mallocAndStrcpy_s(&result->diagnosticId, source->diagnosticId) != 0)
|
---|
208 | {
|
---|
209 | LogError("mallocAndStrcpy_s for diagnosticId failed");
|
---|
210 | free(result->diagnosticCreationTimeUtc);
|
---|
211 | free(result);
|
---|
212 | result = NULL;
|
---|
213 | }
|
---|
214 | }
|
---|
215 | }
|
---|
216 | return result;
|
---|
217 | }
|
---|
218 |
|
---|
219 | IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromByteArray(const unsigned char* byteArray, size_t size)
|
---|
220 | {
|
---|
221 | IOTHUB_MESSAGE_HANDLE_DATA* result;
|
---|
222 | if ((byteArray == NULL) && (size != 0))
|
---|
223 | {
|
---|
224 | LogError("Invalid argument - byteArray is NULL");
|
---|
225 | result = NULL;
|
---|
226 | }
|
---|
227 | else
|
---|
228 | {
|
---|
229 | result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA));
|
---|
230 | if (result == NULL)
|
---|
231 | {
|
---|
232 | LogError("unable to malloc");
|
---|
233 | /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */
|
---|
234 | /*let it go through*/
|
---|
235 | }
|
---|
236 | else
|
---|
237 | {
|
---|
238 | const unsigned char* source;
|
---|
239 | unsigned char temp = 0x00;
|
---|
240 |
|
---|
241 | memset(result, 0, sizeof(*result));
|
---|
242 | /*Codes_SRS_IOTHUBMESSAGE_02_026: [The type of the new message shall be IOTHUBMESSAGE_BYTEARRAY.] */
|
---|
243 | result->contentType = IOTHUBMESSAGE_BYTEARRAY;
|
---|
244 |
|
---|
245 | if (size != 0)
|
---|
246 | {
|
---|
247 | /*Codes_SRS_IOTHUBMESSAGE_06_002: [If size is NOT zero then byteArray MUST NOT be NULL*/
|
---|
248 | if (byteArray == NULL)
|
---|
249 | {
|
---|
250 | LogError("Attempted to create a Hub Message from a NULL pointer!");
|
---|
251 | DestroyMessageData(result);
|
---|
252 | result = NULL;
|
---|
253 | source = NULL;
|
---|
254 | }
|
---|
255 | else
|
---|
256 | {
|
---|
257 | source = byteArray;
|
---|
258 | }
|
---|
259 | }
|
---|
260 | else
|
---|
261 | {
|
---|
262 | /*Codes_SRS_IOTHUBMESSAGE_06_001: [If size is zero then byteArray may be NULL.]*/
|
---|
263 | source = &temp;
|
---|
264 | }
|
---|
265 | if (result != NULL)
|
---|
266 | {
|
---|
267 | /*Codes_SRS_IOTHUBMESSAGE_02_022: [IoTHubMessage_CreateFromByteArray shall call BUFFER_create passing byteArray and size as parameters.] */
|
---|
268 | if ((result->value.byteArray = BUFFER_create(source, size)) == NULL)
|
---|
269 | {
|
---|
270 | LogError("BUFFER_create failed");
|
---|
271 | /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */
|
---|
272 | DestroyMessageData(result);
|
---|
273 | result = NULL;
|
---|
274 | }
|
---|
275 | /*Codes_SRS_IOTHUBMESSAGE_02_023: [IoTHubMessage_CreateFromByteArray shall call Map_Create to create the message properties.] */
|
---|
276 | else if ((result->properties = Map_Create(ValidateAsciiCharactersFilter)) == NULL)
|
---|
277 | {
|
---|
278 | LogError("Map_Create for properties failed");
|
---|
279 | /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */
|
---|
280 | DestroyMessageData(result);
|
---|
281 | result = NULL;
|
---|
282 | }
|
---|
283 | /*Codes_SRS_IOTHUBMESSAGE_02_025: [Otherwise, IoTHubMessage_CreateFromByteArray shall return a non-NULL handle.] */
|
---|
284 | }
|
---|
285 | }
|
---|
286 | }
|
---|
287 | return result;
|
---|
288 | }
|
---|
289 |
|
---|
290 | IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromString(const char* source)
|
---|
291 | {
|
---|
292 | IOTHUB_MESSAGE_HANDLE_DATA* result;
|
---|
293 | if (source == NULL)
|
---|
294 | {
|
---|
295 | LogError("Invalid argument - source is NULL");
|
---|
296 | result = NULL;
|
---|
297 | }
|
---|
298 | else
|
---|
299 | {
|
---|
300 | result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA));
|
---|
301 | if (result == NULL)
|
---|
302 | {
|
---|
303 | LogError("malloc failed");
|
---|
304 | /*Codes_SRS_IOTHUBMESSAGE_02_029: [If there are any encountered in the execution of IoTHubMessage_CreateFromString then IoTHubMessage_CreateFromString shall return NULL.] */
|
---|
305 | /*let it go through*/
|
---|
306 | }
|
---|
307 | else
|
---|
308 | {
|
---|
309 | memset(result, 0, sizeof(*result));
|
---|
310 | /*Codes_SRS_IOTHUBMESSAGE_02_032: [The type of the new message shall be IOTHUBMESSAGE_STRING.] */
|
---|
311 | result->contentType = IOTHUBMESSAGE_STRING;
|
---|
312 |
|
---|
313 | /*Codes_SRS_IOTHUBMESSAGE_02_027: [IoTHubMessage_CreateFromString shall call STRING_construct passing source as parameter.] */
|
---|
314 | if ((result->value.string = STRING_construct(source)) == NULL)
|
---|
315 | {
|
---|
316 | LogError("STRING_construct failed");
|
---|
317 | /*Codes_SRS_IOTHUBMESSAGE_02_029: [If there are any encountered in the execution of IoTHubMessage_CreateFromString then IoTHubMessage_CreateFromString shall return NULL.] */
|
---|
318 | DestroyMessageData(result);
|
---|
319 | result = NULL;
|
---|
320 | }
|
---|
321 | /*Codes_SRS_IOTHUBMESSAGE_02_028: [IoTHubMessage_CreateFromString shall call Map_Create to create the message properties.] */
|
---|
322 | else if ((result->properties = Map_Create(ValidateAsciiCharactersFilter)) == NULL)
|
---|
323 | {
|
---|
324 | LogError("Map_Create for properties failed");
|
---|
325 | /*Codes_SRS_IOTHUBMESSAGE_02_029: [If there are any encountered in the execution of IoTHubMessage_CreateFromString then IoTHubMessage_CreateFromString shall return NULL.] */
|
---|
326 | DestroyMessageData(result);
|
---|
327 | result = NULL;
|
---|
328 | }
|
---|
329 | /*Codes_SRS_IOTHUBMESSAGE_02_031: [Otherwise, IoTHubMessage_CreateFromString shall return a non-NULL handle.] */
|
---|
330 | }
|
---|
331 | }
|
---|
332 | return result;
|
---|
333 | }
|
---|
334 |
|
---|
335 | /*Codes_SRS_IOTHUBMESSAGE_03_001: [IoTHubMessage_Clone shall create a new IoT hub message with data content identical to that of the iotHubMessageHandle parameter.]*/
|
---|
336 | IOTHUB_MESSAGE_HANDLE IoTHubMessage_Clone(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
337 | {
|
---|
338 | IOTHUB_MESSAGE_HANDLE_DATA* result;
|
---|
339 | const IOTHUB_MESSAGE_HANDLE_DATA* source = (const IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
|
---|
340 | /* Codes_SRS_IOTHUBMESSAGE_03_005: [IoTHubMessage_Clone shall return NULL if iotHubMessageHandle is NULL.] */
|
---|
341 | if (source == NULL)
|
---|
342 | {
|
---|
343 | result = NULL;
|
---|
344 | LogError("iotHubMessageHandle parameter cannot be NULL for IoTHubMessage_Clone");
|
---|
345 | }
|
---|
346 | else
|
---|
347 | {
|
---|
348 | result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA));
|
---|
349 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
|
---|
350 | if (result == NULL)
|
---|
351 | {
|
---|
352 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
|
---|
353 | /*do nothing and return as is*/
|
---|
354 | LogError("unable to malloc");
|
---|
355 | }
|
---|
356 | else
|
---|
357 | {
|
---|
358 | memset(result, 0, sizeof(*result));
|
---|
359 | result->contentType = source->contentType;
|
---|
360 | result->is_security_message = source->is_security_message;
|
---|
361 |
|
---|
362 | if (source->messageId != NULL && mallocAndStrcpy_s(&result->messageId, source->messageId) != 0)
|
---|
363 | {
|
---|
364 | LogError("unable to Copy messageId");
|
---|
365 | DestroyMessageData(result);
|
---|
366 | result = NULL;
|
---|
367 | }
|
---|
368 | else if (source->correlationId != NULL && mallocAndStrcpy_s(&result->correlationId, source->correlationId) != 0)
|
---|
369 | {
|
---|
370 | LogError("unable to Copy correlationId");
|
---|
371 | DestroyMessageData(result);
|
---|
372 | result = NULL;
|
---|
373 | }
|
---|
374 | else if (source->userDefinedContentType != NULL && mallocAndStrcpy_s(&result->userDefinedContentType, source->userDefinedContentType) != 0)
|
---|
375 | {
|
---|
376 | LogError("unable to copy contentType");
|
---|
377 | DestroyMessageData(result);
|
---|
378 | result = NULL;
|
---|
379 | }
|
---|
380 | else if (source->contentEncoding != NULL && mallocAndStrcpy_s(&result->contentEncoding, source->contentEncoding) != 0)
|
---|
381 | {
|
---|
382 | LogError("unable to copy contentEncoding");
|
---|
383 | DestroyMessageData(result);
|
---|
384 | result = NULL;
|
---|
385 | }
|
---|
386 | else if (source->diagnosticData != NULL && (result->diagnosticData = CloneDiagnosticPropertyData(source->diagnosticData)) == NULL)
|
---|
387 | {
|
---|
388 | LogError("unable to copy CloneDiagnosticPropertyData");
|
---|
389 | DestroyMessageData(result);
|
---|
390 | result = NULL;
|
---|
391 | }
|
---|
392 | else if (source->outputName != NULL && mallocAndStrcpy_s(&result->outputName, source->outputName) != 0)
|
---|
393 | {
|
---|
394 | LogError("unable to copy outputName");
|
---|
395 | DestroyMessageData(result);
|
---|
396 | result = NULL;
|
---|
397 | }
|
---|
398 | else if (source->inputName != NULL && mallocAndStrcpy_s(&result->inputName, source->inputName) != 0)
|
---|
399 | {
|
---|
400 | LogError("unable to copy inputName");
|
---|
401 | DestroyMessageData(result);
|
---|
402 | result = NULL;
|
---|
403 | }
|
---|
404 | else if (source->creationTimeUtc != NULL && mallocAndStrcpy_s(&result->creationTimeUtc, source->creationTimeUtc) != 0)
|
---|
405 | {
|
---|
406 | LogError("unable to copy creationTimeUtc");
|
---|
407 | DestroyMessageData(result);
|
---|
408 | result = NULL;
|
---|
409 | }
|
---|
410 | else if (source->userId != NULL && mallocAndStrcpy_s(&result->userId, source->userId) != 0)
|
---|
411 | {
|
---|
412 | LogError("unable to copy userId");
|
---|
413 | DestroyMessageData(result);
|
---|
414 | result = NULL;
|
---|
415 | }
|
---|
416 | else if (source->connectionModuleId != NULL && mallocAndStrcpy_s(&result->connectionModuleId, source->connectionModuleId) != 0)
|
---|
417 | {
|
---|
418 | LogError("unable to copy inputName");
|
---|
419 | DestroyMessageData(result);
|
---|
420 | result = NULL;
|
---|
421 | }
|
---|
422 | else if (source->connectionDeviceId != NULL && mallocAndStrcpy_s(&result->connectionDeviceId, source->connectionDeviceId) != 0)
|
---|
423 | {
|
---|
424 | LogError("unable to copy inputName");
|
---|
425 | DestroyMessageData(result);
|
---|
426 | result = NULL;
|
---|
427 | }
|
---|
428 | else if (source->contentType == IOTHUBMESSAGE_BYTEARRAY)
|
---|
429 | {
|
---|
430 | /*Codes_SRS_IOTHUBMESSAGE_02_006: [IoTHubMessage_Clone shall clone to content by a call to BUFFER_clone] */
|
---|
431 | if ((result->value.byteArray = BUFFER_clone(source->value.byteArray)) == NULL)
|
---|
432 | {
|
---|
433 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
|
---|
434 | LogError("unable to BUFFER_clone");
|
---|
435 | DestroyMessageData(result);
|
---|
436 | result = NULL;
|
---|
437 | }
|
---|
438 | /*Codes_SRS_IOTHUBMESSAGE_02_005: [IoTHubMessage_Clone shall clone the properties map by using Map_Clone.] */
|
---|
439 | else if ((result->properties = Map_Clone(source->properties)) == NULL)
|
---|
440 | {
|
---|
441 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
|
---|
442 | LogError("unable to Map_Clone");
|
---|
443 | DestroyMessageData(result);
|
---|
444 | result = NULL;
|
---|
445 | }
|
---|
446 | /*Codes_SRS_IOTHUBMESSAGE_03_002: [IoTHubMessage_Clone shall return upon success a non-NULL handle to the newly created IoT hub message.]*/
|
---|
447 | }
|
---|
448 | else /*can only be STRING*/
|
---|
449 | {
|
---|
450 | /*Codes_SRS_IOTHUBMESSAGE_02_006: [IoTHubMessage_Clone shall clone the content by a call to BUFFER_clone or STRING_clone] */
|
---|
451 | if ((result->value.string = STRING_clone(source->value.string)) == NULL)
|
---|
452 | {
|
---|
453 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
|
---|
454 | LogError("failed to STRING_clone");
|
---|
455 | DestroyMessageData(result);
|
---|
456 | result = NULL;
|
---|
457 | }
|
---|
458 | /*Codes_SRS_IOTHUBMESSAGE_02_005: [IoTHubMessage_Clone shall clone the properties map by using Map_Clone.] */
|
---|
459 | else if ((result->properties = Map_Clone(source->properties)) == NULL)
|
---|
460 | {
|
---|
461 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/
|
---|
462 | LogError("unable to Map_Clone");
|
---|
463 | DestroyMessageData(result);
|
---|
464 | result = NULL;
|
---|
465 | }
|
---|
466 | }
|
---|
467 | }
|
---|
468 | }
|
---|
469 | return result;
|
---|
470 | }
|
---|
471 |
|
---|
472 | IOTHUB_MESSAGE_RESULT IoTHubMessage_GetByteArray(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const unsigned char** buffer, size_t* size)
|
---|
473 | {
|
---|
474 | IOTHUB_MESSAGE_RESULT result;
|
---|
475 | if (
|
---|
476 | (iotHubMessageHandle == NULL) ||
|
---|
477 | (buffer == NULL) ||
|
---|
478 | (size == NULL)
|
---|
479 | )
|
---|
480 | {
|
---|
481 | /*Codes_SRS_IOTHUBMESSAGE_01_014: [If any of the arguments passed to IoTHubMessage_GetByteArray is NULL IoTHubMessage_GetByteArray shall return IOTHUBMESSAGE_INVALID_ARG.] */
|
---|
482 | LogError("invalid parameter (NULL) to IoTHubMessage_GetByteArray IOTHUB_MESSAGE_HANDLE iotHubMessageHandle=%p, const unsigned char** buffer=%p, size_t* size=%p", iotHubMessageHandle, buffer, size);
|
---|
483 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
484 | }
|
---|
485 | else
|
---|
486 | {
|
---|
487 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
488 | if (handleData->contentType != IOTHUBMESSAGE_BYTEARRAY)
|
---|
489 | {
|
---|
490 | /*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.] */
|
---|
491 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
492 | LogError("invalid type of message %s", MU_ENUM_TO_STRING(IOTHUBMESSAGE_CONTENT_TYPE, handleData->contentType));
|
---|
493 | }
|
---|
494 | else
|
---|
495 | {
|
---|
496 | /*Codes_SRS_IOTHUBMESSAGE_01_011: [The pointer shall be obtained by using BUFFER_u_char and it shall be copied in the buffer argument.]*/
|
---|
497 | *buffer = BUFFER_u_char(handleData->value.byteArray);
|
---|
498 | /*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.]*/
|
---|
499 | *size = BUFFER_length(handleData->value.byteArray);
|
---|
500 | result = IOTHUB_MESSAGE_OK;
|
---|
501 | }
|
---|
502 | }
|
---|
503 | return result;
|
---|
504 | }
|
---|
505 |
|
---|
506 | const char* IoTHubMessage_GetString(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
507 | {
|
---|
508 | const char* result;
|
---|
509 | if (iotHubMessageHandle == NULL)
|
---|
510 | {
|
---|
511 | /*Codes_SRS_IOTHUBMESSAGE_02_016: [If any parameter is NULL then IoTHubMessage_GetString shall return NULL.] */
|
---|
512 | result = NULL;
|
---|
513 | }
|
---|
514 | else
|
---|
515 | {
|
---|
516 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
517 | if (handleData->contentType != IOTHUBMESSAGE_STRING)
|
---|
518 | {
|
---|
519 | /*Codes_SRS_IOTHUBMESSAGE_02_017: [IoTHubMessage_GetString shall return NULL if the iotHubMessageHandle does not refer to a IOTHUBMESSAGE of type STRING.] */
|
---|
520 | result = NULL;
|
---|
521 | }
|
---|
522 | else
|
---|
523 | {
|
---|
524 | /*Codes_SRS_IOTHUBMESSAGE_02_018: [IoTHubMessage_GetStringData shall return the currently stored null terminated string.] */
|
---|
525 | result = STRING_c_str(handleData->value.string);
|
---|
526 | }
|
---|
527 | }
|
---|
528 | return result;
|
---|
529 | }
|
---|
530 |
|
---|
531 | IOTHUBMESSAGE_CONTENT_TYPE IoTHubMessage_GetContentType(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
532 | {
|
---|
533 | IOTHUBMESSAGE_CONTENT_TYPE result;
|
---|
534 | /*Codes_SRS_IOTHUBMESSAGE_02_008: [If any parameter is NULL then IoTHubMessage_GetContentType shall return IOTHUBMESSAGE_UNKNOWN.] */
|
---|
535 | if (iotHubMessageHandle == NULL)
|
---|
536 | {
|
---|
537 | result = IOTHUBMESSAGE_UNKNOWN;
|
---|
538 | }
|
---|
539 | else
|
---|
540 | {
|
---|
541 | /*Codes_SRS_IOTHUBMESSAGE_02_009: [Otherwise IoTHubMessage_GetContentType shall return the type of the message.] */
|
---|
542 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
543 | result = handleData->contentType;
|
---|
544 | }
|
---|
545 | return result;
|
---|
546 | }
|
---|
547 |
|
---|
548 | MAP_HANDLE IoTHubMessage_Properties(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
549 | {
|
---|
550 | MAP_HANDLE result;
|
---|
551 | /*Codes_SRS_IOTHUBMESSAGE_02_001: [If iotHubMessageHandle is NULL then IoTHubMessage_Properties shall return NULL.]*/
|
---|
552 | if (iotHubMessageHandle == NULL)
|
---|
553 | {
|
---|
554 | LogError("invalid arg (NULL) passed to IoTHubMessage_Properties");
|
---|
555 | result = NULL;
|
---|
556 | }
|
---|
557 | else
|
---|
558 | {
|
---|
559 | /*Codes_SRS_IOTHUBMESSAGE_02_002: [Otherwise, for any non-NULL iotHubMessageHandle it shall return a non-NULL MAP_HANDLE.]*/
|
---|
560 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
|
---|
561 | result = handleData->properties;
|
---|
562 | }
|
---|
563 | return result;
|
---|
564 | }
|
---|
565 |
|
---|
566 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetProperty(IOTHUB_MESSAGE_HANDLE msg_handle, const char* key, const char* value)
|
---|
567 | {
|
---|
568 | IOTHUB_MESSAGE_RESULT result;
|
---|
569 | if (msg_handle == NULL || key == NULL || value == NULL)
|
---|
570 | {
|
---|
571 | LogError("invalid parameter (NULL) to IoTHubMessage_SetProperty iotHubMessageHandle=%p, key=%p, value=%p", msg_handle, key, value);
|
---|
572 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
573 | }
|
---|
574 | else
|
---|
575 | {
|
---|
576 | MAP_RESULT map_result = Map_AddOrUpdate(msg_handle->properties, key, value);
|
---|
577 | if (map_result == MAP_FILTER_REJECT)
|
---|
578 | {
|
---|
579 | LogError("Failure validating property as ASCII");
|
---|
580 | result = IOTHUB_MESSAGE_INVALID_TYPE;
|
---|
581 | }
|
---|
582 | else if (map_result != MAP_OK)
|
---|
583 | {
|
---|
584 | LogError("Failure adding property to internal map");
|
---|
585 | result = IOTHUB_MESSAGE_ERROR;
|
---|
586 | }
|
---|
587 | else
|
---|
588 | {
|
---|
589 | result = IOTHUB_MESSAGE_OK;
|
---|
590 | }
|
---|
591 | }
|
---|
592 | return result;
|
---|
593 | }
|
---|
594 |
|
---|
595 | const char* IoTHubMessage_GetProperty(IOTHUB_MESSAGE_HANDLE msg_handle, const char* key)
|
---|
596 | {
|
---|
597 | const char* result;
|
---|
598 | if (msg_handle == NULL || key == NULL)
|
---|
599 | {
|
---|
600 | LogError("invalid parameter (NULL) to IoTHubMessage_GetProperty iotHubMessageHandle=%p, key=%p", msg_handle, key);
|
---|
601 | result = NULL;
|
---|
602 | }
|
---|
603 | else
|
---|
604 | {
|
---|
605 | bool key_exists = false;
|
---|
606 | // The return value is not neccessary, just check the key_exist variable
|
---|
607 | if ((Map_ContainsKey(msg_handle->properties, key, &key_exists) == MAP_OK) && key_exists)
|
---|
608 | {
|
---|
609 | result = Map_GetValueFromKey(msg_handle->properties, key);
|
---|
610 | }
|
---|
611 | else
|
---|
612 | {
|
---|
613 | result = NULL;
|
---|
614 | }
|
---|
615 | }
|
---|
616 | return result;
|
---|
617 | }
|
---|
618 |
|
---|
619 | const char* IoTHubMessage_GetCorrelationId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
620 | {
|
---|
621 | const char* result;
|
---|
622 | /* Codes_SRS_IOTHUBMESSAGE_07_016: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetCorrelationId shall return a NULL value.] */
|
---|
623 | if (iotHubMessageHandle == NULL)
|
---|
624 | {
|
---|
625 | LogError("invalid arg (NULL) passed to IoTHubMessage_GetCorrelationId");
|
---|
626 | result = NULL;
|
---|
627 | }
|
---|
628 | else
|
---|
629 | {
|
---|
630 | /* Codes_SRS_IOTHUBMESSAGE_07_017: [IoTHubMessage_GetCorrelationId shall return the correlationId as a const char*.] */
|
---|
631 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
632 | result = handleData->correlationId;
|
---|
633 | }
|
---|
634 | return result;
|
---|
635 | }
|
---|
636 |
|
---|
637 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetCorrelationId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* correlationId)
|
---|
638 | {
|
---|
639 | IOTHUB_MESSAGE_RESULT result;
|
---|
640 | /* Codes_SRS_IOTHUBMESSAGE_07_018: [if any of the parameters are NULL then IoTHubMessage_SetCorrelationId shall return a IOTHUB_MESSAGE_INVALID_ARG value.]*/
|
---|
641 | if (iotHubMessageHandle == NULL || correlationId == NULL)
|
---|
642 | {
|
---|
643 | LogError("invalid arg (NULL) passed to IoTHubMessage_SetCorrelationId");
|
---|
644 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
645 | }
|
---|
646 | else
|
---|
647 | {
|
---|
648 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
649 | /* Codes_SRS_IOTHUBMESSAGE_07_019: [If the IOTHUB_MESSAGE_HANDLE correlationId is not NULL, then the IOTHUB_MESSAGE_HANDLE correlationId will be deallocated.] */
|
---|
650 | if (handleData->correlationId != NULL)
|
---|
651 | {
|
---|
652 | free(handleData->correlationId);
|
---|
653 | handleData->correlationId = NULL;
|
---|
654 | }
|
---|
655 |
|
---|
656 | if (mallocAndStrcpy_s(&handleData->correlationId, correlationId) != 0)
|
---|
657 | {
|
---|
658 | /* Codes_SRS_IOTHUBMESSAGE_07_020: [If the allocation or the copying of the correlationId fails, then IoTHubMessage_SetCorrelationId shall return IOTHUB_MESSAGE_ERROR.] */
|
---|
659 | result = IOTHUB_MESSAGE_ERROR;
|
---|
660 | }
|
---|
661 | else
|
---|
662 | {
|
---|
663 | /* Codes_SRS_IOTHUBMESSAGE_07_021: [IoTHubMessage_SetCorrelationId finishes successfully it shall return IOTHUB_MESSAGE_OK.] */
|
---|
664 | result = IOTHUB_MESSAGE_OK;
|
---|
665 | }
|
---|
666 | }
|
---|
667 | return result;
|
---|
668 | }
|
---|
669 |
|
---|
670 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetMessageId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* messageId)
|
---|
671 | {
|
---|
672 | IOTHUB_MESSAGE_RESULT result;
|
---|
673 | /* Codes_SRS_IOTHUBMESSAGE_07_012: [if any of the parameters are NULL then IoTHubMessage_SetMessageId shall return a IOTHUB_MESSAGE_INVALID_ARG value.] */
|
---|
674 | if (iotHubMessageHandle == NULL || messageId == NULL)
|
---|
675 | {
|
---|
676 | LogError("invalid arg (NULL) passed to IoTHubMessage_SetMessageId");
|
---|
677 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
678 | }
|
---|
679 | else
|
---|
680 | {
|
---|
681 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
682 | /* Codes_SRS_IOTHUBMESSAGE_07_013: [If the IOTHUB_MESSAGE_HANDLE messageId is not NULL, then the IOTHUB_MESSAGE_HANDLE messageId will be freed] */
|
---|
683 | if (handleData->messageId != NULL)
|
---|
684 | {
|
---|
685 | free(handleData->messageId);
|
---|
686 | handleData->messageId = NULL;
|
---|
687 | }
|
---|
688 |
|
---|
689 | /* Codes_SRS_IOTHUBMESSAGE_07_014: [If the allocation or the copying of the messageId fails, then IoTHubMessage_SetMessageId shall return IOTHUB_MESSAGE_ERROR.] */
|
---|
690 | if (mallocAndStrcpy_s(&handleData->messageId, messageId) != 0)
|
---|
691 | {
|
---|
692 | result = IOTHUB_MESSAGE_ERROR;
|
---|
693 | }
|
---|
694 | else
|
---|
695 | {
|
---|
696 | result = IOTHUB_MESSAGE_OK;
|
---|
697 | }
|
---|
698 | }
|
---|
699 | return result;
|
---|
700 | }
|
---|
701 |
|
---|
702 | const char* IoTHubMessage_GetMessageId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
703 | {
|
---|
704 | const char* result;
|
---|
705 | /* Codes_SRS_IOTHUBMESSAGE_07_010: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_MessageId shall return a NULL value.] */
|
---|
706 | if (iotHubMessageHandle == NULL)
|
---|
707 | {
|
---|
708 | LogError("invalid arg (NULL) passed to IoTHubMessage_GetMessageId");
|
---|
709 | result = NULL;
|
---|
710 | }
|
---|
711 | else
|
---|
712 | {
|
---|
713 | /* Codes_SRS_IOTHUBMESSAGE_07_011: [IoTHubMessage_MessageId shall return the messageId as a const char*.] */
|
---|
714 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
715 | result = handleData->messageId;
|
---|
716 | }
|
---|
717 | return result;
|
---|
718 | }
|
---|
719 |
|
---|
720 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetContentTypeSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* contentType)
|
---|
721 | {
|
---|
722 | IOTHUB_MESSAGE_RESULT result;
|
---|
723 |
|
---|
724 | // Codes_SRS_IOTHUBMESSAGE_09_001: [If any of the parameters are NULL then IoTHubMessage_SetContentTypeSystemProperty shall return a IOTHUB_MESSAGE_INVALID_ARG value.]
|
---|
725 | if (iotHubMessageHandle == NULL || contentType == NULL)
|
---|
726 | {
|
---|
727 | LogError("Invalid argument (iotHubMessageHandle=%p, contentType=%p)", iotHubMessageHandle, contentType);
|
---|
728 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
729 | }
|
---|
730 | else
|
---|
731 | {
|
---|
732 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
|
---|
733 |
|
---|
734 | // Codes_SRS_IOTHUBMESSAGE_09_002: [If the IOTHUB_MESSAGE_HANDLE `contentType` is not NULL it shall be deallocated.]
|
---|
735 | if (handleData->userDefinedContentType != NULL)
|
---|
736 | {
|
---|
737 | free(handleData->userDefinedContentType);
|
---|
738 | handleData->userDefinedContentType = NULL;
|
---|
739 | }
|
---|
740 |
|
---|
741 | if (mallocAndStrcpy_s(&handleData->userDefinedContentType, contentType) != 0)
|
---|
742 | {
|
---|
743 | LogError("Failed saving a copy of contentType");
|
---|
744 | // Codes_SRS_IOTHUBMESSAGE_09_003: [If the allocation or the copying of `contentType` fails, then IoTHubMessage_SetContentTypeSystemProperty shall return IOTHUB_MESSAGE_ERROR.]
|
---|
745 | result = IOTHUB_MESSAGE_ERROR;
|
---|
746 | }
|
---|
747 | else
|
---|
748 | {
|
---|
749 | // Codes_SRS_IOTHUBMESSAGE_09_004: [If IoTHubMessage_SetContentTypeSystemProperty finishes successfully it shall return IOTHUB_MESSAGE_OK.]
|
---|
750 | result = IOTHUB_MESSAGE_OK;
|
---|
751 | }
|
---|
752 | }
|
---|
753 |
|
---|
754 | return result;
|
---|
755 | }
|
---|
756 |
|
---|
757 | const char* IoTHubMessage_GetContentTypeSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
758 | {
|
---|
759 | const char* result;
|
---|
760 |
|
---|
761 | // Codes_SRS_IOTHUBMESSAGE_09_005: [If any of the parameters are NULL then IoTHubMessage_GetContentTypeSystemProperty shall return a IOTHUB_MESSAGE_INVALID_ARG value.]
|
---|
762 | if (iotHubMessageHandle == NULL)
|
---|
763 | {
|
---|
764 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
765 | result = NULL;
|
---|
766 | }
|
---|
767 | else
|
---|
768 | {
|
---|
769 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
770 |
|
---|
771 | // Codes_SRS_IOTHUBMESSAGE_09_006: [IoTHubMessage_GetContentTypeSystemProperty shall return the `contentType` as a const char* ]
|
---|
772 | result = (const char*)handleData->userDefinedContentType;
|
---|
773 | }
|
---|
774 |
|
---|
775 | return result;
|
---|
776 | }
|
---|
777 |
|
---|
778 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetContentEncodingSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* contentEncoding)
|
---|
779 | {
|
---|
780 | IOTHUB_MESSAGE_RESULT result;
|
---|
781 |
|
---|
782 | // Codes_SRS_IOTHUBMESSAGE_09_006: [If any of the parameters are NULL then IoTHubMessage_SetContentEncodingSystemProperty shall return a IOTHUB_MESSAGE_INVALID_ARG value.]
|
---|
783 | if (iotHubMessageHandle == NULL || contentEncoding == NULL)
|
---|
784 | {
|
---|
785 | LogError("Invalid argument (iotHubMessageHandle=%p, contentEncoding=%p)", iotHubMessageHandle, contentEncoding);
|
---|
786 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
787 | }
|
---|
788 | else
|
---|
789 | {
|
---|
790 | if (set_content_encoding(iotHubMessageHandle, contentEncoding) != 0)
|
---|
791 | {
|
---|
792 | LogError("Failed saving a copy of contentEncoding");
|
---|
793 | // Codes_SRS_IOTHUBMESSAGE_09_008: [If the allocation or the copying of `contentEncoding` fails, then IoTHubMessage_SetContentEncodingSystemProperty shall return IOTHUB_MESSAGE_ERROR.]
|
---|
794 | result = IOTHUB_MESSAGE_ERROR;
|
---|
795 | }
|
---|
796 | else
|
---|
797 | {
|
---|
798 | // Codes_SRS_IOTHUBMESSAGE_09_009: [If IoTHubMessage_SetContentEncodingSystemProperty finishes successfully it shall return IOTHUB_MESSAGE_OK.]
|
---|
799 | result = IOTHUB_MESSAGE_OK;
|
---|
800 | }
|
---|
801 | }
|
---|
802 | return result;
|
---|
803 | }
|
---|
804 |
|
---|
805 | const char* IoTHubMessage_GetContentEncodingSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
806 | {
|
---|
807 | const char* result;
|
---|
808 |
|
---|
809 | // Codes_SRS_IOTHUBMESSAGE_09_010: [If any of the parameters are NULL then IoTHubMessage_GetContentEncodingSystemProperty shall return a IOTHUB_MESSAGE_INVALID_ARG value.]
|
---|
810 | if (iotHubMessageHandle == NULL)
|
---|
811 | {
|
---|
812 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
813 | result = NULL;
|
---|
814 | }
|
---|
815 | else
|
---|
816 | {
|
---|
817 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
818 |
|
---|
819 | // Codes_SRS_IOTHUBMESSAGE_09_011: [IoTHubMessage_GetContentEncodingSystemProperty shall return the `contentEncoding` as a const char* ]
|
---|
820 | result = (const char*)handleData->contentEncoding;
|
---|
821 | }
|
---|
822 |
|
---|
823 | return result;
|
---|
824 | }
|
---|
825 |
|
---|
826 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetMessageCreationTimeUtcSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* creationTimeUtc)
|
---|
827 | {
|
---|
828 | IOTHUB_MESSAGE_RESULT result;
|
---|
829 |
|
---|
830 | if (iotHubMessageHandle == NULL || creationTimeUtc == NULL)
|
---|
831 | {
|
---|
832 | LogError("Invalid argument (iotHubMessageHandle=%p, creationTimeUtc=%p)", iotHubMessageHandle, creationTimeUtc);
|
---|
833 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
834 | }
|
---|
835 | else
|
---|
836 | {
|
---|
837 | if (set_message_creation_time(iotHubMessageHandle, creationTimeUtc) != 0)
|
---|
838 | {
|
---|
839 | LogError("Failed saving a copy of creationTimeUtc");
|
---|
840 | result = IOTHUB_MESSAGE_ERROR;
|
---|
841 | }
|
---|
842 | else
|
---|
843 | {
|
---|
844 | result = IOTHUB_MESSAGE_OK;
|
---|
845 | }
|
---|
846 | }
|
---|
847 | return result;
|
---|
848 | }
|
---|
849 |
|
---|
850 | const char* IoTHubMessage_GetMessageCreationTimeUtcSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
851 | {
|
---|
852 | const char* result;
|
---|
853 |
|
---|
854 | if (iotHubMessageHandle == NULL)
|
---|
855 | {
|
---|
856 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
857 | result = NULL;
|
---|
858 | }
|
---|
859 | else
|
---|
860 | {
|
---|
861 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
862 | result = (const char*)handleData->creationTimeUtc;
|
---|
863 | }
|
---|
864 |
|
---|
865 | return result;
|
---|
866 | }
|
---|
867 |
|
---|
868 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetMessageUserIdSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* userId)
|
---|
869 | {
|
---|
870 | IOTHUB_MESSAGE_RESULT result;
|
---|
871 |
|
---|
872 | if (iotHubMessageHandle == NULL || userId == NULL)
|
---|
873 | {
|
---|
874 | LogError("Invalid argument (iotHubMessageHandle=%p, userId=%p)", iotHubMessageHandle, userId);
|
---|
875 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
876 | }
|
---|
877 | else
|
---|
878 | {
|
---|
879 | if (set_message_user_id(iotHubMessageHandle, userId) != 0)
|
---|
880 | {
|
---|
881 | LogError("Failed saving a copy of userId");
|
---|
882 | result = IOTHUB_MESSAGE_ERROR;
|
---|
883 | }
|
---|
884 | else
|
---|
885 | {
|
---|
886 | result = IOTHUB_MESSAGE_OK;
|
---|
887 | }
|
---|
888 | }
|
---|
889 | return result;
|
---|
890 | }
|
---|
891 |
|
---|
892 | const char* IoTHubMessage_GetMessageUserIdSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
893 | {
|
---|
894 | const char* result;
|
---|
895 |
|
---|
896 | if (iotHubMessageHandle == NULL)
|
---|
897 | {
|
---|
898 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
899 | result = NULL;
|
---|
900 | }
|
---|
901 | else
|
---|
902 | {
|
---|
903 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle;
|
---|
904 | result = (const char*)handleData->userId;
|
---|
905 | }
|
---|
906 |
|
---|
907 | return result;
|
---|
908 | }
|
---|
909 |
|
---|
910 | const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* IoTHubMessage_GetDiagnosticPropertyData(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
911 | {
|
---|
912 | const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* result;
|
---|
913 | // Codes_SRS_IOTHUBMESSAGE_10_001: [If any of the parameters are NULL then IoTHubMessage_GetDiagnosticPropertyData shall return a NULL value.]
|
---|
914 | if (iotHubMessageHandle == NULL)
|
---|
915 | {
|
---|
916 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
917 | result = NULL;
|
---|
918 | }
|
---|
919 | else
|
---|
920 | {
|
---|
921 | /* Codes_SRS_IOTHUBMESSAGE_10_002: [IoTHubMessage_GetDiagnosticPropertyData shall return the diagnosticData as a const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*.] */
|
---|
922 | result = iotHubMessageHandle->diagnosticData;
|
---|
923 | }
|
---|
924 | return result;
|
---|
925 | }
|
---|
926 |
|
---|
927 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetDiagnosticPropertyData(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* diagnosticData)
|
---|
928 | {
|
---|
929 | IOTHUB_MESSAGE_RESULT result;
|
---|
930 | // Codes_SRS_IOTHUBMESSAGE_10_003: [If any of the parameters are NULL then IoTHubMessage_SetDiagnosticId shall return a IOTHUB_MESSAGE_INVALID_ARG value.]
|
---|
931 | if (iotHubMessageHandle == NULL ||
|
---|
932 | diagnosticData == NULL ||
|
---|
933 | diagnosticData->diagnosticCreationTimeUtc == NULL ||
|
---|
934 | diagnosticData->diagnosticId == NULL)
|
---|
935 | {
|
---|
936 | LogError("Invalid argument (iotHubMessageHandle=%p, diagnosticData=%p, diagnosticData->diagnosticId=%p, diagnosticData->diagnosticCreationTimeUtc=%p)",
|
---|
937 | iotHubMessageHandle, diagnosticData,
|
---|
938 | diagnosticData == NULL ? NULL : diagnosticData->diagnosticId,
|
---|
939 | diagnosticData == NULL ? NULL : diagnosticData->diagnosticCreationTimeUtc);
|
---|
940 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
941 | }
|
---|
942 | else
|
---|
943 | {
|
---|
944 | // Codes_SRS_IOTHUBMESSAGE_10_004: [If the IOTHUB_MESSAGE_HANDLE `diagnosticData` is not NULL it shall be deallocated.]
|
---|
945 | if (iotHubMessageHandle->diagnosticData != NULL)
|
---|
946 | {
|
---|
947 | DestroyDiagnosticPropertyData(iotHubMessageHandle->diagnosticData);
|
---|
948 | iotHubMessageHandle->diagnosticData = NULL;
|
---|
949 | }
|
---|
950 |
|
---|
951 | // Codes_SRS_IOTHUBMESSAGE_10_005: [If the allocation or the copying of `diagnosticData` fails, then IoTHubMessage_SetDiagnosticPropertyData shall return IOTHUB_MESSAGE_ERROR.]
|
---|
952 | if ((iotHubMessageHandle->diagnosticData = CloneDiagnosticPropertyData(diagnosticData)) == NULL)
|
---|
953 | {
|
---|
954 | LogError("Failed saving a copy of diagnosticData");
|
---|
955 | result = IOTHUB_MESSAGE_ERROR;
|
---|
956 | }
|
---|
957 | else
|
---|
958 | {
|
---|
959 | // Codes_SRS_IOTHUBMESSAGE_10_006: [If IoTHubMessage_SetDiagnosticPropertyData finishes successfully it shall return IOTHUB_MESSAGE_OK.]
|
---|
960 | result = IOTHUB_MESSAGE_OK;
|
---|
961 | }
|
---|
962 | }
|
---|
963 | return result;
|
---|
964 | }
|
---|
965 |
|
---|
966 |
|
---|
967 | const char* IoTHubMessage_GetOutputName(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
968 | {
|
---|
969 | const char* result;
|
---|
970 | // Codes_SRS_IOTHUBMESSAGE_31_034: [If the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetOutputName shall return a NULL value.]
|
---|
971 | if (iotHubMessageHandle == NULL)
|
---|
972 | {
|
---|
973 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
974 | result = NULL;
|
---|
975 | }
|
---|
976 | else
|
---|
977 | {
|
---|
978 | // Codes_SRS_IOTHUBMESSAGE_31_035: [IoTHubMessage_GetOutputName shall return the OutputName as a const char*.]
|
---|
979 | result = iotHubMessageHandle->outputName;
|
---|
980 | }
|
---|
981 | return result;
|
---|
982 | }
|
---|
983 |
|
---|
984 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetOutputName(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* outputName)
|
---|
985 | {
|
---|
986 | IOTHUB_MESSAGE_RESULT result;
|
---|
987 |
|
---|
988 | // Codes_SRS_IOTHUBMESSAGE_31_036: [If any of the parameters are NULL then IoTHubMessage_SetOutputName shall return a IOTHUB_MESSAGE_INVALID_ARG value.]
|
---|
989 | if ((iotHubMessageHandle == NULL) || (outputName == NULL))
|
---|
990 | {
|
---|
991 | LogError("Invalid argument (iotHubMessageHandle=%p, outputName=%p)", iotHubMessageHandle, outputName);
|
---|
992 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
993 | }
|
---|
994 | else
|
---|
995 | {
|
---|
996 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
|
---|
997 |
|
---|
998 | // Codes_SRS_IOTHUBMESSAGE_31_037: [If the IOTHUB_MESSAGE_HANDLE OutputName is not NULL, then the IOTHUB_MESSAGE_HANDLE OutputName will be deallocated.]
|
---|
999 | if (handleData->outputName != NULL)
|
---|
1000 | {
|
---|
1001 | free(handleData->outputName);
|
---|
1002 | handleData->outputName = NULL;
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | if (mallocAndStrcpy_s(&handleData->outputName, outputName) != 0)
|
---|
1006 | {
|
---|
1007 | // Codes_SRS_IOTHUBMESSAGE_31_038: [If the allocation or the copying of the OutputName fails, then IoTHubMessage_SetOutputName shall return IOTHUB_MESSAGE_ERROR.]
|
---|
1008 | LogError("Failed saving a copy of outputName");
|
---|
1009 | result = IOTHUB_MESSAGE_ERROR;
|
---|
1010 | }
|
---|
1011 | else
|
---|
1012 | {
|
---|
1013 | // Codes_SRS_IOTHUBMESSAGE_31_039: [IoTHubMessage_SetOutputName finishes successfully it shall return IOTHUB_MESSAGE_OK.]
|
---|
1014 | result = IOTHUB_MESSAGE_OK;
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | }
|
---|
1018 |
|
---|
1019 | return result;
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | const char* IoTHubMessage_GetInputName(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
1023 | {
|
---|
1024 | const char* result;
|
---|
1025 | // Codes_SRS_IOTHUBMESSAGE_31_040: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetInputName shall return a NULL value.]
|
---|
1026 | if (iotHubMessageHandle == NULL)
|
---|
1027 | {
|
---|
1028 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
1029 | result = NULL;
|
---|
1030 | }
|
---|
1031 | else
|
---|
1032 | {
|
---|
1033 | // Codes_SRS_IOTHUBMESSAGE_31_041: [IoTHubMessage_GetInputName shall return the InputName as a const char*.]
|
---|
1034 | result = iotHubMessageHandle->inputName;
|
---|
1035 | }
|
---|
1036 | return result;
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetInputName(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* inputName)
|
---|
1040 | {
|
---|
1041 | IOTHUB_MESSAGE_RESULT result;
|
---|
1042 |
|
---|
1043 | // Codes_SRS_IOTHUBMESSAGE_31_042: [if any of the parameters are NULL then IoTHubMessage_SetInputName shall return a IOTHUB_MESSAGE_INVALID_ARG value.]
|
---|
1044 | if ((iotHubMessageHandle == NULL) || (inputName == NULL))
|
---|
1045 | {
|
---|
1046 | LogError("Invalid argument (iotHubMessageHandle=%p, inputName=%p)", iotHubMessageHandle, inputName);
|
---|
1047 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
1048 | }
|
---|
1049 | else
|
---|
1050 | {
|
---|
1051 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
|
---|
1052 |
|
---|
1053 | // Codes_SRS_IOTHUBMESSAGE_31_043: [If the IOTHUB_MESSAGE_HANDLE InputName is not NULL, then the IOTHUB_MESSAGE_HANDLE InputName will be deallocated.]
|
---|
1054 | if (handleData->inputName != NULL)
|
---|
1055 | {
|
---|
1056 | free(handleData->inputName);
|
---|
1057 | handleData->inputName = NULL;
|
---|
1058 | }
|
---|
1059 |
|
---|
1060 | if (mallocAndStrcpy_s(&handleData->inputName, inputName) != 0)
|
---|
1061 | {
|
---|
1062 | // Codes_SRS_IOTHUBMESSAGE_31_044: [If the allocation or the copying of the InputName fails, then IoTHubMessage_SetInputName shall return IOTHUB_MESSAGE_ERROR.]
|
---|
1063 | LogError("Failed saving a copy of inputName");
|
---|
1064 | result = IOTHUB_MESSAGE_ERROR;
|
---|
1065 | }
|
---|
1066 | else
|
---|
1067 | {
|
---|
1068 | // Codes_SRS_IOTHUBMESSAGE_31_045: [IoTHubMessage_SetInputName finishes successfully it shall return IOTHUB_MESSAGE_OK.]
|
---|
1069 | result = IOTHUB_MESSAGE_OK;
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | return result;
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 |
|
---|
1078 | const char* IoTHubMessage_GetConnectionModuleId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
1079 | {
|
---|
1080 | const char* result;
|
---|
1081 | // Codes_SRS_IOTHUBMESSAGE_31_046: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetConnectionModuleId shall return a NULL value.]
|
---|
1082 | if (iotHubMessageHandle == NULL)
|
---|
1083 | {
|
---|
1084 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
1085 | result = NULL;
|
---|
1086 | }
|
---|
1087 | else
|
---|
1088 | {
|
---|
1089 | // Codes_SRS_IOTHUBMESSAGE_31_047: [IoTHubMessage_GetConnectionModuleId shall return the ConnectionModuleId as a const char*.]
|
---|
1090 | result = iotHubMessageHandle->connectionModuleId;
|
---|
1091 | }
|
---|
1092 | return result;
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetConnectionModuleId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* connectionModuleId)
|
---|
1096 | {
|
---|
1097 | IOTHUB_MESSAGE_RESULT result;
|
---|
1098 |
|
---|
1099 | // Codes_SRS_IOTHUBMESSAGE_31_048: [if any of the parameters are NULL then IoTHubMessage_SetConnectionModuleId shall return a IOTHUB_MESSAGE_INVALID_ARG value.]
|
---|
1100 | if ((iotHubMessageHandle == NULL) || (connectionModuleId == NULL))
|
---|
1101 | {
|
---|
1102 | LogError("Invalid argument (iotHubMessageHandle=%p, connectionModuleId=%p)", iotHubMessageHandle, connectionModuleId);
|
---|
1103 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
1104 | }
|
---|
1105 | else
|
---|
1106 | {
|
---|
1107 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
|
---|
1108 |
|
---|
1109 | // Codes_SRS_IOTHUBMESSAGE_31_049: [If the IOTHUB_MESSAGE_HANDLE ConnectionModuleId is not NULL, then the IOTHUB_MESSAGE_HANDLE ConnectionModuleId will be deallocated.]
|
---|
1110 | if (handleData->connectionModuleId != NULL)
|
---|
1111 | {
|
---|
1112 | free(handleData->connectionModuleId);
|
---|
1113 | handleData->connectionModuleId = NULL;
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | if (mallocAndStrcpy_s(&handleData->connectionModuleId, connectionModuleId) != 0)
|
---|
1117 | {
|
---|
1118 | // Codes_SRS_IOTHUBMESSAGE_31_050: [If the allocation or the copying of the ConnectionModuleId fails, then IoTHubMessage_SetConnectionModuleId shall return IOTHUB_MESSAGE_ERROR.]
|
---|
1119 | LogError("Failed saving a copy of connectionModuleId");
|
---|
1120 | result = IOTHUB_MESSAGE_ERROR;
|
---|
1121 | }
|
---|
1122 | else
|
---|
1123 | {
|
---|
1124 | // Codes_SRS_IOTHUBMESSAGE_31_051: [IoTHubMessage_SetConnectionModuleId finishes successfully it shall return IOTHUB_MESSAGE_OK.]
|
---|
1125 | result = IOTHUB_MESSAGE_OK;
|
---|
1126 | }
|
---|
1127 |
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | return result;
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 |
|
---|
1134 | const char* IoTHubMessage_GetConnectionDeviceId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
1135 | {
|
---|
1136 | const char* result;
|
---|
1137 | // Codes_SRS_IOTHUBMESSAGE_31_052: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetConnectionDeviceId shall return a NULL value.]
|
---|
1138 | if (iotHubMessageHandle == NULL)
|
---|
1139 | {
|
---|
1140 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
1141 | result = NULL;
|
---|
1142 | }
|
---|
1143 | else
|
---|
1144 | {
|
---|
1145 | // Codes_SRS_IOTHUBMESSAGE_31_053: [IoTHubMessage_GetConnectionDeviceId shall return the ConnectionDeviceId as a const char*.]
|
---|
1146 | result = iotHubMessageHandle->connectionDeviceId;
|
---|
1147 | }
|
---|
1148 | return result;
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetConnectionDeviceId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* connectionDeviceId)
|
---|
1152 | {
|
---|
1153 | IOTHUB_MESSAGE_RESULT result;
|
---|
1154 |
|
---|
1155 | // Codes_SRS_IOTHUBMESSAGE_31_054: [if any of the parameters are NULL then IoTHubMessage_SetConnectionDeviceId shall return a IOTHUB_MESSAGE_INVALID_ARG value.]
|
---|
1156 | if ((iotHubMessageHandle == NULL) || (connectionDeviceId == NULL))
|
---|
1157 | {
|
---|
1158 | LogError("Invalid argument (iotHubMessageHandle=%p, connectionDeviceId=%p)", iotHubMessageHandle, connectionDeviceId);
|
---|
1159 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
1160 | }
|
---|
1161 | else
|
---|
1162 | {
|
---|
1163 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle;
|
---|
1164 |
|
---|
1165 | // Codes_SRS_IOTHUBMESSAGE_31_055: [If the IOTHUB_MESSAGE_HANDLE ConnectionDeviceId is not NULL, then the IOTHUB_MESSAGE_HANDLE ConnectionDeviceId will be deallocated.]
|
---|
1166 | if (handleData->connectionDeviceId != NULL)
|
---|
1167 | {
|
---|
1168 | free(handleData->connectionDeviceId);
|
---|
1169 | handleData->connectionDeviceId = NULL;
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | if (mallocAndStrcpy_s(&handleData->connectionDeviceId, connectionDeviceId) != 0)
|
---|
1173 | {
|
---|
1174 | // Codes_SRS_IOTHUBMESSAGE_31_056: [If the allocation or the copying of the ConnectionDeviceId fails, then IoTHubMessage_SetConnectionDeviceId shall return IOTHUB_MESSAGE_ERROR.]
|
---|
1175 | LogError("Failed saving a copy of connectionDeviceId");
|
---|
1176 | result = IOTHUB_MESSAGE_ERROR;
|
---|
1177 | }
|
---|
1178 | else
|
---|
1179 | {
|
---|
1180 | // Codes_SRS_IOTHUBMESSAGE_31_057: [IoTHubMessage_SetConnectionDeviceId finishes successfully it shall return IOTHUB_MESSAGE_OK.]
|
---|
1181 | result = IOTHUB_MESSAGE_OK;
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | return result;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetAsSecurityMessage(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
1190 | {
|
---|
1191 | IOTHUB_MESSAGE_RESULT result;
|
---|
1192 | if (iotHubMessageHandle == NULL)
|
---|
1193 | {
|
---|
1194 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
1195 | result = IOTHUB_MESSAGE_INVALID_ARG;
|
---|
1196 | }
|
---|
1197 | else
|
---|
1198 | {
|
---|
1199 | if (set_content_encoding(iotHubMessageHandle, SECURITY_CLIENT_JSON_ENCODING) != 0)
|
---|
1200 | {
|
---|
1201 | LogError("Failure setting security message content encoding");
|
---|
1202 | result = IOTHUB_MESSAGE_ERROR;
|
---|
1203 | }
|
---|
1204 | else
|
---|
1205 | {
|
---|
1206 | iotHubMessageHandle->is_security_message = true;
|
---|
1207 | result = IOTHUB_MESSAGE_OK;
|
---|
1208 | }
|
---|
1209 | }
|
---|
1210 | return result;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | bool IoTHubMessage_IsSecurityMessage(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
1214 | {
|
---|
1215 | bool result;
|
---|
1216 | if (iotHubMessageHandle == NULL)
|
---|
1217 | {
|
---|
1218 | LogError("Invalid argument (iotHubMessageHandle is NULL)");
|
---|
1219 | result = false;
|
---|
1220 | }
|
---|
1221 | else
|
---|
1222 | {
|
---|
1223 | result = iotHubMessageHandle->is_security_message;
|
---|
1224 | }
|
---|
1225 | return result;
|
---|
1226 | }
|
---|
1227 |
|
---|
1228 | void IoTHubMessage_Destroy(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle)
|
---|
1229 | {
|
---|
1230 | /*Codes_SRS_IOTHUBMESSAGE_01_004: [If iotHubMessageHandle is NULL, IoTHubMessage_Destroy shall do nothing.] */
|
---|
1231 | if (iotHubMessageHandle != NULL)
|
---|
1232 | {
|
---|
1233 | /*Codes_SRS_IOTHUBMESSAGE_01_003: [IoTHubMessage_Destroy shall free all resources associated with iotHubMessageHandle.] */
|
---|
1234 | DestroyMessageData((IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle);
|
---|
1235 | }
|
---|
1236 | }
|
---|