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

Committer:
AzureIoTClient
Date:
Mon Jul 18 16:45:01 2016 -0700
Revision:
46:6a69294b6119
Parent:
45:54c11b1b1407
Child:
47:aaa262b5f898
1.0.11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 16:deba40344375 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 16:deba40344375 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 16:deba40344375 3
AzureIoTClient 16:deba40344375 4 #include <stdlib.h>
AzureIoTClient 16:deba40344375 5 #ifdef _CRTDBG_MAP_ALLOC
AzureIoTClient 16:deba40344375 6 #include <crtdbg.h>
AzureIoTClient 16:deba40344375 7 #endif
Azure.IoT Build 38:a05929a75111 8 #include <string.h>
Azure.IoT Build 38:a05929a75111 9 #include "azure_c_shared_utility/gballoc.h"
Azure.IoT Build 38:a05929a75111 10 #include "azure_c_shared_utility/string_tokenizer.h"
Azure.IoT Build 38:a05929a75111 11 #include "azure_c_shared_utility/doublylinkedlist.h"
Azure.IoT Build 45:54c11b1b1407 12 #include "azure_c_shared_utility/xlogging.h"
Azure.IoT Build 38:a05929a75111 13 #include "azure_c_shared_utility/tickcounter.h"
AzureIoTClient 16:deba40344375 14
AzureIoTClient 16:deba40344375 15 #include "iothub_client_ll.h"
AzureIoTClient 16:deba40344375 16 #include "iothub_client_private.h"
AzureIoTClient 33:b372b0efcd20 17 #include "iothub_client_version.h"
Azure.IoT Build 38:a05929a75111 18 #include "iothub_transport_ll.h"
AzureIoTClient 43:038d8511e817 19
AzureIoTClient 44:33dd78697616 20 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 21 #include "iothub_client_ll_uploadtoblob.h"
AzureIoTClient 43:038d8511e817 22 #endif
Azure.IoT Build 36:67300d5a4c1f 23
Azure.IoT Build 45:54c11b1b1407 24 #define LOG_ERROR_RESULT LogError("result = %s", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result));
AzureIoTClient 16:deba40344375 25 #define INDEFINITE_TIME ((time_t)(-1))
AzureIoTClient 16:deba40344375 26
AzureIoTClient 16:deba40344375 27 DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_RESULT_VALUES);
Azure.IoT Build 45:54c11b1b1407 28 DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES);
AzureIoTClient 16:deba40344375 29
AzureIoTClient 16:deba40344375 30 typedef struct IOTHUB_CLIENT_LL_HANDLE_DATA_TAG
AzureIoTClient 16:deba40344375 31 {
AzureIoTClient 42:448eecc3676e 32 DLIST_ENTRY waitingToSend;
AzureIoTClient 42:448eecc3676e 33 TRANSPORT_LL_HANDLE transportHandle;
AzureIoTClient 42:448eecc3676e 34 bool isSharedTransport;
AzureIoTClient 42:448eecc3676e 35 IOTHUB_DEVICE_HANDLE deviceHandle;
AzureIoTClient 42:448eecc3676e 36 TRANSPORT_PROVIDER_FIELDS;
AzureIoTClient 42:448eecc3676e 37 IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback;
AzureIoTClient 42:448eecc3676e 38 void* messageUserContextCallback;
AzureIoTClient 42:448eecc3676e 39 time_t lastMessageReceiveTime;
AzureIoTClient 42:448eecc3676e 40 TICK_COUNTER_HANDLE tickCounter; /*shared tickcounter used to track message timeouts in waitingToSend list*/
AzureIoTClient 42:448eecc3676e 41 uint64_t currentMessageTimeout;
AzureIoTClient 44:33dd78697616 42 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 43 IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE uploadToBlobHandle;
AzureIoTClient 43:038d8511e817 44 #endif
AzureIoTClient 42:448eecc3676e 45
AzureIoTClient 16:deba40344375 46 }IOTHUB_CLIENT_LL_HANDLE_DATA;
AzureIoTClient 16:deba40344375 47
AzureIoTClient 16:deba40344375 48 static const char HOSTNAME_TOKEN[] = "HostName";
AzureIoTClient 16:deba40344375 49 static const char DEVICEID_TOKEN[] = "DeviceId";
Azure.IoT Build 45:54c11b1b1407 50 static const char X509_TOKEN[] = "x509";
Azure.IoT Build 45:54c11b1b1407 51 static const char X509_TOKEN_ONLY_ACCEPTABLE_VALUE[] = "true";
AzureIoTClient 16:deba40344375 52 static const char DEVICEKEY_TOKEN[] = "SharedAccessKey";
AzureIoTClient 40:1a94db9139ea 53 static const char DEVICESAS_TOKEN[] = "SharedAccessSignature";
AzureIoTClient 16:deba40344375 54 static const char PROTOCOL_GATEWAY_HOST[] = "GatewayHostName";
AzureIoTClient 16:deba40344375 55
AzureIoTClient 16:deba40344375 56 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol)
AzureIoTClient 16:deba40344375 57 {
AzureIoTClient 42:448eecc3676e 58 IOTHUB_CLIENT_LL_HANDLE result = NULL;
AzureIoTClient 16:deba40344375 59
AzureIoTClient 42:448eecc3676e 60 /*Codes_SRS_IOTHUBCLIENT_LL_05_001: [IoTHubClient_LL_CreateFromConnectionString shall obtain the version string by a call to IoTHubClient_GetVersionString.]*/
AzureIoTClient 42:448eecc3676e 61 /*Codes_SRS_IOTHUBCLIENT_LL_05_002: [IoTHubClient_LL_CreateFromConnectionString shall print the version string to standard output.]*/
AzureIoTClient 42:448eecc3676e 62 LogInfo("IoT Hub SDK for C, version %s", IoTHubClient_GetVersionString());
AzureIoTClient 16:deba40344375 63
AzureIoTClient 42:448eecc3676e 64 /* Codes_SRS_IOTHUBCLIENT_LL_12_003: [IoTHubClient_LL_CreateFromConnectionString shall verify the input parameter and if it is NULL then return NULL] */
AzureIoTClient 42:448eecc3676e 65 if (connectionString == NULL)
AzureIoTClient 42:448eecc3676e 66 {
AzureIoTClient 42:448eecc3676e 67 LogError("Input parameter is NULL: connectionString");
AzureIoTClient 42:448eecc3676e 68 }
AzureIoTClient 42:448eecc3676e 69 else if (protocol == NULL)
AzureIoTClient 42:448eecc3676e 70 {
AzureIoTClient 42:448eecc3676e 71 LogError("Input parameter is NULL: protocol");
AzureIoTClient 42:448eecc3676e 72 }
AzureIoTClient 42:448eecc3676e 73 else
AzureIoTClient 42:448eecc3676e 74 {
AzureIoTClient 42:448eecc3676e 75 /* Codes_SRS_IOTHUBCLIENT_LL_12_004: [IoTHubClient_LL_CreateFromConnectionString shall allocate IOTHUB_CLIENT_CONFIG structure] */
AzureIoTClient 42:448eecc3676e 76 IOTHUB_CLIENT_CONFIG* config = malloc(sizeof(IOTHUB_CLIENT_CONFIG));
AzureIoTClient 42:448eecc3676e 77 if (config == NULL)
AzureIoTClient 42:448eecc3676e 78 {
AzureIoTClient 42:448eecc3676e 79 /* Codes_SRS_IOTHUBCLIENT_LL_12_012: [If the allocation failed IoTHubClient_LL_CreateFromConnectionString returns NULL] */
AzureIoTClient 42:448eecc3676e 80 LogError("Malloc failed");
AzureIoTClient 42:448eecc3676e 81 return NULL;
AzureIoTClient 42:448eecc3676e 82 }
AzureIoTClient 42:448eecc3676e 83 else
AzureIoTClient 42:448eecc3676e 84 {
AzureIoTClient 42:448eecc3676e 85 STRING_TOKENIZER_HANDLE tokenizer1 = NULL;
AzureIoTClient 42:448eecc3676e 86 STRING_HANDLE connString = NULL;
AzureIoTClient 42:448eecc3676e 87 STRING_HANDLE tokenString = NULL;
AzureIoTClient 42:448eecc3676e 88 STRING_HANDLE valueString = NULL;
AzureIoTClient 42:448eecc3676e 89 STRING_HANDLE hostNameString = NULL;
AzureIoTClient 42:448eecc3676e 90 STRING_HANDLE hostSuffixString = NULL;
AzureIoTClient 42:448eecc3676e 91 STRING_HANDLE deviceIdString = NULL;
AzureIoTClient 42:448eecc3676e 92 STRING_HANDLE deviceKeyString = NULL;
AzureIoTClient 42:448eecc3676e 93 STRING_HANDLE deviceSasTokenString = NULL;
AzureIoTClient 42:448eecc3676e 94 STRING_HANDLE protocolGateway = NULL;
AzureIoTClient 16:deba40344375 95
AzureIoTClient 42:448eecc3676e 96 config->protocol = protocol;
AzureIoTClient 16:deba40344375 97
AzureIoTClient 42:448eecc3676e 98 config->iotHubName = NULL;
AzureIoTClient 42:448eecc3676e 99 config->iotHubSuffix = NULL;
AzureIoTClient 42:448eecc3676e 100 config->deviceId = NULL;
AzureIoTClient 42:448eecc3676e 101 config->deviceKey = NULL;
AzureIoTClient 42:448eecc3676e 102 config->deviceSasToken = NULL;
AzureIoTClient 40:1a94db9139ea 103
AzureIoTClient 42:448eecc3676e 104 /* Codes_SRS_IOTHUBCLIENT_LL_04_002: [If it does not, it shall pass the protocolGatewayHostName NULL.] */
AzureIoTClient 42:448eecc3676e 105 config->protocolGatewayHostName = NULL;
AzureIoTClient 16:deba40344375 106
AzureIoTClient 42:448eecc3676e 107 if ((connString = STRING_construct(connectionString)) == NULL)
AzureIoTClient 42:448eecc3676e 108 {
AzureIoTClient 42:448eecc3676e 109 LogError("Error constructing connectiong String");
AzureIoTClient 42:448eecc3676e 110 }
AzureIoTClient 42:448eecc3676e 111 else if ((tokenizer1 = STRING_TOKENIZER_create(connString)) == NULL)
AzureIoTClient 42:448eecc3676e 112 {
AzureIoTClient 42:448eecc3676e 113 LogError("Error creating Tokenizer");
AzureIoTClient 42:448eecc3676e 114 }
AzureIoTClient 42:448eecc3676e 115 else if ((tokenString = STRING_new()) == NULL)
AzureIoTClient 42:448eecc3676e 116 {
AzureIoTClient 42:448eecc3676e 117 LogError("Error creating Token String");
AzureIoTClient 42:448eecc3676e 118 }
AzureIoTClient 42:448eecc3676e 119 else if ((valueString = STRING_new()) == NULL)
AzureIoTClient 42:448eecc3676e 120 {
AzureIoTClient 42:448eecc3676e 121 LogError("Error creating Value String");
AzureIoTClient 42:448eecc3676e 122 }
AzureIoTClient 42:448eecc3676e 123 else if ((hostNameString = STRING_new()) == NULL)
AzureIoTClient 42:448eecc3676e 124 {
AzureIoTClient 42:448eecc3676e 125 LogError("Error creating HostName String");
AzureIoTClient 42:448eecc3676e 126 }
AzureIoTClient 42:448eecc3676e 127 else if ((hostSuffixString = STRING_new()) == NULL)
AzureIoTClient 42:448eecc3676e 128 {
AzureIoTClient 42:448eecc3676e 129 LogError("Error creating HostSuffix String");
AzureIoTClient 42:448eecc3676e 130 }
AzureIoTClient 42:448eecc3676e 131 /* Codes_SRS_IOTHUBCLIENT_LL_12_005: [IoTHubClient_LL_CreateFromConnectionString shall try to parse the connectionString input parameter for the following structure: "Key1=value1;key2=value2;key3=value3..."] */
Azure.IoT Build 45:54c11b1b1407 132 /* Codes_SRS_IOTHUBCLIENT_LL_12_006: [IoTHubClient_LL_CreateFromConnectionString shall verify the existence of the following Key/Value pairs in the connection string: HostName, DeviceId, SharedAccessKey, SharedAccessSignature or x509] */
AzureIoTClient 42:448eecc3676e 133 else
AzureIoTClient 42:448eecc3676e 134 {
Azure.IoT Build 45:54c11b1b1407 135 int isx509found = 0;
AzureIoTClient 42:448eecc3676e 136 while ((STRING_TOKENIZER_get_next_token(tokenizer1, tokenString, "=") == 0))
AzureIoTClient 42:448eecc3676e 137 {
AzureIoTClient 42:448eecc3676e 138 if (STRING_TOKENIZER_get_next_token(tokenizer1, valueString, ";") != 0)
AzureIoTClient 42:448eecc3676e 139 {
AzureIoTClient 42:448eecc3676e 140 LogError("Tokenizer error");
AzureIoTClient 42:448eecc3676e 141 break;
AzureIoTClient 42:448eecc3676e 142 }
AzureIoTClient 42:448eecc3676e 143 else
AzureIoTClient 42:448eecc3676e 144 {
AzureIoTClient 42:448eecc3676e 145 if (tokenString != NULL)
AzureIoTClient 42:448eecc3676e 146 {
AzureIoTClient 42:448eecc3676e 147 /* Codes_SRS_IOTHUBCLIENT_LL_12_010: [IoTHubClient_LL_CreateFromConnectionString shall fill up the IOTHUB_CLIENT_CONFIG structure using the following mapping: iotHubName = Name, iotHubSuffix = Suffix, deviceId = DeviceId, deviceKey = SharedAccessKey or deviceSasToken = SharedAccessSignature] */
AzureIoTClient 42:448eecc3676e 148 const char* s_token = STRING_c_str(tokenString);
AzureIoTClient 42:448eecc3676e 149 if (strcmp(s_token, HOSTNAME_TOKEN) == 0)
AzureIoTClient 42:448eecc3676e 150 {
AzureIoTClient 42:448eecc3676e 151 /* Codes_SRS_IOTHUBCLIENT_LL_12_009: [IoTHubClient_LL_CreateFromConnectionString shall split the value of HostName to Name and Suffix using the first "." as a separator] */
AzureIoTClient 42:448eecc3676e 152 STRING_TOKENIZER_HANDLE tokenizer2 = NULL;
AzureIoTClient 42:448eecc3676e 153 if ((tokenizer2 = STRING_TOKENIZER_create(valueString)) == NULL)
AzureIoTClient 42:448eecc3676e 154 {
AzureIoTClient 42:448eecc3676e 155 LogError("Error creating Tokenizer");
AzureIoTClient 42:448eecc3676e 156 break;
AzureIoTClient 42:448eecc3676e 157 }
AzureIoTClient 42:448eecc3676e 158 else
AzureIoTClient 42:448eecc3676e 159 {
AzureIoTClient 42:448eecc3676e 160 /* Codes_SRS_IOTHUBCLIENT_LL_12_015: [If the string split failed, IoTHubClient_LL_CreateFromConnectionString returns NULL ] */
AzureIoTClient 42:448eecc3676e 161 if (STRING_TOKENIZER_get_next_token(tokenizer2, hostNameString, ".") != 0)
AzureIoTClient 42:448eecc3676e 162 {
AzureIoTClient 42:448eecc3676e 163 LogError("Tokenizer error");
AzureIoTClient 42:448eecc3676e 164 STRING_TOKENIZER_destroy(tokenizer2);
AzureIoTClient 42:448eecc3676e 165 break;
AzureIoTClient 42:448eecc3676e 166 }
AzureIoTClient 42:448eecc3676e 167 else
AzureIoTClient 42:448eecc3676e 168 {
AzureIoTClient 42:448eecc3676e 169 config->iotHubName = STRING_c_str(hostNameString);
AzureIoTClient 42:448eecc3676e 170 if (STRING_TOKENIZER_get_next_token(tokenizer2, hostSuffixString, ";") != 0)
AzureIoTClient 42:448eecc3676e 171 {
AzureIoTClient 42:448eecc3676e 172 LogError("Tokenizer error");
AzureIoTClient 42:448eecc3676e 173 STRING_TOKENIZER_destroy(tokenizer2);
AzureIoTClient 42:448eecc3676e 174 break;
AzureIoTClient 42:448eecc3676e 175 }
AzureIoTClient 42:448eecc3676e 176 else
AzureIoTClient 42:448eecc3676e 177 {
AzureIoTClient 42:448eecc3676e 178 config->iotHubSuffix = STRING_c_str(hostSuffixString);
AzureIoTClient 42:448eecc3676e 179 }
AzureIoTClient 42:448eecc3676e 180 }
AzureIoTClient 42:448eecc3676e 181 STRING_TOKENIZER_destroy(tokenizer2);
AzureIoTClient 42:448eecc3676e 182 }
AzureIoTClient 42:448eecc3676e 183 }
AzureIoTClient 42:448eecc3676e 184 else if (strcmp(s_token, DEVICEID_TOKEN) == 0)
AzureIoTClient 42:448eecc3676e 185 {
AzureIoTClient 42:448eecc3676e 186 deviceIdString = STRING_clone(valueString);
AzureIoTClient 42:448eecc3676e 187 if (deviceIdString != NULL)
AzureIoTClient 42:448eecc3676e 188 {
AzureIoTClient 42:448eecc3676e 189 config->deviceId = STRING_c_str(deviceIdString);
AzureIoTClient 42:448eecc3676e 190 }
AzureIoTClient 42:448eecc3676e 191 }
AzureIoTClient 42:448eecc3676e 192 else if (strcmp(s_token, DEVICEKEY_TOKEN) == 0)
AzureIoTClient 42:448eecc3676e 193 {
AzureIoTClient 42:448eecc3676e 194 deviceKeyString = STRING_clone(valueString);
AzureIoTClient 42:448eecc3676e 195 if (deviceKeyString != NULL)
AzureIoTClient 42:448eecc3676e 196 {
AzureIoTClient 42:448eecc3676e 197 config->deviceKey = STRING_c_str(deviceKeyString);
AzureIoTClient 42:448eecc3676e 198 }
AzureIoTClient 42:448eecc3676e 199 }
AzureIoTClient 42:448eecc3676e 200 else if (strcmp(s_token, DEVICESAS_TOKEN) == 0)
AzureIoTClient 42:448eecc3676e 201 {
AzureIoTClient 42:448eecc3676e 202 deviceSasTokenString = STRING_clone(valueString);
AzureIoTClient 42:448eecc3676e 203 if (deviceSasTokenString != NULL)
AzureIoTClient 42:448eecc3676e 204 {
AzureIoTClient 42:448eecc3676e 205 config->deviceSasToken = STRING_c_str(deviceSasTokenString);
AzureIoTClient 42:448eecc3676e 206 }
AzureIoTClient 42:448eecc3676e 207 }
Azure.IoT Build 45:54c11b1b1407 208 else if (strcmp(s_token, X509_TOKEN) == 0)
Azure.IoT Build 45:54c11b1b1407 209 {
Azure.IoT Build 45:54c11b1b1407 210 if (strcmp(STRING_c_str(valueString), X509_TOKEN_ONLY_ACCEPTABLE_VALUE) != 0)
Azure.IoT Build 45:54c11b1b1407 211 {
Azure.IoT Build 45:54c11b1b1407 212 LogError("x509 option has wrong value, the only acceptable one is \"true\"");
Azure.IoT Build 45:54c11b1b1407 213 }
Azure.IoT Build 45:54c11b1b1407 214 else
Azure.IoT Build 45:54c11b1b1407 215 {
Azure.IoT Build 45:54c11b1b1407 216 isx509found = 1;
Azure.IoT Build 45:54c11b1b1407 217 }
Azure.IoT Build 45:54c11b1b1407 218 }
AzureIoTClient 42:448eecc3676e 219 /* Codes_SRS_IOTHUBCLIENT_LL_04_001: [IoTHubClient_LL_CreateFromConnectionString shall verify the existence of key/value pair GatewayHostName. If it does exist it shall pass the value to IoTHubClient_LL_Create API.] */
AzureIoTClient 42:448eecc3676e 220 else if (strcmp(s_token, PROTOCOL_GATEWAY_HOST) == 0)
AzureIoTClient 42:448eecc3676e 221 {
AzureIoTClient 42:448eecc3676e 222 protocolGateway = STRING_clone(valueString);
AzureIoTClient 42:448eecc3676e 223 if (protocolGateway != NULL)
AzureIoTClient 42:448eecc3676e 224 {
AzureIoTClient 42:448eecc3676e 225 config->protocolGatewayHostName = STRING_c_str(protocolGateway);
AzureIoTClient 42:448eecc3676e 226 }
AzureIoTClient 42:448eecc3676e 227 }
AzureIoTClient 42:448eecc3676e 228 }
AzureIoTClient 42:448eecc3676e 229 }
AzureIoTClient 42:448eecc3676e 230 }
AzureIoTClient 42:448eecc3676e 231 /* parsing is done - check the result */
AzureIoTClient 42:448eecc3676e 232 if (config->iotHubName == NULL)
AzureIoTClient 42:448eecc3676e 233 {
AzureIoTClient 42:448eecc3676e 234 LogError("iotHubName is not found");
AzureIoTClient 42:448eecc3676e 235 }
AzureIoTClient 42:448eecc3676e 236 else if (config->iotHubSuffix == NULL)
AzureIoTClient 42:448eecc3676e 237 {
AzureIoTClient 42:448eecc3676e 238 LogError("iotHubSuffix is not found");
AzureIoTClient 42:448eecc3676e 239 }
AzureIoTClient 42:448eecc3676e 240 else if (config->deviceId == NULL)
AzureIoTClient 42:448eecc3676e 241 {
AzureIoTClient 42:448eecc3676e 242 LogError("deviceId is not found");
AzureIoTClient 42:448eecc3676e 243 }
Azure.IoT Build 45:54c11b1b1407 244 else if (!(
Azure.IoT Build 45:54c11b1b1407 245 ((!isx509found) && (config->deviceSasToken == NULL) ^ (config->deviceKey == NULL)) ||
Azure.IoT Build 45:54c11b1b1407 246 ((isx509found) && (config->deviceSasToken == NULL) && (config->deviceKey == NULL))
Azure.IoT Build 45:54c11b1b1407 247 ))
AzureIoTClient 42:448eecc3676e 248 {
Azure.IoT Build 45:54c11b1b1407 249 LogError("invalid combination of x509, deviceSasToken and deviceKey");
AzureIoTClient 42:448eecc3676e 250 }
AzureIoTClient 42:448eecc3676e 251 else
AzureIoTClient 42:448eecc3676e 252 {
AzureIoTClient 42:448eecc3676e 253 /* Codes_SRS_IOTHUBCLIENT_LL_12_011: [IoTHubClient_LL_CreateFromConnectionString shall call into the IoTHubClient_LL_Create API with the current structure and returns with the return value of it] */
AzureIoTClient 42:448eecc3676e 254
AzureIoTClient 42:448eecc3676e 255 result = IoTHubClient_LL_Create(config);
AzureIoTClient 42:448eecc3676e 256 if (result == NULL)
AzureIoTClient 42:448eecc3676e 257 {
AzureIoTClient 42:448eecc3676e 258 LogError("IoTHubClient_LL_Create failed");
AzureIoTClient 42:448eecc3676e 259 }
AzureIoTClient 42:448eecc3676e 260 else
AzureIoTClient 42:448eecc3676e 261 {
AzureIoTClient 42:448eecc3676e 262 /*return as is*/
AzureIoTClient 42:448eecc3676e 263 }
AzureIoTClient 42:448eecc3676e 264 }
AzureIoTClient 42:448eecc3676e 265 }
AzureIoTClient 42:448eecc3676e 266 if (deviceSasTokenString != NULL)
AzureIoTClient 42:448eecc3676e 267 STRING_delete(deviceSasTokenString);
AzureIoTClient 42:448eecc3676e 268 if (deviceKeyString != NULL)
AzureIoTClient 42:448eecc3676e 269 STRING_delete(deviceKeyString);
AzureIoTClient 42:448eecc3676e 270 if (deviceIdString != NULL)
AzureIoTClient 42:448eecc3676e 271 STRING_delete(deviceIdString);
AzureIoTClient 42:448eecc3676e 272 if (hostSuffixString != NULL)
AzureIoTClient 42:448eecc3676e 273 STRING_delete(hostSuffixString);
AzureIoTClient 42:448eecc3676e 274 if (hostNameString != NULL)
AzureIoTClient 42:448eecc3676e 275 STRING_delete(hostNameString);
AzureIoTClient 42:448eecc3676e 276 if (valueString != NULL)
AzureIoTClient 42:448eecc3676e 277 STRING_delete(valueString);
AzureIoTClient 42:448eecc3676e 278 if (tokenString != NULL)
AzureIoTClient 42:448eecc3676e 279 STRING_delete(tokenString);
AzureIoTClient 42:448eecc3676e 280 if (connString != NULL)
AzureIoTClient 42:448eecc3676e 281 STRING_delete(connString);
AzureIoTClient 42:448eecc3676e 282 if (protocolGateway != NULL)
AzureIoTClient 42:448eecc3676e 283 STRING_delete(protocolGateway);
AzureIoTClient 16:deba40344375 284
AzureIoTClient 42:448eecc3676e 285 if (tokenizer1 != NULL)
AzureIoTClient 42:448eecc3676e 286 STRING_TOKENIZER_destroy(tokenizer1);
AzureIoTClient 16:deba40344375 287
AzureIoTClient 42:448eecc3676e 288 free(config);
AzureIoTClient 42:448eecc3676e 289 }
AzureIoTClient 42:448eecc3676e 290 }
AzureIoTClient 42:448eecc3676e 291 return result;
AzureIoTClient 16:deba40344375 292 }
AzureIoTClient 16:deba40344375 293
Azure.IoT Build 36:67300d5a4c1f 294 static void setTransportProtocol(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, TRANSPORT_PROVIDER* protocol)
Azure.IoT Build 36:67300d5a4c1f 295 {
AzureIoTClient 43:038d8511e817 296 handleData->IoTHubTransport_GetHostname = protocol->IoTHubTransport_GetHostname;
AzureIoTClient 42:448eecc3676e 297 handleData->IoTHubTransport_SetOption = protocol->IoTHubTransport_SetOption;
AzureIoTClient 42:448eecc3676e 298 handleData->IoTHubTransport_Create = protocol->IoTHubTransport_Create;
AzureIoTClient 42:448eecc3676e 299 handleData->IoTHubTransport_Destroy = protocol->IoTHubTransport_Destroy;
AzureIoTClient 42:448eecc3676e 300 handleData->IoTHubTransport_Register = protocol->IoTHubTransport_Register;
AzureIoTClient 42:448eecc3676e 301 handleData->IoTHubTransport_Unregister = protocol->IoTHubTransport_Unregister;
AzureIoTClient 42:448eecc3676e 302 handleData->IoTHubTransport_Subscribe = protocol->IoTHubTransport_Subscribe;
AzureIoTClient 42:448eecc3676e 303 handleData->IoTHubTransport_Unsubscribe = protocol->IoTHubTransport_Unsubscribe;
AzureIoTClient 42:448eecc3676e 304 handleData->IoTHubTransport_DoWork = protocol->IoTHubTransport_DoWork;
AzureIoTClient 42:448eecc3676e 305 handleData->IoTHubTransport_GetSendStatus = protocol->IoTHubTransport_GetSendStatus;
Azure.IoT Build 36:67300d5a4c1f 306
Azure.IoT Build 36:67300d5a4c1f 307 }
AzureIoTClient 16:deba40344375 308
AzureIoTClient 16:deba40344375 309 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_Create(const IOTHUB_CLIENT_CONFIG* config)
AzureIoTClient 16:deba40344375 310 {
AzureIoTClient 42:448eecc3676e 311 IOTHUB_CLIENT_LL_HANDLE result;
AzureIoTClient 42:448eecc3676e 312 /*Codes_SRS_IOTHUBCLIENT_LL_02_001: [IoTHubClient_LL_Create shall return NULL if config parameter is NULL or protocol field is NULL.]*/
AzureIoTClient 42:448eecc3676e 313 if(
AzureIoTClient 42:448eecc3676e 314 (config == NULL) ||
AzureIoTClient 42:448eecc3676e 315 (config->protocol == NULL)
AzureIoTClient 42:448eecc3676e 316 )
AzureIoTClient 42:448eecc3676e 317 {
AzureIoTClient 42:448eecc3676e 318 result = NULL;
AzureIoTClient 42:448eecc3676e 319 LogError("invalid configuration (NULL detected)");
AzureIoTClient 42:448eecc3676e 320 }
AzureIoTClient 42:448eecc3676e 321 else
AzureIoTClient 42:448eecc3676e 322 {
AzureIoTClient 42:448eecc3676e 323 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)malloc(sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA));
AzureIoTClient 42:448eecc3676e 324 if (handleData == NULL)
AzureIoTClient 42:448eecc3676e 325 {
AzureIoTClient 42:448eecc3676e 326 LogError("malloc failed");
AzureIoTClient 42:448eecc3676e 327 result = NULL;
AzureIoTClient 42:448eecc3676e 328 }
AzureIoTClient 42:448eecc3676e 329 else
AzureIoTClient 42:448eecc3676e 330 {
AzureIoTClient 44:33dd78697616 331 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 332 /*Codes_SRS_IOTHUBCLIENT_LL_02_094: [ IoTHubClient_LL_Create shall create a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE from IOTHUB_CLIENT_CONFIG. ]*/
AzureIoTClient 42:448eecc3676e 333 /*Codes_SRS_IOTHUBCLIENT_LL_02_092: [ IoTHubClient_LL_CreateFromConnectionString shall create a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE from IOTHUB_CLIENT_CONFIG. ]*/
AzureIoTClient 42:448eecc3676e 334 handleData->uploadToBlobHandle = IoTHubClient_LL_UploadToBlob_Create(config);
AzureIoTClient 42:448eecc3676e 335 if (handleData->uploadToBlobHandle == NULL)
AzureIoTClient 42:448eecc3676e 336 {
AzureIoTClient 42:448eecc3676e 337 /*Codes_SRS_IOTHUBCLIENT_LL_02_093: [ If creating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateFromConnectionString shall fail and return NULL. ]*/
AzureIoTClient 42:448eecc3676e 338 /*Codes_SRS_IOTHUBCLIENT_LL_02_095: [ If creating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_Create shall fail and return NULL. ]*/
AzureIoTClient 42:448eecc3676e 339 LogError("unable to IoTHubClient_LL_UploadToBlob_Create");
AzureIoTClient 42:448eecc3676e 340 free(handleData);
AzureIoTClient 42:448eecc3676e 341 result = NULL;
AzureIoTClient 42:448eecc3676e 342 }
AzureIoTClient 42:448eecc3676e 343 else
AzureIoTClient 43:038d8511e817 344 #endif
AzureIoTClient 42:448eecc3676e 345 {
AzureIoTClient 42:448eecc3676e 346 /*Codes_SRS_IOTHUBCLIENT_LL_02_045: [ Otherwise IoTHubClient_LL_Create shall create a new TICK_COUNTER_HANDLE ]*/
AzureIoTClient 42:448eecc3676e 347 if ((handleData->tickCounter = tickcounter_create()) == NULL)
AzureIoTClient 42:448eecc3676e 348 {
AzureIoTClient 44:33dd78697616 349 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 350 /*Codes_SRS_IOTHUBCLIENT_LL_02_046: [ If creating the TICK_COUNTER_HANDLE fails then IoTHubClient_LL_Create shall fail and return NULL. ]*/
AzureIoTClient 42:448eecc3676e 351 IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle);
AzureIoTClient 43:038d8511e817 352 #endif
AzureIoTClient 42:448eecc3676e 353 LogError("unable to get a tickcounter");
AzureIoTClient 42:448eecc3676e 354 free(handleData);
AzureIoTClient 42:448eecc3676e 355 result = NULL;
AzureIoTClient 42:448eecc3676e 356 }
AzureIoTClient 42:448eecc3676e 357 else
AzureIoTClient 42:448eecc3676e 358 {
AzureIoTClient 42:448eecc3676e 359 /*Codes_SRS_IOTHUBCLIENT_LL_02_004: [Otherwise IoTHubClient_LL_Create shall initialize a new DLIST (further called "waitingToSend") containing records with fields of the following types: IOTHUB_MESSAGE_HANDLE, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, void*.]*/
AzureIoTClient 42:448eecc3676e 360 IOTHUBTRANSPORT_CONFIG lowerLayerConfig;
AzureIoTClient 42:448eecc3676e 361 DList_InitializeListHead(&(handleData->waitingToSend));
AzureIoTClient 42:448eecc3676e 362 setTransportProtocol(handleData, (TRANSPORT_PROVIDER*)config->protocol());
AzureIoTClient 42:448eecc3676e 363 handleData->messageCallback = NULL;
AzureIoTClient 42:448eecc3676e 364 handleData->messageUserContextCallback = NULL;
AzureIoTClient 42:448eecc3676e 365 handleData->lastMessageReceiveTime = INDEFINITE_TIME;
AzureIoTClient 42:448eecc3676e 366 /*Codes_SRS_IOTHUBCLIENT_LL_02_006: [IoTHubClient_LL_Create shall populate a structure of type IOTHUBTRANSPORT_CONFIG with the information from config parameter and the previous DLIST and shall pass that to the underlying layer _Create function.]*/
AzureIoTClient 42:448eecc3676e 367 lowerLayerConfig.upperConfig = config;
AzureIoTClient 42:448eecc3676e 368 lowerLayerConfig.waitingToSend = &(handleData->waitingToSend);
AzureIoTClient 42:448eecc3676e 369 /*Codes_SRS_IOTHUBCLIENT_LL_02_007: [If the underlaying layer _Create function fails them IoTHubClient_LL_Create shall fail and return NULL.] */
AzureIoTClient 42:448eecc3676e 370 if ((handleData->transportHandle = handleData->IoTHubTransport_Create(&lowerLayerConfig)) == NULL)
AzureIoTClient 42:448eecc3676e 371 {
AzureIoTClient 42:448eecc3676e 372 LogError("underlying transport failed");
AzureIoTClient 44:33dd78697616 373 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 374 IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle);
AzureIoTClient 43:038d8511e817 375 #endif
AzureIoTClient 42:448eecc3676e 376 tickcounter_destroy(handleData->tickCounter);
AzureIoTClient 42:448eecc3676e 377 free(handleData);
AzureIoTClient 42:448eecc3676e 378 result = NULL;
AzureIoTClient 42:448eecc3676e 379 }
AzureIoTClient 42:448eecc3676e 380 else
AzureIoTClient 42:448eecc3676e 381 {
AzureIoTClient 42:448eecc3676e 382 IOTHUB_DEVICE_CONFIG deviceConfig;
AzureIoTClient 40:1a94db9139ea 383
AzureIoTClient 42:448eecc3676e 384 deviceConfig.deviceId = config->deviceId;
AzureIoTClient 42:448eecc3676e 385 deviceConfig.deviceKey = config->deviceKey;
AzureIoTClient 42:448eecc3676e 386 deviceConfig.deviceSasToken = config->deviceSasToken;
AzureIoTClient 40:1a94db9139ea 387
AzureIoTClient 42:448eecc3676e 388 /*Codes_SRS_IOTHUBCLIENT_LL_17_008: [IoTHubClient_LL_Create shall call the transport _Register function with a populated structure of type IOTHUB_DEVICE_CONFIG and waitingToSend list.] */
AzureIoTClient 42:448eecc3676e 389 if ((handleData->deviceHandle = handleData->IoTHubTransport_Register(handleData->transportHandle, &deviceConfig, handleData, &(handleData->waitingToSend))) == NULL)
AzureIoTClient 42:448eecc3676e 390 {
AzureIoTClient 42:448eecc3676e 391 /*Codes_SRS_IOTHUBCLIENT_LL_17_009: [If the _Register function fails, this function shall fail and return NULL.]*/
AzureIoTClient 42:448eecc3676e 392 LogError("Registering device in transport failed");
AzureIoTClient 42:448eecc3676e 393 handleData->IoTHubTransport_Destroy(handleData->transportHandle);
AzureIoTClient 44:33dd78697616 394 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 395 IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle);
AzureIoTClient 43:038d8511e817 396 #endif
AzureIoTClient 42:448eecc3676e 397 tickcounter_destroy(handleData->tickCounter);
AzureIoTClient 42:448eecc3676e 398 free(handleData);
AzureIoTClient 42:448eecc3676e 399 result = NULL;
AzureIoTClient 42:448eecc3676e 400 }
AzureIoTClient 42:448eecc3676e 401 else
AzureIoTClient 42:448eecc3676e 402 {
AzureIoTClient 42:448eecc3676e 403 /*Codes_SRS_IOTHUBCLIENT_LL_02_008: [Otherwise, IoTHubClient_LL_Create shall succeed and return a non-NULL handle.] */
AzureIoTClient 42:448eecc3676e 404 handleData->isSharedTransport = false;
AzureIoTClient 42:448eecc3676e 405 /*Codes_SRS_IOTHUBCLIENT_LL_02_042: [ By default, messages shall not timeout. ]*/
AzureIoTClient 42:448eecc3676e 406 handleData->currentMessageTimeout = 0;
AzureIoTClient 42:448eecc3676e 407 result = handleData;
AzureIoTClient 42:448eecc3676e 408 }
AzureIoTClient 42:448eecc3676e 409 }
AzureIoTClient 42:448eecc3676e 410 }
AzureIoTClient 42:448eecc3676e 411 }
AzureIoTClient 42:448eecc3676e 412 }
AzureIoTClient 42:448eecc3676e 413 }
AzureIoTClient 16:deba40344375 414
AzureIoTClient 42:448eecc3676e 415 return result;
AzureIoTClient 16:deba40344375 416 }
AzureIoTClient 16:deba40344375 417
Azure.IoT Build 36:67300d5a4c1f 418 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateWithTransport(const IOTHUB_CLIENT_DEVICE_CONFIG * config)
Azure.IoT Build 36:67300d5a4c1f 419 {
AzureIoTClient 42:448eecc3676e 420 IOTHUB_CLIENT_LL_HANDLE result;
AzureIoTClient 42:448eecc3676e 421 /*Codes_SRS_IOTHUBCLIENT_LL_17_001: [IoTHubClient_LL_CreateWithTransport shall return NULL if config parameter is NULL, or protocol field is NULL or transportHandle is NULL.]*/
AzureIoTClient 42:448eecc3676e 422 if (
AzureIoTClient 42:448eecc3676e 423 (config == NULL) ||
AzureIoTClient 42:448eecc3676e 424 (config->protocol == NULL) ||
Azure.IoT Build 45:54c11b1b1407 425 (config->transportHandle == NULL) ||
Azure.IoT Build 45:54c11b1b1407 426 /*Codes_SRS_IOTHUBCLIENT_LL_02_098: [ IoTHubClient_LL_CreateWithTransport shall fail and return NULL if both config->deviceKey AND config->deviceSasToken are NULL. ]*/
Azure.IoT Build 45:54c11b1b1407 427 ((config->deviceKey == NULL) && (config->deviceSasToken == NULL))
AzureIoTClient 42:448eecc3676e 428 )
AzureIoTClient 42:448eecc3676e 429 {
AzureIoTClient 42:448eecc3676e 430 result = NULL;
AzureIoTClient 42:448eecc3676e 431 LogError("invalid configuration (NULL detected)");
AzureIoTClient 42:448eecc3676e 432 }
AzureIoTClient 42:448eecc3676e 433 else
AzureIoTClient 42:448eecc3676e 434 {
AzureIoTClient 42:448eecc3676e 435 /*Codes_SRS_IOTHUBCLIENT_LL_17_002: [IoTHubClient_LL_CreateWithTransport shall allocate data for the IOTHUB_CLIENT_LL_HANDLE.]*/
AzureIoTClient 42:448eecc3676e 436 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)malloc(sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA));
AzureIoTClient 42:448eecc3676e 437 if (handleData == NULL)
AzureIoTClient 42:448eecc3676e 438 {
AzureIoTClient 42:448eecc3676e 439 /*Codes_SRS_IOTHUBCLIENT_LL_17_003: [If allocation fails, the function shall fail and return NULL.] */
AzureIoTClient 42:448eecc3676e 440 LogError("malloc failed");
AzureIoTClient 42:448eecc3676e 441 result = NULL;
AzureIoTClient 42:448eecc3676e 442 }
AzureIoTClient 42:448eecc3676e 443 else
AzureIoTClient 42:448eecc3676e 444 {
AzureIoTClient 43:038d8511e817 445 handleData->transportHandle = config->transportHandle;
AzureIoTClient 43:038d8511e817 446 setTransportProtocol(handleData, (TRANSPORT_PROVIDER*)config->protocol());
AzureIoTClient 43:038d8511e817 447
AzureIoTClient 44:33dd78697616 448 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 43:038d8511e817 449 const char* hostname = STRING_c_str(handleData->IoTHubTransport_GetHostname(handleData->transportHandle));
AzureIoTClient 43:038d8511e817 450 /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/
AzureIoTClient 43:038d8511e817 451 /*the first '.' says where the iothubname finishes*/
AzureIoTClient 43:038d8511e817 452 const char* whereIsDot = strchr(hostname, '.');
AzureIoTClient 43:038d8511e817 453 if (whereIsDot == NULL)
AzureIoTClient 42:448eecc3676e 454 {
AzureIoTClient 43:038d8511e817 455 /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/
AzureIoTClient 43:038d8511e817 456 LogError("unable to determine the IoTHub name");
AzureIoTClient 42:448eecc3676e 457 free(handleData);
AzureIoTClient 42:448eecc3676e 458 result = NULL;
AzureIoTClient 42:448eecc3676e 459 }
AzureIoTClient 42:448eecc3676e 460 else
AzureIoTClient 42:448eecc3676e 461 {
AzureIoTClient 43:038d8511e817 462 /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/
AzureIoTClient 43:038d8511e817 463 char* IoTHubName = malloc(whereIsDot - hostname + 1);
AzureIoTClient 43:038d8511e817 464 if (IoTHubName == NULL)
AzureIoTClient 42:448eecc3676e 465 {
AzureIoTClient 43:038d8511e817 466 /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/
AzureIoTClient 43:038d8511e817 467 LogError("unable to malloc");
AzureIoTClient 42:448eecc3676e 468 free(handleData);
AzureIoTClient 42:448eecc3676e 469 result = NULL;
AzureIoTClient 42:448eecc3676e 470 }
AzureIoTClient 42:448eecc3676e 471 else
AzureIoTClient 42:448eecc3676e 472 {
AzureIoTClient 43:038d8511e817 473 const char* IotHubSuffix = whereIsDot + 1;
AzureIoTClient 43:038d8511e817 474 memcpy(IoTHubName, hostname, whereIsDot - hostname);
AzureIoTClient 43:038d8511e817 475 IoTHubName[whereIsDot - hostname ] = '\0';
AzureIoTClient 43:038d8511e817 476
AzureIoTClient 43:038d8511e817 477 IOTHUB_CLIENT_CONFIG temp;
AzureIoTClient 43:038d8511e817 478 temp.deviceId = config->deviceId;
AzureIoTClient 43:038d8511e817 479 temp.deviceKey = config->deviceKey;
AzureIoTClient 43:038d8511e817 480 temp.deviceSasToken = config->deviceSasToken;
AzureIoTClient 43:038d8511e817 481 temp.iotHubName = IoTHubName;
AzureIoTClient 43:038d8511e817 482 temp.iotHubSuffix = IotHubSuffix;
AzureIoTClient 43:038d8511e817 483 temp.protocol = NULL; /*irrelevant to IoTHubClient_LL_UploadToBlob*/
AzureIoTClient 43:038d8511e817 484 temp.protocolGatewayHostName = NULL; /*irrelevant to IoTHubClient_LL_UploadToBlob*/
AzureIoTClient 43:038d8511e817 485
AzureIoTClient 43:038d8511e817 486 /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/
AzureIoTClient 43:038d8511e817 487 handleData->uploadToBlobHandle = IoTHubClient_LL_UploadToBlob_Create(&temp);
AzureIoTClient 43:038d8511e817 488 if (handleData->uploadToBlobHandle == NULL)
AzureIoTClient 43:038d8511e817 489 {
AzureIoTClient 43:038d8511e817 490 /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/
AzureIoTClient 43:038d8511e817 491 LogError("unable to IoTHubClient_LL_UploadToBlob_Create");
AzureIoTClient 43:038d8511e817 492 free(handleData);
AzureIoTClient 43:038d8511e817 493 result = NULL;
AzureIoTClient 43:038d8511e817 494 }
AzureIoTClient 43:038d8511e817 495 else
AzureIoTClient 43:038d8511e817 496 #endif
AzureIoTClient 43:038d8511e817 497 {
AzureIoTClient 43:038d8511e817 498 /*Codes_SRS_IOTHUBCLIENT_LL_02_047: [ IoTHubClient_LL_CreateWithTransport shall create a TICK_COUNTER_HANDLE. ]*/
AzureIoTClient 43:038d8511e817 499 if ((handleData->tickCounter = tickcounter_create()) == NULL)
AzureIoTClient 43:038d8511e817 500 {
AzureIoTClient 43:038d8511e817 501 /*Codes_SRS_IOTHUBCLIENT_LL_02_048: [ If creating the handle fails, then IoTHubClient_LL_CreateWithTransport shall fail and return NULL ]*/
AzureIoTClient 43:038d8511e817 502 LogError("unable to get a tickcounter");
AzureIoTClient 44:33dd78697616 503 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 43:038d8511e817 504 IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle);
AzureIoTClient 43:038d8511e817 505 #endif
AzureIoTClient 43:038d8511e817 506 free(handleData);
AzureIoTClient 43:038d8511e817 507 result = NULL;
AzureIoTClient 43:038d8511e817 508 }
AzureIoTClient 43:038d8511e817 509 else
AzureIoTClient 43:038d8511e817 510 {
AzureIoTClient 43:038d8511e817 511 /*Codes_SRS_IOTHUBCLIENT_LL_17_004: [IoTHubClient_LL_CreateWithTransport shall initialize a new DLIST (further called "waitingToSend") containing records with fields of the following types: IOTHUB_MESSAGE_HANDLE, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, void*.]*/
AzureIoTClient 43:038d8511e817 512 DList_InitializeListHead(&(handleData->waitingToSend));
AzureIoTClient 43:038d8511e817 513
AzureIoTClient 43:038d8511e817 514 handleData->messageCallback = NULL;
AzureIoTClient 43:038d8511e817 515 handleData->messageUserContextCallback = NULL;
AzureIoTClient 43:038d8511e817 516 handleData->lastMessageReceiveTime = INDEFINITE_TIME;
AzureIoTClient 43:038d8511e817 517
AzureIoTClient 43:038d8511e817 518
AzureIoTClient 43:038d8511e817 519 IOTHUB_DEVICE_CONFIG deviceConfig;
AzureIoTClient 43:038d8511e817 520
AzureIoTClient 43:038d8511e817 521 deviceConfig.deviceId = config->deviceId;
AzureIoTClient 43:038d8511e817 522 deviceConfig.deviceKey = config->deviceKey;
AzureIoTClient 43:038d8511e817 523 deviceConfig.deviceSasToken = config->deviceSasToken;
AzureIoTClient 43:038d8511e817 524
AzureIoTClient 43:038d8511e817 525 /*Codes_SRS_IOTHUBCLIENT_LL_17_006: [IoTHubClient_LL_CreateWithTransport shall call the transport _Register function with the IOTHUB_DEVICE_CONFIG populated structure and waitingToSend list.]*/
AzureIoTClient 43:038d8511e817 526 if ((handleData->deviceHandle = handleData->IoTHubTransport_Register(config->transportHandle, &deviceConfig, handleData, &(handleData->waitingToSend))) == NULL)
AzureIoTClient 43:038d8511e817 527 {
AzureIoTClient 43:038d8511e817 528 /*Codes_SRS_IOTHUBCLIENT_LL_17_007: [If the _Register function fails, this function shall fail and return NULL.]*/
AzureIoTClient 43:038d8511e817 529 LogError("Registering device in transport failed");
AzureIoTClient 44:33dd78697616 530 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 43:038d8511e817 531 IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle);
AzureIoTClient 43:038d8511e817 532 #endif
AzureIoTClient 43:038d8511e817 533 tickcounter_destroy(handleData->tickCounter);
AzureIoTClient 43:038d8511e817 534 free(handleData);
AzureIoTClient 43:038d8511e817 535 result = NULL;
AzureIoTClient 43:038d8511e817 536 }
AzureIoTClient 43:038d8511e817 537 else
AzureIoTClient 43:038d8511e817 538 {
AzureIoTClient 43:038d8511e817 539 /*Codes_SRS_IOTHUBCLIENT_LL_17_005: [IoTHubClient_LL_CreateWithTransport shall save the transport handle and mark this transport as shared.]*/
AzureIoTClient 43:038d8511e817 540 handleData->isSharedTransport = true;
AzureIoTClient 43:038d8511e817 541 /*Codes_SRS_IOTHUBCLIENT_LL_02_042: [ By default, messages shall not timeout. ]*/
AzureIoTClient 43:038d8511e817 542 handleData->currentMessageTimeout = 0;
AzureIoTClient 43:038d8511e817 543 result = handleData;
AzureIoTClient 43:038d8511e817 544 }
AzureIoTClient 43:038d8511e817 545 }
AzureIoTClient 43:038d8511e817 546 }
AzureIoTClient 44:33dd78697616 547 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 43:038d8511e817 548 free(IoTHubName);
AzureIoTClient 42:448eecc3676e 549 }
AzureIoTClient 42:448eecc3676e 550 }
AzureIoTClient 43:038d8511e817 551 #endif
AzureIoTClient 42:448eecc3676e 552 }
AzureIoTClient 42:448eecc3676e 553 }
Azure.IoT Build 36:67300d5a4c1f 554
AzureIoTClient 42:448eecc3676e 555 return result;
Azure.IoT Build 36:67300d5a4c1f 556 }
Azure.IoT Build 36:67300d5a4c1f 557
AzureIoTClient 16:deba40344375 558 void IoTHubClient_LL_Destroy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle)
AzureIoTClient 16:deba40344375 559 {
AzureIoTClient 42:448eecc3676e 560 /*Codes_SRS_IOTHUBCLIENT_LL_02_009: [IoTHubClient_LL_Destroy shall do nothing if parameter iotHubClientHandle is NULL.]*/
AzureIoTClient 42:448eecc3676e 561 if (iotHubClientHandle != NULL)
AzureIoTClient 42:448eecc3676e 562 {
AzureIoTClient 42:448eecc3676e 563 PDLIST_ENTRY unsend;
AzureIoTClient 42:448eecc3676e 564 /*Codes_SRS_IOTHUBCLIENT_LL_17_010: [IoTHubClient_LL_Destroy shall call the underlaying layer's _Unregister function] */
AzureIoTClient 42:448eecc3676e 565 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 42:448eecc3676e 566 handleData->IoTHubTransport_Unregister(handleData->deviceHandle);
AzureIoTClient 42:448eecc3676e 567 if (handleData->isSharedTransport == false)
AzureIoTClient 42:448eecc3676e 568 {
AzureIoTClient 42:448eecc3676e 569 /*Codes_SRS_IOTHUBCLIENT_LL_02_010: [If iotHubClientHandle was not created by IoTHubClient_LL_CreateWithTransport, IoTHubClient_LL_Destroy shall call the underlaying layer's _Destroy function.] */
AzureIoTClient 42:448eecc3676e 570 handleData->IoTHubTransport_Destroy(handleData->transportHandle);
AzureIoTClient 42:448eecc3676e 571 }
AzureIoTClient 42:448eecc3676e 572 /*if any, remove the items currently not send*/
AzureIoTClient 42:448eecc3676e 573 while ((unsend = DList_RemoveHeadList(&(handleData->waitingToSend))) != &(handleData->waitingToSend))
AzureIoTClient 42:448eecc3676e 574 {
AzureIoTClient 42:448eecc3676e 575 IOTHUB_MESSAGE_LIST* temp = containingRecord(unsend, IOTHUB_MESSAGE_LIST, entry);
AzureIoTClient 42:448eecc3676e 576 /*Codes_SRS_IOTHUBCLIENT_LL_02_033: [Otherwise, IoTHubClient_LL_Destroy shall complete all the event message callbacks that are in the waitingToSend list with the result IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY.] */
AzureIoTClient 42:448eecc3676e 577 if (temp->callback != NULL)
AzureIoTClient 42:448eecc3676e 578 {
AzureIoTClient 42:448eecc3676e 579 temp->callback(IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY, temp->context);
AzureIoTClient 42:448eecc3676e 580 }
AzureIoTClient 42:448eecc3676e 581 IoTHubMessage_Destroy(temp->messageHandle);
AzureIoTClient 42:448eecc3676e 582 free(temp);
AzureIoTClient 42:448eecc3676e 583 }
AzureIoTClient 42:448eecc3676e 584 /*Codes_SRS_IOTHUBCLIENT_LL_17_011: [IoTHubClient_LL_Destroy shall free the resources allocated by IoTHubClient (if any).] */
AzureIoTClient 42:448eecc3676e 585 tickcounter_destroy(handleData->tickCounter);
AzureIoTClient 44:33dd78697616 586 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 587 IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle);
AzureIoTClient 43:038d8511e817 588 #endif
AzureIoTClient 42:448eecc3676e 589 free(handleData);
AzureIoTClient 42:448eecc3676e 590 }
AzureIoTClient 16:deba40344375 591 }
AzureIoTClient 16:deba40344375 592
Azure.IoT Build 36:67300d5a4c1f 593 /*Codes_SRS_IOTHUBCLIENT_LL_02_044: [ Messages already delivered to IoTHubClient_LL shall not have their timeouts modified by a new call to IoTHubClient_LL_SetOption. ]*/
Azure.IoT Build 36:67300d5a4c1f 594 /*returns 0 on success, any other value is error*/
Azure.IoT Build 36:67300d5a4c1f 595 static int attach_ms_timesOutAfter(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, IOTHUB_MESSAGE_LIST *newEntry)
Azure.IoT Build 36:67300d5a4c1f 596 {
AzureIoTClient 42:448eecc3676e 597 int result;
AzureIoTClient 42:448eecc3676e 598 /*Codes_SRS_IOTHUBCLIENT_LL_02_043: [ Calling IoTHubClient_LL_SetOption with value set to "0" shall disable the timeout mechanism for all new messages. ]*/
AzureIoTClient 42:448eecc3676e 599 if (handleData->currentMessageTimeout == 0)
AzureIoTClient 42:448eecc3676e 600 {
AzureIoTClient 42:448eecc3676e 601 newEntry->ms_timesOutAfter = 0; /*do not timeout*/
AzureIoTClient 42:448eecc3676e 602 result = 0;
AzureIoTClient 42:448eecc3676e 603 }
AzureIoTClient 42:448eecc3676e 604 else
AzureIoTClient 42:448eecc3676e 605 {
AzureIoTClient 42:448eecc3676e 606 /*Codes_SRS_IOTHUBCLIENT_LL_02_039: [ "messageTimeout" - once IoTHubClient_LL_SendEventAsync is called the message shall timeout after value miliseconds. Value is a pointer to a uint64. ]*/
AzureIoTClient 42:448eecc3676e 607 if (tickcounter_get_current_ms(handleData->tickCounter, &newEntry->ms_timesOutAfter) != 0)
AzureIoTClient 42:448eecc3676e 608 {
AzureIoTClient 42:448eecc3676e 609 result = __LINE__;
AzureIoTClient 42:448eecc3676e 610 LogError("unable to get the current relative tickcount");
AzureIoTClient 42:448eecc3676e 611 }
AzureIoTClient 42:448eecc3676e 612 else
AzureIoTClient 42:448eecc3676e 613 {
AzureIoTClient 42:448eecc3676e 614 newEntry->ms_timesOutAfter += handleData->currentMessageTimeout;
AzureIoTClient 42:448eecc3676e 615 result = 0;
AzureIoTClient 42:448eecc3676e 616 }
AzureIoTClient 42:448eecc3676e 617 }
AzureIoTClient 42:448eecc3676e 618 return result;
Azure.IoT Build 36:67300d5a4c1f 619 }
Azure.IoT Build 36:67300d5a4c1f 620
AzureIoTClient 16:deba40344375 621 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SendEventAsync(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback)
AzureIoTClient 16:deba40344375 622 {
AzureIoTClient 42:448eecc3676e 623 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 42:448eecc3676e 624 /*Codes_SRS_IOTHUBCLIENT_LL_02_011: [IoTHubClient_LL_SendEventAsync shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle or eventMessageHandle is NULL.]*/
AzureIoTClient 42:448eecc3676e 625 if (
AzureIoTClient 42:448eecc3676e 626 (iotHubClientHandle == NULL) ||
AzureIoTClient 42:448eecc3676e 627 (eventMessageHandle == NULL) ||
AzureIoTClient 42:448eecc3676e 628 /*Codes_SRS_IOTHUBCLIENT_LL_02_012: [IoTHubClient_LL_SendEventAsync shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter eventConfirmationCallback is NULL and userContextCallback is not NULL.] */
AzureIoTClient 42:448eecc3676e 629 ((eventConfirmationCallback == NULL) && (userContextCallback != NULL))
AzureIoTClient 42:448eecc3676e 630 )
AzureIoTClient 42:448eecc3676e 631 {
AzureIoTClient 42:448eecc3676e 632 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 45:54c11b1b1407 633 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 634 }
AzureIoTClient 42:448eecc3676e 635 else
AzureIoTClient 42:448eecc3676e 636 {
AzureIoTClient 42:448eecc3676e 637 IOTHUB_MESSAGE_LIST *newEntry = (IOTHUB_MESSAGE_LIST*)malloc(sizeof(IOTHUB_MESSAGE_LIST));
AzureIoTClient 42:448eecc3676e 638 if (newEntry == NULL)
AzureIoTClient 42:448eecc3676e 639 {
AzureIoTClient 42:448eecc3676e 640 result = IOTHUB_CLIENT_ERROR;
Azure.IoT Build 45:54c11b1b1407 641 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 642 }
AzureIoTClient 42:448eecc3676e 643 else
AzureIoTClient 42:448eecc3676e 644 {
AzureIoTClient 42:448eecc3676e 645 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 40:1a94db9139ea 646
AzureIoTClient 42:448eecc3676e 647 if (attach_ms_timesOutAfter(handleData, newEntry) != 0)
AzureIoTClient 42:448eecc3676e 648 {
AzureIoTClient 42:448eecc3676e 649 result = IOTHUB_CLIENT_ERROR;
Azure.IoT Build 45:54c11b1b1407 650 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 651 free(newEntry);
AzureIoTClient 42:448eecc3676e 652 }
AzureIoTClient 42:448eecc3676e 653 else
AzureIoTClient 42:448eecc3676e 654 {
AzureIoTClient 42:448eecc3676e 655 /*Codes_SRS_IOTHUBCLIENT_LL_02_013: [IoTHubClient_SendEventAsync shall add the DLIST waitingToSend a new record cloning the information from eventMessageHandle, eventConfirmationCallback, userContextCallback.]*/
AzureIoTClient 42:448eecc3676e 656 if ((newEntry->messageHandle = IoTHubMessage_Clone(eventMessageHandle)) == NULL)
AzureIoTClient 42:448eecc3676e 657 {
AzureIoTClient 42:448eecc3676e 658 /*Codes_SRS_IOTHUBCLIENT_LL_02_014: [If cloning and/or adding the information fails for any reason, IoTHubClient_LL_SendEventAsync shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 42:448eecc3676e 659 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 42:448eecc3676e 660 free(newEntry);
Azure.IoT Build 45:54c11b1b1407 661 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 662 }
AzureIoTClient 42:448eecc3676e 663 else
AzureIoTClient 42:448eecc3676e 664 {
AzureIoTClient 42:448eecc3676e 665 /*Codes_SRS_IOTHUBCLIENT_LL_02_013: [IoTHubClient_SendEventAsync shall add the DLIST waitingToSend a new record cloning the information from eventMessageHandle, eventConfirmationCallback, userContextCallback.]*/
AzureIoTClient 42:448eecc3676e 666 newEntry->callback = eventConfirmationCallback;
AzureIoTClient 42:448eecc3676e 667 newEntry->context = userContextCallback;
AzureIoTClient 46:6a69294b6119 668 DList_InsertTailList(&(iotHubClientHandle->waitingToSend), &(newEntry->entry));
AzureIoTClient 42:448eecc3676e 669 /*Codes_SRS_IOTHUBCLIENT_LL_02_015: [Otherwise IoTHubClient_LL_SendEventAsync shall succeed and return IOTHUB_CLIENT_OK.] */
AzureIoTClient 42:448eecc3676e 670 result = IOTHUB_CLIENT_OK;
AzureIoTClient 42:448eecc3676e 671 }
AzureIoTClient 42:448eecc3676e 672 }
AzureIoTClient 42:448eecc3676e 673 }
AzureIoTClient 42:448eecc3676e 674 }
AzureIoTClient 42:448eecc3676e 675 return result;
AzureIoTClient 16:deba40344375 676 }
AzureIoTClient 16:deba40344375 677
AzureIoTClient 16:deba40344375 678 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetMessageCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback)
AzureIoTClient 16:deba40344375 679 {
AzureIoTClient 42:448eecc3676e 680 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 42:448eecc3676e 681 /*Codes_SRS_IOTHUBCLIENT_LL_02_016: [IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.] */
AzureIoTClient 42:448eecc3676e 682 if (iotHubClientHandle == NULL)
AzureIoTClient 42:448eecc3676e 683 {
AzureIoTClient 42:448eecc3676e 684 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 45:54c11b1b1407 685 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 686 }
AzureIoTClient 42:448eecc3676e 687 else
AzureIoTClient 42:448eecc3676e 688 {
AzureIoTClient 42:448eecc3676e 689 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 42:448eecc3676e 690 if (messageCallback == NULL)
AzureIoTClient 42:448eecc3676e 691 {
AzureIoTClient 42:448eecc3676e 692 /*Codes_SRS_IOTHUBCLIENT_LL_02_019: [If parameter messageCallback is NULL then IoTHubClient_LL_SetMessageCallback shall call the underlying layer's _Unsubscribe function and return IOTHUB_CLIENT_OK.] */
AzureIoTClient 42:448eecc3676e 693 handleData->IoTHubTransport_Unsubscribe(handleData->deviceHandle);
AzureIoTClient 42:448eecc3676e 694 handleData->messageCallback = NULL;
AzureIoTClient 42:448eecc3676e 695 handleData->messageUserContextCallback = NULL;
AzureIoTClient 42:448eecc3676e 696 result = IOTHUB_CLIENT_OK;
AzureIoTClient 42:448eecc3676e 697 }
AzureIoTClient 42:448eecc3676e 698 else
AzureIoTClient 42:448eecc3676e 699 {
AzureIoTClient 42:448eecc3676e 700 /*Codes_SRS_IOTHUBCLIENT_LL_02_017: [If parameter messageCallback is non-NULL then IoTHubClient_LL_SetMessageCallback shall call the underlying layer's _Subscribe function.]*/
AzureIoTClient 42:448eecc3676e 701 if (handleData->IoTHubTransport_Subscribe(handleData->deviceHandle) == 0)
AzureIoTClient 42:448eecc3676e 702 {
AzureIoTClient 42:448eecc3676e 703 handleData->messageCallback = messageCallback;
AzureIoTClient 42:448eecc3676e 704 handleData->messageUserContextCallback = userContextCallback;
AzureIoTClient 42:448eecc3676e 705 result = IOTHUB_CLIENT_OK;
AzureIoTClient 42:448eecc3676e 706 }
AzureIoTClient 42:448eecc3676e 707 else
AzureIoTClient 42:448eecc3676e 708 {
AzureIoTClient 42:448eecc3676e 709 handleData->messageCallback = NULL;
AzureIoTClient 42:448eecc3676e 710 handleData->messageUserContextCallback = NULL;
AzureIoTClient 42:448eecc3676e 711 /*Codes_SRS_IOTHUBCLIENT_LL_02_018: [If the underlying layer's _Subscribe function fails, then IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_ERROR. Otherwise IoTHubClient_LL_SetMessageCallback shall succeed and return IOTHUB_CLIENT_OK.]*/
AzureIoTClient 42:448eecc3676e 712 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 42:448eecc3676e 713 }
AzureIoTClient 42:448eecc3676e 714 }
AzureIoTClient 42:448eecc3676e 715 }
AzureIoTClient 40:1a94db9139ea 716
AzureIoTClient 42:448eecc3676e 717 return result;
AzureIoTClient 16:deba40344375 718 }
AzureIoTClient 16:deba40344375 719
Azure.IoT Build 36:67300d5a4c1f 720 static void DoTimeouts(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData)
Azure.IoT Build 36:67300d5a4c1f 721 {
AzureIoTClient 42:448eecc3676e 722 uint64_t nowTick;
AzureIoTClient 42:448eecc3676e 723 if (tickcounter_get_current_ms(handleData->tickCounter, &nowTick) != 0)
AzureIoTClient 42:448eecc3676e 724 {
AzureIoTClient 42:448eecc3676e 725 LogError("unable to get the current ms, timeouts will not be processed");
AzureIoTClient 42:448eecc3676e 726 }
AzureIoTClient 42:448eecc3676e 727 else
AzureIoTClient 42:448eecc3676e 728 {
AzureIoTClient 42:448eecc3676e 729 DLIST_ENTRY* currentItemInWaitingToSend = handleData->waitingToSend.Flink;
AzureIoTClient 42:448eecc3676e 730 while (currentItemInWaitingToSend != &(handleData->waitingToSend)) /*while we are not at the end of the list*/
AzureIoTClient 42:448eecc3676e 731 {
AzureIoTClient 42:448eecc3676e 732 IOTHUB_MESSAGE_LIST* fullEntry = containingRecord(currentItemInWaitingToSend, IOTHUB_MESSAGE_LIST, entry);
AzureIoTClient 42:448eecc3676e 733 /*Codes_SRS_IOTHUBCLIENT_LL_02_041: [ If more than value miliseconds have passed since the call to IoTHubClient_LL_SendEventAsync then the message callback shall be called with a status code of IOTHUB_CLIENT_CONFIRMATION_TIMEOUT. ]*/
AzureIoTClient 42:448eecc3676e 734 if ((fullEntry->ms_timesOutAfter != 0) && (fullEntry->ms_timesOutAfter < nowTick))
AzureIoTClient 42:448eecc3676e 735 {
AzureIoTClient 42:448eecc3676e 736 PDLIST_ENTRY theNext = currentItemInWaitingToSend->Flink; /*need to save the next item, because the below operations are destructive*/
AzureIoTClient 42:448eecc3676e 737 DList_RemoveEntryList(currentItemInWaitingToSend);
AzureIoTClient 42:448eecc3676e 738 if (fullEntry->callback != NULL)
AzureIoTClient 42:448eecc3676e 739 {
AzureIoTClient 42:448eecc3676e 740 fullEntry->callback(IOTHUB_CLIENT_CONFIRMATION_MESSAGE_TIMEOUT, fullEntry->context);
AzureIoTClient 42:448eecc3676e 741 }
AzureIoTClient 42:448eecc3676e 742 IoTHubMessage_Destroy(fullEntry->messageHandle); /*because it has been cloned*/
AzureIoTClient 42:448eecc3676e 743 free(fullEntry);
AzureIoTClient 42:448eecc3676e 744 currentItemInWaitingToSend = theNext;
AzureIoTClient 42:448eecc3676e 745 }
AzureIoTClient 42:448eecc3676e 746 else
AzureIoTClient 42:448eecc3676e 747 {
AzureIoTClient 42:448eecc3676e 748 currentItemInWaitingToSend = currentItemInWaitingToSend->Flink;
AzureIoTClient 42:448eecc3676e 749 }
AzureIoTClient 42:448eecc3676e 750 }
AzureIoTClient 42:448eecc3676e 751 }
Azure.IoT Build 36:67300d5a4c1f 752 }
Azure.IoT Build 36:67300d5a4c1f 753
AzureIoTClient 16:deba40344375 754 void IoTHubClient_LL_DoWork(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle)
AzureIoTClient 16:deba40344375 755 {
AzureIoTClient 42:448eecc3676e 756 /*Codes_SRS_IOTHUBCLIENT_LL_02_020: [If parameter iotHubClientHandle is NULL then IoTHubClient_LL_DoWork shall not perform any action.] */
AzureIoTClient 42:448eecc3676e 757 if (iotHubClientHandle != NULL)
AzureIoTClient 42:448eecc3676e 758 {
AzureIoTClient 42:448eecc3676e 759 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 42:448eecc3676e 760 DoTimeouts(handleData);
AzureIoTClient 42:448eecc3676e 761
AzureIoTClient 42:448eecc3676e 762 /*Codes_SRS_IOTHUBCLIENT_LL_02_021: [Otherwise, IoTHubClient_LL_DoWork shall invoke the underlaying layer's _DoWork function.]*/
AzureIoTClient 42:448eecc3676e 763 handleData->IoTHubTransport_DoWork(handleData->transportHandle, iotHubClientHandle);
AzureIoTClient 42:448eecc3676e 764 }
AzureIoTClient 16:deba40344375 765 }
AzureIoTClient 16:deba40344375 766
AzureIoTClient 16:deba40344375 767 IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetSendStatus(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus)
AzureIoTClient 16:deba40344375 768 {
AzureIoTClient 42:448eecc3676e 769 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 770
AzureIoTClient 42:448eecc3676e 771 /* Codes_SRS_IOTHUBCLIENT_09_007: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter] */
AzureIoTClient 42:448eecc3676e 772 if (iotHubClientHandle == NULL || iotHubClientStatus == NULL)
AzureIoTClient 42:448eecc3676e 773 {
AzureIoTClient 42:448eecc3676e 774 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 45:54c11b1b1407 775 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 776 }
AzureIoTClient 42:448eecc3676e 777 else
AzureIoTClient 42:448eecc3676e 778 {
AzureIoTClient 42:448eecc3676e 779 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 780
AzureIoTClient 42:448eecc3676e 781 /* Codes_SRS_IOTHUBCLIENT_09_008: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_OK and status IOTHUB_CLIENT_SEND_STATUS_IDLE if there is currently no items to be sent] */
AzureIoTClient 42:448eecc3676e 782 /* Codes_SRS_IOTHUBCLIENT_09_009: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_OK and status IOTHUB_CLIENT_SEND_STATUS_BUSY if there are currently items to be sent] */
AzureIoTClient 42:448eecc3676e 783 result = handleData->IoTHubTransport_GetSendStatus(handleData->deviceHandle, iotHubClientStatus);
AzureIoTClient 42:448eecc3676e 784 }
AzureIoTClient 16:deba40344375 785
AzureIoTClient 42:448eecc3676e 786 return result;
AzureIoTClient 16:deba40344375 787 }
AzureIoTClient 16:deba40344375 788
Azure.IoT Build 45:54c11b1b1407 789 void IoTHubClient_LL_SendComplete(IOTHUB_CLIENT_LL_HANDLE handle, PDLIST_ENTRY completed, IOTHUB_CLIENT_CONFIRMATION_RESULT result)
AzureIoTClient 16:deba40344375 790 {
AzureIoTClient 42:448eecc3676e 791 /*Codes_SRS_IOTHUBCLIENT_LL_02_022: [If parameter completed is NULL, or parameter handle is NULL then IoTHubClient_LL_SendBatch shall return.]*/
AzureIoTClient 42:448eecc3676e 792 if (
AzureIoTClient 42:448eecc3676e 793 (handle == NULL) ||
AzureIoTClient 42:448eecc3676e 794 (completed == NULL)
AzureIoTClient 42:448eecc3676e 795 )
AzureIoTClient 42:448eecc3676e 796 {
AzureIoTClient 42:448eecc3676e 797 /*"shall return"*/
AzureIoTClient 42:448eecc3676e 798 LogError("invalid arg");
AzureIoTClient 42:448eecc3676e 799 }
AzureIoTClient 42:448eecc3676e 800 else
AzureIoTClient 42:448eecc3676e 801 {
Azure.IoT Build 45:54c11b1b1407 802 /*Codes_SRS_IOTHUBCLIENT_LL_02_027: [If parameter result is IOTHUB_CLIENT_CONFIRMATION_ERROR then IoTHubClient_LL_SendComplete shall call all the non-NULL callbacks with the result parameter set to IOTHUB_CLIENT_CONFIRMATION_ERROR and the context set to the context passed originally in the SendEventAsync call.] */
Azure.IoT Build 45:54c11b1b1407 803 /*Codes_SRS_IOTHUBCLIENT_LL_02_025: [If parameter result is IOTHUB_CLIENT_CONFIRMATION_OK then IoTHubClient_LL_SendComplete shall call all the non-NULL callbacks with the result parameter set to IOTHUB_CLIENT_CONFIRMATION_OK and the context set to the context passed originally in the SendEventAsync call.]*/
AzureIoTClient 42:448eecc3676e 804 PDLIST_ENTRY oldest;
AzureIoTClient 42:448eecc3676e 805 while ((oldest = DList_RemoveHeadList(completed)) != completed)
AzureIoTClient 42:448eecc3676e 806 {
AzureIoTClient 42:448eecc3676e 807 IOTHUB_MESSAGE_LIST* messageList = (IOTHUB_MESSAGE_LIST*)containingRecord(oldest, IOTHUB_MESSAGE_LIST, entry);
AzureIoTClient 42:448eecc3676e 808 /*Codes_SRS_IOTHUBCLIENT_LL_02_026: [If any callback is NULL then there shall not be a callback call.]*/
AzureIoTClient 42:448eecc3676e 809 if (messageList->callback != NULL)
AzureIoTClient 42:448eecc3676e 810 {
Azure.IoT Build 45:54c11b1b1407 811 messageList->callback(result, messageList->context);
AzureIoTClient 42:448eecc3676e 812 }
AzureIoTClient 42:448eecc3676e 813 IoTHubMessage_Destroy(messageList->messageHandle);
AzureIoTClient 42:448eecc3676e 814 free(messageList);
AzureIoTClient 42:448eecc3676e 815 }
AzureIoTClient 42:448eecc3676e 816 }
AzureIoTClient 16:deba40344375 817 }
AzureIoTClient 16:deba40344375 818
AzureIoTClient 16:deba40344375 819 IOTHUBMESSAGE_DISPOSITION_RESULT IoTHubClient_LL_MessageCallback(IOTHUB_CLIENT_LL_HANDLE handle, IOTHUB_MESSAGE_HANDLE message)
AzureIoTClient 16:deba40344375 820 {
AzureIoTClient 42:448eecc3676e 821 int result;
AzureIoTClient 42:448eecc3676e 822 /*Codes_SRS_IOTHUBCLIENT_LL_02_029: [If parameter handle is NULL then IoTHubClient_LL_MessageCallback shall return IOTHUBMESSAGE_ABANDONED.] */
AzureIoTClient 42:448eecc3676e 823 if (handle == NULL)
AzureIoTClient 42:448eecc3676e 824 {
AzureIoTClient 42:448eecc3676e 825 LogError("invalid argument");
AzureIoTClient 42:448eecc3676e 826 result = IOTHUBMESSAGE_ABANDONED;
AzureIoTClient 42:448eecc3676e 827 }
AzureIoTClient 42:448eecc3676e 828 else
AzureIoTClient 42:448eecc3676e 829 {
AzureIoTClient 42:448eecc3676e 830 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
AzureIoTClient 16:deba40344375 831
AzureIoTClient 42:448eecc3676e 832 /* Codes_SRS_IOTHUBCLIENT_LL_09_004: [IoTHubClient_LL_GetLastMessageReceiveTime shall return lastMessageReceiveTime in localtime] */
AzureIoTClient 42:448eecc3676e 833 handleData->lastMessageReceiveTime = get_time(NULL);
AzureIoTClient 16:deba40344375 834
AzureIoTClient 42:448eecc3676e 835 /*Codes_SRS_IOTHUBCLIENT_LL_02_030: [IoTHubClient_LL_MessageCallback shall invoke the last callback function (the parameter messageCallback to IoTHubClient_LL_SetMessageCallback) passing the message and the passed userContextCallback.]*/
AzureIoTClient 42:448eecc3676e 836 if (handleData->messageCallback != NULL)
AzureIoTClient 42:448eecc3676e 837 {
AzureIoTClient 42:448eecc3676e 838 result = handleData->messageCallback(message, handleData->messageUserContextCallback);
AzureIoTClient 42:448eecc3676e 839 }
AzureIoTClient 42:448eecc3676e 840 else
AzureIoTClient 42:448eecc3676e 841 {
AzureIoTClient 42:448eecc3676e 842 /*Codes_SRS_IOTHUBCLIENT_LL_02_032: [If the last callback function was NULL, then IoTHubClient_LL_MessageCallback shall return IOTHUBMESSAGE_ABANDONED.] */
AzureIoTClient 42:448eecc3676e 843 LogError("user callback was NULL");
AzureIoTClient 42:448eecc3676e 844 result = IOTHUBMESSAGE_ABANDONED;
AzureIoTClient 42:448eecc3676e 845 }
AzureIoTClient 42:448eecc3676e 846 }
AzureIoTClient 42:448eecc3676e 847 /*Codes_SRS_IOTHUBCLIENT_LL_02_031: [Then IoTHubClient_LL_MessageCallback shall return what the user function returns.]*/
AzureIoTClient 42:448eecc3676e 848 return result;
AzureIoTClient 16:deba40344375 849 }
AzureIoTClient 16:deba40344375 850
AzureIoTClient 16:deba40344375 851 IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetLastMessageReceiveTime(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime)
AzureIoTClient 16:deba40344375 852 {
AzureIoTClient 42:448eecc3676e 853 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 42:448eecc3676e 854 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 855
AzureIoTClient 42:448eecc3676e 856 /* Codes_SRS_IOTHUBCLIENT_LL_09_001: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG if any of the arguments is NULL] */
AzureIoTClient 42:448eecc3676e 857 if (handleData == NULL || lastMessageReceiveTime == NULL)
AzureIoTClient 42:448eecc3676e 858 {
AzureIoTClient 42:448eecc3676e 859 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 45:54c11b1b1407 860 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 861 }
AzureIoTClient 42:448eecc3676e 862 else
AzureIoTClient 42:448eecc3676e 863 {
AzureIoTClient 42:448eecc3676e 864 /* Codes_SRS_IOTHUBCLIENT_LL_09_002: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INDEFINITE_TIME - and not set 'lastMessageReceiveTime' - if it is unable to provide the time for the last commands] */
AzureIoTClient 42:448eecc3676e 865 if (handleData->lastMessageReceiveTime == INDEFINITE_TIME)
AzureIoTClient 42:448eecc3676e 866 {
AzureIoTClient 42:448eecc3676e 867 result = IOTHUB_CLIENT_INDEFINITE_TIME;
Azure.IoT Build 45:54c11b1b1407 868 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 869 }
AzureIoTClient 42:448eecc3676e 870 else
AzureIoTClient 42:448eecc3676e 871 {
AzureIoTClient 42:448eecc3676e 872 /* Codes_SRS_IOTHUBCLIENT_LL_09_003: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_OK if it wrote in the lastMessageReceiveTime the time when the last command was received] */
AzureIoTClient 42:448eecc3676e 873 /* Codes_SRS_IOTHUBCLIENT_LL_09_004: [IoTHubClient_LL_GetLastMessageReceiveTime shall return lastMessageReceiveTime in localtime] */
AzureIoTClient 42:448eecc3676e 874 *lastMessageReceiveTime = handleData->lastMessageReceiveTime;
AzureIoTClient 42:448eecc3676e 875 result = IOTHUB_CLIENT_OK;
AzureIoTClient 42:448eecc3676e 876 }
AzureIoTClient 42:448eecc3676e 877 }
AzureIoTClient 16:deba40344375 878
AzureIoTClient 42:448eecc3676e 879 return result;
AzureIoTClient 16:deba40344375 880 }
AzureIoTClient 16:deba40344375 881
AzureIoTClient 16:deba40344375 882 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetOption(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* optionName, const void* value)
AzureIoTClient 16:deba40344375 883 {
AzureIoTClient 40:1a94db9139ea 884
AzureIoTClient 42:448eecc3676e 885 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 42:448eecc3676e 886 /*Codes_SRS_IOTHUBCLIENT_LL_02_034: [If iotHubClientHandle is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.]*/
AzureIoTClient 42:448eecc3676e 887 /*Codes_SRS_IOTHUBCLIENT_LL_02_035: [If optionName is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 42:448eecc3676e 888 /*Codes_SRS_IOTHUBCLIENT_LL_02_036: [If value is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 42:448eecc3676e 889 if (
AzureIoTClient 42:448eecc3676e 890 (iotHubClientHandle == NULL) ||
AzureIoTClient 42:448eecc3676e 891 (optionName == NULL) ||
AzureIoTClient 42:448eecc3676e 892 (value == NULL)
AzureIoTClient 42:448eecc3676e 893 )
AzureIoTClient 42:448eecc3676e 894 {
AzureIoTClient 42:448eecc3676e 895 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 42:448eecc3676e 896 LogError("invalid argument (NULL)");
AzureIoTClient 42:448eecc3676e 897 }
AzureIoTClient 42:448eecc3676e 898 else
AzureIoTClient 42:448eecc3676e 899 {
AzureIoTClient 42:448eecc3676e 900 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 42:448eecc3676e 901
AzureIoTClient 42:448eecc3676e 902 /*Codes_SRS_IOTHUBCLIENT_LL_02_039: [ "messageTimeout" - once IoTHubClient_LL_SendEventAsync is called the message shall timeout after value miliseconds. Value is a pointer to a uint64. ]*/
AzureIoTClient 42:448eecc3676e 903 if (strcmp(optionName, "messageTimeout") == 0)
AzureIoTClient 42:448eecc3676e 904 {
AzureIoTClient 42:448eecc3676e 905 /*this is an option handled by IoTHubClient_LL*/
AzureIoTClient 42:448eecc3676e 906 /*Codes_SRS_IOTHUBCLIENT_LL_02_043: [ Calling IoTHubClient_LL_SetOption with value set to "0" shall disable the timeout mechanism for all new messages. ]*/
AzureIoTClient 42:448eecc3676e 907 handleData->currentMessageTimeout = *(const uint64_t*)value;
AzureIoTClient 42:448eecc3676e 908 result = IOTHUB_CLIENT_OK;
AzureIoTClient 42:448eecc3676e 909 }
AzureIoTClient 42:448eecc3676e 910 else
AzureIoTClient 42:448eecc3676e 911 {
AzureIoTClient 46:6a69294b6119 912
AzureIoTClient 46:6a69294b6119 913 /*Codes_SRS_IOTHUBCLIENT_LL_02_099: [ IoTHubClient_LL_SetOption shall return according to the table below ]*/
AzureIoTClient 46:6a69294b6119 914 IOTHUB_CLIENT_RESULT uploadToBlob_result;
AzureIoTClient 46:6a69294b6119 915 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 46:6a69294b6119 916 uploadToBlob_result = IoTHubClient_LL_UploadToBlob_SetOption(handleData->uploadToBlobHandle, optionName, value);
AzureIoTClient 46:6a69294b6119 917 if(uploadToBlob_result == IOTHUB_CLIENT_ERROR)
AzureIoTClient 46:6a69294b6119 918 {
AzureIoTClient 46:6a69294b6119 919 LogError("unable to IoTHubClient_LL_UploadToBlob_SetOption");
AzureIoTClient 46:6a69294b6119 920 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 46:6a69294b6119 921 }
AzureIoTClient 46:6a69294b6119 922 #else
AzureIoTClient 46:6a69294b6119 923 uploadToBlob_result = IOTHUB_CLIENT_INVALID_ARG; /*harmless value (IOTHUB_CLIENT_INVALID_ARG)in the case when uploadtoblob is not compiled in, otherwise whatever IoTHubClient_LL_UploadToBlob_SetOption returned*/
AzureIoTClient 46:6a69294b6119 924 #endif /*DONT_USE_UPLOADTOBLOB*/
AzureIoTClient 16:deba40344375 925
AzureIoTClient 46:6a69294b6119 926
AzureIoTClient 46:6a69294b6119 927 result =
AzureIoTClient 46:6a69294b6119 928 /*based on uploadToBlob_result value this is what happens:*/
AzureIoTClient 46:6a69294b6119 929 /*IOTHUB_CLIENT_INVALID_ARG always returns what IoTHubTransport_SetOption returns*/
AzureIoTClient 46:6a69294b6119 930 /*IOTHUB_CLIENT_ERROR always returns IOTHUB_CLIENT_ERROR */
AzureIoTClient 46:6a69294b6119 931 /*IOTHUB_CLIENT_OK returns OK
AzureIoTClient 46:6a69294b6119 932 IOTHUB_CLIENT_OK if IoTHubTransport_SetOption returns OK or INVALID_ARG
AzureIoTClient 46:6a69294b6119 933 IOTHUB_CLIENT_ERROR if IoTHubTransport_SetOption returns ERROR*/
AzureIoTClient 46:6a69294b6119 934
AzureIoTClient 46:6a69294b6119 935 (uploadToBlob_result == IOTHUB_CLIENT_INVALID_ARG) ? handleData->IoTHubTransport_SetOption(handleData->transportHandle, optionName, value) :
AzureIoTClient 46:6a69294b6119 936 (uploadToBlob_result == IOTHUB_CLIENT_ERROR) ? IOTHUB_CLIENT_ERROR :
AzureIoTClient 46:6a69294b6119 937 (handleData->IoTHubTransport_SetOption(handleData->transportHandle, optionName, value) == IOTHUB_CLIENT_ERROR) ? IOTHUB_CLIENT_ERROR : IOTHUB_CLIENT_OK;
AzureIoTClient 46:6a69294b6119 938
AzureIoTClient 46:6a69294b6119 939 if (result != IOTHUB_CLIENT_OK)
AzureIoTClient 46:6a69294b6119 940 {
AzureIoTClient 46:6a69294b6119 941 LogError("underlying transport failed, returned = %s", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result));
AzureIoTClient 46:6a69294b6119 942 }
AzureIoTClient 46:6a69294b6119 943 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 944 }
AzureIoTClient 46:6a69294b6119 945 #endif
AzureIoTClient 42:448eecc3676e 946 }
AzureIoTClient 42:448eecc3676e 947 return result;
AzureIoTClient 42:448eecc3676e 948 }
AzureIoTClient 16:deba40344375 949
AzureIoTClient 44:33dd78697616 950 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 951 IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* destinationFileName, const unsigned char* source, size_t size)
AzureIoTClient 42:448eecc3676e 952 {
AzureIoTClient 42:448eecc3676e 953 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 42:448eecc3676e 954 /*Codes_SRS_IOTHUBCLIENT_LL_02_061: [ If iotHubClientHandle is NULL then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/
AzureIoTClient 42:448eecc3676e 955 /*Codes_SRS_IOTHUBCLIENT_LL_02_062: [ If destinationFileName is NULL then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/
AzureIoTClient 42:448eecc3676e 956 if (
AzureIoTClient 42:448eecc3676e 957 (iotHubClientHandle == NULL) ||
AzureIoTClient 42:448eecc3676e 958 (destinationFileName == NULL) ||
AzureIoTClient 42:448eecc3676e 959 ((source == NULL) && (size >0))
AzureIoTClient 42:448eecc3676e 960 )
AzureIoTClient 42:448eecc3676e 961 {
AzureIoTClient 42:448eecc3676e 962 LogError("invalid parameters IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle=%p, const char* destinationFileName=%s, const unsigned char* source=%p, size_t size=%zu", iotHubClientHandle, destinationFileName, source, size);
AzureIoTClient 42:448eecc3676e 963 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 42:448eecc3676e 964 }
AzureIoTClient 42:448eecc3676e 965 else
AzureIoTClient 42:448eecc3676e 966 {
AzureIoTClient 42:448eecc3676e 967 result = IoTHubClient_LL_UploadToBlob_Impl(iotHubClientHandle->uploadToBlobHandle, destinationFileName, source, size);
AzureIoTClient 42:448eecc3676e 968 }
AzureIoTClient 42:448eecc3676e 969 return result;
AzureIoTClient 16:deba40344375 970 }
AzureIoTClient 43:038d8511e817 971 #endif