Microsoft Azure IoTHub client MQTT transport
Dependents: STM32F746_iothub_client_sample_mqtt FXOS8700CQ_To_Azure_IoT f767zi_mqtt FXOS8700CQ_To_Azure_IoT ... more
Diff: iothubtransport_mqtt_common.c
- Revision:
- 22:07fec4d325b6
- Parent:
- 21:167f8fcf6fb1
- Child:
- 23:84f4c36da8c1
--- a/iothubtransport_mqtt_common.c Thu Apr 06 14:11:00 2017 -0700 +++ b/iothubtransport_mqtt_common.c Mon May 08 10:50:18 2017 -0700 @@ -23,6 +23,7 @@ #include "azure_c_shared_utility/string_tokenizer.h" #include "azure_c_shared_utility/shared_util_options.h" +#include "azure_c_shared_utility/urlencode.h" #include "iothub_client_version.h" #include "iothubtransport_mqtt_common.h" @@ -1686,6 +1687,22 @@ if (result == 0) { + void* product_info; + STRING_HANDLE clone; + if ((IoTHubClient_LL_GetOption(transport_data->llClientHandle, OPTION_PRODUCT_INFO, &product_info) == IOTHUB_CLIENT_ERROR) || (product_info == NULL)) + { + clone = STRING_construct_sprintf("%s%%2F%s", CLIENT_DEVICE_TYPE_PREFIX, IOTHUB_SDK_VERSION); + } + else + { + clone = URL_Encode(product_info); + } + if (clone != NULL) + { + (void)STRING_concat_with_STRING(transport_data->configPassedThroughUsername, clone); + STRING_delete(clone); + } + MQTT_CLIENT_OPTIONS options = { 0 }; options.clientId = (char*)STRING_c_str(transport_data->device_id); options.willMessage = NULL; @@ -1824,8 +1841,7 @@ static STRING_HANDLE buildConfigForUsername(const IOTHUB_CLIENT_CONFIG* upperConfig) { - STRING_HANDLE result = STRING_construct_sprintf("%s.%s/%s/api-version=%s&DeviceClientType=%s%%2F%s", upperConfig->iotHubName, upperConfig->iotHubSuffix, upperConfig->deviceId, IOTHUB_API_VERSION, CLIENT_DEVICE_TYPE_PREFIX, IOTHUB_SDK_VERSION); - return result; + return STRING_construct_sprintf("%s.%s/%s/api-version=%s&DeviceClientType=", upperConfig->iotHubName, upperConfig->iotHubSuffix, upperConfig->deviceId, IOTHUB_API_VERSION); } static PMQTTTRANSPORT_HANDLE_DATA InitializeTransportHandleData(const IOTHUB_CLIENT_CONFIG* upperConfig, PDLIST_ENTRY waitingToSend, IOTHUB_AUTHORIZATION_HANDLE auth_module) @@ -2808,11 +2824,12 @@ { result = NULL; } - else + /*Codes_SRS_IOTHUB_MQTT_TRANSPORT_02_002: [ Otherwise IoTHubTransport_MQTT_Common_GetHostname shall return a non-NULL STRING_HANDLE containg the hostname. ]*/ + else if ((result = STRING_clone(((MQTTTRANSPORT_HANDLE_DATA*)(handle))->hostAddress)) == NULL) { - /*Codes_SRS_IOTHUB_MQTT_TRANSPORT_02_002: [ Otherwise IoTHubTransport_MQTT_Common_GetHostname shall return a non-NULL STRING_HANDLE containg the hostname. ]*/ - result = ((MQTTTRANSPORT_HANDLE_DATA*)handle)->hostAddress; + LogError("Cannot provide the target host name (STRING_clone failed)."); } + return result; }