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