A small memory footprint AMQP implimentation
Dependents: iothub_client_sample_amqp remote_monitoring simplesample_amqp
amqpvalue_to_string.c@25:1101516ee67d, 2017-05-22 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Mon May 22 10:35:21 2017 -0700
- Revision:
- 25:1101516ee67d
- Parent:
- 23:1111ee8bcba4
- Child:
- 28:add19eb7defa
1.1.15
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Azure.IoT Build | 0:6ae2f7bca550 | 1 | // Copyright (c) Microsoft. All rights reserved. |
Azure.IoT Build | 0:6ae2f7bca550 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
Azure.IoT Build | 0:6ae2f7bca550 | 3 | |
Azure.IoT Build | 0:6ae2f7bca550 | 4 | #include <stdlib.h> |
Azure.IoT Build | 0:6ae2f7bca550 | 5 | #include <stdint.h> |
Azure.IoT Build | 0:6ae2f7bca550 | 6 | #include <stddef.h> |
Azure.IoT Build | 0:6ae2f7bca550 | 7 | #include <string.h> |
Azure.IoT Build | 0:6ae2f7bca550 | 8 | #include <stdio.h> |
AzureIoTClient | 19:000ab4e6a2c1 | 9 | #include "azure_c_shared_utility/optimize_size.h" |
AzureIoTClient | 21:f9c433d8e6ca | 10 | #include "azure_c_shared_utility/gballoc.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 11 | #include "azure_uamqp_c/amqpvalue_to_string.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 12 | #include "azure_uamqp_c/amqpvalue.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 13 | |
Azure.IoT Build | 0:6ae2f7bca550 | 14 | #if _WIN32 |
Azure.IoT Build | 0:6ae2f7bca550 | 15 | /* The MS runtime does not have snprintf */ |
Azure.IoT Build | 0:6ae2f7bca550 | 16 | #define snprintf _snprintf |
Azure.IoT Build | 0:6ae2f7bca550 | 17 | #endif |
Azure.IoT Build | 0:6ae2f7bca550 | 18 | |
Azure.IoT Build | 0:6ae2f7bca550 | 19 | static int string_concat(char** string, const char* to_concat) |
Azure.IoT Build | 0:6ae2f7bca550 | 20 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 21 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 22 | |
Azure.IoT Build | 0:6ae2f7bca550 | 23 | if ((string == NULL) || |
Azure.IoT Build | 0:6ae2f7bca550 | 24 | (to_concat == NULL)) |
Azure.IoT Build | 0:6ae2f7bca550 | 25 | { |
AzureIoTClient | 19:000ab4e6a2c1 | 26 | result = __FAILURE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 27 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 28 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 29 | { |
AzureIoTClient | 25:1101516ee67d | 30 | char* new_string; |
AzureIoTClient | 25:1101516ee67d | 31 | |
Azure.IoT Build | 0:6ae2f7bca550 | 32 | size_t length = strlen(to_concat) + 1; |
Azure.IoT Build | 0:6ae2f7bca550 | 33 | size_t src_length; |
Azure.IoT Build | 0:6ae2f7bca550 | 34 | |
Azure.IoT Build | 0:6ae2f7bca550 | 35 | if (*string != NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 36 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 37 | src_length = strlen(*string); |
Azure.IoT Build | 0:6ae2f7bca550 | 38 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 39 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 40 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 41 | src_length = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 42 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 43 | |
Azure.IoT Build | 0:6ae2f7bca550 | 44 | length += src_length; |
Azure.IoT Build | 0:6ae2f7bca550 | 45 | |
AzureIoTClient | 25:1101516ee67d | 46 | new_string = (char*)realloc(*string, length); |
Azure.IoT Build | 0:6ae2f7bca550 | 47 | if (new_string == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 48 | { |
AzureIoTClient | 19:000ab4e6a2c1 | 49 | result = __FAILURE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 50 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 51 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 52 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 53 | *string = new_string; |
Azure.IoT Build | 0:6ae2f7bca550 | 54 | (void)strcpy(*string + src_length, to_concat); |
Azure.IoT Build | 0:6ae2f7bca550 | 55 | result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 56 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 57 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 58 | |
Azure.IoT Build | 0:6ae2f7bca550 | 59 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 60 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 61 | |
Azure.IoT Build | 0:6ae2f7bca550 | 62 | char* amqpvalue_to_string(AMQP_VALUE amqp_value) |
Azure.IoT Build | 0:6ae2f7bca550 | 63 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 64 | char* result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 65 | |
Azure.IoT Build | 0:6ae2f7bca550 | 66 | if (amqp_value != NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 67 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 68 | AMQP_TYPE amqp_type = amqpvalue_get_type(amqp_value); |
Azure.IoT Build | 0:6ae2f7bca550 | 69 | switch (amqp_type) |
Azure.IoT Build | 0:6ae2f7bca550 | 70 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 71 | default: |
Azure.IoT Build | 0:6ae2f7bca550 | 72 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 73 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 74 | |
Azure.IoT Build | 0:6ae2f7bca550 | 75 | case AMQP_TYPE_NULL: |
Azure.IoT Build | 0:6ae2f7bca550 | 76 | if (string_concat(&result, "NULL") != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 77 | { |
AzureIoTClient | 21:f9c433d8e6ca | 78 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 79 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 80 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 81 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 82 | case AMQP_TYPE_BOOL: |
Azure.IoT Build | 0:6ae2f7bca550 | 83 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 84 | bool value; |
Azure.IoT Build | 0:6ae2f7bca550 | 85 | if ((amqpvalue_get_boolean(amqp_value, &value) != 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 86 | (string_concat(&result, (value == true) ? "true" : "false") != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 87 | { |
AzureIoTClient | 21:f9c433d8e6ca | 88 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 89 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 90 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 91 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 92 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 93 | case AMQP_TYPE_UBYTE: |
Azure.IoT Build | 0:6ae2f7bca550 | 94 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 95 | char str_value[4]; |
Azure.IoT Build | 0:6ae2f7bca550 | 96 | uint8_t value; |
Azure.IoT Build | 0:6ae2f7bca550 | 97 | if (amqpvalue_get_ubyte(amqp_value, &value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 98 | { |
AzureIoTClient | 21:f9c433d8e6ca | 99 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 100 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 101 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 102 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 103 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 104 | unsigned int uint_value = value; |
Azure.IoT Build | 0:6ae2f7bca550 | 105 | if ((sprintf(str_value, "%u", uint_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 106 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 107 | { |
AzureIoTClient | 21:f9c433d8e6ca | 108 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 109 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 110 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 111 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 112 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 113 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 114 | case AMQP_TYPE_USHORT: |
Azure.IoT Build | 0:6ae2f7bca550 | 115 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 116 | char str_value[6]; |
Azure.IoT Build | 0:6ae2f7bca550 | 117 | uint16_t value; |
Azure.IoT Build | 0:6ae2f7bca550 | 118 | if (amqpvalue_get_ushort(amqp_value, &value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 119 | { |
AzureIoTClient | 21:f9c433d8e6ca | 120 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 121 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 122 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 123 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 124 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 125 | unsigned int uint_value = value; |
Azure.IoT Build | 0:6ae2f7bca550 | 126 | if ((sprintf(str_value, "%u", uint_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 127 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 128 | { |
AzureIoTClient | 21:f9c433d8e6ca | 129 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 130 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 131 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 132 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 133 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 134 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 135 | case AMQP_TYPE_UINT: |
Azure.IoT Build | 0:6ae2f7bca550 | 136 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 137 | char str_value[11]; |
Azure.IoT Build | 0:6ae2f7bca550 | 138 | uint32_t value; |
Azure.IoT Build | 0:6ae2f7bca550 | 139 | if (amqpvalue_get_uint(amqp_value, &value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 140 | { |
AzureIoTClient | 21:f9c433d8e6ca | 141 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 142 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 143 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 144 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 145 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 146 | unsigned long uint_value = value; |
Azure.IoT Build | 0:6ae2f7bca550 | 147 | if ((sprintf(str_value, "%lu", uint_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 148 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 149 | { |
AzureIoTClient | 21:f9c433d8e6ca | 150 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 151 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 152 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 153 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 154 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 155 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 156 | case AMQP_TYPE_ULONG: |
Azure.IoT Build | 0:6ae2f7bca550 | 157 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 158 | char str_value[21]; |
Azure.IoT Build | 0:6ae2f7bca550 | 159 | uint64_t value; |
Azure.IoT Build | 0:6ae2f7bca550 | 160 | if (amqpvalue_get_ulong(amqp_value, &value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 161 | { |
AzureIoTClient | 21:f9c433d8e6ca | 162 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 163 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 164 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 165 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 166 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 167 | unsigned long long uint_value = value; |
Azure.IoT Build | 0:6ae2f7bca550 | 168 | if ((sprintf(str_value, "%llu", uint_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 169 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 170 | { |
AzureIoTClient | 21:f9c433d8e6ca | 171 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 172 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 173 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 174 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 175 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 176 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 177 | case AMQP_TYPE_BYTE: |
Azure.IoT Build | 0:6ae2f7bca550 | 178 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 179 | char str_value[5]; |
AzureIoTClient | 6:641a9672db08 | 180 | uint8_t value; |
Azure.IoT Build | 0:6ae2f7bca550 | 181 | if (amqpvalue_get_ubyte(amqp_value, &value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 182 | { |
AzureIoTClient | 21:f9c433d8e6ca | 183 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 184 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 185 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 186 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 187 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 188 | int int_value = value; |
Azure.IoT Build | 0:6ae2f7bca550 | 189 | if ((sprintf(str_value, "%d", int_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 190 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 191 | { |
AzureIoTClient | 21:f9c433d8e6ca | 192 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 193 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 194 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 195 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 196 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 197 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 198 | case AMQP_TYPE_SHORT: |
Azure.IoT Build | 0:6ae2f7bca550 | 199 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 200 | char str_value[7]; |
AzureIoTClient | 6:641a9672db08 | 201 | uint16_t value; |
Azure.IoT Build | 0:6ae2f7bca550 | 202 | if (amqpvalue_get_ushort(amqp_value, &value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 203 | { |
AzureIoTClient | 21:f9c433d8e6ca | 204 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 205 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 206 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 207 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 208 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 209 | int int_value = value; |
Azure.IoT Build | 0:6ae2f7bca550 | 210 | if ((sprintf(str_value, "%d", int_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 211 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 212 | { |
AzureIoTClient | 21:f9c433d8e6ca | 213 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 214 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 215 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 216 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 217 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 218 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 219 | case AMQP_TYPE_INT: |
Azure.IoT Build | 0:6ae2f7bca550 | 220 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 221 | char str_value[12]; |
Azure.IoT Build | 0:6ae2f7bca550 | 222 | int32_t value; |
Azure.IoT Build | 0:6ae2f7bca550 | 223 | if (amqpvalue_get_int(amqp_value, &value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 224 | { |
AzureIoTClient | 21:f9c433d8e6ca | 225 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 226 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 227 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 228 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 229 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 230 | unsigned long int_value = value; |
Azure.IoT Build | 0:6ae2f7bca550 | 231 | if ((sprintf(str_value, "%ld", int_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 232 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 233 | { |
AzureIoTClient | 21:f9c433d8e6ca | 234 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 235 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 236 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 237 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 238 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 239 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 240 | case AMQP_TYPE_LONG: |
Azure.IoT Build | 0:6ae2f7bca550 | 241 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 242 | char str_value[21]; |
AzureIoTClient | 6:641a9672db08 | 243 | uint64_t value; |
Azure.IoT Build | 0:6ae2f7bca550 | 244 | if (amqpvalue_get_ulong(amqp_value, &value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 245 | { |
AzureIoTClient | 21:f9c433d8e6ca | 246 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 247 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 248 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 249 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 250 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 251 | long long int_value = value; |
Azure.IoT Build | 0:6ae2f7bca550 | 252 | if ((sprintf(str_value, "%lld", int_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 253 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 254 | { |
AzureIoTClient | 21:f9c433d8e6ca | 255 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 256 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 257 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 258 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 259 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 260 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 261 | case AMQP_TYPE_FLOAT: |
Azure.IoT Build | 0:6ae2f7bca550 | 262 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 263 | float float_value; |
Azure.IoT Build | 0:6ae2f7bca550 | 264 | if (amqpvalue_get_float(amqp_value, &float_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 265 | { |
AzureIoTClient | 21:f9c433d8e6ca | 266 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 267 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 268 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 269 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 270 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 271 | char str_value[25]; |
Azure.IoT Build | 0:6ae2f7bca550 | 272 | if ((snprintf(str_value, sizeof(str_value), "%.02f", float_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 273 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 274 | { |
AzureIoTClient | 21:f9c433d8e6ca | 275 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 276 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 277 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 278 | if (string_concat(&result, str_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 279 | { |
AzureIoTClient | 21:f9c433d8e6ca | 280 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 281 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 282 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 283 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 284 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 285 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 286 | case AMQP_TYPE_DOUBLE: |
Azure.IoT Build | 0:6ae2f7bca550 | 287 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 288 | double double_value; |
Azure.IoT Build | 0:6ae2f7bca550 | 289 | if (amqpvalue_get_double(amqp_value, &double_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 290 | { |
AzureIoTClient | 21:f9c433d8e6ca | 291 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 292 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 293 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 294 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 295 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 296 | char str_value[25]; |
Azure.IoT Build | 0:6ae2f7bca550 | 297 | if ((snprintf(str_value, sizeof(str_value), "%.02lf", double_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 298 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 299 | { |
AzureIoTClient | 21:f9c433d8e6ca | 300 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 301 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 302 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 303 | if (string_concat(&result, str_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 304 | { |
AzureIoTClient | 21:f9c433d8e6ca | 305 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 306 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 307 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 308 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 309 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 310 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 311 | case AMQP_TYPE_CHAR: |
Azure.IoT Build | 0:6ae2f7bca550 | 312 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 313 | uint32_t char_code; |
Azure.IoT Build | 0:6ae2f7bca550 | 314 | if (amqpvalue_get_char(amqp_value, &char_code) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 315 | { |
AzureIoTClient | 21:f9c433d8e6ca | 316 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 317 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 318 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 319 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 320 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 321 | char str_value[25]; |
Azure.IoT Build | 0:6ae2f7bca550 | 322 | if ((snprintf(str_value, sizeof(str_value), "U%02X%02X%02X%02X", char_code >> 24, (char_code >> 16) & 0xFF, (char_code >> 8) & 0xFF, char_code & 0xFF) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 323 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 324 | { |
AzureIoTClient | 21:f9c433d8e6ca | 325 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 326 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 327 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 328 | if (string_concat(&result, str_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 329 | { |
AzureIoTClient | 21:f9c433d8e6ca | 330 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 331 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 332 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 333 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 334 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 335 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 336 | case AMQP_TYPE_TIMESTAMP: |
Azure.IoT Build | 0:6ae2f7bca550 | 337 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 338 | char str_value[21]; |
Azure.IoT Build | 0:6ae2f7bca550 | 339 | int64_t value; |
Azure.IoT Build | 0:6ae2f7bca550 | 340 | if (amqpvalue_get_timestamp(amqp_value, &value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 341 | { |
AzureIoTClient | 21:f9c433d8e6ca | 342 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 343 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 344 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 345 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 346 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 347 | long long int_value = value; |
Azure.IoT Build | 0:6ae2f7bca550 | 348 | if ((sprintf(str_value, "%lld", int_value) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 349 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 350 | { |
AzureIoTClient | 21:f9c433d8e6ca | 351 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 352 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 353 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 354 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 355 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 356 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 357 | case AMQP_TYPE_UUID: |
Azure.IoT Build | 0:6ae2f7bca550 | 358 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 359 | case AMQP_TYPE_BINARY: |
Azure.IoT Build | 0:6ae2f7bca550 | 360 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 361 | amqp_binary binary_value; |
Azure.IoT Build | 0:6ae2f7bca550 | 362 | if (amqpvalue_get_binary(amqp_value, &binary_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 363 | { |
AzureIoTClient | 21:f9c433d8e6ca | 364 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 365 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 366 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 367 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 368 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 369 | if (string_concat(&result, "<") != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 370 | { |
AzureIoTClient | 21:f9c433d8e6ca | 371 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 372 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 373 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 374 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 375 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 376 | uint64_t i; |
Azure.IoT Build | 0:6ae2f7bca550 | 377 | |
Azure.IoT Build | 0:6ae2f7bca550 | 378 | for (i = 0; i < binary_value.length; i++) |
Azure.IoT Build | 0:6ae2f7bca550 | 379 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 380 | char str_value[4]; |
Azure.IoT Build | 0:6ae2f7bca550 | 381 | if ((snprintf(str_value, sizeof(str_value), "%s%02X", (i > 0) ? " " : "", ((unsigned char*)binary_value.bytes)[i]) < 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 382 | (string_concat(&result, str_value) != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 383 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 384 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 385 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 386 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 387 | |
Azure.IoT Build | 0:6ae2f7bca550 | 388 | if (i < binary_value.length) |
Azure.IoT Build | 0:6ae2f7bca550 | 389 | { |
AzureIoTClient | 21:f9c433d8e6ca | 390 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 391 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 392 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 393 | else if (string_concat(&result, ">") != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 394 | { |
AzureIoTClient | 21:f9c433d8e6ca | 395 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 396 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 397 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 398 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 399 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 400 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 401 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 402 | case AMQP_TYPE_STRING: |
Azure.IoT Build | 0:6ae2f7bca550 | 403 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 404 | const char* string_value; |
Azure.IoT Build | 0:6ae2f7bca550 | 405 | if (amqpvalue_get_string(amqp_value, &string_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 406 | { |
AzureIoTClient | 21:f9c433d8e6ca | 407 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 408 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 409 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 410 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 411 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 412 | if (string_concat(&result, string_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 413 | { |
AzureIoTClient | 21:f9c433d8e6ca | 414 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 415 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 416 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 417 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 418 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 419 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 420 | case AMQP_TYPE_SYMBOL: |
Azure.IoT Build | 0:6ae2f7bca550 | 421 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 422 | const char* string_value; |
Azure.IoT Build | 0:6ae2f7bca550 | 423 | if (amqpvalue_get_symbol(amqp_value, &string_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 424 | { |
AzureIoTClient | 21:f9c433d8e6ca | 425 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 426 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 427 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 428 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 429 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 430 | if (string_concat(&result, string_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 431 | { |
AzureIoTClient | 21:f9c433d8e6ca | 432 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 433 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 434 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 435 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 436 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 437 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 438 | case AMQP_TYPE_LIST: |
Azure.IoT Build | 0:6ae2f7bca550 | 439 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 440 | uint32_t count; |
Azure.IoT Build | 0:6ae2f7bca550 | 441 | if ((amqpvalue_get_list_item_count(amqp_value, &count) != 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 442 | (string_concat(&result, "{") != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 443 | { |
AzureIoTClient | 21:f9c433d8e6ca | 444 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 445 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 446 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 447 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 448 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 449 | size_t i; |
Azure.IoT Build | 0:6ae2f7bca550 | 450 | for (i = 0; i < count; i++) |
Azure.IoT Build | 0:6ae2f7bca550 | 451 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 452 | AMQP_VALUE item = amqpvalue_get_list_item(amqp_value, i); |
Azure.IoT Build | 0:6ae2f7bca550 | 453 | if (item == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 454 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 455 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 456 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 457 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 458 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 459 | char* item_string = amqpvalue_to_string(item); |
Azure.IoT Build | 0:6ae2f7bca550 | 460 | if (item_string == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 461 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 462 | amqpvalue_destroy(item); |
Azure.IoT Build | 0:6ae2f7bca550 | 463 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 464 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 465 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 466 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 467 | if ((i > 0) && (string_concat(&result, ",") != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 468 | { |
AzureIoTClient | 21:f9c433d8e6ca | 469 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 470 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 471 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 472 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 473 | else if (string_concat(&result, item_string) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 474 | { |
AzureIoTClient | 21:f9c433d8e6ca | 475 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 476 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 477 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 478 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 479 | |
AzureIoTClient | 21:f9c433d8e6ca | 480 | free(item_string); |
Azure.IoT Build | 0:6ae2f7bca550 | 481 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 482 | |
Azure.IoT Build | 0:6ae2f7bca550 | 483 | amqpvalue_destroy(item); |
Azure.IoT Build | 0:6ae2f7bca550 | 484 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 485 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 486 | |
Azure.IoT Build | 0:6ae2f7bca550 | 487 | if ((i < count) || |
Azure.IoT Build | 0:6ae2f7bca550 | 488 | (string_concat(&result, "}") != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 489 | { |
AzureIoTClient | 21:f9c433d8e6ca | 490 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 491 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 492 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 493 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 494 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 495 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 496 | case AMQP_TYPE_MAP: |
Azure.IoT Build | 0:6ae2f7bca550 | 497 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 498 | uint32_t count; |
Azure.IoT Build | 0:6ae2f7bca550 | 499 | if ((amqpvalue_get_map_pair_count(amqp_value, &count) != 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 500 | (string_concat(&result, "{") != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 501 | { |
AzureIoTClient | 21:f9c433d8e6ca | 502 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 503 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 504 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 505 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 506 | { |
AzureIoTClient | 6:641a9672db08 | 507 | uint32_t i; |
Azure.IoT Build | 0:6ae2f7bca550 | 508 | for (i = 0; i < count; i++) |
Azure.IoT Build | 0:6ae2f7bca550 | 509 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 510 | AMQP_VALUE key; |
Azure.IoT Build | 0:6ae2f7bca550 | 511 | AMQP_VALUE value; |
Azure.IoT Build | 0:6ae2f7bca550 | 512 | if (amqpvalue_get_map_key_value_pair(amqp_value, i, &key, &value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 513 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 514 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 515 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 516 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 517 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 518 | char* key_string = amqpvalue_to_string(key); |
Azure.IoT Build | 0:6ae2f7bca550 | 519 | if (key_string == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 520 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 521 | amqpvalue_destroy(key); |
Azure.IoT Build | 0:6ae2f7bca550 | 522 | amqpvalue_destroy(value); |
Azure.IoT Build | 0:6ae2f7bca550 | 523 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 524 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 525 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 526 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 527 | char* value_string = amqpvalue_to_string(value); |
Azure.IoT Build | 0:6ae2f7bca550 | 528 | if (key_string == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 529 | { |
AzureIoTClient | 21:f9c433d8e6ca | 530 | free(key_string); |
Azure.IoT Build | 0:6ae2f7bca550 | 531 | amqpvalue_destroy(key); |
Azure.IoT Build | 0:6ae2f7bca550 | 532 | amqpvalue_destroy(value); |
Azure.IoT Build | 0:6ae2f7bca550 | 533 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 534 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 535 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 536 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 537 | if (((i > 0) && (string_concat(&result, ",") != 0)) || |
Azure.IoT Build | 0:6ae2f7bca550 | 538 | (string_concat(&result, "[") != 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 539 | (string_concat(&result, key_string) != 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 540 | (string_concat(&result, ":") != 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 541 | (string_concat(&result, value_string) != 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 542 | (string_concat(&result, "]") != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 543 | { |
AzureIoTClient | 21:f9c433d8e6ca | 544 | free(key_string); |
AzureIoTClient | 21:f9c433d8e6ca | 545 | free(value_string); |
Azure.IoT Build | 0:6ae2f7bca550 | 546 | amqpvalue_destroy(key); |
Azure.IoT Build | 0:6ae2f7bca550 | 547 | amqpvalue_destroy(value); |
Azure.IoT Build | 0:6ae2f7bca550 | 548 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 549 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 550 | |
AzureIoTClient | 21:f9c433d8e6ca | 551 | free(value_string); |
Azure.IoT Build | 0:6ae2f7bca550 | 552 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 553 | |
AzureIoTClient | 21:f9c433d8e6ca | 554 | free(key_string); |
Azure.IoT Build | 0:6ae2f7bca550 | 555 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 556 | |
Azure.IoT Build | 0:6ae2f7bca550 | 557 | amqpvalue_destroy(key); |
Azure.IoT Build | 0:6ae2f7bca550 | 558 | amqpvalue_destroy(value); |
Azure.IoT Build | 0:6ae2f7bca550 | 559 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 560 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 561 | |
Azure.IoT Build | 0:6ae2f7bca550 | 562 | if ((i < count) || |
Azure.IoT Build | 0:6ae2f7bca550 | 563 | (string_concat(&result, "}") != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 564 | { |
AzureIoTClient | 21:f9c433d8e6ca | 565 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 566 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 567 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 568 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 569 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 570 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 571 | case AMQP_TYPE_ARRAY: |
Azure.IoT Build | 0:6ae2f7bca550 | 572 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 573 | uint32_t count; |
Azure.IoT Build | 0:6ae2f7bca550 | 574 | if ((amqpvalue_get_array_item_count(amqp_value, &count) != 0) || |
Azure.IoT Build | 0:6ae2f7bca550 | 575 | (string_concat(&result, "{") != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 576 | { |
AzureIoTClient | 21:f9c433d8e6ca | 577 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 578 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 579 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 580 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 581 | { |
AzureIoTClient | 6:641a9672db08 | 582 | uint32_t i; |
Azure.IoT Build | 0:6ae2f7bca550 | 583 | for (i = 0; i < count; i++) |
Azure.IoT Build | 0:6ae2f7bca550 | 584 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 585 | AMQP_VALUE item = amqpvalue_get_array_item(amqp_value, i); |
Azure.IoT Build | 0:6ae2f7bca550 | 586 | if (item == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 587 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 588 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 589 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 590 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 591 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 592 | char* item_string = amqpvalue_to_string(item); |
Azure.IoT Build | 0:6ae2f7bca550 | 593 | if (item_string == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 594 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 595 | amqpvalue_destroy(item); |
Azure.IoT Build | 0:6ae2f7bca550 | 596 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 597 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 598 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 599 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 600 | if ((i > 0) && (string_concat(&result, ",") != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 601 | { |
AzureIoTClient | 21:f9c433d8e6ca | 602 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 603 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 604 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 605 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 606 | else if (string_concat(&result, item_string) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 607 | { |
AzureIoTClient | 21:f9c433d8e6ca | 608 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 609 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 610 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 611 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 612 | |
AzureIoTClient | 21:f9c433d8e6ca | 613 | free(item_string); |
Azure.IoT Build | 0:6ae2f7bca550 | 614 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 615 | |
Azure.IoT Build | 0:6ae2f7bca550 | 616 | amqpvalue_destroy(item); |
Azure.IoT Build | 0:6ae2f7bca550 | 617 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 618 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 619 | |
Azure.IoT Build | 0:6ae2f7bca550 | 620 | if ((i < count) || |
Azure.IoT Build | 0:6ae2f7bca550 | 621 | (string_concat(&result, "}") != 0)) |
Azure.IoT Build | 0:6ae2f7bca550 | 622 | { |
AzureIoTClient | 21:f9c433d8e6ca | 623 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 624 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 625 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 626 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 627 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 628 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 629 | case AMQP_TYPE_COMPOSITE: |
Azure.IoT Build | 0:6ae2f7bca550 | 630 | case AMQP_TYPE_DESCRIBED: |
Azure.IoT Build | 0:6ae2f7bca550 | 631 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 632 | AMQP_VALUE described_value = amqpvalue_get_inplace_described_value(amqp_value); |
Azure.IoT Build | 0:6ae2f7bca550 | 633 | if (described_value == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 634 | { |
AzureIoTClient | 21:f9c433d8e6ca | 635 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 636 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 637 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 638 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 639 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 640 | if (string_concat(&result, "* ") != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 641 | { |
AzureIoTClient | 21:f9c433d8e6ca | 642 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 643 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 644 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 645 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 646 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 647 | char* described_value_string = amqpvalue_to_string(described_value); |
Azure.IoT Build | 0:6ae2f7bca550 | 648 | if (described_value_string == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 649 | { |
AzureIoTClient | 21:f9c433d8e6ca | 650 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 651 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 652 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 653 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 654 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 655 | if (string_concat(&result, described_value_string) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 656 | { |
AzureIoTClient | 21:f9c433d8e6ca | 657 | free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 658 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 659 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 660 | |
AzureIoTClient | 21:f9c433d8e6ca | 661 | free(described_value_string); |
Azure.IoT Build | 0:6ae2f7bca550 | 662 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 663 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 664 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 665 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 666 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 667 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 668 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 669 | |
Azure.IoT Build | 0:6ae2f7bca550 | 670 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 671 | } |