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