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:
Fri Dec 15 14:09:20 2017 -0800
Revision:
80:db5f5237bc95
Parent:
78:74a8d3068204
Child:
81:8de701563187
1.1.29

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>
Azure.IoT Build 38:a05929a75111 5 #include <string.h>
AzureIoTClient 60:41648c4e7036 6 #include "azure_c_shared_utility/optimize_size.h"
Azure.IoT Build 38:a05929a75111 7 #include "azure_c_shared_utility/gballoc.h"
Azure.IoT Build 38:a05929a75111 8 #include "azure_c_shared_utility/string_tokenizer.h"
Azure.IoT Build 38:a05929a75111 9 #include "azure_c_shared_utility/doublylinkedlist.h"
Azure.IoT Build 45:54c11b1b1407 10 #include "azure_c_shared_utility/xlogging.h"
Azure.IoT Build 38:a05929a75111 11 #include "azure_c_shared_utility/tickcounter.h"
AzureIoTClient 53:1e5a1ca1f274 12 #include "azure_c_shared_utility/constbuffer.h"
AzureIoTClient 66:a419827cb051 13 #include "azure_c_shared_utility/platform.h"
AzureIoTClient 16:deba40344375 14
AzureIoTClient 62:5a4cdacf5090 15 #include "iothub_client_authorization.h"
AzureIoTClient 16:deba40344375 16 #include "iothub_client_ll.h"
AzureIoTClient 61:8b85a4e797cf 17 #include "iothub_transport_ll.h"
AzureIoTClient 16:deba40344375 18 #include "iothub_client_private.h"
AzureIoTClient 66:a419827cb051 19 #include "iothub_client_options.h"
AzureIoTClient 33:b372b0efcd20 20 #include "iothub_client_version.h"
AzureIoTClient 77:e4e36df9caee 21 #include "iothub_client_diagnostic.h"
AzureIoTClient 53:1e5a1ca1f274 22 #include <stdint.h>
AzureIoTClient 43:038d8511e817 23
AzureIoTClient 78:74a8d3068204 24 #ifdef USE_PROV_MODULE
AzureIoTClient 78:74a8d3068204 25 #include "iothub_client_hsm_ll.h"
AzureIoTClient 75:86205ca63a59 26 #endif
AzureIoTClient 75:86205ca63a59 27
AzureIoTClient 44:33dd78697616 28 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 29 #include "iothub_client_ll_uploadtoblob.h"
AzureIoTClient 43:038d8511e817 30 #endif
Azure.IoT Build 36:67300d5a4c1f 31
Azure.IoT Build 45:54c11b1b1407 32 #define LOG_ERROR_RESULT LogError("result = %s", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result));
AzureIoTClient 16:deba40344375 33 #define INDEFINITE_TIME ((time_t)(-1))
AzureIoTClient 16:deba40344375 34
AzureIoTClient 16:deba40344375 35 DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_RESULT_VALUES);
Azure.IoT Build 45:54c11b1b1407 36 DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES);
AzureIoTClient 16:deba40344375 37
AzureIoTClient 62:5a4cdacf5090 38 #define CALLBACK_TYPE_VALUES \
AzureIoTClient 62:5a4cdacf5090 39 CALLBACK_TYPE_NONE, \
AzureIoTClient 62:5a4cdacf5090 40 CALLBACK_TYPE_SYNC, \
AzureIoTClient 62:5a4cdacf5090 41 CALLBACK_TYPE_ASYNC
AzureIoTClient 62:5a4cdacf5090 42
AzureIoTClient 62:5a4cdacf5090 43 DEFINE_ENUM(CALLBACK_TYPE, CALLBACK_TYPE_VALUES)
AzureIoTClient 62:5a4cdacf5090 44 DEFINE_ENUM_STRINGS(CALLBACK_TYPE, CALLBACK_TYPE_VALUES)
AzureIoTClient 61:8b85a4e797cf 45
AzureIoTClient 62:5a4cdacf5090 46 typedef struct IOTHUB_METHOD_CALLBACK_DATA_TAG
AzureIoTClient 62:5a4cdacf5090 47 {
AzureIoTClient 62:5a4cdacf5090 48 CALLBACK_TYPE type;
AzureIoTClient 62:5a4cdacf5090 49 IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC callbackSync;
AzureIoTClient 62:5a4cdacf5090 50 IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK callbackAsync;
AzureIoTClient 62:5a4cdacf5090 51 void* userContextCallback;
AzureIoTClient 62:5a4cdacf5090 52 }IOTHUB_METHOD_CALLBACK_DATA;
AzureIoTClient 61:8b85a4e797cf 53
AzureIoTClient 61:8b85a4e797cf 54 typedef struct IOTHUB_MESSAGE_CALLBACK_DATA_TAG
AzureIoTClient 61:8b85a4e797cf 55 {
AzureIoTClient 62:5a4cdacf5090 56 CALLBACK_TYPE type;
AzureIoTClient 61:8b85a4e797cf 57 IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC callbackSync;
AzureIoTClient 61:8b85a4e797cf 58 IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC_EX callbackAsync;
AzureIoTClient 62:5a4cdacf5090 59 void* userContextCallback;
AzureIoTClient 61:8b85a4e797cf 60 }IOTHUB_MESSAGE_CALLBACK_DATA;
AzureIoTClient 61:8b85a4e797cf 61
AzureIoTClient 16:deba40344375 62 typedef struct IOTHUB_CLIENT_LL_HANDLE_DATA_TAG
AzureIoTClient 16:deba40344375 63 {
AzureIoTClient 42:448eecc3676e 64 DLIST_ENTRY waitingToSend;
AzureIoTClient 53:1e5a1ca1f274 65 DLIST_ENTRY iot_msg_queue;
AzureIoTClient 53:1e5a1ca1f274 66 DLIST_ENTRY iot_ack_queue;
AzureIoTClient 42:448eecc3676e 67 TRANSPORT_LL_HANDLE transportHandle;
AzureIoTClient 42:448eecc3676e 68 bool isSharedTransport;
AzureIoTClient 42:448eecc3676e 69 IOTHUB_DEVICE_HANDLE deviceHandle;
AzureIoTClient 42:448eecc3676e 70 TRANSPORT_PROVIDER_FIELDS;
AzureIoTClient 61:8b85a4e797cf 71 IOTHUB_MESSAGE_CALLBACK_DATA messageCallback;
AzureIoTClient 62:5a4cdacf5090 72 IOTHUB_METHOD_CALLBACK_DATA methodCallback;
AzureIoTClient 53:1e5a1ca1f274 73 IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK conStatusCallback;
AzureIoTClient 53:1e5a1ca1f274 74 void* conStatusUserContextCallback;
AzureIoTClient 42:448eecc3676e 75 time_t lastMessageReceiveTime;
AzureIoTClient 42:448eecc3676e 76 TICK_COUNTER_HANDLE tickCounter; /*shared tickcounter used to track message timeouts in waitingToSend list*/
Azure.IoT.Build 54:6dcad9019a64 77 tickcounter_ms_t currentMessageTimeout;
AzureIoTClient 53:1e5a1ca1f274 78 uint64_t current_device_twin_timeout;
AzureIoTClient 53:1e5a1ca1f274 79 IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback;
AzureIoTClient 53:1e5a1ca1f274 80 void* deviceTwinContextCallback;
AzureIoTClient 52:1cc3c6d07cad 81 IOTHUB_CLIENT_RETRY_POLICY retryPolicy;
AzureIoTClient 53:1e5a1ca1f274 82 size_t retryTimeoutLimitInSeconds;
AzureIoTClient 44:33dd78697616 83 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 84 IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE uploadToBlobHandle;
AzureIoTClient 43:038d8511e817 85 #endif
AzureIoTClient 53:1e5a1ca1f274 86 uint32_t data_msg_id;
AzureIoTClient 53:1e5a1ca1f274 87 bool complete_twin_update_encountered;
AzureIoTClient 62:5a4cdacf5090 88 IOTHUB_AUTHORIZATION_HANDLE authorization_module;
AzureIoTClient 66:a419827cb051 89 STRING_HANDLE product_info;
AzureIoTClient 77:e4e36df9caee 90 IOTHUB_DIAGNOSTIC_SETTING_DATA diagnostic_setting;
AzureIoTClient 16:deba40344375 91 }IOTHUB_CLIENT_LL_HANDLE_DATA;
AzureIoTClient 16:deba40344375 92
AzureIoTClient 16:deba40344375 93 static const char HOSTNAME_TOKEN[] = "HostName";
AzureIoTClient 16:deba40344375 94 static const char DEVICEID_TOKEN[] = "DeviceId";
Azure.IoT Build 45:54c11b1b1407 95 static const char X509_TOKEN[] = "x509";
Azure.IoT Build 45:54c11b1b1407 96 static const char X509_TOKEN_ONLY_ACCEPTABLE_VALUE[] = "true";
AzureIoTClient 16:deba40344375 97 static const char DEVICEKEY_TOKEN[] = "SharedAccessKey";
AzureIoTClient 40:1a94db9139ea 98 static const char DEVICESAS_TOKEN[] = "SharedAccessSignature";
AzureIoTClient 16:deba40344375 99 static const char PROTOCOL_GATEWAY_HOST[] = "GatewayHostName";
AzureIoTClient 80:db5f5237bc95 100 static const char PROVISIONING_TOKEN[] = "UseProvisioning";
AzureIoTClient 80:db5f5237bc95 101 static const char PROVISIONING_ACCEPTABLE_VALUE[] = "true";
AzureIoTClient 16:deba40344375 102
AzureIoTClient 62:5a4cdacf5090 103 static void setTransportProtocol(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, TRANSPORT_PROVIDER* protocol)
AzureIoTClient 62:5a4cdacf5090 104 {
AzureIoTClient 62:5a4cdacf5090 105 handleData->IoTHubTransport_SendMessageDisposition = protocol->IoTHubTransport_SendMessageDisposition;
AzureIoTClient 62:5a4cdacf5090 106 handleData->IoTHubTransport_GetHostname = protocol->IoTHubTransport_GetHostname;
AzureIoTClient 62:5a4cdacf5090 107 handleData->IoTHubTransport_SetOption = protocol->IoTHubTransport_SetOption;
AzureIoTClient 62:5a4cdacf5090 108 handleData->IoTHubTransport_Create = protocol->IoTHubTransport_Create;
AzureIoTClient 62:5a4cdacf5090 109 handleData->IoTHubTransport_Destroy = protocol->IoTHubTransport_Destroy;
AzureIoTClient 62:5a4cdacf5090 110 handleData->IoTHubTransport_Register = protocol->IoTHubTransport_Register;
AzureIoTClient 62:5a4cdacf5090 111 handleData->IoTHubTransport_Unregister = protocol->IoTHubTransport_Unregister;
AzureIoTClient 62:5a4cdacf5090 112 handleData->IoTHubTransport_Subscribe = protocol->IoTHubTransport_Subscribe;
AzureIoTClient 62:5a4cdacf5090 113 handleData->IoTHubTransport_Unsubscribe = protocol->IoTHubTransport_Unsubscribe;
AzureIoTClient 62:5a4cdacf5090 114 handleData->IoTHubTransport_DoWork = protocol->IoTHubTransport_DoWork;
AzureIoTClient 62:5a4cdacf5090 115 handleData->IoTHubTransport_SetRetryPolicy = protocol->IoTHubTransport_SetRetryPolicy;
AzureIoTClient 62:5a4cdacf5090 116 handleData->IoTHubTransport_GetSendStatus = protocol->IoTHubTransport_GetSendStatus;
AzureIoTClient 62:5a4cdacf5090 117 handleData->IoTHubTransport_ProcessItem = protocol->IoTHubTransport_ProcessItem;
AzureIoTClient 62:5a4cdacf5090 118 handleData->IoTHubTransport_Subscribe_DeviceTwin = protocol->IoTHubTransport_Subscribe_DeviceTwin;
AzureIoTClient 62:5a4cdacf5090 119 handleData->IoTHubTransport_Unsubscribe_DeviceTwin = protocol->IoTHubTransport_Unsubscribe_DeviceTwin;
AzureIoTClient 62:5a4cdacf5090 120 handleData->IoTHubTransport_Subscribe_DeviceMethod = protocol->IoTHubTransport_Subscribe_DeviceMethod;
AzureIoTClient 62:5a4cdacf5090 121 handleData->IoTHubTransport_Unsubscribe_DeviceMethod = protocol->IoTHubTransport_Unsubscribe_DeviceMethod;
AzureIoTClient 62:5a4cdacf5090 122 handleData->IoTHubTransport_DeviceMethod_Response = protocol->IoTHubTransport_DeviceMethod_Response;
AzureIoTClient 62:5a4cdacf5090 123 }
AzureIoTClient 62:5a4cdacf5090 124
AzureIoTClient 53:1e5a1ca1f274 125 static void device_twin_data_destroy(IOTHUB_DEVICE_TWIN* client_item)
AzureIoTClient 53:1e5a1ca1f274 126 {
AzureIoTClient 53:1e5a1ca1f274 127 CONSTBUFFER_Destroy(client_item->report_data_handle);
AzureIoTClient 53:1e5a1ca1f274 128 free(client_item);
AzureIoTClient 53:1e5a1ca1f274 129 }
AzureIoTClient 53:1e5a1ca1f274 130
AzureIoTClient 62:5a4cdacf5090 131 static int create_blob_upload_module(IOTHUB_CLIENT_LL_HANDLE_DATA* handle_data, const IOTHUB_CLIENT_CONFIG* config)
AzureIoTClient 62:5a4cdacf5090 132 {
AzureIoTClient 62:5a4cdacf5090 133 int result;
AzureIoTClient 63:1bf1c2d60aab 134 (void)handle_data;
AzureIoTClient 63:1bf1c2d60aab 135 (void)config;
AzureIoTClient 62:5a4cdacf5090 136 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 62:5a4cdacf5090 137 handle_data->uploadToBlobHandle = IoTHubClient_LL_UploadToBlob_Create(config);
AzureIoTClient 62:5a4cdacf5090 138 if (handle_data->uploadToBlobHandle == NULL)
AzureIoTClient 62:5a4cdacf5090 139 {
AzureIoTClient 62:5a4cdacf5090 140 LogError("unable to IoTHubClient_LL_UploadToBlob_Create");
AzureIoTClient 62:5a4cdacf5090 141 result = __FAILURE__;
AzureIoTClient 62:5a4cdacf5090 142 }
AzureIoTClient 62:5a4cdacf5090 143 else
AzureIoTClient 62:5a4cdacf5090 144 {
AzureIoTClient 62:5a4cdacf5090 145 result = 0;
AzureIoTClient 62:5a4cdacf5090 146 }
AzureIoTClient 62:5a4cdacf5090 147 #else
AzureIoTClient 62:5a4cdacf5090 148 result = 0;
AzureIoTClient 62:5a4cdacf5090 149 #endif
AzureIoTClient 62:5a4cdacf5090 150 return result;
AzureIoTClient 62:5a4cdacf5090 151 }
AzureIoTClient 62:5a4cdacf5090 152
AzureIoTClient 62:5a4cdacf5090 153 static void destroy_blob_upload_module(IOTHUB_CLIENT_LL_HANDLE_DATA* handle_data)
AzureIoTClient 62:5a4cdacf5090 154 {
AzureIoTClient 63:1bf1c2d60aab 155 (void)handle_data;
AzureIoTClient 62:5a4cdacf5090 156 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 62:5a4cdacf5090 157 /*Codes_SRS_IOTHUBCLIENT_LL_02_046: [ If creating the TICK_COUNTER_HANDLE fails then IoTHubClient_LL_Create shall fail and return NULL. ]*/
AzureIoTClient 62:5a4cdacf5090 158 IoTHubClient_LL_UploadToBlob_Destroy(handle_data->uploadToBlobHandle);
AzureIoTClient 62:5a4cdacf5090 159 #endif
AzureIoTClient 62:5a4cdacf5090 160 }
AzureIoTClient 62:5a4cdacf5090 161
AzureIoTClient 66:a419827cb051 162 /*Codes_SRS_IOTHUBCLIENT_LL_10_032: ["product_info" - takes a char string as an argument to specify the product information(e.g. `"ProductName/ProductVersion"`). ]*/
AzureIoTClient 66:a419827cb051 163 /*Codes_SRS_IOTHUBCLIENT_LL_10_034: ["product_info" - shall store the given string concatenated with the sdk information and the platform information in the form(ProductInfo DeviceSDKName / DeviceSDKVersion(OSName OSVersion; Architecture). ]*/
AzureIoTClient 66:a419827cb051 164 static STRING_HANDLE make_product_info(const char* product)
AzureIoTClient 62:5a4cdacf5090 165 {
AzureIoTClient 66:a419827cb051 166 STRING_HANDLE result;
AzureIoTClient 66:a419827cb051 167 STRING_HANDLE pfi = platform_get_platform_info();
AzureIoTClient 66:a419827cb051 168 if (pfi == NULL)
AzureIoTClient 62:5a4cdacf5090 169 {
AzureIoTClient 66:a419827cb051 170 result = NULL;
AzureIoTClient 62:5a4cdacf5090 171 }
AzureIoTClient 62:5a4cdacf5090 172 else
AzureIoTClient 62:5a4cdacf5090 173 {
AzureIoTClient 66:a419827cb051 174 if (product == NULL)
AzureIoTClient 66:a419827cb051 175 {
AzureIoTClient 66:a419827cb051 176 result = STRING_construct_sprintf("%s %s", CLIENT_DEVICE_TYPE_PREFIX CLIENT_DEVICE_BACKSLASH IOTHUB_SDK_VERSION, STRING_c_str(pfi));
AzureIoTClient 66:a419827cb051 177 }
AzureIoTClient 66:a419827cb051 178 else
AzureIoTClient 66:a419827cb051 179 {
AzureIoTClient 66:a419827cb051 180 result = STRING_construct_sprintf("%s %s %s", product, CLIENT_DEVICE_TYPE_PREFIX CLIENT_DEVICE_BACKSLASH IOTHUB_SDK_VERSION, STRING_c_str(pfi));
AzureIoTClient 66:a419827cb051 181 }
AzureIoTClient 66:a419827cb051 182 STRING_delete(pfi);
AzureIoTClient 66:a419827cb051 183 }
AzureIoTClient 66:a419827cb051 184 return result;
AzureIoTClient 66:a419827cb051 185 }
AzureIoTClient 62:5a4cdacf5090 186
AzureIoTClient 75:86205ca63a59 187 static IOTHUB_CLIENT_LL_HANDLE_DATA* initialize_iothub_client(const IOTHUB_CLIENT_CONFIG* client_config, const IOTHUB_CLIENT_DEVICE_CONFIG* device_config, bool use_dev_auth)
AzureIoTClient 66:a419827cb051 188 {
AzureIoTClient 66:a419827cb051 189 IOTHUB_CLIENT_LL_HANDLE_DATA* result;
AzureIoTClient 77:e4e36df9caee 190 srand((unsigned int)time(NULL));
AzureIoTClient 66:a419827cb051 191 STRING_HANDLE product_info = make_product_info(NULL);
AzureIoTClient 66:a419827cb051 192 if (product_info == NULL)
AzureIoTClient 66:a419827cb051 193 {
AzureIoTClient 66:a419827cb051 194 LogError("failed to initialize product info");
AzureIoTClient 66:a419827cb051 195 result = NULL;
AzureIoTClient 66:a419827cb051 196 }
AzureIoTClient 66:a419827cb051 197 else
AzureIoTClient 66:a419827cb051 198 {
AzureIoTClient 66:a419827cb051 199 result = (IOTHUB_CLIENT_LL_HANDLE_DATA*)malloc(sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA));
AzureIoTClient 66:a419827cb051 200 if (result == NULL)
AzureIoTClient 63:1bf1c2d60aab 201 {
AzureIoTClient 66:a419827cb051 202 LogError("failure allocating IOTHUB_CLIENT_LL_HANDLE_DATA");
AzureIoTClient 66:a419827cb051 203 STRING_delete(product_info);
AzureIoTClient 63:1bf1c2d60aab 204 }
AzureIoTClient 63:1bf1c2d60aab 205 else
AzureIoTClient 63:1bf1c2d60aab 206 {
AzureIoTClient 66:a419827cb051 207 IOTHUB_CLIENT_CONFIG actual_config;
AzureIoTClient 66:a419827cb051 208 const IOTHUB_CLIENT_CONFIG* config = NULL;
AzureIoTClient 66:a419827cb051 209 char* IoTHubName = NULL;
AzureIoTClient 75:86205ca63a59 210 char* IoTHubSuffix = NULL;
AzureIoTClient 66:a419827cb051 211
AzureIoTClient 66:a419827cb051 212 memset(result, 0, sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA));
AzureIoTClient 75:86205ca63a59 213 if (use_dev_auth)
AzureIoTClient 66:a419827cb051 214 {
AzureIoTClient 75:86205ca63a59 215 if ((result->authorization_module = IoTHubClient_Auth_CreateFromDeviceAuth(client_config->deviceId)) == NULL)
AzureIoTClient 66:a419827cb051 216 {
AzureIoTClient 75:86205ca63a59 217 LogError("Failed create authorization module");
AzureIoTClient 66:a419827cb051 218 free(result);
AzureIoTClient 75:86205ca63a59 219 STRING_delete(product_info);
AzureIoTClient 66:a419827cb051 220 result = NULL;
AzureIoTClient 66:a419827cb051 221 }
AzureIoTClient 62:5a4cdacf5090 222 }
AzureIoTClient 62:5a4cdacf5090 223 else
AzureIoTClient 62:5a4cdacf5090 224 {
AzureIoTClient 75:86205ca63a59 225 const char* device_key;
AzureIoTClient 75:86205ca63a59 226 const char* device_id;
AzureIoTClient 75:86205ca63a59 227 const char* sas_token;
AzureIoTClient 75:86205ca63a59 228 if (device_config == NULL)
AzureIoTClient 62:5a4cdacf5090 229 {
AzureIoTClient 75:86205ca63a59 230 device_key = client_config->deviceKey;
AzureIoTClient 75:86205ca63a59 231 device_id = client_config->deviceId;
AzureIoTClient 75:86205ca63a59 232 sas_token = client_config->deviceSasToken;
AzureIoTClient 62:5a4cdacf5090 233 }
AzureIoTClient 62:5a4cdacf5090 234 else
AzureIoTClient 62:5a4cdacf5090 235 {
AzureIoTClient 75:86205ca63a59 236 device_key = device_config->deviceKey;
AzureIoTClient 75:86205ca63a59 237 device_id = device_config->deviceId;
AzureIoTClient 75:86205ca63a59 238 sas_token = device_config->deviceSasToken;
AzureIoTClient 75:86205ca63a59 239 }
AzureIoTClient 75:86205ca63a59 240
AzureIoTClient 75:86205ca63a59 241 /* Codes_SRS_IOTHUBCLIENT_LL_07_029: [ IoTHubClient_LL_Create shall create the Auth module with the device_key, device_id, and/or deviceSasToken values ] */
AzureIoTClient 75:86205ca63a59 242 if ((result->authorization_module = IoTHubClient_Auth_Create(device_key, device_id, sas_token)) == NULL)
AzureIoTClient 75:86205ca63a59 243 {
AzureIoTClient 75:86205ca63a59 244 LogError("Failed create authorization module");
AzureIoTClient 75:86205ca63a59 245 free(result);
AzureIoTClient 75:86205ca63a59 246 STRING_delete(product_info);
AzureIoTClient 75:86205ca63a59 247 result = NULL;
AzureIoTClient 75:86205ca63a59 248 }
AzureIoTClient 75:86205ca63a59 249 }
AzureIoTClient 75:86205ca63a59 250
AzureIoTClient 75:86205ca63a59 251 if (result != NULL)
AzureIoTClient 75:86205ca63a59 252 {
AzureIoTClient 75:86205ca63a59 253 if (client_config != NULL)
AzureIoTClient 75:86205ca63a59 254 {
AzureIoTClient 75:86205ca63a59 255 IOTHUBTRANSPORT_CONFIG lowerLayerConfig;
AzureIoTClient 75:86205ca63a59 256 memset(&lowerLayerConfig, 0, sizeof(IOTHUBTRANSPORT_CONFIG));
AzureIoTClient 75:86205ca63a59 257 /*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 75:86205ca63a59 258 lowerLayerConfig.upperConfig = client_config;
AzureIoTClient 75:86205ca63a59 259 lowerLayerConfig.waitingToSend = &(result->waitingToSend);
AzureIoTClient 75:86205ca63a59 260 lowerLayerConfig.auth_module_handle = result->authorization_module;
AzureIoTClient 75:86205ca63a59 261
AzureIoTClient 75:86205ca63a59 262 setTransportProtocol(result, (TRANSPORT_PROVIDER*)client_config->protocol());
AzureIoTClient 75:86205ca63a59 263 if ((result->transportHandle = result->IoTHubTransport_Create(&lowerLayerConfig)) == NULL)
AzureIoTClient 62:5a4cdacf5090 264 {
AzureIoTClient 75:86205ca63a59 265 /*Codes_SRS_IOTHUBCLIENT_LL_02_007: [If the underlaying layer _Create function fails them IoTHubClient_LL_Create shall fail and return NULL.] */
AzureIoTClient 75:86205ca63a59 266 LogError("underlying transport failed");
AzureIoTClient 75:86205ca63a59 267 destroy_blob_upload_module(result);
AzureIoTClient 75:86205ca63a59 268 tickcounter_destroy(result->tickCounter);
AzureIoTClient 63:1bf1c2d60aab 269 IoTHubClient_Auth_Destroy(result->authorization_module);
AzureIoTClient 66:a419827cb051 270 STRING_delete(product_info);
AzureIoTClient 62:5a4cdacf5090 271 free(result);
AzureIoTClient 62:5a4cdacf5090 272 result = NULL;
AzureIoTClient 62:5a4cdacf5090 273 }
AzureIoTClient 62:5a4cdacf5090 274 else
AzureIoTClient 62:5a4cdacf5090 275 {
AzureIoTClient 75:86205ca63a59 276 /*Codes_SRS_IOTHUBCLIENT_LL_02_008: [Otherwise, IoTHubClient_LL_Create shall succeed and return a non-NULL handle.] */
AzureIoTClient 75:86205ca63a59 277 result->isSharedTransport = false;
AzureIoTClient 75:86205ca63a59 278 config = client_config;
AzureIoTClient 75:86205ca63a59 279 }
AzureIoTClient 75:86205ca63a59 280 }
AzureIoTClient 75:86205ca63a59 281 else
AzureIoTClient 75:86205ca63a59 282 {
AzureIoTClient 75:86205ca63a59 283 STRING_HANDLE transport_hostname = NULL;
AzureIoTClient 75:86205ca63a59 284
AzureIoTClient 75:86205ca63a59 285 result->transportHandle = device_config->transportHandle;
AzureIoTClient 75:86205ca63a59 286 setTransportProtocol(result, (TRANSPORT_PROVIDER*)device_config->protocol());
AzureIoTClient 75:86205ca63a59 287
AzureIoTClient 75:86205ca63a59 288 transport_hostname = result->IoTHubTransport_GetHostname(result->transportHandle);
AzureIoTClient 75:86205ca63a59 289 if (transport_hostname == NULL)
AzureIoTClient 75:86205ca63a59 290 {
AzureIoTClient 75:86205ca63a59 291 /*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 75:86205ca63a59 292 LogError("unable to determine the transport IoTHub name");
AzureIoTClient 75:86205ca63a59 293 IoTHubClient_Auth_Destroy(result->authorization_module);
AzureIoTClient 75:86205ca63a59 294 STRING_delete(product_info);
AzureIoTClient 75:86205ca63a59 295 free(result);
AzureIoTClient 75:86205ca63a59 296 result = NULL;
AzureIoTClient 75:86205ca63a59 297 }
AzureIoTClient 75:86205ca63a59 298 else
AzureIoTClient 75:86205ca63a59 299 {
AzureIoTClient 75:86205ca63a59 300 const char* hostname = STRING_c_str(transport_hostname);
AzureIoTClient 66:a419827cb051 301 /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/
AzureIoTClient 75:86205ca63a59 302 /*the first '.' says where the iothubname finishes*/
AzureIoTClient 75:86205ca63a59 303 const char* whereIsDot = strchr(hostname, '.');
AzureIoTClient 75:86205ca63a59 304 if (whereIsDot == NULL)
AzureIoTClient 66:a419827cb051 305 {
AzureIoTClient 66:a419827cb051 306 /*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 75:86205ca63a59 307 LogError("unable to determine the IoTHub name");
AzureIoTClient 66:a419827cb051 308 IoTHubClient_Auth_Destroy(result->authorization_module);
AzureIoTClient 66:a419827cb051 309 STRING_delete(product_info);
AzureIoTClient 66:a419827cb051 310 free(result);
AzureIoTClient 66:a419827cb051 311 result = NULL;
AzureIoTClient 66:a419827cb051 312 }
AzureIoTClient 66:a419827cb051 313 else
AzureIoTClient 66:a419827cb051 314 {
AzureIoTClient 75:86205ca63a59 315 size_t suffix_len = strlen(whereIsDot);
AzureIoTClient 75:86205ca63a59 316 /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/
AzureIoTClient 75:86205ca63a59 317 IoTHubName = (char*)malloc(whereIsDot - hostname + 1);
AzureIoTClient 75:86205ca63a59 318 if (IoTHubName == NULL)
AzureIoTClient 75:86205ca63a59 319 {
AzureIoTClient 75:86205ca63a59 320 /*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 75:86205ca63a59 321 LogError("unable to malloc");
AzureIoTClient 75:86205ca63a59 322 IoTHubClient_Auth_Destroy(result->authorization_module);
AzureIoTClient 75:86205ca63a59 323 STRING_delete(product_info);
AzureIoTClient 75:86205ca63a59 324 free(result);
AzureIoTClient 75:86205ca63a59 325 result = NULL;
AzureIoTClient 75:86205ca63a59 326 }
AzureIoTClient 75:86205ca63a59 327 else if ((IoTHubSuffix = (char*)malloc(suffix_len + 1)) == NULL)
AzureIoTClient 75:86205ca63a59 328 {
AzureIoTClient 75:86205ca63a59 329 /*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 75:86205ca63a59 330 LogError("unable to malloc");
AzureIoTClient 75:86205ca63a59 331 IoTHubClient_Auth_Destroy(result->authorization_module);
AzureIoTClient 75:86205ca63a59 332 STRING_delete(product_info);
AzureIoTClient 75:86205ca63a59 333 free(result);
AzureIoTClient 75:86205ca63a59 334 result = NULL;
AzureIoTClient 75:86205ca63a59 335 }
AzureIoTClient 75:86205ca63a59 336 else
AzureIoTClient 75:86205ca63a59 337 {
AzureIoTClient 75:86205ca63a59 338 memset(IoTHubName, 0, whereIsDot - hostname + 1);
AzureIoTClient 75:86205ca63a59 339 (void)strncpy(IoTHubName, hostname, whereIsDot - hostname);
AzureIoTClient 75:86205ca63a59 340 (void)strcpy(IoTHubSuffix, whereIsDot+1);
AzureIoTClient 62:5a4cdacf5090 341
AzureIoTClient 75:86205ca63a59 342 actual_config.deviceId = device_config->deviceId;
AzureIoTClient 75:86205ca63a59 343 actual_config.deviceKey = device_config->deviceKey;
AzureIoTClient 75:86205ca63a59 344 actual_config.deviceSasToken = device_config->deviceSasToken;
AzureIoTClient 75:86205ca63a59 345 actual_config.iotHubName = IoTHubName;
AzureIoTClient 75:86205ca63a59 346 actual_config.iotHubSuffix = IoTHubSuffix;
AzureIoTClient 75:86205ca63a59 347 actual_config.protocol = NULL; /*irrelevant to IoTHubClient_LL_UploadToBlob*/
AzureIoTClient 75:86205ca63a59 348 actual_config.protocolGatewayHostName = NULL; /*irrelevant to IoTHubClient_LL_UploadToBlob*/
AzureIoTClient 62:5a4cdacf5090 349
AzureIoTClient 75:86205ca63a59 350 config = &actual_config;
AzureIoTClient 62:5a4cdacf5090 351
AzureIoTClient 75:86205ca63a59 352 /*Codes_SRS_IOTHUBCLIENT_LL_02_008: [Otherwise, IoTHubClient_LL_Create shall succeed and return a non-NULL handle.] */
AzureIoTClient 75:86205ca63a59 353 result->isSharedTransport = true;
AzureIoTClient 75:86205ca63a59 354 }
AzureIoTClient 66:a419827cb051 355 }
AzureIoTClient 62:5a4cdacf5090 356 }
AzureIoTClient 75:86205ca63a59 357 STRING_delete(transport_hostname);
AzureIoTClient 62:5a4cdacf5090 358 }
AzureIoTClient 62:5a4cdacf5090 359 }
AzureIoTClient 66:a419827cb051 360 if (result != NULL)
AzureIoTClient 62:5a4cdacf5090 361 {
AzureIoTClient 66:a419827cb051 362 if (create_blob_upload_module(result, config) != 0)
AzureIoTClient 62:5a4cdacf5090 363 {
AzureIoTClient 66:a419827cb051 364 LogError("unable to create blob upload");
AzureIoTClient 73:c4d9077dd0a1 365 // Codes_SRS_IOTHUBCLIENT_LL_09_010: [ If any failure occurs `IoTHubClient_LL_Create` shall destroy the `transportHandle` only if it has created it ]
AzureIoTClient 73:c4d9077dd0a1 366 if (!result->isSharedTransport)
AzureIoTClient 73:c4d9077dd0a1 367 {
AzureIoTClient 73:c4d9077dd0a1 368 result->IoTHubTransport_Destroy(result->transportHandle);
AzureIoTClient 73:c4d9077dd0a1 369 }
AzureIoTClient 62:5a4cdacf5090 370 IoTHubClient_Auth_Destroy(result->authorization_module);
AzureIoTClient 66:a419827cb051 371 STRING_delete(product_info);
AzureIoTClient 62:5a4cdacf5090 372 free(result);
AzureIoTClient 62:5a4cdacf5090 373 result = NULL;
AzureIoTClient 62:5a4cdacf5090 374 }
AzureIoTClient 62:5a4cdacf5090 375 else
AzureIoTClient 62:5a4cdacf5090 376 {
AzureIoTClient 66:a419827cb051 377 if ((result->tickCounter = tickcounter_create()) == NULL)
AzureIoTClient 62:5a4cdacf5090 378 {
AzureIoTClient 66:a419827cb051 379 LogError("unable to get a tickcounter");
AzureIoTClient 73:c4d9077dd0a1 380 // Codes_SRS_IOTHUBCLIENT_LL_09_010: [ If any failure occurs `IoTHubClient_LL_Create` shall destroy the `transportHandle` only if it has created it ]
AzureIoTClient 73:c4d9077dd0a1 381 if (!result->isSharedTransport)
AzureIoTClient 73:c4d9077dd0a1 382 {
AzureIoTClient 73:c4d9077dd0a1 383 result->IoTHubTransport_Destroy(result->transportHandle);
AzureIoTClient 73:c4d9077dd0a1 384 }
AzureIoTClient 66:a419827cb051 385 destroy_blob_upload_module(result);
AzureIoTClient 62:5a4cdacf5090 386 IoTHubClient_Auth_Destroy(result->authorization_module);
AzureIoTClient 66:a419827cb051 387 STRING_delete(product_info);
AzureIoTClient 62:5a4cdacf5090 388 free(result);
AzureIoTClient 62:5a4cdacf5090 389 result = NULL;
AzureIoTClient 62:5a4cdacf5090 390 }
AzureIoTClient 62:5a4cdacf5090 391 else
AzureIoTClient 62:5a4cdacf5090 392 {
AzureIoTClient 66:a419827cb051 393 /*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 66:a419827cb051 394 DList_InitializeListHead(&(result->waitingToSend));
AzureIoTClient 66:a419827cb051 395 DList_InitializeListHead(&(result->iot_msg_queue));
AzureIoTClient 66:a419827cb051 396 DList_InitializeListHead(&(result->iot_ack_queue));
AzureIoTClient 66:a419827cb051 397 result->messageCallback.type = CALLBACK_TYPE_NONE;
AzureIoTClient 66:a419827cb051 398 result->lastMessageReceiveTime = INDEFINITE_TIME;
AzureIoTClient 66:a419827cb051 399 result->data_msg_id = 1;
AzureIoTClient 66:a419827cb051 400 result->product_info = product_info;
AzureIoTClient 66:a419827cb051 401
AzureIoTClient 66:a419827cb051 402 IOTHUB_DEVICE_CONFIG deviceConfig;
AzureIoTClient 66:a419827cb051 403 deviceConfig.deviceId = config->deviceId;
AzureIoTClient 66:a419827cb051 404 deviceConfig.deviceKey = config->deviceKey;
AzureIoTClient 66:a419827cb051 405 deviceConfig.deviceSasToken = config->deviceSasToken;
AzureIoTClient 66:a419827cb051 406 deviceConfig.authorization_module = result->authorization_module;
AzureIoTClient 66:a419827cb051 407
AzureIoTClient 66:a419827cb051 408 /*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 66:a419827cb051 409 if ((result->deviceHandle = result->IoTHubTransport_Register(result->transportHandle, &deviceConfig, result, &(result->waitingToSend))) == NULL)
AzureIoTClient 62:5a4cdacf5090 410 {
AzureIoTClient 66:a419827cb051 411 LogError("Registering device in transport failed");
AzureIoTClient 62:5a4cdacf5090 412 IoTHubClient_Auth_Destroy(result->authorization_module);
AzureIoTClient 73:c4d9077dd0a1 413 // Codes_SRS_IOTHUBCLIENT_LL_09_010: [ If any failure occurs `IoTHubClient_LL_Create` shall destroy the `transportHandle` only if it has created it ]
AzureIoTClient 73:c4d9077dd0a1 414 if (!result->isSharedTransport)
AzureIoTClient 73:c4d9077dd0a1 415 {
AzureIoTClient 73:c4d9077dd0a1 416 result->IoTHubTransport_Destroy(result->transportHandle);
AzureIoTClient 73:c4d9077dd0a1 417 }
AzureIoTClient 62:5a4cdacf5090 418 destroy_blob_upload_module(result);
AzureIoTClient 62:5a4cdacf5090 419 tickcounter_destroy(result->tickCounter);
AzureIoTClient 66:a419827cb051 420 STRING_delete(product_info);
AzureIoTClient 62:5a4cdacf5090 421 free(result);
AzureIoTClient 62:5a4cdacf5090 422 result = NULL;
AzureIoTClient 62:5a4cdacf5090 423 }
AzureIoTClient 66:a419827cb051 424 else
AzureIoTClient 66:a419827cb051 425 {
AzureIoTClient 66:a419827cb051 426 /*Codes_SRS_IOTHUBCLIENT_LL_02_042: [ By default, messages shall not timeout. ]*/
AzureIoTClient 66:a419827cb051 427 result->currentMessageTimeout = 0;
AzureIoTClient 66:a419827cb051 428 result->current_device_twin_timeout = 0;
AzureIoTClient 77:e4e36df9caee 429
AzureIoTClient 77:e4e36df9caee 430 result->diagnostic_setting.currentMessageNumber = 0;
AzureIoTClient 77:e4e36df9caee 431 result->diagnostic_setting.diagSamplingPercentage = 0;
AzureIoTClient 66:a419827cb051 432 /*Codes_SRS_IOTHUBCLIENT_LL_25_124: [ `IoTHubClient_LL_Create` shall set the default retry policy as Exponential backoff with jitter and if succeed and return a `non-NULL` handle. ]*/
AzureIoTClient 66:a419827cb051 433 if (IoTHubClient_LL_SetRetryPolicy(result, IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER, 0) != IOTHUB_CLIENT_OK)
AzureIoTClient 66:a419827cb051 434 {
AzureIoTClient 66:a419827cb051 435 LogError("Setting default retry policy in transport failed");
AzureIoTClient 66:a419827cb051 436 result->IoTHubTransport_Unregister(result->deviceHandle);
AzureIoTClient 66:a419827cb051 437 IoTHubClient_Auth_Destroy(result->authorization_module);
AzureIoTClient 73:c4d9077dd0a1 438 // Codes_SRS_IOTHUBCLIENT_LL_09_010: [ If any failure occurs `IoTHubClient_LL_Create` shall destroy the `transportHandle` only if it has created it ]
AzureIoTClient 73:c4d9077dd0a1 439 if (!result->isSharedTransport)
AzureIoTClient 73:c4d9077dd0a1 440 {
AzureIoTClient 73:c4d9077dd0a1 441 result->IoTHubTransport_Destroy(result->transportHandle);
AzureIoTClient 73:c4d9077dd0a1 442 }
AzureIoTClient 66:a419827cb051 443 destroy_blob_upload_module(result);
AzureIoTClient 66:a419827cb051 444 tickcounter_destroy(result->tickCounter);
AzureIoTClient 66:a419827cb051 445 STRING_delete(product_info);
AzureIoTClient 66:a419827cb051 446 free(result);
AzureIoTClient 66:a419827cb051 447 result = NULL;
AzureIoTClient 66:a419827cb051 448 }
AzureIoTClient 66:a419827cb051 449 }
AzureIoTClient 62:5a4cdacf5090 450 }
AzureIoTClient 62:5a4cdacf5090 451 }
AzureIoTClient 62:5a4cdacf5090 452 }
AzureIoTClient 66:a419827cb051 453 if (IoTHubName)
AzureIoTClient 66:a419827cb051 454 {
AzureIoTClient 66:a419827cb051 455 free(IoTHubName);
AzureIoTClient 66:a419827cb051 456 }
AzureIoTClient 75:86205ca63a59 457 if (IoTHubSuffix)
AzureIoTClient 66:a419827cb051 458 {
AzureIoTClient 75:86205ca63a59 459 free(IoTHubSuffix);
AzureIoTClient 66:a419827cb051 460 }
AzureIoTClient 62:5a4cdacf5090 461 }
AzureIoTClient 62:5a4cdacf5090 462 }
AzureIoTClient 62:5a4cdacf5090 463 return result;
AzureIoTClient 62:5a4cdacf5090 464 }
AzureIoTClient 62:5a4cdacf5090 465
AzureIoTClient 53:1e5a1ca1f274 466 static uint32_t get_next_item_id(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData)
AzureIoTClient 53:1e5a1ca1f274 467 {
AzureIoTClient 53:1e5a1ca1f274 468 if (handleData->data_msg_id+1 >= UINT32_MAX)
AzureIoTClient 53:1e5a1ca1f274 469 {
AzureIoTClient 53:1e5a1ca1f274 470 handleData->data_msg_id = 1;
AzureIoTClient 53:1e5a1ca1f274 471 }
AzureIoTClient 53:1e5a1ca1f274 472 else
AzureIoTClient 53:1e5a1ca1f274 473 {
AzureIoTClient 53:1e5a1ca1f274 474 handleData->data_msg_id++;
AzureIoTClient 53:1e5a1ca1f274 475 }
AzureIoTClient 53:1e5a1ca1f274 476 return handleData->data_msg_id;
AzureIoTClient 53:1e5a1ca1f274 477 }
AzureIoTClient 53:1e5a1ca1f274 478
AzureIoTClient 53:1e5a1ca1f274 479 static IOTHUB_DEVICE_TWIN* dev_twin_data_create(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, uint32_t id, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback)
AzureIoTClient 53:1e5a1ca1f274 480 {
AzureIoTClient 53:1e5a1ca1f274 481 IOTHUB_DEVICE_TWIN* result = (IOTHUB_DEVICE_TWIN*)malloc(sizeof(IOTHUB_DEVICE_TWIN) );
AzureIoTClient 53:1e5a1ca1f274 482 if (result != NULL)
AzureIoTClient 53:1e5a1ca1f274 483 {
AzureIoTClient 53:1e5a1ca1f274 484 result->report_data_handle = CONSTBUFFER_Create(reportedState, size);
AzureIoTClient 53:1e5a1ca1f274 485 if (result->report_data_handle == NULL)
AzureIoTClient 53:1e5a1ca1f274 486 {
AzureIoTClient 53:1e5a1ca1f274 487 LogError("Failure allocating reported state data");
AzureIoTClient 53:1e5a1ca1f274 488 free(result);
AzureIoTClient 53:1e5a1ca1f274 489 result = NULL;
AzureIoTClient 53:1e5a1ca1f274 490 }
AzureIoTClient 53:1e5a1ca1f274 491 else if (tickcounter_get_current_ms(handleData->tickCounter, &result->ms_timesOutAfter) != 0)
AzureIoTClient 53:1e5a1ca1f274 492 {
AzureIoTClient 53:1e5a1ca1f274 493 LogError("Failure getting tickcount info");
AzureIoTClient 53:1e5a1ca1f274 494 CONSTBUFFER_Destroy(result->report_data_handle);
AzureIoTClient 53:1e5a1ca1f274 495 free(result);
AzureIoTClient 53:1e5a1ca1f274 496 result = NULL;
AzureIoTClient 53:1e5a1ca1f274 497 }
AzureIoTClient 53:1e5a1ca1f274 498 else
AzureIoTClient 53:1e5a1ca1f274 499 {
AzureIoTClient 53:1e5a1ca1f274 500 result->item_id = id;
AzureIoTClient 53:1e5a1ca1f274 501 result->ms_timesOutAfter = 0;
AzureIoTClient 53:1e5a1ca1f274 502 result->context = userContextCallback;
AzureIoTClient 53:1e5a1ca1f274 503 result->reported_state_callback = reportedStateCallback;
AzureIoTClient 75:86205ca63a59 504 result->client_handle = handleData;
AzureIoTClient 75:86205ca63a59 505 result->device_handle = handleData->deviceHandle;
AzureIoTClient 53:1e5a1ca1f274 506 }
AzureIoTClient 53:1e5a1ca1f274 507 }
AzureIoTClient 53:1e5a1ca1f274 508 else
AzureIoTClient 53:1e5a1ca1f274 509 {
AzureIoTClient 53:1e5a1ca1f274 510 LogError("Failure allocating device twin information");
AzureIoTClient 53:1e5a1ca1f274 511 }
AzureIoTClient 53:1e5a1ca1f274 512 return result;
AzureIoTClient 53:1e5a1ca1f274 513 }
AzureIoTClient 53:1e5a1ca1f274 514
AzureIoTClient 75:86205ca63a59 515 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromDeviceAuth(const char* iothub_uri, const char* device_id, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol)
AzureIoTClient 75:86205ca63a59 516 {
AzureIoTClient 75:86205ca63a59 517 IOTHUB_CLIENT_LL_HANDLE result;
AzureIoTClient 75:86205ca63a59 518 if (iothub_uri == NULL || protocol == NULL || device_id == NULL)
AzureIoTClient 75:86205ca63a59 519 {
AzureIoTClient 75:86205ca63a59 520 LogError("Input parameter is NULL: iothub_uri: %p protocol: %p device_id: %p", iothub_uri, protocol, device_id);
AzureIoTClient 75:86205ca63a59 521 result = NULL;
AzureIoTClient 75:86205ca63a59 522 }
AzureIoTClient 75:86205ca63a59 523 else
AzureIoTClient 75:86205ca63a59 524 {
AzureIoTClient 78:74a8d3068204 525 #ifdef USE_PROV_MODULE
AzureIoTClient 75:86205ca63a59 526 IOTHUB_CLIENT_CONFIG* config = (IOTHUB_CLIENT_CONFIG*)malloc(sizeof(IOTHUB_CLIENT_CONFIG));
AzureIoTClient 75:86205ca63a59 527 if (config == NULL)
AzureIoTClient 75:86205ca63a59 528 {
AzureIoTClient 75:86205ca63a59 529 /* Codes_SRS_IOTHUBCLIENT_LL_12_012: [If the allocation failed IoTHubClient_LL_CreateFromConnectionString returns NULL] */
AzureIoTClient 75:86205ca63a59 530 LogError("Malloc failed");
AzureIoTClient 75:86205ca63a59 531 result = NULL;
AzureIoTClient 75:86205ca63a59 532 }
AzureIoTClient 75:86205ca63a59 533 else
AzureIoTClient 75:86205ca63a59 534 {
AzureIoTClient 75:86205ca63a59 535 const char* iterator;
AzureIoTClient 75:86205ca63a59 536 const char* initial;
AzureIoTClient 75:86205ca63a59 537 char* iothub_name = NULL;
AzureIoTClient 75:86205ca63a59 538 char* iothub_suffix = NULL;
AzureIoTClient 75:86205ca63a59 539
AzureIoTClient 75:86205ca63a59 540 memset(config, 0, sizeof(IOTHUB_CLIENT_CONFIG) );
AzureIoTClient 75:86205ca63a59 541 config->protocol = protocol;
AzureIoTClient 75:86205ca63a59 542 config->deviceId = device_id;
AzureIoTClient 75:86205ca63a59 543
AzureIoTClient 75:86205ca63a59 544 // Find the iothub suffix
AzureIoTClient 75:86205ca63a59 545 initial = iterator = iothub_uri;
AzureIoTClient 75:86205ca63a59 546 while (iterator != NULL && *iterator != '\0')
AzureIoTClient 75:86205ca63a59 547 {
AzureIoTClient 75:86205ca63a59 548 if (*iterator == '.')
AzureIoTClient 75:86205ca63a59 549 {
AzureIoTClient 75:86205ca63a59 550 size_t length = iterator-initial;
AzureIoTClient 75:86205ca63a59 551 iothub_name = (char*)malloc(length+1);
AzureIoTClient 75:86205ca63a59 552 if (iothub_name != NULL)
AzureIoTClient 75:86205ca63a59 553 {
AzureIoTClient 75:86205ca63a59 554 memset(iothub_name, 0, length + 1);
AzureIoTClient 75:86205ca63a59 555 memcpy(iothub_name, initial, length);
AzureIoTClient 75:86205ca63a59 556 config->iotHubName = iothub_name;
AzureIoTClient 75:86205ca63a59 557
AzureIoTClient 75:86205ca63a59 558 length = strlen(initial)-length-1;
AzureIoTClient 75:86205ca63a59 559 iothub_suffix = (char*)malloc(length + 1);
AzureIoTClient 75:86205ca63a59 560 if (iothub_suffix != NULL)
AzureIoTClient 75:86205ca63a59 561 {
AzureIoTClient 75:86205ca63a59 562 memset(iothub_suffix, 0, length + 1);
AzureIoTClient 75:86205ca63a59 563 memcpy(iothub_suffix, iterator+1, length);
AzureIoTClient 75:86205ca63a59 564 config->iotHubSuffix = iothub_suffix;
AzureIoTClient 75:86205ca63a59 565 break;
AzureIoTClient 75:86205ca63a59 566 }
AzureIoTClient 75:86205ca63a59 567 else
AzureIoTClient 75:86205ca63a59 568 {
AzureIoTClient 75:86205ca63a59 569 LogError("Failed to allocate iothub suffix");
AzureIoTClient 75:86205ca63a59 570 free(iothub_name);
AzureIoTClient 80:db5f5237bc95 571 iothub_name = NULL;
AzureIoTClient 75:86205ca63a59 572 result = NULL;
AzureIoTClient 75:86205ca63a59 573 }
AzureIoTClient 75:86205ca63a59 574 }
AzureIoTClient 75:86205ca63a59 575 else
AzureIoTClient 75:86205ca63a59 576 {
AzureIoTClient 75:86205ca63a59 577 LogError("Failed to allocate iothub name");
AzureIoTClient 75:86205ca63a59 578 result = NULL;
AzureIoTClient 75:86205ca63a59 579 }
AzureIoTClient 75:86205ca63a59 580 }
AzureIoTClient 75:86205ca63a59 581 iterator++;
AzureIoTClient 75:86205ca63a59 582 }
AzureIoTClient 75:86205ca63a59 583
AzureIoTClient 75:86205ca63a59 584 if (config->iotHubName == NULL || config->iotHubSuffix == NULL)
AzureIoTClient 75:86205ca63a59 585 {
AzureIoTClient 75:86205ca63a59 586 LogError("initialize iothub client");
AzureIoTClient 75:86205ca63a59 587 result = NULL;
AzureIoTClient 75:86205ca63a59 588 }
AzureIoTClient 75:86205ca63a59 589 else
AzureIoTClient 75:86205ca63a59 590 {
AzureIoTClient 75:86205ca63a59 591 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = initialize_iothub_client(config, NULL, true);
AzureIoTClient 75:86205ca63a59 592 if (handleData == NULL)
AzureIoTClient 75:86205ca63a59 593 {
AzureIoTClient 75:86205ca63a59 594 LogError("initialize iothub client");
AzureIoTClient 75:86205ca63a59 595 result = NULL;
AzureIoTClient 75:86205ca63a59 596 }
AzureIoTClient 75:86205ca63a59 597 else
AzureIoTClient 75:86205ca63a59 598 {
AzureIoTClient 75:86205ca63a59 599 result = handleData;
AzureIoTClient 75:86205ca63a59 600 }
AzureIoTClient 75:86205ca63a59 601 }
AzureIoTClient 75:86205ca63a59 602
AzureIoTClient 75:86205ca63a59 603 free(iothub_name);
AzureIoTClient 75:86205ca63a59 604 free(iothub_suffix);
AzureIoTClient 75:86205ca63a59 605 free(config);
AzureIoTClient 75:86205ca63a59 606 }
AzureIoTClient 75:86205ca63a59 607 #else
AzureIoTClient 78:74a8d3068204 608 LogError("HSM module is not included");
AzureIoTClient 75:86205ca63a59 609 result = NULL;
AzureIoTClient 75:86205ca63a59 610 #endif
AzureIoTClient 75:86205ca63a59 611 }
AzureIoTClient 75:86205ca63a59 612 return result;
AzureIoTClient 75:86205ca63a59 613 }
AzureIoTClient 75:86205ca63a59 614
AzureIoTClient 16:deba40344375 615 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol)
AzureIoTClient 16:deba40344375 616 {
AzureIoTClient 53:1e5a1ca1f274 617 IOTHUB_CLIENT_LL_HANDLE result;
AzureIoTClient 16:deba40344375 618
AzureIoTClient 42:448eecc3676e 619 /*Codes_SRS_IOTHUBCLIENT_LL_05_001: [IoTHubClient_LL_CreateFromConnectionString shall obtain the version string by a call to IoTHubClient_GetVersionString.]*/
AzureIoTClient 42:448eecc3676e 620 /*Codes_SRS_IOTHUBCLIENT_LL_05_002: [IoTHubClient_LL_CreateFromConnectionString shall print the version string to standard output.]*/
AzureIoTClient 42:448eecc3676e 621 LogInfo("IoT Hub SDK for C, version %s", IoTHubClient_GetVersionString());
AzureIoTClient 16:deba40344375 622
AzureIoTClient 42:448eecc3676e 623 /* 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 624 if (connectionString == NULL)
AzureIoTClient 42:448eecc3676e 625 {
AzureIoTClient 42:448eecc3676e 626 LogError("Input parameter is NULL: connectionString");
AzureIoTClient 53:1e5a1ca1f274 627 result = NULL;
AzureIoTClient 42:448eecc3676e 628 }
AzureIoTClient 42:448eecc3676e 629 else if (protocol == NULL)
AzureIoTClient 42:448eecc3676e 630 {
AzureIoTClient 42:448eecc3676e 631 LogError("Input parameter is NULL: protocol");
AzureIoTClient 53:1e5a1ca1f274 632 result = NULL;
AzureIoTClient 42:448eecc3676e 633 }
AzureIoTClient 42:448eecc3676e 634 else
AzureIoTClient 42:448eecc3676e 635 {
AzureIoTClient 42:448eecc3676e 636 /* Codes_SRS_IOTHUBCLIENT_LL_12_004: [IoTHubClient_LL_CreateFromConnectionString shall allocate IOTHUB_CLIENT_CONFIG structure] */
AzureIoTClient 53:1e5a1ca1f274 637 IOTHUB_CLIENT_CONFIG* config = (IOTHUB_CLIENT_CONFIG*) malloc(sizeof(IOTHUB_CLIENT_CONFIG));
AzureIoTClient 42:448eecc3676e 638 if (config == NULL)
AzureIoTClient 42:448eecc3676e 639 {
AzureIoTClient 42:448eecc3676e 640 /* Codes_SRS_IOTHUBCLIENT_LL_12_012: [If the allocation failed IoTHubClient_LL_CreateFromConnectionString returns NULL] */
AzureIoTClient 42:448eecc3676e 641 LogError("Malloc failed");
AzureIoTClient 53:1e5a1ca1f274 642 result = NULL;
AzureIoTClient 42:448eecc3676e 643 }
AzureIoTClient 42:448eecc3676e 644 else
AzureIoTClient 42:448eecc3676e 645 {
AzureIoTClient 42:448eecc3676e 646 STRING_TOKENIZER_HANDLE tokenizer1 = NULL;
AzureIoTClient 42:448eecc3676e 647 STRING_HANDLE connString = NULL;
AzureIoTClient 42:448eecc3676e 648 STRING_HANDLE tokenString = NULL;
AzureIoTClient 42:448eecc3676e 649 STRING_HANDLE valueString = NULL;
AzureIoTClient 42:448eecc3676e 650 STRING_HANDLE hostNameString = NULL;
AzureIoTClient 42:448eecc3676e 651 STRING_HANDLE hostSuffixString = NULL;
AzureIoTClient 42:448eecc3676e 652 STRING_HANDLE deviceIdString = NULL;
AzureIoTClient 42:448eecc3676e 653 STRING_HANDLE deviceKeyString = NULL;
AzureIoTClient 42:448eecc3676e 654 STRING_HANDLE deviceSasTokenString = NULL;
AzureIoTClient 42:448eecc3676e 655 STRING_HANDLE protocolGateway = NULL;
AzureIoTClient 16:deba40344375 656
AzureIoTClient 42:448eecc3676e 657 config->protocol = protocol;
AzureIoTClient 16:deba40344375 658
AzureIoTClient 42:448eecc3676e 659 config->iotHubName = NULL;
AzureIoTClient 42:448eecc3676e 660 config->iotHubSuffix = NULL;
AzureIoTClient 42:448eecc3676e 661 config->deviceId = NULL;
AzureIoTClient 42:448eecc3676e 662 config->deviceKey = NULL;
AzureIoTClient 42:448eecc3676e 663 config->deviceSasToken = NULL;
AzureIoTClient 40:1a94db9139ea 664
AzureIoTClient 42:448eecc3676e 665 /* Codes_SRS_IOTHUBCLIENT_LL_04_002: [If it does not, it shall pass the protocolGatewayHostName NULL.] */
AzureIoTClient 42:448eecc3676e 666 config->protocolGatewayHostName = NULL;
AzureIoTClient 16:deba40344375 667
AzureIoTClient 42:448eecc3676e 668 if ((connString = STRING_construct(connectionString)) == NULL)
AzureIoTClient 42:448eecc3676e 669 {
AzureIoTClient 42:448eecc3676e 670 LogError("Error constructing connectiong String");
AzureIoTClient 53:1e5a1ca1f274 671 result = NULL;
AzureIoTClient 42:448eecc3676e 672 }
AzureIoTClient 42:448eecc3676e 673 else if ((tokenizer1 = STRING_TOKENIZER_create(connString)) == NULL)
AzureIoTClient 42:448eecc3676e 674 {
AzureIoTClient 42:448eecc3676e 675 LogError("Error creating Tokenizer");
AzureIoTClient 53:1e5a1ca1f274 676 result = NULL;
AzureIoTClient 42:448eecc3676e 677 }
AzureIoTClient 42:448eecc3676e 678 else if ((tokenString = STRING_new()) == NULL)
AzureIoTClient 42:448eecc3676e 679 {
AzureIoTClient 42:448eecc3676e 680 LogError("Error creating Token String");
AzureIoTClient 53:1e5a1ca1f274 681 result = NULL;
AzureIoTClient 42:448eecc3676e 682 }
AzureIoTClient 42:448eecc3676e 683 else if ((valueString = STRING_new()) == NULL)
AzureIoTClient 42:448eecc3676e 684 {
AzureIoTClient 42:448eecc3676e 685 LogError("Error creating Value String");
AzureIoTClient 53:1e5a1ca1f274 686 result = NULL;
AzureIoTClient 42:448eecc3676e 687 }
AzureIoTClient 42:448eecc3676e 688 else if ((hostNameString = STRING_new()) == NULL)
AzureIoTClient 42:448eecc3676e 689 {
AzureIoTClient 42:448eecc3676e 690 LogError("Error creating HostName String");
AzureIoTClient 53:1e5a1ca1f274 691 result = NULL;
AzureIoTClient 42:448eecc3676e 692 }
AzureIoTClient 42:448eecc3676e 693 else if ((hostSuffixString = STRING_new()) == NULL)
AzureIoTClient 42:448eecc3676e 694 {
AzureIoTClient 42:448eecc3676e 695 LogError("Error creating HostSuffix String");
AzureIoTClient 53:1e5a1ca1f274 696 result = NULL;
AzureIoTClient 42:448eecc3676e 697 }
AzureIoTClient 42:448eecc3676e 698 /* 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 699 /* 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 700 else
AzureIoTClient 42:448eecc3676e 701 {
Azure.IoT Build 45:54c11b1b1407 702 int isx509found = 0;
AzureIoTClient 80:db5f5237bc95 703 bool use_provisioning = false;
AzureIoTClient 42:448eecc3676e 704 while ((STRING_TOKENIZER_get_next_token(tokenizer1, tokenString, "=") == 0))
AzureIoTClient 42:448eecc3676e 705 {
AzureIoTClient 42:448eecc3676e 706 if (STRING_TOKENIZER_get_next_token(tokenizer1, valueString, ";") != 0)
AzureIoTClient 42:448eecc3676e 707 {
AzureIoTClient 42:448eecc3676e 708 LogError("Tokenizer error");
AzureIoTClient 42:448eecc3676e 709 break;
AzureIoTClient 42:448eecc3676e 710 }
AzureIoTClient 42:448eecc3676e 711 else
AzureIoTClient 42:448eecc3676e 712 {
AzureIoTClient 42:448eecc3676e 713 if (tokenString != NULL)
AzureIoTClient 42:448eecc3676e 714 {
AzureIoTClient 42:448eecc3676e 715 /* 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 716 const char* s_token = STRING_c_str(tokenString);
AzureIoTClient 42:448eecc3676e 717 if (strcmp(s_token, HOSTNAME_TOKEN) == 0)
AzureIoTClient 42:448eecc3676e 718 {
AzureIoTClient 42:448eecc3676e 719 /* 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 720 STRING_TOKENIZER_HANDLE tokenizer2 = NULL;
AzureIoTClient 42:448eecc3676e 721 if ((tokenizer2 = STRING_TOKENIZER_create(valueString)) == NULL)
AzureIoTClient 42:448eecc3676e 722 {
AzureIoTClient 42:448eecc3676e 723 LogError("Error creating Tokenizer");
AzureIoTClient 42:448eecc3676e 724 break;
AzureIoTClient 42:448eecc3676e 725 }
AzureIoTClient 42:448eecc3676e 726 else
AzureIoTClient 42:448eecc3676e 727 {
AzureIoTClient 42:448eecc3676e 728 /* Codes_SRS_IOTHUBCLIENT_LL_12_015: [If the string split failed, IoTHubClient_LL_CreateFromConnectionString returns NULL ] */
AzureIoTClient 42:448eecc3676e 729 if (STRING_TOKENIZER_get_next_token(tokenizer2, hostNameString, ".") != 0)
AzureIoTClient 42:448eecc3676e 730 {
AzureIoTClient 42:448eecc3676e 731 LogError("Tokenizer error");
AzureIoTClient 42:448eecc3676e 732 STRING_TOKENIZER_destroy(tokenizer2);
AzureIoTClient 42:448eecc3676e 733 break;
AzureIoTClient 42:448eecc3676e 734 }
AzureIoTClient 42:448eecc3676e 735 else
AzureIoTClient 42:448eecc3676e 736 {
AzureIoTClient 42:448eecc3676e 737 config->iotHubName = STRING_c_str(hostNameString);
AzureIoTClient 42:448eecc3676e 738 if (STRING_TOKENIZER_get_next_token(tokenizer2, hostSuffixString, ";") != 0)
AzureIoTClient 42:448eecc3676e 739 {
AzureIoTClient 42:448eecc3676e 740 LogError("Tokenizer error");
AzureIoTClient 42:448eecc3676e 741 STRING_TOKENIZER_destroy(tokenizer2);
AzureIoTClient 42:448eecc3676e 742 break;
AzureIoTClient 42:448eecc3676e 743 }
AzureIoTClient 42:448eecc3676e 744 else
AzureIoTClient 42:448eecc3676e 745 {
AzureIoTClient 42:448eecc3676e 746 config->iotHubSuffix = STRING_c_str(hostSuffixString);
AzureIoTClient 42:448eecc3676e 747 }
AzureIoTClient 42:448eecc3676e 748 }
AzureIoTClient 42:448eecc3676e 749 STRING_TOKENIZER_destroy(tokenizer2);
AzureIoTClient 42:448eecc3676e 750 }
AzureIoTClient 42:448eecc3676e 751 }
AzureIoTClient 42:448eecc3676e 752 else if (strcmp(s_token, DEVICEID_TOKEN) == 0)
AzureIoTClient 42:448eecc3676e 753 {
AzureIoTClient 42:448eecc3676e 754 deviceIdString = STRING_clone(valueString);
AzureIoTClient 42:448eecc3676e 755 if (deviceIdString != NULL)
AzureIoTClient 42:448eecc3676e 756 {
AzureIoTClient 42:448eecc3676e 757 config->deviceId = STRING_c_str(deviceIdString);
AzureIoTClient 42:448eecc3676e 758 }
AzureIoTClient 53:1e5a1ca1f274 759 else
AzureIoTClient 53:1e5a1ca1f274 760 {
AzureIoTClient 53:1e5a1ca1f274 761 LogError("Failure cloning device id string");
AzureIoTClient 53:1e5a1ca1f274 762 break;
AzureIoTClient 53:1e5a1ca1f274 763 }
AzureIoTClient 42:448eecc3676e 764 }
AzureIoTClient 42:448eecc3676e 765 else if (strcmp(s_token, DEVICEKEY_TOKEN) == 0)
AzureIoTClient 42:448eecc3676e 766 {
AzureIoTClient 42:448eecc3676e 767 deviceKeyString = STRING_clone(valueString);
AzureIoTClient 42:448eecc3676e 768 if (deviceKeyString != NULL)
AzureIoTClient 42:448eecc3676e 769 {
AzureIoTClient 42:448eecc3676e 770 config->deviceKey = STRING_c_str(deviceKeyString);
AzureIoTClient 42:448eecc3676e 771 }
AzureIoTClient 53:1e5a1ca1f274 772 else
AzureIoTClient 53:1e5a1ca1f274 773 {
AzureIoTClient 53:1e5a1ca1f274 774 LogError("Failure cloning device key string");
AzureIoTClient 53:1e5a1ca1f274 775 break;
AzureIoTClient 53:1e5a1ca1f274 776 }
AzureIoTClient 42:448eecc3676e 777 }
AzureIoTClient 42:448eecc3676e 778 else if (strcmp(s_token, DEVICESAS_TOKEN) == 0)
AzureIoTClient 42:448eecc3676e 779 {
AzureIoTClient 42:448eecc3676e 780 deviceSasTokenString = STRING_clone(valueString);
AzureIoTClient 42:448eecc3676e 781 if (deviceSasTokenString != NULL)
AzureIoTClient 42:448eecc3676e 782 {
AzureIoTClient 42:448eecc3676e 783 config->deviceSasToken = STRING_c_str(deviceSasTokenString);
AzureIoTClient 42:448eecc3676e 784 }
AzureIoTClient 53:1e5a1ca1f274 785 else
AzureIoTClient 53:1e5a1ca1f274 786 {
AzureIoTClient 53:1e5a1ca1f274 787 LogError("Failure cloning device sasToken string");
AzureIoTClient 53:1e5a1ca1f274 788 break;
AzureIoTClient 53:1e5a1ca1f274 789 }
AzureIoTClient 42:448eecc3676e 790 }
Azure.IoT Build 45:54c11b1b1407 791 else if (strcmp(s_token, X509_TOKEN) == 0)
Azure.IoT Build 45:54c11b1b1407 792 {
Azure.IoT Build 45:54c11b1b1407 793 if (strcmp(STRING_c_str(valueString), X509_TOKEN_ONLY_ACCEPTABLE_VALUE) != 0)
Azure.IoT Build 45:54c11b1b1407 794 {
Azure.IoT Build 45:54c11b1b1407 795 LogError("x509 option has wrong value, the only acceptable one is \"true\"");
AzureIoTClient 53:1e5a1ca1f274 796 break;
Azure.IoT Build 45:54c11b1b1407 797 }
Azure.IoT Build 45:54c11b1b1407 798 else
Azure.IoT Build 45:54c11b1b1407 799 {
Azure.IoT Build 45:54c11b1b1407 800 isx509found = 1;
Azure.IoT Build 45:54c11b1b1407 801 }
Azure.IoT Build 45:54c11b1b1407 802 }
AzureIoTClient 80:db5f5237bc95 803 else if (strcmp(s_token, PROVISIONING_TOKEN) == 0)
AzureIoTClient 80:db5f5237bc95 804 {
AzureIoTClient 80:db5f5237bc95 805 if (strcmp(STRING_c_str(valueString), PROVISIONING_ACCEPTABLE_VALUE) != 0)
AzureIoTClient 80:db5f5237bc95 806 {
AzureIoTClient 80:db5f5237bc95 807 LogError("provisioning option has wrong value, the only acceptable one is \"true\"");
AzureIoTClient 80:db5f5237bc95 808 break;
AzureIoTClient 80:db5f5237bc95 809 }
AzureIoTClient 80:db5f5237bc95 810 else
AzureIoTClient 80:db5f5237bc95 811 {
AzureIoTClient 80:db5f5237bc95 812 use_provisioning = 1;
AzureIoTClient 80:db5f5237bc95 813 }
AzureIoTClient 80:db5f5237bc95 814 }
AzureIoTClient 80:db5f5237bc95 815
AzureIoTClient 42:448eecc3676e 816 /* 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 817 else if (strcmp(s_token, PROTOCOL_GATEWAY_HOST) == 0)
AzureIoTClient 42:448eecc3676e 818 {
AzureIoTClient 42:448eecc3676e 819 protocolGateway = STRING_clone(valueString);
AzureIoTClient 42:448eecc3676e 820 if (protocolGateway != NULL)
AzureIoTClient 42:448eecc3676e 821 {
AzureIoTClient 42:448eecc3676e 822 config->protocolGatewayHostName = STRING_c_str(protocolGateway);
AzureIoTClient 42:448eecc3676e 823 }
AzureIoTClient 53:1e5a1ca1f274 824 else
AzureIoTClient 53:1e5a1ca1f274 825 {
AzureIoTClient 53:1e5a1ca1f274 826 LogError("Failure cloning protocol Gateway Name");
AzureIoTClient 53:1e5a1ca1f274 827 break;
AzureIoTClient 53:1e5a1ca1f274 828 }
AzureIoTClient 42:448eecc3676e 829 }
AzureIoTClient 42:448eecc3676e 830 }
AzureIoTClient 42:448eecc3676e 831 }
AzureIoTClient 42:448eecc3676e 832 }
AzureIoTClient 42:448eecc3676e 833 /* parsing is done - check the result */
AzureIoTClient 42:448eecc3676e 834 if (config->iotHubName == NULL)
AzureIoTClient 42:448eecc3676e 835 {
AzureIoTClient 42:448eecc3676e 836 LogError("iotHubName is not found");
AzureIoTClient 53:1e5a1ca1f274 837 result = NULL;
AzureIoTClient 42:448eecc3676e 838 }
AzureIoTClient 42:448eecc3676e 839 else if (config->iotHubSuffix == NULL)
AzureIoTClient 42:448eecc3676e 840 {
AzureIoTClient 42:448eecc3676e 841 LogError("iotHubSuffix is not found");
AzureIoTClient 53:1e5a1ca1f274 842 result = NULL;
AzureIoTClient 42:448eecc3676e 843 }
AzureIoTClient 42:448eecc3676e 844 else if (config->deviceId == NULL)
AzureIoTClient 42:448eecc3676e 845 {
AzureIoTClient 42:448eecc3676e 846 LogError("deviceId is not found");
AzureIoTClient 53:1e5a1ca1f274 847 result = NULL;
AzureIoTClient 42:448eecc3676e 848 }
Azure.IoT Build 45:54c11b1b1407 849 else if (!(
AzureIoTClient 80:db5f5237bc95 850 ((!use_provisioning && !isx509found) && (config->deviceSasToken == NULL) ^ (config->deviceKey == NULL)) ||
AzureIoTClient 80:db5f5237bc95 851 ((use_provisioning || isx509found) && (config->deviceSasToken == NULL) && (config->deviceKey == NULL))
Azure.IoT Build 45:54c11b1b1407 852 ))
AzureIoTClient 42:448eecc3676e 853 {
AzureIoTClient 80:db5f5237bc95 854 LogError("invalid combination of x509, provisioning, deviceSasToken and deviceKey");
AzureIoTClient 53:1e5a1ca1f274 855 result = NULL;
AzureIoTClient 42:448eecc3676e 856 }
AzureIoTClient 42:448eecc3676e 857 else
AzureIoTClient 42:448eecc3676e 858 {
AzureIoTClient 42:448eecc3676e 859 /* 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 80:db5f5237bc95 860 result = initialize_iothub_client(config, NULL, use_provisioning);
AzureIoTClient 42:448eecc3676e 861 if (result == NULL)
AzureIoTClient 42:448eecc3676e 862 {
AzureIoTClient 42:448eecc3676e 863 LogError("IoTHubClient_LL_Create failed");
AzureIoTClient 42:448eecc3676e 864 }
AzureIoTClient 42:448eecc3676e 865 else
AzureIoTClient 42:448eecc3676e 866 {
AzureIoTClient 42:448eecc3676e 867 /*return as is*/
AzureIoTClient 42:448eecc3676e 868 }
AzureIoTClient 42:448eecc3676e 869 }
AzureIoTClient 42:448eecc3676e 870 }
AzureIoTClient 42:448eecc3676e 871 if (deviceSasTokenString != NULL)
AzureIoTClient 42:448eecc3676e 872 STRING_delete(deviceSasTokenString);
AzureIoTClient 42:448eecc3676e 873 if (deviceKeyString != NULL)
AzureIoTClient 42:448eecc3676e 874 STRING_delete(deviceKeyString);
AzureIoTClient 42:448eecc3676e 875 if (deviceIdString != NULL)
AzureIoTClient 42:448eecc3676e 876 STRING_delete(deviceIdString);
AzureIoTClient 42:448eecc3676e 877 if (hostSuffixString != NULL)
AzureIoTClient 42:448eecc3676e 878 STRING_delete(hostSuffixString);
AzureIoTClient 42:448eecc3676e 879 if (hostNameString != NULL)
AzureIoTClient 42:448eecc3676e 880 STRING_delete(hostNameString);
AzureIoTClient 42:448eecc3676e 881 if (valueString != NULL)
AzureIoTClient 42:448eecc3676e 882 STRING_delete(valueString);
AzureIoTClient 42:448eecc3676e 883 if (tokenString != NULL)
AzureIoTClient 42:448eecc3676e 884 STRING_delete(tokenString);
AzureIoTClient 42:448eecc3676e 885 if (connString != NULL)
AzureIoTClient 42:448eecc3676e 886 STRING_delete(connString);
AzureIoTClient 42:448eecc3676e 887 if (protocolGateway != NULL)
AzureIoTClient 42:448eecc3676e 888 STRING_delete(protocolGateway);
AzureIoTClient 16:deba40344375 889
AzureIoTClient 42:448eecc3676e 890 if (tokenizer1 != NULL)
AzureIoTClient 42:448eecc3676e 891 STRING_TOKENIZER_destroy(tokenizer1);
AzureIoTClient 16:deba40344375 892
AzureIoTClient 42:448eecc3676e 893 free(config);
AzureIoTClient 42:448eecc3676e 894 }
AzureIoTClient 42:448eecc3676e 895 }
AzureIoTClient 42:448eecc3676e 896 return result;
AzureIoTClient 16:deba40344375 897 }
AzureIoTClient 16:deba40344375 898
AzureIoTClient 16:deba40344375 899 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_Create(const IOTHUB_CLIENT_CONFIG* config)
AzureIoTClient 16:deba40344375 900 {
AzureIoTClient 42:448eecc3676e 901 IOTHUB_CLIENT_LL_HANDLE result;
AzureIoTClient 42:448eecc3676e 902 /*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 903 if(
AzureIoTClient 42:448eecc3676e 904 (config == NULL) ||
AzureIoTClient 42:448eecc3676e 905 (config->protocol == NULL)
AzureIoTClient 42:448eecc3676e 906 )
AzureIoTClient 42:448eecc3676e 907 {
AzureIoTClient 42:448eecc3676e 908 result = NULL;
AzureIoTClient 42:448eecc3676e 909 LogError("invalid configuration (NULL detected)");
AzureIoTClient 42:448eecc3676e 910 }
AzureIoTClient 42:448eecc3676e 911 else
AzureIoTClient 42:448eecc3676e 912 {
AzureIoTClient 75:86205ca63a59 913 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = initialize_iothub_client(config, NULL, false);
AzureIoTClient 42:448eecc3676e 914 if (handleData == NULL)
AzureIoTClient 42:448eecc3676e 915 {
AzureIoTClient 62:5a4cdacf5090 916 LogError("initialize iothub client");
AzureIoTClient 42:448eecc3676e 917 result = NULL;
AzureIoTClient 42:448eecc3676e 918 }
AzureIoTClient 42:448eecc3676e 919 else
AzureIoTClient 42:448eecc3676e 920 {
AzureIoTClient 62:5a4cdacf5090 921 result = handleData;
AzureIoTClient 42:448eecc3676e 922 }
AzureIoTClient 42:448eecc3676e 923 }
AzureIoTClient 16:deba40344375 924
AzureIoTClient 42:448eecc3676e 925 return result;
AzureIoTClient 16:deba40344375 926 }
AzureIoTClient 16:deba40344375 927
Azure.IoT Build 36:67300d5a4c1f 928 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateWithTransport(const IOTHUB_CLIENT_DEVICE_CONFIG * config)
Azure.IoT Build 36:67300d5a4c1f 929 {
AzureIoTClient 42:448eecc3676e 930 IOTHUB_CLIENT_LL_HANDLE result;
AzureIoTClient 42:448eecc3676e 931 /*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 932 if (
AzureIoTClient 42:448eecc3676e 933 (config == NULL) ||
AzureIoTClient 42:448eecc3676e 934 (config->protocol == NULL) ||
Azure.IoT Build 45:54c11b1b1407 935 (config->transportHandle == NULL) ||
Azure.IoT Build 45:54c11b1b1407 936 /*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 937 ((config->deviceKey == NULL) && (config->deviceSasToken == NULL))
AzureIoTClient 42:448eecc3676e 938 )
AzureIoTClient 42:448eecc3676e 939 {
AzureIoTClient 42:448eecc3676e 940 result = NULL;
AzureIoTClient 42:448eecc3676e 941 LogError("invalid configuration (NULL detected)");
AzureIoTClient 42:448eecc3676e 942 }
AzureIoTClient 42:448eecc3676e 943 else
AzureIoTClient 42:448eecc3676e 944 {
AzureIoTClient 75:86205ca63a59 945 result = initialize_iothub_client(NULL, config, false);
AzureIoTClient 42:448eecc3676e 946 }
AzureIoTClient 42:448eecc3676e 947 return result;
Azure.IoT Build 36:67300d5a4c1f 948 }
Azure.IoT Build 36:67300d5a4c1f 949
AzureIoTClient 16:deba40344375 950 void IoTHubClient_LL_Destroy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle)
AzureIoTClient 16:deba40344375 951 {
AzureIoTClient 42:448eecc3676e 952 /*Codes_SRS_IOTHUBCLIENT_LL_02_009: [IoTHubClient_LL_Destroy shall do nothing if parameter iotHubClientHandle is NULL.]*/
AzureIoTClient 42:448eecc3676e 953 if (iotHubClientHandle != NULL)
AzureIoTClient 42:448eecc3676e 954 {
AzureIoTClient 42:448eecc3676e 955 PDLIST_ENTRY unsend;
AzureIoTClient 42:448eecc3676e 956 /*Codes_SRS_IOTHUBCLIENT_LL_17_010: [IoTHubClient_LL_Destroy shall call the underlaying layer's _Unregister function] */
AzureIoTClient 42:448eecc3676e 957 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 42:448eecc3676e 958 handleData->IoTHubTransport_Unregister(handleData->deviceHandle);
AzureIoTClient 42:448eecc3676e 959 if (handleData->isSharedTransport == false)
AzureIoTClient 42:448eecc3676e 960 {
AzureIoTClient 42:448eecc3676e 961 /*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 962 handleData->IoTHubTransport_Destroy(handleData->transportHandle);
AzureIoTClient 42:448eecc3676e 963 }
AzureIoTClient 42:448eecc3676e 964 /*if any, remove the items currently not send*/
AzureIoTClient 42:448eecc3676e 965 while ((unsend = DList_RemoveHeadList(&(handleData->waitingToSend))) != &(handleData->waitingToSend))
AzureIoTClient 42:448eecc3676e 966 {
AzureIoTClient 42:448eecc3676e 967 IOTHUB_MESSAGE_LIST* temp = containingRecord(unsend, IOTHUB_MESSAGE_LIST, entry);
AzureIoTClient 42:448eecc3676e 968 /*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 969 if (temp->callback != NULL)
AzureIoTClient 42:448eecc3676e 970 {
AzureIoTClient 42:448eecc3676e 971 temp->callback(IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY, temp->context);
AzureIoTClient 42:448eecc3676e 972 }
AzureIoTClient 42:448eecc3676e 973 IoTHubMessage_Destroy(temp->messageHandle);
AzureIoTClient 42:448eecc3676e 974 free(temp);
AzureIoTClient 42:448eecc3676e 975 }
AzureIoTClient 53:1e5a1ca1f274 976
AzureIoTClient 53:1e5a1ca1f274 977 /* Codes_SRS_IOTHUBCLIENT_LL_07_007: [ IoTHubClient_LL_Destroy shall iterate the device twin queues and destroy any remaining items. ] */
AzureIoTClient 53:1e5a1ca1f274 978 while ((unsend = DList_RemoveHeadList(&(handleData->iot_msg_queue))) != &(handleData->iot_msg_queue))
AzureIoTClient 53:1e5a1ca1f274 979 {
AzureIoTClient 53:1e5a1ca1f274 980 IOTHUB_DEVICE_TWIN* temp = containingRecord(unsend, IOTHUB_DEVICE_TWIN, entry);
AzureIoTClient 53:1e5a1ca1f274 981 device_twin_data_destroy(temp);
AzureIoTClient 53:1e5a1ca1f274 982 }
AzureIoTClient 53:1e5a1ca1f274 983 while ((unsend = DList_RemoveHeadList(&(handleData->iot_ack_queue))) != &(handleData->iot_ack_queue))
AzureIoTClient 53:1e5a1ca1f274 984 {
AzureIoTClient 53:1e5a1ca1f274 985 IOTHUB_DEVICE_TWIN* temp = containingRecord(unsend, IOTHUB_DEVICE_TWIN, entry);
AzureIoTClient 53:1e5a1ca1f274 986 device_twin_data_destroy(temp);
AzureIoTClient 53:1e5a1ca1f274 987 }
AzureIoTClient 53:1e5a1ca1f274 988
AzureIoTClient 42:448eecc3676e 989 /*Codes_SRS_IOTHUBCLIENT_LL_17_011: [IoTHubClient_LL_Destroy shall free the resources allocated by IoTHubClient (if any).] */
AzureIoTClient 62:5a4cdacf5090 990 IoTHubClient_Auth_Destroy(handleData->authorization_module);
AzureIoTClient 42:448eecc3676e 991 tickcounter_destroy(handleData->tickCounter);
AzureIoTClient 44:33dd78697616 992 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 993 IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle);
AzureIoTClient 43:038d8511e817 994 #endif
AzureIoTClient 66:a419827cb051 995 STRING_delete(handleData->product_info);
AzureIoTClient 42:448eecc3676e 996 free(handleData);
AzureIoTClient 42:448eecc3676e 997 }
AzureIoTClient 16:deba40344375 998 }
AzureIoTClient 16:deba40344375 999
Azure.IoT Build 36:67300d5a4c1f 1000 /*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 1001 /*returns 0 on success, any other value is error*/
Azure.IoT Build 36:67300d5a4c1f 1002 static int attach_ms_timesOutAfter(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, IOTHUB_MESSAGE_LIST *newEntry)
Azure.IoT Build 36:67300d5a4c1f 1003 {
AzureIoTClient 42:448eecc3676e 1004 int result;
AzureIoTClient 42:448eecc3676e 1005 /*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 1006 if (handleData->currentMessageTimeout == 0)
AzureIoTClient 42:448eecc3676e 1007 {
AzureIoTClient 42:448eecc3676e 1008 newEntry->ms_timesOutAfter = 0; /*do not timeout*/
AzureIoTClient 42:448eecc3676e 1009 result = 0;
AzureIoTClient 42:448eecc3676e 1010 }
AzureIoTClient 42:448eecc3676e 1011 else
AzureIoTClient 42:448eecc3676e 1012 {
AzureIoTClient 78:74a8d3068204 1013 /*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 tickcounter_ms_t. ]*/
AzureIoTClient 42:448eecc3676e 1014 if (tickcounter_get_current_ms(handleData->tickCounter, &newEntry->ms_timesOutAfter) != 0)
AzureIoTClient 42:448eecc3676e 1015 {
AzureIoTClient 60:41648c4e7036 1016 result = __FAILURE__;
AzureIoTClient 42:448eecc3676e 1017 LogError("unable to get the current relative tickcount");
AzureIoTClient 42:448eecc3676e 1018 }
AzureIoTClient 42:448eecc3676e 1019 else
AzureIoTClient 42:448eecc3676e 1020 {
AzureIoTClient 42:448eecc3676e 1021 newEntry->ms_timesOutAfter += handleData->currentMessageTimeout;
AzureIoTClient 42:448eecc3676e 1022 result = 0;
AzureIoTClient 42:448eecc3676e 1023 }
AzureIoTClient 42:448eecc3676e 1024 }
AzureIoTClient 42:448eecc3676e 1025 return result;
Azure.IoT Build 36:67300d5a4c1f 1026 }
Azure.IoT Build 36:67300d5a4c1f 1027
AzureIoTClient 16:deba40344375 1028 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 1029 {
AzureIoTClient 42:448eecc3676e 1030 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 42:448eecc3676e 1031 /*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 1032 if (
AzureIoTClient 42:448eecc3676e 1033 (iotHubClientHandle == NULL) ||
AzureIoTClient 42:448eecc3676e 1034 (eventMessageHandle == NULL) ||
AzureIoTClient 42:448eecc3676e 1035 /*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 1036 ((eventConfirmationCallback == NULL) && (userContextCallback != NULL))
AzureIoTClient 42:448eecc3676e 1037 )
AzureIoTClient 42:448eecc3676e 1038 {
AzureIoTClient 42:448eecc3676e 1039 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 45:54c11b1b1407 1040 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 1041 }
AzureIoTClient 42:448eecc3676e 1042 else
AzureIoTClient 42:448eecc3676e 1043 {
AzureIoTClient 42:448eecc3676e 1044 IOTHUB_MESSAGE_LIST *newEntry = (IOTHUB_MESSAGE_LIST*)malloc(sizeof(IOTHUB_MESSAGE_LIST));
AzureIoTClient 42:448eecc3676e 1045 if (newEntry == NULL)
AzureIoTClient 42:448eecc3676e 1046 {
AzureIoTClient 42:448eecc3676e 1047 result = IOTHUB_CLIENT_ERROR;
Azure.IoT Build 45:54c11b1b1407 1048 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 1049 }
AzureIoTClient 42:448eecc3676e 1050 else
AzureIoTClient 42:448eecc3676e 1051 {
AzureIoTClient 42:448eecc3676e 1052 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 40:1a94db9139ea 1053
AzureIoTClient 42:448eecc3676e 1054 if (attach_ms_timesOutAfter(handleData, newEntry) != 0)
AzureIoTClient 42:448eecc3676e 1055 {
AzureIoTClient 42:448eecc3676e 1056 result = IOTHUB_CLIENT_ERROR;
Azure.IoT Build 45:54c11b1b1407 1057 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 1058 free(newEntry);
AzureIoTClient 42:448eecc3676e 1059 }
AzureIoTClient 42:448eecc3676e 1060 else
AzureIoTClient 42:448eecc3676e 1061 {
AzureIoTClient 62:5a4cdacf5090 1062 /*Codes_SRS_IOTHUBCLIENT_LL_02_013: [IoTHubClient_LL_SendEventAsync shall add the DLIST waitingToSend a new record cloning the information from eventMessageHandle, eventConfirmationCallback, userContextCallback.]*/
AzureIoTClient 42:448eecc3676e 1063 if ((newEntry->messageHandle = IoTHubMessage_Clone(eventMessageHandle)) == NULL)
AzureIoTClient 42:448eecc3676e 1064 {
AzureIoTClient 42:448eecc3676e 1065 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 42:448eecc3676e 1066 free(newEntry);
Azure.IoT Build 45:54c11b1b1407 1067 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 1068 }
AzureIoTClient 77:e4e36df9caee 1069 else if (IoTHubClient_Diagnostic_AddIfNecessary(&handleData->diagnostic_setting, newEntry->messageHandle) != 0)
AzureIoTClient 77:e4e36df9caee 1070 {
AzureIoTClient 77:e4e36df9caee 1071 /*Codes_SRS_IOTHUBCLIENT_LL_02_014: [If cloning and/or adding the information/diagnostic fails for any reason, IoTHubClient_LL_SendEventAsync shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 77:e4e36df9caee 1072 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 77:e4e36df9caee 1073 IoTHubMessage_Destroy(newEntry->messageHandle);
AzureIoTClient 77:e4e36df9caee 1074 free(newEntry);
AzureIoTClient 77:e4e36df9caee 1075 LOG_ERROR_RESULT;
AzureIoTClient 77:e4e36df9caee 1076 }
AzureIoTClient 42:448eecc3676e 1077 else
AzureIoTClient 42:448eecc3676e 1078 {
AzureIoTClient 62:5a4cdacf5090 1079 /*Codes_SRS_IOTHUBCLIENT_LL_02_013: [IoTHubClient_LL_SendEventAsync shall add the DLIST waitingToSend a new record cloning the information from eventMessageHandle, eventConfirmationCallback, userContextCallback.]*/
AzureIoTClient 42:448eecc3676e 1080 newEntry->callback = eventConfirmationCallback;
AzureIoTClient 42:448eecc3676e 1081 newEntry->context = userContextCallback;
AzureIoTClient 46:6a69294b6119 1082 DList_InsertTailList(&(iotHubClientHandle->waitingToSend), &(newEntry->entry));
AzureIoTClient 42:448eecc3676e 1083 /*Codes_SRS_IOTHUBCLIENT_LL_02_015: [Otherwise IoTHubClient_LL_SendEventAsync shall succeed and return IOTHUB_CLIENT_OK.] */
AzureIoTClient 42:448eecc3676e 1084 result = IOTHUB_CLIENT_OK;
AzureIoTClient 42:448eecc3676e 1085 }
AzureIoTClient 42:448eecc3676e 1086 }
AzureIoTClient 42:448eecc3676e 1087 }
AzureIoTClient 42:448eecc3676e 1088 }
AzureIoTClient 42:448eecc3676e 1089 return result;
AzureIoTClient 16:deba40344375 1090 }
AzureIoTClient 16:deba40344375 1091
AzureIoTClient 16:deba40344375 1092 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetMessageCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback)
AzureIoTClient 16:deba40344375 1093 {
AzureIoTClient 42:448eecc3676e 1094 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 42:448eecc3676e 1095 if (iotHubClientHandle == NULL)
AzureIoTClient 42:448eecc3676e 1096 {
AzureIoTClient 61:8b85a4e797cf 1097 /*Codes_SRS_IOTHUBCLIENT_LL_02_016: [IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.] */
AzureIoTClient 61:8b85a4e797cf 1098 LogError("Invalid argument - iotHubClientHandle is NULL");
AzureIoTClient 42:448eecc3676e 1099 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 42:448eecc3676e 1100 }
AzureIoTClient 42:448eecc3676e 1101 else
AzureIoTClient 42:448eecc3676e 1102 {
AzureIoTClient 42:448eecc3676e 1103 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 42:448eecc3676e 1104 if (messageCallback == NULL)
AzureIoTClient 42:448eecc3676e 1105 {
AzureIoTClient 62:5a4cdacf5090 1106 if (handleData->messageCallback.type == CALLBACK_TYPE_NONE)
AzureIoTClient 61:8b85a4e797cf 1107 {
AzureIoTClient 61:8b85a4e797cf 1108 /*Codes_SRS_IOTHUBCLIENT_LL_10_010: [If parameter messageCallback is NULL and the _SetMessageCallback had not been called to subscribe for messages, then IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 61:8b85a4e797cf 1109 LogError("not currently set to accept or process incoming messages.");
AzureIoTClient 61:8b85a4e797cf 1110 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 61:8b85a4e797cf 1111 }
AzureIoTClient 62:5a4cdacf5090 1112 else if (handleData->messageCallback.type == CALLBACK_TYPE_ASYNC)
AzureIoTClient 61:8b85a4e797cf 1113 {
AzureIoTClient 61:8b85a4e797cf 1114 /*Codes_SRS_IOTHUBCLIENT_LL_10_010: [If parameter messageCallback is NULL and the _SetMessageCallback had not been called to subscribe for messages, then IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 62:5a4cdacf5090 1115 LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetMessageCallback_Ex function.");
AzureIoTClient 61:8b85a4e797cf 1116 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 61:8b85a4e797cf 1117 }
AzureIoTClient 61:8b85a4e797cf 1118 else
AzureIoTClient 61:8b85a4e797cf 1119 {
AzureIoTClient 61:8b85a4e797cf 1120 /*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 61:8b85a4e797cf 1121 handleData->IoTHubTransport_Unsubscribe(handleData->deviceHandle);
AzureIoTClient 62:5a4cdacf5090 1122 handleData->messageCallback.type = CALLBACK_TYPE_NONE;
AzureIoTClient 61:8b85a4e797cf 1123 handleData->messageCallback.callbackSync = NULL;
AzureIoTClient 61:8b85a4e797cf 1124 handleData->messageCallback.callbackAsync = NULL;
AzureIoTClient 62:5a4cdacf5090 1125 handleData->messageCallback.userContextCallback = NULL;
AzureIoTClient 61:8b85a4e797cf 1126 result = IOTHUB_CLIENT_OK;
AzureIoTClient 61:8b85a4e797cf 1127 }
AzureIoTClient 42:448eecc3676e 1128 }
AzureIoTClient 42:448eecc3676e 1129 else
AzureIoTClient 42:448eecc3676e 1130 {
AzureIoTClient 62:5a4cdacf5090 1131 if (handleData->messageCallback.type == CALLBACK_TYPE_ASYNC)
AzureIoTClient 42:448eecc3676e 1132 {
AzureIoTClient 62:5a4cdacf5090 1133 /* Codes_SRS_IOTHUBCLIENT_LL_10_011: [If parameter messageCallback is non-NULL and the _SetMessageCallback_Ex had been used to susbscribe for messages, then IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 62:5a4cdacf5090 1134 LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetMessageCallback_Ex function before subscribing with MessageCallback.");
AzureIoTClient 61:8b85a4e797cf 1135 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 42:448eecc3676e 1136 }
AzureIoTClient 42:448eecc3676e 1137 else
AzureIoTClient 42:448eecc3676e 1138 {
AzureIoTClient 61:8b85a4e797cf 1139 if (handleData->IoTHubTransport_Subscribe(handleData->deviceHandle) == 0)
AzureIoTClient 61:8b85a4e797cf 1140 {
AzureIoTClient 61:8b85a4e797cf 1141 /*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 62:5a4cdacf5090 1142 handleData->messageCallback.type = CALLBACK_TYPE_SYNC;
AzureIoTClient 61:8b85a4e797cf 1143 handleData->messageCallback.callbackSync = messageCallback;
AzureIoTClient 62:5a4cdacf5090 1144 handleData->messageCallback.userContextCallback = userContextCallback;
AzureIoTClient 61:8b85a4e797cf 1145 result = IOTHUB_CLIENT_OK;
AzureIoTClient 61:8b85a4e797cf 1146 }
AzureIoTClient 61:8b85a4e797cf 1147 else
AzureIoTClient 61:8b85a4e797cf 1148 {
AzureIoTClient 61:8b85a4e797cf 1149 /*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 62:5a4cdacf5090 1150 LogError("IoTHubTransport_Subscribe failed");
AzureIoTClient 62:5a4cdacf5090 1151 handleData->messageCallback.type = CALLBACK_TYPE_NONE;
AzureIoTClient 61:8b85a4e797cf 1152 handleData->messageCallback.callbackSync = NULL;
AzureIoTClient 61:8b85a4e797cf 1153 handleData->messageCallback.callbackAsync = NULL;
AzureIoTClient 62:5a4cdacf5090 1154 handleData->messageCallback.userContextCallback = NULL;
AzureIoTClient 61:8b85a4e797cf 1155 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 61:8b85a4e797cf 1156 }
AzureIoTClient 42:448eecc3676e 1157 }
AzureIoTClient 42:448eecc3676e 1158 }
AzureIoTClient 42:448eecc3676e 1159 }
AzureIoTClient 61:8b85a4e797cf 1160 return result;
AzureIoTClient 61:8b85a4e797cf 1161 }
AzureIoTClient 40:1a94db9139ea 1162
AzureIoTClient 62:5a4cdacf5090 1163 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetMessageCallback_Ex(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC_EX messageCallback, void* userContextCallback)
AzureIoTClient 61:8b85a4e797cf 1164 {
AzureIoTClient 61:8b85a4e797cf 1165 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 61:8b85a4e797cf 1166 if (iotHubClientHandle == NULL)
AzureIoTClient 61:8b85a4e797cf 1167 {
AzureIoTClient 62:5a4cdacf5090 1168 /*Codes_SRS_IOTHUBCLIENT_LL_10_021: [IoTHubClient_LL_SetMessageCallback_Ex shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.]*/
AzureIoTClient 61:8b85a4e797cf 1169 LogError("Invalid argument - iotHubClientHandle is NULL");
AzureIoTClient 61:8b85a4e797cf 1170 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 61:8b85a4e797cf 1171 }
AzureIoTClient 61:8b85a4e797cf 1172 else
AzureIoTClient 61:8b85a4e797cf 1173 {
AzureIoTClient 61:8b85a4e797cf 1174 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 61:8b85a4e797cf 1175 if (messageCallback == NULL)
AzureIoTClient 61:8b85a4e797cf 1176 {
AzureIoTClient 62:5a4cdacf5090 1177 if (handleData->messageCallback.type == CALLBACK_TYPE_NONE)
AzureIoTClient 61:8b85a4e797cf 1178 {
AzureIoTClient 62:5a4cdacf5090 1179 /*Codes_SRS_IOTHUBCLIENT_LL_10_018: [If parameter messageCallback is NULL and IoTHubClient_LL_SetMessageCallback_Ex had not been used to subscribe for messages, then IoTHubClient_LL_SetMessageCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 61:8b85a4e797cf 1180 LogError("not currently set to accept or process incoming messages.");
AzureIoTClient 61:8b85a4e797cf 1181 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 61:8b85a4e797cf 1182 }
AzureIoTClient 62:5a4cdacf5090 1183 else if (handleData->messageCallback.type == CALLBACK_TYPE_SYNC)
AzureIoTClient 61:8b85a4e797cf 1184 {
AzureIoTClient 62:5a4cdacf5090 1185 /*Codes_SRS_IOTHUBCLIENT_LL_10_019: [If parameter messageCallback is NULL and IoTHubClient_LL_SetMessageCallback had been used to subscribe for messages, then IoTHubClient_LL_SetMessageCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 61:8b85a4e797cf 1186 LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetMessageCallback function.");
AzureIoTClient 61:8b85a4e797cf 1187 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 61:8b85a4e797cf 1188 }
AzureIoTClient 61:8b85a4e797cf 1189 else
AzureIoTClient 61:8b85a4e797cf 1190 {
AzureIoTClient 62:5a4cdacf5090 1191 /*Codes_SRS_IOTHUBCLIENT_LL_10_023: [If parameter messageCallback is NULL then IoTHubClient_LL_SetMessageCallback_Ex shall call the underlying layer's _Unsubscribe function and return IOTHUB_CLIENT_OK.] */
AzureIoTClient 61:8b85a4e797cf 1192 handleData->IoTHubTransport_Unsubscribe(handleData->deviceHandle);
AzureIoTClient 62:5a4cdacf5090 1193 handleData->messageCallback.type = CALLBACK_TYPE_NONE;
AzureIoTClient 61:8b85a4e797cf 1194 handleData->messageCallback.callbackSync = NULL;
AzureIoTClient 61:8b85a4e797cf 1195 handleData->messageCallback.callbackAsync = NULL;
AzureIoTClient 62:5a4cdacf5090 1196 handleData->messageCallback.userContextCallback = NULL;
AzureIoTClient 61:8b85a4e797cf 1197 result = IOTHUB_CLIENT_OK;
AzureIoTClient 61:8b85a4e797cf 1198 }
AzureIoTClient 61:8b85a4e797cf 1199 }
AzureIoTClient 61:8b85a4e797cf 1200 else
AzureIoTClient 61:8b85a4e797cf 1201 {
AzureIoTClient 62:5a4cdacf5090 1202 if (handleData->messageCallback.type == CALLBACK_TYPE_SYNC)
AzureIoTClient 61:8b85a4e797cf 1203 {
AzureIoTClient 62:5a4cdacf5090 1204 /*Codes_SRS_IOTHUBCLIENT_LL_10_020: [If parameter messageCallback is non-NULL, and IoTHubClient_LL_SetMessageCallback had been used to subscribe for messages, then IoTHubClient_LL_SetMessageCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 61:8b85a4e797cf 1205 LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_MessageCallbackEx function before subscribing with MessageCallback.");
AzureIoTClient 61:8b85a4e797cf 1206 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 61:8b85a4e797cf 1207 }
AzureIoTClient 61:8b85a4e797cf 1208 else
AzureIoTClient 61:8b85a4e797cf 1209 {
AzureIoTClient 61:8b85a4e797cf 1210 if (handleData->IoTHubTransport_Subscribe(handleData->deviceHandle) == 0)
AzureIoTClient 61:8b85a4e797cf 1211 {
AzureIoTClient 62:5a4cdacf5090 1212 /*Codes_SRS_IOTHUBCLIENT_LL_10_024: [If parameter messageCallback is non-NULL then IoTHubClient_LL_SetMessageCallback_Ex shall call the underlying layer's _Subscribe function.]*/
AzureIoTClient 62:5a4cdacf5090 1213 handleData->messageCallback.type = CALLBACK_TYPE_ASYNC;
AzureIoTClient 61:8b85a4e797cf 1214 handleData->messageCallback.callbackAsync = messageCallback;
AzureIoTClient 62:5a4cdacf5090 1215 handleData->messageCallback.userContextCallback = userContextCallback;
AzureIoTClient 61:8b85a4e797cf 1216 result = IOTHUB_CLIENT_OK;
AzureIoTClient 61:8b85a4e797cf 1217 }
AzureIoTClient 61:8b85a4e797cf 1218 else
AzureIoTClient 61:8b85a4e797cf 1219 {
AzureIoTClient 62:5a4cdacf5090 1220 /*Codes_SRS_IOTHUBCLIENT_LL_10_025: [If the underlying layer's _Subscribe function fails, then IoTHubClient_LL_SetMessageCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR. Otherwise IoTHubClient_LL_SetMessageCallback_Ex shall succeed and return IOTHUB_CLIENT_OK.] */
AzureIoTClient 62:5a4cdacf5090 1221 LogError("IoTHubTransport_Subscribe failed");
AzureIoTClient 62:5a4cdacf5090 1222 handleData->messageCallback.type = CALLBACK_TYPE_NONE;
AzureIoTClient 61:8b85a4e797cf 1223 handleData->messageCallback.callbackSync = NULL;
AzureIoTClient 61:8b85a4e797cf 1224 handleData->messageCallback.callbackAsync = NULL;
AzureIoTClient 62:5a4cdacf5090 1225 handleData->messageCallback.userContextCallback = NULL;
AzureIoTClient 61:8b85a4e797cf 1226 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 61:8b85a4e797cf 1227 }
AzureIoTClient 61:8b85a4e797cf 1228 }
AzureIoTClient 61:8b85a4e797cf 1229 }
AzureIoTClient 61:8b85a4e797cf 1230 }
AzureIoTClient 61:8b85a4e797cf 1231 return result;
AzureIoTClient 61:8b85a4e797cf 1232 }
AzureIoTClient 61:8b85a4e797cf 1233
AzureIoTClient 61:8b85a4e797cf 1234 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SendMessageDisposition(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, MESSAGE_CALLBACK_INFO* message_data, IOTHUBMESSAGE_DISPOSITION_RESULT disposition)
AzureIoTClient 61:8b85a4e797cf 1235 {
AzureIoTClient 61:8b85a4e797cf 1236 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 61:8b85a4e797cf 1237 if ((iotHubClientHandle == NULL) || (message_data == NULL))
AzureIoTClient 61:8b85a4e797cf 1238 {
AzureIoTClient 61:8b85a4e797cf 1239 /*Codes_SRS_IOTHUBCLIENT_LL_10_026: [IoTHubClient_LL_SendMessageDisposition shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.]*/
AzureIoTClient 61:8b85a4e797cf 1240 LogError("Invalid argument handle=%p, message=%p", iotHubClientHandle, message_data);
AzureIoTClient 61:8b85a4e797cf 1241 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 61:8b85a4e797cf 1242 }
AzureIoTClient 61:8b85a4e797cf 1243 else
AzureIoTClient 61:8b85a4e797cf 1244 {
AzureIoTClient 61:8b85a4e797cf 1245 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 61:8b85a4e797cf 1246 /*Codes_SRS_IOTHUBCLIENT_LL_10_027: [IoTHubClient_LL_SendMessageDisposition shall return the result from calling the underlying layer's _Send_Message_Disposition.]*/
AzureIoTClient 61:8b85a4e797cf 1247 result = handleData->IoTHubTransport_SendMessageDisposition(message_data, disposition);
AzureIoTClient 61:8b85a4e797cf 1248 }
AzureIoTClient 42:448eecc3676e 1249 return result;
AzureIoTClient 16:deba40344375 1250 }
AzureIoTClient 16:deba40344375 1251
Azure.IoT Build 36:67300d5a4c1f 1252 static void DoTimeouts(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData)
Azure.IoT Build 36:67300d5a4c1f 1253 {
Azure.IoT.Build 54:6dcad9019a64 1254 tickcounter_ms_t nowTick;
AzureIoTClient 42:448eecc3676e 1255 if (tickcounter_get_current_ms(handleData->tickCounter, &nowTick) != 0)
AzureIoTClient 42:448eecc3676e 1256 {
AzureIoTClient 42:448eecc3676e 1257 LogError("unable to get the current ms, timeouts will not be processed");
AzureIoTClient 42:448eecc3676e 1258 }
AzureIoTClient 42:448eecc3676e 1259 else
AzureIoTClient 42:448eecc3676e 1260 {
AzureIoTClient 42:448eecc3676e 1261 DLIST_ENTRY* currentItemInWaitingToSend = handleData->waitingToSend.Flink;
AzureIoTClient 42:448eecc3676e 1262 while (currentItemInWaitingToSend != &(handleData->waitingToSend)) /*while we are not at the end of the list*/
AzureIoTClient 42:448eecc3676e 1263 {
AzureIoTClient 42:448eecc3676e 1264 IOTHUB_MESSAGE_LIST* fullEntry = containingRecord(currentItemInWaitingToSend, IOTHUB_MESSAGE_LIST, entry);
AzureIoTClient 42:448eecc3676e 1265 /*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 1266 if ((fullEntry->ms_timesOutAfter != 0) && (fullEntry->ms_timesOutAfter < nowTick))
AzureIoTClient 42:448eecc3676e 1267 {
AzureIoTClient 42:448eecc3676e 1268 PDLIST_ENTRY theNext = currentItemInWaitingToSend->Flink; /*need to save the next item, because the below operations are destructive*/
AzureIoTClient 42:448eecc3676e 1269 DList_RemoveEntryList(currentItemInWaitingToSend);
AzureIoTClient 42:448eecc3676e 1270 if (fullEntry->callback != NULL)
AzureIoTClient 42:448eecc3676e 1271 {
AzureIoTClient 42:448eecc3676e 1272 fullEntry->callback(IOTHUB_CLIENT_CONFIRMATION_MESSAGE_TIMEOUT, fullEntry->context);
AzureIoTClient 42:448eecc3676e 1273 }
AzureIoTClient 42:448eecc3676e 1274 IoTHubMessage_Destroy(fullEntry->messageHandle); /*because it has been cloned*/
AzureIoTClient 42:448eecc3676e 1275 free(fullEntry);
AzureIoTClient 42:448eecc3676e 1276 currentItemInWaitingToSend = theNext;
AzureIoTClient 42:448eecc3676e 1277 }
AzureIoTClient 42:448eecc3676e 1278 else
AzureIoTClient 42:448eecc3676e 1279 {
AzureIoTClient 42:448eecc3676e 1280 currentItemInWaitingToSend = currentItemInWaitingToSend->Flink;
AzureIoTClient 42:448eecc3676e 1281 }
AzureIoTClient 42:448eecc3676e 1282 }
AzureIoTClient 42:448eecc3676e 1283 }
Azure.IoT Build 36:67300d5a4c1f 1284 }
Azure.IoT Build 36:67300d5a4c1f 1285
AzureIoTClient 16:deba40344375 1286 void IoTHubClient_LL_DoWork(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle)
AzureIoTClient 16:deba40344375 1287 {
AzureIoTClient 42:448eecc3676e 1288 /*Codes_SRS_IOTHUBCLIENT_LL_02_020: [If parameter iotHubClientHandle is NULL then IoTHubClient_LL_DoWork shall not perform any action.] */
AzureIoTClient 42:448eecc3676e 1289 if (iotHubClientHandle != NULL)
AzureIoTClient 42:448eecc3676e 1290 {
AzureIoTClient 42:448eecc3676e 1291 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 42:448eecc3676e 1292 DoTimeouts(handleData);
AzureIoTClient 42:448eecc3676e 1293
AzureIoTClient 53:1e5a1ca1f274 1294 /*Codes_SRS_IOTHUBCLIENT_LL_07_008: [ IoTHubClient_LL_DoWork shall iterate the message queue and execute the underlying transports IoTHubTransport_ProcessItem function for each item. ] */
AzureIoTClient 53:1e5a1ca1f274 1295 DLIST_ENTRY* client_item = handleData->iot_msg_queue.Flink;
AzureIoTClient 53:1e5a1ca1f274 1296 while (client_item != &(handleData->iot_msg_queue)) /*while we are not at the end of the list*/
AzureIoTClient 53:1e5a1ca1f274 1297 {
AzureIoTClient 53:1e5a1ca1f274 1298 PDLIST_ENTRY next_item = client_item->Flink;
AzureIoTClient 53:1e5a1ca1f274 1299
AzureIoTClient 53:1e5a1ca1f274 1300 IOTHUB_DEVICE_TWIN* queue_data = containingRecord(client_item, IOTHUB_DEVICE_TWIN, entry);
AzureIoTClient 53:1e5a1ca1f274 1301 IOTHUB_IDENTITY_INFO identity_info;
AzureIoTClient 53:1e5a1ca1f274 1302 identity_info.device_twin = queue_data;
AzureIoTClient 53:1e5a1ca1f274 1303 IOTHUB_PROCESS_ITEM_RESULT process_results = handleData->IoTHubTransport_ProcessItem(handleData->transportHandle, IOTHUB_TYPE_DEVICE_TWIN, &identity_info);
AzureIoTClient 53:1e5a1ca1f274 1304 if (process_results == IOTHUB_PROCESS_CONTINUE || process_results == IOTHUB_PROCESS_NOT_CONNECTED)
AzureIoTClient 53:1e5a1ca1f274 1305 {
AzureIoTClient 53:1e5a1ca1f274 1306 /*Codes_SRS_IOTHUBCLIENT_LL_07_010: [ If 'IoTHubTransport_ProcessItem' returns IOTHUB_PROCESS_CONTINUE or IOTHUB_PROCESS_NOT_CONNECTED IoTHubClient_LL_DoWork shall continue on to call the underlaying layer's _DoWork function. ]*/
AzureIoTClient 53:1e5a1ca1f274 1307 break;
AzureIoTClient 53:1e5a1ca1f274 1308 }
AzureIoTClient 53:1e5a1ca1f274 1309 else
AzureIoTClient 53:1e5a1ca1f274 1310 {
AzureIoTClient 53:1e5a1ca1f274 1311 DList_RemoveEntryList(client_item);
AzureIoTClient 53:1e5a1ca1f274 1312 if (process_results == IOTHUB_PROCESS_OK)
AzureIoTClient 53:1e5a1ca1f274 1313 {
AzureIoTClient 53:1e5a1ca1f274 1314 /*Codes_SRS_IOTHUBCLIENT_LL_07_011: [ If 'IoTHubTransport_ProcessItem' returns IOTHUB_PROCESS_OK IoTHubClient_LL_DoWork shall add the IOTHUB_DEVICE_TWIN to the ack queue. ]*/
AzureIoTClient 53:1e5a1ca1f274 1315 DList_InsertTailList(&(iotHubClientHandle->iot_ack_queue), &(queue_data->entry));
AzureIoTClient 53:1e5a1ca1f274 1316 }
AzureIoTClient 53:1e5a1ca1f274 1317 else
AzureIoTClient 53:1e5a1ca1f274 1318 {
AzureIoTClient 53:1e5a1ca1f274 1319 /*Codes_SRS_IOTHUBCLIENT_LL_07_012: [ If 'IoTHubTransport_ProcessItem' returns any other value IoTHubClient_LL_DoWork shall destroy the IOTHUB_DEVICE_TWIN item. ]*/
AzureIoTClient 53:1e5a1ca1f274 1320 LogError("Failure queue processing item");
AzureIoTClient 53:1e5a1ca1f274 1321 device_twin_data_destroy(queue_data);
AzureIoTClient 53:1e5a1ca1f274 1322 }
AzureIoTClient 53:1e5a1ca1f274 1323 }
AzureIoTClient 53:1e5a1ca1f274 1324 // Move along to the next item
AzureIoTClient 53:1e5a1ca1f274 1325 client_item = next_item;
AzureIoTClient 53:1e5a1ca1f274 1326 }
AzureIoTClient 53:1e5a1ca1f274 1327
AzureIoTClient 42:448eecc3676e 1328 /*Codes_SRS_IOTHUBCLIENT_LL_02_021: [Otherwise, IoTHubClient_LL_DoWork shall invoke the underlaying layer's _DoWork function.]*/
AzureIoTClient 42:448eecc3676e 1329 handleData->IoTHubTransport_DoWork(handleData->transportHandle, iotHubClientHandle);
AzureIoTClient 42:448eecc3676e 1330 }
AzureIoTClient 16:deba40344375 1331 }
AzureIoTClient 16:deba40344375 1332
AzureIoTClient 16:deba40344375 1333 IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetSendStatus(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus)
AzureIoTClient 16:deba40344375 1334 {
AzureIoTClient 42:448eecc3676e 1335 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 1336
AzureIoTClient 42:448eecc3676e 1337 /* Codes_SRS_IOTHUBCLIENT_09_007: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter] */
AzureIoTClient 42:448eecc3676e 1338 if (iotHubClientHandle == NULL || iotHubClientStatus == NULL)
AzureIoTClient 42:448eecc3676e 1339 {
AzureIoTClient 42:448eecc3676e 1340 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 45:54c11b1b1407 1341 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 1342 }
AzureIoTClient 42:448eecc3676e 1343 else
AzureIoTClient 42:448eecc3676e 1344 {
AzureIoTClient 42:448eecc3676e 1345 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 1346
AzureIoTClient 42:448eecc3676e 1347 /* 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 1348 /* 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 1349 result = handleData->IoTHubTransport_GetSendStatus(handleData->deviceHandle, iotHubClientStatus);
AzureIoTClient 42:448eecc3676e 1350 }
AzureIoTClient 16:deba40344375 1351
AzureIoTClient 42:448eecc3676e 1352 return result;
AzureIoTClient 16:deba40344375 1353 }
AzureIoTClient 16:deba40344375 1354
Azure.IoT Build 45:54c11b1b1407 1355 void IoTHubClient_LL_SendComplete(IOTHUB_CLIENT_LL_HANDLE handle, PDLIST_ENTRY completed, IOTHUB_CLIENT_CONFIRMATION_RESULT result)
AzureIoTClient 16:deba40344375 1356 {
AzureIoTClient 42:448eecc3676e 1357 /*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 1358 if (
AzureIoTClient 42:448eecc3676e 1359 (handle == NULL) ||
AzureIoTClient 42:448eecc3676e 1360 (completed == NULL)
AzureIoTClient 42:448eecc3676e 1361 )
AzureIoTClient 42:448eecc3676e 1362 {
AzureIoTClient 42:448eecc3676e 1363 /*"shall return"*/
AzureIoTClient 42:448eecc3676e 1364 LogError("invalid arg");
AzureIoTClient 42:448eecc3676e 1365 }
AzureIoTClient 42:448eecc3676e 1366 else
AzureIoTClient 42:448eecc3676e 1367 {
Azure.IoT Build 45:54c11b1b1407 1368 /*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 1369 /*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 1370 PDLIST_ENTRY oldest;
AzureIoTClient 42:448eecc3676e 1371 while ((oldest = DList_RemoveHeadList(completed)) != completed)
AzureIoTClient 42:448eecc3676e 1372 {
AzureIoTClient 42:448eecc3676e 1373 IOTHUB_MESSAGE_LIST* messageList = (IOTHUB_MESSAGE_LIST*)containingRecord(oldest, IOTHUB_MESSAGE_LIST, entry);
AzureIoTClient 42:448eecc3676e 1374 /*Codes_SRS_IOTHUBCLIENT_LL_02_026: [If any callback is NULL then there shall not be a callback call.]*/
AzureIoTClient 42:448eecc3676e 1375 if (messageList->callback != NULL)
AzureIoTClient 42:448eecc3676e 1376 {
Azure.IoT Build 45:54c11b1b1407 1377 messageList->callback(result, messageList->context);
AzureIoTClient 42:448eecc3676e 1378 }
AzureIoTClient 42:448eecc3676e 1379 IoTHubMessage_Destroy(messageList->messageHandle);
AzureIoTClient 42:448eecc3676e 1380 free(messageList);
AzureIoTClient 42:448eecc3676e 1381 }
AzureIoTClient 42:448eecc3676e 1382 }
AzureIoTClient 16:deba40344375 1383 }
AzureIoTClient 16:deba40344375 1384
AzureIoTClient 55:59b527ab3452 1385 int IoTHubClient_LL_DeviceMethodComplete(IOTHUB_CLIENT_LL_HANDLE handle, const char* method_name, const unsigned char* payLoad, size_t size, METHOD_HANDLE response_id)
AzureIoTClient 53:1e5a1ca1f274 1386 {
AzureIoTClient 53:1e5a1ca1f274 1387 int result;
AzureIoTClient 55:59b527ab3452 1388 if (handle == NULL)
AzureIoTClient 53:1e5a1ca1f274 1389 {
AzureIoTClient 53:1e5a1ca1f274 1390 /* Codes_SRS_IOTHUBCLIENT_LL_07_017: [ If handle or response is NULL then IoTHubClient_LL_DeviceMethodComplete shall return 500. ] */
AzureIoTClient 53:1e5a1ca1f274 1391 LogError("Invalid argument handle=%p", handle);
AzureIoTClient 60:41648c4e7036 1392 result = __FAILURE__;
AzureIoTClient 53:1e5a1ca1f274 1393 }
AzureIoTClient 53:1e5a1ca1f274 1394 else
AzureIoTClient 53:1e5a1ca1f274 1395 {
AzureIoTClient 53:1e5a1ca1f274 1396 /* Codes_SRS_IOTHUBCLIENT_LL_07_018: [ If deviceMethodCallback is not NULL IoTHubClient_LL_DeviceMethodComplete shall execute deviceMethodCallback and return the status. ] */
AzureIoTClient 53:1e5a1ca1f274 1397 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
AzureIoTClient 62:5a4cdacf5090 1398 switch (handleData->methodCallback.type)
AzureIoTClient 53:1e5a1ca1f274 1399 {
AzureIoTClient 62:5a4cdacf5090 1400 case CALLBACK_TYPE_SYNC:
AzureIoTClient 53:1e5a1ca1f274 1401 {
AzureIoTClient 62:5a4cdacf5090 1402 unsigned char* payload_resp = NULL;
AzureIoTClient 62:5a4cdacf5090 1403 size_t response_size = 0;
AzureIoTClient 62:5a4cdacf5090 1404 result = handleData->methodCallback.callbackSync(method_name, payLoad, size, &payload_resp, &response_size, handleData->methodCallback.userContextCallback);
AzureIoTClient 62:5a4cdacf5090 1405 /* Codes_SRS_IOTHUBCLIENT_LL_07_020: [ deviceMethodCallback shall build the BUFFER_HANDLE with the response payload from the IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC callback. ] */
AzureIoTClient 62:5a4cdacf5090 1406 if (payload_resp != NULL && response_size > 0)
AzureIoTClient 62:5a4cdacf5090 1407 {
AzureIoTClient 62:5a4cdacf5090 1408 result = handleData->IoTHubTransport_DeviceMethod_Response(handleData->deviceHandle, response_id, payload_resp, response_size, result);
AzureIoTClient 62:5a4cdacf5090 1409 }
AzureIoTClient 62:5a4cdacf5090 1410 else
AzureIoTClient 62:5a4cdacf5090 1411 {
AzureIoTClient 62:5a4cdacf5090 1412 result = __FAILURE__;
AzureIoTClient 62:5a4cdacf5090 1413 }
AzureIoTClient 62:5a4cdacf5090 1414 if (payload_resp != NULL)
AzureIoTClient 62:5a4cdacf5090 1415 {
AzureIoTClient 62:5a4cdacf5090 1416 free(payload_resp);
AzureIoTClient 62:5a4cdacf5090 1417 }
AzureIoTClient 62:5a4cdacf5090 1418 break;
AzureIoTClient 53:1e5a1ca1f274 1419 }
AzureIoTClient 62:5a4cdacf5090 1420 case CALLBACK_TYPE_ASYNC:
AzureIoTClient 62:5a4cdacf5090 1421 result = handleData->methodCallback.callbackAsync(method_name, payLoad, size, response_id, handleData->methodCallback.userContextCallback);
AzureIoTClient 62:5a4cdacf5090 1422 break;
AzureIoTClient 62:5a4cdacf5090 1423 default:
AzureIoTClient 62:5a4cdacf5090 1424 /* Codes_SRS_IOTHUBCLIENT_LL_07_019: [ If deviceMethodCallback is NULL IoTHubClient_LL_DeviceMethodComplete shall return 404. ] */
AzureIoTClient 62:5a4cdacf5090 1425 result = 0;
AzureIoTClient 62:5a4cdacf5090 1426 break;
AzureIoTClient 53:1e5a1ca1f274 1427 }
AzureIoTClient 53:1e5a1ca1f274 1428 }
AzureIoTClient 53:1e5a1ca1f274 1429 return result;
AzureIoTClient 53:1e5a1ca1f274 1430 }
AzureIoTClient 53:1e5a1ca1f274 1431
AzureIoTClient 53:1e5a1ca1f274 1432 void IoTHubClient_LL_RetrievePropertyComplete(IOTHUB_CLIENT_LL_HANDLE handle, DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size)
AzureIoTClient 53:1e5a1ca1f274 1433 {
AzureIoTClient 53:1e5a1ca1f274 1434 if (handle == NULL)
AzureIoTClient 53:1e5a1ca1f274 1435 {
AzureIoTClient 53:1e5a1ca1f274 1436 /* Codes_SRS_IOTHUBCLIENT_LL_07_013: [ If handle is NULL then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */
AzureIoTClient 53:1e5a1ca1f274 1437 LogError("Invalid argument handle=%p", handle);
AzureIoTClient 53:1e5a1ca1f274 1438 }
AzureIoTClient 53:1e5a1ca1f274 1439 else
AzureIoTClient 53:1e5a1ca1f274 1440 {
AzureIoTClient 53:1e5a1ca1f274 1441 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
AzureIoTClient 53:1e5a1ca1f274 1442 /* Codes_SRS_IOTHUBCLIENT_LL_07_014: [ If deviceTwinCallback is NULL then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */
AzureIoTClient 53:1e5a1ca1f274 1443 if (handleData->deviceTwinCallback)
AzureIoTClient 53:1e5a1ca1f274 1444 {
AzureIoTClient 53:1e5a1ca1f274 1445 /* Codes_SRS_IOTHUBCLIENT_LL_07_015: [ If the the update_state parameter is DEVICE_TWIN_UPDATE_PARTIAL and a DEVICE_TWIN_UPDATE_COMPLETE has not been previously recieved then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */
AzureIoTClient 53:1e5a1ca1f274 1446 if (update_state == DEVICE_TWIN_UPDATE_COMPLETE)
AzureIoTClient 53:1e5a1ca1f274 1447 {
AzureIoTClient 53:1e5a1ca1f274 1448 handleData->complete_twin_update_encountered = true;
AzureIoTClient 53:1e5a1ca1f274 1449 }
AzureIoTClient 53:1e5a1ca1f274 1450 if (handleData->complete_twin_update_encountered)
AzureIoTClient 53:1e5a1ca1f274 1451 {
AzureIoTClient 53:1e5a1ca1f274 1452 /* Codes_SRS_IOTHUBCLIENT_LL_07_016: [ If deviceTwinCallback is set and DEVICE_TWIN_UPDATE_COMPLETE has been encountered then IoTHubClient_LL_RetrievePropertyComplete shall call deviceTwinCallback.] */
AzureIoTClient 53:1e5a1ca1f274 1453 handleData->deviceTwinCallback(update_state, payLoad, size, handleData->deviceTwinContextCallback);
AzureIoTClient 53:1e5a1ca1f274 1454 }
AzureIoTClient 53:1e5a1ca1f274 1455 }
AzureIoTClient 53:1e5a1ca1f274 1456 }
AzureIoTClient 53:1e5a1ca1f274 1457 }
AzureIoTClient 53:1e5a1ca1f274 1458
AzureIoTClient 53:1e5a1ca1f274 1459 void IoTHubClient_LL_ReportedStateComplete(IOTHUB_CLIENT_LL_HANDLE handle, uint32_t item_id, int status_code)
AzureIoTClient 53:1e5a1ca1f274 1460 {
AzureIoTClient 53:1e5a1ca1f274 1461 /* Codes_SRS_IOTHUBCLIENT_LL_07_002: [ if handle or queue_handle are NULL then IoTHubClient_LL_ReportedStateComplete shall do nothing. ] */
AzureIoTClient 53:1e5a1ca1f274 1462 if (handle == NULL)
AzureIoTClient 53:1e5a1ca1f274 1463 {
AzureIoTClient 53:1e5a1ca1f274 1464 /*"shall return"*/
AzureIoTClient 53:1e5a1ca1f274 1465 LogError("Invalid argument handle=%p", handle);
AzureIoTClient 53:1e5a1ca1f274 1466 }
AzureIoTClient 53:1e5a1ca1f274 1467 else
AzureIoTClient 53:1e5a1ca1f274 1468 {
AzureIoTClient 53:1e5a1ca1f274 1469 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
AzureIoTClient 53:1e5a1ca1f274 1470
AzureIoTClient 53:1e5a1ca1f274 1471 /* Codes_SRS_IOTHUBCLIENT_LL_07_003: [ IoTHubClient_LL_ReportedStateComplete shall enumerate through the IOTHUB_DEVICE_TWIN structures in queue_handle. ]*/
AzureIoTClient 53:1e5a1ca1f274 1472 DLIST_ENTRY* client_item = handleData->iot_ack_queue.Flink;
AzureIoTClient 53:1e5a1ca1f274 1473 while (client_item != &(handleData->iot_ack_queue)) /*while we are not at the end of the list*/
AzureIoTClient 53:1e5a1ca1f274 1474 {
AzureIoTClient 53:1e5a1ca1f274 1475 PDLIST_ENTRY next_item = client_item->Flink;
AzureIoTClient 53:1e5a1ca1f274 1476 IOTHUB_DEVICE_TWIN* queue_data = containingRecord(client_item, IOTHUB_DEVICE_TWIN, entry);
AzureIoTClient 53:1e5a1ca1f274 1477 if (queue_data->item_id == item_id)
AzureIoTClient 53:1e5a1ca1f274 1478 {
AzureIoTClient 53:1e5a1ca1f274 1479 if (queue_data->reported_state_callback != NULL)
AzureIoTClient 53:1e5a1ca1f274 1480 {
AzureIoTClient 53:1e5a1ca1f274 1481 queue_data->reported_state_callback(status_code, queue_data->context);
AzureIoTClient 53:1e5a1ca1f274 1482 }
AzureIoTClient 53:1e5a1ca1f274 1483 /*Codes_SRS_IOTHUBCLIENT_LL_07_009: [ IoTHubClient_LL_ReportedStateComplete shall remove the IOTHUB_DEVICE_TWIN item from the ack queue.]*/
AzureIoTClient 53:1e5a1ca1f274 1484 DList_RemoveEntryList(client_item);
AzureIoTClient 53:1e5a1ca1f274 1485 device_twin_data_destroy(queue_data);
AzureIoTClient 53:1e5a1ca1f274 1486 break;
AzureIoTClient 53:1e5a1ca1f274 1487 }
AzureIoTClient 53:1e5a1ca1f274 1488 client_item = next_item;
AzureIoTClient 53:1e5a1ca1f274 1489 }
AzureIoTClient 53:1e5a1ca1f274 1490 }
AzureIoTClient 53:1e5a1ca1f274 1491 }
AzureIoTClient 53:1e5a1ca1f274 1492
AzureIoTClient 61:8b85a4e797cf 1493 bool IoTHubClient_LL_MessageCallback(IOTHUB_CLIENT_LL_HANDLE handle, MESSAGE_CALLBACK_INFO* messageData)
AzureIoTClient 16:deba40344375 1494 {
AzureIoTClient 61:8b85a4e797cf 1495 bool result;
AzureIoTClient 61:8b85a4e797cf 1496 if ((handle == NULL) || messageData == NULL)
AzureIoTClient 42:448eecc3676e 1497 {
AzureIoTClient 61:8b85a4e797cf 1498 /*Codes_SRS_IOTHUBCLIENT_LL_02_029: [If parameter handle is NULL then IoTHubClient_LL_MessageCallback shall return IOTHUBMESSAGE_ABANDONED.] */
AzureIoTClient 61:8b85a4e797cf 1499 LogError("invalid argument: handle(%p), messageData(%p)", handle, messageData);
AzureIoTClient 61:8b85a4e797cf 1500 result = false;
AzureIoTClient 61:8b85a4e797cf 1501 }
AzureIoTClient 61:8b85a4e797cf 1502 else if (messageData->messageHandle == NULL)
AzureIoTClient 61:8b85a4e797cf 1503 {
AzureIoTClient 61:8b85a4e797cf 1504 /*Codes_SRS_IOTHUBCLIENT_LL_10_004: [If messageHandle field of paramger messageData is NULL then IoTHubClient_LL_MessageCallback shall return IOTHUBMESSAGE_ABANDONED.] */
AzureIoTClient 61:8b85a4e797cf 1505 LogError("invalid argument messageData->messageHandle(NULL)");
AzureIoTClient 61:8b85a4e797cf 1506 result = false;
AzureIoTClient 42:448eecc3676e 1507 }
AzureIoTClient 42:448eecc3676e 1508 else
AzureIoTClient 42:448eecc3676e 1509 {
AzureIoTClient 42:448eecc3676e 1510 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
AzureIoTClient 16:deba40344375 1511
AzureIoTClient 42:448eecc3676e 1512 /* Codes_SRS_IOTHUBCLIENT_LL_09_004: [IoTHubClient_LL_GetLastMessageReceiveTime shall return lastMessageReceiveTime in localtime] */
AzureIoTClient 42:448eecc3676e 1513 handleData->lastMessageReceiveTime = get_time(NULL);
AzureIoTClient 62:5a4cdacf5090 1514 switch (handleData->messageCallback.type)
AzureIoTClient 42:448eecc3676e 1515 {
AzureIoTClient 62:5a4cdacf5090 1516 case CALLBACK_TYPE_NONE:
AzureIoTClient 61:8b85a4e797cf 1517 {
AzureIoTClient 61:8b85a4e797cf 1518 /*Codes_SRS_IOTHUBCLIENT_LL_02_032: [If the client is not subscribed to receive messages then IoTHubClient_LL_MessageCallback shall return false.] */
AzureIoTClient 61:8b85a4e797cf 1519 LogError("Invalid workflow - not currently set up to accept messages");
AzureIoTClient 61:8b85a4e797cf 1520 result = false;
AzureIoTClient 61:8b85a4e797cf 1521 break;
AzureIoTClient 61:8b85a4e797cf 1522 }
AzureIoTClient 62:5a4cdacf5090 1523 case CALLBACK_TYPE_SYNC:
AzureIoTClient 61:8b85a4e797cf 1524 {
AzureIoTClient 61:8b85a4e797cf 1525 /*Codes_SRS_IOTHUBCLIENT_LL_02_030: [If messageCallbackType is LEGACY then IoTHubClient_LL_MessageCallback shall invoke the last callback function (the parameter messageCallback to IoTHubClient_LL_SetMessageCallback) passing the message and the passed userContextCallback.]*/
AzureIoTClient 62:5a4cdacf5090 1526 IOTHUBMESSAGE_DISPOSITION_RESULT cb_result = handleData->messageCallback.callbackSync(messageData->messageHandle, handleData->messageCallback.userContextCallback);
AzureIoTClient 61:8b85a4e797cf 1527
AzureIoTClient 61:8b85a4e797cf 1528 /*Codes_SRS_IOTHUBCLIENT_LL_10_007: [If messageCallbackType is LEGACY then IoTHubClient_LL_MessageCallback shall send the message disposition as returned by the client to the underlying layer.] */
AzureIoTClient 61:8b85a4e797cf 1529 if (handleData->IoTHubTransport_SendMessageDisposition(messageData, cb_result) != IOTHUB_CLIENT_OK)
AzureIoTClient 61:8b85a4e797cf 1530 {
AzureIoTClient 61:8b85a4e797cf 1531 LogError("IoTHubTransport_SendMessageDisposition failed");
AzureIoTClient 61:8b85a4e797cf 1532 }
AzureIoTClient 61:8b85a4e797cf 1533 result = true;
AzureIoTClient 61:8b85a4e797cf 1534 break;
AzureIoTClient 61:8b85a4e797cf 1535 }
AzureIoTClient 62:5a4cdacf5090 1536 case CALLBACK_TYPE_ASYNC:
AzureIoTClient 61:8b85a4e797cf 1537 {
AzureIoTClient 61:8b85a4e797cf 1538 /* Codes_SRS_IOTHUBCLIENT_LL_10_009: [If messageCallbackType is ASYNC then IoTHubClient_LL_MessageCallback shall return what messageCallbacEx returns.] */
AzureIoTClient 62:5a4cdacf5090 1539 result = handleData->messageCallback.callbackAsync(messageData, handleData->messageCallback.userContextCallback);
AzureIoTClient 61:8b85a4e797cf 1540 if (!result)
AzureIoTClient 61:8b85a4e797cf 1541 {
AzureIoTClient 61:8b85a4e797cf 1542 LogError("messageCallbackEx failed");
AzureIoTClient 61:8b85a4e797cf 1543 }
AzureIoTClient 61:8b85a4e797cf 1544 break;
AzureIoTClient 61:8b85a4e797cf 1545 }
AzureIoTClient 61:8b85a4e797cf 1546 default:
AzureIoTClient 61:8b85a4e797cf 1547 {
AzureIoTClient 61:8b85a4e797cf 1548 LogError("Invalid state");
AzureIoTClient 61:8b85a4e797cf 1549 result = false;
AzureIoTClient 61:8b85a4e797cf 1550 break;
AzureIoTClient 61:8b85a4e797cf 1551 }
AzureIoTClient 42:448eecc3676e 1552 }
AzureIoTClient 42:448eecc3676e 1553 }
AzureIoTClient 61:8b85a4e797cf 1554 return result;
AzureIoTClient 16:deba40344375 1555 }
AzureIoTClient 16:deba40344375 1556
AzureIoTClient 61:8b85a4e797cf 1557 void IoTHubClient_LL_ConnectionStatusCallBack(IOTHUB_CLIENT_LL_HANDLE handle, IOTHUB_CLIENT_CONNECTION_STATUS status, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason)
AzureIoTClient 52:1cc3c6d07cad 1558 {
AzureIoTClient 61:8b85a4e797cf 1559 /*Codes_SRS_IOTHUBCLIENT_LL_25_113: [If parameter connectionStatus is NULL or parameter handle is NULL then IoTHubClient_LL_ConnectionStatusCallBack shall return.]*/
AzureIoTClient 53:1e5a1ca1f274 1560 if (handle == NULL)
AzureIoTClient 53:1e5a1ca1f274 1561 {
AzureIoTClient 53:1e5a1ca1f274 1562 /*"shall return"*/
AzureIoTClient 53:1e5a1ca1f274 1563 LogError("invalid arg");
AzureIoTClient 53:1e5a1ca1f274 1564 }
AzureIoTClient 53:1e5a1ca1f274 1565 else
AzureIoTClient 53:1e5a1ca1f274 1566 {
AzureIoTClient 53:1e5a1ca1f274 1567 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
AzureIoTClient 53:1e5a1ca1f274 1568
AzureIoTClient 61:8b85a4e797cf 1569 /*Codes_SRS_IOTHUBCLIENT_LL_25_114: [IoTHubClient_LL_ConnectionStatusCallBack shall call non-callback set by the user from IoTHubClient_LL_SetConnectionStatusCallback passing the status, reason and the passed userContextCallback.]*/
AzureIoTClient 53:1e5a1ca1f274 1570 if (handleData->conStatusCallback != NULL)
AzureIoTClient 53:1e5a1ca1f274 1571 {
AzureIoTClient 53:1e5a1ca1f274 1572 handleData->conStatusCallback(status, reason, handleData->conStatusUserContextCallback);
AzureIoTClient 53:1e5a1ca1f274 1573 }
AzureIoTClient 53:1e5a1ca1f274 1574 }
AzureIoTClient 53:1e5a1ca1f274 1575
AzureIoTClient 52:1cc3c6d07cad 1576 }
AzureIoTClient 52:1cc3c6d07cad 1577
AzureIoTClient 52:1cc3c6d07cad 1578 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetConnectionStatusCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void * userContextCallback)
AzureIoTClient 52:1cc3c6d07cad 1579 {
AzureIoTClient 53:1e5a1ca1f274 1580 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 53:1e5a1ca1f274 1581 /*Codes_SRS_IOTHUBCLIENT_LL_25_111: [IoTHubClient_LL_SetConnectionStatusCallback shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter iotHubClientHandle**]** */
AzureIoTClient 53:1e5a1ca1f274 1582 if (iotHubClientHandle == NULL)
AzureIoTClient 53:1e5a1ca1f274 1583 {
AzureIoTClient 53:1e5a1ca1f274 1584 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 53:1e5a1ca1f274 1585 LOG_ERROR_RESULT;
AzureIoTClient 53:1e5a1ca1f274 1586 }
AzureIoTClient 53:1e5a1ca1f274 1587 else
AzureIoTClient 53:1e5a1ca1f274 1588 {
AzureIoTClient 53:1e5a1ca1f274 1589 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 53:1e5a1ca1f274 1590 /*Codes_SRS_IOTHUBCLIENT_LL_25_112: [IoTHubClient_LL_SetConnectionStatusCallback shall return IOTHUB_CLIENT_OK and save the callback and userContext as a member of the handle.] */
AzureIoTClient 53:1e5a1ca1f274 1591 handleData->conStatusCallback = connectionStatusCallback;
AzureIoTClient 53:1e5a1ca1f274 1592 handleData->conStatusUserContextCallback = userContextCallback;
AzureIoTClient 53:1e5a1ca1f274 1593 result = IOTHUB_CLIENT_OK;
AzureIoTClient 53:1e5a1ca1f274 1594 }
AzureIoTClient 52:1cc3c6d07cad 1595
AzureIoTClient 52:1cc3c6d07cad 1596 return result;
AzureIoTClient 52:1cc3c6d07cad 1597 }
AzureIoTClient 52:1cc3c6d07cad 1598
AzureIoTClient 53:1e5a1ca1f274 1599 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds)
AzureIoTClient 52:1cc3c6d07cad 1600 {
AzureIoTClient 53:1e5a1ca1f274 1601 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 53:1e5a1ca1f274 1602 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 52:1cc3c6d07cad 1603
AzureIoTClient 62:5a4cdacf5090 1604 /* Codes_SRS_IOTHUBCLIENT_LL_25_116: [If iotHubClientHandle, retryPolicy or retryTimeoutLimitinSeconds is NULL, IoTHubClient_LL_GetRetryPolicy shall return IOTHUB_CLIENT_INVALID_ARG]*/
AzureIoTClient 53:1e5a1ca1f274 1605 if (handleData == NULL)
AzureIoTClient 53:1e5a1ca1f274 1606 {
AzureIoTClient 53:1e5a1ca1f274 1607 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 53:1e5a1ca1f274 1608 LOG_ERROR_RESULT;
AzureIoTClient 53:1e5a1ca1f274 1609 }
AzureIoTClient 53:1e5a1ca1f274 1610 else
AzureIoTClient 53:1e5a1ca1f274 1611 {
AzureIoTClient 53:1e5a1ca1f274 1612 if (handleData->transportHandle == NULL)
AzureIoTClient 53:1e5a1ca1f274 1613 {
AzureIoTClient 53:1e5a1ca1f274 1614 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 53:1e5a1ca1f274 1615 LOG_ERROR_RESULT;
AzureIoTClient 53:1e5a1ca1f274 1616 }
AzureIoTClient 53:1e5a1ca1f274 1617 else
AzureIoTClient 53:1e5a1ca1f274 1618 {
AzureIoTClient 53:1e5a1ca1f274 1619 if (handleData->IoTHubTransport_SetRetryPolicy(handleData->transportHandle, retryPolicy, retryTimeoutLimitInSeconds) != 0)
AzureIoTClient 53:1e5a1ca1f274 1620 {
AzureIoTClient 53:1e5a1ca1f274 1621 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 53:1e5a1ca1f274 1622 LOG_ERROR_RESULT;
AzureIoTClient 53:1e5a1ca1f274 1623 }
AzureIoTClient 53:1e5a1ca1f274 1624 else
AzureIoTClient 53:1e5a1ca1f274 1625 {
AzureIoTClient 62:5a4cdacf5090 1626 /* Codes_SRS_IOTHUBCLIENT_LL_25_118: [IoTHubClient_LL_SetRetryPolicy shall save connection retry policies specified by the user to retryPolicy in struct IOTHUB_CLIENT_LL_HANDLE_DATA] */
AzureIoTClient 62:5a4cdacf5090 1627 /* Codes_SRS_IOTHUBCLIENT_LL_25_119: [IoTHubClient_LL_SetRetryPolicy shall save retryTimeoutLimitInSeconds in seconds to retryTimeout in struct IOTHUB_CLIENT_LL_HANDLE_DATA] */
AzureIoTClient 53:1e5a1ca1f274 1628 handleData->retryPolicy = retryPolicy;
AzureIoTClient 53:1e5a1ca1f274 1629 handleData->retryTimeoutLimitInSeconds = retryTimeoutLimitInSeconds;
AzureIoTClient 53:1e5a1ca1f274 1630 result = IOTHUB_CLIENT_OK;
AzureIoTClient 53:1e5a1ca1f274 1631 }
AzureIoTClient 53:1e5a1ca1f274 1632 }
AzureIoTClient 53:1e5a1ca1f274 1633 }
AzureIoTClient 52:1cc3c6d07cad 1634 return result;
AzureIoTClient 52:1cc3c6d07cad 1635 }
AzureIoTClient 52:1cc3c6d07cad 1636
AzureIoTClient 53:1e5a1ca1f274 1637 IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy, size_t* retryTimeoutLimitInSeconds)
AzureIoTClient 52:1cc3c6d07cad 1638 {
AzureIoTClient 62:5a4cdacf5090 1639 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 53:1e5a1ca1f274 1640
AzureIoTClient 53:1e5a1ca1f274 1641 /* Codes_SRS_IOTHUBCLIENT_LL_09_001: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG if any of the arguments is NULL] */
AzureIoTClient 62:5a4cdacf5090 1642 if (iotHubClientHandle == NULL || retryPolicy == NULL || retryTimeoutLimitInSeconds == NULL)
AzureIoTClient 53:1e5a1ca1f274 1643 {
AzureIoTClient 62:5a4cdacf5090 1644 LogError("Invalid parameter IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle = %p, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy = %p, size_t* retryTimeoutLimitInSeconds = %p", iotHubClientHandle, retryPolicy, retryTimeoutLimitInSeconds);
AzureIoTClient 53:1e5a1ca1f274 1645 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 53:1e5a1ca1f274 1646 }
AzureIoTClient 53:1e5a1ca1f274 1647 else
AzureIoTClient 53:1e5a1ca1f274 1648 {
AzureIoTClient 62:5a4cdacf5090 1649 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 62:5a4cdacf5090 1650
AzureIoTClient 53:1e5a1ca1f274 1651 *retryPolicy = handleData->retryPolicy;
AzureIoTClient 53:1e5a1ca1f274 1652 *retryTimeoutLimitInSeconds = handleData->retryTimeoutLimitInSeconds;
AzureIoTClient 53:1e5a1ca1f274 1653 result = IOTHUB_CLIENT_OK;
AzureIoTClient 53:1e5a1ca1f274 1654 }
AzureIoTClient 52:1cc3c6d07cad 1655
AzureIoTClient 52:1cc3c6d07cad 1656 return result;
AzureIoTClient 52:1cc3c6d07cad 1657 }
AzureIoTClient 52:1cc3c6d07cad 1658
AzureIoTClient 16:deba40344375 1659 IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetLastMessageReceiveTime(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime)
AzureIoTClient 16:deba40344375 1660 {
AzureIoTClient 42:448eecc3676e 1661 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 42:448eecc3676e 1662 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 1663
AzureIoTClient 42:448eecc3676e 1664 /* 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 1665 if (handleData == NULL || lastMessageReceiveTime == NULL)
AzureIoTClient 42:448eecc3676e 1666 {
AzureIoTClient 42:448eecc3676e 1667 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 45:54c11b1b1407 1668 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 1669 }
AzureIoTClient 42:448eecc3676e 1670 else
AzureIoTClient 42:448eecc3676e 1671 {
AzureIoTClient 42:448eecc3676e 1672 /* 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 1673 if (handleData->lastMessageReceiveTime == INDEFINITE_TIME)
AzureIoTClient 42:448eecc3676e 1674 {
AzureIoTClient 42:448eecc3676e 1675 result = IOTHUB_CLIENT_INDEFINITE_TIME;
Azure.IoT Build 45:54c11b1b1407 1676 LOG_ERROR_RESULT;
AzureIoTClient 42:448eecc3676e 1677 }
AzureIoTClient 42:448eecc3676e 1678 else
AzureIoTClient 42:448eecc3676e 1679 {
AzureIoTClient 42:448eecc3676e 1680 /* 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 1681 /* Codes_SRS_IOTHUBCLIENT_LL_09_004: [IoTHubClient_LL_GetLastMessageReceiveTime shall return lastMessageReceiveTime in localtime] */
AzureIoTClient 42:448eecc3676e 1682 *lastMessageReceiveTime = handleData->lastMessageReceiveTime;
AzureIoTClient 42:448eecc3676e 1683 result = IOTHUB_CLIENT_OK;
AzureIoTClient 42:448eecc3676e 1684 }
AzureIoTClient 42:448eecc3676e 1685 }
AzureIoTClient 16:deba40344375 1686
AzureIoTClient 42:448eecc3676e 1687 return result;
AzureIoTClient 16:deba40344375 1688 }
AzureIoTClient 16:deba40344375 1689
AzureIoTClient 16:deba40344375 1690 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetOption(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* optionName, const void* value)
AzureIoTClient 16:deba40344375 1691 {
AzureIoTClient 40:1a94db9139ea 1692
AzureIoTClient 42:448eecc3676e 1693 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 42:448eecc3676e 1694 /*Codes_SRS_IOTHUBCLIENT_LL_02_034: [If iotHubClientHandle is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.]*/
AzureIoTClient 42:448eecc3676e 1695 /*Codes_SRS_IOTHUBCLIENT_LL_02_035: [If optionName is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 42:448eecc3676e 1696 /*Codes_SRS_IOTHUBCLIENT_LL_02_036: [If value is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 42:448eecc3676e 1697 if (
AzureIoTClient 42:448eecc3676e 1698 (iotHubClientHandle == NULL) ||
AzureIoTClient 42:448eecc3676e 1699 (optionName == NULL) ||
AzureIoTClient 42:448eecc3676e 1700 (value == NULL)
AzureIoTClient 42:448eecc3676e 1701 )
AzureIoTClient 42:448eecc3676e 1702 {
AzureIoTClient 42:448eecc3676e 1703 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 42:448eecc3676e 1704 LogError("invalid argument (NULL)");
AzureIoTClient 42:448eecc3676e 1705 }
AzureIoTClient 42:448eecc3676e 1706 else
AzureIoTClient 42:448eecc3676e 1707 {
AzureIoTClient 42:448eecc3676e 1708 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 42:448eecc3676e 1709
AzureIoTClient 78:74a8d3068204 1710 /*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 tickcounter_ms_t. ]*/
AzureIoTClient 70:875388a7d419 1711 if (strcmp(optionName, OPTION_MESSAGE_TIMEOUT) == 0)
AzureIoTClient 42:448eecc3676e 1712 {
AzureIoTClient 42:448eecc3676e 1713 /*this is an option handled by IoTHubClient_LL*/
AzureIoTClient 42:448eecc3676e 1714 /*Codes_SRS_IOTHUBCLIENT_LL_02_043: [ Calling IoTHubClient_LL_SetOption with value set to "0" shall disable the timeout mechanism for all new messages. ]*/
Azure.IoT.Build 54:6dcad9019a64 1715 handleData->currentMessageTimeout = *(const tickcounter_ms_t*)value;
AzureIoTClient 42:448eecc3676e 1716 result = IOTHUB_CLIENT_OK;
AzureIoTClient 42:448eecc3676e 1717 }
AzureIoTClient 66:a419827cb051 1718 else if (strcmp(optionName, OPTION_PRODUCT_INFO) == 0)
AzureIoTClient 66:a419827cb051 1719 {
AzureIoTClient 66:a419827cb051 1720 /*Codes_SRS_IOTHUBCLIENT_LL_10_033: [repeat calls with "product_info" will erase the previously set product information if applicatble. ]*/
AzureIoTClient 66:a419827cb051 1721 if (handleData->product_info != NULL)
AzureIoTClient 66:a419827cb051 1722 {
AzureIoTClient 66:a419827cb051 1723 STRING_delete(handleData->product_info);
AzureIoTClient 66:a419827cb051 1724 handleData->product_info = NULL;
AzureIoTClient 66:a419827cb051 1725 }
AzureIoTClient 66:a419827cb051 1726
AzureIoTClient 66:a419827cb051 1727 /*Codes_SRS_IOTHUBCLIENT_LL_10_035: [If string concatenation fails, `IoTHubClient_LL_SetOption` shall return `IOTHUB_CLIENT_ERRROR`. Otherwise, `IOTHUB_CLIENT_OK` shall be returned. ]*/
AzureIoTClient 66:a419827cb051 1728 handleData->product_info = make_product_info((const char*)value);
AzureIoTClient 66:a419827cb051 1729 if (handleData->product_info == NULL)
AzureIoTClient 66:a419827cb051 1730 {
AzureIoTClient 66:a419827cb051 1731 LogError("STRING_construct_sprintf failed");
AzureIoTClient 66:a419827cb051 1732 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 66:a419827cb051 1733 }
AzureIoTClient 66:a419827cb051 1734 else
AzureIoTClient 66:a419827cb051 1735 {
AzureIoTClient 66:a419827cb051 1736 result = IOTHUB_CLIENT_OK;
AzureIoTClient 66:a419827cb051 1737 }
AzureIoTClient 66:a419827cb051 1738 }
AzureIoTClient 77:e4e36df9caee 1739 else if (strcmp(optionName, OPTION_DIAGNOSTIC_SAMPLING_PERCENTAGE) == 0)
AzureIoTClient 77:e4e36df9caee 1740 {
AzureIoTClient 77:e4e36df9caee 1741 uint32_t percentage = *(uint32_t*)value;
AzureIoTClient 77:e4e36df9caee 1742 if (percentage > 100)
AzureIoTClient 77:e4e36df9caee 1743 {
AzureIoTClient 77:e4e36df9caee 1744 /*Codes_SRS_IOTHUBCLIENT_LL_10_036: [Calling IoTHubClient_LL_SetOption with value > 100 shall return `IOTHUB_CLIENT_ERRROR`. ]*/
AzureIoTClient 77:e4e36df9caee 1745 LogError("The value of diag_sampling_percentage is out of range [0, 100]: %u", percentage);
AzureIoTClient 77:e4e36df9caee 1746 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 77:e4e36df9caee 1747 }
AzureIoTClient 77:e4e36df9caee 1748 else
AzureIoTClient 77:e4e36df9caee 1749 {
AzureIoTClient 77:e4e36df9caee 1750 /*Codes_SRS_IOTHUBCLIENT_LL_10_037: [Calling IoTHubClient_LL_SetOption with value between [0, 100] shall return `IOTHUB_CLIENT_OK`. ]*/
AzureIoTClient 77:e4e36df9caee 1751 handleData->diagnostic_setting.diagSamplingPercentage = percentage;
AzureIoTClient 77:e4e36df9caee 1752 handleData->diagnostic_setting.currentMessageNumber = 0;
AzureIoTClient 77:e4e36df9caee 1753 result = IOTHUB_CLIENT_OK;
AzureIoTClient 77:e4e36df9caee 1754 }
AzureIoTClient 77:e4e36df9caee 1755 }
AzureIoTClient 42:448eecc3676e 1756 else
AzureIoTClient 42:448eecc3676e 1757 {
AzureIoTClient 46:6a69294b6119 1758
AzureIoTClient 46:6a69294b6119 1759 /*Codes_SRS_IOTHUBCLIENT_LL_02_099: [ IoTHubClient_LL_SetOption shall return according to the table below ]*/
AzureIoTClient 46:6a69294b6119 1760 IOTHUB_CLIENT_RESULT uploadToBlob_result;
AzureIoTClient 46:6a69294b6119 1761 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 46:6a69294b6119 1762 uploadToBlob_result = IoTHubClient_LL_UploadToBlob_SetOption(handleData->uploadToBlobHandle, optionName, value);
AzureIoTClient 46:6a69294b6119 1763 if(uploadToBlob_result == IOTHUB_CLIENT_ERROR)
AzureIoTClient 46:6a69294b6119 1764 {
AzureIoTClient 46:6a69294b6119 1765 LogError("unable to IoTHubClient_LL_UploadToBlob_SetOption");
AzureIoTClient 46:6a69294b6119 1766 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 46:6a69294b6119 1767 }
AzureIoTClient 46:6a69294b6119 1768 #else
AzureIoTClient 46:6a69294b6119 1769 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 1770 #endif /*DONT_USE_UPLOADTOBLOB*/
AzureIoTClient 16:deba40344375 1771
AzureIoTClient 70:875388a7d419 1772 /*Codes_SRS_IOTHUBCLIENT_LL_12_023: [** `c2d_keep_alive_freq_secs` - shall set the cloud to device keep alive frequency(in seconds) for the connection. Zero means keep alive will not be sent. ]*/
AzureIoTClient 46:6a69294b6119 1773 result =
AzureIoTClient 46:6a69294b6119 1774 /*based on uploadToBlob_result value this is what happens:*/
AzureIoTClient 46:6a69294b6119 1775 /*IOTHUB_CLIENT_INVALID_ARG always returns what IoTHubTransport_SetOption returns*/
AzureIoTClient 46:6a69294b6119 1776 /*IOTHUB_CLIENT_ERROR always returns IOTHUB_CLIENT_ERROR */
AzureIoTClient 46:6a69294b6119 1777 /*IOTHUB_CLIENT_OK returns OK
AzureIoTClient 46:6a69294b6119 1778 IOTHUB_CLIENT_OK if IoTHubTransport_SetOption returns OK or INVALID_ARG
AzureIoTClient 46:6a69294b6119 1779 IOTHUB_CLIENT_ERROR if IoTHubTransport_SetOption returns ERROR*/
AzureIoTClient 46:6a69294b6119 1780
AzureIoTClient 46:6a69294b6119 1781 (uploadToBlob_result == IOTHUB_CLIENT_INVALID_ARG) ? handleData->IoTHubTransport_SetOption(handleData->transportHandle, optionName, value) :
AzureIoTClient 46:6a69294b6119 1782 (uploadToBlob_result == IOTHUB_CLIENT_ERROR) ? IOTHUB_CLIENT_ERROR :
AzureIoTClient 46:6a69294b6119 1783 (handleData->IoTHubTransport_SetOption(handleData->transportHandle, optionName, value) == IOTHUB_CLIENT_ERROR) ? IOTHUB_CLIENT_ERROR : IOTHUB_CLIENT_OK;
AzureIoTClient 46:6a69294b6119 1784
AzureIoTClient 47:aaa262b5f898 1785 if (result != IOTHUB_CLIENT_OK)
AzureIoTClient 47:aaa262b5f898 1786 {
AzureIoTClient 47:aaa262b5f898 1787 LogError("underlying transport failed, returned = %s", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result));
AzureIoTClient 42:448eecc3676e 1788 }
AzureIoTClient 47:aaa262b5f898 1789 }
AzureIoTClient 42:448eecc3676e 1790 }
AzureIoTClient 42:448eecc3676e 1791 return result;
AzureIoTClient 42:448eecc3676e 1792 }
AzureIoTClient 16:deba40344375 1793
AzureIoTClient 66:a419827cb051 1794 IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetOption(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* optionName, void** value)
AzureIoTClient 66:a419827cb051 1795 {
AzureIoTClient 66:a419827cb051 1796 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 66:a419827cb051 1797
AzureIoTClient 66:a419827cb051 1798 if ((iotHubClientHandle == NULL) || (optionName == NULL) || (value == NULL))
AzureIoTClient 66:a419827cb051 1799 {
AzureIoTClient 66:a419827cb051 1800 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 66:a419827cb051 1801 LogError("invalid argument iotHubClientHandle(%p); optionName(%p); value(%p)", iotHubClientHandle, optionName, value);
AzureIoTClient 66:a419827cb051 1802 }
AzureIoTClient 66:a419827cb051 1803 else if (strcmp(optionName, OPTION_PRODUCT_INFO) == 0)
AzureIoTClient 66:a419827cb051 1804 {
AzureIoTClient 66:a419827cb051 1805 result = IOTHUB_CLIENT_OK;
AzureIoTClient 66:a419827cb051 1806 *value = iotHubClientHandle->product_info;
AzureIoTClient 66:a419827cb051 1807 }
AzureIoTClient 66:a419827cb051 1808 else
AzureIoTClient 66:a419827cb051 1809 {
AzureIoTClient 66:a419827cb051 1810 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 66:a419827cb051 1811 LogError("invalid argument (%s)", optionName);
AzureIoTClient 66:a419827cb051 1812 }
AzureIoTClient 66:a419827cb051 1813 return result;
AzureIoTClient 66:a419827cb051 1814 }
AzureIoTClient 66:a419827cb051 1815
AzureIoTClient 53:1e5a1ca1f274 1816 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetDeviceTwinCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback, void* userContextCallback)
AzureIoTClient 53:1e5a1ca1f274 1817 {
AzureIoTClient 53:1e5a1ca1f274 1818 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 53:1e5a1ca1f274 1819 /* Codes_SRS_IOTHUBCLIENT_LL_10_001: [ IoTHubClient_LL_SetDeviceTwinCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.] */
AzureIoTClient 53:1e5a1ca1f274 1820 if (iotHubClientHandle == NULL)
AzureIoTClient 53:1e5a1ca1f274 1821 {
AzureIoTClient 53:1e5a1ca1f274 1822 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 53:1e5a1ca1f274 1823 LogError("Invalid argument specified iothubClientHandle=%p", iotHubClientHandle);
AzureIoTClient 53:1e5a1ca1f274 1824 }
AzureIoTClient 53:1e5a1ca1f274 1825 else
AzureIoTClient 53:1e5a1ca1f274 1826 {
AzureIoTClient 53:1e5a1ca1f274 1827 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 53:1e5a1ca1f274 1828 if (deviceTwinCallback == NULL)
AzureIoTClient 53:1e5a1ca1f274 1829 {
AzureIoTClient 53:1e5a1ca1f274 1830 /* Codes_SRS_IOTHUBCLIENT_LL_10_006: [ If deviceTwinCallback is NULL, then IoTHubClient_LL_SetDeviceTwinCallback shall call the underlying layer's _Unsubscribe function and return IOTHUB_CLIENT_OK.] */
AzureIoTClient 53:1e5a1ca1f274 1831 handleData->IoTHubTransport_Unsubscribe_DeviceTwin(handleData->transportHandle);
AzureIoTClient 53:1e5a1ca1f274 1832 handleData->deviceTwinCallback = NULL;
AzureIoTClient 53:1e5a1ca1f274 1833 result = IOTHUB_CLIENT_OK;
AzureIoTClient 53:1e5a1ca1f274 1834 }
AzureIoTClient 53:1e5a1ca1f274 1835 else
AzureIoTClient 53:1e5a1ca1f274 1836 {
AzureIoTClient 53:1e5a1ca1f274 1837 /* Codes_SRS_IOTHUBCLIENT_LL_10_002: [ If deviceTwinCallback is not NULL, then IoTHubClient_LL_SetDeviceTwinCallback shall call the underlying layer's _Subscribe function.] */
AzureIoTClient 53:1e5a1ca1f274 1838 if (handleData->IoTHubTransport_Subscribe_DeviceTwin(handleData->transportHandle) == 0)
AzureIoTClient 53:1e5a1ca1f274 1839 {
AzureIoTClient 53:1e5a1ca1f274 1840 handleData->deviceTwinCallback = deviceTwinCallback;
AzureIoTClient 53:1e5a1ca1f274 1841 handleData->deviceTwinContextCallback = userContextCallback;
AzureIoTClient 53:1e5a1ca1f274 1842 /* Codes_SRS_IOTHUBCLIENT_LL_10_005: [ Otherwise IoTHubClient_LL_SetDeviceTwinCallback shall succeed and return IOTHUB_CLIENT_OK.] */
AzureIoTClient 53:1e5a1ca1f274 1843 result = IOTHUB_CLIENT_OK;
AzureIoTClient 53:1e5a1ca1f274 1844 }
AzureIoTClient 53:1e5a1ca1f274 1845 else
AzureIoTClient 53:1e5a1ca1f274 1846 {
AzureIoTClient 53:1e5a1ca1f274 1847 /* Codes_SRS_IOTHUBCLIENT_LL_10_003: [ If the underlying layer's _Subscribe function fails, then IoTHubClient_LL_SetDeviceTwinCallback shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 53:1e5a1ca1f274 1848 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 53:1e5a1ca1f274 1849 }
AzureIoTClient 53:1e5a1ca1f274 1850 }
AzureIoTClient 53:1e5a1ca1f274 1851 }
AzureIoTClient 53:1e5a1ca1f274 1852 return result;
AzureIoTClient 53:1e5a1ca1f274 1853 }
AzureIoTClient 53:1e5a1ca1f274 1854
AzureIoTClient 53:1e5a1ca1f274 1855 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SendReportedState(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback)
AzureIoTClient 53:1e5a1ca1f274 1856 {
AzureIoTClient 53:1e5a1ca1f274 1857 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 53:1e5a1ca1f274 1858 /* Codes_SRS_IOTHUBCLIENT_LL_10_012: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL. ] */
AzureIoTClient 53:1e5a1ca1f274 1859 /* Codes_SRS_IOTHUBCLIENT_LL_10_013: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter reportedState is NULL] */
AzureIoTClient 53:1e5a1ca1f274 1860 /* Codes_SRS_IOTHUBCLIENT_LL_07_005: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter size is equal to 0. ] */
AzureIoTClient 53:1e5a1ca1f274 1861 if (iotHubClientHandle == NULL || (reportedState == NULL || size == 0) )
AzureIoTClient 53:1e5a1ca1f274 1862 {
AzureIoTClient 53:1e5a1ca1f274 1863 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 53:1e5a1ca1f274 1864 LogError("Invalid argument specified iothubClientHandle=%p, reportedState=%p, size=%zu", iotHubClientHandle, reportedState, size);
AzureIoTClient 53:1e5a1ca1f274 1865 }
AzureIoTClient 53:1e5a1ca1f274 1866 else
AzureIoTClient 53:1e5a1ca1f274 1867 {
AzureIoTClient 53:1e5a1ca1f274 1868 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 53:1e5a1ca1f274 1869 /* Codes_SRS_IOTHUBCLIENT_LL_10_014: [IoTHubClient_LL_SendReportedState shall construct and queue the reported a Device_Twin structure for transmition by the underlying transport.] */
AzureIoTClient 53:1e5a1ca1f274 1870 IOTHUB_DEVICE_TWIN* client_data = dev_twin_data_create(handleData, get_next_item_id(handleData), reportedState, size, reportedStateCallback, userContextCallback);
AzureIoTClient 53:1e5a1ca1f274 1871 if (client_data == NULL)
AzureIoTClient 53:1e5a1ca1f274 1872 {
AzureIoTClient 53:1e5a1ca1f274 1873 /* Codes_SRS_IOTHUBCLIENT_LL_10_015: [If any error is encountered IoTHubClient_LL_SendReportedState shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 53:1e5a1ca1f274 1874 LogError("Failure constructing device twin data");
AzureIoTClient 53:1e5a1ca1f274 1875 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 53:1e5a1ca1f274 1876 }
AzureIoTClient 53:1e5a1ca1f274 1877 else
AzureIoTClient 53:1e5a1ca1f274 1878 {
AzureIoTClient 53:1e5a1ca1f274 1879 if (handleData->IoTHubTransport_Subscribe_DeviceTwin(handleData->transportHandle) != 0)
AzureIoTClient 53:1e5a1ca1f274 1880 {
AzureIoTClient 53:1e5a1ca1f274 1881 LogError("Failure adding device twin data to queue");
AzureIoTClient 53:1e5a1ca1f274 1882 device_twin_data_destroy(client_data);
AzureIoTClient 53:1e5a1ca1f274 1883 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 53:1e5a1ca1f274 1884 }
AzureIoTClient 53:1e5a1ca1f274 1885 else
AzureIoTClient 53:1e5a1ca1f274 1886 {
AzureIoTClient 53:1e5a1ca1f274 1887 /* Codes_SRS_IOTHUBCLIENT_LL_07_001: [ IoTHubClient_LL_SendReportedState shall queue the constructed reportedState data to be consumed by the targeted transport. ] */
AzureIoTClient 53:1e5a1ca1f274 1888 DList_InsertTailList(&(iotHubClientHandle->iot_msg_queue), &(client_data->entry));
AzureIoTClient 53:1e5a1ca1f274 1889
AzureIoTClient 53:1e5a1ca1f274 1890 /* Codes_SRS_IOTHUBCLIENT_LL_10_016: [ Otherwise IoTHubClient_LL_SendReportedState shall succeed and return IOTHUB_CLIENT_OK.] */
AzureIoTClient 53:1e5a1ca1f274 1891 result = IOTHUB_CLIENT_OK;
AzureIoTClient 53:1e5a1ca1f274 1892 }
AzureIoTClient 53:1e5a1ca1f274 1893 }
AzureIoTClient 53:1e5a1ca1f274 1894 }
AzureIoTClient 53:1e5a1ca1f274 1895 return result;
AzureIoTClient 53:1e5a1ca1f274 1896 }
AzureIoTClient 53:1e5a1ca1f274 1897
AzureIoTClient 53:1e5a1ca1f274 1898 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetDeviceMethodCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC deviceMethodCallback, void* userContextCallback)
AzureIoTClient 53:1e5a1ca1f274 1899 {
AzureIoTClient 53:1e5a1ca1f274 1900 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 53:1e5a1ca1f274 1901
AzureIoTClient 53:1e5a1ca1f274 1902 /*Codes_SRS_IOTHUBCLIENT_LL_12_017: [ IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL. ] */
AzureIoTClient 53:1e5a1ca1f274 1903 if (iotHubClientHandle == NULL)
AzureIoTClient 53:1e5a1ca1f274 1904 {
AzureIoTClient 53:1e5a1ca1f274 1905 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 53:1e5a1ca1f274 1906 LOG_ERROR_RESULT;
AzureIoTClient 53:1e5a1ca1f274 1907 }
AzureIoTClient 53:1e5a1ca1f274 1908 else
AzureIoTClient 53:1e5a1ca1f274 1909 {
AzureIoTClient 53:1e5a1ca1f274 1910 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 53:1e5a1ca1f274 1911 if (deviceMethodCallback == NULL)
AzureIoTClient 53:1e5a1ca1f274 1912 {
AzureIoTClient 62:5a4cdacf5090 1913 if (handleData->methodCallback.type == CALLBACK_TYPE_NONE)
AzureIoTClient 62:5a4cdacf5090 1914 {
AzureIoTClient 62:5a4cdacf5090 1915 /* Codes_SRS_IOTHUBCLIENT_LL_10_029: [ If deviceMethodCallback is NULL and the client is not subscribed to receive method calls, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ] */
AzureIoTClient 62:5a4cdacf5090 1916 LogError("not currently set to accept or process incoming messages.");
AzureIoTClient 62:5a4cdacf5090 1917 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 62:5a4cdacf5090 1918 }
AzureIoTClient 62:5a4cdacf5090 1919 else if (handleData->methodCallback.type == CALLBACK_TYPE_ASYNC)
AzureIoTClient 62:5a4cdacf5090 1920 {
AzureIoTClient 62:5a4cdacf5090 1921 /* Codes_SRS_IOTHUBCLIENT_LL_10_028: [If the user has subscribed using IoTHubClient_LL_SetDeviceMethodCallback_Ex, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ] */
AzureIoTClient 62:5a4cdacf5090 1922 LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetDeviceMethodCallback_Ex function.");
AzureIoTClient 62:5a4cdacf5090 1923 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 62:5a4cdacf5090 1924 }
AzureIoTClient 62:5a4cdacf5090 1925 else
AzureIoTClient 62:5a4cdacf5090 1926 {
AzureIoTClient 62:5a4cdacf5090 1927 /*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 62:5a4cdacf5090 1928 /*Codes_SRS_IOTHUBCLIENT_LL_12_018: [If deviceMethodCallback is NULL, then IoTHubClient_LL_SetDeviceMethodCallback shall call the underlying layer's IoTHubTransport_Unsubscribe_DeviceMethod function and return IOTHUB_CLIENT_OK. ] */
AzureIoTClient 62:5a4cdacf5090 1929 /*Codes_SRS_IOTHUBCLIENT_LL_12_022: [ Otherwise IoTHubClient_LL_SetDeviceMethodCallback shall succeed and return IOTHUB_CLIENT_OK. ]*/
AzureIoTClient 62:5a4cdacf5090 1930 handleData->IoTHubTransport_Unsubscribe_DeviceMethod(handleData->transportHandle);
AzureIoTClient 62:5a4cdacf5090 1931 handleData->methodCallback.type = CALLBACK_TYPE_NONE;
AzureIoTClient 62:5a4cdacf5090 1932 handleData->methodCallback.callbackSync = NULL;
AzureIoTClient 62:5a4cdacf5090 1933 handleData->methodCallback.userContextCallback = NULL;
AzureIoTClient 62:5a4cdacf5090 1934 result = IOTHUB_CLIENT_OK;
AzureIoTClient 62:5a4cdacf5090 1935 }
AzureIoTClient 53:1e5a1ca1f274 1936 }
AzureIoTClient 53:1e5a1ca1f274 1937 else
AzureIoTClient 53:1e5a1ca1f274 1938 {
AzureIoTClient 62:5a4cdacf5090 1939 if (handleData->methodCallback.type == CALLBACK_TYPE_ASYNC)
AzureIoTClient 53:1e5a1ca1f274 1940 {
AzureIoTClient 62:5a4cdacf5090 1941 /* Codes_SRS_IOTHUBCLIENT_LL_10_028: [If the user has subscribed using IoTHubClient_LL_SetDeviceMethodCallback_Ex, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ] */
AzureIoTClient 62:5a4cdacf5090 1942 LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetDeviceMethodCallback_Ex function before subscribing with IoTHubClient_LL_SetDeviceMethodCallback.");
AzureIoTClient 62:5a4cdacf5090 1943 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 53:1e5a1ca1f274 1944 }
AzureIoTClient 53:1e5a1ca1f274 1945 else
AzureIoTClient 53:1e5a1ca1f274 1946 {
AzureIoTClient 62:5a4cdacf5090 1947 /*Codes_SRS_IOTHUBCLIENT_LL_12_019: [ If deviceMethodCallback is not NULL, then IoTHubClient_LL_SetDeviceMethodCallback shall call the underlying layer's IoTHubTransport_Subscribe_DeviceMethod function. ]*/
AzureIoTClient 62:5a4cdacf5090 1948 if (handleData->IoTHubTransport_Subscribe_DeviceMethod(handleData->deviceHandle) == 0)
AzureIoTClient 62:5a4cdacf5090 1949 {
AzureIoTClient 62:5a4cdacf5090 1950 /*Codes_SRS_IOTHUBCLIENT_LL_12_022: [ Otherwise IoTHubClient_LL_SetDeviceMethodCallback shall succeed and return IOTHUB_CLIENT_OK. ]*/
AzureIoTClient 62:5a4cdacf5090 1951 handleData->methodCallback.type = CALLBACK_TYPE_SYNC;
AzureIoTClient 62:5a4cdacf5090 1952 handleData->methodCallback.callbackSync = deviceMethodCallback;
AzureIoTClient 62:5a4cdacf5090 1953 handleData->methodCallback.callbackAsync = NULL;
AzureIoTClient 62:5a4cdacf5090 1954 handleData->methodCallback.userContextCallback = userContextCallback;
AzureIoTClient 62:5a4cdacf5090 1955 result = IOTHUB_CLIENT_OK;
AzureIoTClient 62:5a4cdacf5090 1956 }
AzureIoTClient 62:5a4cdacf5090 1957 else
AzureIoTClient 62:5a4cdacf5090 1958 {
AzureIoTClient 62:5a4cdacf5090 1959 /*Codes_SRS_IOTHUBCLIENT_LL_12_020: [ If the underlying layer's IoTHubTransport_Subscribe_DeviceMethod function fails, then IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ]*/
AzureIoTClient 62:5a4cdacf5090 1960 /*Codes_SRS_IOTHUBCLIENT_LL_12_021: [ If adding the information fails for any reason, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ]*/
AzureIoTClient 62:5a4cdacf5090 1961 LogError("IoTHubTransport_Subscribe_DeviceMethod failed");
AzureIoTClient 62:5a4cdacf5090 1962 handleData->methodCallback.type = CALLBACK_TYPE_NONE;
AzureIoTClient 62:5a4cdacf5090 1963 handleData->methodCallback.callbackAsync = NULL;
AzureIoTClient 62:5a4cdacf5090 1964 handleData->methodCallback.callbackSync = NULL;
AzureIoTClient 62:5a4cdacf5090 1965 handleData->methodCallback.userContextCallback = NULL;
AzureIoTClient 62:5a4cdacf5090 1966 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 62:5a4cdacf5090 1967 }
AzureIoTClient 53:1e5a1ca1f274 1968 }
AzureIoTClient 53:1e5a1ca1f274 1969 }
AzureIoTClient 53:1e5a1ca1f274 1970 }
AzureIoTClient 53:1e5a1ca1f274 1971 return result;
AzureIoTClient 53:1e5a1ca1f274 1972 }
AzureIoTClient 53:1e5a1ca1f274 1973
AzureIoTClient 55:59b527ab3452 1974 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetDeviceMethodCallback_Ex(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK inboundDeviceMethodCallback, void* userContextCallback)
AzureIoTClient 55:59b527ab3452 1975 {
AzureIoTClient 55:59b527ab3452 1976 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 55:59b527ab3452 1977 /* Codes_SRS_IOTHUBCLIENT_LL_07_021: [ If handle is NULL then IoTHubClient_LL_SetDeviceMethodCallback_Ex shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 55:59b527ab3452 1978 if (iotHubClientHandle == NULL)
AzureIoTClient 55:59b527ab3452 1979 {
AzureIoTClient 55:59b527ab3452 1980 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 55:59b527ab3452 1981 LOG_ERROR_RESULT;
AzureIoTClient 55:59b527ab3452 1982 }
AzureIoTClient 55:59b527ab3452 1983 else
AzureIoTClient 55:59b527ab3452 1984 {
AzureIoTClient 55:59b527ab3452 1985 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 55:59b527ab3452 1986 if (inboundDeviceMethodCallback == NULL)
AzureIoTClient 55:59b527ab3452 1987 {
AzureIoTClient 62:5a4cdacf5090 1988 if (handleData->methodCallback.type == CALLBACK_TYPE_NONE)
AzureIoTClient 62:5a4cdacf5090 1989 {
AzureIoTClient 62:5a4cdacf5090 1990 /* Codes_SRS_IOTHUBCLIENT_LL_10_030: [ If deviceMethodCallback is NULL and the client is not subscribed to receive method calls, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ] */
AzureIoTClient 62:5a4cdacf5090 1991 LogError("not currently set to accept or process incoming messages.");
AzureIoTClient 62:5a4cdacf5090 1992 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 62:5a4cdacf5090 1993 }
AzureIoTClient 62:5a4cdacf5090 1994 else if (handleData->methodCallback.type == CALLBACK_TYPE_SYNC)
AzureIoTClient 62:5a4cdacf5090 1995 {
AzureIoTClient 62:5a4cdacf5090 1996 /* Codes_SRS_IOTHUBCLIENT_LL_10_031: [If the user has subscribed using IoTHubClient_LL_SetDeviceMethodCallback, IoTHubClient_LL_SetDeviceMethodCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR. ] */
AzureIoTClient 62:5a4cdacf5090 1997 LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetDeviceMethodCallback function.");
AzureIoTClient 62:5a4cdacf5090 1998 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 62:5a4cdacf5090 1999 }
AzureIoTClient 62:5a4cdacf5090 2000 else
AzureIoTClient 62:5a4cdacf5090 2001 {
AzureIoTClient 62:5a4cdacf5090 2002 /* Codes_SRS_IOTHUBCLIENT_LL_07_022: [ If inboundDeviceMethodCallback is NULL then IoTHubClient_LL_SetDeviceMethodCallback_Ex shall call the underlying layer's IoTHubTransport_Unsubscribe_DeviceMethod function and return IOTHUB_CLIENT_OK.] */
AzureIoTClient 62:5a4cdacf5090 2003 handleData->IoTHubTransport_Unsubscribe_DeviceMethod(handleData->transportHandle);
AzureIoTClient 62:5a4cdacf5090 2004 handleData->methodCallback.type = CALLBACK_TYPE_NONE;
AzureIoTClient 62:5a4cdacf5090 2005 handleData->methodCallback.callbackAsync = NULL;
AzureIoTClient 62:5a4cdacf5090 2006 handleData->methodCallback.userContextCallback = NULL;
AzureIoTClient 62:5a4cdacf5090 2007 result = IOTHUB_CLIENT_OK;
AzureIoTClient 62:5a4cdacf5090 2008 }
AzureIoTClient 55:59b527ab3452 2009 }
AzureIoTClient 55:59b527ab3452 2010 else
AzureIoTClient 55:59b527ab3452 2011 {
AzureIoTClient 62:5a4cdacf5090 2012 if (handleData->methodCallback.type == CALLBACK_TYPE_SYNC)
AzureIoTClient 55:59b527ab3452 2013 {
AzureIoTClient 62:5a4cdacf5090 2014 /* Codes_SRS_IOTHUBCLIENT_LL_10_031: [If the user has subscribed using IoTHubClient_LL_SetDeviceMethodCallback, IoTHubClient_LL_SetDeviceMethodCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR. ] */
AzureIoTClient 62:5a4cdacf5090 2015 LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetDeviceMethodCallback function before subscribing with IoTHubClient_LL_SetDeviceMethodCallback_Ex.");
AzureIoTClient 62:5a4cdacf5090 2016 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 55:59b527ab3452 2017 }
AzureIoTClient 55:59b527ab3452 2018 else
AzureIoTClient 55:59b527ab3452 2019 {
AzureIoTClient 62:5a4cdacf5090 2020 /* Codes_SRS_IOTHUBCLIENT_LL_07_023: [ If inboundDeviceMethodCallback is non-NULL then IoTHubClient_LL_SetDeviceMethodCallback_Ex shall call the underlying layer's IoTHubTransport_Subscribe_DeviceMethod function.]*/
AzureIoTClient 62:5a4cdacf5090 2021 if (handleData->IoTHubTransport_Subscribe_DeviceMethod(handleData->deviceHandle) == 0)
AzureIoTClient 62:5a4cdacf5090 2022 {
AzureIoTClient 62:5a4cdacf5090 2023 handleData->methodCallback.type = CALLBACK_TYPE_ASYNC;
AzureIoTClient 62:5a4cdacf5090 2024 handleData->methodCallback.callbackAsync = inboundDeviceMethodCallback;
AzureIoTClient 62:5a4cdacf5090 2025 handleData->methodCallback.callbackSync = NULL;
AzureIoTClient 62:5a4cdacf5090 2026 handleData->methodCallback.userContextCallback = userContextCallback;
AzureIoTClient 62:5a4cdacf5090 2027 result = IOTHUB_CLIENT_OK;
AzureIoTClient 62:5a4cdacf5090 2028 }
AzureIoTClient 62:5a4cdacf5090 2029 else
AzureIoTClient 62:5a4cdacf5090 2030 {
AzureIoTClient 62:5a4cdacf5090 2031 /* Codes_SRS_IOTHUBCLIENT_LL_07_025: [ If any error is encountered then IoTHubClient_LL_SetDeviceMethodCallback_Ex shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 62:5a4cdacf5090 2032 LogError("IoTHubTransport_Subscribe_DeviceMethod failed");
AzureIoTClient 62:5a4cdacf5090 2033 handleData->methodCallback.type = CALLBACK_TYPE_NONE;
AzureIoTClient 62:5a4cdacf5090 2034 handleData->methodCallback.callbackAsync = NULL;
AzureIoTClient 62:5a4cdacf5090 2035 handleData->methodCallback.callbackSync = NULL;
AzureIoTClient 62:5a4cdacf5090 2036 handleData->methodCallback.userContextCallback = NULL;
AzureIoTClient 62:5a4cdacf5090 2037 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 62:5a4cdacf5090 2038 }
AzureIoTClient 55:59b527ab3452 2039 }
AzureIoTClient 55:59b527ab3452 2040 }
AzureIoTClient 55:59b527ab3452 2041 }
AzureIoTClient 55:59b527ab3452 2042 return result;
AzureIoTClient 55:59b527ab3452 2043 }
AzureIoTClient 55:59b527ab3452 2044
AzureIoTClient 55:59b527ab3452 2045 IOTHUB_CLIENT_RESULT IoTHubClient_LL_DeviceMethodResponse(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, METHOD_HANDLE methodId, const unsigned char* response, size_t response_size, int status_response)
AzureIoTClient 55:59b527ab3452 2046 {
AzureIoTClient 55:59b527ab3452 2047 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 55:59b527ab3452 2048 /* Codes_SRS_IOTHUBCLIENT_LL_07_026: [ If handle or methodId is NULL then IoTHubClient_LL_DeviceMethodResponse shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 55:59b527ab3452 2049 if (iotHubClientHandle == NULL || methodId == NULL)
AzureIoTClient 55:59b527ab3452 2050 {
AzureIoTClient 55:59b527ab3452 2051 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 55:59b527ab3452 2052 LOG_ERROR_RESULT;
AzureIoTClient 55:59b527ab3452 2053 }
AzureIoTClient 55:59b527ab3452 2054 else
AzureIoTClient 55:59b527ab3452 2055 {
AzureIoTClient 55:59b527ab3452 2056 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 55:59b527ab3452 2057 /* Codes_SRS_IOTHUBCLIENT_LL_07_027: [ IoTHubClient_LL_DeviceMethodResponse shall call the IoTHubTransport_DeviceMethod_Response transport function.] */
AzureIoTClient 55:59b527ab3452 2058 if (handleData->IoTHubTransport_DeviceMethod_Response(handleData->deviceHandle, methodId, response, response_size, status_response) != 0)
AzureIoTClient 55:59b527ab3452 2059 {
AzureIoTClient 55:59b527ab3452 2060 LogError("IoTHubTransport_DeviceMethod_Response failed");
AzureIoTClient 55:59b527ab3452 2061 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 55:59b527ab3452 2062 }
AzureIoTClient 55:59b527ab3452 2063 else
AzureIoTClient 55:59b527ab3452 2064 {
AzureIoTClient 55:59b527ab3452 2065 result = IOTHUB_CLIENT_OK;
AzureIoTClient 55:59b527ab3452 2066 }
AzureIoTClient 55:59b527ab3452 2067 }
AzureIoTClient 55:59b527ab3452 2068 return result;
AzureIoTClient 55:59b527ab3452 2069 }
AzureIoTClient 55:59b527ab3452 2070
AzureIoTClient 44:33dd78697616 2071 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 42:448eecc3676e 2072 IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* destinationFileName, const unsigned char* source, size_t size)
AzureIoTClient 42:448eecc3676e 2073 {
AzureIoTClient 42:448eecc3676e 2074 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 42:448eecc3676e 2075 /*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 2076 /*Codes_SRS_IOTHUBCLIENT_LL_02_062: [ If destinationFileName is NULL then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/
AzureIoTClient 80:db5f5237bc95 2077 /*Codes_SRS_IOTHUBCLIENT_LL_02_063: [ If `source` is `NULL` and size is greater than 0 then `IoTHubClient_LL_UploadToBlob` shall fail and return `IOTHUB_CLIENT_INVALID_ARG`. ]*/
AzureIoTClient 42:448eecc3676e 2078 if (
AzureIoTClient 42:448eecc3676e 2079 (iotHubClientHandle == NULL) ||
AzureIoTClient 42:448eecc3676e 2080 (destinationFileName == NULL) ||
AzureIoTClient 42:448eecc3676e 2081 ((source == NULL) && (size >0))
AzureIoTClient 42:448eecc3676e 2082 )
AzureIoTClient 42:448eecc3676e 2083 {
AzureIoTClient 42:448eecc3676e 2084 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 2085 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 42:448eecc3676e 2086 }
AzureIoTClient 42:448eecc3676e 2087 else
AzureIoTClient 42:448eecc3676e 2088 {
AzureIoTClient 42:448eecc3676e 2089 result = IoTHubClient_LL_UploadToBlob_Impl(iotHubClientHandle->uploadToBlobHandle, destinationFileName, source, size);
AzureIoTClient 42:448eecc3676e 2090 }
AzureIoTClient 42:448eecc3676e 2091 return result;
AzureIoTClient 16:deba40344375 2092 }
AzureIoTClient 80:db5f5237bc95 2093
AzureIoTClient 80:db5f5237bc95 2094 IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadMultipleBlocksToBlob(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK getDataCallback, void* context)
AzureIoTClient 80:db5f5237bc95 2095 {
AzureIoTClient 80:db5f5237bc95 2096 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 80:db5f5237bc95 2097 /*Codes_SRS_IOTHUBCLIENT_LL_99_005: [ If `iotHubClientHandle` is `NULL` then `IoTHubClient_LL_UploadMultipleBlocksToBlob` shall fail and return `IOTHUB_CLIENT_INVALID_ARG`. ]*/
AzureIoTClient 80:db5f5237bc95 2098 /*Codes_SRS_IOTHUBCLIENT_LL_99_006: [ If `destinationFileName` is `NULL` then `IoTHubClient_LL_UploadMultipleBlocksToBlob` shall fail and return `IOTHUB_CLIENT_INVALID_ARG`. ]*/
AzureIoTClient 80:db5f5237bc95 2099 /*Codes_SRS_IOTHUBCLIENT_LL_99_007: [ If `getDataCallback` is `NULL` then `IoTHubClient_LL_UploadMultipleBlocksToBlob` shall fail and return `IOTHUB_CLIENT_INVALID_ARG`. ]*/
AzureIoTClient 80:db5f5237bc95 2100 if (
AzureIoTClient 80:db5f5237bc95 2101 (iotHubClientHandle == NULL) ||
AzureIoTClient 80:db5f5237bc95 2102 (destinationFileName == NULL) ||
AzureIoTClient 80:db5f5237bc95 2103 (getDataCallback == NULL)
AzureIoTClient 80:db5f5237bc95 2104 )
AzureIoTClient 80:db5f5237bc95 2105 {
AzureIoTClient 80:db5f5237bc95 2106 LogError("invalid parameters IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle=%p, const char* destinationFileName=%p, getDataCallback=%p", iotHubClientHandle, destinationFileName, getDataCallback);
AzureIoTClient 80:db5f5237bc95 2107 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 80:db5f5237bc95 2108 }
AzureIoTClient 80:db5f5237bc95 2109 else
AzureIoTClient 80:db5f5237bc95 2110 {
AzureIoTClient 80:db5f5237bc95 2111 result = IoTHubClient_LL_UploadMultipleBlocksToBlob_Impl(iotHubClientHandle->uploadToBlobHandle, destinationFileName, getDataCallback, context);
AzureIoTClient 80:db5f5237bc95 2112 }
AzureIoTClient 80:db5f5237bc95 2113 return result;
AzureIoTClient 80:db5f5237bc95 2114 }
AzureIoTClient 80:db5f5237bc95 2115
AzureIoTClient 80:db5f5237bc95 2116 #endif /* DONT_USE_UPLOADTOBLOB */