Microsoft Azure IoTHub client libraries
Dependents: sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more
This library implements the Microsoft Azure IoTHub client library. The code is replicated from https://github.com/Azure/azure-iot-sdks
iothub_client_ll_uploadtoblob.c@75:86205ca63a59, 2017-09-11 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Mon Sep 11 09:22:55 2017 -0700
- Revision:
- 75:86205ca63a59
- Parent:
- 74:ea0021abecf7
- Child:
- 77:e4e36df9caee
1.1.23
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AzureIoTClient | 42:448eecc3676e | 1 | // Copyright (c) Microsoft. All rights reserved. |
AzureIoTClient | 42:448eecc3676e | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
AzureIoTClient | 42:448eecc3676e | 3 | |
Azure.IoT Build | 45:54c11b1b1407 | 4 | #ifdef DONT_USE_UPLOADTOBLOB |
Azure.IoT Build | 45:54c11b1b1407 | 5 | #error "trying to compile iothub_client_ll_uploadtoblob.c while the symbol DONT_USE_UPLOADTOBLOB is #define'd" |
Azure.IoT Build | 45:54c11b1b1407 | 6 | #else |
Azure.IoT Build | 45:54c11b1b1407 | 7 | |
AzureIoTClient | 42:448eecc3676e | 8 | #include <stdlib.h> |
AzureIoTClient | 42:448eecc3676e | 9 | #include <string.h> |
AzureIoTClient | 60:41648c4e7036 | 10 | #include "azure_c_shared_utility/optimize_size.h" |
AzureIoTClient | 42:448eecc3676e | 11 | #include "azure_c_shared_utility/gballoc.h" |
AzureIoTClient | 42:448eecc3676e | 12 | #include "azure_c_shared_utility/string_tokenizer.h" |
AzureIoTClient | 42:448eecc3676e | 13 | #include "azure_c_shared_utility/doublylinkedlist.h" |
Azure.IoT Build | 45:54c11b1b1407 | 14 | #include "azure_c_shared_utility/xlogging.h" |
AzureIoTClient | 42:448eecc3676e | 15 | #include "azure_c_shared_utility/tickcounter.h" |
AzureIoTClient | 42:448eecc3676e | 16 | #include "azure_c_shared_utility/httpapiexsas.h" |
AzureIoTClient | 74:ea0021abecf7 | 17 | #include "azure_c_shared_utility/shared_util_options.h" |
AzureIoTClient | 42:448eecc3676e | 18 | |
AzureIoTClient | 42:448eecc3676e | 19 | #include "iothub_client_ll.h" |
AzureIoTClient | 48:cc5d91f2b06d | 20 | #include "iothub_client_options.h" |
AzureIoTClient | 42:448eecc3676e | 21 | #include "iothub_client_private.h" |
AzureIoTClient | 42:448eecc3676e | 22 | #include "iothub_client_version.h" |
AzureIoTClient | 42:448eecc3676e | 23 | #include "iothub_transport_ll.h" |
AzureIoTClient | 42:448eecc3676e | 24 | #include "parson.h" |
AzureIoTClient | 42:448eecc3676e | 25 | #include "iothub_client_ll_uploadtoblob.h" |
AzureIoTClient | 42:448eecc3676e | 26 | #include "blob.h" |
AzureIoTClient | 42:448eecc3676e | 27 | |
AzureIoTClient | 47:aaa262b5f898 | 28 | |
AzureIoTClient | 47:aaa262b5f898 | 29 | #ifdef WINCE |
AzureIoTClient | 47:aaa262b5f898 | 30 | #include <stdarg.h> |
AzureIoTClient | 47:aaa262b5f898 | 31 | // Returns number of characters copied. |
AzureIoTClient | 47:aaa262b5f898 | 32 | int snprintf(char * s, size_t n, const char * format, ...) |
AzureIoTClient | 47:aaa262b5f898 | 33 | { |
AzureIoTClient | 48:cc5d91f2b06d | 34 | int result; |
AzureIoTClient | 48:cc5d91f2b06d | 35 | va_list args; |
AzureIoTClient | 48:cc5d91f2b06d | 36 | va_start(args, format); |
AzureIoTClient | 48:cc5d91f2b06d | 37 | result = vsnprintf(s, n, format, args); |
AzureIoTClient | 48:cc5d91f2b06d | 38 | va_end(args); |
AzureIoTClient | 48:cc5d91f2b06d | 39 | return result; |
AzureIoTClient | 47:aaa262b5f898 | 40 | } |
AzureIoTClient | 47:aaa262b5f898 | 41 | #endif |
AzureIoTClient | 47:aaa262b5f898 | 42 | |
AzureIoTClient | 47:aaa262b5f898 | 43 | |
AzureIoTClient | 42:448eecc3676e | 44 | /*Codes_SRS_IOTHUBCLIENT_LL_02_085: [ IoTHubClient_LL_UploadToBlob shall use the same authorization as step 1. to prepare and perform a HTTP request with the following parameters: ]*/ |
AzureIoTClient | 42:448eecc3676e | 45 | #define FILE_UPLOAD_FAILED_BODY "{ \"isSuccess\":false, \"statusCode\":-1,\"statusDescription\" : \"client not able to connect with the server\" }" |
AzureIoTClient | 42:448eecc3676e | 46 | |
AzureIoTClient | 42:448eecc3676e | 47 | #define AUTHORIZATION_SCHEME_VALUES \ |
AzureIoTClient | 42:448eecc3676e | 48 | DEVICE_KEY, \ |
AzureIoTClient | 46:6a69294b6119 | 49 | X509, \ |
AzureIoTClient | 42:448eecc3676e | 50 | SAS_TOKEN |
AzureIoTClient | 42:448eecc3676e | 51 | DEFINE_ENUM(AUTHORIZATION_SCHEME, AUTHORIZATION_SCHEME_VALUES); |
AzureIoTClient | 42:448eecc3676e | 52 | |
AzureIoTClient | 46:6a69294b6119 | 53 | typedef struct UPLOADTOBLOB_X509_CREDENTIALS_TAG |
AzureIoTClient | 46:6a69294b6119 | 54 | { |
AzureIoTClient | 46:6a69294b6119 | 55 | const char* x509certificate; |
AzureIoTClient | 46:6a69294b6119 | 56 | const char* x509privatekey; |
AzureIoTClient | 46:6a69294b6119 | 57 | }UPLOADTOBLOB_X509_CREDENTIALS; |
AzureIoTClient | 46:6a69294b6119 | 58 | |
AzureIoTClient | 42:448eecc3676e | 59 | typedef struct IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA_TAG |
AzureIoTClient | 42:448eecc3676e | 60 | { |
AzureIoTClient | 42:448eecc3676e | 61 | STRING_HANDLE deviceId; /*needed for file upload*/ |
AzureIoTClient | 42:448eecc3676e | 62 | const char* hostname; /*needed for file upload*/ |
AzureIoTClient | 42:448eecc3676e | 63 | AUTHORIZATION_SCHEME authorizationScheme; /*needed for file upload*/ |
AzureIoTClient | 42:448eecc3676e | 64 | union { |
AzureIoTClient | 42:448eecc3676e | 65 | STRING_HANDLE deviceKey; /*used when authorizationScheme is DEVICE_KEY*/ |
AzureIoTClient | 42:448eecc3676e | 66 | STRING_HANDLE sas; /*used when authorizationScheme is SAS_TOKEN*/ |
AzureIoTClient | 46:6a69294b6119 | 67 | UPLOADTOBLOB_X509_CREDENTIALS x509credentials; /*assumed to be used when both deviceKey and deviceSasToken are NULL*/ |
AzureIoTClient | 42:448eecc3676e | 68 | } credentials; /*needed for file upload*/ |
AzureIoTClient | 62:5a4cdacf5090 | 69 | char* certificates; /*if there are any certificates used*/ |
AzureIoTClient | 74:ea0021abecf7 | 70 | HTTP_PROXY_OPTIONS http_proxy_options; |
AzureIoTClient | 42:448eecc3676e | 71 | }IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA; |
AzureIoTClient | 42:448eecc3676e | 72 | |
AzureIoTClient | 42:448eecc3676e | 73 | IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE IoTHubClient_LL_UploadToBlob_Create(const IOTHUB_CLIENT_CONFIG* config) |
AzureIoTClient | 42:448eecc3676e | 74 | { |
AzureIoTClient | 42:448eecc3676e | 75 | IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* handleData = malloc(sizeof(IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA)); |
AzureIoTClient | 42:448eecc3676e | 76 | if (handleData == NULL) |
AzureIoTClient | 42:448eecc3676e | 77 | { |
AzureIoTClient | 42:448eecc3676e | 78 | LogError("oom - malloc"); |
AzureIoTClient | 42:448eecc3676e | 79 | /*return as is*/ |
AzureIoTClient | 42:448eecc3676e | 80 | } |
AzureIoTClient | 42:448eecc3676e | 81 | else |
AzureIoTClient | 42:448eecc3676e | 82 | { |
AzureIoTClient | 42:448eecc3676e | 83 | size_t iotHubNameLength = strlen(config->iotHubName); |
AzureIoTClient | 42:448eecc3676e | 84 | size_t iotHubSuffixLength = strlen(config->iotHubSuffix); |
AzureIoTClient | 42:448eecc3676e | 85 | handleData->deviceId = STRING_construct(config->deviceId); |
AzureIoTClient | 42:448eecc3676e | 86 | if (handleData->deviceId == NULL) |
AzureIoTClient | 42:448eecc3676e | 87 | { |
AzureIoTClient | 42:448eecc3676e | 88 | LogError("unable to STRING_construct"); |
AzureIoTClient | 42:448eecc3676e | 89 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 90 | handleData = NULL; |
AzureIoTClient | 42:448eecc3676e | 91 | } |
AzureIoTClient | 42:448eecc3676e | 92 | else |
AzureIoTClient | 42:448eecc3676e | 93 | { |
AzureIoTClient | 42:448eecc3676e | 94 | handleData->hostname = malloc(iotHubNameLength + 1 + iotHubSuffixLength + 1); /*first +1 is because "." the second +1 is because \0*/ |
AzureIoTClient | 42:448eecc3676e | 95 | if (handleData->hostname == NULL) |
AzureIoTClient | 42:448eecc3676e | 96 | { |
AzureIoTClient | 42:448eecc3676e | 97 | LogError("malloc failed"); |
AzureIoTClient | 42:448eecc3676e | 98 | STRING_delete(handleData->deviceId); |
AzureIoTClient | 42:448eecc3676e | 99 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 100 | handleData = NULL; |
AzureIoTClient | 42:448eecc3676e | 101 | } |
AzureIoTClient | 42:448eecc3676e | 102 | else |
AzureIoTClient | 42:448eecc3676e | 103 | { |
AzureIoTClient | 75:86205ca63a59 | 104 | char* insert_pos = (char*)handleData->hostname; |
AzureIoTClient | 75:86205ca63a59 | 105 | (void)memcpy((char*)insert_pos, config->iotHubName, iotHubNameLength); |
AzureIoTClient | 75:86205ca63a59 | 106 | insert_pos += iotHubNameLength; |
AzureIoTClient | 75:86205ca63a59 | 107 | *insert_pos = '.'; |
AzureIoTClient | 75:86205ca63a59 | 108 | insert_pos += 1; |
AzureIoTClient | 75:86205ca63a59 | 109 | (void)memcpy(insert_pos, config->iotHubSuffix, iotHubSuffixLength); /*+1 will copy the \0 too*/ |
AzureIoTClient | 75:86205ca63a59 | 110 | insert_pos += iotHubSuffixLength; |
AzureIoTClient | 75:86205ca63a59 | 111 | *insert_pos = '\0'; |
AzureIoTClient | 75:86205ca63a59 | 112 | |
AzureIoTClient | 62:5a4cdacf5090 | 113 | handleData->certificates = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 114 | memset(&(handleData->http_proxy_options), 0, sizeof(HTTP_PROXY_OPTIONS)); |
AzureIoTClient | 74:ea0021abecf7 | 115 | |
AzureIoTClient | 46:6a69294b6119 | 116 | if ((config->deviceSasToken != NULL) && (config->deviceKey == NULL)) |
AzureIoTClient | 42:448eecc3676e | 117 | { |
AzureIoTClient | 42:448eecc3676e | 118 | handleData->authorizationScheme = SAS_TOKEN; |
AzureIoTClient | 42:448eecc3676e | 119 | handleData->credentials.sas = STRING_construct(config->deviceSasToken); |
AzureIoTClient | 42:448eecc3676e | 120 | if (handleData->credentials.sas == NULL) |
AzureIoTClient | 42:448eecc3676e | 121 | { |
AzureIoTClient | 42:448eecc3676e | 122 | LogError("unable to STRING_construct"); |
AzureIoTClient | 42:448eecc3676e | 123 | free((void*)handleData->hostname); |
AzureIoTClient | 42:448eecc3676e | 124 | STRING_delete(handleData->deviceId); |
AzureIoTClient | 42:448eecc3676e | 125 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 126 | handleData = NULL; |
AzureIoTClient | 42:448eecc3676e | 127 | } |
AzureIoTClient | 42:448eecc3676e | 128 | else |
AzureIoTClient | 42:448eecc3676e | 129 | { |
AzureIoTClient | 42:448eecc3676e | 130 | /*return as is*/ |
AzureIoTClient | 42:448eecc3676e | 131 | } |
AzureIoTClient | 42:448eecc3676e | 132 | } |
AzureIoTClient | 46:6a69294b6119 | 133 | else if ((config->deviceSasToken == NULL) && (config->deviceKey != NULL)) |
AzureIoTClient | 42:448eecc3676e | 134 | { |
AzureIoTClient | 42:448eecc3676e | 135 | handleData->authorizationScheme = DEVICE_KEY; |
AzureIoTClient | 42:448eecc3676e | 136 | handleData->credentials.deviceKey = STRING_construct(config->deviceKey); |
AzureIoTClient | 42:448eecc3676e | 137 | if (handleData->credentials.deviceKey == NULL) |
AzureIoTClient | 42:448eecc3676e | 138 | { |
AzureIoTClient | 42:448eecc3676e | 139 | LogError("unable to STRING_construct"); |
AzureIoTClient | 42:448eecc3676e | 140 | free((void*)handleData->hostname); |
AzureIoTClient | 42:448eecc3676e | 141 | STRING_delete(handleData->deviceId); |
AzureIoTClient | 42:448eecc3676e | 142 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 143 | handleData = NULL; |
AzureIoTClient | 42:448eecc3676e | 144 | } |
AzureIoTClient | 42:448eecc3676e | 145 | else |
AzureIoTClient | 42:448eecc3676e | 146 | { |
AzureIoTClient | 42:448eecc3676e | 147 | /*return as is*/ |
AzureIoTClient | 42:448eecc3676e | 148 | } |
AzureIoTClient | 42:448eecc3676e | 149 | } |
AzureIoTClient | 46:6a69294b6119 | 150 | else if ((config->deviceSasToken == NULL) && (config->deviceKey == NULL)) |
AzureIoTClient | 46:6a69294b6119 | 151 | { |
AzureIoTClient | 46:6a69294b6119 | 152 | handleData->authorizationScheme = X509; |
AzureIoTClient | 46:6a69294b6119 | 153 | handleData->credentials.x509credentials.x509certificate = NULL; |
AzureIoTClient | 46:6a69294b6119 | 154 | handleData->credentials.x509credentials.x509privatekey = NULL; |
AzureIoTClient | 46:6a69294b6119 | 155 | /*return as is*/ |
AzureIoTClient | 46:6a69294b6119 | 156 | } |
AzureIoTClient | 42:448eecc3676e | 157 | } |
AzureIoTClient | 42:448eecc3676e | 158 | } |
AzureIoTClient | 42:448eecc3676e | 159 | } |
AzureIoTClient | 42:448eecc3676e | 160 | return (IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE)handleData; |
AzureIoTClient | 42:448eecc3676e | 161 | |
AzureIoTClient | 42:448eecc3676e | 162 | } |
AzureIoTClient | 42:448eecc3676e | 163 | |
AzureIoTClient | 42:448eecc3676e | 164 | /*returns 0 when correlationId, sasUri contain data*/ |
AzureIoTClient | 42:448eecc3676e | 165 | static int IoTHubClient_LL_UploadToBlob_step1and2(IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* handleData, HTTPAPIEX_HANDLE iotHubHttpApiExHandle, HTTP_HEADERS_HANDLE requestHttpHeaders, const char* destinationFileName, |
AzureIoTClient | 42:448eecc3676e | 166 | STRING_HANDLE correlationId, STRING_HANDLE sasUri) |
AzureIoTClient | 42:448eecc3676e | 167 | { |
AzureIoTClient | 42:448eecc3676e | 168 | int result; |
AzureIoTClient | 42:448eecc3676e | 169 | |
AzureIoTClient | 69:b6f532f8c608 | 170 | /*Codes_SRS_IOTHUBCLIENT_LL_02_066: [ IoTHubClient_LL_UploadToBlob shall create an HTTP relative path formed from "/devices/" + deviceId + "/files/" + "?api-version=API_VERSION". ]*/ |
AzureIoTClient | 42:448eecc3676e | 171 | STRING_HANDLE relativePath = STRING_construct("/devices/"); |
AzureIoTClient | 42:448eecc3676e | 172 | if (relativePath == NULL) |
AzureIoTClient | 42:448eecc3676e | 173 | { |
AzureIoTClient | 42:448eecc3676e | 174 | /*Codes_SRS_IOTHUBCLIENT_LL_02_067: [ If creating the relativePath fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 42:448eecc3676e | 175 | LogError("unable to STRING_construct"); |
AzureIoTClient | 60:41648c4e7036 | 176 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 177 | } |
AzureIoTClient | 74:ea0021abecf7 | 178 | else |
AzureIoTClient | 74:ea0021abecf7 | 179 | { |
AzureIoTClient | 74:ea0021abecf7 | 180 | if (!( |
AzureIoTClient | 74:ea0021abecf7 | 181 | (STRING_concat_with_STRING(relativePath, handleData->deviceId) == 0) && |
AzureIoTClient | 74:ea0021abecf7 | 182 | (STRING_concat(relativePath, "/files") == 0) && |
AzureIoTClient | 74:ea0021abecf7 | 183 | (STRING_concat(relativePath, API_VERSION) == 0) |
AzureIoTClient | 74:ea0021abecf7 | 184 | )) |
AzureIoTClient | 74:ea0021abecf7 | 185 | { |
AzureIoTClient | 74:ea0021abecf7 | 186 | /*Codes_SRS_IOTHUBCLIENT_LL_02_067: [ If creating the relativePath fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 187 | LogError("unable to concatenate STRING"); |
AzureIoTClient | 74:ea0021abecf7 | 188 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 189 | } |
AzureIoTClient | 74:ea0021abecf7 | 190 | else |
AzureIoTClient | 74:ea0021abecf7 | 191 | { |
AzureIoTClient | 74:ea0021abecf7 | 192 | /*Codes_SRS_IOTHUBCLIENT_LL_32_001: [ IoTHubClient_LL_UploadToBlob shall create a JSON string formed from "{ \"blobName\": \" + destinationFileName + "\" }" */ |
AzureIoTClient | 74:ea0021abecf7 | 193 | STRING_HANDLE blobName = STRING_construct("{ \"blobName\": \""); |
AzureIoTClient | 74:ea0021abecf7 | 194 | if (blobName == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 195 | { |
AzureIoTClient | 74:ea0021abecf7 | 196 | /*Codes_SRS_IOTHUBCLIENT_LL_32_002: [ If creating the JSON string fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 197 | LogError("unable to STRING_construct"); |
AzureIoTClient | 74:ea0021abecf7 | 198 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 199 | } |
AzureIoTClient | 74:ea0021abecf7 | 200 | else |
AzureIoTClient | 74:ea0021abecf7 | 201 | { |
AzureIoTClient | 74:ea0021abecf7 | 202 | if (!( |
AzureIoTClient | 74:ea0021abecf7 | 203 | (STRING_concat(blobName, destinationFileName) == 0) && |
AzureIoTClient | 74:ea0021abecf7 | 204 | (STRING_concat(blobName, "\" }") == 0) |
AzureIoTClient | 74:ea0021abecf7 | 205 | )) |
AzureIoTClient | 74:ea0021abecf7 | 206 | { |
AzureIoTClient | 74:ea0021abecf7 | 207 | /*Codes_SRS_IOTHUBCLIENT_LL_32_002: [ If creating the JSON string fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 208 | LogError("unable to concatenate STRING"); |
AzureIoTClient | 74:ea0021abecf7 | 209 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 210 | } |
AzureIoTClient | 74:ea0021abecf7 | 211 | else |
AzureIoTClient | 74:ea0021abecf7 | 212 | { |
AzureIoTClient | 69:b6f532f8c608 | 213 | size_t len = STRING_length(blobName); |
AzureIoTClient | 74:ea0021abecf7 | 214 | BUFFER_HANDLE blobBuffer = BUFFER_create((const unsigned char *)STRING_c_str(blobName), len); |
AzureIoTClient | 42:448eecc3676e | 215 | |
AzureIoTClient | 74:ea0021abecf7 | 216 | if (blobBuffer == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 217 | { |
AzureIoTClient | 74:ea0021abecf7 | 218 | /*Codes_SRS_IOTHUBCLIENT_LL_32_002: [ If creating the JSON string fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 69:b6f532f8c608 | 219 | LogError("unable to create BUFFER"); |
AzureIoTClient | 74:ea0021abecf7 | 220 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 221 | } |
AzureIoTClient | 74:ea0021abecf7 | 222 | else |
AzureIoTClient | 74:ea0021abecf7 | 223 | { |
AzureIoTClient | 74:ea0021abecf7 | 224 | /*Codes_SRS_IOTHUBCLIENT_LL_02_068: [ IoTHubClient_LL_UploadToBlob shall create an HTTP responseContent BUFFER_HANDLE. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 225 | BUFFER_HANDLE responseContent = BUFFER_new(); |
AzureIoTClient | 74:ea0021abecf7 | 226 | if (responseContent == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 227 | { |
AzureIoTClient | 74:ea0021abecf7 | 228 | /*Codes_SRS_IOTHUBCLIENT_LL_02_069: [ If creating the HTTP response buffer handle fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 229 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 230 | LogError("unable to BUFFER_new"); |
AzureIoTClient | 74:ea0021abecf7 | 231 | } |
AzureIoTClient | 74:ea0021abecf7 | 232 | else |
AzureIoTClient | 74:ea0021abecf7 | 233 | { |
AzureIoTClient | 74:ea0021abecf7 | 234 | /*Codes_SRS_IOTHUBCLIENT_LL_02_072: [ IoTHubClient_LL_UploadToBlob shall add the following name:value to request HTTP headers: ] "Content-Type": "application/json" "Accept": "application/json" "User-Agent": "iothubclient/" IOTHUB_SDK_VERSION*/ |
AzureIoTClient | 74:ea0021abecf7 | 235 | /*Codes_SRS_IOTHUBCLIENT_LL_02_107: [ - "Authorization" header shall not be build. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 236 | if (!( |
AzureIoTClient | 74:ea0021abecf7 | 237 | (HTTPHeaders_AddHeaderNameValuePair(requestHttpHeaders, "Content-Type", "application/json") == HTTP_HEADERS_OK) && |
AzureIoTClient | 74:ea0021abecf7 | 238 | (HTTPHeaders_AddHeaderNameValuePair(requestHttpHeaders, "Accept", "application/json") == HTTP_HEADERS_OK) && |
AzureIoTClient | 74:ea0021abecf7 | 239 | (HTTPHeaders_AddHeaderNameValuePair(requestHttpHeaders, "User-Agent", "iothubclient/" IOTHUB_SDK_VERSION) == HTTP_HEADERS_OK) && |
AzureIoTClient | 74:ea0021abecf7 | 240 | (handleData->authorizationScheme == X509 || (HTTPHeaders_AddHeaderNameValuePair(requestHttpHeaders, "Authorization", "") == HTTP_HEADERS_OK)) |
AzureIoTClient | 74:ea0021abecf7 | 241 | )) |
AzureIoTClient | 74:ea0021abecf7 | 242 | { |
AzureIoTClient | 74:ea0021abecf7 | 243 | /*Codes_SRS_IOTHUBCLIENT_LL_02_071: [ If creating the HTTP headers fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 244 | LogError("unable to HTTPHeaders_AddHeaderNameValuePair"); |
AzureIoTClient | 74:ea0021abecf7 | 245 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 246 | } |
AzureIoTClient | 74:ea0021abecf7 | 247 | else |
AzureIoTClient | 74:ea0021abecf7 | 248 | { |
AzureIoTClient | 74:ea0021abecf7 | 249 | int wasIoTHubRequestSuccess = 0; /*!=0 means responseContent has a buffer that should be parsed by parson after executing the below switch*/ |
AzureIoTClient | 74:ea0021abecf7 | 250 | /* set the result to error by default */ |
AzureIoTClient | 74:ea0021abecf7 | 251 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 252 | switch (handleData->authorizationScheme) |
AzureIoTClient | 74:ea0021abecf7 | 253 | { |
AzureIoTClient | 74:ea0021abecf7 | 254 | default: |
AzureIoTClient | 74:ea0021abecf7 | 255 | { |
AzureIoTClient | 74:ea0021abecf7 | 256 | /*wasIoTHubRequestSuccess takes care of the return value*/ |
AzureIoTClient | 74:ea0021abecf7 | 257 | LogError("Internal Error: unexpected value in handleData->authorizationScheme = %d", handleData->authorizationScheme); |
AzureIoTClient | 74:ea0021abecf7 | 258 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 259 | break; |
AzureIoTClient | 74:ea0021abecf7 | 260 | } |
AzureIoTClient | 74:ea0021abecf7 | 261 | case(X509): |
AzureIoTClient | 74:ea0021abecf7 | 262 | { |
AzureIoTClient | 74:ea0021abecf7 | 263 | unsigned int statusCode; |
AzureIoTClient | 74:ea0021abecf7 | 264 | /*Codes_SRS_IOTHUBCLIENT_LL_32_003: [ IoTHubClient_LL_UploadToBlob shall execute HTTPAPIEX_ExecuteRequest passing the following information for arguments: ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 265 | if (HTTPAPIEX_ExecuteRequest( |
AzureIoTClient | 74:ea0021abecf7 | 266 | iotHubHttpApiExHandle, /*HTTPAPIEX_HANDLE handle - the handle created at the beginning of `IoTHubClient_LL_UploadToBlob`*/ |
AzureIoTClient | 74:ea0021abecf7 | 267 | HTTPAPI_REQUEST_POST, /*HTTPAPI_REQUEST_TYPE requestType - HTTPAPI_REQUEST_POST*/ |
AzureIoTClient | 74:ea0021abecf7 | 268 | STRING_c_str(relativePath), /*const char* relativePath - the HTTP relative path*/ |
AzureIoTClient | 74:ea0021abecf7 | 269 | requestHttpHeaders, /*HTTP_HEADERS_HANDLE requestHttpHeadersHandle - request HTTP headers*/ |
AzureIoTClient | 74:ea0021abecf7 | 270 | blobBuffer, /*BUFFER_HANDLE requestContent - address of JSON with optional/directory/tree/filename*/ |
AzureIoTClient | 74:ea0021abecf7 | 271 | &statusCode, /*unsigned int* statusCode - the address of an unsigned int that will contain the HTTP status code*/ |
AzureIoTClient | 74:ea0021abecf7 | 272 | NULL, /*HTTP_HEADERS_HANDLE responseHttpHeadersHandle - NULL*/ |
AzureIoTClient | 74:ea0021abecf7 | 273 | responseContent /*BUFFER_HANDLE responseContent - the HTTP response BUFFER_HANDLE - responseContent*/ |
AzureIoTClient | 74:ea0021abecf7 | 274 | ) != HTTPAPIEX_OK) |
AzureIoTClient | 74:ea0021abecf7 | 275 | { |
AzureIoTClient | 74:ea0021abecf7 | 276 | /*Codes_SRS_IOTHUBCLIENT_LL_02_076: [ If HTTPAPIEX_ExecuteRequest call fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 277 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 278 | LogError("unable to HTTPAPIEX_ExecuteRequest"); |
AzureIoTClient | 74:ea0021abecf7 | 279 | } |
AzureIoTClient | 74:ea0021abecf7 | 280 | else |
AzureIoTClient | 74:ea0021abecf7 | 281 | { |
AzureIoTClient | 74:ea0021abecf7 | 282 | /*Codes_SRS_IOTHUBCLIENT_LL_02_077: [ If HTTP statusCode is greater than or equal to 300 then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 283 | if (statusCode >= 300) |
AzureIoTClient | 74:ea0021abecf7 | 284 | { |
AzureIoTClient | 74:ea0021abecf7 | 285 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 286 | LogError("HTTP code was %u", statusCode); |
AzureIoTClient | 74:ea0021abecf7 | 287 | } |
AzureIoTClient | 74:ea0021abecf7 | 288 | else |
AzureIoTClient | 74:ea0021abecf7 | 289 | { |
AzureIoTClient | 74:ea0021abecf7 | 290 | wasIoTHubRequestSuccess = 1; |
AzureIoTClient | 74:ea0021abecf7 | 291 | } |
AzureIoTClient | 74:ea0021abecf7 | 292 | } |
AzureIoTClient | 74:ea0021abecf7 | 293 | break; |
AzureIoTClient | 74:ea0021abecf7 | 294 | } |
AzureIoTClient | 74:ea0021abecf7 | 295 | case (SAS_TOKEN): |
AzureIoTClient | 74:ea0021abecf7 | 296 | { |
AzureIoTClient | 74:ea0021abecf7 | 297 | const char* sasToken = STRING_c_str(handleData->credentials.sas); |
AzureIoTClient | 74:ea0021abecf7 | 298 | /*Codes_SRS_IOTHUBCLIENT_LL_02_073: [ If the credentials used to create handle have "sasToken" then IoTHubClient_LL_UploadToBlob shall add the following HTTP request headers: ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 299 | if (HTTPHeaders_ReplaceHeaderNameValuePair(requestHttpHeaders, "Authorization", sasToken) != HTTP_HEADERS_OK) |
AzureIoTClient | 74:ea0021abecf7 | 300 | { |
AzureIoTClient | 74:ea0021abecf7 | 301 | /*Codes_SRS_IOTHUBCLIENT_LL_02_074: [ If adding "Authorization" fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 302 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 303 | LogError("unable to HTTPHeaders_AddHeaderNameValuePair"); |
AzureIoTClient | 74:ea0021abecf7 | 304 | } |
AzureIoTClient | 74:ea0021abecf7 | 305 | else |
AzureIoTClient | 74:ea0021abecf7 | 306 | { |
AzureIoTClient | 74:ea0021abecf7 | 307 | unsigned int statusCode; |
AzureIoTClient | 74:ea0021abecf7 | 308 | /*Codes_SRS_IOTHUBCLIENT_LL_32_004: [ IoTHubClient_LL_UploadToBlob shall execute HTTPAPIEX_ExecuteRequest passing the following information for arguments: ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 309 | if (HTTPAPIEX_ExecuteRequest( |
AzureIoTClient | 74:ea0021abecf7 | 310 | iotHubHttpApiExHandle, /*HTTPAPIEX_HANDLE handle - the handle created at the beginning of `IoTHubClient_LL_UploadToBlob`*/ |
AzureIoTClient | 74:ea0021abecf7 | 311 | HTTPAPI_REQUEST_POST, /*HTTPAPI_REQUEST_TYPE requestType - HTTPAPI_REQUEST_POST*/ |
AzureIoTClient | 74:ea0021abecf7 | 312 | STRING_c_str(relativePath), /*const char* relativePath - the HTTP relative path*/ |
AzureIoTClient | 74:ea0021abecf7 | 313 | requestHttpHeaders, /*HTTP_HEADERS_HANDLE requestHttpHeadersHandle - request HTTP headers*/ |
AzureIoTClient | 74:ea0021abecf7 | 314 | blobBuffer, /*BUFFER_HANDLE requestContent - address of JSON with optional/directory/tree/filename*/ |
AzureIoTClient | 74:ea0021abecf7 | 315 | &statusCode, /*unsigned int* statusCode - the address of an unsigned int that will contain the HTTP status code*/ |
AzureIoTClient | 74:ea0021abecf7 | 316 | NULL, /*HTTP_HEADERS_HANDLE responseHttpHeadersHandle - NULL*/ |
AzureIoTClient | 74:ea0021abecf7 | 317 | responseContent /*BUFFER_HANDLE responseContent - the HTTP response BUFFER_HANDLE - responseContent*/ |
AzureIoTClient | 74:ea0021abecf7 | 318 | ) != HTTPAPIEX_OK) |
AzureIoTClient | 74:ea0021abecf7 | 319 | { |
AzureIoTClient | 74:ea0021abecf7 | 320 | /*Codes_SRS_IOTHUBCLIENT_LL_02_076: [ If HTTPAPIEX_ExecuteRequest call fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 321 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 322 | LogError("unable to HTTPAPIEX_ExecuteRequest"); |
AzureIoTClient | 74:ea0021abecf7 | 323 | } |
AzureIoTClient | 74:ea0021abecf7 | 324 | else |
AzureIoTClient | 74:ea0021abecf7 | 325 | { |
AzureIoTClient | 74:ea0021abecf7 | 326 | /*Codes_SRS_IOTHUBCLIENT_LL_02_077: [ If HTTP statusCode is greater than or equal to 300 then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 327 | if (statusCode >= 300) |
AzureIoTClient | 74:ea0021abecf7 | 328 | { |
AzureIoTClient | 74:ea0021abecf7 | 329 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 330 | LogError("HTTP code was %u", statusCode); |
AzureIoTClient | 74:ea0021abecf7 | 331 | } |
AzureIoTClient | 74:ea0021abecf7 | 332 | else |
AzureIoTClient | 74:ea0021abecf7 | 333 | { |
AzureIoTClient | 74:ea0021abecf7 | 334 | wasIoTHubRequestSuccess = 1; |
AzureIoTClient | 74:ea0021abecf7 | 335 | } |
AzureIoTClient | 74:ea0021abecf7 | 336 | } |
AzureIoTClient | 74:ea0021abecf7 | 337 | } |
AzureIoTClient | 74:ea0021abecf7 | 338 | break; |
AzureIoTClient | 74:ea0021abecf7 | 339 | } |
AzureIoTClient | 74:ea0021abecf7 | 340 | case(DEVICE_KEY): |
AzureIoTClient | 74:ea0021abecf7 | 341 | { |
AzureIoTClient | 74:ea0021abecf7 | 342 | /*Codes_SRS_IOTHUBCLIENT_LL_02_078: [ If the credentials used to create handle have "deviceKey" then IoTHubClient_LL_UploadToBlob shall create an HTTPAPIEX_SAS_HANDLE passing as arguments: ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 343 | STRING_HANDLE uriResource = STRING_construct(handleData->hostname); |
AzureIoTClient | 74:ea0021abecf7 | 344 | if (uriResource == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 345 | { |
AzureIoTClient | 74:ea0021abecf7 | 346 | /*Codes_SRS_IOTHUBCLIENT_LL_02_089: [ If creating the HTTPAPIEX_SAS_HANDLE fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 347 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 348 | LogError("unable to STRING_construct"); |
AzureIoTClient | 74:ea0021abecf7 | 349 | } |
AzureIoTClient | 74:ea0021abecf7 | 350 | else |
AzureIoTClient | 74:ea0021abecf7 | 351 | { |
AzureIoTClient | 74:ea0021abecf7 | 352 | if (!( |
AzureIoTClient | 74:ea0021abecf7 | 353 | (STRING_concat(uriResource, "/devices/") == 0) && |
AzureIoTClient | 74:ea0021abecf7 | 354 | (STRING_concat_with_STRING(uriResource, handleData->deviceId) == 0) |
AzureIoTClient | 74:ea0021abecf7 | 355 | )) |
AzureIoTClient | 74:ea0021abecf7 | 356 | { |
AzureIoTClient | 74:ea0021abecf7 | 357 | /*Codes_SRS_IOTHUBCLIENT_LL_02_089: [ If creating the HTTPAPIEX_SAS_HANDLE fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 358 | LogError("unable to STRING_concat_with_STRING"); |
AzureIoTClient | 74:ea0021abecf7 | 359 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 360 | } |
AzureIoTClient | 74:ea0021abecf7 | 361 | else |
AzureIoTClient | 74:ea0021abecf7 | 362 | { |
AzureIoTClient | 74:ea0021abecf7 | 363 | STRING_HANDLE empty = STRING_new(); |
AzureIoTClient | 74:ea0021abecf7 | 364 | if (empty == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 365 | { |
AzureIoTClient | 74:ea0021abecf7 | 366 | LogError("unable to STRING_new"); |
AzureIoTClient | 74:ea0021abecf7 | 367 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 368 | } |
AzureIoTClient | 74:ea0021abecf7 | 369 | else |
AzureIoTClient | 74:ea0021abecf7 | 370 | { |
AzureIoTClient | 74:ea0021abecf7 | 371 | /*Codes_SRS_IOTHUBCLIENT_LL_02_089: [ If creating the HTTPAPIEX_SAS_HANDLE fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 372 | HTTPAPIEX_SAS_HANDLE sasHandle = HTTPAPIEX_SAS_Create(handleData->credentials.deviceKey, uriResource, empty); |
AzureIoTClient | 74:ea0021abecf7 | 373 | if (sasHandle == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 374 | { |
AzureIoTClient | 74:ea0021abecf7 | 375 | LogError("unable to HTTPAPIEX_SAS_Create"); |
AzureIoTClient | 74:ea0021abecf7 | 376 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 377 | } |
AzureIoTClient | 74:ea0021abecf7 | 378 | else |
AzureIoTClient | 74:ea0021abecf7 | 379 | { |
AzureIoTClient | 74:ea0021abecf7 | 380 | unsigned int statusCode; |
AzureIoTClient | 74:ea0021abecf7 | 381 | /*Codes_SRS_IOTHUBCLIENT_LL_32_005: [ IoTHubClient_LL_UploadToBlob shall call HTTPAPIEX_SAS_ExecuteRequest passing as arguments: ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 382 | if (HTTPAPIEX_SAS_ExecuteRequest( |
AzureIoTClient | 74:ea0021abecf7 | 383 | sasHandle, /*HTTPAPIEX_SAS_HANDLE sasHandle - the created HTTPAPIEX_SAS_HANDLE*/ |
AzureIoTClient | 74:ea0021abecf7 | 384 | iotHubHttpApiExHandle, /*HTTPAPIEX_HANDLE handle - the created HTTPAPIEX_HANDLE*/ |
AzureIoTClient | 74:ea0021abecf7 | 385 | HTTPAPI_REQUEST_POST, /*HTTPAPI_REQUEST_TYPE requestType - HTTPAPI_REQUEST_POST*/ |
AzureIoTClient | 74:ea0021abecf7 | 386 | STRING_c_str(relativePath), /*const char* relativePath - the HTTP relative path*/ |
AzureIoTClient | 74:ea0021abecf7 | 387 | requestHttpHeaders, /*HTTP_HEADERS_HANDLE requestHttpHeadersHandle - request HTTP headers*/ |
AzureIoTClient | 74:ea0021abecf7 | 388 | blobBuffer, /*BUFFER_HANDLE requestContent - address of JSON with optional/directory/tree/filename*/ |
AzureIoTClient | 74:ea0021abecf7 | 389 | &statusCode, /*unsigned int* statusCode - the address of an unsigned int that will contain the HTTP status code*/ |
AzureIoTClient | 74:ea0021abecf7 | 390 | NULL, /*HTTP_HEADERS_HANDLE responseHeadersHandle - NULL*/ |
AzureIoTClient | 74:ea0021abecf7 | 391 | responseContent |
AzureIoTClient | 74:ea0021abecf7 | 392 | ) != HTTPAPIEX_OK) |
AzureIoTClient | 74:ea0021abecf7 | 393 | { |
AzureIoTClient | 74:ea0021abecf7 | 394 | /*Codes_SRS_IOTHUBCLIENT_LL_02_079: [ If HTTPAPIEX_SAS_ExecuteRequest fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 395 | LogError("unable to HTTPAPIEX_SAS_ExecuteRequest"); |
AzureIoTClient | 74:ea0021abecf7 | 396 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 397 | } |
AzureIoTClient | 74:ea0021abecf7 | 398 | else |
AzureIoTClient | 74:ea0021abecf7 | 399 | { |
AzureIoTClient | 74:ea0021abecf7 | 400 | if (statusCode >= 300) |
AzureIoTClient | 74:ea0021abecf7 | 401 | { |
AzureIoTClient | 74:ea0021abecf7 | 402 | /*Codes_SRS_IOTHUBCLIENT_LL_02_080: [ If status code is greater than or equal to 300 then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 403 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 404 | LogError("HTTP code was %u", statusCode); |
AzureIoTClient | 74:ea0021abecf7 | 405 | } |
AzureIoTClient | 74:ea0021abecf7 | 406 | else |
AzureIoTClient | 74:ea0021abecf7 | 407 | { |
AzureIoTClient | 74:ea0021abecf7 | 408 | wasIoTHubRequestSuccess = 1; |
AzureIoTClient | 74:ea0021abecf7 | 409 | } |
AzureIoTClient | 74:ea0021abecf7 | 410 | } |
AzureIoTClient | 74:ea0021abecf7 | 411 | HTTPAPIEX_SAS_Destroy(sasHandle); |
AzureIoTClient | 74:ea0021abecf7 | 412 | } |
AzureIoTClient | 74:ea0021abecf7 | 413 | STRING_delete(empty); |
AzureIoTClient | 74:ea0021abecf7 | 414 | } |
AzureIoTClient | 74:ea0021abecf7 | 415 | } |
AzureIoTClient | 74:ea0021abecf7 | 416 | STRING_delete(uriResource); |
AzureIoTClient | 74:ea0021abecf7 | 417 | } |
AzureIoTClient | 74:ea0021abecf7 | 418 | } |
AzureIoTClient | 74:ea0021abecf7 | 419 | } /*switch*/ |
AzureIoTClient | 42:448eecc3676e | 420 | |
AzureIoTClient | 74:ea0021abecf7 | 421 | if (wasIoTHubRequestSuccess == 0) |
AzureIoTClient | 74:ea0021abecf7 | 422 | { |
AzureIoTClient | 74:ea0021abecf7 | 423 | /*do nothing, shall be reported as an error*/ |
AzureIoTClient | 74:ea0021abecf7 | 424 | } |
AzureIoTClient | 74:ea0021abecf7 | 425 | else |
AzureIoTClient | 74:ea0021abecf7 | 426 | { |
AzureIoTClient | 74:ea0021abecf7 | 427 | const unsigned char*responseContent_u_char = BUFFER_u_char(responseContent); |
AzureIoTClient | 74:ea0021abecf7 | 428 | size_t responseContent_length = BUFFER_length(responseContent); |
AzureIoTClient | 74:ea0021abecf7 | 429 | STRING_HANDLE responseAsString = STRING_from_byte_array(responseContent_u_char, responseContent_length); |
AzureIoTClient | 74:ea0021abecf7 | 430 | if (responseAsString == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 431 | { |
AzureIoTClient | 74:ea0021abecf7 | 432 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 433 | LogError("unable to get the response as string"); |
AzureIoTClient | 74:ea0021abecf7 | 434 | } |
AzureIoTClient | 74:ea0021abecf7 | 435 | else |
AzureIoTClient | 74:ea0021abecf7 | 436 | { |
AzureIoTClient | 74:ea0021abecf7 | 437 | /*Codes_SRS_IOTHUBCLIENT_LL_02_081: [ Otherwise, IoTHubClient_LL_UploadToBlob shall use parson to extract and save the following information from the response buffer: correlationID and SasUri. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 438 | JSON_Value* allJson = json_parse_string(STRING_c_str(responseAsString)); |
AzureIoTClient | 74:ea0021abecf7 | 439 | if (allJson == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 440 | { |
AzureIoTClient | 74:ea0021abecf7 | 441 | /*Codes_SRS_IOTHUBCLIENT_LL_02_082: [ If extracting and saving the correlationId or SasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 442 | LogError("unable to json_parse_string"); |
AzureIoTClient | 74:ea0021abecf7 | 443 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 444 | } |
AzureIoTClient | 74:ea0021abecf7 | 445 | else |
AzureIoTClient | 74:ea0021abecf7 | 446 | { |
AzureIoTClient | 74:ea0021abecf7 | 447 | JSON_Object* jsonObject = json_value_get_object(allJson); |
AzureIoTClient | 74:ea0021abecf7 | 448 | if (jsonObject == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 449 | { |
AzureIoTClient | 74:ea0021abecf7 | 450 | /*Codes_SRS_IOTHUBCLIENT_LL_02_082: [ If extracting and saving the correlationId or SasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 451 | LogError("unable to json_value_get_object"); |
AzureIoTClient | 74:ea0021abecf7 | 452 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 453 | } |
AzureIoTClient | 74:ea0021abecf7 | 454 | else |
AzureIoTClient | 74:ea0021abecf7 | 455 | { |
AzureIoTClient | 74:ea0021abecf7 | 456 | const char* json_correlationId; |
AzureIoTClient | 74:ea0021abecf7 | 457 | json_correlationId = json_object_get_string(jsonObject, "correlationId"); |
AzureIoTClient | 74:ea0021abecf7 | 458 | if (json_correlationId == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 459 | { |
AzureIoTClient | 74:ea0021abecf7 | 460 | /*Codes_SRS_IOTHUBCLIENT_LL_02_082: [ If extracting and saving the correlationId or SasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 461 | LogError("unable to json_object_get_string(jsonObject, \"correlationId\")"); |
AzureIoTClient | 74:ea0021abecf7 | 462 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 463 | } |
AzureIoTClient | 74:ea0021abecf7 | 464 | else |
AzureIoTClient | 74:ea0021abecf7 | 465 | { |
AzureIoTClient | 74:ea0021abecf7 | 466 | if (STRING_copy(correlationId, json_correlationId) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 467 | { |
AzureIoTClient | 74:ea0021abecf7 | 468 | /*Codes_SRS_IOTHUBCLIENT_LL_02_082: [ If extracting and saving the correlationId or SasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 469 | LogError("unable to copy json_correlationId"); |
AzureIoTClient | 74:ea0021abecf7 | 470 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 471 | } |
AzureIoTClient | 74:ea0021abecf7 | 472 | else |
AzureIoTClient | 74:ea0021abecf7 | 473 | { |
AzureIoTClient | 74:ea0021abecf7 | 474 | const char* json_hostName = json_object_get_string(jsonObject, "hostName"); |
AzureIoTClient | 74:ea0021abecf7 | 475 | if (json_hostName == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 476 | { |
AzureIoTClient | 74:ea0021abecf7 | 477 | /*Codes_SRS_IOTHUBCLIENT_LL_02_082: [ If extracting and saving the correlationId or SasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 478 | LogError("unable to json_object_get_string(jsonObject, \"hostName\")"); |
AzureIoTClient | 74:ea0021abecf7 | 479 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 480 | } |
AzureIoTClient | 74:ea0021abecf7 | 481 | else |
AzureIoTClient | 74:ea0021abecf7 | 482 | { |
AzureIoTClient | 74:ea0021abecf7 | 483 | const char* json_containerName = json_object_get_string(jsonObject, "containerName"); |
AzureIoTClient | 74:ea0021abecf7 | 484 | if (json_containerName == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 485 | { |
AzureIoTClient | 74:ea0021abecf7 | 486 | /*Codes_SRS_IOTHUBCLIENT_LL_02_082: [ If extracting and saving the correlationId or SasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 487 | LogError("unable to json_object_get_string(jsonObject, \"containerName\")"); |
AzureIoTClient | 74:ea0021abecf7 | 488 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 489 | } |
AzureIoTClient | 74:ea0021abecf7 | 490 | else |
AzureIoTClient | 74:ea0021abecf7 | 491 | { |
AzureIoTClient | 74:ea0021abecf7 | 492 | const char* json_blobName = json_object_get_string(jsonObject, "blobName"); |
AzureIoTClient | 74:ea0021abecf7 | 493 | if (json_blobName == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 494 | { |
AzureIoTClient | 74:ea0021abecf7 | 495 | /*Codes_SRS_IOTHUBCLIENT_LL_02_082: [ If extracting and saving the correlationId or SasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 496 | LogError("unable to json_object_get_string(jsonObject, \"blobName\")"); |
AzureIoTClient | 74:ea0021abecf7 | 497 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 498 | } |
AzureIoTClient | 74:ea0021abecf7 | 499 | else |
AzureIoTClient | 74:ea0021abecf7 | 500 | { |
AzureIoTClient | 74:ea0021abecf7 | 501 | const char* json_sasToken = json_object_get_string(jsonObject, "sasToken"); |
AzureIoTClient | 74:ea0021abecf7 | 502 | if (json_sasToken == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 503 | { |
AzureIoTClient | 74:ea0021abecf7 | 504 | /*Codes_SRS_IOTHUBCLIENT_LL_02_082: [ If extracting and saving the correlationId or SasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 505 | LogError("unable to json_object_get_string(jsonObject, \"sasToken\")"); |
AzureIoTClient | 74:ea0021abecf7 | 506 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 507 | } |
AzureIoTClient | 74:ea0021abecf7 | 508 | else |
AzureIoTClient | 74:ea0021abecf7 | 509 | { |
AzureIoTClient | 74:ea0021abecf7 | 510 | /*good JSON received from the service*/ |
AzureIoTClient | 42:448eecc3676e | 511 | |
AzureIoTClient | 74:ea0021abecf7 | 512 | if (STRING_copy(sasUri, "https://") != 0) |
AzureIoTClient | 74:ea0021abecf7 | 513 | { |
AzureIoTClient | 74:ea0021abecf7 | 514 | /*Codes_SRS_IOTHUBCLIENT_LL_02_082: [ If extracting and saving the correlationId or SasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 515 | LogError("unable to STRING_copy"); |
AzureIoTClient | 74:ea0021abecf7 | 516 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 517 | } |
AzureIoTClient | 74:ea0021abecf7 | 518 | else |
AzureIoTClient | 74:ea0021abecf7 | 519 | { |
AzureIoTClient | 74:ea0021abecf7 | 520 | if (!( |
AzureIoTClient | 74:ea0021abecf7 | 521 | (STRING_concat(sasUri, json_hostName) == 0) && |
AzureIoTClient | 74:ea0021abecf7 | 522 | (STRING_concat(sasUri, "/") == 0) && |
AzureIoTClient | 74:ea0021abecf7 | 523 | (STRING_concat(sasUri, json_containerName) == 0) && |
AzureIoTClient | 74:ea0021abecf7 | 524 | (STRING_concat(sasUri, "/") == 0) && |
AzureIoTClient | 74:ea0021abecf7 | 525 | (STRING_concat(sasUri, json_blobName) == 0) && |
AzureIoTClient | 74:ea0021abecf7 | 526 | (STRING_concat(sasUri, json_sasToken) == 0) |
AzureIoTClient | 74:ea0021abecf7 | 527 | )) |
AzureIoTClient | 74:ea0021abecf7 | 528 | { |
AzureIoTClient | 74:ea0021abecf7 | 529 | /*Codes_SRS_IOTHUBCLIENT_LL_02_082: [ If extracting and saving the correlationId or SasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 530 | LogError("unable to STRING_concat"); |
AzureIoTClient | 74:ea0021abecf7 | 531 | result = __FAILURE__; |
AzureIoTClient | 74:ea0021abecf7 | 532 | } |
AzureIoTClient | 74:ea0021abecf7 | 533 | else |
AzureIoTClient | 74:ea0021abecf7 | 534 | { |
AzureIoTClient | 74:ea0021abecf7 | 535 | result = 0; /*success in step 1*/ |
AzureIoTClient | 74:ea0021abecf7 | 536 | } |
AzureIoTClient | 74:ea0021abecf7 | 537 | } |
AzureIoTClient | 74:ea0021abecf7 | 538 | } |
AzureIoTClient | 74:ea0021abecf7 | 539 | } |
AzureIoTClient | 74:ea0021abecf7 | 540 | } |
AzureIoTClient | 74:ea0021abecf7 | 541 | } |
AzureIoTClient | 74:ea0021abecf7 | 542 | } |
AzureIoTClient | 74:ea0021abecf7 | 543 | } |
AzureIoTClient | 74:ea0021abecf7 | 544 | } |
AzureIoTClient | 74:ea0021abecf7 | 545 | json_value_free(allJson); |
AzureIoTClient | 74:ea0021abecf7 | 546 | } |
AzureIoTClient | 74:ea0021abecf7 | 547 | STRING_delete(responseAsString); |
AzureIoTClient | 74:ea0021abecf7 | 548 | } |
AzureIoTClient | 74:ea0021abecf7 | 549 | } |
AzureIoTClient | 74:ea0021abecf7 | 550 | } |
AzureIoTClient | 74:ea0021abecf7 | 551 | BUFFER_delete(responseContent); |
AzureIoTClient | 74:ea0021abecf7 | 552 | } |
AzureIoTClient | 69:b6f532f8c608 | 553 | BUFFER_delete(blobBuffer); |
AzureIoTClient | 74:ea0021abecf7 | 554 | } |
AzureIoTClient | 74:ea0021abecf7 | 555 | } |
AzureIoTClient | 74:ea0021abecf7 | 556 | STRING_delete(blobName); |
AzureIoTClient | 74:ea0021abecf7 | 557 | } |
AzureIoTClient | 74:ea0021abecf7 | 558 | } |
AzureIoTClient | 74:ea0021abecf7 | 559 | STRING_delete(relativePath); |
AzureIoTClient | 74:ea0021abecf7 | 560 | } |
AzureIoTClient | 42:448eecc3676e | 561 | return result; |
AzureIoTClient | 42:448eecc3676e | 562 | } |
AzureIoTClient | 42:448eecc3676e | 563 | |
AzureIoTClient | 42:448eecc3676e | 564 | /*returns 0 when the IoTHub has been informed about the file upload status*/ |
AzureIoTClient | 42:448eecc3676e | 565 | static int IoTHubClient_LL_UploadToBlob_step3(IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* handleData, STRING_HANDLE correlationId, HTTPAPIEX_HANDLE iotHubHttpApiExHandle, HTTP_HEADERS_HANDLE requestHttpHeaders, BUFFER_HANDLE messageBody) |
AzureIoTClient | 42:448eecc3676e | 566 | { |
AzureIoTClient | 42:448eecc3676e | 567 | int result; |
AzureIoTClient | 42:448eecc3676e | 568 | /*here is step 3. depending on the outcome of step 2 it needs to inform IoTHub about the file upload status*/ |
AzureIoTClient | 42:448eecc3676e | 569 | /*if step 1 failed, there's nothing that step 3 needs to report.*/ |
AzureIoTClient | 42:448eecc3676e | 570 | /*this POST "tries" to happen*/ |
AzureIoTClient | 42:448eecc3676e | 571 | |
AzureIoTClient | 42:448eecc3676e | 572 | /*Codes_SRS_IOTHUBCLIENT_LL_02_085: [ IoTHubClient_LL_UploadToBlob shall use the same authorization as step 1. to prepare and perform a HTTP request with the following parameters: ]*/ |
AzureIoTClient | 42:448eecc3676e | 573 | STRING_HANDLE uriResource = STRING_construct(handleData->hostname); |
AzureIoTClient | 42:448eecc3676e | 574 | if (uriResource == NULL) |
AzureIoTClient | 42:448eecc3676e | 575 | { |
AzureIoTClient | 42:448eecc3676e | 576 | LogError("unable to construct URI"); |
AzureIoTClient | 60:41648c4e7036 | 577 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 578 | } |
AzureIoTClient | 42:448eecc3676e | 579 | else |
AzureIoTClient | 42:448eecc3676e | 580 | { |
AzureIoTClient | 42:448eecc3676e | 581 | if (!( |
AzureIoTClient | 42:448eecc3676e | 582 | (STRING_concat(uriResource, "/devices/") == 0) && |
AzureIoTClient | 42:448eecc3676e | 583 | (STRING_concat_with_STRING(uriResource, handleData->deviceId) == 0) && |
AzureIoTClient | 42:448eecc3676e | 584 | (STRING_concat(uriResource, "/files/notifications") == 0) |
AzureIoTClient | 42:448eecc3676e | 585 | )) |
AzureIoTClient | 42:448eecc3676e | 586 | { |
AzureIoTClient | 42:448eecc3676e | 587 | LogError("unable to STRING_concat"); |
AzureIoTClient | 60:41648c4e7036 | 588 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 589 | } |
AzureIoTClient | 42:448eecc3676e | 590 | else |
AzureIoTClient | 42:448eecc3676e | 591 | { |
AzureIoTClient | 42:448eecc3676e | 592 | STRING_HANDLE relativePathNotification = STRING_construct("/devices/"); |
AzureIoTClient | 42:448eecc3676e | 593 | if (relativePathNotification == NULL) |
AzureIoTClient | 42:448eecc3676e | 594 | { |
AzureIoTClient | 60:41648c4e7036 | 595 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 596 | LogError("unable to STRING_construct"); |
AzureIoTClient | 42:448eecc3676e | 597 | } |
AzureIoTClient | 42:448eecc3676e | 598 | else |
AzureIoTClient | 42:448eecc3676e | 599 | { |
AzureIoTClient | 42:448eecc3676e | 600 | if (!( |
AzureIoTClient | 42:448eecc3676e | 601 | (STRING_concat_with_STRING(relativePathNotification, handleData->deviceId) == 0) && |
AzureIoTClient | 42:448eecc3676e | 602 | (STRING_concat(relativePathNotification, "/files/notifications/") == 0) && |
AzureIoTClient | 42:448eecc3676e | 603 | (STRING_concat(relativePathNotification, STRING_c_str(correlationId)) == 0) && |
AzureIoTClient | 42:448eecc3676e | 604 | (STRING_concat(relativePathNotification, API_VERSION) == 0) |
AzureIoTClient | 42:448eecc3676e | 605 | )) |
AzureIoTClient | 42:448eecc3676e | 606 | { |
AzureIoTClient | 42:448eecc3676e | 607 | LogError("unable to STRING_concat_with_STRING"); |
AzureIoTClient | 60:41648c4e7036 | 608 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 609 | } |
AzureIoTClient | 42:448eecc3676e | 610 | else |
AzureIoTClient | 42:448eecc3676e | 611 | { |
AzureIoTClient | 42:448eecc3676e | 612 | /*Codes_SRS_IOTHUBCLIENT_LL_02_086: [ If performing the HTTP request fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 42:448eecc3676e | 613 | switch (handleData->authorizationScheme) |
AzureIoTClient | 42:448eecc3676e | 614 | { |
AzureIoTClient | 42:448eecc3676e | 615 | default: |
AzureIoTClient | 42:448eecc3676e | 616 | { |
AzureIoTClient | 42:448eecc3676e | 617 | LogError("internal error: unknown authorization Scheme"); |
AzureIoTClient | 60:41648c4e7036 | 618 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 619 | break; |
AzureIoTClient | 42:448eecc3676e | 620 | } |
AzureIoTClient | 46:6a69294b6119 | 621 | case (X509): |
AzureIoTClient | 46:6a69294b6119 | 622 | { |
AzureIoTClient | 46:6a69294b6119 | 623 | unsigned int notificationStatusCode; |
AzureIoTClient | 46:6a69294b6119 | 624 | if (HTTPAPIEX_ExecuteRequest( |
AzureIoTClient | 46:6a69294b6119 | 625 | iotHubHttpApiExHandle, |
AzureIoTClient | 46:6a69294b6119 | 626 | HTTPAPI_REQUEST_POST, |
AzureIoTClient | 46:6a69294b6119 | 627 | STRING_c_str(relativePathNotification), |
AzureIoTClient | 46:6a69294b6119 | 628 | requestHttpHeaders, |
AzureIoTClient | 46:6a69294b6119 | 629 | messageBody, |
AzureIoTClient | 46:6a69294b6119 | 630 | ¬ificationStatusCode, |
AzureIoTClient | 46:6a69294b6119 | 631 | NULL, |
AzureIoTClient | 46:6a69294b6119 | 632 | NULL) != HTTPAPIEX_OK) |
AzureIoTClient | 46:6a69294b6119 | 633 | { |
AzureIoTClient | 46:6a69294b6119 | 634 | LogError("unable to do HTTPAPIEX_ExecuteRequest"); |
AzureIoTClient | 60:41648c4e7036 | 635 | result = __FAILURE__; |
AzureIoTClient | 46:6a69294b6119 | 636 | } |
AzureIoTClient | 46:6a69294b6119 | 637 | else |
AzureIoTClient | 46:6a69294b6119 | 638 | { |
AzureIoTClient | 46:6a69294b6119 | 639 | if (notificationStatusCode >= 300) |
AzureIoTClient | 46:6a69294b6119 | 640 | { |
AzureIoTClient | 46:6a69294b6119 | 641 | /*Codes_SRS_IOTHUBCLIENT_LL_02_087: [If the statusCode of the HTTP request is greater than or equal to 300 then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR]*/ |
AzureIoTClient | 46:6a69294b6119 | 642 | LogError("server didn't like the notification request"); |
AzureIoTClient | 60:41648c4e7036 | 643 | result = __FAILURE__; |
AzureIoTClient | 46:6a69294b6119 | 644 | } |
AzureIoTClient | 46:6a69294b6119 | 645 | else |
AzureIoTClient | 46:6a69294b6119 | 646 | { |
AzureIoTClient | 46:6a69294b6119 | 647 | result = 0; |
AzureIoTClient | 46:6a69294b6119 | 648 | } |
AzureIoTClient | 46:6a69294b6119 | 649 | } |
AzureIoTClient | 46:6a69294b6119 | 650 | break; |
AzureIoTClient | 46:6a69294b6119 | 651 | } |
AzureIoTClient | 42:448eecc3676e | 652 | case (DEVICE_KEY): |
AzureIoTClient | 42:448eecc3676e | 653 | { |
AzureIoTClient | 42:448eecc3676e | 654 | STRING_HANDLE empty = STRING_new(); |
AzureIoTClient | 42:448eecc3676e | 655 | if (empty == NULL) |
AzureIoTClient | 42:448eecc3676e | 656 | { |
AzureIoTClient | 42:448eecc3676e | 657 | LogError("unable to STRING_new"); |
AzureIoTClient | 60:41648c4e7036 | 658 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 659 | } |
AzureIoTClient | 42:448eecc3676e | 660 | else |
AzureIoTClient | 42:448eecc3676e | 661 | { |
AzureIoTClient | 42:448eecc3676e | 662 | HTTPAPIEX_SAS_HANDLE sasHandle = HTTPAPIEX_SAS_Create(handleData->credentials.deviceKey, uriResource, empty); |
AzureIoTClient | 42:448eecc3676e | 663 | if (sasHandle == NULL) |
AzureIoTClient | 42:448eecc3676e | 664 | { |
AzureIoTClient | 42:448eecc3676e | 665 | LogError("unable to HTTPAPIEX_SAS_Create"); |
AzureIoTClient | 60:41648c4e7036 | 666 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 667 | } |
AzureIoTClient | 42:448eecc3676e | 668 | else |
AzureIoTClient | 42:448eecc3676e | 669 | { |
AzureIoTClient | 42:448eecc3676e | 670 | unsigned int statusCode; |
AzureIoTClient | 42:448eecc3676e | 671 | if (HTTPAPIEX_SAS_ExecuteRequest( |
AzureIoTClient | 42:448eecc3676e | 672 | sasHandle, /*HTTPAPIEX_SAS_HANDLE sasHandle - the created HTTPAPIEX_SAS_HANDLE*/ |
AzureIoTClient | 42:448eecc3676e | 673 | iotHubHttpApiExHandle, /*HTTPAPIEX_HANDLE handle - the created HTTPAPIEX_HANDLE*/ |
AzureIoTClient | 42:448eecc3676e | 674 | HTTPAPI_REQUEST_POST, /*HTTPAPI_REQUEST_TYPE requestType - HTTPAPI_REQUEST_GET*/ |
AzureIoTClient | 42:448eecc3676e | 675 | STRING_c_str(relativePathNotification), /*const char* relativePath - the HTTP relative path*/ |
AzureIoTClient | 42:448eecc3676e | 676 | requestHttpHeaders, /*HTTP_HEADERS_HANDLE requestHttpHeadersHandle - request HTTP headers*/ |
AzureIoTClient | 42:448eecc3676e | 677 | messageBody, /*BUFFER_HANDLE requestContent*/ |
AzureIoTClient | 42:448eecc3676e | 678 | &statusCode, /*unsigned int* statusCode - the address of an unsigned int that will contain the HTTP status code*/ |
AzureIoTClient | 42:448eecc3676e | 679 | NULL, /*HTTP_HEADERS_HANDLE responseHeadersHandle - NULL*/ |
AzureIoTClient | 42:448eecc3676e | 680 | NULL |
AzureIoTClient | 42:448eecc3676e | 681 | ) != HTTPAPIEX_OK) |
AzureIoTClient | 42:448eecc3676e | 682 | { |
AzureIoTClient | 42:448eecc3676e | 683 | /*Codes_SRS_IOTHUBCLIENT_LL_02_079: [ If HTTPAPIEX_SAS_ExecuteRequest fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 42:448eecc3676e | 684 | LogError("unable to HTTPAPIEX_SAS_ExecuteRequest"); |
AzureIoTClient | 60:41648c4e7036 | 685 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 686 | ; |
AzureIoTClient | 42:448eecc3676e | 687 | } |
AzureIoTClient | 42:448eecc3676e | 688 | else |
AzureIoTClient | 42:448eecc3676e | 689 | { |
AzureIoTClient | 42:448eecc3676e | 690 | if (statusCode >= 300) |
AzureIoTClient | 42:448eecc3676e | 691 | { |
AzureIoTClient | 42:448eecc3676e | 692 | /*Codes_SRS_IOTHUBCLIENT_LL_02_087: [If the statusCode of the HTTP request is greater than or equal to 300 then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR]*/ |
AzureIoTClient | 60:41648c4e7036 | 693 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 694 | LogError("HTTP code was %u", statusCode); |
AzureIoTClient | 42:448eecc3676e | 695 | } |
AzureIoTClient | 42:448eecc3676e | 696 | else |
AzureIoTClient | 42:448eecc3676e | 697 | { |
AzureIoTClient | 42:448eecc3676e | 698 | result = 0; |
AzureIoTClient | 42:448eecc3676e | 699 | } |
AzureIoTClient | 42:448eecc3676e | 700 | } |
AzureIoTClient | 42:448eecc3676e | 701 | HTTPAPIEX_SAS_Destroy(sasHandle); |
AzureIoTClient | 42:448eecc3676e | 702 | } |
AzureIoTClient | 42:448eecc3676e | 703 | STRING_delete(empty); |
AzureIoTClient | 42:448eecc3676e | 704 | } |
AzureIoTClient | 42:448eecc3676e | 705 | break; |
AzureIoTClient | 42:448eecc3676e | 706 | } |
AzureIoTClient | 42:448eecc3676e | 707 | case(SAS_TOKEN): |
AzureIoTClient | 42:448eecc3676e | 708 | { |
AzureIoTClient | 42:448eecc3676e | 709 | unsigned int notificationStatusCode; |
AzureIoTClient | 42:448eecc3676e | 710 | if (HTTPAPIEX_ExecuteRequest( |
AzureIoTClient | 42:448eecc3676e | 711 | iotHubHttpApiExHandle, |
AzureIoTClient | 42:448eecc3676e | 712 | HTTPAPI_REQUEST_POST, |
AzureIoTClient | 42:448eecc3676e | 713 | STRING_c_str(relativePathNotification), |
AzureIoTClient | 42:448eecc3676e | 714 | requestHttpHeaders, |
AzureIoTClient | 42:448eecc3676e | 715 | messageBody, |
AzureIoTClient | 42:448eecc3676e | 716 | ¬ificationStatusCode, |
AzureIoTClient | 42:448eecc3676e | 717 | NULL, |
AzureIoTClient | 42:448eecc3676e | 718 | NULL) != HTTPAPIEX_OK) |
AzureIoTClient | 42:448eecc3676e | 719 | { |
AzureIoTClient | 42:448eecc3676e | 720 | LogError("unable to do HTTPAPIEX_ExecuteRequest"); |
AzureIoTClient | 60:41648c4e7036 | 721 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 722 | } |
AzureIoTClient | 42:448eecc3676e | 723 | else |
AzureIoTClient | 42:448eecc3676e | 724 | { |
AzureIoTClient | 42:448eecc3676e | 725 | if (notificationStatusCode >= 300) |
AzureIoTClient | 42:448eecc3676e | 726 | { |
AzureIoTClient | 42:448eecc3676e | 727 | /*Codes_SRS_IOTHUBCLIENT_LL_02_087: [If the statusCode of the HTTP request is greater than or equal to 300 then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR]*/ |
AzureIoTClient | 42:448eecc3676e | 728 | LogError("server didn't like the notification request"); |
AzureIoTClient | 60:41648c4e7036 | 729 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 730 | } |
AzureIoTClient | 42:448eecc3676e | 731 | else |
AzureIoTClient | 42:448eecc3676e | 732 | { |
AzureIoTClient | 42:448eecc3676e | 733 | result = 0; |
AzureIoTClient | 42:448eecc3676e | 734 | } |
AzureIoTClient | 42:448eecc3676e | 735 | } |
AzureIoTClient | 42:448eecc3676e | 736 | break; |
AzureIoTClient | 42:448eecc3676e | 737 | } |
AzureIoTClient | 42:448eecc3676e | 738 | } /*switch authorizationScheme*/ |
AzureIoTClient | 42:448eecc3676e | 739 | } |
AzureIoTClient | 42:448eecc3676e | 740 | STRING_delete(relativePathNotification); |
AzureIoTClient | 42:448eecc3676e | 741 | } |
AzureIoTClient | 42:448eecc3676e | 742 | } |
AzureIoTClient | 42:448eecc3676e | 743 | STRING_delete(uriResource); |
AzureIoTClient | 42:448eecc3676e | 744 | } |
AzureIoTClient | 42:448eecc3676e | 745 | return result; |
AzureIoTClient | 42:448eecc3676e | 746 | } |
AzureIoTClient | 42:448eecc3676e | 747 | |
AzureIoTClient | 42:448eecc3676e | 748 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob_Impl(IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE handle, const char* destinationFileName, const unsigned char* source, size_t size) |
AzureIoTClient | 42:448eecc3676e | 749 | { |
AzureIoTClient | 42:448eecc3676e | 750 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 48:cc5d91f2b06d | 751 | BUFFER_HANDLE toBeTransmitted; |
AzureIoTClient | 48:cc5d91f2b06d | 752 | int requiredStringLength; |
AzureIoTClient | 48:cc5d91f2b06d | 753 | char* requiredString; |
AzureIoTClient | 42:448eecc3676e | 754 | |
AzureIoTClient | 42:448eecc3676e | 755 | /*Codes_SRS_IOTHUBCLIENT_LL_02_061: [ If handle is NULL then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 756 | /*Codes_SRS_IOTHUBCLIENT_LL_02_062: [ If destinationFileName is NULL then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 757 | /*Codes_SRS_IOTHUBCLIENT_LL_02_063: [ If source is NULL and size is greater than 0 then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 758 | if ( |
AzureIoTClient | 42:448eecc3676e | 759 | (handle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 760 | (destinationFileName == NULL) || |
Azure.IoT Build | 45:54c11b1b1407 | 761 | ((source == NULL) && (size > 0)) |
AzureIoTClient | 42:448eecc3676e | 762 | ) |
AzureIoTClient | 42:448eecc3676e | 763 | { |
AzureIoTClient | 42:448eecc3676e | 764 | LogError("invalid argument detected handle=%p destinationFileName=%p source=%p size=%zu", handle, destinationFileName, source, size); |
AzureIoTClient | 42:448eecc3676e | 765 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 42:448eecc3676e | 766 | } |
AzureIoTClient | 42:448eecc3676e | 767 | else |
AzureIoTClient | 42:448eecc3676e | 768 | { |
AzureIoTClient | 42:448eecc3676e | 769 | IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA*)handle; |
AzureIoTClient | 42:448eecc3676e | 770 | |
AzureIoTClient | 42:448eecc3676e | 771 | /*Codes_SRS_IOTHUBCLIENT_LL_02_064: [ IoTHubClient_LL_UploadToBlob shall create an HTTPAPIEX_HANDLE to the IoTHub hostname. ]*/ |
AzureIoTClient | 42:448eecc3676e | 772 | HTTPAPIEX_HANDLE iotHubHttpApiExHandle = HTTPAPIEX_Create(handleData->hostname); |
AzureIoTClient | 42:448eecc3676e | 773 | |
AzureIoTClient | 42:448eecc3676e | 774 | /*Codes_SRS_IOTHUBCLIENT_LL_02_065: [ If creating the HTTPAPIEX_HANDLE fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 42:448eecc3676e | 775 | if (iotHubHttpApiExHandle == NULL) |
AzureIoTClient | 42:448eecc3676e | 776 | { |
AzureIoTClient | 42:448eecc3676e | 777 | LogError("unable to HTTPAPIEX_Create"); |
AzureIoTClient | 42:448eecc3676e | 778 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 779 | } |
AzureIoTClient | 42:448eecc3676e | 780 | else |
AzureIoTClient | 42:448eecc3676e | 781 | { |
AzureIoTClient | 46:6a69294b6119 | 782 | if ( |
AzureIoTClient | 46:6a69294b6119 | 783 | (handleData->authorizationScheme == X509) && |
AzureIoTClient | 46:6a69294b6119 | 784 | |
AzureIoTClient | 46:6a69294b6119 | 785 | /*transmit the x509certificate and x509privatekey*/ |
AzureIoTClient | 46:6a69294b6119 | 786 | /*Codes_SRS_IOTHUBCLIENT_LL_02_106: [ - x509certificate and x509privatekey saved options shall be passed on the HTTPAPIEX_SetOption ]*/ |
AzureIoTClient | 46:6a69294b6119 | 787 | (!( |
AzureIoTClient | 48:cc5d91f2b06d | 788 | (HTTPAPIEX_SetOption(iotHubHttpApiExHandle, OPTION_X509_CERT, handleData->credentials.x509credentials.x509certificate) == HTTPAPIEX_OK) && |
AzureIoTClient | 48:cc5d91f2b06d | 789 | (HTTPAPIEX_SetOption(iotHubHttpApiExHandle, OPTION_X509_PRIVATE_KEY, handleData->credentials.x509credentials.x509privatekey) == HTTPAPIEX_OK) |
AzureIoTClient | 46:6a69294b6119 | 790 | )) |
AzureIoTClient | 46:6a69294b6119 | 791 | ) |
AzureIoTClient | 42:448eecc3676e | 792 | { |
AzureIoTClient | 46:6a69294b6119 | 793 | LogError("unable to HTTPAPIEX_SetOption for x509"); |
AzureIoTClient | 42:448eecc3676e | 794 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 795 | } |
AzureIoTClient | 42:448eecc3676e | 796 | else |
AzureIoTClient | 42:448eecc3676e | 797 | { |
AzureIoTClient | 62:5a4cdacf5090 | 798 | /*Codes_SRS_IOTHUBCLIENT_LL_02_111: [ If certificates is non-NULL then certificates shall be passed to HTTPAPIEX_SetOption with optionName TrustedCerts. ]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 799 | if ((handleData->certificates != NULL) && (HTTPAPIEX_SetOption(iotHubHttpApiExHandle, "TrustedCerts", handleData->certificates) != HTTPAPIEX_OK)) |
AzureIoTClient | 42:448eecc3676e | 800 | { |
AzureIoTClient | 62:5a4cdacf5090 | 801 | LogError("unable to set TrustedCerts!"); |
AzureIoTClient | 42:448eecc3676e | 802 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 803 | } |
AzureIoTClient | 42:448eecc3676e | 804 | else |
AzureIoTClient | 42:448eecc3676e | 805 | { |
AzureIoTClient | 62:5a4cdacf5090 | 806 | |
AzureIoTClient | 74:ea0021abecf7 | 807 | if (handleData->http_proxy_options.host_address != NULL) |
AzureIoTClient | 42:448eecc3676e | 808 | { |
AzureIoTClient | 74:ea0021abecf7 | 809 | HTTP_PROXY_OPTIONS proxy_options; |
AzureIoTClient | 74:ea0021abecf7 | 810 | proxy_options = handleData->http_proxy_options; |
AzureIoTClient | 74:ea0021abecf7 | 811 | |
AzureIoTClient | 74:ea0021abecf7 | 812 | if (HTTPAPIEX_SetOption(iotHubHttpApiExHandle, OPTION_HTTP_PROXY, &proxy_options) != HTTPAPIEX_OK) |
AzureIoTClient | 74:ea0021abecf7 | 813 | { |
AzureIoTClient | 74:ea0021abecf7 | 814 | LogError("unable to set http proxy!"); |
AzureIoTClient | 74:ea0021abecf7 | 815 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 816 | } |
AzureIoTClient | 74:ea0021abecf7 | 817 | else |
AzureIoTClient | 74:ea0021abecf7 | 818 | { |
AzureIoTClient | 74:ea0021abecf7 | 819 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 74:ea0021abecf7 | 820 | } |
AzureIoTClient | 42:448eecc3676e | 821 | } |
AzureIoTClient | 42:448eecc3676e | 822 | else |
AzureIoTClient | 42:448eecc3676e | 823 | { |
AzureIoTClient | 74:ea0021abecf7 | 824 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 74:ea0021abecf7 | 825 | } |
AzureIoTClient | 74:ea0021abecf7 | 826 | |
AzureIoTClient | 74:ea0021abecf7 | 827 | if (result != IOTHUB_CLIENT_ERROR) |
AzureIoTClient | 74:ea0021abecf7 | 828 | { |
AzureIoTClient | 74:ea0021abecf7 | 829 | STRING_HANDLE correlationId = STRING_new(); |
AzureIoTClient | 74:ea0021abecf7 | 830 | if (correlationId == NULL) |
AzureIoTClient | 42:448eecc3676e | 831 | { |
AzureIoTClient | 62:5a4cdacf5090 | 832 | LogError("unable to STRING_new"); |
AzureIoTClient | 42:448eecc3676e | 833 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 834 | } |
AzureIoTClient | 42:448eecc3676e | 835 | else |
AzureIoTClient | 42:448eecc3676e | 836 | { |
AzureIoTClient | 74:ea0021abecf7 | 837 | STRING_HANDLE sasUri = STRING_new(); |
AzureIoTClient | 74:ea0021abecf7 | 838 | if (sasUri == NULL) |
AzureIoTClient | 42:448eecc3676e | 839 | { |
AzureIoTClient | 74:ea0021abecf7 | 840 | LogError("unable to STRING_new"); |
AzureIoTClient | 42:448eecc3676e | 841 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 842 | } |
AzureIoTClient | 42:448eecc3676e | 843 | else |
AzureIoTClient | 42:448eecc3676e | 844 | { |
AzureIoTClient | 74:ea0021abecf7 | 845 | /*Codes_SRS_IOTHUBCLIENT_LL_02_070: [ IoTHubClient_LL_UploadToBlob shall create request HTTP headers. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 846 | HTTP_HEADERS_HANDLE requestHttpHeaders = HTTPHeaders_Alloc(); /*these are build by step 1 and used by step 3 too*/ |
AzureIoTClient | 74:ea0021abecf7 | 847 | if (requestHttpHeaders == NULL) |
AzureIoTClient | 46:6a69294b6119 | 848 | { |
AzureIoTClient | 74:ea0021abecf7 | 849 | LogError("unable to HTTPHeaders_Alloc"); |
AzureIoTClient | 42:448eecc3676e | 850 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 851 | } |
AzureIoTClient | 42:448eecc3676e | 852 | else |
AzureIoTClient | 42:448eecc3676e | 853 | { |
AzureIoTClient | 74:ea0021abecf7 | 854 | /*do step 1*/ |
AzureIoTClient | 74:ea0021abecf7 | 855 | if (IoTHubClient_LL_UploadToBlob_step1and2(handleData, iotHubHttpApiExHandle, requestHttpHeaders, destinationFileName, correlationId, sasUri) != 0) |
AzureIoTClient | 62:5a4cdacf5090 | 856 | { |
AzureIoTClient | 74:ea0021abecf7 | 857 | LogError("error in IoTHubClient_LL_UploadToBlob_step1"); |
AzureIoTClient | 42:448eecc3676e | 858 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 859 | } |
AzureIoTClient | 42:448eecc3676e | 860 | else |
AzureIoTClient | 42:448eecc3676e | 861 | { |
AzureIoTClient | 74:ea0021abecf7 | 862 | /*do step 2.*/ |
AzureIoTClient | 46:6a69294b6119 | 863 | |
AzureIoTClient | 74:ea0021abecf7 | 864 | unsigned int httpResponse; |
AzureIoTClient | 74:ea0021abecf7 | 865 | BUFFER_HANDLE responseToIoTHub = BUFFER_new(); |
AzureIoTClient | 74:ea0021abecf7 | 866 | if (responseToIoTHub == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 867 | { |
AzureIoTClient | 42:448eecc3676e | 868 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 869 | LogError("unable to BUFFER_new"); |
AzureIoTClient | 42:448eecc3676e | 870 | } |
AzureIoTClient | 42:448eecc3676e | 871 | else |
AzureIoTClient | 42:448eecc3676e | 872 | { |
AzureIoTClient | 74:ea0021abecf7 | 873 | int step2success; |
AzureIoTClient | 74:ea0021abecf7 | 874 | /*Codes_SRS_IOTHUBCLIENT_LL_02_083: [ IoTHubClient_LL_UploadToBlob shall call Blob_UploadFromSasUri and capture the HTTP return code and HTTP body. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 875 | step2success = (Blob_UploadFromSasUri(STRING_c_str(sasUri), source, size, &httpResponse, responseToIoTHub, handleData->certificates) == BLOB_OK); |
AzureIoTClient | 74:ea0021abecf7 | 876 | if (!step2success) |
AzureIoTClient | 74:ea0021abecf7 | 877 | { |
AzureIoTClient | 74:ea0021abecf7 | 878 | /*Codes_SRS_IOTHUBCLIENT_LL_02_084: [ If Blob_UploadFromSasUri fails then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 879 | LogError("unable to Blob_UploadFromSasUri"); |
AzureIoTClient | 62:5a4cdacf5090 | 880 | |
AzureIoTClient | 74:ea0021abecf7 | 881 | /*do step 3*/ /*try*/ |
AzureIoTClient | 74:ea0021abecf7 | 882 | /*Codes_SRS_IOTHUBCLIENT_LL_02_091: [ If step 2 fails without establishing an HTTP dialogue, then the HTTP message body shall look like: ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 883 | if (BUFFER_build(responseToIoTHub, (const unsigned char*)FILE_UPLOAD_FAILED_BODY, sizeof(FILE_UPLOAD_FAILED_BODY) / sizeof(FILE_UPLOAD_FAILED_BODY[0])) == 0) |
AzureIoTClient | 74:ea0021abecf7 | 884 | { |
AzureIoTClient | 74:ea0021abecf7 | 885 | if (IoTHubClient_LL_UploadToBlob_step3(handleData, correlationId, iotHubHttpApiExHandle, requestHttpHeaders, responseToIoTHub) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 886 | { |
AzureIoTClient | 74:ea0021abecf7 | 887 | LogError("IoTHubClient_LL_UploadToBlob_step3 failed"); |
AzureIoTClient | 74:ea0021abecf7 | 888 | } |
AzureIoTClient | 74:ea0021abecf7 | 889 | } |
AzureIoTClient | 42:448eecc3676e | 890 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 891 | } |
AzureIoTClient | 42:448eecc3676e | 892 | else |
AzureIoTClient | 42:448eecc3676e | 893 | { |
AzureIoTClient | 74:ea0021abecf7 | 894 | /*must make a json*/ |
AzureIoTClient | 74:ea0021abecf7 | 895 | |
AzureIoTClient | 74:ea0021abecf7 | 896 | requiredStringLength = snprintf(NULL, 0, "{\"isSuccess\":%s, \"statusCode\":%d, \"statusDescription\":\"%s\"}", ((httpResponse < 300) ? "true" : "false"), httpResponse, BUFFER_u_char(responseToIoTHub)); |
AzureIoTClient | 74:ea0021abecf7 | 897 | |
AzureIoTClient | 74:ea0021abecf7 | 898 | requiredString = malloc(requiredStringLength + 1); |
AzureIoTClient | 74:ea0021abecf7 | 899 | if (requiredString == 0) |
AzureIoTClient | 46:6a69294b6119 | 900 | { |
AzureIoTClient | 74:ea0021abecf7 | 901 | LogError("unable to malloc"); |
AzureIoTClient | 46:6a69294b6119 | 902 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 46:6a69294b6119 | 903 | } |
AzureIoTClient | 46:6a69294b6119 | 904 | else |
AzureIoTClient | 46:6a69294b6119 | 905 | { |
AzureIoTClient | 74:ea0021abecf7 | 906 | /*do again snprintf*/ |
AzureIoTClient | 74:ea0021abecf7 | 907 | (void)snprintf(requiredString, requiredStringLength + 1, "{\"isSuccess\":%s, \"statusCode\":%d, \"statusDescription\":\"%s\"}", ((httpResponse < 300) ? "true" : "false"), httpResponse, BUFFER_u_char(responseToIoTHub)); |
AzureIoTClient | 74:ea0021abecf7 | 908 | toBeTransmitted = BUFFER_create((const unsigned char*)requiredString, requiredStringLength); |
AzureIoTClient | 74:ea0021abecf7 | 909 | if (toBeTransmitted == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 910 | { |
AzureIoTClient | 74:ea0021abecf7 | 911 | LogError("unable to BUFFER_create"); |
AzureIoTClient | 62:5a4cdacf5090 | 912 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 62:5a4cdacf5090 | 913 | } |
AzureIoTClient | 62:5a4cdacf5090 | 914 | else |
AzureIoTClient | 62:5a4cdacf5090 | 915 | { |
AzureIoTClient | 74:ea0021abecf7 | 916 | if (IoTHubClient_LL_UploadToBlob_step3(handleData, correlationId, iotHubHttpApiExHandle, requestHttpHeaders, toBeTransmitted) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 917 | { |
AzureIoTClient | 74:ea0021abecf7 | 918 | LogError("IoTHubClient_LL_UploadToBlob_step3 failed"); |
AzureIoTClient | 74:ea0021abecf7 | 919 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 920 | } |
AzureIoTClient | 74:ea0021abecf7 | 921 | else |
AzureIoTClient | 74:ea0021abecf7 | 922 | { |
AzureIoTClient | 74:ea0021abecf7 | 923 | result = (httpResponse < 300) ? IOTHUB_CLIENT_OK : IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 924 | } |
AzureIoTClient | 74:ea0021abecf7 | 925 | BUFFER_delete(toBeTransmitted); |
AzureIoTClient | 62:5a4cdacf5090 | 926 | } |
AzureIoTClient | 74:ea0021abecf7 | 927 | free(requiredString); |
AzureIoTClient | 46:6a69294b6119 | 928 | } |
AzureIoTClient | 42:448eecc3676e | 929 | } |
AzureIoTClient | 74:ea0021abecf7 | 930 | BUFFER_delete(responseToIoTHub); |
AzureIoTClient | 42:448eecc3676e | 931 | } |
AzureIoTClient | 42:448eecc3676e | 932 | } |
AzureIoTClient | 74:ea0021abecf7 | 933 | HTTPHeaders_Free(requestHttpHeaders); |
AzureIoTClient | 42:448eecc3676e | 934 | } |
AzureIoTClient | 74:ea0021abecf7 | 935 | STRING_delete(sasUri); |
AzureIoTClient | 42:448eecc3676e | 936 | } |
AzureIoTClient | 74:ea0021abecf7 | 937 | STRING_delete(correlationId); |
AzureIoTClient | 42:448eecc3676e | 938 | } |
AzureIoTClient | 42:448eecc3676e | 939 | } |
AzureIoTClient | 42:448eecc3676e | 940 | } |
AzureIoTClient | 42:448eecc3676e | 941 | } |
AzureIoTClient | 42:448eecc3676e | 942 | HTTPAPIEX_Destroy(iotHubHttpApiExHandle); |
AzureIoTClient | 42:448eecc3676e | 943 | } |
AzureIoTClient | 42:448eecc3676e | 944 | } |
AzureIoTClient | 42:448eecc3676e | 945 | return result; |
AzureIoTClient | 42:448eecc3676e | 946 | } |
AzureIoTClient | 42:448eecc3676e | 947 | |
AzureIoTClient | 42:448eecc3676e | 948 | void IoTHubClient_LL_UploadToBlob_Destroy(IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE handle) |
AzureIoTClient | 42:448eecc3676e | 949 | { |
AzureIoTClient | 42:448eecc3676e | 950 | if (handle == NULL) |
AzureIoTClient | 42:448eecc3676e | 951 | { |
AzureIoTClient | 62:5a4cdacf5090 | 952 | LogError("unexpected NULL argument"); |
AzureIoTClient | 42:448eecc3676e | 953 | } |
AzureIoTClient | 42:448eecc3676e | 954 | else |
AzureIoTClient | 42:448eecc3676e | 955 | { |
AzureIoTClient | 42:448eecc3676e | 956 | IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA*)handle; |
AzureIoTClient | 42:448eecc3676e | 957 | switch (handleData->authorizationScheme) |
AzureIoTClient | 42:448eecc3676e | 958 | { |
AzureIoTClient | 42:448eecc3676e | 959 | case(SAS_TOKEN): |
AzureIoTClient | 42:448eecc3676e | 960 | { |
AzureIoTClient | 42:448eecc3676e | 961 | STRING_delete(handleData->credentials.sas); |
AzureIoTClient | 42:448eecc3676e | 962 | break; |
AzureIoTClient | 42:448eecc3676e | 963 | } |
AzureIoTClient | 42:448eecc3676e | 964 | case(DEVICE_KEY): |
AzureIoTClient | 42:448eecc3676e | 965 | { |
AzureIoTClient | 42:448eecc3676e | 966 | STRING_delete(handleData->credentials.deviceKey); |
AzureIoTClient | 42:448eecc3676e | 967 | break; |
AzureIoTClient | 42:448eecc3676e | 968 | } |
AzureIoTClient | 46:6a69294b6119 | 969 | case(X509): |
AzureIoTClient | 46:6a69294b6119 | 970 | { |
AzureIoTClient | 46:6a69294b6119 | 971 | if (handleData->credentials.x509credentials.x509certificate != NULL) |
AzureIoTClient | 46:6a69294b6119 | 972 | { |
AzureIoTClient | 46:6a69294b6119 | 973 | free((void*)handleData->credentials.x509credentials.x509certificate); |
AzureIoTClient | 46:6a69294b6119 | 974 | } |
AzureIoTClient | 46:6a69294b6119 | 975 | if (handleData->credentials.x509credentials.x509privatekey != NULL) |
AzureIoTClient | 46:6a69294b6119 | 976 | { |
AzureIoTClient | 46:6a69294b6119 | 977 | free((void*)handleData->credentials.x509credentials.x509privatekey); |
AzureIoTClient | 46:6a69294b6119 | 978 | } |
AzureIoTClient | 46:6a69294b6119 | 979 | break; |
AzureIoTClient | 46:6a69294b6119 | 980 | } |
AzureIoTClient | 42:448eecc3676e | 981 | default: |
AzureIoTClient | 42:448eecc3676e | 982 | { |
AzureIoTClient | 42:448eecc3676e | 983 | LogError("INTERNAL ERROR"); |
AzureIoTClient | 42:448eecc3676e | 984 | break; |
AzureIoTClient | 42:448eecc3676e | 985 | } |
AzureIoTClient | 42:448eecc3676e | 986 | } |
AzureIoTClient | 42:448eecc3676e | 987 | free((void*)handleData->hostname); |
AzureIoTClient | 42:448eecc3676e | 988 | STRING_delete(handleData->deviceId); |
AzureIoTClient | 62:5a4cdacf5090 | 989 | if (handleData->certificates != NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 990 | { |
AzureIoTClient | 62:5a4cdacf5090 | 991 | free(handleData->certificates); |
AzureIoTClient | 62:5a4cdacf5090 | 992 | } |
AzureIoTClient | 74:ea0021abecf7 | 993 | if (handleData->http_proxy_options.host_address != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 994 | { |
AzureIoTClient | 74:ea0021abecf7 | 995 | free((char *)handleData->http_proxy_options.host_address); |
AzureIoTClient | 74:ea0021abecf7 | 996 | } |
AzureIoTClient | 74:ea0021abecf7 | 997 | if (handleData->http_proxy_options.username != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 998 | { |
AzureIoTClient | 74:ea0021abecf7 | 999 | free((char *)handleData->http_proxy_options.username); |
AzureIoTClient | 74:ea0021abecf7 | 1000 | } |
AzureIoTClient | 74:ea0021abecf7 | 1001 | if (handleData->http_proxy_options.password != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 1002 | { |
AzureIoTClient | 74:ea0021abecf7 | 1003 | free((char *)handleData->http_proxy_options.password); |
AzureIoTClient | 74:ea0021abecf7 | 1004 | } |
AzureIoTClient | 42:448eecc3676e | 1005 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 1006 | } |
AzureIoTClient | 42:448eecc3676e | 1007 | } |
AzureIoTClient | 46:6a69294b6119 | 1008 | |
AzureIoTClient | 46:6a69294b6119 | 1009 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob_SetOption(IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE handle, const char* optionName, const void* value) |
AzureIoTClient | 46:6a69294b6119 | 1010 | { |
AzureIoTClient | 46:6a69294b6119 | 1011 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 46:6a69294b6119 | 1012 | /*Codes_SRS_IOTHUBCLIENT_LL_02_110: [ If parameter handle is NULL then IoTHubClient_LL_UploadToBlob_SetOption shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1013 | if (handle == NULL) |
AzureIoTClient | 46:6a69294b6119 | 1014 | { |
AzureIoTClient | 46:6a69294b6119 | 1015 | LogError("invalid argument detected: IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE handle=%p, const char* optionName=%s, const void* value=%p", handle, optionName, value); |
AzureIoTClient | 46:6a69294b6119 | 1016 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 46:6a69294b6119 | 1017 | } |
AzureIoTClient | 46:6a69294b6119 | 1018 | else |
AzureIoTClient | 46:6a69294b6119 | 1019 | { |
AzureIoTClient | 46:6a69294b6119 | 1020 | IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA*)handle; |
AzureIoTClient | 46:6a69294b6119 | 1021 | |
AzureIoTClient | 46:6a69294b6119 | 1022 | /*Codes_SRS_IOTHUBCLIENT_LL_02_100: [ x509certificate - then value then is a null terminated string that contains the x509 certificate. ]*/ |
AzureIoTClient | 48:cc5d91f2b06d | 1023 | if (strcmp(optionName, OPTION_X509_CERT) == 0) |
AzureIoTClient | 46:6a69294b6119 | 1024 | { |
AzureIoTClient | 46:6a69294b6119 | 1025 | /*Codes_SRS_IOTHUBCLIENT_LL_02_109: [ If the authentication scheme is NOT x509 then IoTHubClient_LL_UploadToBlob_SetOption shall return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1026 | if (handleData->authorizationScheme != X509) |
AzureIoTClient | 46:6a69294b6119 | 1027 | { |
AzureIoTClient | 46:6a69294b6119 | 1028 | LogError("trying to set a x509 certificate while the authentication scheme is not x509"); |
AzureIoTClient | 46:6a69294b6119 | 1029 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 46:6a69294b6119 | 1030 | } |
AzureIoTClient | 46:6a69294b6119 | 1031 | else |
AzureIoTClient | 46:6a69294b6119 | 1032 | { |
AzureIoTClient | 46:6a69294b6119 | 1033 | /*Codes_SRS_IOTHUBCLIENT_LL_02_103: [ The options shall be saved. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1034 | /*try to make a copy of the certificate*/ |
AzureIoTClient | 46:6a69294b6119 | 1035 | char* temp; |
AzureIoTClient | 46:6a69294b6119 | 1036 | if (mallocAndStrcpy_s(&temp, value) != 0) |
AzureIoTClient | 46:6a69294b6119 | 1037 | { |
AzureIoTClient | 46:6a69294b6119 | 1038 | /*Codes_SRS_IOTHUBCLIENT_LL_02_104: [ If saving fails, then IoTHubClient_LL_UploadToBlob_SetOption shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1039 | LogError("unable to mallocAndStrcpy_s"); |
AzureIoTClient | 46:6a69294b6119 | 1040 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 46:6a69294b6119 | 1041 | } |
AzureIoTClient | 46:6a69294b6119 | 1042 | else |
AzureIoTClient | 46:6a69294b6119 | 1043 | { |
AzureIoTClient | 46:6a69294b6119 | 1044 | /*Codes_SRS_IOTHUBCLIENT_LL_02_105: [ Otherwise IoTHubClient_LL_UploadToBlob_SetOption shall succeed and return IOTHUB_CLIENT_OK. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1045 | if (handleData->credentials.x509credentials.x509certificate != NULL) /*free any previous values, if any*/ |
AzureIoTClient | 46:6a69294b6119 | 1046 | { |
AzureIoTClient | 46:6a69294b6119 | 1047 | free((void*)handleData->credentials.x509credentials.x509certificate); |
AzureIoTClient | 46:6a69294b6119 | 1048 | } |
AzureIoTClient | 46:6a69294b6119 | 1049 | handleData->credentials.x509credentials.x509certificate = temp; |
AzureIoTClient | 46:6a69294b6119 | 1050 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 46:6a69294b6119 | 1051 | } |
AzureIoTClient | 46:6a69294b6119 | 1052 | } |
AzureIoTClient | 46:6a69294b6119 | 1053 | } |
AzureIoTClient | 46:6a69294b6119 | 1054 | /*Codes_SRS_IOTHUBCLIENT_LL_02_101: [ x509privatekey - then value is a null terminated string that contains the x509 privatekey. ]*/ |
AzureIoTClient | 48:cc5d91f2b06d | 1055 | else if (strcmp(optionName, OPTION_X509_PRIVATE_KEY) == 0) |
AzureIoTClient | 46:6a69294b6119 | 1056 | { |
AzureIoTClient | 46:6a69294b6119 | 1057 | /*Codes_SRS_IOTHUBCLIENT_LL_02_109: [ If the authentication scheme is NOT x509 then IoTHubClient_LL_UploadToBlob_SetOption shall return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1058 | if (handleData->authorizationScheme != X509) |
AzureIoTClient | 46:6a69294b6119 | 1059 | { |
AzureIoTClient | 46:6a69294b6119 | 1060 | LogError("trying to set a x509 privatekey while the authentication scheme is not x509"); |
AzureIoTClient | 46:6a69294b6119 | 1061 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 46:6a69294b6119 | 1062 | } |
AzureIoTClient | 46:6a69294b6119 | 1063 | else |
AzureIoTClient | 46:6a69294b6119 | 1064 | { |
AzureIoTClient | 46:6a69294b6119 | 1065 | /*Codes_SRS_IOTHUBCLIENT_LL_02_103: [ The options shall be saved. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1066 | /*try to make a copy of the privatekey*/ |
AzureIoTClient | 46:6a69294b6119 | 1067 | char* temp; |
AzureIoTClient | 46:6a69294b6119 | 1068 | if (mallocAndStrcpy_s(&temp, value) != 0) |
AzureIoTClient | 46:6a69294b6119 | 1069 | { |
AzureIoTClient | 46:6a69294b6119 | 1070 | /*Codes_SRS_IOTHUBCLIENT_LL_02_104: [ If saving fails, then IoTHubClient_LL_UploadToBlob_SetOption shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1071 | LogError("unable to mallocAndStrcpy_s"); |
AzureIoTClient | 46:6a69294b6119 | 1072 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 46:6a69294b6119 | 1073 | } |
AzureIoTClient | 46:6a69294b6119 | 1074 | else |
AzureIoTClient | 46:6a69294b6119 | 1075 | { |
AzureIoTClient | 46:6a69294b6119 | 1076 | /*Codes_SRS_IOTHUBCLIENT_LL_02_105: [ Otherwise IoTHubClient_LL_UploadToBlob_SetOption shall succeed and return IOTHUB_CLIENT_OK. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1077 | if (handleData->credentials.x509credentials.x509privatekey != NULL) /*free any previous values, if any*/ |
AzureIoTClient | 46:6a69294b6119 | 1078 | { |
AzureIoTClient | 46:6a69294b6119 | 1079 | free((void*)handleData->credentials.x509credentials.x509privatekey); |
AzureIoTClient | 46:6a69294b6119 | 1080 | } |
AzureIoTClient | 46:6a69294b6119 | 1081 | handleData->credentials.x509credentials.x509privatekey = temp; |
AzureIoTClient | 46:6a69294b6119 | 1082 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 46:6a69294b6119 | 1083 | } |
AzureIoTClient | 46:6a69294b6119 | 1084 | } |
AzureIoTClient | 46:6a69294b6119 | 1085 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1086 | else if (strcmp("TrustedCerts", optionName) == 0) |
AzureIoTClient | 62:5a4cdacf5090 | 1087 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1088 | if (value == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 1089 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1090 | LogError("NULL is a not a valid value for TrustedCerts"); |
AzureIoTClient | 62:5a4cdacf5090 | 1091 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 62:5a4cdacf5090 | 1092 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1093 | else |
AzureIoTClient | 62:5a4cdacf5090 | 1094 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1095 | char* tempCopy; |
AzureIoTClient | 62:5a4cdacf5090 | 1096 | if (mallocAndStrcpy_s(&tempCopy, value) != 0) |
AzureIoTClient | 62:5a4cdacf5090 | 1097 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1098 | LogError("failure in mallocAndStrcpy_s"); |
AzureIoTClient | 62:5a4cdacf5090 | 1099 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 62:5a4cdacf5090 | 1100 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1101 | else |
AzureIoTClient | 62:5a4cdacf5090 | 1102 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1103 | if (handleData->certificates != NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 1104 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1105 | free(handleData->certificates); |
AzureIoTClient | 62:5a4cdacf5090 | 1106 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1107 | handleData->certificates = tempCopy; |
AzureIoTClient | 62:5a4cdacf5090 | 1108 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 62:5a4cdacf5090 | 1109 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1110 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1111 | } |
AzureIoTClient | 74:ea0021abecf7 | 1112 | /*Codes_SRS_IOTHUBCLIENT_LL_32_008: [ OPTION_HTTP_PROXY - then the value will be a pointer to HTTP_PROXY_OPTIONS structure. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 1113 | else if (strcmp(optionName, OPTION_HTTP_PROXY) == 0) |
AzureIoTClient | 74:ea0021abecf7 | 1114 | { |
AzureIoTClient | 74:ea0021abecf7 | 1115 | HTTP_PROXY_OPTIONS* proxy_options = (HTTP_PROXY_OPTIONS *)value; |
AzureIoTClient | 74:ea0021abecf7 | 1116 | |
AzureIoTClient | 74:ea0021abecf7 | 1117 | if (proxy_options->host_address == NULL) |
AzureIoTClient | 74:ea0021abecf7 | 1118 | { |
AzureIoTClient | 74:ea0021abecf7 | 1119 | /* Codes_SRS_IOTHUBCLIENT_LL_32_006: [ If `host_address` is NULL, `IoTHubClient_LL_UploadToBlob_SetOption` shall fail and return `IOTHUB_CLIENT_INVALID_ARG`. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 1120 | LogError("NULL host_address in proxy options"); |
AzureIoTClient | 74:ea0021abecf7 | 1121 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 74:ea0021abecf7 | 1122 | } |
AzureIoTClient | 74:ea0021abecf7 | 1123 | /* Codes_SRS_IOTHUBCLIENT_LL_32_007: [ If only one of `username` and `password` is NULL, `IoTHubClient_LL_UploadToBlob_SetOption` shall fail and return `IOTHUB_CLIENT_INVALID_ARG`. ]*/ |
AzureIoTClient | 74:ea0021abecf7 | 1124 | else if (((proxy_options->username == NULL) || (proxy_options->password == NULL)) && |
AzureIoTClient | 74:ea0021abecf7 | 1125 | (proxy_options->username != proxy_options->password)) |
AzureIoTClient | 74:ea0021abecf7 | 1126 | { |
AzureIoTClient | 74:ea0021abecf7 | 1127 | LogError("Only one of username and password for proxy settings was NULL"); |
AzureIoTClient | 74:ea0021abecf7 | 1128 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 74:ea0021abecf7 | 1129 | } |
AzureIoTClient | 74:ea0021abecf7 | 1130 | else |
AzureIoTClient | 74:ea0021abecf7 | 1131 | { |
AzureIoTClient | 74:ea0021abecf7 | 1132 | if (handleData->http_proxy_options.host_address != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 1133 | { |
AzureIoTClient | 74:ea0021abecf7 | 1134 | free((char *)handleData->http_proxy_options.host_address); |
AzureIoTClient | 74:ea0021abecf7 | 1135 | handleData->http_proxy_options.host_address = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 1136 | } |
AzureIoTClient | 74:ea0021abecf7 | 1137 | if (handleData->http_proxy_options.username != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 1138 | { |
AzureIoTClient | 74:ea0021abecf7 | 1139 | free((char *)handleData->http_proxy_options.username); |
AzureIoTClient | 74:ea0021abecf7 | 1140 | handleData->http_proxy_options.username = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 1141 | } |
AzureIoTClient | 74:ea0021abecf7 | 1142 | if (handleData->http_proxy_options.password != NULL) |
AzureIoTClient | 74:ea0021abecf7 | 1143 | { |
AzureIoTClient | 74:ea0021abecf7 | 1144 | free((char *)handleData->http_proxy_options.password); |
AzureIoTClient | 74:ea0021abecf7 | 1145 | handleData->http_proxy_options.password = NULL; |
AzureIoTClient | 74:ea0021abecf7 | 1146 | } |
AzureIoTClient | 74:ea0021abecf7 | 1147 | |
AzureIoTClient | 74:ea0021abecf7 | 1148 | handleData->http_proxy_options.port = proxy_options->port; |
AzureIoTClient | 74:ea0021abecf7 | 1149 | |
AzureIoTClient | 74:ea0021abecf7 | 1150 | if (mallocAndStrcpy_s((char **)(&handleData->http_proxy_options.host_address), proxy_options->host_address) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 1151 | { |
AzureIoTClient | 74:ea0021abecf7 | 1152 | LogError("failure in mallocAndStrcpy_s - handleData->http_proxy_options.host_address"); |
AzureIoTClient | 74:ea0021abecf7 | 1153 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 1154 | } |
AzureIoTClient | 74:ea0021abecf7 | 1155 | else if (proxy_options->username != NULL && mallocAndStrcpy_s((char **)(&handleData->http_proxy_options.username), proxy_options->username) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 1156 | { |
AzureIoTClient | 74:ea0021abecf7 | 1157 | LogError("failure in mallocAndStrcpy_s - handleData->http_proxy_options.username"); |
AzureIoTClient | 74:ea0021abecf7 | 1158 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 1159 | } |
AzureIoTClient | 74:ea0021abecf7 | 1160 | else if (proxy_options->password != NULL && mallocAndStrcpy_s((char **)(&handleData->http_proxy_options.password), proxy_options->password) != 0) |
AzureIoTClient | 74:ea0021abecf7 | 1161 | { |
AzureIoTClient | 74:ea0021abecf7 | 1162 | LogError("failure in mallocAndStrcpy_s - handleData->http_proxy_options.password"); |
AzureIoTClient | 74:ea0021abecf7 | 1163 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 74:ea0021abecf7 | 1164 | } |
AzureIoTClient | 74:ea0021abecf7 | 1165 | else |
AzureIoTClient | 74:ea0021abecf7 | 1166 | { |
AzureIoTClient | 74:ea0021abecf7 | 1167 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 74:ea0021abecf7 | 1168 | } |
AzureIoTClient | 74:ea0021abecf7 | 1169 | } |
AzureIoTClient | 74:ea0021abecf7 | 1170 | } |
AzureIoTClient | 46:6a69294b6119 | 1171 | else |
AzureIoTClient | 46:6a69294b6119 | 1172 | { |
AzureIoTClient | 46:6a69294b6119 | 1173 | /*Codes_SRS_IOTHUBCLIENT_LL_02_102: [ If an unknown option is presented then IoTHubClient_LL_UploadToBlob_SetOption shall return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1174 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 46:6a69294b6119 | 1175 | } |
AzureIoTClient | 46:6a69294b6119 | 1176 | } |
AzureIoTClient | 46:6a69294b6119 | 1177 | return result; |
AzureIoTClient | 46:6a69294b6119 | 1178 | } |
AzureIoTClient | 46:6a69294b6119 | 1179 | |
AzureIoTClient | 46:6a69294b6119 | 1180 | |
Azure.IoT Build | 45:54c11b1b1407 | 1181 | #endif /*DONT_USE_UPLOADTOBLOB*/ |
AzureIoTClient | 46:6a69294b6119 | 1182 | |
AzureIoTClient | 46:6a69294b6119 | 1183 |