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@88:248736be106e, 2018-06-11 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Mon Jun 11 15:39:23 2018 -0700
- Revision:
- 88:248736be106e
- Parent:
- 78:74a8d3068204
- Child:
- 89:a2ed767a532e
1.2.5
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 | 88:248736be106e | 444 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetProperty(IOTHUB_MESSAGE_HANDLE msg_handle, const char* key, const char* value) |
AzureIoTClient | 88:248736be106e | 445 | { |
AzureIoTClient | 88:248736be106e | 446 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 88:248736be106e | 447 | if (msg_handle == NULL || key == NULL || value == NULL) |
AzureIoTClient | 88:248736be106e | 448 | { |
AzureIoTClient | 88:248736be106e | 449 | LogError("invalid parameter (NULL) to IoTHubMessage_SetProperty iotHubMessageHandle=%p, key=%p, value=%p", msg_handle, key, value); |
AzureIoTClient | 88:248736be106e | 450 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 88:248736be106e | 451 | } |
AzureIoTClient | 88:248736be106e | 452 | else |
AzureIoTClient | 88:248736be106e | 453 | { |
AzureIoTClient | 88:248736be106e | 454 | if (Map_AddOrUpdate(msg_handle->properties, key, value) != MAP_OK) |
AzureIoTClient | 88:248736be106e | 455 | { |
AzureIoTClient | 88:248736be106e | 456 | LogError("Failure adding property to internal map"); |
AzureIoTClient | 88:248736be106e | 457 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 88:248736be106e | 458 | } |
AzureIoTClient | 88:248736be106e | 459 | else |
AzureIoTClient | 88:248736be106e | 460 | { |
AzureIoTClient | 88:248736be106e | 461 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 88:248736be106e | 462 | } |
AzureIoTClient | 88:248736be106e | 463 | } |
AzureIoTClient | 88:248736be106e | 464 | return result; |
AzureIoTClient | 88:248736be106e | 465 | } |
AzureIoTClient | 88:248736be106e | 466 | |
AzureIoTClient | 88:248736be106e | 467 | const char* IoTHubMessage_GetProperty(IOTHUB_MESSAGE_HANDLE msg_handle, const char* key) |
AzureIoTClient | 88:248736be106e | 468 | { |
AzureIoTClient | 88:248736be106e | 469 | const char* result; |
AzureIoTClient | 88:248736be106e | 470 | if (msg_handle == NULL || key == NULL) |
AzureIoTClient | 88:248736be106e | 471 | { |
AzureIoTClient | 88:248736be106e | 472 | LogError("invalid parameter (NULL) to IoTHubMessage_GetProperty iotHubMessageHandle=%p, key=%p", msg_handle, key); |
AzureIoTClient | 88:248736be106e | 473 | result = NULL; |
AzureIoTClient | 88:248736be106e | 474 | } |
AzureIoTClient | 88:248736be106e | 475 | else |
AzureIoTClient | 88:248736be106e | 476 | { |
AzureIoTClient | 88:248736be106e | 477 | bool key_exists = false; |
AzureIoTClient | 88:248736be106e | 478 | // The return value is not neccessary, just check the key_exist variable |
AzureIoTClient | 88:248736be106e | 479 | if ((Map_ContainsKey(msg_handle->properties, key, &key_exists) == MAP_OK) && key_exists) |
AzureIoTClient | 88:248736be106e | 480 | { |
AzureIoTClient | 88:248736be106e | 481 | result = Map_GetValueFromKey(msg_handle->properties, key); |
AzureIoTClient | 88:248736be106e | 482 | } |
AzureIoTClient | 88:248736be106e | 483 | else |
AzureIoTClient | 88:248736be106e | 484 | { |
AzureIoTClient | 88:248736be106e | 485 | result = NULL; |
AzureIoTClient | 88:248736be106e | 486 | } |
AzureIoTClient | 88:248736be106e | 487 | } |
AzureIoTClient | 88:248736be106e | 488 | return result; |
AzureIoTClient | 88:248736be106e | 489 | } |
AzureIoTClient | 88:248736be106e | 490 | |
AzureIoTClient | 18:1e9adb15c645 | 491 | const char* IoTHubMessage_GetCorrelationId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 18:1e9adb15c645 | 492 | { |
AzureIoTClient | 18:1e9adb15c645 | 493 | const char* result; |
AzureIoTClient | 18:1e9adb15c645 | 494 | /* Codes_SRS_IOTHUBMESSAGE_07_016: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetCorrelationId shall return a NULL value.] */ |
AzureIoTClient | 18:1e9adb15c645 | 495 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 496 | { |
AzureIoTClient | 39:2719651a5bee | 497 | LogError("invalid arg (NULL) passed to IoTHubMessage_GetCorrelationId"); |
AzureIoTClient | 18:1e9adb15c645 | 498 | result = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 499 | } |
AzureIoTClient | 18:1e9adb15c645 | 500 | else |
AzureIoTClient | 18:1e9adb15c645 | 501 | { |
AzureIoTClient | 18:1e9adb15c645 | 502 | /* Codes_SRS_IOTHUBMESSAGE_07_017: [IoTHubMessage_GetCorrelationId shall return the correlationId as a const char*.] */ |
AzureIoTClient | 18:1e9adb15c645 | 503 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 504 | result = handleData->correlationId; |
AzureIoTClient | 18:1e9adb15c645 | 505 | } |
AzureIoTClient | 18:1e9adb15c645 | 506 | return result; |
AzureIoTClient | 18:1e9adb15c645 | 507 | } |
AzureIoTClient | 18:1e9adb15c645 | 508 | |
AzureIoTClient | 18:1e9adb15c645 | 509 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetCorrelationId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* correlationId) |
AzureIoTClient | 18:1e9adb15c645 | 510 | { |
AzureIoTClient | 18:1e9adb15c645 | 511 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 18:1e9adb15c645 | 512 | /* 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 | 513 | if (iotHubMessageHandle == NULL || correlationId == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 514 | { |
AzureIoTClient | 39:2719651a5bee | 515 | LogError("invalid arg (NULL) passed to IoTHubMessage_SetCorrelationId"); |
AzureIoTClient | 18:1e9adb15c645 | 516 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 18:1e9adb15c645 | 517 | } |
AzureIoTClient | 18:1e9adb15c645 | 518 | else |
AzureIoTClient | 18:1e9adb15c645 | 519 | { |
AzureIoTClient | 18:1e9adb15c645 | 520 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 521 | /* 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 | 522 | if (handleData->correlationId != NULL) |
AzureIoTClient | 18:1e9adb15c645 | 523 | { |
AzureIoTClient | 18:1e9adb15c645 | 524 | free(handleData->correlationId); |
AzureIoTClient | 74:ea0021abecf7 | 525 | handleData->correlationId = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 526 | } |
AzureIoTClient | 18:1e9adb15c645 | 527 | |
AzureIoTClient | 18:1e9adb15c645 | 528 | if (mallocAndStrcpy_s(&handleData->correlationId, correlationId) != 0) |
AzureIoTClient | 18:1e9adb15c645 | 529 | { |
AzureIoTClient | 18:1e9adb15c645 | 530 | /* 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 | 531 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 18:1e9adb15c645 | 532 | } |
AzureIoTClient | 18:1e9adb15c645 | 533 | else |
AzureIoTClient | 18:1e9adb15c645 | 534 | { |
AzureIoTClient | 18:1e9adb15c645 | 535 | /* Codes_SRS_IOTHUBMESSAGE_07_021: [IoTHubMessage_SetCorrelationId finishes successfully it shall return IOTHUB_MESSAGE_OK.] */ |
AzureIoTClient | 18:1e9adb15c645 | 536 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 18:1e9adb15c645 | 537 | } |
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_SetMessageId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* messageId) |
AzureIoTClient | 18:1e9adb15c645 | 543 | { |
AzureIoTClient | 18:1e9adb15c645 | 544 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 18:1e9adb15c645 | 545 | /* 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 | 546 | if (iotHubMessageHandle == NULL || messageId == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 547 | { |
AzureIoTClient | 39:2719651a5bee | 548 | LogError("invalid arg (NULL) passed to IoTHubMessage_SetMessageId"); |
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_013: [If the IOTHUB_MESSAGE_HANDLE messageId is not NULL, then the IOTHUB_MESSAGE_HANDLE messageId will be freed] */ |
AzureIoTClient | 18:1e9adb15c645 | 555 | if (handleData->messageId != NULL) |
AzureIoTClient | 18:1e9adb15c645 | 556 | { |
AzureIoTClient | 18:1e9adb15c645 | 557 | free(handleData->messageId); |
AzureIoTClient | 74:ea0021abecf7 | 558 | handleData->messageId = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 559 | } |
AzureIoTClient | 18:1e9adb15c645 | 560 | |
AzureIoTClient | 18:1e9adb15c645 | 561 | /* 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 | 562 | if (mallocAndStrcpy_s(&handleData->messageId, messageId) != 0) |
AzureIoTClient | 18:1e9adb15c645 | 563 | { |
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 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 18:1e9adb15c645 | 569 | } |
AzureIoTClient | 18:1e9adb15c645 | 570 | } |
AzureIoTClient | 18:1e9adb15c645 | 571 | return result; |
AzureIoTClient | 18:1e9adb15c645 | 572 | } |
AzureIoTClient | 18:1e9adb15c645 | 573 | |
AzureIoTClient | 18:1e9adb15c645 | 574 | const char* IoTHubMessage_GetMessageId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 18:1e9adb15c645 | 575 | { |
AzureIoTClient | 18:1e9adb15c645 | 576 | const char* result; |
AzureIoTClient | 18:1e9adb15c645 | 577 | /* Codes_SRS_IOTHUBMESSAGE_07_010: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_MessageId shall return a NULL value.] */ |
AzureIoTClient | 18:1e9adb15c645 | 578 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 579 | { |
AzureIoTClient | 39:2719651a5bee | 580 | LogError("invalid arg (NULL) passed to IoTHubMessage_GetMessageId"); |
AzureIoTClient | 18:1e9adb15c645 | 581 | result = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 582 | } |
AzureIoTClient | 18:1e9adb15c645 | 583 | else |
AzureIoTClient | 18:1e9adb15c645 | 584 | { |
AzureIoTClient | 18:1e9adb15c645 | 585 | /* Codes_SRS_IOTHUBMESSAGE_07_011: [IoTHubMessage_MessageId shall return the messageId as a const char*.] */ |
AzureIoTClient | 18:1e9adb15c645 | 586 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 587 | result = handleData->messageId; |
AzureIoTClient | 18:1e9adb15c645 | 588 | } |
AzureIoTClient | 18:1e9adb15c645 | 589 | return result; |
AzureIoTClient | 18:1e9adb15c645 | 590 | } |
AzureIoTClient | 18:1e9adb15c645 | 591 | |
AzureIoTClient | 74:ea0021abecf7 | 592 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetContentTypeSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* contentType) |
AzureIoTClient | 74:ea0021abecf7 | 593 | { |
AzureIoTClient | 74:ea0021abecf7 | 594 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 74:ea0021abecf7 | 595 | |
AzureIoTClient | 74:ea0021abecf7 | 596 | // 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 | 597 | if (iotHubMessageHandle == NULL || contentType == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 598 | { |
AzureIoTClient | 74:ea0021abecf7 | 599 | LogError("Invalid argument (iotHubMessageHandle=%p, contentType=%p)", iotHubMessageHandle, contentType); |
AzureIoTClient | 74:ea0021abecf7 | 600 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 74:ea0021abecf7 | 601 | } |
AzureIoTClient | 74:ea0021abecf7 | 602 | else |
AzureIoTClient | 74:ea0021abecf7 | 603 | { |
AzureIoTClient | 74:ea0021abecf7 | 604 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 605 | |
AzureIoTClient | 74:ea0021abecf7 | 606 | // Codes_SRS_IOTHUBMESSAGE_09_002: [If the IOTHUB_MESSAGE_HANDLE `contentType` is not NULL it shall be deallocated.] |
AzureIoTClient | 74:ea0021abecf7 | 607 | if (handleData->userDefinedContentType != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 608 | { |
AzureIoTClient | 74:ea0021abecf7 | 609 | free(handleData->userDefinedContentType); |
AzureIoTClient | 74:ea0021abecf7 | 610 | handleData->userDefinedContentType = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 611 | } |
AzureIoTClient | 74:ea0021abecf7 | 612 | |
AzureIoTClient | 74:ea0021abecf7 | 613 | if (mallocAndStrcpy_s(&handleData->userDefinedContentType, contentType) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 614 | { |
AzureIoTClient | 74:ea0021abecf7 | 615 | LogError("Failed saving a copy of contentType"); |
AzureIoTClient | 74:ea0021abecf7 | 616 | // 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 | 617 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 618 | } |
AzureIoTClient | 74:ea0021abecf7 | 619 | else |
AzureIoTClient | 74:ea0021abecf7 | 620 | { |
AzureIoTClient | 74:ea0021abecf7 | 621 | // Codes_SRS_IOTHUBMESSAGE_09_004: [If IoTHubMessage_SetContentTypeSystemProperty finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 74:ea0021abecf7 | 622 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 74:ea0021abecf7 | 623 | } |
AzureIoTClient | 74:ea0021abecf7 | 624 | } |
AzureIoTClient | 74:ea0021abecf7 | 625 | |
AzureIoTClient | 74:ea0021abecf7 | 626 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 627 | } |
AzureIoTClient | 74:ea0021abecf7 | 628 | |
AzureIoTClient | 74:ea0021abecf7 | 629 | const char* IoTHubMessage_GetContentTypeSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 74:ea0021abecf7 | 630 | { |
AzureIoTClient | 74:ea0021abecf7 | 631 | const char* result; |
AzureIoTClient | 74:ea0021abecf7 | 632 | |
AzureIoTClient | 74:ea0021abecf7 | 633 | // 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 | 634 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 635 | { |
AzureIoTClient | 74:ea0021abecf7 | 636 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 74:ea0021abecf7 | 637 | result = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 638 | } |
AzureIoTClient | 74:ea0021abecf7 | 639 | else |
AzureIoTClient | 74:ea0021abecf7 | 640 | { |
AzureIoTClient | 74:ea0021abecf7 | 641 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 642 | |
AzureIoTClient | 74:ea0021abecf7 | 643 | // Codes_SRS_IOTHUBMESSAGE_09_006: [IoTHubMessage_GetContentTypeSystemProperty shall return the `contentType` as a const char* ] |
AzureIoTClient | 74:ea0021abecf7 | 644 | result = (const char*)handleData->userDefinedContentType; |
AzureIoTClient | 74:ea0021abecf7 | 645 | } |
AzureIoTClient | 74:ea0021abecf7 | 646 | |
AzureIoTClient | 74:ea0021abecf7 | 647 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 648 | } |
AzureIoTClient | 74:ea0021abecf7 | 649 | |
AzureIoTClient | 74:ea0021abecf7 | 650 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetContentEncodingSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* contentEncoding) |
AzureIoTClient | 74:ea0021abecf7 | 651 | { |
AzureIoTClient | 74:ea0021abecf7 | 652 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 74:ea0021abecf7 | 653 | |
AzureIoTClient | 74:ea0021abecf7 | 654 | // 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 | 655 | if (iotHubMessageHandle == NULL || contentEncoding == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 656 | { |
AzureIoTClient | 74:ea0021abecf7 | 657 | LogError("Invalid argument (iotHubMessageHandle=%p, contentEncoding=%p)", iotHubMessageHandle, contentEncoding); |
AzureIoTClient | 74:ea0021abecf7 | 658 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 74:ea0021abecf7 | 659 | } |
AzureIoTClient | 74:ea0021abecf7 | 660 | else |
AzureIoTClient | 74:ea0021abecf7 | 661 | { |
AzureIoTClient | 74:ea0021abecf7 | 662 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 663 | |
AzureIoTClient | 74:ea0021abecf7 | 664 | // Codes_SRS_IOTHUBMESSAGE_09_007: [If the IOTHUB_MESSAGE_HANDLE `contentEncoding` is not NULL it shall be deallocated.] |
AzureIoTClient | 74:ea0021abecf7 | 665 | if (handleData->contentEncoding != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 666 | { |
AzureIoTClient | 74:ea0021abecf7 | 667 | free(handleData->contentEncoding); |
AzureIoTClient | 74:ea0021abecf7 | 668 | handleData->contentEncoding = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 669 | } |
AzureIoTClient | 74:ea0021abecf7 | 670 | |
AzureIoTClient | 74:ea0021abecf7 | 671 | if (mallocAndStrcpy_s(&handleData->contentEncoding, contentEncoding) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 672 | { |
AzureIoTClient | 74:ea0021abecf7 | 673 | LogError("Failed saving a copy of contentEncoding"); |
AzureIoTClient | 74:ea0021abecf7 | 674 | // 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 | 675 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 676 | } |
AzureIoTClient | 74:ea0021abecf7 | 677 | else |
AzureIoTClient | 74:ea0021abecf7 | 678 | { |
AzureIoTClient | 74:ea0021abecf7 | 679 | // Codes_SRS_IOTHUBMESSAGE_09_009: [If IoTHubMessage_SetContentEncodingSystemProperty finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 74:ea0021abecf7 | 680 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 74:ea0021abecf7 | 681 | } |
AzureIoTClient | 74:ea0021abecf7 | 682 | } |
AzureIoTClient | 74:ea0021abecf7 | 683 | |
AzureIoTClient | 74:ea0021abecf7 | 684 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 685 | } |
AzureIoTClient | 74:ea0021abecf7 | 686 | |
AzureIoTClient | 74:ea0021abecf7 | 687 | const char* IoTHubMessage_GetContentEncodingSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 74:ea0021abecf7 | 688 | { |
AzureIoTClient | 74:ea0021abecf7 | 689 | const char* result; |
AzureIoTClient | 74:ea0021abecf7 | 690 | |
AzureIoTClient | 74:ea0021abecf7 | 691 | // 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 | 692 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 693 | { |
AzureIoTClient | 74:ea0021abecf7 | 694 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 74:ea0021abecf7 | 695 | result = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 696 | } |
AzureIoTClient | 74:ea0021abecf7 | 697 | else |
AzureIoTClient | 74:ea0021abecf7 | 698 | { |
AzureIoTClient | 74:ea0021abecf7 | 699 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 700 | |
AzureIoTClient | 74:ea0021abecf7 | 701 | // Codes_SRS_IOTHUBMESSAGE_09_011: [IoTHubMessage_GetContentEncodingSystemProperty shall return the `contentEncoding` as a const char* ] |
AzureIoTClient | 74:ea0021abecf7 | 702 | result = (const char*)handleData->contentEncoding; |
AzureIoTClient | 74:ea0021abecf7 | 703 | } |
AzureIoTClient | 74:ea0021abecf7 | 704 | |
AzureIoTClient | 74:ea0021abecf7 | 705 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 706 | } |
AzureIoTClient | 74:ea0021abecf7 | 707 | |
AzureIoTClient | 77:e4e36df9caee | 708 | const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* IoTHubMessage_GetDiagnosticPropertyData(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 77:e4e36df9caee | 709 | { |
AzureIoTClient | 77:e4e36df9caee | 710 | const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* result; |
AzureIoTClient | 77:e4e36df9caee | 711 | // Codes_SRS_IOTHUBMESSAGE_10_001: [If any of the parameters are NULL then IoTHubMessage_GetDiagnosticPropertyData shall return a NULL value.] |
AzureIoTClient | 77:e4e36df9caee | 712 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 77:e4e36df9caee | 713 | { |
AzureIoTClient | 77:e4e36df9caee | 714 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 77:e4e36df9caee | 715 | result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 716 | } |
AzureIoTClient | 77:e4e36df9caee | 717 | else |
AzureIoTClient | 77:e4e36df9caee | 718 | { |
AzureIoTClient | 77:e4e36df9caee | 719 | /* Codes_SRS_IOTHUBMESSAGE_10_002: [IoTHubMessage_GetDiagnosticPropertyData shall return the diagnosticData as a const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*.] */ |
AzureIoTClient | 77:e4e36df9caee | 720 | result = iotHubMessageHandle->diagnosticData; |
AzureIoTClient | 77:e4e36df9caee | 721 | } |
AzureIoTClient | 77:e4e36df9caee | 722 | return result; |
AzureIoTClient | 77:e4e36df9caee | 723 | } |
AzureIoTClient | 77:e4e36df9caee | 724 | |
AzureIoTClient | 77:e4e36df9caee | 725 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetDiagnosticPropertyData(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* diagnosticData) |
AzureIoTClient | 77:e4e36df9caee | 726 | { |
AzureIoTClient | 77:e4e36df9caee | 727 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 77:e4e36df9caee | 728 | // 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 | 729 | if (iotHubMessageHandle == NULL || |
AzureIoTClient | 77:e4e36df9caee | 730 | diagnosticData == NULL || |
AzureIoTClient | 77:e4e36df9caee | 731 | diagnosticData->diagnosticCreationTimeUtc == NULL || |
AzureIoTClient | 77:e4e36df9caee | 732 | diagnosticData->diagnosticId == NULL) |
AzureIoTClient | 77:e4e36df9caee | 733 | { |
AzureIoTClient | 77:e4e36df9caee | 734 | LogError("Invalid argument (iotHubMessageHandle=%p, diagnosticData=%p, diagnosticData->diagnosticId=%p, diagnosticData->diagnosticCreationTimeUtc=%p)", |
AzureIoTClient | 77:e4e36df9caee | 735 | iotHubMessageHandle, diagnosticData, |
AzureIoTClient | 77:e4e36df9caee | 736 | diagnosticData == NULL ? NULL : diagnosticData->diagnosticId, |
AzureIoTClient | 77:e4e36df9caee | 737 | diagnosticData == NULL ? NULL : diagnosticData->diagnosticCreationTimeUtc); |
AzureIoTClient | 77:e4e36df9caee | 738 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 77:e4e36df9caee | 739 | } |
AzureIoTClient | 77:e4e36df9caee | 740 | else |
AzureIoTClient | 77:e4e36df9caee | 741 | { |
AzureIoTClient | 77:e4e36df9caee | 742 | // Codes_SRS_IOTHUBMESSAGE_10_004: [If the IOTHUB_MESSAGE_HANDLE `diagnosticData` is not NULL it shall be deallocated.] |
AzureIoTClient | 77:e4e36df9caee | 743 | if (iotHubMessageHandle->diagnosticData != NULL) |
AzureIoTClient | 77:e4e36df9caee | 744 | { |
AzureIoTClient | 77:e4e36df9caee | 745 | DestroyDiagnosticPropertyData(iotHubMessageHandle->diagnosticData); |
AzureIoTClient | 77:e4e36df9caee | 746 | iotHubMessageHandle->diagnosticData = NULL; |
AzureIoTClient | 77:e4e36df9caee | 747 | } |
AzureIoTClient | 77:e4e36df9caee | 748 | |
AzureIoTClient | 77:e4e36df9caee | 749 | // 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 | 750 | if ((iotHubMessageHandle->diagnosticData = CloneDiagnosticPropertyData(diagnosticData)) == NULL) |
AzureIoTClient | 77:e4e36df9caee | 751 | { |
AzureIoTClient | 77:e4e36df9caee | 752 | LogError("Failed saving a copy of diagnosticData"); |
AzureIoTClient | 77:e4e36df9caee | 753 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 77:e4e36df9caee | 754 | } |
AzureIoTClient | 77:e4e36df9caee | 755 | else |
AzureIoTClient | 77:e4e36df9caee | 756 | { |
AzureIoTClient | 77:e4e36df9caee | 757 | // Codes_SRS_IOTHUBMESSAGE_10_006: [If IoTHubMessage_SetDiagnosticPropertyData finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 77:e4e36df9caee | 758 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 77:e4e36df9caee | 759 | } |
AzureIoTClient | 77:e4e36df9caee | 760 | } |
AzureIoTClient | 77:e4e36df9caee | 761 | return result; |
AzureIoTClient | 77:e4e36df9caee | 762 | } |
AzureIoTClient | 77:e4e36df9caee | 763 | |
AzureIoTClient | 0:e393db310d89 | 764 | void IoTHubMessage_Destroy(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 765 | { |
AzureIoTClient | 0:e393db310d89 | 766 | /*Codes_SRS_IOTHUBMESSAGE_01_004: [If iotHubMessageHandle is NULL, IoTHubMessage_Destroy shall do nothing.] */ |
AzureIoTClient | 0:e393db310d89 | 767 | if (iotHubMessageHandle != NULL) |
AzureIoTClient | 0:e393db310d89 | 768 | { |
AzureIoTClient | 0:e393db310d89 | 769 | /*Codes_SRS_IOTHUBMESSAGE_01_003: [IoTHubMessage_Destroy shall free all resources associated with iotHubMessageHandle.] */ |
AzureIoTClient | 78:74a8d3068204 | 770 | DestroyMessageData((IOTHUB_MESSAGE_HANDLE_DATA* )iotHubMessageHandle); |
AzureIoTClient | 0:e393db310d89 | 771 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 772 | } |