A small memory footprint AMQP implimentation

Dependents:   iothub_client_sample_amqp remote_monitoring simplesample_amqp

Committer:
AzureIoTClient
Date:
Mon May 08 10:50:45 2017 -0700
Revision:
24:2c59c2d43ebf
Parent:
23:1111ee8bcba4
Child:
28:add19eb7defa
1.1.14

Who changed what in which revision?

UserRevisionLine numberNew 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 <string.h>
AzureIoTClient 24:2c59c2d43ebf 6 #include <stdint.h>
AzureIoTClient 19:000ab4e6a2c1 7 #include "azure_c_shared_utility/optimize_size.h"
AzureIoTClient 20:206846c14c80 8 #include "azure_c_shared_utility/gballoc.h"
AzureIoTClient 24:2c59c2d43ebf 9 #include "azure_c_shared_utility/xlogging.h"
Azure.IoT Build 0:6ae2f7bca550 10 #include "azure_uamqp_c/message.h"
Azure.IoT Build 0:6ae2f7bca550 11 #include "azure_uamqp_c/amqpvalue.h"
Azure.IoT Build 0:6ae2f7bca550 12
Azure.IoT Build 0:6ae2f7bca550 13 typedef struct BODY_AMQP_DATA_TAG
Azure.IoT Build 0:6ae2f7bca550 14 {
Azure.IoT Build 0:6ae2f7bca550 15 unsigned char* body_data_section_bytes;
Azure.IoT Build 0:6ae2f7bca550 16 size_t body_data_section_length;
Azure.IoT Build 0:6ae2f7bca550 17 } BODY_AMQP_DATA;
Azure.IoT Build 0:6ae2f7bca550 18
Azure.IoT Build 0:6ae2f7bca550 19 typedef struct MESSAGE_INSTANCE_TAG
Azure.IoT Build 0:6ae2f7bca550 20 {
Azure.IoT Build 0:6ae2f7bca550 21 BODY_AMQP_DATA* body_amqp_data_items;
Azure.IoT Build 0:6ae2f7bca550 22 size_t body_amqp_data_count;
Azure.IoT Build 0:6ae2f7bca550 23 AMQP_VALUE* body_amqp_sequence_items;
Azure.IoT Build 0:6ae2f7bca550 24 size_t body_amqp_sequence_count;
Azure.IoT Build 0:6ae2f7bca550 25 AMQP_VALUE body_amqp_value;
Azure.IoT Build 0:6ae2f7bca550 26 HEADER_HANDLE header;
Azure.IoT Build 0:6ae2f7bca550 27 annotations delivery_annotations;
Azure.IoT Build 0:6ae2f7bca550 28 annotations message_annotations;
Azure.IoT Build 0:6ae2f7bca550 29 PROPERTIES_HANDLE properties;
Azure.IoT Build 0:6ae2f7bca550 30 application_properties application_properties;
Azure.IoT Build 0:6ae2f7bca550 31 annotations footer;
Azure.IoT Build 0:6ae2f7bca550 32 uint32_t message_format;
Azure.IoT Build 0:6ae2f7bca550 33 } MESSAGE_INSTANCE;
Azure.IoT Build 0:6ae2f7bca550 34
AzureIoTClient 24:2c59c2d43ebf 35 static void free_all_body_data_items(MESSAGE_HANDLE message)
Azure.IoT Build 0:6ae2f7bca550 36 {
Azure.IoT Build 0:6ae2f7bca550 37 size_t i;
Azure.IoT Build 0:6ae2f7bca550 38
AzureIoTClient 24:2c59c2d43ebf 39 for (i = 0; i < message->body_amqp_data_count; i++)
Azure.IoT Build 0:6ae2f7bca550 40 {
AzureIoTClient 24:2c59c2d43ebf 41 if (message->body_amqp_data_items[i].body_data_section_bytes != NULL)
Azure.IoT Build 0:6ae2f7bca550 42 {
AzureIoTClient 24:2c59c2d43ebf 43 free(message->body_amqp_data_items[i].body_data_section_bytes);
Azure.IoT Build 0:6ae2f7bca550 44 }
Azure.IoT Build 0:6ae2f7bca550 45 }
Azure.IoT Build 0:6ae2f7bca550 46
AzureIoTClient 24:2c59c2d43ebf 47 free(message->body_amqp_data_items);
AzureIoTClient 24:2c59c2d43ebf 48 message->body_amqp_data_count = 0;
AzureIoTClient 24:2c59c2d43ebf 49 message->body_amqp_data_items = NULL;
Azure.IoT Build 0:6ae2f7bca550 50 }
Azure.IoT Build 0:6ae2f7bca550 51
AzureIoTClient 24:2c59c2d43ebf 52 static void free_all_body_sequence_items(MESSAGE_HANDLE message)
Azure.IoT Build 0:6ae2f7bca550 53 {
Azure.IoT Build 0:6ae2f7bca550 54 size_t i;
Azure.IoT Build 0:6ae2f7bca550 55
AzureIoTClient 24:2c59c2d43ebf 56 for (i = 0; i < message->body_amqp_sequence_count; i++)
Azure.IoT Build 0:6ae2f7bca550 57 {
AzureIoTClient 24:2c59c2d43ebf 58 if (message->body_amqp_sequence_items[i] != NULL)
Azure.IoT Build 0:6ae2f7bca550 59 {
AzureIoTClient 24:2c59c2d43ebf 60 amqpvalue_destroy(message->body_amqp_sequence_items[i]);
Azure.IoT Build 0:6ae2f7bca550 61 }
Azure.IoT Build 0:6ae2f7bca550 62 }
Azure.IoT Build 0:6ae2f7bca550 63
AzureIoTClient 24:2c59c2d43ebf 64 free(message->body_amqp_sequence_items);
AzureIoTClient 24:2c59c2d43ebf 65 message->body_amqp_sequence_count = 0;
AzureIoTClient 24:2c59c2d43ebf 66 message->body_amqp_sequence_items = NULL;
Azure.IoT Build 0:6ae2f7bca550 67 }
Azure.IoT Build 0:6ae2f7bca550 68
Azure.IoT Build 0:6ae2f7bca550 69 MESSAGE_HANDLE message_create(void)
Azure.IoT Build 0:6ae2f7bca550 70 {
AzureIoTClient 24:2c59c2d43ebf 71 MESSAGE_HANDLE result = (MESSAGE_HANDLE)malloc(sizeof(MESSAGE_INSTANCE));
AzureIoTClient 24:2c59c2d43ebf 72 if (result == NULL)
AzureIoTClient 24:2c59c2d43ebf 73 {
AzureIoTClient 24:2c59c2d43ebf 74 /* Codes_SRS_MESSAGE_01_002: [If allocating memory for the message fails, `message_create` shall fail and return NULL.] */
AzureIoTClient 24:2c59c2d43ebf 75 LogError("Cannot allocate memory for message");
AzureIoTClient 24:2c59c2d43ebf 76 }
AzureIoTClient 24:2c59c2d43ebf 77 else
Azure.IoT Build 0:6ae2f7bca550 78 {
Azure.IoT Build 0:6ae2f7bca550 79 result->header = NULL;
Azure.IoT Build 0:6ae2f7bca550 80 result->delivery_annotations = NULL;
Azure.IoT Build 0:6ae2f7bca550 81 result->message_annotations = NULL;
Azure.IoT Build 0:6ae2f7bca550 82 result->properties = NULL;
Azure.IoT Build 0:6ae2f7bca550 83 result->application_properties = NULL;
Azure.IoT Build 0:6ae2f7bca550 84 result->footer = NULL;
Azure.IoT Build 0:6ae2f7bca550 85 result->body_amqp_data_items = NULL;
Azure.IoT Build 0:6ae2f7bca550 86 result->body_amqp_data_count = 0;
Azure.IoT Build 0:6ae2f7bca550 87 result->body_amqp_value = NULL;
Azure.IoT Build 0:6ae2f7bca550 88 result->body_amqp_sequence_items = NULL;
Azure.IoT Build 0:6ae2f7bca550 89 result->body_amqp_sequence_count = 0;
Azure.IoT Build 0:6ae2f7bca550 90 result->message_format = 0;
Azure.IoT Build 0:6ae2f7bca550 91 }
Azure.IoT Build 0:6ae2f7bca550 92
AzureIoTClient 24:2c59c2d43ebf 93 /* Codes_SRS_MESSAGE_01_001: [`message_create` shall create a new AMQP message instance and on success it shall return a non-NULL handle for the newly created message instance.] */
Azure.IoT Build 0:6ae2f7bca550 94 return result;
Azure.IoT Build 0:6ae2f7bca550 95 }
Azure.IoT Build 0:6ae2f7bca550 96
Azure.IoT Build 0:6ae2f7bca550 97 MESSAGE_HANDLE message_clone(MESSAGE_HANDLE source_message)
Azure.IoT Build 0:6ae2f7bca550 98 {
AzureIoTClient 24:2c59c2d43ebf 99 MESSAGE_HANDLE result;
Azure.IoT Build 0:6ae2f7bca550 100
AzureIoTClient 24:2c59c2d43ebf 101 /* Codes_SRS_MESSAGE_01_062: [If `source_message` is NULL, `message_clone` shall fail and return NULL.] */
Azure.IoT Build 0:6ae2f7bca550 102 if (source_message == NULL)
Azure.IoT Build 0:6ae2f7bca550 103 {
AzureIoTClient 24:2c59c2d43ebf 104 LogError("NULL source_message");
Azure.IoT Build 0:6ae2f7bca550 105 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 106 }
Azure.IoT Build 0:6ae2f7bca550 107 else
Azure.IoT Build 0:6ae2f7bca550 108 {
AzureIoTClient 24:2c59c2d43ebf 109 /* Codes_SRS_MESSAGE_01_003: [`message_clone` shall clone a message entirely and on success return a non-NULL handle to the cloned message.] */
AzureIoTClient 24:2c59c2d43ebf 110 result = (MESSAGE_HANDLE)message_create();
AzureIoTClient 24:2c59c2d43ebf 111 if (result == NULL)
Azure.IoT Build 0:6ae2f7bca550 112 {
AzureIoTClient 24:2c59c2d43ebf 113 /* Codes_SRS_MESSAGE_01_004: [If allocating memory for the new cloned message fails, `message_clone` shall fail and return NULL.] */
AzureIoTClient 24:2c59c2d43ebf 114 LogError("Cannot clone message");
AzureIoTClient 24:2c59c2d43ebf 115 }
AzureIoTClient 24:2c59c2d43ebf 116 else
AzureIoTClient 24:2c59c2d43ebf 117 {
AzureIoTClient 24:2c59c2d43ebf 118 result->message_format = source_message->message_format;
Azure.IoT Build 0:6ae2f7bca550 119
AzureIoTClient 24:2c59c2d43ebf 120 if (source_message->header != NULL)
Azure.IoT Build 0:6ae2f7bca550 121 {
AzureIoTClient 24:2c59c2d43ebf 122 /* Codes_SRS_MESSAGE_01_005: [If a header exists on the source message it shall be cloned by using `header_clone`.] */
AzureIoTClient 24:2c59c2d43ebf 123 result->header = header_clone(source_message->header);
Azure.IoT Build 0:6ae2f7bca550 124 if (result->header == NULL)
Azure.IoT Build 0:6ae2f7bca550 125 {
AzureIoTClient 24:2c59c2d43ebf 126 LogError("Cannot clone message header");
Azure.IoT Build 0:6ae2f7bca550 127 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 128 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 129 }
Azure.IoT Build 0:6ae2f7bca550 130 }
Azure.IoT Build 0:6ae2f7bca550 131
AzureIoTClient 24:2c59c2d43ebf 132 if ((result != NULL) && (source_message->delivery_annotations != NULL))
Azure.IoT Build 0:6ae2f7bca550 133 {
AzureIoTClient 24:2c59c2d43ebf 134 /* Codes_SRS_MESSAGE_01_006: [If delivery annotations exist on the source message they shall be cloned by using `annotations_clone`.] */
AzureIoTClient 24:2c59c2d43ebf 135 result->delivery_annotations = annotations_clone(source_message->delivery_annotations);
Azure.IoT Build 0:6ae2f7bca550 136 if (result->delivery_annotations == NULL)
Azure.IoT Build 0:6ae2f7bca550 137 {
AzureIoTClient 24:2c59c2d43ebf 138 LogError("Cannot clone delivery annotations");
Azure.IoT Build 0:6ae2f7bca550 139 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 140 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 141 }
Azure.IoT Build 0:6ae2f7bca550 142 }
Azure.IoT Build 0:6ae2f7bca550 143
AzureIoTClient 24:2c59c2d43ebf 144 if ((result != NULL) && (source_message->message_annotations != NULL))
Azure.IoT Build 0:6ae2f7bca550 145 {
AzureIoTClient 24:2c59c2d43ebf 146 /* Codes_SRS_MESSAGE_01_007: [If message annotations exist on the source message they shall be cloned by using `annotations_clone`.] */
AzureIoTClient 24:2c59c2d43ebf 147 result->message_annotations = annotations_clone(source_message->message_annotations);
Azure.IoT Build 0:6ae2f7bca550 148 if (result->message_annotations == NULL)
Azure.IoT Build 0:6ae2f7bca550 149 {
AzureIoTClient 24:2c59c2d43ebf 150 LogError("Cannot clone message annotations");
Azure.IoT Build 0:6ae2f7bca550 151 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 152 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 153 }
Azure.IoT Build 0:6ae2f7bca550 154 }
Azure.IoT Build 0:6ae2f7bca550 155
AzureIoTClient 24:2c59c2d43ebf 156 if ((result != NULL) && (source_message->properties != NULL))
Azure.IoT Build 0:6ae2f7bca550 157 {
AzureIoTClient 24:2c59c2d43ebf 158 /* Codes_SRS_MESSAGE_01_008: [If message properties exist on the source message they shall be cloned by using `properties_clone`.] */
AzureIoTClient 24:2c59c2d43ebf 159 result->properties = properties_clone(source_message->properties);
Azure.IoT Build 0:6ae2f7bca550 160 if (result->properties == NULL)
Azure.IoT Build 0:6ae2f7bca550 161 {
AzureIoTClient 24:2c59c2d43ebf 162 LogError("Cannot clone message properties");
Azure.IoT Build 0:6ae2f7bca550 163 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 164 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 165 }
Azure.IoT Build 0:6ae2f7bca550 166 }
Azure.IoT Build 0:6ae2f7bca550 167
AzureIoTClient 24:2c59c2d43ebf 168 if ((result != NULL) && (source_message->application_properties != NULL))
Azure.IoT Build 0:6ae2f7bca550 169 {
AzureIoTClient 24:2c59c2d43ebf 170 /* Codes_SRS_MESSAGE_01_009: [If application properties exist on the source message they shall be cloned by using `amqpvalue_clone`.] */
AzureIoTClient 24:2c59c2d43ebf 171 result->application_properties = amqpvalue_clone(source_message->application_properties);
Azure.IoT Build 0:6ae2f7bca550 172 if (result->application_properties == NULL)
Azure.IoT Build 0:6ae2f7bca550 173 {
AzureIoTClient 24:2c59c2d43ebf 174 LogError("Cannot clone application annotations");
Azure.IoT Build 0:6ae2f7bca550 175 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 176 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 177 }
Azure.IoT Build 0:6ae2f7bca550 178 }
Azure.IoT Build 0:6ae2f7bca550 179
AzureIoTClient 24:2c59c2d43ebf 180 if ((result != NULL) && (source_message->footer != NULL))
Azure.IoT Build 0:6ae2f7bca550 181 {
AzureIoTClient 24:2c59c2d43ebf 182 /* Codes_SRS_MESSAGE_01_010: [If a footer exists on the source message it shall be cloned by using `annotations_clone`.] */
AzureIoTClient 24:2c59c2d43ebf 183 result->footer = amqpvalue_clone(source_message->footer);
Azure.IoT Build 0:6ae2f7bca550 184 if (result->footer == NULL)
Azure.IoT Build 0:6ae2f7bca550 185 {
AzureIoTClient 24:2c59c2d43ebf 186 LogError("Cannot clone message footer");
Azure.IoT Build 0:6ae2f7bca550 187 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 188 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 189 }
Azure.IoT Build 0:6ae2f7bca550 190 }
Azure.IoT Build 0:6ae2f7bca550 191
AzureIoTClient 24:2c59c2d43ebf 192 if ((result != NULL) && (source_message->body_amqp_data_count > 0))
Azure.IoT Build 0:6ae2f7bca550 193 {
Azure.IoT Build 0:6ae2f7bca550 194 size_t i;
Azure.IoT Build 0:6ae2f7bca550 195
AzureIoTClient 24:2c59c2d43ebf 196 result->body_amqp_data_items = (BODY_AMQP_DATA*)malloc(source_message->body_amqp_data_count * sizeof(BODY_AMQP_DATA));
Azure.IoT Build 0:6ae2f7bca550 197 if (result->body_amqp_data_items == NULL)
Azure.IoT Build 0:6ae2f7bca550 198 {
AzureIoTClient 24:2c59c2d43ebf 199 LogError("Cannot allocate memory for body data sections");
Azure.IoT Build 0:6ae2f7bca550 200 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 201 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 202 }
Azure.IoT Build 0:6ae2f7bca550 203 else
Azure.IoT Build 0:6ae2f7bca550 204 {
AzureIoTClient 24:2c59c2d43ebf 205 for (i = 0; i < source_message->body_amqp_data_count; i++)
Azure.IoT Build 0:6ae2f7bca550 206 {
AzureIoTClient 24:2c59c2d43ebf 207 result->body_amqp_data_items[i].body_data_section_length = source_message->body_amqp_data_items[i].body_data_section_length;
Azure.IoT Build 0:6ae2f7bca550 208
Azure.IoT Build 0:6ae2f7bca550 209 /* Codes_SRS_MESSAGE_01_011: [If an AMQP data has been set as message body on the source message it shall be cloned by allocating memory for the binary payload.] */
AzureIoTClient 24:2c59c2d43ebf 210 result->body_amqp_data_items[i].body_data_section_bytes = (unsigned char*)malloc(source_message->body_amqp_data_items[i].body_data_section_length);
Azure.IoT Build 0:6ae2f7bca550 211 if (result->body_amqp_data_items[i].body_data_section_bytes == NULL)
Azure.IoT Build 0:6ae2f7bca550 212 {
AzureIoTClient 24:2c59c2d43ebf 213 LogError("Cannot allocate memory for body data section %u", (unsigned int)i);
Azure.IoT Build 0:6ae2f7bca550 214 break;
Azure.IoT Build 0:6ae2f7bca550 215 }
Azure.IoT Build 0:6ae2f7bca550 216 else
Azure.IoT Build 0:6ae2f7bca550 217 {
AzureIoTClient 24:2c59c2d43ebf 218 (void)memcpy(result->body_amqp_data_items[i].body_data_section_bytes, source_message->body_amqp_data_items[i].body_data_section_bytes, result->body_amqp_data_items[i].body_data_section_length);
Azure.IoT Build 0:6ae2f7bca550 219 }
Azure.IoT Build 0:6ae2f7bca550 220 }
Azure.IoT Build 0:6ae2f7bca550 221
Azure.IoT Build 0:6ae2f7bca550 222 result->body_amqp_data_count = i;
AzureIoTClient 24:2c59c2d43ebf 223 if (i < source_message->body_amqp_data_count)
Azure.IoT Build 0:6ae2f7bca550 224 {
Azure.IoT Build 0:6ae2f7bca550 225 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 226 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 227 }
Azure.IoT Build 0:6ae2f7bca550 228 }
Azure.IoT Build 0:6ae2f7bca550 229 }
Azure.IoT Build 0:6ae2f7bca550 230
AzureIoTClient 24:2c59c2d43ebf 231 if ((result != NULL) && (source_message->body_amqp_sequence_count > 0))
Azure.IoT Build 0:6ae2f7bca550 232 {
Azure.IoT Build 0:6ae2f7bca550 233 size_t i;
Azure.IoT Build 0:6ae2f7bca550 234
AzureIoTClient 24:2c59c2d43ebf 235 result->body_amqp_sequence_items = (AMQP_VALUE*)malloc(source_message->body_amqp_sequence_count * sizeof(AMQP_VALUE));
Azure.IoT Build 0:6ae2f7bca550 236 if (result->body_amqp_sequence_items == NULL)
Azure.IoT Build 0:6ae2f7bca550 237 {
AzureIoTClient 24:2c59c2d43ebf 238 LogError("Cannot allocate memory for body AMQP sequences");
Azure.IoT Build 0:6ae2f7bca550 239 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 240 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 241 }
Azure.IoT Build 0:6ae2f7bca550 242 else
Azure.IoT Build 0:6ae2f7bca550 243 {
AzureIoTClient 24:2c59c2d43ebf 244 for (i = 0; i < source_message->body_amqp_sequence_count; i++)
Azure.IoT Build 0:6ae2f7bca550 245 {
Azure.IoT Build 0:6ae2f7bca550 246 /* Codes_SRS_MESSAGE_01_011: [If an AMQP data has been set as message body on the source message it shall be cloned by allocating memory for the binary payload.] */
AzureIoTClient 24:2c59c2d43ebf 247 result->body_amqp_sequence_items[i] = amqpvalue_clone(source_message->body_amqp_sequence_items[i]);
Azure.IoT Build 0:6ae2f7bca550 248 if (result->body_amqp_sequence_items[i] == NULL)
Azure.IoT Build 0:6ae2f7bca550 249 {
AzureIoTClient 24:2c59c2d43ebf 250 LogError("Cannot clone AMQP sequence %u", (unsigned int)i);
Azure.IoT Build 0:6ae2f7bca550 251 break;
Azure.IoT Build 0:6ae2f7bca550 252 }
Azure.IoT Build 0:6ae2f7bca550 253 }
Azure.IoT Build 0:6ae2f7bca550 254
Azure.IoT Build 0:6ae2f7bca550 255 result->body_amqp_sequence_count = i;
AzureIoTClient 24:2c59c2d43ebf 256 if (i < source_message->body_amqp_sequence_count)
Azure.IoT Build 0:6ae2f7bca550 257 {
Azure.IoT Build 0:6ae2f7bca550 258 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 259 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 260 }
Azure.IoT Build 0:6ae2f7bca550 261 }
Azure.IoT Build 0:6ae2f7bca550 262 }
Azure.IoT Build 0:6ae2f7bca550 263
AzureIoTClient 24:2c59c2d43ebf 264 if ((result != NULL) && (source_message->body_amqp_value != NULL))
Azure.IoT Build 0:6ae2f7bca550 265 {
AzureIoTClient 24:2c59c2d43ebf 266 result->body_amqp_value = amqpvalue_clone(source_message->body_amqp_value);
Azure.IoT Build 0:6ae2f7bca550 267 if (result->body_amqp_value == NULL)
Azure.IoT Build 0:6ae2f7bca550 268 {
AzureIoTClient 24:2c59c2d43ebf 269 LogError("Cannot clone body AMQP value");
Azure.IoT Build 0:6ae2f7bca550 270 message_destroy(result);
Azure.IoT Build 0:6ae2f7bca550 271 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 272 }
Azure.IoT Build 0:6ae2f7bca550 273 }
Azure.IoT Build 0:6ae2f7bca550 274 }
Azure.IoT Build 0:6ae2f7bca550 275 }
Azure.IoT Build 0:6ae2f7bca550 276
Azure.IoT Build 0:6ae2f7bca550 277 return result;
Azure.IoT Build 0:6ae2f7bca550 278 }
Azure.IoT Build 0:6ae2f7bca550 279
Azure.IoT Build 0:6ae2f7bca550 280 void message_destroy(MESSAGE_HANDLE message)
Azure.IoT Build 0:6ae2f7bca550 281 {
AzureIoTClient 24:2c59c2d43ebf 282 if (message == NULL)
Azure.IoT Build 0:6ae2f7bca550 283 {
AzureIoTClient 24:2c59c2d43ebf 284 LogError("NULL message");
AzureIoTClient 24:2c59c2d43ebf 285 }
AzureIoTClient 24:2c59c2d43ebf 286 else
AzureIoTClient 24:2c59c2d43ebf 287 {
AzureIoTClient 24:2c59c2d43ebf 288 if (message->header != NULL)
Azure.IoT Build 0:6ae2f7bca550 289 {
AzureIoTClient 24:2c59c2d43ebf 290 header_destroy(message->header);
Azure.IoT Build 0:6ae2f7bca550 291 }
AzureIoTClient 24:2c59c2d43ebf 292 if (message->properties != NULL)
Azure.IoT Build 0:6ae2f7bca550 293 {
AzureIoTClient 24:2c59c2d43ebf 294 properties_destroy(message->properties);
Azure.IoT Build 0:6ae2f7bca550 295 }
AzureIoTClient 24:2c59c2d43ebf 296 if (message->application_properties != NULL)
Azure.IoT Build 0:6ae2f7bca550 297 {
AzureIoTClient 24:2c59c2d43ebf 298 application_properties_destroy(message->application_properties);
Azure.IoT Build 0:6ae2f7bca550 299 }
AzureIoTClient 24:2c59c2d43ebf 300 if (message->footer != NULL)
Azure.IoT Build 0:6ae2f7bca550 301 {
AzureIoTClient 24:2c59c2d43ebf 302 annotations_destroy(message->footer);
Azure.IoT Build 0:6ae2f7bca550 303 }
AzureIoTClient 24:2c59c2d43ebf 304 if (message->body_amqp_value != NULL)
AzureIoTClient 24:2c59c2d43ebf 305 {
AzureIoTClient 24:2c59c2d43ebf 306 amqpvalue_destroy(message->body_amqp_value);
AzureIoTClient 24:2c59c2d43ebf 307 }
AzureIoTClient 24:2c59c2d43ebf 308 if (message->message_annotations != NULL)
Azure.IoT Build 0:6ae2f7bca550 309 {
AzureIoTClient 24:2c59c2d43ebf 310 application_properties_destroy(message->message_annotations);
Azure.IoT Build 0:6ae2f7bca550 311 }
Azure.IoT Build 0:6ae2f7bca550 312
AzureIoTClient 24:2c59c2d43ebf 313 free_all_body_data_items(message);
AzureIoTClient 24:2c59c2d43ebf 314 free_all_body_sequence_items(message);
AzureIoTClient 24:2c59c2d43ebf 315 free(message);
Azure.IoT Build 0:6ae2f7bca550 316 }
Azure.IoT Build 0:6ae2f7bca550 317 }
Azure.IoT Build 0:6ae2f7bca550 318
Azure.IoT Build 0:6ae2f7bca550 319 int message_set_header(MESSAGE_HANDLE message, HEADER_HANDLE header)
Azure.IoT Build 0:6ae2f7bca550 320 {
Azure.IoT Build 0:6ae2f7bca550 321 int result;
Azure.IoT Build 0:6ae2f7bca550 322
Azure.IoT Build 0:6ae2f7bca550 323 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 324 (header == NULL))
Azure.IoT Build 0:6ae2f7bca550 325 {
AzureIoTClient 24:2c59c2d43ebf 326 LogError("Bad arguments: message = %p, header = %p",
AzureIoTClient 24:2c59c2d43ebf 327 message, header);
AzureIoTClient 19:000ab4e6a2c1 328 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 329 }
Azure.IoT Build 0:6ae2f7bca550 330 else
Azure.IoT Build 0:6ae2f7bca550 331 {
Azure.IoT Build 0:6ae2f7bca550 332 HEADER_HANDLE new_header;
Azure.IoT Build 0:6ae2f7bca550 333
Azure.IoT Build 0:6ae2f7bca550 334 new_header = header_clone(header);
Azure.IoT Build 0:6ae2f7bca550 335 if (new_header == NULL)
Azure.IoT Build 0:6ae2f7bca550 336 {
AzureIoTClient 24:2c59c2d43ebf 337 LogError("Cannot clone message header");
AzureIoTClient 19:000ab4e6a2c1 338 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 339 }
Azure.IoT Build 0:6ae2f7bca550 340 else
Azure.IoT Build 0:6ae2f7bca550 341 {
AzureIoTClient 24:2c59c2d43ebf 342 if (message->header != NULL)
Azure.IoT Build 0:6ae2f7bca550 343 {
AzureIoTClient 24:2c59c2d43ebf 344 header_destroy(message->header);
Azure.IoT Build 0:6ae2f7bca550 345 }
Azure.IoT Build 0:6ae2f7bca550 346
AzureIoTClient 24:2c59c2d43ebf 347 message->header = new_header;
Azure.IoT Build 0:6ae2f7bca550 348 result = 0;
Azure.IoT Build 0:6ae2f7bca550 349 }
Azure.IoT Build 0:6ae2f7bca550 350 }
Azure.IoT Build 0:6ae2f7bca550 351
Azure.IoT Build 0:6ae2f7bca550 352 return result;
Azure.IoT Build 0:6ae2f7bca550 353 }
Azure.IoT Build 0:6ae2f7bca550 354
Azure.IoT Build 0:6ae2f7bca550 355 int message_get_header(MESSAGE_HANDLE message, HEADER_HANDLE* header)
Azure.IoT Build 0:6ae2f7bca550 356 {
Azure.IoT Build 0:6ae2f7bca550 357 int result;
Azure.IoT Build 0:6ae2f7bca550 358
Azure.IoT Build 0:6ae2f7bca550 359 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 360 (header == NULL))
Azure.IoT Build 0:6ae2f7bca550 361 {
AzureIoTClient 24:2c59c2d43ebf 362 LogError("Bad arguments: message = %p, header = %p",
AzureIoTClient 24:2c59c2d43ebf 363 message, header);
AzureIoTClient 19:000ab4e6a2c1 364 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 365 }
Azure.IoT Build 0:6ae2f7bca550 366 else
Azure.IoT Build 0:6ae2f7bca550 367 {
AzureIoTClient 24:2c59c2d43ebf 368 if (message->header == NULL)
Azure.IoT Build 0:6ae2f7bca550 369 {
Azure.IoT Build 0:6ae2f7bca550 370 *header = NULL;
Azure.IoT Build 0:6ae2f7bca550 371 result = 0;
Azure.IoT Build 0:6ae2f7bca550 372 }
Azure.IoT Build 0:6ae2f7bca550 373 else
Azure.IoT Build 0:6ae2f7bca550 374 {
AzureIoTClient 24:2c59c2d43ebf 375 *header = header_clone(message->header);
Azure.IoT Build 0:6ae2f7bca550 376 if (*header == NULL)
Azure.IoT Build 0:6ae2f7bca550 377 {
AzureIoTClient 24:2c59c2d43ebf 378 LogError("Cannot clone message header");
AzureIoTClient 19:000ab4e6a2c1 379 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 380 }
Azure.IoT Build 0:6ae2f7bca550 381 else
Azure.IoT Build 0:6ae2f7bca550 382 {
Azure.IoT Build 0:6ae2f7bca550 383 result = 0;
Azure.IoT Build 0:6ae2f7bca550 384 }
Azure.IoT Build 0:6ae2f7bca550 385 }
Azure.IoT Build 0:6ae2f7bca550 386 }
Azure.IoT Build 0:6ae2f7bca550 387
Azure.IoT Build 0:6ae2f7bca550 388 return result;
Azure.IoT Build 0:6ae2f7bca550 389 }
Azure.IoT Build 0:6ae2f7bca550 390
Azure.IoT Build 0:6ae2f7bca550 391 int message_set_delivery_annotations(MESSAGE_HANDLE message, annotations delivery_annotations)
Azure.IoT Build 0:6ae2f7bca550 392 {
Azure.IoT Build 0:6ae2f7bca550 393 int result;
Azure.IoT Build 0:6ae2f7bca550 394
Azure.IoT Build 0:6ae2f7bca550 395 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 396 (delivery_annotations == NULL))
Azure.IoT Build 0:6ae2f7bca550 397 {
AzureIoTClient 24:2c59c2d43ebf 398 LogError("Bad arguments: message = %p, delivery_annotations = %p",
AzureIoTClient 24:2c59c2d43ebf 399 message, delivery_annotations);
AzureIoTClient 19:000ab4e6a2c1 400 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 401 }
Azure.IoT Build 0:6ae2f7bca550 402 else
Azure.IoT Build 0:6ae2f7bca550 403 {
Azure.IoT Build 0:6ae2f7bca550 404 annotations new_delivery_annotations;
Azure.IoT Build 0:6ae2f7bca550 405
Azure.IoT Build 0:6ae2f7bca550 406 new_delivery_annotations = annotations_clone(delivery_annotations);
Azure.IoT Build 0:6ae2f7bca550 407 if (new_delivery_annotations == NULL)
Azure.IoT Build 0:6ae2f7bca550 408 {
AzureIoTClient 24:2c59c2d43ebf 409 LogError("Cannot clone delivery annotations");
AzureIoTClient 19:000ab4e6a2c1 410 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 411 }
Azure.IoT Build 0:6ae2f7bca550 412 else
Azure.IoT Build 0:6ae2f7bca550 413 {
AzureIoTClient 24:2c59c2d43ebf 414 if (message->delivery_annotations != NULL)
Azure.IoT Build 0:6ae2f7bca550 415 {
AzureIoTClient 24:2c59c2d43ebf 416 annotations_destroy(message->delivery_annotations);
Azure.IoT Build 0:6ae2f7bca550 417 }
AzureIoTClient 24:2c59c2d43ebf 418
AzureIoTClient 24:2c59c2d43ebf 419 message->delivery_annotations = new_delivery_annotations;
Azure.IoT Build 0:6ae2f7bca550 420 result = 0;
Azure.IoT Build 0:6ae2f7bca550 421 }
Azure.IoT Build 0:6ae2f7bca550 422 }
Azure.IoT Build 0:6ae2f7bca550 423
Azure.IoT Build 0:6ae2f7bca550 424 return result;
Azure.IoT Build 0:6ae2f7bca550 425 }
Azure.IoT Build 0:6ae2f7bca550 426
Azure.IoT Build 0:6ae2f7bca550 427 int message_get_delivery_annotations(MESSAGE_HANDLE message, annotations* delivery_annotations)
Azure.IoT Build 0:6ae2f7bca550 428 {
Azure.IoT Build 0:6ae2f7bca550 429 int result;
Azure.IoT Build 0:6ae2f7bca550 430
Azure.IoT Build 0:6ae2f7bca550 431 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 432 (delivery_annotations == NULL))
Azure.IoT Build 0:6ae2f7bca550 433 {
AzureIoTClient 24:2c59c2d43ebf 434 LogError("Bad arguments: message = %p, delivery_annotations = %p",
AzureIoTClient 24:2c59c2d43ebf 435 message, delivery_annotations);
AzureIoTClient 19:000ab4e6a2c1 436 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 437 }
Azure.IoT Build 0:6ae2f7bca550 438 else
Azure.IoT Build 0:6ae2f7bca550 439 {
AzureIoTClient 24:2c59c2d43ebf 440 if (message->delivery_annotations == NULL)
Azure.IoT Build 0:6ae2f7bca550 441 {
Azure.IoT Build 0:6ae2f7bca550 442 *delivery_annotations = NULL;
Azure.IoT Build 0:6ae2f7bca550 443 result = 0;
Azure.IoT Build 0:6ae2f7bca550 444 }
Azure.IoT Build 0:6ae2f7bca550 445 else
Azure.IoT Build 0:6ae2f7bca550 446 {
AzureIoTClient 24:2c59c2d43ebf 447 *delivery_annotations = annotations_clone(message->delivery_annotations);
Azure.IoT Build 0:6ae2f7bca550 448 if (*delivery_annotations == NULL)
Azure.IoT Build 0:6ae2f7bca550 449 {
AzureIoTClient 24:2c59c2d43ebf 450 LogError("Cannot clone delivery annotations");
AzureIoTClient 19:000ab4e6a2c1 451 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 452 }
Azure.IoT Build 0:6ae2f7bca550 453 else
Azure.IoT Build 0:6ae2f7bca550 454 {
Azure.IoT Build 0:6ae2f7bca550 455 result = 0;
Azure.IoT Build 0:6ae2f7bca550 456 }
Azure.IoT Build 0:6ae2f7bca550 457 }
Azure.IoT Build 0:6ae2f7bca550 458 }
Azure.IoT Build 0:6ae2f7bca550 459
Azure.IoT Build 0:6ae2f7bca550 460 return result;
Azure.IoT Build 0:6ae2f7bca550 461 }
Azure.IoT Build 0:6ae2f7bca550 462
Azure.IoT Build 0:6ae2f7bca550 463 int message_set_message_annotations(MESSAGE_HANDLE message, annotations message_annotations)
Azure.IoT Build 0:6ae2f7bca550 464 {
Azure.IoT Build 0:6ae2f7bca550 465 int result;
Azure.IoT Build 0:6ae2f7bca550 466
Azure.IoT Build 0:6ae2f7bca550 467 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 468 (message_annotations == NULL))
Azure.IoT Build 0:6ae2f7bca550 469 {
AzureIoTClient 24:2c59c2d43ebf 470 LogError("Bad arguments: message = %p, message_annotations = %p",
AzureIoTClient 24:2c59c2d43ebf 471 message, message_annotations);
AzureIoTClient 19:000ab4e6a2c1 472 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 473 }
Azure.IoT Build 0:6ae2f7bca550 474 else
Azure.IoT Build 0:6ae2f7bca550 475 {
Azure.IoT Build 0:6ae2f7bca550 476 annotations new_message_annotations;
Azure.IoT Build 0:6ae2f7bca550 477
Azure.IoT Build 0:6ae2f7bca550 478 new_message_annotations = annotations_clone(message_annotations);
Azure.IoT Build 0:6ae2f7bca550 479 if (new_message_annotations == NULL)
Azure.IoT Build 0:6ae2f7bca550 480 {
AzureIoTClient 24:2c59c2d43ebf 481 LogError("Cannot clone message annotations");
AzureIoTClient 19:000ab4e6a2c1 482 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 483 }
Azure.IoT Build 0:6ae2f7bca550 484 else
Azure.IoT Build 0:6ae2f7bca550 485 {
AzureIoTClient 24:2c59c2d43ebf 486 if (message->message_annotations != NULL)
Azure.IoT Build 0:6ae2f7bca550 487 {
AzureIoTClient 24:2c59c2d43ebf 488 annotations_destroy(message->message_annotations);
Azure.IoT Build 0:6ae2f7bca550 489 }
Azure.IoT Build 0:6ae2f7bca550 490
AzureIoTClient 24:2c59c2d43ebf 491 message->message_annotations = new_message_annotations;
Azure.IoT Build 0:6ae2f7bca550 492 result = 0;
Azure.IoT Build 0:6ae2f7bca550 493 }
Azure.IoT Build 0:6ae2f7bca550 494 }
Azure.IoT Build 0:6ae2f7bca550 495
Azure.IoT Build 0:6ae2f7bca550 496 return result;
Azure.IoT Build 0:6ae2f7bca550 497 }
Azure.IoT Build 0:6ae2f7bca550 498
Azure.IoT Build 0:6ae2f7bca550 499 int message_get_message_annotations(MESSAGE_HANDLE message, annotations* message_annotations)
Azure.IoT Build 0:6ae2f7bca550 500 {
Azure.IoT Build 0:6ae2f7bca550 501 int result;
Azure.IoT Build 0:6ae2f7bca550 502
Azure.IoT Build 0:6ae2f7bca550 503 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 504 (message_annotations == NULL))
Azure.IoT Build 0:6ae2f7bca550 505 {
AzureIoTClient 24:2c59c2d43ebf 506 LogError("Bad arguments: message = %p, message_annotations = %p",
AzureIoTClient 24:2c59c2d43ebf 507 message, message_annotations);
AzureIoTClient 19:000ab4e6a2c1 508 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 509 }
Azure.IoT Build 0:6ae2f7bca550 510 else
Azure.IoT Build 0:6ae2f7bca550 511 {
AzureIoTClient 24:2c59c2d43ebf 512 if (message->message_annotations == NULL)
Azure.IoT Build 0:6ae2f7bca550 513 {
Azure.IoT Build 0:6ae2f7bca550 514 *message_annotations = NULL;
Azure.IoT Build 0:6ae2f7bca550 515 result = 0;
Azure.IoT Build 0:6ae2f7bca550 516 }
Azure.IoT Build 0:6ae2f7bca550 517 else
Azure.IoT Build 0:6ae2f7bca550 518 {
AzureIoTClient 24:2c59c2d43ebf 519 *message_annotations = annotations_clone(message->message_annotations);
Azure.IoT Build 0:6ae2f7bca550 520 if (*message_annotations == NULL)
Azure.IoT Build 0:6ae2f7bca550 521 {
AzureIoTClient 24:2c59c2d43ebf 522 LogError("Cannot clone message annotations");
AzureIoTClient 19:000ab4e6a2c1 523 result = __FAILURE__;
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 result = 0;
Azure.IoT Build 0:6ae2f7bca550 528 }
Azure.IoT Build 0:6ae2f7bca550 529 }
Azure.IoT Build 0:6ae2f7bca550 530 }
Azure.IoT Build 0:6ae2f7bca550 531
Azure.IoT Build 0:6ae2f7bca550 532 return result;
Azure.IoT Build 0:6ae2f7bca550 533 }
Azure.IoT Build 0:6ae2f7bca550 534
Azure.IoT Build 0:6ae2f7bca550 535 int message_set_properties(MESSAGE_HANDLE message, PROPERTIES_HANDLE properties)
Azure.IoT Build 0:6ae2f7bca550 536 {
Azure.IoT Build 0:6ae2f7bca550 537 int result;
Azure.IoT Build 0:6ae2f7bca550 538
Azure.IoT Build 0:6ae2f7bca550 539 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 540 (properties == NULL))
Azure.IoT Build 0:6ae2f7bca550 541 {
AzureIoTClient 24:2c59c2d43ebf 542 LogError("Bad arguments: message = %p, properties = %p",
AzureIoTClient 24:2c59c2d43ebf 543 message, properties);
AzureIoTClient 19:000ab4e6a2c1 544 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 545 }
Azure.IoT Build 0:6ae2f7bca550 546 else
Azure.IoT Build 0:6ae2f7bca550 547 {
Azure.IoT Build 0:6ae2f7bca550 548 PROPERTIES_HANDLE new_properties;
Azure.IoT Build 0:6ae2f7bca550 549
Azure.IoT Build 0:6ae2f7bca550 550 new_properties = properties_clone(properties);
Azure.IoT Build 0:6ae2f7bca550 551 if (new_properties == NULL)
Azure.IoT Build 0:6ae2f7bca550 552 {
AzureIoTClient 24:2c59c2d43ebf 553 LogError("Cannot clone message properties");
AzureIoTClient 19:000ab4e6a2c1 554 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 555 }
Azure.IoT Build 0:6ae2f7bca550 556 else
Azure.IoT Build 0:6ae2f7bca550 557 {
AzureIoTClient 24:2c59c2d43ebf 558 if (message->properties != NULL)
Azure.IoT Build 0:6ae2f7bca550 559 {
AzureIoTClient 24:2c59c2d43ebf 560 properties_destroy(message->properties);
Azure.IoT Build 0:6ae2f7bca550 561 }
Azure.IoT Build 0:6ae2f7bca550 562
AzureIoTClient 24:2c59c2d43ebf 563 message->properties = new_properties;
Azure.IoT Build 0:6ae2f7bca550 564 result = 0;
Azure.IoT Build 0:6ae2f7bca550 565 }
Azure.IoT Build 0:6ae2f7bca550 566 }
Azure.IoT Build 0:6ae2f7bca550 567
Azure.IoT Build 0:6ae2f7bca550 568 return result;
Azure.IoT Build 0:6ae2f7bca550 569 }
Azure.IoT Build 0:6ae2f7bca550 570
Azure.IoT Build 0:6ae2f7bca550 571 int message_get_properties(MESSAGE_HANDLE message, PROPERTIES_HANDLE* properties)
Azure.IoT Build 0:6ae2f7bca550 572 {
Azure.IoT Build 0:6ae2f7bca550 573 int result;
Azure.IoT Build 0:6ae2f7bca550 574
Azure.IoT Build 0:6ae2f7bca550 575 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 576 (properties == NULL))
Azure.IoT Build 0:6ae2f7bca550 577 {
AzureIoTClient 24:2c59c2d43ebf 578 LogError("Bad arguments: message = %p, properties = %p",
AzureIoTClient 24:2c59c2d43ebf 579 message, properties);
AzureIoTClient 19:000ab4e6a2c1 580 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 581 }
Azure.IoT Build 0:6ae2f7bca550 582 else
Azure.IoT Build 0:6ae2f7bca550 583 {
AzureIoTClient 24:2c59c2d43ebf 584 if (message->properties == NULL)
Azure.IoT Build 0:6ae2f7bca550 585 {
Azure.IoT Build 0:6ae2f7bca550 586 *properties = NULL;
Azure.IoT Build 0:6ae2f7bca550 587 result = 0;
Azure.IoT Build 0:6ae2f7bca550 588 }
Azure.IoT Build 0:6ae2f7bca550 589 else
Azure.IoT Build 0:6ae2f7bca550 590 {
AzureIoTClient 24:2c59c2d43ebf 591 *properties = properties_clone(message->properties);
Azure.IoT Build 0:6ae2f7bca550 592 if (*properties == NULL)
Azure.IoT Build 0:6ae2f7bca550 593 {
AzureIoTClient 24:2c59c2d43ebf 594 LogError("Cannot clone message properties");
AzureIoTClient 19:000ab4e6a2c1 595 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 596 }
Azure.IoT Build 0:6ae2f7bca550 597 else
Azure.IoT Build 0:6ae2f7bca550 598 {
Azure.IoT Build 0:6ae2f7bca550 599 result = 0;
Azure.IoT Build 0:6ae2f7bca550 600 }
Azure.IoT Build 0:6ae2f7bca550 601 }
Azure.IoT Build 0:6ae2f7bca550 602 }
Azure.IoT Build 0:6ae2f7bca550 603
Azure.IoT Build 0:6ae2f7bca550 604 return result;
Azure.IoT Build 0:6ae2f7bca550 605 }
Azure.IoT Build 0:6ae2f7bca550 606
Azure.IoT Build 0:6ae2f7bca550 607 int message_set_application_properties(MESSAGE_HANDLE message, AMQP_VALUE application_properties)
Azure.IoT Build 0:6ae2f7bca550 608 {
Azure.IoT Build 0:6ae2f7bca550 609 int result;
Azure.IoT Build 0:6ae2f7bca550 610
Azure.IoT Build 0:6ae2f7bca550 611 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 612 (application_properties == NULL))
Azure.IoT Build 0:6ae2f7bca550 613 {
AzureIoTClient 24:2c59c2d43ebf 614 LogError("Bad arguments: message = %p, application_properties = %p",
AzureIoTClient 24:2c59c2d43ebf 615 message, application_properties);
AzureIoTClient 19:000ab4e6a2c1 616 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 617 }
Azure.IoT Build 0:6ae2f7bca550 618 else
Azure.IoT Build 0:6ae2f7bca550 619 {
Azure.IoT Build 0:6ae2f7bca550 620 AMQP_VALUE new_application_properties;
Azure.IoT Build 0:6ae2f7bca550 621
Azure.IoT Build 0:6ae2f7bca550 622 new_application_properties = application_properties_clone(application_properties);
Azure.IoT Build 0:6ae2f7bca550 623 if (new_application_properties == NULL)
Azure.IoT Build 0:6ae2f7bca550 624 {
AzureIoTClient 24:2c59c2d43ebf 625 LogError("Cannot clone application properties");
AzureIoTClient 19:000ab4e6a2c1 626 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 627 }
Azure.IoT Build 0:6ae2f7bca550 628 else
Azure.IoT Build 0:6ae2f7bca550 629 {
AzureIoTClient 24:2c59c2d43ebf 630 if (message->application_properties != NULL)
Azure.IoT Build 0:6ae2f7bca550 631 {
AzureIoTClient 24:2c59c2d43ebf 632 amqpvalue_destroy(message->application_properties);
Azure.IoT Build 0:6ae2f7bca550 633 }
Azure.IoT Build 0:6ae2f7bca550 634
AzureIoTClient 24:2c59c2d43ebf 635 message->application_properties = new_application_properties;
Azure.IoT Build 0:6ae2f7bca550 636 result = 0;
Azure.IoT Build 0:6ae2f7bca550 637 }
Azure.IoT Build 0:6ae2f7bca550 638 }
Azure.IoT Build 0:6ae2f7bca550 639
Azure.IoT Build 0:6ae2f7bca550 640 return result;
Azure.IoT Build 0:6ae2f7bca550 641 }
Azure.IoT Build 0:6ae2f7bca550 642
Azure.IoT Build 0:6ae2f7bca550 643 int message_get_application_properties(MESSAGE_HANDLE message, AMQP_VALUE* application_properties)
Azure.IoT Build 0:6ae2f7bca550 644 {
Azure.IoT Build 0:6ae2f7bca550 645 int result;
Azure.IoT Build 0:6ae2f7bca550 646
Azure.IoT Build 0:6ae2f7bca550 647 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 648 (application_properties == NULL))
Azure.IoT Build 0:6ae2f7bca550 649 {
AzureIoTClient 24:2c59c2d43ebf 650 LogError("Bad arguments: message = %p, application_properties = %p",
AzureIoTClient 24:2c59c2d43ebf 651 message, application_properties);
AzureIoTClient 19:000ab4e6a2c1 652 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 653 }
Azure.IoT Build 0:6ae2f7bca550 654 else
Azure.IoT Build 0:6ae2f7bca550 655 {
AzureIoTClient 24:2c59c2d43ebf 656 if (message->application_properties == NULL)
Azure.IoT Build 0:6ae2f7bca550 657 {
Azure.IoT Build 0:6ae2f7bca550 658 *application_properties = NULL;
Azure.IoT Build 0:6ae2f7bca550 659 result = 0;
Azure.IoT Build 0:6ae2f7bca550 660 }
Azure.IoT Build 0:6ae2f7bca550 661 else
Azure.IoT Build 0:6ae2f7bca550 662 {
AzureIoTClient 24:2c59c2d43ebf 663 *application_properties = application_properties_clone(message->application_properties);
Azure.IoT Build 0:6ae2f7bca550 664 if (*application_properties == NULL)
Azure.IoT Build 0:6ae2f7bca550 665 {
AzureIoTClient 24:2c59c2d43ebf 666 LogError("Cannot clone application properties");
AzureIoTClient 19:000ab4e6a2c1 667 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 668 }
Azure.IoT Build 0:6ae2f7bca550 669 else
Azure.IoT Build 0:6ae2f7bca550 670 {
Azure.IoT Build 0:6ae2f7bca550 671 result = 0;
Azure.IoT Build 0:6ae2f7bca550 672 }
Azure.IoT Build 0:6ae2f7bca550 673 }
Azure.IoT Build 0:6ae2f7bca550 674 }
Azure.IoT Build 0:6ae2f7bca550 675
Azure.IoT Build 0:6ae2f7bca550 676 return result;
Azure.IoT Build 0:6ae2f7bca550 677 }
Azure.IoT Build 0:6ae2f7bca550 678
Azure.IoT Build 0:6ae2f7bca550 679 int message_set_footer(MESSAGE_HANDLE message, annotations footer)
Azure.IoT Build 0:6ae2f7bca550 680 {
Azure.IoT Build 0:6ae2f7bca550 681 int result;
Azure.IoT Build 0:6ae2f7bca550 682
Azure.IoT Build 0:6ae2f7bca550 683 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 684 (footer == NULL))
Azure.IoT Build 0:6ae2f7bca550 685 {
AzureIoTClient 24:2c59c2d43ebf 686 LogError("Bad arguments: message = %p, footer = %p",
AzureIoTClient 24:2c59c2d43ebf 687 message, footer);
AzureIoTClient 19:000ab4e6a2c1 688 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 689 }
Azure.IoT Build 0:6ae2f7bca550 690 else
Azure.IoT Build 0:6ae2f7bca550 691 {
Azure.IoT Build 0:6ae2f7bca550 692 AMQP_VALUE new_footer;
Azure.IoT Build 0:6ae2f7bca550 693
Azure.IoT Build 0:6ae2f7bca550 694 new_footer = annotations_clone(footer);
Azure.IoT Build 0:6ae2f7bca550 695 if (new_footer == NULL)
Azure.IoT Build 0:6ae2f7bca550 696 {
AzureIoTClient 24:2c59c2d43ebf 697 LogError("Cannot clone message footer");
AzureIoTClient 19:000ab4e6a2c1 698 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 699 }
Azure.IoT Build 0:6ae2f7bca550 700 else
Azure.IoT Build 0:6ae2f7bca550 701 {
AzureIoTClient 24:2c59c2d43ebf 702 if (message->footer != NULL)
Azure.IoT Build 0:6ae2f7bca550 703 {
AzureIoTClient 24:2c59c2d43ebf 704 annotations_destroy(message->footer);
Azure.IoT Build 0:6ae2f7bca550 705 }
Azure.IoT Build 0:6ae2f7bca550 706
AzureIoTClient 24:2c59c2d43ebf 707 message->footer = new_footer;
Azure.IoT Build 0:6ae2f7bca550 708 result = 0;
Azure.IoT Build 0:6ae2f7bca550 709 }
Azure.IoT Build 0:6ae2f7bca550 710 }
Azure.IoT Build 0:6ae2f7bca550 711
Azure.IoT Build 0:6ae2f7bca550 712 return result;
Azure.IoT Build 0:6ae2f7bca550 713 }
Azure.IoT Build 0:6ae2f7bca550 714
Azure.IoT Build 0:6ae2f7bca550 715 int message_get_footer(MESSAGE_HANDLE message, annotations* footer)
Azure.IoT Build 0:6ae2f7bca550 716 {
Azure.IoT Build 0:6ae2f7bca550 717 int result;
Azure.IoT Build 0:6ae2f7bca550 718
Azure.IoT Build 0:6ae2f7bca550 719 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 720 (footer == NULL))
Azure.IoT Build 0:6ae2f7bca550 721 {
AzureIoTClient 24:2c59c2d43ebf 722 LogError("Bad arguments: message = %p, footer = %p",
AzureIoTClient 24:2c59c2d43ebf 723 message, footer);
AzureIoTClient 19:000ab4e6a2c1 724 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 725 }
Azure.IoT Build 0:6ae2f7bca550 726 else
Azure.IoT Build 0:6ae2f7bca550 727 {
AzureIoTClient 24:2c59c2d43ebf 728 if (message->footer == NULL)
Azure.IoT Build 0:6ae2f7bca550 729 {
Azure.IoT Build 0:6ae2f7bca550 730 *footer = NULL;
Azure.IoT Build 0:6ae2f7bca550 731 result = 0;
Azure.IoT Build 0:6ae2f7bca550 732 }
Azure.IoT Build 0:6ae2f7bca550 733 else
Azure.IoT Build 0:6ae2f7bca550 734 {
AzureIoTClient 24:2c59c2d43ebf 735 *footer = annotations_clone(message->footer);
Azure.IoT Build 0:6ae2f7bca550 736 if (*footer == NULL)
Azure.IoT Build 0:6ae2f7bca550 737 {
AzureIoTClient 24:2c59c2d43ebf 738 LogError("Cannot clone message footer");
AzureIoTClient 19:000ab4e6a2c1 739 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 740 }
Azure.IoT Build 0:6ae2f7bca550 741 else
Azure.IoT Build 0:6ae2f7bca550 742 {
Azure.IoT Build 0:6ae2f7bca550 743 result = 0;
Azure.IoT Build 0:6ae2f7bca550 744 }
Azure.IoT Build 0:6ae2f7bca550 745 }
Azure.IoT Build 0:6ae2f7bca550 746 }
Azure.IoT Build 0:6ae2f7bca550 747
Azure.IoT Build 0:6ae2f7bca550 748 return result;
Azure.IoT Build 0:6ae2f7bca550 749 }
Azure.IoT Build 0:6ae2f7bca550 750
AzureIoTClient 24:2c59c2d43ebf 751 int message_add_body_amqp_data(MESSAGE_HANDLE message, BINARY_DATA amqp_data)
Azure.IoT Build 0:6ae2f7bca550 752 {
Azure.IoT Build 0:6ae2f7bca550 753 int result;
Azure.IoT Build 0:6ae2f7bca550 754
Azure.IoT Build 0:6ae2f7bca550 755 if ((message == NULL) ||
AzureIoTClient 24:2c59c2d43ebf 756 ((amqp_data.bytes == NULL) &&
AzureIoTClient 24:2c59c2d43ebf 757 (amqp_data.length != 0)))
Azure.IoT Build 0:6ae2f7bca550 758 {
AzureIoTClient 24:2c59c2d43ebf 759 LogError("Bad arguments: message = %p, bytes = %p, length = %u",
AzureIoTClient 24:2c59c2d43ebf 760 message, amqp_data.bytes, (unsigned int)amqp_data.length);
AzureIoTClient 19:000ab4e6a2c1 761 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 762 }
Azure.IoT Build 0:6ae2f7bca550 763 else
Azure.IoT Build 0:6ae2f7bca550 764 {
AzureIoTClient 24:2c59c2d43ebf 765 BODY_AMQP_DATA* new_body_amqp_data_items = (BODY_AMQP_DATA*)realloc(message->body_amqp_data_items, sizeof(BODY_AMQP_DATA) * (message->body_amqp_data_count + 1));
Azure.IoT Build 0:6ae2f7bca550 766 if (new_body_amqp_data_items == NULL)
Azure.IoT Build 0:6ae2f7bca550 767 {
AzureIoTClient 24:2c59c2d43ebf 768 LogError("Cannot allocate memory for body AMQP data items");
AzureIoTClient 19:000ab4e6a2c1 769 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 770 }
Azure.IoT Build 0:6ae2f7bca550 771 else
Azure.IoT Build 0:6ae2f7bca550 772 {
AzureIoTClient 24:2c59c2d43ebf 773 message->body_amqp_data_items = new_body_amqp_data_items;
Azure.IoT Build 0:6ae2f7bca550 774
AzureIoTClient 24:2c59c2d43ebf 775 message->body_amqp_data_items[message->body_amqp_data_count].body_data_section_bytes = (unsigned char*)malloc(amqp_data.length);
AzureIoTClient 24:2c59c2d43ebf 776 if (message->body_amqp_data_items[message->body_amqp_data_count].body_data_section_bytes == NULL)
Azure.IoT Build 0:6ae2f7bca550 777 {
AzureIoTClient 24:2c59c2d43ebf 778 LogError("Cannot allocate memory for body AMQP data to be added");
AzureIoTClient 19:000ab4e6a2c1 779 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 780 }
Azure.IoT Build 0:6ae2f7bca550 781 else
Azure.IoT Build 0:6ae2f7bca550 782 {
AzureIoTClient 24:2c59c2d43ebf 783 message->body_amqp_data_items[message->body_amqp_data_count].body_data_section_length = amqp_data.length;
AzureIoTClient 24:2c59c2d43ebf 784 (void)memcpy(message->body_amqp_data_items[message->body_amqp_data_count].body_data_section_bytes, amqp_data.bytes, amqp_data.length);
Azure.IoT Build 0:6ae2f7bca550 785
AzureIoTClient 24:2c59c2d43ebf 786 if (message->body_amqp_value != NULL)
Azure.IoT Build 0:6ae2f7bca550 787 {
AzureIoTClient 24:2c59c2d43ebf 788 amqpvalue_destroy(message->body_amqp_value);
AzureIoTClient 24:2c59c2d43ebf 789 message->body_amqp_value = NULL;
Azure.IoT Build 0:6ae2f7bca550 790 }
AzureIoTClient 24:2c59c2d43ebf 791 free_all_body_sequence_items(message);
Azure.IoT Build 0:6ae2f7bca550 792
AzureIoTClient 24:2c59c2d43ebf 793 message->body_amqp_data_count++;
Azure.IoT Build 0:6ae2f7bca550 794 result = 0;
Azure.IoT Build 0:6ae2f7bca550 795 }
Azure.IoT Build 0:6ae2f7bca550 796 }
Azure.IoT Build 0:6ae2f7bca550 797 }
Azure.IoT Build 0:6ae2f7bca550 798
Azure.IoT Build 0:6ae2f7bca550 799 return result;
Azure.IoT Build 0:6ae2f7bca550 800 }
Azure.IoT Build 0:6ae2f7bca550 801
AzureIoTClient 24:2c59c2d43ebf 802 int message_get_body_amqp_data_in_place(MESSAGE_HANDLE message, size_t index, BINARY_DATA* binary_data)
Azure.IoT Build 0:6ae2f7bca550 803 {
Azure.IoT Build 0:6ae2f7bca550 804 int result;
Azure.IoT Build 0:6ae2f7bca550 805
Azure.IoT Build 0:6ae2f7bca550 806 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 807 (binary_data == NULL))
Azure.IoT Build 0:6ae2f7bca550 808 {
AzureIoTClient 24:2c59c2d43ebf 809 LogError("Bad arguments: message = %p, binary_data = %p",
AzureIoTClient 24:2c59c2d43ebf 810 message, binary_data);
AzureIoTClient 19:000ab4e6a2c1 811 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 812 }
Azure.IoT Build 0:6ae2f7bca550 813 else
Azure.IoT Build 0:6ae2f7bca550 814 {
AzureIoTClient 24:2c59c2d43ebf 815 if (index >= message->body_amqp_data_count)
Azure.IoT Build 0:6ae2f7bca550 816 {
AzureIoTClient 24:2c59c2d43ebf 817 LogError("Index too high for AMQP data (%u), number of AMQP data entries is %u",
AzureIoTClient 24:2c59c2d43ebf 818 index, message->body_amqp_data_count);
AzureIoTClient 19:000ab4e6a2c1 819 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 820 }
Azure.IoT Build 0:6ae2f7bca550 821 else
Azure.IoT Build 0:6ae2f7bca550 822 {
AzureIoTClient 24:2c59c2d43ebf 823 binary_data->bytes = message->body_amqp_data_items[index].body_data_section_bytes;
AzureIoTClient 24:2c59c2d43ebf 824 binary_data->length = message->body_amqp_data_items[index].body_data_section_length;
Azure.IoT Build 0:6ae2f7bca550 825
Azure.IoT Build 0:6ae2f7bca550 826 result = 0;
Azure.IoT Build 0:6ae2f7bca550 827 }
Azure.IoT Build 0:6ae2f7bca550 828 }
Azure.IoT Build 0:6ae2f7bca550 829
Azure.IoT Build 0:6ae2f7bca550 830 return result;
Azure.IoT Build 0:6ae2f7bca550 831 }
Azure.IoT Build 0:6ae2f7bca550 832
Azure.IoT Build 0:6ae2f7bca550 833 int message_get_body_amqp_data_count(MESSAGE_HANDLE message, size_t* count)
Azure.IoT Build 0:6ae2f7bca550 834 {
Azure.IoT Build 0:6ae2f7bca550 835 int result;
Azure.IoT Build 0:6ae2f7bca550 836
Azure.IoT Build 0:6ae2f7bca550 837 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 838 (count == NULL))
Azure.IoT Build 0:6ae2f7bca550 839 {
AzureIoTClient 24:2c59c2d43ebf 840 LogError("Bad arguments: message = %p, count = %p",
AzureIoTClient 24:2c59c2d43ebf 841 message, count);
AzureIoTClient 19:000ab4e6a2c1 842 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 843 }
Azure.IoT Build 0:6ae2f7bca550 844 else
Azure.IoT Build 0:6ae2f7bca550 845 {
AzureIoTClient 24:2c59c2d43ebf 846 *count = message->body_amqp_data_count;
Azure.IoT Build 0:6ae2f7bca550 847 result = 0;
Azure.IoT Build 0:6ae2f7bca550 848 }
Azure.IoT Build 0:6ae2f7bca550 849
Azure.IoT Build 0:6ae2f7bca550 850 return result;
Azure.IoT Build 0:6ae2f7bca550 851 }
Azure.IoT Build 0:6ae2f7bca550 852
Azure.IoT Build 0:6ae2f7bca550 853 int message_add_body_amqp_sequence(MESSAGE_HANDLE message, AMQP_VALUE sequence_list)
Azure.IoT Build 0:6ae2f7bca550 854 {
Azure.IoT Build 0:6ae2f7bca550 855 int result;
Azure.IoT Build 0:6ae2f7bca550 856 size_t item_count;
Azure.IoT Build 0:6ae2f7bca550 857
Azure.IoT Build 0:6ae2f7bca550 858 if ((message == NULL) ||
AzureIoTClient 24:2c59c2d43ebf 859 (sequence_list == NULL))
Azure.IoT Build 0:6ae2f7bca550 860 {
AzureIoTClient 24:2c59c2d43ebf 861 LogError("Bad arguments: message = %p, sequence_list = %p",
AzureIoTClient 24:2c59c2d43ebf 862 message, sequence_list);
AzureIoTClient 24:2c59c2d43ebf 863 result = __FAILURE__;
AzureIoTClient 24:2c59c2d43ebf 864 }
AzureIoTClient 24:2c59c2d43ebf 865 else if (amqpvalue_get_list_item_count(sequence_list, (uint32_t*)&item_count) != 0)
AzureIoTClient 24:2c59c2d43ebf 866 {
AzureIoTClient 24:2c59c2d43ebf 867 LogError("Cannot retrieve message sequence list item count");
AzureIoTClient 19:000ab4e6a2c1 868 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 869 }
Azure.IoT Build 0:6ae2f7bca550 870 else
Azure.IoT Build 0:6ae2f7bca550 871 {
AzureIoTClient 24:2c59c2d43ebf 872 AMQP_VALUE* new_body_amqp_sequence_items = (AMQP_VALUE*)realloc(message->body_amqp_sequence_items, sizeof(AMQP_VALUE) * (message->body_amqp_sequence_count + 1));
Azure.IoT Build 0:6ae2f7bca550 873 if (new_body_amqp_sequence_items == NULL)
Azure.IoT Build 0:6ae2f7bca550 874 {
AzureIoTClient 24:2c59c2d43ebf 875 LogError("Cannot allocate enough memory for sequence items");
AzureIoTClient 19:000ab4e6a2c1 876 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 877 }
Azure.IoT Build 0:6ae2f7bca550 878 else
Azure.IoT Build 0:6ae2f7bca550 879 {
AzureIoTClient 24:2c59c2d43ebf 880 message->body_amqp_sequence_items = new_body_amqp_sequence_items;
Azure.IoT Build 0:6ae2f7bca550 881
AzureIoTClient 24:2c59c2d43ebf 882 message->body_amqp_sequence_items[message->body_amqp_sequence_count] = amqpvalue_clone(sequence_list);
AzureIoTClient 24:2c59c2d43ebf 883 if (message->body_amqp_sequence_items[message->body_amqp_sequence_count] == NULL)
Azure.IoT Build 0:6ae2f7bca550 884 {
AzureIoTClient 24:2c59c2d43ebf 885 LogError("Cloning sequence failed");
AzureIoTClient 19:000ab4e6a2c1 886 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 887 }
Azure.IoT Build 0:6ae2f7bca550 888 else
Azure.IoT Build 0:6ae2f7bca550 889 {
AzureIoTClient 24:2c59c2d43ebf 890 if (message->body_amqp_value != NULL)
Azure.IoT Build 0:6ae2f7bca550 891 {
AzureIoTClient 24:2c59c2d43ebf 892 amqpvalue_destroy(message->body_amqp_value);
AzureIoTClient 24:2c59c2d43ebf 893 message->body_amqp_value = NULL;
Azure.IoT Build 0:6ae2f7bca550 894 }
AzureIoTClient 24:2c59c2d43ebf 895 free_all_body_data_items(message);
Azure.IoT Build 0:6ae2f7bca550 896
AzureIoTClient 24:2c59c2d43ebf 897 message->body_amqp_sequence_count++;
Azure.IoT Build 0:6ae2f7bca550 898 result = 0;
Azure.IoT Build 0:6ae2f7bca550 899 }
Azure.IoT Build 0:6ae2f7bca550 900 }
Azure.IoT Build 0:6ae2f7bca550 901 }
Azure.IoT Build 0:6ae2f7bca550 902
Azure.IoT Build 0:6ae2f7bca550 903 return result;
Azure.IoT Build 0:6ae2f7bca550 904 }
Azure.IoT Build 0:6ae2f7bca550 905
Azure.IoT Build 0:6ae2f7bca550 906 int message_get_body_amqp_sequence(MESSAGE_HANDLE message, size_t index, AMQP_VALUE* sequence_list)
Azure.IoT Build 0:6ae2f7bca550 907 {
Azure.IoT Build 0:6ae2f7bca550 908 int result;
Azure.IoT Build 0:6ae2f7bca550 909
Azure.IoT Build 0:6ae2f7bca550 910 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 911 (sequence_list == NULL))
Azure.IoT Build 0:6ae2f7bca550 912 {
AzureIoTClient 24:2c59c2d43ebf 913 LogError("Bad arguments: message = %p, sequence_list = %p",
AzureIoTClient 24:2c59c2d43ebf 914 message, sequence_list);
AzureIoTClient 19:000ab4e6a2c1 915 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 916 }
Azure.IoT Build 0:6ae2f7bca550 917 else
Azure.IoT Build 0:6ae2f7bca550 918 {
AzureIoTClient 24:2c59c2d43ebf 919 if (index >= message->body_amqp_sequence_count)
Azure.IoT Build 0:6ae2f7bca550 920 {
AzureIoTClient 24:2c59c2d43ebf 921 LogError("Index too high for AMQP sequence (%u), maximum is %u",
AzureIoTClient 24:2c59c2d43ebf 922 index, message->body_amqp_sequence_count);
AzureIoTClient 19:000ab4e6a2c1 923 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 924 }
Azure.IoT Build 0:6ae2f7bca550 925 else
Azure.IoT Build 0:6ae2f7bca550 926 {
AzureIoTClient 24:2c59c2d43ebf 927 *sequence_list = amqpvalue_clone(message->body_amqp_sequence_items[index]);
Azure.IoT Build 0:6ae2f7bca550 928 if (*sequence_list == NULL)
Azure.IoT Build 0:6ae2f7bca550 929 {
AzureIoTClient 24:2c59c2d43ebf 930 LogError("Cannot clone AMQP sequence");
AzureIoTClient 19:000ab4e6a2c1 931 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 932 }
Azure.IoT Build 0:6ae2f7bca550 933 else
Azure.IoT Build 0:6ae2f7bca550 934 {
Azure.IoT Build 0:6ae2f7bca550 935 result = 0;
Azure.IoT Build 0:6ae2f7bca550 936 }
Azure.IoT Build 0:6ae2f7bca550 937 }
Azure.IoT Build 0:6ae2f7bca550 938 }
Azure.IoT Build 0:6ae2f7bca550 939
Azure.IoT Build 0:6ae2f7bca550 940 return result;
Azure.IoT Build 0:6ae2f7bca550 941 }
Azure.IoT Build 0:6ae2f7bca550 942
Azure.IoT Build 0:6ae2f7bca550 943 int message_get_body_amqp_sequence_count(MESSAGE_HANDLE message, size_t* count)
Azure.IoT Build 0:6ae2f7bca550 944 {
Azure.IoT Build 0:6ae2f7bca550 945 int result;
Azure.IoT Build 0:6ae2f7bca550 946
Azure.IoT Build 0:6ae2f7bca550 947 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 948 (count == NULL))
Azure.IoT Build 0:6ae2f7bca550 949 {
AzureIoTClient 24:2c59c2d43ebf 950 LogError("Bad arguments: message = %p, count = %p",
AzureIoTClient 24:2c59c2d43ebf 951 message, count);
AzureIoTClient 19:000ab4e6a2c1 952 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 953 }
Azure.IoT Build 0:6ae2f7bca550 954 else
Azure.IoT Build 0:6ae2f7bca550 955 {
AzureIoTClient 24:2c59c2d43ebf 956 *count = message->body_amqp_sequence_count;
Azure.IoT Build 0:6ae2f7bca550 957 result = 0;
Azure.IoT Build 0:6ae2f7bca550 958 }
Azure.IoT Build 0:6ae2f7bca550 959
Azure.IoT Build 0:6ae2f7bca550 960 return result;
Azure.IoT Build 0:6ae2f7bca550 961 }
Azure.IoT Build 0:6ae2f7bca550 962
Azure.IoT Build 0:6ae2f7bca550 963 int message_set_body_amqp_value(MESSAGE_HANDLE message, AMQP_VALUE body_amqp_value)
Azure.IoT Build 0:6ae2f7bca550 964 {
Azure.IoT Build 0:6ae2f7bca550 965 int result;
Azure.IoT Build 0:6ae2f7bca550 966
Azure.IoT Build 0:6ae2f7bca550 967 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 968 (body_amqp_value == NULL))
Azure.IoT Build 0:6ae2f7bca550 969 {
AzureIoTClient 24:2c59c2d43ebf 970 LogError("Bad arguments: message = %p, body_amqp_value = %p",
AzureIoTClient 24:2c59c2d43ebf 971 message, body_amqp_value);
AzureIoTClient 19:000ab4e6a2c1 972 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 973 }
Azure.IoT Build 0:6ae2f7bca550 974 else
Azure.IoT Build 0:6ae2f7bca550 975 {
AzureIoTClient 24:2c59c2d43ebf 976 message->body_amqp_value = amqpvalue_clone(body_amqp_value);
AzureIoTClient 24:2c59c2d43ebf 977 if (message->body_amqp_value == NULL)
AzureIoTClient 24:2c59c2d43ebf 978 {
AzureIoTClient 24:2c59c2d43ebf 979 LogError("Cannot clone body AMQP value",
AzureIoTClient 24:2c59c2d43ebf 980 message, body_amqp_value);
AzureIoTClient 24:2c59c2d43ebf 981 result = __FAILURE__;
AzureIoTClient 24:2c59c2d43ebf 982 }
AzureIoTClient 24:2c59c2d43ebf 983 else
AzureIoTClient 24:2c59c2d43ebf 984 {
AzureIoTClient 24:2c59c2d43ebf 985 free_all_body_data_items(message);
AzureIoTClient 24:2c59c2d43ebf 986 free_all_body_sequence_items(message);
AzureIoTClient 24:2c59c2d43ebf 987 result = 0;
AzureIoTClient 24:2c59c2d43ebf 988 }
Azure.IoT Build 0:6ae2f7bca550 989 }
Azure.IoT Build 0:6ae2f7bca550 990
Azure.IoT Build 0:6ae2f7bca550 991 return result;
Azure.IoT Build 0:6ae2f7bca550 992 }
Azure.IoT Build 0:6ae2f7bca550 993
AzureIoTClient 24:2c59c2d43ebf 994 int message_get_body_amqp_value_in_place(MESSAGE_HANDLE message, AMQP_VALUE* body_amqp_value)
Azure.IoT Build 0:6ae2f7bca550 995 {
Azure.IoT Build 0:6ae2f7bca550 996 int result;
Azure.IoT Build 0:6ae2f7bca550 997
Azure.IoT Build 0:6ae2f7bca550 998 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 999 (body_amqp_value == NULL))
Azure.IoT Build 0:6ae2f7bca550 1000 {
AzureIoTClient 24:2c59c2d43ebf 1001 LogError("Bad arguments: message = %p, body_amqp_value = %p",
AzureIoTClient 24:2c59c2d43ebf 1002 message, body_amqp_value);
AzureIoTClient 19:000ab4e6a2c1 1003 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 1004 }
Azure.IoT Build 0:6ae2f7bca550 1005 else
Azure.IoT Build 0:6ae2f7bca550 1006 {
AzureIoTClient 24:2c59c2d43ebf 1007 *body_amqp_value = message->body_amqp_value;
Azure.IoT Build 0:6ae2f7bca550 1008
Azure.IoT Build 0:6ae2f7bca550 1009 result = 0;
Azure.IoT Build 0:6ae2f7bca550 1010 }
Azure.IoT Build 0:6ae2f7bca550 1011
Azure.IoT Build 0:6ae2f7bca550 1012 return result;
Azure.IoT Build 0:6ae2f7bca550 1013 }
Azure.IoT Build 0:6ae2f7bca550 1014
Azure.IoT Build 0:6ae2f7bca550 1015 int message_get_body_type(MESSAGE_HANDLE message, MESSAGE_BODY_TYPE* body_type)
Azure.IoT Build 0:6ae2f7bca550 1016 {
Azure.IoT Build 0:6ae2f7bca550 1017 int result;
Azure.IoT Build 0:6ae2f7bca550 1018
Azure.IoT Build 0:6ae2f7bca550 1019 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 1020 (body_type == NULL))
Azure.IoT Build 0:6ae2f7bca550 1021 {
AzureIoTClient 24:2c59c2d43ebf 1022 LogError("Bad arguments: message = %p, body_type = %p",
AzureIoTClient 24:2c59c2d43ebf 1023 message, body_type);
AzureIoTClient 19:000ab4e6a2c1 1024 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 1025 }
Azure.IoT Build 0:6ae2f7bca550 1026 else
Azure.IoT Build 0:6ae2f7bca550 1027 {
AzureIoTClient 24:2c59c2d43ebf 1028 if (message->body_amqp_value != NULL)
Azure.IoT Build 0:6ae2f7bca550 1029 {
Azure.IoT Build 0:6ae2f7bca550 1030 *body_type = MESSAGE_BODY_TYPE_VALUE;
Azure.IoT Build 0:6ae2f7bca550 1031 }
AzureIoTClient 24:2c59c2d43ebf 1032 else if (message->body_amqp_data_count > 0)
Azure.IoT Build 0:6ae2f7bca550 1033 {
Azure.IoT Build 0:6ae2f7bca550 1034 *body_type = MESSAGE_BODY_TYPE_DATA;
Azure.IoT Build 0:6ae2f7bca550 1035 }
AzureIoTClient 24:2c59c2d43ebf 1036 else if (message->body_amqp_sequence_count > 0)
Azure.IoT Build 0:6ae2f7bca550 1037 {
Azure.IoT Build 0:6ae2f7bca550 1038 *body_type = MESSAGE_BODY_TYPE_SEQUENCE;
Azure.IoT Build 0:6ae2f7bca550 1039 }
Azure.IoT Build 0:6ae2f7bca550 1040 else
Azure.IoT Build 0:6ae2f7bca550 1041 {
Azure.IoT Build 0:6ae2f7bca550 1042 *body_type = MESSAGE_BODY_TYPE_NONE;
Azure.IoT Build 0:6ae2f7bca550 1043 }
Azure.IoT Build 0:6ae2f7bca550 1044
Azure.IoT Build 0:6ae2f7bca550 1045 result = 0;
Azure.IoT Build 0:6ae2f7bca550 1046 }
Azure.IoT Build 0:6ae2f7bca550 1047
Azure.IoT Build 0:6ae2f7bca550 1048 return result;
Azure.IoT Build 0:6ae2f7bca550 1049 }
Azure.IoT Build 0:6ae2f7bca550 1050
Azure.IoT Build 0:6ae2f7bca550 1051 int message_set_message_format(MESSAGE_HANDLE message, uint32_t message_format)
Azure.IoT Build 0:6ae2f7bca550 1052 {
Azure.IoT Build 0:6ae2f7bca550 1053 int result;
Azure.IoT Build 0:6ae2f7bca550 1054
Azure.IoT Build 0:6ae2f7bca550 1055 if (message == NULL)
Azure.IoT Build 0:6ae2f7bca550 1056 {
AzureIoTClient 24:2c59c2d43ebf 1057 LogError("NULL message");
AzureIoTClient 24:2c59c2d43ebf 1058 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 1059 }
Azure.IoT Build 0:6ae2f7bca550 1060 else
Azure.IoT Build 0:6ae2f7bca550 1061 {
AzureIoTClient 24:2c59c2d43ebf 1062 message->message_format = message_format;
Azure.IoT Build 0:6ae2f7bca550 1063 result = 0;
Azure.IoT Build 0:6ae2f7bca550 1064 }
Azure.IoT Build 0:6ae2f7bca550 1065
Azure.IoT Build 0:6ae2f7bca550 1066 return result;
Azure.IoT Build 0:6ae2f7bca550 1067 }
Azure.IoT Build 0:6ae2f7bca550 1068
Azure.IoT Build 0:6ae2f7bca550 1069 int message_get_message_format(MESSAGE_HANDLE message, uint32_t *message_format)
Azure.IoT Build 0:6ae2f7bca550 1070 {
Azure.IoT Build 0:6ae2f7bca550 1071 int result;
Azure.IoT Build 0:6ae2f7bca550 1072
Azure.IoT Build 0:6ae2f7bca550 1073 if ((message == NULL) ||
Azure.IoT Build 0:6ae2f7bca550 1074 (message_format == NULL))
Azure.IoT Build 0:6ae2f7bca550 1075 {
AzureIoTClient 24:2c59c2d43ebf 1076 LogError("Bad arguments: message = %p, message_format = %p",
AzureIoTClient 24:2c59c2d43ebf 1077 message, message_format);
AzureIoTClient 24:2c59c2d43ebf 1078 result = __FAILURE__;
Azure.IoT Build 0:6ae2f7bca550 1079 }
Azure.IoT Build 0:6ae2f7bca550 1080 else
Azure.IoT Build 0:6ae2f7bca550 1081 {
AzureIoTClient 24:2c59c2d43ebf 1082 *message_format = message->message_format;
Azure.IoT Build 0:6ae2f7bca550 1083 result = 0;
Azure.IoT Build 0:6ae2f7bca550 1084 }
Azure.IoT Build 0:6ae2f7bca550 1085
Azure.IoT Build 0:6ae2f7bca550 1086 return result;
Azure.IoT Build 0:6ae2f7bca550 1087 }