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

Committer:
AzureIoTClient
Date:
Tue Jan 24 15:24:19 2017 -0800
Revision:
21:6d3dea1abd9c
Parent:
16:ef107f3f230c
Child:
22:422d94bd3c18
1.1.5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 0:1f9b2707ec7d 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 0:1f9b2707ec7d 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 0:1f9b2707ec7d 3
AzureIoTClient 0:1f9b2707ec7d 4 #include <stdlib.h>
Azure.IoT Build 10:c2aee3965a83 5 #include "azure_c_shared_utility/gballoc.h"
AzureIoTClient 0:1f9b2707ec7d 6
AzureIoTClient 0:1f9b2707ec7d 7 #include "agenttypesystem.h"
Azure.IoT Build 9:747680124ff7 8 #include <inttypes.h>
AzureIoTClient 0:1f9b2707ec7d 9
AzureIoTClient 0:1f9b2707ec7d 10 #ifdef _MSC_VER
AzureIoTClient 0:1f9b2707ec7d 11 #pragma warning(disable: 4756) /* Known warning for INFINITY */
AzureIoTClient 0:1f9b2707ec7d 12 #endif
AzureIoTClient 0:1f9b2707ec7d 13
AzureIoTClient 0:1f9b2707ec7d 14 #include <stddef.h>
AzureIoTClient 0:1f9b2707ec7d 15
AzureIoTClient 0:1f9b2707ec7d 16 #include <float.h>
AzureIoTClient 0:1f9b2707ec7d 17 #include <math.h>
Azure.IoT Build 9:747680124ff7 18 #include <limits.h>
AzureIoTClient 14:0c00e67a4ab1 19 #include <errno.h>
Azure.IoT Build 9:747680124ff7 20
Azure.IoT Build 9:747680124ff7 21 /*if ULLONG_MAX is defined by limits.h for whatever reasons... */
Azure.IoT Build 9:747680124ff7 22 #ifndef ULLONG_MAX
Azure.IoT Build 9:747680124ff7 23 #define ULLONG_MAX 18446744073709551615
Azure.IoT Build 9:747680124ff7 24 #endif
Azure.IoT Build 9:747680124ff7 25
Azure.IoT Build 10:c2aee3965a83 26 #include "azure_c_shared_utility/crt_abstractions.h"
AzureIoTClient 0:1f9b2707ec7d 27
AzureIoTClient 0:1f9b2707ec7d 28 #include "jsonencoder.h"
AzureIoTClient 0:1f9b2707ec7d 29 #include "multitree.h"
AzureIoTClient 0:1f9b2707ec7d 30
Azure.IoT Build 13:16e88f0cfa5f 31 #include "azure_c_shared_utility/xlogging.h"
AzureIoTClient 0:1f9b2707ec7d 32
AzureIoTClient 0:1f9b2707ec7d 33 #define NaN_STRING "NaN"
AzureIoTClient 0:1f9b2707ec7d 34 #define MINUSINF_STRING "-INF"
AzureIoTClient 0:1f9b2707ec7d 35 #define PLUSINF_STRING "INF"
AzureIoTClient 0:1f9b2707ec7d 36
AzureIoTClient 0:1f9b2707ec7d 37 #ifndef _HUGE_ENUF
AzureIoTClient 0:1f9b2707ec7d 38 #define _HUGE_ENUF 1e+300 /* _HUGE_ENUF*_HUGE_ENUF must overflow */
AzureIoTClient 0:1f9b2707ec7d 39 #endif /* _HUGE_ENUF */
AzureIoTClient 0:1f9b2707ec7d 40
AzureIoTClient 0:1f9b2707ec7d 41 #ifndef INFINITY
AzureIoTClient 0:1f9b2707ec7d 42 #define INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF)) /* causes warning C4756: overflow in constant arithmetic (by design) */
AzureIoTClient 0:1f9b2707ec7d 43 #endif /* INFINITY */
AzureIoTClient 0:1f9b2707ec7d 44
AzureIoTClient 0:1f9b2707ec7d 45 #ifndef NAN
AzureIoTClient 0:1f9b2707ec7d 46 #define NAN ((float)(INFINITY * 0.0F))
AzureIoTClient 0:1f9b2707ec7d 47 #endif /* NAN */
AzureIoTClient 0:1f9b2707ec7d 48
Azure.IoT Build 8:380e6e830589 49 #define GUID_STRING_LENGTH 38
Azure.IoT Build 8:380e6e830589 50
Azure.IoT Build 8:380e6e830589 51 // This is an artificial upper limit on floating point string length
Azure.IoT Build 8:380e6e830589 52 // (e.g. the size of the string when printing %f). It is set to twice the
Azure.IoT Build 8:380e6e830589 53 // maximum decimal precision plus 2. 1 for the decimal point and 1 for a
Azure.IoT Build 8:380e6e830589 54 // sign (+/-)
Azure.IoT Build 8:380e6e830589 55 // Unfortunately it is quite possible to print a float larger than this.
Azure.IoT Build 8:380e6e830589 56 // An example of this would be printf("%.*f", MAX_FLOATING_POINT_STRING_LENGTH, 1.3);
Azure.IoT Build 8:380e6e830589 57 // But currently no explicit requests for this exist in the file nor are
Azure.IoT Build 8:380e6e830589 58 // any expected to reasonably occur when being used (numbers that hit
Azure.IoT Build 8:380e6e830589 59 // this limit would be experiencing significant precision loss in storage anyway.
Azure.IoT Build 8:380e6e830589 60 #define MAX_FLOATING_POINT_STRING_LENGTH (DECIMAL_DIG *2 + 2)
Azure.IoT Build 8:380e6e830589 61
Azure.IoT Build 8:380e6e830589 62 // This maximum length is 11 for 32 bit integers (including the sign)
Azure.IoT Build 8:380e6e830589 63 // optionally increase to 21 if longs are 64 bit
Azure.IoT Build 8:380e6e830589 64 #define MAX_LONG_STRING_LENGTH ( 11 + (10 * (sizeof(long)/ 8)))
Azure.IoT Build 8:380e6e830589 65
Azure.IoT Build 8:380e6e830589 66 // This is the maximum length for the largest 64 bit number (signed)
Azure.IoT Build 8:380e6e830589 67 #define MAX_ULONG_LONG_STRING_LENGTH 20
AzureIoTClient 0:1f9b2707ec7d 68
AzureIoTClient 0:1f9b2707ec7d 69 DEFINE_ENUM_STRINGS(AGENT_DATA_TYPES_RESULT, AGENT_DATA_TYPES_RESULT_VALUES);
AzureIoTClient 0:1f9b2707ec7d 70
AzureIoTClient 0:1f9b2707ec7d 71 static int ValidateDate(int year, int month, int day);
AzureIoTClient 0:1f9b2707ec7d 72
AzureIoTClient 0:1f9b2707ec7d 73 static int NoCloneFunction(void** destination, const void* source)
AzureIoTClient 0:1f9b2707ec7d 74 {
AzureIoTClient 0:1f9b2707ec7d 75 *destination = (void*)source;
AzureIoTClient 0:1f9b2707ec7d 76 return 0;
AzureIoTClient 0:1f9b2707ec7d 77 }
AzureIoTClient 0:1f9b2707ec7d 78
AzureIoTClient 0:1f9b2707ec7d 79 static void NoFreeFunction(void* value)
AzureIoTClient 0:1f9b2707ec7d 80 {
AzureIoTClient 0:1f9b2707ec7d 81 (void)value;
AzureIoTClient 0:1f9b2707ec7d 82 }
AzureIoTClient 0:1f9b2707ec7d 83
AzureIoTClient 0:1f9b2707ec7d 84
AzureIoTClient 16:ef107f3f230c 85 #define IS_DIGIT(a) (('0'<=(a)) &&((a)<='9'))
AzureIoTClient 16:ef107f3f230c 86 #define splitInt(intVal, bytePos) (char)((intVal >> (bytePos << 3)) & 0xFF)
AzureIoTClient 16:ef107f3f230c 87 #define joinChars(a, b, c, d) (uint32_t)( (uint32_t)a + ((uint32_t)b << 8) + ((uint32_t)c << 16) + ((uint32_t)d << 24))
AzureIoTClient 16:ef107f3f230c 88
AzureIoTClient 16:ef107f3f230c 89 static char base64char(unsigned char val)
AzureIoTClient 16:ef107f3f230c 90 {
AzureIoTClient 16:ef107f3f230c 91 char result;
AzureIoTClient 0:1f9b2707ec7d 92
AzureIoTClient 16:ef107f3f230c 93 if (val < 26)
AzureIoTClient 16:ef107f3f230c 94 {
AzureIoTClient 16:ef107f3f230c 95 result = 'A' + (char)val;
AzureIoTClient 16:ef107f3f230c 96 }
AzureIoTClient 16:ef107f3f230c 97 else if (val < 52)
AzureIoTClient 16:ef107f3f230c 98 {
AzureIoTClient 16:ef107f3f230c 99 result = 'a' + ((char)val - 26);
AzureIoTClient 16:ef107f3f230c 100 }
AzureIoTClient 16:ef107f3f230c 101 else if (val < 62)
AzureIoTClient 16:ef107f3f230c 102 {
AzureIoTClient 16:ef107f3f230c 103 result = '0' + ((char)val - 52);
AzureIoTClient 16:ef107f3f230c 104 }
AzureIoTClient 16:ef107f3f230c 105 else if (val == 62)
AzureIoTClient 16:ef107f3f230c 106 {
AzureIoTClient 16:ef107f3f230c 107 result = '-';
AzureIoTClient 16:ef107f3f230c 108 }
AzureIoTClient 16:ef107f3f230c 109 else
AzureIoTClient 16:ef107f3f230c 110 {
AzureIoTClient 16:ef107f3f230c 111 result = '_';
AzureIoTClient 16:ef107f3f230c 112 }
AzureIoTClient 0:1f9b2707ec7d 113
AzureIoTClient 16:ef107f3f230c 114 return result;
AzureIoTClient 16:ef107f3f230c 115 }
AzureIoTClient 16:ef107f3f230c 116
AzureIoTClient 16:ef107f3f230c 117 static char base64b16(unsigned char val)
AzureIoTClient 16:ef107f3f230c 118 {
AzureIoTClient 16:ef107f3f230c 119 const uint32_t base64b16values[4] = {
AzureIoTClient 16:ef107f3f230c 120 joinChars('A', 'E', 'I', 'M'),
AzureIoTClient 16:ef107f3f230c 121 joinChars('Q', 'U', 'Y', 'c'),
AzureIoTClient 16:ef107f3f230c 122 joinChars('g', 'k', 'o', 's'),
AzureIoTClient 16:ef107f3f230c 123 joinChars('w', '0', '4', '8')
AzureIoTClient 16:ef107f3f230c 124 };
AzureIoTClient 16:ef107f3f230c 125 return splitInt(base64b16values[val >> 2], (val & 0x03));
AzureIoTClient 16:ef107f3f230c 126 }
AzureIoTClient 16:ef107f3f230c 127
AzureIoTClient 16:ef107f3f230c 128 static char base64b8(unsigned char val)
AzureIoTClient 16:ef107f3f230c 129 {
AzureIoTClient 16:ef107f3f230c 130 const uint32_t base64b8values = joinChars('A', 'Q', 'g', 'w');
AzureIoTClient 16:ef107f3f230c 131 return splitInt(base64b8values, val);
AzureIoTClient 0:1f9b2707ec7d 132 };
AzureIoTClient 0:1f9b2707ec7d 133
AzureIoTClient 0:1f9b2707ec7d 134 /*creates an AGENT_DATA_TYPE containing a EDM_BOOLEAN from a int*/
AzureIoTClient 0:1f9b2707ec7d 135 AGENT_DATA_TYPES_RESULT Create_EDM_BOOLEAN_from_int(AGENT_DATA_TYPE* agentData, int v)
AzureIoTClient 0:1f9b2707ec7d 136 {
AzureIoTClient 0:1f9b2707ec7d 137 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 138 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[All the Create_... functions shall check their parameters for validity.When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned]*/
AzureIoTClient 0:1f9b2707ec7d 139 if(agentData==NULL)
AzureIoTClient 0:1f9b2707ec7d 140 {
AzureIoTClient 0:1f9b2707ec7d 141 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 142 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 143 }
AzureIoTClient 0:1f9b2707ec7d 144 else
AzureIoTClient 0:1f9b2707ec7d 145 {
AzureIoTClient 0:1f9b2707ec7d 146 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_031:[ Creates a AGENT_DATA_TYPE representing an EDM_BOOLEAN.]*/
AzureIoTClient 0:1f9b2707ec7d 147 agentData->type = EDM_BOOLEAN_TYPE;
AzureIoTClient 0:1f9b2707ec7d 148 agentData->value.edmBoolean.value = (v)?(EDM_TRUE):(EDM_FALSE);
AzureIoTClient 0:1f9b2707ec7d 149 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 150 }
AzureIoTClient 0:1f9b2707ec7d 151 return result;
AzureIoTClient 0:1f9b2707ec7d 152 }
AzureIoTClient 0:1f9b2707ec7d 153
AzureIoTClient 0:1f9b2707ec7d 154 /*creates an AGENT_DATA_TYPE containing a UINT8*/
AzureIoTClient 0:1f9b2707ec7d 155 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_UINT8(AGENT_DATA_TYPE* agentData, uint8_t v)
AzureIoTClient 0:1f9b2707ec7d 156 {
AzureIoTClient 0:1f9b2707ec7d 157 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 158 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the Create_... functions shall check their parameters for validity. When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 159 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 160 {
AzureIoTClient 0:1f9b2707ec7d 161 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 162 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 163 }
AzureIoTClient 0:1f9b2707ec7d 164 else
AzureIoTClient 0:1f9b2707ec7d 165 {
AzureIoTClient 0:1f9b2707ec7d 166 agentData->type = EDM_BYTE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 167 agentData->value.edmByte.value = v;
AzureIoTClient 0:1f9b2707ec7d 168 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 169 }
AzureIoTClient 0:1f9b2707ec7d 170 return result;
AzureIoTClient 0:1f9b2707ec7d 171 }
AzureIoTClient 0:1f9b2707ec7d 172
AzureIoTClient 0:1f9b2707ec7d 173 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_091:[Creates an AGENT_DATA_TYPE containing an Edm.DateTimeOffset from an EDM_DATE_TIME_OFFSET.]*/
AzureIoTClient 0:1f9b2707ec7d 174 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_EDM_DATE_TIME_OFFSET(AGENT_DATA_TYPE* agentData, EDM_DATE_TIME_OFFSET v)
AzureIoTClient 0:1f9b2707ec7d 175 {
AzureIoTClient 0:1f9b2707ec7d 176 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 177 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the Create_... functions shall check their parameters for validity. When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned ]*/
AzureIoTClient 0:1f9b2707ec7d 178 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 179 {
AzureIoTClient 0:1f9b2707ec7d 180 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 181 }
AzureIoTClient 0:1f9b2707ec7d 182 else if (ValidateDate(v.dateTime.tm_year+1900, v.dateTime.tm_mon +1 , v.dateTime.tm_mday) != 0)
AzureIoTClient 0:1f9b2707ec7d 183 {
AzureIoTClient 0:1f9b2707ec7d 184 /*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.]*/
AzureIoTClient 0:1f9b2707ec7d 185 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 186 }
AzureIoTClient 0:1f9b2707ec7d 187 else if (
AzureIoTClient 0:1f9b2707ec7d 188 (v.dateTime.tm_hour > 23) ||
AzureIoTClient 0:1f9b2707ec7d 189 (v.dateTime.tm_hour < 0) ||
AzureIoTClient 0:1f9b2707ec7d 190 (v.dateTime.tm_min > 59) ||
AzureIoTClient 0:1f9b2707ec7d 191 (v.dateTime.tm_min < 0) ||
AzureIoTClient 0:1f9b2707ec7d 192 (v.dateTime.tm_sec > 59) ||
AzureIoTClient 0:1f9b2707ec7d 193 (v.dateTime.tm_sec < 0)
AzureIoTClient 0:1f9b2707ec7d 194 )
AzureIoTClient 0:1f9b2707ec7d 195 {
AzureIoTClient 0:1f9b2707ec7d 196 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_092:[ The structure shall be validated, and if found invalid, AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 197 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 198 }
AzureIoTClient 0:1f9b2707ec7d 199 else if ((v.hasFractionalSecond) && (v.fractionalSecond > 999999999999))
AzureIoTClient 0:1f9b2707ec7d 200 {
AzureIoTClient 0:1f9b2707ec7d 201 /*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.]*/
AzureIoTClient 0:1f9b2707ec7d 202 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 203 }
AzureIoTClient 0:1f9b2707ec7d 204 else if (
AzureIoTClient 0:1f9b2707ec7d 205 (v.hasTimeZone) &&
AzureIoTClient 0:1f9b2707ec7d 206 (
AzureIoTClient 0:1f9b2707ec7d 207 (v.timeZoneHour<-23) ||
AzureIoTClient 0:1f9b2707ec7d 208 (v.timeZoneHour>23) ||
AzureIoTClient 0:1f9b2707ec7d 209 (v.timeZoneMinute>59)
AzureIoTClient 0:1f9b2707ec7d 210 )
AzureIoTClient 0:1f9b2707ec7d 211 )
AzureIoTClient 0:1f9b2707ec7d 212 {
AzureIoTClient 0:1f9b2707ec7d 213 /*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.]*/
AzureIoTClient 0:1f9b2707ec7d 214 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 215 }
AzureIoTClient 0:1f9b2707ec7d 216 else
AzureIoTClient 0:1f9b2707ec7d 217 {
AzureIoTClient 0:1f9b2707ec7d 218 agentData->type = EDM_DATE_TIME_OFFSET_TYPE;
AzureIoTClient 0:1f9b2707ec7d 219 agentData->value.edmDateTimeOffset = v;
AzureIoTClient 0:1f9b2707ec7d 220 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 221 }
AzureIoTClient 0:1f9b2707ec7d 222 return result;
AzureIoTClient 0:1f9b2707ec7d 223 }
AzureIoTClient 0:1f9b2707ec7d 224
AzureIoTClient 0:1f9b2707ec7d 225 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_094:[ Creates and AGENT_DATA_TYPE containing a EDM_GUID from an EDM_GUID]*/
AzureIoTClient 0:1f9b2707ec7d 226 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_EDM_GUID(AGENT_DATA_TYPE* agentData, EDM_GUID v)
AzureIoTClient 0:1f9b2707ec7d 227 {
AzureIoTClient 0:1f9b2707ec7d 228 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 229 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the functions shall check their parameters for validity. When an invalid parameter is detected, the value AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 230 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 231 {
AzureIoTClient 0:1f9b2707ec7d 232 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 233 LogError("result = %s ", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 234 }
AzureIoTClient 0:1f9b2707ec7d 235 else
AzureIoTClient 0:1f9b2707ec7d 236 {
AzureIoTClient 0:1f9b2707ec7d 237 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_094:[ Creates and AGENT_DATA_TYPE containing a EDM_GUID from an EDM_GUID]*/
AzureIoTClient 0:1f9b2707ec7d 238 agentData->type = EDM_GUID_TYPE;
AzureIoTClient 0:1f9b2707ec7d 239 memmove(agentData->value.edmGuid.GUID, v.GUID, 16);
AzureIoTClient 0:1f9b2707ec7d 240 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 241 }
AzureIoTClient 0:1f9b2707ec7d 242 return result;
AzureIoTClient 0:1f9b2707ec7d 243 }
AzureIoTClient 0:1f9b2707ec7d 244
AzureIoTClient 0:1f9b2707ec7d 245 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_098:[ Creates an AGENT_DATA_TYPE containing a EDM_BINARY from a EDM_BINARY.]*/
AzureIoTClient 0:1f9b2707ec7d 246 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_EDM_BINARY(AGENT_DATA_TYPE* agentData, EDM_BINARY v)
AzureIoTClient 0:1f9b2707ec7d 247 {
AzureIoTClient 0:1f9b2707ec7d 248 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 249 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the functions shall check their parameters for validity. When an invalid parameter is detected, the value AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 250 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 251 {
AzureIoTClient 0:1f9b2707ec7d 252 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 253 LogError("result = %s", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 254 }
AzureIoTClient 0:1f9b2707ec7d 255 else
AzureIoTClient 0:1f9b2707ec7d 256 {
AzureIoTClient 0:1f9b2707ec7d 257 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_098:[ Creates an AGENT_DATA_TYPE containing a EDM_BINARY from a EDM_BINARY.]*/
AzureIoTClient 0:1f9b2707ec7d 258 if (v.data == NULL)
AzureIoTClient 0:1f9b2707ec7d 259 {
AzureIoTClient 0:1f9b2707ec7d 260 if (v.size != 0)
AzureIoTClient 0:1f9b2707ec7d 261 {
AzureIoTClient 0:1f9b2707ec7d 262 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 263 LogError("result = %s ", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 264 }
AzureIoTClient 0:1f9b2707ec7d 265 else
AzureIoTClient 0:1f9b2707ec7d 266 {
AzureIoTClient 0:1f9b2707ec7d 267 agentData->type = EDM_BINARY_TYPE;
AzureIoTClient 0:1f9b2707ec7d 268 agentData->value.edmBinary.size = 0;
AzureIoTClient 0:1f9b2707ec7d 269 agentData->value.edmBinary.data = NULL;
AzureIoTClient 0:1f9b2707ec7d 270 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 271 }
AzureIoTClient 0:1f9b2707ec7d 272 }
AzureIoTClient 0:1f9b2707ec7d 273 else
AzureIoTClient 0:1f9b2707ec7d 274 {
AzureIoTClient 0:1f9b2707ec7d 275 if (v.size != 0)
AzureIoTClient 0:1f9b2707ec7d 276 {
AzureIoTClient 0:1f9b2707ec7d 277 /*make a copy*/
AzureIoTClient 0:1f9b2707ec7d 278 if ((agentData->value.edmBinary.data = (unsigned char*)malloc(v.size)) == NULL)
AzureIoTClient 0:1f9b2707ec7d 279 {
AzureIoTClient 0:1f9b2707ec7d 280 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 281 LogError("result = %s", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 282 }
AzureIoTClient 0:1f9b2707ec7d 283 else
AzureIoTClient 0:1f9b2707ec7d 284 {
AzureIoTClient 0:1f9b2707ec7d 285 memcpy(agentData->value.edmBinary.data, v.data, v.size);
AzureIoTClient 0:1f9b2707ec7d 286 agentData->type = EDM_BINARY_TYPE;
AzureIoTClient 0:1f9b2707ec7d 287 agentData->value.edmBinary.size = v.size;
AzureIoTClient 0:1f9b2707ec7d 288 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 289 }
AzureIoTClient 0:1f9b2707ec7d 290 }
AzureIoTClient 0:1f9b2707ec7d 291 else
AzureIoTClient 0:1f9b2707ec7d 292 {
AzureIoTClient 0:1f9b2707ec7d 293 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 294 LogError("result = %s", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 295 }
AzureIoTClient 0:1f9b2707ec7d 296 }
AzureIoTClient 0:1f9b2707ec7d 297 }
AzureIoTClient 0:1f9b2707ec7d 298 return result;
AzureIoTClient 0:1f9b2707ec7d 299 }
AzureIoTClient 0:1f9b2707ec7d 300
AzureIoTClient 0:1f9b2707ec7d 301 /*scans sign, if any*/
AzureIoTClient 0:1f9b2707ec7d 302 /*if no sign, then it will set *sign to = +1*/
AzureIoTClient 0:1f9b2707ec7d 303 /*if sign, then it will set *sign to = +/-1*/
AzureIoTClient 0:1f9b2707ec7d 304 static void scanOptionalSign(const char* source, size_t sourceSize, size_t* position, int* sign)
AzureIoTClient 0:1f9b2707ec7d 305 {
AzureIoTClient 0:1f9b2707ec7d 306 if (*position < sourceSize)
AzureIoTClient 0:1f9b2707ec7d 307 {
AzureIoTClient 0:1f9b2707ec7d 308 if (source[*position] == '-')
AzureIoTClient 0:1f9b2707ec7d 309 {
AzureIoTClient 0:1f9b2707ec7d 310
AzureIoTClient 0:1f9b2707ec7d 311 *sign = -1;
AzureIoTClient 0:1f9b2707ec7d 312 (*position)++;
AzureIoTClient 0:1f9b2707ec7d 313 }
AzureIoTClient 0:1f9b2707ec7d 314 else if (source[*position] == '+')
AzureIoTClient 0:1f9b2707ec7d 315 {
AzureIoTClient 0:1f9b2707ec7d 316 *sign = +1;
AzureIoTClient 0:1f9b2707ec7d 317 (*position)++;
AzureIoTClient 0:1f9b2707ec7d 318 }
AzureIoTClient 0:1f9b2707ec7d 319 else
AzureIoTClient 0:1f9b2707ec7d 320 {
AzureIoTClient 0:1f9b2707ec7d 321 *sign = +1;
AzureIoTClient 0:1f9b2707ec7d 322 }
AzureIoTClient 0:1f9b2707ec7d 323 }
AzureIoTClient 0:1f9b2707ec7d 324 }
AzureIoTClient 0:1f9b2707ec7d 325
AzureIoTClient 0:1f9b2707ec7d 326 /*scans a minus sign, if any*/
AzureIoTClient 0:1f9b2707ec7d 327 /*if no sign, then it will set *sign to = +1*/
AzureIoTClient 0:1f9b2707ec7d 328 /*if sign, then it will set *sign to = +/-1*/
AzureIoTClient 0:1f9b2707ec7d 329 static void scanOptionalMinusSign(const char* source, size_t sourceSize, size_t* position, int* sign)
AzureIoTClient 0:1f9b2707ec7d 330 {
AzureIoTClient 0:1f9b2707ec7d 331 if (*position < sourceSize)
AzureIoTClient 0:1f9b2707ec7d 332 {
AzureIoTClient 0:1f9b2707ec7d 333 if (source[*position] == '-')
AzureIoTClient 0:1f9b2707ec7d 334 {
AzureIoTClient 0:1f9b2707ec7d 335
AzureIoTClient 0:1f9b2707ec7d 336 *sign = -1;
AzureIoTClient 0:1f9b2707ec7d 337 (*position)++;
AzureIoTClient 0:1f9b2707ec7d 338 }
AzureIoTClient 0:1f9b2707ec7d 339 else
AzureIoTClient 0:1f9b2707ec7d 340 {
AzureIoTClient 0:1f9b2707ec7d 341 *sign = +1;
AzureIoTClient 0:1f9b2707ec7d 342 }
AzureIoTClient 0:1f9b2707ec7d 343 }
AzureIoTClient 0:1f9b2707ec7d 344 }
AzureIoTClient 0:1f9b2707ec7d 345
AzureIoTClient 0:1f9b2707ec7d 346 /*this function alawys returns 0 if it processed 1 digit*/
AzureIoTClient 0:1f9b2707ec7d 347 /*return 1 when error (such as wrong parameters)*/
AzureIoTClient 0:1f9b2707ec7d 348 static int scanMandatoryOneDigit(const char* source, size_t sourceSize, size_t* position)
AzureIoTClient 0:1f9b2707ec7d 349 {
AzureIoTClient 0:1f9b2707ec7d 350 int result;
AzureIoTClient 0:1f9b2707ec7d 351 if (*position < sourceSize)
AzureIoTClient 0:1f9b2707ec7d 352 {
AzureIoTClient 0:1f9b2707ec7d 353 if (IS_DIGIT(source[*position]))
AzureIoTClient 0:1f9b2707ec7d 354 {
AzureIoTClient 0:1f9b2707ec7d 355 (*position)++;
AzureIoTClient 0:1f9b2707ec7d 356 result = 0;
AzureIoTClient 0:1f9b2707ec7d 357 }
AzureIoTClient 0:1f9b2707ec7d 358 else
AzureIoTClient 0:1f9b2707ec7d 359 {
AzureIoTClient 0:1f9b2707ec7d 360 result = 1;
AzureIoTClient 0:1f9b2707ec7d 361 }
AzureIoTClient 0:1f9b2707ec7d 362 }
AzureIoTClient 0:1f9b2707ec7d 363 else
AzureIoTClient 0:1f9b2707ec7d 364 {
AzureIoTClient 0:1f9b2707ec7d 365 result = 1;
AzureIoTClient 0:1f9b2707ec7d 366 }
AzureIoTClient 0:1f9b2707ec7d 367 return result;
AzureIoTClient 0:1f9b2707ec7d 368 }
AzureIoTClient 0:1f9b2707ec7d 369
AzureIoTClient 0:1f9b2707ec7d 370 /*scans digits, if any*/
AzureIoTClient 0:1f9b2707ec7d 371 static void scanOptionalNDigits(const char* source, size_t sourceSize, size_t* position)
AzureIoTClient 0:1f9b2707ec7d 372 {
AzureIoTClient 0:1f9b2707ec7d 373 while (*position < sourceSize)
AzureIoTClient 0:1f9b2707ec7d 374 {
AzureIoTClient 0:1f9b2707ec7d 375 if (IS_DIGIT(source[*position]))
AzureIoTClient 0:1f9b2707ec7d 376 {
AzureIoTClient 0:1f9b2707ec7d 377 (*position)++;
AzureIoTClient 0:1f9b2707ec7d 378 }
AzureIoTClient 0:1f9b2707ec7d 379 else
AzureIoTClient 0:1f9b2707ec7d 380 {
AzureIoTClient 0:1f9b2707ec7d 381 break;
AzureIoTClient 0:1f9b2707ec7d 382 }
AzureIoTClient 0:1f9b2707ec7d 383 }
AzureIoTClient 0:1f9b2707ec7d 384 }
AzureIoTClient 0:1f9b2707ec7d 385
AzureIoTClient 0:1f9b2707ec7d 386 /*from the string pointed to by source, having the size sourceSize, starting at initial position *position*/
AzureIoTClient 0:1f9b2707ec7d 387 /*this function will attempt to read a decimal number having an optional sign(+/-) followed by precisely N digits */
AzureIoTClient 0:1f9b2707ec7d 388 /*will return 0 if in the string there was a number and that number has been read in the *value parameter*/
AzureIoTClient 0:1f9b2707ec7d 389 /*will update position parameter to reflect the first character not belonging to the number*/
AzureIoTClient 14:0c00e67a4ab1 390 static int scanAndReadNDigitsInt(const char* source, size_t* position, int *value, size_t N)
AzureIoTClient 0:1f9b2707ec7d 391 {
AzureIoTClient 0:1f9b2707ec7d 392 N++;
AzureIoTClient 0:1f9b2707ec7d 393 *value = 0;
AzureIoTClient 14:0c00e67a4ab1 394 while ((IS_DIGIT(source[*position])) &&
AzureIoTClient 0:1f9b2707ec7d 395 (N > 0))
AzureIoTClient 0:1f9b2707ec7d 396 {
AzureIoTClient 14:0c00e67a4ab1 397 *value *= 10;
AzureIoTClient 14:0c00e67a4ab1 398 *value += (source[*position] - '0');
AzureIoTClient 14:0c00e67a4ab1 399 (*position)++;
AzureIoTClient 0:1f9b2707ec7d 400 N--;
AzureIoTClient 0:1f9b2707ec7d 401 }
AzureIoTClient 0:1f9b2707ec7d 402
AzureIoTClient 0:1f9b2707ec7d 403 return N != 1;
AzureIoTClient 0:1f9b2707ec7d 404 }
AzureIoTClient 0:1f9b2707ec7d 405
AzureIoTClient 0:1f9b2707ec7d 406 /*this function alawys returns 0 if it found a dot followed by at least digit*/
AzureIoTClient 0:1f9b2707ec7d 407 /*return 1 when error (such as wrong parameters)*/
AzureIoTClient 0:1f9b2707ec7d 408 static int scanOptionalDotAndDigits(const char* source, size_t sourceSize, size_t* position)
AzureIoTClient 0:1f9b2707ec7d 409 {
AzureIoTClient 0:1f9b2707ec7d 410 int result = 0;
AzureIoTClient 0:1f9b2707ec7d 411 if (*position < sourceSize)
AzureIoTClient 0:1f9b2707ec7d 412 {
AzureIoTClient 0:1f9b2707ec7d 413 if (source[*position] == '.')
AzureIoTClient 0:1f9b2707ec7d 414 {
AzureIoTClient 0:1f9b2707ec7d 415 (*position)++;
AzureIoTClient 0:1f9b2707ec7d 416 if (scanMandatoryOneDigit(source, sourceSize, position) != 0)
AzureIoTClient 0:1f9b2707ec7d 417 {
AzureIoTClient 0:1f9b2707ec7d 418 /* not a digit following the dot... */
AzureIoTClient 0:1f9b2707ec7d 419 result = 1;
AzureIoTClient 0:1f9b2707ec7d 420 }
AzureIoTClient 0:1f9b2707ec7d 421 else
AzureIoTClient 0:1f9b2707ec7d 422 {
AzureIoTClient 0:1f9b2707ec7d 423 scanOptionalNDigits(source, sourceSize, position);
AzureIoTClient 0:1f9b2707ec7d 424 }
AzureIoTClient 0:1f9b2707ec7d 425 }
AzureIoTClient 0:1f9b2707ec7d 426 else
AzureIoTClient 0:1f9b2707ec7d 427 {
AzureIoTClient 0:1f9b2707ec7d 428 /*not a dot, don't care*/
AzureIoTClient 0:1f9b2707ec7d 429 }
AzureIoTClient 0:1f9b2707ec7d 430 }
AzureIoTClient 0:1f9b2707ec7d 431 return result;
AzureIoTClient 0:1f9b2707ec7d 432 }
AzureIoTClient 0:1f9b2707ec7d 433
AzureIoTClient 0:1f9b2707ec7d 434
AzureIoTClient 0:1f9b2707ec7d 435 static int scanMandatory1CapitalHexDigit(const char* source, uint8_t* value)
AzureIoTClient 0:1f9b2707ec7d 436 {
AzureIoTClient 0:1f9b2707ec7d 437 int result = 0;
AzureIoTClient 0:1f9b2707ec7d 438 if (('0' <= source[0]) && (source[0] <= '9'))
AzureIoTClient 0:1f9b2707ec7d 439 {
AzureIoTClient 0:1f9b2707ec7d 440 *value = (source[0] - '0');
AzureIoTClient 0:1f9b2707ec7d 441 }
AzureIoTClient 0:1f9b2707ec7d 442 else if (('A' <= source[0]) && (source[0] <= 'F'))
AzureIoTClient 0:1f9b2707ec7d 443 {
AzureIoTClient 0:1f9b2707ec7d 444 *value = (source[0] - 'A'+10);
AzureIoTClient 0:1f9b2707ec7d 445 }
AzureIoTClient 0:1f9b2707ec7d 446 else
AzureIoTClient 0:1f9b2707ec7d 447 {
AzureIoTClient 0:1f9b2707ec7d 448 result = 1;
AzureIoTClient 0:1f9b2707ec7d 449 }
AzureIoTClient 0:1f9b2707ec7d 450 return result;
AzureIoTClient 0:1f9b2707ec7d 451 }
AzureIoTClient 0:1f9b2707ec7d 452
AzureIoTClient 0:1f9b2707ec7d 453 /*this function alawys returns 0 if it found 2 hex digits, also updates the *value parameter*/
AzureIoTClient 0:1f9b2707ec7d 454 /*return 1 when error (such as wrong parameters)*/
AzureIoTClient 0:1f9b2707ec7d 455 static int scanMandatory2CapitalHexDigits(const char* source, uint8_t* value)
AzureIoTClient 0:1f9b2707ec7d 456 {
AzureIoTClient 0:1f9b2707ec7d 457 int result;
AzureIoTClient 0:1f9b2707ec7d 458 uint8_t temp;
AzureIoTClient 0:1f9b2707ec7d 459 if (scanMandatory1CapitalHexDigit(source, &temp) == 0)
AzureIoTClient 0:1f9b2707ec7d 460 {
AzureIoTClient 0:1f9b2707ec7d 461 *value = temp*16;
AzureIoTClient 0:1f9b2707ec7d 462 if (scanMandatory1CapitalHexDigit(source + 1, &temp) == 0)
AzureIoTClient 0:1f9b2707ec7d 463 {
AzureIoTClient 0:1f9b2707ec7d 464 *value += temp;
AzureIoTClient 0:1f9b2707ec7d 465 result = 0;
AzureIoTClient 0:1f9b2707ec7d 466 }
AzureIoTClient 0:1f9b2707ec7d 467 else
AzureIoTClient 0:1f9b2707ec7d 468 {
AzureIoTClient 0:1f9b2707ec7d 469 result = 1;
AzureIoTClient 0:1f9b2707ec7d 470 }
AzureIoTClient 0:1f9b2707ec7d 471 }
AzureIoTClient 0:1f9b2707ec7d 472 else
AzureIoTClient 0:1f9b2707ec7d 473 {
AzureIoTClient 0:1f9b2707ec7d 474 result = 2;
AzureIoTClient 0:1f9b2707ec7d 475 }
AzureIoTClient 0:1f9b2707ec7d 476
AzureIoTClient 0:1f9b2707ec7d 477 return result;
AzureIoTClient 0:1f9b2707ec7d 478 }
AzureIoTClient 0:1f9b2707ec7d 479
AzureIoTClient 0:1f9b2707ec7d 480 static int ValidateDecimal(const char* v, size_t vlen)
AzureIoTClient 0:1f9b2707ec7d 481 {
AzureIoTClient 0:1f9b2707ec7d 482 int result;
AzureIoTClient 0:1f9b2707ec7d 483 int sign = 0;
AzureIoTClient 0:1f9b2707ec7d 484 size_t validatePosition = 0;
AzureIoTClient 0:1f9b2707ec7d 485 scanOptionalSign(v, vlen, &validatePosition, &sign);
AzureIoTClient 0:1f9b2707ec7d 486 if (scanMandatoryOneDigit(v, vlen, &validatePosition) != 0)
AzureIoTClient 0:1f9b2707ec7d 487 {
AzureIoTClient 0:1f9b2707ec7d 488 result = 1;
AzureIoTClient 0:1f9b2707ec7d 489 }
AzureIoTClient 0:1f9b2707ec7d 490 else
AzureIoTClient 0:1f9b2707ec7d 491 {
AzureIoTClient 0:1f9b2707ec7d 492 scanOptionalNDigits(v, vlen, &validatePosition);
AzureIoTClient 0:1f9b2707ec7d 493 if (scanOptionalDotAndDigits(v, vlen, &validatePosition) != 0)
AzureIoTClient 0:1f9b2707ec7d 494 {
AzureIoTClient 0:1f9b2707ec7d 495 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_067:[ If the string indicated by the parameter v does not match exactly an ODATA string representation, AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 496 result = 1;
AzureIoTClient 0:1f9b2707ec7d 497 }
AzureIoTClient 0:1f9b2707ec7d 498 else if (validatePosition != vlen) /*Trailing wrong characters*/
AzureIoTClient 0:1f9b2707ec7d 499 {
AzureIoTClient 0:1f9b2707ec7d 500 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_067:[ If the string indicated by the parameter v does not match exactly an ODATA string representation, AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 501 result = 1;
AzureIoTClient 0:1f9b2707ec7d 502 }
AzureIoTClient 0:1f9b2707ec7d 503 else
AzureIoTClient 0:1f9b2707ec7d 504 {
AzureIoTClient 0:1f9b2707ec7d 505 result = 0;
AzureIoTClient 0:1f9b2707ec7d 506 }
AzureIoTClient 0:1f9b2707ec7d 507 }
AzureIoTClient 0:1f9b2707ec7d 508
AzureIoTClient 0:1f9b2707ec7d 509 return result;
AzureIoTClient 0:1f9b2707ec7d 510 }
AzureIoTClient 0:1f9b2707ec7d 511
AzureIoTClient 0:1f9b2707ec7d 512 /*return 0 if everything went ok*/
AzureIoTClient 0:1f9b2707ec7d 513 /*takes 1 base64char and returns its value*/
AzureIoTClient 0:1f9b2707ec7d 514 static int base64toValue(char base64charSource, unsigned char* value)
AzureIoTClient 0:1f9b2707ec7d 515 {
AzureIoTClient 0:1f9b2707ec7d 516 int result;
AzureIoTClient 0:1f9b2707ec7d 517 if (('A' <= base64charSource) && (base64charSource <= 'Z'))
AzureIoTClient 0:1f9b2707ec7d 518 {
AzureIoTClient 0:1f9b2707ec7d 519 *value = base64charSource - 'A';
AzureIoTClient 0:1f9b2707ec7d 520 result = 0;
AzureIoTClient 0:1f9b2707ec7d 521 }
AzureIoTClient 0:1f9b2707ec7d 522 else if (('a' <= base64charSource) && (base64charSource <= 'z'))
AzureIoTClient 0:1f9b2707ec7d 523 {
AzureIoTClient 0:1f9b2707ec7d 524 *value = ('Z' - 'A') +1+ (base64charSource - 'a');
AzureIoTClient 0:1f9b2707ec7d 525 result = 0;
AzureIoTClient 0:1f9b2707ec7d 526 }
AzureIoTClient 0:1f9b2707ec7d 527 else if (('0' <= base64charSource) && (base64charSource <= '9'))
AzureIoTClient 0:1f9b2707ec7d 528 {
AzureIoTClient 0:1f9b2707ec7d 529 *value = ('Z' - 'A') +1+('z'-'a')+1 +(base64charSource - '0');
AzureIoTClient 0:1f9b2707ec7d 530 result = 0;
AzureIoTClient 0:1f9b2707ec7d 531 }
AzureIoTClient 0:1f9b2707ec7d 532 else if ('-' == base64charSource)
AzureIoTClient 0:1f9b2707ec7d 533 {
AzureIoTClient 0:1f9b2707ec7d 534 *value = 62;
AzureIoTClient 0:1f9b2707ec7d 535 result = 0;
AzureIoTClient 0:1f9b2707ec7d 536 }
AzureIoTClient 0:1f9b2707ec7d 537 else if ('_' == base64charSource)
AzureIoTClient 0:1f9b2707ec7d 538 {
AzureIoTClient 0:1f9b2707ec7d 539 *value = 63;
AzureIoTClient 0:1f9b2707ec7d 540 result = 0;
AzureIoTClient 0:1f9b2707ec7d 541 }
AzureIoTClient 0:1f9b2707ec7d 542 else
AzureIoTClient 0:1f9b2707ec7d 543 {
AzureIoTClient 0:1f9b2707ec7d 544 result = 1;
AzureIoTClient 0:1f9b2707ec7d 545 }
AzureIoTClient 0:1f9b2707ec7d 546 return result;
AzureIoTClient 0:1f9b2707ec7d 547 }
AzureIoTClient 0:1f9b2707ec7d 548
AzureIoTClient 0:1f9b2707ec7d 549 /*returns 0 if everything went ok*/
AzureIoTClient 0:1f9b2707ec7d 550 /*scans 4 base64 characters and returns 3 usual bytes*/
AzureIoTClient 0:1f9b2707ec7d 551 static int scan4base64char(const char* source, size_t sourceSize, unsigned char *destination0, unsigned char* destination1, unsigned char* destination2)
AzureIoTClient 0:1f9b2707ec7d 552 {
AzureIoTClient 0:1f9b2707ec7d 553 int result;
AzureIoTClient 0:1f9b2707ec7d 554 if (sourceSize < 4)
AzureIoTClient 0:1f9b2707ec7d 555 {
AzureIoTClient 0:1f9b2707ec7d 556 result = 1;
AzureIoTClient 0:1f9b2707ec7d 557 }
AzureIoTClient 0:1f9b2707ec7d 558 else
AzureIoTClient 0:1f9b2707ec7d 559 {
AzureIoTClient 0:1f9b2707ec7d 560 unsigned char b0, b1, b2, b3;
AzureIoTClient 0:1f9b2707ec7d 561 if (
AzureIoTClient 0:1f9b2707ec7d 562 (base64toValue(source[0], &b0) == 0) &&
AzureIoTClient 0:1f9b2707ec7d 563 (base64toValue(source[1], &b1) == 0) &&
AzureIoTClient 0:1f9b2707ec7d 564 (base64toValue(source[2], &b2) == 0) &&
AzureIoTClient 0:1f9b2707ec7d 565 (base64toValue(source[3], &b3) == 0)
AzureIoTClient 0:1f9b2707ec7d 566 )
AzureIoTClient 0:1f9b2707ec7d 567 {
AzureIoTClient 0:1f9b2707ec7d 568 *destination0 = (b0 << 2) | ((b1 & 0x30) >> 4);
AzureIoTClient 0:1f9b2707ec7d 569 *destination1 = ((b1 & 0x0F)<<4) | ((b2 & 0x3C) >>2 );
AzureIoTClient 0:1f9b2707ec7d 570 *destination2 = ((b2 & 0x03) << 6) | (b3);
AzureIoTClient 0:1f9b2707ec7d 571 result = 0;
AzureIoTClient 0:1f9b2707ec7d 572 }
AzureIoTClient 0:1f9b2707ec7d 573 else
AzureIoTClient 0:1f9b2707ec7d 574 {
AzureIoTClient 0:1f9b2707ec7d 575 result = 2;
AzureIoTClient 0:1f9b2707ec7d 576 }
AzureIoTClient 0:1f9b2707ec7d 577 }
AzureIoTClient 0:1f9b2707ec7d 578 return result;
AzureIoTClient 0:1f9b2707ec7d 579 }
AzureIoTClient 0:1f9b2707ec7d 580
AzureIoTClient 0:1f9b2707ec7d 581 /*return 0 if the character is one of ( 'A' / 'E' / 'I' / 'M' / 'Q' / 'U' / 'Y' / 'c' / 'g' / 'k' / 'o' / 's' / 'w' / '0' / '4' / '8' )*/
AzureIoTClient 0:1f9b2707ec7d 582 static int base64b16toValue(unsigned char source, unsigned char* destination)
AzureIoTClient 0:1f9b2707ec7d 583 {
AzureIoTClient 0:1f9b2707ec7d 584 unsigned char i;
AzureIoTClient 0:1f9b2707ec7d 585 for (i = 0; i <= 15; i++)
AzureIoTClient 0:1f9b2707ec7d 586 {
AzureIoTClient 16:ef107f3f230c 587 if (base64b16(i) == source)
AzureIoTClient 0:1f9b2707ec7d 588 {
AzureIoTClient 0:1f9b2707ec7d 589 *destination = i;
AzureIoTClient 0:1f9b2707ec7d 590 return 0;
AzureIoTClient 0:1f9b2707ec7d 591 }
AzureIoTClient 0:1f9b2707ec7d 592 }
AzureIoTClient 0:1f9b2707ec7d 593 return 1;
AzureIoTClient 0:1f9b2707ec7d 594 }
AzureIoTClient 0:1f9b2707ec7d 595
AzureIoTClient 0:1f9b2707ec7d 596 /*return 0 if the character is one of ( 'A' / 'Q' / 'g' / 'w' )*/
AzureIoTClient 0:1f9b2707ec7d 597 static int base64b8toValue(unsigned char source, unsigned char* destination)
AzureIoTClient 0:1f9b2707ec7d 598 {
AzureIoTClient 0:1f9b2707ec7d 599 unsigned char i;
AzureIoTClient 0:1f9b2707ec7d 600 for (i = 0; i <= 3; i++)
AzureIoTClient 0:1f9b2707ec7d 601 {
AzureIoTClient 16:ef107f3f230c 602 if (base64b8(i) == source)
AzureIoTClient 0:1f9b2707ec7d 603 {
AzureIoTClient 0:1f9b2707ec7d 604 *destination = i;
AzureIoTClient 0:1f9b2707ec7d 605 return 0;
AzureIoTClient 0:1f9b2707ec7d 606 }
AzureIoTClient 0:1f9b2707ec7d 607 }
AzureIoTClient 0:1f9b2707ec7d 608 return 1;
AzureIoTClient 0:1f9b2707ec7d 609 }
AzureIoTClient 0:1f9b2707ec7d 610
AzureIoTClient 0:1f9b2707ec7d 611
AzureIoTClient 0:1f9b2707ec7d 612 /*returns 0 if everything went ok*/
AzureIoTClient 0:1f9b2707ec7d 613 /*scans 2 base64 characters + 1 special + 1 optional = and returns 2 usual bytes*/
AzureIoTClient 0:1f9b2707ec7d 614 int scanbase64b16(const char* source, size_t sourceSize, size_t *consumed, unsigned char* destination0, unsigned char* destination1)
AzureIoTClient 0:1f9b2707ec7d 615 {
AzureIoTClient 0:1f9b2707ec7d 616 int result;
AzureIoTClient 0:1f9b2707ec7d 617 if (sourceSize < 3)
AzureIoTClient 0:1f9b2707ec7d 618 {
AzureIoTClient 0:1f9b2707ec7d 619 result = 1;
AzureIoTClient 0:1f9b2707ec7d 620 }
AzureIoTClient 0:1f9b2707ec7d 621 else
AzureIoTClient 0:1f9b2707ec7d 622 {
AzureIoTClient 0:1f9b2707ec7d 623 unsigned char c0, c1, c2;
AzureIoTClient 0:1f9b2707ec7d 624 *consumed = 0;
AzureIoTClient 0:1f9b2707ec7d 625 if (
AzureIoTClient 0:1f9b2707ec7d 626 (base64toValue(source[0], &c0) == 0) &&
AzureIoTClient 0:1f9b2707ec7d 627 (base64toValue(source[1], &c1) == 0) &&
AzureIoTClient 0:1f9b2707ec7d 628 (base64b16toValue(source[2], &c2) == 0)
AzureIoTClient 0:1f9b2707ec7d 629 )
AzureIoTClient 0:1f9b2707ec7d 630 {
AzureIoTClient 0:1f9b2707ec7d 631 *consumed = 3 + ((sourceSize>=3)&&(source[3] == '=')); /*== produce 1 or 0 ( in C )*/
AzureIoTClient 0:1f9b2707ec7d 632 *destination0 = (c0 << 2) | ((c1 & 0x30) >> 4);
AzureIoTClient 0:1f9b2707ec7d 633 *destination1 = ((c1 &0x0F) <<4) | c2;
AzureIoTClient 0:1f9b2707ec7d 634 result = 0;
AzureIoTClient 0:1f9b2707ec7d 635 }
AzureIoTClient 0:1f9b2707ec7d 636 else
AzureIoTClient 0:1f9b2707ec7d 637 {
AzureIoTClient 0:1f9b2707ec7d 638 result = 2;
AzureIoTClient 0:1f9b2707ec7d 639 }
AzureIoTClient 0:1f9b2707ec7d 640 }
AzureIoTClient 0:1f9b2707ec7d 641 return result;
AzureIoTClient 0:1f9b2707ec7d 642 }
AzureIoTClient 0:1f9b2707ec7d 643
AzureIoTClient 0:1f9b2707ec7d 644 /*return 0 if everything is ok*/
AzureIoTClient 0:1f9b2707ec7d 645 /*Reads base64b8 = base64char ( 'A' / 'Q' / 'g' / 'w' ) [ "==" ]*/
AzureIoTClient 0:1f9b2707ec7d 646 int scanbase64b8(const char* source, size_t sourceSize, size_t *consumed, unsigned char* destination0)
AzureIoTClient 0:1f9b2707ec7d 647 {
AzureIoTClient 0:1f9b2707ec7d 648 int result;
AzureIoTClient 0:1f9b2707ec7d 649 if (sourceSize < 2)
AzureIoTClient 0:1f9b2707ec7d 650 {
AzureIoTClient 0:1f9b2707ec7d 651 result = 1;
AzureIoTClient 0:1f9b2707ec7d 652 }
AzureIoTClient 0:1f9b2707ec7d 653 else
AzureIoTClient 0:1f9b2707ec7d 654 {
AzureIoTClient 0:1f9b2707ec7d 655 unsigned char c0, c1;
AzureIoTClient 0:1f9b2707ec7d 656 if (
AzureIoTClient 0:1f9b2707ec7d 657 (base64toValue(source[0], &c0) == 0) &&
AzureIoTClient 0:1f9b2707ec7d 658 (base64b8toValue(source[1], &c1) == 0)
AzureIoTClient 0:1f9b2707ec7d 659 )
AzureIoTClient 0:1f9b2707ec7d 660 {
AzureIoTClient 0:1f9b2707ec7d 661 *consumed = 2 + (((sourceSize>=4) && (source[2] == '=') && (source[3] == '='))?2:0); /*== produce 1 or 0 ( in C )*/
AzureIoTClient 0:1f9b2707ec7d 662 *destination0 = (c0 << 2) | (c1 & 3);
AzureIoTClient 0:1f9b2707ec7d 663 result = 0;
AzureIoTClient 0:1f9b2707ec7d 664 }
AzureIoTClient 0:1f9b2707ec7d 665 else
AzureIoTClient 0:1f9b2707ec7d 666 {
AzureIoTClient 0:1f9b2707ec7d 667 result = 2;
AzureIoTClient 0:1f9b2707ec7d 668 }
AzureIoTClient 0:1f9b2707ec7d 669 }
AzureIoTClient 0:1f9b2707ec7d 670 return result;
AzureIoTClient 0:1f9b2707ec7d 671 }
AzureIoTClient 0:1f9b2707ec7d 672
AzureIoTClient 0:1f9b2707ec7d 673 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_039:[ Creates an AGENT_DATA_TYPE containing an EDM_DECIMAL from a null-terminated string.]*/
AzureIoTClient 0:1f9b2707ec7d 674 AGENT_DATA_TYPES_RESULT Create_EDM_DECIMAL_from_charz(AGENT_DATA_TYPE* agentData, const char* v)
AzureIoTClient 0:1f9b2707ec7d 675 {
AzureIoTClient 0:1f9b2707ec7d 676 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 677 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the Create_... functions shall check their parameters for validity. When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 678 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 679 {
AzureIoTClient 0:1f9b2707ec7d 680 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 681 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 682 }
AzureIoTClient 0:1f9b2707ec7d 683 else if (v == NULL)
AzureIoTClient 0:1f9b2707ec7d 684 {
AzureIoTClient 0:1f9b2707ec7d 685 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 686 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 687 }
AzureIoTClient 0:1f9b2707ec7d 688 else
AzureIoTClient 0:1f9b2707ec7d 689 {
AzureIoTClient 0:1f9b2707ec7d 690 size_t vlen = strlen(v);
AzureIoTClient 0:1f9b2707ec7d 691 /*validate that v has the form [SIGN] 1*DIGIT ["." 1*DIGIT]*/
AzureIoTClient 0:1f9b2707ec7d 692 if (vlen == 0)
AzureIoTClient 0:1f9b2707ec7d 693 {
AzureIoTClient 0:1f9b2707ec7d 694 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_067:[ If the string indicated by the parameter v does not match exactly an ODATA string representation, AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 695 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 696 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 697 }
AzureIoTClient 0:1f9b2707ec7d 698 else
AzureIoTClient 0:1f9b2707ec7d 699 {
AzureIoTClient 0:1f9b2707ec7d 700 if (ValidateDecimal(v, vlen) != 0)
AzureIoTClient 0:1f9b2707ec7d 701 {
AzureIoTClient 0:1f9b2707ec7d 702 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_067:[ If the string indicated by the parameter v does not match exactly an ODATA string representation, AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 703 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 704 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 705 }
AzureIoTClient 0:1f9b2707ec7d 706 else if ((agentData->value.edmDecimal.value = STRING_construct(v)) == NULL)
AzureIoTClient 0:1f9b2707ec7d 707 {
AzureIoTClient 0:1f9b2707ec7d 708 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 709 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 710 }
AzureIoTClient 0:1f9b2707ec7d 711 else
AzureIoTClient 0:1f9b2707ec7d 712 {
AzureIoTClient 0:1f9b2707ec7d 713 agentData->type = EDM_DECIMAL_TYPE;
AzureIoTClient 0:1f9b2707ec7d 714 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 715 }
AzureIoTClient 0:1f9b2707ec7d 716 }
AzureIoTClient 0:1f9b2707ec7d 717 }
AzureIoTClient 0:1f9b2707ec7d 718 return result;
AzureIoTClient 0:1f9b2707ec7d 719 }
AzureIoTClient 0:1f9b2707ec7d 720
AzureIoTClient 0:1f9b2707ec7d 721 /*create an AGENT_DATA_TYPE containing an EDM_DOUBLE from a double*/
AzureIoTClient 0:1f9b2707ec7d 722 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_DOUBLE(AGENT_DATA_TYPE* agentData, double v)
AzureIoTClient 0:1f9b2707ec7d 723 {
AzureIoTClient 0:1f9b2707ec7d 724 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 725 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[All the Create_... functions shall check their parameters for validity.When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned]*/
AzureIoTClient 0:1f9b2707ec7d 726 if(agentData==NULL)
AzureIoTClient 0:1f9b2707ec7d 727 {
AzureIoTClient 0:1f9b2707ec7d 728 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 729 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 730 }
AzureIoTClient 0:1f9b2707ec7d 731 else
AzureIoTClient 0:1f9b2707ec7d 732 {
AzureIoTClient 0:1f9b2707ec7d 733 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_041:[Creates an AGENT_DATA_TYPE containing an EDM_DOUBLE from double]*/
AzureIoTClient 0:1f9b2707ec7d 734 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_042:[Values of NaN, -INF, +INF are accepted]*/
AzureIoTClient 0:1f9b2707ec7d 735 agentData->type = EDM_DOUBLE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 736 agentData->value.edmDouble.value = v;
AzureIoTClient 0:1f9b2707ec7d 737 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 738 }
AzureIoTClient 0:1f9b2707ec7d 739 return result;
AzureIoTClient 0:1f9b2707ec7d 740 }
AzureIoTClient 0:1f9b2707ec7d 741
AzureIoTClient 0:1f9b2707ec7d 742 /*create an AGENT_DATA_TYPE from INT16_T*/
AzureIoTClient 0:1f9b2707ec7d 743 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_043:[ Creates an AGENT_DATA_TYPE containing an EDM_INT16 from int16_t]*/
AzureIoTClient 0:1f9b2707ec7d 744 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_SINT16(AGENT_DATA_TYPE* agentData, int16_t v)
AzureIoTClient 0:1f9b2707ec7d 745 {
AzureIoTClient 0:1f9b2707ec7d 746 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 747 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the Create_... functions shall check their parameters for validity. When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 748 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 749 {
AzureIoTClient 0:1f9b2707ec7d 750 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 751 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 752 }
AzureIoTClient 0:1f9b2707ec7d 753 else
AzureIoTClient 0:1f9b2707ec7d 754 {
AzureIoTClient 0:1f9b2707ec7d 755 agentData->type = EDM_INT16_TYPE;
AzureIoTClient 0:1f9b2707ec7d 756 agentData->value.edmInt16.value = v;
AzureIoTClient 0:1f9b2707ec7d 757 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 758 }
AzureIoTClient 0:1f9b2707ec7d 759 return result;
AzureIoTClient 0:1f9b2707ec7d 760 }
AzureIoTClient 0:1f9b2707ec7d 761
AzureIoTClient 0:1f9b2707ec7d 762 /*create an AGENT_DATA_TYPE from INT32_T*/
AzureIoTClient 0:1f9b2707ec7d 763 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_SINT32(AGENT_DATA_TYPE* agentData, int32_t v)
AzureIoTClient 0:1f9b2707ec7d 764 {
AzureIoTClient 0:1f9b2707ec7d 765 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 766 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the Create_... functions shall check their parameters for validity. When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 767 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 768 {
AzureIoTClient 0:1f9b2707ec7d 769 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 770 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 771 }
AzureIoTClient 0:1f9b2707ec7d 772 else
AzureIoTClient 0:1f9b2707ec7d 773 {
AzureIoTClient 0:1f9b2707ec7d 774 agentData->type = EDM_INT32_TYPE;
AzureIoTClient 0:1f9b2707ec7d 775 agentData->value.edmInt32.value = v;
AzureIoTClient 0:1f9b2707ec7d 776 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 777 }
AzureIoTClient 0:1f9b2707ec7d 778 return result;
AzureIoTClient 0:1f9b2707ec7d 779 }
AzureIoTClient 0:1f9b2707ec7d 780
AzureIoTClient 0:1f9b2707ec7d 781 /*create an AGENT_DATA_TYPE from INT64_T*/
AzureIoTClient 0:1f9b2707ec7d 782 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_045:[ Creates an AGENT_DATA_TYPE containing an EDM_INT64 from int64_t]*/
AzureIoTClient 0:1f9b2707ec7d 783 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_SINT64(AGENT_DATA_TYPE* agentData, int64_t v)
AzureIoTClient 0:1f9b2707ec7d 784 {
AzureIoTClient 0:1f9b2707ec7d 785 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 786 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the Create_... functions shall check their parameters for validity. When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 787 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 788 {
AzureIoTClient 0:1f9b2707ec7d 789 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 790 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 791
AzureIoTClient 0:1f9b2707ec7d 792 }
AzureIoTClient 0:1f9b2707ec7d 793 else
AzureIoTClient 0:1f9b2707ec7d 794 {
AzureIoTClient 0:1f9b2707ec7d 795 agentData->type = EDM_INT64_TYPE;
AzureIoTClient 0:1f9b2707ec7d 796 agentData->value.edmInt64.value = v;
AzureIoTClient 0:1f9b2707ec7d 797 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 798 }
AzureIoTClient 0:1f9b2707ec7d 799 return result;
AzureIoTClient 0:1f9b2707ec7d 800 }
AzureIoTClient 0:1f9b2707ec7d 801
AzureIoTClient 0:1f9b2707ec7d 802 /*create an AGENT_DATA_TYPE from int8_t*/
AzureIoTClient 0:1f9b2707ec7d 803 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_SINT8(AGENT_DATA_TYPE* agentData, int8_t v)
AzureIoTClient 0:1f9b2707ec7d 804 {
AzureIoTClient 0:1f9b2707ec7d 805 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 806 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the Create_... functions shall check their parameters for validity. When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 807 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 808 {
AzureIoTClient 0:1f9b2707ec7d 809 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 810 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 811
AzureIoTClient 0:1f9b2707ec7d 812 }
AzureIoTClient 0:1f9b2707ec7d 813 else
AzureIoTClient 0:1f9b2707ec7d 814 {
AzureIoTClient 0:1f9b2707ec7d 815 agentData->type = EDM_SBYTE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 816 agentData->value.edmSbyte.value = v;
AzureIoTClient 0:1f9b2707ec7d 817 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 818 }
AzureIoTClient 0:1f9b2707ec7d 819 return result;
AzureIoTClient 0:1f9b2707ec7d 820 }
AzureIoTClient 0:1f9b2707ec7d 821
AzureIoTClient 0:1f9b2707ec7d 822 static int ValidateDate(int year, int month, int day)
AzureIoTClient 0:1f9b2707ec7d 823 {
AzureIoTClient 0:1f9b2707ec7d 824 int result;
AzureIoTClient 0:1f9b2707ec7d 825
AzureIoTClient 0:1f9b2707ec7d 826 if ((year <= -10000) || (year >= 10000))
AzureIoTClient 0:1f9b2707ec7d 827 {
AzureIoTClient 0:1f9b2707ec7d 828 result = 1;
AzureIoTClient 0:1f9b2707ec7d 829 }
AzureIoTClient 0:1f9b2707ec7d 830 else
AzureIoTClient 0:1f9b2707ec7d 831 {
AzureIoTClient 0:1f9b2707ec7d 832 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_070:[ If year-month-date does not indicate a valid day (for example 31 Feb 2013), then AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 833 if (day <= 0)
AzureIoTClient 0:1f9b2707ec7d 834 {
AzureIoTClient 0:1f9b2707ec7d 835 result = 1;
AzureIoTClient 0:1f9b2707ec7d 836 }
AzureIoTClient 0:1f9b2707ec7d 837 else
AzureIoTClient 0:1f9b2707ec7d 838 {
AzureIoTClient 0:1f9b2707ec7d 839 /*the following data will be validated...*/
AzureIoTClient 0:1f9b2707ec7d 840 /*leap years are those that can be divided by 4. But if the year can be divided by 100, it is not leap. But if they year can be divided by 400 it is leap*/
AzureIoTClient 0:1f9b2707ec7d 841 if (
AzureIoTClient 0:1f9b2707ec7d 842 (month == 1) || /*these months have always 31 days*/
AzureIoTClient 0:1f9b2707ec7d 843 (month == 3) ||
AzureIoTClient 0:1f9b2707ec7d 844 (month == 5) ||
AzureIoTClient 0:1f9b2707ec7d 845 (month == 7) ||
AzureIoTClient 0:1f9b2707ec7d 846 (month == 8) ||
AzureIoTClient 0:1f9b2707ec7d 847 (month == 10) ||
AzureIoTClient 0:1f9b2707ec7d 848 (month == 12)
AzureIoTClient 0:1f9b2707ec7d 849 )
AzureIoTClient 0:1f9b2707ec7d 850 {
AzureIoTClient 0:1f9b2707ec7d 851 if (day <= 31)
AzureIoTClient 0:1f9b2707ec7d 852 {
AzureIoTClient 0:1f9b2707ec7d 853 result = 0;
AzureIoTClient 0:1f9b2707ec7d 854 }
AzureIoTClient 0:1f9b2707ec7d 855 else
AzureIoTClient 0:1f9b2707ec7d 856 {
AzureIoTClient 0:1f9b2707ec7d 857 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_070:[If year - month - date does not indicate a valid day(for example 31 Feb 2013), then AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 858 result = 1;
AzureIoTClient 0:1f9b2707ec7d 859 }
AzureIoTClient 0:1f9b2707ec7d 860 }
AzureIoTClient 0:1f9b2707ec7d 861 else if (
AzureIoTClient 0:1f9b2707ec7d 862 (month == 4) ||
AzureIoTClient 0:1f9b2707ec7d 863 (month == 6) ||
AzureIoTClient 0:1f9b2707ec7d 864 (month == 9) ||
AzureIoTClient 0:1f9b2707ec7d 865 (month == 11)
AzureIoTClient 0:1f9b2707ec7d 866 )
AzureIoTClient 0:1f9b2707ec7d 867 {
AzureIoTClient 0:1f9b2707ec7d 868 if (day <= 30)
AzureIoTClient 0:1f9b2707ec7d 869 {
AzureIoTClient 0:1f9b2707ec7d 870 result = 0;
AzureIoTClient 0:1f9b2707ec7d 871 }
AzureIoTClient 0:1f9b2707ec7d 872 else
AzureIoTClient 0:1f9b2707ec7d 873 {
AzureIoTClient 0:1f9b2707ec7d 874 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_070:[If year - month - date does not indicate a valid day(for example 31 Feb 2013), then AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 875 result = -1;
AzureIoTClient 0:1f9b2707ec7d 876 }
AzureIoTClient 0:1f9b2707ec7d 877 }
AzureIoTClient 0:1f9b2707ec7d 878 else if (month == 2)/*february*/
AzureIoTClient 0:1f9b2707ec7d 879 {
AzureIoTClient 0:1f9b2707ec7d 880 if ((year % 400) == 0)
AzureIoTClient 0:1f9b2707ec7d 881 {
AzureIoTClient 0:1f9b2707ec7d 882 /*these are leap years, suchs as 2000*/
AzureIoTClient 0:1f9b2707ec7d 883 if (day <= 29)
AzureIoTClient 0:1f9b2707ec7d 884 {
AzureIoTClient 0:1f9b2707ec7d 885 result = 0;
AzureIoTClient 0:1f9b2707ec7d 886 }
AzureIoTClient 0:1f9b2707ec7d 887 else
AzureIoTClient 0:1f9b2707ec7d 888 {
AzureIoTClient 0:1f9b2707ec7d 889 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_070:[If year - month - date does not indicate a valid day(for example 31 Feb 2013), then AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 890 result = 1;
AzureIoTClient 0:1f9b2707ec7d 891 }
AzureIoTClient 0:1f9b2707ec7d 892 }
AzureIoTClient 0:1f9b2707ec7d 893 else if ((year % 100) == 0)
AzureIoTClient 0:1f9b2707ec7d 894 {
AzureIoTClient 0:1f9b2707ec7d 895 /*non-leap year, such as 1900*/
AzureIoTClient 0:1f9b2707ec7d 896 if (day <= 28)
AzureIoTClient 0:1f9b2707ec7d 897 {
AzureIoTClient 0:1f9b2707ec7d 898 result = 0;
AzureIoTClient 0:1f9b2707ec7d 899 }
AzureIoTClient 0:1f9b2707ec7d 900 else
AzureIoTClient 0:1f9b2707ec7d 901 {
AzureIoTClient 0:1f9b2707ec7d 902 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_070:[If year - month - date does not indicate a valid day(for example 31 Feb 2013), then AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 903 result = 1;
AzureIoTClient 0:1f9b2707ec7d 904 }
AzureIoTClient 0:1f9b2707ec7d 905 }
AzureIoTClient 0:1f9b2707ec7d 906 else if ((year % 4) == 0)
AzureIoTClient 0:1f9b2707ec7d 907 {
AzureIoTClient 0:1f9b2707ec7d 908 /*these are leap years, such as 2104*/
AzureIoTClient 0:1f9b2707ec7d 909 if (day <= 29)
AzureIoTClient 0:1f9b2707ec7d 910 {
AzureIoTClient 0:1f9b2707ec7d 911 result = 0;
AzureIoTClient 0:1f9b2707ec7d 912 }
AzureIoTClient 0:1f9b2707ec7d 913 else
AzureIoTClient 0:1f9b2707ec7d 914 {
AzureIoTClient 0:1f9b2707ec7d 915 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_070:[If year - month - date does not indicate a valid day(for example 31 Feb 2013), then AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 916 result = 1;
AzureIoTClient 0:1f9b2707ec7d 917 }
AzureIoTClient 0:1f9b2707ec7d 918 }
AzureIoTClient 0:1f9b2707ec7d 919 else
AzureIoTClient 0:1f9b2707ec7d 920 {
AzureIoTClient 0:1f9b2707ec7d 921 /*certainly not a leap year*/
AzureIoTClient 0:1f9b2707ec7d 922 if (day <= 28)
AzureIoTClient 0:1f9b2707ec7d 923 {
AzureIoTClient 0:1f9b2707ec7d 924 result = 0;
AzureIoTClient 0:1f9b2707ec7d 925 }
AzureIoTClient 0:1f9b2707ec7d 926 else
AzureIoTClient 0:1f9b2707ec7d 927 {
AzureIoTClient 0:1f9b2707ec7d 928 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_070:[If year - month - date does not indicate a valid day(for example 31 Feb 2013), then AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 929 result = 1;
AzureIoTClient 0:1f9b2707ec7d 930 }
AzureIoTClient 0:1f9b2707ec7d 931 }
AzureIoTClient 0:1f9b2707ec7d 932 }
AzureIoTClient 0:1f9b2707ec7d 933 else
AzureIoTClient 0:1f9b2707ec7d 934 {
AzureIoTClient 0:1f9b2707ec7d 935 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_070:[If year - month - date does not indicate a valid day(for example 31 Feb 2013), then AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 936 result = 1;
AzureIoTClient 0:1f9b2707ec7d 937 }
AzureIoTClient 0:1f9b2707ec7d 938 }
AzureIoTClient 0:1f9b2707ec7d 939 }
AzureIoTClient 0:1f9b2707ec7d 940
AzureIoTClient 0:1f9b2707ec7d 941 return result;
AzureIoTClient 0:1f9b2707ec7d 942 }
AzureIoTClient 0:1f9b2707ec7d 943
AzureIoTClient 0:1f9b2707ec7d 944 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_069:[ Creates an AGENT_DATA_TYPE containing an EDM_DATE from a year, a month and a day of the month.]*/
AzureIoTClient 0:1f9b2707ec7d 945 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_date(AGENT_DATA_TYPE* agentData, int16_t year, uint8_t month, uint8_t day)
AzureIoTClient 0:1f9b2707ec7d 946 {
AzureIoTClient 0:1f9b2707ec7d 947 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 948 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the Create_... functions shall check their parameters for validity. When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 949 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 950 {
AzureIoTClient 0:1f9b2707ec7d 951 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 952 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 953 }
AzureIoTClient 0:1f9b2707ec7d 954 /*ODATA-ABNF: year = [ "-" ] ( "0" 3DIGIT / oneToNine 3*DIGIT )*/
AzureIoTClient 0:1f9b2707ec7d 955 else if (ValidateDate(year, month, day) != 0)
AzureIoTClient 0:1f9b2707ec7d 956 {
AzureIoTClient 0:1f9b2707ec7d 957 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 958 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 959 }
AzureIoTClient 0:1f9b2707ec7d 960 else
AzureIoTClient 0:1f9b2707ec7d 961 {
AzureIoTClient 0:1f9b2707ec7d 962 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_069:[ Creates an AGENT_DATA_TYPE containing an EDM_DATE from a year, a month and a day of the month.]*/
AzureIoTClient 0:1f9b2707ec7d 963 agentData->type = EDM_DATE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 964 agentData->value.edmDate.year = year;
AzureIoTClient 0:1f9b2707ec7d 965 agentData->value.edmDate.month = month;
AzureIoTClient 0:1f9b2707ec7d 966 agentData->value.edmDate.day = day;
AzureIoTClient 0:1f9b2707ec7d 967 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 968 }
AzureIoTClient 0:1f9b2707ec7d 969
AzureIoTClient 0:1f9b2707ec7d 970 return result;
AzureIoTClient 0:1f9b2707ec7d 971 }
AzureIoTClient 0:1f9b2707ec7d 972
AzureIoTClient 0:1f9b2707ec7d 973
AzureIoTClient 0:1f9b2707ec7d 974 /*create an AGENT_DATA_TYPE from SINGLE*/
AzureIoTClient 0:1f9b2707ec7d 975 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_FLOAT(AGENT_DATA_TYPE* agentData, float v)
AzureIoTClient 0:1f9b2707ec7d 976 {
AzureIoTClient 0:1f9b2707ec7d 977 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 978 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[All the Create_... functions shall check their parameters for validity.When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned]*/
AzureIoTClient 0:1f9b2707ec7d 979 if(agentData==NULL)
AzureIoTClient 0:1f9b2707ec7d 980 {
AzureIoTClient 0:1f9b2707ec7d 981 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 982 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 983 }
AzureIoTClient 0:1f9b2707ec7d 984 else
AzureIoTClient 0:1f9b2707ec7d 985 {
AzureIoTClient 0:1f9b2707ec7d 986 agentData->type = EDM_SINGLE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 987 agentData->value.edmSingle.value = v;
AzureIoTClient 0:1f9b2707ec7d 988 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 989 }
AzureIoTClient 0:1f9b2707ec7d 990 return result;
AzureIoTClient 0:1f9b2707ec7d 991 }
AzureIoTClient 0:1f9b2707ec7d 992
AzureIoTClient 0:1f9b2707ec7d 993 const char hexToASCII[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
AzureIoTClient 0:1f9b2707ec7d 994
AzureIoTClient 0:1f9b2707ec7d 995 /*create an AGENT_DATA_TYPE from ANSI zero terminated string*/
AzureIoTClient 0:1f9b2707ec7d 996 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_charz(AGENT_DATA_TYPE* agentData, const char* v)
AzureIoTClient 0:1f9b2707ec7d 997 {
AzureIoTClient 0:1f9b2707ec7d 998 AGENT_DATA_TYPES_RESULT result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 999 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the Create_... functions shall check their parameters for validity. When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 1000 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 1001 {
AzureIoTClient 0:1f9b2707ec7d 1002 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1003 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1004 }
AzureIoTClient 0:1f9b2707ec7d 1005 else if (v == NULL)
AzureIoTClient 0:1f9b2707ec7d 1006 {
AzureIoTClient 0:1f9b2707ec7d 1007 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1008 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1009 }
AzureIoTClient 0:1f9b2707ec7d 1010 else
AzureIoTClient 0:1f9b2707ec7d 1011 {
AzureIoTClient 0:1f9b2707ec7d 1012 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_049:[ Creates an AGENT_DATA_TYPE containing an EDM_STRING from an ASCII zero terminated string.]*/
AzureIoTClient 0:1f9b2707ec7d 1013 agentData->type = EDM_STRING_TYPE;
AzureIoTClient 0:1f9b2707ec7d 1014 if (mallocAndStrcpy_s(&agentData->value.edmString.chars, v) != 0)
AzureIoTClient 0:1f9b2707ec7d 1015 {
AzureIoTClient 0:1f9b2707ec7d 1016 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1017 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1018 }
AzureIoTClient 0:1f9b2707ec7d 1019 else
AzureIoTClient 0:1f9b2707ec7d 1020 {
AzureIoTClient 0:1f9b2707ec7d 1021 agentData->value.edmString.length = strlen(agentData->value.edmString.chars);
AzureIoTClient 0:1f9b2707ec7d 1022 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1023 }
AzureIoTClient 0:1f9b2707ec7d 1024 }
AzureIoTClient 0:1f9b2707ec7d 1025 return result;
AzureIoTClient 0:1f9b2707ec7d 1026 }
AzureIoTClient 0:1f9b2707ec7d 1027
AzureIoTClient 0:1f9b2707ec7d 1028 /*create an AGENT_DATA_TYPE from ANSI zero terminated string (without quotes) */
AzureIoTClient 0:1f9b2707ec7d 1029 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_charz_no_quotes(AGENT_DATA_TYPE* agentData, const char* v)
AzureIoTClient 0:1f9b2707ec7d 1030 {
AzureIoTClient 0:1f9b2707ec7d 1031 AGENT_DATA_TYPES_RESULT result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1032 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the Create_... functions shall check their parameters for validity. When an invalid parameter is detected, a code of AGENT_DATA_TYPES_INVALID_ARG shall be returned ].*/
AzureIoTClient 0:1f9b2707ec7d 1033 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 1034 {
AzureIoTClient 0:1f9b2707ec7d 1035 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1036 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1037 }
AzureIoTClient 0:1f9b2707ec7d 1038 else if (v == NULL)
AzureIoTClient 0:1f9b2707ec7d 1039 {
AzureIoTClient 0:1f9b2707ec7d 1040 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1041 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1042 }
AzureIoTClient 0:1f9b2707ec7d 1043 else
AzureIoTClient 0:1f9b2707ec7d 1044 {
AzureIoTClient 0:1f9b2707ec7d 1045 /* Codes_SRS_AGENT_TYPE_SYSTEM_01_001: [Creates an AGENT_DATA_TYPE containing an EDM_STRING from an ASCII zero terminated string.] */
AzureIoTClient 0:1f9b2707ec7d 1046 agentData->type = EDM_STRING_NO_QUOTES_TYPE;
AzureIoTClient 0:1f9b2707ec7d 1047 if (mallocAndStrcpy_s(&agentData->value.edmStringNoQuotes.chars, v) != 0)
AzureIoTClient 0:1f9b2707ec7d 1048 {
AzureIoTClient 0:1f9b2707ec7d 1049 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1050 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1051 }
AzureIoTClient 0:1f9b2707ec7d 1052 else
AzureIoTClient 0:1f9b2707ec7d 1053 {
AzureIoTClient 0:1f9b2707ec7d 1054 agentData->value.edmStringNoQuotes.length = strlen(agentData->value.edmStringNoQuotes.chars);
AzureIoTClient 0:1f9b2707ec7d 1055 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1056 }
AzureIoTClient 0:1f9b2707ec7d 1057 }
AzureIoTClient 0:1f9b2707ec7d 1058 return result;
AzureIoTClient 0:1f9b2707ec7d 1059 }
AzureIoTClient 0:1f9b2707ec7d 1060
AzureIoTClient 0:1f9b2707ec7d 1061 void Destroy_AGENT_DATA_TYPE(AGENT_DATA_TYPE* agentData)
AzureIoTClient 0:1f9b2707ec7d 1062 {
AzureIoTClient 0:1f9b2707ec7d 1063 if(agentData==NULL)
AzureIoTClient 0:1f9b2707ec7d 1064 {
AzureIoTClient 11:b1327861f5e0 1065 LogError("agentData was NULL.");
AzureIoTClient 0:1f9b2707ec7d 1066 }
AzureIoTClient 0:1f9b2707ec7d 1067 else
AzureIoTClient 0:1f9b2707ec7d 1068 {
AzureIoTClient 0:1f9b2707ec7d 1069 switch(agentData->type)
AzureIoTClient 0:1f9b2707ec7d 1070 {
AzureIoTClient 0:1f9b2707ec7d 1071 default:
AzureIoTClient 0:1f9b2707ec7d 1072 {
AzureIoTClient 11:b1327861f5e0 1073 LogError("invalid agentData");
AzureIoTClient 0:1f9b2707ec7d 1074 break;
AzureIoTClient 0:1f9b2707ec7d 1075 }
AzureIoTClient 0:1f9b2707ec7d 1076 case(EDM_NO_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1077 {
AzureIoTClient 11:b1327861f5e0 1078 LogError("invalid agentData");
AzureIoTClient 0:1f9b2707ec7d 1079 break;
AzureIoTClient 0:1f9b2707ec7d 1080 }
AzureIoTClient 0:1f9b2707ec7d 1081 case(EDM_BINARY_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1082 {
AzureIoTClient 0:1f9b2707ec7d 1083 /*destroying means maybe deallocating some memory*/
AzureIoTClient 0:1f9b2707ec7d 1084 free(agentData->value.edmBinary.data); /* If ptr is a null pointer, no action occurs*/
AzureIoTClient 0:1f9b2707ec7d 1085 agentData->value.edmBinary.data = NULL;
AzureIoTClient 0:1f9b2707ec7d 1086 break;
AzureIoTClient 0:1f9b2707ec7d 1087 }
AzureIoTClient 0:1f9b2707ec7d 1088 case(EDM_BOOLEAN_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1089 {
AzureIoTClient 0:1f9b2707ec7d 1090 /*nothing to do*/
AzureIoTClient 0:1f9b2707ec7d 1091 break;
AzureIoTClient 0:1f9b2707ec7d 1092 }
AzureIoTClient 0:1f9b2707ec7d 1093 case(EDM_BYTE_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1094 {
AzureIoTClient 0:1f9b2707ec7d 1095 /*nothing to do*/
AzureIoTClient 0:1f9b2707ec7d 1096 break;
AzureIoTClient 0:1f9b2707ec7d 1097 }
AzureIoTClient 0:1f9b2707ec7d 1098 case(EDM_DATE_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1099 {
AzureIoTClient 0:1f9b2707ec7d 1100 /*nothing to do*/
AzureIoTClient 0:1f9b2707ec7d 1101 break;
AzureIoTClient 0:1f9b2707ec7d 1102 }
AzureIoTClient 0:1f9b2707ec7d 1103 case(EDM_DATE_TIME_OFFSET_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1104 {
AzureIoTClient 0:1f9b2707ec7d 1105 /*nothing to do*/
AzureIoTClient 0:1f9b2707ec7d 1106 break;
AzureIoTClient 0:1f9b2707ec7d 1107 }
AzureIoTClient 0:1f9b2707ec7d 1108 case(EDM_DECIMAL_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1109 {
AzureIoTClient 0:1f9b2707ec7d 1110 STRING_delete(agentData->value.edmDecimal.value);
AzureIoTClient 0:1f9b2707ec7d 1111 agentData->value.edmDecimal.value = NULL;
AzureIoTClient 0:1f9b2707ec7d 1112 break;
AzureIoTClient 0:1f9b2707ec7d 1113 }
AzureIoTClient 0:1f9b2707ec7d 1114 case(EDM_DURATION_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1115 {
AzureIoTClient 11:b1327861f5e0 1116 LogError("EDM_DURATION_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1117 break;
AzureIoTClient 0:1f9b2707ec7d 1118 }
AzureIoTClient 0:1f9b2707ec7d 1119 case(EDM_GUID_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1120 {
AzureIoTClient 0:1f9b2707ec7d 1121 /*nothing to do*/
AzureIoTClient 0:1f9b2707ec7d 1122 break;
AzureIoTClient 0:1f9b2707ec7d 1123 }
AzureIoTClient 0:1f9b2707ec7d 1124 case(EDM_INT16_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1125 {
AzureIoTClient 0:1f9b2707ec7d 1126 /*nothing to do*/
AzureIoTClient 0:1f9b2707ec7d 1127 break;
AzureIoTClient 0:1f9b2707ec7d 1128 }
AzureIoTClient 0:1f9b2707ec7d 1129 case(EDM_INT32_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1130 {
AzureIoTClient 0:1f9b2707ec7d 1131 /*nothing to do*/
AzureIoTClient 0:1f9b2707ec7d 1132 break;
AzureIoTClient 0:1f9b2707ec7d 1133 }
AzureIoTClient 0:1f9b2707ec7d 1134 case(EDM_INT64_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1135 {
AzureIoTClient 0:1f9b2707ec7d 1136 /*nothing to do*/
AzureIoTClient 0:1f9b2707ec7d 1137 break;
AzureIoTClient 0:1f9b2707ec7d 1138 }
AzureIoTClient 0:1f9b2707ec7d 1139 case(EDM_SBYTE_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1140 {
AzureIoTClient 0:1f9b2707ec7d 1141 /*nothing to do*/
AzureIoTClient 0:1f9b2707ec7d 1142 break;
AzureIoTClient 0:1f9b2707ec7d 1143 }
AzureIoTClient 0:1f9b2707ec7d 1144 case(EDM_STREAM):
AzureIoTClient 0:1f9b2707ec7d 1145 {
AzureIoTClient 11:b1327861f5e0 1146 LogError("EDM_STREAM not implemented");
AzureIoTClient 0:1f9b2707ec7d 1147 break;
AzureIoTClient 0:1f9b2707ec7d 1148 }
AzureIoTClient 0:1f9b2707ec7d 1149 case(EDM_STRING_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1150 {
AzureIoTClient 0:1f9b2707ec7d 1151 if (agentData->value.edmString.chars != NULL)
AzureIoTClient 0:1f9b2707ec7d 1152 {
AzureIoTClient 0:1f9b2707ec7d 1153 free(agentData->value.edmString.chars);
AzureIoTClient 0:1f9b2707ec7d 1154 agentData->value.edmString.chars = NULL;
AzureIoTClient 0:1f9b2707ec7d 1155 }
AzureIoTClient 0:1f9b2707ec7d 1156 break;
AzureIoTClient 0:1f9b2707ec7d 1157 }
AzureIoTClient 0:1f9b2707ec7d 1158 case(EDM_STRING_NO_QUOTES_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1159 {
AzureIoTClient 0:1f9b2707ec7d 1160 if (agentData->value.edmStringNoQuotes.chars != NULL)
AzureIoTClient 0:1f9b2707ec7d 1161 {
AzureIoTClient 0:1f9b2707ec7d 1162 free(agentData->value.edmStringNoQuotes.chars);
AzureIoTClient 0:1f9b2707ec7d 1163 agentData->value.edmStringNoQuotes.chars = NULL;
AzureIoTClient 0:1f9b2707ec7d 1164 }
AzureIoTClient 0:1f9b2707ec7d 1165 break;
AzureIoTClient 0:1f9b2707ec7d 1166 }
AzureIoTClient 0:1f9b2707ec7d 1167 case(EDM_TIME_OF_DAY_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1168 {
AzureIoTClient 11:b1327861f5e0 1169 LogError("EDM_TIME_OF_DAY_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1170 break;
AzureIoTClient 0:1f9b2707ec7d 1171 }
AzureIoTClient 0:1f9b2707ec7d 1172 case(EDM_GEOGRAPHY_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1173 {
AzureIoTClient 11:b1327861f5e0 1174 LogError("EDM_GEOGRAPHY_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1175 break;
AzureIoTClient 0:1f9b2707ec7d 1176 }
AzureIoTClient 0:1f9b2707ec7d 1177 case(EDM_GEOGRAPHY_POINT_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1178 {
AzureIoTClient 11:b1327861f5e0 1179 LogError("EDM_GEOGRAPHY_POINT_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1180 break;
AzureIoTClient 0:1f9b2707ec7d 1181 }
AzureIoTClient 0:1f9b2707ec7d 1182 case(EDM_GEOGRAPHY_LINE_STRING_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1183 {
AzureIoTClient 11:b1327861f5e0 1184 LogError("EDM_GEOGRAPHY_LINE_STRING_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1185 break;
AzureIoTClient 0:1f9b2707ec7d 1186 }
AzureIoTClient 0:1f9b2707ec7d 1187 case(EDM_GEOGRAPHY_POLYGON_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1188 {
AzureIoTClient 11:b1327861f5e0 1189 LogError("EDM_GEOGRAPHY_POLYGON_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1190 break;
AzureIoTClient 0:1f9b2707ec7d 1191 }
AzureIoTClient 0:1f9b2707ec7d 1192 case(EDM_GEOGRAPHY_MULTI_POINT_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1193 {
AzureIoTClient 11:b1327861f5e0 1194 LogError("EDM_GEOGRAPHY_MULTI_POINT_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1195 break;
AzureIoTClient 0:1f9b2707ec7d 1196 }
AzureIoTClient 0:1f9b2707ec7d 1197 case(EDM_GEOGRAPHY_MULTI_LINE_STRING_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1198 {
AzureIoTClient 11:b1327861f5e0 1199 LogError("EDM_GEOGRAPHY_MULTI_LINE_STRING_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1200 break;
AzureIoTClient 0:1f9b2707ec7d 1201 }
AzureIoTClient 0:1f9b2707ec7d 1202 case(EDM_GEOGRAPHY_MULTI_POLYGON_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1203 {
AzureIoTClient 11:b1327861f5e0 1204 LogError("EDM_GEOGRAPHY_MULTI_POLYGON_TYPE");
AzureIoTClient 0:1f9b2707ec7d 1205 break;
AzureIoTClient 0:1f9b2707ec7d 1206 }
AzureIoTClient 0:1f9b2707ec7d 1207 case(EDM_GEOGRAPHY_COLLECTION_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1208 {
AzureIoTClient 11:b1327861f5e0 1209 LogError("EDM_GEOGRAPHY_COLLECTION_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1210 break;
AzureIoTClient 0:1f9b2707ec7d 1211 }
AzureIoTClient 0:1f9b2707ec7d 1212 case(EDM_GEOMETRY_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1213 {
AzureIoTClient 11:b1327861f5e0 1214 LogError("EDM_GEOMETRY_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1215 break;
AzureIoTClient 0:1f9b2707ec7d 1216 }
AzureIoTClient 0:1f9b2707ec7d 1217 case(EDM_GEOMETRY_POINT_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1218 {
AzureIoTClient 11:b1327861f5e0 1219 LogError("EDM_GEOMETRY_POINT_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1220 break;
AzureIoTClient 0:1f9b2707ec7d 1221 }
AzureIoTClient 0:1f9b2707ec7d 1222 case(EDM_GEOMETRY_LINE_STRING_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1223 {
AzureIoTClient 11:b1327861f5e0 1224 LogError("EDM_GEOMETRY_LINE_STRING_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1225 break;
AzureIoTClient 0:1f9b2707ec7d 1226 }
AzureIoTClient 0:1f9b2707ec7d 1227 case(EDM_GEOMETRY_POLYGON_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1228 {
AzureIoTClient 11:b1327861f5e0 1229 LogError("EDM_GEOMETRY_POLYGON_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1230 break;
AzureIoTClient 0:1f9b2707ec7d 1231 }
AzureIoTClient 0:1f9b2707ec7d 1232 case(EDM_GEOMETRY_MULTI_POINT_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1233 {
AzureIoTClient 11:b1327861f5e0 1234 LogError("EDM_GEOMETRY_MULTI_POINT_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1235 break;
AzureIoTClient 0:1f9b2707ec7d 1236 }
AzureIoTClient 0:1f9b2707ec7d 1237 case(EDM_GEOMETRY_MULTI_LINE_STRING_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1238 {
AzureIoTClient 11:b1327861f5e0 1239 LogError("EDM_GEOMETRY_MULTI_LINE_STRING_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1240 break;
AzureIoTClient 0:1f9b2707ec7d 1241 }
AzureIoTClient 0:1f9b2707ec7d 1242 case(EDM_GEOMETRY_MULTI_POLYGON_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1243 {
AzureIoTClient 11:b1327861f5e0 1244 LogError("EDM_GEOMETRY_MULTI_POLYGON_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1245 break;
AzureIoTClient 0:1f9b2707ec7d 1246 }
AzureIoTClient 0:1f9b2707ec7d 1247 case(EDM_GEOMETRY_COLLECTION_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1248 {
AzureIoTClient 11:b1327861f5e0 1249 LogError("EDM_GEOMETRY_COLLECTION_TYPE not implemented");
AzureIoTClient 0:1f9b2707ec7d 1250 break;
AzureIoTClient 0:1f9b2707ec7d 1251 }
AzureIoTClient 0:1f9b2707ec7d 1252 case(EDM_SINGLE_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1253 {
AzureIoTClient 0:1f9b2707ec7d 1254 break;
AzureIoTClient 0:1f9b2707ec7d 1255 }
AzureIoTClient 0:1f9b2707ec7d 1256 case(EDM_DOUBLE_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1257 {
AzureIoTClient 0:1f9b2707ec7d 1258 break;
AzureIoTClient 0:1f9b2707ec7d 1259 }
AzureIoTClient 0:1f9b2707ec7d 1260 case (EDM_COMPLEX_TYPE_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1261 {
AzureIoTClient 0:1f9b2707ec7d 1262 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_050:[Destroy_AGENT_DATA_TYPE shall deallocate all allocated resources used to represent the type.]*/
AzureIoTClient 0:1f9b2707ec7d 1263 size_t i;
AzureIoTClient 0:1f9b2707ec7d 1264 for (i = 0; i < agentData->value.edmComplexType.nMembers; i++)
AzureIoTClient 0:1f9b2707ec7d 1265 {
AzureIoTClient 0:1f9b2707ec7d 1266 free((void*)(agentData->value.edmComplexType.fields[i].fieldName));
AzureIoTClient 0:1f9b2707ec7d 1267 agentData->value.edmComplexType.fields[i].fieldName = NULL;
AzureIoTClient 0:1f9b2707ec7d 1268 Destroy_AGENT_DATA_TYPE(agentData->value.edmComplexType.fields[i].value);
AzureIoTClient 0:1f9b2707ec7d 1269 free(agentData->value.edmComplexType.fields[i].value);
AzureIoTClient 0:1f9b2707ec7d 1270 agentData->value.edmComplexType.fields[i].value = NULL;
AzureIoTClient 0:1f9b2707ec7d 1271 }
AzureIoTClient 0:1f9b2707ec7d 1272 free(agentData->value.edmComplexType.fields);
AzureIoTClient 0:1f9b2707ec7d 1273 break;
AzureIoTClient 0:1f9b2707ec7d 1274 }
AzureIoTClient 0:1f9b2707ec7d 1275 }
AzureIoTClient 0:1f9b2707ec7d 1276 agentData->type = EDM_NO_TYPE; /*mark as detroyed*/
AzureIoTClient 0:1f9b2707ec7d 1277 }
AzureIoTClient 0:1f9b2707ec7d 1278 }
AzureIoTClient 0:1f9b2707ec7d 1279
AzureIoTClient 0:1f9b2707ec7d 1280 static char hexDigitToChar(uint8_t hexDigit)
AzureIoTClient 0:1f9b2707ec7d 1281 {
AzureIoTClient 0:1f9b2707ec7d 1282 if (hexDigit < 10) return '0' + hexDigit;
AzureIoTClient 0:1f9b2707ec7d 1283 else return ('A' - 10) + hexDigit;
AzureIoTClient 0:1f9b2707ec7d 1284 }
AzureIoTClient 0:1f9b2707ec7d 1285
AzureIoTClient 0:1f9b2707ec7d 1286 AGENT_DATA_TYPES_RESULT AgentDataTypes_ToString(STRING_HANDLE destination, const AGENT_DATA_TYPE* value)
AzureIoTClient 0:1f9b2707ec7d 1287 {
AzureIoTClient 0:1f9b2707ec7d 1288 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 1289
AzureIoTClient 0:1f9b2707ec7d 1290 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_015:[If destination parameter is NULL, AgentDataTypes_ToString shall return AGENT_DATA_TYPES_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 1291 if(destination == NULL)
AzureIoTClient 0:1f9b2707ec7d 1292 {
AzureIoTClient 0:1f9b2707ec7d 1293 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1294 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1295 }
AzureIoTClient 0:1f9b2707ec7d 1296 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_053:[ If value is NULL or has been destroyed or otherwise doesn't contain valid data, AGENT_DATA_TYPES_INVALID_ARG shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 1297 else if (value == NULL)
AzureIoTClient 0:1f9b2707ec7d 1298 {
AzureIoTClient 0:1f9b2707ec7d 1299 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1300 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1301 }
AzureIoTClient 0:1f9b2707ec7d 1302 else
AzureIoTClient 0:1f9b2707ec7d 1303 {
AzureIoTClient 0:1f9b2707ec7d 1304 switch(value->type)
AzureIoTClient 0:1f9b2707ec7d 1305 {
AzureIoTClient 0:1f9b2707ec7d 1306 default:
AzureIoTClient 0:1f9b2707ec7d 1307 {
AzureIoTClient 0:1f9b2707ec7d 1308 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1309 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1310 break;
AzureIoTClient 0:1f9b2707ec7d 1311 }
AzureIoTClient 0:1f9b2707ec7d 1312 case(EDM_NULL_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1313 {
AzureIoTClient 0:1f9b2707ec7d 1314 /*SRS_AGENT_TYPE_SYSTEM_99_101:[ EDM_NULL_TYPE shall return the unquoted string null.]*/
AzureIoTClient 0:1f9b2707ec7d 1315 if (STRING_concat(destination, "null") != 0)
AzureIoTClient 0:1f9b2707ec7d 1316 {
AzureIoTClient 0:1f9b2707ec7d 1317 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_016:[ When the value cannot be converted to a string AgentDataTypes_ToString shall return AGENT_DATA_TYPES_ERROR.]*/
AzureIoTClient 0:1f9b2707ec7d 1318 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1319 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1320 }
AzureIoTClient 0:1f9b2707ec7d 1321 else
AzureIoTClient 0:1f9b2707ec7d 1322 {
AzureIoTClient 0:1f9b2707ec7d 1323 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_014:[ All functions shall return AGENT_DATA_TYPES_OK when the processing is successful.]*/
AzureIoTClient 0:1f9b2707ec7d 1324 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1325 }
AzureIoTClient 0:1f9b2707ec7d 1326 break;
AzureIoTClient 0:1f9b2707ec7d 1327 }
AzureIoTClient 0:1f9b2707ec7d 1328 case(EDM_BOOLEAN_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1329 {
AzureIoTClient 0:1f9b2707ec7d 1330 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_017:[EDM_BOOLEAN:as in(odata - abnf - construction - rules, 2013), booleanValue = "true" / "false"]*/
AzureIoTClient 0:1f9b2707ec7d 1331 if (value->value.edmBoolean.value == EDM_TRUE)
AzureIoTClient 0:1f9b2707ec7d 1332 {
AzureIoTClient 0:1f9b2707ec7d 1333 /*SRS_AGENT_TYPE_SYSTEM_99_030:[If v is different than 0 then the AGENT_DATA_TYPE shall have the value "true".]*/
AzureIoTClient 0:1f9b2707ec7d 1334 if (STRING_concat(destination, "true") != 0)
AzureIoTClient 0:1f9b2707ec7d 1335 {
AzureIoTClient 0:1f9b2707ec7d 1336 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_016:[ When the value cannot be converted to a string AgentDataTypes_ToString shall return AGENT_DATA_TYPES_ERROR.]*/
AzureIoTClient 0:1f9b2707ec7d 1337 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1338 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1339 }
AzureIoTClient 0:1f9b2707ec7d 1340 else
AzureIoTClient 0:1f9b2707ec7d 1341 {
AzureIoTClient 0:1f9b2707ec7d 1342 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_014:[ All functions shall return AGENT_DATA_TYPES_OK when the processing is successful.]*/
AzureIoTClient 0:1f9b2707ec7d 1343 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1344 }
AzureIoTClient 0:1f9b2707ec7d 1345 }
AzureIoTClient 0:1f9b2707ec7d 1346 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_017:[EDM_BOOLEAN:as in(odata - abnf - construction - rules, 2013), booleanValue = "true" / "false"]*/
AzureIoTClient 0:1f9b2707ec7d 1347 else if (value->value.edmBoolean.value == EDM_FALSE)
AzureIoTClient 0:1f9b2707ec7d 1348 {
AzureIoTClient 0:1f9b2707ec7d 1349 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_029:[ If v 0 then the AGENT_DATA_TYPE shall have the value "false" Boolean.]*/
AzureIoTClient 0:1f9b2707ec7d 1350 if (STRING_concat(destination, "false") != 0)
AzureIoTClient 0:1f9b2707ec7d 1351 {
AzureIoTClient 0:1f9b2707ec7d 1352 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_016:[ When the value cannot be converted to a string AgentDataTypes_ToString shall return AGENT_DATA_TYPES_ERROR.]*/
AzureIoTClient 0:1f9b2707ec7d 1353 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1354 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1355 }
AzureIoTClient 0:1f9b2707ec7d 1356 else
AzureIoTClient 0:1f9b2707ec7d 1357 {
AzureIoTClient 0:1f9b2707ec7d 1358 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_014:[ All functions shall return AGENT_DATA_TYPES_OK when the processing is successful.]*/
AzureIoTClient 0:1f9b2707ec7d 1359 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1360 }
AzureIoTClient 0:1f9b2707ec7d 1361 }
AzureIoTClient 0:1f9b2707ec7d 1362 else
AzureIoTClient 0:1f9b2707ec7d 1363 {
AzureIoTClient 0:1f9b2707ec7d 1364 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_053:[ If value contains invalid data, AgentDataTypes_ToString shall return AGENT_DATA_TYPES_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 1365 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1366 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1367 }
AzureIoTClient 0:1f9b2707ec7d 1368
AzureIoTClient 0:1f9b2707ec7d 1369 break;
AzureIoTClient 0:1f9b2707ec7d 1370 }
AzureIoTClient 0:1f9b2707ec7d 1371 case(EDM_BYTE_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1372 {
AzureIoTClient 0:1f9b2707ec7d 1373 char tempbuffer2[4]; /*because bytes can at most be 255 and that is 3 characters + 1 for '\0'*/
AzureIoTClient 0:1f9b2707ec7d 1374 size_t pos = 0;
AzureIoTClient 0:1f9b2707ec7d 1375 if (value->value.edmByte.value >= 100) tempbuffer2[pos++] = '0' + (value->value.edmByte.value / 100);
AzureIoTClient 0:1f9b2707ec7d 1376 if (value->value.edmByte.value >= 10) tempbuffer2[pos++] = '0' + (value->value.edmByte.value % 100) / 10;
AzureIoTClient 0:1f9b2707ec7d 1377 tempbuffer2[pos++] = '0' + (value->value.edmByte.value % 10);
AzureIoTClient 0:1f9b2707ec7d 1378 tempbuffer2[pos++] = '\0';
AzureIoTClient 0:1f9b2707ec7d 1379
AzureIoTClient 0:1f9b2707ec7d 1380 if (STRING_concat(destination, tempbuffer2) != 0)
AzureIoTClient 0:1f9b2707ec7d 1381 {
AzureIoTClient 0:1f9b2707ec7d 1382 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1383 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1384 }
AzureIoTClient 0:1f9b2707ec7d 1385 else
AzureIoTClient 0:1f9b2707ec7d 1386 {
AzureIoTClient 0:1f9b2707ec7d 1387 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1388 }
AzureIoTClient 0:1f9b2707ec7d 1389 break;
AzureIoTClient 0:1f9b2707ec7d 1390 }
AzureIoTClient 0:1f9b2707ec7d 1391 case(EDM_DATE_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1392 {
AzureIoTClient 0:1f9b2707ec7d 1393 size_t pos = 0;
AzureIoTClient 0:1f9b2707ec7d 1394 char tempBuffer2[1 + 5 + 1 + 2 + 1 + 2 + 1+1];
AzureIoTClient 0:1f9b2707ec7d 1395 int16_t year = value->value.edmDate.year;
AzureIoTClient 0:1f9b2707ec7d 1396 tempBuffer2[pos++] = '\"';
AzureIoTClient 0:1f9b2707ec7d 1397 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_068:[ EDM_DATE: dateValue = year "-" month "-" day.]*/
AzureIoTClient 0:1f9b2707ec7d 1398 if (year < 0)
AzureIoTClient 0:1f9b2707ec7d 1399 {
AzureIoTClient 0:1f9b2707ec7d 1400 tempBuffer2[pos++] = '-';
AzureIoTClient 0:1f9b2707ec7d 1401 year = -year;
AzureIoTClient 0:1f9b2707ec7d 1402 }
AzureIoTClient 0:1f9b2707ec7d 1403
AzureIoTClient 0:1f9b2707ec7d 1404 tempBuffer2[pos++] = '0' + (char)(year / 1000);
AzureIoTClient 0:1f9b2707ec7d 1405 tempBuffer2[pos++] = '0' + (char)((year % 1000) / 100);
AzureIoTClient 0:1f9b2707ec7d 1406 tempBuffer2[pos++] = '0' + (char)((year % 100) / 10);
AzureIoTClient 0:1f9b2707ec7d 1407 tempBuffer2[pos++] = '0' + (char)(year % 10);
AzureIoTClient 0:1f9b2707ec7d 1408 tempBuffer2[pos++] = '-';
AzureIoTClient 0:1f9b2707ec7d 1409 tempBuffer2[pos++] = '0' + value->value.edmDate.month / 10;
AzureIoTClient 0:1f9b2707ec7d 1410 tempBuffer2[pos++] = '0' + value->value.edmDate.month % 10;
AzureIoTClient 0:1f9b2707ec7d 1411 tempBuffer2[pos++] = '-';
AzureIoTClient 0:1f9b2707ec7d 1412 tempBuffer2[pos++] = '0' + value->value.edmDate.day / 10;
AzureIoTClient 0:1f9b2707ec7d 1413 tempBuffer2[pos++] = '0' + value->value.edmDate.day % 10;
AzureIoTClient 0:1f9b2707ec7d 1414 tempBuffer2[pos++] = '\"';
AzureIoTClient 0:1f9b2707ec7d 1415 tempBuffer2[pos++] = '\0';
AzureIoTClient 0:1f9b2707ec7d 1416
AzureIoTClient 0:1f9b2707ec7d 1417 if (STRING_concat(destination, tempBuffer2) != 0)
AzureIoTClient 0:1f9b2707ec7d 1418 {
AzureIoTClient 0:1f9b2707ec7d 1419 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1420 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1421 }
AzureIoTClient 0:1f9b2707ec7d 1422 else
AzureIoTClient 0:1f9b2707ec7d 1423 {
AzureIoTClient 0:1f9b2707ec7d 1424 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1425 }
AzureIoTClient 0:1f9b2707ec7d 1426 break;
AzureIoTClient 0:1f9b2707ec7d 1427 }
AzureIoTClient 0:1f9b2707ec7d 1428 case (EDM_DATE_TIME_OFFSET_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1429 {
AzureIoTClient 0:1f9b2707ec7d 1430 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_019:[ EDM_DATETIMEOFFSET: dateTimeOffsetValue = year "-" month "-" day "T" hour ":" minute [ ":" second [ "." fractionalSeconds ] ] ( "Z" / sign hour ":" minute )]*/
AzureIoTClient 0:1f9b2707ec7d 1431 /*from ABNF seems like these numbers HAVE to be padded with zeroes*/
AzureIoTClient 0:1f9b2707ec7d 1432 if (value->value.edmDateTimeOffset.hasTimeZone)
AzureIoTClient 0:1f9b2707ec7d 1433 {
AzureIoTClient 0:1f9b2707ec7d 1434 if (value->value.edmDateTimeOffset.hasFractionalSecond)
AzureIoTClient 0:1f9b2707ec7d 1435 {
Azure.IoT Build 8:380e6e830589 1436 size_t tempBufferSize = 1 + // \"
Azure.IoT Build 8:380e6e830589 1437 MAX_LONG_STRING_LENGTH + // %.4d
Azure.IoT Build 8:380e6e830589 1438 1 + // -
Azure.IoT Build 8:380e6e830589 1439 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1440 1 + // -
Azure.IoT Build 8:380e6e830589 1441 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1442 1 + // T
Azure.IoT Build 8:380e6e830589 1443 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1444 1 + // :
Azure.IoT Build 8:380e6e830589 1445 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1446 1 + // :
Azure.IoT Build 8:380e6e830589 1447 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1448 1 + // .
Azure.IoT Build 8:380e6e830589 1449 MAX_ULONG_LONG_STRING_LENGTH + // %.12llu
Azure.IoT Build 8:380e6e830589 1450 1 + MAX_LONG_STRING_LENGTH + // %+.2d
Azure.IoT Build 8:380e6e830589 1451 1 + // :
Azure.IoT Build 8:380e6e830589 1452 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1453 1 + //\"
Azure.IoT Build 8:380e6e830589 1454 1; // " (terminating NULL);
Azure.IoT Build 8:380e6e830589 1455
Azure.IoT Build 8:380e6e830589 1456 char* tempBuffer = (char*)malloc(tempBufferSize);
Azure.IoT Build 8:380e6e830589 1457 if (tempBuffer == NULL)
AzureIoTClient 0:1f9b2707ec7d 1458 {
AzureIoTClient 0:1f9b2707ec7d 1459 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1460 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1461 }
AzureIoTClient 0:1f9b2707ec7d 1462 else
AzureIoTClient 0:1f9b2707ec7d 1463 {
Azure.IoT Build 8:380e6e830589 1464 if (sprintf_s(tempBuffer, tempBufferSize, "\"%.4d-%.2d-%.2dT%.2d:%.2d:%.2d.%.12llu%+.2d:%.2d\"", /*+ in printf forces the sign to appear*/
Azure.IoT Build 8:380e6e830589 1465 value->value.edmDateTimeOffset.dateTime.tm_year+1900,
Azure.IoT Build 8:380e6e830589 1466 value->value.edmDateTimeOffset.dateTime.tm_mon+1,
Azure.IoT Build 8:380e6e830589 1467 value->value.edmDateTimeOffset.dateTime.tm_mday,
Azure.IoT Build 8:380e6e830589 1468 value->value.edmDateTimeOffset.dateTime.tm_hour,
Azure.IoT Build 8:380e6e830589 1469 value->value.edmDateTimeOffset.dateTime.tm_min,
Azure.IoT Build 8:380e6e830589 1470 value->value.edmDateTimeOffset.dateTime.tm_sec,
Azure.IoT Build 8:380e6e830589 1471 value->value.edmDateTimeOffset.fractionalSecond,
Azure.IoT Build 8:380e6e830589 1472 value->value.edmDateTimeOffset.timeZoneHour,
Azure.IoT Build 8:380e6e830589 1473 value->value.edmDateTimeOffset.timeZoneMinute) < 0)
Azure.IoT Build 8:380e6e830589 1474 {
Azure.IoT Build 8:380e6e830589 1475 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1476 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 1477 }
Azure.IoT Build 8:380e6e830589 1478 else if (STRING_concat(destination, tempBuffer) != 0)
Azure.IoT Build 8:380e6e830589 1479 {
Azure.IoT Build 8:380e6e830589 1480 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1481 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 1482 }
Azure.IoT Build 8:380e6e830589 1483 else
Azure.IoT Build 8:380e6e830589 1484 {
Azure.IoT Build 8:380e6e830589 1485 result = AGENT_DATA_TYPES_OK;
Azure.IoT Build 8:380e6e830589 1486 }
Azure.IoT Build 8:380e6e830589 1487
Azure.IoT Build 8:380e6e830589 1488 // Clean up temp buffer if allocated
Azure.IoT Build 8:380e6e830589 1489 free(tempBuffer);
AzureIoTClient 0:1f9b2707ec7d 1490 }
AzureIoTClient 0:1f9b2707ec7d 1491 }
AzureIoTClient 0:1f9b2707ec7d 1492 else
AzureIoTClient 0:1f9b2707ec7d 1493 {
Azure.IoT Build 8:380e6e830589 1494 size_t tempBufferSize = 1 + // \"
Azure.IoT Build 8:380e6e830589 1495 MAX_LONG_STRING_LENGTH + // %.4d
Azure.IoT Build 8:380e6e830589 1496 1 + // -
Azure.IoT Build 8:380e6e830589 1497 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1498 1 + // -
Azure.IoT Build 8:380e6e830589 1499 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1500 1 + // T
Azure.IoT Build 8:380e6e830589 1501 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1502 1 + // :
Azure.IoT Build 8:380e6e830589 1503 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1504 1 + // :
Azure.IoT Build 8:380e6e830589 1505 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1506 1 + MAX_LONG_STRING_LENGTH + // %+.2d
Azure.IoT Build 8:380e6e830589 1507 1 + // :
Azure.IoT Build 8:380e6e830589 1508 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1509 1 + // \"
Azure.IoT Build 8:380e6e830589 1510 1; // " terminating NULL
Azure.IoT Build 8:380e6e830589 1511 char* tempBuffer = (char*)malloc(tempBufferSize);
Azure.IoT Build 8:380e6e830589 1512
Azure.IoT Build 8:380e6e830589 1513 if (tempBuffer == NULL)
AzureIoTClient 0:1f9b2707ec7d 1514 {
AzureIoTClient 0:1f9b2707ec7d 1515 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1516 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1517 }
AzureIoTClient 0:1f9b2707ec7d 1518 else
AzureIoTClient 0:1f9b2707ec7d 1519 {
Azure.IoT Build 8:380e6e830589 1520 if (sprintf_s(tempBuffer, tempBufferSize, "\"%.4d-%.2d-%.2dT%.2d:%.2d:%.2d%+.2d:%.2d\"", /*+ in printf forces the sign to appear*/
Azure.IoT Build 8:380e6e830589 1521 value->value.edmDateTimeOffset.dateTime.tm_year + 1900,
Azure.IoT Build 8:380e6e830589 1522 value->value.edmDateTimeOffset.dateTime.tm_mon+1,
Azure.IoT Build 8:380e6e830589 1523 value->value.edmDateTimeOffset.dateTime.tm_mday,
Azure.IoT Build 8:380e6e830589 1524 value->value.edmDateTimeOffset.dateTime.tm_hour,
Azure.IoT Build 8:380e6e830589 1525 value->value.edmDateTimeOffset.dateTime.tm_min,
Azure.IoT Build 8:380e6e830589 1526 value->value.edmDateTimeOffset.dateTime.tm_sec,
Azure.IoT Build 8:380e6e830589 1527 value->value.edmDateTimeOffset.timeZoneHour,
Azure.IoT Build 8:380e6e830589 1528 value->value.edmDateTimeOffset.timeZoneMinute) < 0)
Azure.IoT Build 8:380e6e830589 1529 {
Azure.IoT Build 8:380e6e830589 1530 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1531 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 1532 }
Azure.IoT Build 8:380e6e830589 1533 else if (STRING_concat(destination, tempBuffer) != 0)
Azure.IoT Build 8:380e6e830589 1534 {
Azure.IoT Build 8:380e6e830589 1535 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1536 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 1537 }
Azure.IoT Build 8:380e6e830589 1538 else
Azure.IoT Build 8:380e6e830589 1539 {
Azure.IoT Build 8:380e6e830589 1540 result = AGENT_DATA_TYPES_OK;
Azure.IoT Build 8:380e6e830589 1541 }
Azure.IoT Build 8:380e6e830589 1542
Azure.IoT Build 8:380e6e830589 1543 // Clean up temp buffer if allocated
Azure.IoT Build 8:380e6e830589 1544 free(tempBuffer);
AzureIoTClient 0:1f9b2707ec7d 1545 }
AzureIoTClient 0:1f9b2707ec7d 1546 }
AzureIoTClient 0:1f9b2707ec7d 1547 }
AzureIoTClient 0:1f9b2707ec7d 1548 else
AzureIoTClient 0:1f9b2707ec7d 1549 {
AzureIoTClient 0:1f9b2707ec7d 1550 if (value->value.edmDateTimeOffset.hasFractionalSecond)
AzureIoTClient 0:1f9b2707ec7d 1551 {
Azure.IoT Build 8:380e6e830589 1552 size_t tempBufferSize = 1 + //\"
Azure.IoT Build 8:380e6e830589 1553 MAX_LONG_STRING_LENGTH + // %.4d
Azure.IoT Build 8:380e6e830589 1554 1 + // -
Azure.IoT Build 8:380e6e830589 1555 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1556 1 + // -
Azure.IoT Build 8:380e6e830589 1557 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1558 1 + // T
Azure.IoT Build 8:380e6e830589 1559 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1560 1 + // :
Azure.IoT Build 8:380e6e830589 1561 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1562 1 + // :
Azure.IoT Build 8:380e6e830589 1563 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1564 1 + // .
Azure.IoT Build 8:380e6e830589 1565 MAX_ULONG_LONG_STRING_LENGTH + // %.12llu
Azure.IoT Build 8:380e6e830589 1566 1 + // Z
Azure.IoT Build 8:380e6e830589 1567 1 + // \"
Azure.IoT Build 8:380e6e830589 1568 1; // " (terminating NULL)
Azure.IoT Build 8:380e6e830589 1569 char* tempBuffer = (char*)malloc(tempBufferSize);
Azure.IoT Build 8:380e6e830589 1570
Azure.IoT Build 8:380e6e830589 1571 if (tempBuffer == NULL)
AzureIoTClient 0:1f9b2707ec7d 1572 {
AzureIoTClient 0:1f9b2707ec7d 1573 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1574 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1575 }
AzureIoTClient 0:1f9b2707ec7d 1576 else
AzureIoTClient 0:1f9b2707ec7d 1577 {
Azure.IoT Build 8:380e6e830589 1578 if (sprintf_s(tempBuffer, tempBufferSize, "\"%.4d-%.2d-%.2dT%.2d:%.2d:%.2d.%.12lluZ\"", /*+ in printf forces the sign to appear*/
Azure.IoT Build 8:380e6e830589 1579 value->value.edmDateTimeOffset.dateTime.tm_year + 1900,
Azure.IoT Build 8:380e6e830589 1580 value->value.edmDateTimeOffset.dateTime.tm_mon+1,
Azure.IoT Build 8:380e6e830589 1581 value->value.edmDateTimeOffset.dateTime.tm_mday,
Azure.IoT Build 8:380e6e830589 1582 value->value.edmDateTimeOffset.dateTime.tm_hour,
Azure.IoT Build 8:380e6e830589 1583 value->value.edmDateTimeOffset.dateTime.tm_min,
Azure.IoT Build 8:380e6e830589 1584 value->value.edmDateTimeOffset.dateTime.tm_sec,
Azure.IoT Build 8:380e6e830589 1585 value->value.edmDateTimeOffset.fractionalSecond) < 0)
Azure.IoT Build 8:380e6e830589 1586 {
Azure.IoT Build 8:380e6e830589 1587 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1588 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 1589 }
Azure.IoT Build 8:380e6e830589 1590 else if (STRING_concat(destination, tempBuffer) != 0)
Azure.IoT Build 8:380e6e830589 1591 {
Azure.IoT Build 8:380e6e830589 1592 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1593 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 1594 }
Azure.IoT Build 8:380e6e830589 1595 else
Azure.IoT Build 8:380e6e830589 1596 {
Azure.IoT Build 8:380e6e830589 1597 result = AGENT_DATA_TYPES_OK;
Azure.IoT Build 8:380e6e830589 1598 }
Azure.IoT Build 8:380e6e830589 1599
Azure.IoT Build 8:380e6e830589 1600 free(tempBuffer);
AzureIoTClient 0:1f9b2707ec7d 1601 }
AzureIoTClient 0:1f9b2707ec7d 1602 }
AzureIoTClient 0:1f9b2707ec7d 1603 else
AzureIoTClient 0:1f9b2707ec7d 1604 {
Azure.IoT Build 8:380e6e830589 1605 size_t tempBufferSize = 1 + // \"
Azure.IoT Build 8:380e6e830589 1606 MAX_LONG_STRING_LENGTH + // %.4d
Azure.IoT Build 8:380e6e830589 1607 1 + // -
Azure.IoT Build 8:380e6e830589 1608 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1609 1 + // -
Azure.IoT Build 8:380e6e830589 1610 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1611 1 + // T
Azure.IoT Build 8:380e6e830589 1612 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1613 1 + // :
Azure.IoT Build 8:380e6e830589 1614 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1615 1 + // :
Azure.IoT Build 8:380e6e830589 1616 MAX_LONG_STRING_LENGTH + // %.2d
Azure.IoT Build 8:380e6e830589 1617 1 + // Z
Azure.IoT Build 8:380e6e830589 1618 1 + // \"
Azure.IoT Build 8:380e6e830589 1619 1; // " (terminating null);
Azure.IoT Build 8:380e6e830589 1620
Azure.IoT Build 8:380e6e830589 1621 char* tempBuffer = (char*)malloc(tempBufferSize);
Azure.IoT Build 8:380e6e830589 1622
Azure.IoT Build 8:380e6e830589 1623 if (tempBuffer == NULL)
AzureIoTClient 0:1f9b2707ec7d 1624 {
AzureIoTClient 0:1f9b2707ec7d 1625 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1626 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1627 }
AzureIoTClient 0:1f9b2707ec7d 1628 else
AzureIoTClient 0:1f9b2707ec7d 1629 {
Azure.IoT Build 8:380e6e830589 1630 if (sprintf_s(tempBuffer, tempBufferSize, "\"%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ\"",
Azure.IoT Build 8:380e6e830589 1631 value->value.edmDateTimeOffset.dateTime.tm_year + 1900,
Azure.IoT Build 8:380e6e830589 1632 value->value.edmDateTimeOffset.dateTime.tm_mon+1,
Azure.IoT Build 8:380e6e830589 1633 value->value.edmDateTimeOffset.dateTime.tm_mday,
Azure.IoT Build 8:380e6e830589 1634 value->value.edmDateTimeOffset.dateTime.tm_hour,
Azure.IoT Build 8:380e6e830589 1635 value->value.edmDateTimeOffset.dateTime.tm_min,
Azure.IoT Build 8:380e6e830589 1636 value->value.edmDateTimeOffset.dateTime.tm_sec) < 0)
Azure.IoT Build 8:380e6e830589 1637 {
Azure.IoT Build 8:380e6e830589 1638 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1639 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 1640 }
Azure.IoT Build 8:380e6e830589 1641 else if (STRING_concat(destination, tempBuffer) != 0)
Azure.IoT Build 8:380e6e830589 1642 {
Azure.IoT Build 8:380e6e830589 1643 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1644 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 1645 }
Azure.IoT Build 8:380e6e830589 1646 else
Azure.IoT Build 8:380e6e830589 1647 {
Azure.IoT Build 8:380e6e830589 1648 result = AGENT_DATA_TYPES_OK;
Azure.IoT Build 8:380e6e830589 1649 }
Azure.IoT Build 8:380e6e830589 1650
Azure.IoT Build 8:380e6e830589 1651 free(tempBuffer);
AzureIoTClient 0:1f9b2707ec7d 1652 }
AzureIoTClient 0:1f9b2707ec7d 1653 }
AzureIoTClient 0:1f9b2707ec7d 1654 }
AzureIoTClient 0:1f9b2707ec7d 1655 break;
AzureIoTClient 0:1f9b2707ec7d 1656 }
AzureIoTClient 0:1f9b2707ec7d 1657 case(EDM_DECIMAL_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1658 {
AzureIoTClient 0:1f9b2707ec7d 1659 if (STRING_concat_with_STRING(destination, value->value.edmDecimal.value) != 0)
AzureIoTClient 0:1f9b2707ec7d 1660 {
AzureIoTClient 0:1f9b2707ec7d 1661 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1662 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1663 }
AzureIoTClient 0:1f9b2707ec7d 1664 else
AzureIoTClient 0:1f9b2707ec7d 1665 {
AzureIoTClient 0:1f9b2707ec7d 1666 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1667 }
AzureIoTClient 0:1f9b2707ec7d 1668 break;
AzureIoTClient 0:1f9b2707ec7d 1669 }
AzureIoTClient 0:1f9b2707ec7d 1670 case (EDM_INT16_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1671 {
AzureIoTClient 0:1f9b2707ec7d 1672 /*-32768 to +32767*/
AzureIoTClient 0:1f9b2707ec7d 1673 char buffertemp2[7]; /*because 5 digits and sign and '\0'*/
AzureIoTClient 0:1f9b2707ec7d 1674 uint16_t positiveValue;
AzureIoTClient 0:1f9b2707ec7d 1675 size_t pos = 0;
AzureIoTClient 0:1f9b2707ec7d 1676 uint16_t rank = (uint16_t)10000;
AzureIoTClient 0:1f9b2707ec7d 1677 bool foundFirstDigit = false;
AzureIoTClient 0:1f9b2707ec7d 1678
AzureIoTClient 0:1f9b2707ec7d 1679 if (value->value.edmInt16.value < 0)
AzureIoTClient 0:1f9b2707ec7d 1680 {
AzureIoTClient 0:1f9b2707ec7d 1681 buffertemp2[pos++] = '-';
AzureIoTClient 0:1f9b2707ec7d 1682 positiveValue = -value->value.edmInt16.value;
AzureIoTClient 0:1f9b2707ec7d 1683 }
AzureIoTClient 0:1f9b2707ec7d 1684 else
AzureIoTClient 0:1f9b2707ec7d 1685 {
AzureIoTClient 0:1f9b2707ec7d 1686 positiveValue = value->value.edmInt16.value;
AzureIoTClient 0:1f9b2707ec7d 1687 }
AzureIoTClient 0:1f9b2707ec7d 1688
AzureIoTClient 0:1f9b2707ec7d 1689 while (rank >= 10)
AzureIoTClient 0:1f9b2707ec7d 1690 {
AzureIoTClient 0:1f9b2707ec7d 1691 if ((foundFirstDigit == true) || (positiveValue / rank) > 0)
AzureIoTClient 0:1f9b2707ec7d 1692 {
AzureIoTClient 0:1f9b2707ec7d 1693 buffertemp2[pos++] = '0' + (char)(positiveValue / rank);
AzureIoTClient 0:1f9b2707ec7d 1694 foundFirstDigit = true;
AzureIoTClient 0:1f9b2707ec7d 1695 }
AzureIoTClient 0:1f9b2707ec7d 1696 positiveValue %= rank;
AzureIoTClient 0:1f9b2707ec7d 1697 rank /= 10;
AzureIoTClient 0:1f9b2707ec7d 1698 }
AzureIoTClient 0:1f9b2707ec7d 1699 buffertemp2[pos++] = '0' + (char)(positiveValue);
AzureIoTClient 0:1f9b2707ec7d 1700 buffertemp2[pos++] = '\0';
AzureIoTClient 0:1f9b2707ec7d 1701
AzureIoTClient 0:1f9b2707ec7d 1702 if (STRING_concat(destination, buffertemp2) != 0)
AzureIoTClient 0:1f9b2707ec7d 1703 {
AzureIoTClient 0:1f9b2707ec7d 1704 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1705 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1706 }
AzureIoTClient 0:1f9b2707ec7d 1707 else
AzureIoTClient 0:1f9b2707ec7d 1708 {
AzureIoTClient 0:1f9b2707ec7d 1709 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1710 }
AzureIoTClient 0:1f9b2707ec7d 1711 break;
AzureIoTClient 0:1f9b2707ec7d 1712 }
AzureIoTClient 0:1f9b2707ec7d 1713 case (EDM_INT32_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1714 {
AzureIoTClient 0:1f9b2707ec7d 1715 /*-2147483648 to +2147483647*/
AzureIoTClient 0:1f9b2707ec7d 1716 char buffertemp2[12]; /*because 10 digits and sign and '\0'*/
AzureIoTClient 0:1f9b2707ec7d 1717 uint32_t positiveValue;
AzureIoTClient 0:1f9b2707ec7d 1718 size_t pos = 0;
AzureIoTClient 0:1f9b2707ec7d 1719 uint32_t rank = 1000000000UL;
AzureIoTClient 0:1f9b2707ec7d 1720 bool foundFirstDigit = false;
AzureIoTClient 0:1f9b2707ec7d 1721
AzureIoTClient 0:1f9b2707ec7d 1722 if (value->value.edmInt32.value < 0)
AzureIoTClient 0:1f9b2707ec7d 1723 {
AzureIoTClient 0:1f9b2707ec7d 1724 buffertemp2[pos++] = '-';
AzureIoTClient 0:1f9b2707ec7d 1725 positiveValue = - value->value.edmInt32.value;
AzureIoTClient 0:1f9b2707ec7d 1726 }
AzureIoTClient 0:1f9b2707ec7d 1727 else
AzureIoTClient 0:1f9b2707ec7d 1728 {
AzureIoTClient 0:1f9b2707ec7d 1729 positiveValue = value->value.edmInt32.value;
AzureIoTClient 0:1f9b2707ec7d 1730 }
AzureIoTClient 0:1f9b2707ec7d 1731
AzureIoTClient 0:1f9b2707ec7d 1732 while (rank >= 10)
AzureIoTClient 0:1f9b2707ec7d 1733 {
AzureIoTClient 0:1f9b2707ec7d 1734 if ((foundFirstDigit == true) || (positiveValue / rank) > 0)
AzureIoTClient 0:1f9b2707ec7d 1735 {
AzureIoTClient 0:1f9b2707ec7d 1736 buffertemp2[pos++] = '0' + (char)(positiveValue / rank);
AzureIoTClient 0:1f9b2707ec7d 1737 foundFirstDigit = true;
AzureIoTClient 0:1f9b2707ec7d 1738 }
AzureIoTClient 0:1f9b2707ec7d 1739 positiveValue %= rank;
AzureIoTClient 0:1f9b2707ec7d 1740 rank /= 10;
AzureIoTClient 0:1f9b2707ec7d 1741 }
AzureIoTClient 0:1f9b2707ec7d 1742 buffertemp2[pos++] = '0' + (char)(positiveValue);
AzureIoTClient 0:1f9b2707ec7d 1743 buffertemp2[pos++] = '\0';
AzureIoTClient 0:1f9b2707ec7d 1744
AzureIoTClient 0:1f9b2707ec7d 1745 if (STRING_concat(destination, buffertemp2) != 0)
AzureIoTClient 0:1f9b2707ec7d 1746 {
AzureIoTClient 0:1f9b2707ec7d 1747 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1748 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1749 }
AzureIoTClient 0:1f9b2707ec7d 1750 else
AzureIoTClient 0:1f9b2707ec7d 1751 {
AzureIoTClient 0:1f9b2707ec7d 1752 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1753 }
AzureIoTClient 0:1f9b2707ec7d 1754 break;
AzureIoTClient 0:1f9b2707ec7d 1755 }
AzureIoTClient 0:1f9b2707ec7d 1756 case (EDM_INT64_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1757 {
AzureIoTClient 0:1f9b2707ec7d 1758 char buffertemp2[21]; /*because 19 digits and sign and '\0'*/
AzureIoTClient 0:1f9b2707ec7d 1759 uint64_t positiveValue;
AzureIoTClient 0:1f9b2707ec7d 1760 size_t pos = 0;
AzureIoTClient 0:1f9b2707ec7d 1761 uint64_t rank = 10000000000000000000ULL;
AzureIoTClient 0:1f9b2707ec7d 1762 bool foundFirstDigit = false;
AzureIoTClient 0:1f9b2707ec7d 1763
AzureIoTClient 0:1f9b2707ec7d 1764 if (value->value.edmInt64.value < 0)
AzureIoTClient 0:1f9b2707ec7d 1765 {
AzureIoTClient 0:1f9b2707ec7d 1766 buffertemp2[pos++] = '-';
AzureIoTClient 0:1f9b2707ec7d 1767 positiveValue = -value->value.edmInt64.value;
AzureIoTClient 0:1f9b2707ec7d 1768 }
AzureIoTClient 0:1f9b2707ec7d 1769 else
AzureIoTClient 0:1f9b2707ec7d 1770 {
AzureIoTClient 0:1f9b2707ec7d 1771 positiveValue = value->value.edmInt64.value;
AzureIoTClient 0:1f9b2707ec7d 1772 }
AzureIoTClient 0:1f9b2707ec7d 1773
AzureIoTClient 0:1f9b2707ec7d 1774 while (rank >= 10)
AzureIoTClient 0:1f9b2707ec7d 1775 {
AzureIoTClient 0:1f9b2707ec7d 1776 if ((foundFirstDigit == true) || (positiveValue / rank) > 0)
AzureIoTClient 0:1f9b2707ec7d 1777 {
AzureIoTClient 0:1f9b2707ec7d 1778 buffertemp2[pos++] = '0' + (char)(positiveValue / rank);
AzureIoTClient 0:1f9b2707ec7d 1779 foundFirstDigit = true;
AzureIoTClient 0:1f9b2707ec7d 1780 }
AzureIoTClient 0:1f9b2707ec7d 1781 positiveValue %= rank;
AzureIoTClient 0:1f9b2707ec7d 1782 rank /= 10;
AzureIoTClient 0:1f9b2707ec7d 1783 }
AzureIoTClient 0:1f9b2707ec7d 1784 buffertemp2[pos++] = '0' + (char)(positiveValue);
AzureIoTClient 0:1f9b2707ec7d 1785 buffertemp2[pos++] = '\0';
AzureIoTClient 0:1f9b2707ec7d 1786
AzureIoTClient 0:1f9b2707ec7d 1787 if (STRING_concat(destination, buffertemp2) != 0)
AzureIoTClient 0:1f9b2707ec7d 1788 {
AzureIoTClient 0:1f9b2707ec7d 1789 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1790 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1791 }
AzureIoTClient 0:1f9b2707ec7d 1792 else
AzureIoTClient 0:1f9b2707ec7d 1793 {
AzureIoTClient 0:1f9b2707ec7d 1794 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1795 }
AzureIoTClient 0:1f9b2707ec7d 1796 break;
AzureIoTClient 0:1f9b2707ec7d 1797 }
AzureIoTClient 0:1f9b2707ec7d 1798 case (EDM_SBYTE_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1799 {
AzureIoTClient 0:1f9b2707ec7d 1800 char tempbuffer2[5]; /* because '-' and 3 characters for 127 let's say and '\0'*/
AzureIoTClient 0:1f9b2707ec7d 1801 int absValue = value->value.edmSbyte.value;
AzureIoTClient 0:1f9b2707ec7d 1802 size_t pos=0;
AzureIoTClient 0:1f9b2707ec7d 1803 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_026:[ EDM_SBYTE: sbyteValue = [ sign ] 1*3DIGIT ; numbers in the range from -128 to 127]*/
AzureIoTClient 0:1f9b2707ec7d 1804
AzureIoTClient 0:1f9b2707ec7d 1805 if (value->value.edmSbyte.value < 0)
AzureIoTClient 0:1f9b2707ec7d 1806 {
AzureIoTClient 0:1f9b2707ec7d 1807 tempbuffer2[pos++] = '-';
AzureIoTClient 0:1f9b2707ec7d 1808 absValue = -absValue;
AzureIoTClient 0:1f9b2707ec7d 1809 }
AzureIoTClient 0:1f9b2707ec7d 1810
AzureIoTClient 0:1f9b2707ec7d 1811 if (absValue >= 100 ) tempbuffer2[pos++] = '0' + (char)(absValue / 100);
AzureIoTClient 0:1f9b2707ec7d 1812 if (absValue >=10) tempbuffer2[pos++] = '0' + (absValue % 100) / 10;
AzureIoTClient 0:1f9b2707ec7d 1813 tempbuffer2[pos++] = '0' + (absValue % 10);
AzureIoTClient 0:1f9b2707ec7d 1814 tempbuffer2[pos++] = '\0';
AzureIoTClient 0:1f9b2707ec7d 1815
AzureIoTClient 0:1f9b2707ec7d 1816
AzureIoTClient 0:1f9b2707ec7d 1817 if (STRING_concat(destination, tempbuffer2) != 0)
AzureIoTClient 0:1f9b2707ec7d 1818 {
AzureIoTClient 0:1f9b2707ec7d 1819 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1820 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1821 }
AzureIoTClient 0:1f9b2707ec7d 1822 else
AzureIoTClient 0:1f9b2707ec7d 1823 {
AzureIoTClient 0:1f9b2707ec7d 1824 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1825 }
AzureIoTClient 0:1f9b2707ec7d 1826 break;
AzureIoTClient 0:1f9b2707ec7d 1827 }
AzureIoTClient 0:1f9b2707ec7d 1828 case (EDM_STRING_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1829 {
AzureIoTClient 0:1f9b2707ec7d 1830 size_t i;
AzureIoTClient 0:1f9b2707ec7d 1831 size_t nControlCharacters = 0; /*counts how many characters are to be expanded from 1 character to \uxxxx (6 characters)*/
AzureIoTClient 0:1f9b2707ec7d 1832 size_t nEscapeCharacters = 0;
AzureIoTClient 0:1f9b2707ec7d 1833 size_t vlen = value->value.edmString.length;
AzureIoTClient 0:1f9b2707ec7d 1834 char* v = value->value.edmString.chars;
AzureIoTClient 0:1f9b2707ec7d 1835
AzureIoTClient 0:1f9b2707ec7d 1836 for (i = 0; i < vlen; i++)
AzureIoTClient 0:1f9b2707ec7d 1837 {
AzureIoTClient 0:1f9b2707ec7d 1838 if ((unsigned char)v[i] >= 128) /*this be a UNICODE character begin*/
AzureIoTClient 0:1f9b2707ec7d 1839 {
AzureIoTClient 0:1f9b2707ec7d 1840 break;
AzureIoTClient 0:1f9b2707ec7d 1841 }
AzureIoTClient 0:1f9b2707ec7d 1842 else
AzureIoTClient 0:1f9b2707ec7d 1843 {
AzureIoTClient 0:1f9b2707ec7d 1844 if (v[i] <= 0x1F)
AzureIoTClient 0:1f9b2707ec7d 1845 {
AzureIoTClient 0:1f9b2707ec7d 1846 nControlCharacters++;
AzureIoTClient 0:1f9b2707ec7d 1847 }
AzureIoTClient 0:1f9b2707ec7d 1848 else if (
AzureIoTClient 0:1f9b2707ec7d 1849 (v[i] == '"') ||
AzureIoTClient 0:1f9b2707ec7d 1850 (v[i] == '\\') ||
AzureIoTClient 0:1f9b2707ec7d 1851 (v[i] == '/')
AzureIoTClient 0:1f9b2707ec7d 1852 )
AzureIoTClient 0:1f9b2707ec7d 1853 {
AzureIoTClient 0:1f9b2707ec7d 1854 nEscapeCharacters++;
AzureIoTClient 0:1f9b2707ec7d 1855 }
AzureIoTClient 0:1f9b2707ec7d 1856 }
AzureIoTClient 0:1f9b2707ec7d 1857 }
AzureIoTClient 0:1f9b2707ec7d 1858
AzureIoTClient 0:1f9b2707ec7d 1859 if (i < vlen)
AzureIoTClient 0:1f9b2707ec7d 1860 {
AzureIoTClient 0:1f9b2707ec7d 1861 result = AGENT_DATA_TYPES_INVALID_ARG; /*don't handle those who do not copy bit by bit to UTF8*/
AzureIoTClient 11:b1327861f5e0 1862 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1863 }
AzureIoTClient 0:1f9b2707ec7d 1864 else
AzureIoTClient 0:1f9b2707ec7d 1865 {
AzureIoTClient 0:1f9b2707ec7d 1866 /*forward parse the string to scan for " and for \ that in JSON are \" respectively \\*/
Azure.IoT Build 8:380e6e830589 1867 size_t tempBufferSize = vlen + 5 * nControlCharacters + nEscapeCharacters + 3 + 1;
Azure.IoT Build 8:380e6e830589 1868 char* tempBuffer = (char*)malloc(tempBufferSize);
Azure.IoT Build 8:380e6e830589 1869 if (tempBuffer == NULL)
AzureIoTClient 0:1f9b2707ec7d 1870 {
AzureIoTClient 0:1f9b2707ec7d 1871 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1872 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1873 }
AzureIoTClient 0:1f9b2707ec7d 1874 else
AzureIoTClient 0:1f9b2707ec7d 1875 {
AzureIoTClient 0:1f9b2707ec7d 1876 size_t w = 0;
AzureIoTClient 0:1f9b2707ec7d 1877 tempBuffer[w++] = '"';
AzureIoTClient 0:1f9b2707ec7d 1878 for (i = 0; i < vlen; i++)
AzureIoTClient 0:1f9b2707ec7d 1879 {
AzureIoTClient 0:1f9b2707ec7d 1880 if (v[i] <= 0x1F)
AzureIoTClient 0:1f9b2707ec7d 1881 {
AzureIoTClient 0:1f9b2707ec7d 1882 tempBuffer[w++] = '\\';
AzureIoTClient 0:1f9b2707ec7d 1883 tempBuffer[w++] = 'u';
AzureIoTClient 0:1f9b2707ec7d 1884 tempBuffer[w++] = '0';
AzureIoTClient 0:1f9b2707ec7d 1885 tempBuffer[w++] = '0';
AzureIoTClient 0:1f9b2707ec7d 1886 tempBuffer[w++] = hexToASCII[(v[i] & 0xF0) >> 4]; /*high nibble*/
AzureIoTClient 0:1f9b2707ec7d 1887 tempBuffer[w++] = hexToASCII[v[i] & 0x0F]; /*lowNibble nibble*/
AzureIoTClient 0:1f9b2707ec7d 1888 }
AzureIoTClient 0:1f9b2707ec7d 1889 else if (v[i] == '"')
AzureIoTClient 0:1f9b2707ec7d 1890 {
AzureIoTClient 0:1f9b2707ec7d 1891 tempBuffer[w++] = '\\';
AzureIoTClient 0:1f9b2707ec7d 1892 tempBuffer[w++] = '"';
AzureIoTClient 0:1f9b2707ec7d 1893 }
AzureIoTClient 0:1f9b2707ec7d 1894 else if (v[i] == '\\')
AzureIoTClient 0:1f9b2707ec7d 1895 {
AzureIoTClient 0:1f9b2707ec7d 1896 tempBuffer[w++] = '\\';
AzureIoTClient 0:1f9b2707ec7d 1897 tempBuffer[w++] = '\\';
AzureIoTClient 0:1f9b2707ec7d 1898 }
AzureIoTClient 0:1f9b2707ec7d 1899 else if (v[i] == '/')
AzureIoTClient 0:1f9b2707ec7d 1900 {
AzureIoTClient 0:1f9b2707ec7d 1901 tempBuffer[w++] = '\\';
AzureIoTClient 0:1f9b2707ec7d 1902 tempBuffer[w++] = '/';
AzureIoTClient 0:1f9b2707ec7d 1903 }
AzureIoTClient 0:1f9b2707ec7d 1904 else
AzureIoTClient 0:1f9b2707ec7d 1905 {
AzureIoTClient 0:1f9b2707ec7d 1906 tempBuffer[w++] = v[i];
AzureIoTClient 0:1f9b2707ec7d 1907 }
AzureIoTClient 0:1f9b2707ec7d 1908 }
AzureIoTClient 0:1f9b2707ec7d 1909
AzureIoTClient 0:1f9b2707ec7d 1910 #ifdef _MSC_VER
AzureIoTClient 0:1f9b2707ec7d 1911 #pragma warning(suppress: 6386) /* The test Create_AGENT_DATA_TYPE_from_charz_With_2_Slashes_Succeeds verifies that Code Analysis is wrong here */
AzureIoTClient 0:1f9b2707ec7d 1912 #endif
AzureIoTClient 0:1f9b2707ec7d 1913 tempBuffer[w] = '"';
AzureIoTClient 0:1f9b2707ec7d 1914 /*zero terminating it*/
AzureIoTClient 0:1f9b2707ec7d 1915 tempBuffer[vlen + 5 * nControlCharacters + nEscapeCharacters + 3 - 1] = '\0';
AzureIoTClient 0:1f9b2707ec7d 1916
AzureIoTClient 0:1f9b2707ec7d 1917 if (STRING_concat(destination, tempBuffer) != 0)
AzureIoTClient 0:1f9b2707ec7d 1918 {
AzureIoTClient 0:1f9b2707ec7d 1919 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1920 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1921 }
AzureIoTClient 0:1f9b2707ec7d 1922 else
AzureIoTClient 0:1f9b2707ec7d 1923 {
AzureIoTClient 0:1f9b2707ec7d 1924 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1925 }
Azure.IoT Build 8:380e6e830589 1926
Azure.IoT Build 8:380e6e830589 1927 free(tempBuffer);
AzureIoTClient 0:1f9b2707ec7d 1928 }
AzureIoTClient 0:1f9b2707ec7d 1929 }
AzureIoTClient 0:1f9b2707ec7d 1930
AzureIoTClient 0:1f9b2707ec7d 1931 break;
AzureIoTClient 0:1f9b2707ec7d 1932 }
AzureIoTClient 0:1f9b2707ec7d 1933
AzureIoTClient 0:1f9b2707ec7d 1934 /* Codes_SRS_AGENT_TYPE_SYSTEM_01_003: [EDM_STRING_no_quotes: the string is copied as given when the AGENT_DATA_TYPE was created.] */
AzureIoTClient 0:1f9b2707ec7d 1935 case (EDM_STRING_NO_QUOTES_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 1936 {
AzureIoTClient 0:1f9b2707ec7d 1937 /* this is a special case where we just want to copy/paste the contents, no encoding, no quotes */
AzureIoTClient 0:1f9b2707ec7d 1938 /* Codes_SRS_AGENT_TYPE_SYSTEM_01_002: [When serialized, this type is not enclosed with quotes.] */
AzureIoTClient 0:1f9b2707ec7d 1939 if (STRING_concat(destination, value->value.edmStringNoQuotes.chars) != 0)
AzureIoTClient 0:1f9b2707ec7d 1940 {
AzureIoTClient 0:1f9b2707ec7d 1941 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1942 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1943 }
AzureIoTClient 0:1f9b2707ec7d 1944 else
AzureIoTClient 0:1f9b2707ec7d 1945 {
AzureIoTClient 0:1f9b2707ec7d 1946 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1947 }
AzureIoTClient 0:1f9b2707ec7d 1948
AzureIoTClient 0:1f9b2707ec7d 1949 break;
AzureIoTClient 0:1f9b2707ec7d 1950 }
AzureIoTClient 0:1f9b2707ec7d 1951
Azure.IoT Build 7:5176a13270bb 1952 #ifndef NO_FLOATS
AzureIoTClient 0:1f9b2707ec7d 1953 case(EDM_SINGLE_TYPE):
AzureIoTClient 0:1f9b2707ec7d 1954 {
AzureIoTClient 0:1f9b2707ec7d 1955 /*C89 standard says: When a float is promoted to double or long double, or a double is promoted to long double, its value is unchanged*/
AzureIoTClient 0:1f9b2707ec7d 1956 /*I read that as : when a float is NaN or Inf, it will stay NaN or INF in double representation*/
AzureIoTClient 0:1f9b2707ec7d 1957
AzureIoTClient 0:1f9b2707ec7d 1958 /*The sprintf function returns the number of characters written in the array, not counting the terminating null character.*/
AzureIoTClient 0:1f9b2707ec7d 1959
AzureIoTClient 0:1f9b2707ec7d 1960 if(ISNAN(value->value.edmSingle.value))
AzureIoTClient 0:1f9b2707ec7d 1961 {
AzureIoTClient 0:1f9b2707ec7d 1962 if (STRING_concat(destination, NaN_STRING) != 0)
AzureIoTClient 0:1f9b2707ec7d 1963 {
AzureIoTClient 0:1f9b2707ec7d 1964 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1965 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1966 }
AzureIoTClient 0:1f9b2707ec7d 1967 else
AzureIoTClient 0:1f9b2707ec7d 1968 {
AzureIoTClient 0:1f9b2707ec7d 1969 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1970 }
AzureIoTClient 0:1f9b2707ec7d 1971 }
AzureIoTClient 0:1f9b2707ec7d 1972 else if (ISNEGATIVEINFINITY(value->value.edmSingle.value))
AzureIoTClient 0:1f9b2707ec7d 1973 {
AzureIoTClient 0:1f9b2707ec7d 1974 if (STRING_concat(destination, MINUSINF_STRING) != 0)
AzureIoTClient 0:1f9b2707ec7d 1975 {
AzureIoTClient 0:1f9b2707ec7d 1976 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1977 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1978 }
AzureIoTClient 0:1f9b2707ec7d 1979 else
AzureIoTClient 0:1f9b2707ec7d 1980 {
AzureIoTClient 0:1f9b2707ec7d 1981 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1982 }
AzureIoTClient 0:1f9b2707ec7d 1983 }
AzureIoTClient 0:1f9b2707ec7d 1984 else if (ISPOSITIVEINFINITY(value->value.edmSingle.value))
AzureIoTClient 0:1f9b2707ec7d 1985 {
AzureIoTClient 0:1f9b2707ec7d 1986 if (STRING_concat(destination, PLUSINF_STRING) != 0)
AzureIoTClient 0:1f9b2707ec7d 1987 {
AzureIoTClient 0:1f9b2707ec7d 1988 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 1989 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1990 }
AzureIoTClient 0:1f9b2707ec7d 1991 else
AzureIoTClient 0:1f9b2707ec7d 1992 {
AzureIoTClient 0:1f9b2707ec7d 1993 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 1994 }
AzureIoTClient 0:1f9b2707ec7d 1995 }
AzureIoTClient 0:1f9b2707ec7d 1996 else
AzureIoTClient 0:1f9b2707ec7d 1997 {
Azure.IoT Build 8:380e6e830589 1998 size_t tempBufferSize = MAX_FLOATING_POINT_STRING_LENGTH;
Azure.IoT Build 8:380e6e830589 1999 char* tempBuffer = (char*)malloc(tempBufferSize);
Azure.IoT Build 8:380e6e830589 2000 if (tempBuffer == NULL)
Azure.IoT Build 8:380e6e830589 2001 {
Azure.IoT Build 8:380e6e830589 2002 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2003 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 2004 }
Azure.IoT Build 8:380e6e830589 2005 else
Azure.IoT Build 8:380e6e830589 2006 {
Azure.IoT Build 8:380e6e830589 2007 if (sprintf_s(tempBuffer, tempBufferSize, "%.*f", FLT_DIG, (double)(value->value.edmSingle.value)) < 0)
Azure.IoT Build 8:380e6e830589 2008 {
Azure.IoT Build 8:380e6e830589 2009 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2010 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 2011 }
Azure.IoT Build 8:380e6e830589 2012 else if (STRING_concat(destination, tempBuffer) != 0)
Azure.IoT Build 8:380e6e830589 2013 {
Azure.IoT Build 8:380e6e830589 2014 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2015 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 2016 }
Azure.IoT Build 8:380e6e830589 2017 else
Azure.IoT Build 8:380e6e830589 2018 {
Azure.IoT Build 8:380e6e830589 2019 result = AGENT_DATA_TYPES_OK;
Azure.IoT Build 8:380e6e830589 2020 }
Azure.IoT Build 8:380e6e830589 2021
Azure.IoT Build 8:380e6e830589 2022 free(tempBuffer);
Azure.IoT Build 8:380e6e830589 2023 }
AzureIoTClient 0:1f9b2707ec7d 2024 }
AzureIoTClient 0:1f9b2707ec7d 2025 break;
AzureIoTClient 0:1f9b2707ec7d 2026 }
AzureIoTClient 0:1f9b2707ec7d 2027 case(EDM_DOUBLE_TYPE):
AzureIoTClient 0:1f9b2707ec7d 2028 {
AzureIoTClient 0:1f9b2707ec7d 2029 /*The sprintf function returns the number of characters written in the array, not counting the terminating null character.*/
AzureIoTClient 0:1f9b2707ec7d 2030 /*OData-ABNF says these can be used: nanInfinity = 'NaN' / '-INF' / 'INF'*/
AzureIoTClient 0:1f9b2707ec7d 2031 /*C90 doesn't declare a NaN or Inf in the standard, however, values might be NaN or Inf...*/
AzureIoTClient 0:1f9b2707ec7d 2032 /*C99 ... does*/
AzureIoTClient 0:1f9b2707ec7d 2033 /*C11 is same as C99*/
AzureIoTClient 0:1f9b2707ec7d 2034 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_022:[ EDM_DOUBLE: doubleValue = decimalValue [ "e" [SIGN] 1*DIGIT ] / nanInfinity ; IEEE 754 binary64 floating-point number (15-17 decimal digits). The representation shall use DBL_DIG C #define*/
AzureIoTClient 0:1f9b2707ec7d 2035 if(ISNAN(value->value.edmDouble.value))
AzureIoTClient 0:1f9b2707ec7d 2036 {
AzureIoTClient 0:1f9b2707ec7d 2037 if (STRING_concat(destination, NaN_STRING) != 0)
AzureIoTClient 0:1f9b2707ec7d 2038 {
AzureIoTClient 0:1f9b2707ec7d 2039 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2040 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2041 }
AzureIoTClient 0:1f9b2707ec7d 2042 else
AzureIoTClient 0:1f9b2707ec7d 2043 {
AzureIoTClient 0:1f9b2707ec7d 2044 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2045 }
AzureIoTClient 0:1f9b2707ec7d 2046 }
AzureIoTClient 0:1f9b2707ec7d 2047 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_022:[ EDM_DOUBLE: doubleValue = decimalValue [ "e" [SIGN] 1*DIGIT ] / nanInfinity ; IEEE 754 binary64 floating-point number (15-17 decimal digits). The representation shall use DBL_DIG C #define*/
AzureIoTClient 0:1f9b2707ec7d 2048 else if (ISNEGATIVEINFINITY(value->value.edmDouble.value))
AzureIoTClient 0:1f9b2707ec7d 2049 {
AzureIoTClient 0:1f9b2707ec7d 2050 if (STRING_concat(destination, MINUSINF_STRING) != 0)
AzureIoTClient 0:1f9b2707ec7d 2051 {
AzureIoTClient 0:1f9b2707ec7d 2052 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2053 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2054 }
AzureIoTClient 0:1f9b2707ec7d 2055 else
AzureIoTClient 0:1f9b2707ec7d 2056 {
AzureIoTClient 0:1f9b2707ec7d 2057 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2058 }
AzureIoTClient 0:1f9b2707ec7d 2059 }
AzureIoTClient 0:1f9b2707ec7d 2060 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_022:[ EDM_DOUBLE: doubleValue = decimalValue [ "e" [SIGN] 1*DIGIT ] / nanInfinity ; IEEE 754 binary64 floating-point number (15-17 decimal digits). The representation shall use DBL_DIG C #define*/
AzureIoTClient 0:1f9b2707ec7d 2061 else if (ISPOSITIVEINFINITY(value->value.edmDouble.value))
AzureIoTClient 0:1f9b2707ec7d 2062 {
AzureIoTClient 0:1f9b2707ec7d 2063 if (STRING_concat(destination, PLUSINF_STRING) != 0)
AzureIoTClient 0:1f9b2707ec7d 2064 {
AzureIoTClient 0:1f9b2707ec7d 2065 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2066 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2067 }
AzureIoTClient 0:1f9b2707ec7d 2068 else
AzureIoTClient 0:1f9b2707ec7d 2069 {
AzureIoTClient 0:1f9b2707ec7d 2070 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2071 }
AzureIoTClient 0:1f9b2707ec7d 2072 }
AzureIoTClient 0:1f9b2707ec7d 2073 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_022:[ EDM_DOUBLE: doubleValue = decimalValue [ "e" [SIGN] 1*DIGIT ] / nanInfinity ; IEEE 754 binary64 floating-point number (15-17 decimal digits). The representation shall use DBL_DIG C #define*/
AzureIoTClient 0:1f9b2707ec7d 2074 else
AzureIoTClient 0:1f9b2707ec7d 2075 {
Azure.IoT Build 8:380e6e830589 2076 size_t tempBufferSize = DECIMAL_DIG * 2;
Azure.IoT Build 8:380e6e830589 2077 char* tempBuffer = (char*)malloc(tempBufferSize);
Azure.IoT Build 8:380e6e830589 2078 if (tempBuffer == NULL)
Azure.IoT Build 8:380e6e830589 2079 {
Azure.IoT Build 8:380e6e830589 2080 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2081 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 2082 }
Azure.IoT Build 8:380e6e830589 2083 else
Azure.IoT Build 8:380e6e830589 2084 {
Azure.IoT Build 8:380e6e830589 2085 if (sprintf_s(tempBuffer, tempBufferSize, "%.*f", DBL_DIG, value->value.edmDouble.value) < 0)
Azure.IoT Build 8:380e6e830589 2086 {
Azure.IoT Build 8:380e6e830589 2087 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2088 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 2089 }
Azure.IoT Build 8:380e6e830589 2090 else if (STRING_concat(destination, tempBuffer) != 0)
Azure.IoT Build 8:380e6e830589 2091 {
Azure.IoT Build 8:380e6e830589 2092 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2093 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
Azure.IoT Build 8:380e6e830589 2094 }
Azure.IoT Build 8:380e6e830589 2095 else
Azure.IoT Build 8:380e6e830589 2096 {
Azure.IoT Build 8:380e6e830589 2097 result = AGENT_DATA_TYPES_OK;
Azure.IoT Build 8:380e6e830589 2098 }
Azure.IoT Build 8:380e6e830589 2099
Azure.IoT Build 8:380e6e830589 2100 free(tempBuffer);
Azure.IoT Build 8:380e6e830589 2101 }
AzureIoTClient 0:1f9b2707ec7d 2102 }
AzureIoTClient 0:1f9b2707ec7d 2103 break;
AzureIoTClient 0:1f9b2707ec7d 2104 }
AzureIoTClient 6:36cc37b1dbc9 2105 #endif
AzureIoTClient 0:1f9b2707ec7d 2106
AzureIoTClient 0:1f9b2707ec7d 2107 case(EDM_COMPLEX_TYPE_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2108 {
AzureIoTClient 0:1f9b2707ec7d 2109 /*to produce an EDM_COMPLEX_TYPE is a recursive process*/
AzureIoTClient 0:1f9b2707ec7d 2110 /*uses JSON encoder*/
AzureIoTClient 0:1f9b2707ec7d 2111 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_062:[ If the AGENT_DATA_TYPE represents a "complex type", then the JSON marshaller shall produce the following JSON value:[...]*/
AzureIoTClient 0:1f9b2707ec7d 2112 MULTITREE_HANDLE treeHandle;
AzureIoTClient 0:1f9b2707ec7d 2113 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2114 /*SRS_AGENT_TYPE_SYSTEM_99_016:[ When the value cannot be converted to a string AgentDataTypes_ToString shall return AGENT_DATA_TYPES_ERROR.]*/
AzureIoTClient 0:1f9b2707ec7d 2115 treeHandle = MultiTree_Create(NoCloneFunction, NoFreeFunction);
AzureIoTClient 0:1f9b2707ec7d 2116 if (treeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 2117 {
AzureIoTClient 0:1f9b2707ec7d 2118 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2119 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2120 }
AzureIoTClient 0:1f9b2707ec7d 2121 else
AzureIoTClient 0:1f9b2707ec7d 2122 {
AzureIoTClient 0:1f9b2707ec7d 2123 size_t i;
AzureIoTClient 0:1f9b2707ec7d 2124 for (i = 0; i < value->value.edmComplexType.nMembers; i++)
AzureIoTClient 0:1f9b2707ec7d 2125 {
AzureIoTClient 0:1f9b2707ec7d 2126 if (MultiTree_AddLeaf(treeHandle, value->value.edmComplexType.fields[i].fieldName, value->value.edmComplexType.fields[i].value) != MULTITREE_OK)
AzureIoTClient 0:1f9b2707ec7d 2127 {
AzureIoTClient 0:1f9b2707ec7d 2128 /*SRS_AGENT_TYPE_SYSTEM_99_016:[ When the value cannot be converted to a string AgentDataTypes_ToString shall return AGENT_DATA_TYPES_ERROR.]*/
AzureIoTClient 0:1f9b2707ec7d 2129 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2130 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2131 break;
AzureIoTClient 0:1f9b2707ec7d 2132 }
AzureIoTClient 0:1f9b2707ec7d 2133 else
AzureIoTClient 0:1f9b2707ec7d 2134 {
AzureIoTClient 0:1f9b2707ec7d 2135 /*all is fine*/
AzureIoTClient 0:1f9b2707ec7d 2136 }
AzureIoTClient 0:1f9b2707ec7d 2137 }
AzureIoTClient 0:1f9b2707ec7d 2138
AzureIoTClient 0:1f9b2707ec7d 2139 if (result == AGENT_DATA_TYPES_OK)
AzureIoTClient 0:1f9b2707ec7d 2140 {
AzureIoTClient 0:1f9b2707ec7d 2141 /*SRS_AGENT_TYPE_SYSTEM_99_016:[ When the value cannot be converted to a string AgentDataTypes_ToString shall return AGENT_DATA_TYPES_ERROR.]*/
AzureIoTClient 0:1f9b2707ec7d 2142 if (JSONEncoder_EncodeTree(treeHandle, destination, (JSON_ENCODER_TOSTRING_FUNC)AgentDataTypes_ToString) != JSON_ENCODER_OK)
AzureIoTClient 0:1f9b2707ec7d 2143 {
AzureIoTClient 0:1f9b2707ec7d 2144 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2145 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2146 }
AzureIoTClient 0:1f9b2707ec7d 2147 else
AzureIoTClient 0:1f9b2707ec7d 2148 {
AzureIoTClient 0:1f9b2707ec7d 2149 /*all is fine*/
AzureIoTClient 0:1f9b2707ec7d 2150 }
AzureIoTClient 0:1f9b2707ec7d 2151
AzureIoTClient 0:1f9b2707ec7d 2152 }
AzureIoTClient 0:1f9b2707ec7d 2153
AzureIoTClient 0:1f9b2707ec7d 2154 MultiTree_Destroy(treeHandle);
AzureIoTClient 0:1f9b2707ec7d 2155 }
AzureIoTClient 0:1f9b2707ec7d 2156 break;
AzureIoTClient 0:1f9b2707ec7d 2157 }
AzureIoTClient 0:1f9b2707ec7d 2158 case EDM_GUID_TYPE:
AzureIoTClient 0:1f9b2707ec7d 2159 {
AzureIoTClient 0:1f9b2707ec7d 2160 char tempBuffer2[1 + 8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 12 + 1+ 1];
AzureIoTClient 0:1f9b2707ec7d 2161 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_093:[ EDM_GUID: 8HEXDIG "-" 4HEXDIG "-" 4HEXDIG "-" 4HEXDIG "-" 12HEXDIG]*/
AzureIoTClient 0:1f9b2707ec7d 2162 tempBuffer2[0] = '\"';
AzureIoTClient 0:1f9b2707ec7d 2163 tempBuffer2[1] = hexDigitToChar(value->value.edmGuid.GUID[0] / 16);
AzureIoTClient 0:1f9b2707ec7d 2164 tempBuffer2[2] = hexDigitToChar(value->value.edmGuid.GUID[0] % 16);
AzureIoTClient 0:1f9b2707ec7d 2165 tempBuffer2[3] = hexDigitToChar(value->value.edmGuid.GUID[1] / 16);
AzureIoTClient 0:1f9b2707ec7d 2166 tempBuffer2[4] = hexDigitToChar(value->value.edmGuid.GUID[1] % 16);
AzureIoTClient 0:1f9b2707ec7d 2167 tempBuffer2[5] = hexDigitToChar(value->value.edmGuid.GUID[2] / 16);
AzureIoTClient 0:1f9b2707ec7d 2168 tempBuffer2[6] = hexDigitToChar(value->value.edmGuid.GUID[2] % 16);
AzureIoTClient 0:1f9b2707ec7d 2169 tempBuffer2[7] = hexDigitToChar(value->value.edmGuid.GUID[3] / 16);
AzureIoTClient 0:1f9b2707ec7d 2170 tempBuffer2[8] = hexDigitToChar(value->value.edmGuid.GUID[3] % 16);
AzureIoTClient 0:1f9b2707ec7d 2171
AzureIoTClient 0:1f9b2707ec7d 2172 tempBuffer2[9] = '-';
AzureIoTClient 0:1f9b2707ec7d 2173 tempBuffer2[10] = hexDigitToChar(value->value.edmGuid.GUID[4] / 16);
AzureIoTClient 0:1f9b2707ec7d 2174 tempBuffer2[11] = hexDigitToChar(value->value.edmGuid.GUID[4] % 16);
AzureIoTClient 0:1f9b2707ec7d 2175 tempBuffer2[12] = hexDigitToChar(value->value.edmGuid.GUID[5] / 16);
AzureIoTClient 0:1f9b2707ec7d 2176 tempBuffer2[13] = hexDigitToChar(value->value.edmGuid.GUID[5] % 16);
AzureIoTClient 0:1f9b2707ec7d 2177
AzureIoTClient 0:1f9b2707ec7d 2178 tempBuffer2[14] = '-';
AzureIoTClient 0:1f9b2707ec7d 2179 tempBuffer2[15] = hexDigitToChar(value->value.edmGuid.GUID[6] / 16);
AzureIoTClient 0:1f9b2707ec7d 2180 tempBuffer2[16] = hexDigitToChar(value->value.edmGuid.GUID[6] % 16);
AzureIoTClient 0:1f9b2707ec7d 2181 tempBuffer2[17] = hexDigitToChar(value->value.edmGuid.GUID[7] / 16);
AzureIoTClient 0:1f9b2707ec7d 2182 tempBuffer2[18] = hexDigitToChar(value->value.edmGuid.GUID[7] % 16);
AzureIoTClient 0:1f9b2707ec7d 2183
AzureIoTClient 0:1f9b2707ec7d 2184 tempBuffer2[19] = '-';
AzureIoTClient 0:1f9b2707ec7d 2185 tempBuffer2[20] = hexDigitToChar(value->value.edmGuid.GUID[8] / 16);
AzureIoTClient 0:1f9b2707ec7d 2186 tempBuffer2[21] = hexDigitToChar(value->value.edmGuid.GUID[8] % 16);
AzureIoTClient 0:1f9b2707ec7d 2187 tempBuffer2[22] = hexDigitToChar(value->value.edmGuid.GUID[9] / 16);
AzureIoTClient 0:1f9b2707ec7d 2188 tempBuffer2[23] = hexDigitToChar(value->value.edmGuid.GUID[9] % 16);
AzureIoTClient 0:1f9b2707ec7d 2189
AzureIoTClient 0:1f9b2707ec7d 2190 tempBuffer2[24] = '-';
AzureIoTClient 0:1f9b2707ec7d 2191 tempBuffer2[25] = hexDigitToChar(value->value.edmGuid.GUID[10] / 16);
AzureIoTClient 0:1f9b2707ec7d 2192 tempBuffer2[26] = hexDigitToChar(value->value.edmGuid.GUID[10] % 16);
AzureIoTClient 0:1f9b2707ec7d 2193 tempBuffer2[27] = hexDigitToChar(value->value.edmGuid.GUID[11] / 16);
AzureIoTClient 0:1f9b2707ec7d 2194 tempBuffer2[28] = hexDigitToChar(value->value.edmGuid.GUID[11] % 16);
AzureIoTClient 0:1f9b2707ec7d 2195 tempBuffer2[29] = hexDigitToChar(value->value.edmGuid.GUID[12] / 16);
AzureIoTClient 0:1f9b2707ec7d 2196 tempBuffer2[30] = hexDigitToChar(value->value.edmGuid.GUID[12] % 16);
AzureIoTClient 0:1f9b2707ec7d 2197 tempBuffer2[31] = hexDigitToChar(value->value.edmGuid.GUID[13] / 16);
AzureIoTClient 0:1f9b2707ec7d 2198 tempBuffer2[32] = hexDigitToChar(value->value.edmGuid.GUID[13] % 16);
AzureIoTClient 0:1f9b2707ec7d 2199 tempBuffer2[33] = hexDigitToChar(value->value.edmGuid.GUID[14] / 16);
AzureIoTClient 0:1f9b2707ec7d 2200 tempBuffer2[34] = hexDigitToChar(value->value.edmGuid.GUID[14] % 16);
AzureIoTClient 0:1f9b2707ec7d 2201 tempBuffer2[35] = hexDigitToChar(value->value.edmGuid.GUID[15] / 16);
AzureIoTClient 0:1f9b2707ec7d 2202 tempBuffer2[36] = hexDigitToChar(value->value.edmGuid.GUID[15] % 16);
AzureIoTClient 0:1f9b2707ec7d 2203
AzureIoTClient 0:1f9b2707ec7d 2204 tempBuffer2[37] = '\"';
AzureIoTClient 0:1f9b2707ec7d 2205 tempBuffer2[38] = '\0';
AzureIoTClient 0:1f9b2707ec7d 2206
AzureIoTClient 0:1f9b2707ec7d 2207 if (STRING_concat(destination, tempBuffer2) != 0)
AzureIoTClient 0:1f9b2707ec7d 2208 {
AzureIoTClient 0:1f9b2707ec7d 2209 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2210 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2211 }
AzureIoTClient 0:1f9b2707ec7d 2212 else
AzureIoTClient 0:1f9b2707ec7d 2213 {
AzureIoTClient 0:1f9b2707ec7d 2214 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2215 }
AzureIoTClient 0:1f9b2707ec7d 2216 break;
AzureIoTClient 0:1f9b2707ec7d 2217 }
AzureIoTClient 0:1f9b2707ec7d 2218 case EDM_BINARY_TYPE:
AzureIoTClient 0:1f9b2707ec7d 2219 {
AzureIoTClient 0:1f9b2707ec7d 2220 size_t currentPosition = 0;
AzureIoTClient 0:1f9b2707ec7d 2221 char* temp;
AzureIoTClient 0:1f9b2707ec7d 2222 /*binary types */
AzureIoTClient 0:1f9b2707ec7d 2223 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_099:[EDM_BINARY:= *(4base64char)[base64b16 / base64b8]]*/
AzureIoTClient 0:1f9b2707ec7d 2224 /*the following will happen*/
AzureIoTClient 0:1f9b2707ec7d 2225 /*1. the "data" of the binary shall be "eaten" 3 characters at a time and produce 4 base64 encoded characters for as long as there are more than 3 characters still to process*/
AzureIoTClient 0:1f9b2707ec7d 2226 /*2. the remaining characters (1 or 2) shall be encoded.*/
AzureIoTClient 0:1f9b2707ec7d 2227 /*there's a level of assumption that 'a' corresponds to 0b000000 and that '_' corresponds to 0b111111*/
AzureIoTClient 0:1f9b2707ec7d 2228 /*the encoding will use the optional [=] or [==] at the end of the encoded string, so that other less standard aware libraries can do their work*/
AzureIoTClient 0:1f9b2707ec7d 2229 /*these are the bits of the 3 normal bytes to be encoded*/
AzureIoTClient 0:1f9b2707ec7d 2230 size_t neededSize = 2; /*2 because starting and ending quotes */
AzureIoTClient 0:1f9b2707ec7d 2231 neededSize += (value->value.edmBinary.size == 0) ? (0) : ((((value->value.edmBinary.size-1) / 3) + 1) * 4);
AzureIoTClient 0:1f9b2707ec7d 2232 neededSize += 1; /*+1 because \0 at the end of the string*/
AzureIoTClient 0:1f9b2707ec7d 2233 if ((temp = (char*)malloc(neededSize))==NULL)
AzureIoTClient 0:1f9b2707ec7d 2234 {
AzureIoTClient 0:1f9b2707ec7d 2235 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 0:1f9b2707ec7d 2236 }
AzureIoTClient 0:1f9b2707ec7d 2237 else
AzureIoTClient 0:1f9b2707ec7d 2238 {
AzureIoTClient 0:1f9b2707ec7d 2239 /*b0 b1(+1) b2(+2)
AzureIoTClient 0:1f9b2707ec7d 2240 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
AzureIoTClient 0:1f9b2707ec7d 2241 |----c1---| |----c2---| |----c3---| |----c4---|
AzureIoTClient 0:1f9b2707ec7d 2242 */
AzureIoTClient 0:1f9b2707ec7d 2243
AzureIoTClient 0:1f9b2707ec7d 2244 size_t destinationPointer = 0;
AzureIoTClient 0:1f9b2707ec7d 2245 temp[destinationPointer++] = '"';
AzureIoTClient 0:1f9b2707ec7d 2246 while (value->value.edmBinary.size - currentPosition >= 3)
AzureIoTClient 0:1f9b2707ec7d 2247 {
AzureIoTClient 16:ef107f3f230c 2248 char c1 = base64char(value->value.edmBinary.data[currentPosition] >> 2);
AzureIoTClient 16:ef107f3f230c 2249 char c2 = base64char(
AzureIoTClient 0:1f9b2707ec7d 2250 ((value->value.edmBinary.data[currentPosition] & 3) << 4) |
AzureIoTClient 0:1f9b2707ec7d 2251 (value->value.edmBinary.data[currentPosition + 1] >> 4)
AzureIoTClient 16:ef107f3f230c 2252 );
AzureIoTClient 16:ef107f3f230c 2253 char c3 = base64char(
AzureIoTClient 0:1f9b2707ec7d 2254 ((value->value.edmBinary.data[currentPosition + 1] & 0x0F) << 2) |
AzureIoTClient 0:1f9b2707ec7d 2255 ((value->value.edmBinary.data[currentPosition + 2] >> 6) & 3)
AzureIoTClient 16:ef107f3f230c 2256 );
AzureIoTClient 16:ef107f3f230c 2257 char c4 = base64char(
AzureIoTClient 0:1f9b2707ec7d 2258 value->value.edmBinary.data[currentPosition + 2] & 0x3F
AzureIoTClient 16:ef107f3f230c 2259 );
AzureIoTClient 0:1f9b2707ec7d 2260 currentPosition += 3;
AzureIoTClient 0:1f9b2707ec7d 2261 temp[destinationPointer++] = c1;
AzureIoTClient 0:1f9b2707ec7d 2262 temp[destinationPointer++] = c2;
AzureIoTClient 0:1f9b2707ec7d 2263 temp[destinationPointer++] = c3;
AzureIoTClient 0:1f9b2707ec7d 2264 temp[destinationPointer++] = c4;
AzureIoTClient 0:1f9b2707ec7d 2265
AzureIoTClient 0:1f9b2707ec7d 2266 }
AzureIoTClient 0:1f9b2707ec7d 2267 if (value->value.edmBinary.size - currentPosition == 2)
AzureIoTClient 0:1f9b2707ec7d 2268 {
AzureIoTClient 16:ef107f3f230c 2269 char c1 = base64char(value->value.edmBinary.data[currentPosition] >> 2);
AzureIoTClient 16:ef107f3f230c 2270 char c2 = base64char(
AzureIoTClient 0:1f9b2707ec7d 2271 ((value->value.edmBinary.data[currentPosition] & 0x03) << 4) |
AzureIoTClient 0:1f9b2707ec7d 2272 (value->value.edmBinary.data[currentPosition + 1] >> 4)
AzureIoTClient 16:ef107f3f230c 2273 );
AzureIoTClient 16:ef107f3f230c 2274 char c3 = base64b16(value->value.edmBinary.data[currentPosition + 1] & 0x0F);
AzureIoTClient 0:1f9b2707ec7d 2275 temp[destinationPointer++] = c1;
AzureIoTClient 0:1f9b2707ec7d 2276 temp[destinationPointer++] = c2;
AzureIoTClient 0:1f9b2707ec7d 2277 temp[destinationPointer++] = c3;
AzureIoTClient 0:1f9b2707ec7d 2278 temp[destinationPointer++] = '=';
AzureIoTClient 0:1f9b2707ec7d 2279 }
AzureIoTClient 0:1f9b2707ec7d 2280 else if (value->value.edmBinary.size - currentPosition == 1)
AzureIoTClient 0:1f9b2707ec7d 2281 {
AzureIoTClient 16:ef107f3f230c 2282 char c1 = base64char(value->value.edmBinary.data[currentPosition] >> 2);
AzureIoTClient 16:ef107f3f230c 2283 char c2 = base64b8(value->value.edmBinary.data[currentPosition] & 0x03);
AzureIoTClient 0:1f9b2707ec7d 2284 temp[destinationPointer++] = c1;
AzureIoTClient 0:1f9b2707ec7d 2285 temp[destinationPointer++] = c2;
AzureIoTClient 0:1f9b2707ec7d 2286 temp[destinationPointer++] = '=';
AzureIoTClient 0:1f9b2707ec7d 2287 temp[destinationPointer++] = '=';
AzureIoTClient 0:1f9b2707ec7d 2288 }
AzureIoTClient 0:1f9b2707ec7d 2289
AzureIoTClient 0:1f9b2707ec7d 2290 /*closing quote*/
AzureIoTClient 0:1f9b2707ec7d 2291 temp[destinationPointer++] = '"';
AzureIoTClient 0:1f9b2707ec7d 2292 /*null terminating the string*/
AzureIoTClient 0:1f9b2707ec7d 2293 temp[destinationPointer] = '\0';
AzureIoTClient 0:1f9b2707ec7d 2294
AzureIoTClient 0:1f9b2707ec7d 2295 if (STRING_concat(destination, temp) != 0)
AzureIoTClient 0:1f9b2707ec7d 2296 {
AzureIoTClient 0:1f9b2707ec7d 2297 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2298 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2299 }
AzureIoTClient 0:1f9b2707ec7d 2300 else
AzureIoTClient 0:1f9b2707ec7d 2301 {
AzureIoTClient 0:1f9b2707ec7d 2302 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2303 }
AzureIoTClient 0:1f9b2707ec7d 2304 free(temp);
AzureIoTClient 0:1f9b2707ec7d 2305 }
AzureIoTClient 0:1f9b2707ec7d 2306 break;
AzureIoTClient 0:1f9b2707ec7d 2307 }
AzureIoTClient 0:1f9b2707ec7d 2308 }
AzureIoTClient 0:1f9b2707ec7d 2309 }
AzureIoTClient 0:1f9b2707ec7d 2310 return result;
AzureIoTClient 0:1f9b2707ec7d 2311 }
AzureIoTClient 0:1f9b2707ec7d 2312
AzureIoTClient 0:1f9b2707ec7d 2313 /*return 0 if all names are different than NULL*/
AzureIoTClient 0:1f9b2707ec7d 2314 static int isOneNameNULL(size_t nMemberNames, const char* const * memberNames)
AzureIoTClient 0:1f9b2707ec7d 2315 {
AzureIoTClient 0:1f9b2707ec7d 2316 size_t i;
AzureIoTClient 0:1f9b2707ec7d 2317 int result = 0;
AzureIoTClient 0:1f9b2707ec7d 2318 for (i = 0; i < nMemberNames; i++)
AzureIoTClient 0:1f9b2707ec7d 2319 {
AzureIoTClient 0:1f9b2707ec7d 2320 if (memberNames[i] == NULL)
AzureIoTClient 0:1f9b2707ec7d 2321 {
AzureIoTClient 0:1f9b2707ec7d 2322 result = 1;
AzureIoTClient 0:1f9b2707ec7d 2323 break;
AzureIoTClient 0:1f9b2707ec7d 2324 }
AzureIoTClient 0:1f9b2707ec7d 2325 }
AzureIoTClient 0:1f9b2707ec7d 2326 return result;
AzureIoTClient 0:1f9b2707ec7d 2327 }
AzureIoTClient 0:1f9b2707ec7d 2328
AzureIoTClient 0:1f9b2707ec7d 2329 /*return 0 if all names are different than NULL*/
AzureIoTClient 0:1f9b2707ec7d 2330 static int areThereTwoSameNames(size_t nMemberNames, const char* const * memberNames)
AzureIoTClient 0:1f9b2707ec7d 2331 {
AzureIoTClient 0:1f9b2707ec7d 2332 size_t i, j;
AzureIoTClient 0:1f9b2707ec7d 2333 int result = 0;
AzureIoTClient 0:1f9b2707ec7d 2334 for (i = 0; i < nMemberNames-1; i++)
AzureIoTClient 0:1f9b2707ec7d 2335 {
AzureIoTClient 0:1f9b2707ec7d 2336 for (j = i + 1; j < nMemberNames; j++)
AzureIoTClient 0:1f9b2707ec7d 2337 {
AzureIoTClient 0:1f9b2707ec7d 2338 if (strcmp(memberNames[i], memberNames[j]) == 0)
AzureIoTClient 0:1f9b2707ec7d 2339 {
AzureIoTClient 0:1f9b2707ec7d 2340 result = 1;
AzureIoTClient 0:1f9b2707ec7d 2341 goto out;
AzureIoTClient 0:1f9b2707ec7d 2342 }
AzureIoTClient 0:1f9b2707ec7d 2343 }
AzureIoTClient 0:1f9b2707ec7d 2344 }
AzureIoTClient 0:1f9b2707ec7d 2345 out:
AzureIoTClient 0:1f9b2707ec7d 2346 return result;
AzureIoTClient 0:1f9b2707ec7d 2347 }
AzureIoTClient 0:1f9b2707ec7d 2348
AzureIoTClient 0:1f9b2707ec7d 2349 static void DestroyHalfBakedComplexType(AGENT_DATA_TYPE* agentData)
AzureIoTClient 0:1f9b2707ec7d 2350 {
AzureIoTClient 0:1f9b2707ec7d 2351 size_t i;
AzureIoTClient 0:1f9b2707ec7d 2352 if (agentData != NULL)
AzureIoTClient 0:1f9b2707ec7d 2353 {
AzureIoTClient 0:1f9b2707ec7d 2354 if (agentData->type == EDM_COMPLEX_TYPE_TYPE)
AzureIoTClient 0:1f9b2707ec7d 2355 {
AzureIoTClient 0:1f9b2707ec7d 2356 if (agentData->value.edmComplexType.fields != NULL)
AzureIoTClient 0:1f9b2707ec7d 2357 {
AzureIoTClient 0:1f9b2707ec7d 2358 for (i = 0; i < agentData->value.edmComplexType.nMembers; i++)
AzureIoTClient 0:1f9b2707ec7d 2359 {
AzureIoTClient 0:1f9b2707ec7d 2360 if (agentData->value.edmComplexType.fields[i].fieldName != NULL)
AzureIoTClient 0:1f9b2707ec7d 2361 {
AzureIoTClient 0:1f9b2707ec7d 2362 free((void*)(agentData->value.edmComplexType.fields[i].fieldName));
AzureIoTClient 0:1f9b2707ec7d 2363 agentData->value.edmComplexType.fields[i].fieldName = NULL;
AzureIoTClient 0:1f9b2707ec7d 2364 }
AzureIoTClient 0:1f9b2707ec7d 2365 if (agentData->value.edmComplexType.fields[i].value != NULL)
AzureIoTClient 0:1f9b2707ec7d 2366 {
AzureIoTClient 0:1f9b2707ec7d 2367 Destroy_AGENT_DATA_TYPE(agentData->value.edmComplexType.fields[i].value);
AzureIoTClient 0:1f9b2707ec7d 2368 free(agentData->value.edmComplexType.fields[i].value);
AzureIoTClient 0:1f9b2707ec7d 2369 agentData->value.edmComplexType.fields[i].value = NULL;
AzureIoTClient 0:1f9b2707ec7d 2370 }
AzureIoTClient 0:1f9b2707ec7d 2371 }
AzureIoTClient 0:1f9b2707ec7d 2372 free(agentData->value.edmComplexType.fields);
AzureIoTClient 0:1f9b2707ec7d 2373 agentData->value.edmComplexType.fields = NULL;
AzureIoTClient 0:1f9b2707ec7d 2374 }
AzureIoTClient 0:1f9b2707ec7d 2375 agentData->type = EDM_NO_TYPE;
AzureIoTClient 0:1f9b2707ec7d 2376 }
AzureIoTClient 0:1f9b2707ec7d 2377 }
AzureIoTClient 0:1f9b2707ec7d 2378 }
AzureIoTClient 0:1f9b2707ec7d 2379
AzureIoTClient 0:1f9b2707ec7d 2380 /* Creates an object of AGENT_DATA_TYPE_TYPE EDM_NULL_TYPE*/
AzureIoTClient 0:1f9b2707ec7d 2381 AGENT_DATA_TYPES_RESULT Create_NULL_AGENT_DATA_TYPE(AGENT_DATA_TYPE* agentData)
AzureIoTClient 0:1f9b2707ec7d 2382 {
AzureIoTClient 0:1f9b2707ec7d 2383 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 2384 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 2385 {
AzureIoTClient 0:1f9b2707ec7d 2386 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2387 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2388 }
AzureIoTClient 0:1f9b2707ec7d 2389 else
AzureIoTClient 0:1f9b2707ec7d 2390 {
AzureIoTClient 0:1f9b2707ec7d 2391 agentData->type = EDM_NULL_TYPE;
AzureIoTClient 0:1f9b2707ec7d 2392 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2393 }
AzureIoTClient 0:1f9b2707ec7d 2394 return result;
AzureIoTClient 0:1f9b2707ec7d 2395 }
AzureIoTClient 0:1f9b2707ec7d 2396 /*creates a copy of the AGENT_DATA_TYPE*/
AzureIoTClient 0:1f9b2707ec7d 2397 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_AGENT_DATA_TYPE(AGENT_DATA_TYPE* dest, const AGENT_DATA_TYPE* src)
AzureIoTClient 0:1f9b2707ec7d 2398 {
AzureIoTClient 0:1f9b2707ec7d 2399 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 2400 size_t i;
AzureIoTClient 0:1f9b2707ec7d 2401 if ((dest == NULL) || (src == NULL))
AzureIoTClient 0:1f9b2707ec7d 2402 {
AzureIoTClient 0:1f9b2707ec7d 2403 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2404 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2405 }
AzureIoTClient 0:1f9b2707ec7d 2406 else
AzureIoTClient 0:1f9b2707ec7d 2407 {
AzureIoTClient 0:1f9b2707ec7d 2408 switch (src->type)
AzureIoTClient 0:1f9b2707ec7d 2409 {
AzureIoTClient 0:1f9b2707ec7d 2410 default:
AzureIoTClient 0:1f9b2707ec7d 2411 {
AzureIoTClient 0:1f9b2707ec7d 2412 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2413 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2414 break;
AzureIoTClient 0:1f9b2707ec7d 2415 }
AzureIoTClient 0:1f9b2707ec7d 2416 case(EDM_NO_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2417 case(EDM_NULL_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2418 {
AzureIoTClient 0:1f9b2707ec7d 2419 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2420 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2421 break;
AzureIoTClient 0:1f9b2707ec7d 2422 }
AzureIoTClient 0:1f9b2707ec7d 2423 case(EDM_BOOLEAN_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2424 {
AzureIoTClient 0:1f9b2707ec7d 2425 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2426 dest->value.edmBoolean= src->value.edmBoolean;
AzureIoTClient 0:1f9b2707ec7d 2427 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2428 break;
AzureIoTClient 0:1f9b2707ec7d 2429 }
AzureIoTClient 0:1f9b2707ec7d 2430 case(EDM_BYTE_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2431 {
AzureIoTClient 0:1f9b2707ec7d 2432 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2433 dest->value.edmByte= src->value.edmByte;
AzureIoTClient 0:1f9b2707ec7d 2434 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2435 break;
AzureIoTClient 0:1f9b2707ec7d 2436 }
AzureIoTClient 0:1f9b2707ec7d 2437 case(EDM_DATE_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2438 {
AzureIoTClient 0:1f9b2707ec7d 2439 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2440 dest->value.edmDate = src->value.edmDate;
AzureIoTClient 0:1f9b2707ec7d 2441 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2442 break;
AzureIoTClient 0:1f9b2707ec7d 2443 }
AzureIoTClient 0:1f9b2707ec7d 2444 case(EDM_DATE_TIME_OFFSET_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2445 {
AzureIoTClient 0:1f9b2707ec7d 2446 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2447 dest->value.edmDateTimeOffset = src->value.edmDateTimeOffset;
AzureIoTClient 0:1f9b2707ec7d 2448 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2449 break;
AzureIoTClient 0:1f9b2707ec7d 2450 }
AzureIoTClient 0:1f9b2707ec7d 2451 case(EDM_DECIMAL_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2452 {
AzureIoTClient 0:1f9b2707ec7d 2453 if ((dest->value.edmDecimal.value = STRING_clone(src->value.edmDecimal.value)) == NULL)
AzureIoTClient 0:1f9b2707ec7d 2454 {
AzureIoTClient 0:1f9b2707ec7d 2455 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2456 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2457 }
AzureIoTClient 0:1f9b2707ec7d 2458 else
AzureIoTClient 0:1f9b2707ec7d 2459 {
AzureIoTClient 0:1f9b2707ec7d 2460 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2461 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2462 /*all is fine*/
AzureIoTClient 0:1f9b2707ec7d 2463 }
AzureIoTClient 0:1f9b2707ec7d 2464 break;
AzureIoTClient 0:1f9b2707ec7d 2465 }
AzureIoTClient 0:1f9b2707ec7d 2466 case(EDM_DOUBLE_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2467 {
AzureIoTClient 0:1f9b2707ec7d 2468 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2469 dest->value.edmDouble = src->value.edmDouble;
AzureIoTClient 0:1f9b2707ec7d 2470 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2471 break;
AzureIoTClient 0:1f9b2707ec7d 2472 }
AzureIoTClient 0:1f9b2707ec7d 2473 case(EDM_DURATION_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2474 {
AzureIoTClient 0:1f9b2707ec7d 2475 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2476 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2477 break;
AzureIoTClient 0:1f9b2707ec7d 2478 }
AzureIoTClient 0:1f9b2707ec7d 2479 case(EDM_GUID_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2480 {
AzureIoTClient 0:1f9b2707ec7d 2481 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2482 dest->value.edmGuid = src->value.edmGuid;
AzureIoTClient 0:1f9b2707ec7d 2483 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2484 break;
AzureIoTClient 0:1f9b2707ec7d 2485 }
AzureIoTClient 0:1f9b2707ec7d 2486 case EDM_BINARY_TYPE:
AzureIoTClient 0:1f9b2707ec7d 2487 {
AzureIoTClient 0:1f9b2707ec7d 2488 if (src->value.edmBinary.size == 0)
AzureIoTClient 0:1f9b2707ec7d 2489 {
AzureIoTClient 0:1f9b2707ec7d 2490 dest->value.edmBinary.size = 0;
AzureIoTClient 0:1f9b2707ec7d 2491 dest->value.edmBinary.data = NULL;
AzureIoTClient 0:1f9b2707ec7d 2492 dest->type = EDM_BINARY_TYPE;
AzureIoTClient 0:1f9b2707ec7d 2493 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2494 }
AzureIoTClient 0:1f9b2707ec7d 2495 else
AzureIoTClient 0:1f9b2707ec7d 2496 {
AzureIoTClient 0:1f9b2707ec7d 2497 if ((dest->value.edmBinary.data = (unsigned char*)malloc(src->value.edmBinary.size)) == NULL)
AzureIoTClient 0:1f9b2707ec7d 2498 {
AzureIoTClient 0:1f9b2707ec7d 2499 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 0:1f9b2707ec7d 2500 }
AzureIoTClient 0:1f9b2707ec7d 2501 else
AzureIoTClient 0:1f9b2707ec7d 2502 {
AzureIoTClient 0:1f9b2707ec7d 2503 dest->value.edmBinary.size = src->value.edmBinary.size;
AzureIoTClient 0:1f9b2707ec7d 2504 memcpy(dest->value.edmBinary.data, src->value.edmBinary.data, src->value.edmBinary.size);
AzureIoTClient 0:1f9b2707ec7d 2505 dest->type = EDM_BINARY_TYPE;
AzureIoTClient 0:1f9b2707ec7d 2506 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2507 }
AzureIoTClient 0:1f9b2707ec7d 2508 }
AzureIoTClient 0:1f9b2707ec7d 2509 break;
AzureIoTClient 0:1f9b2707ec7d 2510 }
AzureIoTClient 0:1f9b2707ec7d 2511 case(EDM_INT16_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2512 {
AzureIoTClient 0:1f9b2707ec7d 2513 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2514 dest->value.edmInt16 = src->value.edmInt16;
AzureIoTClient 0:1f9b2707ec7d 2515 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2516 break;
AzureIoTClient 0:1f9b2707ec7d 2517 }
AzureIoTClient 0:1f9b2707ec7d 2518 case(EDM_INT32_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2519 {
AzureIoTClient 0:1f9b2707ec7d 2520 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2521 dest->value.edmInt32 = src->value.edmInt32;
AzureIoTClient 0:1f9b2707ec7d 2522 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2523 break;
AzureIoTClient 0:1f9b2707ec7d 2524 }
AzureIoTClient 0:1f9b2707ec7d 2525 case(EDM_INT64_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2526 {
AzureIoTClient 0:1f9b2707ec7d 2527 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2528 dest->value.edmInt64 = src->value.edmInt64;
AzureIoTClient 0:1f9b2707ec7d 2529 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2530 break;
AzureIoTClient 0:1f9b2707ec7d 2531 }
AzureIoTClient 0:1f9b2707ec7d 2532 case(EDM_SBYTE_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2533 {
AzureIoTClient 0:1f9b2707ec7d 2534 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2535 dest->value.edmSbyte = src->value.edmSbyte;
AzureIoTClient 0:1f9b2707ec7d 2536 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2537 break;
AzureIoTClient 0:1f9b2707ec7d 2538 }
AzureIoTClient 0:1f9b2707ec7d 2539 case(EDM_SINGLE_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2540 {
AzureIoTClient 0:1f9b2707ec7d 2541 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2542 dest->value.edmSingle = src->value.edmSingle;
AzureIoTClient 0:1f9b2707ec7d 2543 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2544 break;
AzureIoTClient 0:1f9b2707ec7d 2545 }
AzureIoTClient 0:1f9b2707ec7d 2546 case(EDM_STREAM) :
AzureIoTClient 0:1f9b2707ec7d 2547 {
AzureIoTClient 0:1f9b2707ec7d 2548 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2549 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2550 break;
AzureIoTClient 0:1f9b2707ec7d 2551 } /*not supported, because what is stream?*/
AzureIoTClient 0:1f9b2707ec7d 2552 case(EDM_STRING_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2553 {
AzureIoTClient 0:1f9b2707ec7d 2554 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2555 dest->value.edmString.length = src->value.edmString.length;
AzureIoTClient 0:1f9b2707ec7d 2556 if (mallocAndStrcpy_s((char**)&(dest->value.edmString.chars), (char*)src->value.edmString.chars) != 0)
AzureIoTClient 0:1f9b2707ec7d 2557 {
AzureIoTClient 0:1f9b2707ec7d 2558 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2559 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2560 }
AzureIoTClient 0:1f9b2707ec7d 2561 else
AzureIoTClient 0:1f9b2707ec7d 2562 {
AzureIoTClient 0:1f9b2707ec7d 2563 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2564 /*all is fine*/
AzureIoTClient 0:1f9b2707ec7d 2565 }
AzureIoTClient 0:1f9b2707ec7d 2566 break;
AzureIoTClient 0:1f9b2707ec7d 2567 }
AzureIoTClient 0:1f9b2707ec7d 2568 case(EDM_STRING_NO_QUOTES_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2569 {
AzureIoTClient 0:1f9b2707ec7d 2570 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2571 dest->value.edmStringNoQuotes.length = src->value.edmStringNoQuotes.length;
AzureIoTClient 0:1f9b2707ec7d 2572 if (mallocAndStrcpy_s((char**)&(dest->value.edmStringNoQuotes.chars), (char*)src->value.edmStringNoQuotes.chars) != 0)
AzureIoTClient 0:1f9b2707ec7d 2573 {
AzureIoTClient 0:1f9b2707ec7d 2574 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2575 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2576 }
AzureIoTClient 0:1f9b2707ec7d 2577 else
AzureIoTClient 0:1f9b2707ec7d 2578 {
AzureIoTClient 0:1f9b2707ec7d 2579 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2580 /*all is fine*/
AzureIoTClient 0:1f9b2707ec7d 2581 }
AzureIoTClient 0:1f9b2707ec7d 2582 break;
AzureIoTClient 0:1f9b2707ec7d 2583 }
AzureIoTClient 0:1f9b2707ec7d 2584 case(EDM_TIME_OF_DAY_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2585 {
AzureIoTClient 0:1f9b2707ec7d 2586 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2587 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2588 break;
AzureIoTClient 0:1f9b2707ec7d 2589 }
AzureIoTClient 0:1f9b2707ec7d 2590 case(EDM_GEOGRAPHY_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2591 {
AzureIoTClient 0:1f9b2707ec7d 2592 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2593 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2594 break;
AzureIoTClient 0:1f9b2707ec7d 2595 } /*not supported because what is "abstract base type"*/
AzureIoTClient 0:1f9b2707ec7d 2596 case(EDM_GEOGRAPHY_POINT_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2597 {
AzureIoTClient 0:1f9b2707ec7d 2598 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2599 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2600 break;
AzureIoTClient 0:1f9b2707ec7d 2601 }
AzureIoTClient 0:1f9b2707ec7d 2602 case(EDM_GEOGRAPHY_LINE_STRING_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2603 {
AzureIoTClient 0:1f9b2707ec7d 2604 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2605 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2606 break;
AzureIoTClient 0:1f9b2707ec7d 2607 }
AzureIoTClient 0:1f9b2707ec7d 2608 case(EDM_GEOGRAPHY_POLYGON_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2609 {
AzureIoTClient 0:1f9b2707ec7d 2610 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2611 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2612 break;
AzureIoTClient 0:1f9b2707ec7d 2613 }
AzureIoTClient 0:1f9b2707ec7d 2614 case(EDM_GEOGRAPHY_MULTI_POINT_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2615 {
AzureIoTClient 0:1f9b2707ec7d 2616 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2617 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2618 break;
AzureIoTClient 0:1f9b2707ec7d 2619 }
AzureIoTClient 0:1f9b2707ec7d 2620 case(EDM_GEOGRAPHY_MULTI_LINE_STRING_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2621 {
AzureIoTClient 0:1f9b2707ec7d 2622 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2623 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2624 break;
AzureIoTClient 0:1f9b2707ec7d 2625 }
AzureIoTClient 0:1f9b2707ec7d 2626 case(EDM_GEOGRAPHY_MULTI_POLYGON_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2627 {
AzureIoTClient 0:1f9b2707ec7d 2628 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2629 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2630 break;
AzureIoTClient 0:1f9b2707ec7d 2631 }
AzureIoTClient 0:1f9b2707ec7d 2632 case(EDM_GEOGRAPHY_COLLECTION_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2633 {
AzureIoTClient 0:1f9b2707ec7d 2634 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2635 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2636 break;
AzureIoTClient 0:1f9b2707ec7d 2637 }
AzureIoTClient 0:1f9b2707ec7d 2638 case(EDM_GEOMETRY_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2639 {
AzureIoTClient 0:1f9b2707ec7d 2640 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2641 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2642 break;
AzureIoTClient 0:1f9b2707ec7d 2643 } /*not supported because what is "abstract base type"*/
AzureIoTClient 0:1f9b2707ec7d 2644 case(EDM_GEOMETRY_POINT_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2645 {
AzureIoTClient 0:1f9b2707ec7d 2646 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2647 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2648 break;
AzureIoTClient 0:1f9b2707ec7d 2649 }
AzureIoTClient 0:1f9b2707ec7d 2650 case(EDM_GEOMETRY_LINE_STRING_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2651 {
AzureIoTClient 0:1f9b2707ec7d 2652 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2653 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2654 break;
AzureIoTClient 0:1f9b2707ec7d 2655 }
AzureIoTClient 0:1f9b2707ec7d 2656 case(EDM_GEOMETRY_POLYGON_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2657 {
AzureIoTClient 0:1f9b2707ec7d 2658 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2659 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2660 break;
AzureIoTClient 0:1f9b2707ec7d 2661 }
AzureIoTClient 0:1f9b2707ec7d 2662 case(EDM_GEOMETRY_MULTI_POINT_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2663 {
AzureIoTClient 0:1f9b2707ec7d 2664 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2665 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2666 break;
AzureIoTClient 0:1f9b2707ec7d 2667 }
AzureIoTClient 0:1f9b2707ec7d 2668 case(EDM_GEOMETRY_MULTI_LINE_STRING_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2669 {
AzureIoTClient 0:1f9b2707ec7d 2670 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2671 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2672 break;
AzureIoTClient 0:1f9b2707ec7d 2673 }
AzureIoTClient 0:1f9b2707ec7d 2674 case(EDM_GEOMETRY_MULTI_POLYGON_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2675 {
AzureIoTClient 0:1f9b2707ec7d 2676 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2677 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2678 break;
AzureIoTClient 0:1f9b2707ec7d 2679 }
AzureIoTClient 0:1f9b2707ec7d 2680 case(EDM_GEOMETRY_COLLECTION_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2681 {
AzureIoTClient 0:1f9b2707ec7d 2682 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 2683 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2684 break;
AzureIoTClient 0:1f9b2707ec7d 2685 }
AzureIoTClient 0:1f9b2707ec7d 2686 case(EDM_COMPLEX_TYPE_TYPE) :
AzureIoTClient 0:1f9b2707ec7d 2687 {
AzureIoTClient 0:1f9b2707ec7d 2688 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 2689 /*copying a COMPLEX_TYPE means to copy all its member names and all its fields*/
AzureIoTClient 0:1f9b2707ec7d 2690 dest->type = src->type;
AzureIoTClient 0:1f9b2707ec7d 2691 if (src->value.edmComplexType.nMembers == 0)
AzureIoTClient 0:1f9b2707ec7d 2692 {
AzureIoTClient 0:1f9b2707ec7d 2693 /*error*/
AzureIoTClient 0:1f9b2707ec7d 2694 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2695 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2696 }
AzureIoTClient 0:1f9b2707ec7d 2697 else
AzureIoTClient 0:1f9b2707ec7d 2698 {
AzureIoTClient 0:1f9b2707ec7d 2699 dest->value.edmComplexType.nMembers = src->value.edmComplexType.nMembers;
AzureIoTClient 0:1f9b2707ec7d 2700 dest->value.edmComplexType.fields = (COMPLEX_TYPE_FIELD_TYPE*)malloc(dest->value.edmComplexType.nMembers * sizeof(COMPLEX_TYPE_FIELD_TYPE));
AzureIoTClient 0:1f9b2707ec7d 2701 if (dest->value.edmComplexType.fields == NULL)
AzureIoTClient 0:1f9b2707ec7d 2702 {
AzureIoTClient 0:1f9b2707ec7d 2703 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2704 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2705 }
AzureIoTClient 0:1f9b2707ec7d 2706 else
AzureIoTClient 0:1f9b2707ec7d 2707 {
AzureIoTClient 0:1f9b2707ec7d 2708 for (i = 0; i < dest->value.edmComplexType.nMembers; i++)
AzureIoTClient 0:1f9b2707ec7d 2709 {
AzureIoTClient 0:1f9b2707ec7d 2710 dest->value.edmComplexType.fields[i].fieldName = NULL;
AzureIoTClient 0:1f9b2707ec7d 2711 dest->value.edmComplexType.fields[i].value = NULL;
AzureIoTClient 0:1f9b2707ec7d 2712 }
AzureIoTClient 0:1f9b2707ec7d 2713
AzureIoTClient 0:1f9b2707ec7d 2714 for (i = 0; i < dest->value.edmComplexType.nMembers; i++)
AzureIoTClient 0:1f9b2707ec7d 2715 {
AzureIoTClient 0:1f9b2707ec7d 2716 /*copy the name of this field*/
AzureIoTClient 0:1f9b2707ec7d 2717 if (mallocAndStrcpy_s((char**)(&(dest->value.edmComplexType.fields[i].fieldName)), src->value.edmComplexType.fields[i].fieldName) != 0)
AzureIoTClient 0:1f9b2707ec7d 2718 {
AzureIoTClient 0:1f9b2707ec7d 2719 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2720 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2721 break;
AzureIoTClient 0:1f9b2707ec7d 2722 }
AzureIoTClient 0:1f9b2707ec7d 2723 else
AzureIoTClient 0:1f9b2707ec7d 2724 {
AzureIoTClient 0:1f9b2707ec7d 2725 /*field name copied success*/
AzureIoTClient 0:1f9b2707ec7d 2726 /*field value copy follows*/
AzureIoTClient 0:1f9b2707ec7d 2727 dest->value.edmComplexType.fields[i].value = (AGENT_DATA_TYPE*)malloc(sizeof(AGENT_DATA_TYPE));
AzureIoTClient 0:1f9b2707ec7d 2728 if (dest->value.edmComplexType.fields[i].value == NULL)
AzureIoTClient 0:1f9b2707ec7d 2729 {
AzureIoTClient 0:1f9b2707ec7d 2730 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2731 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2732 break;
AzureIoTClient 0:1f9b2707ec7d 2733 }
AzureIoTClient 0:1f9b2707ec7d 2734 else
AzureIoTClient 0:1f9b2707ec7d 2735 {
AzureIoTClient 0:1f9b2707ec7d 2736 if (Create_AGENT_DATA_TYPE_from_AGENT_DATA_TYPE(dest->value.edmComplexType.fields[i].value, src->value.edmComplexType.fields[i].value) != AGENT_DATA_TYPES_OK)
AzureIoTClient 0:1f9b2707ec7d 2737 {
AzureIoTClient 0:1f9b2707ec7d 2738 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2739 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2740 break;
AzureIoTClient 0:1f9b2707ec7d 2741 }
AzureIoTClient 0:1f9b2707ec7d 2742 else
AzureIoTClient 0:1f9b2707ec7d 2743 {
AzureIoTClient 0:1f9b2707ec7d 2744 /*all is fine*/
AzureIoTClient 0:1f9b2707ec7d 2745 }
AzureIoTClient 0:1f9b2707ec7d 2746 }
AzureIoTClient 0:1f9b2707ec7d 2747 }
AzureIoTClient 0:1f9b2707ec7d 2748 }
AzureIoTClient 0:1f9b2707ec7d 2749
AzureIoTClient 0:1f9b2707ec7d 2750 if (result != AGENT_DATA_TYPES_OK)
AzureIoTClient 0:1f9b2707ec7d 2751 {
AzureIoTClient 0:1f9b2707ec7d 2752 /*unbuild*/
AzureIoTClient 0:1f9b2707ec7d 2753 DestroyHalfBakedComplexType(dest);
AzureIoTClient 0:1f9b2707ec7d 2754 }
AzureIoTClient 0:1f9b2707ec7d 2755 }
AzureIoTClient 0:1f9b2707ec7d 2756 }
AzureIoTClient 0:1f9b2707ec7d 2757 break;
AzureIoTClient 0:1f9b2707ec7d 2758 } /*ANY CHANGE (?!) here must be reflected in the tool providing the binary file (XML2BINARY) */
AzureIoTClient 0:1f9b2707ec7d 2759 }
AzureIoTClient 0:1f9b2707ec7d 2760
AzureIoTClient 0:1f9b2707ec7d 2761 if (result != AGENT_DATA_TYPES_OK)
AzureIoTClient 0:1f9b2707ec7d 2762 {
AzureIoTClient 0:1f9b2707ec7d 2763 dest->type = EDM_NO_TYPE;
AzureIoTClient 0:1f9b2707ec7d 2764 }
AzureIoTClient 0:1f9b2707ec7d 2765 }
AzureIoTClient 0:1f9b2707ec7d 2766
AzureIoTClient 0:1f9b2707ec7d 2767 return result;
AzureIoTClient 0:1f9b2707ec7d 2768 }
AzureIoTClient 0:1f9b2707ec7d 2769
AzureIoTClient 0:1f9b2707ec7d 2770 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_MemberPointers(AGENT_DATA_TYPE* agentData, const char* typeName, size_t nMembers, const char* const * memberNames, const AGENT_DATA_TYPE** memberPointerValues)
AzureIoTClient 0:1f9b2707ec7d 2771 {
AzureIoTClient 0:1f9b2707ec7d 2772 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 2773
AzureIoTClient 0:1f9b2707ec7d 2774 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_109:[ AGENT_DATA_TYPES_INVALID_ARG shall be returned if memberPointerValues parameter is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 2775 if (memberPointerValues == NULL)
AzureIoTClient 0:1f9b2707ec7d 2776 {
AzureIoTClient 0:1f9b2707ec7d 2777 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2778 LogError("(result: AGENT_DATA_TYPES_INVALID_ARG)");
AzureIoTClient 0:1f9b2707ec7d 2779 }
AzureIoTClient 0:1f9b2707ec7d 2780 else
AzureIoTClient 0:1f9b2707ec7d 2781 {
AzureIoTClient 0:1f9b2707ec7d 2782 AGENT_DATA_TYPE* values = (AGENT_DATA_TYPE*)malloc(nMembers* sizeof(AGENT_DATA_TYPE));
AzureIoTClient 0:1f9b2707ec7d 2783 if (values == NULL)
AzureIoTClient 0:1f9b2707ec7d 2784 {
AzureIoTClient 0:1f9b2707ec7d 2785 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2786 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2787 }
AzureIoTClient 0:1f9b2707ec7d 2788 else
AzureIoTClient 0:1f9b2707ec7d 2789 {
AzureIoTClient 0:1f9b2707ec7d 2790 size_t i;
AzureIoTClient 0:1f9b2707ec7d 2791 for (i = 0; i < nMembers; i++)
AzureIoTClient 0:1f9b2707ec7d 2792 {
AzureIoTClient 0:1f9b2707ec7d 2793 if (Create_AGENT_DATA_TYPE_from_AGENT_DATA_TYPE(values + i, memberPointerValues[i]) != AGENT_DATA_TYPES_OK)
AzureIoTClient 0:1f9b2707ec7d 2794 {
AzureIoTClient 0:1f9b2707ec7d 2795 size_t j;
AzureIoTClient 0:1f9b2707ec7d 2796 for (j = 0; j < i; j++)
AzureIoTClient 0:1f9b2707ec7d 2797 {
AzureIoTClient 0:1f9b2707ec7d 2798 Destroy_AGENT_DATA_TYPE(values + j);
AzureIoTClient 0:1f9b2707ec7d 2799 }
AzureIoTClient 0:1f9b2707ec7d 2800 break;
AzureIoTClient 0:1f9b2707ec7d 2801 }
AzureIoTClient 0:1f9b2707ec7d 2802 }
AzureIoTClient 0:1f9b2707ec7d 2803
AzureIoTClient 0:1f9b2707ec7d 2804 if (i != nMembers)
AzureIoTClient 0:1f9b2707ec7d 2805 {
AzureIoTClient 0:1f9b2707ec7d 2806 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2807 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2808 }
AzureIoTClient 0:1f9b2707ec7d 2809 else
AzureIoTClient 0:1f9b2707ec7d 2810 {
AzureIoTClient 0:1f9b2707ec7d 2811 /* SRS_AGENT_TYPE_SYSTEM_99_111:[ AGENT_DATA_TYPES_OK shall be returned upon success.] */
AzureIoTClient 0:1f9b2707ec7d 2812 result = Create_AGENT_DATA_TYPE_from_Members(agentData, typeName, nMembers, memberNames, values);
AzureIoTClient 0:1f9b2707ec7d 2813 if (result != AGENT_DATA_TYPES_OK)
AzureIoTClient 0:1f9b2707ec7d 2814 {
AzureIoTClient 11:b1327861f5e0 2815 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2816 }
AzureIoTClient 0:1f9b2707ec7d 2817 for (i = 0; i < nMembers; i++)
AzureIoTClient 0:1f9b2707ec7d 2818 {
AzureIoTClient 0:1f9b2707ec7d 2819 Destroy_AGENT_DATA_TYPE(&values[i]);
AzureIoTClient 0:1f9b2707ec7d 2820 }
AzureIoTClient 0:1f9b2707ec7d 2821 }
AzureIoTClient 0:1f9b2707ec7d 2822 free(values);
AzureIoTClient 0:1f9b2707ec7d 2823 }
AzureIoTClient 0:1f9b2707ec7d 2824 }
AzureIoTClient 0:1f9b2707ec7d 2825 return result;
AzureIoTClient 0:1f9b2707ec7d 2826 }
AzureIoTClient 0:1f9b2707ec7d 2827
AzureIoTClient 0:1f9b2707ec7d 2828 AGENT_DATA_TYPES_RESULT Create_AGENT_DATA_TYPE_from_Members(AGENT_DATA_TYPE* agentData, const char* typeName, size_t nMembers, const char* const * memberNames, const AGENT_DATA_TYPE* memberValues)
AzureIoTClient 0:1f9b2707ec7d 2829 {
AzureIoTClient 0:1f9b2707ec7d 2830 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 2831 size_t i;
AzureIoTClient 0:1f9b2707ec7d 2832 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_013:[ All the functions shall check their parameters for validity. When an invalid parameter is detected, the value AGENT_DATA_TYPES_INVALID_ARG shall be returned ]*/
AzureIoTClient 0:1f9b2707ec7d 2833 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 2834 {
AzureIoTClient 0:1f9b2707ec7d 2835 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2836 LogError("(result: AGENT_DATA_TYPES_INVALID_ARG)");
AzureIoTClient 0:1f9b2707ec7d 2837 }
AzureIoTClient 0:1f9b2707ec7d 2838 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_055:[ If typeName is NULL, the function shall return AGENT_DATA_TYPES_INVALID_ARG .]*/
AzureIoTClient 0:1f9b2707ec7d 2839 else if (typeName==NULL)
AzureIoTClient 0:1f9b2707ec7d 2840 {
AzureIoTClient 0:1f9b2707ec7d 2841 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2842 LogError("(result: AGENT_DATA_TYPES_INVALID_ARG)");
AzureIoTClient 0:1f9b2707ec7d 2843 }
AzureIoTClient 0:1f9b2707ec7d 2844 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_056:[If nMembers is 0, the function shall return AGENT_DATA_TYPES_INVALID_ARG .]*/
AzureIoTClient 0:1f9b2707ec7d 2845 else if (nMembers == 0)
AzureIoTClient 0:1f9b2707ec7d 2846 {
AzureIoTClient 0:1f9b2707ec7d 2847 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2848 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2849 }
AzureIoTClient 0:1f9b2707ec7d 2850 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_057:[ If memberNames is NULL, the function shall return AGENT_DATA_TYPES_INVALID_ARG .]*/
AzureIoTClient 0:1f9b2707ec7d 2851 else if (memberNames == NULL)
AzureIoTClient 0:1f9b2707ec7d 2852 {
AzureIoTClient 0:1f9b2707ec7d 2853 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2854 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2855 }
AzureIoTClient 0:1f9b2707ec7d 2856 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_058:[ If any of the memberNames[i] is NULL, the function shall return AGENT_DATA_TYPES_INVALID_ARG .]*/
AzureIoTClient 0:1f9b2707ec7d 2857 else if (isOneNameNULL(nMembers, memberNames)!=0)
AzureIoTClient 0:1f9b2707ec7d 2858 {
AzureIoTClient 0:1f9b2707ec7d 2859 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2860 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2861 }
AzureIoTClient 0:1f9b2707ec7d 2862 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_059:[ If memberValues is NULL, the function shall return AGENT_DATA_TYPES_INVALID_ARG .]*/
AzureIoTClient 0:1f9b2707ec7d 2863 else if (memberValues == NULL)
AzureIoTClient 0:1f9b2707ec7d 2864 {
AzureIoTClient 0:1f9b2707ec7d 2865 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2866 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2867 }
AzureIoTClient 0:1f9b2707ec7d 2868 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_063:[ If there are two memberNames with the same name, then the function shall return AGENT_DATA_TYPES_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 2869 else if (areThereTwoSameNames(nMembers, memberNames) != 0)
AzureIoTClient 0:1f9b2707ec7d 2870 {
AzureIoTClient 0:1f9b2707ec7d 2871 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 2872 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2873 }
AzureIoTClient 0:1f9b2707ec7d 2874 else
AzureIoTClient 0:1f9b2707ec7d 2875 {
AzureIoTClient 0:1f9b2707ec7d 2876 agentData->value.edmComplexType.nMembers = nMembers;
AzureIoTClient 0:1f9b2707ec7d 2877 agentData->value.edmComplexType.fields = (COMPLEX_TYPE_FIELD_TYPE*)malloc(nMembers *sizeof(COMPLEX_TYPE_FIELD_TYPE));
AzureIoTClient 0:1f9b2707ec7d 2878 if (agentData->value.edmComplexType.fields == NULL)
AzureIoTClient 0:1f9b2707ec7d 2879 {
AzureIoTClient 0:1f9b2707ec7d 2880 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2881 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2882 }
AzureIoTClient 0:1f9b2707ec7d 2883 else
AzureIoTClient 0:1f9b2707ec7d 2884 {
AzureIoTClient 0:1f9b2707ec7d 2885 result = AGENT_DATA_TYPES_OK; /*not liking this, solution might be to use a temp variable*/
AzureIoTClient 0:1f9b2707ec7d 2886
AzureIoTClient 0:1f9b2707ec7d 2887 /*initialize the fields*/
AzureIoTClient 0:1f9b2707ec7d 2888 for (i = 0; i < nMembers; i++)
AzureIoTClient 0:1f9b2707ec7d 2889 {
AzureIoTClient 0:1f9b2707ec7d 2890 agentData->value.edmComplexType.fields[i].fieldName = NULL;
AzureIoTClient 0:1f9b2707ec7d 2891 agentData->value.edmComplexType.fields[i].value = NULL;
AzureIoTClient 0:1f9b2707ec7d 2892 }
AzureIoTClient 0:1f9b2707ec7d 2893
AzureIoTClient 0:1f9b2707ec7d 2894 for (i = 0; i < nMembers; i++)
AzureIoTClient 0:1f9b2707ec7d 2895 {
AzureIoTClient 0:1f9b2707ec7d 2896 /*copy the name*/
AzureIoTClient 0:1f9b2707ec7d 2897 if (mallocAndStrcpy_s((char**)(&(agentData->value.edmComplexType.fields[i].fieldName)), memberNames[i]) != 0)
AzureIoTClient 0:1f9b2707ec7d 2898 {
AzureIoTClient 0:1f9b2707ec7d 2899 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2900 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2901 break;
AzureIoTClient 0:1f9b2707ec7d 2902 }
AzureIoTClient 0:1f9b2707ec7d 2903 else
AzureIoTClient 0:1f9b2707ec7d 2904 {
AzureIoTClient 0:1f9b2707ec7d 2905 /*field name was transferred successfully*/
AzureIoTClient 0:1f9b2707ec7d 2906 /*copy the rest*/
AzureIoTClient 0:1f9b2707ec7d 2907 agentData->value.edmComplexType.fields[i].value = (AGENT_DATA_TYPE*)malloc(sizeof(AGENT_DATA_TYPE));
AzureIoTClient 0:1f9b2707ec7d 2908 if (agentData->value.edmComplexType.fields[i].value == NULL)
AzureIoTClient 0:1f9b2707ec7d 2909 {
AzureIoTClient 0:1f9b2707ec7d 2910 /*deallocate the name*/
AzureIoTClient 0:1f9b2707ec7d 2911 free((void*)(agentData->value.edmComplexType.fields[i].fieldName));
AzureIoTClient 0:1f9b2707ec7d 2912 agentData->value.edmComplexType.fields[i].fieldName = NULL;
AzureIoTClient 0:1f9b2707ec7d 2913 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2914 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2915 break;
AzureIoTClient 0:1f9b2707ec7d 2916 }
AzureIoTClient 0:1f9b2707ec7d 2917 else
AzureIoTClient 0:1f9b2707ec7d 2918 {
AzureIoTClient 0:1f9b2707ec7d 2919 /*copy the values*/
AzureIoTClient 0:1f9b2707ec7d 2920 if (Create_AGENT_DATA_TYPE_from_AGENT_DATA_TYPE(agentData->value.edmComplexType.fields[i].value, &(memberValues[i])) != AGENT_DATA_TYPES_OK)
AzureIoTClient 0:1f9b2707ec7d 2921 {
AzureIoTClient 0:1f9b2707ec7d 2922 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 2923 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 2924 break;
AzureIoTClient 0:1f9b2707ec7d 2925 }
AzureIoTClient 0:1f9b2707ec7d 2926 else
AzureIoTClient 0:1f9b2707ec7d 2927 {
AzureIoTClient 0:1f9b2707ec7d 2928 /*all is fine*/
AzureIoTClient 0:1f9b2707ec7d 2929 }
AzureIoTClient 0:1f9b2707ec7d 2930 }
AzureIoTClient 0:1f9b2707ec7d 2931 }
AzureIoTClient 0:1f9b2707ec7d 2932
AzureIoTClient 0:1f9b2707ec7d 2933 }
AzureIoTClient 0:1f9b2707ec7d 2934 }
AzureIoTClient 0:1f9b2707ec7d 2935
AzureIoTClient 0:1f9b2707ec7d 2936 if (result != AGENT_DATA_TYPES_OK)
AzureIoTClient 0:1f9b2707ec7d 2937 {
AzureIoTClient 0:1f9b2707ec7d 2938 /*dealloc, something went bad*/
AzureIoTClient 0:1f9b2707ec7d 2939 DestroyHalfBakedComplexType(agentData);
AzureIoTClient 0:1f9b2707ec7d 2940 }
AzureIoTClient 0:1f9b2707ec7d 2941 else
AzureIoTClient 0:1f9b2707ec7d 2942 {
AzureIoTClient 0:1f9b2707ec7d 2943 agentData->type = EDM_COMPLEX_TYPE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 2944 }
AzureIoTClient 0:1f9b2707ec7d 2945 }
AzureIoTClient 0:1f9b2707ec7d 2946 return result;
AzureIoTClient 0:1f9b2707ec7d 2947 }
AzureIoTClient 0:1f9b2707ec7d 2948
AzureIoTClient 0:1f9b2707ec7d 2949 #define isLeapYear(y) ((((y) % 400) == 0) || (((y)%4==0)&&(!((y)%100==0))))
AzureIoTClient 0:1f9b2707ec7d 2950
AzureIoTClient 16:ef107f3f230c 2951 static int daysInAllPreviousMonths(int month)
AzureIoTClient 16:ef107f3f230c 2952 {
AzureIoTClient 16:ef107f3f230c 2953 int result = 0;
AzureIoTClient 16:ef107f3f230c 2954 for (int i = 0; i < month; i++)
AzureIoTClient 16:ef107f3f230c 2955 {
AzureIoTClient 16:ef107f3f230c 2956 switch (i)
AzureIoTClient 16:ef107f3f230c 2957 {
AzureIoTClient 16:ef107f3f230c 2958 case 0:
AzureIoTClient 16:ef107f3f230c 2959 case 2:
AzureIoTClient 16:ef107f3f230c 2960 case 4:
AzureIoTClient 16:ef107f3f230c 2961 case 6:
AzureIoTClient 16:ef107f3f230c 2962 case 7:
AzureIoTClient 16:ef107f3f230c 2963 case 9:
AzureIoTClient 16:ef107f3f230c 2964 result += 31;
AzureIoTClient 16:ef107f3f230c 2965 break;
AzureIoTClient 16:ef107f3f230c 2966 case 1:
AzureIoTClient 16:ef107f3f230c 2967 result += 28;
AzureIoTClient 16:ef107f3f230c 2968 break;
AzureIoTClient 16:ef107f3f230c 2969 default:
AzureIoTClient 16:ef107f3f230c 2970 result += 30;
AzureIoTClient 16:ef107f3f230c 2971 }
AzureIoTClient 16:ef107f3f230c 2972 }
AzureIoTClient 16:ef107f3f230c 2973 return result;
AzureIoTClient 16:ef107f3f230c 2974 }
AzureIoTClient 0:1f9b2707ec7d 2975
AzureIoTClient 0:1f9b2707ec7d 2976 /*this function assumes a correctly filled in tm_year, tm_mon and tm_mday and will fill in tm_yday and tm_wday*/
AzureIoTClient 0:1f9b2707ec7d 2977 static void fill_tm_yday_and_tm_wday(struct tm* source)
AzureIoTClient 0:1f9b2707ec7d 2978 {
AzureIoTClient 0:1f9b2707ec7d 2979 /*to fill in tm_yday the function shall add the number of days in every month, not including the current one*/
AzureIoTClient 0:1f9b2707ec7d 2980 /*and then it will add the number of days in the current month*/
AzureIoTClient 0:1f9b2707ec7d 2981 /*1st of Jan is day "0" in a year*/
AzureIoTClient 0:1f9b2707ec7d 2982 int year = source->tm_year + 1900 + 10000;
AzureIoTClient 0:1f9b2707ec7d 2983 int nLeapYearsSinceYearMinus9999 = ((year - 1) / 4) - ((year - 1) / 100) + ((year - 1) / 400);
AzureIoTClient 16:ef107f3f230c 2984 source->tm_yday = (daysInAllPreviousMonths(source->tm_mon)) + (source->tm_mday - 1) + ((source->tm_mon > 1 /*1 is Feb*/) && isLeapYear(year));
AzureIoTClient 0:1f9b2707ec7d 2985 source->tm_wday = ((365 * year + nLeapYearsSinceYearMinus9999) + source->tm_yday) % 7;
AzureIoTClient 0:1f9b2707ec7d 2986 /*day "0" is 1st jan -9999 (this is how much odata can span*/
AzureIoTClient 0:1f9b2707ec7d 2987 /*the function shall count days */
AzureIoTClient 0:1f9b2707ec7d 2988 }
AzureIoTClient 0:1f9b2707ec7d 2989
Azure.IoT Build 9:747680124ff7 2990 /*the following function does the same as sscanf(pos2, ":%02d", &sec)*/
Azure.IoT Build 9:747680124ff7 2991 /*this function only exists because of optimizing valgrind time, otherwise sscanf would be just as good*/
Azure.IoT Build 9:747680124ff7 2992 static int sscanf2d(const char *pos2, int* sec)
Azure.IoT Build 9:747680124ff7 2993 {
Azure.IoT Build 9:747680124ff7 2994 int result;
Azure.IoT Build 9:747680124ff7 2995 size_t position = 1;
Azure.IoT Build 9:747680124ff7 2996 if (
Azure.IoT Build 9:747680124ff7 2997 (pos2[0] == ':') &&
AzureIoTClient 14:0c00e67a4ab1 2998 (scanAndReadNDigitsInt(pos2, &position, sec, 2) == 0)
Azure.IoT Build 9:747680124ff7 2999 )
Azure.IoT Build 9:747680124ff7 3000 {
Azure.IoT Build 9:747680124ff7 3001 result = 1;
Azure.IoT Build 9:747680124ff7 3002 }
Azure.IoT Build 9:747680124ff7 3003 else
Azure.IoT Build 9:747680124ff7 3004 {
AzureIoTClient 14:0c00e67a4ab1 3005 result = EOF;
Azure.IoT Build 9:747680124ff7 3006 }
Azure.IoT Build 9:747680124ff7 3007
Azure.IoT Build 9:747680124ff7 3008 return result;
Azure.IoT Build 9:747680124ff7 3009
Azure.IoT Build 9:747680124ff7 3010 }
Azure.IoT Build 9:747680124ff7 3011
AzureIoTClient 14:0c00e67a4ab1 3012 /*the following function does the same as sscanf(pos2, "%d", &sec)*/
AzureIoTClient 14:0c00e67a4ab1 3013 /*this function only exists because of optimizing valgrind time, otherwise sscanf would be just as good*/
AzureIoTClient 14:0c00e67a4ab1 3014 static int sscanfd(const char *src, int* dst)
AzureIoTClient 14:0c00e67a4ab1 3015 {
AzureIoTClient 14:0c00e67a4ab1 3016 char* next;
AzureIoTClient 14:0c00e67a4ab1 3017 (*dst) = strtol(src, &next, 10);
AzureIoTClient 14:0c00e67a4ab1 3018 if ((src == next) || ((((*dst) == LONG_MAX) || ((*dst) == LONG_MIN)) && (errno != 0)))
AzureIoTClient 14:0c00e67a4ab1 3019 {
AzureIoTClient 14:0c00e67a4ab1 3020 return EOF;
AzureIoTClient 14:0c00e67a4ab1 3021 }
AzureIoTClient 14:0c00e67a4ab1 3022 return 1;
AzureIoTClient 14:0c00e67a4ab1 3023 }
AzureIoTClient 14:0c00e67a4ab1 3024
AzureIoTClient 14:0c00e67a4ab1 3025 /*the following function does the same as sscanf(src, "%llu", &dst), but, it changes the src pointer.*/
AzureIoTClient 14:0c00e67a4ab1 3026 static int sscanfllu(const char** src, unsigned long long* dst)
AzureIoTClient 14:0c00e67a4ab1 3027 {
AzureIoTClient 14:0c00e67a4ab1 3028 int result = 1;
AzureIoTClient 14:0c00e67a4ab1 3029 char* next;
AzureIoTClient 14:0c00e67a4ab1 3030 (*dst) = strtoull((*src), &next, 10);
AzureIoTClient 14:0c00e67a4ab1 3031 if (((*src) == (const char*)next) || (((*dst) == ULLONG_MAX) && (errno != 0)))
AzureIoTClient 14:0c00e67a4ab1 3032 {
AzureIoTClient 14:0c00e67a4ab1 3033 result = EOF;
AzureIoTClient 14:0c00e67a4ab1 3034 }
AzureIoTClient 14:0c00e67a4ab1 3035 (*src) = (const char*)next;
AzureIoTClient 14:0c00e67a4ab1 3036 return result;
AzureIoTClient 14:0c00e67a4ab1 3037 }
AzureIoTClient 14:0c00e67a4ab1 3038
AzureIoTClient 14:0c00e67a4ab1 3039 /*the following function does the same as sscanf(src, ".%llu", &dst)*/
AzureIoTClient 14:0c00e67a4ab1 3040 static int sscanfdotllu(const char*src, unsigned long long* dst)
Azure.IoT Build 9:747680124ff7 3041 {
Azure.IoT Build 9:747680124ff7 3042 int result;
Azure.IoT Build 9:747680124ff7 3043
AzureIoTClient 14:0c00e67a4ab1 3044 if ((*src) != '.')
Azure.IoT Build 9:747680124ff7 3045 {
Azure.IoT Build 9:747680124ff7 3046 /*doesn't start with '.' error out*/
AzureIoTClient 14:0c00e67a4ab1 3047 result = EOF;
Azure.IoT Build 9:747680124ff7 3048 }
Azure.IoT Build 9:747680124ff7 3049 else
Azure.IoT Build 9:747680124ff7 3050 {
AzureIoTClient 14:0c00e67a4ab1 3051 src++;
AzureIoTClient 14:0c00e67a4ab1 3052 result = sscanfllu(&src, dst);
AzureIoTClient 14:0c00e67a4ab1 3053 }
AzureIoTClient 14:0c00e67a4ab1 3054
AzureIoTClient 14:0c00e67a4ab1 3055 return result;
AzureIoTClient 14:0c00e67a4ab1 3056 }
Azure.IoT Build 9:747680124ff7 3057
AzureIoTClient 14:0c00e67a4ab1 3058 /*the following function does the same as sscanf(src, "%u", &dst)*/
AzureIoTClient 14:0c00e67a4ab1 3059 static int sscanfu(const char*src, unsigned int* dst)
AzureIoTClient 14:0c00e67a4ab1 3060 {
AzureIoTClient 14:0c00e67a4ab1 3061 char* next;
AzureIoTClient 14:0c00e67a4ab1 3062 (*dst) = strtoul(src, &next, 10);
AzureIoTClient 14:0c00e67a4ab1 3063 int error = errno;
AzureIoTClient 14:0c00e67a4ab1 3064 if ((src == next) || (((*dst) == ULONG_MAX) && (error != 0)))
AzureIoTClient 14:0c00e67a4ab1 3065 {
AzureIoTClient 14:0c00e67a4ab1 3066 return EOF;
AzureIoTClient 14:0c00e67a4ab1 3067 }
AzureIoTClient 14:0c00e67a4ab1 3068 return 1;
AzureIoTClient 14:0c00e67a4ab1 3069 }
AzureIoTClient 14:0c00e67a4ab1 3070
AzureIoTClient 14:0c00e67a4ab1 3071 /*the following function does the same as sscanf(src, "%f", &dst)*/
AzureIoTClient 14:0c00e67a4ab1 3072 static int sscanff(const char*src, float* dst)
AzureIoTClient 14:0c00e67a4ab1 3073 {
AzureIoTClient 14:0c00e67a4ab1 3074 int result = 1;
AzureIoTClient 14:0c00e67a4ab1 3075 char* next;
AzureIoTClient 14:0c00e67a4ab1 3076 (*dst) = strtof(src, &next);
AzureIoTClient 14:0c00e67a4ab1 3077 errno_t error = errno;
AzureIoTClient 14:0c00e67a4ab1 3078 if ((src == next) || (((*dst) == HUGE_VALF) && (error != 0)))
AzureIoTClient 14:0c00e67a4ab1 3079 {
AzureIoTClient 14:0c00e67a4ab1 3080 result = EOF;
Azure.IoT Build 9:747680124ff7 3081 }
Azure.IoT Build 9:747680124ff7 3082 return result;
Azure.IoT Build 9:747680124ff7 3083 }
Azure.IoT Build 9:747680124ff7 3084
AzureIoTClient 14:0c00e67a4ab1 3085 /*the following function does the same as sscanf(src, "%lf", &dst)*/
AzureIoTClient 14:0c00e67a4ab1 3086 static int sscanflf(const char*src, double* dst)
AzureIoTClient 14:0c00e67a4ab1 3087 {
AzureIoTClient 14:0c00e67a4ab1 3088 int result = 1;
AzureIoTClient 14:0c00e67a4ab1 3089 char* next;
AzureIoTClient 14:0c00e67a4ab1 3090 (*dst) = strtod(src, &next);
AzureIoTClient 14:0c00e67a4ab1 3091 errno_t error = errno;
AzureIoTClient 14:0c00e67a4ab1 3092 if ((src == next) || (((*dst) == HUGE_VALL) && (error != 0)))
AzureIoTClient 14:0c00e67a4ab1 3093 {
AzureIoTClient 14:0c00e67a4ab1 3094 result = EOF;
AzureIoTClient 14:0c00e67a4ab1 3095 }
AzureIoTClient 14:0c00e67a4ab1 3096 return result;
AzureIoTClient 14:0c00e67a4ab1 3097 }
AzureIoTClient 14:0c00e67a4ab1 3098
AzureIoTClient 14:0c00e67a4ab1 3099
AzureIoTClient 14:0c00e67a4ab1 3100 /*the below function replaces sscanf(src, "%03d:%02d\"", &hourOffset, &minOffset)*/
Azure.IoT Build 9:747680124ff7 3101 /*return 2 if success*/
Azure.IoT Build 9:747680124ff7 3102
AzureIoTClient 14:0c00e67a4ab1 3103 static int sscanf3d2d(const char* src, int* hourOffset, int* minOffset)
Azure.IoT Build 9:747680124ff7 3104 {
Azure.IoT Build 9:747680124ff7 3105 size_t position = 0;
AzureIoTClient 14:0c00e67a4ab1 3106 int result = EOF;
AzureIoTClient 14:0c00e67a4ab1 3107 bool isNegative = false;
AzureIoTClient 14:0c00e67a4ab1 3108
AzureIoTClient 14:0c00e67a4ab1 3109 if (*src == '+')
AzureIoTClient 14:0c00e67a4ab1 3110 {
AzureIoTClient 14:0c00e67a4ab1 3111 position++;
AzureIoTClient 14:0c00e67a4ab1 3112 }
AzureIoTClient 14:0c00e67a4ab1 3113 else if (*src == '-')
AzureIoTClient 14:0c00e67a4ab1 3114 {
AzureIoTClient 14:0c00e67a4ab1 3115 isNegative = true;
AzureIoTClient 14:0c00e67a4ab1 3116 position++;
AzureIoTClient 14:0c00e67a4ab1 3117 }
AzureIoTClient 14:0c00e67a4ab1 3118
Azure.IoT Build 9:747680124ff7 3119 if (
AzureIoTClient 14:0c00e67a4ab1 3120 (scanAndReadNDigitsInt(src, &position, hourOffset, (3-position)) == 0) &&
AzureIoTClient 15:370c47516bd4 3121 (src[position++] == ':') &&
AzureIoTClient 14:0c00e67a4ab1 3122 (scanAndReadNDigitsInt(src, &position, minOffset, 2) == 0)
Azure.IoT Build 9:747680124ff7 3123 )
Azure.IoT Build 9:747680124ff7 3124 {
Azure.IoT Build 9:747680124ff7 3125 result = 2;
Azure.IoT Build 9:747680124ff7 3126 }
Azure.IoT Build 9:747680124ff7 3127 else
Azure.IoT Build 9:747680124ff7 3128 {
Azure.IoT Build 9:747680124ff7 3129 result = 0;
Azure.IoT Build 9:747680124ff7 3130 }
AzureIoTClient 14:0c00e67a4ab1 3131 if (isNegative)
AzureIoTClient 14:0c00e67a4ab1 3132 *hourOffset *= -1;
AzureIoTClient 14:0c00e67a4ab1 3133
Azure.IoT Build 9:747680124ff7 3134 return result;
Azure.IoT Build 9:747680124ff7 3135 }
Azure.IoT Build 9:747680124ff7 3136
AzureIoTClient 0:1f9b2707ec7d 3137 AGENT_DATA_TYPES_RESULT CreateAgentDataType_From_String(const char* source, AGENT_DATA_TYPE_TYPE type, AGENT_DATA_TYPE* agentData)
AzureIoTClient 0:1f9b2707ec7d 3138 {
AzureIoTClient 0:1f9b2707ec7d 3139
AzureIoTClient 0:1f9b2707ec7d 3140 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 3141
AzureIoTClient 0:1f9b2707ec7d 3142 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_073:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 3143 if ((source == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 3144 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_074:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if agentData is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 3145 (agentData == NULL))
AzureIoTClient 0:1f9b2707ec7d 3146 {
AzureIoTClient 0:1f9b2707ec7d 3147 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3148 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3149 }
AzureIoTClient 0:1f9b2707ec7d 3150 else
AzureIoTClient 0:1f9b2707ec7d 3151 {
AzureIoTClient 0:1f9b2707ec7d 3152 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_071:[ CreateAgentDataType_From_String shall create an AGENT_DATA_TYPE from a char* representation of the type indicated by type parameter.] */
AzureIoTClient 0:1f9b2707ec7d 3153 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_072:[ The implementation for the transformation of the char* source into AGENT_DATA_TYPE shall be type specific.] */
AzureIoTClient 0:1f9b2707ec7d 3154 switch (type)
AzureIoTClient 0:1f9b2707ec7d 3155 {
AzureIoTClient 0:1f9b2707ec7d 3156 default:
AzureIoTClient 0:1f9b2707ec7d 3157 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_075:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_NOT_IMPLEMENTED if type is not a supported type.] */
AzureIoTClient 0:1f9b2707ec7d 3158 result = AGENT_DATA_TYPES_NOT_IMPLEMENTED;
AzureIoTClient 11:b1327861f5e0 3159 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3160 break;
AzureIoTClient 0:1f9b2707ec7d 3161
AzureIoTClient 0:1f9b2707ec7d 3162 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_086:[ EDM_STRING] */
AzureIoTClient 0:1f9b2707ec7d 3163 case EDM_BOOLEAN_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3164 {
AzureIoTClient 0:1f9b2707ec7d 3165 if (strcmp(source, "true") == 0)
AzureIoTClient 0:1f9b2707ec7d 3166 {
AzureIoTClient 0:1f9b2707ec7d 3167 agentData->type = EDM_BOOLEAN_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3168 agentData->value.edmBoolean.value = EDM_TRUE;
AzureIoTClient 0:1f9b2707ec7d 3169 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3170 }
AzureIoTClient 0:1f9b2707ec7d 3171 else if (strcmp(source, "false") == 0)
AzureIoTClient 0:1f9b2707ec7d 3172 {
AzureIoTClient 0:1f9b2707ec7d 3173 agentData->type = EDM_BOOLEAN_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3174 agentData->value.edmBoolean.value = EDM_FALSE;
AzureIoTClient 0:1f9b2707ec7d 3175 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3176 }
AzureIoTClient 0:1f9b2707ec7d 3177 else
AzureIoTClient 0:1f9b2707ec7d 3178 {
AzureIoTClient 0:1f9b2707ec7d 3179 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3180 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3181 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3182 }
AzureIoTClient 0:1f9b2707ec7d 3183
AzureIoTClient 0:1f9b2707ec7d 3184 break;
AzureIoTClient 0:1f9b2707ec7d 3185 }
AzureIoTClient 0:1f9b2707ec7d 3186 case EDM_NULL_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3187 {
AzureIoTClient 0:1f9b2707ec7d 3188 if (strcmp(source, "null") == 0)
AzureIoTClient 0:1f9b2707ec7d 3189 {
AzureIoTClient 0:1f9b2707ec7d 3190 agentData->type = EDM_NULL_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3191 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3192 }
AzureIoTClient 0:1f9b2707ec7d 3193 else
AzureIoTClient 0:1f9b2707ec7d 3194 {
AzureIoTClient 0:1f9b2707ec7d 3195 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3196 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3197 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3198 }
AzureIoTClient 0:1f9b2707ec7d 3199
AzureIoTClient 0:1f9b2707ec7d 3200 break;
AzureIoTClient 0:1f9b2707ec7d 3201 }
AzureIoTClient 0:1f9b2707ec7d 3202
AzureIoTClient 0:1f9b2707ec7d 3203 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_084:[ EDM_SBYTE] */
AzureIoTClient 0:1f9b2707ec7d 3204 case EDM_SBYTE_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3205 {
AzureIoTClient 0:1f9b2707ec7d 3206 int sByteValue;
AzureIoTClient 14:0c00e67a4ab1 3207 if ((sscanfd(source, &sByteValue) != 1) ||
AzureIoTClient 0:1f9b2707ec7d 3208 (sByteValue < -128) ||
AzureIoTClient 0:1f9b2707ec7d 3209 (sByteValue > 127))
AzureIoTClient 0:1f9b2707ec7d 3210 {
AzureIoTClient 0:1f9b2707ec7d 3211 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3212 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3213 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3214 }
AzureIoTClient 0:1f9b2707ec7d 3215 else
AzureIoTClient 0:1f9b2707ec7d 3216 {
AzureIoTClient 0:1f9b2707ec7d 3217 agentData->type = EDM_SBYTE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3218 agentData->value.edmSbyte.value = (int8_t)sByteValue;
AzureIoTClient 0:1f9b2707ec7d 3219 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3220 }
AzureIoTClient 0:1f9b2707ec7d 3221
AzureIoTClient 0:1f9b2707ec7d 3222 break;
AzureIoTClient 0:1f9b2707ec7d 3223 }
AzureIoTClient 0:1f9b2707ec7d 3224
AzureIoTClient 0:1f9b2707ec7d 3225 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_077:[ EDM_BYTE] */
AzureIoTClient 0:1f9b2707ec7d 3226 case EDM_BYTE_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3227 {
AzureIoTClient 0:1f9b2707ec7d 3228 int byteValue;
AzureIoTClient 14:0c00e67a4ab1 3229 if ((sscanfd(source, &byteValue) != 1) ||
AzureIoTClient 0:1f9b2707ec7d 3230 (byteValue < 0) ||
AzureIoTClient 0:1f9b2707ec7d 3231 (byteValue > 255))
AzureIoTClient 0:1f9b2707ec7d 3232 {
AzureIoTClient 0:1f9b2707ec7d 3233 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3234 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3235 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3236 }
AzureIoTClient 0:1f9b2707ec7d 3237 else
AzureIoTClient 0:1f9b2707ec7d 3238 {
AzureIoTClient 0:1f9b2707ec7d 3239 agentData->type = EDM_BYTE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3240 agentData->value.edmByte.value = (uint8_t)byteValue;
AzureIoTClient 0:1f9b2707ec7d 3241 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3242 }
AzureIoTClient 0:1f9b2707ec7d 3243
AzureIoTClient 0:1f9b2707ec7d 3244 break;
AzureIoTClient 0:1f9b2707ec7d 3245 }
AzureIoTClient 0:1f9b2707ec7d 3246
AzureIoTClient 0:1f9b2707ec7d 3247 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_081:[ EDM_INT16] */
AzureIoTClient 0:1f9b2707ec7d 3248 case EDM_INT16_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3249 {
AzureIoTClient 0:1f9b2707ec7d 3250 int int16Value;
AzureIoTClient 14:0c00e67a4ab1 3251 if ((sscanfd(source, &int16Value) != 1) ||
AzureIoTClient 0:1f9b2707ec7d 3252 (int16Value < -32768) ||
AzureIoTClient 0:1f9b2707ec7d 3253 (int16Value > 32767))
AzureIoTClient 0:1f9b2707ec7d 3254 {
AzureIoTClient 0:1f9b2707ec7d 3255 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3256 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3257 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3258 }
AzureIoTClient 0:1f9b2707ec7d 3259 else
AzureIoTClient 0:1f9b2707ec7d 3260 {
AzureIoTClient 0:1f9b2707ec7d 3261 agentData->type = EDM_INT16_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3262 agentData->value.edmInt16.value = (int16_t)int16Value;
AzureIoTClient 0:1f9b2707ec7d 3263 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3264 }
AzureIoTClient 0:1f9b2707ec7d 3265
AzureIoTClient 0:1f9b2707ec7d 3266 break;
AzureIoTClient 0:1f9b2707ec7d 3267 }
AzureIoTClient 0:1f9b2707ec7d 3268
AzureIoTClient 0:1f9b2707ec7d 3269 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_082:[ EDM_INT32] */
AzureIoTClient 0:1f9b2707ec7d 3270 case EDM_INT32_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3271 {
Azure.IoT Build 8:380e6e830589 3272 int32_t int32Value;
Azure.IoT Build 8:380e6e830589 3273 unsigned char isNegative;
Azure.IoT Build 8:380e6e830589 3274 uint32_t uint32Value;
Azure.IoT Build 8:380e6e830589 3275 const char* pos;
Azure.IoT Build 8:380e6e830589 3276 size_t strLength;
Azure.IoT Build 8:380e6e830589 3277
Azure.IoT Build 8:380e6e830589 3278 if (source[0] == '-')
Azure.IoT Build 8:380e6e830589 3279 {
Azure.IoT Build 8:380e6e830589 3280 isNegative = 1;
Azure.IoT Build 8:380e6e830589 3281 pos = &source[1];
Azure.IoT Build 8:380e6e830589 3282 }
Azure.IoT Build 8:380e6e830589 3283 else
Azure.IoT Build 8:380e6e830589 3284 {
Azure.IoT Build 8:380e6e830589 3285 isNegative = 0;
Azure.IoT Build 8:380e6e830589 3286 pos = &source[0];
Azure.IoT Build 8:380e6e830589 3287 }
Azure.IoT Build 8:380e6e830589 3288
Azure.IoT Build 8:380e6e830589 3289 strLength = strlen(source);
Azure.IoT Build 8:380e6e830589 3290
AzureIoTClient 14:0c00e67a4ab1 3291 if ((sscanfu(pos, &uint32Value) != 1) ||
Azure.IoT Build 8:380e6e830589 3292 (strLength > 11) ||
Azure.IoT Build 8:380e6e830589 3293 ((uint32Value > 2147483648UL) && isNegative) ||
Azure.IoT Build 8:380e6e830589 3294 ((uint32Value > 2147483647UL) && (!isNegative)))
AzureIoTClient 0:1f9b2707ec7d 3295 {
AzureIoTClient 0:1f9b2707ec7d 3296 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3297 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3298 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3299 }
AzureIoTClient 0:1f9b2707ec7d 3300 else
AzureIoTClient 0:1f9b2707ec7d 3301 {
Azure.IoT Build 8:380e6e830589 3302 if (isNegative)
Azure.IoT Build 8:380e6e830589 3303 {
Azure.IoT Build 8:380e6e830589 3304 if (uint32Value == 2147483648UL)
Azure.IoT Build 8:380e6e830589 3305 {
Azure.IoT Build 8:380e6e830589 3306 int32Value = -2147483647L - 1L;
Azure.IoT Build 8:380e6e830589 3307 }
Azure.IoT Build 8:380e6e830589 3308 else
Azure.IoT Build 8:380e6e830589 3309 {
Azure.IoT Build 8:380e6e830589 3310 int32Value = -(int32_t)uint32Value;
Azure.IoT Build 8:380e6e830589 3311 }
Azure.IoT Build 8:380e6e830589 3312 }
Azure.IoT Build 8:380e6e830589 3313 else
Azure.IoT Build 8:380e6e830589 3314 {
Azure.IoT Build 8:380e6e830589 3315 int32Value = uint32Value;
Azure.IoT Build 8:380e6e830589 3316 }
Azure.IoT Build 8:380e6e830589 3317
AzureIoTClient 0:1f9b2707ec7d 3318 agentData->type = EDM_INT32_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3319 agentData->value.edmInt32.value = (int32_t)int32Value;
AzureIoTClient 0:1f9b2707ec7d 3320 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3321 }
AzureIoTClient 0:1f9b2707ec7d 3322
AzureIoTClient 0:1f9b2707ec7d 3323 break;
AzureIoTClient 0:1f9b2707ec7d 3324 }
AzureIoTClient 0:1f9b2707ec7d 3325
AzureIoTClient 0:1f9b2707ec7d 3326 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_083:[ EDM_INT64] */
AzureIoTClient 0:1f9b2707ec7d 3327 case EDM_INT64_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3328 {
AzureIoTClient 0:1f9b2707ec7d 3329 long long int64Value;
AzureIoTClient 0:1f9b2707ec7d 3330 unsigned char isNegative;
AzureIoTClient 0:1f9b2707ec7d 3331 unsigned long long ullValue;
AzureIoTClient 0:1f9b2707ec7d 3332 const char* pos;
AzureIoTClient 0:1f9b2707ec7d 3333 size_t strLength;
AzureIoTClient 0:1f9b2707ec7d 3334
AzureIoTClient 0:1f9b2707ec7d 3335 if (source[0] == '-')
AzureIoTClient 0:1f9b2707ec7d 3336 {
AzureIoTClient 0:1f9b2707ec7d 3337 isNegative = 1;
AzureIoTClient 0:1f9b2707ec7d 3338 pos = &source[1];
AzureIoTClient 0:1f9b2707ec7d 3339 }
AzureIoTClient 0:1f9b2707ec7d 3340 else
AzureIoTClient 0:1f9b2707ec7d 3341 {
AzureIoTClient 0:1f9b2707ec7d 3342 isNegative = 0;
AzureIoTClient 0:1f9b2707ec7d 3343 pos = &source[0];
AzureIoTClient 0:1f9b2707ec7d 3344 }
AzureIoTClient 0:1f9b2707ec7d 3345
AzureIoTClient 0:1f9b2707ec7d 3346 strLength = strlen(source);
AzureIoTClient 0:1f9b2707ec7d 3347
AzureIoTClient 14:0c00e67a4ab1 3348 if ((sscanfllu(&pos, &ullValue) != 1) ||
AzureIoTClient 0:1f9b2707ec7d 3349 (strLength > 20) ||
AzureIoTClient 0:1f9b2707ec7d 3350 ((ullValue > 9223372036854775808ULL) && isNegative) ||
AzureIoTClient 0:1f9b2707ec7d 3351 ((ullValue > 9223372036854775807ULL) && (!isNegative)))
AzureIoTClient 0:1f9b2707ec7d 3352 {
AzureIoTClient 0:1f9b2707ec7d 3353 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3354 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3355 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3356 }
AzureIoTClient 0:1f9b2707ec7d 3357 else
AzureIoTClient 0:1f9b2707ec7d 3358 {
AzureIoTClient 0:1f9b2707ec7d 3359 if (isNegative)
AzureIoTClient 0:1f9b2707ec7d 3360 {
AzureIoTClient 0:1f9b2707ec7d 3361 if (ullValue == 9223372036854775808ULL)
AzureIoTClient 0:1f9b2707ec7d 3362 {
AzureIoTClient 0:1f9b2707ec7d 3363 int64Value = -9223372036854775807LL - 1LL;
AzureIoTClient 0:1f9b2707ec7d 3364 }
AzureIoTClient 0:1f9b2707ec7d 3365 else
AzureIoTClient 0:1f9b2707ec7d 3366 {
AzureIoTClient 0:1f9b2707ec7d 3367 int64Value = -(long long)ullValue;
AzureIoTClient 0:1f9b2707ec7d 3368 }
AzureIoTClient 0:1f9b2707ec7d 3369 }
AzureIoTClient 0:1f9b2707ec7d 3370 else
AzureIoTClient 0:1f9b2707ec7d 3371 {
AzureIoTClient 0:1f9b2707ec7d 3372 int64Value = ullValue;
AzureIoTClient 0:1f9b2707ec7d 3373 }
AzureIoTClient 0:1f9b2707ec7d 3374 agentData->type = EDM_INT64_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3375 agentData->value.edmInt64.value = (int64_t)int64Value;
AzureIoTClient 0:1f9b2707ec7d 3376 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3377 }
AzureIoTClient 0:1f9b2707ec7d 3378
AzureIoTClient 0:1f9b2707ec7d 3379 break;
AzureIoTClient 0:1f9b2707ec7d 3380 }
AzureIoTClient 0:1f9b2707ec7d 3381
AzureIoTClient 0:1f9b2707ec7d 3382 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_085:[ EDM_DATE] */
AzureIoTClient 0:1f9b2707ec7d 3383 case EDM_DATE_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3384 {
AzureIoTClient 0:1f9b2707ec7d 3385 int year;
AzureIoTClient 0:1f9b2707ec7d 3386 int month;
AzureIoTClient 0:1f9b2707ec7d 3387 int day;
AzureIoTClient 0:1f9b2707ec7d 3388 size_t strLength = strlen(source);
AzureIoTClient 0:1f9b2707ec7d 3389
AzureIoTClient 0:1f9b2707ec7d 3390 if ((strLength < 2) ||
AzureIoTClient 0:1f9b2707ec7d 3391 (source[0] != '"') ||
AzureIoTClient 14:0c00e67a4ab1 3392 (source[strLength - 1] != '"'))
AzureIoTClient 0:1f9b2707ec7d 3393 {
AzureIoTClient 0:1f9b2707ec7d 3394 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3395 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3396 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3397 }
AzureIoTClient 0:1f9b2707ec7d 3398 else
AzureIoTClient 0:1f9b2707ec7d 3399 {
AzureIoTClient 0:1f9b2707ec7d 3400 size_t pos = 1;
AzureIoTClient 0:1f9b2707ec7d 3401 int sign;
AzureIoTClient 0:1f9b2707ec7d 3402 scanOptionalMinusSign(source, 2, &pos, &sign);
AzureIoTClient 0:1f9b2707ec7d 3403
AzureIoTClient 14:0c00e67a4ab1 3404 if ((scanAndReadNDigitsInt(source, &pos, &year, 4) != 0) ||
AzureIoTClient 0:1f9b2707ec7d 3405 (source[pos++] != '-') ||
AzureIoTClient 14:0c00e67a4ab1 3406 (scanAndReadNDigitsInt(source, &pos, &month, 2) != 0) ||
AzureIoTClient 0:1f9b2707ec7d 3407 (source[pos++] != '-') ||
AzureIoTClient 14:0c00e67a4ab1 3408 (scanAndReadNDigitsInt(source, &pos, &day, 2) != 0) ||
AzureIoTClient 0:1f9b2707ec7d 3409 (Create_AGENT_DATA_TYPE_from_date(agentData, (int16_t)(sign*year), (uint8_t)month, (uint8_t)day) != AGENT_DATA_TYPES_OK))
AzureIoTClient 0:1f9b2707ec7d 3410 {
AzureIoTClient 0:1f9b2707ec7d 3411 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3412 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3413 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3414 }
AzureIoTClient 0:1f9b2707ec7d 3415 else
AzureIoTClient 0:1f9b2707ec7d 3416 {
AzureIoTClient 0:1f9b2707ec7d 3417 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3418 }
AzureIoTClient 0:1f9b2707ec7d 3419 }
AzureIoTClient 0:1f9b2707ec7d 3420
AzureIoTClient 0:1f9b2707ec7d 3421 break;
AzureIoTClient 0:1f9b2707ec7d 3422 }
AzureIoTClient 0:1f9b2707ec7d 3423
AzureIoTClient 0:1f9b2707ec7d 3424 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_078:[ EDM_DATETIMEOFFSET] */
AzureIoTClient 0:1f9b2707ec7d 3425 case EDM_DATE_TIME_OFFSET_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3426 {
AzureIoTClient 0:1f9b2707ec7d 3427 int year;
AzureIoTClient 0:1f9b2707ec7d 3428 int month;
AzureIoTClient 0:1f9b2707ec7d 3429 int day;
AzureIoTClient 0:1f9b2707ec7d 3430 int hour;
AzureIoTClient 0:1f9b2707ec7d 3431 int min;
AzureIoTClient 0:1f9b2707ec7d 3432 int sec = 0;
AzureIoTClient 0:1f9b2707ec7d 3433 int hourOffset;
AzureIoTClient 0:1f9b2707ec7d 3434 int minOffset;
AzureIoTClient 0:1f9b2707ec7d 3435 unsigned long long fractionalSeconds = 0;
AzureIoTClient 0:1f9b2707ec7d 3436 size_t strLength = strlen(source);
AzureIoTClient 0:1f9b2707ec7d 3437
AzureIoTClient 0:1f9b2707ec7d 3438 agentData->value.edmDateTimeOffset.hasFractionalSecond = 0;
AzureIoTClient 0:1f9b2707ec7d 3439 agentData->value.edmDateTimeOffset.hasTimeZone = 0;
AzureIoTClient 0:1f9b2707ec7d 3440 /* The value of tm_isdst is positive if Daylight Saving Time is in effect, zero if Daylight
AzureIoTClient 0:1f9b2707ec7d 3441 Saving Time is not in effect, and negative if the information is not available.*/
AzureIoTClient 0:1f9b2707ec7d 3442 agentData->value.edmDateTimeOffset.dateTime.tm_isdst = -1;
AzureIoTClient 0:1f9b2707ec7d 3443
AzureIoTClient 0:1f9b2707ec7d 3444 if ((strLength < 2) ||
AzureIoTClient 0:1f9b2707ec7d 3445 (source[0] != '"') ||
AzureIoTClient 14:0c00e67a4ab1 3446 (source[strLength - 1] != '"'))
AzureIoTClient 0:1f9b2707ec7d 3447 {
AzureIoTClient 0:1f9b2707ec7d 3448 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3449 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3450 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3451 }
AzureIoTClient 0:1f9b2707ec7d 3452 else
AzureIoTClient 0:1f9b2707ec7d 3453 {
AzureIoTClient 0:1f9b2707ec7d 3454 size_t pos = 1;
AzureIoTClient 0:1f9b2707ec7d 3455 int sign;
AzureIoTClient 0:1f9b2707ec7d 3456 scanOptionalMinusSign(source, 2, &pos, &sign);
AzureIoTClient 0:1f9b2707ec7d 3457
AzureIoTClient 14:0c00e67a4ab1 3458 if ((scanAndReadNDigitsInt(source, &pos, &year, 4) != 0) ||
AzureIoTClient 0:1f9b2707ec7d 3459 (source[pos++] != '-') ||
AzureIoTClient 14:0c00e67a4ab1 3460 (scanAndReadNDigitsInt(source, &pos, &month, 2) != 0) ||
AzureIoTClient 0:1f9b2707ec7d 3461 (source[pos++] != '-') ||
AzureIoTClient 14:0c00e67a4ab1 3462 (scanAndReadNDigitsInt(source, &pos, &day, 2) != 0) ||
AzureIoTClient 0:1f9b2707ec7d 3463 (source[pos++] != 'T') ||
AzureIoTClient 14:0c00e67a4ab1 3464 (scanAndReadNDigitsInt(source, &pos, &hour, 2) != 0) ||
AzureIoTClient 0:1f9b2707ec7d 3465 (source[pos++] != ':') ||
AzureIoTClient 14:0c00e67a4ab1 3466 (scanAndReadNDigitsInt(source, &pos, &min, 2) != 0))
AzureIoTClient 0:1f9b2707ec7d 3467 {
AzureIoTClient 0:1f9b2707ec7d 3468 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3469 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3470 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3471 }
AzureIoTClient 0:1f9b2707ec7d 3472 else
AzureIoTClient 0:1f9b2707ec7d 3473 {
AzureIoTClient 0:1f9b2707ec7d 3474 const char* pos2;
AzureIoTClient 0:1f9b2707ec7d 3475 year = year*sign;
AzureIoTClient 0:1f9b2707ec7d 3476 if ((pos2 = strchr(source, ':')) == NULL)
AzureIoTClient 0:1f9b2707ec7d 3477 {
AzureIoTClient 0:1f9b2707ec7d 3478 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3479 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3480 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3481 }
AzureIoTClient 0:1f9b2707ec7d 3482 else
AzureIoTClient 0:1f9b2707ec7d 3483 {
AzureIoTClient 0:1f9b2707ec7d 3484 pos2 += 3;
AzureIoTClient 0:1f9b2707ec7d 3485 if (*pos2 == ':')
AzureIoTClient 0:1f9b2707ec7d 3486 {
Azure.IoT Build 9:747680124ff7 3487 if (sscanf2d(pos2, &sec) != 1)
AzureIoTClient 0:1f9b2707ec7d 3488 {
AzureIoTClient 0:1f9b2707ec7d 3489 pos2 = NULL;
AzureIoTClient 0:1f9b2707ec7d 3490 }
AzureIoTClient 0:1f9b2707ec7d 3491 else
AzureIoTClient 0:1f9b2707ec7d 3492 {
AzureIoTClient 0:1f9b2707ec7d 3493 pos2 += 3;
AzureIoTClient 0:1f9b2707ec7d 3494 }
AzureIoTClient 0:1f9b2707ec7d 3495 }
AzureIoTClient 0:1f9b2707ec7d 3496
AzureIoTClient 0:1f9b2707ec7d 3497 if ((pos2 != NULL) &&
AzureIoTClient 0:1f9b2707ec7d 3498 (*pos2 == '.'))
AzureIoTClient 0:1f9b2707ec7d 3499 {
AzureIoTClient 14:0c00e67a4ab1 3500 if (sscanfdotllu(pos2, &fractionalSeconds) != 1)
AzureIoTClient 0:1f9b2707ec7d 3501 {
AzureIoTClient 0:1f9b2707ec7d 3502 pos2 = NULL;
AzureIoTClient 0:1f9b2707ec7d 3503 }
AzureIoTClient 0:1f9b2707ec7d 3504 else
AzureIoTClient 0:1f9b2707ec7d 3505 {
AzureIoTClient 0:1f9b2707ec7d 3506 pos2++;
AzureIoTClient 0:1f9b2707ec7d 3507
AzureIoTClient 0:1f9b2707ec7d 3508 agentData->value.edmDateTimeOffset.hasFractionalSecond = 1;
AzureIoTClient 0:1f9b2707ec7d 3509
AzureIoTClient 0:1f9b2707ec7d 3510 while ((*pos2 != '\0') &&
AzureIoTClient 0:1f9b2707ec7d 3511 (IS_DIGIT(*pos2)))
AzureIoTClient 0:1f9b2707ec7d 3512 {
AzureIoTClient 0:1f9b2707ec7d 3513 pos2++;
AzureIoTClient 0:1f9b2707ec7d 3514 }
AzureIoTClient 0:1f9b2707ec7d 3515
AzureIoTClient 0:1f9b2707ec7d 3516 if (*pos2 == '\0')
AzureIoTClient 0:1f9b2707ec7d 3517 {
AzureIoTClient 0:1f9b2707ec7d 3518 pos2 = NULL;
AzureIoTClient 0:1f9b2707ec7d 3519 }
AzureIoTClient 0:1f9b2707ec7d 3520 }
AzureIoTClient 0:1f9b2707ec7d 3521 }
AzureIoTClient 0:1f9b2707ec7d 3522
AzureIoTClient 0:1f9b2707ec7d 3523 if (pos2 == NULL)
AzureIoTClient 0:1f9b2707ec7d 3524 {
AzureIoTClient 0:1f9b2707ec7d 3525 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3526 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3527 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3528 }
AzureIoTClient 0:1f9b2707ec7d 3529 else
AzureIoTClient 0:1f9b2707ec7d 3530 {
AzureIoTClient 0:1f9b2707ec7d 3531 hourOffset = 0;
AzureIoTClient 0:1f9b2707ec7d 3532 minOffset = 0;
AzureIoTClient 0:1f9b2707ec7d 3533
AzureIoTClient 14:0c00e67a4ab1 3534 if (sscanf3d2d(pos2, &hourOffset, &minOffset) == 2)
AzureIoTClient 0:1f9b2707ec7d 3535 {
AzureIoTClient 0:1f9b2707ec7d 3536 agentData->value.edmDateTimeOffset.hasTimeZone = 1;
AzureIoTClient 0:1f9b2707ec7d 3537 }
AzureIoTClient 0:1f9b2707ec7d 3538
AzureIoTClient 0:1f9b2707ec7d 3539 if ((strcmp(pos2, "Z\"") == 0) ||
AzureIoTClient 0:1f9b2707ec7d 3540 agentData->value.edmDateTimeOffset.hasTimeZone)
AzureIoTClient 0:1f9b2707ec7d 3541 {
AzureIoTClient 0:1f9b2707ec7d 3542 if ((ValidateDate(year, month, day) != 0) ||
AzureIoTClient 0:1f9b2707ec7d 3543 (hour < 0) ||
AzureIoTClient 0:1f9b2707ec7d 3544 (hour > 23) ||
AzureIoTClient 0:1f9b2707ec7d 3545 (min < 0) ||
AzureIoTClient 0:1f9b2707ec7d 3546 (min > 59) ||
AzureIoTClient 0:1f9b2707ec7d 3547 (sec < 0) ||
AzureIoTClient 0:1f9b2707ec7d 3548 (sec > 59) ||
AzureIoTClient 0:1f9b2707ec7d 3549 (fractionalSeconds > 999999999999) ||
AzureIoTClient 0:1f9b2707ec7d 3550 (hourOffset < -23) ||
AzureIoTClient 0:1f9b2707ec7d 3551 (hourOffset > 23) ||
AzureIoTClient 0:1f9b2707ec7d 3552 (minOffset < 0) ||
AzureIoTClient 0:1f9b2707ec7d 3553 (minOffset > 59))
AzureIoTClient 0:1f9b2707ec7d 3554 {
AzureIoTClient 0:1f9b2707ec7d 3555 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3556 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3557 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3558 }
AzureIoTClient 0:1f9b2707ec7d 3559 else
AzureIoTClient 0:1f9b2707ec7d 3560 {
AzureIoTClient 0:1f9b2707ec7d 3561 agentData->type = EDM_DATE_TIME_OFFSET_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3562 agentData->value.edmDateTimeOffset.dateTime.tm_year= year-1900;
AzureIoTClient 0:1f9b2707ec7d 3563 agentData->value.edmDateTimeOffset.dateTime.tm_mon = month-1;
AzureIoTClient 0:1f9b2707ec7d 3564 agentData->value.edmDateTimeOffset.dateTime.tm_mday = day;
AzureIoTClient 0:1f9b2707ec7d 3565 agentData->value.edmDateTimeOffset.dateTime.tm_hour = hour;
AzureIoTClient 0:1f9b2707ec7d 3566 agentData->value.edmDateTimeOffset.dateTime.tm_min = min;
AzureIoTClient 0:1f9b2707ec7d 3567 agentData->value.edmDateTimeOffset.dateTime.tm_sec = sec;
AzureIoTClient 0:1f9b2707ec7d 3568 /*fill in tm_wday and tm_yday*/
AzureIoTClient 0:1f9b2707ec7d 3569 fill_tm_yday_and_tm_wday(&agentData->value.edmDateTimeOffset.dateTime);
AzureIoTClient 0:1f9b2707ec7d 3570 agentData->value.edmDateTimeOffset.fractionalSecond = (uint64_t)fractionalSeconds;
AzureIoTClient 0:1f9b2707ec7d 3571 agentData->value.edmDateTimeOffset.timeZoneHour = (int8_t)hourOffset;
AzureIoTClient 0:1f9b2707ec7d 3572 agentData->value.edmDateTimeOffset.timeZoneMinute = (uint8_t)minOffset;
AzureIoTClient 0:1f9b2707ec7d 3573 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3574 }
AzureIoTClient 0:1f9b2707ec7d 3575 }
AzureIoTClient 0:1f9b2707ec7d 3576 else
AzureIoTClient 0:1f9b2707ec7d 3577 {
AzureIoTClient 0:1f9b2707ec7d 3578 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3579 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3580 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3581 }
AzureIoTClient 0:1f9b2707ec7d 3582 }
AzureIoTClient 0:1f9b2707ec7d 3583 }
AzureIoTClient 0:1f9b2707ec7d 3584 }
AzureIoTClient 0:1f9b2707ec7d 3585 }
AzureIoTClient 0:1f9b2707ec7d 3586
AzureIoTClient 0:1f9b2707ec7d 3587 break;
AzureIoTClient 0:1f9b2707ec7d 3588 }
AzureIoTClient 0:1f9b2707ec7d 3589
AzureIoTClient 0:1f9b2707ec7d 3590 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_080:[ EDM_DOUBLE] */
AzureIoTClient 0:1f9b2707ec7d 3591 case EDM_DOUBLE_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3592 {
AzureIoTClient 0:1f9b2707ec7d 3593 if (strcmp(source, "\"NaN\"") == 0)
AzureIoTClient 0:1f9b2707ec7d 3594 {
AzureIoTClient 0:1f9b2707ec7d 3595 agentData->type = EDM_DOUBLE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3596 agentData->value.edmDouble.value = NAN;
AzureIoTClient 0:1f9b2707ec7d 3597 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3598 }
AzureIoTClient 0:1f9b2707ec7d 3599 else if (strcmp(source, "\"INF\"") == 0)
AzureIoTClient 0:1f9b2707ec7d 3600 {
AzureIoTClient 0:1f9b2707ec7d 3601 agentData->type = EDM_DOUBLE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3602 agentData->value.edmDouble.value = INFINITY;
AzureIoTClient 0:1f9b2707ec7d 3603 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3604 }
AzureIoTClient 0:1f9b2707ec7d 3605 else if (strcmp(source, "\"-INF\"") == 0)
AzureIoTClient 0:1f9b2707ec7d 3606 {
AzureIoTClient 0:1f9b2707ec7d 3607 agentData->type = EDM_DOUBLE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3608 #ifdef _MSC_VER
AzureIoTClient 0:1f9b2707ec7d 3609 #pragma warning(push)
AzureIoTClient 0:1f9b2707ec7d 3610 #pragma warning(disable: 4056) /* Known warning for INIFNITY */
AzureIoTClient 0:1f9b2707ec7d 3611 #endif
AzureIoTClient 0:1f9b2707ec7d 3612 agentData->value.edmDouble.value = -INFINITY;
AzureIoTClient 0:1f9b2707ec7d 3613 #ifdef _MSC_VER
AzureIoTClient 0:1f9b2707ec7d 3614 #pragma warning(pop)
AzureIoTClient 0:1f9b2707ec7d 3615 #endif
AzureIoTClient 0:1f9b2707ec7d 3616 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3617 }
AzureIoTClient 14:0c00e67a4ab1 3618 else if (sscanflf(source, &(agentData->value.edmDouble.value)) != 1)
AzureIoTClient 0:1f9b2707ec7d 3619 {
AzureIoTClient 0:1f9b2707ec7d 3620 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3621 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3622 }
AzureIoTClient 0:1f9b2707ec7d 3623 else
AzureIoTClient 0:1f9b2707ec7d 3624 {
AzureIoTClient 0:1f9b2707ec7d 3625 agentData->type = EDM_DOUBLE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3626 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3627 }
AzureIoTClient 0:1f9b2707ec7d 3628 break;
AzureIoTClient 0:1f9b2707ec7d 3629 }
AzureIoTClient 0:1f9b2707ec7d 3630
AzureIoTClient 0:1f9b2707ec7d 3631 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_089:[EDM_SINGLE] */
AzureIoTClient 0:1f9b2707ec7d 3632 case EDM_SINGLE_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3633 {
AzureIoTClient 0:1f9b2707ec7d 3634 if (strcmp(source, "\"NaN\"") == 0)
AzureIoTClient 0:1f9b2707ec7d 3635 {
AzureIoTClient 0:1f9b2707ec7d 3636 agentData->type = EDM_SINGLE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3637 agentData->value.edmSingle.value = NAN;
AzureIoTClient 0:1f9b2707ec7d 3638 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3639 }
AzureIoTClient 0:1f9b2707ec7d 3640 else if (strcmp(source, "\"INF\"") == 0)
AzureIoTClient 0:1f9b2707ec7d 3641 {
AzureIoTClient 0:1f9b2707ec7d 3642 agentData->type = EDM_SINGLE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3643 agentData->value.edmSingle.value = INFINITY;
AzureIoTClient 0:1f9b2707ec7d 3644 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3645 }
AzureIoTClient 0:1f9b2707ec7d 3646 else if (strcmp(source, "\"-INF\"") == 0)
AzureIoTClient 0:1f9b2707ec7d 3647 {
AzureIoTClient 0:1f9b2707ec7d 3648 agentData->type = EDM_SINGLE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3649 #ifdef _MSC_VER
AzureIoTClient 0:1f9b2707ec7d 3650 #pragma warning(push)
AzureIoTClient 0:1f9b2707ec7d 3651 #pragma warning(disable: 4056) /* Known warning for INIFNITY */
AzureIoTClient 0:1f9b2707ec7d 3652 #endif
AzureIoTClient 0:1f9b2707ec7d 3653 agentData->value.edmSingle.value = -INFINITY;
AzureIoTClient 0:1f9b2707ec7d 3654 #ifdef _MSC_VER
AzureIoTClient 0:1f9b2707ec7d 3655 #pragma warning(pop)
AzureIoTClient 0:1f9b2707ec7d 3656 #endif
AzureIoTClient 0:1f9b2707ec7d 3657 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3658 }
AzureIoTClient 14:0c00e67a4ab1 3659 else if (sscanff(source, &agentData->value.edmSingle.value) != 1)
AzureIoTClient 0:1f9b2707ec7d 3660 {
AzureIoTClient 0:1f9b2707ec7d 3661 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3662 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3663 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3664 }
AzureIoTClient 0:1f9b2707ec7d 3665 else
AzureIoTClient 0:1f9b2707ec7d 3666 {
AzureIoTClient 0:1f9b2707ec7d 3667 agentData->type = EDM_SINGLE_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3668 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3669 }
AzureIoTClient 0:1f9b2707ec7d 3670 break;
AzureIoTClient 0:1f9b2707ec7d 3671 }
AzureIoTClient 0:1f9b2707ec7d 3672
AzureIoTClient 0:1f9b2707ec7d 3673 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_079:[ EDM_DECIMAL] */
AzureIoTClient 0:1f9b2707ec7d 3674 case EDM_DECIMAL_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3675 {
AzureIoTClient 0:1f9b2707ec7d 3676 size_t strLength = strlen(source);
AzureIoTClient 0:1f9b2707ec7d 3677 if ((strLength < 2) ||
AzureIoTClient 0:1f9b2707ec7d 3678 (source[0] != '"') ||
AzureIoTClient 0:1f9b2707ec7d 3679 (source[strLength - 1] != '"') ||
AzureIoTClient 0:1f9b2707ec7d 3680 (ValidateDecimal(source + 1, strLength - 2) != 0))
AzureIoTClient 0:1f9b2707ec7d 3681 {
AzureIoTClient 0:1f9b2707ec7d 3682 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3683 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3684 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3685 }
AzureIoTClient 0:1f9b2707ec7d 3686 else
AzureIoTClient 0:1f9b2707ec7d 3687 {
AzureIoTClient 0:1f9b2707ec7d 3688 agentData->type = EDM_DECIMAL_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3689 agentData->value.edmDecimal.value = STRING_construct_n(source + 1, strLength-2);
AzureIoTClient 0:1f9b2707ec7d 3690 if (agentData->value.edmDecimal.value == NULL)
AzureIoTClient 0:1f9b2707ec7d 3691 {
AzureIoTClient 0:1f9b2707ec7d 3692 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_088:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_ERROR if any other error occurs.] */
AzureIoTClient 0:1f9b2707ec7d 3693 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 3694 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3695 }
AzureIoTClient 0:1f9b2707ec7d 3696 else
AzureIoTClient 0:1f9b2707ec7d 3697 {
AzureIoTClient 0:1f9b2707ec7d 3698 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3699 }
AzureIoTClient 0:1f9b2707ec7d 3700 }
AzureIoTClient 0:1f9b2707ec7d 3701 break;
AzureIoTClient 0:1f9b2707ec7d 3702 }
AzureIoTClient 0:1f9b2707ec7d 3703
AzureIoTClient 0:1f9b2707ec7d 3704 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_086:[ EDM_STRING] */
AzureIoTClient 0:1f9b2707ec7d 3705 case EDM_STRING_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3706 {
AzureIoTClient 0:1f9b2707ec7d 3707 size_t strLength = strlen(source);
AzureIoTClient 0:1f9b2707ec7d 3708 if ((strLength < 2) ||
AzureIoTClient 0:1f9b2707ec7d 3709 (source[0] != '"') ||
AzureIoTClient 0:1f9b2707ec7d 3710 (source[strLength - 1] != '"'))
AzureIoTClient 0:1f9b2707ec7d 3711 {
AzureIoTClient 0:1f9b2707ec7d 3712 /* Codes_SRS_AGENT_TYPE_SYSTEM_99_087:[ CreateAgentDataType_From_String shall return AGENT_DATA_TYPES_INVALID_ARG if source is not a valid string for a value of type type.] */
AzureIoTClient 0:1f9b2707ec7d 3713 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3714 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3715 }
AzureIoTClient 0:1f9b2707ec7d 3716 else
AzureIoTClient 0:1f9b2707ec7d 3717 {
AzureIoTClient 0:1f9b2707ec7d 3718 char* temp;
AzureIoTClient 0:1f9b2707ec7d 3719 if ((temp = (char*)malloc(strLength - 1)) == NULL)
AzureIoTClient 0:1f9b2707ec7d 3720 {
AzureIoTClient 0:1f9b2707ec7d 3721 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 3722 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3723 }
AzureIoTClient 0:1f9b2707ec7d 3724 else if (strncpy_s(temp, strLength - 1, source + 1, strLength - 2) != 0)
AzureIoTClient 0:1f9b2707ec7d 3725 {
AzureIoTClient 0:1f9b2707ec7d 3726 free(temp);
AzureIoTClient 0:1f9b2707ec7d 3727
AzureIoTClient 0:1f9b2707ec7d 3728 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 3729 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3730 }
AzureIoTClient 0:1f9b2707ec7d 3731 else
AzureIoTClient 0:1f9b2707ec7d 3732 {
AzureIoTClient 0:1f9b2707ec7d 3733 temp[strLength - 2] = 0;
AzureIoTClient 0:1f9b2707ec7d 3734
AzureIoTClient 0:1f9b2707ec7d 3735 agentData->type = EDM_STRING_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3736 agentData->value.edmString.chars = temp;
AzureIoTClient 0:1f9b2707ec7d 3737 agentData->value.edmString.length = strLength - 2;
AzureIoTClient 0:1f9b2707ec7d 3738 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3739 }
AzureIoTClient 0:1f9b2707ec7d 3740 }
AzureIoTClient 0:1f9b2707ec7d 3741 break;
AzureIoTClient 0:1f9b2707ec7d 3742 }
AzureIoTClient 0:1f9b2707ec7d 3743 /* Codes_SRS_AGENT_TYPE_SYSTEM_01_004: [EDM_STRING_NO_QUOTES] */
AzureIoTClient 0:1f9b2707ec7d 3744 case EDM_STRING_NO_QUOTES_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3745 {
AzureIoTClient 0:1f9b2707ec7d 3746 char* temp;
AzureIoTClient 0:1f9b2707ec7d 3747 size_t strLength = strlen(source);
AzureIoTClient 0:1f9b2707ec7d 3748 if (mallocAndStrcpy_s(&temp, source) != 0)
AzureIoTClient 0:1f9b2707ec7d 3749 {
AzureIoTClient 0:1f9b2707ec7d 3750 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 3751 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3752 }
AzureIoTClient 0:1f9b2707ec7d 3753 else
AzureIoTClient 0:1f9b2707ec7d 3754 {
AzureIoTClient 0:1f9b2707ec7d 3755 agentData->type = EDM_STRING_NO_QUOTES_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3756 agentData->value.edmStringNoQuotes.chars = temp;
AzureIoTClient 0:1f9b2707ec7d 3757 agentData->value.edmStringNoQuotes.length = strLength;
AzureIoTClient 0:1f9b2707ec7d 3758 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3759 }
AzureIoTClient 0:1f9b2707ec7d 3760 break;
AzureIoTClient 0:1f9b2707ec7d 3761 }
AzureIoTClient 0:1f9b2707ec7d 3762 /*Codes_SRS_AGENT_TYPE_SYSTEM_99_097:[ EDM_GUID]*/
AzureIoTClient 0:1f9b2707ec7d 3763 case EDM_GUID_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3764 {
Azure.IoT Build 8:380e6e830589 3765 if (strlen(source) != GUID_STRING_LENGTH)
AzureIoTClient 0:1f9b2707ec7d 3766 {
AzureIoTClient 0:1f9b2707ec7d 3767 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3768 }
AzureIoTClient 0:1f9b2707ec7d 3769 else
AzureIoTClient 0:1f9b2707ec7d 3770 {
AzureIoTClient 0:1f9b2707ec7d 3771 if (source[0] != '"')
AzureIoTClient 0:1f9b2707ec7d 3772 {
AzureIoTClient 0:1f9b2707ec7d 3773 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3774 }
AzureIoTClient 0:1f9b2707ec7d 3775 else if (scanMandatory2CapitalHexDigits(source + 1, &(agentData->value.edmGuid.GUID[0])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3776 {
AzureIoTClient 0:1f9b2707ec7d 3777 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3778 }
AzureIoTClient 0:1f9b2707ec7d 3779 else if (scanMandatory2CapitalHexDigits(source + 3, &(agentData->value.edmGuid.GUID[1])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3780 {
AzureIoTClient 0:1f9b2707ec7d 3781 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3782 }
AzureIoTClient 0:1f9b2707ec7d 3783 else if (scanMandatory2CapitalHexDigits(source + 5, &(agentData->value.edmGuid.GUID[2])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3784 {
AzureIoTClient 0:1f9b2707ec7d 3785 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3786 }
AzureIoTClient 0:1f9b2707ec7d 3787 else if (scanMandatory2CapitalHexDigits(source + 7, &(agentData->value.edmGuid.GUID[3])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3788 {
AzureIoTClient 0:1f9b2707ec7d 3789 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3790 }
AzureIoTClient 0:1f9b2707ec7d 3791 else if (source[9] != '-')
AzureIoTClient 0:1f9b2707ec7d 3792 {
AzureIoTClient 0:1f9b2707ec7d 3793 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3794 }
AzureIoTClient 0:1f9b2707ec7d 3795 else if (scanMandatory2CapitalHexDigits(source + 10, &(agentData->value.edmGuid.GUID[4])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3796 {
AzureIoTClient 0:1f9b2707ec7d 3797 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3798 }
AzureIoTClient 0:1f9b2707ec7d 3799 else if (scanMandatory2CapitalHexDigits(source + 12, &(agentData->value.edmGuid.GUID[5])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3800 {
AzureIoTClient 0:1f9b2707ec7d 3801 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3802 }
AzureIoTClient 0:1f9b2707ec7d 3803 else if (source[14] != '-')
AzureIoTClient 0:1f9b2707ec7d 3804 {
AzureIoTClient 0:1f9b2707ec7d 3805 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3806 }
AzureIoTClient 0:1f9b2707ec7d 3807 else if (scanMandatory2CapitalHexDigits(source + 15, &(agentData->value.edmGuid.GUID[6])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3808 {
AzureIoTClient 0:1f9b2707ec7d 3809 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3810 }
AzureIoTClient 0:1f9b2707ec7d 3811 else if (scanMandatory2CapitalHexDigits(source + 17, &(agentData->value.edmGuid.GUID[7])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3812 {
AzureIoTClient 0:1f9b2707ec7d 3813 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3814 }
AzureIoTClient 0:1f9b2707ec7d 3815 else if (source[19] != '-')
AzureIoTClient 0:1f9b2707ec7d 3816 {
AzureIoTClient 0:1f9b2707ec7d 3817 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3818 }
AzureIoTClient 0:1f9b2707ec7d 3819 else if (scanMandatory2CapitalHexDigits(source + 20, &(agentData->value.edmGuid.GUID[8])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3820 {
AzureIoTClient 0:1f9b2707ec7d 3821 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3822 }
AzureIoTClient 0:1f9b2707ec7d 3823 else if (scanMandatory2CapitalHexDigits(source + 22, &(agentData->value.edmGuid.GUID[9])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3824 {
AzureIoTClient 0:1f9b2707ec7d 3825 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3826 }
AzureIoTClient 0:1f9b2707ec7d 3827 else if (source[24] != '-')
AzureIoTClient 0:1f9b2707ec7d 3828 {
AzureIoTClient 0:1f9b2707ec7d 3829 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3830 }
AzureIoTClient 0:1f9b2707ec7d 3831 else if (scanMandatory2CapitalHexDigits(source + 25, &(agentData->value.edmGuid.GUID[10])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3832 {
AzureIoTClient 0:1f9b2707ec7d 3833 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3834 }
AzureIoTClient 0:1f9b2707ec7d 3835 else if (scanMandatory2CapitalHexDigits(source + 27, &(agentData->value.edmGuid.GUID[11])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3836 {
AzureIoTClient 0:1f9b2707ec7d 3837 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3838 }
AzureIoTClient 0:1f9b2707ec7d 3839 else if (scanMandatory2CapitalHexDigits(source + 29, &(agentData->value.edmGuid.GUID[12])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3840 {
AzureIoTClient 0:1f9b2707ec7d 3841 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3842 }
AzureIoTClient 0:1f9b2707ec7d 3843 else if (scanMandatory2CapitalHexDigits(source + 31, &(agentData->value.edmGuid.GUID[13])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3844 {
AzureIoTClient 0:1f9b2707ec7d 3845 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3846 }
AzureIoTClient 0:1f9b2707ec7d 3847 else if (scanMandatory2CapitalHexDigits(source + 33, &(agentData->value.edmGuid.GUID[14])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3848 {
AzureIoTClient 0:1f9b2707ec7d 3849 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3850 }
AzureIoTClient 0:1f9b2707ec7d 3851 else if (scanMandatory2CapitalHexDigits(source + 35, &(agentData->value.edmGuid.GUID[15])) != 0)
AzureIoTClient 0:1f9b2707ec7d 3852 {
AzureIoTClient 0:1f9b2707ec7d 3853 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3854 }
AzureIoTClient 0:1f9b2707ec7d 3855 else if (source[37] != '"')
AzureIoTClient 0:1f9b2707ec7d 3856 {
AzureIoTClient 0:1f9b2707ec7d 3857 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3858 }
AzureIoTClient 0:1f9b2707ec7d 3859 else
AzureIoTClient 0:1f9b2707ec7d 3860 {
AzureIoTClient 0:1f9b2707ec7d 3861 agentData->type = EDM_GUID_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3862 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3863 }
AzureIoTClient 0:1f9b2707ec7d 3864 }
AzureIoTClient 0:1f9b2707ec7d 3865 break;
AzureIoTClient 0:1f9b2707ec7d 3866 }
AzureIoTClient 0:1f9b2707ec7d 3867 case EDM_BINARY_TYPE:
AzureIoTClient 0:1f9b2707ec7d 3868 {
AzureIoTClient 0:1f9b2707ec7d 3869 size_t sourceLength = strlen(source);
AzureIoTClient 0:1f9b2707ec7d 3870 if (sourceLength < 2)
AzureIoTClient 0:1f9b2707ec7d 3871 {
AzureIoTClient 0:1f9b2707ec7d 3872 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3873 }
AzureIoTClient 0:1f9b2707ec7d 3874 else if (sourceLength == 2)
AzureIoTClient 0:1f9b2707ec7d 3875 {
AzureIoTClient 0:1f9b2707ec7d 3876 agentData->type = EDM_BINARY_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3877 agentData->value.edmBinary.data = NULL;
AzureIoTClient 0:1f9b2707ec7d 3878 agentData->value.edmBinary.size = 0;
AzureIoTClient 0:1f9b2707ec7d 3879 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3880 }
AzureIoTClient 0:1f9b2707ec7d 3881 else
AzureIoTClient 0:1f9b2707ec7d 3882 {
AzureIoTClient 0:1f9b2707ec7d 3883 size_t sourcePosition = 0;
AzureIoTClient 0:1f9b2707ec7d 3884 if (source[sourcePosition++] != '"') /*if it doesn't start with a quote then... */
AzureIoTClient 0:1f9b2707ec7d 3885 {
AzureIoTClient 0:1f9b2707ec7d 3886 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3887 }
AzureIoTClient 0:1f9b2707ec7d 3888 else
AzureIoTClient 0:1f9b2707ec7d 3889 {
AzureIoTClient 0:1f9b2707ec7d 3890 /*1. read groups of 4 base64 character and transfer those into groups of 3 "normal" characters.
AzureIoTClient 0:1f9b2707ec7d 3891 2. read the end of the string and produce from that the ending characters*/
AzureIoTClient 0:1f9b2707ec7d 3892
AzureIoTClient 0:1f9b2707ec7d 3893 /*compute the amount of memory to allocate*/
AzureIoTClient 0:1f9b2707ec7d 3894 agentData->value.edmBinary.size = (((sourceLength - 2) + 4) / 4) * 3; /*this is overallocation, shall be trimmed later*/
AzureIoTClient 0:1f9b2707ec7d 3895 agentData->value.edmBinary.data = (unsigned char*)malloc(agentData->value.edmBinary.size); /*this is overallocation, shall be trimmed later*/
AzureIoTClient 0:1f9b2707ec7d 3896 if (agentData->value.edmBinary.data == NULL)
AzureIoTClient 0:1f9b2707ec7d 3897 {
AzureIoTClient 0:1f9b2707ec7d 3898 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 0:1f9b2707ec7d 3899 }
AzureIoTClient 0:1f9b2707ec7d 3900 else
AzureIoTClient 0:1f9b2707ec7d 3901 {
AzureIoTClient 0:1f9b2707ec7d 3902
AzureIoTClient 0:1f9b2707ec7d 3903 size_t destinationPosition = 0;
AzureIoTClient 0:1f9b2707ec7d 3904 size_t consumed;
AzureIoTClient 0:1f9b2707ec7d 3905 /*read and store "solid" groups of 4 base64 chars*/
AzureIoTClient 0:1f9b2707ec7d 3906 while (scan4base64char(source + sourcePosition, sourceLength - sourcePosition, agentData->value.edmBinary.data + destinationPosition, agentData->value.edmBinary.data + destinationPosition + 1, agentData->value.edmBinary.data + destinationPosition + 2) == 0)
AzureIoTClient 0:1f9b2707ec7d 3907 {
AzureIoTClient 0:1f9b2707ec7d 3908 sourcePosition += 4;
AzureIoTClient 0:1f9b2707ec7d 3909 destinationPosition += 3;
AzureIoTClient 0:1f9b2707ec7d 3910 }
AzureIoTClient 0:1f9b2707ec7d 3911
AzureIoTClient 0:1f9b2707ec7d 3912 if (scanbase64b16(source + sourcePosition, sourceLength - sourcePosition, &consumed, agentData->value.edmBinary.data + destinationPosition, agentData->value.edmBinary.data + destinationPosition + 1) == 0)
AzureIoTClient 0:1f9b2707ec7d 3913 {
AzureIoTClient 0:1f9b2707ec7d 3914 sourcePosition += consumed;
AzureIoTClient 0:1f9b2707ec7d 3915 destinationPosition += 2;
AzureIoTClient 0:1f9b2707ec7d 3916
AzureIoTClient 0:1f9b2707ec7d 3917 }
AzureIoTClient 0:1f9b2707ec7d 3918 else if (scanbase64b8(source + sourcePosition, sourceLength - sourcePosition, &consumed, agentData->value.edmBinary.data + destinationPosition) == 0)
AzureIoTClient 0:1f9b2707ec7d 3919 {
AzureIoTClient 0:1f9b2707ec7d 3920 sourcePosition += consumed;
AzureIoTClient 0:1f9b2707ec7d 3921 destinationPosition += 1;
AzureIoTClient 0:1f9b2707ec7d 3922 }
AzureIoTClient 0:1f9b2707ec7d 3923
AzureIoTClient 0:1f9b2707ec7d 3924 if (source[sourcePosition++] != '"') /*if it doesn't end with " then bail out*/
AzureIoTClient 0:1f9b2707ec7d 3925 {
AzureIoTClient 0:1f9b2707ec7d 3926 free(agentData->value.edmBinary.data);
AzureIoTClient 0:1f9b2707ec7d 3927 agentData->value.edmBinary.data = NULL;
AzureIoTClient 0:1f9b2707ec7d 3928 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3929 }
AzureIoTClient 0:1f9b2707ec7d 3930 else if (sourcePosition != sourceLength)
AzureIoTClient 0:1f9b2707ec7d 3931 {
AzureIoTClient 0:1f9b2707ec7d 3932 free(agentData->value.edmBinary.data);
AzureIoTClient 0:1f9b2707ec7d 3933 agentData->value.edmBinary.data = NULL;
AzureIoTClient 0:1f9b2707ec7d 3934 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 3935 }
AzureIoTClient 0:1f9b2707ec7d 3936 else
AzureIoTClient 0:1f9b2707ec7d 3937 {
AzureIoTClient 0:1f9b2707ec7d 3938 /*trim the result*/
AzureIoTClient 0:1f9b2707ec7d 3939 void* temp = realloc(agentData->value.edmBinary.data, destinationPosition);
AzureIoTClient 0:1f9b2707ec7d 3940 if (temp == NULL) /*this is extremely unlikely to happen, but whatever*/
AzureIoTClient 0:1f9b2707ec7d 3941 {
AzureIoTClient 0:1f9b2707ec7d 3942 free(agentData->value.edmBinary.data);
AzureIoTClient 0:1f9b2707ec7d 3943 agentData->value.edmBinary.data = NULL;
AzureIoTClient 0:1f9b2707ec7d 3944 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 0:1f9b2707ec7d 3945 }
AzureIoTClient 0:1f9b2707ec7d 3946 else
AzureIoTClient 0:1f9b2707ec7d 3947 {
AzureIoTClient 0:1f9b2707ec7d 3948 agentData->type = EDM_BINARY_TYPE;
AzureIoTClient 0:1f9b2707ec7d 3949 agentData->value.edmBinary.data = (unsigned char*)temp;
AzureIoTClient 0:1f9b2707ec7d 3950 agentData->value.edmBinary.size = destinationPosition;
AzureIoTClient 0:1f9b2707ec7d 3951 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 3952 }
AzureIoTClient 0:1f9b2707ec7d 3953 }
AzureIoTClient 0:1f9b2707ec7d 3954 }
AzureIoTClient 0:1f9b2707ec7d 3955 }
AzureIoTClient 0:1f9b2707ec7d 3956 }
AzureIoTClient 0:1f9b2707ec7d 3957 break;
AzureIoTClient 0:1f9b2707ec7d 3958 }
AzureIoTClient 0:1f9b2707ec7d 3959 }
AzureIoTClient 0:1f9b2707ec7d 3960 }
AzureIoTClient 0:1f9b2707ec7d 3961
AzureIoTClient 0:1f9b2707ec7d 3962 return result;
AzureIoTClient 0:1f9b2707ec7d 3963 }
AzureIoTClient 0:1f9b2707ec7d 3964
AzureIoTClient 0:1f9b2707ec7d 3965 // extern AGENT_DATA_TYPES_RESULT AgentDataType_GetComplexTypeField(AGENT_DATA_TYPE* agentData, size_t index, COMPLEX_TYPE_FIELD_TYPE* complexField);
AzureIoTClient 0:1f9b2707ec7d 3966 COMPLEX_TYPE_FIELD_TYPE* AgentDataType_GetComplexTypeField(AGENT_DATA_TYPE* agentData, size_t index)
AzureIoTClient 0:1f9b2707ec7d 3967 {
AzureIoTClient 0:1f9b2707ec7d 3968 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 3969 COMPLEX_TYPE_FIELD_TYPE* complexField = NULL;
AzureIoTClient 0:1f9b2707ec7d 3970 if (agentData == NULL)
AzureIoTClient 0:1f9b2707ec7d 3971 {
AzureIoTClient 0:1f9b2707ec7d 3972 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3973 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3974 }
AzureIoTClient 0:1f9b2707ec7d 3975 else
AzureIoTClient 0:1f9b2707ec7d 3976 {
AzureIoTClient 0:1f9b2707ec7d 3977 if (agentData->type != EDM_COMPLEX_TYPE_TYPE)
AzureIoTClient 0:1f9b2707ec7d 3978 {
AzureIoTClient 0:1f9b2707ec7d 3979 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3980 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3981 }
AzureIoTClient 0:1f9b2707ec7d 3982
AzureIoTClient 0:1f9b2707ec7d 3983 else
AzureIoTClient 0:1f9b2707ec7d 3984 {
AzureIoTClient 0:1f9b2707ec7d 3985 if (index >= agentData->value.edmComplexType.nMembers)
AzureIoTClient 0:1f9b2707ec7d 3986 {
AzureIoTClient 0:1f9b2707ec7d 3987 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 3988 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3989 }
AzureIoTClient 0:1f9b2707ec7d 3990 else
AzureIoTClient 0:1f9b2707ec7d 3991 {
AzureIoTClient 0:1f9b2707ec7d 3992 complexField = (COMPLEX_TYPE_FIELD_TYPE*)malloc(sizeof(COMPLEX_TYPE_FIELD_TYPE));
AzureIoTClient 0:1f9b2707ec7d 3993 if (complexField == NULL)
AzureIoTClient 0:1f9b2707ec7d 3994 {
AzureIoTClient 0:1f9b2707ec7d 3995 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 11:b1327861f5e0 3996 LogError("(result = %s)", ENUM_TO_STRING(AGENT_DATA_TYPES_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 3997 }
AzureIoTClient 0:1f9b2707ec7d 3998 else
AzureIoTClient 0:1f9b2707ec7d 3999 {
AzureIoTClient 0:1f9b2707ec7d 4000 *complexField = agentData->value.edmComplexType.fields[index];
AzureIoTClient 0:1f9b2707ec7d 4001 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 4002 }
AzureIoTClient 0:1f9b2707ec7d 4003 }
AzureIoTClient 0:1f9b2707ec7d 4004 }
AzureIoTClient 0:1f9b2707ec7d 4005 }
AzureIoTClient 0:1f9b2707ec7d 4006 return complexField;
AzureIoTClient 0:1f9b2707ec7d 4007 }
AzureIoTClient 0:1f9b2707ec7d 4008