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
iothub_message.c@85:de16c0a8a196, 2018-03-20 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Tue Mar 20 10:29:00 2018 -0700
- Revision:
- 85:de16c0a8a196
- Parent:
- 78:74a8d3068204
- Child:
- 88:248736be106e
1.2.1
Who changed what in which revision?
User | Revision | Line number | New 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 | 77:e4e36df9caee | 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 | 74:ea0021abecf7 | 29 | char* userDefinedContentType; |
AzureIoTClient | 74:ea0021abecf7 | 30 | char* contentEncoding; |
AzureIoTClient | 77:e4e36df9caee | 31 | IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE diagnosticData; |
AzureIoTClient | 0:e393db310d89 | 32 | }IOTHUB_MESSAGE_HANDLE_DATA; |
AzureIoTClient | 0:e393db310d89 | 33 | |
AzureIoTClient | 0:e393db310d89 | 34 | static bool ContainsOnlyUsAscii(const char* asciiValue) |
AzureIoTClient | 0:e393db310d89 | 35 | { |
AzureIoTClient | 21:3c90c2262ce4 | 36 | bool result = true; |
AzureIoTClient | 0:e393db310d89 | 37 | const char* iterator = asciiValue; |
AzureIoTClient | 0:e393db310d89 | 38 | while (iterator != NULL && *iterator != '\0') |
AzureIoTClient | 0:e393db310d89 | 39 | { |
AzureIoTClient | 0:e393db310d89 | 40 | // Allow only printable ascii char |
AzureIoTClient | 0:e393db310d89 | 41 | if (*iterator < ' ' || *iterator > '~') |
AzureIoTClient | 0:e393db310d89 | 42 | { |
AzureIoTClient | 0:e393db310d89 | 43 | result = false; |
AzureIoTClient | 0:e393db310d89 | 44 | break; |
AzureIoTClient | 0:e393db310d89 | 45 | } |
AzureIoTClient | 0:e393db310d89 | 46 | iterator++; |
AzureIoTClient | 0:e393db310d89 | 47 | } |
AzureIoTClient | 0:e393db310d89 | 48 | return result; |
AzureIoTClient | 0:e393db310d89 | 49 | } |
AzureIoTClient | 0:e393db310d89 | 50 | |
AzureIoTClient | 0:e393db310d89 | 51 | /* 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 | 52 | static int ValidateAsciiCharactersFilter(const char* mapKey, const char* mapValue) |
AzureIoTClient | 0:e393db310d89 | 53 | { |
AzureIoTClient | 0:e393db310d89 | 54 | int result; |
AzureIoTClient | 77:e4e36df9caee | 55 | if (!ContainsOnlyUsAscii(mapKey) || !ContainsOnlyUsAscii(mapValue)) |
AzureIoTClient | 0:e393db310d89 | 56 | { |
AzureIoTClient | 60:41648c4e7036 | 57 | result = __FAILURE__; |
AzureIoTClient | 0:e393db310d89 | 58 | } |
AzureIoTClient | 0:e393db310d89 | 59 | else |
AzureIoTClient | 0:e393db310d89 | 60 | { |
AzureIoTClient | 0:e393db310d89 | 61 | result = 0; |
AzureIoTClient | 0:e393db310d89 | 62 | } |
AzureIoTClient | 0:e393db310d89 | 63 | return result; |
AzureIoTClient | 0:e393db310d89 | 64 | } |
AzureIoTClient | 0:e393db310d89 | 65 | |
AzureIoTClient | 77:e4e36df9caee | 66 | static void DestroyDiagnosticPropertyData(IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE diagnosticHandle) |
AzureIoTClient | 77:e4e36df9caee | 67 | { |
AzureIoTClient | 77:e4e36df9caee | 68 | if (diagnosticHandle != NULL) |
AzureIoTClient | 77:e4e36df9caee | 69 | { |
AzureIoTClient | 77:e4e36df9caee | 70 | free(diagnosticHandle->diagnosticId); |
AzureIoTClient | 77:e4e36df9caee | 71 | free(diagnosticHandle->diagnosticCreationTimeUtc); |
AzureIoTClient | 77:e4e36df9caee | 72 | } |
AzureIoTClient | 77:e4e36df9caee | 73 | free(diagnosticHandle); |
AzureIoTClient | 77:e4e36df9caee | 74 | } |
AzureIoTClient | 77:e4e36df9caee | 75 | |
AzureIoTClient | 78:74a8d3068204 | 76 | static void DestroyMessageData(IOTHUB_MESSAGE_HANDLE_DATA* handleData) |
AzureIoTClient | 78:74a8d3068204 | 77 | { |
AzureIoTClient | 78:74a8d3068204 | 78 | if (handleData->contentType == IOTHUBMESSAGE_BYTEARRAY) |
AzureIoTClient | 78:74a8d3068204 | 79 | { |
AzureIoTClient | 78:74a8d3068204 | 80 | BUFFER_delete(handleData->value.byteArray); |
AzureIoTClient | 78:74a8d3068204 | 81 | } |
AzureIoTClient | 78:74a8d3068204 | 82 | else if (handleData->contentType == IOTHUBMESSAGE_STRING) |
AzureIoTClient | 78:74a8d3068204 | 83 | { |
AzureIoTClient | 78:74a8d3068204 | 84 | STRING_delete(handleData->value.string); |
AzureIoTClient | 78:74a8d3068204 | 85 | } |
AzureIoTClient | 78:74a8d3068204 | 86 | |
AzureIoTClient | 78:74a8d3068204 | 87 | Map_Destroy(handleData->properties); |
AzureIoTClient | 78:74a8d3068204 | 88 | free(handleData->messageId); |
AzureIoTClient | 78:74a8d3068204 | 89 | handleData->messageId = NULL; |
AzureIoTClient | 78:74a8d3068204 | 90 | free(handleData->correlationId); |
AzureIoTClient | 78:74a8d3068204 | 91 | handleData->correlationId = NULL; |
AzureIoTClient | 78:74a8d3068204 | 92 | free(handleData->userDefinedContentType); |
AzureIoTClient | 78:74a8d3068204 | 93 | free(handleData->contentEncoding); |
AzureIoTClient | 78:74a8d3068204 | 94 | DestroyDiagnosticPropertyData(handleData->diagnosticData); |
AzureIoTClient | 78:74a8d3068204 | 95 | free(handleData); |
AzureIoTClient | 78:74a8d3068204 | 96 | } |
AzureIoTClient | 78:74a8d3068204 | 97 | |
AzureIoTClient | 77:e4e36df9caee | 98 | static IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE CloneDiagnosticPropertyData(const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* source) |
AzureIoTClient | 77:e4e36df9caee | 99 | { |
AzureIoTClient | 77:e4e36df9caee | 100 | IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 101 | if (source == NULL) |
AzureIoTClient | 77:e4e36df9caee | 102 | { |
AzureIoTClient | 77:e4e36df9caee | 103 | LogError("Invalid argument - source is NULL"); |
AzureIoTClient | 77:e4e36df9caee | 104 | } |
AzureIoTClient | 77:e4e36df9caee | 105 | else |
AzureIoTClient | 77:e4e36df9caee | 106 | { |
AzureIoTClient | 77:e4e36df9caee | 107 | result = (IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE)malloc(sizeof(IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA)); |
AzureIoTClient | 77:e4e36df9caee | 108 | if (result == NULL) |
AzureIoTClient | 77:e4e36df9caee | 109 | { |
AzureIoTClient | 77:e4e36df9caee | 110 | LogError("malloc failed"); |
AzureIoTClient | 77:e4e36df9caee | 111 | } |
AzureIoTClient | 77:e4e36df9caee | 112 | else |
AzureIoTClient | 77:e4e36df9caee | 113 | { |
AzureIoTClient | 77:e4e36df9caee | 114 | result->diagnosticCreationTimeUtc = NULL; |
AzureIoTClient | 77:e4e36df9caee | 115 | result->diagnosticId = NULL; |
AzureIoTClient | 77:e4e36df9caee | 116 | if (source->diagnosticCreationTimeUtc != NULL && mallocAndStrcpy_s(&result->diagnosticCreationTimeUtc, source->diagnosticCreationTimeUtc) != 0) |
AzureIoTClient | 77:e4e36df9caee | 117 | { |
AzureIoTClient | 77:e4e36df9caee | 118 | LogError("mallocAndStrcpy_s for diagnosticCreationTimeUtc failed"); |
AzureIoTClient | 77:e4e36df9caee | 119 | free(result); |
AzureIoTClient | 77:e4e36df9caee | 120 | result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 121 | } |
AzureIoTClient | 77:e4e36df9caee | 122 | else if (source->diagnosticId != NULL && mallocAndStrcpy_s(&result->diagnosticId, source->diagnosticId) != 0) |
AzureIoTClient | 77:e4e36df9caee | 123 | { |
AzureIoTClient | 77:e4e36df9caee | 124 | LogError("mallocAndStrcpy_s for diagnosticId failed"); |
AzureIoTClient | 77:e4e36df9caee | 125 | free(result->diagnosticCreationTimeUtc); |
AzureIoTClient | 77:e4e36df9caee | 126 | free(result); |
AzureIoTClient | 77:e4e36df9caee | 127 | result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 128 | } |
AzureIoTClient | 77:e4e36df9caee | 129 | } |
AzureIoTClient | 77:e4e36df9caee | 130 | } |
AzureIoTClient | 77:e4e36df9caee | 131 | return result; |
AzureIoTClient | 77:e4e36df9caee | 132 | } |
AzureIoTClient | 77:e4e36df9caee | 133 | |
AzureIoTClient | 0:e393db310d89 | 134 | IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromByteArray(const unsigned char* byteArray, size_t size) |
AzureIoTClient | 0:e393db310d89 | 135 | { |
AzureIoTClient | 0:e393db310d89 | 136 | IOTHUB_MESSAGE_HANDLE_DATA* result; |
AzureIoTClient | 61:8b85a4e797cf | 137 | if ((byteArray == NULL) && (size != 0)) |
AzureIoTClient | 0:e393db310d89 | 138 | { |
AzureIoTClient | 61:8b85a4e797cf | 139 | LogError("Invalid argument - byteArray is NULL"); |
AzureIoTClient | 61:8b85a4e797cf | 140 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 141 | } |
AzureIoTClient | 0:e393db310d89 | 142 | else |
AzureIoTClient | 0:e393db310d89 | 143 | { |
AzureIoTClient | 61:8b85a4e797cf | 144 | result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA)); |
AzureIoTClient | 61:8b85a4e797cf | 145 | if (result == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 146 | { |
AzureIoTClient | 61:8b85a4e797cf | 147 | LogError("unable to malloc"); |
AzureIoTClient | 61:8b85a4e797cf | 148 | /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */ |
AzureIoTClient | 61:8b85a4e797cf | 149 | /*let it go through*/ |
AzureIoTClient | 61:8b85a4e797cf | 150 | } |
AzureIoTClient | 61:8b85a4e797cf | 151 | else |
AzureIoTClient | 0:e393db310d89 | 152 | { |
AzureIoTClient | 61:8b85a4e797cf | 153 | const unsigned char* source; |
AzureIoTClient | 61:8b85a4e797cf | 154 | unsigned char temp = 0x00; |
AzureIoTClient | 78:74a8d3068204 | 155 | |
AzureIoTClient | 78:74a8d3068204 | 156 | memset(result, 0, sizeof(*result)); |
AzureIoTClient | 78:74a8d3068204 | 157 | /*Codes_SRS_IOTHUBMESSAGE_02_026: [The type of the new message shall be IOTHUBMESSAGE_BYTEARRAY.] */ |
AzureIoTClient | 78:74a8d3068204 | 158 | result->contentType = IOTHUBMESSAGE_BYTEARRAY; |
AzureIoTClient | 78:74a8d3068204 | 159 | |
AzureIoTClient | 61:8b85a4e797cf | 160 | if (size != 0) |
AzureIoTClient | 0:e393db310d89 | 161 | { |
AzureIoTClient | 61:8b85a4e797cf | 162 | /*Codes_SRS_IOTHUBMESSAGE_06_002: [If size is NOT zero then byteArray MUST NOT be NULL*/ |
AzureIoTClient | 61:8b85a4e797cf | 163 | if (byteArray == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 164 | { |
AzureIoTClient | 61:8b85a4e797cf | 165 | LogError("Attempted to create a Hub Message from a NULL pointer!"); |
AzureIoTClient | 78:74a8d3068204 | 166 | DestroyMessageData(result); |
AzureIoTClient | 61:8b85a4e797cf | 167 | result = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 168 | source = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 169 | } |
AzureIoTClient | 61:8b85a4e797cf | 170 | else |
AzureIoTClient | 61:8b85a4e797cf | 171 | { |
AzureIoTClient | 61:8b85a4e797cf | 172 | source = byteArray; |
AzureIoTClient | 61:8b85a4e797cf | 173 | } |
AzureIoTClient | 0:e393db310d89 | 174 | } |
AzureIoTClient | 0:e393db310d89 | 175 | else |
AzureIoTClient | 0:e393db310d89 | 176 | { |
AzureIoTClient | 61:8b85a4e797cf | 177 | /*Codes_SRS_IOTHUBMESSAGE_06_001: [If size is zero then byteArray may be NULL.]*/ |
AzureIoTClient | 61:8b85a4e797cf | 178 | source = &temp; |
AzureIoTClient | 0:e393db310d89 | 179 | } |
AzureIoTClient | 61:8b85a4e797cf | 180 | if (result != NULL) |
AzureIoTClient | 61:8b85a4e797cf | 181 | { |
AzureIoTClient | 61:8b85a4e797cf | 182 | /*Codes_SRS_IOTHUBMESSAGE_02_022: [IoTHubMessage_CreateFromByteArray shall call BUFFER_create passing byteArray and size as parameters.] */ |
AzureIoTClient | 61:8b85a4e797cf | 183 | if ((result->value.byteArray = BUFFER_create(source, size)) == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 184 | { |
AzureIoTClient | 61:8b85a4e797cf | 185 | LogError("BUFFER_create failed"); |
AzureIoTClient | 61:8b85a4e797cf | 186 | /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */ |
AzureIoTClient | 78:74a8d3068204 | 187 | DestroyMessageData(result); |
AzureIoTClient | 61:8b85a4e797cf | 188 | result = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 189 | } |
AzureIoTClient | 61:8b85a4e797cf | 190 | /*Codes_SRS_IOTHUBMESSAGE_02_023: [IoTHubMessage_CreateFromByteArray shall call Map_Create to create the message properties.] */ |
AzureIoTClient | 61:8b85a4e797cf | 191 | else if ((result->properties = Map_Create(ValidateAsciiCharactersFilter)) == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 192 | { |
AzureIoTClient | 77:e4e36df9caee | 193 | LogError("Map_Create for properties failed"); |
AzureIoTClient | 61:8b85a4e797cf | 194 | /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */ |
AzureIoTClient | 78:74a8d3068204 | 195 | DestroyMessageData(result); |
AzureIoTClient | 61:8b85a4e797cf | 196 | result = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 197 | } |
AzureIoTClient | 78:74a8d3068204 | 198 | /*Codes_SRS_IOTHUBMESSAGE_02_025: [Otherwise, IoTHubMessage_CreateFromByteArray shall return a non-NULL handle.] */ |
AzureIoTClient | 61:8b85a4e797cf | 199 | } |
AzureIoTClient | 61:8b85a4e797cf | 200 | } |
AzureIoTClient | 61:8b85a4e797cf | 201 | } |
AzureIoTClient | 61:8b85a4e797cf | 202 | return result; |
AzureIoTClient | 61:8b85a4e797cf | 203 | } |
AzureIoTClient | 61:8b85a4e797cf | 204 | |
AzureIoTClient | 61:8b85a4e797cf | 205 | IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromString(const char* source) |
AzureIoTClient | 61:8b85a4e797cf | 206 | { |
AzureIoTClient | 61:8b85a4e797cf | 207 | IOTHUB_MESSAGE_HANDLE_DATA* result; |
AzureIoTClient | 61:8b85a4e797cf | 208 | if (source == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 209 | { |
AzureIoTClient | 61:8b85a4e797cf | 210 | LogError("Invalid argument - source is NULL"); |
AzureIoTClient | 61:8b85a4e797cf | 211 | result = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 212 | } |
AzureIoTClient | 61:8b85a4e797cf | 213 | else |
AzureIoTClient | 61:8b85a4e797cf | 214 | { |
AzureIoTClient | 61:8b85a4e797cf | 215 | result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA)); |
AzureIoTClient | 61:8b85a4e797cf | 216 | if (result == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 217 | { |
AzureIoTClient | 61:8b85a4e797cf | 218 | LogError("malloc failed"); |
AzureIoTClient | 61:8b85a4e797cf | 219 | /*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 | 220 | /*let it go through*/ |
AzureIoTClient | 0:e393db310d89 | 221 | } |
AzureIoTClient | 0:e393db310d89 | 222 | else |
AzureIoTClient | 0:e393db310d89 | 223 | { |
AzureIoTClient | 78:74a8d3068204 | 224 | memset(result, 0, sizeof(*result)); |
AzureIoTClient | 78:74a8d3068204 | 225 | /*Codes_SRS_IOTHUBMESSAGE_02_032: [The type of the new message shall be IOTHUBMESSAGE_STRING.] */ |
AzureIoTClient | 78:74a8d3068204 | 226 | result->contentType = IOTHUBMESSAGE_STRING; |
AzureIoTClient | 78:74a8d3068204 | 227 | |
AzureIoTClient | 61:8b85a4e797cf | 228 | /*Codes_SRS_IOTHUBMESSAGE_02_027: [IoTHubMessage_CreateFromString shall call STRING_construct passing source as parameter.] */ |
AzureIoTClient | 61:8b85a4e797cf | 229 | if ((result->value.string = STRING_construct(source)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 230 | { |
AzureIoTClient | 61:8b85a4e797cf | 231 | LogError("STRING_construct failed"); |
AzureIoTClient | 61:8b85a4e797cf | 232 | /*Codes_SRS_IOTHUBMESSAGE_02_029: [If there are any encountered in the execution of IoTHubMessage_CreateFromString then IoTHubMessage_CreateFromString shall return NULL.] */ |
AzureIoTClient | 78:74a8d3068204 | 233 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 234 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 235 | } |
AzureIoTClient | 61:8b85a4e797cf | 236 | /*Codes_SRS_IOTHUBMESSAGE_02_028: [IoTHubMessage_CreateFromString shall call Map_Create to create the message properties.] */ |
AzureIoTClient | 0:e393db310d89 | 237 | else if ((result->properties = Map_Create(ValidateAsciiCharactersFilter)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 238 | { |
AzureIoTClient | 77:e4e36df9caee | 239 | LogError("Map_Create for properties failed"); |
AzureIoTClient | 61:8b85a4e797cf | 240 | /*Codes_SRS_IOTHUBMESSAGE_02_029: [If there are any encountered in the execution of IoTHubMessage_CreateFromString then IoTHubMessage_CreateFromString shall return NULL.] */ |
AzureIoTClient | 78:74a8d3068204 | 241 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 242 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 243 | } |
AzureIoTClient | 78:74a8d3068204 | 244 | /*Codes_SRS_IOTHUBMESSAGE_02_031: [Otherwise, IoTHubMessage_CreateFromString shall return a non-NULL handle.] */ |
AzureIoTClient | 0:e393db310d89 | 245 | } |
AzureIoTClient | 0:e393db310d89 | 246 | } |
AzureIoTClient | 0:e393db310d89 | 247 | return result; |
AzureIoTClient | 0:e393db310d89 | 248 | } |
AzureIoTClient | 0:e393db310d89 | 249 | |
AzureIoTClient | 0:e393db310d89 | 250 | /*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 | 251 | IOTHUB_MESSAGE_HANDLE IoTHubMessage_Clone(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 252 | { |
AzureIoTClient | 0:e393db310d89 | 253 | IOTHUB_MESSAGE_HANDLE_DATA* result; |
AzureIoTClient | 0:e393db310d89 | 254 | const IOTHUB_MESSAGE_HANDLE_DATA* source = (const IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 0:e393db310d89 | 255 | /* Codes_SRS_IOTHUBMESSAGE_03_005: [IoTHubMessage_Clone shall return NULL if iotHubMessageHandle is NULL.] */ |
AzureIoTClient | 0:e393db310d89 | 256 | if (source == NULL) |
AzureIoTClient | 0:e393db310d89 | 257 | { |
AzureIoTClient | 0:e393db310d89 | 258 | result = NULL; |
AzureIoTClient | 39:2719651a5bee | 259 | LogError("iotHubMessageHandle parameter cannot be NULL for IoTHubMessage_Clone"); |
AzureIoTClient | 0:e393db310d89 | 260 | } |
AzureIoTClient | 0:e393db310d89 | 261 | else |
AzureIoTClient | 0:e393db310d89 | 262 | { |
AzureIoTClient | 0:e393db310d89 | 263 | result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA)); |
AzureIoTClient | 0:e393db310d89 | 264 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 0:e393db310d89 | 265 | if (result == NULL) |
AzureIoTClient | 0:e393db310d89 | 266 | { |
AzureIoTClient | 0:e393db310d89 | 267 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 0:e393db310d89 | 268 | /*do nothing and return as is*/ |
AzureIoTClient | 39:2719651a5bee | 269 | LogError("unable to malloc"); |
AzureIoTClient | 0:e393db310d89 | 270 | } |
AzureIoTClient | 0:e393db310d89 | 271 | else |
AzureIoTClient | 0:e393db310d89 | 272 | { |
AzureIoTClient | 78:74a8d3068204 | 273 | memset(result, 0, sizeof(*result)); |
AzureIoTClient | 78:74a8d3068204 | 274 | result->contentType = source->contentType; |
AzureIoTClient | 74:ea0021abecf7 | 275 | |
AzureIoTClient | 18:1e9adb15c645 | 276 | if (source->messageId != NULL && mallocAndStrcpy_s(&result->messageId, source->messageId) != 0) |
AzureIoTClient | 18:1e9adb15c645 | 277 | { |
AzureIoTClient | 39:2719651a5bee | 278 | LogError("unable to Copy messageId"); |
AzureIoTClient | 78:74a8d3068204 | 279 | DestroyMessageData(result); |
AzureIoTClient | 18:1e9adb15c645 | 280 | result = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 281 | } |
AzureIoTClient | 18:1e9adb15c645 | 282 | else if (source->correlationId != NULL && mallocAndStrcpy_s(&result->correlationId, source->correlationId) != 0) |
AzureIoTClient | 18:1e9adb15c645 | 283 | { |
AzureIoTClient | 39:2719651a5bee | 284 | LogError("unable to Copy correlationId"); |
AzureIoTClient | 78:74a8d3068204 | 285 | DestroyMessageData(result); |
AzureIoTClient | 74:ea0021abecf7 | 286 | result = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 287 | } |
AzureIoTClient | 74:ea0021abecf7 | 288 | else if (source->userDefinedContentType != NULL && mallocAndStrcpy_s(&result->userDefinedContentType, source->userDefinedContentType) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 289 | { |
AzureIoTClient | 74:ea0021abecf7 | 290 | LogError("unable to copy contentType"); |
AzureIoTClient | 78:74a8d3068204 | 291 | DestroyMessageData(result); |
AzureIoTClient | 74:ea0021abecf7 | 292 | result = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 293 | } |
AzureIoTClient | 74:ea0021abecf7 | 294 | else if (source->contentEncoding != NULL && mallocAndStrcpy_s(&result->contentEncoding, source->contentEncoding) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 295 | { |
AzureIoTClient | 74:ea0021abecf7 | 296 | LogError("unable to copy contentEncoding"); |
AzureIoTClient | 78:74a8d3068204 | 297 | DestroyMessageData(result); |
AzureIoTClient | 18:1e9adb15c645 | 298 | result = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 299 | } |
AzureIoTClient | 77:e4e36df9caee | 300 | else if (source->diagnosticData != NULL && (result->diagnosticData = CloneDiagnosticPropertyData(source->diagnosticData)) == NULL) |
AzureIoTClient | 77:e4e36df9caee | 301 | { |
AzureIoTClient | 77:e4e36df9caee | 302 | LogError("unable to CloneDiagnosticPropertyData"); |
AzureIoTClient | 78:74a8d3068204 | 303 | DestroyMessageData(result); |
AzureIoTClient | 77:e4e36df9caee | 304 | result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 305 | } |
AzureIoTClient | 18:1e9adb15c645 | 306 | else if (source->contentType == IOTHUBMESSAGE_BYTEARRAY) |
AzureIoTClient | 0:e393db310d89 | 307 | { |
AzureIoTClient | 0:e393db310d89 | 308 | /*Codes_SRS_IOTHUBMESSAGE_02_006: [IoTHubMessage_Clone shall clone to content by a call to BUFFER_clone] */ |
AzureIoTClient | 0:e393db310d89 | 309 | if ((result->value.byteArray = BUFFER_clone(source->value.byteArray)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 310 | { |
AzureIoTClient | 0:e393db310d89 | 311 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 39:2719651a5bee | 312 | LogError("unable to BUFFER_clone"); |
AzureIoTClient | 78:74a8d3068204 | 313 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 314 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 315 | } |
AzureIoTClient | 0:e393db310d89 | 316 | /*Codes_SRS_IOTHUBMESSAGE_02_005: [IoTHubMessage_Clone shall clone the properties map by using Map_Clone.] */ |
AzureIoTClient | 0:e393db310d89 | 317 | else if ((result->properties = Map_Clone(source->properties)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 318 | { |
AzureIoTClient | 0:e393db310d89 | 319 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 39:2719651a5bee | 320 | LogError("unable to Map_Clone"); |
AzureIoTClient | 78:74a8d3068204 | 321 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 322 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 323 | } |
AzureIoTClient | 78:74a8d3068204 | 324 | /*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 | 325 | } |
AzureIoTClient | 0:e393db310d89 | 326 | else /*can only be STRING*/ |
AzureIoTClient | 0:e393db310d89 | 327 | { |
AzureIoTClient | 0:e393db310d89 | 328 | /*Codes_SRS_IOTHUBMESSAGE_02_006: [IoTHubMessage_Clone shall clone the content by a call to BUFFER_clone or STRING_clone] */ |
AzureIoTClient | 0:e393db310d89 | 329 | if ((result->value.string = STRING_clone(source->value.string)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 330 | { |
AzureIoTClient | 0:e393db310d89 | 331 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 78:74a8d3068204 | 332 | LogError("failed to STRING_clone"); |
AzureIoTClient | 78:74a8d3068204 | 333 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 334 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 335 | } |
AzureIoTClient | 0:e393db310d89 | 336 | /*Codes_SRS_IOTHUBMESSAGE_02_005: [IoTHubMessage_Clone shall clone the properties map by using Map_Clone.] */ |
AzureIoTClient | 0:e393db310d89 | 337 | else if ((result->properties = Map_Clone(source->properties)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 338 | { |
AzureIoTClient | 0:e393db310d89 | 339 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 39:2719651a5bee | 340 | LogError("unable to Map_Clone"); |
AzureIoTClient | 78:74a8d3068204 | 341 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 342 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 343 | } |
AzureIoTClient | 0:e393db310d89 | 344 | } |
AzureIoTClient | 0:e393db310d89 | 345 | } |
AzureIoTClient | 0:e393db310d89 | 346 | } |
AzureIoTClient | 0:e393db310d89 | 347 | return result; |
AzureIoTClient | 0:e393db310d89 | 348 | } |
AzureIoTClient | 0:e393db310d89 | 349 | |
AzureIoTClient | 0:e393db310d89 | 350 | IOTHUB_MESSAGE_RESULT IoTHubMessage_GetByteArray(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const unsigned char** buffer, size_t* size) |
AzureIoTClient | 0:e393db310d89 | 351 | { |
AzureIoTClient | 0:e393db310d89 | 352 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 0:e393db310d89 | 353 | if ( |
AzureIoTClient | 0:e393db310d89 | 354 | (iotHubMessageHandle == NULL) || |
AzureIoTClient | 0:e393db310d89 | 355 | (buffer == NULL) || |
AzureIoTClient | 0:e393db310d89 | 356 | (size == NULL) |
AzureIoTClient | 0:e393db310d89 | 357 | ) |
AzureIoTClient | 0:e393db310d89 | 358 | { |
AzureIoTClient | 0:e393db310d89 | 359 | /*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 | 360 | 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 | 361 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 0:e393db310d89 | 362 | } |
AzureIoTClient | 0:e393db310d89 | 363 | else |
AzureIoTClient | 0:e393db310d89 | 364 | { |
AzureIoTClient | 0:e393db310d89 | 365 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 0:e393db310d89 | 366 | if (handleData->contentType != IOTHUBMESSAGE_BYTEARRAY) |
AzureIoTClient | 0:e393db310d89 | 367 | { |
AzureIoTClient | 0:e393db310d89 | 368 | /*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 | 369 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 39:2719651a5bee | 370 | LogError("invalid type of message %s", ENUM_TO_STRING(IOTHUBMESSAGE_CONTENT_TYPE, handleData->contentType)); |
AzureIoTClient | 0:e393db310d89 | 371 | } |
AzureIoTClient | 0:e393db310d89 | 372 | else |
AzureIoTClient | 0:e393db310d89 | 373 | { |
AzureIoTClient | 0:e393db310d89 | 374 | /*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 | 375 | *buffer = BUFFER_u_char(handleData->value.byteArray); |
AzureIoTClient | 0:e393db310d89 | 376 | /*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 | 377 | *size = BUFFER_length(handleData->value.byteArray); |
AzureIoTClient | 0:e393db310d89 | 378 | result = IOTHUB_MESSAGE_OK; |
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 | const char* IoTHubMessage_GetString(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 385 | { |
AzureIoTClient | 0:e393db310d89 | 386 | const char* result; |
AzureIoTClient | 0:e393db310d89 | 387 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 0:e393db310d89 | 388 | { |
AzureIoTClient | 0:e393db310d89 | 389 | /*Codes_SRS_IOTHUBMESSAGE_02_016: [If any parameter is NULL then IoTHubMessage_GetString shall return NULL.] */ |
AzureIoTClient | 0:e393db310d89 | 390 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 391 | } |
AzureIoTClient | 0:e393db310d89 | 392 | else |
AzureIoTClient | 0:e393db310d89 | 393 | { |
AzureIoTClient | 0:e393db310d89 | 394 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 0:e393db310d89 | 395 | if (handleData->contentType != IOTHUBMESSAGE_STRING) |
AzureIoTClient | 0:e393db310d89 | 396 | { |
AzureIoTClient | 0:e393db310d89 | 397 | /*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 | 398 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 399 | } |
AzureIoTClient | 0:e393db310d89 | 400 | else |
AzureIoTClient | 0:e393db310d89 | 401 | { |
AzureIoTClient | 0:e393db310d89 | 402 | /*Codes_SRS_IOTHUBMESSAGE_02_018: [IoTHubMessage_GetStringData shall return the currently stored null terminated string.] */ |
AzureIoTClient | 0:e393db310d89 | 403 | result = STRING_c_str(handleData->value.string); |
AzureIoTClient | 0:e393db310d89 | 404 | } |
AzureIoTClient | 0:e393db310d89 | 405 | } |
AzureIoTClient | 0:e393db310d89 | 406 | return result; |
AzureIoTClient | 0:e393db310d89 | 407 | } |
AzureIoTClient | 0:e393db310d89 | 408 | |
AzureIoTClient | 0:e393db310d89 | 409 | IOTHUBMESSAGE_CONTENT_TYPE IoTHubMessage_GetContentType(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 410 | { |
AzureIoTClient | 0:e393db310d89 | 411 | IOTHUBMESSAGE_CONTENT_TYPE result; |
AzureIoTClient | 0:e393db310d89 | 412 | /*Codes_SRS_IOTHUBMESSAGE_02_008: [If any parameter is NULL then IoTHubMessage_GetContentType shall return IOTHUBMESSAGE_UNKNOWN.] */ |
AzureIoTClient | 0:e393db310d89 | 413 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 0:e393db310d89 | 414 | { |
AzureIoTClient | 0:e393db310d89 | 415 | result = IOTHUBMESSAGE_UNKNOWN; |
AzureIoTClient | 0:e393db310d89 | 416 | } |
AzureIoTClient | 0:e393db310d89 | 417 | else |
AzureIoTClient | 0:e393db310d89 | 418 | { |
AzureIoTClient | 0:e393db310d89 | 419 | /*Codes_SRS_IOTHUBMESSAGE_02_009: [Otherwise IoTHubMessage_GetContentType shall return the type of the message.] */ |
AzureIoTClient | 0:e393db310d89 | 420 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 0:e393db310d89 | 421 | result = handleData->contentType; |
AzureIoTClient | 0:e393db310d89 | 422 | } |
AzureIoTClient | 0:e393db310d89 | 423 | return result; |
AzureIoTClient | 0:e393db310d89 | 424 | } |
AzureIoTClient | 0:e393db310d89 | 425 | |
AzureIoTClient | 0:e393db310d89 | 426 | MAP_HANDLE IoTHubMessage_Properties(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 427 | { |
AzureIoTClient | 0:e393db310d89 | 428 | MAP_HANDLE result; |
AzureIoTClient | 0:e393db310d89 | 429 | /*Codes_SRS_IOTHUBMESSAGE_02_001: [If iotHubMessageHandle is NULL then IoTHubMessage_Properties shall return NULL.]*/ |
AzureIoTClient | 0:e393db310d89 | 430 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 0:e393db310d89 | 431 | { |
AzureIoTClient | 39:2719651a5bee | 432 | LogError("invalid arg (NULL) passed to IoTHubMessage_Properties"); |
AzureIoTClient | 18:1e9adb15c645 | 433 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 434 | } |
AzureIoTClient | 0:e393db310d89 | 435 | else |
AzureIoTClient | 0:e393db310d89 | 436 | { |
AzureIoTClient | 0:e393db310d89 | 437 | /*Codes_SRS_IOTHUBMESSAGE_02_002: [Otherwise, for any non-NULL iotHubMessageHandle it shall return a non-NULL MAP_HANDLE.]*/ |
AzureIoTClient | 0:e393db310d89 | 438 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 0:e393db310d89 | 439 | result = handleData->properties; |
AzureIoTClient | 0:e393db310d89 | 440 | } |
AzureIoTClient | 0:e393db310d89 | 441 | return result; |
AzureIoTClient | 0:e393db310d89 | 442 | } |
AzureIoTClient | 0:e393db310d89 | 443 | |
AzureIoTClient | 18:1e9adb15c645 | 444 | const char* IoTHubMessage_GetCorrelationId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 18:1e9adb15c645 | 445 | { |
AzureIoTClient | 18:1e9adb15c645 | 446 | const char* result; |
AzureIoTClient | 18:1e9adb15c645 | 447 | /* Codes_SRS_IOTHUBMESSAGE_07_016: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetCorrelationId shall return a NULL value.] */ |
AzureIoTClient | 18:1e9adb15c645 | 448 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 449 | { |
AzureIoTClient | 39:2719651a5bee | 450 | LogError("invalid arg (NULL) passed to IoTHubMessage_GetCorrelationId"); |
AzureIoTClient | 18:1e9adb15c645 | 451 | result = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 452 | } |
AzureIoTClient | 18:1e9adb15c645 | 453 | else |
AzureIoTClient | 18:1e9adb15c645 | 454 | { |
AzureIoTClient | 18:1e9adb15c645 | 455 | /* Codes_SRS_IOTHUBMESSAGE_07_017: [IoTHubMessage_GetCorrelationId shall return the correlationId as a const char*.] */ |
AzureIoTClient | 18:1e9adb15c645 | 456 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 457 | result = handleData->correlationId; |
AzureIoTClient | 18:1e9adb15c645 | 458 | } |
AzureIoTClient | 18:1e9adb15c645 | 459 | return result; |
AzureIoTClient | 18:1e9adb15c645 | 460 | } |
AzureIoTClient | 18:1e9adb15c645 | 461 | |
AzureIoTClient | 18:1e9adb15c645 | 462 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetCorrelationId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* correlationId) |
AzureIoTClient | 18:1e9adb15c645 | 463 | { |
AzureIoTClient | 18:1e9adb15c645 | 464 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 18:1e9adb15c645 | 465 | /* 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 | 466 | if (iotHubMessageHandle == NULL || correlationId == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 467 | { |
AzureIoTClient | 39:2719651a5bee | 468 | LogError("invalid arg (NULL) passed to IoTHubMessage_SetCorrelationId"); |
AzureIoTClient | 18:1e9adb15c645 | 469 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 18:1e9adb15c645 | 470 | } |
AzureIoTClient | 18:1e9adb15c645 | 471 | else |
AzureIoTClient | 18:1e9adb15c645 | 472 | { |
AzureIoTClient | 18:1e9adb15c645 | 473 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 474 | /* 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 | 475 | if (handleData->correlationId != NULL) |
AzureIoTClient | 18:1e9adb15c645 | 476 | { |
AzureIoTClient | 18:1e9adb15c645 | 477 | free(handleData->correlationId); |
AzureIoTClient | 74:ea0021abecf7 | 478 | handleData->correlationId = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 479 | } |
AzureIoTClient | 18:1e9adb15c645 | 480 | |
AzureIoTClient | 18:1e9adb15c645 | 481 | if (mallocAndStrcpy_s(&handleData->correlationId, correlationId) != 0) |
AzureIoTClient | 18:1e9adb15c645 | 482 | { |
AzureIoTClient | 18:1e9adb15c645 | 483 | /* 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 | 484 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 18:1e9adb15c645 | 485 | } |
AzureIoTClient | 18:1e9adb15c645 | 486 | else |
AzureIoTClient | 18:1e9adb15c645 | 487 | { |
AzureIoTClient | 18:1e9adb15c645 | 488 | /* Codes_SRS_IOTHUBMESSAGE_07_021: [IoTHubMessage_SetCorrelationId finishes successfully it shall return IOTHUB_MESSAGE_OK.] */ |
AzureIoTClient | 18:1e9adb15c645 | 489 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 18:1e9adb15c645 | 490 | } |
AzureIoTClient | 18:1e9adb15c645 | 491 | } |
AzureIoTClient | 18:1e9adb15c645 | 492 | return result; |
AzureIoTClient | 18:1e9adb15c645 | 493 | } |
AzureIoTClient | 18:1e9adb15c645 | 494 | |
AzureIoTClient | 18:1e9adb15c645 | 495 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetMessageId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* messageId) |
AzureIoTClient | 18:1e9adb15c645 | 496 | { |
AzureIoTClient | 18:1e9adb15c645 | 497 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 18:1e9adb15c645 | 498 | /* 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 | 499 | if (iotHubMessageHandle == NULL || messageId == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 500 | { |
AzureIoTClient | 39:2719651a5bee | 501 | LogError("invalid arg (NULL) passed to IoTHubMessage_SetMessageId"); |
AzureIoTClient | 18:1e9adb15c645 | 502 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 18:1e9adb15c645 | 503 | } |
AzureIoTClient | 18:1e9adb15c645 | 504 | else |
AzureIoTClient | 18:1e9adb15c645 | 505 | { |
AzureIoTClient | 18:1e9adb15c645 | 506 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 507 | /* 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 | 508 | if (handleData->messageId != NULL) |
AzureIoTClient | 18:1e9adb15c645 | 509 | { |
AzureIoTClient | 18:1e9adb15c645 | 510 | free(handleData->messageId); |
AzureIoTClient | 74:ea0021abecf7 | 511 | handleData->messageId = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 512 | } |
AzureIoTClient | 18:1e9adb15c645 | 513 | |
AzureIoTClient | 18:1e9adb15c645 | 514 | /* 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 | 515 | if (mallocAndStrcpy_s(&handleData->messageId, messageId) != 0) |
AzureIoTClient | 18:1e9adb15c645 | 516 | { |
AzureIoTClient | 18:1e9adb15c645 | 517 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 18:1e9adb15c645 | 518 | } |
AzureIoTClient | 18:1e9adb15c645 | 519 | else |
AzureIoTClient | 18:1e9adb15c645 | 520 | { |
AzureIoTClient | 18:1e9adb15c645 | 521 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 18:1e9adb15c645 | 522 | } |
AzureIoTClient | 18:1e9adb15c645 | 523 | } |
AzureIoTClient | 18:1e9adb15c645 | 524 | return result; |
AzureIoTClient | 18:1e9adb15c645 | 525 | } |
AzureIoTClient | 18:1e9adb15c645 | 526 | |
AzureIoTClient | 18:1e9adb15c645 | 527 | const char* IoTHubMessage_GetMessageId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 18:1e9adb15c645 | 528 | { |
AzureIoTClient | 18:1e9adb15c645 | 529 | const char* result; |
AzureIoTClient | 18:1e9adb15c645 | 530 | /* Codes_SRS_IOTHUBMESSAGE_07_010: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_MessageId shall return a NULL value.] */ |
AzureIoTClient | 18:1e9adb15c645 | 531 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 532 | { |
AzureIoTClient | 39:2719651a5bee | 533 | LogError("invalid arg (NULL) passed to IoTHubMessage_GetMessageId"); |
AzureIoTClient | 18:1e9adb15c645 | 534 | result = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 535 | } |
AzureIoTClient | 18:1e9adb15c645 | 536 | else |
AzureIoTClient | 18:1e9adb15c645 | 537 | { |
AzureIoTClient | 18:1e9adb15c645 | 538 | /* Codes_SRS_IOTHUBMESSAGE_07_011: [IoTHubMessage_MessageId shall return the messageId as a const char*.] */ |
AzureIoTClient | 18:1e9adb15c645 | 539 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 540 | result = handleData->messageId; |
AzureIoTClient | 18:1e9adb15c645 | 541 | } |
AzureIoTClient | 18:1e9adb15c645 | 542 | return result; |
AzureIoTClient | 18:1e9adb15c645 | 543 | } |
AzureIoTClient | 18:1e9adb15c645 | 544 | |
AzureIoTClient | 74:ea0021abecf7 | 545 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetContentTypeSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* contentType) |
AzureIoTClient | 74:ea0021abecf7 | 546 | { |
AzureIoTClient | 74:ea0021abecf7 | 547 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 74:ea0021abecf7 | 548 | |
AzureIoTClient | 74:ea0021abecf7 | 549 | // Codes_SRS_IOTHUBMESSAGE_09_001: [If any of the parameters are NULL then IoTHubMessage_SetContentTypeSystemProperty shall return a IOTHUB_MESSAGE_INVALID_ARG value.] |
AzureIoTClient | 74:ea0021abecf7 | 550 | if (iotHubMessageHandle == NULL || contentType == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 551 | { |
AzureIoTClient | 74:ea0021abecf7 | 552 | LogError("Invalid argument (iotHubMessageHandle=%p, contentType=%p)", iotHubMessageHandle, contentType); |
AzureIoTClient | 74:ea0021abecf7 | 553 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 74:ea0021abecf7 | 554 | } |
AzureIoTClient | 74:ea0021abecf7 | 555 | else |
AzureIoTClient | 74:ea0021abecf7 | 556 | { |
AzureIoTClient | 74:ea0021abecf7 | 557 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 558 | |
AzureIoTClient | 74:ea0021abecf7 | 559 | // Codes_SRS_IOTHUBMESSAGE_09_002: [If the IOTHUB_MESSAGE_HANDLE `contentType` is not NULL it shall be deallocated.] |
AzureIoTClient | 74:ea0021abecf7 | 560 | if (handleData->userDefinedContentType != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 561 | { |
AzureIoTClient | 74:ea0021abecf7 | 562 | free(handleData->userDefinedContentType); |
AzureIoTClient | 74:ea0021abecf7 | 563 | handleData->userDefinedContentType = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 564 | } |
AzureIoTClient | 74:ea0021abecf7 | 565 | |
AzureIoTClient | 74:ea0021abecf7 | 566 | if (mallocAndStrcpy_s(&handleData->userDefinedContentType, contentType) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 567 | { |
AzureIoTClient | 74:ea0021abecf7 | 568 | LogError("Failed saving a copy of contentType"); |
AzureIoTClient | 74:ea0021abecf7 | 569 | // Codes_SRS_IOTHUBMESSAGE_09_003: [If the allocation or the copying of `contentType` fails, then IoTHubMessage_SetContentTypeSystemProperty shall return IOTHUB_MESSAGE_ERROR.] |
AzureIoTClient | 74:ea0021abecf7 | 570 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 571 | } |
AzureIoTClient | 74:ea0021abecf7 | 572 | else |
AzureIoTClient | 74:ea0021abecf7 | 573 | { |
AzureIoTClient | 74:ea0021abecf7 | 574 | // Codes_SRS_IOTHUBMESSAGE_09_004: [If IoTHubMessage_SetContentTypeSystemProperty finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 74:ea0021abecf7 | 575 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 74:ea0021abecf7 | 576 | } |
AzureIoTClient | 74:ea0021abecf7 | 577 | } |
AzureIoTClient | 74:ea0021abecf7 | 578 | |
AzureIoTClient | 74:ea0021abecf7 | 579 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 580 | } |
AzureIoTClient | 74:ea0021abecf7 | 581 | |
AzureIoTClient | 74:ea0021abecf7 | 582 | const char* IoTHubMessage_GetContentTypeSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 74:ea0021abecf7 | 583 | { |
AzureIoTClient | 74:ea0021abecf7 | 584 | const char* result; |
AzureIoTClient | 74:ea0021abecf7 | 585 | |
AzureIoTClient | 74:ea0021abecf7 | 586 | // Codes_SRS_IOTHUBMESSAGE_09_005: [If any of the parameters are NULL then IoTHubMessage_GetContentTypeSystemProperty shall return a IOTHUB_MESSAGE_INVALID_ARG value.] |
AzureIoTClient | 74:ea0021abecf7 | 587 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 588 | { |
AzureIoTClient | 74:ea0021abecf7 | 589 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 74:ea0021abecf7 | 590 | result = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 591 | } |
AzureIoTClient | 74:ea0021abecf7 | 592 | else |
AzureIoTClient | 74:ea0021abecf7 | 593 | { |
AzureIoTClient | 74:ea0021abecf7 | 594 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 595 | |
AzureIoTClient | 74:ea0021abecf7 | 596 | // Codes_SRS_IOTHUBMESSAGE_09_006: [IoTHubMessage_GetContentTypeSystemProperty shall return the `contentType` as a const char* ] |
AzureIoTClient | 74:ea0021abecf7 | 597 | result = (const char*)handleData->userDefinedContentType; |
AzureIoTClient | 74:ea0021abecf7 | 598 | } |
AzureIoTClient | 74:ea0021abecf7 | 599 | |
AzureIoTClient | 74:ea0021abecf7 | 600 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 601 | } |
AzureIoTClient | 74:ea0021abecf7 | 602 | |
AzureIoTClient | 74:ea0021abecf7 | 603 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetContentEncodingSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* contentEncoding) |
AzureIoTClient | 74:ea0021abecf7 | 604 | { |
AzureIoTClient | 74:ea0021abecf7 | 605 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 74:ea0021abecf7 | 606 | |
AzureIoTClient | 74:ea0021abecf7 | 607 | // Codes_SRS_IOTHUBMESSAGE_09_006: [If any of the parameters are NULL then IoTHubMessage_SetContentEncodingSystemProperty shall return a IOTHUB_MESSAGE_INVALID_ARG value.] |
AzureIoTClient | 74:ea0021abecf7 | 608 | if (iotHubMessageHandle == NULL || contentEncoding == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 609 | { |
AzureIoTClient | 74:ea0021abecf7 | 610 | LogError("Invalid argument (iotHubMessageHandle=%p, contentEncoding=%p)", iotHubMessageHandle, contentEncoding); |
AzureIoTClient | 74:ea0021abecf7 | 611 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 74:ea0021abecf7 | 612 | } |
AzureIoTClient | 74:ea0021abecf7 | 613 | else |
AzureIoTClient | 74:ea0021abecf7 | 614 | { |
AzureIoTClient | 74:ea0021abecf7 | 615 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 616 | |
AzureIoTClient | 74:ea0021abecf7 | 617 | // Codes_SRS_IOTHUBMESSAGE_09_007: [If the IOTHUB_MESSAGE_HANDLE `contentEncoding` is not NULL it shall be deallocated.] |
AzureIoTClient | 74:ea0021abecf7 | 618 | if (handleData->contentEncoding != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 619 | { |
AzureIoTClient | 74:ea0021abecf7 | 620 | free(handleData->contentEncoding); |
AzureIoTClient | 74:ea0021abecf7 | 621 | handleData->contentEncoding = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 622 | } |
AzureIoTClient | 74:ea0021abecf7 | 623 | |
AzureIoTClient | 74:ea0021abecf7 | 624 | if (mallocAndStrcpy_s(&handleData->contentEncoding, contentEncoding) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 625 | { |
AzureIoTClient | 74:ea0021abecf7 | 626 | LogError("Failed saving a copy of contentEncoding"); |
AzureIoTClient | 74:ea0021abecf7 | 627 | // Codes_SRS_IOTHUBMESSAGE_09_008: [If the allocation or the copying of `contentEncoding` fails, then IoTHubMessage_SetContentEncodingSystemProperty shall return IOTHUB_MESSAGE_ERROR.] |
AzureIoTClient | 74:ea0021abecf7 | 628 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 629 | } |
AzureIoTClient | 74:ea0021abecf7 | 630 | else |
AzureIoTClient | 74:ea0021abecf7 | 631 | { |
AzureIoTClient | 74:ea0021abecf7 | 632 | // Codes_SRS_IOTHUBMESSAGE_09_009: [If IoTHubMessage_SetContentEncodingSystemProperty finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 74:ea0021abecf7 | 633 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 74:ea0021abecf7 | 634 | } |
AzureIoTClient | 74:ea0021abecf7 | 635 | } |
AzureIoTClient | 74:ea0021abecf7 | 636 | |
AzureIoTClient | 74:ea0021abecf7 | 637 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 638 | } |
AzureIoTClient | 74:ea0021abecf7 | 639 | |
AzureIoTClient | 74:ea0021abecf7 | 640 | const char* IoTHubMessage_GetContentEncodingSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 74:ea0021abecf7 | 641 | { |
AzureIoTClient | 74:ea0021abecf7 | 642 | const char* result; |
AzureIoTClient | 74:ea0021abecf7 | 643 | |
AzureIoTClient | 74:ea0021abecf7 | 644 | // Codes_SRS_IOTHUBMESSAGE_09_010: [If any of the parameters are NULL then IoTHubMessage_GetContentEncodingSystemProperty shall return a IOTHUB_MESSAGE_INVALID_ARG value.] |
AzureIoTClient | 74:ea0021abecf7 | 645 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 646 | { |
AzureIoTClient | 74:ea0021abecf7 | 647 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 74:ea0021abecf7 | 648 | result = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 649 | } |
AzureIoTClient | 74:ea0021abecf7 | 650 | else |
AzureIoTClient | 74:ea0021abecf7 | 651 | { |
AzureIoTClient | 74:ea0021abecf7 | 652 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 653 | |
AzureIoTClient | 74:ea0021abecf7 | 654 | // Codes_SRS_IOTHUBMESSAGE_09_011: [IoTHubMessage_GetContentEncodingSystemProperty shall return the `contentEncoding` as a const char* ] |
AzureIoTClient | 74:ea0021abecf7 | 655 | result = (const char*)handleData->contentEncoding; |
AzureIoTClient | 74:ea0021abecf7 | 656 | } |
AzureIoTClient | 74:ea0021abecf7 | 657 | |
AzureIoTClient | 74:ea0021abecf7 | 658 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 659 | } |
AzureIoTClient | 74:ea0021abecf7 | 660 | |
AzureIoTClient | 77:e4e36df9caee | 661 | const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* IoTHubMessage_GetDiagnosticPropertyData(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 77:e4e36df9caee | 662 | { |
AzureIoTClient | 77:e4e36df9caee | 663 | const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* result; |
AzureIoTClient | 77:e4e36df9caee | 664 | // Codes_SRS_IOTHUBMESSAGE_10_001: [If any of the parameters are NULL then IoTHubMessage_GetDiagnosticPropertyData shall return a NULL value.] |
AzureIoTClient | 77:e4e36df9caee | 665 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 77:e4e36df9caee | 666 | { |
AzureIoTClient | 77:e4e36df9caee | 667 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 77:e4e36df9caee | 668 | result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 669 | } |
AzureIoTClient | 77:e4e36df9caee | 670 | else |
AzureIoTClient | 77:e4e36df9caee | 671 | { |
AzureIoTClient | 77:e4e36df9caee | 672 | /* Codes_SRS_IOTHUBMESSAGE_10_002: [IoTHubMessage_GetDiagnosticPropertyData shall return the diagnosticData as a const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*.] */ |
AzureIoTClient | 77:e4e36df9caee | 673 | result = iotHubMessageHandle->diagnosticData; |
AzureIoTClient | 77:e4e36df9caee | 674 | } |
AzureIoTClient | 77:e4e36df9caee | 675 | return result; |
AzureIoTClient | 77:e4e36df9caee | 676 | } |
AzureIoTClient | 77:e4e36df9caee | 677 | |
AzureIoTClient | 77:e4e36df9caee | 678 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetDiagnosticPropertyData(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* diagnosticData) |
AzureIoTClient | 77:e4e36df9caee | 679 | { |
AzureIoTClient | 77:e4e36df9caee | 680 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 77:e4e36df9caee | 681 | // Codes_SRS_IOTHUBMESSAGE_10_003: [If any of the parameters are NULL then IoTHubMessage_SetDiagnosticId shall return a IOTHUB_MESSAGE_INVALID_ARG value.] |
AzureIoTClient | 77:e4e36df9caee | 682 | if (iotHubMessageHandle == NULL || |
AzureIoTClient | 77:e4e36df9caee | 683 | diagnosticData == NULL || |
AzureIoTClient | 77:e4e36df9caee | 684 | diagnosticData->diagnosticCreationTimeUtc == NULL || |
AzureIoTClient | 77:e4e36df9caee | 685 | diagnosticData->diagnosticId == NULL) |
AzureIoTClient | 77:e4e36df9caee | 686 | { |
AzureIoTClient | 77:e4e36df9caee | 687 | LogError("Invalid argument (iotHubMessageHandle=%p, diagnosticData=%p, diagnosticData->diagnosticId=%p, diagnosticData->diagnosticCreationTimeUtc=%p)", |
AzureIoTClient | 77:e4e36df9caee | 688 | iotHubMessageHandle, diagnosticData, |
AzureIoTClient | 77:e4e36df9caee | 689 | diagnosticData == NULL ? NULL : diagnosticData->diagnosticId, |
AzureIoTClient | 77:e4e36df9caee | 690 | diagnosticData == NULL ? NULL : diagnosticData->diagnosticCreationTimeUtc); |
AzureIoTClient | 77:e4e36df9caee | 691 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 77:e4e36df9caee | 692 | } |
AzureIoTClient | 77:e4e36df9caee | 693 | else |
AzureIoTClient | 77:e4e36df9caee | 694 | { |
AzureIoTClient | 77:e4e36df9caee | 695 | // Codes_SRS_IOTHUBMESSAGE_10_004: [If the IOTHUB_MESSAGE_HANDLE `diagnosticData` is not NULL it shall be deallocated.] |
AzureIoTClient | 77:e4e36df9caee | 696 | if (iotHubMessageHandle->diagnosticData != NULL) |
AzureIoTClient | 77:e4e36df9caee | 697 | { |
AzureIoTClient | 77:e4e36df9caee | 698 | DestroyDiagnosticPropertyData(iotHubMessageHandle->diagnosticData); |
AzureIoTClient | 77:e4e36df9caee | 699 | iotHubMessageHandle->diagnosticData = NULL; |
AzureIoTClient | 77:e4e36df9caee | 700 | } |
AzureIoTClient | 77:e4e36df9caee | 701 | |
AzureIoTClient | 77:e4e36df9caee | 702 | // Codes_SRS_IOTHUBMESSAGE_10_005: [If the allocation or the copying of `diagnosticData` fails, then IoTHubMessage_SetDiagnosticPropertyData shall return IOTHUB_MESSAGE_ERROR.] |
AzureIoTClient | 77:e4e36df9caee | 703 | if ((iotHubMessageHandle->diagnosticData = CloneDiagnosticPropertyData(diagnosticData)) == NULL) |
AzureIoTClient | 77:e4e36df9caee | 704 | { |
AzureIoTClient | 77:e4e36df9caee | 705 | LogError("Failed saving a copy of diagnosticData"); |
AzureIoTClient | 77:e4e36df9caee | 706 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 77:e4e36df9caee | 707 | } |
AzureIoTClient | 77:e4e36df9caee | 708 | else |
AzureIoTClient | 77:e4e36df9caee | 709 | { |
AzureIoTClient | 77:e4e36df9caee | 710 | // Codes_SRS_IOTHUBMESSAGE_10_006: [If IoTHubMessage_SetDiagnosticPropertyData finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 77:e4e36df9caee | 711 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 77:e4e36df9caee | 712 | } |
AzureIoTClient | 77:e4e36df9caee | 713 | } |
AzureIoTClient | 77:e4e36df9caee | 714 | return result; |
AzureIoTClient | 77:e4e36df9caee | 715 | } |
AzureIoTClient | 77:e4e36df9caee | 716 | |
AzureIoTClient | 0:e393db310d89 | 717 | void IoTHubMessage_Destroy(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 718 | { |
AzureIoTClient | 0:e393db310d89 | 719 | /*Codes_SRS_IOTHUBMESSAGE_01_004: [If iotHubMessageHandle is NULL, IoTHubMessage_Destroy shall do nothing.] */ |
AzureIoTClient | 0:e393db310d89 | 720 | if (iotHubMessageHandle != NULL) |
AzureIoTClient | 0:e393db310d89 | 721 | { |
AzureIoTClient | 0:e393db310d89 | 722 | /*Codes_SRS_IOTHUBMESSAGE_01_003: [IoTHubMessage_Destroy shall free all resources associated with iotHubMessageHandle.] */ |
AzureIoTClient | 78:74a8d3068204 | 723 | DestroyMessageData((IOTHUB_MESSAGE_HANDLE_DATA* )iotHubMessageHandle); |
AzureIoTClient | 0:e393db310d89 | 724 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 725 | } |