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@93:7c0bbb86b167, 2018-10-04 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Thu Oct 04 09:15:49 2018 -0700
- Revision:
- 93:7c0bbb86b167
- Parent:
- 92:97148cf9aa2a
1.2.10
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 | 89:a2ed767a532e | 31 | char* outputName; |
AzureIoTClient | 89:a2ed767a532e | 32 | char* inputName; |
AzureIoTClient | 89:a2ed767a532e | 33 | char* connectionModuleId; |
AzureIoTClient | 89:a2ed767a532e | 34 | char* connectionDeviceId; |
AzureIoTClient | 77:e4e36df9caee | 35 | IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE diagnosticData; |
AzureIoTClient | 0:e393db310d89 | 36 | }IOTHUB_MESSAGE_HANDLE_DATA; |
AzureIoTClient | 0:e393db310d89 | 37 | |
AzureIoTClient | 0:e393db310d89 | 38 | static bool ContainsOnlyUsAscii(const char* asciiValue) |
AzureIoTClient | 0:e393db310d89 | 39 | { |
AzureIoTClient | 21:3c90c2262ce4 | 40 | bool result = true; |
AzureIoTClient | 0:e393db310d89 | 41 | const char* iterator = asciiValue; |
AzureIoTClient | 0:e393db310d89 | 42 | while (iterator != NULL && *iterator != '\0') |
AzureIoTClient | 0:e393db310d89 | 43 | { |
AzureIoTClient | 92:97148cf9aa2a | 44 | // Allow only printable ascii char |
AzureIoTClient | 0:e393db310d89 | 45 | if (*iterator < ' ' || *iterator > '~') |
AzureIoTClient | 0:e393db310d89 | 46 | { |
AzureIoTClient | 0:e393db310d89 | 47 | result = false; |
AzureIoTClient | 0:e393db310d89 | 48 | break; |
AzureIoTClient | 0:e393db310d89 | 49 | } |
AzureIoTClient | 0:e393db310d89 | 50 | iterator++; |
AzureIoTClient | 0:e393db310d89 | 51 | } |
AzureIoTClient | 0:e393db310d89 | 52 | return result; |
AzureIoTClient | 0:e393db310d89 | 53 | } |
AzureIoTClient | 0:e393db310d89 | 54 | |
AzureIoTClient | 0:e393db310d89 | 55 | /* 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 | 56 | static int ValidateAsciiCharactersFilter(const char* mapKey, const char* mapValue) |
AzureIoTClient | 0:e393db310d89 | 57 | { |
AzureIoTClient | 0:e393db310d89 | 58 | int result; |
AzureIoTClient | 77:e4e36df9caee | 59 | if (!ContainsOnlyUsAscii(mapKey) || !ContainsOnlyUsAscii(mapValue)) |
AzureIoTClient | 0:e393db310d89 | 60 | { |
AzureIoTClient | 60:41648c4e7036 | 61 | result = __FAILURE__; |
AzureIoTClient | 0:e393db310d89 | 62 | } |
AzureIoTClient | 0:e393db310d89 | 63 | else |
AzureIoTClient | 0:e393db310d89 | 64 | { |
AzureIoTClient | 0:e393db310d89 | 65 | result = 0; |
AzureIoTClient | 0:e393db310d89 | 66 | } |
AzureIoTClient | 0:e393db310d89 | 67 | return result; |
AzureIoTClient | 0:e393db310d89 | 68 | } |
AzureIoTClient | 0:e393db310d89 | 69 | |
AzureIoTClient | 77:e4e36df9caee | 70 | static void DestroyDiagnosticPropertyData(IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE diagnosticHandle) |
AzureIoTClient | 77:e4e36df9caee | 71 | { |
AzureIoTClient | 77:e4e36df9caee | 72 | if (diagnosticHandle != NULL) |
AzureIoTClient | 77:e4e36df9caee | 73 | { |
AzureIoTClient | 77:e4e36df9caee | 74 | free(diagnosticHandle->diagnosticId); |
AzureIoTClient | 77:e4e36df9caee | 75 | free(diagnosticHandle->diagnosticCreationTimeUtc); |
AzureIoTClient | 77:e4e36df9caee | 76 | } |
AzureIoTClient | 77:e4e36df9caee | 77 | free(diagnosticHandle); |
AzureIoTClient | 77:e4e36df9caee | 78 | } |
AzureIoTClient | 77:e4e36df9caee | 79 | |
AzureIoTClient | 78:74a8d3068204 | 80 | static void DestroyMessageData(IOTHUB_MESSAGE_HANDLE_DATA* handleData) |
AzureIoTClient | 78:74a8d3068204 | 81 | { |
AzureIoTClient | 78:74a8d3068204 | 82 | if (handleData->contentType == IOTHUBMESSAGE_BYTEARRAY) |
AzureIoTClient | 78:74a8d3068204 | 83 | { |
AzureIoTClient | 78:74a8d3068204 | 84 | BUFFER_delete(handleData->value.byteArray); |
AzureIoTClient | 78:74a8d3068204 | 85 | } |
AzureIoTClient | 78:74a8d3068204 | 86 | else if (handleData->contentType == IOTHUBMESSAGE_STRING) |
AzureIoTClient | 78:74a8d3068204 | 87 | { |
AzureIoTClient | 78:74a8d3068204 | 88 | STRING_delete(handleData->value.string); |
AzureIoTClient | 78:74a8d3068204 | 89 | } |
AzureIoTClient | 78:74a8d3068204 | 90 | |
AzureIoTClient | 78:74a8d3068204 | 91 | Map_Destroy(handleData->properties); |
AzureIoTClient | 78:74a8d3068204 | 92 | free(handleData->messageId); |
AzureIoTClient | 78:74a8d3068204 | 93 | handleData->messageId = NULL; |
AzureIoTClient | 78:74a8d3068204 | 94 | free(handleData->correlationId); |
AzureIoTClient | 78:74a8d3068204 | 95 | handleData->correlationId = NULL; |
AzureIoTClient | 78:74a8d3068204 | 96 | free(handleData->userDefinedContentType); |
AzureIoTClient | 78:74a8d3068204 | 97 | free(handleData->contentEncoding); |
AzureIoTClient | 78:74a8d3068204 | 98 | DestroyDiagnosticPropertyData(handleData->diagnosticData); |
AzureIoTClient | 89:a2ed767a532e | 99 | free(handleData->outputName); |
AzureIoTClient | 89:a2ed767a532e | 100 | free(handleData->inputName); |
AzureIoTClient | 89:a2ed767a532e | 101 | free(handleData->connectionModuleId); |
AzureIoTClient | 89:a2ed767a532e | 102 | free(handleData->connectionDeviceId); |
AzureIoTClient | 78:74a8d3068204 | 103 | free(handleData); |
AzureIoTClient | 78:74a8d3068204 | 104 | } |
AzureIoTClient | 78:74a8d3068204 | 105 | |
AzureIoTClient | 77:e4e36df9caee | 106 | static IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE CloneDiagnosticPropertyData(const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* source) |
AzureIoTClient | 77:e4e36df9caee | 107 | { |
AzureIoTClient | 77:e4e36df9caee | 108 | IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 109 | if (source == NULL) |
AzureIoTClient | 77:e4e36df9caee | 110 | { |
AzureIoTClient | 77:e4e36df9caee | 111 | LogError("Invalid argument - source is NULL"); |
AzureIoTClient | 77:e4e36df9caee | 112 | } |
AzureIoTClient | 77:e4e36df9caee | 113 | else |
AzureIoTClient | 77:e4e36df9caee | 114 | { |
AzureIoTClient | 77:e4e36df9caee | 115 | result = (IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE)malloc(sizeof(IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA)); |
AzureIoTClient | 77:e4e36df9caee | 116 | if (result == NULL) |
AzureIoTClient | 77:e4e36df9caee | 117 | { |
AzureIoTClient | 77:e4e36df9caee | 118 | LogError("malloc failed"); |
AzureIoTClient | 77:e4e36df9caee | 119 | } |
AzureIoTClient | 77:e4e36df9caee | 120 | else |
AzureIoTClient | 77:e4e36df9caee | 121 | { |
AzureIoTClient | 77:e4e36df9caee | 122 | result->diagnosticCreationTimeUtc = NULL; |
AzureIoTClient | 77:e4e36df9caee | 123 | result->diagnosticId = NULL; |
AzureIoTClient | 77:e4e36df9caee | 124 | if (source->diagnosticCreationTimeUtc != NULL && mallocAndStrcpy_s(&result->diagnosticCreationTimeUtc, source->diagnosticCreationTimeUtc) != 0) |
AzureIoTClient | 77:e4e36df9caee | 125 | { |
AzureIoTClient | 77:e4e36df9caee | 126 | LogError("mallocAndStrcpy_s for diagnosticCreationTimeUtc failed"); |
AzureIoTClient | 77:e4e36df9caee | 127 | free(result); |
AzureIoTClient | 77:e4e36df9caee | 128 | result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 129 | } |
AzureIoTClient | 77:e4e36df9caee | 130 | else if (source->diagnosticId != NULL && mallocAndStrcpy_s(&result->diagnosticId, source->diagnosticId) != 0) |
AzureIoTClient | 77:e4e36df9caee | 131 | { |
AzureIoTClient | 77:e4e36df9caee | 132 | LogError("mallocAndStrcpy_s for diagnosticId failed"); |
AzureIoTClient | 77:e4e36df9caee | 133 | free(result->diagnosticCreationTimeUtc); |
AzureIoTClient | 77:e4e36df9caee | 134 | free(result); |
AzureIoTClient | 77:e4e36df9caee | 135 | result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 136 | } |
AzureIoTClient | 77:e4e36df9caee | 137 | } |
AzureIoTClient | 77:e4e36df9caee | 138 | } |
AzureIoTClient | 77:e4e36df9caee | 139 | return result; |
AzureIoTClient | 77:e4e36df9caee | 140 | } |
AzureIoTClient | 77:e4e36df9caee | 141 | |
AzureIoTClient | 0:e393db310d89 | 142 | IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromByteArray(const unsigned char* byteArray, size_t size) |
AzureIoTClient | 0:e393db310d89 | 143 | { |
AzureIoTClient | 0:e393db310d89 | 144 | IOTHUB_MESSAGE_HANDLE_DATA* result; |
AzureIoTClient | 61:8b85a4e797cf | 145 | if ((byteArray == NULL) && (size != 0)) |
AzureIoTClient | 0:e393db310d89 | 146 | { |
AzureIoTClient | 61:8b85a4e797cf | 147 | LogError("Invalid argument - byteArray is NULL"); |
AzureIoTClient | 61:8b85a4e797cf | 148 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 149 | } |
AzureIoTClient | 0:e393db310d89 | 150 | else |
AzureIoTClient | 0:e393db310d89 | 151 | { |
AzureIoTClient | 61:8b85a4e797cf | 152 | result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA)); |
AzureIoTClient | 61:8b85a4e797cf | 153 | if (result == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 154 | { |
AzureIoTClient | 61:8b85a4e797cf | 155 | LogError("unable to malloc"); |
AzureIoTClient | 61:8b85a4e797cf | 156 | /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */ |
AzureIoTClient | 61:8b85a4e797cf | 157 | /*let it go through*/ |
AzureIoTClient | 61:8b85a4e797cf | 158 | } |
AzureIoTClient | 61:8b85a4e797cf | 159 | else |
AzureIoTClient | 0:e393db310d89 | 160 | { |
AzureIoTClient | 61:8b85a4e797cf | 161 | const unsigned char* source; |
AzureIoTClient | 61:8b85a4e797cf | 162 | unsigned char temp = 0x00; |
AzureIoTClient | 78:74a8d3068204 | 163 | |
AzureIoTClient | 78:74a8d3068204 | 164 | memset(result, 0, sizeof(*result)); |
AzureIoTClient | 78:74a8d3068204 | 165 | /*Codes_SRS_IOTHUBMESSAGE_02_026: [The type of the new message shall be IOTHUBMESSAGE_BYTEARRAY.] */ |
AzureIoTClient | 78:74a8d3068204 | 166 | result->contentType = IOTHUBMESSAGE_BYTEARRAY; |
AzureIoTClient | 78:74a8d3068204 | 167 | |
AzureIoTClient | 61:8b85a4e797cf | 168 | if (size != 0) |
AzureIoTClient | 0:e393db310d89 | 169 | { |
AzureIoTClient | 61:8b85a4e797cf | 170 | /*Codes_SRS_IOTHUBMESSAGE_06_002: [If size is NOT zero then byteArray MUST NOT be NULL*/ |
AzureIoTClient | 61:8b85a4e797cf | 171 | if (byteArray == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 172 | { |
AzureIoTClient | 61:8b85a4e797cf | 173 | LogError("Attempted to create a Hub Message from a NULL pointer!"); |
AzureIoTClient | 78:74a8d3068204 | 174 | DestroyMessageData(result); |
AzureIoTClient | 61:8b85a4e797cf | 175 | result = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 176 | source = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 177 | } |
AzureIoTClient | 61:8b85a4e797cf | 178 | else |
AzureIoTClient | 61:8b85a4e797cf | 179 | { |
AzureIoTClient | 61:8b85a4e797cf | 180 | source = byteArray; |
AzureIoTClient | 61:8b85a4e797cf | 181 | } |
AzureIoTClient | 0:e393db310d89 | 182 | } |
AzureIoTClient | 0:e393db310d89 | 183 | else |
AzureIoTClient | 0:e393db310d89 | 184 | { |
AzureIoTClient | 61:8b85a4e797cf | 185 | /*Codes_SRS_IOTHUBMESSAGE_06_001: [If size is zero then byteArray may be NULL.]*/ |
AzureIoTClient | 61:8b85a4e797cf | 186 | source = &temp; |
AzureIoTClient | 0:e393db310d89 | 187 | } |
AzureIoTClient | 61:8b85a4e797cf | 188 | if (result != NULL) |
AzureIoTClient | 61:8b85a4e797cf | 189 | { |
AzureIoTClient | 61:8b85a4e797cf | 190 | /*Codes_SRS_IOTHUBMESSAGE_02_022: [IoTHubMessage_CreateFromByteArray shall call BUFFER_create passing byteArray and size as parameters.] */ |
AzureIoTClient | 61:8b85a4e797cf | 191 | if ((result->value.byteArray = BUFFER_create(source, size)) == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 192 | { |
AzureIoTClient | 61:8b85a4e797cf | 193 | LogError("BUFFER_create 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 | 61:8b85a4e797cf | 198 | /*Codes_SRS_IOTHUBMESSAGE_02_023: [IoTHubMessage_CreateFromByteArray shall call Map_Create to create the message properties.] */ |
AzureIoTClient | 61:8b85a4e797cf | 199 | else if ((result->properties = Map_Create(ValidateAsciiCharactersFilter)) == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 200 | { |
AzureIoTClient | 77:e4e36df9caee | 201 | LogError("Map_Create for properties failed"); |
AzureIoTClient | 61:8b85a4e797cf | 202 | /*Codes_SRS_IOTHUBMESSAGE_02_024: [If there are any errors then IoTHubMessage_CreateFromByteArray shall return NULL.] */ |
AzureIoTClient | 78:74a8d3068204 | 203 | DestroyMessageData(result); |
AzureIoTClient | 61:8b85a4e797cf | 204 | result = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 205 | } |
AzureIoTClient | 78:74a8d3068204 | 206 | /*Codes_SRS_IOTHUBMESSAGE_02_025: [Otherwise, IoTHubMessage_CreateFromByteArray shall return a non-NULL handle.] */ |
AzureIoTClient | 61:8b85a4e797cf | 207 | } |
AzureIoTClient | 61:8b85a4e797cf | 208 | } |
AzureIoTClient | 61:8b85a4e797cf | 209 | } |
AzureIoTClient | 61:8b85a4e797cf | 210 | return result; |
AzureIoTClient | 61:8b85a4e797cf | 211 | } |
AzureIoTClient | 61:8b85a4e797cf | 212 | |
AzureIoTClient | 61:8b85a4e797cf | 213 | IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromString(const char* source) |
AzureIoTClient | 61:8b85a4e797cf | 214 | { |
AzureIoTClient | 61:8b85a4e797cf | 215 | IOTHUB_MESSAGE_HANDLE_DATA* result; |
AzureIoTClient | 61:8b85a4e797cf | 216 | if (source == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 217 | { |
AzureIoTClient | 61:8b85a4e797cf | 218 | LogError("Invalid argument - source is NULL"); |
AzureIoTClient | 61:8b85a4e797cf | 219 | result = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 220 | } |
AzureIoTClient | 61:8b85a4e797cf | 221 | else |
AzureIoTClient | 61:8b85a4e797cf | 222 | { |
AzureIoTClient | 61:8b85a4e797cf | 223 | result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA)); |
AzureIoTClient | 61:8b85a4e797cf | 224 | if (result == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 225 | { |
AzureIoTClient | 61:8b85a4e797cf | 226 | LogError("malloc failed"); |
AzureIoTClient | 61:8b85a4e797cf | 227 | /*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 | 228 | /*let it go through*/ |
AzureIoTClient | 0:e393db310d89 | 229 | } |
AzureIoTClient | 0:e393db310d89 | 230 | else |
AzureIoTClient | 0:e393db310d89 | 231 | { |
AzureIoTClient | 78:74a8d3068204 | 232 | memset(result, 0, sizeof(*result)); |
AzureIoTClient | 78:74a8d3068204 | 233 | /*Codes_SRS_IOTHUBMESSAGE_02_032: [The type of the new message shall be IOTHUBMESSAGE_STRING.] */ |
AzureIoTClient | 78:74a8d3068204 | 234 | result->contentType = IOTHUBMESSAGE_STRING; |
AzureIoTClient | 92:97148cf9aa2a | 235 | |
AzureIoTClient | 61:8b85a4e797cf | 236 | /*Codes_SRS_IOTHUBMESSAGE_02_027: [IoTHubMessage_CreateFromString shall call STRING_construct passing source as parameter.] */ |
AzureIoTClient | 61:8b85a4e797cf | 237 | if ((result->value.string = STRING_construct(source)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 238 | { |
AzureIoTClient | 61:8b85a4e797cf | 239 | LogError("STRING_construct 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 | 61:8b85a4e797cf | 244 | /*Codes_SRS_IOTHUBMESSAGE_02_028: [IoTHubMessage_CreateFromString shall call Map_Create to create the message properties.] */ |
AzureIoTClient | 0:e393db310d89 | 245 | else if ((result->properties = Map_Create(ValidateAsciiCharactersFilter)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 246 | { |
AzureIoTClient | 77:e4e36df9caee | 247 | LogError("Map_Create for properties failed"); |
AzureIoTClient | 61:8b85a4e797cf | 248 | /*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 | 249 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 250 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 251 | } |
AzureIoTClient | 78:74a8d3068204 | 252 | /*Codes_SRS_IOTHUBMESSAGE_02_031: [Otherwise, IoTHubMessage_CreateFromString shall return a non-NULL handle.] */ |
AzureIoTClient | 0:e393db310d89 | 253 | } |
AzureIoTClient | 0:e393db310d89 | 254 | } |
AzureIoTClient | 0:e393db310d89 | 255 | return result; |
AzureIoTClient | 0:e393db310d89 | 256 | } |
AzureIoTClient | 0:e393db310d89 | 257 | |
AzureIoTClient | 0:e393db310d89 | 258 | /*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 | 259 | IOTHUB_MESSAGE_HANDLE IoTHubMessage_Clone(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 260 | { |
AzureIoTClient | 0:e393db310d89 | 261 | IOTHUB_MESSAGE_HANDLE_DATA* result; |
AzureIoTClient | 0:e393db310d89 | 262 | const IOTHUB_MESSAGE_HANDLE_DATA* source = (const IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 0:e393db310d89 | 263 | /* Codes_SRS_IOTHUBMESSAGE_03_005: [IoTHubMessage_Clone shall return NULL if iotHubMessageHandle is NULL.] */ |
AzureIoTClient | 0:e393db310d89 | 264 | if (source == NULL) |
AzureIoTClient | 0:e393db310d89 | 265 | { |
AzureIoTClient | 0:e393db310d89 | 266 | result = NULL; |
AzureIoTClient | 39:2719651a5bee | 267 | LogError("iotHubMessageHandle parameter cannot be NULL for IoTHubMessage_Clone"); |
AzureIoTClient | 0:e393db310d89 | 268 | } |
AzureIoTClient | 0:e393db310d89 | 269 | else |
AzureIoTClient | 0:e393db310d89 | 270 | { |
AzureIoTClient | 0:e393db310d89 | 271 | result = (IOTHUB_MESSAGE_HANDLE_DATA*)malloc(sizeof(IOTHUB_MESSAGE_HANDLE_DATA)); |
AzureIoTClient | 0:e393db310d89 | 272 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 0:e393db310d89 | 273 | if (result == NULL) |
AzureIoTClient | 0:e393db310d89 | 274 | { |
AzureIoTClient | 0:e393db310d89 | 275 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 0:e393db310d89 | 276 | /*do nothing and return as is*/ |
AzureIoTClient | 39:2719651a5bee | 277 | LogError("unable to malloc"); |
AzureIoTClient | 0:e393db310d89 | 278 | } |
AzureIoTClient | 0:e393db310d89 | 279 | else |
AzureIoTClient | 0:e393db310d89 | 280 | { |
AzureIoTClient | 78:74a8d3068204 | 281 | memset(result, 0, sizeof(*result)); |
AzureIoTClient | 78:74a8d3068204 | 282 | result->contentType = source->contentType; |
AzureIoTClient | 74:ea0021abecf7 | 283 | |
AzureIoTClient | 18:1e9adb15c645 | 284 | if (source->messageId != NULL && mallocAndStrcpy_s(&result->messageId, source->messageId) != 0) |
AzureIoTClient | 18:1e9adb15c645 | 285 | { |
AzureIoTClient | 39:2719651a5bee | 286 | LogError("unable to Copy messageId"); |
AzureIoTClient | 78:74a8d3068204 | 287 | DestroyMessageData(result); |
AzureIoTClient | 18:1e9adb15c645 | 288 | result = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 289 | } |
AzureIoTClient | 18:1e9adb15c645 | 290 | else if (source->correlationId != NULL && mallocAndStrcpy_s(&result->correlationId, source->correlationId) != 0) |
AzureIoTClient | 18:1e9adb15c645 | 291 | { |
AzureIoTClient | 39:2719651a5bee | 292 | LogError("unable to Copy correlationId"); |
AzureIoTClient | 78:74a8d3068204 | 293 | DestroyMessageData(result); |
AzureIoTClient | 74:ea0021abecf7 | 294 | result = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 295 | } |
AzureIoTClient | 74:ea0021abecf7 | 296 | else if (source->userDefinedContentType != NULL && mallocAndStrcpy_s(&result->userDefinedContentType, source->userDefinedContentType) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 297 | { |
AzureIoTClient | 74:ea0021abecf7 | 298 | LogError("unable to copy contentType"); |
AzureIoTClient | 78:74a8d3068204 | 299 | DestroyMessageData(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 | 78:74a8d3068204 | 305 | DestroyMessageData(result); |
AzureIoTClient | 18:1e9adb15c645 | 306 | result = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 307 | } |
AzureIoTClient | 77:e4e36df9caee | 308 | else if (source->diagnosticData != NULL && (result->diagnosticData = CloneDiagnosticPropertyData(source->diagnosticData)) == NULL) |
AzureIoTClient | 77:e4e36df9caee | 309 | { |
AzureIoTClient | 89:a2ed767a532e | 310 | LogError("unable to copy CloneDiagnosticPropertyData"); |
AzureIoTClient | 89:a2ed767a532e | 311 | DestroyMessageData(result); |
AzureIoTClient | 89:a2ed767a532e | 312 | result = NULL; |
AzureIoTClient | 89:a2ed767a532e | 313 | } |
AzureIoTClient | 89:a2ed767a532e | 314 | else if (source->outputName != NULL && mallocAndStrcpy_s(&result->outputName, source->outputName) != 0) |
AzureIoTClient | 89:a2ed767a532e | 315 | { |
AzureIoTClient | 89:a2ed767a532e | 316 | LogError("unable to copy outputName"); |
AzureIoTClient | 89:a2ed767a532e | 317 | DestroyMessageData(result); |
AzureIoTClient | 89:a2ed767a532e | 318 | result = NULL; |
AzureIoTClient | 89:a2ed767a532e | 319 | } |
AzureIoTClient | 89:a2ed767a532e | 320 | else if (source->inputName != NULL && mallocAndStrcpy_s(&result->inputName, source->inputName) != 0) |
AzureIoTClient | 89:a2ed767a532e | 321 | { |
AzureIoTClient | 89:a2ed767a532e | 322 | LogError("unable to copy inputName"); |
AzureIoTClient | 89:a2ed767a532e | 323 | DestroyMessageData(result); |
AzureIoTClient | 89:a2ed767a532e | 324 | result = NULL; |
AzureIoTClient | 89:a2ed767a532e | 325 | } |
AzureIoTClient | 89:a2ed767a532e | 326 | else if (source->connectionModuleId != NULL && mallocAndStrcpy_s(&result->connectionModuleId, source->connectionModuleId) != 0) |
AzureIoTClient | 89:a2ed767a532e | 327 | { |
AzureIoTClient | 89:a2ed767a532e | 328 | LogError("unable to copy inputName"); |
AzureIoTClient | 89:a2ed767a532e | 329 | DestroyMessageData(result); |
AzureIoTClient | 89:a2ed767a532e | 330 | result = NULL; |
AzureIoTClient | 89:a2ed767a532e | 331 | } |
AzureIoTClient | 89:a2ed767a532e | 332 | else if (source->connectionDeviceId != NULL && mallocAndStrcpy_s(&result->connectionDeviceId, source->connectionDeviceId) != 0) |
AzureIoTClient | 89:a2ed767a532e | 333 | { |
AzureIoTClient | 89:a2ed767a532e | 334 | LogError("unable to copy inputName"); |
AzureIoTClient | 78:74a8d3068204 | 335 | DestroyMessageData(result); |
AzureIoTClient | 77:e4e36df9caee | 336 | result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 337 | } |
AzureIoTClient | 18:1e9adb15c645 | 338 | else if (source->contentType == IOTHUBMESSAGE_BYTEARRAY) |
AzureIoTClient | 0:e393db310d89 | 339 | { |
AzureIoTClient | 0:e393db310d89 | 340 | /*Codes_SRS_IOTHUBMESSAGE_02_006: [IoTHubMessage_Clone shall clone to content by a call to BUFFER_clone] */ |
AzureIoTClient | 0:e393db310d89 | 341 | if ((result->value.byteArray = BUFFER_clone(source->value.byteArray)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 342 | { |
AzureIoTClient | 0:e393db310d89 | 343 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 39:2719651a5bee | 344 | LogError("unable to BUFFER_clone"); |
AzureIoTClient | 78:74a8d3068204 | 345 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 346 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 347 | } |
AzureIoTClient | 0:e393db310d89 | 348 | /*Codes_SRS_IOTHUBMESSAGE_02_005: [IoTHubMessage_Clone shall clone the properties map by using Map_Clone.] */ |
AzureIoTClient | 0:e393db310d89 | 349 | else if ((result->properties = Map_Clone(source->properties)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 350 | { |
AzureIoTClient | 0:e393db310d89 | 351 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 39:2719651a5bee | 352 | LogError("unable to Map_Clone"); |
AzureIoTClient | 78:74a8d3068204 | 353 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 354 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 355 | } |
AzureIoTClient | 78:74a8d3068204 | 356 | /*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 | 357 | } |
AzureIoTClient | 0:e393db310d89 | 358 | else /*can only be STRING*/ |
AzureIoTClient | 0:e393db310d89 | 359 | { |
AzureIoTClient | 0:e393db310d89 | 360 | /*Codes_SRS_IOTHUBMESSAGE_02_006: [IoTHubMessage_Clone shall clone the content by a call to BUFFER_clone or STRING_clone] */ |
AzureIoTClient | 0:e393db310d89 | 361 | if ((result->value.string = STRING_clone(source->value.string)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 362 | { |
AzureIoTClient | 0:e393db310d89 | 363 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 78:74a8d3068204 | 364 | LogError("failed to STRING_clone"); |
AzureIoTClient | 78:74a8d3068204 | 365 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 366 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 367 | } |
AzureIoTClient | 0:e393db310d89 | 368 | /*Codes_SRS_IOTHUBMESSAGE_02_005: [IoTHubMessage_Clone shall clone the properties map by using Map_Clone.] */ |
AzureIoTClient | 0:e393db310d89 | 369 | else if ((result->properties = Map_Clone(source->properties)) == NULL) |
AzureIoTClient | 0:e393db310d89 | 370 | { |
AzureIoTClient | 0:e393db310d89 | 371 | /*Codes_SRS_IOTHUBMESSAGE_03_004: [IoTHubMessage_Clone shall return NULL if it fails for any reason.]*/ |
AzureIoTClient | 39:2719651a5bee | 372 | LogError("unable to Map_Clone"); |
AzureIoTClient | 78:74a8d3068204 | 373 | DestroyMessageData(result); |
AzureIoTClient | 0:e393db310d89 | 374 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 375 | } |
AzureIoTClient | 0:e393db310d89 | 376 | } |
AzureIoTClient | 0:e393db310d89 | 377 | } |
AzureIoTClient | 0:e393db310d89 | 378 | } |
AzureIoTClient | 0:e393db310d89 | 379 | return result; |
AzureIoTClient | 0:e393db310d89 | 380 | } |
AzureIoTClient | 0:e393db310d89 | 381 | |
AzureIoTClient | 0:e393db310d89 | 382 | IOTHUB_MESSAGE_RESULT IoTHubMessage_GetByteArray(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const unsigned char** buffer, size_t* size) |
AzureIoTClient | 0:e393db310d89 | 383 | { |
AzureIoTClient | 0:e393db310d89 | 384 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 0:e393db310d89 | 385 | if ( |
AzureIoTClient | 0:e393db310d89 | 386 | (iotHubMessageHandle == NULL) || |
AzureIoTClient | 0:e393db310d89 | 387 | (buffer == NULL) || |
AzureIoTClient | 0:e393db310d89 | 388 | (size == NULL) |
AzureIoTClient | 0:e393db310d89 | 389 | ) |
AzureIoTClient | 0:e393db310d89 | 390 | { |
AzureIoTClient | 0:e393db310d89 | 391 | /*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 | 392 | 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 | 393 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 0:e393db310d89 | 394 | } |
AzureIoTClient | 0:e393db310d89 | 395 | else |
AzureIoTClient | 0:e393db310d89 | 396 | { |
AzureIoTClient | 0:e393db310d89 | 397 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 0:e393db310d89 | 398 | if (handleData->contentType != IOTHUBMESSAGE_BYTEARRAY) |
AzureIoTClient | 0:e393db310d89 | 399 | { |
AzureIoTClient | 0:e393db310d89 | 400 | /*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 | 401 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 39:2719651a5bee | 402 | LogError("invalid type of message %s", ENUM_TO_STRING(IOTHUBMESSAGE_CONTENT_TYPE, handleData->contentType)); |
AzureIoTClient | 0:e393db310d89 | 403 | } |
AzureIoTClient | 0:e393db310d89 | 404 | else |
AzureIoTClient | 0:e393db310d89 | 405 | { |
AzureIoTClient | 0:e393db310d89 | 406 | /*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 | 407 | *buffer = BUFFER_u_char(handleData->value.byteArray); |
AzureIoTClient | 0:e393db310d89 | 408 | /*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 | 409 | *size = BUFFER_length(handleData->value.byteArray); |
AzureIoTClient | 0:e393db310d89 | 410 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 0:e393db310d89 | 411 | } |
AzureIoTClient | 0:e393db310d89 | 412 | } |
AzureIoTClient | 0:e393db310d89 | 413 | return result; |
AzureIoTClient | 0:e393db310d89 | 414 | } |
AzureIoTClient | 0:e393db310d89 | 415 | |
AzureIoTClient | 0:e393db310d89 | 416 | const char* IoTHubMessage_GetString(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 417 | { |
AzureIoTClient | 0:e393db310d89 | 418 | const char* result; |
AzureIoTClient | 0:e393db310d89 | 419 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 0:e393db310d89 | 420 | { |
AzureIoTClient | 0:e393db310d89 | 421 | /*Codes_SRS_IOTHUBMESSAGE_02_016: [If any parameter is NULL then IoTHubMessage_GetString shall return NULL.] */ |
AzureIoTClient | 0:e393db310d89 | 422 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 423 | } |
AzureIoTClient | 0:e393db310d89 | 424 | else |
AzureIoTClient | 0:e393db310d89 | 425 | { |
AzureIoTClient | 0:e393db310d89 | 426 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 0:e393db310d89 | 427 | if (handleData->contentType != IOTHUBMESSAGE_STRING) |
AzureIoTClient | 0:e393db310d89 | 428 | { |
AzureIoTClient | 0:e393db310d89 | 429 | /*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 | 430 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 431 | } |
AzureIoTClient | 0:e393db310d89 | 432 | else |
AzureIoTClient | 0:e393db310d89 | 433 | { |
AzureIoTClient | 0:e393db310d89 | 434 | /*Codes_SRS_IOTHUBMESSAGE_02_018: [IoTHubMessage_GetStringData shall return the currently stored null terminated string.] */ |
AzureIoTClient | 0:e393db310d89 | 435 | result = STRING_c_str(handleData->value.string); |
AzureIoTClient | 0:e393db310d89 | 436 | } |
AzureIoTClient | 0:e393db310d89 | 437 | } |
AzureIoTClient | 0:e393db310d89 | 438 | return result; |
AzureIoTClient | 0:e393db310d89 | 439 | } |
AzureIoTClient | 0:e393db310d89 | 440 | |
AzureIoTClient | 0:e393db310d89 | 441 | IOTHUBMESSAGE_CONTENT_TYPE IoTHubMessage_GetContentType(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 442 | { |
AzureIoTClient | 0:e393db310d89 | 443 | IOTHUBMESSAGE_CONTENT_TYPE result; |
AzureIoTClient | 0:e393db310d89 | 444 | /*Codes_SRS_IOTHUBMESSAGE_02_008: [If any parameter is NULL then IoTHubMessage_GetContentType shall return IOTHUBMESSAGE_UNKNOWN.] */ |
AzureIoTClient | 0:e393db310d89 | 445 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 0:e393db310d89 | 446 | { |
AzureIoTClient | 0:e393db310d89 | 447 | result = IOTHUBMESSAGE_UNKNOWN; |
AzureIoTClient | 0:e393db310d89 | 448 | } |
AzureIoTClient | 0:e393db310d89 | 449 | else |
AzureIoTClient | 0:e393db310d89 | 450 | { |
AzureIoTClient | 0:e393db310d89 | 451 | /*Codes_SRS_IOTHUBMESSAGE_02_009: [Otherwise IoTHubMessage_GetContentType shall return the type of the message.] */ |
AzureIoTClient | 0:e393db310d89 | 452 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 0:e393db310d89 | 453 | result = handleData->contentType; |
AzureIoTClient | 0:e393db310d89 | 454 | } |
AzureIoTClient | 0:e393db310d89 | 455 | return result; |
AzureIoTClient | 0:e393db310d89 | 456 | } |
AzureIoTClient | 0:e393db310d89 | 457 | |
AzureIoTClient | 0:e393db310d89 | 458 | MAP_HANDLE IoTHubMessage_Properties(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 459 | { |
AzureIoTClient | 0:e393db310d89 | 460 | MAP_HANDLE result; |
AzureIoTClient | 0:e393db310d89 | 461 | /*Codes_SRS_IOTHUBMESSAGE_02_001: [If iotHubMessageHandle is NULL then IoTHubMessage_Properties shall return NULL.]*/ |
AzureIoTClient | 0:e393db310d89 | 462 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 0:e393db310d89 | 463 | { |
AzureIoTClient | 39:2719651a5bee | 464 | LogError("invalid arg (NULL) passed to IoTHubMessage_Properties"); |
AzureIoTClient | 18:1e9adb15c645 | 465 | result = NULL; |
AzureIoTClient | 0:e393db310d89 | 466 | } |
AzureIoTClient | 0:e393db310d89 | 467 | else |
AzureIoTClient | 0:e393db310d89 | 468 | { |
AzureIoTClient | 0:e393db310d89 | 469 | /*Codes_SRS_IOTHUBMESSAGE_02_002: [Otherwise, for any non-NULL iotHubMessageHandle it shall return a non-NULL MAP_HANDLE.]*/ |
AzureIoTClient | 0:e393db310d89 | 470 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 0:e393db310d89 | 471 | result = handleData->properties; |
AzureIoTClient | 0:e393db310d89 | 472 | } |
AzureIoTClient | 0:e393db310d89 | 473 | return result; |
AzureIoTClient | 0:e393db310d89 | 474 | } |
AzureIoTClient | 0:e393db310d89 | 475 | |
AzureIoTClient | 88:248736be106e | 476 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetProperty(IOTHUB_MESSAGE_HANDLE msg_handle, const char* key, const char* value) |
AzureIoTClient | 88:248736be106e | 477 | { |
AzureIoTClient | 88:248736be106e | 478 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 88:248736be106e | 479 | if (msg_handle == NULL || key == NULL || value == NULL) |
AzureIoTClient | 88:248736be106e | 480 | { |
AzureIoTClient | 88:248736be106e | 481 | LogError("invalid parameter (NULL) to IoTHubMessage_SetProperty iotHubMessageHandle=%p, key=%p, value=%p", msg_handle, key, value); |
AzureIoTClient | 88:248736be106e | 482 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 88:248736be106e | 483 | } |
AzureIoTClient | 88:248736be106e | 484 | else |
AzureIoTClient | 88:248736be106e | 485 | { |
AzureIoTClient | 88:248736be106e | 486 | if (Map_AddOrUpdate(msg_handle->properties, key, value) != MAP_OK) |
AzureIoTClient | 88:248736be106e | 487 | { |
AzureIoTClient | 88:248736be106e | 488 | LogError("Failure adding property to internal map"); |
AzureIoTClient | 88:248736be106e | 489 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 88:248736be106e | 490 | } |
AzureIoTClient | 88:248736be106e | 491 | else |
AzureIoTClient | 88:248736be106e | 492 | { |
AzureIoTClient | 88:248736be106e | 493 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 88:248736be106e | 494 | } |
AzureIoTClient | 88:248736be106e | 495 | } |
AzureIoTClient | 88:248736be106e | 496 | return result; |
AzureIoTClient | 88:248736be106e | 497 | } |
AzureIoTClient | 88:248736be106e | 498 | |
AzureIoTClient | 88:248736be106e | 499 | const char* IoTHubMessage_GetProperty(IOTHUB_MESSAGE_HANDLE msg_handle, const char* key) |
AzureIoTClient | 88:248736be106e | 500 | { |
AzureIoTClient | 88:248736be106e | 501 | const char* result; |
AzureIoTClient | 88:248736be106e | 502 | if (msg_handle == NULL || key == NULL) |
AzureIoTClient | 88:248736be106e | 503 | { |
AzureIoTClient | 88:248736be106e | 504 | LogError("invalid parameter (NULL) to IoTHubMessage_GetProperty iotHubMessageHandle=%p, key=%p", msg_handle, key); |
AzureIoTClient | 88:248736be106e | 505 | result = NULL; |
AzureIoTClient | 88:248736be106e | 506 | } |
AzureIoTClient | 88:248736be106e | 507 | else |
AzureIoTClient | 88:248736be106e | 508 | { |
AzureIoTClient | 88:248736be106e | 509 | bool key_exists = false; |
AzureIoTClient | 88:248736be106e | 510 | // The return value is not neccessary, just check the key_exist variable |
AzureIoTClient | 88:248736be106e | 511 | if ((Map_ContainsKey(msg_handle->properties, key, &key_exists) == MAP_OK) && key_exists) |
AzureIoTClient | 88:248736be106e | 512 | { |
AzureIoTClient | 88:248736be106e | 513 | result = Map_GetValueFromKey(msg_handle->properties, key); |
AzureIoTClient | 88:248736be106e | 514 | } |
AzureIoTClient | 88:248736be106e | 515 | else |
AzureIoTClient | 88:248736be106e | 516 | { |
AzureIoTClient | 88:248736be106e | 517 | result = NULL; |
AzureIoTClient | 88:248736be106e | 518 | } |
AzureIoTClient | 88:248736be106e | 519 | } |
AzureIoTClient | 88:248736be106e | 520 | return result; |
AzureIoTClient | 88:248736be106e | 521 | } |
AzureIoTClient | 88:248736be106e | 522 | |
AzureIoTClient | 18:1e9adb15c645 | 523 | const char* IoTHubMessage_GetCorrelationId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 18:1e9adb15c645 | 524 | { |
AzureIoTClient | 18:1e9adb15c645 | 525 | const char* result; |
AzureIoTClient | 18:1e9adb15c645 | 526 | /* Codes_SRS_IOTHUBMESSAGE_07_016: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetCorrelationId shall return a NULL value.] */ |
AzureIoTClient | 18:1e9adb15c645 | 527 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 528 | { |
AzureIoTClient | 39:2719651a5bee | 529 | LogError("invalid arg (NULL) passed to IoTHubMessage_GetCorrelationId"); |
AzureIoTClient | 18:1e9adb15c645 | 530 | result = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 531 | } |
AzureIoTClient | 18:1e9adb15c645 | 532 | else |
AzureIoTClient | 18:1e9adb15c645 | 533 | { |
AzureIoTClient | 18:1e9adb15c645 | 534 | /* Codes_SRS_IOTHUBMESSAGE_07_017: [IoTHubMessage_GetCorrelationId shall return the correlationId as a const char*.] */ |
AzureIoTClient | 18:1e9adb15c645 | 535 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 536 | result = handleData->correlationId; |
AzureIoTClient | 18:1e9adb15c645 | 537 | } |
AzureIoTClient | 18:1e9adb15c645 | 538 | return result; |
AzureIoTClient | 18:1e9adb15c645 | 539 | } |
AzureIoTClient | 18:1e9adb15c645 | 540 | |
AzureIoTClient | 18:1e9adb15c645 | 541 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetCorrelationId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* correlationId) |
AzureIoTClient | 18:1e9adb15c645 | 542 | { |
AzureIoTClient | 18:1e9adb15c645 | 543 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 18:1e9adb15c645 | 544 | /* 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 | 545 | if (iotHubMessageHandle == NULL || correlationId == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 546 | { |
AzureIoTClient | 39:2719651a5bee | 547 | LogError("invalid arg (NULL) passed to IoTHubMessage_SetCorrelationId"); |
AzureIoTClient | 18:1e9adb15c645 | 548 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 18:1e9adb15c645 | 549 | } |
AzureIoTClient | 18:1e9adb15c645 | 550 | else |
AzureIoTClient | 18:1e9adb15c645 | 551 | { |
AzureIoTClient | 18:1e9adb15c645 | 552 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 553 | /* 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 | 554 | if (handleData->correlationId != NULL) |
AzureIoTClient | 18:1e9adb15c645 | 555 | { |
AzureIoTClient | 18:1e9adb15c645 | 556 | free(handleData->correlationId); |
AzureIoTClient | 74:ea0021abecf7 | 557 | handleData->correlationId = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 558 | } |
AzureIoTClient | 18:1e9adb15c645 | 559 | |
AzureIoTClient | 18:1e9adb15c645 | 560 | if (mallocAndStrcpy_s(&handleData->correlationId, correlationId) != 0) |
AzureIoTClient | 18:1e9adb15c645 | 561 | { |
AzureIoTClient | 18:1e9adb15c645 | 562 | /* 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 | 563 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 18:1e9adb15c645 | 564 | } |
AzureIoTClient | 18:1e9adb15c645 | 565 | else |
AzureIoTClient | 18:1e9adb15c645 | 566 | { |
AzureIoTClient | 18:1e9adb15c645 | 567 | /* Codes_SRS_IOTHUBMESSAGE_07_021: [IoTHubMessage_SetCorrelationId finishes successfully it shall return IOTHUB_MESSAGE_OK.] */ |
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 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetMessageId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* messageId) |
AzureIoTClient | 18:1e9adb15c645 | 575 | { |
AzureIoTClient | 18:1e9adb15c645 | 576 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 18:1e9adb15c645 | 577 | /* 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 | 578 | if (iotHubMessageHandle == NULL || messageId == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 579 | { |
AzureIoTClient | 39:2719651a5bee | 580 | LogError("invalid arg (NULL) passed to IoTHubMessage_SetMessageId"); |
AzureIoTClient | 18:1e9adb15c645 | 581 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 18:1e9adb15c645 | 582 | } |
AzureIoTClient | 18:1e9adb15c645 | 583 | else |
AzureIoTClient | 18:1e9adb15c645 | 584 | { |
AzureIoTClient | 18:1e9adb15c645 | 585 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 586 | /* 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 | 587 | if (handleData->messageId != NULL) |
AzureIoTClient | 18:1e9adb15c645 | 588 | { |
AzureIoTClient | 18:1e9adb15c645 | 589 | free(handleData->messageId); |
AzureIoTClient | 74:ea0021abecf7 | 590 | handleData->messageId = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 591 | } |
AzureIoTClient | 18:1e9adb15c645 | 592 | |
AzureIoTClient | 18:1e9adb15c645 | 593 | /* 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 | 594 | if (mallocAndStrcpy_s(&handleData->messageId, messageId) != 0) |
AzureIoTClient | 18:1e9adb15c645 | 595 | { |
AzureIoTClient | 18:1e9adb15c645 | 596 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 18:1e9adb15c645 | 597 | } |
AzureIoTClient | 18:1e9adb15c645 | 598 | else |
AzureIoTClient | 18:1e9adb15c645 | 599 | { |
AzureIoTClient | 18:1e9adb15c645 | 600 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 18:1e9adb15c645 | 601 | } |
AzureIoTClient | 18:1e9adb15c645 | 602 | } |
AzureIoTClient | 18:1e9adb15c645 | 603 | return result; |
AzureIoTClient | 18:1e9adb15c645 | 604 | } |
AzureIoTClient | 18:1e9adb15c645 | 605 | |
AzureIoTClient | 18:1e9adb15c645 | 606 | const char* IoTHubMessage_GetMessageId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 18:1e9adb15c645 | 607 | { |
AzureIoTClient | 18:1e9adb15c645 | 608 | const char* result; |
AzureIoTClient | 18:1e9adb15c645 | 609 | /* Codes_SRS_IOTHUBMESSAGE_07_010: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_MessageId shall return a NULL value.] */ |
AzureIoTClient | 18:1e9adb15c645 | 610 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 18:1e9adb15c645 | 611 | { |
AzureIoTClient | 39:2719651a5bee | 612 | LogError("invalid arg (NULL) passed to IoTHubMessage_GetMessageId"); |
AzureIoTClient | 18:1e9adb15c645 | 613 | result = NULL; |
AzureIoTClient | 18:1e9adb15c645 | 614 | } |
AzureIoTClient | 18:1e9adb15c645 | 615 | else |
AzureIoTClient | 18:1e9adb15c645 | 616 | { |
AzureIoTClient | 18:1e9adb15c645 | 617 | /* Codes_SRS_IOTHUBMESSAGE_07_011: [IoTHubMessage_MessageId shall return the messageId as a const char*.] */ |
AzureIoTClient | 18:1e9adb15c645 | 618 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 18:1e9adb15c645 | 619 | result = handleData->messageId; |
AzureIoTClient | 18:1e9adb15c645 | 620 | } |
AzureIoTClient | 18:1e9adb15c645 | 621 | return result; |
AzureIoTClient | 18:1e9adb15c645 | 622 | } |
AzureIoTClient | 18:1e9adb15c645 | 623 | |
AzureIoTClient | 74:ea0021abecf7 | 624 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetContentTypeSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* contentType) |
AzureIoTClient | 74:ea0021abecf7 | 625 | { |
AzureIoTClient | 74:ea0021abecf7 | 626 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 74:ea0021abecf7 | 627 | |
AzureIoTClient | 92:97148cf9aa2a | 628 | // 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 | 629 | if (iotHubMessageHandle == NULL || contentType == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 630 | { |
AzureIoTClient | 74:ea0021abecf7 | 631 | LogError("Invalid argument (iotHubMessageHandle=%p, contentType=%p)", iotHubMessageHandle, contentType); |
AzureIoTClient | 74:ea0021abecf7 | 632 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 74:ea0021abecf7 | 633 | } |
AzureIoTClient | 74:ea0021abecf7 | 634 | else |
AzureIoTClient | 74:ea0021abecf7 | 635 | { |
AzureIoTClient | 74:ea0021abecf7 | 636 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 637 | |
AzureIoTClient | 92:97148cf9aa2a | 638 | // Codes_SRS_IOTHUBMESSAGE_09_002: [If the IOTHUB_MESSAGE_HANDLE `contentType` is not NULL it shall be deallocated.] |
AzureIoTClient | 74:ea0021abecf7 | 639 | if (handleData->userDefinedContentType != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 640 | { |
AzureIoTClient | 74:ea0021abecf7 | 641 | free(handleData->userDefinedContentType); |
AzureIoTClient | 74:ea0021abecf7 | 642 | handleData->userDefinedContentType = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 643 | } |
AzureIoTClient | 74:ea0021abecf7 | 644 | |
AzureIoTClient | 74:ea0021abecf7 | 645 | if (mallocAndStrcpy_s(&handleData->userDefinedContentType, contentType) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 646 | { |
AzureIoTClient | 74:ea0021abecf7 | 647 | LogError("Failed saving a copy of contentType"); |
AzureIoTClient | 92:97148cf9aa2a | 648 | // 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 | 649 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 650 | } |
AzureIoTClient | 74:ea0021abecf7 | 651 | else |
AzureIoTClient | 74:ea0021abecf7 | 652 | { |
AzureIoTClient | 74:ea0021abecf7 | 653 | // Codes_SRS_IOTHUBMESSAGE_09_004: [If IoTHubMessage_SetContentTypeSystemProperty finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 74:ea0021abecf7 | 654 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 74:ea0021abecf7 | 655 | } |
AzureIoTClient | 74:ea0021abecf7 | 656 | } |
AzureIoTClient | 74:ea0021abecf7 | 657 | |
AzureIoTClient | 74:ea0021abecf7 | 658 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 659 | } |
AzureIoTClient | 74:ea0021abecf7 | 660 | |
AzureIoTClient | 74:ea0021abecf7 | 661 | const char* IoTHubMessage_GetContentTypeSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 74:ea0021abecf7 | 662 | { |
AzureIoTClient | 74:ea0021abecf7 | 663 | const char* result; |
AzureIoTClient | 74:ea0021abecf7 | 664 | |
AzureIoTClient | 92:97148cf9aa2a | 665 | // 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 | 666 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 667 | { |
AzureIoTClient | 74:ea0021abecf7 | 668 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 74:ea0021abecf7 | 669 | result = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 670 | } |
AzureIoTClient | 74:ea0021abecf7 | 671 | else |
AzureIoTClient | 74:ea0021abecf7 | 672 | { |
AzureIoTClient | 74:ea0021abecf7 | 673 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 674 | |
AzureIoTClient | 92:97148cf9aa2a | 675 | // Codes_SRS_IOTHUBMESSAGE_09_006: [IoTHubMessage_GetContentTypeSystemProperty shall return the `contentType` as a const char* ] |
AzureIoTClient | 74:ea0021abecf7 | 676 | result = (const char*)handleData->userDefinedContentType; |
AzureIoTClient | 74:ea0021abecf7 | 677 | } |
AzureIoTClient | 74:ea0021abecf7 | 678 | |
AzureIoTClient | 74:ea0021abecf7 | 679 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 680 | } |
AzureIoTClient | 74:ea0021abecf7 | 681 | |
AzureIoTClient | 74:ea0021abecf7 | 682 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetContentEncodingSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* contentEncoding) |
AzureIoTClient | 74:ea0021abecf7 | 683 | { |
AzureIoTClient | 74:ea0021abecf7 | 684 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 74:ea0021abecf7 | 685 | |
AzureIoTClient | 92:97148cf9aa2a | 686 | // 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 | 687 | if (iotHubMessageHandle == NULL || contentEncoding == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 688 | { |
AzureIoTClient | 74:ea0021abecf7 | 689 | LogError("Invalid argument (iotHubMessageHandle=%p, contentEncoding=%p)", iotHubMessageHandle, contentEncoding); |
AzureIoTClient | 74:ea0021abecf7 | 690 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 74:ea0021abecf7 | 691 | } |
AzureIoTClient | 74:ea0021abecf7 | 692 | else |
AzureIoTClient | 74:ea0021abecf7 | 693 | { |
AzureIoTClient | 74:ea0021abecf7 | 694 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 695 | |
AzureIoTClient | 92:97148cf9aa2a | 696 | // Codes_SRS_IOTHUBMESSAGE_09_007: [If the IOTHUB_MESSAGE_HANDLE `contentEncoding` is not NULL it shall be deallocated.] |
AzureIoTClient | 74:ea0021abecf7 | 697 | if (handleData->contentEncoding != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 698 | { |
AzureIoTClient | 74:ea0021abecf7 | 699 | free(handleData->contentEncoding); |
AzureIoTClient | 74:ea0021abecf7 | 700 | handleData->contentEncoding = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 701 | } |
AzureIoTClient | 74:ea0021abecf7 | 702 | |
AzureIoTClient | 74:ea0021abecf7 | 703 | if (mallocAndStrcpy_s(&handleData->contentEncoding, contentEncoding) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 704 | { |
AzureIoTClient | 74:ea0021abecf7 | 705 | LogError("Failed saving a copy of contentEncoding"); |
AzureIoTClient | 74:ea0021abecf7 | 706 | // 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 | 707 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 708 | } |
AzureIoTClient | 74:ea0021abecf7 | 709 | else |
AzureIoTClient | 74:ea0021abecf7 | 710 | { |
AzureIoTClient | 74:ea0021abecf7 | 711 | // Codes_SRS_IOTHUBMESSAGE_09_009: [If IoTHubMessage_SetContentEncodingSystemProperty finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 74:ea0021abecf7 | 712 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 74:ea0021abecf7 | 713 | } |
AzureIoTClient | 74:ea0021abecf7 | 714 | } |
AzureIoTClient | 74:ea0021abecf7 | 715 | |
AzureIoTClient | 74:ea0021abecf7 | 716 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 717 | } |
AzureIoTClient | 74:ea0021abecf7 | 718 | |
AzureIoTClient | 74:ea0021abecf7 | 719 | const char* IoTHubMessage_GetContentEncodingSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 74:ea0021abecf7 | 720 | { |
AzureIoTClient | 74:ea0021abecf7 | 721 | const char* result; |
AzureIoTClient | 74:ea0021abecf7 | 722 | |
AzureIoTClient | 92:97148cf9aa2a | 723 | // 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 | 724 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 725 | { |
AzureIoTClient | 74:ea0021abecf7 | 726 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 74:ea0021abecf7 | 727 | result = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 728 | } |
AzureIoTClient | 74:ea0021abecf7 | 729 | else |
AzureIoTClient | 74:ea0021abecf7 | 730 | { |
AzureIoTClient | 74:ea0021abecf7 | 731 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; |
AzureIoTClient | 74:ea0021abecf7 | 732 | |
AzureIoTClient | 92:97148cf9aa2a | 733 | // Codes_SRS_IOTHUBMESSAGE_09_011: [IoTHubMessage_GetContentEncodingSystemProperty shall return the `contentEncoding` as a const char* ] |
AzureIoTClient | 74:ea0021abecf7 | 734 | result = (const char*)handleData->contentEncoding; |
AzureIoTClient | 74:ea0021abecf7 | 735 | } |
AzureIoTClient | 74:ea0021abecf7 | 736 | |
AzureIoTClient | 74:ea0021abecf7 | 737 | return result; |
AzureIoTClient | 74:ea0021abecf7 | 738 | } |
AzureIoTClient | 74:ea0021abecf7 | 739 | |
AzureIoTClient | 77:e4e36df9caee | 740 | const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* IoTHubMessage_GetDiagnosticPropertyData(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 77:e4e36df9caee | 741 | { |
AzureIoTClient | 77:e4e36df9caee | 742 | const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* result; |
AzureIoTClient | 92:97148cf9aa2a | 743 | // Codes_SRS_IOTHUBMESSAGE_10_001: [If any of the parameters are NULL then IoTHubMessage_GetDiagnosticPropertyData shall return a NULL value.] |
AzureIoTClient | 77:e4e36df9caee | 744 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 77:e4e36df9caee | 745 | { |
AzureIoTClient | 77:e4e36df9caee | 746 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 77:e4e36df9caee | 747 | result = NULL; |
AzureIoTClient | 77:e4e36df9caee | 748 | } |
AzureIoTClient | 77:e4e36df9caee | 749 | else |
AzureIoTClient | 77:e4e36df9caee | 750 | { |
AzureIoTClient | 77:e4e36df9caee | 751 | /* Codes_SRS_IOTHUBMESSAGE_10_002: [IoTHubMessage_GetDiagnosticPropertyData shall return the diagnosticData as a const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*.] */ |
AzureIoTClient | 77:e4e36df9caee | 752 | result = iotHubMessageHandle->diagnosticData; |
AzureIoTClient | 77:e4e36df9caee | 753 | } |
AzureIoTClient | 77:e4e36df9caee | 754 | return result; |
AzureIoTClient | 77:e4e36df9caee | 755 | } |
AzureIoTClient | 77:e4e36df9caee | 756 | |
AzureIoTClient | 77:e4e36df9caee | 757 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetDiagnosticPropertyData(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* diagnosticData) |
AzureIoTClient | 77:e4e36df9caee | 758 | { |
AzureIoTClient | 77:e4e36df9caee | 759 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 92:97148cf9aa2a | 760 | // Codes_SRS_IOTHUBMESSAGE_10_003: [If any of the parameters are NULL then IoTHubMessage_SetDiagnosticId shall return a IOTHUB_MESSAGE_INVALID_ARG value.] |
AzureIoTClient | 92:97148cf9aa2a | 761 | if (iotHubMessageHandle == NULL || |
AzureIoTClient | 77:e4e36df9caee | 762 | diagnosticData == NULL || |
AzureIoTClient | 77:e4e36df9caee | 763 | diagnosticData->diagnosticCreationTimeUtc == NULL || |
AzureIoTClient | 77:e4e36df9caee | 764 | diagnosticData->diagnosticId == NULL) |
AzureIoTClient | 77:e4e36df9caee | 765 | { |
AzureIoTClient | 92:97148cf9aa2a | 766 | LogError("Invalid argument (iotHubMessageHandle=%p, diagnosticData=%p, diagnosticData->diagnosticId=%p, diagnosticData->diagnosticCreationTimeUtc=%p)", |
AzureIoTClient | 92:97148cf9aa2a | 767 | iotHubMessageHandle, diagnosticData, |
AzureIoTClient | 77:e4e36df9caee | 768 | diagnosticData == NULL ? NULL : diagnosticData->diagnosticId, |
AzureIoTClient | 77:e4e36df9caee | 769 | diagnosticData == NULL ? NULL : diagnosticData->diagnosticCreationTimeUtc); |
AzureIoTClient | 77:e4e36df9caee | 770 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 77:e4e36df9caee | 771 | } |
AzureIoTClient | 77:e4e36df9caee | 772 | else |
AzureIoTClient | 77:e4e36df9caee | 773 | { |
AzureIoTClient | 92:97148cf9aa2a | 774 | // Codes_SRS_IOTHUBMESSAGE_10_004: [If the IOTHUB_MESSAGE_HANDLE `diagnosticData` is not NULL it shall be deallocated.] |
AzureIoTClient | 77:e4e36df9caee | 775 | if (iotHubMessageHandle->diagnosticData != NULL) |
AzureIoTClient | 77:e4e36df9caee | 776 | { |
AzureIoTClient | 77:e4e36df9caee | 777 | DestroyDiagnosticPropertyData(iotHubMessageHandle->diagnosticData); |
AzureIoTClient | 77:e4e36df9caee | 778 | iotHubMessageHandle->diagnosticData = NULL; |
AzureIoTClient | 77:e4e36df9caee | 779 | } |
AzureIoTClient | 77:e4e36df9caee | 780 | |
AzureIoTClient | 77:e4e36df9caee | 781 | // 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 | 782 | if ((iotHubMessageHandle->diagnosticData = CloneDiagnosticPropertyData(diagnosticData)) == NULL) |
AzureIoTClient | 77:e4e36df9caee | 783 | { |
AzureIoTClient | 77:e4e36df9caee | 784 | LogError("Failed saving a copy of diagnosticData"); |
AzureIoTClient | 77:e4e36df9caee | 785 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 77:e4e36df9caee | 786 | } |
AzureIoTClient | 77:e4e36df9caee | 787 | else |
AzureIoTClient | 77:e4e36df9caee | 788 | { |
AzureIoTClient | 77:e4e36df9caee | 789 | // Codes_SRS_IOTHUBMESSAGE_10_006: [If IoTHubMessage_SetDiagnosticPropertyData finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 77:e4e36df9caee | 790 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 77:e4e36df9caee | 791 | } |
AzureIoTClient | 77:e4e36df9caee | 792 | } |
AzureIoTClient | 77:e4e36df9caee | 793 | return result; |
AzureIoTClient | 77:e4e36df9caee | 794 | } |
AzureIoTClient | 77:e4e36df9caee | 795 | |
AzureIoTClient | 89:a2ed767a532e | 796 | |
AzureIoTClient | 89:a2ed767a532e | 797 | const char* IoTHubMessage_GetOutputName(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 89:a2ed767a532e | 798 | { |
AzureIoTClient | 89:a2ed767a532e | 799 | const char* result; |
AzureIoTClient | 89:a2ed767a532e | 800 | // Codes_SRS_IOTHUBMESSAGE_31_034: [If the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetOutputName shall return a NULL value.] |
AzureIoTClient | 89:a2ed767a532e | 801 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 89:a2ed767a532e | 802 | { |
AzureIoTClient | 89:a2ed767a532e | 803 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 89:a2ed767a532e | 804 | result = NULL; |
AzureIoTClient | 89:a2ed767a532e | 805 | } |
AzureIoTClient | 89:a2ed767a532e | 806 | else |
AzureIoTClient | 89:a2ed767a532e | 807 | { |
AzureIoTClient | 89:a2ed767a532e | 808 | // Codes_SRS_IOTHUBMESSAGE_31_035: [IoTHubMessage_GetOutputName shall return the OutputName as a const char*.] |
AzureIoTClient | 89:a2ed767a532e | 809 | result = iotHubMessageHandle->outputName; |
AzureIoTClient | 89:a2ed767a532e | 810 | } |
AzureIoTClient | 89:a2ed767a532e | 811 | return result; |
AzureIoTClient | 89:a2ed767a532e | 812 | } |
AzureIoTClient | 89:a2ed767a532e | 813 | |
AzureIoTClient | 89:a2ed767a532e | 814 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetOutputName(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* outputName) |
AzureIoTClient | 89:a2ed767a532e | 815 | { |
AzureIoTClient | 89:a2ed767a532e | 816 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 89:a2ed767a532e | 817 | |
AzureIoTClient | 89:a2ed767a532e | 818 | // Codes_SRS_IOTHUBMESSAGE_31_036: [If any of the parameters are NULL then IoTHubMessage_SetOutputName shall return a IOTHUB_MESSAGE_INVALID_ARG value.] |
AzureIoTClient | 89:a2ed767a532e | 819 | if ((iotHubMessageHandle == NULL) || (outputName == NULL)) |
AzureIoTClient | 89:a2ed767a532e | 820 | { |
AzureIoTClient | 89:a2ed767a532e | 821 | LogError("Invalid argument (iotHubMessageHandle=%p, outputName=%p)", iotHubMessageHandle, outputName); |
AzureIoTClient | 89:a2ed767a532e | 822 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 89:a2ed767a532e | 823 | } |
AzureIoTClient | 89:a2ed767a532e | 824 | else |
AzureIoTClient | 89:a2ed767a532e | 825 | { |
AzureIoTClient | 89:a2ed767a532e | 826 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 89:a2ed767a532e | 827 | |
AzureIoTClient | 89:a2ed767a532e | 828 | // Codes_SRS_IOTHUBMESSAGE_31_037: [If the IOTHUB_MESSAGE_HANDLE OutputName is not NULL, then the IOTHUB_MESSAGE_HANDLE OutputName will be deallocated.] |
AzureIoTClient | 89:a2ed767a532e | 829 | if (handleData->outputName != NULL) |
AzureIoTClient | 89:a2ed767a532e | 830 | { |
AzureIoTClient | 89:a2ed767a532e | 831 | free(handleData->outputName); |
AzureIoTClient | 89:a2ed767a532e | 832 | handleData->outputName = NULL; |
AzureIoTClient | 89:a2ed767a532e | 833 | } |
AzureIoTClient | 89:a2ed767a532e | 834 | |
AzureIoTClient | 89:a2ed767a532e | 835 | if (mallocAndStrcpy_s(&handleData->outputName, outputName) != 0) |
AzureIoTClient | 89:a2ed767a532e | 836 | { |
AzureIoTClient | 89:a2ed767a532e | 837 | // Codes_SRS_IOTHUBMESSAGE_31_038: [If the allocation or the copying of the OutputName fails, then IoTHubMessage_SetOutputName shall return IOTHUB_MESSAGE_ERROR.] |
AzureIoTClient | 89:a2ed767a532e | 838 | LogError("Failed saving a copy of outputName"); |
AzureIoTClient | 89:a2ed767a532e | 839 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 89:a2ed767a532e | 840 | } |
AzureIoTClient | 89:a2ed767a532e | 841 | else |
AzureIoTClient | 89:a2ed767a532e | 842 | { |
AzureIoTClient | 89:a2ed767a532e | 843 | // Codes_SRS_IOTHUBMESSAGE_31_039: [IoTHubMessage_SetOutputName finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 89:a2ed767a532e | 844 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 89:a2ed767a532e | 845 | } |
AzureIoTClient | 89:a2ed767a532e | 846 | |
AzureIoTClient | 89:a2ed767a532e | 847 | } |
AzureIoTClient | 89:a2ed767a532e | 848 | |
AzureIoTClient | 89:a2ed767a532e | 849 | return result; |
AzureIoTClient | 89:a2ed767a532e | 850 | } |
AzureIoTClient | 89:a2ed767a532e | 851 | |
AzureIoTClient | 89:a2ed767a532e | 852 | const char* IoTHubMessage_GetInputName(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 89:a2ed767a532e | 853 | { |
AzureIoTClient | 89:a2ed767a532e | 854 | const char* result; |
AzureIoTClient | 89:a2ed767a532e | 855 | // Codes_SRS_IOTHUBMESSAGE_31_040: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetInputName shall return a NULL value.] |
AzureIoTClient | 89:a2ed767a532e | 856 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 89:a2ed767a532e | 857 | { |
AzureIoTClient | 89:a2ed767a532e | 858 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 89:a2ed767a532e | 859 | result = NULL; |
AzureIoTClient | 89:a2ed767a532e | 860 | } |
AzureIoTClient | 89:a2ed767a532e | 861 | else |
AzureIoTClient | 89:a2ed767a532e | 862 | { |
AzureIoTClient | 89:a2ed767a532e | 863 | // Codes_SRS_IOTHUBMESSAGE_31_041: [IoTHubMessage_GetInputName shall return the InputName as a const char*.] |
AzureIoTClient | 89:a2ed767a532e | 864 | result = iotHubMessageHandle->inputName; |
AzureIoTClient | 89:a2ed767a532e | 865 | } |
AzureIoTClient | 89:a2ed767a532e | 866 | return result; |
AzureIoTClient | 89:a2ed767a532e | 867 | } |
AzureIoTClient | 89:a2ed767a532e | 868 | |
AzureIoTClient | 89:a2ed767a532e | 869 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetInputName(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* inputName) |
AzureIoTClient | 89:a2ed767a532e | 870 | { |
AzureIoTClient | 89:a2ed767a532e | 871 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 89:a2ed767a532e | 872 | |
AzureIoTClient | 89:a2ed767a532e | 873 | // Codes_SRS_IOTHUBMESSAGE_31_042: [if any of the parameters are NULL then IoTHubMessage_SetInputName shall return a IOTHUB_MESSAGE_INVALID_ARG value.] |
AzureIoTClient | 89:a2ed767a532e | 874 | if ((iotHubMessageHandle == NULL) || (inputName == NULL)) |
AzureIoTClient | 89:a2ed767a532e | 875 | { |
AzureIoTClient | 89:a2ed767a532e | 876 | LogError("Invalid argument (iotHubMessageHandle=%p, inputName=%p)", iotHubMessageHandle, inputName); |
AzureIoTClient | 89:a2ed767a532e | 877 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 89:a2ed767a532e | 878 | } |
AzureIoTClient | 89:a2ed767a532e | 879 | else |
AzureIoTClient | 89:a2ed767a532e | 880 | { |
AzureIoTClient | 89:a2ed767a532e | 881 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 89:a2ed767a532e | 882 | |
AzureIoTClient | 89:a2ed767a532e | 883 | // Codes_SRS_IOTHUBMESSAGE_31_043: [If the IOTHUB_MESSAGE_HANDLE InputName is not NULL, then the IOTHUB_MESSAGE_HANDLE InputName will be deallocated.] |
AzureIoTClient | 89:a2ed767a532e | 884 | if (handleData->inputName != NULL) |
AzureIoTClient | 89:a2ed767a532e | 885 | { |
AzureIoTClient | 89:a2ed767a532e | 886 | free(handleData->inputName); |
AzureIoTClient | 89:a2ed767a532e | 887 | handleData->inputName = NULL; |
AzureIoTClient | 89:a2ed767a532e | 888 | } |
AzureIoTClient | 89:a2ed767a532e | 889 | |
AzureIoTClient | 89:a2ed767a532e | 890 | if (mallocAndStrcpy_s(&handleData->inputName, inputName) != 0) |
AzureIoTClient | 89:a2ed767a532e | 891 | { |
AzureIoTClient | 89:a2ed767a532e | 892 | // Codes_SRS_IOTHUBMESSAGE_31_044: [If the allocation or the copying of the InputName fails, then IoTHubMessage_SetInputName shall return IOTHUB_MESSAGE_ERROR.] |
AzureIoTClient | 89:a2ed767a532e | 893 | LogError("Failed saving a copy of inputName"); |
AzureIoTClient | 89:a2ed767a532e | 894 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 89:a2ed767a532e | 895 | } |
AzureIoTClient | 89:a2ed767a532e | 896 | else |
AzureIoTClient | 89:a2ed767a532e | 897 | { |
AzureIoTClient | 89:a2ed767a532e | 898 | // Codes_SRS_IOTHUBMESSAGE_31_045: [IoTHubMessage_SetInputName finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 89:a2ed767a532e | 899 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 89:a2ed767a532e | 900 | } |
AzureIoTClient | 89:a2ed767a532e | 901 | |
AzureIoTClient | 89:a2ed767a532e | 902 | } |
AzureIoTClient | 89:a2ed767a532e | 903 | |
AzureIoTClient | 89:a2ed767a532e | 904 | return result; |
AzureIoTClient | 89:a2ed767a532e | 905 | } |
AzureIoTClient | 89:a2ed767a532e | 906 | |
AzureIoTClient | 89:a2ed767a532e | 907 | |
AzureIoTClient | 89:a2ed767a532e | 908 | const char* IoTHubMessage_GetConnectionModuleId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 89:a2ed767a532e | 909 | { |
AzureIoTClient | 89:a2ed767a532e | 910 | const char* result; |
AzureIoTClient | 89:a2ed767a532e | 911 | // Codes_SRS_IOTHUBMESSAGE_31_046: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetConnectionModuleId shall return a NULL value.] |
AzureIoTClient | 89:a2ed767a532e | 912 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 89:a2ed767a532e | 913 | { |
AzureIoTClient | 89:a2ed767a532e | 914 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 89:a2ed767a532e | 915 | result = NULL; |
AzureIoTClient | 89:a2ed767a532e | 916 | } |
AzureIoTClient | 89:a2ed767a532e | 917 | else |
AzureIoTClient | 89:a2ed767a532e | 918 | { |
AzureIoTClient | 89:a2ed767a532e | 919 | // Codes_SRS_IOTHUBMESSAGE_31_047: [IoTHubMessage_GetConnectionModuleId shall return the ConnectionModuleId as a const char*.] |
AzureIoTClient | 89:a2ed767a532e | 920 | result = iotHubMessageHandle->connectionModuleId; |
AzureIoTClient | 89:a2ed767a532e | 921 | } |
AzureIoTClient | 89:a2ed767a532e | 922 | return result; |
AzureIoTClient | 89:a2ed767a532e | 923 | } |
AzureIoTClient | 89:a2ed767a532e | 924 | |
AzureIoTClient | 89:a2ed767a532e | 925 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetConnectionModuleId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* connectionModuleId) |
AzureIoTClient | 89:a2ed767a532e | 926 | { |
AzureIoTClient | 89:a2ed767a532e | 927 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 89:a2ed767a532e | 928 | |
AzureIoTClient | 89:a2ed767a532e | 929 | // Codes_SRS_IOTHUBMESSAGE_31_048: [if any of the parameters are NULL then IoTHubMessage_SetConnectionModuleId shall return a IOTHUB_MESSAGE_INVALID_ARG value.] |
AzureIoTClient | 89:a2ed767a532e | 930 | if ((iotHubMessageHandle == NULL) || (connectionModuleId == NULL)) |
AzureIoTClient | 89:a2ed767a532e | 931 | { |
AzureIoTClient | 89:a2ed767a532e | 932 | LogError("Invalid argument (iotHubMessageHandle=%p, connectionModuleId=%p)", iotHubMessageHandle, connectionModuleId); |
AzureIoTClient | 89:a2ed767a532e | 933 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 89:a2ed767a532e | 934 | } |
AzureIoTClient | 89:a2ed767a532e | 935 | else |
AzureIoTClient | 89:a2ed767a532e | 936 | { |
AzureIoTClient | 89:a2ed767a532e | 937 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 89:a2ed767a532e | 938 | |
AzureIoTClient | 89:a2ed767a532e | 939 | // Codes_SRS_IOTHUBMESSAGE_31_049: [If the IOTHUB_MESSAGE_HANDLE ConnectionModuleId is not NULL, then the IOTHUB_MESSAGE_HANDLE ConnectionModuleId will be deallocated.] |
AzureIoTClient | 89:a2ed767a532e | 940 | if (handleData->connectionModuleId != NULL) |
AzureIoTClient | 89:a2ed767a532e | 941 | { |
AzureIoTClient | 89:a2ed767a532e | 942 | free(handleData->connectionModuleId); |
AzureIoTClient | 89:a2ed767a532e | 943 | handleData->connectionModuleId = NULL; |
AzureIoTClient | 89:a2ed767a532e | 944 | } |
AzureIoTClient | 89:a2ed767a532e | 945 | |
AzureIoTClient | 89:a2ed767a532e | 946 | if (mallocAndStrcpy_s(&handleData->connectionModuleId, connectionModuleId) != 0) |
AzureIoTClient | 89:a2ed767a532e | 947 | { |
AzureIoTClient | 89:a2ed767a532e | 948 | // Codes_SRS_IOTHUBMESSAGE_31_050: [If the allocation or the copying of the ConnectionModuleId fails, then IoTHubMessage_SetConnectionModuleId shall return IOTHUB_MESSAGE_ERROR.] |
AzureIoTClient | 89:a2ed767a532e | 949 | LogError("Failed saving a copy of connectionModuleId"); |
AzureIoTClient | 89:a2ed767a532e | 950 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 89:a2ed767a532e | 951 | } |
AzureIoTClient | 89:a2ed767a532e | 952 | else |
AzureIoTClient | 89:a2ed767a532e | 953 | { |
AzureIoTClient | 89:a2ed767a532e | 954 | // Codes_SRS_IOTHUBMESSAGE_31_051: [IoTHubMessage_SetConnectionModuleId finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 89:a2ed767a532e | 955 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 89:a2ed767a532e | 956 | } |
AzureIoTClient | 89:a2ed767a532e | 957 | |
AzureIoTClient | 89:a2ed767a532e | 958 | } |
AzureIoTClient | 89:a2ed767a532e | 959 | |
AzureIoTClient | 89:a2ed767a532e | 960 | return result; |
AzureIoTClient | 89:a2ed767a532e | 961 | } |
AzureIoTClient | 89:a2ed767a532e | 962 | |
AzureIoTClient | 89:a2ed767a532e | 963 | |
AzureIoTClient | 89:a2ed767a532e | 964 | const char* IoTHubMessage_GetConnectionDeviceId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 89:a2ed767a532e | 965 | { |
AzureIoTClient | 89:a2ed767a532e | 966 | const char* result; |
AzureIoTClient | 89:a2ed767a532e | 967 | // Codes_SRS_IOTHUBMESSAGE_31_052: [if the iotHubMessageHandle parameter is NULL then IoTHubMessage_GetConnectionDeviceId shall return a NULL value.] |
AzureIoTClient | 89:a2ed767a532e | 968 | if (iotHubMessageHandle == NULL) |
AzureIoTClient | 89:a2ed767a532e | 969 | { |
AzureIoTClient | 89:a2ed767a532e | 970 | LogError("Invalid argument (iotHubMessageHandle is NULL)"); |
AzureIoTClient | 89:a2ed767a532e | 971 | result = NULL; |
AzureIoTClient | 89:a2ed767a532e | 972 | } |
AzureIoTClient | 89:a2ed767a532e | 973 | else |
AzureIoTClient | 89:a2ed767a532e | 974 | { |
AzureIoTClient | 89:a2ed767a532e | 975 | // Codes_SRS_IOTHUBMESSAGE_31_053: [IoTHubMessage_GetConnectionDeviceId shall return the ConnectionDeviceId as a const char*.] |
AzureIoTClient | 89:a2ed767a532e | 976 | result = iotHubMessageHandle->connectionDeviceId; |
AzureIoTClient | 89:a2ed767a532e | 977 | } |
AzureIoTClient | 89:a2ed767a532e | 978 | return result; |
AzureIoTClient | 89:a2ed767a532e | 979 | } |
AzureIoTClient | 89:a2ed767a532e | 980 | |
AzureIoTClient | 89:a2ed767a532e | 981 | IOTHUB_MESSAGE_RESULT IoTHubMessage_SetConnectionDeviceId(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* connectionDeviceId) |
AzureIoTClient | 89:a2ed767a532e | 982 | { |
AzureIoTClient | 89:a2ed767a532e | 983 | IOTHUB_MESSAGE_RESULT result; |
AzureIoTClient | 89:a2ed767a532e | 984 | |
AzureIoTClient | 89:a2ed767a532e | 985 | // Codes_SRS_IOTHUBMESSAGE_31_054: [if any of the parameters are NULL then IoTHubMessage_SetConnectionDeviceId shall return a IOTHUB_MESSAGE_INVALID_ARG value.] |
AzureIoTClient | 89:a2ed767a532e | 986 | if ((iotHubMessageHandle == NULL) || (connectionDeviceId == NULL)) |
AzureIoTClient | 89:a2ed767a532e | 987 | { |
AzureIoTClient | 89:a2ed767a532e | 988 | LogError("Invalid argument (iotHubMessageHandle=%p, connectionDeviceId=%p)", iotHubMessageHandle, connectionDeviceId); |
AzureIoTClient | 89:a2ed767a532e | 989 | result = IOTHUB_MESSAGE_INVALID_ARG; |
AzureIoTClient | 89:a2ed767a532e | 990 | } |
AzureIoTClient | 89:a2ed767a532e | 991 | else |
AzureIoTClient | 89:a2ed767a532e | 992 | { |
AzureIoTClient | 89:a2ed767a532e | 993 | IOTHUB_MESSAGE_HANDLE_DATA* handleData = (IOTHUB_MESSAGE_HANDLE_DATA*)iotHubMessageHandle; |
AzureIoTClient | 89:a2ed767a532e | 994 | |
AzureIoTClient | 89:a2ed767a532e | 995 | // Codes_SRS_IOTHUBMESSAGE_31_055: [If the IOTHUB_MESSAGE_HANDLE ConnectionDeviceId is not NULL, then the IOTHUB_MESSAGE_HANDLE ConnectionDeviceId will be deallocated.] |
AzureIoTClient | 89:a2ed767a532e | 996 | if (handleData->connectionDeviceId != NULL) |
AzureIoTClient | 89:a2ed767a532e | 997 | { |
AzureIoTClient | 89:a2ed767a532e | 998 | free(handleData->connectionDeviceId); |
AzureIoTClient | 89:a2ed767a532e | 999 | handleData->connectionDeviceId = NULL; |
AzureIoTClient | 89:a2ed767a532e | 1000 | } |
AzureIoTClient | 89:a2ed767a532e | 1001 | |
AzureIoTClient | 89:a2ed767a532e | 1002 | if (mallocAndStrcpy_s(&handleData->connectionDeviceId, connectionDeviceId) != 0) |
AzureIoTClient | 89:a2ed767a532e | 1003 | { |
AzureIoTClient | 89:a2ed767a532e | 1004 | // Codes_SRS_IOTHUBMESSAGE_31_056: [If the allocation or the copying of the ConnectionDeviceId fails, then IoTHubMessage_SetConnectionDeviceId shall return IOTHUB_MESSAGE_ERROR.] |
AzureIoTClient | 89:a2ed767a532e | 1005 | LogError("Failed saving a copy of connectionDeviceId"); |
AzureIoTClient | 89:a2ed767a532e | 1006 | result = IOTHUB_MESSAGE_ERROR; |
AzureIoTClient | 89:a2ed767a532e | 1007 | } |
AzureIoTClient | 89:a2ed767a532e | 1008 | else |
AzureIoTClient | 89:a2ed767a532e | 1009 | { |
AzureIoTClient | 89:a2ed767a532e | 1010 | // Codes_SRS_IOTHUBMESSAGE_31_057: [IoTHubMessage_SetConnectionDeviceId finishes successfully it shall return IOTHUB_MESSAGE_OK.] |
AzureIoTClient | 89:a2ed767a532e | 1011 | result = IOTHUB_MESSAGE_OK; |
AzureIoTClient | 89:a2ed767a532e | 1012 | } |
AzureIoTClient | 89:a2ed767a532e | 1013 | |
AzureIoTClient | 89:a2ed767a532e | 1014 | } |
AzureIoTClient | 89:a2ed767a532e | 1015 | |
AzureIoTClient | 89:a2ed767a532e | 1016 | return result; |
AzureIoTClient | 89:a2ed767a532e | 1017 | } |
AzureIoTClient | 89:a2ed767a532e | 1018 | |
AzureIoTClient | 0:e393db310d89 | 1019 | void IoTHubMessage_Destroy(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) |
AzureIoTClient | 0:e393db310d89 | 1020 | { |
AzureIoTClient | 0:e393db310d89 | 1021 | /*Codes_SRS_IOTHUBMESSAGE_01_004: [If iotHubMessageHandle is NULL, IoTHubMessage_Destroy shall do nothing.] */ |
AzureIoTClient | 0:e393db310d89 | 1022 | if (iotHubMessageHandle != NULL) |
AzureIoTClient | 0:e393db310d89 | 1023 | { |
AzureIoTClient | 0:e393db310d89 | 1024 | /*Codes_SRS_IOTHUBMESSAGE_01_003: [IoTHubMessage_Destroy shall free all resources associated with iotHubMessageHandle.] */ |
AzureIoTClient | 78:74a8d3068204 | 1025 | DestroyMessageData((IOTHUB_MESSAGE_HANDLE_DATA* )iotHubMessageHandle); |
AzureIoTClient | 0:e393db310d89 | 1026 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1027 | } |