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

Committer:
AzureIoTClient
Date:
Fri Dec 15 14:09:20 2017 -0800
Revision:
80:db5f5237bc95
Parent:
79:bb88037c05e6
Child:
82:f94e6bed4495
1.1.29

Who changed what in which revision?

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