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