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:
Mon Jun 11 15:39:23 2018 -0700
Revision:
88:248736be106e
Parent:
86:a1352899ea45
Child:
92:97148cf9aa2a
1.2.5

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