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
Diff: iothubtransporthttp.c
- Revision:
- 7:48f0f78cd3ef
- Parent:
- 6:73793bae15ba
- Child:
- 8:1b71bf027eb5
--- a/iothubtransporthttp.c Thu Oct 22 18:33:19 2015 -0700 +++ b/iothubtransporthttp.c Mon Nov 02 19:21:17 2015 -0800 @@ -23,6 +23,8 @@ #include "agenttime.h" #define IOTHUB_APP_PREFIX "iothub-app-" +const char* IOTHUB_MESSAGE_ID = "iothub-messageid"; +const char* IOTHUB_CORRELATION_ID = "iothub-correlationid"; #define CONTENT_TYPE "Content-Type" #define APPLICATION_OCTET_STREAM "application/octet-stream" @@ -1146,6 +1148,27 @@ } } + // Add the Message Id and the Correlation Id + const char* msgId = IoTHubMessage_GetMessageId(message->messageHandle); + if (goOn && msgId != NULL) + { + if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_MESSAGE_ID, msgId) != HTTP_HEADERS_OK) + { + LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair\r\n"); + goOn = false; + } + } + + const char* corrId = IoTHubMessage_GetCorrelationId(message->messageHandle); + if (goOn && corrId != NULL) + { + if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_CORRELATION_ID, corrId) != HTTP_HEADERS_OK) + { + LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair\r\n"); + goOn = false; + } + } + if (!goOn) { /*Codes_SRS_IOTHUBTRANSPORTTHTTP_02_108: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */ @@ -1461,6 +1484,7 @@ else { /*Codes_SRS_IOTHUBTRANSPORTTHTTP_02_087: [All the HTTP headers of the form iothub-app-name:somecontent shall be transformed in message properties {name, somecontent}.]*/ + /*Codes_SRS_IOTHUBTRANSPORTTHTTP_07_008: [The HTTP header of iothub-messageid shall be set in the MessageId.]*/ size_t nHeaders; if (HTTPHeaders_GetHeaderCount(responseHTTPHeaders, &nHeaders) != HTTP_HEADERS_OK) { @@ -1485,11 +1509,40 @@ /*looks like a property headers*/ /*there's a guaranteed ':' in the completeHeader, by HTTP_HEADERS module*/ char* whereIsColon = strchr(completeHeader, ':'); - *whereIsColon = '\0'; /*cut it down*/ - 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*/ + if (whereIsColon != NULL) + { + *whereIsColon = '\0'; /*cut it down*/ + 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*/ + { + free(completeHeader); + break; + } + } + } + else if (strncmp(IOTHUB_MESSAGE_ID, completeHeader, strlen(IOTHUB_MESSAGE_ID)) == 0) + { + char* whereIsColon = strchr(completeHeader, ':'); + if (whereIsColon != NULL) { - free(completeHeader); - break; + *whereIsColon = '\0'; /*cut it down*/ + if (IoTHubMessage_SetMessageId(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK) + { + free(completeHeader); + break; + } + } + } + else if (strncmp(IOTHUB_CORRELATION_ID, completeHeader, strlen(IOTHUB_CORRELATION_ID)) == 0) + { + char* whereIsColon = strchr(completeHeader, ':'); + if (whereIsColon != NULL) + { + *whereIsColon = '\0'; /*cut it down*/ + if (IoTHubMessage_SetCorrelationId(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK) + { + free(completeHeader); + break; + } } } free(completeHeader);