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:
Tue Mar 20 10:29:00 2018 -0700
Revision:
85:de16c0a8a196
Parent:
82:f94e6bed4495
Child:
86:a1352899ea45
1.2.1

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