A small memory footprint AMQP implimentation
Dependents: iothub_client_sample_amqp remote_monitoring simplesample_amqp
message.c@46:01f7ca900e07, 2018-09-11 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Tue Sep 11 11:13:43 2018 -0700
- Revision:
- 46:01f7ca900e07
- Parent:
- 40:f0ceafa8d570
1.2.9
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 <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" |
AzureIoTClient | 40:f0ceafa8d570 | 10 | #include "azure_uamqp_c/amqp_definitions.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 11 | #include "azure_uamqp_c/message.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 | typedef struct BODY_AMQP_DATA_TAG |
Azure.IoT Build | 0:6ae2f7bca550 | 15 | { |
AzureIoTClient | 28:add19eb7defa | 16 | unsigned char* body_data_section_bytes; |
AzureIoTClient | 28:add19eb7defa | 17 | size_t body_data_section_length; |
Azure.IoT Build | 0:6ae2f7bca550 | 18 | } BODY_AMQP_DATA; |
Azure.IoT Build | 0:6ae2f7bca550 | 19 | |
Azure.IoT Build | 0:6ae2f7bca550 | 20 | typedef struct MESSAGE_INSTANCE_TAG |
Azure.IoT Build | 0:6ae2f7bca550 | 21 | { |
AzureIoTClient | 28:add19eb7defa | 22 | BODY_AMQP_DATA* body_amqp_data_items; |
AzureIoTClient | 28:add19eb7defa | 23 | size_t body_amqp_data_count; |
AzureIoTClient | 28:add19eb7defa | 24 | AMQP_VALUE* body_amqp_sequence_items; |
AzureIoTClient | 28:add19eb7defa | 25 | size_t body_amqp_sequence_count; |
AzureIoTClient | 28:add19eb7defa | 26 | AMQP_VALUE body_amqp_value; |
AzureIoTClient | 28:add19eb7defa | 27 | HEADER_HANDLE header; |
AzureIoTClient | 28:add19eb7defa | 28 | delivery_annotations delivery_annotations; |
AzureIoTClient | 28:add19eb7defa | 29 | message_annotations message_annotations; |
AzureIoTClient | 28:add19eb7defa | 30 | PROPERTIES_HANDLE properties; |
AzureIoTClient | 28:add19eb7defa | 31 | application_properties application_properties; |
AzureIoTClient | 28:add19eb7defa | 32 | annotations footer; |
Azure.IoT Build | 0:6ae2f7bca550 | 33 | uint32_t message_format; |
Azure.IoT Build | 0:6ae2f7bca550 | 34 | } MESSAGE_INSTANCE; |
Azure.IoT Build | 0:6ae2f7bca550 | 35 | |
AzureIoTClient | 28:add19eb7defa | 36 | MESSAGE_BODY_TYPE internal_get_body_type(MESSAGE_HANDLE message) |
AzureIoTClient | 28:add19eb7defa | 37 | { |
AzureIoTClient | 28:add19eb7defa | 38 | MESSAGE_BODY_TYPE result; |
AzureIoTClient | 28:add19eb7defa | 39 | |
AzureIoTClient | 28:add19eb7defa | 40 | if (message->body_amqp_value != NULL) |
AzureIoTClient | 28:add19eb7defa | 41 | { |
AzureIoTClient | 28:add19eb7defa | 42 | result = MESSAGE_BODY_TYPE_VALUE; |
AzureIoTClient | 28:add19eb7defa | 43 | } |
AzureIoTClient | 28:add19eb7defa | 44 | else if (message->body_amqp_data_count > 0) |
AzureIoTClient | 28:add19eb7defa | 45 | { |
AzureIoTClient | 28:add19eb7defa | 46 | result = MESSAGE_BODY_TYPE_DATA; |
AzureIoTClient | 28:add19eb7defa | 47 | } |
AzureIoTClient | 28:add19eb7defa | 48 | else if (message->body_amqp_sequence_count > 0) |
AzureIoTClient | 28:add19eb7defa | 49 | { |
AzureIoTClient | 28:add19eb7defa | 50 | result = MESSAGE_BODY_TYPE_SEQUENCE; |
AzureIoTClient | 28:add19eb7defa | 51 | } |
AzureIoTClient | 28:add19eb7defa | 52 | else |
AzureIoTClient | 28:add19eb7defa | 53 | { |
AzureIoTClient | 28:add19eb7defa | 54 | result = MESSAGE_BODY_TYPE_NONE; |
AzureIoTClient | 28:add19eb7defa | 55 | } |
AzureIoTClient | 28:add19eb7defa | 56 | |
AzureIoTClient | 28:add19eb7defa | 57 | return result; |
AzureIoTClient | 28:add19eb7defa | 58 | } |
AzureIoTClient | 28:add19eb7defa | 59 | |
AzureIoTClient | 24:2c59c2d43ebf | 60 | static void free_all_body_data_items(MESSAGE_HANDLE message) |
Azure.IoT Build | 0:6ae2f7bca550 | 61 | { |
AzureIoTClient | 28:add19eb7defa | 62 | size_t i; |
Azure.IoT Build | 0:6ae2f7bca550 | 63 | |
AzureIoTClient | 28:add19eb7defa | 64 | for (i = 0; i < message->body_amqp_data_count; i++) |
AzureIoTClient | 28:add19eb7defa | 65 | { |
AzureIoTClient | 28:add19eb7defa | 66 | if (message->body_amqp_data_items[i].body_data_section_bytes != NULL) |
AzureIoTClient | 28:add19eb7defa | 67 | { |
AzureIoTClient | 28:add19eb7defa | 68 | free(message->body_amqp_data_items[i].body_data_section_bytes); |
AzureIoTClient | 28:add19eb7defa | 69 | } |
AzureIoTClient | 28:add19eb7defa | 70 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 71 | |
AzureIoTClient | 28:add19eb7defa | 72 | if (message->body_amqp_data_items != NULL) |
AzureIoTClient | 28:add19eb7defa | 73 | { |
AzureIoTClient | 28:add19eb7defa | 74 | free(message->body_amqp_data_items); |
AzureIoTClient | 28:add19eb7defa | 75 | } |
AzureIoTClient | 28:add19eb7defa | 76 | message->body_amqp_data_count = 0; |
AzureIoTClient | 28:add19eb7defa | 77 | message->body_amqp_data_items = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 78 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 79 | |
AzureIoTClient | 24:2c59c2d43ebf | 80 | static void free_all_body_sequence_items(MESSAGE_HANDLE message) |
Azure.IoT Build | 0:6ae2f7bca550 | 81 | { |
AzureIoTClient | 28:add19eb7defa | 82 | size_t i; |
Azure.IoT Build | 0:6ae2f7bca550 | 83 | |
AzureIoTClient | 28:add19eb7defa | 84 | for (i = 0; i < message->body_amqp_sequence_count; i++) |
AzureIoTClient | 28:add19eb7defa | 85 | { |
AzureIoTClient | 28:add19eb7defa | 86 | if (message->body_amqp_sequence_items[i] != NULL) |
AzureIoTClient | 28:add19eb7defa | 87 | { |
AzureIoTClient | 28:add19eb7defa | 88 | /* Codes_SRS_MESSAGE_01_137: [ Each sequence shall be freed by calling `amqpvalue_destroy`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 89 | amqpvalue_destroy(message->body_amqp_sequence_items[i]); |
AzureIoTClient | 28:add19eb7defa | 90 | } |
AzureIoTClient | 28:add19eb7defa | 91 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 92 | |
AzureIoTClient | 28:add19eb7defa | 93 | if (message->body_amqp_sequence_items != NULL) |
AzureIoTClient | 28:add19eb7defa | 94 | { |
AzureIoTClient | 28:add19eb7defa | 95 | free(message->body_amqp_sequence_items); |
AzureIoTClient | 28:add19eb7defa | 96 | } |
AzureIoTClient | 28:add19eb7defa | 97 | message->body_amqp_sequence_count = 0; |
AzureIoTClient | 28:add19eb7defa | 98 | message->body_amqp_sequence_items = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 99 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 100 | |
Azure.IoT Build | 0:6ae2f7bca550 | 101 | MESSAGE_HANDLE message_create(void) |
Azure.IoT Build | 0:6ae2f7bca550 | 102 | { |
AzureIoTClient | 28:add19eb7defa | 103 | MESSAGE_HANDLE result = (MESSAGE_HANDLE)malloc(sizeof(MESSAGE_INSTANCE)); |
AzureIoTClient | 28:add19eb7defa | 104 | if (result == NULL) |
AzureIoTClient | 28:add19eb7defa | 105 | { |
AzureIoTClient | 28:add19eb7defa | 106 | /* Codes_SRS_MESSAGE_01_002: [If allocating memory for the message fails, `message_create` shall fail and return NULL.] */ |
AzureIoTClient | 28:add19eb7defa | 107 | LogError("Cannot allocate memory for message"); |
AzureIoTClient | 28:add19eb7defa | 108 | } |
AzureIoTClient | 28:add19eb7defa | 109 | else |
AzureIoTClient | 28:add19eb7defa | 110 | { |
AzureIoTClient | 28:add19eb7defa | 111 | result->header = NULL; |
AzureIoTClient | 28:add19eb7defa | 112 | result->delivery_annotations = NULL; |
AzureIoTClient | 28:add19eb7defa | 113 | result->message_annotations = NULL; |
AzureIoTClient | 28:add19eb7defa | 114 | result->properties = NULL; |
AzureIoTClient | 28:add19eb7defa | 115 | result->application_properties = NULL; |
AzureIoTClient | 28:add19eb7defa | 116 | result->footer = NULL; |
AzureIoTClient | 28:add19eb7defa | 117 | result->body_amqp_data_items = NULL; |
AzureIoTClient | 28:add19eb7defa | 118 | result->body_amqp_data_count = 0; |
AzureIoTClient | 28:add19eb7defa | 119 | result->body_amqp_value = NULL; |
AzureIoTClient | 28:add19eb7defa | 120 | result->body_amqp_sequence_items = NULL; |
AzureIoTClient | 28:add19eb7defa | 121 | result->body_amqp_sequence_count = 0; |
AzureIoTClient | 28:add19eb7defa | 122 | |
AzureIoTClient | 28:add19eb7defa | 123 | /* Codes_SRS_MESSAGE_01_135: [ By default a message on which `message_set_message_format` was not called shall have message format set to 0. ]*/ |
Azure.IoT Build | 0:6ae2f7bca550 | 124 | result->message_format = 0; |
AzureIoTClient | 28:add19eb7defa | 125 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 126 | |
AzureIoTClient | 28:add19eb7defa | 127 | /* 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.] */ |
AzureIoTClient | 28:add19eb7defa | 128 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 129 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 130 | |
Azure.IoT Build | 0:6ae2f7bca550 | 131 | MESSAGE_HANDLE message_clone(MESSAGE_HANDLE source_message) |
Azure.IoT Build | 0:6ae2f7bca550 | 132 | { |
AzureIoTClient | 28:add19eb7defa | 133 | MESSAGE_HANDLE result; |
Azure.IoT Build | 0:6ae2f7bca550 | 134 | |
AzureIoTClient | 28:add19eb7defa | 135 | if (source_message == NULL) |
AzureIoTClient | 28:add19eb7defa | 136 | { |
AzureIoTClient | 28:add19eb7defa | 137 | /* Codes_SRS_MESSAGE_01_062: [If `source_message` is NULL, `message_clone` shall fail and return NULL.] */ |
AzureIoTClient | 28:add19eb7defa | 138 | LogError("NULL source_message"); |
AzureIoTClient | 28:add19eb7defa | 139 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 140 | } |
AzureIoTClient | 28:add19eb7defa | 141 | else |
AzureIoTClient | 28:add19eb7defa | 142 | { |
AzureIoTClient | 28:add19eb7defa | 143 | /* 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 | 28:add19eb7defa | 144 | result = (MESSAGE_HANDLE)message_create(); |
AzureIoTClient | 28:add19eb7defa | 145 | if (result == NULL) |
AzureIoTClient | 28:add19eb7defa | 146 | { |
AzureIoTClient | 28:add19eb7defa | 147 | /* Codes_SRS_MESSAGE_01_004: [If allocating memory for the new cloned message fails, `message_clone` shall fail and return NULL.] */ |
AzureIoTClient | 28:add19eb7defa | 148 | LogError("Cannot clone message"); |
AzureIoTClient | 28:add19eb7defa | 149 | } |
AzureIoTClient | 28:add19eb7defa | 150 | else |
AzureIoTClient | 28:add19eb7defa | 151 | { |
AzureIoTClient | 24:2c59c2d43ebf | 152 | result->message_format = source_message->message_format; |
Azure.IoT Build | 0:6ae2f7bca550 | 153 | |
AzureIoTClient | 28:add19eb7defa | 154 | if (source_message->header != NULL) |
AzureIoTClient | 28:add19eb7defa | 155 | { |
AzureIoTClient | 28:add19eb7defa | 156 | /* Codes_SRS_MESSAGE_01_005: [If a header exists on the source message it shall be cloned by using `header_clone`.] */ |
AzureIoTClient | 28:add19eb7defa | 157 | result->header = header_clone(source_message->header); |
AzureIoTClient | 28:add19eb7defa | 158 | if (result->header == NULL) |
AzureIoTClient | 28:add19eb7defa | 159 | { |
AzureIoTClient | 28:add19eb7defa | 160 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 161 | LogError("Cannot clone message header"); |
AzureIoTClient | 28:add19eb7defa | 162 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 163 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 164 | } |
AzureIoTClient | 28:add19eb7defa | 165 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 166 | |
AzureIoTClient | 28:add19eb7defa | 167 | if ((result != NULL) && (source_message->delivery_annotations != NULL)) |
AzureIoTClient | 28:add19eb7defa | 168 | { |
AzureIoTClient | 28:add19eb7defa | 169 | /* Codes_SRS_MESSAGE_01_006: [If delivery annotations exist on the source message they shall be cloned by using `annotations_clone`.] */ |
AzureIoTClient | 28:add19eb7defa | 170 | result->delivery_annotations = annotations_clone(source_message->delivery_annotations); |
AzureIoTClient | 28:add19eb7defa | 171 | if (result->delivery_annotations == NULL) |
AzureIoTClient | 28:add19eb7defa | 172 | { |
AzureIoTClient | 28:add19eb7defa | 173 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 174 | LogError("Cannot clone delivery annotations"); |
AzureIoTClient | 28:add19eb7defa | 175 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 176 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 177 | } |
AzureIoTClient | 28:add19eb7defa | 178 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 179 | |
AzureIoTClient | 28:add19eb7defa | 180 | if ((result != NULL) && (source_message->message_annotations != NULL)) |
AzureIoTClient | 28:add19eb7defa | 181 | { |
AzureIoTClient | 28:add19eb7defa | 182 | /* Codes_SRS_MESSAGE_01_007: [If message annotations exist on the source message they shall be cloned by using `annotations_clone`.] */ |
AzureIoTClient | 28:add19eb7defa | 183 | result->message_annotations = annotations_clone(source_message->message_annotations); |
AzureIoTClient | 28:add19eb7defa | 184 | if (result->message_annotations == NULL) |
AzureIoTClient | 28:add19eb7defa | 185 | { |
AzureIoTClient | 28:add19eb7defa | 186 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 187 | LogError("Cannot clone message annotations"); |
AzureIoTClient | 28:add19eb7defa | 188 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 189 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 190 | } |
AzureIoTClient | 28:add19eb7defa | 191 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 192 | |
AzureIoTClient | 28:add19eb7defa | 193 | if ((result != NULL) && (source_message->properties != NULL)) |
AzureIoTClient | 28:add19eb7defa | 194 | { |
AzureIoTClient | 28:add19eb7defa | 195 | /* Codes_SRS_MESSAGE_01_008: [If message properties exist on the source message they shall be cloned by using `properties_clone`.] */ |
AzureIoTClient | 28:add19eb7defa | 196 | result->properties = properties_clone(source_message->properties); |
AzureIoTClient | 28:add19eb7defa | 197 | if (result->properties == NULL) |
AzureIoTClient | 28:add19eb7defa | 198 | { |
AzureIoTClient | 28:add19eb7defa | 199 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 200 | LogError("Cannot clone message properties"); |
AzureIoTClient | 28:add19eb7defa | 201 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 202 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 203 | } |
AzureIoTClient | 28:add19eb7defa | 204 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 205 | |
AzureIoTClient | 28:add19eb7defa | 206 | if ((result != NULL) && (source_message->application_properties != NULL)) |
AzureIoTClient | 28:add19eb7defa | 207 | { |
AzureIoTClient | 28:add19eb7defa | 208 | /* Codes_SRS_MESSAGE_01_009: [If application properties exist on the source message they shall be cloned by using `amqpvalue_clone`.] */ |
AzureIoTClient | 28:add19eb7defa | 209 | result->application_properties = amqpvalue_clone(source_message->application_properties); |
AzureIoTClient | 28:add19eb7defa | 210 | if (result->application_properties == NULL) |
AzureIoTClient | 28:add19eb7defa | 211 | { |
AzureIoTClient | 28:add19eb7defa | 212 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 213 | LogError("Cannot clone application annotations"); |
AzureIoTClient | 28:add19eb7defa | 214 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 215 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 216 | } |
AzureIoTClient | 28:add19eb7defa | 217 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 218 | |
AzureIoTClient | 28:add19eb7defa | 219 | if ((result != NULL) && (source_message->footer != NULL)) |
AzureIoTClient | 28:add19eb7defa | 220 | { |
AzureIoTClient | 28:add19eb7defa | 221 | /* Codes_SRS_MESSAGE_01_010: [If a footer exists on the source message it shall be cloned by using `annotations_clone`.] */ |
AzureIoTClient | 28:add19eb7defa | 222 | result->footer = amqpvalue_clone(source_message->footer); |
AzureIoTClient | 28:add19eb7defa | 223 | if (result->footer == NULL) |
AzureIoTClient | 28:add19eb7defa | 224 | { |
AzureIoTClient | 28:add19eb7defa | 225 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 226 | LogError("Cannot clone message footer"); |
AzureIoTClient | 28:add19eb7defa | 227 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 228 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 229 | } |
AzureIoTClient | 28:add19eb7defa | 230 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 231 | |
AzureIoTClient | 28:add19eb7defa | 232 | if ((result != NULL) && (source_message->body_amqp_data_count > 0)) |
AzureIoTClient | 28:add19eb7defa | 233 | { |
AzureIoTClient | 28:add19eb7defa | 234 | size_t i; |
Azure.IoT Build | 0:6ae2f7bca550 | 235 | |
AzureIoTClient | 28:add19eb7defa | 236 | result->body_amqp_data_items = (BODY_AMQP_DATA*)malloc(source_message->body_amqp_data_count * sizeof(BODY_AMQP_DATA)); |
AzureIoTClient | 28:add19eb7defa | 237 | if (result->body_amqp_data_items == NULL) |
AzureIoTClient | 28:add19eb7defa | 238 | { |
AzureIoTClient | 28:add19eb7defa | 239 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 240 | LogError("Cannot allocate memory for body data sections"); |
AzureIoTClient | 28:add19eb7defa | 241 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 242 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 243 | } |
AzureIoTClient | 28:add19eb7defa | 244 | else |
AzureIoTClient | 28:add19eb7defa | 245 | { |
AzureIoTClient | 28:add19eb7defa | 246 | for (i = 0; i < source_message->body_amqp_data_count; i++) |
AzureIoTClient | 28:add19eb7defa | 247 | { |
AzureIoTClient | 28:add19eb7defa | 248 | 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 | 249 | |
AzureIoTClient | 28:add19eb7defa | 250 | /* 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 | 28:add19eb7defa | 251 | result->body_amqp_data_items[i].body_data_section_bytes = (unsigned char*)malloc(source_message->body_amqp_data_items[i].body_data_section_length); |
AzureIoTClient | 28:add19eb7defa | 252 | if (result->body_amqp_data_items[i].body_data_section_bytes == NULL) |
AzureIoTClient | 28:add19eb7defa | 253 | { |
AzureIoTClient | 28:add19eb7defa | 254 | LogError("Cannot allocate memory for body data section %u", (unsigned int)i); |
AzureIoTClient | 28:add19eb7defa | 255 | break; |
AzureIoTClient | 28:add19eb7defa | 256 | } |
AzureIoTClient | 28:add19eb7defa | 257 | else |
AzureIoTClient | 28:add19eb7defa | 258 | { |
AzureIoTClient | 28:add19eb7defa | 259 | (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); |
AzureIoTClient | 28:add19eb7defa | 260 | } |
AzureIoTClient | 28:add19eb7defa | 261 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 262 | |
AzureIoTClient | 28:add19eb7defa | 263 | result->body_amqp_data_count = i; |
AzureIoTClient | 28:add19eb7defa | 264 | if (i < source_message->body_amqp_data_count) |
AzureIoTClient | 28:add19eb7defa | 265 | { |
AzureIoTClient | 28:add19eb7defa | 266 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 267 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 268 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 269 | } |
AzureIoTClient | 28:add19eb7defa | 270 | } |
AzureIoTClient | 28:add19eb7defa | 271 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 272 | |
AzureIoTClient | 28:add19eb7defa | 273 | if ((result != NULL) && (source_message->body_amqp_sequence_count > 0)) |
AzureIoTClient | 28:add19eb7defa | 274 | { |
AzureIoTClient | 28:add19eb7defa | 275 | size_t i; |
Azure.IoT Build | 0:6ae2f7bca550 | 276 | |
AzureIoTClient | 28:add19eb7defa | 277 | result->body_amqp_sequence_items = (AMQP_VALUE*)malloc(source_message->body_amqp_sequence_count * sizeof(AMQP_VALUE)); |
AzureIoTClient | 28:add19eb7defa | 278 | if (result->body_amqp_sequence_items == NULL) |
AzureIoTClient | 28:add19eb7defa | 279 | { |
AzureIoTClient | 28:add19eb7defa | 280 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 281 | LogError("Cannot allocate memory for body AMQP sequences"); |
AzureIoTClient | 28:add19eb7defa | 282 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 283 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 284 | } |
AzureIoTClient | 28:add19eb7defa | 285 | else |
AzureIoTClient | 28:add19eb7defa | 286 | { |
AzureIoTClient | 28:add19eb7defa | 287 | for (i = 0; i < source_message->body_amqp_sequence_count; i++) |
AzureIoTClient | 28:add19eb7defa | 288 | { |
AzureIoTClient | 28:add19eb7defa | 289 | /* Codes_SRS_MESSAGE_01_160: [ If AMQP sequences are set as AMQP body they shall be cloned by calling `amqpvalue_clone`. ] */ |
AzureIoTClient | 28:add19eb7defa | 290 | result->body_amqp_sequence_items[i] = amqpvalue_clone(source_message->body_amqp_sequence_items[i]); |
AzureIoTClient | 28:add19eb7defa | 291 | if (result->body_amqp_sequence_items[i] == NULL) |
AzureIoTClient | 28:add19eb7defa | 292 | { |
AzureIoTClient | 28:add19eb7defa | 293 | LogError("Cannot clone AMQP sequence %u", (unsigned int)i); |
AzureIoTClient | 28:add19eb7defa | 294 | break; |
AzureIoTClient | 28:add19eb7defa | 295 | } |
AzureIoTClient | 28:add19eb7defa | 296 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 297 | |
AzureIoTClient | 28:add19eb7defa | 298 | result->body_amqp_sequence_count = i; |
AzureIoTClient | 28:add19eb7defa | 299 | if (i < source_message->body_amqp_sequence_count) |
AzureIoTClient | 28:add19eb7defa | 300 | { |
AzureIoTClient | 28:add19eb7defa | 301 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 302 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 303 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 304 | } |
AzureIoTClient | 28:add19eb7defa | 305 | } |
AzureIoTClient | 28:add19eb7defa | 306 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 307 | |
AzureIoTClient | 28:add19eb7defa | 308 | if ((result != NULL) && (source_message->body_amqp_value != NULL)) |
AzureIoTClient | 28:add19eb7defa | 309 | { |
AzureIoTClient | 28:add19eb7defa | 310 | /* Codes_SRS_MESSAGE_01_159: [If an AMQP value has been set as message body on the source message it shall be cloned by calling `amqpvalue_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 311 | result->body_amqp_value = amqpvalue_clone(source_message->body_amqp_value); |
AzureIoTClient | 28:add19eb7defa | 312 | if (result->body_amqp_value == NULL) |
AzureIoTClient | 28:add19eb7defa | 313 | { |
AzureIoTClient | 28:add19eb7defa | 314 | /* Codes_SRS_MESSAGE_01_012: [ If any cloning operation for the members of the source message fails, then `message_clone` shall fail and return NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 315 | LogError("Cannot clone body AMQP value"); |
AzureIoTClient | 28:add19eb7defa | 316 | message_destroy(result); |
AzureIoTClient | 28:add19eb7defa | 317 | result = NULL; |
AzureIoTClient | 28:add19eb7defa | 318 | } |
AzureIoTClient | 28:add19eb7defa | 319 | } |
AzureIoTClient | 28:add19eb7defa | 320 | } |
AzureIoTClient | 28:add19eb7defa | 321 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 322 | |
AzureIoTClient | 28:add19eb7defa | 323 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 324 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 325 | |
Azure.IoT Build | 0:6ae2f7bca550 | 326 | void message_destroy(MESSAGE_HANDLE message) |
Azure.IoT Build | 0:6ae2f7bca550 | 327 | { |
AzureIoTClient | 28:add19eb7defa | 328 | if (message == NULL) |
AzureIoTClient | 28:add19eb7defa | 329 | { |
AzureIoTClient | 28:add19eb7defa | 330 | /* Codes_SRS_MESSAGE_01_014: [ If `message` is NULL, `message_destroy` shall do nothing. ]*/ |
AzureIoTClient | 28:add19eb7defa | 331 | LogError("NULL message"); |
AzureIoTClient | 28:add19eb7defa | 332 | } |
AzureIoTClient | 28:add19eb7defa | 333 | else |
AzureIoTClient | 28:add19eb7defa | 334 | { |
AzureIoTClient | 28:add19eb7defa | 335 | /* Codes_SRS_MESSAGE_01_013: [ `message_destroy` shall free all resources allocated by the message instance identified by the `message` argument. ]*/ |
AzureIoTClient | 28:add19eb7defa | 336 | if (message->header != NULL) |
AzureIoTClient | 28:add19eb7defa | 337 | { |
AzureIoTClient | 28:add19eb7defa | 338 | /* Codes_SRS_MESSAGE_01_015: [ The message header shall be freed by calling `header_destroy`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 339 | header_destroy(message->header); |
AzureIoTClient | 28:add19eb7defa | 340 | } |
AzureIoTClient | 28:add19eb7defa | 341 | |
AzureIoTClient | 28:add19eb7defa | 342 | if (message->delivery_annotations != NULL) |
AzureIoTClient | 28:add19eb7defa | 343 | { |
AzureIoTClient | 28:add19eb7defa | 344 | /* Codes_SRS_MESSAGE_01_016: [ The delivery annotations shall be freed by calling `annotations_destroy`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 345 | annotations_destroy(message->delivery_annotations); |
AzureIoTClient | 28:add19eb7defa | 346 | } |
AzureIoTClient | 28:add19eb7defa | 347 | |
AzureIoTClient | 24:2c59c2d43ebf | 348 | if (message->message_annotations != NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 349 | { |
AzureIoTClient | 28:add19eb7defa | 350 | /* Codes_SRS_MESSAGE_01_017: [ The message annotations shall be freed by calling `annotations_destroy`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 351 | annotations_destroy(message->message_annotations); |
AzureIoTClient | 28:add19eb7defa | 352 | } |
AzureIoTClient | 28:add19eb7defa | 353 | |
AzureIoTClient | 28:add19eb7defa | 354 | if (message->properties != NULL) |
AzureIoTClient | 28:add19eb7defa | 355 | { |
AzureIoTClient | 28:add19eb7defa | 356 | /* Codes_SRS_MESSAGE_01_018: [ The message properties shall be freed by calling `properties_destroy`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 357 | properties_destroy(message->properties); |
AzureIoTClient | 28:add19eb7defa | 358 | } |
AzureIoTClient | 28:add19eb7defa | 359 | |
AzureIoTClient | 28:add19eb7defa | 360 | if (message->application_properties != NULL) |
AzureIoTClient | 28:add19eb7defa | 361 | { |
AzureIoTClient | 28:add19eb7defa | 362 | /* Codes_SRS_MESSAGE_01_019: [ The application properties shall be freed by calling `amqpvalue_destroy`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 363 | application_properties_destroy(message->application_properties); |
Azure.IoT Build | 0:6ae2f7bca550 | 364 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 365 | |
AzureIoTClient | 28:add19eb7defa | 366 | if (message->footer != NULL) |
AzureIoTClient | 28:add19eb7defa | 367 | { |
AzureIoTClient | 28:add19eb7defa | 368 | /* Codes_SRS_MESSAGE_01_020: [ The message footer shall be freed by calling `annotations_destroy`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 369 | annotations_destroy(message->footer); |
AzureIoTClient | 28:add19eb7defa | 370 | } |
AzureIoTClient | 28:add19eb7defa | 371 | |
AzureIoTClient | 28:add19eb7defa | 372 | if (message->body_amqp_value != NULL) |
AzureIoTClient | 28:add19eb7defa | 373 | { |
AzureIoTClient | 28:add19eb7defa | 374 | /* Codes_SRS_MESSAGE_01_021: [ If the message body is made of an AMQP value, the value shall be freed by calling `amqpvalue_destroy`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 375 | amqpvalue_destroy(message->body_amqp_value); |
AzureIoTClient | 28:add19eb7defa | 376 | } |
AzureIoTClient | 28:add19eb7defa | 377 | |
AzureIoTClient | 28:add19eb7defa | 378 | /* Codes_SRS_MESSAGE_01_136: [ If the message body is made of several AMQP data items, they shall all be freed. ]*/ |
AzureIoTClient | 28:add19eb7defa | 379 | free_all_body_data_items(message); |
AzureIoTClient | 28:add19eb7defa | 380 | |
AzureIoTClient | 28:add19eb7defa | 381 | /* Codes_SRS_MESSAGE_01_136: [ If the message body is made of several AMQP sequences, they shall all be freed. ]*/ |
AzureIoTClient | 28:add19eb7defa | 382 | free_all_body_sequence_items(message); |
AzureIoTClient | 28:add19eb7defa | 383 | free(message); |
AzureIoTClient | 28:add19eb7defa | 384 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 385 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 386 | |
Azure.IoT Build | 0:6ae2f7bca550 | 387 | int message_set_header(MESSAGE_HANDLE message, HEADER_HANDLE header) |
Azure.IoT Build | 0:6ae2f7bca550 | 388 | { |
AzureIoTClient | 28:add19eb7defa | 389 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 390 | |
AzureIoTClient | 28:add19eb7defa | 391 | if (message == NULL) |
AzureIoTClient | 28:add19eb7defa | 392 | { |
AzureIoTClient | 28:add19eb7defa | 393 | /* Codes_SRS_MESSAGE_01_024: [ If `message` is NULL, `message_set_header` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 394 | LogError("NULL message"); |
AzureIoTClient | 28:add19eb7defa | 395 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 396 | } |
AzureIoTClient | 28:add19eb7defa | 397 | else |
AzureIoTClient | 28:add19eb7defa | 398 | { |
AzureIoTClient | 28:add19eb7defa | 399 | HEADER_HANDLE new_header; |
AzureIoTClient | 28:add19eb7defa | 400 | |
AzureIoTClient | 28:add19eb7defa | 401 | if (header == NULL) |
AzureIoTClient | 28:add19eb7defa | 402 | { |
AzureIoTClient | 28:add19eb7defa | 403 | /* Codes_SRS_MESSAGE_01_139: [ If `message_header` is NULL, the previously stored header associated with `message` shall be freed. ]*/ |
AzureIoTClient | 28:add19eb7defa | 404 | if (message->header != NULL) |
AzureIoTClient | 28:add19eb7defa | 405 | { |
AzureIoTClient | 28:add19eb7defa | 406 | header_destroy(message->header); |
AzureIoTClient | 28:add19eb7defa | 407 | message->header = NULL; |
AzureIoTClient | 28:add19eb7defa | 408 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 409 | |
AzureIoTClient | 28:add19eb7defa | 410 | /* Codes_SRS_MESSAGE_01_023: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 411 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 412 | } |
AzureIoTClient | 28:add19eb7defa | 413 | else |
AzureIoTClient | 28:add19eb7defa | 414 | { |
AzureIoTClient | 28:add19eb7defa | 415 | /* Codes_SRS_MESSAGE_01_022: [ `message_set_header` shall copy the contents of `message_header` as the header for the message instance identified by message. ]*/ |
AzureIoTClient | 28:add19eb7defa | 416 | /* Codes_SRS_MESSAGE_01_025: [ Cloning the header shall be done by calling `header_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 417 | new_header = header_clone(header); |
AzureIoTClient | 28:add19eb7defa | 418 | if (new_header == NULL) |
AzureIoTClient | 28:add19eb7defa | 419 | { |
AzureIoTClient | 28:add19eb7defa | 420 | /* Codes_SRS_MESSAGE_01_026: [ If `header_clone` fails, `message_set_header` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 421 | LogError("Cannot clone message header"); |
AzureIoTClient | 28:add19eb7defa | 422 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 423 | } |
AzureIoTClient | 28:add19eb7defa | 424 | else |
AzureIoTClient | 28:add19eb7defa | 425 | { |
AzureIoTClient | 28:add19eb7defa | 426 | /* Codes_SRS_MESSAGE_01_138: [ If setting the header fails, the previous value shall be preserved. ]*/ |
AzureIoTClient | 28:add19eb7defa | 427 | /* Only do the free of the previous value if we could clone the new one*/ |
AzureIoTClient | 28:add19eb7defa | 428 | if (message->header != NULL) |
AzureIoTClient | 28:add19eb7defa | 429 | { |
AzureIoTClient | 28:add19eb7defa | 430 | header_destroy(message->header); |
AzureIoTClient | 28:add19eb7defa | 431 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 432 | |
AzureIoTClient | 28:add19eb7defa | 433 | message->header = new_header; |
Azure.IoT Build | 0:6ae2f7bca550 | 434 | |
AzureIoTClient | 28:add19eb7defa | 435 | /* Codes_SRS_MESSAGE_01_023: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 436 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 437 | } |
AzureIoTClient | 28:add19eb7defa | 438 | } |
AzureIoTClient | 28:add19eb7defa | 439 | } |
AzureIoTClient | 28:add19eb7defa | 440 | |
AzureIoTClient | 28:add19eb7defa | 441 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 442 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 443 | |
Azure.IoT Build | 0:6ae2f7bca550 | 444 | int message_get_header(MESSAGE_HANDLE message, HEADER_HANDLE* header) |
Azure.IoT Build | 0:6ae2f7bca550 | 445 | { |
AzureIoTClient | 28:add19eb7defa | 446 | int result; |
AzureIoTClient | 28:add19eb7defa | 447 | |
AzureIoTClient | 28:add19eb7defa | 448 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 449 | (header == NULL)) |
AzureIoTClient | 28:add19eb7defa | 450 | { |
AzureIoTClient | 28:add19eb7defa | 451 | /* Codes_SRS_MESSAGE_01_029: [ If `message` or `message_header` is NULL, `message_get_header` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 452 | LogError("Bad arguments: message = %p, header = %p", |
AzureIoTClient | 28:add19eb7defa | 453 | message, header); |
AzureIoTClient | 28:add19eb7defa | 454 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 455 | } |
AzureIoTClient | 28:add19eb7defa | 456 | else |
AzureIoTClient | 28:add19eb7defa | 457 | { |
AzureIoTClient | 28:add19eb7defa | 458 | if (message->header == NULL) |
AzureIoTClient | 28:add19eb7defa | 459 | { |
AzureIoTClient | 28:add19eb7defa | 460 | /* Codes_SRS_MESSAGE_01_143: [ If no header has been set, `message_get_header` shall set `message_header` to NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 461 | *header = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 462 | |
AzureIoTClient | 28:add19eb7defa | 463 | /* Codes_SRS_MESSAGE_01_028: [ On success, `message_get_header` shall return 0.]*/ |
AzureIoTClient | 28:add19eb7defa | 464 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 465 | } |
AzureIoTClient | 28:add19eb7defa | 466 | else |
AzureIoTClient | 28:add19eb7defa | 467 | { |
AzureIoTClient | 28:add19eb7defa | 468 | /* Codes_SRS_MESSAGE_01_027: [ `message_get_header` shall copy the contents of header for the message instance identified by `message` into the argument `message_header`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 469 | /* Codes_SRS_MESSAGE_01_030: [ Cloning the header shall be done by calling `header_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 470 | *header = header_clone(message->header); |
AzureIoTClient | 28:add19eb7defa | 471 | if (*header == NULL) |
AzureIoTClient | 28:add19eb7defa | 472 | { |
AzureIoTClient | 28:add19eb7defa | 473 | /* Codes_SRS_MESSAGE_01_031: [ If `header_clone` fails, `message_get_header` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 474 | LogError("Cannot clone message header"); |
AzureIoTClient | 28:add19eb7defa | 475 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 476 | } |
AzureIoTClient | 28:add19eb7defa | 477 | else |
AzureIoTClient | 28:add19eb7defa | 478 | { |
AzureIoTClient | 28:add19eb7defa | 479 | /* Codes_SRS_MESSAGE_01_028: [ On success, `message_get_header` shall return 0.]*/ |
AzureIoTClient | 28:add19eb7defa | 480 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 481 | } |
AzureIoTClient | 28:add19eb7defa | 482 | } |
AzureIoTClient | 28:add19eb7defa | 483 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 484 | |
AzureIoTClient | 28:add19eb7defa | 485 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 486 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 487 | |
AzureIoTClient | 28:add19eb7defa | 488 | int message_set_delivery_annotations(MESSAGE_HANDLE message, delivery_annotations annotations) |
Azure.IoT Build | 0:6ae2f7bca550 | 489 | { |
AzureIoTClient | 28:add19eb7defa | 490 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 491 | |
AzureIoTClient | 28:add19eb7defa | 492 | if (message == NULL) |
AzureIoTClient | 28:add19eb7defa | 493 | { |
AzureIoTClient | 28:add19eb7defa | 494 | /* Codes_SRS_MESSAGE_01_034: [ If `message` is NULL, `message_set_delivery_annotations` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 495 | LogError("NULL message"); |
AzureIoTClient | 28:add19eb7defa | 496 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 497 | } |
AzureIoTClient | 28:add19eb7defa | 498 | else |
AzureIoTClient | 28:add19eb7defa | 499 | { |
AzureIoTClient | 28:add19eb7defa | 500 | delivery_annotations new_delivery_annotations; |
Azure.IoT Build | 0:6ae2f7bca550 | 501 | |
AzureIoTClient | 28:add19eb7defa | 502 | if (annotations == NULL) |
AzureIoTClient | 28:add19eb7defa | 503 | { |
AzureIoTClient | 28:add19eb7defa | 504 | /* Codes_SRS_MESSAGE_01_141: [ If `annotations` is NULL, the previously stored delivery annotations associated with `message` shall be freed. ]*/ |
AzureIoTClient | 28:add19eb7defa | 505 | if (message->delivery_annotations != NULL) |
AzureIoTClient | 28:add19eb7defa | 506 | { |
AzureIoTClient | 28:add19eb7defa | 507 | annotations_destroy(message->delivery_annotations); |
AzureIoTClient | 28:add19eb7defa | 508 | message->delivery_annotations = NULL; |
AzureIoTClient | 28:add19eb7defa | 509 | } |
AzureIoTClient | 46:01f7ca900e07 | 510 | |
AzureIoTClient | 28:add19eb7defa | 511 | /* Codes_SRS_MESSAGE_01_033: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 512 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 513 | } |
AzureIoTClient | 28:add19eb7defa | 514 | else |
AzureIoTClient | 28:add19eb7defa | 515 | { |
AzureIoTClient | 28:add19eb7defa | 516 | /* Codes_SRS_MESSAGE_01_032: [ `message_set_delivery_annotations` shall copy the contents of `annotations` as the delivery annotations for the message instance identified by `message`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 517 | /* Codes_SRS_MESSAGE_01_035: [ Cloning the delivery annotations shall be done by calling `annotations_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 518 | new_delivery_annotations = annotations_clone(annotations); |
AzureIoTClient | 28:add19eb7defa | 519 | if (new_delivery_annotations == NULL) |
AzureIoTClient | 28:add19eb7defa | 520 | { |
AzureIoTClient | 28:add19eb7defa | 521 | /* Codes_SRS_MESSAGE_01_036: [ If `annotations_clone` fails, `message_set_delivery_annotations` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 522 | LogError("Cannot clone delivery annotations"); |
AzureIoTClient | 28:add19eb7defa | 523 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 524 | } |
AzureIoTClient | 28:add19eb7defa | 525 | else |
AzureIoTClient | 28:add19eb7defa | 526 | { |
AzureIoTClient | 28:add19eb7defa | 527 | /* Codes_SRS_MESSAGE_01_140: [** If setting the delivery annotations fails, the previous value shall be preserved. ]*/ |
AzureIoTClient | 28:add19eb7defa | 528 | /* Only do the free of the previous value if we could clone the new one*/ |
AzureIoTClient | 28:add19eb7defa | 529 | if (message->delivery_annotations != NULL) |
AzureIoTClient | 28:add19eb7defa | 530 | { |
AzureIoTClient | 28:add19eb7defa | 531 | annotations_destroy(message->delivery_annotations); |
AzureIoTClient | 28:add19eb7defa | 532 | } |
AzureIoTClient | 24:2c59c2d43ebf | 533 | |
AzureIoTClient | 28:add19eb7defa | 534 | message->delivery_annotations = new_delivery_annotations; |
Azure.IoT Build | 0:6ae2f7bca550 | 535 | |
AzureIoTClient | 28:add19eb7defa | 536 | /* Codes_SRS_MESSAGE_01_033: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 537 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 538 | } |
AzureIoTClient | 28:add19eb7defa | 539 | } |
AzureIoTClient | 28:add19eb7defa | 540 | } |
AzureIoTClient | 28:add19eb7defa | 541 | |
AzureIoTClient | 28:add19eb7defa | 542 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 543 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 544 | |
AzureIoTClient | 28:add19eb7defa | 545 | int message_get_delivery_annotations(MESSAGE_HANDLE message, delivery_annotations* annotations) |
Azure.IoT Build | 0:6ae2f7bca550 | 546 | { |
AzureIoTClient | 28:add19eb7defa | 547 | int result; |
AzureIoTClient | 28:add19eb7defa | 548 | |
AzureIoTClient | 28:add19eb7defa | 549 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 550 | (annotations == NULL)) |
AzureIoTClient | 28:add19eb7defa | 551 | { |
AzureIoTClient | 28:add19eb7defa | 552 | /* Codes_SRS_MESSAGE_01_039: [ If `message` or `annotations` is NULL, `message_get_delivery_annotations` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 553 | LogError("Bad arguments: message = %p, annotations = %p", |
AzureIoTClient | 28:add19eb7defa | 554 | message, annotations); |
AzureIoTClient | 28:add19eb7defa | 555 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 556 | } |
AzureIoTClient | 28:add19eb7defa | 557 | else |
AzureIoTClient | 28:add19eb7defa | 558 | { |
AzureIoTClient | 28:add19eb7defa | 559 | if (message->delivery_annotations == NULL) |
AzureIoTClient | 28:add19eb7defa | 560 | { |
AzureIoTClient | 28:add19eb7defa | 561 | /* Codes_SRS_MESSAGE_01_142: [ If no delivery annotations have been set, `message_get_delivery_annotations` shall set `annotations` to NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 562 | *annotations = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 563 | |
AzureIoTClient | 28:add19eb7defa | 564 | /* Codes_SRS_MESSAGE_01_038: [ On success, `message_get_delivery_annotations` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 565 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 566 | } |
AzureIoTClient | 28:add19eb7defa | 567 | else |
AzureIoTClient | 28:add19eb7defa | 568 | { |
AzureIoTClient | 28:add19eb7defa | 569 | /* Codes_SRS_MESSAGE_01_037: [ `message_get_delivery_annotations` shall copy the contents of delivery annotations for the message instance identified by `message` into the argument `annotations`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 570 | /* Codes_SRS_MESSAGE_01_040: [ Cloning the delivery annotations shall be done by calling `annotations_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 571 | *annotations = annotations_clone(message->delivery_annotations); |
AzureIoTClient | 28:add19eb7defa | 572 | if (*annotations == NULL) |
AzureIoTClient | 28:add19eb7defa | 573 | { |
AzureIoTClient | 28:add19eb7defa | 574 | /* Codes_SRS_MESSAGE_01_041: [ If `annotations_clone` fails, `message_get_delivery_annotations` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 575 | LogError("Cannot clone delivery annotations"); |
AzureIoTClient | 28:add19eb7defa | 576 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 577 | } |
AzureIoTClient | 28:add19eb7defa | 578 | else |
AzureIoTClient | 28:add19eb7defa | 579 | { |
AzureIoTClient | 28:add19eb7defa | 580 | /* Codes_SRS_MESSAGE_01_038: [ On success, `message_get_delivery_annotations` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 581 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 582 | } |
AzureIoTClient | 28:add19eb7defa | 583 | } |
AzureIoTClient | 28:add19eb7defa | 584 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 585 | |
AzureIoTClient | 28:add19eb7defa | 586 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 587 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 588 | |
AzureIoTClient | 28:add19eb7defa | 589 | int message_set_message_annotations(MESSAGE_HANDLE message, message_annotations annotations) |
Azure.IoT Build | 0:6ae2f7bca550 | 590 | { |
AzureIoTClient | 28:add19eb7defa | 591 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 592 | |
AzureIoTClient | 28:add19eb7defa | 593 | if (message == NULL) |
AzureIoTClient | 28:add19eb7defa | 594 | { |
AzureIoTClient | 28:add19eb7defa | 595 | /* Codes_SRS_MESSAGE_01_044: [ If `message` is NULL, `message_set_message_annotations` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 596 | LogError("NULL message"); |
AzureIoTClient | 28:add19eb7defa | 597 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 598 | } |
AzureIoTClient | 28:add19eb7defa | 599 | else |
AzureIoTClient | 28:add19eb7defa | 600 | { |
AzureIoTClient | 28:add19eb7defa | 601 | if (annotations == NULL) |
AzureIoTClient | 28:add19eb7defa | 602 | { |
AzureIoTClient | 28:add19eb7defa | 603 | /* Codes_SRS_MESSAGE_01_145: [ If `annotations` is NULL, the previously stored message annotations associated with `message` shall be freed. ]*/ |
AzureIoTClient | 28:add19eb7defa | 604 | if (message->message_annotations != NULL) |
AzureIoTClient | 28:add19eb7defa | 605 | { |
AzureIoTClient | 28:add19eb7defa | 606 | annotations_destroy(message->message_annotations); |
AzureIoTClient | 28:add19eb7defa | 607 | message->message_annotations = NULL; |
AzureIoTClient | 28:add19eb7defa | 608 | } |
AzureIoTClient | 28:add19eb7defa | 609 | |
AzureIoTClient | 28:add19eb7defa | 610 | /* Codes_SRS_MESSAGE_01_043: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 611 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 612 | } |
AzureIoTClient | 28:add19eb7defa | 613 | else |
AzureIoTClient | 28:add19eb7defa | 614 | { |
AzureIoTClient | 28:add19eb7defa | 615 | message_annotations new_message_annotations; |
Azure.IoT Build | 0:6ae2f7bca550 | 616 | |
AzureIoTClient | 28:add19eb7defa | 617 | /* Codes_SRS_MESSAGE_01_042: [ `message_set_message_annotations` shall copy the contents of `annotations` as the message annotations for the message instance identified by `message`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 618 | /* Codes_SRS_MESSAGE_01_045: [ Cloning the message annotations shall be done by calling `annotations_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 619 | new_message_annotations = annotations_clone(annotations); |
AzureIoTClient | 28:add19eb7defa | 620 | if (new_message_annotations == NULL) |
AzureIoTClient | 28:add19eb7defa | 621 | { |
AzureIoTClient | 28:add19eb7defa | 622 | /* Codes_SRS_MESSAGE_01_046: [ If `annotations_clone` fails, `message_set_message_annotations` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 623 | LogError("Cannot clone message annotations"); |
AzureIoTClient | 28:add19eb7defa | 624 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 625 | } |
AzureIoTClient | 28:add19eb7defa | 626 | else |
AzureIoTClient | 28:add19eb7defa | 627 | { |
AzureIoTClient | 28:add19eb7defa | 628 | /* Codes_SRS_MESSAGE_01_144: [ If setting the message annotations fails, the previous value shall be preserved. ]*/ |
AzureIoTClient | 28:add19eb7defa | 629 | /* Only do the free of the previous value if we could clone the new one*/ |
AzureIoTClient | 28:add19eb7defa | 630 | if (message->message_annotations != NULL) |
AzureIoTClient | 28:add19eb7defa | 631 | { |
AzureIoTClient | 28:add19eb7defa | 632 | annotations_destroy(message->message_annotations); |
AzureIoTClient | 28:add19eb7defa | 633 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 634 | |
AzureIoTClient | 28:add19eb7defa | 635 | message->message_annotations = new_message_annotations; |
Azure.IoT Build | 0:6ae2f7bca550 | 636 | |
AzureIoTClient | 28:add19eb7defa | 637 | /* Codes_SRS_MESSAGE_01_043: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 638 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 639 | } |
AzureIoTClient | 28:add19eb7defa | 640 | } |
AzureIoTClient | 28:add19eb7defa | 641 | } |
AzureIoTClient | 28:add19eb7defa | 642 | |
AzureIoTClient | 28:add19eb7defa | 643 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 644 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 645 | |
Azure.IoT Build | 0:6ae2f7bca550 | 646 | int message_get_message_annotations(MESSAGE_HANDLE message, annotations* message_annotations) |
Azure.IoT Build | 0:6ae2f7bca550 | 647 | { |
AzureIoTClient | 28:add19eb7defa | 648 | int result; |
AzureIoTClient | 28:add19eb7defa | 649 | |
AzureIoTClient | 28:add19eb7defa | 650 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 651 | (message_annotations == NULL)) |
AzureIoTClient | 28:add19eb7defa | 652 | { |
AzureIoTClient | 28:add19eb7defa | 653 | /* Codes_SRS_MESSAGE_01_049: [ If `message` or `annotations` is NULL, `message_get_message_annotations` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 654 | LogError("Bad arguments: message = %p, message_annotations = %p", |
AzureIoTClient | 28:add19eb7defa | 655 | message, message_annotations); |
AzureIoTClient | 28:add19eb7defa | 656 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 657 | } |
AzureIoTClient | 28:add19eb7defa | 658 | else |
AzureIoTClient | 28:add19eb7defa | 659 | { |
AzureIoTClient | 28:add19eb7defa | 660 | if (message->message_annotations == NULL) |
AzureIoTClient | 28:add19eb7defa | 661 | { |
AzureIoTClient | 28:add19eb7defa | 662 | /* Codes_SRS_MESSAGE_01_146: [ If no message annotations have been set, `message_get_message_annotations` shall set `annotations` to NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 663 | *message_annotations = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 664 | |
AzureIoTClient | 28:add19eb7defa | 665 | /* Codes_SRS_MESSAGE_01_048: [ On success, `message_get_message_annotations` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 666 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 667 | } |
AzureIoTClient | 28:add19eb7defa | 668 | else |
AzureIoTClient | 28:add19eb7defa | 669 | { |
AzureIoTClient | 28:add19eb7defa | 670 | /* Codes_SRS_MESSAGE_01_047: [ `message_get_message_annotations` shall copy the contents of message annotations for the message instance identified by `message` into the argument `annotations`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 671 | /* Codes_SRS_MESSAGE_01_050: [ Cloning the message annotations shall be done by calling `annotations_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 672 | *message_annotations = annotations_clone(message->message_annotations); |
AzureIoTClient | 28:add19eb7defa | 673 | if (*message_annotations == NULL) |
AzureIoTClient | 28:add19eb7defa | 674 | { |
AzureIoTClient | 28:add19eb7defa | 675 | /* Codes_SRS_MESSAGE_01_051: [ If `annotations_clone` fails, `message_get_message_annotations` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 676 | LogError("Cannot clone message annotations"); |
AzureIoTClient | 28:add19eb7defa | 677 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 678 | } |
AzureIoTClient | 28:add19eb7defa | 679 | else |
AzureIoTClient | 28:add19eb7defa | 680 | { |
AzureIoTClient | 28:add19eb7defa | 681 | /* Codes_SRS_MESSAGE_01_048: [ On success, `message_get_message_annotations` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 682 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 683 | } |
AzureIoTClient | 28:add19eb7defa | 684 | } |
AzureIoTClient | 28:add19eb7defa | 685 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 686 | |
AzureIoTClient | 28:add19eb7defa | 687 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 688 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 689 | |
Azure.IoT Build | 0:6ae2f7bca550 | 690 | int message_set_properties(MESSAGE_HANDLE message, PROPERTIES_HANDLE properties) |
Azure.IoT Build | 0:6ae2f7bca550 | 691 | { |
AzureIoTClient | 28:add19eb7defa | 692 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 693 | |
AzureIoTClient | 28:add19eb7defa | 694 | if (message == NULL) |
AzureIoTClient | 28:add19eb7defa | 695 | { |
AzureIoTClient | 28:add19eb7defa | 696 | /* Codes_SRS_MESSAGE_01_054: [ If `message` is NULL, `message_set_properties` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 697 | LogError("NULL message"); |
AzureIoTClient | 28:add19eb7defa | 698 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 699 | } |
AzureIoTClient | 28:add19eb7defa | 700 | else |
AzureIoTClient | 28:add19eb7defa | 701 | { |
AzureIoTClient | 28:add19eb7defa | 702 | if (properties == NULL) |
AzureIoTClient | 28:add19eb7defa | 703 | { |
AzureIoTClient | 28:add19eb7defa | 704 | /* Codes_SRS_MESSAGE_01_147: [ If `properties` is NULL, the previously stored message properties associated with `message` shall be freed. ]*/ |
AzureIoTClient | 28:add19eb7defa | 705 | if (message->properties != NULL) |
AzureIoTClient | 28:add19eb7defa | 706 | { |
AzureIoTClient | 28:add19eb7defa | 707 | properties_destroy(message->properties); |
AzureIoTClient | 28:add19eb7defa | 708 | message->properties = NULL; |
AzureIoTClient | 28:add19eb7defa | 709 | } |
AzureIoTClient | 28:add19eb7defa | 710 | |
AzureIoTClient | 28:add19eb7defa | 711 | /* Codes_SRS_MESSAGE_01_053: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 712 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 713 | } |
AzureIoTClient | 28:add19eb7defa | 714 | else |
AzureIoTClient | 28:add19eb7defa | 715 | { |
AzureIoTClient | 28:add19eb7defa | 716 | PROPERTIES_HANDLE new_properties; |
Azure.IoT Build | 0:6ae2f7bca550 | 717 | |
AzureIoTClient | 28:add19eb7defa | 718 | /* Codes_SRS_MESSAGE_01_052: [ `message_set_properties` shall copy the contents of `properties` as the message properties for the message instance identified by `message`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 719 | /* Codes_SRS_MESSAGE_01_055: [ Cloning the message properties shall be done by calling `properties_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 720 | new_properties = properties_clone(properties); |
AzureIoTClient | 28:add19eb7defa | 721 | if (new_properties == NULL) |
AzureIoTClient | 28:add19eb7defa | 722 | { |
AzureIoTClient | 28:add19eb7defa | 723 | /* Codes_SRS_MESSAGE_01_056: [ If `properties_clone` fails, `message_set_properties` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 724 | LogError("Cannot clone message properties"); |
AzureIoTClient | 28:add19eb7defa | 725 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 726 | } |
AzureIoTClient | 28:add19eb7defa | 727 | else |
AzureIoTClient | 28:add19eb7defa | 728 | { |
AzureIoTClient | 28:add19eb7defa | 729 | /* Codes_SRS_MESSAGE_01_063: [ If setting the message properties fails, the previous value shall be preserved. ]*/ |
AzureIoTClient | 28:add19eb7defa | 730 | /* Only do the free of the previous value if we could clone the new one*/ |
AzureIoTClient | 28:add19eb7defa | 731 | if (message->properties != NULL) |
AzureIoTClient | 28:add19eb7defa | 732 | { |
AzureIoTClient | 28:add19eb7defa | 733 | properties_destroy(message->properties); |
AzureIoTClient | 28:add19eb7defa | 734 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 735 | |
AzureIoTClient | 28:add19eb7defa | 736 | message->properties = new_properties; |
Azure.IoT Build | 0:6ae2f7bca550 | 737 | |
AzureIoTClient | 28:add19eb7defa | 738 | /* Codes_SRS_MESSAGE_01_053: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 739 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 740 | } |
AzureIoTClient | 28:add19eb7defa | 741 | } |
AzureIoTClient | 28:add19eb7defa | 742 | } |
AzureIoTClient | 28:add19eb7defa | 743 | |
AzureIoTClient | 28:add19eb7defa | 744 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 745 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 746 | |
Azure.IoT Build | 0:6ae2f7bca550 | 747 | int message_get_properties(MESSAGE_HANDLE message, PROPERTIES_HANDLE* properties) |
Azure.IoT Build | 0:6ae2f7bca550 | 748 | { |
AzureIoTClient | 28:add19eb7defa | 749 | int result; |
AzureIoTClient | 28:add19eb7defa | 750 | |
AzureIoTClient | 28:add19eb7defa | 751 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 752 | (properties == NULL)) |
AzureIoTClient | 28:add19eb7defa | 753 | { |
AzureIoTClient | 28:add19eb7defa | 754 | /* Codes_SRS_MESSAGE_01_059: [ If `message` or `properties` is NULL, `message_get_properties` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 755 | LogError("Bad arguments: message = %p, properties = %p", |
AzureIoTClient | 28:add19eb7defa | 756 | message, properties); |
AzureIoTClient | 28:add19eb7defa | 757 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 758 | } |
AzureIoTClient | 28:add19eb7defa | 759 | else |
AzureIoTClient | 28:add19eb7defa | 760 | { |
AzureIoTClient | 28:add19eb7defa | 761 | if (message->properties == NULL) |
AzureIoTClient | 28:add19eb7defa | 762 | { |
AzureIoTClient | 28:add19eb7defa | 763 | /* Codes_SRS_MESSAGE_01_148: [ If no message properties have been set, `message_get_properties` shall set `properties` to NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 764 | *properties = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 765 | |
AzureIoTClient | 28:add19eb7defa | 766 | /* Codes_SRS_MESSAGE_01_058: [ On success, `message_get_properties` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 767 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 768 | } |
AzureIoTClient | 28:add19eb7defa | 769 | else |
AzureIoTClient | 28:add19eb7defa | 770 | { |
AzureIoTClient | 28:add19eb7defa | 771 | /* Codes_SRS_MESSAGE_01_057: [ `message_get_properties` shall copy the contents of message properties for the message instance identified by `message` into the argument `properties`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 772 | /* Codes_SRS_MESSAGE_01_060: [ Cloning the message properties shall be done by calling `properties_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 773 | *properties = properties_clone(message->properties); |
AzureIoTClient | 28:add19eb7defa | 774 | if (*properties == NULL) |
AzureIoTClient | 28:add19eb7defa | 775 | { |
AzureIoTClient | 28:add19eb7defa | 776 | /* Codes_SRS_MESSAGE_01_061: [ If `properties_clone` fails, `message_get_properties` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 777 | LogError("Cannot clone message properties"); |
AzureIoTClient | 28:add19eb7defa | 778 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 779 | } |
AzureIoTClient | 28:add19eb7defa | 780 | else |
AzureIoTClient | 28:add19eb7defa | 781 | { |
AzureIoTClient | 28:add19eb7defa | 782 | /* Codes_SRS_MESSAGE_01_058: [ On success, `message_get_properties` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 783 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 784 | } |
AzureIoTClient | 28:add19eb7defa | 785 | } |
AzureIoTClient | 28:add19eb7defa | 786 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 787 | |
AzureIoTClient | 28:add19eb7defa | 788 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 789 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 790 | |
Azure.IoT Build | 0:6ae2f7bca550 | 791 | int message_set_application_properties(MESSAGE_HANDLE message, AMQP_VALUE application_properties) |
Azure.IoT Build | 0:6ae2f7bca550 | 792 | { |
AzureIoTClient | 28:add19eb7defa | 793 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 794 | |
AzureIoTClient | 28:add19eb7defa | 795 | if (message == NULL) |
AzureIoTClient | 28:add19eb7defa | 796 | { |
AzureIoTClient | 28:add19eb7defa | 797 | /* Codes_SRS_MESSAGE_01_066: [ If `message` is NULL, `message_set_application_properties` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 798 | LogError("NULL message"); |
AzureIoTClient | 28:add19eb7defa | 799 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 800 | } |
AzureIoTClient | 28:add19eb7defa | 801 | else |
AzureIoTClient | 28:add19eb7defa | 802 | { |
AzureIoTClient | 28:add19eb7defa | 803 | AMQP_VALUE new_application_properties; |
AzureIoTClient | 28:add19eb7defa | 804 | |
AzureIoTClient | 28:add19eb7defa | 805 | /* Tests_SRS_MESSAGE_01_149: [ If `application_properties` is NULL, the previously stored application properties associated with `message` shall be freed. ]*/ |
AzureIoTClient | 28:add19eb7defa | 806 | if (application_properties == NULL) |
AzureIoTClient | 28:add19eb7defa | 807 | { |
AzureIoTClient | 28:add19eb7defa | 808 | if (message->application_properties != NULL) |
AzureIoTClient | 28:add19eb7defa | 809 | { |
AzureIoTClient | 28:add19eb7defa | 810 | amqpvalue_destroy(message->application_properties); |
AzureIoTClient | 28:add19eb7defa | 811 | message->application_properties = NULL; |
AzureIoTClient | 28:add19eb7defa | 812 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 813 | |
AzureIoTClient | 28:add19eb7defa | 814 | /* Codes_SRS_MESSAGE_01_065: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 815 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 816 | } |
AzureIoTClient | 28:add19eb7defa | 817 | else |
AzureIoTClient | 28:add19eb7defa | 818 | { |
AzureIoTClient | 28:add19eb7defa | 819 | /* Codes_SRS_MESSAGE_01_064: [ `message_set_application_properties` shall copy the contents of `application_properties` as the application properties for the message instance identified by `message`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 820 | /* Codes_SRS_MESSAGE_01_067: [ Cloning the message properties shall be done by calling `application_properties_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 821 | new_application_properties = application_properties_clone(application_properties); |
AzureIoTClient | 28:add19eb7defa | 822 | if (new_application_properties == NULL) |
AzureIoTClient | 28:add19eb7defa | 823 | { |
AzureIoTClient | 28:add19eb7defa | 824 | /* Codes_SRS_MESSAGE_01_068: [ If `application_properties_clone` fails, `message_set_application_properties` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 825 | LogError("Cannot clone application properties"); |
AzureIoTClient | 28:add19eb7defa | 826 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 827 | } |
AzureIoTClient | 28:add19eb7defa | 828 | else |
AzureIoTClient | 28:add19eb7defa | 829 | { |
AzureIoTClient | 28:add19eb7defa | 830 | /* Codes_SRS_MESSAGE_01_069: [ If setting the application properties fails, the previous value shall be preserved. ]*/ |
AzureIoTClient | 28:add19eb7defa | 831 | /* Only do the free of the previous value if we could clone the new one*/ |
AzureIoTClient | 28:add19eb7defa | 832 | if (message->application_properties != NULL) |
AzureIoTClient | 28:add19eb7defa | 833 | { |
AzureIoTClient | 28:add19eb7defa | 834 | amqpvalue_destroy(message->application_properties); |
AzureIoTClient | 28:add19eb7defa | 835 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 836 | |
AzureIoTClient | 28:add19eb7defa | 837 | message->application_properties = new_application_properties; |
Azure.IoT Build | 0:6ae2f7bca550 | 838 | |
AzureIoTClient | 28:add19eb7defa | 839 | /* Codes_SRS_MESSAGE_01_065: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 840 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 841 | } |
AzureIoTClient | 28:add19eb7defa | 842 | } |
AzureIoTClient | 28:add19eb7defa | 843 | } |
AzureIoTClient | 28:add19eb7defa | 844 | |
AzureIoTClient | 28:add19eb7defa | 845 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 846 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 847 | |
Azure.IoT Build | 0:6ae2f7bca550 | 848 | int message_get_application_properties(MESSAGE_HANDLE message, AMQP_VALUE* application_properties) |
Azure.IoT Build | 0:6ae2f7bca550 | 849 | { |
AzureIoTClient | 28:add19eb7defa | 850 | int result; |
AzureIoTClient | 28:add19eb7defa | 851 | |
AzureIoTClient | 28:add19eb7defa | 852 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 853 | (application_properties == NULL)) |
AzureIoTClient | 28:add19eb7defa | 854 | { |
AzureIoTClient | 28:add19eb7defa | 855 | /* Codes_SRS_MESSAGE_01_072: [ If `message` or `application_properties` is NULL, `message_get_application_properties` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 856 | LogError("Bad arguments: message = %p, application_properties = %p", |
AzureIoTClient | 28:add19eb7defa | 857 | message, application_properties); |
AzureIoTClient | 28:add19eb7defa | 858 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 859 | } |
AzureIoTClient | 28:add19eb7defa | 860 | else |
AzureIoTClient | 28:add19eb7defa | 861 | { |
AzureIoTClient | 28:add19eb7defa | 862 | if (message->application_properties == NULL) |
AzureIoTClient | 28:add19eb7defa | 863 | { |
AzureIoTClient | 28:add19eb7defa | 864 | /* Codes_SRS_MESSAGE_01_150: [ If no application properties have been set, `message_get_application_properties` shall set `application_properties` to NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 865 | *application_properties = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 866 | |
AzureIoTClient | 28:add19eb7defa | 867 | /* Codes_SRS_MESSAGE_01_071: [ On success, `message_get_application_properties` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 868 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 869 | } |
AzureIoTClient | 28:add19eb7defa | 870 | else |
AzureIoTClient | 28:add19eb7defa | 871 | { |
AzureIoTClient | 28:add19eb7defa | 872 | /* Codes_SRS_MESSAGE_01_070: [ `message_get_application_properties` shall copy the contents of application message properties for the message instance identified by `message` into the argument `application_properties`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 873 | /* Codes_SRS_MESSAGE_01_073: [ Cloning the application properties shall be done by calling `application_properties_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 874 | *application_properties = application_properties_clone(message->application_properties); |
AzureIoTClient | 28:add19eb7defa | 875 | if (*application_properties == NULL) |
AzureIoTClient | 28:add19eb7defa | 876 | { |
AzureIoTClient | 28:add19eb7defa | 877 | /* Codes_SRS_MESSAGE_01_074: [ If `application_properties_clone` fails, `message_get_application_properties` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 878 | LogError("Cannot clone application properties"); |
AzureIoTClient | 28:add19eb7defa | 879 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 880 | } |
AzureIoTClient | 28:add19eb7defa | 881 | else |
AzureIoTClient | 28:add19eb7defa | 882 | { |
AzureIoTClient | 28:add19eb7defa | 883 | /* Codes_SRS_MESSAGE_01_071: [ On success, `message_get_application_properties` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 884 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 885 | } |
AzureIoTClient | 28:add19eb7defa | 886 | } |
AzureIoTClient | 28:add19eb7defa | 887 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 888 | |
AzureIoTClient | 28:add19eb7defa | 889 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 890 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 891 | |
Azure.IoT Build | 0:6ae2f7bca550 | 892 | int message_set_footer(MESSAGE_HANDLE message, annotations footer) |
Azure.IoT Build | 0:6ae2f7bca550 | 893 | { |
AzureIoTClient | 28:add19eb7defa | 894 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 895 | |
AzureIoTClient | 28:add19eb7defa | 896 | if (message == NULL) |
AzureIoTClient | 28:add19eb7defa | 897 | { |
AzureIoTClient | 28:add19eb7defa | 898 | /* Codes_SRS_MESSAGE_01_077: [ If `message` is NULL, `message_set_footer` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 899 | LogError("NULL message"); |
AzureIoTClient | 28:add19eb7defa | 900 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 901 | } |
AzureIoTClient | 28:add19eb7defa | 902 | else |
AzureIoTClient | 28:add19eb7defa | 903 | { |
AzureIoTClient | 28:add19eb7defa | 904 | if (footer == NULL) |
AzureIoTClient | 28:add19eb7defa | 905 | { |
AzureIoTClient | 28:add19eb7defa | 906 | /* Codes_SRS_MESSAGE_01_151: [ If `footer` is NULL, the previously stored footer associated with `message` shall be freed. ]*/ |
AzureIoTClient | 28:add19eb7defa | 907 | if (message->footer != NULL) |
AzureIoTClient | 28:add19eb7defa | 908 | { |
AzureIoTClient | 28:add19eb7defa | 909 | annotations_destroy(message->footer); |
AzureIoTClient | 28:add19eb7defa | 910 | message->footer = NULL; |
AzureIoTClient | 28:add19eb7defa | 911 | } |
AzureIoTClient | 28:add19eb7defa | 912 | |
AzureIoTClient | 28:add19eb7defa | 913 | /* Codes_SRS_MESSAGE_01_076: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 914 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 915 | } |
AzureIoTClient | 28:add19eb7defa | 916 | else |
AzureIoTClient | 28:add19eb7defa | 917 | { |
AzureIoTClient | 28:add19eb7defa | 918 | annotations new_footer; |
Azure.IoT Build | 0:6ae2f7bca550 | 919 | |
AzureIoTClient | 28:add19eb7defa | 920 | /* Codes_SRS_MESSAGE_01_075: [ `message_set_footer` shall copy the contents of `footer` as the footer contents for the message instance identified by `message`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 921 | /* Codes_SRS_MESSAGE_01_078: [ Cloning the footer shall be done by calling `annotations_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 922 | new_footer = annotations_clone(footer); |
AzureIoTClient | 28:add19eb7defa | 923 | if (new_footer == NULL) |
AzureIoTClient | 28:add19eb7defa | 924 | { |
AzureIoTClient | 28:add19eb7defa | 925 | /* Codes_SRS_MESSAGE_01_079: [ If `annotations_clone` fails, `message_set_footer` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 926 | LogError("Cannot clone message footer"); |
AzureIoTClient | 28:add19eb7defa | 927 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 928 | } |
AzureIoTClient | 28:add19eb7defa | 929 | else |
AzureIoTClient | 28:add19eb7defa | 930 | { |
AzureIoTClient | 28:add19eb7defa | 931 | /* Codes_SRS_MESSAGE_01_080: [ If setting the footer fails, the previous value shall be preserved. ]*/ |
AzureIoTClient | 28:add19eb7defa | 932 | /* Only do the free of the previous value if we could clone the new one*/ |
AzureIoTClient | 28:add19eb7defa | 933 | if (message->footer != NULL) |
AzureIoTClient | 28:add19eb7defa | 934 | { |
AzureIoTClient | 28:add19eb7defa | 935 | annotations_destroy(message->footer); |
AzureIoTClient | 28:add19eb7defa | 936 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 937 | |
AzureIoTClient | 28:add19eb7defa | 938 | message->footer = new_footer; |
Azure.IoT Build | 0:6ae2f7bca550 | 939 | |
AzureIoTClient | 28:add19eb7defa | 940 | /* Codes_SRS_MESSAGE_01_076: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 941 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 942 | } |
AzureIoTClient | 28:add19eb7defa | 943 | } |
AzureIoTClient | 28:add19eb7defa | 944 | } |
AzureIoTClient | 28:add19eb7defa | 945 | |
AzureIoTClient | 28:add19eb7defa | 946 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 947 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 948 | |
Azure.IoT Build | 0:6ae2f7bca550 | 949 | int message_get_footer(MESSAGE_HANDLE message, annotations* footer) |
Azure.IoT Build | 0:6ae2f7bca550 | 950 | { |
AzureIoTClient | 28:add19eb7defa | 951 | int result; |
AzureIoTClient | 28:add19eb7defa | 952 | |
AzureIoTClient | 28:add19eb7defa | 953 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 954 | (footer == NULL)) |
AzureIoTClient | 28:add19eb7defa | 955 | { |
AzureIoTClient | 28:add19eb7defa | 956 | /* Codes_SRS_MESSAGE_01_083: [ If `message` or `footer` is NULL, `message_get_footer` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 957 | LogError("Bad arguments: message = %p, footer = %p", |
AzureIoTClient | 28:add19eb7defa | 958 | message, footer); |
AzureIoTClient | 28:add19eb7defa | 959 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 960 | } |
AzureIoTClient | 28:add19eb7defa | 961 | else |
AzureIoTClient | 28:add19eb7defa | 962 | { |
AzureIoTClient | 28:add19eb7defa | 963 | if (message->footer == NULL) |
AzureIoTClient | 28:add19eb7defa | 964 | { |
AzureIoTClient | 28:add19eb7defa | 965 | /* Codes_SRS_MESSAGE_01_152: [ If no footer has been set, `message_get_footer` shall set `footer` to NULL. ]*/ |
AzureIoTClient | 28:add19eb7defa | 966 | *footer = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 967 | |
AzureIoTClient | 28:add19eb7defa | 968 | /* Codes_SRS_MESSAGE_01_082: [ On success, `message_get_footer` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 969 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 970 | } |
AzureIoTClient | 28:add19eb7defa | 971 | else |
AzureIoTClient | 28:add19eb7defa | 972 | { |
AzureIoTClient | 28:add19eb7defa | 973 | /* Codes_SRS_MESSAGE_01_081: [ `message_get_footer` shall copy the contents of footer for the message instance identified by `message` into the argument `footer`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 974 | /* Codes_SRS_MESSAGE_01_084: [ Cloning the footer shall be done by calling `annotations_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 975 | *footer = annotations_clone(message->footer); |
AzureIoTClient | 28:add19eb7defa | 976 | if (*footer == NULL) |
AzureIoTClient | 28:add19eb7defa | 977 | { |
AzureIoTClient | 28:add19eb7defa | 978 | /* Codes_SRS_MESSAGE_01_085: [ If `annotations_clone` fails, `message_get_footer` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 979 | LogError("Cannot clone message footer"); |
AzureIoTClient | 28:add19eb7defa | 980 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 981 | } |
AzureIoTClient | 28:add19eb7defa | 982 | else |
AzureIoTClient | 28:add19eb7defa | 983 | { |
AzureIoTClient | 28:add19eb7defa | 984 | /* Codes_SRS_MESSAGE_01_082: [ On success, `message_get_footer` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 985 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 986 | } |
AzureIoTClient | 28:add19eb7defa | 987 | } |
AzureIoTClient | 28:add19eb7defa | 988 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 989 | |
AzureIoTClient | 28:add19eb7defa | 990 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 991 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 992 | |
AzureIoTClient | 24:2c59c2d43ebf | 993 | int message_add_body_amqp_data(MESSAGE_HANDLE message, BINARY_DATA amqp_data) |
Azure.IoT Build | 0:6ae2f7bca550 | 994 | { |
AzureIoTClient | 28:add19eb7defa | 995 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 996 | |
AzureIoTClient | 28:add19eb7defa | 997 | /* Codes_SRS_MESSAGE_01_088: [ If `message` is NULL, `message_add_body_amqp_data` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 998 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 999 | /* Tests_SRS_MESSAGE_01_089: [ If the `bytes` member of `amqp_data` is NULL and the `size` member is non-zero, `message_add_body_amqp_data` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1000 | ((amqp_data.bytes == NULL) && |
AzureIoTClient | 28:add19eb7defa | 1001 | (amqp_data.length != 0))) |
AzureIoTClient | 28:add19eb7defa | 1002 | { |
AzureIoTClient | 28:add19eb7defa | 1003 | LogError("Bad arguments: message = %p, bytes = %p, length = %u", |
AzureIoTClient | 28:add19eb7defa | 1004 | message, amqp_data.bytes, (unsigned int)amqp_data.length); |
AzureIoTClient | 28:add19eb7defa | 1005 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1006 | } |
AzureIoTClient | 28:add19eb7defa | 1007 | else |
AzureIoTClient | 28:add19eb7defa | 1008 | { |
AzureIoTClient | 28:add19eb7defa | 1009 | MESSAGE_BODY_TYPE body_type = internal_get_body_type(message); |
AzureIoTClient | 28:add19eb7defa | 1010 | if ((body_type == MESSAGE_BODY_TYPE_SEQUENCE) || |
AzureIoTClient | 28:add19eb7defa | 1011 | (body_type == MESSAGE_BODY_TYPE_VALUE)) |
AzureIoTClient | 28:add19eb7defa | 1012 | { |
AzureIoTClient | 28:add19eb7defa | 1013 | /* Codes_SRS_MESSAGE_01_091: [ If the body was already set to an AMQP value or a list of AMQP sequences, `message_add_body_amqp_data` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1014 | LogError("Body type already set"); |
AzureIoTClient | 28:add19eb7defa | 1015 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1016 | } |
AzureIoTClient | 28:add19eb7defa | 1017 | else |
AzureIoTClient | 28:add19eb7defa | 1018 | { |
AzureIoTClient | 28:add19eb7defa | 1019 | /* Codes_SRS_MESSAGE_01_086: [ `message_add_body_amqp_data` shall add the contents of `amqp_data` to the list of AMQP data values for the body of the message identified by `message`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1020 | 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)); |
AzureIoTClient | 28:add19eb7defa | 1021 | if (new_body_amqp_data_items == NULL) |
AzureIoTClient | 28:add19eb7defa | 1022 | { |
AzureIoTClient | 28:add19eb7defa | 1023 | /* Codes_SRS_MESSAGE_01_153: [ If allocating memory to store the added AMQP data fails, `message_add_body_amqp_data` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1024 | LogError("Cannot allocate memory for body AMQP data items"); |
AzureIoTClient | 28:add19eb7defa | 1025 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1026 | } |
AzureIoTClient | 28:add19eb7defa | 1027 | else |
AzureIoTClient | 28:add19eb7defa | 1028 | { |
AzureIoTClient | 28:add19eb7defa | 1029 | message->body_amqp_data_items = new_body_amqp_data_items; |
Azure.IoT Build | 0:6ae2f7bca550 | 1030 | |
AzureIoTClient | 40:f0ceafa8d570 | 1031 | if (amqp_data.length == 0) |
AzureIoTClient | 28:add19eb7defa | 1032 | { |
AzureIoTClient | 40:f0ceafa8d570 | 1033 | message->body_amqp_data_items[message->body_amqp_data_count].body_data_section_bytes = NULL; |
AzureIoTClient | 40:f0ceafa8d570 | 1034 | message->body_amqp_data_items[message->body_amqp_data_count].body_data_section_length = 0; |
AzureIoTClient | 28:add19eb7defa | 1035 | message->body_amqp_data_count++; |
Azure.IoT Build | 0:6ae2f7bca550 | 1036 | |
AzureIoTClient | 28:add19eb7defa | 1037 | /* Codes_SRS_MESSAGE_01_087: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1038 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 1039 | } |
AzureIoTClient | 40:f0ceafa8d570 | 1040 | else |
AzureIoTClient | 40:f0ceafa8d570 | 1041 | { |
AzureIoTClient | 40:f0ceafa8d570 | 1042 | message->body_amqp_data_items[message->body_amqp_data_count].body_data_section_bytes = (unsigned char*)malloc(amqp_data.length); |
AzureIoTClient | 40:f0ceafa8d570 | 1043 | if (message->body_amqp_data_items[message->body_amqp_data_count].body_data_section_bytes == NULL) |
AzureIoTClient | 40:f0ceafa8d570 | 1044 | { |
AzureIoTClient | 40:f0ceafa8d570 | 1045 | /* Codes_SRS_MESSAGE_01_153: [ If allocating memory to store the added AMQP data fails, `message_add_body_amqp_data` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 40:f0ceafa8d570 | 1046 | LogError("Cannot allocate memory for body AMQP data to be added"); |
AzureIoTClient | 40:f0ceafa8d570 | 1047 | result = __FAILURE__; |
AzureIoTClient | 40:f0ceafa8d570 | 1048 | } |
AzureIoTClient | 40:f0ceafa8d570 | 1049 | else |
AzureIoTClient | 40:f0ceafa8d570 | 1050 | { |
AzureIoTClient | 40:f0ceafa8d570 | 1051 | message->body_amqp_data_items[message->body_amqp_data_count].body_data_section_length = amqp_data.length; |
AzureIoTClient | 40:f0ceafa8d570 | 1052 | (void)memcpy(message->body_amqp_data_items[message->body_amqp_data_count].body_data_section_bytes, amqp_data.bytes, amqp_data.length); |
AzureIoTClient | 40:f0ceafa8d570 | 1053 | message->body_amqp_data_count++; |
AzureIoTClient | 40:f0ceafa8d570 | 1054 | |
AzureIoTClient | 40:f0ceafa8d570 | 1055 | /* Codes_SRS_MESSAGE_01_087: [ On success it shall return 0. ]*/ |
AzureIoTClient | 40:f0ceafa8d570 | 1056 | result = 0; |
AzureIoTClient | 40:f0ceafa8d570 | 1057 | } |
AzureIoTClient | 40:f0ceafa8d570 | 1058 | } |
AzureIoTClient | 28:add19eb7defa | 1059 | } |
AzureIoTClient | 28:add19eb7defa | 1060 | } |
AzureIoTClient | 28:add19eb7defa | 1061 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1062 | |
AzureIoTClient | 28:add19eb7defa | 1063 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1064 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1065 | |
AzureIoTClient | 28:add19eb7defa | 1066 | int message_get_body_amqp_data_in_place(MESSAGE_HANDLE message, size_t index, BINARY_DATA* amqp_data) |
Azure.IoT Build | 0:6ae2f7bca550 | 1067 | { |
AzureIoTClient | 28:add19eb7defa | 1068 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1069 | |
AzureIoTClient | 28:add19eb7defa | 1070 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 1071 | (amqp_data == NULL)) |
AzureIoTClient | 28:add19eb7defa | 1072 | { |
AzureIoTClient | 28:add19eb7defa | 1073 | /* Codes_SRS_MESSAGE_01_094: [ If `message` or `amqp_data` is NULL, `message_get_body_amqp_data_in_place` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1074 | LogError("Bad arguments: message = %p, amqp_data = %p", |
AzureIoTClient | 28:add19eb7defa | 1075 | message, amqp_data); |
AzureIoTClient | 28:add19eb7defa | 1076 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1077 | } |
AzureIoTClient | 28:add19eb7defa | 1078 | else |
AzureIoTClient | 28:add19eb7defa | 1079 | { |
AzureIoTClient | 28:add19eb7defa | 1080 | MESSAGE_BODY_TYPE body_type = internal_get_body_type(message); |
AzureIoTClient | 28:add19eb7defa | 1081 | if (body_type != MESSAGE_BODY_TYPE_DATA) |
AzureIoTClient | 28:add19eb7defa | 1082 | { |
AzureIoTClient | 28:add19eb7defa | 1083 | /* Codes_SRS_MESSAGE_01_096: [ If the body for `message` is not of type `MESSAGE_BODY_TYPE_DATA`, `message_get_body_amqp_data_in_place` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1084 | LogError("Body type is not AMQP data"); |
AzureIoTClient | 28:add19eb7defa | 1085 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1086 | } |
AzureIoTClient | 28:add19eb7defa | 1087 | else if (index >= message->body_amqp_data_count) |
AzureIoTClient | 28:add19eb7defa | 1088 | { |
AzureIoTClient | 28:add19eb7defa | 1089 | /* Codes_SRS_MESSAGE_01_095: [ If `index` indicates an AMQP data entry that is out of bounds, `message_get_body_amqp_data_in_place` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1090 | LogError("Index too high for AMQP data (%u), number of AMQP data entries is %u", |
AzureIoTClient | 28:add19eb7defa | 1091 | index, message->body_amqp_data_count); |
AzureIoTClient | 28:add19eb7defa | 1092 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1093 | } |
AzureIoTClient | 28:add19eb7defa | 1094 | else |
AzureIoTClient | 28:add19eb7defa | 1095 | { |
AzureIoTClient | 28:add19eb7defa | 1096 | /* Codes_SRS_MESSAGE_01_092: [ `message_get_body_amqp_data_in_place` shall place the contents of the `index`th AMQP data for the message instance identified by `message` into the argument `amqp_data`, without copying the binary payload memory. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1097 | amqp_data->bytes = message->body_amqp_data_items[index].body_data_section_bytes; |
AzureIoTClient | 28:add19eb7defa | 1098 | amqp_data->length = message->body_amqp_data_items[index].body_data_section_length; |
Azure.IoT Build | 0:6ae2f7bca550 | 1099 | |
AzureIoTClient | 28:add19eb7defa | 1100 | /* Codes_SRS_MESSAGE_01_093: [ On success, `message_get_body_amqp_data_in_place` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1101 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 1102 | } |
AzureIoTClient | 28:add19eb7defa | 1103 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1104 | |
AzureIoTClient | 28:add19eb7defa | 1105 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1106 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1107 | |
Azure.IoT Build | 0:6ae2f7bca550 | 1108 | int message_get_body_amqp_data_count(MESSAGE_HANDLE message, size_t* count) |
Azure.IoT Build | 0:6ae2f7bca550 | 1109 | { |
AzureIoTClient | 28:add19eb7defa | 1110 | int result; |
AzureIoTClient | 28:add19eb7defa | 1111 | |
AzureIoTClient | 28:add19eb7defa | 1112 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 1113 | (count == NULL)) |
AzureIoTClient | 28:add19eb7defa | 1114 | { |
AzureIoTClient | 28:add19eb7defa | 1115 | /* Codes_SRS_MESSAGE_01_099: [ If `message` or `count` is NULL, `message_get_body_amqp_data_count` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1116 | LogError("Bad arguments: message = %p, count = %p", |
AzureIoTClient | 28:add19eb7defa | 1117 | message, count); |
AzureIoTClient | 28:add19eb7defa | 1118 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1119 | } |
AzureIoTClient | 28:add19eb7defa | 1120 | else |
AzureIoTClient | 28:add19eb7defa | 1121 | { |
AzureIoTClient | 28:add19eb7defa | 1122 | MESSAGE_BODY_TYPE body_type = internal_get_body_type(message); |
AzureIoTClient | 28:add19eb7defa | 1123 | if (body_type != MESSAGE_BODY_TYPE_DATA) |
AzureIoTClient | 28:add19eb7defa | 1124 | { |
AzureIoTClient | 28:add19eb7defa | 1125 | /* Codes_SRS_MESSAGE_01_100: [ If the body for `message` is not of type `MESSAGE_BODY_TYPE_DATA`, `message_get_body_amqp_data_count` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1126 | LogError("Body type is not AMQP data"); |
AzureIoTClient | 28:add19eb7defa | 1127 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1128 | } |
AzureIoTClient | 28:add19eb7defa | 1129 | else |
AzureIoTClient | 28:add19eb7defa | 1130 | { |
AzureIoTClient | 28:add19eb7defa | 1131 | /* Codes_SRS_MESSAGE_01_097: [ `message_get_body_amqp_data_count` shall fill in `count` the number of AMQP data chunks that are stored by the message identified by `message`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1132 | *count = message->body_amqp_data_count; |
AzureIoTClient | 28:add19eb7defa | 1133 | |
AzureIoTClient | 28:add19eb7defa | 1134 | /* Codes_SRS_MESSAGE_01_098: [ On success, `message_get_body_amqp_data_count` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1135 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 1136 | } |
AzureIoTClient | 28:add19eb7defa | 1137 | } |
AzureIoTClient | 28:add19eb7defa | 1138 | |
AzureIoTClient | 28:add19eb7defa | 1139 | return result; |
AzureIoTClient | 28:add19eb7defa | 1140 | } |
AzureIoTClient | 28:add19eb7defa | 1141 | |
AzureIoTClient | 28:add19eb7defa | 1142 | int message_set_body_amqp_value(MESSAGE_HANDLE message, AMQP_VALUE body_amqp_value) |
AzureIoTClient | 28:add19eb7defa | 1143 | { |
AzureIoTClient | 28:add19eb7defa | 1144 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1145 | |
AzureIoTClient | 28:add19eb7defa | 1146 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 1147 | (body_amqp_value == NULL)) |
AzureIoTClient | 28:add19eb7defa | 1148 | { |
AzureIoTClient | 28:add19eb7defa | 1149 | /* Codes_SRS_MESSAGE_01_103: [ If `message` or `body_amqp_value` is NULL, `message_set_body_amqp_value` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1150 | LogError("Bad arguments: message = %p, body_amqp_value = %p", |
AzureIoTClient | 28:add19eb7defa | 1151 | message, body_amqp_value); |
AzureIoTClient | 28:add19eb7defa | 1152 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1153 | } |
AzureIoTClient | 28:add19eb7defa | 1154 | else |
AzureIoTClient | 28:add19eb7defa | 1155 | { |
AzureIoTClient | 28:add19eb7defa | 1156 | MESSAGE_BODY_TYPE body_type = internal_get_body_type(message); |
AzureIoTClient | 28:add19eb7defa | 1157 | if ((body_type == MESSAGE_BODY_TYPE_DATA) || |
AzureIoTClient | 28:add19eb7defa | 1158 | (body_type == MESSAGE_BODY_TYPE_SEQUENCE)) |
AzureIoTClient | 28:add19eb7defa | 1159 | { |
AzureIoTClient | 28:add19eb7defa | 1160 | /* Codes_SRS_MESSAGE_01_105: [ If the body was already set to an AMQP data list or a list of AMQP sequences, `message_set_body_amqp_value` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1161 | LogError("Body is already set to another body type"); |
AzureIoTClient | 28:add19eb7defa | 1162 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1163 | } |
AzureIoTClient | 28:add19eb7defa | 1164 | else |
AzureIoTClient | 28:add19eb7defa | 1165 | { |
AzureIoTClient | 28:add19eb7defa | 1166 | /* Codes_SRS_MESSAGE_01_154: [ Cloning the amqp value shall be done by calling `amqpvalue_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1167 | AMQP_VALUE new_amqp_value = amqpvalue_clone(body_amqp_value); |
AzureIoTClient | 28:add19eb7defa | 1168 | if (new_amqp_value == NULL) |
AzureIoTClient | 28:add19eb7defa | 1169 | { |
AzureIoTClient | 28:add19eb7defa | 1170 | LogError("Cannot clone body AMQP value", |
AzureIoTClient | 28:add19eb7defa | 1171 | message, body_amqp_value); |
AzureIoTClient | 28:add19eb7defa | 1172 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1173 | } |
AzureIoTClient | 28:add19eb7defa | 1174 | else |
AzureIoTClient | 28:add19eb7defa | 1175 | { |
AzureIoTClient | 28:add19eb7defa | 1176 | /* Codes_SRS_MESSAGE_01_104: [ If setting the body AMQP value fails, the previous value shall be preserved. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1177 | /* Only free the previous value when cloning is succesfull */ |
AzureIoTClient | 28:add19eb7defa | 1178 | if (message->body_amqp_value != NULL) |
AzureIoTClient | 28:add19eb7defa | 1179 | { |
AzureIoTClient | 28:add19eb7defa | 1180 | amqpvalue_destroy(body_amqp_value); |
AzureIoTClient | 28:add19eb7defa | 1181 | } |
AzureIoTClient | 28:add19eb7defa | 1182 | |
AzureIoTClient | 28:add19eb7defa | 1183 | /* Codes_SRS_MESSAGE_01_101: [ `message_set_body_amqp_value` shall set the contents of body as being the AMQP value indicate by `body_amqp_value`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1184 | message->body_amqp_value = new_amqp_value; |
Azure.IoT Build | 0:6ae2f7bca550 | 1185 | |
AzureIoTClient | 28:add19eb7defa | 1186 | /* Codes_SRS_MESSAGE_01_102: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1187 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 1188 | } |
AzureIoTClient | 28:add19eb7defa | 1189 | } |
AzureIoTClient | 28:add19eb7defa | 1190 | } |
AzureIoTClient | 28:add19eb7defa | 1191 | |
AzureIoTClient | 28:add19eb7defa | 1192 | return result; |
AzureIoTClient | 28:add19eb7defa | 1193 | } |
AzureIoTClient | 28:add19eb7defa | 1194 | |
AzureIoTClient | 28:add19eb7defa | 1195 | int message_get_body_amqp_value_in_place(MESSAGE_HANDLE message, AMQP_VALUE* body_amqp_value) |
AzureIoTClient | 28:add19eb7defa | 1196 | { |
AzureIoTClient | 28:add19eb7defa | 1197 | int result; |
AzureIoTClient | 28:add19eb7defa | 1198 | |
AzureIoTClient | 28:add19eb7defa | 1199 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 1200 | (body_amqp_value == NULL)) |
AzureIoTClient | 28:add19eb7defa | 1201 | { |
AzureIoTClient | 28:add19eb7defa | 1202 | /* Codes_SRS_MESSAGE_01_108: [ If `message` or `body_amqp_value` is NULL, `message_get_body_amqp_value_in_place` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1203 | LogError("Bad arguments: message = %p, body_amqp_value = %p", |
AzureIoTClient | 28:add19eb7defa | 1204 | message, body_amqp_value); |
AzureIoTClient | 28:add19eb7defa | 1205 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1206 | } |
AzureIoTClient | 28:add19eb7defa | 1207 | else |
AzureIoTClient | 28:add19eb7defa | 1208 | { |
AzureIoTClient | 28:add19eb7defa | 1209 | MESSAGE_BODY_TYPE body_type = internal_get_body_type(message); |
AzureIoTClient | 28:add19eb7defa | 1210 | if (body_type != MESSAGE_BODY_TYPE_VALUE) |
AzureIoTClient | 28:add19eb7defa | 1211 | { |
AzureIoTClient | 28:add19eb7defa | 1212 | /* Codes_SRS_MESSAGE_01_109: [ If the body for `message` is not of type `MESSAGE_BODY_TYPE_VALUE`, `message_get_body_amqp_value_in_place` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1213 | LogError("Body is not of type AMQP value"); |
AzureIoTClient | 28:add19eb7defa | 1214 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1215 | } |
AzureIoTClient | 28:add19eb7defa | 1216 | else |
AzureIoTClient | 28:add19eb7defa | 1217 | { |
AzureIoTClient | 28:add19eb7defa | 1218 | /* Codes_SRS_MESSAGE_01_106: [ `message_get_body_amqp_value_in_place` shall get the body AMQP value for the message instance identified by `message` in place (not cloning) into the `body_amqp_value` argument. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1219 | *body_amqp_value = message->body_amqp_value; |
AzureIoTClient | 28:add19eb7defa | 1220 | |
AzureIoTClient | 28:add19eb7defa | 1221 | /* Codes_SRS_MESSAGE_01_107: [ On success, `message_get_body_amqp_value_in_place` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1222 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 1223 | } |
AzureIoTClient | 28:add19eb7defa | 1224 | } |
AzureIoTClient | 28:add19eb7defa | 1225 | |
AzureIoTClient | 28:add19eb7defa | 1226 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1227 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1228 | |
Azure.IoT Build | 0:6ae2f7bca550 | 1229 | int message_add_body_amqp_sequence(MESSAGE_HANDLE message, AMQP_VALUE sequence_list) |
Azure.IoT Build | 0:6ae2f7bca550 | 1230 | { |
AzureIoTClient | 28:add19eb7defa | 1231 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1232 | |
AzureIoTClient | 28:add19eb7defa | 1233 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 1234 | (sequence_list == NULL)) |
AzureIoTClient | 28:add19eb7defa | 1235 | { |
AzureIoTClient | 28:add19eb7defa | 1236 | /* Codes_SRS_MESSAGE_01_112: [ If `message` or `sequence` is NULL, `message_add_body_amqp_sequence` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1237 | LogError("Bad arguments: message = %p, sequence_list = %p", |
AzureIoTClient | 28:add19eb7defa | 1238 | message, sequence_list); |
AzureIoTClient | 28:add19eb7defa | 1239 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1240 | } |
AzureIoTClient | 28:add19eb7defa | 1241 | else |
AzureIoTClient | 28:add19eb7defa | 1242 | { |
AzureIoTClient | 28:add19eb7defa | 1243 | MESSAGE_BODY_TYPE body_type = internal_get_body_type(message); |
AzureIoTClient | 28:add19eb7defa | 1244 | if ((body_type == MESSAGE_BODY_TYPE_DATA) || |
AzureIoTClient | 28:add19eb7defa | 1245 | (body_type == MESSAGE_BODY_TYPE_VALUE)) |
AzureIoTClient | 28:add19eb7defa | 1246 | { |
AzureIoTClient | 28:add19eb7defa | 1247 | /* Codes_SRS_MESSAGE_01_115: [ If the body was already set to an AMQP data list or an AMQP value, `message_add_body_amqp_sequence` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1248 | LogError("Body is already set to another body type"); |
AzureIoTClient | 28:add19eb7defa | 1249 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1250 | } |
AzureIoTClient | 28:add19eb7defa | 1251 | else |
AzureIoTClient | 28:add19eb7defa | 1252 | { |
AzureIoTClient | 28:add19eb7defa | 1253 | AMQP_VALUE* new_body_amqp_sequence_items = (AMQP_VALUE*)realloc(message->body_amqp_sequence_items, sizeof(AMQP_VALUE) * (message->body_amqp_sequence_count + 1)); |
AzureIoTClient | 28:add19eb7defa | 1254 | if (new_body_amqp_sequence_items == NULL) |
AzureIoTClient | 28:add19eb7defa | 1255 | { |
AzureIoTClient | 28:add19eb7defa | 1256 | /* Codes_SRS_MESSAGE_01_158: [ If allocating memory in order to store the sequence fails, `message_add_body_amqp_sequence` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1257 | LogError("Cannot allocate enough memory for sequence items"); |
AzureIoTClient | 28:add19eb7defa | 1258 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1259 | } |
AzureIoTClient | 28:add19eb7defa | 1260 | else |
AzureIoTClient | 28:add19eb7defa | 1261 | { |
AzureIoTClient | 28:add19eb7defa | 1262 | message->body_amqp_sequence_items = new_body_amqp_sequence_items; |
Azure.IoT Build | 0:6ae2f7bca550 | 1263 | |
AzureIoTClient | 28:add19eb7defa | 1264 | /* Codes_SRS_MESSAGE_01_110: [ `message_add_body_amqp_sequence` shall add the contents of `sequence` to the list of AMQP sequences for the body of the message identified by `message`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1265 | /* Codes_SRS_MESSAGE_01_156: [ The AMQP sequence shall be cloned by calling `amqpvalue_clone`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1266 | message->body_amqp_sequence_items[message->body_amqp_sequence_count] = amqpvalue_clone(sequence_list); |
AzureIoTClient | 28:add19eb7defa | 1267 | if (message->body_amqp_sequence_items[message->body_amqp_sequence_count] == NULL) |
AzureIoTClient | 28:add19eb7defa | 1268 | { |
AzureIoTClient | 28:add19eb7defa | 1269 | /* Codes_SRS_MESSAGE_01_157: [ If `amqpvalue_clone` fails, `message_add_body_amqp_sequence` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1270 | LogError("Cloning sequence failed"); |
AzureIoTClient | 28:add19eb7defa | 1271 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1272 | } |
AzureIoTClient | 28:add19eb7defa | 1273 | else |
AzureIoTClient | 28:add19eb7defa | 1274 | { |
AzureIoTClient | 28:add19eb7defa | 1275 | /* Codes_SRS_MESSAGE_01_114: [ If adding the AMQP sequence fails, the previous value shall be preserved. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1276 | message->body_amqp_sequence_count++; |
Azure.IoT Build | 0:6ae2f7bca550 | 1277 | |
AzureIoTClient | 28:add19eb7defa | 1278 | /* Codes_SRS_MESSAGE_01_111: [ On success it shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1279 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 1280 | } |
AzureIoTClient | 28:add19eb7defa | 1281 | } |
AzureIoTClient | 28:add19eb7defa | 1282 | } |
AzureIoTClient | 28:add19eb7defa | 1283 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1284 | |
AzureIoTClient | 28:add19eb7defa | 1285 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1286 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1287 | |
AzureIoTClient | 28:add19eb7defa | 1288 | int message_get_body_amqp_sequence_in_place(MESSAGE_HANDLE message, size_t index, AMQP_VALUE* sequence) |
Azure.IoT Build | 0:6ae2f7bca550 | 1289 | { |
AzureIoTClient | 28:add19eb7defa | 1290 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1291 | |
AzureIoTClient | 28:add19eb7defa | 1292 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 1293 | (sequence == NULL)) |
AzureIoTClient | 28:add19eb7defa | 1294 | { |
AzureIoTClient | 28:add19eb7defa | 1295 | /* Codes_SRS_MESSAGE_01_118: [ If `message` or `sequence` is NULL, `message_get_body_amqp_sequence_in_place` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1296 | LogError("Bad arguments: message = %p, sequence = %p", |
AzureIoTClient | 28:add19eb7defa | 1297 | message, sequence); |
AzureIoTClient | 28:add19eb7defa | 1298 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1299 | } |
AzureIoTClient | 28:add19eb7defa | 1300 | else |
AzureIoTClient | 28:add19eb7defa | 1301 | { |
AzureIoTClient | 28:add19eb7defa | 1302 | MESSAGE_BODY_TYPE body_type = internal_get_body_type(message); |
AzureIoTClient | 28:add19eb7defa | 1303 | if (body_type != MESSAGE_BODY_TYPE_SEQUENCE) |
AzureIoTClient | 28:add19eb7defa | 1304 | { |
AzureIoTClient | 28:add19eb7defa | 1305 | /* Codes_SRS_MESSAGE_01_120: [ If the body for `message` is not of type `MESSAGE_BODY_TYPE_SEQUENCE`, `message_get_body_amqp_sequence_in_place` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1306 | LogError("Body is not of type SEQUENCE"); |
AzureIoTClient | 28:add19eb7defa | 1307 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1308 | } |
AzureIoTClient | 28:add19eb7defa | 1309 | else |
AzureIoTClient | 28:add19eb7defa | 1310 | { |
AzureIoTClient | 28:add19eb7defa | 1311 | if (index >= message->body_amqp_sequence_count) |
AzureIoTClient | 28:add19eb7defa | 1312 | { |
AzureIoTClient | 28:add19eb7defa | 1313 | /* Codes_SRS_MESSAGE_01_119: [ If `index` indicates an AMQP sequence entry that is out of bounds, `message_get_body_amqp_sequence_in_place` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1314 | LogError("Index too high for AMQP sequence (%u), maximum is %u", |
AzureIoTClient | 28:add19eb7defa | 1315 | index, message->body_amqp_sequence_count); |
AzureIoTClient | 28:add19eb7defa | 1316 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1317 | } |
AzureIoTClient | 28:add19eb7defa | 1318 | else |
AzureIoTClient | 28:add19eb7defa | 1319 | { |
AzureIoTClient | 28:add19eb7defa | 1320 | /* Codes_SRS_MESSAGE_01_116: [ `message_get_body_amqp_sequence_in_place` shall return in `sequence` the content of the `index`th AMQP seuquence entry for the message instance identified by `message`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1321 | *sequence = message->body_amqp_sequence_items[index]; |
Azure.IoT Build | 0:6ae2f7bca550 | 1322 | |
AzureIoTClient | 28:add19eb7defa | 1323 | /* Codes_SRS_MESSAGE_01_117: [ On success, `message_get_body_amqp_sequence_in_place` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1324 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 1325 | } |
AzureIoTClient | 28:add19eb7defa | 1326 | } |
AzureIoTClient | 28:add19eb7defa | 1327 | } |
AzureIoTClient | 28:add19eb7defa | 1328 | |
AzureIoTClient | 28:add19eb7defa | 1329 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1330 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1331 | |
Azure.IoT Build | 0:6ae2f7bca550 | 1332 | int message_get_body_amqp_sequence_count(MESSAGE_HANDLE message, size_t* count) |
Azure.IoT Build | 0:6ae2f7bca550 | 1333 | { |
AzureIoTClient | 28:add19eb7defa | 1334 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1335 | |
AzureIoTClient | 28:add19eb7defa | 1336 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 1337 | (count == NULL)) |
AzureIoTClient | 28:add19eb7defa | 1338 | { |
AzureIoTClient | 28:add19eb7defa | 1339 | /* Codes_SRS_MESSAGE_01_123: [ If `message` or `count` is NULL, `message_get_body_amqp_sequence_count` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1340 | LogError("Bad arguments: message = %p, count = %p", |
AzureIoTClient | 28:add19eb7defa | 1341 | message, count); |
AzureIoTClient | 28:add19eb7defa | 1342 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1343 | } |
AzureIoTClient | 28:add19eb7defa | 1344 | else |
AzureIoTClient | 28:add19eb7defa | 1345 | { |
AzureIoTClient | 28:add19eb7defa | 1346 | MESSAGE_BODY_TYPE body_type = internal_get_body_type(message); |
AzureIoTClient | 28:add19eb7defa | 1347 | if (body_type != MESSAGE_BODY_TYPE_SEQUENCE) |
AzureIoTClient | 28:add19eb7defa | 1348 | { |
AzureIoTClient | 28:add19eb7defa | 1349 | /* Codes_SRS_MESSAGE_01_124: [ If the body for `message` is not of type `MESSAGE_BODY_TYPE_SEQUENCE`, `message_get_body_amqp_sequence_count` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1350 | LogError("Body is not of type SEQUENCE"); |
AzureIoTClient | 28:add19eb7defa | 1351 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1352 | } |
AzureIoTClient | 28:add19eb7defa | 1353 | else |
AzureIoTClient | 28:add19eb7defa | 1354 | { |
AzureIoTClient | 28:add19eb7defa | 1355 | /* Codes_SRS_MESSAGE_01_121: [ `message_get_body_amqp_sequence_count` shall fill in `count` the number of AMQP sequences that are stored by the message identified by `message`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1356 | *count = message->body_amqp_sequence_count; |
Azure.IoT Build | 0:6ae2f7bca550 | 1357 | |
AzureIoTClient | 28:add19eb7defa | 1358 | /* Codes_SRS_MESSAGE_01_122: [ On success, `message_get_body_amqp_sequence_count` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1359 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 1360 | } |
AzureIoTClient | 28:add19eb7defa | 1361 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1362 | |
AzureIoTClient | 28:add19eb7defa | 1363 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1364 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1365 | |
Azure.IoT Build | 0:6ae2f7bca550 | 1366 | int message_get_body_type(MESSAGE_HANDLE message, MESSAGE_BODY_TYPE* body_type) |
Azure.IoT Build | 0:6ae2f7bca550 | 1367 | { |
AzureIoTClient | 28:add19eb7defa | 1368 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1369 | |
AzureIoTClient | 28:add19eb7defa | 1370 | if ((message == NULL) || |
AzureIoTClient | 28:add19eb7defa | 1371 | (body_type == NULL)) |
AzureIoTClient | 28:add19eb7defa | 1372 | { |
AzureIoTClient | 28:add19eb7defa | 1373 | /* Codes_SRS_MESSAGE_01_127: [ If `message` or `body_type` is NULL, `message_get_body_type` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1374 | LogError("Bad arguments: message = %p, body_type = %p", |
AzureIoTClient | 28:add19eb7defa | 1375 | message, body_type); |
AzureIoTClient | 28:add19eb7defa | 1376 | result = __FAILURE__; |
AzureIoTClient | 28:add19eb7defa | 1377 | } |
AzureIoTClient | 28:add19eb7defa | 1378 | else |
AzureIoTClient | 28:add19eb7defa | 1379 | { |
AzureIoTClient | 28:add19eb7defa | 1380 | /* Codes_SRS_MESSAGE_01_125: [ `message_get_body_type` shall fill in `body_type` the AMQP message body type. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1381 | if (message->body_amqp_value != NULL) |
AzureIoTClient | 28:add19eb7defa | 1382 | { |
AzureIoTClient | 28:add19eb7defa | 1383 | *body_type = MESSAGE_BODY_TYPE_VALUE; |
AzureIoTClient | 28:add19eb7defa | 1384 | } |
AzureIoTClient | 28:add19eb7defa | 1385 | else if (message->body_amqp_data_count > 0) |
AzureIoTClient | 28:add19eb7defa | 1386 | { |
AzureIoTClient | 28:add19eb7defa | 1387 | *body_type = MESSAGE_BODY_TYPE_DATA; |
AzureIoTClient | 28:add19eb7defa | 1388 | } |
AzureIoTClient | 28:add19eb7defa | 1389 | else if (message->body_amqp_sequence_count > 0) |
AzureIoTClient | 28:add19eb7defa | 1390 | { |
AzureIoTClient | 28:add19eb7defa | 1391 | *body_type = MESSAGE_BODY_TYPE_SEQUENCE; |
AzureIoTClient | 28:add19eb7defa | 1392 | } |
AzureIoTClient | 28:add19eb7defa | 1393 | else |
AzureIoTClient | 28:add19eb7defa | 1394 | { |
AzureIoTClient | 28:add19eb7defa | 1395 | /* Codes_SRS_MESSAGE_01_128: [ If no body has been set on the message, `body_type` shall be `MESSAGE_BODY_TYPE_NONE`. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1396 | *body_type = MESSAGE_BODY_TYPE_NONE; |
AzureIoTClient | 28:add19eb7defa | 1397 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1398 | |
AzureIoTClient | 28:add19eb7defa | 1399 | /* Codes_SRS_MESSAGE_01_126: [ On success, `message_get_body_type` shall return 0. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1400 | result = 0; |
AzureIoTClient | 28:add19eb7defa | 1401 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1402 | |
AzureIoTClient | 28:add19eb7defa | 1403 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1404 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1405 | |
Azure.IoT Build | 0:6ae2f7bca550 | 1406 | int message_set_message_format(MESSAGE_HANDLE message, uint32_t message_format) |
Azure.IoT Build | 0:6ae2f7bca550 | 1407 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 1408 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1409 | |
Azure.IoT Build | 0:6ae2f7bca550 | 1410 | if (message == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 1411 | { |
AzureIoTClient | 28:add19eb7defa | 1412 | /* Codes_SRS_MESSAGE_01_131: [ If `message` is NULL, `message_set_message_format` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1413 | LogError("NULL message"); |
AzureIoTClient | 28:add19eb7defa | 1414 | result = __FAILURE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 1415 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1416 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 1417 | { |
AzureIoTClient | 28:add19eb7defa | 1418 | /* Codes_SRS_MESSAGE_01_129: [ `message_set_message_format` shall set the message format for the message identified by `message`. ]*/ |
AzureIoTClient | 24:2c59c2d43ebf | 1419 | message->message_format = message_format; |
AzureIoTClient | 28:add19eb7defa | 1420 | |
AzureIoTClient | 28:add19eb7defa | 1421 | /* Codes_SRS_MESSAGE_01_130: [ On success, `message_set_message_format` shall return 0. ]*/ |
Azure.IoT Build | 0:6ae2f7bca550 | 1422 | result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 1423 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1424 | |
Azure.IoT Build | 0:6ae2f7bca550 | 1425 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1426 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1427 | |
Azure.IoT Build | 0:6ae2f7bca550 | 1428 | int message_get_message_format(MESSAGE_HANDLE message, uint32_t *message_format) |
Azure.IoT Build | 0:6ae2f7bca550 | 1429 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 1430 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1431 | |
Azure.IoT Build | 0:6ae2f7bca550 | 1432 | if ((message == NULL) || |
Azure.IoT Build | 0:6ae2f7bca550 | 1433 | (message_format == NULL)) |
Azure.IoT Build | 0:6ae2f7bca550 | 1434 | { |
AzureIoTClient | 28:add19eb7defa | 1435 | /* Codes_SRS_MESSAGE_01_134: [ If `message` or `message_format` is NULL, `message_get_message_format` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 28:add19eb7defa | 1436 | LogError("Bad arguments: message = %p, message_format = %p", |
AzureIoTClient | 28:add19eb7defa | 1437 | message, message_format); |
AzureIoTClient | 28:add19eb7defa | 1438 | result = __FAILURE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 1439 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1440 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 1441 | { |
AzureIoTClient | 28:add19eb7defa | 1442 | /* Codes_SRS_MESSAGE_01_132: [ `message_get_message_format` shall get the message format for the message identified by `message` and return it in the `message_fomrat` argument. ]*/ |
AzureIoTClient | 24:2c59c2d43ebf | 1443 | *message_format = message->message_format; |
AzureIoTClient | 28:add19eb7defa | 1444 | |
AzureIoTClient | 28:add19eb7defa | 1445 | /* Codes_SRS_MESSAGE_01_133: [ On success, `message_get_message_format` shall return 0. ]*/ |
Azure.IoT Build | 0:6ae2f7bca550 | 1446 | result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 1447 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1448 | |
Azure.IoT Build | 0:6ae2f7bca550 | 1449 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1450 | } |