Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Sync Arduino libraries with latest Azure IoT SDK 1.0.45
Browse files Browse the repository at this point in the history
  • Loading branch information
az-iot-builder-01 committed Jun 14, 2018
1 parent a05a36c commit 2462c17
Show file tree
Hide file tree
Showing 23 changed files with 1,030 additions and 664 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AzureIoTHub
version=1.0.44
version=1.0.45
author=Microsoft
maintainer=Microsoft <iotcert@microsoft.com>
sentence=Azure IoT library for Arduino. For the Arduino MKR1000 or Zero and WiFi Shield 101, Adafruit Huzzah and Feather M0, or SparkFun Thing.
Expand Down
2 changes: 1 addition & 1 deletion src/AzureIoTHub.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
#include "sdk/iothubtransportmqtt.h"
#include "sdk/iothub_client_options.h"

#define AzureIoTHubVersion "1.0.44"
#define AzureIoTHubVersion "1.0.45"
#endif
18 changes: 6 additions & 12 deletions src/sdk/agenttypesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3022,7 +3022,7 @@ static int sscanfd(const char *src, int* dst)
}
else
{
(*dst) = temp;
(*dst) = (int)temp;
result = 1;
}
return result;
Expand Down Expand Up @@ -3074,7 +3074,7 @@ static int sscanfu(const char* src, unsigned int* dst)
else
{
result = 1;
(*dst) = temp;
(*dst) = (unsigned int)temp;
}
return result;
}
Expand Down Expand Up @@ -3974,40 +3974,34 @@ result = AGENT_DATA_TYPES_OK;
// extern AGENT_DATA_TYPES_RESULT AgentDataType_GetComplexTypeField(AGENT_DATA_TYPE* agentData, size_t index, COMPLEX_TYPE_FIELD_TYPE* complexField);
COMPLEX_TYPE_FIELD_TYPE* AgentDataType_GetComplexTypeField(AGENT_DATA_TYPE* agentData, size_t index)
{
AGENT_DATA_TYPES_RESULT result;
COMPLEX_TYPE_FIELD_TYPE* complexField = NULL;
if (agentData == NULL)
{
result = AGENT_DATA_TYPES_INVALID_ARG;
LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, AGENT_DATA_TYPES_INVALID_ARG));
}
else
{
if (agentData->type != EDM_COMPLEX_TYPE_TYPE)
{
result = AGENT_DATA_TYPES_INVALID_ARG;
LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, AGENT_DATA_TYPES_INVALID_ARG));
}

else
{
if (index >= agentData->value.edmComplexType.nMembers)
{
result = AGENT_DATA_TYPES_INVALID_ARG;
LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, AGENT_DATA_TYPES_INVALID_ARG));
}
else
{
complexField = (COMPLEX_TYPE_FIELD_TYPE*)malloc(sizeof(COMPLEX_TYPE_FIELD_TYPE));
if (complexField == NULL)
{
result = AGENT_DATA_TYPES_ERROR;
LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, AGENT_DATA_TYPES_ERROR));
}
else
{
*complexField = agentData->value.edmComplexType.fields[index];
result = AGENT_DATA_TYPES_OK;
}
}
}
Expand Down
126 changes: 59 additions & 67 deletions src/sdk/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ BLOB_RESULT Blob_UploadBlock(
return result;
}

