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
Diff: iothub_client_ll.c
- Revision:
- 63:1bf1c2d60aab
- Parent:
- 62:5a4cdacf5090
- Child:
- 66:a419827cb051
--- a/iothub_client_ll.c Fri Mar 24 16:35:32 2017 -0700 +++ b/iothub_client_ll.c Thu Apr 06 14:11:13 2017 -0700 @@ -120,6 +120,8 @@ static int create_blob_upload_module(IOTHUB_CLIENT_LL_HANDLE_DATA* handle_data, const IOTHUB_CLIENT_CONFIG* config) { int result; + (void)handle_data; + (void)config; #ifndef DONT_USE_UPLOADTOBLOB handle_data->uploadToBlobHandle = IoTHubClient_LL_UploadToBlob_Create(config); if (handle_data->uploadToBlobHandle == NULL) @@ -139,6 +141,7 @@ static void destroy_blob_upload_module(IOTHUB_CLIENT_LL_HANDLE_DATA* handle_data) { + (void)handle_data; #ifndef DONT_USE_UPLOADTOBLOB /*Codes_SRS_IOTHUBCLIENT_LL_02_046: [ If creating the TICK_COUNTER_HANDLE fails then IoTHubClient_LL_Create shall fail and return NULL. ]*/ IoTHubClient_LL_UploadToBlob_Destroy(handle_data->uploadToBlobHandle); @@ -160,12 +163,37 @@ memset(result, 0, sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA) ); - if (client_config != NULL) + const char* device_key; + const char* device_id; + const char* sas_token; + + if (device_config == NULL) + { + device_key = client_config->deviceKey; + device_id = client_config->deviceId; + sas_token = client_config->deviceSasToken; + } + else + { + device_key = device_config->deviceKey; + device_id = device_config->deviceId; + sas_token = device_config->deviceSasToken; + } + + /* Codes_SRS_IOTHUBCLIENT_LL_07_029: [ IoTHubClient_LL_Create shall create the Auth module with the device_key, device_id, and/or deviceSasToken values ] */ + if ((result->authorization_module = IoTHubClient_Auth_Create(device_key, device_id, sas_token) ) == NULL) + { + LogError("Failed create authorization module"); + free(result); + result = NULL; + } + else if (client_config != NULL) { IOTHUBTRANSPORT_CONFIG lowerLayerConfig; /*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.]*/ lowerLayerConfig.upperConfig = client_config; lowerLayerConfig.waitingToSend = &(result->waitingToSend); + lowerLayerConfig.auth_module_handle = result->authorization_module; setTransportProtocol(result, (TRANSPORT_PROVIDER*)client_config->protocol()); if ((result->transportHandle = result->IoTHubTransport_Create(&lowerLayerConfig)) == NULL) @@ -174,6 +202,7 @@ LogError("underlying transport failed"); destroy_blob_upload_module(result); tickcounter_destroy(result->tickCounter); + IoTHubClient_Auth_Destroy(result->authorization_module); free(result); result = NULL; } @@ -194,6 +223,7 @@ { /*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. ]*/ LogError("unable to determine the transport IoTHub name"); + IoTHubClient_Auth_Destroy(result->authorization_module); free(result); result = NULL; } @@ -207,6 +237,7 @@ { /*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. ]*/ LogError("unable to determine the IoTHub name"); + IoTHubClient_Auth_Destroy(result->authorization_module); free(result); result = NULL; } @@ -218,6 +249,7 @@ { /*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. ]*/ LogError("unable to malloc"); + IoTHubClient_Auth_Destroy(result->authorization_module); free(result); result = NULL; } @@ -246,13 +278,7 @@ if (result != NULL) { - if ((result->authorization_module = IoTHubClient_Auth_Create(config->deviceKey, config->deviceId, config->deviceSasToken) ) == NULL) - { - LogError("Failed create authorization module"); - free(result); - result = NULL; - } - else if (create_blob_upload_module(result, config) != 0) + if (create_blob_upload_module(result, config) != 0) { LogError("unable to create blob upload"); IoTHubClient_Auth_Destroy(result->authorization_module);