Microsoft Azure IoTHub client HTTP transport

Dependents:   iothub_client_sample_http simplesample_http temp_sensor_anomaly

This library implements the HTTP transport for Microsoft Azure IoTHub client. The code is replicated from https://github.com/Azure/azure-iot-sdks

Committer:
AzureIoTClient
Date:
Thu Oct 04 09:15:09 2018 -0700
Revision:
39:bc04888bf292
Parent:
38:01bf35934f1b
1.2.10

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 6:73793bae15ba 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 6:73793bae15ba 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 6:73793bae15ba 3
AzureIoTClient 6:73793bae15ba 4 #include <stdlib.h>
Azure.IoT Build 15:52602fffff8d 5 #include "azure_c_shared_utility/gballoc.h"
AzureIoTClient 6:73793bae15ba 6
AzureIoTClient 6:73793bae15ba 7 #include <time.h>
AzureIoTClient 22:e0add922c564 8 #include "iothub_client_options.h"
AzureIoTClient 11:495deb847d9c 9 #include "iothub_client_version.h"
AzureIoTClient 36:36c1e1ca5679 10 #include "internal/iothub_client_private.h"
Azure.IoT Build 15:52602fffff8d 11 #include "iothub_transport_ll.h"
AzureIoTClient 6:73793bae15ba 12 #include "iothubtransporthttp.h"
AzureIoTClient 36:36c1e1ca5679 13 #include "internal/iothubtransport.h"
AzureIoTClient 6:73793bae15ba 14
AzureIoTClient 28:f57de550d450 15 #include "azure_c_shared_utility/optimize_size.h"
Azure.IoT Build 15:52602fffff8d 16 #include "azure_c_shared_utility/httpapiexsas.h"
Azure.IoT Build 15:52602fffff8d 17 #include "azure_c_shared_utility/urlencode.h"
Azure.IoT Build 19:d4f9e872bf3e 18 #include "azure_c_shared_utility/xlogging.h"
Azure.IoT Build 15:52602fffff8d 19 #include "azure_c_shared_utility/httpapiex.h"
Azure.IoT Build 15:52602fffff8d 20 #include "azure_c_shared_utility/httpapiexsas.h"
Azure.IoT Build 15:52602fffff8d 21 #include "azure_c_shared_utility/strings.h"
Azure.IoT Build 15:52602fffff8d 22 #include "azure_c_shared_utility/base64.h"
Azure.IoT Build 15:52602fffff8d 23 #include "azure_c_shared_utility/doublylinkedlist.h"
Azure.IoT Build 15:52602fffff8d 24 #include "azure_c_shared_utility/vector.h"
Azure.IoT Build 15:52602fffff8d 25 #include "azure_c_shared_utility/httpheaders.h"
Azure.IoT Build 15:52602fffff8d 26 #include "azure_c_shared_utility/agenttime.h"
AzureIoTClient 6:73793bae15ba 27
AzureIoTClient 6:73793bae15ba 28 #define IOTHUB_APP_PREFIX "iothub-app-"
AzureIoTClient 32:4d4a226b072b 29 static const char* IOTHUB_MESSAGE_ID = "iothub-messageid";
AzureIoTClient 32:4d4a226b072b 30 static const char* IOTHUB_CORRELATION_ID = "iothub-correlationid";
AzureIoTClient 32:4d4a226b072b 31 static const char* IOTHUB_CONTENT_TYPE_D2C = "iothub-contenttype";
AzureIoTClient 32:4d4a226b072b 32 static const char* IOTHUB_CONTENT_ENCODING_D2C = "iothub-contentencoding";
AzureIoTClient 32:4d4a226b072b 33 static const char* IOTHUB_CONTENT_TYPE_C2D = "ContentType";
AzureIoTClient 32:4d4a226b072b 34 static const char* IOTHUB_CONTENT_ENCODING_C2D = "ContentEncoding";
AzureIoTClient 6:73793bae15ba 35
AzureIoTClient 6:73793bae15ba 36 #define CONTENT_TYPE "Content-Type"
AzureIoTClient 6:73793bae15ba 37 #define APPLICATION_OCTET_STREAM "application/octet-stream"
AzureIoTClient 6:73793bae15ba 38 #define APPLICATION_VND_MICROSOFT_IOTHUB_JSON "application/vnd.microsoft.iothub.json"
AzureIoTClient 6:73793bae15ba 39
AzureIoTClient 6:73793bae15ba 40 /*DEFAULT_GETMINIMUMPOLLINGTIME is the minimum time in seconds allowed between 2 consecutive GET issues to the service (GET=fetch messages)*/
AzureIoTClient 6:73793bae15ba 41 /*the default is 25 minutes*/
AzureIoTClient 38:01bf35934f1b 42 #define DEFAULT_GETMINIMUMPOLLINGTIME ((unsigned int)25*60)
AzureIoTClient 6:73793bae15ba 43
AzureIoTClient 6:73793bae15ba 44 #define MAXIMUM_MESSAGE_SIZE (255*1024-1)
AzureIoTClient 6:73793bae15ba 45 #define MAXIMUM_PAYLOAD_OVERHEAD 384
AzureIoTClient 6:73793bae15ba 46 #define MAXIMUM_PROPERTY_OVERHEAD 16
AzureIoTClient 6:73793bae15ba 47
AzureIoTClient 6:73793bae15ba 48 /*forward declaration*/
AzureIoTClient 6:73793bae15ba 49 static int appendMapToJSON(STRING_HANDLE existing, const char* const* keys, const char* const* values, size_t count);
AzureIoTClient 6:73793bae15ba 50
AzureIoTClient 6:73793bae15ba 51 typedef struct HTTPTRANSPORT_HANDLE_DATA_TAG
AzureIoTClient 6:73793bae15ba 52 {
Azure.IoT Build 19:d4f9e872bf3e 53 STRING_HANDLE hostName;
Azure.IoT Build 19:d4f9e872bf3e 54 HTTPAPIEX_HANDLE httpApiExHandle;
Azure.IoT Build 19:d4f9e872bf3e 55 bool doBatchedTransfers;
Azure.IoT Build 19:d4f9e872bf3e 56 unsigned int getMinimumPollingTime;
Azure.IoT Build 19:d4f9e872bf3e 57 VECTOR_HANDLE perDeviceList;
Azure.IoT Build 13:848d52f93daf 58 }HTTPTRANSPORT_HANDLE_DATA;
Azure.IoT Build 13:848d52f93daf 59
Azure.IoT Build 13:848d52f93daf 60 typedef struct HTTPTRANSPORT_PERDEVICE_DATA_TAG
Azure.IoT Build 13:848d52f93daf 61 {
Azure.IoT Build 19:d4f9e872bf3e 62 HTTPTRANSPORT_HANDLE_DATA* transportHandle;
Azure.IoT Build 13:848d52f93daf 63
Azure.IoT Build 19:d4f9e872bf3e 64 STRING_HANDLE deviceId;
Azure.IoT Build 19:d4f9e872bf3e 65 STRING_HANDLE deviceKey;
Azure.IoT Build 19:d4f9e872bf3e 66 STRING_HANDLE deviceSasToken;
Azure.IoT Build 19:d4f9e872bf3e 67 STRING_HANDLE eventHTTPrelativePath;
Azure.IoT Build 19:d4f9e872bf3e 68 STRING_HANDLE messageHTTPrelativePath;
Azure.IoT Build 19:d4f9e872bf3e 69 HTTP_HEADERS_HANDLE eventHTTPrequestHeaders;
Azure.IoT Build 19:d4f9e872bf3e 70 HTTP_HEADERS_HANDLE messageHTTPrequestHeaders;
Azure.IoT Build 19:d4f9e872bf3e 71 STRING_HANDLE abandonHTTPrelativePathBegin;
Azure.IoT Build 19:d4f9e872bf3e 72 HTTPAPIEX_SAS_HANDLE sasObject;
Azure.IoT Build 19:d4f9e872bf3e 73 bool DoWork_PullMessage;
Azure.IoT Build 19:d4f9e872bf3e 74 time_t lastPollTime;
Azure.IoT Build 19:d4f9e872bf3e 75 bool isFirstPoll;
Azure.IoT Build 13:848d52f93daf 76
AzureIoTClient 36:36c1e1ca5679 77 IOTHUB_CLIENT_CORE_LL_HANDLE iotHubClientHandle;
Azure.IoT Build 19:d4f9e872bf3e 78 PDLIST_ENTRY waitingToSend;
Azure.IoT Build 19:d4f9e872bf3e 79 DLIST_ENTRY eventConfirmations; /*holds items for event confirmations*/
Azure.IoT Build 13:848d52f93daf 80 } HTTPTRANSPORT_PERDEVICE_DATA;
AzureIoTClient 6:73793bae15ba 81
AzureIoTClient 29:e44b1f827914 82 typedef struct MESSAGE_DISPOSITION_CONTEXT_TAG
AzureIoTClient 29:e44b1f827914 83 {
AzureIoTClient 29:e44b1f827914 84 HTTPTRANSPORT_HANDLE_DATA* handleData;
AzureIoTClient 29:e44b1f827914 85 HTTPTRANSPORT_PERDEVICE_DATA* deviceData;
AzureIoTClient 29:e44b1f827914 86 char* etagValue;
AzureIoTClient 29:e44b1f827914 87 } MESSAGE_DISPOSITION_CONTEXT;
AzureIoTClient 29:e44b1f827914 88
AzureIoTClient 29:e44b1f827914 89 DEFINE_ENUM_STRINGS(IOTHUBMESSAGE_DISPOSITION_RESULT, IOTHUBMESSAGE_DISPOSITION_RESULT_VALUES);
AzureIoTClient 29:e44b1f827914 90
Azure.IoT Build 13:848d52f93daf 91 static void destroy_eventHTTPrelativePath(HTTPTRANSPORT_PERDEVICE_DATA* handleData)
AzureIoTClient 6:73793bae15ba 92 {
Azure.IoT Build 19:d4f9e872bf3e 93 STRING_delete(handleData->eventHTTPrelativePath);
Azure.IoT Build 19:d4f9e872bf3e 94 handleData->eventHTTPrelativePath = NULL;
AzureIoTClient 6:73793bae15ba 95 }
AzureIoTClient 6:73793bae15ba 96
Azure.IoT Build 13:848d52f93daf 97 static bool create_eventHTTPrelativePath(HTTPTRANSPORT_PERDEVICE_DATA* handleData, const char * deviceId)
AzureIoTClient 6:73793bae15ba 98 {
Azure.IoT Build 19:d4f9e872bf3e 99 /*Codes_SRS_TRANSPORTMULTITHTTP_17_017: [ IoTHubTransportHttp_Register shall create an immutable string (further called "event HTTP relative path") from the following pieces: "/devices/" + URL_ENCODED(deviceId) + "/messages/events" + APIVERSION. ]*/
Azure.IoT Build 19:d4f9e872bf3e 100 bool result;
Azure.IoT Build 19:d4f9e872bf3e 101 STRING_HANDLE urlEncodedDeviceId;
Azure.IoT Build 19:d4f9e872bf3e 102 handleData->eventHTTPrelativePath = STRING_construct("/devices/");
Azure.IoT Build 19:d4f9e872bf3e 103 if (handleData->eventHTTPrelativePath == NULL)
Azure.IoT Build 19:d4f9e872bf3e 104 {
Azure.IoT Build 19:d4f9e872bf3e 105 LogError("STRING_construct failed.");
Azure.IoT Build 19:d4f9e872bf3e 106 result = false;
Azure.IoT Build 19:d4f9e872bf3e 107 }
Azure.IoT Build 19:d4f9e872bf3e 108 else
Azure.IoT Build 19:d4f9e872bf3e 109 {
Azure.IoT Build 19:d4f9e872bf3e 110 if (!(
Azure.IoT Build 19:d4f9e872bf3e 111 ((urlEncodedDeviceId = URL_EncodeString(deviceId)) != NULL) &&
Azure.IoT Build 19:d4f9e872bf3e 112 (STRING_concat_with_STRING(handleData->eventHTTPrelativePath, urlEncodedDeviceId) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 113 (STRING_concat(handleData->eventHTTPrelativePath, EVENT_ENDPOINT API_VERSION) == 0)
Azure.IoT Build 19:d4f9e872bf3e 114 ))
Azure.IoT Build 19:d4f9e872bf3e 115 {
Azure.IoT Build 19:d4f9e872bf3e 116 /*Codes_SRS_TRANSPORTMULTITHTTP_17_018: [ If creating the string fail for any reason then IoTHubTransportHttp_Register shall fail and return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 117 destroy_eventHTTPrelativePath(handleData);
Azure.IoT Build 19:d4f9e872bf3e 118 LogError("Creating HTTP event relative path failed.");
Azure.IoT Build 19:d4f9e872bf3e 119 result = false;
Azure.IoT Build 19:d4f9e872bf3e 120 }
Azure.IoT Build 19:d4f9e872bf3e 121 else
Azure.IoT Build 19:d4f9e872bf3e 122 {
Azure.IoT Build 19:d4f9e872bf3e 123 result = true;
Azure.IoT Build 19:d4f9e872bf3e 124 }
Azure.IoT Build 19:d4f9e872bf3e 125 STRING_delete(urlEncodedDeviceId);
Azure.IoT Build 19:d4f9e872bf3e 126 }
Azure.IoT Build 19:d4f9e872bf3e 127 return result;
AzureIoTClient 6:73793bae15ba 128 }
AzureIoTClient 6:73793bae15ba 129
Azure.IoT Build 13:848d52f93daf 130 static void destroy_messageHTTPrelativePath(HTTPTRANSPORT_PERDEVICE_DATA* handleData)
AzureIoTClient 6:73793bae15ba 131 {
Azure.IoT Build 19:d4f9e872bf3e 132 STRING_delete(handleData->messageHTTPrelativePath);
Azure.IoT Build 19:d4f9e872bf3e 133 handleData->messageHTTPrelativePath = NULL;
AzureIoTClient 6:73793bae15ba 134 }
AzureIoTClient 6:73793bae15ba 135
Azure.IoT Build 13:848d52f93daf 136 static bool create_messageHTTPrelativePath(HTTPTRANSPORT_PERDEVICE_DATA* handleData, const char * deviceId)
AzureIoTClient 6:73793bae15ba 137 {
Azure.IoT Build 19:d4f9e872bf3e 138 bool result;
Azure.IoT Build 19:d4f9e872bf3e 139 handleData->messageHTTPrelativePath = STRING_construct("/devices/");
Azure.IoT Build 19:d4f9e872bf3e 140 if (handleData->messageHTTPrelativePath == NULL)
Azure.IoT Build 19:d4f9e872bf3e 141 {
Azure.IoT Build 19:d4f9e872bf3e 142 LogError("STRING_construct failed.");
Azure.IoT Build 19:d4f9e872bf3e 143 result = false;
Azure.IoT Build 19:d4f9e872bf3e 144 }
Azure.IoT Build 19:d4f9e872bf3e 145 else
Azure.IoT Build 19:d4f9e872bf3e 146 {
Azure.IoT Build 19:d4f9e872bf3e 147 STRING_HANDLE urlEncodedDeviceId;
Azure.IoT Build 19:d4f9e872bf3e 148 /*Codes_SRS_TRANSPORTMULTITHTTP_17_019: [ IoTHubTransportHttp_Register shall create an immutable string (further called "message HTTP relative path") from the following pieces: "/devices/" + URL_ENCODED(deviceId) + "/messages/devicebound" + APIVERSION. ]*/
Azure.IoT Build 19:d4f9e872bf3e 149 if (!(
Azure.IoT Build 19:d4f9e872bf3e 150 ((urlEncodedDeviceId = URL_EncodeString(deviceId)) != NULL) &&
Azure.IoT Build 19:d4f9e872bf3e 151 (STRING_concat_with_STRING(handleData->messageHTTPrelativePath, urlEncodedDeviceId) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 152 (STRING_concat(handleData->messageHTTPrelativePath, MESSAGE_ENDPOINT_HTTP API_VERSION) == 0)
Azure.IoT Build 19:d4f9e872bf3e 153 ))
Azure.IoT Build 19:d4f9e872bf3e 154 {
Azure.IoT Build 19:d4f9e872bf3e 155 /*Codes_SRS_TRANSPORTMULTITHTTP_17_020: [ If creating the message HTTP relative path fails, then IoTHubTransportHttp_Register shall fail and return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 156 LogError("Creating HTTP message relative path failed.");
Azure.IoT Build 19:d4f9e872bf3e 157 result = false;
Azure.IoT Build 19:d4f9e872bf3e 158 destroy_messageHTTPrelativePath(handleData);
Azure.IoT Build 19:d4f9e872bf3e 159 }
Azure.IoT Build 19:d4f9e872bf3e 160 else
Azure.IoT Build 19:d4f9e872bf3e 161 {
Azure.IoT Build 19:d4f9e872bf3e 162 result = true;
Azure.IoT Build 19:d4f9e872bf3e 163 }
Azure.IoT Build 19:d4f9e872bf3e 164 STRING_delete(urlEncodedDeviceId);
Azure.IoT Build 19:d4f9e872bf3e 165 }
AzureIoTClient 17:7ef88cde801f 166
Azure.IoT Build 19:d4f9e872bf3e 167 return result;
AzureIoTClient 6:73793bae15ba 168 }
AzureIoTClient 6:73793bae15ba 169
Azure.IoT Build 13:848d52f93daf 170 static void destroy_eventHTTPrequestHeaders(HTTPTRANSPORT_PERDEVICE_DATA* handleData)
AzureIoTClient 6:73793bae15ba 171 {
Azure.IoT Build 19:d4f9e872bf3e 172 HTTPHeaders_Free(handleData->eventHTTPrequestHeaders);
Azure.IoT Build 19:d4f9e872bf3e 173 handleData->eventHTTPrequestHeaders = NULL;
AzureIoTClient 6:73793bae15ba 174 }
AzureIoTClient 6:73793bae15ba 175
AzureIoTClient 36:36c1e1ca5679 176 static HTTP_HEADERS_RESULT addUserAgentHeaderInfo(IOTHUB_CLIENT_CORE_LL_HANDLE hClient, HTTP_HEADERS_HANDLE eventHTTPrequestHeaders)
AzureIoTClient 30:655054f86a6e 177 {
AzureIoTClient 30:655054f86a6e 178 void* product_info;
AzureIoTClient 30:655054f86a6e 179 HTTP_HEADERS_RESULT result;
AzureIoTClient 36:36c1e1ca5679 180 if ((IoTHubClientCore_LL_GetOption(hClient, OPTION_PRODUCT_INFO, &product_info) == IOTHUB_CLIENT_ERROR) || (product_info == NULL))
AzureIoTClient 30:655054f86a6e 181 {
AzureIoTClient 30:655054f86a6e 182 result = HTTPHeaders_AddHeaderNameValuePair(eventHTTPrequestHeaders, "User-Agent", CLIENT_DEVICE_TYPE_PREFIX CLIENT_DEVICE_BACKSLASH IOTHUB_SDK_VERSION);
AzureIoTClient 30:655054f86a6e 183 }
AzureIoTClient 30:655054f86a6e 184 else
AzureIoTClient 30:655054f86a6e 185 {
AzureIoTClient 30:655054f86a6e 186 result = HTTPHeaders_AddHeaderNameValuePair(eventHTTPrequestHeaders, "User-Agent", STRING_c_str((STRING_HANDLE)product_info));
AzureIoTClient 30:655054f86a6e 187 }
AzureIoTClient 30:655054f86a6e 188 return result;
AzureIoTClient 30:655054f86a6e 189 }
AzureIoTClient 30:655054f86a6e 190
AzureIoTClient 20:b652f2e4cccf 191 static bool create_eventHTTPrequestHeaders(HTTPTRANSPORT_PERDEVICE_DATA* handleData, const char * deviceId, bool is_x509_used)
Azure.IoT Build 13:848d52f93daf 192 {
Azure.IoT Build 19:d4f9e872bf3e 193 /*Codes_SRS_TRANSPORTMULTITHTTP_17_021: [ IoTHubTransportHttp_Register shall create a set of HTTP headers (further called "event HTTP request headers") consisting of the following fixed field names and values: "iothub-to":"/devices/" + URL_ENCODED(deviceId) + "/messages/events"; "Authorization":""
Azure.IoT Build 19:d4f9e872bf3e 194 "Accept":"application/json"
Azure.IoT Build 19:d4f9e872bf3e 195 "Connection":"Keep-Alive" ]*/
Azure.IoT Build 19:d4f9e872bf3e 196 bool result;
Azure.IoT Build 19:d4f9e872bf3e 197 handleData->eventHTTPrequestHeaders = HTTPHeaders_Alloc();
Azure.IoT Build 19:d4f9e872bf3e 198 if (handleData->eventHTTPrequestHeaders == NULL)
Azure.IoT Build 19:d4f9e872bf3e 199 {
Azure.IoT Build 19:d4f9e872bf3e 200 LogError("HTTPHeaders_Alloc failed.");
Azure.IoT Build 19:d4f9e872bf3e 201 result = false;
Azure.IoT Build 19:d4f9e872bf3e 202 }
Azure.IoT Build 19:d4f9e872bf3e 203 else
Azure.IoT Build 19:d4f9e872bf3e 204 {
Azure.IoT Build 19:d4f9e872bf3e 205 STRING_HANDLE temp = STRING_construct("/devices/");
Azure.IoT Build 19:d4f9e872bf3e 206 if (temp == NULL)
Azure.IoT Build 19:d4f9e872bf3e 207 {
Azure.IoT Build 19:d4f9e872bf3e 208 LogError("STRING_construct failed.");
Azure.IoT Build 19:d4f9e872bf3e 209 result = false;
Azure.IoT Build 19:d4f9e872bf3e 210 destroy_eventHTTPrequestHeaders(handleData);
Azure.IoT Build 19:d4f9e872bf3e 211 }
Azure.IoT Build 19:d4f9e872bf3e 212 else
Azure.IoT Build 19:d4f9e872bf3e 213 {
Azure.IoT Build 19:d4f9e872bf3e 214 STRING_HANDLE urlEncodedDeviceId;
Azure.IoT Build 19:d4f9e872bf3e 215 if (!(
Azure.IoT Build 19:d4f9e872bf3e 216 ((urlEncodedDeviceId = URL_EncodeString(deviceId)) != NULL) &&
Azure.IoT Build 19:d4f9e872bf3e 217 (STRING_concat_with_STRING(temp, urlEncodedDeviceId) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 218 (STRING_concat(temp, EVENT_ENDPOINT) == 0)
Azure.IoT Build 19:d4f9e872bf3e 219 ))
Azure.IoT Build 19:d4f9e872bf3e 220 {
Azure.IoT Build 19:d4f9e872bf3e 221 LogError("deviceId construction failed.");
Azure.IoT Build 19:d4f9e872bf3e 222 result = false;
Azure.IoT Build 19:d4f9e872bf3e 223 destroy_eventHTTPrequestHeaders(handleData);
Azure.IoT Build 19:d4f9e872bf3e 224 }
Azure.IoT Build 19:d4f9e872bf3e 225 else
Azure.IoT Build 19:d4f9e872bf3e 226 {
Azure.IoT Build 19:d4f9e872bf3e 227 if (!(
Azure.IoT Build 19:d4f9e872bf3e 228 (HTTPHeaders_AddHeaderNameValuePair(handleData->eventHTTPrequestHeaders, "iothub-to", STRING_c_str(temp)) == HTTP_HEADERS_OK) &&
AzureIoTClient 20:b652f2e4cccf 229 (is_x509_used || (HTTPHeaders_AddHeaderNameValuePair(handleData->eventHTTPrequestHeaders, "Authorization", " ") == HTTP_HEADERS_OK)) &&
Azure.IoT Build 19:d4f9e872bf3e 230 (HTTPHeaders_AddHeaderNameValuePair(handleData->eventHTTPrequestHeaders, "Accept", "application/json") == HTTP_HEADERS_OK) &&
Azure.IoT Build 19:d4f9e872bf3e 231 (HTTPHeaders_AddHeaderNameValuePair(handleData->eventHTTPrequestHeaders, "Connection", "Keep-Alive") == HTTP_HEADERS_OK) &&
AzureIoTClient 30:655054f86a6e 232 (addUserAgentHeaderInfo(handleData->iotHubClientHandle, handleData->eventHTTPrequestHeaders) == HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 233 ))
Azure.IoT Build 19:d4f9e872bf3e 234 {
Azure.IoT Build 19:d4f9e872bf3e 235 /*Codes_SRS_TRANSPORTMULTITHTTP_17_022: [ If creating the event HTTP request headers fails, then IoTHubTransportHttp_Register shall fail and return NULL.] */
Azure.IoT Build 19:d4f9e872bf3e 236 LogError("adding header properties failed.");
Azure.IoT Build 19:d4f9e872bf3e 237 result = false;
Azure.IoT Build 19:d4f9e872bf3e 238 destroy_eventHTTPrequestHeaders(handleData);
Azure.IoT Build 19:d4f9e872bf3e 239 }
Azure.IoT Build 19:d4f9e872bf3e 240 else
Azure.IoT Build 19:d4f9e872bf3e 241 {
Azure.IoT Build 19:d4f9e872bf3e 242 result = true;
Azure.IoT Build 19:d4f9e872bf3e 243 }
Azure.IoT Build 19:d4f9e872bf3e 244 }
Azure.IoT Build 19:d4f9e872bf3e 245 STRING_delete(urlEncodedDeviceId);
Azure.IoT Build 19:d4f9e872bf3e 246 STRING_delete(temp);
Azure.IoT Build 19:d4f9e872bf3e 247 }
Azure.IoT Build 19:d4f9e872bf3e 248 }
Azure.IoT Build 19:d4f9e872bf3e 249 return result;
Azure.IoT Build 13:848d52f93daf 250 }
Azure.IoT Build 13:848d52f93daf 251
Azure.IoT Build 13:848d52f93daf 252 static void destroy_messageHTTPrequestHeaders(HTTPTRANSPORT_PERDEVICE_DATA* handleData)
AzureIoTClient 17:7ef88cde801f 253 {
Azure.IoT Build 19:d4f9e872bf3e 254 HTTPHeaders_Free(handleData->messageHTTPrequestHeaders);
Azure.IoT Build 19:d4f9e872bf3e 255 handleData->messageHTTPrequestHeaders = NULL;
Azure.IoT Build 13:848d52f93daf 256 }
Azure.IoT Build 13:848d52f93daf 257
AzureIoTClient 20:b652f2e4cccf 258 static bool create_messageHTTPrequestHeaders(HTTPTRANSPORT_PERDEVICE_DATA* handleData, bool is_x509_used)
Azure.IoT Build 13:848d52f93daf 259 {
Azure.IoT Build 19:d4f9e872bf3e 260 /*Codes_SRS_TRANSPORTMULTITHTTP_17_132: [ IoTHubTransportHttp_Register shall create a set of HTTP headers (further called "message HTTP request headers") consisting of the following fixed field names and values:
Azure.IoT Build 19:d4f9e872bf3e 261 "Authorization": "" ]*/
Azure.IoT Build 19:d4f9e872bf3e 262 bool result;
Azure.IoT Build 19:d4f9e872bf3e 263 handleData->messageHTTPrequestHeaders = HTTPHeaders_Alloc();
Azure.IoT Build 19:d4f9e872bf3e 264 if (handleData->messageHTTPrequestHeaders == NULL)
Azure.IoT Build 19:d4f9e872bf3e 265 {
Azure.IoT Build 19:d4f9e872bf3e 266 LogError("HTTPHeaders_Alloc failed.");
Azure.IoT Build 19:d4f9e872bf3e 267 result = false;
Azure.IoT Build 19:d4f9e872bf3e 268 }
Azure.IoT Build 19:d4f9e872bf3e 269 else
Azure.IoT Build 19:d4f9e872bf3e 270 {
Azure.IoT Build 19:d4f9e872bf3e 271 if (!(
AzureIoTClient 33:270c65ccd77d 272 (addUserAgentHeaderInfo(handleData->iotHubClientHandle, handleData->messageHTTPrequestHeaders) == HTTP_HEADERS_OK) &&
AzureIoTClient 20:b652f2e4cccf 273 (is_x509_used || (HTTPHeaders_AddHeaderNameValuePair(handleData->messageHTTPrequestHeaders, "Authorization", " ") == HTTP_HEADERS_OK))
Azure.IoT Build 19:d4f9e872bf3e 274 ))
Azure.IoT Build 19:d4f9e872bf3e 275 {
Azure.IoT Build 19:d4f9e872bf3e 276 /*Codes_SRS_TRANSPORTMULTITHTTP_17_023: [ If creating message HTTP request headers then IoTHubTransportHttp_Register shall fail and return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 277 destroy_messageHTTPrequestHeaders(handleData);
Azure.IoT Build 19:d4f9e872bf3e 278 LogError("adding header properties failed.");
Azure.IoT Build 19:d4f9e872bf3e 279 result = false;
Azure.IoT Build 19:d4f9e872bf3e 280 }
Azure.IoT Build 19:d4f9e872bf3e 281 else
Azure.IoT Build 19:d4f9e872bf3e 282 {
Azure.IoT Build 19:d4f9e872bf3e 283 result = true;
Azure.IoT Build 19:d4f9e872bf3e 284 }
Azure.IoT Build 19:d4f9e872bf3e 285 }
Azure.IoT Build 19:d4f9e872bf3e 286 return result;
AzureIoTClient 6:73793bae15ba 287 }
AzureIoTClient 6:73793bae15ba 288
Azure.IoT Build 13:848d52f93daf 289 static void destroy_abandonHTTPrelativePathBegin(HTTPTRANSPORT_PERDEVICE_DATA* handleData)
Azure.IoT Build 13:848d52f93daf 290 {
Azure.IoT Build 19:d4f9e872bf3e 291 STRING_delete(handleData->abandonHTTPrelativePathBegin);
Azure.IoT Build 19:d4f9e872bf3e 292 handleData->abandonHTTPrelativePathBegin = NULL;
Azure.IoT Build 13:848d52f93daf 293 }
Azure.IoT Build 13:848d52f93daf 294
Azure.IoT Build 13:848d52f93daf 295 static bool create_abandonHTTPrelativePathBegin(HTTPTRANSPORT_PERDEVICE_DATA* handleData, const char * deviceId)
Azure.IoT Build 13:848d52f93daf 296 {
Azure.IoT Build 19:d4f9e872bf3e 297 /*Codes_SRS_TRANSPORTMULTITHTTP_17_024: [ IoTHubTransportHttp_Register shall create a STRING containing: "/devices/" + URL_ENCODED(device id) +"/messages/deviceBound/" called abandonHTTPrelativePathBegin. ]*/
Azure.IoT Build 19:d4f9e872bf3e 298 bool result;
Azure.IoT Build 19:d4f9e872bf3e 299 handleData->abandonHTTPrelativePathBegin = STRING_construct("/devices/");
Azure.IoT Build 19:d4f9e872bf3e 300 if (handleData->abandonHTTPrelativePathBegin == NULL)
Azure.IoT Build 19:d4f9e872bf3e 301 {
Azure.IoT Build 19:d4f9e872bf3e 302 result = false;
Azure.IoT Build 19:d4f9e872bf3e 303 }
Azure.IoT Build 19:d4f9e872bf3e 304 else
Azure.IoT Build 19:d4f9e872bf3e 305 {
Azure.IoT Build 19:d4f9e872bf3e 306 STRING_HANDLE urlEncodedDeviceId;
Azure.IoT Build 19:d4f9e872bf3e 307 if (!(
Azure.IoT Build 19:d4f9e872bf3e 308 ((urlEncodedDeviceId = URL_EncodeString(deviceId)) != NULL) &&
Azure.IoT Build 19:d4f9e872bf3e 309 (STRING_concat_with_STRING(handleData->abandonHTTPrelativePathBegin, urlEncodedDeviceId) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 310 (STRING_concat(handleData->abandonHTTPrelativePathBegin, MESSAGE_ENDPOINT_HTTP_ETAG) == 0)
Azure.IoT Build 19:d4f9e872bf3e 311 ))
Azure.IoT Build 19:d4f9e872bf3e 312 {
Azure.IoT Build 19:d4f9e872bf3e 313 /*Codes_SRS_TRANSPORTMULTITHTTP_17_025: [ If creating the abandonHTTPrelativePathBegin fails then IoTHubTransportHttp_Register shall fail and return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 314 LogError("unable to create abandon path string.");
Azure.IoT Build 19:d4f9e872bf3e 315 STRING_delete(handleData->abandonHTTPrelativePathBegin);
Azure.IoT Build 19:d4f9e872bf3e 316 result = false;
Azure.IoT Build 19:d4f9e872bf3e 317 }
Azure.IoT Build 19:d4f9e872bf3e 318 else
Azure.IoT Build 19:d4f9e872bf3e 319 {
Azure.IoT Build 19:d4f9e872bf3e 320 result = true;
Azure.IoT Build 19:d4f9e872bf3e 321 }
Azure.IoT Build 19:d4f9e872bf3e 322 STRING_delete(urlEncodedDeviceId);
Azure.IoT Build 19:d4f9e872bf3e 323 }
Azure.IoT Build 19:d4f9e872bf3e 324 return result;
Azure.IoT Build 13:848d52f93daf 325 }
Azure.IoT Build 13:848d52f93daf 326
Azure.IoT Build 13:848d52f93daf 327 static void destroy_SASObject(HTTPTRANSPORT_PERDEVICE_DATA* handleData)
Azure.IoT Build 13:848d52f93daf 328 {
Azure.IoT Build 19:d4f9e872bf3e 329 HTTPAPIEX_SAS_Destroy(handleData->sasObject);
Azure.IoT Build 19:d4f9e872bf3e 330 handleData->sasObject = NULL;
Azure.IoT Build 13:848d52f93daf 331 }
Azure.IoT Build 13:848d52f93daf 332
Azure.IoT Build 13:848d52f93daf 333 static bool create_deviceSASObject(HTTPTRANSPORT_PERDEVICE_DATA* handleData, STRING_HANDLE hostName, const char * deviceId, const char * deviceKey)
Azure.IoT Build 13:848d52f93daf 334 {
Azure.IoT Build 19:d4f9e872bf3e 335 STRING_HANDLE keyName;
Azure.IoT Build 19:d4f9e872bf3e 336 bool result;
Azure.IoT Build 19:d4f9e872bf3e 337 /*Codes_SRS_TRANSPORTMULTITHTTP_17_026: [IoTHubTransportHttp_Create shall invoke URL_EncodeString with an argument of device id.]*/
Azure.IoT Build 19:d4f9e872bf3e 338 keyName = URL_EncodeString(deviceId);
Azure.IoT Build 19:d4f9e872bf3e 339 if (keyName == NULL)
Azure.IoT Build 19:d4f9e872bf3e 340 {
Azure.IoT Build 19:d4f9e872bf3e 341 /*Codes_SRS_TRANSPORTMULTITHTTP_17_027: [If the encode fails then IoTHubTransportHttp_Create shall fail and return NULL.]*/
Azure.IoT Build 19:d4f9e872bf3e 342 LogError("URL_EncodeString keyname failed");
Azure.IoT Build 19:d4f9e872bf3e 343 result = false;
Azure.IoT Build 19:d4f9e872bf3e 344 }
Azure.IoT Build 19:d4f9e872bf3e 345 else
Azure.IoT Build 19:d4f9e872bf3e 346 {
Azure.IoT Build 19:d4f9e872bf3e 347 STRING_HANDLE uriResource;
Azure.IoT Build 19:d4f9e872bf3e 348 /*Codes_SRS_TRANSPORTMULTITHTTP_17_028: [IoTHubTransportHttp_Create shall invoke STRING_clone using the previously created hostname.]*/
Azure.IoT Build 19:d4f9e872bf3e 349 uriResource = STRING_clone(hostName);
Azure.IoT Build 19:d4f9e872bf3e 350 /*Codes_SRS_TRANSPORTMULTITHTTP_17_029: [If the clone fails then IoTHubTransportHttp_Create shall fail and return NULL.]*/
Azure.IoT Build 19:d4f9e872bf3e 351 if (uriResource != NULL)
Azure.IoT Build 19:d4f9e872bf3e 352 {
Azure.IoT Build 19:d4f9e872bf3e 353 /*Codes_SRS_TRANSPORTMULTITHTTP_17_030: [IoTHubTransportHttp_Create shall invoke STRING_concat with arguments uriResource and the string "/devices/".]*/
Azure.IoT Build 19:d4f9e872bf3e 354 /*Codes_SRS_TRANSPORTMULTITHTTP_17_141: [If the concat fails then IoTHubTransportHttp_Create shall fail and return NULL.]*/
Azure.IoT Build 19:d4f9e872bf3e 355 /*Codes_SRS_TRANSPORTMULTITHTTP_17_031: [IoTHubTransportHttp_Create shall invoke STRING_concat_with_STRING with arguments uriResource and keyName.]*/
Azure.IoT Build 19:d4f9e872bf3e 356 /*Codes_SRS_TRANSPORTMULTITHTTP_17_032: [If the STRING_concat_with_STRING fails then IoTHubTransportHttp_Create shall fail and return NULL.]*/
Azure.IoT Build 19:d4f9e872bf3e 357 if ((STRING_concat(uriResource, "/devices/") == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 358 (STRING_concat_with_STRING(uriResource, keyName) == 0))
Azure.IoT Build 19:d4f9e872bf3e 359 {
Azure.IoT Build 19:d4f9e872bf3e 360 /*Codes_SRS_TRANSPORTMULTITHTTP_17_033: [IoTHubTransportHttp_Create shall invoke STRING_construct with an argument of config->upperConfig->deviceKey.]*/
Azure.IoT Build 19:d4f9e872bf3e 361 /*Codes_SRS_TRANSPORTMULTITHTTP_17_034: [If the STRING_construct fails then IoTHubTransportHttp_Create shall fail and return NULL.]*/
Azure.IoT Build 19:d4f9e872bf3e 362 STRING_HANDLE key = STRING_construct(deviceKey);
Azure.IoT Build 19:d4f9e872bf3e 363 if (key != NULL)
Azure.IoT Build 19:d4f9e872bf3e 364 {
Azure.IoT Build 19:d4f9e872bf3e 365 /*Codes_SRS_TRANSPORTMULTITHTTP_17_035: [The keyName is shortened to zero length, if that fails then IoTHubTransportHttp_Create shall fail and return NULL.]*/
Azure.IoT Build 19:d4f9e872bf3e 366 if (STRING_empty(keyName) != 0)
Azure.IoT Build 19:d4f9e872bf3e 367 {
Azure.IoT Build 19:d4f9e872bf3e 368 LogError("Unable to form the device key name for the SAS");
Azure.IoT Build 19:d4f9e872bf3e 369 result = false;
Azure.IoT Build 19:d4f9e872bf3e 370 }
Azure.IoT Build 19:d4f9e872bf3e 371 else
Azure.IoT Build 19:d4f9e872bf3e 372 {
Azure.IoT Build 19:d4f9e872bf3e 373 /*Codes_SRS_TRANSPORTMULTITHTTP_17_036: [IoTHubTransportHttp_Create shall invoke HTTPAPIEX_SAS_Create with arguments key, uriResource, and zero length keyName.]*/
Azure.IoT Build 19:d4f9e872bf3e 374 /*Codes_SRS_TRANSPORTMULTITHTTP_17_037: [If the HTTPAPIEX_SAS_Create fails then IoTHubTransportHttp_Create shall fail and return NULL.]*/
Azure.IoT Build 19:d4f9e872bf3e 375 handleData->sasObject = HTTPAPIEX_SAS_Create(key, uriResource, keyName);
Azure.IoT Build 19:d4f9e872bf3e 376 result = (handleData->sasObject != NULL) ? (true) : (false);
Azure.IoT Build 19:d4f9e872bf3e 377 }
Azure.IoT Build 19:d4f9e872bf3e 378 STRING_delete(key);
Azure.IoT Build 19:d4f9e872bf3e 379 }
Azure.IoT Build 19:d4f9e872bf3e 380 else
Azure.IoT Build 19:d4f9e872bf3e 381 {
Azure.IoT Build 19:d4f9e872bf3e 382 LogError("STRING_construct Key failed");
Azure.IoT Build 19:d4f9e872bf3e 383 result = false;
Azure.IoT Build 19:d4f9e872bf3e 384 }
Azure.IoT Build 19:d4f9e872bf3e 385 }
Azure.IoT Build 19:d4f9e872bf3e 386 else
Azure.IoT Build 19:d4f9e872bf3e 387 {
Azure.IoT Build 19:d4f9e872bf3e 388 LogError("STRING_concat uri resource failed");
Azure.IoT Build 19:d4f9e872bf3e 389 result = false;
Azure.IoT Build 19:d4f9e872bf3e 390 }
Azure.IoT Build 19:d4f9e872bf3e 391 STRING_delete(uriResource);
Azure.IoT Build 19:d4f9e872bf3e 392 }
Azure.IoT Build 19:d4f9e872bf3e 393 else
Azure.IoT Build 19:d4f9e872bf3e 394 {
Azure.IoT Build 19:d4f9e872bf3e 395 LogError("STRING_staticclone uri resource failed");
Azure.IoT Build 19:d4f9e872bf3e 396 result = false;
Azure.IoT Build 19:d4f9e872bf3e 397 }
Azure.IoT Build 19:d4f9e872bf3e 398 STRING_delete(keyName);
Azure.IoT Build 19:d4f9e872bf3e 399 }
Azure.IoT Build 19:d4f9e872bf3e 400 return result;
Azure.IoT Build 13:848d52f93daf 401 }
Azure.IoT Build 13:848d52f93daf 402
Azure.IoT Build 13:848d52f93daf 403 static void destroy_deviceId(HTTPTRANSPORT_PERDEVICE_DATA* handleData)
Azure.IoT Build 13:848d52f93daf 404 {
Azure.IoT Build 19:d4f9e872bf3e 405 STRING_delete(handleData->deviceId);
Azure.IoT Build 19:d4f9e872bf3e 406 handleData->deviceId = NULL;
Azure.IoT Build 13:848d52f93daf 407 }
Azure.IoT Build 13:848d52f93daf 408
Azure.IoT Build 13:848d52f93daf 409 static bool create_deviceId(HTTPTRANSPORT_PERDEVICE_DATA* handleData, const char * deviceId)
Azure.IoT Build 13:848d52f93daf 410 {
Azure.IoT Build 19:d4f9e872bf3e 411 /*Codes_SRS_TRANSPORTMULTITHTTP_17_133: [ IoTHubTransportHttp_Register shall create an immutable string (further called "deviceId") from config->deviceConfig->deviceId. ]*/
Azure.IoT Build 19:d4f9e872bf3e 412 bool result;
Azure.IoT Build 19:d4f9e872bf3e 413 handleData->deviceId = STRING_construct(deviceId);
Azure.IoT Build 19:d4f9e872bf3e 414 if (handleData->deviceId == NULL)
Azure.IoT Build 19:d4f9e872bf3e 415 {
Azure.IoT Build 19:d4f9e872bf3e 416 /*Codes_SRS_TRANSPORTMULTITHTTP_17_134: [ If deviceId is not created, then IoTHubTransportHttp_Register shall fail and return NULL. */
Azure.IoT Build 19:d4f9e872bf3e 417 LogError("STRING_construct deviceId failed");
Azure.IoT Build 19:d4f9e872bf3e 418 result = false;
Azure.IoT Build 19:d4f9e872bf3e 419 }
Azure.IoT Build 19:d4f9e872bf3e 420 else
Azure.IoT Build 19:d4f9e872bf3e 421 {
Azure.IoT Build 19:d4f9e872bf3e 422 result = true;
Azure.IoT Build 19:d4f9e872bf3e 423 }
Azure.IoT Build 19:d4f9e872bf3e 424 return result;
Azure.IoT Build 13:848d52f93daf 425 }
Azure.IoT Build 13:848d52f93daf 426
Azure.IoT Build 13:848d52f93daf 427 static void destroy_deviceKey(HTTPTRANSPORT_PERDEVICE_DATA* handleData)
Azure.IoT Build 13:848d52f93daf 428 {
Azure.IoT Build 19:d4f9e872bf3e 429 STRING_delete(handleData->deviceKey);
Azure.IoT Build 19:d4f9e872bf3e 430 handleData->deviceKey = NULL;
Azure.IoT Build 13:848d52f93daf 431 }
Azure.IoT Build 13:848d52f93daf 432
AzureIoTClient 17:7ef88cde801f 433 static void destroy_deviceSas(HTTPTRANSPORT_PERDEVICE_DATA* handleData)
AzureIoTClient 17:7ef88cde801f 434 {
AzureIoTClient 17:7ef88cde801f 435 STRING_delete(handleData->deviceSasToken);
AzureIoTClient 17:7ef88cde801f 436 handleData->deviceSasToken = NULL;
AzureIoTClient 17:7ef88cde801f 437 }
AzureIoTClient 17:7ef88cde801f 438
Azure.IoT Build 13:848d52f93daf 439 static bool create_deviceKey(HTTPTRANSPORT_PERDEVICE_DATA* handleData, const char * deviceKey)
Azure.IoT Build 13:848d52f93daf 440 {
Azure.IoT Build 19:d4f9e872bf3e 441 /*Codes_SRS_TRANSPORTMULTITHTTP_17_135: [ IoTHubTransportHttp_Register shall create an immutable string (further called "deviceKey") from deviceKey. ]*/
Azure.IoT Build 19:d4f9e872bf3e 442 bool result;
Azure.IoT Build 19:d4f9e872bf3e 443 handleData->deviceKey = STRING_construct(deviceKey);
Azure.IoT Build 19:d4f9e872bf3e 444 if (handleData->deviceKey == NULL)
Azure.IoT Build 19:d4f9e872bf3e 445 {
Azure.IoT Build 19:d4f9e872bf3e 446 /*Codes_SRS_TRANSPORTMULTITHTTP_17_136: [ If deviceKey is not created, then IoTHubTransportHttp_Register shall fail and return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 447 LogError("STRING_construct deviceKey failed");
Azure.IoT Build 19:d4f9e872bf3e 448 result = false;
Azure.IoT Build 19:d4f9e872bf3e 449 }
Azure.IoT Build 19:d4f9e872bf3e 450 else
Azure.IoT Build 19:d4f9e872bf3e 451 {
Azure.IoT Build 19:d4f9e872bf3e 452 result = true;
Azure.IoT Build 19:d4f9e872bf3e 453 }
Azure.IoT Build 19:d4f9e872bf3e 454 return result;
Azure.IoT Build 13:848d52f93daf 455 }
Azure.IoT Build 13:848d52f93daf 456
AzureIoTClient 17:7ef88cde801f 457 static void destroy_deviceSasToken(HTTPTRANSPORT_PERDEVICE_DATA* handleData)
AzureIoTClient 17:7ef88cde801f 458 {
Azure.IoT Build 19:d4f9e872bf3e 459 STRING_delete(handleData->deviceSasToken);
Azure.IoT Build 19:d4f9e872bf3e 460 handleData->deviceSasToken = NULL;
AzureIoTClient 17:7ef88cde801f 461 }
AzureIoTClient 17:7ef88cde801f 462
AzureIoTClient 17:7ef88cde801f 463 static bool create_deviceSasToken(HTTPTRANSPORT_PERDEVICE_DATA* handleData, const char * deviceSasToken)
AzureIoTClient 17:7ef88cde801f 464 {
Azure.IoT Build 19:d4f9e872bf3e 465 /*Codes_SRS_TRANSPORTMULTITHTTP_03_135: [ IoTHubTransportHttp_Register shall create an immutable string (further called "deviceSasToken") from deviceSasToken. ]*/
Azure.IoT Build 19:d4f9e872bf3e 466 bool result;
Azure.IoT Build 19:d4f9e872bf3e 467 handleData->deviceSasToken = STRING_construct(deviceSasToken);
Azure.IoT Build 19:d4f9e872bf3e 468 if (handleData->deviceSasToken == NULL)
Azure.IoT Build 19:d4f9e872bf3e 469 {
Azure.IoT Build 19:d4f9e872bf3e 470 /*Codes_SRS_TRANSPORTMULTITHTTP_03_136: [ If deviceSasToken is not created, then IoTHubTransportHttp_Register shall fail and return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 471 LogError("STRING_construct deviceSasToken failed");
Azure.IoT Build 19:d4f9e872bf3e 472 result = false;
Azure.IoT Build 19:d4f9e872bf3e 473 }
Azure.IoT Build 19:d4f9e872bf3e 474 else
Azure.IoT Build 19:d4f9e872bf3e 475 {
Azure.IoT Build 19:d4f9e872bf3e 476 result = true;
Azure.IoT Build 19:d4f9e872bf3e 477 }
Azure.IoT Build 19:d4f9e872bf3e 478 return result;
AzureIoTClient 17:7ef88cde801f 479 }
AzureIoTClient 17:7ef88cde801f 480
Azure.IoT Build 13:848d52f93daf 481 /*
Azure.IoT Build 13:848d52f93daf 482 * List queries Find by handle and find by device name
Azure.IoT Build 13:848d52f93daf 483 */
Azure.IoT Build 13:848d52f93daf 484
Azure.IoT Build 13:848d52f93daf 485 /*Codes_SRS_TRANSPORTMULTITHTTP_17_137: [ IoTHubTransportHttp_Register shall search the devices list for any device matching name deviceId. If deviceId is found it shall return NULL. ]*/
AzureIoTClient 18:ab990f6aa61f 486 static bool findDeviceHandle(const void* element, const void* value)
Azure.IoT Build 13:848d52f93daf 487 {
Azure.IoT Build 19:d4f9e872bf3e 488 bool result;
Azure.IoT Build 19:d4f9e872bf3e 489 /* data stored at element is device handle */
Azure.IoT Build 19:d4f9e872bf3e 490 const IOTHUB_DEVICE_HANDLE * guess = (const IOTHUB_DEVICE_HANDLE *)element;
AzureIoTClient 25:3a68a581d3f9 491 IOTHUB_DEVICE_HANDLE match = (IOTHUB_DEVICE_HANDLE)value;
Azure.IoT Build 19:d4f9e872bf3e 492 result = (*guess == match) ? true : false;
Azure.IoT Build 19:d4f9e872bf3e 493 return result;
Azure.IoT Build 13:848d52f93daf 494 }
Azure.IoT Build 13:848d52f93daf 495
Azure.IoT Build 13:848d52f93daf 496 static bool findDeviceById(const void* element, const void* value)
Azure.IoT Build 13:848d52f93daf 497 {
Azure.IoT Build 19:d4f9e872bf3e 498 bool result;
Azure.IoT Build 19:d4f9e872bf3e 499 const char* deviceId = (const char *)value;
Azure.IoT Build 19:d4f9e872bf3e 500 const HTTPTRANSPORT_PERDEVICE_DATA * perDeviceElement = *(const HTTPTRANSPORT_PERDEVICE_DATA **)element;
Azure.IoT Build 13:848d52f93daf 501
Azure.IoT Build 19:d4f9e872bf3e 502 result = (strcmp(STRING_c_str(perDeviceElement->deviceId), deviceId) == 0);
Azure.IoT Build 13:848d52f93daf 503
Azure.IoT Build 19:d4f9e872bf3e 504 return result;
Azure.IoT Build 13:848d52f93daf 505 }
Azure.IoT Build 13:848d52f93daf 506
AzureIoTClient 36:36c1e1ca5679 507 static IOTHUB_DEVICE_HANDLE IoTHubTransportHttp_Register(TRANSPORT_LL_HANDLE handle, const IOTHUB_DEVICE_CONFIG* device, IOTHUB_CLIENT_CORE_LL_HANDLE iotHubClientHandle, PDLIST_ENTRY waitingToSend)
Azure.IoT Build 13:848d52f93daf 508 {
Azure.IoT Build 19:d4f9e872bf3e 509 HTTPTRANSPORT_PERDEVICE_DATA* result;
Azure.IoT Build 19:d4f9e872bf3e 510 if (handle == NULL || device == NULL)
Azure.IoT Build 19:d4f9e872bf3e 511 {
Azure.IoT Build 19:d4f9e872bf3e 512 /*Codes_SRS_TRANSPORTMULTITHTTP_17_142: [ If handle is NULL or device is NULL, then IoTHubTransportHttp_Register shall return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 513 LogError("Transport handle is NULL");
Azure.IoT Build 19:d4f9e872bf3e 514 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 515 }
AzureIoTClient 20:b652f2e4cccf 516 else if (device->deviceId == NULL || ((device->deviceKey != NULL) && (device->deviceSasToken != NULL)) || waitingToSend == NULL || iotHubClientHandle == NULL)
Azure.IoT Build 19:d4f9e872bf3e 517 {
AzureIoTClient 20:b652f2e4cccf 518 /*Codes_SRS_TRANSPORTMULTITHTTP_17_015: [ If IOTHUB_DEVICE_CONFIG fields deviceKey and deviceSasToken are NULL, then IoTHubTransportHttp_Register shall assume a x509 authentication. ]*/
Azure.IoT Build 19:d4f9e872bf3e 519 /*Codes_SRS_TRANSPORTMULTITHTTP_17_014: [ If IOTHUB_DEVICE_CONFIG field deviceId is NULL, then IoTHubTransportHttp_Register shall return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 520 /*Codes_SRS_TRANSPORTMULTITHTTP_17_016: [ If parameter waitingToSend is NULL, then IoTHubTransportHttp_Register shall return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 521 /*Codes_SRS_TRANSPORTMULTITHTTP_17_143: [ If parameter iotHubClientHandle is NULL, then IoTHubTransportHttp_Register shall return NULL. ]*/
AzureIoTClient 36:36c1e1ca5679 522 LogError("invalid parameters detected TRANSPORT_LL_HANDLE handle=%p, const IOTHUB_DEVICE_CONFIG* device=%p, IOTHUB_CLIENT_CORE_LL_HANDLE iotHubClientHandle=%p, PDLIST_ENTRY waitingToSend=%p",
AzureIoTClient 20:b652f2e4cccf 523 handle, device, iotHubClientHandle, waitingToSend);
Azure.IoT Build 19:d4f9e872bf3e 524 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 525 }
Azure.IoT Build 19:d4f9e872bf3e 526 else
Azure.IoT Build 19:d4f9e872bf3e 527 {
Azure.IoT Build 19:d4f9e872bf3e 528 HTTPTRANSPORT_HANDLE_DATA* handleData = (HTTPTRANSPORT_HANDLE_DATA*)handle;
Azure.IoT Build 19:d4f9e872bf3e 529 /*Codes_SRS_TRANSPORTMULTITHTTP_17_137: [ IoTHubTransportHttp_Register shall search the devices list for any device matching name deviceId. If deviceId is found it shall return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 530 void* listItem = VECTOR_find_if(handleData->perDeviceList, findDeviceById, device->deviceId);
Azure.IoT Build 19:d4f9e872bf3e 531 if (listItem != NULL)
Azure.IoT Build 19:d4f9e872bf3e 532 {
Azure.IoT Build 19:d4f9e872bf3e 533 /*Codes_SRS_TRANSPORTMULTITHTTP_17_137: [ IoTHubTransportHttp_Register shall search the devices list for any device matching name deviceId. If deviceId is found it shall return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 534 LogError("Transport already has device registered by id: [%s]", device->deviceId);
Azure.IoT Build 19:d4f9e872bf3e 535 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 536 }
Azure.IoT Build 19:d4f9e872bf3e 537 else
Azure.IoT Build 19:d4f9e872bf3e 538 {
Azure.IoT Build 19:d4f9e872bf3e 539 bool was_create_deviceKey_ok = false;
Azure.IoT Build 19:d4f9e872bf3e 540 bool was_create_deviceSasToken_ok = false;
Azure.IoT Build 19:d4f9e872bf3e 541 bool was_sasObject_ok = false;
AzureIoTClient 20:b652f2e4cccf 542 bool was_x509_ok = false; /*there's nothing "created" in the case of x509, it is a flag indicating that x509 is used*/
AzureIoTClient 17:7ef88cde801f 543
Azure.IoT Build 19:d4f9e872bf3e 544 /*Codes_SRS_TRANSPORTMULTITHTTP_17_038: [ Otherwise, IoTHubTransportHttp_Register shall allocate the IOTHUB_DEVICE_HANDLE structure. ]*/
AzureIoTClient 35:786954ce12e9 545 bool was_resultCreated_ok = ((result = (HTTPTRANSPORT_PERDEVICE_DATA *)malloc(sizeof(HTTPTRANSPORT_PERDEVICE_DATA))) != NULL);
Azure.IoT Build 19:d4f9e872bf3e 546 bool was_create_deviceId_ok = was_resultCreated_ok && create_deviceId(result, device->deviceId);
AzureIoTClient 17:7ef88cde801f 547
AzureIoTClient 20:b652f2e4cccf 548 if (was_create_deviceId_ok)
Azure.IoT Build 19:d4f9e872bf3e 549 {
AzureIoTClient 20:b652f2e4cccf 550 if (device->deviceSasToken != NULL)
AzureIoTClient 20:b652f2e4cccf 551 {
AzureIoTClient 20:b652f2e4cccf 552 /*device->deviceKey is certainly NULL (because of the validation condition (else if (device->deviceId == NULL || ((device->deviceKey != NULL) && (device->deviceSasToken != NULL)) || waitingToSend == NULL || iotHubClientHandle == NULL))that does not accept that both satoken AND devicekey are non-NULL*/
AzureIoTClient 20:b652f2e4cccf 553 was_create_deviceSasToken_ok = create_deviceSasToken(result, device->deviceSasToken);
AzureIoTClient 20:b652f2e4cccf 554 result->deviceKey = NULL;
AzureIoTClient 20:b652f2e4cccf 555 result->sasObject = NULL;
AzureIoTClient 20:b652f2e4cccf 556 }
AzureIoTClient 20:b652f2e4cccf 557 else /*when deviceSasToken == NULL*/
AzureIoTClient 20:b652f2e4cccf 558 {
AzureIoTClient 20:b652f2e4cccf 559 if (device->deviceKey != NULL)
AzureIoTClient 20:b652f2e4cccf 560 {
AzureIoTClient 20:b652f2e4cccf 561 was_create_deviceKey_ok = create_deviceKey(result, device->deviceKey);
AzureIoTClient 20:b652f2e4cccf 562 result->deviceSasToken = NULL;
AzureIoTClient 20:b652f2e4cccf 563 }
AzureIoTClient 20:b652f2e4cccf 564 else
AzureIoTClient 20:b652f2e4cccf 565 {
AzureIoTClient 20:b652f2e4cccf 566 /*when both of them are NULL*/
AzureIoTClient 20:b652f2e4cccf 567 was_x509_ok = true;
AzureIoTClient 20:b652f2e4cccf 568 result->deviceKey = NULL;
AzureIoTClient 20:b652f2e4cccf 569 result->deviceSasToken = NULL;
AzureIoTClient 20:b652f2e4cccf 570 }
AzureIoTClient 20:b652f2e4cccf 571 }
Azure.IoT Build 19:d4f9e872bf3e 572 }
AzureIoTClient 17:7ef88cde801f 573
AzureIoTClient 20:b652f2e4cccf 574 bool was_eventHTTPrelativePath_ok = (was_create_deviceKey_ok || was_create_deviceSasToken_ok || was_x509_ok) && create_eventHTTPrelativePath(result, device->deviceId);
Azure.IoT Build 19:d4f9e872bf3e 575 bool was_messageHTTPrelativePath_ok = was_eventHTTPrelativePath_ok && create_messageHTTPrelativePath(result, device->deviceId);
AzureIoTClient 30:655054f86a6e 576 bool was_eventHTTPrequestHeaders_ok;
AzureIoTClient 30:655054f86a6e 577 if (was_messageHTTPrelativePath_ok)
AzureIoTClient 30:655054f86a6e 578 {
AzureIoTClient 30:655054f86a6e 579 result->iotHubClientHandle = iotHubClientHandle;
AzureIoTClient 30:655054f86a6e 580 was_eventHTTPrequestHeaders_ok = create_eventHTTPrequestHeaders(result, device->deviceId, was_x509_ok);
AzureIoTClient 30:655054f86a6e 581 }
AzureIoTClient 30:655054f86a6e 582 else
AzureIoTClient 30:655054f86a6e 583 {
AzureIoTClient 30:655054f86a6e 584 was_eventHTTPrequestHeaders_ok = false;
AzureIoTClient 30:655054f86a6e 585 }
AzureIoTClient 20:b652f2e4cccf 586 bool was_messageHTTPrequestHeaders_ok = was_eventHTTPrequestHeaders_ok && create_messageHTTPrequestHeaders(result, was_x509_ok);
Azure.IoT Build 19:d4f9e872bf3e 587 bool was_abandonHTTPrelativePathBegin_ok = was_messageHTTPrequestHeaders_ok && create_abandonHTTPrelativePathBegin(result, device->deviceId);
AzureIoTClient 17:7ef88cde801f 588
AzureIoTClient 20:b652f2e4cccf 589 if (was_x509_ok)
Azure.IoT Build 19:d4f9e872bf3e 590 {
AzureIoTClient 20:b652f2e4cccf 591 result->sasObject = NULL; /**/
AzureIoTClient 20:b652f2e4cccf 592 was_sasObject_ok = true;
AzureIoTClient 20:b652f2e4cccf 593 }
AzureIoTClient 20:b652f2e4cccf 594 else
AzureIoTClient 20:b652f2e4cccf 595 {
AzureIoTClient 20:b652f2e4cccf 596 if (!was_create_deviceSasToken_ok)
AzureIoTClient 20:b652f2e4cccf 597 {
AzureIoTClient 20:b652f2e4cccf 598 was_sasObject_ok = was_abandonHTTPrelativePathBegin_ok && create_deviceSASObject(result, handleData->hostName, device->deviceId, device->deviceKey);
AzureIoTClient 20:b652f2e4cccf 599 }
Azure.IoT Build 19:d4f9e872bf3e 600 }
AzureIoTClient 17:7ef88cde801f 601
Azure.IoT Build 19:d4f9e872bf3e 602 /*Codes_SRS_TRANSPORTMULTITHTTP_17_041: [ IoTHubTransportHttp_Register shall call VECTOR_push_back to store the new device information. ]*/
AzureIoTClient 20:b652f2e4cccf 603 bool was_list_add_ok = (was_sasObject_ok || was_create_deviceSasToken_ok || was_x509_ok) && (VECTOR_push_back(handleData->perDeviceList, &result, 1) == 0);
Azure.IoT Build 13:848d52f93daf 604
Azure.IoT Build 19:d4f9e872bf3e 605 if (was_list_add_ok)
Azure.IoT Build 19:d4f9e872bf3e 606 {
Azure.IoT Build 19:d4f9e872bf3e 607 /*Codes_SRS_TRANSPORTMULTITHTTP_17_043: [ Upon success, IoTHubTransportHttp_Register shall store the transport handle, iotHubClientHandle, and the waitingToSend queue in the device handle return a non-NULL value. ]*/
Azure.IoT Build 19:d4f9e872bf3e 608 /*Codes_SRS_TRANSPORTMULTITHTTP_17_040: [ IoTHubTransportHttp_Register shall put event HTTP relative path, message HTTP relative path, event HTTP request headers, message HTTP request headers, abandonHTTPrelativePathBegin, HTTPAPIEX_SAS_HANDLE, and the device handle into a device structure. ]*/
Azure.IoT Build 19:d4f9e872bf3e 609 /*Codes_SRS_TRANSPORTMULTITHTTP_17_128: [ IoTHubTransportHttp_Register shall mark this device as unsubscribed. ]*/
Azure.IoT Build 19:d4f9e872bf3e 610 result->DoWork_PullMessage = false;
Azure.IoT Build 19:d4f9e872bf3e 611 result->isFirstPoll = true;
Azure.IoT Build 19:d4f9e872bf3e 612 result->waitingToSend = waitingToSend;
Azure.IoT Build 19:d4f9e872bf3e 613 DList_InitializeListHead(&(result->eventConfirmations));
AzureIoTClient 35:786954ce12e9 614 result->transportHandle = (HTTPTRANSPORT_HANDLE_DATA *)handle;
Azure.IoT Build 19:d4f9e872bf3e 615 }
Azure.IoT Build 19:d4f9e872bf3e 616 else
Azure.IoT Build 19:d4f9e872bf3e 617 {
AzureIoTClient 24:02406f4a78ae 618 /*Codes_SRS_TRANSPORTMULTITHTTP_17_042: [ If the singlylinkedlist_add fails then IoTHubTransportHttp_Register shall fail and return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 619 if (was_sasObject_ok) destroy_SASObject(result);
Azure.IoT Build 19:d4f9e872bf3e 620 if (was_abandonHTTPrelativePathBegin_ok) destroy_abandonHTTPrelativePathBegin(result);
Azure.IoT Build 19:d4f9e872bf3e 621 if (was_messageHTTPrelativePath_ok) destroy_messageHTTPrelativePath(result);
Azure.IoT Build 19:d4f9e872bf3e 622 if (was_eventHTTPrequestHeaders_ok) destroy_eventHTTPrequestHeaders(result);
Azure.IoT Build 19:d4f9e872bf3e 623 if (was_messageHTTPrequestHeaders_ok) destroy_messageHTTPrequestHeaders(result);
Azure.IoT Build 19:d4f9e872bf3e 624 if (was_eventHTTPrelativePath_ok) destroy_eventHTTPrelativePath(result);
Azure.IoT Build 19:d4f9e872bf3e 625 if (was_create_deviceId_ok) destroy_deviceId(result);
Azure.IoT Build 19:d4f9e872bf3e 626 if (was_create_deviceKey_ok) destroy_deviceKey(result);
Azure.IoT Build 19:d4f9e872bf3e 627 if (was_create_deviceSasToken_ok) destroy_deviceSasToken(result);
Azure.IoT Build 19:d4f9e872bf3e 628 /*Codes_SRS_TRANSPORTMULTITHTTP_17_039: [ If the allocating the device handle fails then IoTHubTransportHttp_Register shall fail and return NULL. ] */
Azure.IoT Build 19:d4f9e872bf3e 629 if (was_resultCreated_ok) free(result);
Azure.IoT Build 19:d4f9e872bf3e 630 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 631 }
Azure.IoT Build 19:d4f9e872bf3e 632 }
AzureIoTClient 17:7ef88cde801f 633
Azure.IoT Build 19:d4f9e872bf3e 634 }
Azure.IoT Build 19:d4f9e872bf3e 635 return (IOTHUB_DEVICE_HANDLE)result;
Azure.IoT Build 13:848d52f93daf 636 }
Azure.IoT Build 13:848d52f93daf 637
Azure.IoT Build 13:848d52f93daf 638
Azure.IoT Build 13:848d52f93daf 639 static void destroy_perDeviceData(HTTPTRANSPORT_PERDEVICE_DATA * perDeviceItem)
Azure.IoT Build 13:848d52f93daf 640 {
Azure.IoT Build 19:d4f9e872bf3e 641 destroy_deviceId(perDeviceItem);
Azure.IoT Build 19:d4f9e872bf3e 642 destroy_deviceKey(perDeviceItem);
AzureIoTClient 17:7ef88cde801f 643 destroy_deviceSas(perDeviceItem);
Azure.IoT Build 19:d4f9e872bf3e 644 destroy_eventHTTPrelativePath(perDeviceItem);
Azure.IoT Build 19:d4f9e872bf3e 645 destroy_messageHTTPrelativePath(perDeviceItem);
Azure.IoT Build 19:d4f9e872bf3e 646 destroy_eventHTTPrequestHeaders(perDeviceItem);
Azure.IoT Build 19:d4f9e872bf3e 647 destroy_messageHTTPrequestHeaders(perDeviceItem);
Azure.IoT Build 19:d4f9e872bf3e 648 destroy_abandonHTTPrelativePathBegin(perDeviceItem);
Azure.IoT Build 19:d4f9e872bf3e 649 destroy_SASObject(perDeviceItem);
Azure.IoT Build 13:848d52f93daf 650 }
Azure.IoT Build 13:848d52f93daf 651
Azure.IoT Build 13:848d52f93daf 652 static IOTHUB_DEVICE_HANDLE* get_perDeviceDataItem(IOTHUB_DEVICE_HANDLE deviceHandle)
Azure.IoT Build 13:848d52f93daf 653 {
Azure.IoT Build 19:d4f9e872bf3e 654 HTTPTRANSPORT_PERDEVICE_DATA* deviceHandleData = (HTTPTRANSPORT_PERDEVICE_DATA*)deviceHandle;
Azure.IoT Build 19:d4f9e872bf3e 655 IOTHUB_DEVICE_HANDLE* listItem;
Azure.IoT Build 13:848d52f93daf 656
Azure.IoT Build 19:d4f9e872bf3e 657 HTTPTRANSPORT_HANDLE_DATA* handleData = deviceHandleData->transportHandle;
Azure.IoT Build 13:848d52f93daf 658
AzureIoTClient 35:786954ce12e9 659 listItem = (IOTHUB_DEVICE_HANDLE *)VECTOR_find_if(handleData->perDeviceList, findDeviceHandle, deviceHandle);
Azure.IoT Build 19:d4f9e872bf3e 660 if (listItem == NULL)
Azure.IoT Build 19:d4f9e872bf3e 661 {
Azure.IoT Build 19:d4f9e872bf3e 662 LogError("device handle not found in transport device list");
Azure.IoT Build 19:d4f9e872bf3e 663 listItem = NULL;
Azure.IoT Build 19:d4f9e872bf3e 664 }
Azure.IoT Build 19:d4f9e872bf3e 665 else
Azure.IoT Build 19:d4f9e872bf3e 666 {
Azure.IoT Build 19:d4f9e872bf3e 667 /* sucessfully found device in list. */
Azure.IoT Build 19:d4f9e872bf3e 668 }
Azure.IoT Build 13:848d52f93daf 669
Azure.IoT Build 19:d4f9e872bf3e 670 return listItem;
Azure.IoT Build 13:848d52f93daf 671 }
Azure.IoT Build 13:848d52f93daf 672
AzureIoTClient 18:ab990f6aa61f 673 static void IoTHubTransportHttp_Unregister(IOTHUB_DEVICE_HANDLE deviceHandle)
Azure.IoT Build 13:848d52f93daf 674 {
Azure.IoT Build 19:d4f9e872bf3e 675 if (deviceHandle == NULL)
Azure.IoT Build 19:d4f9e872bf3e 676 {
Azure.IoT Build 19:d4f9e872bf3e 677 /*Codes_SRS_TRANSPORTMULTITHTTP_17_044: [ If deviceHandle is NULL, then IoTHubTransportHttp_Unregister shall do nothing. ]*/
Azure.IoT Build 19:d4f9e872bf3e 678 LogError("Unregister a NULL device handle");
Azure.IoT Build 19:d4f9e872bf3e 679 }
Azure.IoT Build 19:d4f9e872bf3e 680 else
Azure.IoT Build 19:d4f9e872bf3e 681 {
Azure.IoT Build 19:d4f9e872bf3e 682 HTTPTRANSPORT_PERDEVICE_DATA* deviceHandleData = (HTTPTRANSPORT_PERDEVICE_DATA*)deviceHandle;
Azure.IoT Build 19:d4f9e872bf3e 683 HTTPTRANSPORT_HANDLE_DATA* handleData = deviceHandleData->transportHandle;
Azure.IoT Build 19:d4f9e872bf3e 684 /*Codes_SRS_TRANSPORTMULTITHTTP_17_045: [ IoTHubTransportHttp_Unregister shall locate deviceHandle in the transport device list by calling list_find_if. ]*/
Azure.IoT Build 19:d4f9e872bf3e 685 IOTHUB_DEVICE_HANDLE* listItem = get_perDeviceDataItem(deviceHandle);
Azure.IoT Build 19:d4f9e872bf3e 686 if (listItem == NULL)
Azure.IoT Build 19:d4f9e872bf3e 687 {
Azure.IoT Build 19:d4f9e872bf3e 688 /*Codes_SRS_TRANSPORTMULTITHTTP_17_046: [ If the device structure is not found, then this function shall fail and do nothing. ]*/
Azure.IoT Build 19:d4f9e872bf3e 689 LogError("Device Handle [%p] not found in transport", deviceHandle);
Azure.IoT Build 19:d4f9e872bf3e 690 }
Azure.IoT Build 19:d4f9e872bf3e 691 else
Azure.IoT Build 19:d4f9e872bf3e 692 {
Azure.IoT Build 19:d4f9e872bf3e 693 HTTPTRANSPORT_PERDEVICE_DATA * perDeviceItem = (HTTPTRANSPORT_PERDEVICE_DATA *)(*listItem);
Azure.IoT Build 13:848d52f93daf 694
Azure.IoT Build 19:d4f9e872bf3e 695 /*Codes_SRS_TRANSPORTMULTITHTTP_17_047: [ IoTHubTransportHttp_Unregister shall free all the resources used in the device structure. ]*/
Azure.IoT Build 19:d4f9e872bf3e 696 destroy_perDeviceData(perDeviceItem);
AzureIoTClient 24:02406f4a78ae 697 /*Codes_SRS_TRANSPORTMULTITHTTP_17_048: [ IoTHubTransportHttp_Unregister shall call singlylinkedlist_remove to remove device from devices list. ]*/
Azure.IoT Build 19:d4f9e872bf3e 698 VECTOR_erase(handleData->perDeviceList, listItem, 1);
Azure.IoT Build 19:d4f9e872bf3e 699 free(deviceHandleData);
Azure.IoT Build 19:d4f9e872bf3e 700 }
Azure.IoT Build 19:d4f9e872bf3e 701 }
Azure.IoT Build 13:848d52f93daf 702
Azure.IoT Build 19:d4f9e872bf3e 703 return;
Azure.IoT Build 13:848d52f93daf 704 }
Azure.IoT Build 13:848d52f93daf 705
AzureIoTClient 35:786954ce12e9 706 /*Codes_SRS_TRANSPORTMULTITHTTP_17_005: [If config->upperConfig->protocolGatewayHostName is NULL, `IoTHubTransportHttp_Create` shall create an immutable string (further called hostname) containing `config->transportConfig->iotHubName + config->transportConfig->iotHubSuffix`.] */
AzureIoTClient 23:44d825a1cd09 707 /*Codes_SRS_TRANSPORTMULTITHTTP_20_001: [If config->upperConfig->protocolGatewayHostName is not NULL, IoTHubTransportHttp_Create shall use it as hostname] */
AzureIoTClient 6:73793bae15ba 708 static void destroy_hostName(HTTPTRANSPORT_HANDLE_DATA* handleData)
AzureIoTClient 6:73793bae15ba 709 {
Azure.IoT Build 19:d4f9e872bf3e 710 STRING_delete(handleData->hostName);
Azure.IoT Build 19:d4f9e872bf3e 711 handleData->hostName = NULL;
AzureIoTClient 6:73793bae15ba 712 }
AzureIoTClient 6:73793bae15ba 713
AzureIoTClient 6:73793bae15ba 714 static bool create_hostName(HTTPTRANSPORT_HANDLE_DATA* handleData, const IOTHUBTRANSPORT_CONFIG* config)
AzureIoTClient 6:73793bae15ba 715 {
Azure.IoT Build 19:d4f9e872bf3e 716 bool result;
AzureIoTClient 23:44d825a1cd09 717 if (config->upperConfig->protocolGatewayHostName != NULL)
Azure.IoT Build 19:d4f9e872bf3e 718 {
AzureIoTClient 23:44d825a1cd09 719 /*Codes_SRS_TRANSPORTMULTITHTTP_20_001: [If config->upperConfig->protocolGatewayHostName is not NULL, IoTHubTransportHttp_Create shall use it as hostname] */
AzureIoTClient 23:44d825a1cd09 720 handleData->hostName = STRING_construct(config->upperConfig->protocolGatewayHostName);
AzureIoTClient 23:44d825a1cd09 721 result = (handleData->hostName != NULL);
Azure.IoT Build 19:d4f9e872bf3e 722 }
Azure.IoT Build 19:d4f9e872bf3e 723 else
Azure.IoT Build 19:d4f9e872bf3e 724 {
AzureIoTClient 35:786954ce12e9 725 /*Codes_SRS_TRANSPORTMULTITHTTP_17_005: [If config->upperConfig->protocolGatewayHostName is NULL, `IoTHubTransportHttp_Create` shall create an immutable string (further called hostname) containing `config->transportConfig->iotHubName + config->transportConfig->iotHubSuffix`.] */
AzureIoTClient 23:44d825a1cd09 726 handleData->hostName = STRING_construct(config->upperConfig->iotHubName);
AzureIoTClient 23:44d825a1cd09 727
AzureIoTClient 23:44d825a1cd09 728 if (handleData->hostName == NULL)
Azure.IoT Build 19:d4f9e872bf3e 729 {
Azure.IoT Build 19:d4f9e872bf3e 730 result = false;
Azure.IoT Build 19:d4f9e872bf3e 731 }
Azure.IoT Build 19:d4f9e872bf3e 732 else
Azure.IoT Build 19:d4f9e872bf3e 733 {
AzureIoTClient 23:44d825a1cd09 734 if ((STRING_concat(handleData->hostName, ".") != 0) ||
AzureIoTClient 23:44d825a1cd09 735 (STRING_concat(handleData->hostName, config->upperConfig->iotHubSuffix) != 0))
AzureIoTClient 23:44d825a1cd09 736 {
AzureIoTClient 23:44d825a1cd09 737 /*Codes_SRS_TRANSPORTMULTITHTTP_17_006: [ If creating the hostname fails then IoTHubTransportHttp_Create shall fail and return NULL. ] */
AzureIoTClient 23:44d825a1cd09 738 destroy_hostName(handleData);
AzureIoTClient 23:44d825a1cd09 739 result = false;
AzureIoTClient 23:44d825a1cd09 740 }
AzureIoTClient 23:44d825a1cd09 741 else
AzureIoTClient 23:44d825a1cd09 742 {
AzureIoTClient 23:44d825a1cd09 743 result = true;
AzureIoTClient 23:44d825a1cd09 744 }
Azure.IoT Build 19:d4f9e872bf3e 745 }
Azure.IoT Build 19:d4f9e872bf3e 746 }
Azure.IoT Build 19:d4f9e872bf3e 747 return result;
AzureIoTClient 6:73793bae15ba 748 }
AzureIoTClient 6:73793bae15ba 749
Azure.IoT Build 13:848d52f93daf 750 /*Codes_SRS_TRANSPORTMULTITHTTP_17_007: [Otherwise, IoTHubTransportHttp_Create shall create a HTTPAPIEX_HANDLE by a call to HTTPAPIEX_Create passing for hostName the hostname so far constructed by IoTHubTransportHttp_Create.]*/
AzureIoTClient 6:73793bae15ba 751 static void destroy_httpApiExHandle(HTTPTRANSPORT_HANDLE_DATA* handleData)
AzureIoTClient 6:73793bae15ba 752 {
Azure.IoT Build 19:d4f9e872bf3e 753 HTTPAPIEX_Destroy(handleData->httpApiExHandle);
Azure.IoT Build 19:d4f9e872bf3e 754 handleData->httpApiExHandle = NULL;
AzureIoTClient 6:73793bae15ba 755 }
AzureIoTClient 6:73793bae15ba 756
Azure.IoT Build 13:848d52f93daf 757 /*Codes_SRS_TRANSPORTMULTITHTTP_17_007: [ IoTHubTransportHttp_Create shall create a HTTPAPIEX_HANDLE by a call to HTTPAPIEX_Create passing for hostName the hostname so far constructed by IoTHubTransportHttp_Create. ]*/
AzureIoTClient 6:73793bae15ba 758 static bool create_httpApiExHandle(HTTPTRANSPORT_HANDLE_DATA* handleData, const IOTHUBTRANSPORT_CONFIG* config)
AzureIoTClient 6:73793bae15ba 759 {
Azure.IoT Build 19:d4f9e872bf3e 760 bool result;
Azure.IoT Build 19:d4f9e872bf3e 761 (void)config;
Azure.IoT Build 19:d4f9e872bf3e 762 handleData->httpApiExHandle = HTTPAPIEX_Create(STRING_c_str(handleData->hostName));
Azure.IoT Build 19:d4f9e872bf3e 763 if (handleData->httpApiExHandle == NULL)
Azure.IoT Build 19:d4f9e872bf3e 764 {
Azure.IoT Build 19:d4f9e872bf3e 765 /*Codes_SRS_TRANSPORTMULTITHTTP_17_008: [ If creating the HTTPAPIEX_HANDLE fails then IoTHubTransportHttp_Create shall fail and return NULL. ] */
Azure.IoT Build 19:d4f9e872bf3e 766 result = false;
Azure.IoT Build 19:d4f9e872bf3e 767 }
Azure.IoT Build 19:d4f9e872bf3e 768 else
Azure.IoT Build 19:d4f9e872bf3e 769 {
Azure.IoT Build 19:d4f9e872bf3e 770 result = true;
Azure.IoT Build 19:d4f9e872bf3e 771 }
Azure.IoT Build 19:d4f9e872bf3e 772 return result;
AzureIoTClient 6:73793bae15ba 773 }
AzureIoTClient 6:73793bae15ba 774
Azure.IoT Build 13:848d52f93daf 775 static void destroy_perDeviceList(HTTPTRANSPORT_HANDLE_DATA* handleData)
AzureIoTClient 6:73793bae15ba 776 {
Azure.IoT Build 19:d4f9e872bf3e 777 VECTOR_destroy(handleData->perDeviceList);
Azure.IoT Build 19:d4f9e872bf3e 778 handleData->perDeviceList = NULL;
AzureIoTClient 6:73793bae15ba 779 }
AzureIoTClient 6:73793bae15ba 780
AzureIoTClient 24:02406f4a78ae 781 /*Codes_SRS_TRANSPORTMULTITHTTP_17_009: [ IoTHubTransportHttp_Create shall call singlylinkedlist_create to create a list of registered devices. ]*/
Azure.IoT Build 13:848d52f93daf 782 static bool create_perDeviceList(HTTPTRANSPORT_HANDLE_DATA* handleData)
AzureIoTClient 6:73793bae15ba 783 {
Azure.IoT Build 19:d4f9e872bf3e 784 bool result;
Azure.IoT Build 19:d4f9e872bf3e 785 handleData->perDeviceList = VECTOR_create(sizeof(IOTHUB_DEVICE_HANDLE));
Azure.IoT Build 19:d4f9e872bf3e 786 if (handleData == NULL || handleData->perDeviceList == NULL)
Azure.IoT Build 19:d4f9e872bf3e 787 {
Azure.IoT Build 19:d4f9e872bf3e 788 /*Codes_SRS_TRANSPORTMULTITHTTP_17_010: [ If creating the list fails, then IoTHubTransportHttp_Create shall fail and return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 789 result = false;
Azure.IoT Build 19:d4f9e872bf3e 790 }
Azure.IoT Build 19:d4f9e872bf3e 791 else
Azure.IoT Build 19:d4f9e872bf3e 792 {
Azure.IoT Build 19:d4f9e872bf3e 793 result = true;
Azure.IoT Build 19:d4f9e872bf3e 794 }
Azure.IoT Build 19:d4f9e872bf3e 795 return result;
AzureIoTClient 6:73793bae15ba 796 }
AzureIoTClient 6:73793bae15ba 797
Azure.IoT Build 13:848d52f93daf 798
AzureIoTClient 18:ab990f6aa61f 799 static TRANSPORT_LL_HANDLE IoTHubTransportHttp_Create(const IOTHUBTRANSPORT_CONFIG* config)
AzureIoTClient 6:73793bae15ba 800 {
Azure.IoT Build 19:d4f9e872bf3e 801 HTTPTRANSPORT_HANDLE_DATA* result;
Azure.IoT Build 19:d4f9e872bf3e 802 if (config == NULL)
Azure.IoT Build 19:d4f9e872bf3e 803 {
Azure.IoT Build 19:d4f9e872bf3e 804 /*Codes_SRS_TRANSPORTMULTITHTTP_17_001: [If parameter config is NULL, then IoTHubTransportHttp_Create shall return NULL.]*/
Azure.IoT Build 19:d4f9e872bf3e 805 LogError("invalid arg (configuration is missing)");
Azure.IoT Build 19:d4f9e872bf3e 806 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 807 }
Azure.IoT Build 19:d4f9e872bf3e 808 else if (config->upperConfig == NULL)
Azure.IoT Build 19:d4f9e872bf3e 809 {
Azure.IoT Build 19:d4f9e872bf3e 810 /*Codes_SRS_TRANSPORTMULTITHTTP_17_002: [ If field transportConfig is NULL, then IoTHubTransportHttp_Create shall return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 811 LogError("invalid arg (upperConfig is NULL)");
Azure.IoT Build 19:d4f9e872bf3e 812 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 813 }
Azure.IoT Build 19:d4f9e872bf3e 814 else if (config->upperConfig->protocol == NULL)
Azure.IoT Build 19:d4f9e872bf3e 815 {
Azure.IoT Build 19:d4f9e872bf3e 816 /*Codes_SRS_TRANSPORTMULTITHTTP_17_003: [ If fields protocol, iotHubName or iotHubSuffix in transportConfig are NULL, then IoTHubTransportHttp_Create shall return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 817 LogError("invalid arg (protocol is NULL)");
Azure.IoT Build 19:d4f9e872bf3e 818 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 819 }
Azure.IoT Build 19:d4f9e872bf3e 820 else if (config->upperConfig->iotHubName == NULL)
Azure.IoT Build 19:d4f9e872bf3e 821 {
Azure.IoT Build 19:d4f9e872bf3e 822 /*Codes_SRS_TRANSPORTMULTITHTTP_17_003: [ If fields protocol, iotHubName or iotHubSuffix in transportConfig are NULL, then IoTHubTransportHttp_Create shall return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 823 LogError("invalid arg (iotHubName is NULL)");
Azure.IoT Build 19:d4f9e872bf3e 824 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 825 }
Azure.IoT Build 19:d4f9e872bf3e 826 else if (config->upperConfig->iotHubSuffix == NULL)
Azure.IoT Build 19:d4f9e872bf3e 827 {
Azure.IoT Build 19:d4f9e872bf3e 828 /*Codes_SRS_TRANSPORTMULTITHTTP_17_003: [ If fields protocol, iotHubName or iotHubSuffix in transportConfig are NULL, then IoTHubTransportHttp_Create shall return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 829 LogError("invalid arg (iotHubSuffix is NULL)");
Azure.IoT Build 19:d4f9e872bf3e 830 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 831 }
Azure.IoT Build 19:d4f9e872bf3e 832 else
Azure.IoT Build 19:d4f9e872bf3e 833 {
Azure.IoT Build 19:d4f9e872bf3e 834 /*Codes_SRS_TRANSPORTMULTITHTTP_17_130: [ IoTHubTransportHttp_Create shall allocate memory for the handle. ]*/
Azure.IoT Build 19:d4f9e872bf3e 835 result = (HTTPTRANSPORT_HANDLE_DATA*)malloc(sizeof(HTTPTRANSPORT_HANDLE_DATA));
Azure.IoT Build 19:d4f9e872bf3e 836 if (result == NULL)
Azure.IoT Build 19:d4f9e872bf3e 837 {
Azure.IoT Build 19:d4f9e872bf3e 838 /*Codes_SRS_TRANSPORTMULTITHTTP_17_131: [ If allocation fails, IoTHubTransportHttp_Create shall fail and return NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 839 LogError("unable to malloc");
Azure.IoT Build 19:d4f9e872bf3e 840 }
Azure.IoT Build 19:d4f9e872bf3e 841 else
Azure.IoT Build 19:d4f9e872bf3e 842 {
Azure.IoT Build 19:d4f9e872bf3e 843 bool was_hostName_ok = create_hostName(result, config);
Azure.IoT Build 19:d4f9e872bf3e 844 bool was_httpApiExHandle_ok = was_hostName_ok && create_httpApiExHandle(result, config);
Azure.IoT Build 19:d4f9e872bf3e 845 bool was_perDeviceList_ok = was_httpApiExHandle_ok && create_perDeviceList(result);
Azure.IoT Build 13:848d52f93daf 846
AzureIoTClient 6:73793bae15ba 847
Azure.IoT Build 19:d4f9e872bf3e 848 if (was_perDeviceList_ok)
Azure.IoT Build 19:d4f9e872bf3e 849 {
Azure.IoT Build 19:d4f9e872bf3e 850 /*Codes_SRS_TRANSPORTMULTITHTTP_17_011: [ Otherwise, IoTHubTransportHttp_Create shall succeed and return a non-NULL value. ]*/
Azure.IoT Build 19:d4f9e872bf3e 851 result->doBatchedTransfers = false;
Azure.IoT Build 19:d4f9e872bf3e 852 result->getMinimumPollingTime = DEFAULT_GETMINIMUMPOLLINGTIME;
Azure.IoT Build 19:d4f9e872bf3e 853 }
Azure.IoT Build 19:d4f9e872bf3e 854 else
Azure.IoT Build 19:d4f9e872bf3e 855 {
Azure.IoT Build 19:d4f9e872bf3e 856 if (was_httpApiExHandle_ok) destroy_httpApiExHandle(result);
Azure.IoT Build 19:d4f9e872bf3e 857 if (was_hostName_ok) destroy_hostName(result);
AzureIoTClient 6:73793bae15ba 858
Azure.IoT Build 19:d4f9e872bf3e 859 free(result);
Azure.IoT Build 19:d4f9e872bf3e 860 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 861 }
Azure.IoT Build 19:d4f9e872bf3e 862 }
Azure.IoT Build 19:d4f9e872bf3e 863 }
Azure.IoT Build 19:d4f9e872bf3e 864 return result;
AzureIoTClient 6:73793bae15ba 865 }
AzureIoTClient 6:73793bae15ba 866
AzureIoTClient 18:ab990f6aa61f 867 static void IoTHubTransportHttp_Destroy(TRANSPORT_LL_HANDLE handle)
AzureIoTClient 6:73793bae15ba 868 {
Azure.IoT Build 19:d4f9e872bf3e 869 /*Codes_SRS_TRANSPORTMULTITHTTP_17_012: [ IoTHubTransportHttp_Destroy shall do nothing is handle is NULL. ]*/
Azure.IoT Build 19:d4f9e872bf3e 870 if (handle != NULL)
Azure.IoT Build 19:d4f9e872bf3e 871 {
Azure.IoT Build 19:d4f9e872bf3e 872 HTTPTRANSPORT_HANDLE_DATA* handleData = (HTTPTRANSPORT_HANDLE_DATA*)handle;
Azure.IoT Build 19:d4f9e872bf3e 873 IOTHUB_DEVICE_HANDLE* listItem;
Azure.IoT Build 13:848d52f93daf 874
Azure.IoT Build 19:d4f9e872bf3e 875 size_t deviceListSize = VECTOR_size(handleData->perDeviceList);
Azure.IoT Build 13:848d52f93daf 876
Azure.IoT Build 19:d4f9e872bf3e 877 /*Codes_SRS_TRANSPORTMULTITHTTP_17_013: [ Otherwise, IoTHubTransportHttp_Destroy shall free all the resources currently in use. ]*/
Azure.IoT Build 19:d4f9e872bf3e 878 for (size_t i = 0; i < deviceListSize; i++)
Azure.IoT Build 19:d4f9e872bf3e 879 {
AzureIoTClient 35:786954ce12e9 880 listItem = (IOTHUB_DEVICE_HANDLE *)VECTOR_element(handleData->perDeviceList, i);
Azure.IoT Build 19:d4f9e872bf3e 881 HTTPTRANSPORT_PERDEVICE_DATA* perDeviceItem = (HTTPTRANSPORT_PERDEVICE_DATA*)(*listItem);
Azure.IoT Build 19:d4f9e872bf3e 882 destroy_perDeviceData(perDeviceItem);
Azure.IoT Build 19:d4f9e872bf3e 883 free(perDeviceItem);
Azure.IoT Build 19:d4f9e872bf3e 884 }
Azure.IoT Build 13:848d52f93daf 885
AzureIoTClient 35:786954ce12e9 886 destroy_hostName((HTTPTRANSPORT_HANDLE_DATA *)handle);
AzureIoTClient 35:786954ce12e9 887 destroy_httpApiExHandle((HTTPTRANSPORT_HANDLE_DATA *)handle);
AzureIoTClient 22:e0add922c564 888 destroy_perDeviceList((HTTPTRANSPORT_HANDLE_DATA *)handle);
Azure.IoT Build 19:d4f9e872bf3e 889 free(handle);
Azure.IoT Build 19:d4f9e872bf3e 890 }
AzureIoTClient 6:73793bae15ba 891 }
AzureIoTClient 6:73793bae15ba 892
AzureIoTClient 18:ab990f6aa61f 893 static int IoTHubTransportHttp_Subscribe(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 6:73793bae15ba 894 {
Azure.IoT Build 19:d4f9e872bf3e 895 int result;
Azure.IoT Build 19:d4f9e872bf3e 896 if (handle == NULL)
Azure.IoT Build 19:d4f9e872bf3e 897 {
Azure.IoT Build 19:d4f9e872bf3e 898 /*Codes_SRS_TRANSPORTMULTITHTTP_17_103: [ If parameter deviceHandle is NULL then IoTHubTransportHttp_Subscribe shall fail and return a non-zero value. ]*/
Azure.IoT Build 19:d4f9e872bf3e 899 LogError("invalid arg passed to IoTHubTransportHttp_Subscribe");
AzureIoTClient 28:f57de550d450 900 result = __FAILURE__;
Azure.IoT Build 19:d4f9e872bf3e 901 }
Azure.IoT Build 19:d4f9e872bf3e 902 else
Azure.IoT Build 19:d4f9e872bf3e 903 {
Azure.IoT Build 19:d4f9e872bf3e 904 /*Codes_SRS_TRANSPORTMULTITHTTP_17_104: [ IoTHubTransportHttp_Subscribe shall locate deviceHandle in the transport device list by calling list_find_if. ]*/
Azure.IoT Build 19:d4f9e872bf3e 905 IOTHUB_DEVICE_HANDLE* listItem = get_perDeviceDataItem(handle);
Azure.IoT Build 13:848d52f93daf 906
Azure.IoT Build 19:d4f9e872bf3e 907 if (listItem == NULL)
Azure.IoT Build 19:d4f9e872bf3e 908 {
Azure.IoT Build 19:d4f9e872bf3e 909 /*Codes_SRS_TRANSPORTMULTITHTTP_17_105: [ If the device structure is not found, then this function shall fail and return a non-zero value. ]*/
Azure.IoT Build 19:d4f9e872bf3e 910 LogError("did not find device in transport handle");
AzureIoTClient 28:f57de550d450 911 result = __FAILURE__;
Azure.IoT Build 19:d4f9e872bf3e 912 }
Azure.IoT Build 19:d4f9e872bf3e 913 else
Azure.IoT Build 19:d4f9e872bf3e 914 {
Azure.IoT Build 19:d4f9e872bf3e 915 HTTPTRANSPORT_PERDEVICE_DATA * perDeviceItem;
Azure.IoT Build 13:848d52f93daf 916
Azure.IoT Build 19:d4f9e872bf3e 917 perDeviceItem = (HTTPTRANSPORT_PERDEVICE_DATA *)(*listItem);
Azure.IoT Build 19:d4f9e872bf3e 918 /*Codes_SRS_TRANSPORTMULTITHTTP_17_106: [ Otherwise, IoTHubTransportHttp_Subscribe shall set the device so that subsequent calls to DoWork should execute HTTP requests. ]*/
Azure.IoT Build 19:d4f9e872bf3e 919 perDeviceItem->DoWork_PullMessage = true;
Azure.IoT Build 19:d4f9e872bf3e 920 }
Azure.IoT Build 19:d4f9e872bf3e 921 result = 0;
Azure.IoT Build 19:d4f9e872bf3e 922 }
Azure.IoT Build 19:d4f9e872bf3e 923 return result;
AzureIoTClient 6:73793bae15ba 924 }
AzureIoTClient 6:73793bae15ba 925
AzureIoTClient 18:ab990f6aa61f 926 static void IoTHubTransportHttp_Unsubscribe(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 6:73793bae15ba 927 {
Azure.IoT Build 19:d4f9e872bf3e 928 /*Codes_SRS_TRANSPORTMULTITHTTP_17_107: [ If parameter deviceHandle is NULL then IoTHubTransportHttp_Unsubscribe shall fail do nothing. ]*/
Azure.IoT Build 19:d4f9e872bf3e 929 if (handle != NULL)
Azure.IoT Build 19:d4f9e872bf3e 930 {
Azure.IoT Build 19:d4f9e872bf3e 931 /*Codes_SRS_TRANSPORTMULTITHTTP_17_108: [ IoTHubTransportHttp_Unsubscribe shall locate deviceHandle in the transport device list by calling list_find_if. ]*/
Azure.IoT Build 19:d4f9e872bf3e 932 IOTHUB_DEVICE_HANDLE* listItem = get_perDeviceDataItem(handle);
Azure.IoT Build 19:d4f9e872bf3e 933 /*Codes_SRS_TRANSPORTMULTITHTTP_17_109: [ If the device structure is not found, then this function shall fail and do nothing. ]*/
Azure.IoT Build 19:d4f9e872bf3e 934 if (listItem != NULL)
Azure.IoT Build 19:d4f9e872bf3e 935 {
Azure.IoT Build 19:d4f9e872bf3e 936 HTTPTRANSPORT_PERDEVICE_DATA * perDeviceItem = (HTTPTRANSPORT_PERDEVICE_DATA *)(*listItem);
Azure.IoT Build 19:d4f9e872bf3e 937 /*Codes_SRS_TRANSPORTMULTITHTTP_17_110: [ Otherwise, IoTHubTransportHttp_Subscribe shall set the device so that subsequent calls to DoWork shall not execute HTTP requests. ]*/
Azure.IoT Build 19:d4f9e872bf3e 938 perDeviceItem->DoWork_PullMessage = false;
Azure.IoT Build 19:d4f9e872bf3e 939 }
Azure.IoT Build 19:d4f9e872bf3e 940 else
Azure.IoT Build 19:d4f9e872bf3e 941 {
Azure.IoT Build 19:d4f9e872bf3e 942 LogError("Device not found to unsuscribe.");
Azure.IoT Build 19:d4f9e872bf3e 943 }
Azure.IoT Build 19:d4f9e872bf3e 944 }
Azure.IoT Build 19:d4f9e872bf3e 945 else
Azure.IoT Build 19:d4f9e872bf3e 946 {
Azure.IoT Build 19:d4f9e872bf3e 947 LogError("Null handle passed to Unsuscribe.");
Azure.IoT Build 19:d4f9e872bf3e 948 }
AzureIoTClient 6:73793bae15ba 949 }
AzureIoTClient 6:73793bae15ba 950
AzureIoTClient 25:3a68a581d3f9 951 static int IoTHubTransportHttp_Subscribe_DeviceTwin(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 25:3a68a581d3f9 952 {
AzureIoTClient 25:3a68a581d3f9 953 /*Codes_SRS_TRANSPORTMULTITHTTP_02_003: [ IoTHubTransportHttp_Subscribe_DeviceTwin shall return a non-zero value. ]*/
AzureIoTClient 25:3a68a581d3f9 954 (void)handle;
AzureIoTClient 28:f57de550d450 955 int result = __FAILURE__;
AzureIoTClient 25:3a68a581d3f9 956 LogError("IoTHubTransportHttp_Subscribe_DeviceTwin Not supported");
AzureIoTClient 25:3a68a581d3f9 957 return result;
AzureIoTClient 25:3a68a581d3f9 958 }
AzureIoTClient 25:3a68a581d3f9 959
AzureIoTClient 25:3a68a581d3f9 960 static void IoTHubTransportHttp_Unsubscribe_DeviceTwin(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 25:3a68a581d3f9 961 {
AzureIoTClient 25:3a68a581d3f9 962 (void)handle;
AzureIoTClient 25:3a68a581d3f9 963 /*Codes_SRS_TRANSPORTMULTITHTTP_02_004: [ IoTHubTransportHttp_Unsubscribe_DeviceTwin shall return ]*/
AzureIoTClient 25:3a68a581d3f9 964 LogError("IoTHubTransportHttp_Unsubscribe_DeviceTwin Not supported");
AzureIoTClient 25:3a68a581d3f9 965 }
AzureIoTClient 25:3a68a581d3f9 966
AzureIoTClient 25:3a68a581d3f9 967 static int IoTHubTransportHttp_Subscribe_DeviceMethod(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 25:3a68a581d3f9 968 {
AzureIoTClient 25:3a68a581d3f9 969 (void)handle;
AzureIoTClient 28:f57de550d450 970 int result = __FAILURE__;
AzureIoTClient 25:3a68a581d3f9 971 LogError("not implemented (yet)");
AzureIoTClient 25:3a68a581d3f9 972 return result;
AzureIoTClient 25:3a68a581d3f9 973 }
AzureIoTClient 25:3a68a581d3f9 974
AzureIoTClient 25:3a68a581d3f9 975 static void IoTHubTransportHttp_Unsubscribe_DeviceMethod(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 25:3a68a581d3f9 976 {
AzureIoTClient 25:3a68a581d3f9 977 (void)handle;
AzureIoTClient 25:3a68a581d3f9 978 LogError("not implemented (yet)");
AzureIoTClient 25:3a68a581d3f9 979 }
AzureIoTClient 25:3a68a581d3f9 980
AzureIoTClient 26:aeabbfa5181a 981 static int IoTHubTransportHttp_DeviceMethod_Response(IOTHUB_DEVICE_HANDLE handle, METHOD_HANDLE methodId, const unsigned char* response, size_t response_size, int status_response)
AzureIoTClient 26:aeabbfa5181a 982 {
AzureIoTClient 26:aeabbfa5181a 983 (void)handle;
AzureIoTClient 26:aeabbfa5181a 984 (void)methodId;
AzureIoTClient 26:aeabbfa5181a 985 (void)response;
AzureIoTClient 26:aeabbfa5181a 986 (void)response_size;
AzureIoTClient 26:aeabbfa5181a 987 (void)status_response;
AzureIoTClient 26:aeabbfa5181a 988 LogError("not implemented (yet)");
AzureIoTClient 28:f57de550d450 989 return __FAILURE__;
AzureIoTClient 26:aeabbfa5181a 990 }
AzureIoTClient 26:aeabbfa5181a 991
AzureIoTClient 6:73793bae15ba 992 /*produces a representation of the properties, if they exist*/
AzureIoTClient 6:73793bae15ba 993 /*if they do not exist, produces ""*/
AzureIoTClient 6:73793bae15ba 994 static int concat_Properties(STRING_HANDLE existing, MAP_HANDLE map, size_t* propertiesMessageSizeContribution)
AzureIoTClient 6:73793bae15ba 995 {
Azure.IoT Build 19:d4f9e872bf3e 996 int result;
Azure.IoT Build 19:d4f9e872bf3e 997 const char*const* keys;
Azure.IoT Build 19:d4f9e872bf3e 998 const char*const* values;
Azure.IoT Build 19:d4f9e872bf3e 999 size_t count;
Azure.IoT Build 19:d4f9e872bf3e 1000 if (Map_GetInternals(map, &keys, &values, &count) != MAP_OK)
Azure.IoT Build 19:d4f9e872bf3e 1001 {
AzureIoTClient 28:f57de550d450 1002 result = __FAILURE__;
Azure.IoT Build 19:d4f9e872bf3e 1003 LogError("error while Map_GetInternals");
Azure.IoT Build 19:d4f9e872bf3e 1004 }
Azure.IoT Build 19:d4f9e872bf3e 1005 else
Azure.IoT Build 19:d4f9e872bf3e 1006 {
AzureIoTClient 6:73793bae15ba 1007
Azure.IoT Build 19:d4f9e872bf3e 1008 if (count == 0)
Azure.IoT Build 19:d4f9e872bf3e 1009 {
Azure.IoT Build 19:d4f9e872bf3e 1010 /*Codes_SRS_TRANSPORTMULTITHTTP_17_064: [If IoTHubMessage does not have properties, then "properties":{...} shall be missing from the payload*/
Azure.IoT Build 19:d4f9e872bf3e 1011 /*no properties - do nothing with existing*/
Azure.IoT Build 19:d4f9e872bf3e 1012 result = 0;
Azure.IoT Build 19:d4f9e872bf3e 1013 *propertiesMessageSizeContribution = 0;
Azure.IoT Build 19:d4f9e872bf3e 1014 }
Azure.IoT Build 19:d4f9e872bf3e 1015 else
Azure.IoT Build 19:d4f9e872bf3e 1016 {
Azure.IoT Build 19:d4f9e872bf3e 1017 /*Codes_SRS_TRANSPORTMULTITHTTP_17_058: [If IoTHubMessage has properties, then they shall be serialized at the same level as "body" using the following pattern: "properties":{"iothub-app-name1":"value1","iothub-app-name2":"value2*/
Azure.IoT Build 19:d4f9e872bf3e 1018 if (STRING_concat(existing, ",\"properties\":") != 0)
Azure.IoT Build 19:d4f9e872bf3e 1019 {
Azure.IoT Build 19:d4f9e872bf3e 1020 /*go ahead and return it*/
AzureIoTClient 28:f57de550d450 1021 result = __FAILURE__;
Azure.IoT Build 19:d4f9e872bf3e 1022 LogError("failed STRING_concat");
Azure.IoT Build 19:d4f9e872bf3e 1023 }
Azure.IoT Build 19:d4f9e872bf3e 1024 else if (appendMapToJSON(existing, keys, values, count) != 0)
Azure.IoT Build 19:d4f9e872bf3e 1025 {
AzureIoTClient 28:f57de550d450 1026 result = __FAILURE__;
Azure.IoT Build 19:d4f9e872bf3e 1027 LogError("unable to append the properties");
Azure.IoT Build 19:d4f9e872bf3e 1028 }
Azure.IoT Build 19:d4f9e872bf3e 1029 else
Azure.IoT Build 19:d4f9e872bf3e 1030 {
Azure.IoT Build 19:d4f9e872bf3e 1031 /*all is fine*/
Azure.IoT Build 19:d4f9e872bf3e 1032 size_t i;
Azure.IoT Build 19:d4f9e872bf3e 1033 *propertiesMessageSizeContribution = 0;
AzureIoTClient 35:786954ce12e9 1034 for (i = 0; i < count; i++)
Azure.IoT Build 19:d4f9e872bf3e 1035 {
Azure.IoT Build 19:d4f9e872bf3e 1036 /*Codes_SRS_TRANSPORTMULTITHTTP_17_063: [Every property name shall add to the message size the length of the property name + the length of the property value + 16 bytes.] */
Azure.IoT Build 19:d4f9e872bf3e 1037 *propertiesMessageSizeContribution += (strlen(keys[i]) + strlen(values[i]) + MAXIMUM_PROPERTY_OVERHEAD);
Azure.IoT Build 19:d4f9e872bf3e 1038 }
Azure.IoT Build 19:d4f9e872bf3e 1039 result = 0;
Azure.IoT Build 19:d4f9e872bf3e 1040 }
Azure.IoT Build 19:d4f9e872bf3e 1041 }
Azure.IoT Build 19:d4f9e872bf3e 1042 }
Azure.IoT Build 19:d4f9e872bf3e 1043 return result;
AzureIoTClient 6:73793bae15ba 1044 }
AzureIoTClient 6:73793bae15ba 1045
AzureIoTClient 6:73793bae15ba 1046 /*produces a JSON representation of the map : {"a": "value_of_a","b":"value_of_b"}*/
AzureIoTClient 6:73793bae15ba 1047 static int appendMapToJSON(STRING_HANDLE existing, const char* const* keys, const char* const* values, size_t count) /*under consideration: move to MAP module when it has more than 1 user*/
AzureIoTClient 6:73793bae15ba 1048 {
Azure.IoT Build 19:d4f9e872bf3e 1049 int result;
Azure.IoT Build 19:d4f9e872bf3e 1050 if (STRING_concat(existing, "{") != 0)
Azure.IoT Build 19:d4f9e872bf3e 1051 {
Azure.IoT Build 19:d4f9e872bf3e 1052 /*go on and return it*/
Azure.IoT Build 19:d4f9e872bf3e 1053 LogError("STRING_construct failed");
AzureIoTClient 28:f57de550d450 1054 result = __FAILURE__;
Azure.IoT Build 19:d4f9e872bf3e 1055 }
Azure.IoT Build 19:d4f9e872bf3e 1056 else
Azure.IoT Build 19:d4f9e872bf3e 1057 {
Azure.IoT Build 19:d4f9e872bf3e 1058 size_t i;
Azure.IoT Build 19:d4f9e872bf3e 1059 for (i = 0; i < count; i++)
Azure.IoT Build 19:d4f9e872bf3e 1060 {
Azure.IoT Build 19:d4f9e872bf3e 1061 if (!(
Azure.IoT Build 19:d4f9e872bf3e 1062 (STRING_concat(existing, (i == 0) ? "\"" IOTHUB_APP_PREFIX : ",\"" IOTHUB_APP_PREFIX) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 1063 (STRING_concat(existing, keys[i]) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 1064 (STRING_concat(existing, "\":\"") == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 1065 (STRING_concat(existing, values[i]) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 1066 (STRING_concat(existing, "\"") == 0)
Azure.IoT Build 19:d4f9e872bf3e 1067 ))
Azure.IoT Build 19:d4f9e872bf3e 1068 {
Azure.IoT Build 19:d4f9e872bf3e 1069 LogError("unable to STRING_concat");
Azure.IoT Build 19:d4f9e872bf3e 1070 break;
Azure.IoT Build 19:d4f9e872bf3e 1071 }
Azure.IoT Build 19:d4f9e872bf3e 1072 }
AzureIoTClient 6:73793bae15ba 1073
Azure.IoT Build 19:d4f9e872bf3e 1074 if (i < count)
Azure.IoT Build 19:d4f9e872bf3e 1075 {
AzureIoTClient 28:f57de550d450 1076 result = __FAILURE__;
Azure.IoT Build 19:d4f9e872bf3e 1077 /*error, let it go through*/
Azure.IoT Build 19:d4f9e872bf3e 1078 }
Azure.IoT Build 19:d4f9e872bf3e 1079 else if (STRING_concat(existing, "}") != 0)
Azure.IoT Build 19:d4f9e872bf3e 1080 {
Azure.IoT Build 19:d4f9e872bf3e 1081 LogError("unable to STRING_concat");
AzureIoTClient 28:f57de550d450 1082 result = __FAILURE__;
Azure.IoT Build 19:d4f9e872bf3e 1083 }
Azure.IoT Build 19:d4f9e872bf3e 1084 else
Azure.IoT Build 19:d4f9e872bf3e 1085 {
Azure.IoT Build 19:d4f9e872bf3e 1086 /*all is fine*/
Azure.IoT Build 19:d4f9e872bf3e 1087 result = 0;
Azure.IoT Build 19:d4f9e872bf3e 1088 }
Azure.IoT Build 19:d4f9e872bf3e 1089 }
Azure.IoT Build 19:d4f9e872bf3e 1090 return result;
AzureIoTClient 6:73793bae15ba 1091 }
AzureIoTClient 6:73793bae15ba 1092
AzureIoTClient 6:73793bae15ba 1093 /*makes the following string:{"body":"base64 encoding of the message content"[,"properties":{"a":"valueOfA"}]}*/
AzureIoTClient 6:73793bae15ba 1094 /*return NULL if there was a failure, or a non-NULL STRING_HANDLE that contains the intended data*/
AzureIoTClient 6:73793bae15ba 1095 static STRING_HANDLE make1EventJSONitem(PDLIST_ENTRY item, size_t *messageSizeContribution)
AzureIoTClient 6:73793bae15ba 1096 {
Azure.IoT Build 19:d4f9e872bf3e 1097 STRING_HANDLE result; /*temp wants to contain :{"body":"base64 encoding of the message content"[,"properties":{"a":"valueOfA"}]}*/
Azure.IoT Build 19:d4f9e872bf3e 1098 IOTHUB_MESSAGE_LIST* message = containingRecord(item, IOTHUB_MESSAGE_LIST, entry);
Azure.IoT Build 19:d4f9e872bf3e 1099 IOTHUBMESSAGE_CONTENT_TYPE contentType = IoTHubMessage_GetContentType(message->messageHandle);
AzureIoTClient 17:7ef88cde801f 1100
Azure.IoT Build 19:d4f9e872bf3e 1101 switch (contentType)
Azure.IoT Build 19:d4f9e872bf3e 1102 {
Azure.IoT Build 19:d4f9e872bf3e 1103 case IOTHUBMESSAGE_BYTEARRAY:
Azure.IoT Build 19:d4f9e872bf3e 1104 {
Azure.IoT Build 19:d4f9e872bf3e 1105 result = STRING_construct("{\"body\":\"");
Azure.IoT Build 19:d4f9e872bf3e 1106 if (result == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1107 {
Azure.IoT Build 19:d4f9e872bf3e 1108 LogError("unable to STRING_construct");
Azure.IoT Build 19:d4f9e872bf3e 1109 }
Azure.IoT Build 19:d4f9e872bf3e 1110 else
Azure.IoT Build 19:d4f9e872bf3e 1111 {
Azure.IoT Build 19:d4f9e872bf3e 1112 const unsigned char* source;
Azure.IoT Build 19:d4f9e872bf3e 1113 size_t size;
AzureIoTClient 6:73793bae15ba 1114
Azure.IoT Build 19:d4f9e872bf3e 1115 if (IoTHubMessage_GetByteArray(message->messageHandle, &source, &size) != IOTHUB_MESSAGE_OK)
Azure.IoT Build 19:d4f9e872bf3e 1116 {
Azure.IoT Build 19:d4f9e872bf3e 1117 LogError("unable to get the data for the message.");
Azure.IoT Build 19:d4f9e872bf3e 1118 STRING_delete(result);
Azure.IoT Build 19:d4f9e872bf3e 1119 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 1120 }
Azure.IoT Build 19:d4f9e872bf3e 1121 else
Azure.IoT Build 19:d4f9e872bf3e 1122 {
Azure.IoT Build 19:d4f9e872bf3e 1123 STRING_HANDLE encoded = Base64_Encode_Bytes(source, size);
Azure.IoT Build 19:d4f9e872bf3e 1124 if (encoded == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1125 {
Azure.IoT Build 19:d4f9e872bf3e 1126 LogError("unable to Base64_Encode_Bytes.");
Azure.IoT Build 19:d4f9e872bf3e 1127 STRING_delete(result);
Azure.IoT Build 19:d4f9e872bf3e 1128 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 1129 }
Azure.IoT Build 19:d4f9e872bf3e 1130 else
Azure.IoT Build 19:d4f9e872bf3e 1131 {
AzureIoTClient 35:786954ce12e9 1132 size_t propertiesSize = 0;
Azure.IoT Build 19:d4f9e872bf3e 1133 if (!(
Azure.IoT Build 19:d4f9e872bf3e 1134 (STRING_concat_with_STRING(result, encoded) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 1135 (STRING_concat(result, "\"") == 0) && /*\" because closing value*/
Azure.IoT Build 19:d4f9e872bf3e 1136 (concat_Properties(result, IoTHubMessage_Properties(message->messageHandle), &propertiesSize) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 1137 (STRING_concat(result, "},") == 0) /*the last comma shall be replaced by a ']' by DaCr's suggestion (which is awesome enough to receive credits in the source code)*/
Azure.IoT Build 19:d4f9e872bf3e 1138 ))
Azure.IoT Build 19:d4f9e872bf3e 1139 {
Azure.IoT Build 19:d4f9e872bf3e 1140 STRING_delete(result);
Azure.IoT Build 19:d4f9e872bf3e 1141 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 1142 LogError("unable to STRING_concat_with_STRING.");
Azure.IoT Build 19:d4f9e872bf3e 1143 }
Azure.IoT Build 19:d4f9e872bf3e 1144 else
Azure.IoT Build 19:d4f9e872bf3e 1145 {
Azure.IoT Build 19:d4f9e872bf3e 1146 /*all is fine... */
Azure.IoT Build 19:d4f9e872bf3e 1147 /*Codes_SRS_TRANSPORTMULTITHTTP_17_062: [The message size is computed from the length of the payload + 384.] */
Azure.IoT Build 19:d4f9e872bf3e 1148 *messageSizeContribution = size + MAXIMUM_PAYLOAD_OVERHEAD + propertiesSize;
Azure.IoT Build 19:d4f9e872bf3e 1149 }
Azure.IoT Build 19:d4f9e872bf3e 1150 STRING_delete(encoded);
Azure.IoT Build 19:d4f9e872bf3e 1151 }
Azure.IoT Build 19:d4f9e872bf3e 1152 }
Azure.IoT Build 19:d4f9e872bf3e 1153 }
Azure.IoT Build 19:d4f9e872bf3e 1154 break;
Azure.IoT Build 19:d4f9e872bf3e 1155 }
Azure.IoT Build 19:d4f9e872bf3e 1156 /*Codes_SRS_TRANSPORTMULTITHTTP_17_057: [If a messages to be send has type IOTHUBMESSAGE_STRING, then its serialization shall be {"body":"JSON encoding of the string", "base64Encoded":false}] */
Azure.IoT Build 19:d4f9e872bf3e 1157 case IOTHUBMESSAGE_STRING:
Azure.IoT Build 19:d4f9e872bf3e 1158 {
Azure.IoT Build 19:d4f9e872bf3e 1159 result = STRING_construct("{\"body\":");
Azure.IoT Build 19:d4f9e872bf3e 1160 if (result == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1161 {
Azure.IoT Build 19:d4f9e872bf3e 1162 LogError("unable to STRING_construct");
Azure.IoT Build 19:d4f9e872bf3e 1163 }
Azure.IoT Build 19:d4f9e872bf3e 1164 else
Azure.IoT Build 19:d4f9e872bf3e 1165 {
Azure.IoT Build 19:d4f9e872bf3e 1166 const char* source = IoTHubMessage_GetString(message->messageHandle);
Azure.IoT Build 19:d4f9e872bf3e 1167 if (source == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1168 {
Azure.IoT Build 19:d4f9e872bf3e 1169 LogError("unable to IoTHubMessage_GetString");
Azure.IoT Build 19:d4f9e872bf3e 1170 STRING_delete(result);
Azure.IoT Build 19:d4f9e872bf3e 1171 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 1172 }
Azure.IoT Build 19:d4f9e872bf3e 1173 else
Azure.IoT Build 19:d4f9e872bf3e 1174 {
Azure.IoT Build 19:d4f9e872bf3e 1175 STRING_HANDLE asJson = STRING_new_JSON(source);
Azure.IoT Build 19:d4f9e872bf3e 1176 if (asJson == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1177 {
Azure.IoT Build 19:d4f9e872bf3e 1178 LogError("unable to STRING_new_JSON");
Azure.IoT Build 19:d4f9e872bf3e 1179 STRING_delete(result);
Azure.IoT Build 19:d4f9e872bf3e 1180 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 1181 }
Azure.IoT Build 19:d4f9e872bf3e 1182 else
Azure.IoT Build 19:d4f9e872bf3e 1183 {
AzureIoTClient 35:786954ce12e9 1184 size_t propertiesSize = 0;
Azure.IoT Build 19:d4f9e872bf3e 1185 if (!(
Azure.IoT Build 19:d4f9e872bf3e 1186 (STRING_concat_with_STRING(result, asJson) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 1187 (STRING_concat(result, ",\"base64Encoded\":false") == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 1188 (concat_Properties(result, IoTHubMessage_Properties(message->messageHandle), &propertiesSize) == 0) &&
Azure.IoT Build 19:d4f9e872bf3e 1189 (STRING_concat(result, "},") == 0) /*the last comma shall be replaced by a ']' by DaCr's suggestion (which is awesome enough to receive credits in the source code)*/
Azure.IoT Build 19:d4f9e872bf3e 1190 ))
Azure.IoT Build 19:d4f9e872bf3e 1191 {
Azure.IoT Build 19:d4f9e872bf3e 1192 LogError("unable to STRING_concat_with_STRING");
Azure.IoT Build 19:d4f9e872bf3e 1193 STRING_delete(result);
Azure.IoT Build 19:d4f9e872bf3e 1194 result = NULL;
Azure.IoT Build 19:d4f9e872bf3e 1195 }
Azure.IoT Build 19:d4f9e872bf3e 1196 else
Azure.IoT Build 19:d4f9e872bf3e 1197 {
Azure.IoT Build 19:d4f9e872bf3e 1198 /*result has the intended content*/
Azure.IoT Build 19:d4f9e872bf3e 1199 /*Codes_SRS_TRANSPORTMULTITHTTP_17_062: [The message size is computed from the length of the payload + 384.] */
Azure.IoT Build 19:d4f9e872bf3e 1200 *messageSizeContribution = strlen(source) + MAXIMUM_PAYLOAD_OVERHEAD + propertiesSize;
Azure.IoT Build 19:d4f9e872bf3e 1201 }
Azure.IoT Build 19:d4f9e872bf3e 1202 STRING_delete(asJson);
Azure.IoT Build 19:d4f9e872bf3e 1203 }
Azure.IoT Build 19:d4f9e872bf3e 1204 }
Azure.IoT Build 19:d4f9e872bf3e 1205 }
Azure.IoT Build 19:d4f9e872bf3e 1206 break;
Azure.IoT Build 19:d4f9e872bf3e 1207 }
Azure.IoT Build 19:d4f9e872bf3e 1208 default:
Azure.IoT Build 19:d4f9e872bf3e 1209 {
Azure.IoT Build 19:d4f9e872bf3e 1210 LogError("an unknown message type was encountered (%d)", contentType);
Azure.IoT Build 19:d4f9e872bf3e 1211 result = NULL; /*unknown message type*/
Azure.IoT Build 19:d4f9e872bf3e 1212 break;
Azure.IoT Build 19:d4f9e872bf3e 1213 }
Azure.IoT Build 19:d4f9e872bf3e 1214 }
Azure.IoT Build 19:d4f9e872bf3e 1215 return result;
AzureIoTClient 6:73793bae15ba 1216 }
AzureIoTClient 6:73793bae15ba 1217
AzureIoTClient 6:73793bae15ba 1218 #define MAKE_PAYLOAD_RESULT_VALUES \
AzureIoTClient 6:73793bae15ba 1219 MAKE_PAYLOAD_OK, /*returned when there is a payload to be later send by HTTP*/ \
AzureIoTClient 6:73793bae15ba 1220 MAKE_PAYLOAD_NO_ITEMS, /*returned when there are no items to be send*/ \
AzureIoTClient 6:73793bae15ba 1221 MAKE_PAYLOAD_ERROR, /*returned when there were errors*/ \
AzureIoTClient 6:73793bae15ba 1222 MAKE_PAYLOAD_FIRST_ITEM_DOES_NOT_FIT /*returned when the first item doesn't fit*/
AzureIoTClient 6:73793bae15ba 1223
AzureIoTClient 6:73793bae15ba 1224 DEFINE_ENUM(MAKE_PAYLOAD_RESULT, MAKE_PAYLOAD_RESULT_VALUES);
AzureIoTClient 6:73793bae15ba 1225
AzureIoTClient 6:73793bae15ba 1226 /*this function assembles several {"body":"base64 encoding of the message content"," base64Encoded": true} into 1 payload*/
Azure.IoT Build 13:848d52f93daf 1227 /*Codes_SRS_TRANSPORTMULTITHTTP_17_056: [IoTHubTransportHttp_DoWork shall build the following string:[{"body":"base64 encoding of the message1 content"},{"body":"base64 encoding of the message2 content"}...]]*/
Azure.IoT Build 13:848d52f93daf 1228 static MAKE_PAYLOAD_RESULT makePayload(HTTPTRANSPORT_PERDEVICE_DATA* deviceData, STRING_HANDLE* payload)
AzureIoTClient 6:73793bae15ba 1229 {
Azure.IoT Build 19:d4f9e872bf3e 1230 MAKE_PAYLOAD_RESULT result;
Azure.IoT Build 19:d4f9e872bf3e 1231 size_t allMessagesSize = 0;
Azure.IoT Build 19:d4f9e872bf3e 1232 *payload = STRING_construct("[");
Azure.IoT Build 19:d4f9e872bf3e 1233 if (*payload == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1234 {
Azure.IoT Build 19:d4f9e872bf3e 1235 LogError("unable to STRING_construct");
Azure.IoT Build 19:d4f9e872bf3e 1236 result = MAKE_PAYLOAD_ERROR;
Azure.IoT Build 19:d4f9e872bf3e 1237 }
Azure.IoT Build 19:d4f9e872bf3e 1238 else
Azure.IoT Build 19:d4f9e872bf3e 1239 {
Azure.IoT Build 19:d4f9e872bf3e 1240 bool isFirst = true;
Azure.IoT Build 19:d4f9e872bf3e 1241 PDLIST_ENTRY actual;
Azure.IoT Build 19:d4f9e872bf3e 1242 bool keepGoing = true; /*keepGoing gets sometimes to false from within the loop*/
Azure.IoT Build 19:d4f9e872bf3e 1243 /*either all the items enter the list or only some*/
Azure.IoT Build 19:d4f9e872bf3e 1244 result = MAKE_PAYLOAD_OK; /*optimistically initializing it*/
Azure.IoT Build 19:d4f9e872bf3e 1245 while (keepGoing && ((actual = deviceData->waitingToSend->Flink) != deviceData->waitingToSend))
Azure.IoT Build 19:d4f9e872bf3e 1246 {
Azure.IoT Build 19:d4f9e872bf3e 1247 size_t messageSize;
Azure.IoT Build 19:d4f9e872bf3e 1248 STRING_HANDLE temp = make1EventJSONitem(actual, &messageSize);
Azure.IoT Build 19:d4f9e872bf3e 1249 if (isFirst)
Azure.IoT Build 19:d4f9e872bf3e 1250 {
Azure.IoT Build 19:d4f9e872bf3e 1251 isFirst = false;
Azure.IoT Build 19:d4f9e872bf3e 1252 /*Codes_SRS_TRANSPORTMULTITHTTP_17_067: [If there is no valid payload, IoTHubTransportHttp_DoWork shall advance to the next activity.]*/
Azure.IoT Build 19:d4f9e872bf3e 1253 if (temp == NULL) /*first item failed to create, nothing to send*/
Azure.IoT Build 19:d4f9e872bf3e 1254 {
Azure.IoT Build 19:d4f9e872bf3e 1255 result = MAKE_PAYLOAD_ERROR;
Azure.IoT Build 19:d4f9e872bf3e 1256 STRING_delete(*payload);
Azure.IoT Build 19:d4f9e872bf3e 1257 *payload = NULL;
Azure.IoT Build 19:d4f9e872bf3e 1258 keepGoing = false;
Azure.IoT Build 19:d4f9e872bf3e 1259 }
Azure.IoT Build 19:d4f9e872bf3e 1260 else
Azure.IoT Build 19:d4f9e872bf3e 1261 {
AzureIoTClient 36:36c1e1ca5679 1262 /*Codes_SRS_TRANSPORTMULTITHTTP_17_065: [If the oldest message in waitingToSend causes the message size to exceed the message size limit then it shall be removed from waitingToSend, and IoTHubClientCore_LL_SendComplete shall be called. Parameter PDLIST_ENTRY completed shall point to a list containing only the oldest item, and parameter IOTHUB_CLIENT_CONFIRMATION_RESULT result shall be set to IOTHUB_CLIENT_CONFIRMATION_BATCHSTATE_FAILED.]*/
Azure.IoT Build 19:d4f9e872bf3e 1263 /*Codes_SRS_TRANSPORTMULTITHTTP_17_061: [The message size shall be limited to 255KB - 1 byte.]*/
Azure.IoT Build 19:d4f9e872bf3e 1264 if (messageSize > MAXIMUM_MESSAGE_SIZE)
Azure.IoT Build 19:d4f9e872bf3e 1265 {
Azure.IoT Build 19:d4f9e872bf3e 1266 PDLIST_ENTRY head = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/
Azure.IoT Build 19:d4f9e872bf3e 1267 DList_InsertTailList(&(deviceData->eventConfirmations), head);
Azure.IoT Build 19:d4f9e872bf3e 1268 result = MAKE_PAYLOAD_FIRST_ITEM_DOES_NOT_FIT;
Azure.IoT Build 19:d4f9e872bf3e 1269 STRING_delete(*payload);
Azure.IoT Build 19:d4f9e872bf3e 1270 *payload = NULL;
Azure.IoT Build 19:d4f9e872bf3e 1271 keepGoing = false;
Azure.IoT Build 19:d4f9e872bf3e 1272 }
Azure.IoT Build 19:d4f9e872bf3e 1273 else
Azure.IoT Build 19:d4f9e872bf3e 1274 {
Azure.IoT Build 19:d4f9e872bf3e 1275 if (STRING_concat_with_STRING(*payload, temp) != 0)
Azure.IoT Build 19:d4f9e872bf3e 1276 {
Azure.IoT Build 19:d4f9e872bf3e 1277 /*Codes_SRS_TRANSPORTMULTITHTTP_17_067: [If there is no valid payload, IoTHubTransportHttp_DoWork shall advance to the next activity.]*/
Azure.IoT Build 19:d4f9e872bf3e 1278 result = MAKE_PAYLOAD_ERROR;
Azure.IoT Build 19:d4f9e872bf3e 1279 STRING_delete(*payload);
Azure.IoT Build 19:d4f9e872bf3e 1280 *payload = NULL;
Azure.IoT Build 19:d4f9e872bf3e 1281 keepGoing = false;
Azure.IoT Build 19:d4f9e872bf3e 1282 }
Azure.IoT Build 19:d4f9e872bf3e 1283 else
Azure.IoT Build 19:d4f9e872bf3e 1284 {
Azure.IoT Build 19:d4f9e872bf3e 1285 /*first item was put nicely in the payload*/
Azure.IoT Build 19:d4f9e872bf3e 1286 PDLIST_ENTRY head = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/
Azure.IoT Build 19:d4f9e872bf3e 1287 DList_InsertTailList(&(deviceData->eventConfirmations), head);
Azure.IoT Build 19:d4f9e872bf3e 1288 allMessagesSize += messageSize;
Azure.IoT Build 19:d4f9e872bf3e 1289 }
Azure.IoT Build 19:d4f9e872bf3e 1290 }
Azure.IoT Build 19:d4f9e872bf3e 1291 STRING_delete(temp);
Azure.IoT Build 19:d4f9e872bf3e 1292 }
Azure.IoT Build 19:d4f9e872bf3e 1293 }
Azure.IoT Build 19:d4f9e872bf3e 1294 else
Azure.IoT Build 19:d4f9e872bf3e 1295 {
Azure.IoT Build 19:d4f9e872bf3e 1296 /*there is at least 1 item already in the payload*/
Azure.IoT Build 19:d4f9e872bf3e 1297 if (temp == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1298 {
Azure.IoT Build 19:d4f9e872bf3e 1299 /*there are multiple payloads encoded, the last one had an internal error, just go with those - closing the payload happens "after the loop"*/
Azure.IoT Build 19:d4f9e872bf3e 1300 /*Codes_SRS_TRANSPORTMULTITHTTP_17_066: [If at any point during construction of the string there are errors, IoTHubTransportHttp_DoWork shall use the so far constructed string as payload.]*/
Azure.IoT Build 19:d4f9e872bf3e 1301 result = MAKE_PAYLOAD_OK;
Azure.IoT Build 19:d4f9e872bf3e 1302 keepGoing = false;
Azure.IoT Build 19:d4f9e872bf3e 1303 }
Azure.IoT Build 19:d4f9e872bf3e 1304 else
Azure.IoT Build 19:d4f9e872bf3e 1305 {
Azure.IoT Build 19:d4f9e872bf3e 1306 if (allMessagesSize + messageSize > MAXIMUM_MESSAGE_SIZE)
Azure.IoT Build 19:d4f9e872bf3e 1307 {
Azure.IoT Build 19:d4f9e872bf3e 1308 /*this item doesn't make it to the payload, but the payload is valid so far*/
Azure.IoT Build 19:d4f9e872bf3e 1309 /*Codes_SRS_TRANSPORTMULTITHTTP_17_066: [If at any point during construction of the string there are errors, IoTHubTransportHttp_DoWork shall use the so far constructed string as payload.]*/
Azure.IoT Build 19:d4f9e872bf3e 1310 result = MAKE_PAYLOAD_OK;
Azure.IoT Build 19:d4f9e872bf3e 1311 keepGoing = false;
Azure.IoT Build 19:d4f9e872bf3e 1312 }
Azure.IoT Build 19:d4f9e872bf3e 1313 else if (STRING_concat_with_STRING(*payload, temp) != 0)
Azure.IoT Build 19:d4f9e872bf3e 1314 {
Azure.IoT Build 19:d4f9e872bf3e 1315 /*should still send what there is so far...*/
Azure.IoT Build 19:d4f9e872bf3e 1316 /*Codes_SRS_TRANSPORTMULTITHTTP_17_066: [If at any point during construction of the string there are errors, IoTHubTransportHttp_DoWork shall use the so far constructed string as payload.]*/
Azure.IoT Build 19:d4f9e872bf3e 1317 result = MAKE_PAYLOAD_OK;
Azure.IoT Build 19:d4f9e872bf3e 1318 keepGoing = false;
Azure.IoT Build 19:d4f9e872bf3e 1319 }
Azure.IoT Build 19:d4f9e872bf3e 1320 else
Azure.IoT Build 19:d4f9e872bf3e 1321 {
Azure.IoT Build 19:d4f9e872bf3e 1322 /*cool, the payload made it there, let's continue... */
Azure.IoT Build 19:d4f9e872bf3e 1323 PDLIST_ENTRY head = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/
Azure.IoT Build 19:d4f9e872bf3e 1324 DList_InsertTailList(&(deviceData->eventConfirmations), head);
Azure.IoT Build 19:d4f9e872bf3e 1325 allMessagesSize += messageSize;
Azure.IoT Build 19:d4f9e872bf3e 1326 }
Azure.IoT Build 19:d4f9e872bf3e 1327 STRING_delete(temp);
Azure.IoT Build 19:d4f9e872bf3e 1328 }
Azure.IoT Build 19:d4f9e872bf3e 1329 }
Azure.IoT Build 19:d4f9e872bf3e 1330 }
AzureIoTClient 6:73793bae15ba 1331
Azure.IoT Build 19:d4f9e872bf3e 1332 /*closing the payload*/
Azure.IoT Build 19:d4f9e872bf3e 1333 if (result == MAKE_PAYLOAD_OK)
Azure.IoT Build 19:d4f9e872bf3e 1334 {
Azure.IoT Build 19:d4f9e872bf3e 1335 ((char*)STRING_c_str(*payload))[STRING_length(*payload) - 1] = ']'; /*TODO - do this in STRING_HANDLE*/
Azure.IoT Build 19:d4f9e872bf3e 1336 }
Azure.IoT Build 19:d4f9e872bf3e 1337 else
Azure.IoT Build 19:d4f9e872bf3e 1338 {
Azure.IoT Build 19:d4f9e872bf3e 1339 /*no need to close anything*/
Azure.IoT Build 19:d4f9e872bf3e 1340 }
Azure.IoT Build 19:d4f9e872bf3e 1341 }
Azure.IoT Build 19:d4f9e872bf3e 1342 return result;
AzureIoTClient 6:73793bae15ba 1343 }
AzureIoTClient 6:73793bae15ba 1344
AzureIoTClient 6:73793bae15ba 1345 static void reversePutListBackIn(PDLIST_ENTRY source, PDLIST_ENTRY destination)
AzureIoTClient 6:73793bae15ba 1346 {
Azure.IoT Build 19:d4f9e872bf3e 1347 /*this function takes a list, and inserts it in another list. When done in the context of this file, it reverses the effects of a not-able-to-send situation*/
Azure.IoT Build 19:d4f9e872bf3e 1348 DList_AppendTailList(destination->Flink, source);
Azure.IoT Build 19:d4f9e872bf3e 1349 DList_RemoveEntryList(source);
Azure.IoT Build 19:d4f9e872bf3e 1350 DList_InitializeListHead(source);
AzureIoTClient 6:73793bae15ba 1351 }
AzureIoTClient 6:73793bae15ba 1352
AzureIoTClient 36:36c1e1ca5679 1353 static void DoEvent(HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTRANSPORT_PERDEVICE_DATA* deviceData, IOTHUB_CLIENT_CORE_LL_HANDLE iotHubClientHandle)
AzureIoTClient 6:73793bae15ba 1354 {
Azure.IoT Build 13:848d52f93daf 1355
Azure.IoT Build 19:d4f9e872bf3e 1356 if (DList_IsListEmpty(deviceData->waitingToSend))
Azure.IoT Build 19:d4f9e872bf3e 1357 {
Azure.IoT Build 19:d4f9e872bf3e 1358 /*Codes_SRS_TRANSPORTMULTITHTTP_17_060: [If the list is empty then IoTHubTransportHttp_DoWork shall proceed to the following action.] */
Azure.IoT Build 19:d4f9e872bf3e 1359 }
Azure.IoT Build 19:d4f9e872bf3e 1360 else
Azure.IoT Build 19:d4f9e872bf3e 1361 {
Azure.IoT Build 19:d4f9e872bf3e 1362 /*Codes_SRS_TRANSPORTMULTITHTTP_17_053: [If option SetBatching is true then _Dowork shall send batched event message as specced below.] */
Azure.IoT Build 19:d4f9e872bf3e 1363 if (handleData->doBatchedTransfers)
Azure.IoT Build 19:d4f9e872bf3e 1364 {
Azure.IoT Build 19:d4f9e872bf3e 1365 /*Codes_SRS_TRANSPORTMULTITHTTP_17_054: [Request HTTP headers shall have the value of "Content-Type" created or updated to "application/vnd.microsoft.iothub.json" by a call to HTTPHeaders_ReplaceHeaderNameValuePair.] */
Azure.IoT Build 19:d4f9e872bf3e 1366 if (HTTPHeaders_ReplaceHeaderNameValuePair(deviceData->eventHTTPrequestHeaders, CONTENT_TYPE, APPLICATION_VND_MICROSOFT_IOTHUB_JSON) != HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 1367 {
Azure.IoT Build 19:d4f9e872bf3e 1368 /*Codes_SRS_TRANSPORTMULTITHTTP_17_055: [If updating Content-Type fails for any reason, then _DoWork shall advance to the next action.] */
Azure.IoT Build 19:d4f9e872bf3e 1369 LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair");
Azure.IoT Build 19:d4f9e872bf3e 1370 }
Azure.IoT Build 19:d4f9e872bf3e 1371 else
Azure.IoT Build 19:d4f9e872bf3e 1372 {
Azure.IoT Build 19:d4f9e872bf3e 1373 /*Codes_SRS_TRANSPORTMULTITHTTP_17_059: [It shall inspect the "waitingToSend" DLIST passed in config structure.] */
Azure.IoT Build 19:d4f9e872bf3e 1374 STRING_HANDLE payload;
Azure.IoT Build 19:d4f9e872bf3e 1375 switch (makePayload(deviceData, &payload))
Azure.IoT Build 19:d4f9e872bf3e 1376 {
Azure.IoT Build 19:d4f9e872bf3e 1377 case MAKE_PAYLOAD_OK:
Azure.IoT Build 19:d4f9e872bf3e 1378 {
Azure.IoT Build 19:d4f9e872bf3e 1379 /*Codes_SRS_TRANSPORTMULTITHTTP_17_068: [Once a final payload has been obtained, IoTHubTransportHttp_DoWork shall call HTTPAPIEX_SAS_ExecuteRequest passing the following parameters:] */
Azure.IoT Build 19:d4f9e872bf3e 1380 BUFFER_HANDLE temp = BUFFER_new();
Azure.IoT Build 19:d4f9e872bf3e 1381 if (temp == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1382 {
Azure.IoT Build 19:d4f9e872bf3e 1383 LogError("unable to BUFFER_new");
Azure.IoT Build 19:d4f9e872bf3e 1384 /*Codes_SRS_TRANSPORTMULTITHTTP_17_067: [If there is no valid payload, IoTHubTransportHttp_DoWork shall advance to the next activity.]*/
Azure.IoT Build 19:d4f9e872bf3e 1385 reversePutListBackIn(&(deviceData->eventConfirmations), deviceData->waitingToSend);
Azure.IoT Build 19:d4f9e872bf3e 1386 }
Azure.IoT Build 19:d4f9e872bf3e 1387 else
Azure.IoT Build 19:d4f9e872bf3e 1388 {
Azure.IoT Build 19:d4f9e872bf3e 1389 if (BUFFER_build(temp, (const unsigned char*)STRING_c_str(payload), STRING_length(payload)) != 0)
Azure.IoT Build 19:d4f9e872bf3e 1390 {
Azure.IoT Build 19:d4f9e872bf3e 1391 LogError("unable to BUFFER_build");
Azure.IoT Build 19:d4f9e872bf3e 1392 //items go back to waitingToSend
Azure.IoT Build 19:d4f9e872bf3e 1393 /*Codes_SRS_TRANSPORTMULTITHTTP_17_067: [If there is no valid payload, IoTHubTransportHttp_DoWork shall advance to the next activity.]*/
Azure.IoT Build 19:d4f9e872bf3e 1394 reversePutListBackIn(&(deviceData->eventConfirmations), deviceData->waitingToSend);
Azure.IoT Build 19:d4f9e872bf3e 1395 }
Azure.IoT Build 19:d4f9e872bf3e 1396 else
Azure.IoT Build 19:d4f9e872bf3e 1397 {
Azure.IoT Build 19:d4f9e872bf3e 1398 unsigned int statusCode;
AzureIoTClient 25:3a68a581d3f9 1399 if (HTTPAPIEX_SAS_ExecuteRequest(
Azure.IoT Build 19:d4f9e872bf3e 1400 deviceData->sasObject,
Azure.IoT Build 19:d4f9e872bf3e 1401 handleData->httpApiExHandle,
Azure.IoT Build 19:d4f9e872bf3e 1402 HTTPAPI_REQUEST_POST,
Azure.IoT Build 19:d4f9e872bf3e 1403 STRING_c_str(deviceData->eventHTTPrelativePath),
Azure.IoT Build 19:d4f9e872bf3e 1404 deviceData->eventHTTPrequestHeaders,
Azure.IoT Build 19:d4f9e872bf3e 1405 temp,
Azure.IoT Build 19:d4f9e872bf3e 1406 &statusCode,
Azure.IoT Build 19:d4f9e872bf3e 1407 NULL,
Azure.IoT Build 19:d4f9e872bf3e 1408 NULL
AzureIoTClient 35:786954ce12e9 1409 ) != HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 1410 {
Azure.IoT Build 19:d4f9e872bf3e 1411 LogError("unable to HTTPAPIEX_ExecuteRequest");
Azure.IoT Build 19:d4f9e872bf3e 1412 //items go back to waitingToSend
Azure.IoT Build 19:d4f9e872bf3e 1413 /*Codes_SRS_TRANSPORTMULTITHTTP_17_069: [if HTTPAPIEX_SAS_ExecuteRequest fails or the http status code >=300 then IoTHubTransportHttp_DoWork shall not do any other action (it is assumed at the next _DoWork it shall be retried).] */
Azure.IoT Build 19:d4f9e872bf3e 1414 reversePutListBackIn(&(deviceData->eventConfirmations), deviceData->waitingToSend);
Azure.IoT Build 19:d4f9e872bf3e 1415 }
Azure.IoT Build 19:d4f9e872bf3e 1416 else
Azure.IoT Build 19:d4f9e872bf3e 1417 {
Azure.IoT Build 19:d4f9e872bf3e 1418 if (statusCode < 300)
Azure.IoT Build 19:d4f9e872bf3e 1419 {
AzureIoTClient 36:36c1e1ca5679 1420 /*Codes_SRS_TRANSPORTMULTITHTTP_17_070: [If HTTPAPIEX_SAS_ExecuteRequest does not fail and http status code <300 then IoTHubTransportHttp_DoWork shall call IoTHubClientCore_LL_SendComplete. Parameter PDLIST_ENTRY completed shall point to a list containing all the items batched, and parameter IOTHUB_CLIENT_CONFIRMATION_RESULT result shall be set to IOTHUB_CLIENT_CONFIRMATION_OK. The batched items shall be removed from waitingToSend.] */
AzureIoTClient 36:36c1e1ca5679 1421 IoTHubClientCore_LL_SendComplete(iotHubClientHandle, &(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_OK);
Azure.IoT Build 19:d4f9e872bf3e 1422 }
Azure.IoT Build 19:d4f9e872bf3e 1423 else
Azure.IoT Build 19:d4f9e872bf3e 1424 {
Azure.IoT Build 19:d4f9e872bf3e 1425 //items go back to waitingToSend
Azure.IoT Build 19:d4f9e872bf3e 1426 /*Codes_SRS_TRANSPORTMULTITHTTP_17_069: [if HTTPAPIEX_SAS_ExecuteRequest fails or the http status code >=300 then IoTHubTransportHttp_DoWork shall not do any other action (it is assumed at the next _DoWork it shall be retried).] */
Azure.IoT Build 19:d4f9e872bf3e 1427 LogError("unexpected HTTP status code (%u)", statusCode);
Azure.IoT Build 19:d4f9e872bf3e 1428 reversePutListBackIn(&(deviceData->eventConfirmations), deviceData->waitingToSend);
Azure.IoT Build 19:d4f9e872bf3e 1429 }
Azure.IoT Build 19:d4f9e872bf3e 1430 }
Azure.IoT Build 19:d4f9e872bf3e 1431 }
Azure.IoT Build 19:d4f9e872bf3e 1432 BUFFER_delete(temp);
Azure.IoT Build 19:d4f9e872bf3e 1433 }
Azure.IoT Build 19:d4f9e872bf3e 1434 STRING_delete(payload);
Azure.IoT Build 19:d4f9e872bf3e 1435 break;
Azure.IoT Build 19:d4f9e872bf3e 1436 }
Azure.IoT Build 19:d4f9e872bf3e 1437 case MAKE_PAYLOAD_FIRST_ITEM_DOES_NOT_FIT:
Azure.IoT Build 19:d4f9e872bf3e 1438 {
AzureIoTClient 36:36c1e1ca5679 1439 IoTHubClientCore_LL_SendComplete(iotHubClientHandle, &(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_ERROR); /*takes care of emptying the list too*/
Azure.IoT Build 19:d4f9e872bf3e 1440 break;
Azure.IoT Build 19:d4f9e872bf3e 1441 }
Azure.IoT Build 19:d4f9e872bf3e 1442 case MAKE_PAYLOAD_ERROR:
Azure.IoT Build 19:d4f9e872bf3e 1443 {
Azure.IoT Build 19:d4f9e872bf3e 1444 LogError("unrecoverable errors while building a batch message");
Azure.IoT Build 19:d4f9e872bf3e 1445 break;
Azure.IoT Build 19:d4f9e872bf3e 1446 }
Azure.IoT Build 19:d4f9e872bf3e 1447 case MAKE_PAYLOAD_NO_ITEMS:
Azure.IoT Build 19:d4f9e872bf3e 1448 {
Azure.IoT Build 19:d4f9e872bf3e 1449 /*do nothing*/
Azure.IoT Build 19:d4f9e872bf3e 1450 break;
Azure.IoT Build 19:d4f9e872bf3e 1451 }
Azure.IoT Build 19:d4f9e872bf3e 1452 default:
Azure.IoT Build 19:d4f9e872bf3e 1453 {
Azure.IoT Build 19:d4f9e872bf3e 1454 LogError("internal error: switch's default branch reached when never intended");
Azure.IoT Build 19:d4f9e872bf3e 1455 break;
Azure.IoT Build 19:d4f9e872bf3e 1456 }
Azure.IoT Build 19:d4f9e872bf3e 1457 }
Azure.IoT Build 19:d4f9e872bf3e 1458 }
Azure.IoT Build 19:d4f9e872bf3e 1459 }
Azure.IoT Build 19:d4f9e872bf3e 1460 else
Azure.IoT Build 19:d4f9e872bf3e 1461 {
AzureIoTClient 35:786954ce12e9 1462 const unsigned char* messageContent = NULL;
AzureIoTClient 35:786954ce12e9 1463 size_t messageSize = 0;
AzureIoTClient 35:786954ce12e9 1464 size_t originalMessageSize = 0;
Azure.IoT Build 19:d4f9e872bf3e 1465 IOTHUB_MESSAGE_LIST* message = containingRecord(deviceData->waitingToSend->Flink, IOTHUB_MESSAGE_LIST, entry);
Azure.IoT Build 19:d4f9e872bf3e 1466 IOTHUBMESSAGE_CONTENT_TYPE contentType = IoTHubMessage_GetContentType(message->messageHandle);
AzureIoTClient 6:73793bae15ba 1467
Azure.IoT Build 19:d4f9e872bf3e 1468 /*Codes_SRS_TRANSPORTMULTITHTTP_17_073: [The message size is computed from the length of the payload + 384.]*/
Azure.IoT Build 19:d4f9e872bf3e 1469 if (!(
Azure.IoT Build 19:d4f9e872bf3e 1470 (((contentType == IOTHUBMESSAGE_BYTEARRAY) &&
AzureIoTClient 35:786954ce12e9 1471 (IoTHubMessage_GetByteArray(message->messageHandle, &messageContent, &originalMessageSize) == IOTHUB_MESSAGE_OK))
AzureIoTClient 35:786954ce12e9 1472 ? ((void)(messageSize = originalMessageSize + MAXIMUM_PAYLOAD_OVERHEAD), 1)
AzureIoTClient 35:786954ce12e9 1473 : 0)
AzureIoTClient 17:7ef88cde801f 1474
Azure.IoT Build 19:d4f9e872bf3e 1475 ||
AzureIoTClient 6:73793bae15ba 1476
AzureIoTClient 35:786954ce12e9 1477 ((contentType == IOTHUBMESSAGE_STRING) &&
AzureIoTClient 35:786954ce12e9 1478 ((void)(messageContent = (const unsigned char*)IoTHubMessage_GetString(message->messageHandle)),
AzureIoTClient 35:786954ce12e9 1479 ((void)(messageSize = MAXIMUM_PAYLOAD_OVERHEAD + (originalMessageSize = ((messageContent == NULL)
AzureIoTClient 35:786954ce12e9 1480 ? 0
AzureIoTClient 35:786954ce12e9 1481 : strlen((const char*)messageContent))))),
AzureIoTClient 35:786954ce12e9 1482 messageContent != NULL)
Azure.IoT Build 19:d4f9e872bf3e 1483 )
Azure.IoT Build 19:d4f9e872bf3e 1484 ))
Azure.IoT Build 19:d4f9e872bf3e 1485 {
Azure.IoT Build 19:d4f9e872bf3e 1486 LogError("unable to get the message content");
Azure.IoT Build 19:d4f9e872bf3e 1487 /*go on...*/
Azure.IoT Build 19:d4f9e872bf3e 1488 }
Azure.IoT Build 19:d4f9e872bf3e 1489 else
Azure.IoT Build 19:d4f9e872bf3e 1490 {
AzureIoTClient 36:36c1e1ca5679 1491 /*Codes_SRS_TRANSPORTMULTITHTTP_17_075: [If the oldest message in waitingToSend causes the message to exceed the message size limit then it shall be removed from waitingToSend, and IoTHubClientCore_LL_SendComplete shall be called. Parameter PDLIST_ENTRY completed shall point to a list containing only the oldest item, and parameter IOTHUB_CLIENT_CONFIRMATION_RESULT result shall be set to IOTHUB_CLIENT_CONFIRMATION_BATCHSTATE_FAILED.]*/
Azure.IoT Build 19:d4f9e872bf3e 1492 /*Codes_SRS_TRANSPORTMULTITHTTP_17_072: [The message size shall be limited to 255KB -1 bytes.] */
Azure.IoT Build 19:d4f9e872bf3e 1493 if (messageSize > MAXIMUM_MESSAGE_SIZE)
Azure.IoT Build 19:d4f9e872bf3e 1494 {
Azure.IoT Build 19:d4f9e872bf3e 1495 PDLIST_ENTRY head = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/
Azure.IoT Build 19:d4f9e872bf3e 1496 DList_InsertTailList(&(deviceData->eventConfirmations), head);
AzureIoTClient 36:36c1e1ca5679 1497 IoTHubClientCore_LL_SendComplete(iotHubClientHandle, &(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_ERROR); /*takes care of emptying the list too*/
Azure.IoT Build 19:d4f9e872bf3e 1498 }
Azure.IoT Build 19:d4f9e872bf3e 1499 else
Azure.IoT Build 19:d4f9e872bf3e 1500 {
Azure.IoT Build 19:d4f9e872bf3e 1501 /*Codes_SRS_TRANSPORTMULTITHTTP_17_071: [If option SetBatching is false then _Dowork shall send individual event message as specced below.] */
Azure.IoT Build 19:d4f9e872bf3e 1502 /*Codes_SRS_TRANSPORTMULTITHTTP_17_076: [A clone of the event HTTP request headers shall be created.]*/
Azure.IoT Build 19:d4f9e872bf3e 1503 HTTP_HEADERS_HANDLE clonedEventHTTPrequestHeaders = HTTPHeaders_Clone(deviceData->eventHTTPrequestHeaders);
Azure.IoT Build 19:d4f9e872bf3e 1504 if (clonedEventHTTPrequestHeaders == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1505 {
Azure.IoT Build 19:d4f9e872bf3e 1506 /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */
Azure.IoT Build 19:d4f9e872bf3e 1507 LogError("HTTPHeaders_Clone failed");
Azure.IoT Build 19:d4f9e872bf3e 1508 }
Azure.IoT Build 19:d4f9e872bf3e 1509 else
Azure.IoT Build 19:d4f9e872bf3e 1510 {
Azure.IoT Build 19:d4f9e872bf3e 1511 /*Codes_SRS_TRANSPORTMULTITHTTP_17_077: [The cloned HTTP headers shall have the HTTP header "Content-Type" set to "application/octet-stream".] */
Azure.IoT Build 19:d4f9e872bf3e 1512 if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, CONTENT_TYPE, APPLICATION_OCTET_STREAM) != HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 1513 {
Azure.IoT Build 19:d4f9e872bf3e 1514 /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */
Azure.IoT Build 19:d4f9e872bf3e 1515 LogError("HTTPHeaders_ReplaceHeaderNameValuePair failed");
Azure.IoT Build 19:d4f9e872bf3e 1516 }
Azure.IoT Build 19:d4f9e872bf3e 1517 else
Azure.IoT Build 19:d4f9e872bf3e 1518 {
Azure.IoT Build 19:d4f9e872bf3e 1519 /*Codes_SRS_TRANSPORTMULTITHTTP_17_078: [Every message property "property":"value" shall be added to the HTTP headers as an individual header "iothub-app-property":"value".] */
Azure.IoT Build 19:d4f9e872bf3e 1520 MAP_HANDLE map = IoTHubMessage_Properties(message->messageHandle);
Azure.IoT Build 19:d4f9e872bf3e 1521 const char*const* keys;
Azure.IoT Build 19:d4f9e872bf3e 1522 const char*const* values;
Azure.IoT Build 19:d4f9e872bf3e 1523 size_t count;
Azure.IoT Build 19:d4f9e872bf3e 1524 if (Map_GetInternals(map, &keys, &values, &count) != MAP_OK)
Azure.IoT Build 19:d4f9e872bf3e 1525 {
AzureIoTClient 32:4d4a226b072b 1526 /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */
Azure.IoT Build 19:d4f9e872bf3e 1527 LogError("unable to Map_GetInternals");
Azure.IoT Build 19:d4f9e872bf3e 1528 }
Azure.IoT Build 19:d4f9e872bf3e 1529 else
Azure.IoT Build 19:d4f9e872bf3e 1530 {
Azure.IoT Build 19:d4f9e872bf3e 1531 size_t i;
Azure.IoT Build 19:d4f9e872bf3e 1532 bool goOn = true;
Azure.IoT Build 19:d4f9e872bf3e 1533 const char* msgId;
Azure.IoT Build 19:d4f9e872bf3e 1534 const char* corrId;
AzureIoTClient 32:4d4a226b072b 1535 const char* userDefinedContentType;
AzureIoTClient 32:4d4a226b072b 1536 const char* contentEncoding;
AzureIoTClient 17:7ef88cde801f 1537
Azure.IoT Build 19:d4f9e872bf3e 1538 for (i = 0; (i < count) && goOn; i++)
Azure.IoT Build 19:d4f9e872bf3e 1539 {
Azure.IoT Build 19:d4f9e872bf3e 1540 /*Codes_SRS_TRANSPORTMULTITHTTP_17_074: [Every property name shall add to the message size the length of the property name + the length of the property value + 16 bytes.] */
Azure.IoT Build 19:d4f9e872bf3e 1541 messageSize += (strlen(values[i]) + strlen(keys[i]) + MAXIMUM_PROPERTY_OVERHEAD);
Azure.IoT Build 19:d4f9e872bf3e 1542 if (messageSize > MAXIMUM_MESSAGE_SIZE)
Azure.IoT Build 19:d4f9e872bf3e 1543 {
Azure.IoT Build 19:d4f9e872bf3e 1544 /*Codes_SRS_TRANSPORTMULTITHTTP_17_072: [The message size shall be limited to 255KB -1 bytes.] */
Azure.IoT Build 19:d4f9e872bf3e 1545 PDLIST_ENTRY head = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/
Azure.IoT Build 19:d4f9e872bf3e 1546 DList_InsertTailList(&(deviceData->eventConfirmations), head);
AzureIoTClient 36:36c1e1ca5679 1547 IoTHubClientCore_LL_SendComplete(iotHubClientHandle, &(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_ERROR); /*takes care of emptying the list too*/
Azure.IoT Build 19:d4f9e872bf3e 1548 goOn = false;
Azure.IoT Build 19:d4f9e872bf3e 1549 }
Azure.IoT Build 19:d4f9e872bf3e 1550 else
Azure.IoT Build 19:d4f9e872bf3e 1551 {
Azure.IoT Build 19:d4f9e872bf3e 1552 STRING_HANDLE temp = STRING_construct(IOTHUB_APP_PREFIX);
Azure.IoT Build 19:d4f9e872bf3e 1553 if (temp == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1554 {
Azure.IoT Build 19:d4f9e872bf3e 1555 /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */
Azure.IoT Build 19:d4f9e872bf3e 1556 LogError("unable to STRING_construct");
Azure.IoT Build 19:d4f9e872bf3e 1557 goOn = false;
Azure.IoT Build 19:d4f9e872bf3e 1558 }
Azure.IoT Build 19:d4f9e872bf3e 1559 else
Azure.IoT Build 19:d4f9e872bf3e 1560 {
Azure.IoT Build 19:d4f9e872bf3e 1561 if (STRING_concat(temp, keys[i]) != 0)
Azure.IoT Build 19:d4f9e872bf3e 1562 {
Azure.IoT Build 19:d4f9e872bf3e 1563 /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */
Azure.IoT Build 19:d4f9e872bf3e 1564 LogError("unable to STRING_concat");
Azure.IoT Build 19:d4f9e872bf3e 1565 goOn = false;
Azure.IoT Build 19:d4f9e872bf3e 1566 }
Azure.IoT Build 19:d4f9e872bf3e 1567 else
Azure.IoT Build 19:d4f9e872bf3e 1568 {
Azure.IoT Build 19:d4f9e872bf3e 1569 if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, STRING_c_str(temp), values[i]) != HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 1570 {
Azure.IoT Build 19:d4f9e872bf3e 1571 /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */
Azure.IoT Build 19:d4f9e872bf3e 1572 LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair");
Azure.IoT Build 19:d4f9e872bf3e 1573 goOn = false;
Azure.IoT Build 19:d4f9e872bf3e 1574 }
Azure.IoT Build 19:d4f9e872bf3e 1575 }
Azure.IoT Build 19:d4f9e872bf3e 1576 STRING_delete(temp);
Azure.IoT Build 19:d4f9e872bf3e 1577 }
Azure.IoT Build 19:d4f9e872bf3e 1578 }
Azure.IoT Build 19:d4f9e872bf3e 1579 }
AzureIoTClient 6:73793bae15ba 1580
Azure.IoT Build 19:d4f9e872bf3e 1581 // Add the Message Id and the Correlation Id
Azure.IoT Build 19:d4f9e872bf3e 1582 msgId = IoTHubMessage_GetMessageId(message->messageHandle);
Azure.IoT Build 19:d4f9e872bf3e 1583 if (goOn && msgId != NULL)
Azure.IoT Build 19:d4f9e872bf3e 1584 {
Azure.IoT Build 19:d4f9e872bf3e 1585 if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_MESSAGE_ID, msgId) != HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 1586 {
Azure.IoT Build 19:d4f9e872bf3e 1587 LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair");
Azure.IoT Build 19:d4f9e872bf3e 1588 goOn = false;
Azure.IoT Build 19:d4f9e872bf3e 1589 }
Azure.IoT Build 19:d4f9e872bf3e 1590 }
AzureIoTClient 17:7ef88cde801f 1591
Azure.IoT Build 19:d4f9e872bf3e 1592 corrId = IoTHubMessage_GetCorrelationId(message->messageHandle);
Azure.IoT Build 19:d4f9e872bf3e 1593 if (goOn && corrId != NULL)
Azure.IoT Build 19:d4f9e872bf3e 1594 {
Azure.IoT Build 19:d4f9e872bf3e 1595 if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_CORRELATION_ID, corrId) != HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 1596 {
Azure.IoT Build 19:d4f9e872bf3e 1597 LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair");
Azure.IoT Build 19:d4f9e872bf3e 1598 goOn = false;
Azure.IoT Build 19:d4f9e872bf3e 1599 }
Azure.IoT Build 19:d4f9e872bf3e 1600 }
AzureIoTClient 7:48f0f78cd3ef 1601
AzureIoTClient 38:01bf35934f1b 1602 // Codes_SRS_TRANSPORTMULTITHTTP_09_001: [ If the IoTHubMessage being sent contains property `content-type` it shall be added to the HTTP headers as "iothub-contenttype":"value". ]
AzureIoTClient 32:4d4a226b072b 1603 userDefinedContentType = IoTHubMessage_GetContentTypeSystemProperty(message->messageHandle);
AzureIoTClient 32:4d4a226b072b 1604 if (goOn && userDefinedContentType != NULL)
AzureIoTClient 32:4d4a226b072b 1605 {
AzureIoTClient 32:4d4a226b072b 1606 if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_CONTENT_TYPE_D2C, userDefinedContentType) != HTTP_HEADERS_OK)
AzureIoTClient 32:4d4a226b072b 1607 {
AzureIoTClient 32:4d4a226b072b 1608 LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair (content-type)");
AzureIoTClient 32:4d4a226b072b 1609 goOn = false;
AzureIoTClient 32:4d4a226b072b 1610 }
AzureIoTClient 32:4d4a226b072b 1611 }
AzureIoTClient 32:4d4a226b072b 1612
AzureIoTClient 38:01bf35934f1b 1613 // Codes_SRS_TRANSPORTMULTITHTTP_09_002: [ If the IoTHubMessage being sent contains property `content-encoding` it shall be added to the HTTP headers as "iothub-contentencoding":"value". ]
AzureIoTClient 32:4d4a226b072b 1614 contentEncoding = IoTHubMessage_GetContentEncodingSystemProperty(message->messageHandle);
AzureIoTClient 32:4d4a226b072b 1615 if (goOn && contentEncoding != NULL)
AzureIoTClient 32:4d4a226b072b 1616 {
AzureIoTClient 32:4d4a226b072b 1617 if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_CONTENT_ENCODING_D2C, contentEncoding) != HTTP_HEADERS_OK)
AzureIoTClient 32:4d4a226b072b 1618 {
AzureIoTClient 32:4d4a226b072b 1619 LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair (content-encoding)");
AzureIoTClient 32:4d4a226b072b 1620 goOn = false;
AzureIoTClient 32:4d4a226b072b 1621 }
AzureIoTClient 32:4d4a226b072b 1622 }
AzureIoTClient 32:4d4a226b072b 1623
Azure.IoT Build 19:d4f9e872bf3e 1624 if (!goOn)
Azure.IoT Build 19:d4f9e872bf3e 1625 {
Azure.IoT Build 19:d4f9e872bf3e 1626 /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */
Azure.IoT Build 19:d4f9e872bf3e 1627 }
Azure.IoT Build 19:d4f9e872bf3e 1628 else
Azure.IoT Build 19:d4f9e872bf3e 1629 {
Azure.IoT Build 19:d4f9e872bf3e 1630 BUFFER_HANDLE toBeSend = BUFFER_new();
Azure.IoT Build 19:d4f9e872bf3e 1631 if (toBeSend == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1632 {
Azure.IoT Build 19:d4f9e872bf3e 1633 LogError("unable to BUFFER_new");
Azure.IoT Build 19:d4f9e872bf3e 1634 }
Azure.IoT Build 19:d4f9e872bf3e 1635 else
Azure.IoT Build 19:d4f9e872bf3e 1636 {
Azure.IoT Build 19:d4f9e872bf3e 1637 if (BUFFER_build(toBeSend, messageContent, originalMessageSize) != 0)
Azure.IoT Build 19:d4f9e872bf3e 1638 {
Azure.IoT Build 19:d4f9e872bf3e 1639 LogError("unable to BUFFER_build");
Azure.IoT Build 19:d4f9e872bf3e 1640 }
Azure.IoT Build 19:d4f9e872bf3e 1641 else
Azure.IoT Build 19:d4f9e872bf3e 1642 {
AzureIoTClient 20:b652f2e4cccf 1643 unsigned int statusCode = 0;
Azure.IoT Build 19:d4f9e872bf3e 1644 HTTPAPIEX_RESULT r;
Azure.IoT Build 19:d4f9e872bf3e 1645 if (deviceData->deviceSasToken != NULL)
Azure.IoT Build 19:d4f9e872bf3e 1646 {
Azure.IoT Build 19:d4f9e872bf3e 1647 /*Codes_SRS_TRANSPORTMULTITHTTP_03_001: [if a deviceSasToken exists, HTTPHeaders_ReplaceHeaderNameValuePair shall be invoked with "Authorization" as its second argument and STRING_c_str (deviceSasToken) as its third argument.]*/
Azure.IoT Build 19:d4f9e872bf3e 1648 if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, "Authorization", STRING_c_str(deviceData->deviceSasToken)) != HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 1649 {
Azure.IoT Build 19:d4f9e872bf3e 1650 r = HTTPAPIEX_ERROR;
Azure.IoT Build 19:d4f9e872bf3e 1651 /*Codes_SRS_TRANSPORTMULTITHTTP_03_002: [If the result of the invocation of HTTPHeaders_ReplaceHeaderNameValuePair is NOT HTTP_HEADERS_OK then fallthrough.]*/
Azure.IoT Build 19:d4f9e872bf3e 1652 LogError("Unable to replace the old SAS Token.");
Azure.IoT Build 19:d4f9e872bf3e 1653 }
AzureIoTClient 7:48f0f78cd3ef 1654
Azure.IoT Build 19:d4f9e872bf3e 1655 /*Codes_SRS_TRANSPORTMULTITHTTP_03_003: [If a deviceSasToken exists, IoTHubTransportHttp_DoWork shall call HTTPAPIEX_ExecuteRequest passing the following parameters] */
Azure.IoT Build 19:d4f9e872bf3e 1656 else if ((r = HTTPAPIEX_ExecuteRequest(
Azure.IoT Build 19:d4f9e872bf3e 1657 handleData->httpApiExHandle,
Azure.IoT Build 19:d4f9e872bf3e 1658 HTTPAPI_REQUEST_POST,
Azure.IoT Build 19:d4f9e872bf3e 1659 STRING_c_str(deviceData->eventHTTPrelativePath),
Azure.IoT Build 19:d4f9e872bf3e 1660 clonedEventHTTPrequestHeaders,
Azure.IoT Build 19:d4f9e872bf3e 1661 toBeSend,
Azure.IoT Build 19:d4f9e872bf3e 1662 &statusCode,
Azure.IoT Build 19:d4f9e872bf3e 1663 NULL,
Azure.IoT Build 19:d4f9e872bf3e 1664 NULL
AzureIoTClient 35:786954ce12e9 1665 )) != HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 1666 {
Azure.IoT Build 19:d4f9e872bf3e 1667 LogError("Unable to HTTPAPIEX_ExecuteRequest.");
Azure.IoT Build 19:d4f9e872bf3e 1668 }
Azure.IoT Build 19:d4f9e872bf3e 1669 }
Azure.IoT Build 19:d4f9e872bf3e 1670 else
Azure.IoT Build 19:d4f9e872bf3e 1671 {
Azure.IoT Build 19:d4f9e872bf3e 1672 /*Codes_SRS_TRANSPORTMULTITHTTP_17_080: [If a deviceSasToken does not exist, IoTHubTransportHttp_DoWork shall call HTTPAPIEX_SAS_ExecuteRequest passing the following parameters] */
Azure.IoT Build 19:d4f9e872bf3e 1673 if ((r = HTTPAPIEX_SAS_ExecuteRequest(
Azure.IoT Build 19:d4f9e872bf3e 1674 deviceData->sasObject,
Azure.IoT Build 19:d4f9e872bf3e 1675 handleData->httpApiExHandle,
Azure.IoT Build 19:d4f9e872bf3e 1676 HTTPAPI_REQUEST_POST,
Azure.IoT Build 19:d4f9e872bf3e 1677 STRING_c_str(deviceData->eventHTTPrelativePath),
Azure.IoT Build 19:d4f9e872bf3e 1678 clonedEventHTTPrequestHeaders,
Azure.IoT Build 19:d4f9e872bf3e 1679 toBeSend,
Azure.IoT Build 19:d4f9e872bf3e 1680 &statusCode,
Azure.IoT Build 19:d4f9e872bf3e 1681 NULL,
Azure.IoT Build 19:d4f9e872bf3e 1682 NULL
AzureIoTClient 35:786954ce12e9 1683 )) != HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 1684 {
Azure.IoT Build 19:d4f9e872bf3e 1685 LogError("unable to HTTPAPIEX_SAS_ExecuteRequest");
Azure.IoT Build 19:d4f9e872bf3e 1686 }
Azure.IoT Build 19:d4f9e872bf3e 1687 }
Azure.IoT Build 19:d4f9e872bf3e 1688 if (r == HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 1689 {
Azure.IoT Build 19:d4f9e872bf3e 1690 if (statusCode < 300)
Azure.IoT Build 19:d4f9e872bf3e 1691 {
AzureIoTClient 36:36c1e1ca5679 1692 /*Codes_SRS_TRANSPORTMULTITHTTP_17_082: [If HTTPAPIEX_SAS_ExecuteRequest does not fail and http status code <300 then IoTHubTransportHttp_DoWork shall call IoTHubClientCore_LL_SendComplete. Parameter PDLIST_ENTRY completed shall point to a list the item send, and parameter IOTHUB_CLIENT_CONFIRMATION_RESULT result shall be set to IOTHUB_CLIENT_CONFIRMATION_OK. The item shall be removed from waitingToSend.] */
Azure.IoT Build 19:d4f9e872bf3e 1693 PDLIST_ENTRY justSent = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/
Azure.IoT Build 19:d4f9e872bf3e 1694 DList_InsertTailList(&(deviceData->eventConfirmations), justSent);
AzureIoTClient 36:36c1e1ca5679 1695 IoTHubClientCore_LL_SendComplete(iotHubClientHandle, &(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_OK); /*takes care of emptying the list too*/
Azure.IoT Build 19:d4f9e872bf3e 1696 }
Azure.IoT Build 19:d4f9e872bf3e 1697 else
Azure.IoT Build 19:d4f9e872bf3e 1698 {
Azure.IoT Build 19:d4f9e872bf3e 1699 /*Codes_SRS_TRANSPORTMULTITHTTP_17_081: [If HTTPAPIEX_SAS_ExecuteRequest fails or the http status code >=300 then IoTHubTransportHttp_DoWork shall not do any other action (it is assumed at the next _DoWork it shall be retried).] */
Azure.IoT Build 19:d4f9e872bf3e 1700 LogError("unexpected HTTP status code (%u)", statusCode);
Azure.IoT Build 19:d4f9e872bf3e 1701 }
Azure.IoT Build 19:d4f9e872bf3e 1702 }
AzureIoTClient 39:bc04888bf292 1703 else if (r == HTTPAPIEX_RECOVERYFAILED)
AzureIoTClient 39:bc04888bf292 1704 {
AzureIoTClient 39:bc04888bf292 1705 PDLIST_ENTRY justSent = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/
AzureIoTClient 39:bc04888bf292 1706 DList_InsertTailList(&(deviceData->eventConfirmations), justSent);
AzureIoTClient 39:bc04888bf292 1707 IoTHubClientCore_LL_SendComplete(iotHubClientHandle, &(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_ERROR); /*takes care of emptying the list too*/
AzureIoTClient 39:bc04888bf292 1708 }
Azure.IoT Build 19:d4f9e872bf3e 1709 }
Azure.IoT Build 19:d4f9e872bf3e 1710 BUFFER_delete(toBeSend);
Azure.IoT Build 19:d4f9e872bf3e 1711 }
Azure.IoT Build 19:d4f9e872bf3e 1712 }
Azure.IoT Build 19:d4f9e872bf3e 1713 }
Azure.IoT Build 19:d4f9e872bf3e 1714 }
Azure.IoT Build 19:d4f9e872bf3e 1715 HTTPHeaders_Free(clonedEventHTTPrequestHeaders);
Azure.IoT Build 19:d4f9e872bf3e 1716 }
Azure.IoT Build 19:d4f9e872bf3e 1717 }
Azure.IoT Build 19:d4f9e872bf3e 1718 }
Azure.IoT Build 19:d4f9e872bf3e 1719 }
Azure.IoT Build 19:d4f9e872bf3e 1720 }
AzureIoTClient 6:73793bae15ba 1721 }
AzureIoTClient 6:73793bae15ba 1722
AzureIoTClient 29:e44b1f827914 1723 static bool abandonOrAcceptMessage(HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTRANSPORT_PERDEVICE_DATA* deviceData, const char* ETag, IOTHUBMESSAGE_DISPOSITION_RESULT action)
AzureIoTClient 6:73793bae15ba 1724 {
Azure.IoT Build 19:d4f9e872bf3e 1725 /*Codes_SRS_TRANSPORTMULTITHTTP_17_097: [_DoWork shall call HTTPAPIEX_SAS_ExecuteRequest with the following parameters:
Azure.IoT Build 19:d4f9e872bf3e 1726 -requestType: POST
AzureIoTClient 25:3a68a581d3f9 1727 -relativePath: abandon relative path begin (as created by _Create) + value of ETag + "/abandon?api-version=2016-11-14"
Azure.IoT Build 19:d4f9e872bf3e 1728 - requestHttpHeadersHandle: an HTTP headers instance containing the following
Azure.IoT Build 19:d4f9e872bf3e 1729 Authorization: " "
Azure.IoT Build 19:d4f9e872bf3e 1730 If-Match: value of ETag
Azure.IoT Build 19:d4f9e872bf3e 1731 - requestContent: NULL
Azure.IoT Build 19:d4f9e872bf3e 1732 - statusCode: a pointer to unsigned int which might be examined for logging
Azure.IoT Build 19:d4f9e872bf3e 1733 - responseHeadearsHandle: NULL
Azure.IoT Build 19:d4f9e872bf3e 1734 - responseContent: NULL]*/
Azure.IoT Build 19:d4f9e872bf3e 1735 /*Codes_SRS_TRANSPORTMULTITHTTP_17_099: [_DoWork shall call HTTPAPIEX_SAS_ExecuteRequest with the following parameters:
Azure.IoT Build 19:d4f9e872bf3e 1736 -requestType: DELETE
AzureIoTClient 25:3a68a581d3f9 1737 -relativePath: abandon relative path begin + value of ETag + "?api-version=2016-11-14"
Azure.IoT Build 19:d4f9e872bf3e 1738 - requestHttpHeadersHandle: an HTTP headers instance containing the following
Azure.IoT Build 19:d4f9e872bf3e 1739 Authorization: " "
Azure.IoT Build 19:d4f9e872bf3e 1740 If-Match: value of ETag
Azure.IoT Build 19:d4f9e872bf3e 1741 - requestContent: NULL
Azure.IoT Build 19:d4f9e872bf3e 1742 - statusCode: a pointer to unsigned int which might be used by logging
Azure.IoT Build 19:d4f9e872bf3e 1743 - responseHeadearsHandle: NULL
Azure.IoT Build 19:d4f9e872bf3e 1744 - responseContent: NULL]*/
Azure.IoT Build 19:d4f9e872bf3e 1745 /*Codes_SRS_TRANSPORTMULTITHTTP_17_101: [_DoWork shall call HTTPAPIEX_SAS_ExecuteRequest with the following parameters:
Azure.IoT Build 19:d4f9e872bf3e 1746 -requestType: DELETE
AzureIoTClient 25:3a68a581d3f9 1747 -relativePath: abandon relative path begin + value of ETag +"?api-version=2016-11-14" + "&reject"
Azure.IoT Build 19:d4f9e872bf3e 1748 - requestHttpHeadersHandle: an HTTP headers instance containing the following
Azure.IoT Build 19:d4f9e872bf3e 1749 Authorization: " "
Azure.IoT Build 19:d4f9e872bf3e 1750 If-Match: value of ETag
Azure.IoT Build 19:d4f9e872bf3e 1751 - requestContent: NULL
Azure.IoT Build 19:d4f9e872bf3e 1752 - statusCode: a pointer to unsigned int which might be used by logging
Azure.IoT Build 19:d4f9e872bf3e 1753 - responseHeadearsHandle: NULL
Azure.IoT Build 19:d4f9e872bf3e 1754 - responseContent: NULL]*/
AzureIoTClient 17:7ef88cde801f 1755
AzureIoTClient 29:e44b1f827914 1756 bool result;
Azure.IoT Build 19:d4f9e872bf3e 1757 STRING_HANDLE fullAbandonRelativePath = STRING_clone(deviceData->abandonHTTPrelativePathBegin);
Azure.IoT Build 19:d4f9e872bf3e 1758 if (fullAbandonRelativePath == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1759 {
Azure.IoT Build 19:d4f9e872bf3e 1760 /*Codes_SRS_TRANSPORTMULTITHTTP_17_098: [Abandoning the message is considered successful if the HTTPAPIEX_SAS_ExecuteRequest doesn't fail and the statusCode is 204.]*/
Azure.IoT Build 19:d4f9e872bf3e 1761 /*Codes_SRS_TRANSPORTMULTITHTTP_17_100: [Accepting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1762 /*Codes_SRS_TRANSPORTMULTITHTTP_17_102: [Rejecting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1763 LogError("unable to STRING_clone");
AzureIoTClient 29:e44b1f827914 1764 result = false;
Azure.IoT Build 19:d4f9e872bf3e 1765 }
Azure.IoT Build 19:d4f9e872bf3e 1766 else
Azure.IoT Build 19:d4f9e872bf3e 1767 {
Azure.IoT Build 19:d4f9e872bf3e 1768 STRING_HANDLE ETagUnquoted = STRING_construct_n(ETag + 1, strlen(ETag) - 2); /*skip first character which is '"' and the last one (which is also '"')*/
Azure.IoT Build 19:d4f9e872bf3e 1769 if (ETagUnquoted == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1770 {
Azure.IoT Build 19:d4f9e872bf3e 1771 /*Codes_SRS_TRANSPORTMULTITHTTP_17_098: [Abandoning the message is considered successful if the HTTPAPIEX_SAS_ExecuteRequest doesn't fail and the statusCode is 204.]*/
Azure.IoT Build 19:d4f9e872bf3e 1772 /*Codes_SRS_TRANSPORTMULTITHTTP_17_100: [Accepting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1773 /*Codes_SRS_TRANSPORTMULTITHTTP_17_102: [Rejecting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1774 LogError("unable to STRING_construct_n");
AzureIoTClient 29:e44b1f827914 1775 result = false;
Azure.IoT Build 19:d4f9e872bf3e 1776 }
Azure.IoT Build 19:d4f9e872bf3e 1777 else
Azure.IoT Build 19:d4f9e872bf3e 1778 {
Azure.IoT Build 19:d4f9e872bf3e 1779 if (!(
Azure.IoT Build 19:d4f9e872bf3e 1780 (STRING_concat_with_STRING(fullAbandonRelativePath, ETagUnquoted) == 0) &&
AzureIoTClient 29:e44b1f827914 1781 (STRING_concat(fullAbandonRelativePath, (action == IOTHUBMESSAGE_ABANDONED) ? "/abandon" API_VERSION : ((action == IOTHUBMESSAGE_REJECTED) ? API_VERSION "&reject" : API_VERSION)) == 0)
Azure.IoT Build 19:d4f9e872bf3e 1782 ))
Azure.IoT Build 19:d4f9e872bf3e 1783 {
Azure.IoT Build 19:d4f9e872bf3e 1784 /*Codes_SRS_TRANSPORTMULTITHTTP_17_098: [Abandoning the message is considered successful if the HTTPAPIEX_SAS_ExecuteRequest doesn't fail and the statusCode is 204.]*/
Azure.IoT Build 19:d4f9e872bf3e 1785 /*Codes_SRS_TRANSPORTMULTITHTTP_17_100: [Accepting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1786 /*Codes_SRS_TRANSPORTMULTITHTTP_17_102: [Rejecting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1787 LogError("unable to STRING_concat");
AzureIoTClient 29:e44b1f827914 1788 result = false;
Azure.IoT Build 19:d4f9e872bf3e 1789 }
Azure.IoT Build 19:d4f9e872bf3e 1790 else
Azure.IoT Build 19:d4f9e872bf3e 1791 {
Azure.IoT Build 19:d4f9e872bf3e 1792 HTTP_HEADERS_HANDLE abandonRequestHttpHeaders = HTTPHeaders_Alloc();
Azure.IoT Build 19:d4f9e872bf3e 1793 if (abandonRequestHttpHeaders == NULL)
Azure.IoT Build 19:d4f9e872bf3e 1794 {
Azure.IoT Build 19:d4f9e872bf3e 1795 /*Codes_SRS_TRANSPORTMULTITHTTP_17_098: [Abandoning the message is considered successful if the HTTPAPIEX_SAS_ExecuteRequest doesn't fail and the statusCode is 204.]*/
Azure.IoT Build 19:d4f9e872bf3e 1796 /*Codes_SRS_TRANSPORTMULTITHTTP_17_100: [Accepting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1797 /*Codes_SRS_TRANSPORTMULTITHTTP_17_102: [Rejecting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1798 LogError("unable to HTTPHeaders_Alloc");
AzureIoTClient 29:e44b1f827914 1799 result = false;
Azure.IoT Build 19:d4f9e872bf3e 1800 }
Azure.IoT Build 19:d4f9e872bf3e 1801 else
Azure.IoT Build 19:d4f9e872bf3e 1802 {
Azure.IoT Build 19:d4f9e872bf3e 1803 if (!(
AzureIoTClient 30:655054f86a6e 1804 (addUserAgentHeaderInfo(deviceData->iotHubClientHandle, abandonRequestHttpHeaders) == HTTP_HEADERS_OK) &&
Azure.IoT Build 19:d4f9e872bf3e 1805 (HTTPHeaders_AddHeaderNameValuePair(abandonRequestHttpHeaders, "Authorization", " ") == HTTP_HEADERS_OK) &&
Azure.IoT Build 19:d4f9e872bf3e 1806 (HTTPHeaders_AddHeaderNameValuePair(abandonRequestHttpHeaders, "If-Match", ETag) == HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 1807 ))
Azure.IoT Build 19:d4f9e872bf3e 1808 {
Azure.IoT Build 19:d4f9e872bf3e 1809 /*Codes_SRS_TRANSPORTMULTITHTTP_17_098: [Abandoning the message is considered successful if the HTTPAPIEX_SAS_ExecuteRequest doesn't fail and the statusCode is 204.]*/
Azure.IoT Build 19:d4f9e872bf3e 1810 /*Codes_SRS_TRANSPORTMULTITHTTP_17_100: [Accepting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1811 /*Codes_SRS_TRANSPORTMULTITHTTP_17_102: [Rejecting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1812 LogError("unable to HTTPHeaders_AddHeaderNameValuePair");
AzureIoTClient 29:e44b1f827914 1813 result = false;
Azure.IoT Build 19:d4f9e872bf3e 1814 }
Azure.IoT Build 19:d4f9e872bf3e 1815 else
Azure.IoT Build 19:d4f9e872bf3e 1816 {
AzureIoTClient 20:b652f2e4cccf 1817 unsigned int statusCode = 0;
Azure.IoT Build 19:d4f9e872bf3e 1818 HTTPAPIEX_RESULT r;
Azure.IoT Build 19:d4f9e872bf3e 1819 if (deviceData->deviceSasToken != NULL)
Azure.IoT Build 19:d4f9e872bf3e 1820 {
Azure.IoT Build 19:d4f9e872bf3e 1821 /*Codes_SRS_TRANSPORTMULTITHTTP_03_001: [if a deviceSasToken exists, HTTPHeaders_ReplaceHeaderNameValuePair shall be invoked with "Authorization" as its second argument and STRING_c_str (deviceSasToken) as its third argument.]*/
Azure.IoT Build 19:d4f9e872bf3e 1822 if (HTTPHeaders_ReplaceHeaderNameValuePair(abandonRequestHttpHeaders, "Authorization", STRING_c_str(deviceData->deviceSasToken)) != HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 1823 {
Azure.IoT Build 19:d4f9e872bf3e 1824 r = HTTPAPIEX_ERROR;
Azure.IoT Build 19:d4f9e872bf3e 1825 /*Codes_SRS_TRANSPORTMULTITHTTP_03_002: [If the result of the invocation of HTTPHeaders_ReplaceHeaderNameValuePair is NOT HTTP_HEADERS_OK then fallthrough.]*/
Azure.IoT Build 19:d4f9e872bf3e 1826 LogError("Unable to replace the old SAS Token.");
AzureIoTClient 29:e44b1f827914 1827 result = false;
Azure.IoT Build 19:d4f9e872bf3e 1828 }
Azure.IoT Build 19:d4f9e872bf3e 1829 else if ((r = HTTPAPIEX_ExecuteRequest(
Azure.IoT Build 19:d4f9e872bf3e 1830 handleData->httpApiExHandle,
AzureIoTClient 29:e44b1f827914 1831 (action == IOTHUBMESSAGE_ABANDONED) ? HTTPAPI_REQUEST_POST : HTTPAPI_REQUEST_DELETE, /*-requestType: POST */
AzureIoTClient 25:3a68a581d3f9 1832 STRING_c_str(fullAbandonRelativePath), /*-relativePath: abandon relative path begin (as created by _Create) + value of ETag + "/abandon?api-version=2016-11-14" */
Azure.IoT Build 19:d4f9e872bf3e 1833 abandonRequestHttpHeaders, /*- requestHttpHeadersHandle: an HTTP headers instance containing the following */
Azure.IoT Build 19:d4f9e872bf3e 1834 NULL, /*- requestContent: NULL */
Azure.IoT Build 19:d4f9e872bf3e 1835 &statusCode, /*- statusCode: a pointer to unsigned int which might be examined for logging */
Azure.IoT Build 19:d4f9e872bf3e 1836 NULL, /*- responseHeadearsHandle: NULL */
Azure.IoT Build 19:d4f9e872bf3e 1837 NULL /*- responseContent: NULL] */
AzureIoTClient 35:786954ce12e9 1838 )) != HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 1839 {
Azure.IoT Build 19:d4f9e872bf3e 1840 /*Codes_SRS_TRANSPORTMULTITHTTP_17_098: [Abandoning the message is considered successful if the HTTPAPIEX_SAS_ExecuteRequest doesn't fail and the statusCode is 204.]*/
Azure.IoT Build 19:d4f9e872bf3e 1841 /*Codes_SRS_TRANSPORTMULTITHTTP_17_100: [Accepting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1842 /*Codes_SRS_TRANSPORTMULTITHTTP_17_102: [Rejecting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1843 LogError("Unable to HTTPAPIEX_ExecuteRequest.");
AzureIoTClient 29:e44b1f827914 1844 result = false;
Azure.IoT Build 19:d4f9e872bf3e 1845 }
Azure.IoT Build 19:d4f9e872bf3e 1846 }
Azure.IoT Build 19:d4f9e872bf3e 1847 else if ((r = HTTPAPIEX_SAS_ExecuteRequest(
Azure.IoT Build 19:d4f9e872bf3e 1848 deviceData->sasObject,
Azure.IoT Build 19:d4f9e872bf3e 1849 handleData->httpApiExHandle,
AzureIoTClient 29:e44b1f827914 1850 (action == IOTHUBMESSAGE_ABANDONED) ? HTTPAPI_REQUEST_POST : HTTPAPI_REQUEST_DELETE, /*-requestType: POST */
AzureIoTClient 25:3a68a581d3f9 1851 STRING_c_str(fullAbandonRelativePath), /*-relativePath: abandon relative path begin (as created by _Create) + value of ETag + "/abandon?api-version=2016-11-14" */
Azure.IoT Build 19:d4f9e872bf3e 1852 abandonRequestHttpHeaders, /*- requestHttpHeadersHandle: an HTTP headers instance containing the following */
Azure.IoT Build 19:d4f9e872bf3e 1853 NULL, /*- requestContent: NULL */
Azure.IoT Build 19:d4f9e872bf3e 1854 &statusCode, /*- statusCode: a pointer to unsigned int which might be examined for logging */
Azure.IoT Build 19:d4f9e872bf3e 1855 NULL, /*- responseHeadearsHandle: NULL */
Azure.IoT Build 19:d4f9e872bf3e 1856 NULL /*- responseContent: NULL] */
AzureIoTClient 35:786954ce12e9 1857 )) != HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 1858 {
Azure.IoT Build 19:d4f9e872bf3e 1859 /*Codes_SRS_TRANSPORTMULTITHTTP_17_098: [Abandoning the message is considered successful if the HTTPAPIEX_SAS_ExecuteRequest doesn't fail and the statusCode is 204.]*/
Azure.IoT Build 19:d4f9e872bf3e 1860 /*Codes_SRS_TRANSPORTMULTITHTTP_17_100: [Accepting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1861 /*Codes_SRS_TRANSPORTMULTITHTTP_17_102: [Rejecting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1862 LogError("unable to HTTPAPIEX_SAS_ExecuteRequest");
AzureIoTClient 29:e44b1f827914 1863 result = false;
Azure.IoT Build 19:d4f9e872bf3e 1864 }
Azure.IoT Build 19:d4f9e872bf3e 1865 if (r == HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 1866 {
Azure.IoT Build 19:d4f9e872bf3e 1867 if (statusCode != 204)
Azure.IoT Build 19:d4f9e872bf3e 1868 {
Azure.IoT Build 19:d4f9e872bf3e 1869 /*Codes_SRS_TRANSPORTMULTITHTTP_17_098: [Abandoning the message is considered successful if the HTTPAPIEX_SAS_ExecuteRequest doesn't fail and the statusCode is 204.]*/
Azure.IoT Build 19:d4f9e872bf3e 1870 /*Codes_SRS_TRANSPORTMULTITHTTP_17_100: [Accepting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1871 /*Codes_SRS_TRANSPORTMULTITHTTP_17_102: [Rejecting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1872 LogError("unexpected status code returned %u (was expecting 204)", statusCode);
AzureIoTClient 29:e44b1f827914 1873 result = false;
Azure.IoT Build 19:d4f9e872bf3e 1874 }
Azure.IoT Build 19:d4f9e872bf3e 1875 else
Azure.IoT Build 19:d4f9e872bf3e 1876 {
Azure.IoT Build 19:d4f9e872bf3e 1877 /*Codes_SRS_TRANSPORTMULTITHTTP_17_098: [Abandoning the message is considered successful if the HTTPAPIEX_SAS_ExecuteRequest doesn't fail and the statusCode is 204.]*/
Azure.IoT Build 19:d4f9e872bf3e 1878 /*Codes_SRS_TRANSPORTMULTITHTTP_17_100: [Accepting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1879 /*Codes_SRS_TRANSPORTMULTITHTTP_17_102: [Rejecting a message is successful when HTTPAPIEX_SAS_ExecuteRequest completes successfully and the status code is 204.] */
Azure.IoT Build 19:d4f9e872bf3e 1880 /*all is fine*/
AzureIoTClient 29:e44b1f827914 1881 result = true;
Azure.IoT Build 19:d4f9e872bf3e 1882 }
Azure.IoT Build 19:d4f9e872bf3e 1883 }
AzureIoTClient 29:e44b1f827914 1884 else
AzureIoTClient 29:e44b1f827914 1885 {
AzureIoTClient 29:e44b1f827914 1886 result = false;
AzureIoTClient 29:e44b1f827914 1887 }
Azure.IoT Build 19:d4f9e872bf3e 1888 }
Azure.IoT Build 19:d4f9e872bf3e 1889 HTTPHeaders_Free(abandonRequestHttpHeaders);
Azure.IoT Build 19:d4f9e872bf3e 1890 }
Azure.IoT Build 19:d4f9e872bf3e 1891 }
Azure.IoT Build 19:d4f9e872bf3e 1892 STRING_delete(ETagUnquoted);
Azure.IoT Build 19:d4f9e872bf3e 1893 }
Azure.IoT Build 19:d4f9e872bf3e 1894 STRING_delete(fullAbandonRelativePath);
Azure.IoT Build 19:d4f9e872bf3e 1895 }
AzureIoTClient 29:e44b1f827914 1896 return result;
AzureIoTClient 29:e44b1f827914 1897 }
AzureIoTClient 29:e44b1f827914 1898
AzureIoTClient 29:e44b1f827914 1899 static IOTHUB_CLIENT_RESULT IoTHubTransportHttp_SendMessageDisposition(MESSAGE_CALLBACK_INFO* message_data, IOTHUBMESSAGE_DISPOSITION_RESULT disposition)
AzureIoTClient 29:e44b1f827914 1900 {
AzureIoTClient 29:e44b1f827914 1901 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 29:e44b1f827914 1902 if (message_data == NULL)
AzureIoTClient 29:e44b1f827914 1903 {
AzureIoTClient 29:e44b1f827914 1904 /* Codes_SRS_TRANSPORTMULTITHTTP_10_001: [If messageData is NULL, IoTHubTransportHttp_SendMessageDisposition shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 29:e44b1f827914 1905 LogError("invalid argument messageData is NULL");
AzureIoTClient 29:e44b1f827914 1906 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 29:e44b1f827914 1907 }
AzureIoTClient 29:e44b1f827914 1908 else
AzureIoTClient 29:e44b1f827914 1909 {
AzureIoTClient 29:e44b1f827914 1910 if (message_data->messageHandle == NULL)
AzureIoTClient 29:e44b1f827914 1911 {
AzureIoTClient 29:e44b1f827914 1912 /* Codes_SRS_TRANSPORTMULTITHTTP_10_002: [If any of the messageData fields are NULL, IoTHubTransportHttp_SendMessageDisposition shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 29:e44b1f827914 1913 LogError("invalid message handle");
AzureIoTClient 29:e44b1f827914 1914 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 29:e44b1f827914 1915 }
AzureIoTClient 29:e44b1f827914 1916 else
AzureIoTClient 29:e44b1f827914 1917 {
AzureIoTClient 29:e44b1f827914 1918 MESSAGE_DISPOSITION_CONTEXT* tc = (MESSAGE_DISPOSITION_CONTEXT*)(message_data->transportContext);
AzureIoTClient 29:e44b1f827914 1919 if (tc == NULL)
AzureIoTClient 29:e44b1f827914 1920 {
AzureIoTClient 29:e44b1f827914 1921 /* Codes_SRS_TRANSPORTMULTITHTTP_10_002: [If any of the messageData fields are NULL, IoTHubTransportHttp_SendMessageDisposition shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 29:e44b1f827914 1922 LogError("invalid transport context data");
AzureIoTClient 29:e44b1f827914 1923 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 29:e44b1f827914 1924 }
AzureIoTClient 29:e44b1f827914 1925 else
AzureIoTClient 29:e44b1f827914 1926 {
AzureIoTClient 29:e44b1f827914 1927 if ((tc->handleData == NULL) || (tc->deviceData == NULL) || (tc->etagValue == NULL))
AzureIoTClient 29:e44b1f827914 1928 {
AzureIoTClient 29:e44b1f827914 1929 /* Codes_SRS_TRANSPORTMULTITHTTP_10_002: [If any of the messageData fields are NULL, IoTHubTransportHttp_SendMessageDisposition shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 29:e44b1f827914 1930 LogError("invalid transport context data");
AzureIoTClient 29:e44b1f827914 1931 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 29:e44b1f827914 1932 }
AzureIoTClient 29:e44b1f827914 1933 else
AzureIoTClient 29:e44b1f827914 1934 {
AzureIoTClient 29:e44b1f827914 1935 if (abandonOrAcceptMessage(tc->handleData, tc->deviceData, tc->etagValue, disposition))
AzureIoTClient 29:e44b1f827914 1936 {
AzureIoTClient 29:e44b1f827914 1937 result = IOTHUB_CLIENT_OK;
AzureIoTClient 29:e44b1f827914 1938 }
AzureIoTClient 29:e44b1f827914 1939 else
AzureIoTClient 29:e44b1f827914 1940 {
AzureIoTClient 29:e44b1f827914 1941 /* Codes_SRS_TRANSPORTMULTITHTTP_10_003: [IoTHubTransportHttp_SendMessageDisposition shall fail and return IOTHUB_CLIENT_ERROR if the POST message fails, otherwise return IOTHUB_CLIENT_OK.] */
AzureIoTClient 29:e44b1f827914 1942 LogError("HTTP Transport layer failed to report %s disposition", ENUM_TO_STRING(IOTHUBMESSAGE_DISPOSITION_RESULT, disposition));
AzureIoTClient 29:e44b1f827914 1943 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 29:e44b1f827914 1944 }
AzureIoTClient 29:e44b1f827914 1945 }
AzureIoTClient 29:e44b1f827914 1946 free(tc->etagValue);
AzureIoTClient 29:e44b1f827914 1947 free(tc);
AzureIoTClient 29:e44b1f827914 1948 }
AzureIoTClient 29:e44b1f827914 1949 IoTHubMessage_Destroy(message_data->messageHandle);
AzureIoTClient 29:e44b1f827914 1950 }
AzureIoTClient 29:e44b1f827914 1951 free(message_data);
AzureIoTClient 29:e44b1f827914 1952 }
AzureIoTClient 29:e44b1f827914 1953 return result;
AzureIoTClient 29:e44b1f827914 1954 }
AzureIoTClient 29:e44b1f827914 1955
AzureIoTClient 29:e44b1f827914 1956 static MESSAGE_CALLBACK_INFO* MESSAGE_CALLBACK_INFO_Create(IOTHUB_MESSAGE_HANDLE received_message, HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTRANSPORT_PERDEVICE_DATA* deviceData, const char* etagValue)
AzureIoTClient 29:e44b1f827914 1957 {
AzureIoTClient 29:e44b1f827914 1958 MESSAGE_CALLBACK_INFO* result = (MESSAGE_CALLBACK_INFO*)malloc(sizeof(MESSAGE_CALLBACK_INFO));
AzureIoTClient 29:e44b1f827914 1959 if (result == NULL)
AzureIoTClient 29:e44b1f827914 1960 {
AzureIoTClient 29:e44b1f827914 1961 /*Codes_SRS_TRANSPORTMULTITHTTP_10_006: [If assembling the transport context fails, _DoWork shall "abandon" the message.] */
AzureIoTClient 29:e44b1f827914 1962 LogError("malloc failed");
AzureIoTClient 29:e44b1f827914 1963 }
AzureIoTClient 29:e44b1f827914 1964 else
AzureIoTClient 29:e44b1f827914 1965 {
AzureIoTClient 29:e44b1f827914 1966 MESSAGE_DISPOSITION_CONTEXT* tc = (MESSAGE_DISPOSITION_CONTEXT*)malloc(sizeof(MESSAGE_DISPOSITION_CONTEXT));
AzureIoTClient 29:e44b1f827914 1967 if (tc == NULL)
AzureIoTClient 29:e44b1f827914 1968 {
AzureIoTClient 29:e44b1f827914 1969 /*Codes_SRS_TRANSPORTMULTITHTTP_10_006: [If assembling the transport context fails, _DoWork shall "abandon" the message.] */
AzureIoTClient 29:e44b1f827914 1970 LogError("malloc failed");
AzureIoTClient 29:e44b1f827914 1971 free(result);
AzureIoTClient 29:e44b1f827914 1972 result = NULL;
AzureIoTClient 29:e44b1f827914 1973 }
AzureIoTClient 29:e44b1f827914 1974 else
AzureIoTClient 29:e44b1f827914 1975 {
AzureIoTClient 29:e44b1f827914 1976 result->messageHandle = IoTHubMessage_Clone(received_message);
AzureIoTClient 29:e44b1f827914 1977 if (result->messageHandle == NULL)
AzureIoTClient 29:e44b1f827914 1978 {
AzureIoTClient 29:e44b1f827914 1979 /*Codes_SRS_TRANSPORTMULTITHTTP_10_007: [If assembling a message clone, _DoWork shall "abandon" the message.]*/
AzureIoTClient 29:e44b1f827914 1980 LogError("IoTHubMessage_Clone failed");
AzureIoTClient 29:e44b1f827914 1981 free(tc);
AzureIoTClient 29:e44b1f827914 1982 free(result);
AzureIoTClient 29:e44b1f827914 1983 result = NULL;
AzureIoTClient 29:e44b1f827914 1984 }
AzureIoTClient 29:e44b1f827914 1985 else
AzureIoTClient 29:e44b1f827914 1986 {
AzureIoTClient 29:e44b1f827914 1987 if (mallocAndStrcpy_s(&tc->etagValue, etagValue) != 0)
AzureIoTClient 29:e44b1f827914 1988 {
AzureIoTClient 29:e44b1f827914 1989 LogError("mallocAndStrcpy_s failed");
AzureIoTClient 29:e44b1f827914 1990 free(tc);
AzureIoTClient 29:e44b1f827914 1991 free(result);
AzureIoTClient 29:e44b1f827914 1992 result = NULL;
AzureIoTClient 29:e44b1f827914 1993 }
AzureIoTClient 29:e44b1f827914 1994 else
AzureIoTClient 29:e44b1f827914 1995 {
AzureIoTClient 29:e44b1f827914 1996 tc->handleData = handleData;
AzureIoTClient 29:e44b1f827914 1997 tc->deviceData = deviceData;
AzureIoTClient 29:e44b1f827914 1998
AzureIoTClient 29:e44b1f827914 1999 result->transportContext = tc;
AzureIoTClient 29:e44b1f827914 2000 }
AzureIoTClient 29:e44b1f827914 2001 }
AzureIoTClient 29:e44b1f827914 2002 }
AzureIoTClient 29:e44b1f827914 2003 }
AzureIoTClient 29:e44b1f827914 2004 return result;
AzureIoTClient 6:73793bae15ba 2005 }
AzureIoTClient 6:73793bae15ba 2006
AzureIoTClient 36:36c1e1ca5679 2007 static void DoMessages(HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTRANSPORT_PERDEVICE_DATA* deviceData, IOTHUB_CLIENT_CORE_LL_HANDLE iotHubClientHandle)
AzureIoTClient 6:73793bae15ba 2008 {
Azure.IoT Build 19:d4f9e872bf3e 2009 /*Codes_SRS_TRANSPORTMULTITHTTP_17_083: [ If device is not subscribed then _DoWork shall advance to the next action. ] */
Azure.IoT Build 19:d4f9e872bf3e 2010 if (deviceData->DoWork_PullMessage)
Azure.IoT Build 19:d4f9e872bf3e 2011 {
Azure.IoT Build 19:d4f9e872bf3e 2012 /*Codes_SRS_TRANSPORTMULTITHTTP_17_123: [After client creation, the first GET shall be allowed no matter what the value of GetMinimumPollingTime.] */
Azure.IoT Build 19:d4f9e872bf3e 2013 /*Codes_SRS_TRANSPORTMULTITHTTP_17_124: [If time is not available then all calls shall be treated as if they are the first one.] */
Azure.IoT Build 19:d4f9e872bf3e 2014 /*Codes_SRS_TRANSPORTMULTITHTTP_17_122: [A GET request that happens earlier than GetMinimumPollingTime shall be ignored.] */
Azure.IoT Build 19:d4f9e872bf3e 2015 time_t timeNow = get_time(NULL);
Azure.IoT Build 19:d4f9e872bf3e 2016 bool isPollingAllowed = deviceData->isFirstPoll || (timeNow == (time_t)(-1)) || (get_difftime(timeNow, deviceData->lastPollTime) > handleData->getMinimumPollingTime);
Azure.IoT Build 19:d4f9e872bf3e 2017 if (isPollingAllowed)
Azure.IoT Build 19:d4f9e872bf3e 2018 {
Azure.IoT Build 19:d4f9e872bf3e 2019 HTTP_HEADERS_HANDLE responseHTTPHeaders = HTTPHeaders_Alloc();
Azure.IoT Build 19:d4f9e872bf3e 2020 if (responseHTTPHeaders == NULL)
Azure.IoT Build 19:d4f9e872bf3e 2021 {
Azure.IoT Build 19:d4f9e872bf3e 2022 /*Codes_SRS_TRANSPORTMULTITHTTP_17_085: [If the call to HTTPAPIEX_SAS_ExecuteRequest did not executed successfully or building any part of the prerequisites of the call fails, then _DoWork shall advance to the next action in this description.] */
Azure.IoT Build 19:d4f9e872bf3e 2023 LogError("unable to HTTPHeaders_Alloc");
Azure.IoT Build 19:d4f9e872bf3e 2024 }
Azure.IoT Build 19:d4f9e872bf3e 2025 else
Azure.IoT Build 19:d4f9e872bf3e 2026 {
Azure.IoT Build 19:d4f9e872bf3e 2027 BUFFER_HANDLE responseContent = BUFFER_new();
Azure.IoT Build 19:d4f9e872bf3e 2028 if (responseContent == NULL)
Azure.IoT Build 19:d4f9e872bf3e 2029 {
Azure.IoT Build 19:d4f9e872bf3e 2030 /*Codes_SRS_TRANSPORTMULTITHTTP_17_085: [If the call to HTTPAPIEX_SAS_ExecuteRequest did not executed successfully or building any part of the prerequisites of the call fails, then _DoWork shall advance to the next action in this description.] */
Azure.IoT Build 19:d4f9e872bf3e 2031 LogError("unable to BUFFER_new");
Azure.IoT Build 19:d4f9e872bf3e 2032 }
Azure.IoT Build 19:d4f9e872bf3e 2033 else
Azure.IoT Build 19:d4f9e872bf3e 2034 {
AzureIoTClient 20:b652f2e4cccf 2035 unsigned int statusCode = 0;
Azure.IoT Build 19:d4f9e872bf3e 2036 HTTPAPIEX_RESULT r;
Azure.IoT Build 19:d4f9e872bf3e 2037 if (deviceData->deviceSasToken != NULL)
Azure.IoT Build 19:d4f9e872bf3e 2038 {
Azure.IoT Build 19:d4f9e872bf3e 2039 /*Codes_SRS_TRANSPORTMULTITHTTP_03_001: [if a deviceSasToken exists, HTTPHeaders_ReplaceHeaderNameValuePair shall be invoked with "Authorization" as its second argument and STRING_c_str (deviceSasToken) as its third argument.]*/
Azure.IoT Build 19:d4f9e872bf3e 2040 if (HTTPHeaders_ReplaceHeaderNameValuePair(deviceData->messageHTTPrequestHeaders, "Authorization", STRING_c_str(deviceData->deviceSasToken)) != HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 2041 {
Azure.IoT Build 19:d4f9e872bf3e 2042 r = HTTPAPIEX_ERROR;
Azure.IoT Build 19:d4f9e872bf3e 2043 /*Codes_SRS_TRANSPORTMULTITHTTP_03_002: [If the result of the invocation of HTTPHeaders_ReplaceHeaderNameValuePair is NOT HTTP_HEADERS_OK then fallthrough.]*/
Azure.IoT Build 19:d4f9e872bf3e 2044 LogError("Unable to replace the old SAS Token.");
Azure.IoT Build 19:d4f9e872bf3e 2045 }
Azure.IoT Build 19:d4f9e872bf3e 2046 else if ((r = HTTPAPIEX_ExecuteRequest(
Azure.IoT Build 19:d4f9e872bf3e 2047 handleData->httpApiExHandle,
Azure.IoT Build 19:d4f9e872bf3e 2048 HTTPAPI_REQUEST_GET, /*requestType: GET*/
Azure.IoT Build 19:d4f9e872bf3e 2049 STRING_c_str(deviceData->messageHTTPrelativePath), /*relativePath: the message HTTP relative path*/
Azure.IoT Build 19:d4f9e872bf3e 2050 deviceData->messageHTTPrequestHeaders, /*requestHttpHeadersHandle: message HTTP request headers created by _Create*/
Azure.IoT Build 19:d4f9e872bf3e 2051 NULL, /*requestContent: NULL*/
Azure.IoT Build 19:d4f9e872bf3e 2052 &statusCode, /*statusCode: a pointer to unsigned int which shall be later examined*/
Azure.IoT Build 19:d4f9e872bf3e 2053 responseHTTPHeaders, /*responseHeadearsHandle: a new instance of HTTP headers*/
Azure.IoT Build 19:d4f9e872bf3e 2054 responseContent /*responseContent: a new instance of buffer*/
AzureIoTClient 35:786954ce12e9 2055 )) != HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 2056 {
Azure.IoT Build 19:d4f9e872bf3e 2057 /*Codes_SRS_TRANSPORTMULTITHTTP_17_085: [If the call to HTTPAPIEX_SAS_ExecuteRequest did not executed successfully or building any part of the prerequisites of the call fails, then _DoWork shall advance to the next action in this description.] */
Azure.IoT Build 19:d4f9e872bf3e 2058 LogError("Unable to HTTPAPIEX_ExecuteRequest.");
Azure.IoT Build 19:d4f9e872bf3e 2059 }
Azure.IoT Build 19:d4f9e872bf3e 2060 }
AzureIoTClient 17:7ef88cde801f 2061
Azure.IoT Build 19:d4f9e872bf3e 2062 /*Codes_SRS_TRANSPORTMULTITHTTP_17_084: [Otherwise, IoTHubTransportHttp_DoWork shall call HTTPAPIEX_SAS_ExecuteRequest passing the following parameters
Azure.IoT Build 19:d4f9e872bf3e 2063 requestType: GET
Azure.IoT Build 19:d4f9e872bf3e 2064 relativePath: the message HTTP relative path
Azure.IoT Build 19:d4f9e872bf3e 2065 requestHttpHeadersHandle: message HTTP request headers created by _Create
Azure.IoT Build 19:d4f9e872bf3e 2066 requestContent: NULL
Azure.IoT Build 19:d4f9e872bf3e 2067 statusCode: a pointer to unsigned int which shall be later examined
Azure.IoT Build 19:d4f9e872bf3e 2068 responseHeadearsHandle: a new instance of HTTP headers
Azure.IoT Build 19:d4f9e872bf3e 2069 responseContent: a new instance of buffer]
Azure.IoT Build 19:d4f9e872bf3e 2070 */
Azure.IoT Build 19:d4f9e872bf3e 2071 else if ((r = HTTPAPIEX_SAS_ExecuteRequest(
Azure.IoT Build 19:d4f9e872bf3e 2072 deviceData->sasObject,
Azure.IoT Build 19:d4f9e872bf3e 2073 handleData->httpApiExHandle,
Azure.IoT Build 19:d4f9e872bf3e 2074 HTTPAPI_REQUEST_GET, /*requestType: GET*/
Azure.IoT Build 19:d4f9e872bf3e 2075 STRING_c_str(deviceData->messageHTTPrelativePath), /*relativePath: the message HTTP relative path*/
Azure.IoT Build 19:d4f9e872bf3e 2076 deviceData->messageHTTPrequestHeaders, /*requestHttpHeadersHandle: message HTTP request headers created by _Create*/
Azure.IoT Build 19:d4f9e872bf3e 2077 NULL, /*requestContent: NULL*/
Azure.IoT Build 19:d4f9e872bf3e 2078 &statusCode, /*statusCode: a pointer to unsigned int which shall be later examined*/
Azure.IoT Build 19:d4f9e872bf3e 2079 responseHTTPHeaders, /*responseHeadearsHandle: a new instance of HTTP headers*/
Azure.IoT Build 19:d4f9e872bf3e 2080 responseContent /*responseContent: a new instance of buffer*/
AzureIoTClient 35:786954ce12e9 2081 )) != HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 2082 {
Azure.IoT Build 19:d4f9e872bf3e 2083 /*Codes_SRS_TRANSPORTMULTITHTTP_17_085: [If the call to HTTPAPIEX_SAS_ExecuteRequest did not executed successfully or building any part of the prerequisites of the call fails, then _DoWork shall advance to the next action in this description.] */
Azure.IoT Build 19:d4f9e872bf3e 2084 LogError("unable to HTTPAPIEX_SAS_ExecuteRequest");
Azure.IoT Build 19:d4f9e872bf3e 2085 }
Azure.IoT Build 19:d4f9e872bf3e 2086 if (r == HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 2087 {
Azure.IoT Build 19:d4f9e872bf3e 2088 /*HTTP dialogue was succesfull*/
Azure.IoT Build 19:d4f9e872bf3e 2089 if (timeNow == (time_t)(-1))
Azure.IoT Build 19:d4f9e872bf3e 2090 {
Azure.IoT Build 19:d4f9e872bf3e 2091 deviceData->isFirstPoll = true;
Azure.IoT Build 19:d4f9e872bf3e 2092 }
Azure.IoT Build 19:d4f9e872bf3e 2093 else
Azure.IoT Build 19:d4f9e872bf3e 2094 {
Azure.IoT Build 19:d4f9e872bf3e 2095 deviceData->isFirstPoll = false;
Azure.IoT Build 19:d4f9e872bf3e 2096 deviceData->lastPollTime = timeNow;
Azure.IoT Build 19:d4f9e872bf3e 2097 }
Azure.IoT Build 19:d4f9e872bf3e 2098 if (statusCode == 204)
Azure.IoT Build 19:d4f9e872bf3e 2099 {
Azure.IoT Build 19:d4f9e872bf3e 2100 /*Codes_SRS_TRANSPORTMULTITHTTP_17_086: [If the HTTPAPIEX_SAS_ExecuteRequest executed successfully then status code shall be examined. Any status code different than 200 causes _DoWork to advance to the next action.] */
Azure.IoT Build 19:d4f9e872bf3e 2101 /*this is an expected status code, means "no commands", but logging that creates panic*/
AzureIoTClient 6:73793bae15ba 2102
Azure.IoT Build 19:d4f9e872bf3e 2103 /*do nothing, advance to next action*/
Azure.IoT Build 19:d4f9e872bf3e 2104 }
Azure.IoT Build 19:d4f9e872bf3e 2105 else if (statusCode != 200)
Azure.IoT Build 19:d4f9e872bf3e 2106 {
Azure.IoT Build 19:d4f9e872bf3e 2107 /*Codes_SRS_TRANSPORTMULTITHTTP_17_086: [If the HTTPAPIEX_SAS_ExecuteRequest executed successfully then status code shall be examined. Any status code different than 200 causes _DoWork to advance to the next action.] */
Azure.IoT Build 19:d4f9e872bf3e 2108 LogError("expected status code was 200, but actually was received %u... moving on", statusCode);
Azure.IoT Build 19:d4f9e872bf3e 2109 }
Azure.IoT Build 19:d4f9e872bf3e 2110 else
Azure.IoT Build 19:d4f9e872bf3e 2111 {
Azure.IoT Build 19:d4f9e872bf3e 2112 /*Codes_SRS_TRANSPORTMULTITHTTP_17_087: [If status code is 200, then _DoWork shall make a copy of the value of the "ETag" http header.]*/
Azure.IoT Build 19:d4f9e872bf3e 2113 const char* etagValue = HTTPHeaders_FindHeaderValue(responseHTTPHeaders, "ETag");
Azure.IoT Build 19:d4f9e872bf3e 2114 if (etagValue == NULL)
Azure.IoT Build 19:d4f9e872bf3e 2115 {
Azure.IoT Build 19:d4f9e872bf3e 2116 LogError("unable to find a received header called \"E-Tag\"");
Azure.IoT Build 19:d4f9e872bf3e 2117 }
Azure.IoT Build 19:d4f9e872bf3e 2118 else
Azure.IoT Build 19:d4f9e872bf3e 2119 {
Azure.IoT Build 19:d4f9e872bf3e 2120 /*Codes_SRS_TRANSPORTMULTITHTTP_17_088: [If no such header is found or is invalid, then _DoWork shall advance to the next action.]*/
Azure.IoT Build 19:d4f9e872bf3e 2121 size_t etagsize = strlen(etagValue);
Azure.IoT Build 19:d4f9e872bf3e 2122 if (
Azure.IoT Build 19:d4f9e872bf3e 2123 (etagsize < 2) ||
Azure.IoT Build 19:d4f9e872bf3e 2124 (etagValue[0] != '"') ||
Azure.IoT Build 19:d4f9e872bf3e 2125 (etagValue[etagsize - 1] != '"')
Azure.IoT Build 19:d4f9e872bf3e 2126 )
Azure.IoT Build 19:d4f9e872bf3e 2127 {
Azure.IoT Build 19:d4f9e872bf3e 2128 LogError("ETag is not a valid quoted string");
Azure.IoT Build 19:d4f9e872bf3e 2129 }
Azure.IoT Build 19:d4f9e872bf3e 2130 else
Azure.IoT Build 19:d4f9e872bf3e 2131 {
AzureIoTClient 31:c889be99d3f7 2132 const unsigned char* resp_content;
AzureIoTClient 31:c889be99d3f7 2133 size_t resp_len;
Azure.IoT Build 19:d4f9e872bf3e 2134 /*Codes_SRS_TRANSPORTMULTITHTTP_17_089: [_DoWork shall assemble an IOTHUBMESSAGE_HANDLE from the received HTTP content (using the responseContent buffer).] */
AzureIoTClient 31:c889be99d3f7 2135 resp_content = BUFFER_u_char(responseContent);
AzureIoTClient 31:c889be99d3f7 2136 resp_len = BUFFER_length(responseContent);
AzureIoTClient 31:c889be99d3f7 2137 IOTHUB_MESSAGE_HANDLE receivedMessage = IoTHubMessage_CreateFromByteArray(resp_content, resp_len);
Azure.IoT Build 19:d4f9e872bf3e 2138 if (receivedMessage == NULL)
Azure.IoT Build 19:d4f9e872bf3e 2139 {
Azure.IoT Build 19:d4f9e872bf3e 2140 /*Codes_SRS_TRANSPORTMULTITHTTP_17_092: [If assembling the message fails in any way, then _DoWork shall "abandon" the message.]*/
Azure.IoT Build 19:d4f9e872bf3e 2141 LogError("unable to IoTHubMessage_CreateFromByteArray, trying to abandon the message... ");
AzureIoTClient 29:e44b1f827914 2142 if (!abandonOrAcceptMessage(handleData, deviceData, etagValue, IOTHUBMESSAGE_ABANDONED))
AzureIoTClient 29:e44b1f827914 2143 {
AzureIoTClient 29:e44b1f827914 2144 LogError("HTTP Transport layer failed to report ABANDON disposition");
AzureIoTClient 29:e44b1f827914 2145 }
Azure.IoT Build 19:d4f9e872bf3e 2146 }
Azure.IoT Build 19:d4f9e872bf3e 2147 else
Azure.IoT Build 19:d4f9e872bf3e 2148 {
Azure.IoT Build 19:d4f9e872bf3e 2149 /*Codes_SRS_TRANSPORTMULTITHTTP_17_090: [All the HTTP headers of the form iothub-app-name:somecontent shall be transformed in message properties {name, somecontent}.]*/
Azure.IoT Build 19:d4f9e872bf3e 2150 /*Codes_SRS_TRANSPORTMULTITHTTP_17_091: [The HTTP header of iothub-messageid shall be set in the MessageId.]*/
Azure.IoT Build 19:d4f9e872bf3e 2151 size_t nHeaders;
Azure.IoT Build 19:d4f9e872bf3e 2152 if (HTTPHeaders_GetHeaderCount(responseHTTPHeaders, &nHeaders) != HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 2153 {
Azure.IoT Build 19:d4f9e872bf3e 2154 LogError("unable to get the count of HTTP headers");
AzureIoTClient 29:e44b1f827914 2155 if (!abandonOrAcceptMessage(handleData, deviceData, etagValue, IOTHUBMESSAGE_ABANDONED))
AzureIoTClient 29:e44b1f827914 2156 {
AzureIoTClient 29:e44b1f827914 2157 LogError("HTTP Transport layer failed to report ABANDON disposition");
AzureIoTClient 29:e44b1f827914 2158 }
Azure.IoT Build 19:d4f9e872bf3e 2159 }
Azure.IoT Build 19:d4f9e872bf3e 2160 else
Azure.IoT Build 19:d4f9e872bf3e 2161 {
Azure.IoT Build 19:d4f9e872bf3e 2162 size_t i;
Azure.IoT Build 19:d4f9e872bf3e 2163 MAP_HANDLE properties = (nHeaders > 0) ? IoTHubMessage_Properties(receivedMessage) : NULL;
Azure.IoT Build 19:d4f9e872bf3e 2164 for (i = 0; i < nHeaders; i++)
Azure.IoT Build 19:d4f9e872bf3e 2165 {
Azure.IoT Build 19:d4f9e872bf3e 2166 char* completeHeader;
Azure.IoT Build 19:d4f9e872bf3e 2167 if (HTTPHeaders_GetHeader(responseHTTPHeaders, i, &completeHeader) != HTTP_HEADERS_OK)
Azure.IoT Build 19:d4f9e872bf3e 2168 {
Azure.IoT Build 19:d4f9e872bf3e 2169 break;
Azure.IoT Build 19:d4f9e872bf3e 2170 }
Azure.IoT Build 19:d4f9e872bf3e 2171 else
Azure.IoT Build 19:d4f9e872bf3e 2172 {
Azure.IoT Build 19:d4f9e872bf3e 2173 if (strncmp(IOTHUB_APP_PREFIX, completeHeader, strlen(IOTHUB_APP_PREFIX)) == 0)
Azure.IoT Build 19:d4f9e872bf3e 2174 {
Azure.IoT Build 19:d4f9e872bf3e 2175 /*looks like a property headers*/
Azure.IoT Build 19:d4f9e872bf3e 2176 /*there's a guaranteed ':' in the completeHeader, by HTTP_HEADERS module*/
Azure.IoT Build 19:d4f9e872bf3e 2177 char* whereIsColon = strchr(completeHeader, ':');
Azure.IoT Build 19:d4f9e872bf3e 2178 if (whereIsColon != NULL)
Azure.IoT Build 19:d4f9e872bf3e 2179 {
Azure.IoT Build 19:d4f9e872bf3e 2180 *whereIsColon = '\0'; /*cut it down*/
Azure.IoT Build 19:d4f9e872bf3e 2181 if (Map_AddOrUpdate(properties, completeHeader + strlen(IOTHUB_APP_PREFIX), whereIsColon + 2) != MAP_OK) /*whereIsColon+1 is a space because HTTPEHADERS outputs a ": " between name and value*/
Azure.IoT Build 19:d4f9e872bf3e 2182 {
Azure.IoT Build 19:d4f9e872bf3e 2183 free(completeHeader);
Azure.IoT Build 19:d4f9e872bf3e 2184 break;
Azure.IoT Build 19:d4f9e872bf3e 2185 }
Azure.IoT Build 19:d4f9e872bf3e 2186 }
Azure.IoT Build 19:d4f9e872bf3e 2187 }
Azure.IoT Build 19:d4f9e872bf3e 2188 else if (strncmp(IOTHUB_MESSAGE_ID, completeHeader, strlen(IOTHUB_MESSAGE_ID)) == 0)
Azure.IoT Build 19:d4f9e872bf3e 2189 {
Azure.IoT Build 19:d4f9e872bf3e 2190 char* whereIsColon = strchr(completeHeader, ':');
Azure.IoT Build 19:d4f9e872bf3e 2191 if (whereIsColon != NULL)
Azure.IoT Build 19:d4f9e872bf3e 2192 {
Azure.IoT Build 19:d4f9e872bf3e 2193 *whereIsColon = '\0'; /*cut it down*/
Azure.IoT Build 19:d4f9e872bf3e 2194 if (IoTHubMessage_SetMessageId(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK)
Azure.IoT Build 19:d4f9e872bf3e 2195 {
Azure.IoT Build 19:d4f9e872bf3e 2196 free(completeHeader);
Azure.IoT Build 19:d4f9e872bf3e 2197 break;
Azure.IoT Build 19:d4f9e872bf3e 2198 }
Azure.IoT Build 19:d4f9e872bf3e 2199 }
Azure.IoT Build 19:d4f9e872bf3e 2200 }
Azure.IoT Build 19:d4f9e872bf3e 2201 else if (strncmp(IOTHUB_CORRELATION_ID, completeHeader, strlen(IOTHUB_CORRELATION_ID)) == 0)
Azure.IoT Build 19:d4f9e872bf3e 2202 {
Azure.IoT Build 19:d4f9e872bf3e 2203 char* whereIsColon = strchr(completeHeader, ':');
Azure.IoT Build 19:d4f9e872bf3e 2204 if (whereIsColon != NULL)
Azure.IoT Build 19:d4f9e872bf3e 2205 {
Azure.IoT Build 19:d4f9e872bf3e 2206 *whereIsColon = '\0'; /*cut it down*/
Azure.IoT Build 19:d4f9e872bf3e 2207 if (IoTHubMessage_SetCorrelationId(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK)
Azure.IoT Build 19:d4f9e872bf3e 2208 {
Azure.IoT Build 19:d4f9e872bf3e 2209 free(completeHeader);
Azure.IoT Build 19:d4f9e872bf3e 2210 break;
Azure.IoT Build 19:d4f9e872bf3e 2211 }
Azure.IoT Build 19:d4f9e872bf3e 2212 }
Azure.IoT Build 19:d4f9e872bf3e 2213 }
AzureIoTClient 38:01bf35934f1b 2214 // Codes_SRS_TRANSPORTMULTITHTTP_09_003: [ The HTTP header value of `ContentType` shall be set in the `IoTHubMessage_SetContentTypeSystemProperty`. ]
AzureIoTClient 32:4d4a226b072b 2215 else if (strncmp(IOTHUB_CONTENT_TYPE_C2D, completeHeader, strlen(IOTHUB_CONTENT_TYPE_C2D)) == 0)
AzureIoTClient 32:4d4a226b072b 2216 {
AzureIoTClient 32:4d4a226b072b 2217 char* whereIsColon = strchr(completeHeader, ':');
AzureIoTClient 32:4d4a226b072b 2218 if (whereIsColon != NULL)
AzureIoTClient 32:4d4a226b072b 2219 {
AzureIoTClient 32:4d4a226b072b 2220 *whereIsColon = '\0'; /*cut it down*/
AzureIoTClient 32:4d4a226b072b 2221 if (IoTHubMessage_SetContentTypeSystemProperty(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK)
AzureIoTClient 32:4d4a226b072b 2222 {
AzureIoTClient 32:4d4a226b072b 2223 LogError("Failed setting IoTHubMessage content-type");
AzureIoTClient 32:4d4a226b072b 2224 free(completeHeader);
AzureIoTClient 32:4d4a226b072b 2225 break;
AzureIoTClient 32:4d4a226b072b 2226 }
AzureIoTClient 32:4d4a226b072b 2227 }
AzureIoTClient 32:4d4a226b072b 2228 }
AzureIoTClient 38:01bf35934f1b 2229 // Codes_SRS_TRANSPORTMULTITHTTP_09_004: [ The HTTP header value of `ContentEncoding` shall be set in the `IoTHub_SetContentEncoding`. ]
AzureIoTClient 32:4d4a226b072b 2230 else if (strncmp(IOTHUB_CONTENT_ENCODING_C2D, completeHeader, strlen(IOTHUB_CONTENT_ENCODING_C2D)) == 0)
AzureIoTClient 32:4d4a226b072b 2231 {
AzureIoTClient 32:4d4a226b072b 2232 char* whereIsColon = strchr(completeHeader, ':');
AzureIoTClient 32:4d4a226b072b 2233 if (whereIsColon != NULL)
AzureIoTClient 32:4d4a226b072b 2234 {
AzureIoTClient 32:4d4a226b072b 2235 *whereIsColon = '\0'; /*cut it down*/
AzureIoTClient 32:4d4a226b072b 2236 if (IoTHubMessage_SetContentEncodingSystemProperty(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK)
AzureIoTClient 32:4d4a226b072b 2237 {
AzureIoTClient 32:4d4a226b072b 2238 LogError("Failed setting IoTHubMessage content-encoding");
AzureIoTClient 32:4d4a226b072b 2239 free(completeHeader);
AzureIoTClient 32:4d4a226b072b 2240 break;
AzureIoTClient 32:4d4a226b072b 2241 }
AzureIoTClient 32:4d4a226b072b 2242 }
AzureIoTClient 32:4d4a226b072b 2243 }
AzureIoTClient 32:4d4a226b072b 2244
Azure.IoT Build 19:d4f9e872bf3e 2245 free(completeHeader);
Azure.IoT Build 19:d4f9e872bf3e 2246 }
Azure.IoT Build 19:d4f9e872bf3e 2247 }
AzureIoTClient 6:73793bae15ba 2248
Azure.IoT Build 19:d4f9e872bf3e 2249 if (i < nHeaders)
Azure.IoT Build 19:d4f9e872bf3e 2250 {
AzureIoTClient 29:e44b1f827914 2251 if (!abandonOrAcceptMessage(handleData, deviceData, etagValue, IOTHUBMESSAGE_ABANDONED))
AzureIoTClient 29:e44b1f827914 2252 {
AzureIoTClient 29:e44b1f827914 2253 LogError("HTTP Transport layer failed to report ABANDON disposition");
AzureIoTClient 29:e44b1f827914 2254 }
Azure.IoT Build 19:d4f9e872bf3e 2255 }
Azure.IoT Build 19:d4f9e872bf3e 2256 else
Azure.IoT Build 19:d4f9e872bf3e 2257 {
AzureIoTClient 29:e44b1f827914 2258 MESSAGE_CALLBACK_INFO* messageData = MESSAGE_CALLBACK_INFO_Create(receivedMessage, handleData, deviceData, etagValue);
AzureIoTClient 29:e44b1f827914 2259 if (messageData == NULL)
Azure.IoT Build 19:d4f9e872bf3e 2260 {
AzureIoTClient 29:e44b1f827914 2261 /*Codes_SRS_TRANSPORTMULTITHTTP_10_006: [If assembling the transport context fails, _DoWork shall "abandon" the message.] */
AzureIoTClient 29:e44b1f827914 2262 LogError("failed to assemble callback info");
AzureIoTClient 29:e44b1f827914 2263 if (!abandonOrAcceptMessage(handleData, deviceData, etagValue, IOTHUBMESSAGE_ABANDONED))
AzureIoTClient 29:e44b1f827914 2264 {
AzureIoTClient 29:e44b1f827914 2265 LogError("HTTP Transport layer failed to report ABANDON disposition");
AzureIoTClient 29:e44b1f827914 2266 }
Azure.IoT Build 19:d4f9e872bf3e 2267 }
Azure.IoT Build 19:d4f9e872bf3e 2268 else
Azure.IoT Build 19:d4f9e872bf3e 2269 {
AzureIoTClient 29:e44b1f827914 2270 bool abandon;
AzureIoTClient 36:36c1e1ca5679 2271 if (IoTHubClientCore_LL_MessageCallback(iotHubClientHandle, messageData))
AzureIoTClient 29:e44b1f827914 2272 {
AzureIoTClient 29:e44b1f827914 2273 abandon = false;
AzureIoTClient 29:e44b1f827914 2274 }
AzureIoTClient 29:e44b1f827914 2275 else
AzureIoTClient 29:e44b1f827914 2276 {
AzureIoTClient 36:36c1e1ca5679 2277 LogError("IoTHubClientCore_LL_MessageCallback failed");
AzureIoTClient 29:e44b1f827914 2278 abandon = true;
AzureIoTClient 29:e44b1f827914 2279 }
AzureIoTClient 29:e44b1f827914 2280
AzureIoTClient 36:36c1e1ca5679 2281 /*Codes_SRS_TRANSPORTMULTITHTTP_17_096: [If IoTHubClientCore_LL_MessageCallback returns false then _DoWork shall "abandon" the message.] */
AzureIoTClient 29:e44b1f827914 2282 if (abandon)
AzureIoTClient 29:e44b1f827914 2283 {
AzureIoTClient 29:e44b1f827914 2284 (void)IoTHubTransportHttp_SendMessageDisposition(messageData, IOTHUBMESSAGE_ABANDONED);
AzureIoTClient 29:e44b1f827914 2285 }
Azure.IoT Build 19:d4f9e872bf3e 2286 }
Azure.IoT Build 19:d4f9e872bf3e 2287 }
Azure.IoT Build 19:d4f9e872bf3e 2288 }
Azure.IoT Build 19:d4f9e872bf3e 2289 IoTHubMessage_Destroy(receivedMessage);
Azure.IoT Build 19:d4f9e872bf3e 2290 }
Azure.IoT Build 19:d4f9e872bf3e 2291 }
Azure.IoT Build 19:d4f9e872bf3e 2292 }
Azure.IoT Build 19:d4f9e872bf3e 2293 }
Azure.IoT Build 19:d4f9e872bf3e 2294 }
Azure.IoT Build 19:d4f9e872bf3e 2295 BUFFER_delete(responseContent);
Azure.IoT Build 19:d4f9e872bf3e 2296 }
Azure.IoT Build 19:d4f9e872bf3e 2297 HTTPHeaders_Free(responseHTTPHeaders);
Azure.IoT Build 19:d4f9e872bf3e 2298 }
Azure.IoT Build 19:d4f9e872bf3e 2299 }
Azure.IoT Build 19:d4f9e872bf3e 2300 else
Azure.IoT Build 19:d4f9e872bf3e 2301 {
Azure.IoT Build 19:d4f9e872bf3e 2302 /*isPollingAllowed is false... */
Azure.IoT Build 19:d4f9e872bf3e 2303 /*do nothing "shall be ignored*/
Azure.IoT Build 19:d4f9e872bf3e 2304 }
Azure.IoT Build 19:d4f9e872bf3e 2305 }
AzureIoTClient 6:73793bae15ba 2306 }
AzureIoTClient 6:73793bae15ba 2307
AzureIoTClient 25:3a68a581d3f9 2308 static IOTHUB_PROCESS_ITEM_RESULT IoTHubTransportHttp_ProcessItem(TRANSPORT_LL_HANDLE handle, IOTHUB_IDENTITY_TYPE item_type, IOTHUB_IDENTITY_INFO* iothub_item)
AzureIoTClient 25:3a68a581d3f9 2309 {
AzureIoTClient 25:3a68a581d3f9 2310 (void)handle;
AzureIoTClient 25:3a68a581d3f9 2311 (void)item_type;
AzureIoTClient 25:3a68a581d3f9 2312 (void)iothub_item;
AzureIoTClient 25:3a68a581d3f9 2313 LogError("Currently Not Supported.");
AzureIoTClient 25:3a68a581d3f9 2314 return IOTHUB_PROCESS_ERROR;
AzureIoTClient 25:3a68a581d3f9 2315 }
AzureIoTClient 25:3a68a581d3f9 2316
AzureIoTClient 36:36c1e1ca5679 2317 static void IoTHubTransportHttp_DoWork(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_CORE_LL_HANDLE iotHubClientHandle)
AzureIoTClient 6:73793bae15ba 2318 {
Azure.IoT Build 19:d4f9e872bf3e 2319 /*Codes_SRS_TRANSPORTMULTITHTTP_17_049: [ If handle is NULL, then IoTHubTransportHttp_DoWork shall do nothing. ]*/
Azure.IoT Build 19:d4f9e872bf3e 2320 /*Codes_SRS_TRANSPORTMULTITHTTP_17_140: [ If iotHubClientHandle is NULL, then IoTHubTransportHttp_DoWork shall do nothing. ]*/
Azure.IoT Build 13:848d52f93daf 2321
Azure.IoT Build 19:d4f9e872bf3e 2322 (void)iotHubClientHandle; // use the perDevice handle.
Azure.IoT Build 19:d4f9e872bf3e 2323 if (handle != NULL)
Azure.IoT Build 19:d4f9e872bf3e 2324 {
Azure.IoT Build 19:d4f9e872bf3e 2325 HTTPTRANSPORT_HANDLE_DATA* handleData = (HTTPTRANSPORT_HANDLE_DATA*)handle;
Azure.IoT Build 19:d4f9e872bf3e 2326 IOTHUB_DEVICE_HANDLE* listItem;
Azure.IoT Build 19:d4f9e872bf3e 2327 size_t deviceListSize = VECTOR_size(handleData->perDeviceList);
Azure.IoT Build 19:d4f9e872bf3e 2328 /*Codes_SRS_TRANSPORTMULTITHTTP_17_052: [ IoTHubTransportHttp_DoWork shall perform a round-robin loop through every deviceHandle in the transport device list, using the iotHubClientHandle field saved in the IOTHUB_DEVICE_HANDLE. ]*/
Azure.IoT Build 19:d4f9e872bf3e 2329 /*Codes_SRS_TRANSPORTMULTITHTTP_17_050: [ IoTHubTransportHttp_DoWork shall call loop through the device list. ] */
Azure.IoT Build 19:d4f9e872bf3e 2330 /*Codes_SRS_TRANSPORTMULTITHTTP_17_051: [ IF the list is empty, then IoTHubTransportHttp_DoWork shall do nothing. ]*/
Azure.IoT Build 19:d4f9e872bf3e 2331 for (size_t i = 0; i < deviceListSize; i++)
Azure.IoT Build 19:d4f9e872bf3e 2332 {
AzureIoTClient 35:786954ce12e9 2333 listItem = (IOTHUB_DEVICE_HANDLE *)VECTOR_element(handleData->perDeviceList, i);
AzureIoTClient 22:e0add922c564 2334 HTTPTRANSPORT_PERDEVICE_DATA* perDeviceItem = *(HTTPTRANSPORT_PERDEVICE_DATA**)(listItem);
Azure.IoT Build 19:d4f9e872bf3e 2335 DoEvent(handleData, perDeviceItem, perDeviceItem->iotHubClientHandle);
Azure.IoT Build 19:d4f9e872bf3e 2336 DoMessages(handleData, perDeviceItem, perDeviceItem->iotHubClientHandle);
Azure.IoT Build 13:848d52f93daf 2337
Azure.IoT Build 19:d4f9e872bf3e 2338 }
Azure.IoT Build 19:d4f9e872bf3e 2339 }
Azure.IoT Build 19:d4f9e872bf3e 2340 else
Azure.IoT Build 19:d4f9e872bf3e 2341 {
Azure.IoT Build 19:d4f9e872bf3e 2342 LogError("Invalid Argument NULL call on DoWork.");
Azure.IoT Build 19:d4f9e872bf3e 2343 }
AzureIoTClient 6:73793bae15ba 2344 }
AzureIoTClient 6:73793bae15ba 2345
AzureIoTClient 18:ab990f6aa61f 2346 static IOTHUB_CLIENT_RESULT IoTHubTransportHttp_GetSendStatus(IOTHUB_DEVICE_HANDLE handle, IOTHUB_CLIENT_STATUS *iotHubClientStatus)
AzureIoTClient 6:73793bae15ba 2347 {
Azure.IoT Build 19:d4f9e872bf3e 2348 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 6:73793bae15ba 2349
Azure.IoT Build 19:d4f9e872bf3e 2350 if (handle == NULL)
Azure.IoT Build 19:d4f9e872bf3e 2351 {
Azure.IoT Build 19:d4f9e872bf3e 2352 /*Codes_SRS_TRANSPORTMULTITHTTP_17_111: [ IoTHubTransportHttp_GetSendStatus shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter. ]*/
Azure.IoT Build 19:d4f9e872bf3e 2353 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 19:d4f9e872bf3e 2354 LogError("Invalid handle to IoTHubClient HTTP transport instance.");
Azure.IoT Build 19:d4f9e872bf3e 2355 }
Azure.IoT Build 19:d4f9e872bf3e 2356 else if (iotHubClientStatus == NULL)
Azure.IoT Build 19:d4f9e872bf3e 2357 {
Azure.IoT Build 19:d4f9e872bf3e 2358 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 19:d4f9e872bf3e 2359 LogError("Invalid pointer to output parameter IOTHUB_CLIENT_STATUS.");
Azure.IoT Build 19:d4f9e872bf3e 2360 }
Azure.IoT Build 19:d4f9e872bf3e 2361 else
Azure.IoT Build 19:d4f9e872bf3e 2362 {
Azure.IoT Build 19:d4f9e872bf3e 2363 /*Codes_SRS_TRANSPORTMULTITHTTP_17_138: [ IoTHubTransportHttp_GetSendStatus shall locate deviceHandle in the transport device list by calling list_find_if. ]*/
Azure.IoT Build 19:d4f9e872bf3e 2364 IOTHUB_DEVICE_HANDLE* listItem = get_perDeviceDataItem(handle);
Azure.IoT Build 19:d4f9e872bf3e 2365 if (listItem == NULL)
Azure.IoT Build 19:d4f9e872bf3e 2366 {
Azure.IoT Build 19:d4f9e872bf3e 2367 /*Codes_SRS_TRANSPORTMULTITHTTP_17_139: [ If the device structure is not found, then this function shall fail and return with IOTHUB_CLIENT_INVALID_ARG. ]*/
Azure.IoT Build 19:d4f9e872bf3e 2368 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 19:d4f9e872bf3e 2369 LogError("Device not found in transport list.");
Azure.IoT Build 19:d4f9e872bf3e 2370 }
Azure.IoT Build 19:d4f9e872bf3e 2371 else
Azure.IoT Build 19:d4f9e872bf3e 2372 {
Azure.IoT Build 19:d4f9e872bf3e 2373 HTTPTRANSPORT_PERDEVICE_DATA* deviceData = (HTTPTRANSPORT_PERDEVICE_DATA*)(*listItem);
Azure.IoT Build 19:d4f9e872bf3e 2374 /* Codes_SRS_TRANSPORTMULTITHTTP_17_113: [ IoTHubTransportHttp_GetSendStatus shall return IOTHUB_CLIENT_OK and status IOTHUB_CLIENT_SEND_STATUS_BUSY if there are currently event items to be sent or being sent. ] */
Azure.IoT Build 19:d4f9e872bf3e 2375 if (!DList_IsListEmpty(deviceData->waitingToSend))
Azure.IoT Build 19:d4f9e872bf3e 2376 {
Azure.IoT Build 19:d4f9e872bf3e 2377 *iotHubClientStatus = IOTHUB_CLIENT_SEND_STATUS_BUSY;
Azure.IoT Build 19:d4f9e872bf3e 2378 }
Azure.IoT Build 19:d4f9e872bf3e 2379 /* Codes_SRS_TRANSPORTMULTITHTTP_17_112: [ IoTHubTransportHttp_GetSendStatus shall return IOTHUB_CLIENT_OK and status IOTHUB_CLIENT_SEND_STATUS_IDLE if there are currently no event items to be sent or being sent. ] */
Azure.IoT Build 19:d4f9e872bf3e 2380 else
Azure.IoT Build 19:d4f9e872bf3e 2381 {
Azure.IoT Build 19:d4f9e872bf3e 2382 *iotHubClientStatus = IOTHUB_CLIENT_SEND_STATUS_IDLE;
Azure.IoT Build 19:d4f9e872bf3e 2383 }
Azure.IoT Build 19:d4f9e872bf3e 2384 result = IOTHUB_CLIENT_OK;
Azure.IoT Build 19:d4f9e872bf3e 2385 }
Azure.IoT Build 19:d4f9e872bf3e 2386 }
AzureIoTClient 6:73793bae15ba 2387
Azure.IoT Build 19:d4f9e872bf3e 2388 return result;
AzureIoTClient 6:73793bae15ba 2389 }
AzureIoTClient 6:73793bae15ba 2390
AzureIoTClient 18:ab990f6aa61f 2391 static IOTHUB_CLIENT_RESULT IoTHubTransportHttp_SetOption(TRANSPORT_LL_HANDLE handle, const char* option, const void* value)
AzureIoTClient 6:73793bae15ba 2392 {
Azure.IoT Build 19:d4f9e872bf3e 2393 IOTHUB_CLIENT_RESULT result;
Azure.IoT Build 19:d4f9e872bf3e 2394 /*Codes_SRS_TRANSPORTMULTITHTTP_17_114: [If handle parameter is NULL then IoTHubTransportHttp_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
Azure.IoT Build 19:d4f9e872bf3e 2395 /*Codes_SRS_TRANSPORTMULTITHTTP_17_115: [If option parameter is NULL then IoTHubTransportHttp_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
Azure.IoT Build 19:d4f9e872bf3e 2396 /*Codes_SRS_TRANSPORTMULTITHTTP_17_116: [If value parameter is NULL then IoTHubTransportHttp_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
Azure.IoT Build 19:d4f9e872bf3e 2397 if (
Azure.IoT Build 19:d4f9e872bf3e 2398 (handle == NULL) ||
Azure.IoT Build 19:d4f9e872bf3e 2399 (option == NULL) ||
Azure.IoT Build 19:d4f9e872bf3e 2400 (value == NULL)
Azure.IoT Build 19:d4f9e872bf3e 2401 )
Azure.IoT Build 19:d4f9e872bf3e 2402 {
Azure.IoT Build 19:d4f9e872bf3e 2403 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 19:d4f9e872bf3e 2404 LogError("invalid parameter (NULL) passed to IoTHubTransportHttp_SetOption");
Azure.IoT Build 19:d4f9e872bf3e 2405 }
Azure.IoT Build 19:d4f9e872bf3e 2406 else
Azure.IoT Build 19:d4f9e872bf3e 2407 {
Azure.IoT Build 19:d4f9e872bf3e 2408 HTTPTRANSPORT_HANDLE_DATA* handleData = (HTTPTRANSPORT_HANDLE_DATA*)handle;
Azure.IoT Build 19:d4f9e872bf3e 2409 /*Codes_SRS_TRANSPORTMULTITHTTP_17_120: ["Batching"] */
AzureIoTClient 22:e0add922c564 2410 if (strcmp(OPTION_BATCHING, option) == 0)
Azure.IoT Build 19:d4f9e872bf3e 2411 {
Azure.IoT Build 19:d4f9e872bf3e 2412 /*Codes_SRS_TRANSPORTMULTITHTTP_17_117: [If optionName is an option handled by IoTHubTransportHttp then it shall be set.] */
Azure.IoT Build 19:d4f9e872bf3e 2413 handleData->doBatchedTransfers = *(bool*)value;
Azure.IoT Build 19:d4f9e872bf3e 2414 result = IOTHUB_CLIENT_OK;
Azure.IoT Build 19:d4f9e872bf3e 2415 }
Azure.IoT Build 19:d4f9e872bf3e 2416 /*Codes_SRS_TRANSPORTMULTITHTTP_17_121: ["MinimumPollingTime"] */
AzureIoTClient 22:e0add922c564 2417 else if (strcmp(OPTION_MIN_POLLING_TIME, option) == 0)
Azure.IoT Build 19:d4f9e872bf3e 2418 {
Azure.IoT Build 19:d4f9e872bf3e 2419 handleData->getMinimumPollingTime = *(unsigned int*)value;
Azure.IoT Build 19:d4f9e872bf3e 2420 result = IOTHUB_CLIENT_OK;
Azure.IoT Build 19:d4f9e872bf3e 2421 }
Azure.IoT Build 19:d4f9e872bf3e 2422 else
Azure.IoT Build 19:d4f9e872bf3e 2423 {
Azure.IoT Build 19:d4f9e872bf3e 2424 /*Codes_SRS_TRANSPORTMULTITHTTP_17_126: [ "TrustedCerts"] */
Azure.IoT Build 19:d4f9e872bf3e 2425 /*Codes_SRS_TRANSPORTMULTITHTTP_17_127: [ NULL shall be allowed. ]*/
Azure.IoT Build 19:d4f9e872bf3e 2426 /*Codes_SRS_TRANSPORTMULTITHTTP_17_129: [ This option shall passed down to the lower layer by calling HTTPAPIEX_SetOption. ]*/
Azure.IoT Build 19:d4f9e872bf3e 2427 /*Codes_SRS_TRANSPORTMULTITHTTP_17_118: [Otherwise, IoTHubTransport_Http shall call HTTPAPIEX_SetOption with the same parameters and return the translated code.] */
Azure.IoT Build 19:d4f9e872bf3e 2428 HTTPAPIEX_RESULT HTTPAPIEX_result = HTTPAPIEX_SetOption(handleData->httpApiExHandle, option, value);
Azure.IoT Build 19:d4f9e872bf3e 2429 /*Codes_SRS_TRANSPORTMULTITHTTP_17_119: [The following table translates HTTPAPIEX return codes to IOTHUB_CLIENT_RESULT return codes:] */
Azure.IoT Build 19:d4f9e872bf3e 2430 if (HTTPAPIEX_result == HTTPAPIEX_OK)
Azure.IoT Build 19:d4f9e872bf3e 2431 {
Azure.IoT Build 19:d4f9e872bf3e 2432 result = IOTHUB_CLIENT_OK;
Azure.IoT Build 19:d4f9e872bf3e 2433 }
Azure.IoT Build 19:d4f9e872bf3e 2434 else if (HTTPAPIEX_result == HTTPAPIEX_INVALID_ARG)
Azure.IoT Build 19:d4f9e872bf3e 2435 {
Azure.IoT Build 19:d4f9e872bf3e 2436 result = IOTHUB_CLIENT_INVALID_ARG;
Azure.IoT Build 19:d4f9e872bf3e 2437 LogError("HTTPAPIEX_SetOption failed");
Azure.IoT Build 19:d4f9e872bf3e 2438 }
Azure.IoT Build 19:d4f9e872bf3e 2439 else
Azure.IoT Build 19:d4f9e872bf3e 2440 {
Azure.IoT Build 19:d4f9e872bf3e 2441 result = IOTHUB_CLIENT_ERROR;
Azure.IoT Build 19:d4f9e872bf3e 2442 LogError("HTTPAPIEX_SetOption failed");
Azure.IoT Build 19:d4f9e872bf3e 2443 }
Azure.IoT Build 19:d4f9e872bf3e 2444 }
Azure.IoT Build 19:d4f9e872bf3e 2445 }
Azure.IoT Build 19:d4f9e872bf3e 2446 return result;
AzureIoTClient 6:73793bae15ba 2447 }
AzureIoTClient 18:ab990f6aa61f 2448
AzureIoTClient 18:ab990f6aa61f 2449 static STRING_HANDLE IoTHubTransportHttp_GetHostname(TRANSPORT_LL_HANDLE handle)
AzureIoTClient 18:ab990f6aa61f 2450 {
AzureIoTClient 18:ab990f6aa61f 2451 STRING_HANDLE result;
AzureIoTClient 18:ab990f6aa61f 2452 /*Codes_SRS_TRANSPORTMULTITHTTP_02_001: [ If handle is NULL then IoTHubTransportHttp_GetHostname shall fail and return NULL. ]*/
AzureIoTClient 18:ab990f6aa61f 2453 if (handle == NULL)
AzureIoTClient 18:ab990f6aa61f 2454 {
AzureIoTClient 18:ab990f6aa61f 2455 LogError("invalid parameter handle=%p", handle);
AzureIoTClient 18:ab990f6aa61f 2456 result = NULL;
AzureIoTClient 18:ab990f6aa61f 2457 }
AzureIoTClient 30:655054f86a6e 2458 /*Codes_SRS_TRANSPORTMULTITHTTP_02_002: [ Otherwise IoTHubTransportHttp_GetHostname shall return a non-NULL STRING_HANDLE containing the hostname. ]*/
AzureIoTClient 30:655054f86a6e 2459 else if ((result = STRING_clone(((HTTPTRANSPORT_HANDLE_DATA*)(handle))->hostName)) == NULL)
AzureIoTClient 18:ab990f6aa61f 2460 {
AzureIoTClient 30:655054f86a6e 2461 LogError("Cannot provide the target host name (STRING_clone failed).");
AzureIoTClient 18:ab990f6aa61f 2462 }
AzureIoTClient 30:655054f86a6e 2463
AzureIoTClient 18:ab990f6aa61f 2464 return result;
AzureIoTClient 18:ab990f6aa61f 2465 }
AzureIoTClient 18:ab990f6aa61f 2466
AzureIoTClient 25:3a68a581d3f9 2467 static int IoTHubTransportHttp_SetRetryPolicy(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds)
AzureIoTClient 25:3a68a581d3f9 2468 {
AzureIoTClient 25:3a68a581d3f9 2469 int result;
AzureIoTClient 25:3a68a581d3f9 2470 (void)handle;
AzureIoTClient 25:3a68a581d3f9 2471 (void)retryPolicy;
AzureIoTClient 25:3a68a581d3f9 2472 (void)retryTimeoutLimitInSeconds;
AzureIoTClient 25:3a68a581d3f9 2473
AzureIoTClient 25:3a68a581d3f9 2474 /* Retry Policy is not currently not available for HTTP */
AzureIoTClient 25:3a68a581d3f9 2475
AzureIoTClient 25:3a68a581d3f9 2476 result = 0;
AzureIoTClient 25:3a68a581d3f9 2477 return result;
AzureIoTClient 25:3a68a581d3f9 2478 }
AzureIoTClient 25:3a68a581d3f9 2479
AzureIoTClient 37:ce4c05dd8a6d 2480 static int IotHubTransportHttp_Subscribe_InputQueue(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 37:ce4c05dd8a6d 2481 {
AzureIoTClient 37:ce4c05dd8a6d 2482 (void)handle;
AzureIoTClient 37:ce4c05dd8a6d 2483 LogError("HTTP does not support input queues");
AzureIoTClient 37:ce4c05dd8a6d 2484 return __FAILURE__;
AzureIoTClient 37:ce4c05dd8a6d 2485 }
AzureIoTClient 37:ce4c05dd8a6d 2486
AzureIoTClient 37:ce4c05dd8a6d 2487 static void IotHubTransportHttp_Unsubscribe_InputQueue(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 37:ce4c05dd8a6d 2488 {
AzureIoTClient 37:ce4c05dd8a6d 2489 (void)handle;
AzureIoTClient 37:ce4c05dd8a6d 2490 LogError("HTTP does not support input queues");
AzureIoTClient 37:ce4c05dd8a6d 2491 }
AzureIoTClient 37:ce4c05dd8a6d 2492
AzureIoTClient 37:ce4c05dd8a6d 2493
AzureIoTClient 18:ab990f6aa61f 2494 /*Codes_SRS_TRANSPORTMULTITHTTP_17_125: [This function shall return a pointer to a structure of type TRANSPORT_PROVIDER having the following values for its fields:] */
AzureIoTClient 18:ab990f6aa61f 2495 static TRANSPORT_PROVIDER thisTransportProvider =
AzureIoTClient 18:ab990f6aa61f 2496 {
AzureIoTClient 29:e44b1f827914 2497 IoTHubTransportHttp_SendMessageDisposition, /*pfIotHubTransport_SendMessageDisposition IoTHubTransport_SendMessageDisposition;*/
AzureIoTClient 25:3a68a581d3f9 2498 IoTHubTransportHttp_Subscribe_DeviceMethod, /*pfIoTHubTransport_Subscribe_DeviceMethod IoTHubTransport_Subscribe_DeviceMethod;*/
AzureIoTClient 25:3a68a581d3f9 2499 IoTHubTransportHttp_Unsubscribe_DeviceMethod, /*pfIoTHubTransport_Unsubscribe_DeviceMethod IoTHubTransport_Unsubscribe_DeviceMethod;*/
AzureIoTClient 26:aeabbfa5181a 2500 IoTHubTransportHttp_DeviceMethod_Response, /*pfIoTHubTransport_DeviceMethod_Response IoTHubTransport_DeviceMethod_Response;*/
AzureIoTClient 25:3a68a581d3f9 2501 IoTHubTransportHttp_Subscribe_DeviceTwin, /*pfIoTHubTransport_Subscribe_DeviceTwin IoTHubTransport_Subscribe_DeviceTwin;*/
AzureIoTClient 25:3a68a581d3f9 2502 IoTHubTransportHttp_Unsubscribe_DeviceTwin, /*pfIoTHubTransport_Unsubscribe_DeviceTwin IoTHubTransport_Unsubscribe_DeviceTwin;*/
AzureIoTClient 25:3a68a581d3f9 2503 IoTHubTransportHttp_ProcessItem, /*pfIoTHubTransport_ProcessItem IoTHubTransport_ProcessItem;*/
AzureIoTClient 25:3a68a581d3f9 2504 IoTHubTransportHttp_GetHostname, /*pfIoTHubTransport_GetHostname IoTHubTransport_GetHostname;*/
AzureIoTClient 25:3a68a581d3f9 2505 IoTHubTransportHttp_SetOption, /*pfIoTHubTransport_SetOption IoTHubTransport_SetOption;*/
AzureIoTClient 25:3a68a581d3f9 2506 IoTHubTransportHttp_Create, /*pfIoTHubTransport_Create IoTHubTransport_Create;*/
AzureIoTClient 25:3a68a581d3f9 2507 IoTHubTransportHttp_Destroy, /*pfIoTHubTransport_Destroy IoTHubTransport_Destroy;*/
AzureIoTClient 25:3a68a581d3f9 2508 IoTHubTransportHttp_Register, /*pfIotHubTransport_Register IoTHubTransport_Register;*/
AzureIoTClient 25:3a68a581d3f9 2509 IoTHubTransportHttp_Unregister, /*pfIotHubTransport_Unregister IoTHubTransport_Unegister;*/
AzureIoTClient 25:3a68a581d3f9 2510 IoTHubTransportHttp_Subscribe, /*pfIoTHubTransport_Subscribe IoTHubTransport_Subscribe;*/
AzureIoTClient 25:3a68a581d3f9 2511 IoTHubTransportHttp_Unsubscribe, /*pfIoTHubTransport_Unsubscribe IoTHubTransport_Unsubscribe;*/
AzureIoTClient 25:3a68a581d3f9 2512 IoTHubTransportHttp_DoWork, /*pfIoTHubTransport_DoWork IoTHubTransport_DoWork;*/
AzureIoTClient 25:3a68a581d3f9 2513 IoTHubTransportHttp_SetRetryPolicy, /*pfIoTHubTransport_DoWork IoTHubTransport_SetRetryPolicy;*/
AzureIoTClient 37:ce4c05dd8a6d 2514 IoTHubTransportHttp_GetSendStatus, /*pfIoTHubTransport_GetSendStatus IoTHubTransport_GetSendStatus;*/
AzureIoTClient 37:ce4c05dd8a6d 2515 IotHubTransportHttp_Subscribe_InputQueue, /*pfIoTHubTransport_Subscribe_InputQueue IoTHubTransport_Subscribe_InputQueue; */
AzureIoTClient 37:ce4c05dd8a6d 2516 IotHubTransportHttp_Unsubscribe_InputQueue /*pfIoTHubTransport_Unsubscribe_InputQueue IoTHubTransport_Unsubscribe_InputQueue; */
AzureIoTClient 18:ab990f6aa61f 2517 };
AzureIoTClient 18:ab990f6aa61f 2518
AzureIoTClient 18:ab990f6aa61f 2519 const TRANSPORT_PROVIDER* HTTP_Protocol(void)
AzureIoTClient 18:ab990f6aa61f 2520 {
AzureIoTClient 18:ab990f6aa61f 2521 return &thisTransportProvider;
AzureIoTClient 18:ab990f6aa61f 2522 }