BLOB_RESULT Blob_UploadMultipleBlocksFromSasUri(const char* SASURI, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK getDataCallback, void* context, unsigned int* httpStatus, BUFFER_HANDLE httpResponse, const char* certificates, HTTP_PROXY_OPTIONS *proxyOptions)
BLOB_RESULT Blob_UploadMultipleBlocksFromSasUri(const char* SASURI, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX getDataCallbackEx, void* context, unsigned int* httpStatus, BUFFER_HANDLE httpResponse, const char* certificates, HTTP_PROXY_OPTIONS *proxyOptions)
{
BLOB_RESULT result;
/*Codes_SRS_BLOB_02_001: [ If SASURI is NULL then Blob_UploadMultipleBlocksFromSasUri shall fail and return BLOB_INVALID_ARG. ]*/
Expand All @@ -135,10 +135,10 @@ BLOB_RESULT Blob_UploadMultipleBlocksFromSasUri(const char* SASURI, IOTHUB_CLIEN
}
else
{
/*Codes_SRS_BLOB_02_002: [ If getDataCallback is NULL then Blob_UploadMultipleBlocksFromSasUri shall fail and return BLOB_INVALID_ARG. ]*/
if (getDataCallback == NULL)
/*Codes_SRS_BLOB_02_002: [ If getDataCallbackEx is NULL then Blob_UploadMultipleBlocksFromSasUri shall fail and return BLOB_INVALID_ARG. ]*/
if (getDataCallbackEx == NULL)
{
LogError("IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK getDataCallback = %p is invalid", getDataCallback);
LogError("IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX getDataCallbackEx is NULL");
result = BLOB_INVALID_ARG;
}
/*the below define avoid a "condition always false" on some compilers*/
Expand Down Expand Up @@ -216,92 +216,84 @@ BLOB_RESULT Blob_UploadMultipleBlocksFromSasUri(const char* SASURI, IOTHUB_CLIEN
}
else
{
/*Codes_SRS_BLOB_02_021: [ For every block returned by `getDataCallback` the following operations shall happen: ]*/
/*Codes_SRS_BLOB_02_021: [ For every block returned by `getDataCallbackEx` the following operations shall happen: ]*/
unsigned int blockID = 0; /* incremented for each new block */
unsigned int isError = 0; /* set to 1 if a block upload fails or if getDataCallback returns incorrect blocks to upload */
unsigned int uploadOneMoreBlock; /* set to 1 while getDataCallback returns correct blocks to upload */
unsigned char const * source; /* data set by getDataCallback */
size_t size; /* source size set by getDataCallback */
unsigned int isError = 0; /* set to 1 if a block upload fails or if getDataCallbackEx returns incorrect blocks to upload */
unsigned int uploadOneMoreBlock = 1; /* set to 1 while getDataCallbackEx returns correct blocks to upload */
unsigned char const * source; /* data set by getDataCallbackEx */
size_t size; /* source size set by getDataCallbackEx */
IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_RESULT getDataReturnValue;

/* get first block */
getDataCallback(FILE_UPLOAD_OK, &source, &size, context);

/*Codes_SRS_BLOB_99_002: [ If the size of the block returned by `getDataCallback` is 0 or if the data is NULL, then `Blob_UploadMultipleBlocksFromSasUri` shall exit the loop. ]*/
uploadOneMoreBlock = (source != NULL && size > 0) ? 1 : 0;

if (size > BLOCK_SIZE)
do
{
/*Codes_SRS_BLOB_99_001: [ If the size of the block returned by `getDataCallback` is bigger than 4MB, then `Blob_UploadMultipleBlocksFromSasUri` shall fail and return `BLOB_INVALID_ARG`. ]*/
LogError("tried to upload block of size %u, max allowed size is %d", size, BLOCK_SIZE);
result = BLOB_INVALID_ARG;
isError = 1;
}
else
{
result = BLOB_OK;
}

while(uploadOneMoreBlock && !isError)
{
/*Codes_SRS_BLOB_02_023: [ Blob_UploadMultipleBlocksFromSasUri shall create a BUFFER_HANDLE from source and size parameters. ]*/
BUFFER_HANDLE requestContent = BUFFER_create(source, size);
if (requestContent == NULL)
{
/*Codes_SRS_BLOB_02_033: [ If any previous operation that doesn't have an explicit failure description fails then Blob_UploadMultipleBlocksFromSasUri shall fail and return BLOB_ERROR ]*/
LogError("unable to BUFFER_create");
result = BLOB_ERROR;
isError = 1;
}
else
getDataReturnValue = getDataCallbackEx(FILE_UPLOAD_OK, &source, &size, context);
if (getDataReturnValue == IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_ABORT)
{
result = Blob_UploadBlock(
httpApiExHandle,
relativePath,
requestContent,
blockID,
blockIDList,
httpStatus,
httpResponse);

BUFFER_delete(requestContent);
/*Codes_SRS_BLOB_99_004: [ If `getDataCallbackEx` returns `IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_RESULT_ABORT`, then `Blob_UploadMultipleBlocksFromSasUri` shall exit the loop and return `BLOB_ABORTED`. ]*/
LogInfo("Upload to blob has been aborted by the user");
uploadOneMoreBlock = 0;
result = BLOB_ABORTED;
}

/*Codes_SRS_BLOB_02_026: [ Otherwise, if HTTP response code is >=300 then Blob_UploadMultipleBlocksFromSasUri shall succeed and return BLOB_OK. ]*/
if (result != BLOB_OK || *httpStatus >= 300)
else if (source == NULL || size == 0)
{
isError = 1;
/*Codes_SRS_BLOB_99_002: [ If the size of the block returned by `getDataCallbackEx` is 0 or if the data is NULL, then `Blob_UploadMultipleBlocksFromSasUri` shall exit the loop. ]*/
uploadOneMoreBlock = 0;
result = BLOB_OK;
}
else
{
// try to get next block
getDataCallback(FILE_UPLOAD_OK, &source, &size, context);
if (source == NULL || size == 0)
if (size > BLOCK_SIZE)
{
/*Codes_SRS_BLOB_99_001: [ If the size of the block returned by `getDataCallbackEx` is bigger than 4MB, then `Blob_UploadMultipleBlocksFromSasUri` shall fail and return `BLOB_INVALID_ARG`. ]*/
LogError("tried to upload block of size %u, max allowed size is %d", size, BLOCK_SIZE);
result = BLOB_INVALID_ARG;
isError = 1;
}
else if (blockID >= MAX_BLOCK_COUNT)
{
/*Codes_SRS_BLOB_99_002: [ If the size of the block returned by `getDataCallback` is 0 or if the data is NULL, then `Blob_UploadMultipleBlocksFromSasUri` shall exit the loop. ]*/
uploadOneMoreBlock = 0;
/*Codes_SRS_BLOB_99_003: [ If `getDataCallbackEx` returns more than 50000 blocks, then `Blob_UploadMultipleBlocksFromSasUri` shall fail and return `BLOB_INVALID_ARG`. ]*/
LogError("unable to upload more than %u blocks in one blob", MAX_BLOCK_COUNT);
result = BLOB_INVALID_ARG;
isError = 1;
}
else
{
blockID++;
if (size > BLOCK_SIZE)
/*Codes_SRS_BLOB_02_023: [ Blob_UploadMultipleBlocksFromSasUri shall create a BUFFER_HANDLE from source and size parameters. ]*/
BUFFER_HANDLE requestContent = BUFFER_create(source, size);
if (requestContent == NULL)
{
/*Codes_SRS_BLOB_99_001: [ If the size of the block returned by `getDataCallback` is bigger than 4MB, then `Blob_UploadMultipleBlocksFromSasUri` shall fail and return `BLOB_INVALID_ARG`. ]*/
LogError("tried to upload block of size %u, max allowed size is %d", size, BLOCK_SIZE);
result = BLOB_INVALID_ARG;
/*Codes_SRS_BLOB_02_033: [ If any previous operation that doesn't have an explicit failure description fails then Blob_UploadMultipleBlocksFromSasUri shall fail and return BLOB_ERROR ]*/
LogError("unable to BUFFER_create");
result = BLOB_ERROR;
isError = 1;
}
else if (blockID >= MAX_BLOCK_COUNT)
else
{
result = Blob_UploadBlock(
httpApiExHandle,
relativePath,
requestContent,
blockID,
blockIDList,
httpStatus,
httpResponse);

BUFFER_delete(requestContent);
}

/*Codes_SRS_BLOB_02_026: [ Otherwise, if HTTP response code is >=300 then Blob_UploadMultipleBlocksFromSasUri shall succeed and return BLOB_OK. ]*/
if (result != BLOB_OK || *httpStatus >= 300)
{
/*Codes_SRS_BLOB_99_003: [ If `getDataCallback` returns more than 50000 blocks, then `Blob_UploadMultipleBlocksFromSasUri` shall fail and return `BLOB_INVALID_ARG`. ]*/
LogError("unable to upload more than %u blocks in one blob", MAX_BLOCK_COUNT);
result = BLOB_INVALID_ARG;
LogError("unable to Blob_UploadBlock. Returned value=%d, httpStatus=%u", result, httpStatus);
isError = 1;
}
}
blockID++;
}
}
while(uploadOneMoreBlock && !isError);

if (isError)
if (isError || result != BLOB_OK)
{
/*do nothing, it will be reported "as is"*/
}
Expand Down
7 changes: 4 additions & 3 deletions src/sdk/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ extern "C"
BLOB_ERROR, \
BLOB_NOT_IMPLEMENTED, \
BLOB_HTTP_ERROR, \
BLOB_INVALID_ARG
BLOB_INVALID_ARG, \
BLOB_ABORTED

DEFINE_ENUM(BLOB_RESULT, BLOB_RESULT_VALUES)

/**
* @brief Synchronously uploads a byte array to blob storage
*
* @param SASURI The URI to use to upload data
* @param getDataCallback A callback to be invoked to acquire the file chunks to be uploaded, as well as to indicate the status of the upload of the previous block.
* @param getDataCallbackEx A callback to be invoked to acquire the file chunks to be uploaded, as well as to indicate the status of the upload of the previous block.
* @param context Any data provided by the user to serve as context on getDataCallback.
* @param httpStatus A pointer to an out argument receiving the HTTP status (available only when the return value is BLOB_OK)
* @param httpResponse A BUFFER_HANDLE that receives the HTTP response from the server (available only when the return value is BLOB_OK)
Expand All @@ -58,7 +59,7 @@ DEFINE_ENUM(BLOB_RESULT, BLOB_RESULT_VALUES)
*
* @return A @c BLOB_RESULT. BLOB_OK means the blob has been uploaded successfully. Any other value indicates an error
*/
MOCKABLE_FUNCTION(, BLOB_RESULT, Blob_UploadMultipleBlocksFromSasUri, const char*, SASURI, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK, getDataCallback, void*, context, unsigned int*, httpStatus, BUFFER_HANDLE, httpResponse, const char*, certificates, HTTP_PROXY_OPTIONS*, proxyOptions)
MOCKABLE_FUNCTION(, BLOB_RESULT, Blob_UploadMultipleBlocksFromSasUri, const char*, SASURI, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX, getDataCallbackEx, void*, context, unsigned int*, httpStatus, BUFFER_HANDLE, httpResponse, const char*, certificates, HTTP_PROXY_OPTIONS*, proxyOptions)

/**
* @brief Synchronously uploads a byte array as a new block to blob storage
Expand Down
Loading

0 comments on commit 2462c17

Please sign in to comment.