A modelling and serializer library for Microsoft Azure IoTHub client applications
Dependents: sht15_remote_monitoring f767zi_mqtt remote_monitoring simplesample_amqp ... more
This library implements a serializer library to be used in projects involving Microsoft Azure IoT Hub connectivity. The code is replicated from https://github.com/Azure/azure-iot-sdks
Revision 36:7d12a5386197, committed 2018-09-11
- Comitter:
- AzureIoTClient
- Date:
- Tue Sep 11 11:14:37 2018 -0700
- Parent:
- 35:ede97b73d1bb
- Commit message:
- 1.2.9
Changed in this revision
--- a/agenttypesystem.c Thu Jul 12 18:10:30 2018 -0700 +++ b/agenttypesystem.c Tue Sep 11 11:14:37 2018 -0700 @@ -35,7 +35,7 @@ #define PLUSINF_STRING "INF" #ifndef _HUGE_ENUF -#define _HUGE_ENUF 1e+300 /* _HUGE_ENUF*_HUGE_ENUF must overflow */ +#define _HUGE_ENUF 1e+300 /* _HUGE_ENUF*_HUGE_ENUF must overflow */ #endif /* _HUGE_ENUF */ #ifndef INFINITY @@ -182,7 +182,7 @@ else if (ValidateDate(v.dateTime.tm_year+1900, v.dateTime.tm_mon +1 , v.dateTime.tm_mday) != 0) { /*Codes_SRS_AGENT_TYPE_SYSTEM_99_092:[ The structure shall be validated to be conforming to OData specifications (odata-abnf-construction-rules, 2013), and if found invalid, AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/ - result = AGENT_DATA_TYPES_INVALID_ARG; + result = AGENT_DATA_TYPES_INVALID_ARG; } else if ( (v.dateTime.tm_hour > 23) || @@ -202,7 +202,7 @@ result = AGENT_DATA_TYPES_INVALID_ARG; } else if ( - (v.hasTimeZone) && + (v.hasTimeZone) && ( (v.timeZoneHour<-23) || (v.timeZoneHour>23) || @@ -1286,7 +1286,7 @@ AGENT_DATA_TYPES_RESULT AgentDataTypes_ToString(STRING_HANDLE destination, const AGENT_DATA_TYPE* value) { AGENT_DATA_TYPES_RESULT result; - + /*Codes_SRS_AGENT_TYPE_SYSTEM_99_015:[If destination parameter is NULL, AgentDataTypes_ToString shall return AGENT_DATA_TYPES_INVALID_ARG.]*/ if(destination == NULL) { @@ -1698,7 +1698,7 @@ } buffertemp2[pos++] = '0' + (char)(positiveValue); buffertemp2[pos++] = '\0'; - + if (STRING_concat(destination, buffertemp2) != 0) { result = AGENT_DATA_TYPES_ERROR; @@ -1741,7 +1741,7 @@ } buffertemp2[pos++] = '0' + (char)(positiveValue); buffertemp2[pos++] = '\0'; - + if (STRING_concat(destination, buffertemp2) != 0) { result = AGENT_DATA_TYPES_ERROR; @@ -2148,7 +2148,7 @@ { /*all is fine*/ } - + } MultiTree_Destroy(treeHandle); @@ -2286,7 +2286,7 @@ temp[destinationPointer++] = '='; temp[destinationPointer++] = '='; } - + /*closing quote*/ temp[destinationPointer++] = '"'; /*null terminating the string*/ @@ -2464,7 +2464,7 @@ break; } case(EDM_DOUBLE_TYPE) : - { + { dest->type = src->type; dest->value.edmDouble = src->value.edmDouble; result = AGENT_DATA_TYPES_OK; @@ -2929,7 +2929,7 @@ } } } - + } } @@ -3006,7 +3006,7 @@ } return result; - + } /*the following function does the same as sscanf(pos2, "%d", &sec)*/ @@ -3407,7 +3407,7 @@ else { size_t pos = 1; - int sign; + int sign; scanOptionalMinusSign(source, 2, &pos, &sign); if ((scanAndReadNDigitsInt(source, &pos, &year, 4) != 0) || @@ -3463,7 +3463,7 @@ size_t pos = 1; int sign; scanOptionalMinusSign(source, 2, &pos, &sign); - + if ((scanAndReadNDigitsInt(source, &pos, &year, 4) != 0) || (source[pos++] != '-') || (scanAndReadNDigitsInt(source, &pos, &month, 2) != 0) || @@ -3730,7 +3730,7 @@ result = AGENT_DATA_TYPES_ERROR; LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result)); } - else if (strncpy_s(temp, strLength - 1, source + 1, strLength - 2) != 0) + else if (memcpy(temp, source + 1, strLength - 2) == NULL) { free(temp); @@ -3739,8 +3739,8 @@ } else { + // Removes the " temp[strLength - 2] = 0; - agentData->type = EDM_STRING_TYPE; agentData->value.edmString.chars = temp; agentData->value.edmString.length = strLength - 2; @@ -3922,7 +3922,7 @@ { sourcePosition += consumed; destinationPosition += 2; - + } else if (scanbase64b8(source + sourcePosition, sourceLength - sourcePosition, &consumed, agentData->value.edmBinary.data + destinationPosition) == 0) { @@ -3931,7 +3931,7 @@ } if (source[sourcePosition++] != '"') /*if it doesn't end with " then bail out*/ - { + { free(agentData->value.edmBinary.data); agentData->value.edmBinary.data = NULL; result = AGENT_DATA_TYPES_INVALID_ARG;
--- a/agenttypesystem.h Thu Jul 12 18:10:30 2018 -0700 +++ b/agenttypesystem.h Tue Sep 11 11:14:37 2018 -0700 @@ -49,7 +49,7 @@ #define EDM_BOOLEANS_VALUES \ EDM_TRUE, \ - EDM_FALSE + EDM_FALSE DEFINE_ENUM(EDM_BOOLEANS, EDM_BOOLEANS_VALUES); @@ -66,7 +66,7 @@ #error update this file to contain the latest C standard. #endif #else -#ifdef __cplusplus +#ifdef __cplusplus #define ISPOSITIVEINFINITY(x) (std::isinf((x)) && (signbit((x))==0)) #else #error unknown (or C89) compiler, must provide a definition for ISPOSITIVEINFINITY @@ -86,7 +86,7 @@ #error update this file to contain the latest C standard. #endif #else -#ifdef __cplusplus +#ifdef __cplusplus #define ISNEGATIVEINFINITY(x) (std::isinf((x)) && (signbit((x)) != 0)) #else #error unknown (or C89) compiler, must provide a definition for ISNEGATIVEINFINITY
--- a/codefirst.c Thu Jul 12 18:10:30 2018 -0700 +++ b/codefirst.c Tue Sep 11 11:14:37 2018 -0700 @@ -39,9 +39,9 @@ or call directly an API (that will set automatically g_OverrideSchemaNamespace to NULL). To switch to NOT INIT state, depending on the method used to initialize: - - if CodeFirst_Init was called, then only by a call to CodeFirst_Deinit the switch will take place + - if CodeFirst_Init was called, then only by a call to CodeFirst_Deinit the switch will take place (note how in this case g_OverrideSchemaNamespace survives destruction of all devices). - - if the init has been done "lazily" by an API call then the module returns to uninitialized state + - if the init has been done "lazily" by an API call then the module returns to uninitialized state when the number of devices reaches zero. +-----------------------------+ @@ -73,7 +73,7 @@ #define CODEFIRST_STATE_VALUES \ CODEFIRST_STATE_NOT_INIT, \ CODEFIRST_STATE_INIT_BY_INIT, \ - CODEFIRST_STATE_INIT_BY_API + CODEFIRST_STATE_INIT_BY_API DEFINE_ENUM(CODEFIRST_STATE, CODEFIRST_STATE_VALUES) @@ -157,7 +157,7 @@ { /* Codes_SRS_CODEFIRST_99_085:[CodeFirst_DestroyDevice shall free all resources associated with a device.] */ /* Codes_SRS_CODEFIRST_99_087:[In order to release the device handle, CodeFirst_DestroyDevice shall call Device_Destroy.] */ - + Device_Destroy(deviceHeader->DeviceHandle); free(deviceHeader->data); free(deviceHeader); @@ -301,13 +301,13 @@ } else { - if (Schema_AddModelDesiredProperty(modelTypeHandle, - something->what.desiredProperty.name, - something->what.desiredProperty.type, - something->what.desiredProperty.FromAGENT_DATA_TYPE, - something->what.desiredProperty.desiredPropertInitialize, - something->what.desiredProperty.desiredPropertDeinitialize, - something->what.desiredProperty.offset, + if (Schema_AddModelDesiredProperty(modelTypeHandle, + something->what.desiredProperty.name, + something->what.desiredProperty.type, + something->what.desiredProperty.FromAGENT_DATA_TYPE, + something->what.desiredProperty.desiredPropertInitialize, + something->what.desiredProperty.desiredPropertDeinitialize, + something->what.desiredProperty.offset, something->what.desiredProperty.onDesiredProperty) != SCHEMA_OK) { /*Codes_SRS_CODEFIRST_99_076:[If any Schema APIs fail, CODEFIRST_SCHEMA_ERROR shall be returned.]*/ @@ -738,7 +738,7 @@ { return EDM_SINGLE_TYPE; } - else + else #endif if (strcmp(typeName, "int") == 0) { @@ -892,7 +892,7 @@ { /*Codes_SRS_CODEFIRST_02_037: [ CodeFirst_CreateDevice shall call CodeFirst_Init, passing NULL for overrideSchemaNamespace. ]*/ (void)CodeFirst_Init_impl(NULL, false); /*lazy init*/ - + if ((deviceHeader = (DEVICE_HEADER_DATA*)malloc(sizeof(DEVICE_HEADER_DATA))) == NULL) { /* Codes_SRS_CODEFIRST_99_102:[On any other errors, Device_Create shall return NULL.] */ @@ -916,7 +916,7 @@ initializeDesiredProperties(model, deviceHeader->data); - if (Device_Create(model, CodeFirst_InvokeAction, deviceHeader, CodeFirst_InvokeMethod, deviceHeader, + if (Device_Create(model, CodeFirst_InvokeAction, deviceHeader, CodeFirst_InvokeMethod, deviceHeader, includePropertyPath, &deviceHeader->DeviceHandle) != DEVICE_OK) { free(deviceHeader->data); @@ -946,6 +946,7 @@ if (schemaResult != SCHEMA_OK) { Device_Destroy(deviceHeader->DeviceHandle); + free(newDevices); free(deviceHeader->data); free(deviceHeader); @@ -964,7 +965,7 @@ } } } - + } return result; @@ -1194,8 +1195,8 @@ va_list ap; if ( - (numProperties == 0) || - (destination == NULL) || + (numProperties == 0) || + (destination == NULL) || (destinationSize == NULL) ) { @@ -1208,7 +1209,7 @@ { /*Codes_SRS_CODEFIRST_02_040: [ CodeFirst_SendAsync shall call CodeFirst_Init, passing NULL for overrideSchemaNamespace. ]*/ (void)CodeFirst_Init_impl(NULL, false); /*lazy init*/ - + DEVICE_HEADER_DATA* deviceHeader = NULL; size_t i; TRANSACTION_HANDLE transaction = NULL; @@ -1356,7 +1357,7 @@ } va_end(ap); - + } return result; @@ -1375,7 +1376,7 @@ { /*Codes_SRS_CODEFIRST_02_046: [ CodeFirst_SendAsyncReported shall call CodeFirst_Init, passing NULL for overrideSchemaNamespace. ]*/ (void)CodeFirst_Init_impl(NULL, false);/*lazy init*/ - + DEVICE_HEADER_DATA* deviceHeader = NULL; size_t i; REPORTED_PROPERTIES_TRANSACTION_HANDLE transaction = NULL;
--- a/commanddecoder.c Thu Jul 12 18:10:30 2018 -0700 +++ b/commanddecoder.c Tue Sep 11 11:14:37 2018 -0700 @@ -103,7 +103,7 @@ else { memberNames[j] = propertyName; - + /* Codes_SRS_COMMAND_DECODER_01_014: [CommandDecoder shall use the MultiTree APIs to extract a specific element from the command JSON.] */ if (MultiTree_GetChildByName(node, memberNames[j], &memberNode) != MULTITREE_OK) { @@ -181,6 +181,12 @@ LogError("Invalid action name"); result = EXECUTE_COMMAND_ERROR; } + else if (strLength >= 128) + { + /* Codes_SRS_COMMAND_DECODER_99_021:[ If the parsing of the command fails for any other reason the command shall not be dispatched.] */ + LogError("Invalid action name length"); + result = EXECUTE_COMMAND_ERROR; + } else { /* Codes_SRS_COMMAND_DECODER_99_006:[ The action name shall be decoded from the element "Name" of the command JSON.] */ @@ -188,10 +194,7 @@ size_t argCount; MULTITREE_HANDLE parametersTreeNode; -#ifdef _MSC_VER -#pragma warning(suppress: 6324) /* We intentionally use here strncpy */ -#endif - if (strncpy(tempStr, actionName, strLength - 1) == NULL) + if (memcpy(tempStr, actionName, strLength-1) == NULL) { /* Codes_SRS_COMMAND_DECODER_99_021:[ If the parsing of the command fails for any other reason the command shall not be dispatched.] */ LogError("Invalid action name."); @@ -206,8 +209,7 @@ } else { - tempStr[strLength - 1] = 0; - + tempStr[strLength-1] = 0; /* Codes_SRS_COMMAND_DECODER_99_009:[ CommandDecoder shall call Schema_GetModelActionByName to obtain the information about a specific action.] */ if (((modelActionHandle = Schema_GetModelActionByName(modelHandle, tempStr)) == NULL) || (Schema_GetModelActionArgumentCount(modelActionHandle, &argCount) != SCHEMA_OK)) @@ -309,9 +311,9 @@ size_t argCount; #ifdef _MSC_VER -#pragma warning(suppress: 6324) /* We intentionally use here strncpy */ +#pragma warning(suppress: 6324) /* We intentionally use here strncpy */ #endif - + /*Codes_SRS_COMMAND_DECODER_02_020: [ CommandDecoder_ExecuteMethod shall verify that the model has a method called methodName. ]*/ if (((modelMethodHandle = Schema_GetModelMethodByName(modelHandle, methodName)) == NULL) || (Schema_GetModelMethodArgumentCount(modelMethodHandle, &argCount) != SCHEMA_OK)) @@ -323,7 +325,7 @@ else { /*Codes_SRS_COMMAND_DECODER_02_021: [ For every argument of methodName, CommandDecoder_ExecuteMethod shall build an AGENT_DATA_TYPE from the node with the same name from the MULTITREE_HANDLE. ]*/ - + if (argCount == 0) { /*no need for any parameters*/ @@ -393,7 +395,7 @@ } } - + } return result; } @@ -624,7 +626,7 @@ else { result = ScanMethodPathAndExecuteMethod(commandDecoderInstance, schemaHandle, fullMethodName, methodTree); - + } return result; } @@ -637,7 +639,7 @@ /*Codes_SRS_COMMAND_DECODER_01_010: [If either the buffer or the receiveCallbackContext argument is NULL, the processing shall stop and the command shall not be dispatched and it shall return EXECUTE_COMMAND_ERROR.]*/ if ( (command == NULL) || - (commandDecoderInstance == NULL) + (commandDecoderInstance == NULL) ) { LogError("Invalid argument, COMMAND_DECODER_HANDLE handle=%p, const char* command=%p", handle, command); @@ -800,7 +802,7 @@ /*if the serialization does not contain mandatory items from the model, it fails*/ static bool validateModel_vs_Multitree(void* startAddress, SCHEMA_MODEL_TYPE_HANDLE modelHandle, MULTITREE_HANDLE desiredPropertiesTree, size_t offset) { - + bool result; size_t nChildren; size_t nProcessedChildren = 0; @@ -842,13 +844,13 @@ } case (SCHEMA_PROPERTY): { - LogError("cannot ingest name (WITH_DATA instead of WITH_DESIRED_PROPERTY): %s", STRING_c_str); + LogError("cannot ingest name (WITH_DATA instead of WITH_DESIRED_PROPERTY): %s", childName_str); i = nChildren; break; } case (SCHEMA_REPORTED_PROPERTY): { - LogError("cannot ingest name (WITH_REPORTED_PROPERTY instead of WITH_DESIRED_PROPERTY): %s", STRING_c_str); + LogError("cannot ingest name (WITH_REPORTED_PROPERTY instead of WITH_DESIRED_PROPERTY): %s", childName_str); i = nChildren; break; } @@ -856,7 +858,7 @@ { /*Codes_SRS_COMMAND_DECODER_02_007: [ If the child name corresponds to a desired property then an AGENT_DATA_TYPE shall be constructed from the MULTITREE node. ]*/ SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle = elementType.elementHandle.desiredPropertyHandle; - + const char* desiredPropertyType = Schema_GetModelDesiredPropertyType(desiredPropertyHandle); AGENT_DATA_TYPE output; if (DecodeValueFromNode(Schema_GetSchemaForModelType(modelHandle), &output, child, desiredPropertyType) != 0) @@ -884,13 +886,13 @@ } Destroy_AGENT_DATA_TYPE(&output); } - + break; } case(SCHEMA_MODEL_IN_MODEL): { SCHEMA_MODEL_TYPE_HANDLE modelModel = elementType.elementHandle.modelHandle; - + /*Codes_SRS_COMMAND_DECODER_02_009: [ If the child name corresponds to a model in model then the function shall call itself recursively. ]*/ if (!validateModel_vs_Multitree(startAddress, modelModel, child, offset + Schema_GetModelModelByName_Offset(modelHandle, childName_str))) { @@ -906,10 +908,10 @@ { onDesiredProperty((char*)startAddress + offset); } - + nProcessedChildren++; } - + break; } @@ -980,7 +982,7 @@ EXECUTE_COMMAND_RESULT CommandDecoder_IngestDesiredProperties(void* startAddress, COMMAND_DECODER_HANDLE handle, const char* jsonPayload, bool parseDesiredNode) { EXECUTE_COMMAND_RESULT result; - + /*Codes_SRS_COMMAND_DECODER_02_001: [ If startAddress is NULL then CommandDecoder_IngestDesiredProperties shall fail and return EXECUTE_COMMAND_ERROR. ]*/ /*Codes_SRS_COMMAND_DECODER_02_002: [ If handle is NULL then CommandDecoder_IngestDesiredProperties shall fail and return EXECUTE_COMMAND_ERROR. ]*/ /*Codes_SRS_COMMAND_DECODER_02_003: [ If jsonPayload is NULL then CommandDecoder_IngestDesiredProperties shall fail and return EXECUTE_COMMAND_ERROR. ]*/
--- a/datamarshaller.c Thu Jul 12 18:10:30 2018 -0700 +++ b/datamarshaller.c Tue Sep 11 11:14:37 2018 -0700 @@ -41,7 +41,7 @@ DATA_MARSHALLER_HANDLE_DATA* result; /*Codes_SRS_DATA_MARSHALLER_99_019:[ DataMarshaller_Create shall return NULL if any argument is NULL.]*/ - if (modelHandle == NULL) + if (modelHandle == NULL) { result = NULL; LogError("(result = %s)", ENUM_TO_STRING(DATA_MARSHALLER_RESULT, DATA_MARSHALLER_INVALID_ARG));
--- a/datapublisher.c Thu Jul 12 18:10:30 2018 -0700 +++ b/datapublisher.c Tue Sep 11 11:14:37 2018 -0700 @@ -87,7 +87,7 @@ { DATA_PUBLISHER_HANDLE_DATA* dataPublisherInstance = (DATA_PUBLISHER_HANDLE_DATA*)dataPublisherHandle; DataMarshaller_Destroy(dataPublisherInstance->DataMarshallerHandle); - + free(dataPublisherHandle); } } @@ -383,7 +383,7 @@ /*Codes_SRS_DATA_PUBLISHER_02_011: [ If argument data is NULL then DataPublisher_PublishTransacted_ReportedProperty shall fail and return DATA_PUBLISHER_INVALID_ARG. ]*/ if ( (transactionHandle == NULL) || - (reportedPropertyPath == NULL) || + (reportedPropertyPath == NULL) || (data == NULL) ) {
--- a/dataserializer.h Thu Jul 12 18:10:30 2018 -0700 +++ b/dataserializer.h Tue Sep 11 11:14:37 2018 -0700 @@ -19,7 +19,7 @@ /*Codes_SRS_DATA_SERIALIZER_07_001: [DataSerializer will have the following interface]*/ #define DATA_SERIALIZER_RESULT_VALUES \ DATA_SERIALIZER_INVALID_ARG, \ -DATA_SERIALIZER_ERROR \ +DATA_SERIALIZER_ERROR \ DEFINE_ENUM(DATA_SERIALIZER_RESULT, DATA_SERIALIZER_RESULT_VALUES);
--- a/iotdevice.c Thu Jul 12 18:10:30 2018 -0700 +++ b/iotdevice.c Tue Sep 11 11:14:37 2018 -0700 @@ -385,7 +385,7 @@ { /*Codes_SRS_DEVICE_02_027: [ Device_CommitTransaction_ReportedProperties shall call DataPublisher_CommitTransaction_ReportedProperties. ]*/ DATA_PUBLISHER_RESULT r = DataPublisher_CommitTransaction_ReportedProperties(transactionHandle, destination, destinationSize); - + /*Codes_SRS_DEVICE_02_028: [ If DataPublisher_CommitTransaction_ReportedProperties fails then Device_CommitTransaction_ReportedProperties shall fail and return DEVICE_DATA_PUBLISHER_FAILED. ]*/ if (r != DATA_PUBLISHER_OK) {
--- a/iotdevice.h Thu Jul 12 18:10:30 2018 -0700 +++ b/iotdevice.h Tue Sep 11 11:14:37 2018 -0700 @@ -18,11 +18,11 @@ #include <stddef.h> #endif -#define DEVICE_RESULT_VALUES \ - DEVICE_OK, \ - DEVICE_INVALID_ARG, \ - DEVICE_DATA_PUBLISHER_FAILED, \ - DEVICE_COMMAND_DECODER_FAILED, \ +#define DEVICE_RESULT_VALUES \ + DEVICE_OK, \ + DEVICE_INVALID_ARG, \ + DEVICE_DATA_PUBLISHER_FAILED, \ + DEVICE_COMMAND_DECODER_FAILED, \ DEVICE_ERROR DEFINE_ENUM(DEVICE_RESULT, DEVICE_RESULT_VALUES)
--- a/jsonencoder.h Thu Jul 12 18:10:30 2018 -0700 +++ b/jsonencoder.h Tue Sep 11 11:14:37 2018 -0700 @@ -22,7 +22,7 @@ JSON_ENCODER_ALREADY_EXISTS, \ JSON_ENCODER_MULTITREE_ERROR, \ JSON_ENCODER_TOSTRING_FUNCTION_ERROR, \ -JSON_ENCODER_ERROR +JSON_ENCODER_ERROR DEFINE_ENUM(JSON_ENCODER_RESULT, JSON_ENCODER_RESULT_VALUES);
--- a/methodreturn.h Thu Jul 12 18:10:30 2018 -0700 +++ b/methodreturn.h Tue Sep 11 11:14:37 2018 -0700 @@ -20,7 +20,7 @@ #include "azure_c_shared_utility/umock_c_prod.h" #ifdef __cplusplus -extern "C" +extern "C" { #endif
--- a/multitree.c Thu Jul 12 18:10:30 2018 -0700 +++ b/multitree.c Tue Sep 11 11:14:37 2018 -0700 @@ -94,7 +94,7 @@ }CREATELEAF_RESULT; static STATIC_VAR_UNUSED const char* CreateLeaf_ResultAsString[CREATELEAF_RESULT_COUNT] = -{ +{ TOSTRING(CREATELEAF_OK), TOSTRING(CREATELEAF_ALREADY_EXISTS), TOSTRING(CREATELEAF_EMPTY_NAME), @@ -167,7 +167,7 @@ /*all is fine until now*/ } } - + if (newNode!=NULL) { @@ -216,7 +216,7 @@ { result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); - } + } /*Codes_SRS_MULTITREE_99_019:[ If parameter destinationPath is NULL, MULTITREE_INVALID_ARG shall be returned.]*/ else if (destinationPath == NULL) { @@ -289,14 +289,21 @@ /*if there's more or 1 delimiter in the path... */ /*Codes_SRS_MULTITREE_99_017:[ Subsequent names designate hierarchical children in the tree. The last child designates the child that will receive the value.]*/ char firstInnerNodeName[INNER_NODE_NAME_SIZE]; - if (strncpy_s(firstInnerNodeName, INNER_NODE_NAME_SIZE, destinationPath, whereIsDelimiter - destinationPath) != 0) + if ((whereIsDelimiter - destinationPath) >= INNER_NODE_NAME_SIZE) { /*Codes_SRS_MULTITREE_99_025:[ The function shall return MULTITREE_ERROR to indicate any other error not specified here.]*/ result = MULTITREE_ERROR; - LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); + LogError("Destination path is too large %d", whereIsDelimiter - destinationPath); + } + else if (memcpy(firstInnerNodeName, destinationPath, whereIsDelimiter - destinationPath) == NULL) + { + /*Codes_SRS_MULTITREE_99_025:[ The function shall return MULTITREE_ERROR to indicate any other error not specified here.]*/ + result = MULTITREE_ERROR; + LogError("(result = MULTITREE_ERROR)"); } else { + firstInnerNodeName[whereIsDelimiter - destinationPath] = 0; MULTITREE_HANDLE_DATA *child = getChildByName(node, firstInnerNodeName); if (child == NULL) { @@ -396,13 +403,13 @@ MULTITREE_RESULT result; /*Codes_SRS_MULTITREE_99_027:[If treeHandle is NULL, the function returns MULTITREE_INVALID_ARG.]*/ if (treeHandle == NULL) - { + { result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } /*Codes_SRS_MULTITREE_99_028:[ If parameter count is NULL, the function returns MULTITREE_INVALID_ARG.]*/ else if (count == NULL) - { + { result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } @@ -431,7 +438,7 @@ result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } - else + else { MULTITREE_HANDLE_DATA * node = (MULTITREE_HANDLE_DATA *)treeHandle; /*Codes_SRS_MULTITREE_99_032:[If parameter index is out of range, the function shall return MULTITREE_OUT_OF_RANGE_INDEX]*/ @@ -760,7 +767,7 @@ LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } /*Codes_SRS_MULTITREE_99_053:[ MultiTree_GetLeafValue shall copy into the *destination argument the value of the node identified by the leafPath argument.]*/ - else + else { *destination = node->value; /* Codes_SRS_MULTITREE_99_054:[ On success, MultiTree_GetLeafValue shall return MULTITREE_OK.] */
--- a/schema.c Thu Jul 12 18:10:30 2018 -0700 +++ b/schema.c Tue Sep 11 11:14:37 2018 -0700 @@ -134,7 +134,7 @@ if (action != NULL) { size_t j; - + for (j = 0; j < action->ArgumentCount; j++) { DestroyActionArgument(action->ArgumentHandles[j]); @@ -328,15 +328,22 @@ /* If possible, reduce the memory of over allocation */ if (result != SCHEMA_OK) { - SCHEMA_PROPERTY_HANDLE* oldProperties = (SCHEMA_PROPERTY_HANDLE*)realloc(modelType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * modelType->PropertyCount); - if (oldProperties == NULL) + if (modelType->PropertyCount > 0) { - result = SCHEMA_ERROR; - LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); + SCHEMA_PROPERTY_HANDLE *oldProperties = (SCHEMA_PROPERTY_HANDLE *)realloc(modelType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * modelType->PropertyCount); + if (oldProperties == NULL) + { + result = SCHEMA_ERROR; + LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); + } + else + { + modelType->Properties = oldProperties; + } } else { - modelType->Properties = oldProperties; + modelType->Properties = NULL; } } } @@ -431,7 +438,7 @@ SCHEMA_HANDLE* handle = (g_schemas==NULL)?NULL:(SCHEMA_HANDLE*)VECTOR_find_if(g_schemas, (PREDICATE_FUNCTION)SchemaNamespacesMatch, schemaNamespace); if (handle != NULL) { - /* Codes_SRS_SCHEMA_99_148: [Schema_GetSchemaByNamespace shall search all active schemas and return the schema with the + /* Codes_SRS_SCHEMA_99_148: [Schema_GetSchemaByNamespace shall search all active schemas and return the schema with the namespace given by the schemaNamespace argument.] */ result = *handle; } @@ -918,14 +925,21 @@ /* If possible, reduce the memory of over allocation */ if (result == NULL) { - SCHEMA_ACTION_HANDLE* oldActions = (SCHEMA_ACTION_HANDLE*)realloc(modelType->Actions, sizeof(SCHEMA_ACTION_HANDLE) * modelType->ActionCount); - if (oldActions == NULL) + if (modelType->ActionCount > 0) { - LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); + SCHEMA_ACTION_HANDLE *oldActions = (SCHEMA_ACTION_HANDLE *)realloc(modelType->Actions, sizeof(SCHEMA_ACTION_HANDLE) * modelType->ActionCount); + if (oldActions == NULL) + { + LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); + } + else + { + modelType->Actions = oldActions; + } } else { - modelType->Actions = oldActions; + modelType->Actions = NULL; } } } @@ -1066,7 +1080,11 @@ } else { + action->ArgumentHandles = newArguments; + SCHEMA_ACTION_ARGUMENT_HANDLE_DATA* newActionArgument; + + action->ArgumentHandles = newArguments; if ((newActionArgument = (SCHEMA_ACTION_ARGUMENT_HANDLE_DATA*)malloc(sizeof(SCHEMA_ACTION_ARGUMENT_HANDLE_DATA))) == NULL) { /* Codes_SRS_SCHEMA_99_112: [On any other error, Schema_ AddModelActionArgumet shall return SCHEMA_ERROR.] */ @@ -1092,7 +1110,6 @@ } else { - action->ArgumentHandles = newArguments; /* Codes_SRS_SCHEMA_99_119: [Schema_AddModelActionArgument shall preserve the order of the action arguments according to the order in which they were added, starting with index 0 for the first added argument.] */ action->ArgumentHandles[action->ArgumentCount] = newActionArgument; action->ArgumentCount++; @@ -1105,14 +1122,21 @@ /* If possible, reduce the memory of over allocation */ if (result == SCHEMA_ERROR) { - SCHEMA_ACTION_ARGUMENT_HANDLE* oldArguments = (SCHEMA_ACTION_ARGUMENT_HANDLE*)realloc(action->ArgumentHandles, sizeof(SCHEMA_ACTION_ARGUMENT_HANDLE) * action->ArgumentCount); - if (oldArguments == NULL) + if (action->ArgumentCount > 0) { - LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); + SCHEMA_ACTION_ARGUMENT_HANDLE *oldArguments = (SCHEMA_ACTION_ARGUMENT_HANDLE *)realloc(action->ArgumentHandles, sizeof(SCHEMA_ACTION_ARGUMENT_HANDLE) * action->ArgumentCount); + if (oldArguments == NULL) + { + LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); + } + else + { + action->ArgumentHandles = oldArguments; + } } else { - action->ArgumentHandles = oldArguments; + action->ArgumentHandles = NULL; } } } @@ -1807,15 +1831,22 @@ /* If possible, reduce the memory of over allocation */ if (result == NULL) { - SCHEMA_STRUCT_TYPE_HANDLE* oldStructTypes = (SCHEMA_STRUCT_TYPE_HANDLE*)realloc(schema->StructTypes, sizeof(SCHEMA_STRUCT_TYPE_HANDLE) * schema->StructTypeCount); - if (oldStructTypes == NULL) + if (schema->StructTypeCount > 0) { - result = NULL; - LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); + SCHEMA_STRUCT_TYPE_HANDLE *oldStructTypes = (SCHEMA_STRUCT_TYPE_HANDLE *)realloc(schema->StructTypes, sizeof(SCHEMA_STRUCT_TYPE_HANDLE) * schema->StructTypeCount); + if (oldStructTypes == NULL) + { + result = NULL; + LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); + } + else + { + schema->StructTypes = oldStructTypes; + } } else { - schema->StructTypes = oldStructTypes; + schema->StructTypes = NULL; } } } @@ -1840,7 +1871,7 @@ /* Codes_SRS_SCHEMA_99_135: [Schema_GetStructTypeName shall return the name of a struct type identified by the structTypeHandle argument.] */ result = ((SCHEMA_STRUCT_TYPE_HANDLE_DATA*)structTypeHandle)->Name; } - + return result; } @@ -2011,15 +2042,22 @@ /* If possible, reduce the memory of over allocation */ if (result != SCHEMA_OK) { - SCHEMA_PROPERTY_HANDLE* oldProperties = (SCHEMA_PROPERTY_HANDLE*)realloc(structType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * structType->PropertyCount); - if (oldProperties == NULL) + if (structType->PropertyCount > 0) { - result = SCHEMA_ERROR; - LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); + SCHEMA_PROPERTY_HANDLE *oldProperties = (SCHEMA_PROPERTY_HANDLE *)realloc(structType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * structType->PropertyCount); + if (oldProperties == NULL) + { + result = SCHEMA_ERROR; + LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); + } + else + { + structType->Properties = oldProperties; + } } else { - structType->Properties = oldProperties; + structType->Properties = NULL; } } } @@ -2235,7 +2273,7 @@ else { - /* Codes_SRS_SCHEMA_99_126: [Schema_GetModelByIndex shall return a non-NULL SCHEMA_MODEL_TYPE_HANDLE corresponding to the model identified by schemaHandle and matching the index number provided by the index argument.] */ + /* Codes_SRS_SCHEMA_99_126: [Schema_GetModelByIndex shall return a non-NULL SCHEMA_MODEL_TYPE_HANDLE corresponding to the model identified by schemaHandle and matching the index number provided by the index argument.] */ /* Codes_SRS_SCHEMA_99_127: [The index argument is zero based, and the order in which models were added shall be the index in which they will be retrieved.] */ result = schema->ModelTypes[index]; } @@ -2294,7 +2332,7 @@ else { /*Codes_SRS_SCHEMA_99_164: [If the function succeeds, then the return value shall be SCHEMA_OK.]*/ - + result = SCHEMA_OK; } } @@ -2459,7 +2497,7 @@ SCHEMA_MODEL_TYPE_HANDLE Schema_GetModelModelyByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index) { SCHEMA_MODEL_TYPE_HANDLE result; - if (modelTypeHandle == NULL) + if (modelTypeHandle == NULL) { /*Codes_SRS_SCHEMA_99_173: [Schema_GetModelModelyByIndex shall return NULL in the cases when it cannot provide the handle.]*/ result = NULL;
--- a/schemalib.h Thu Jul 12 18:10:30 2018 -0700 +++ b/schemalib.h Tue Sep 11 11:14:37 2018 -0700 @@ -2,8 +2,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. /** @file schemalib.h - * @brief The IoT Hub Serializer APIs allows developers to define models for -* their devices + * @brief The IoT Hub Serializer APIs allows developers to define models for +* their devices */ #ifndef SCHEMALIB_H @@ -32,7 +32,7 @@ SERIALIZER_GET_MODEL_HANDLE_FAILED, \ SERIALIZER_SERVICEBUS_FAILED -/** @brief Enumeration specifying the status of calls to various APIs in this +/** @brief Enumeration specifying the status of calls to various APIs in this * module. */ DEFINE_ENUM(SERIALIZER_RESULT, SERIALIZER_RESULT_VALUES); @@ -41,7 +41,7 @@ CommandPollingInterval, \ SerializeDelayedBufferMaxSize -/** @brief Enumeration specifying the option to set on the serializer when +/** @brief Enumeration specifying the option to set on the serializer when * calling ::serializer_setconfig. */ DEFINE_ENUM(SERIALIZER_CONFIG, SERIALIZER_CONFIG_VALUES); @@ -55,13 +55,13 @@ * If @p schemaNamespace is not @c NULL, its value shall be used * instead of the namespace defined for each model by using the * @c DECLARE_XXX macro. - * + * * @return @c SERIALIZER_OK on success and any other error on failure. */ extern SERIALIZER_RESULT serializer_init(const char* overrideSchemaNamespace); -/** @brief Shuts down the IOT library. - * +/** @brief Shuts down the IOT library. + * * The library will track all created devices and upon a call to * ::serializer_deinit it will de-initialize all devices. */
--- a/schemaserializer.h Thu Jul 12 18:10:30 2018 -0700 +++ b/schemaserializer.h Tue Sep 11 11:14:37 2018 -0700 @@ -11,8 +11,8 @@ extern "C" { #endif -#define SCHEMA_SERIALIZER_RESULT_VALUES \ - SCHEMA_SERIALIZER_OK, \ +#define SCHEMA_SERIALIZER_RESULT_VALUES \ + SCHEMA_SERIALIZER_OK, \ SCHEMA_SERIALIZER_INVALID_ARG, \ SCHEMA_SERIALIZER_ERROR
--- a/serializer.h Thu Jul 12 18:10:30 2018 -0700 +++ b/serializer.h Tue Sep 11 11:14:37 2018 -0700 @@ -2,35 +2,35 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. /** @file serializer.h -* @brief The IoT Hub Serializer APIs allows developers to define models for -* their devices +* @brief The IoT Hub Serializer APIs allows developers to define models for +* their devices * -* @details The IoT Hub Serializer APIs allows developers to quickly and easily define -* models for their devices directly as code, while supporting the required -* features for modeling devices (including multiple models and multiple -* devices within the same application). For example: -* -* <pre> +* @details The IoT Hub Serializer APIs allows developers to quickly and easily define +* models for their devices directly as code, while supporting the required +* features for modeling devices (including multiple models and multiple +* devices within the same application). For example: +* +* <pre> * BEGIN_NAMESPACE(Contoso); -* +* * DECLARE_STRUCT(SystemProperties, * ascii_char_ptr, DeviceID, * _Bool, Enabled * ); -* +* * DECLARE_MODEL(VendingMachine, -* +* * WITH_DATA(int, SensorValue), -* +* * WITH_DATA(ascii_char_ptr, ObjectName), * WITH_DATA(ascii_char_ptr, ObjectType), * WITH_DATA(ascii_char_ptr, Version), * WITH_DATA(SystemProperties, SystemProperties), * WITH_DATA(ascii_char_ptr_no_quotes, Commands), -* +* * WITH_ACTION(SetItemPrice, ascii_char_ptr, itemId, ascii_char_ptr, price) * ); -* +* * END_NAMESPACE(Contoso); * </pre> */ @@ -148,12 +148,12 @@ * * @param name Specifies the model name * @param element1, element2... Specifies a model element which can be - * a property or an action. - * - A property is described in a - * model by using the WITH_DATA - * - An action is described in a - * model by using the ::WITH_ACTION - * macro. + * a property or an action. + * - A property is described in a + * model by using the WITH_DATA + * - An action is described in a + * model by using the ::WITH_ACTION + * macro. * */ /* WITH_DATA's name argument shall be one of the following data types: */ @@ -163,7 +163,7 @@ #define CREATE_DESIRED_PROPERTY_CALLBACK_MODEL_METHOD(...) #define CREATE_DESIRED_PROPERTY_CALLBACK_MODEL_DESIRED_PROPERTY(type, name, ...) IF(COUNT_ARG(__VA_ARGS__), void __VA_ARGS__ (void*);, ) #define CREATE_DESIRED_PROPERTY_CALLBACK_MODEL_PROPERTY(...) -#define CREATE_DESIRED_PROPERTY_CALLBACK_MODEL_REPORTED_PROPERTY(...) +#define CREATE_DESIRED_PROPERTY_CALLBACK_MODEL_REPORTED_PROPERTY(...) #define CREATE_DESIRED_PROPERTY_CALLBACK(...) CREATE_DESIRED_PROPERTY_CALLBACK_##__VA_ARGS__ @@ -193,7 +193,7 @@ FOR_EACH_1_KEEP_1(CREATE_MODEL_ELEMENT_GLOBAL_DEINITIALIZE, name, __VA_ARGS__) \ } \ - + /** * @def WITH_DATA(type, name) @@ -217,7 +217,7 @@ * - EDM_GUID * - EDM_BINARY * - Any struct type previously introduced by another ::DECLARE_STRUCT. - * + * * @param name Specifies the property name */ #define WITH_DATA(type, name) MODEL_PROPERTY(type, name) @@ -258,7 +258,7 @@ * The ::GET_MODEL_HANDLE macro returns a model handle that can be used in * subsequent operations like generating the CSDL schema for the model, * uploading the schema, creating a device, etc. - * + * * @param schemaNamespace The namespace to which the model belongs. * @param modelName The name of the model. */ @@ -290,7 +290,7 @@ /** * @def SERIALIZE(destination, destinationSize,...) * This macro produces JSON serialized representation of the properties. - * + * * @param destination Pointer to an @c unsigned @c char* that * will receive the serialized data. * @param destinationSize Pointer to a @c size_t that gets @@ -388,9 +388,9 @@ #define TO_AGENT_DT_EXPAND_MODEL_DESIRED_PROPERTY(x, y, ...) ,x,y -#define TO_AGENT_DT_EXPAND_MODEL_ACTION(...) +#define TO_AGENT_DT_EXPAND_MODEL_ACTION(...) -#define TO_AGENT_DT_EXPAND_MODEL_METHOD(...) +#define TO_AGENT_DT_EXPAND_MODEL_METHOD(...) #define TO_AGENT_DT_EXPAND_ELEMENT_ARGS(N, ...) TO_AGENT_DT_EXPAND_##__VA_ARGS__ @@ -435,7 +435,7 @@ return result; \ } -#define FIELD_AS_STRING(x,y) memberNames[iMember++] = #y; +#define FIELD_AS_STRING(x,y) memberNames[iMember++] = #y; #define REFLECTED_LIST_HEAD(name) \ static const REFLECTED_DATA_FROM_DATAPROVIDER ALL_REFLECTED(name) = { &C2(REFLECTED_, C1(DEC(__COUNTER__))) }; @@ -675,7 +675,7 @@ #define UNBUILD_DESTINATION_FIELD(value, type, name) \ C2(destroyLocalParameter, type)(&(value->name)); - + #define ADDRESS_MACRO(x) ,&x @@ -700,7 +700,7 @@ #define CASTMAP__Bool 0!=, 0!= #define CASTMAP_bool 0!=, 0!= -#define EMPTY_TOKEN +#define EMPTY_TOKEN #define ANOTHERIF(x) C2(ANOTHERIF,x) #define ANOTHERIF0(a,b) a @@ -801,7 +801,7 @@ #define END_BUILD_LOCAL_PARAMETER(type, name) \ (void)C2(destroyLocalParameter, type)(&C2(name, _local)); \ - } + } /*The following constructs have been devised to work around the precompiler bug of Visual Studio 2005, version 14.00.50727.42*/ /* The bug is explained in https://connect.microsoft.com/VisualStudio/feedback/details/278752/comma-missing-when-using-va-args */ @@ -1176,7 +1176,7 @@ { result = AGENT_DATA_TYPES_OK; } - + } return result; } @@ -1500,7 +1500,7 @@ { free(*value); } - + } static void C2(destroyLocalParameter, ascii_char_ptr_no_quotes)(ascii_char_ptr_no_quotes* value)
--- a/serializer_devicetwin.h Thu Jul 12 18:10:30 2018 -0700 +++ b/serializer_devicetwin.h Tue Sep 11 11:14:37 2018 -0700 @@ -41,7 +41,7 @@ { /*all is fine*/ } - + free(copyOfPayload); } } @@ -67,7 +67,7 @@ /*Codes_SRS_SERIALIZERDEVICETWIN_02_022: [ deviceMethodCallback shall call EXECUTE_METHOD passing the userContextCallback, method_name and the null terminated string build before. ]*/ METHODRETURN_HANDLE mr = EXECUTE_METHOD(userContextCallback, method_name, payloadZeroTerminated); - + if (mr == NULL) { LogError("failure in EXECUTE_METHOD"); @@ -138,7 +138,7 @@ IOTHUB_CLIENT_HANDLE_VARIANT iothubClientHandleVariant; void* deviceAssigned; } SERIALIZER_DEVICETWIN_PROTOHANDLE; - + static VECTOR_HANDLE g_allProtoHandles=NULL; /*contains SERIALIZER_DEVICETWIN_PROTOHANDLE*/ static int lazilyAddProtohandle(const SERIALIZER_DEVICETWIN_PROTOHANDLE* protoHandle)