A small memory footprint AMQP implimentation
Dependents: iothub_client_sample_amqp remote_monitoring simplesample_amqp
amqp_management.c@40:f0ceafa8d570, 2018-03-05 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Mon Mar 05 17:41:28 2018 -0800
- Revision:
- 40:f0ceafa8d570
- Parent:
- 39:e7c983378f41
- Child:
- 41:0e723f9cbd89
1.2.0
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 <stdio.h> |
AzureIoTClient | 6:641a9672db08 | 6 | #include <stdbool.h> |
Azure.IoT Build | 0:6ae2f7bca550 | 7 | #include <string.h> |
AzureIoTClient | 19:000ab4e6a2c1 | 8 | #include "azure_c_shared_utility/optimize_size.h" |
AzureIoTClient | 21:f9c433d8e6ca | 9 | #include "azure_c_shared_utility/gballoc.h" |
AzureIoTClient | 23:1111ee8bcba4 | 10 | #include "azure_c_shared_utility/singlylinkedlist.h" |
AzureIoTClient | 27:d74f1cea23e1 | 11 | #include "azure_c_shared_utility/xlogging.h" |
AzureIoTClient | 39:e7c983378f41 | 12 | #include "azure_c_shared_utility/crt_abstractions.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 13 | #include "azure_uamqp_c/amqp_management.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 14 | #include "azure_uamqp_c/link.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 15 | #include "azure_uamqp_c/message_sender.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 16 | #include "azure_uamqp_c/message_receiver.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 17 | #include "azure_uamqp_c/messaging.h" |
AzureIoTClient | 40:f0ceafa8d570 | 18 | #include "azure_uamqp_c/amqp_definitions.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 19 | |
AzureIoTClient | 23:1111ee8bcba4 | 20 | static const char sender_suffix[] = "-sender"; |
AzureIoTClient | 23:1111ee8bcba4 | 21 | static const char receiver_suffix[] = "-receiver"; |
AzureIoTClient | 23:1111ee8bcba4 | 22 | |
AzureIoTClient | 23:1111ee8bcba4 | 23 | #define COUNT_CHARS(str) (sizeof(str) / sizeof((str)[0]) - 1) |
Azure.IoT Build | 0:6ae2f7bca550 | 24 | |
Azure.IoT Build | 0:6ae2f7bca550 | 25 | typedef struct OPERATION_MESSAGE_INSTANCE_TAG |
Azure.IoT Build | 0:6ae2f7bca550 | 26 | { |
AzureIoTClient | 22:524bded3f7a8 | 27 | ON_AMQP_MANAGEMENT_EXECUTE_OPERATION_COMPLETE on_execute_operation_complete; |
AzureIoTClient | 6:641a9672db08 | 28 | void* callback_context; |
AzureIoTClient | 23:1111ee8bcba4 | 29 | uint64_t message_id; |
Azure.IoT Build | 0:6ae2f7bca550 | 30 | } OPERATION_MESSAGE_INSTANCE; |
Azure.IoT Build | 0:6ae2f7bca550 | 31 | |
AzureIoTClient | 22:524bded3f7a8 | 32 | typedef enum AMQP_MANAGEMENT_STATE_TAG |
AzureIoTClient | 22:524bded3f7a8 | 33 | { |
AzureIoTClient | 22:524bded3f7a8 | 34 | AMQP_MANAGEMENT_STATE_IDLE, |
AzureIoTClient | 22:524bded3f7a8 | 35 | AMQP_MANAGEMENT_STATE_OPENING, |
AzureIoTClient | 22:524bded3f7a8 | 36 | AMQP_MANAGEMENT_STATE_OPEN, |
AzureIoTClient | 22:524bded3f7a8 | 37 | AMQP_MANAGEMENT_STATE_ERROR |
AzureIoTClient | 22:524bded3f7a8 | 38 | } AMQP_MANAGEMENT_STATE; |
AzureIoTClient | 22:524bded3f7a8 | 39 | |
Azure.IoT Build | 0:6ae2f7bca550 | 40 | typedef struct AMQP_MANAGEMENT_INSTANCE_TAG |
Azure.IoT Build | 0:6ae2f7bca550 | 41 | { |
AzureIoTClient | 6:641a9672db08 | 42 | LINK_HANDLE sender_link; |
AzureIoTClient | 6:641a9672db08 | 43 | LINK_HANDLE receiver_link; |
AzureIoTClient | 6:641a9672db08 | 44 | MESSAGE_SENDER_HANDLE message_sender; |
AzureIoTClient | 6:641a9672db08 | 45 | MESSAGE_RECEIVER_HANDLE message_receiver; |
AzureIoTClient | 23:1111ee8bcba4 | 46 | SINGLYLINKEDLIST_HANDLE pending_operations; |
AzureIoTClient | 23:1111ee8bcba4 | 47 | uint64_t next_message_id; |
AzureIoTClient | 22:524bded3f7a8 | 48 | ON_AMQP_MANAGEMENT_OPEN_COMPLETE on_amqp_management_open_complete; |
AzureIoTClient | 22:524bded3f7a8 | 49 | void* on_amqp_management_open_complete_context; |
AzureIoTClient | 22:524bded3f7a8 | 50 | ON_AMQP_MANAGEMENT_ERROR on_amqp_management_error; |
AzureIoTClient | 22:524bded3f7a8 | 51 | void* on_amqp_management_error_context; |
AzureIoTClient | 6:641a9672db08 | 52 | AMQP_MANAGEMENT_STATE amqp_management_state; |
AzureIoTClient | 39:e7c983378f41 | 53 | char* status_code_key_name; |
AzureIoTClient | 39:e7c983378f41 | 54 | char* status_description_key_name; |
AzureIoTClient | 6:641a9672db08 | 55 | int sender_connected : 1; |
AzureIoTClient | 6:641a9672db08 | 56 | int receiver_connected : 1; |
Azure.IoT Build | 0:6ae2f7bca550 | 57 | } AMQP_MANAGEMENT_INSTANCE; |
Azure.IoT Build | 0:6ae2f7bca550 | 58 | |
AzureIoTClient | 23:1111ee8bcba4 | 59 | static AMQP_VALUE on_message_received(const void* context, MESSAGE_HANDLE message) |
Azure.IoT Build | 0:6ae2f7bca550 | 60 | { |
AzureIoTClient | 23:1111ee8bcba4 | 61 | AMQP_VALUE result; |
Azure.IoT Build | 0:6ae2f7bca550 | 62 | |
AzureIoTClient | 23:1111ee8bcba4 | 63 | if (context == NULL) |
AzureIoTClient | 6:641a9672db08 | 64 | { |
AzureIoTClient | 23:1111ee8bcba4 | 65 | /* Codes_SRS_AMQP_MANAGEMENT_01_108: [ When `on_message_received` is called with a NULL context, it shall do nothing. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 66 | LogError("NULL context in on_message_received"); |
AzureIoTClient | 23:1111ee8bcba4 | 67 | result = NULL; |
AzureIoTClient | 6:641a9672db08 | 68 | } |
AzureIoTClient | 6:641a9672db08 | 69 | else |
AzureIoTClient | 6:641a9672db08 | 70 | { |
AzureIoTClient | 23:1111ee8bcba4 | 71 | AMQP_MANAGEMENT_HANDLE amqp_management = (AMQP_MANAGEMENT_HANDLE)context; |
AzureIoTClient | 23:1111ee8bcba4 | 72 | AMQP_VALUE application_properties; |
Azure.IoT Build | 0:6ae2f7bca550 | 73 | |
AzureIoTClient | 23:1111ee8bcba4 | 74 | /* Codes_SRS_AMQP_MANAGEMENT_01_109: [ `on_message_received` shall obtain the application properties from the message by calling `message_get_application_properties`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 75 | if (message_get_application_properties(message, &application_properties) != 0) |
AzureIoTClient | 6:641a9672db08 | 76 | { |
AzureIoTClient | 23:1111ee8bcba4 | 77 | /* Codes_SRS_AMQP_MANAGEMENT_01_113: [ If obtaining the application properties or message properties fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 78 | LogError("Could not retrieve application properties"); |
AzureIoTClient | 23:1111ee8bcba4 | 79 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 80 | /* Codes_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 81 | result = messaging_delivery_rejected("amqp:internal-error", "Could not get application properties on AMQP management response."); |
AzureIoTClient | 6:641a9672db08 | 82 | } |
AzureIoTClient | 6:641a9672db08 | 83 | else |
AzureIoTClient | 6:641a9672db08 | 84 | { |
AzureIoTClient | 23:1111ee8bcba4 | 85 | PROPERTIES_HANDLE response_properties; |
Azure.IoT Build | 0:6ae2f7bca550 | 86 | |
AzureIoTClient | 23:1111ee8bcba4 | 87 | /* Codes_SRS_AMQP_MANAGEMENT_01_110: [ `on_message_received` shall obtain the message properties from the message by calling `message_get_properties`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 88 | if (message_get_properties(message, &response_properties) != 0) |
AzureIoTClient | 6:641a9672db08 | 89 | { |
AzureIoTClient | 23:1111ee8bcba4 | 90 | /* Codes_SRS_AMQP_MANAGEMENT_01_113: [ If obtaining the application properties or message properties fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 91 | LogError("Could not retrieve message properties"); |
AzureIoTClient | 23:1111ee8bcba4 | 92 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 93 | /* Codes_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 94 | result = messaging_delivery_rejected("amqp:internal-error", "Could not get message properties on AMQP management response."); |
AzureIoTClient | 6:641a9672db08 | 95 | } |
AzureIoTClient | 6:641a9672db08 | 96 | else |
AzureIoTClient | 6:641a9672db08 | 97 | { |
AzureIoTClient | 23:1111ee8bcba4 | 98 | AMQP_VALUE key; |
AzureIoTClient | 23:1111ee8bcba4 | 99 | AMQP_VALUE value; |
AzureIoTClient | 23:1111ee8bcba4 | 100 | AMQP_VALUE desc_key; |
AzureIoTClient | 23:1111ee8bcba4 | 101 | AMQP_VALUE desc_value; |
AzureIoTClient | 23:1111ee8bcba4 | 102 | AMQP_VALUE map; |
AzureIoTClient | 23:1111ee8bcba4 | 103 | AMQP_VALUE correlation_id_value; |
AzureIoTClient | 23:1111ee8bcba4 | 104 | uint64_t correlation_id; |
AzureIoTClient | 23:1111ee8bcba4 | 105 | |
AzureIoTClient | 23:1111ee8bcba4 | 106 | /* Codes_SRS_AMQP_MANAGEMENT_01_111: [ `on_message_received` shall obtain the correlation Id from the message properties by using `properties_get_correlation_id`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 107 | if (properties_get_correlation_id(response_properties, &correlation_id_value) != 0) |
AzureIoTClient | 6:641a9672db08 | 108 | { |
AzureIoTClient | 23:1111ee8bcba4 | 109 | /* Codes_SRS_AMQP_MANAGEMENT_01_114: [ If obtaining the correlation Id fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ] */ |
AzureIoTClient | 23:1111ee8bcba4 | 110 | LogError("Could not retrieve correlation Id"); |
AzureIoTClient | 23:1111ee8bcba4 | 111 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 112 | /* Codes_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 113 | result = messaging_delivery_rejected("amqp:internal-error", "Could not get correlation Id from AMQP management response."); |
AzureIoTClient | 6:641a9672db08 | 114 | } |
AzureIoTClient | 6:641a9672db08 | 115 | else |
AzureIoTClient | 6:641a9672db08 | 116 | { |
AzureIoTClient | 23:1111ee8bcba4 | 117 | if (amqpvalue_get_ulong(correlation_id_value, &correlation_id) != 0) |
AzureIoTClient | 6:641a9672db08 | 118 | { |
AzureIoTClient | 23:1111ee8bcba4 | 119 | /* Codes_SRS_AMQP_MANAGEMENT_01_132: [ If any functions manipulating AMQP values, application properties, etc., fail, an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 120 | LogError("Could not retrieve correlation Id ulong value"); |
AzureIoTClient | 23:1111ee8bcba4 | 121 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 122 | /* Codes_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 123 | result = messaging_delivery_rejected("amqp:internal-error", "Could not get correlation Id from AMQP management response."); |
AzureIoTClient | 6:641a9672db08 | 124 | } |
AzureIoTClient | 6:641a9672db08 | 125 | else |
AzureIoTClient | 6:641a9672db08 | 126 | { |
AzureIoTClient | 23:1111ee8bcba4 | 127 | /* Codes_SRS_AMQP_MANAGEMENT_01_119: [ `on_message_received` shall obtain the application properties map by calling `amqpvalue_get_inplace_described_value`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 128 | /* Codes_SRS_AMQP_MANAGEMENT_01_070: [ Response messages have the following application-properties: ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 129 | map = amqpvalue_get_inplace_described_value(application_properties); |
AzureIoTClient | 23:1111ee8bcba4 | 130 | if (map == NULL) |
AzureIoTClient | 6:641a9672db08 | 131 | { |
AzureIoTClient | 23:1111ee8bcba4 | 132 | /* Codes_SRS_AMQP_MANAGEMENT_01_132: [ If any functions manipulating AMQP values, application properties, etc., fail, an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 133 | LogError("Could not retrieve application property map"); |
AzureIoTClient | 23:1111ee8bcba4 | 134 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 135 | /* Codes_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 136 | result = messaging_delivery_rejected("amqp:internal-error", "Could not get application property map from the application properties in the AMQP management response."); |
AzureIoTClient | 6:641a9672db08 | 137 | } |
AzureIoTClient | 6:641a9672db08 | 138 | else |
AzureIoTClient | 6:641a9672db08 | 139 | { |
AzureIoTClient | 39:e7c983378f41 | 140 | /* Codes_SRS_AMQP_MANAGEMENT_01_120: [ An AMQP value used to lookup the status code shall be created by calling `amqpvalue_create_string` with the status code key name (`statusCode`) as argument. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 141 | /* Codes_SRS_AMQP_MANAGEMENT_01_071: [ statusCode integer Yes HTTP response code [RFC2616] ]*/ |
AzureIoTClient | 39:e7c983378f41 | 142 | key = amqpvalue_create_string(amqp_management->status_code_key_name); |
AzureIoTClient | 23:1111ee8bcba4 | 143 | if (key == NULL) |
AzureIoTClient | 6:641a9672db08 | 144 | { |
AzureIoTClient | 23:1111ee8bcba4 | 145 | /* Codes_SRS_AMQP_MANAGEMENT_01_132: [ If any functions manipulating AMQP values, application properties, etc., fail, an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 146 | LogError("Could not create status-code amqp value"); |
AzureIoTClient | 23:1111ee8bcba4 | 147 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 148 | /* Codes_SRS_AMQP_MANAGEMENT_01_135: [ When an error occurs in creating AMQP values (for status code, etc.) `on_message_received` shall call `messaging_delivery_released` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 149 | result = messaging_delivery_released(); |
AzureIoTClient | 6:641a9672db08 | 150 | } |
AzureIoTClient | 1:eab586236bfe | 151 | else |
AzureIoTClient | 1:eab586236bfe | 152 | { |
AzureIoTClient | 23:1111ee8bcba4 | 153 | /* Codes_SRS_AMQP_MANAGEMENT_01_121: [ The status code shall be looked up in the application properties by using `amqpvalue_get_map_value`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 154 | value = amqpvalue_get_map_value(map, key); |
AzureIoTClient | 23:1111ee8bcba4 | 155 | if (value == NULL) |
AzureIoTClient | 1:eab586236bfe | 156 | { |
AzureIoTClient | 23:1111ee8bcba4 | 157 | /* Codes_SRS_AMQP_MANAGEMENT_01_122: [ If status code is not found an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 158 | LogError("Could not retrieve status code from application properties"); |
AzureIoTClient | 23:1111ee8bcba4 | 159 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 160 | /* Codes_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 161 | result = messaging_delivery_rejected("amqp:internal-error", "Could not retrieve status code from the application properties in the AMQP management response."); |
AzureIoTClient | 1:eab586236bfe | 162 | } |
AzureIoTClient | 1:eab586236bfe | 163 | else |
AzureIoTClient | 1:eab586236bfe | 164 | { |
AzureIoTClient | 23:1111ee8bcba4 | 165 | int32_t status_code; |
AzureIoTClient | 23:1111ee8bcba4 | 166 | /* Codes_SRS_AMQP_MANAGEMENT_01_133: [ The status code value shall be extracted from the value found in the map by using `amqpvalue_get_int`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 167 | if (amqpvalue_get_int(value, &status_code) != 0) |
AzureIoTClient | 23:1111ee8bcba4 | 168 | { |
AzureIoTClient | 23:1111ee8bcba4 | 169 | /* Codes_SRS_AMQP_MANAGEMENT_01_132: [ If any functions manipulating AMQP values, application properties, etc., fail, an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 170 | LogError("Could not retrieve status code int value"); |
AzureIoTClient | 23:1111ee8bcba4 | 171 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 172 | /* Codes_SRS_AMQP_MANAGEMENT_01_136: [ When `on_message_received` fails due to errors in parsing the response message `on_message_received` shall call `messaging_delivery_rejected` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 173 | result = messaging_delivery_rejected("amqp:internal-error", "Could not retrieve status code value from the application properties in the AMQP management response."); |
AzureIoTClient | 23:1111ee8bcba4 | 174 | } |
AzureIoTClient | 23:1111ee8bcba4 | 175 | else |
AzureIoTClient | 1:eab586236bfe | 176 | { |
AzureIoTClient | 39:e7c983378f41 | 177 | /* Codes_SRS_AMQP_MANAGEMENT_01_123: [ An AMQP value used to lookup the status description shall be created by calling `amqpvalue_create_string` with the status description key name (`statusDescription`) as argument. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 178 | /* Codes_SRS_AMQP_MANAGEMENT_01_072: [ statusDescription string No Description of the status. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 179 | desc_key = amqpvalue_create_string(amqp_management->status_description_key_name); |
AzureIoTClient | 23:1111ee8bcba4 | 180 | if (desc_key == NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 181 | { |
AzureIoTClient | 23:1111ee8bcba4 | 182 | /* Codes_SRS_AMQP_MANAGEMENT_01_132: [ If any functions manipulating AMQP values, application properties, etc., fail, an error shall be indicated to the consumer by calling the `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 183 | LogError("Could not create status-description amqp value"); |
AzureIoTClient | 23:1111ee8bcba4 | 184 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 185 | /* Codes_SRS_AMQP_MANAGEMENT_01_135: [ When an error occurs in creating AMQP values (for status code, etc.) `on_message_received` shall call `messaging_delivery_released` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 186 | result = messaging_delivery_released(); |
AzureIoTClient | 23:1111ee8bcba4 | 187 | } |
AzureIoTClient | 23:1111ee8bcba4 | 188 | else |
AzureIoTClient | 23:1111ee8bcba4 | 189 | { |
AzureIoTClient | 23:1111ee8bcba4 | 190 | const char* status_description = NULL; |
AzureIoTClient | 23:1111ee8bcba4 | 191 | LIST_ITEM_HANDLE list_item_handle; |
AzureIoTClient | 23:1111ee8bcba4 | 192 | bool found = false; |
AzureIoTClient | 23:1111ee8bcba4 | 193 | bool is_error = false; |
AzureIoTClient | 1:eab586236bfe | 194 | |
AzureIoTClient | 23:1111ee8bcba4 | 195 | /* Codes_SRS_AMQP_MANAGEMENT_01_124: [ The status description shall be looked up in the application properties by using `amqpvalue_get_map_value`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 196 | desc_value = amqpvalue_get_map_value(map, desc_key); |
AzureIoTClient | 23:1111ee8bcba4 | 197 | if (desc_value != NULL) |
AzureIoTClient | 1:eab586236bfe | 198 | { |
AzureIoTClient | 23:1111ee8bcba4 | 199 | /* Codes_SRS_AMQP_MANAGEMENT_01_134: [ The status description value shall be extracted from the value found in the map by using `amqpvalue_get_string`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 200 | if (amqpvalue_get_string(desc_value, &status_description) != 0) |
AzureIoTClient | 23:1111ee8bcba4 | 201 | { |
AzureIoTClient | 23:1111ee8bcba4 | 202 | /* Codes_SRS_AMQP_MANAGEMENT_01_125: [ If status description is not found, NULL shall be passed to the user callback as `status_description` argument. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 203 | status_description = NULL; |
AzureIoTClient | 23:1111ee8bcba4 | 204 | } |
AzureIoTClient | 1:eab586236bfe | 205 | } |
AzureIoTClient | 1:eab586236bfe | 206 | else |
AzureIoTClient | 1:eab586236bfe | 207 | { |
AzureIoTClient | 23:1111ee8bcba4 | 208 | /* Codes_SRS_AMQP_MANAGEMENT_01_125: [ If status description is not found, NULL shall be passed to the user callback as `status_description` argument. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 209 | status_description = NULL; |
AzureIoTClient | 23:1111ee8bcba4 | 210 | } |
AzureIoTClient | 23:1111ee8bcba4 | 211 | |
AzureIoTClient | 23:1111ee8bcba4 | 212 | list_item_handle = singlylinkedlist_get_head_item(amqp_management->pending_operations); |
AzureIoTClient | 23:1111ee8bcba4 | 213 | while (list_item_handle != NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 214 | { |
AzureIoTClient | 23:1111ee8bcba4 | 215 | /* Codes_SRS_AMQP_MANAGEMENT_01_116: [ Each pending operation item value shall be obtained by calling `singlylinkedlist_item_get_value`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 216 | OPERATION_MESSAGE_INSTANCE* operation_message = (OPERATION_MESSAGE_INSTANCE*)singlylinkedlist_item_get_value(list_item_handle); |
AzureIoTClient | 23:1111ee8bcba4 | 217 | if (operation_message == NULL) |
AzureIoTClient | 1:eab586236bfe | 218 | { |
AzureIoTClient | 23:1111ee8bcba4 | 219 | /* Codes_SRS_AMQP_MANAGEMENT_01_117: [ If iterating through the pending operations list fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 220 | LogError("Could not create status-description amqp value"); |
AzureIoTClient | 23:1111ee8bcba4 | 221 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 222 | /* Codes_SRS_AMQP_MANAGEMENT_01_135: [ When an error occurs in creating AMQP values (for status code, etc.) `on_message_received` shall call `messaging_delivery_released` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 223 | result = messaging_delivery_released(); |
AzureIoTClient | 1:eab586236bfe | 224 | break; |
AzureIoTClient | 1:eab586236bfe | 225 | } |
AzureIoTClient | 1:eab586236bfe | 226 | else |
AzureIoTClient | 1:eab586236bfe | 227 | { |
AzureIoTClient | 23:1111ee8bcba4 | 228 | AMQP_MANAGEMENT_EXECUTE_OPERATION_RESULT execute_operation_result; |
AzureIoTClient | 23:1111ee8bcba4 | 229 | |
AzureIoTClient | 23:1111ee8bcba4 | 230 | /* Codes_SRS_AMQP_MANAGEMENT_01_112: [ `on_message_received` shall check if the correlation Id matches the stored message Id of any pending operation. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 231 | /* Codes_SRS_AMQP_MANAGEMENT_01_068: [ The correlation-id of the response message MUST be the correlation-id from the request message (if present) ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 232 | /* Codes_SRS_AMQP_MANAGEMENT_01_069: [ else the message-id from the request message. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 233 | if (correlation_id == operation_message->message_id) |
AzureIoTClient | 23:1111ee8bcba4 | 234 | { |
AzureIoTClient | 23:1111ee8bcba4 | 235 | /* Codes_SRS_AMQP_MANAGEMENT_01_074: [ Successful operations MUST result in a statusCode in the 2xx range as defined in Section 10.2 of [RFC2616]. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 236 | if ((status_code < 200) || (status_code > 299)) |
AzureIoTClient | 23:1111ee8bcba4 | 237 | { |
AzureIoTClient | 23:1111ee8bcba4 | 238 | /* Codes_SRS_AMQP_MANAGEMENT_01_128: [ If the status indicates that the operation failed, the result callback argument shall be `AMQP_MANAGEMENT_EXECUTE_OPERATION_FAILED_BAD_STATUS`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 239 | /* Codes_SRS_AMQP_MANAGEMENT_01_075: [ Unsuccessful operations MUST NOT result in a statusCode in the 2xx range as defined in Section 10.2 of [RFC2616]. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 240 | execute_operation_result = AMQP_MANAGEMENT_EXECUTE_OPERATION_FAILED_BAD_STATUS; |
AzureIoTClient | 23:1111ee8bcba4 | 241 | } |
AzureIoTClient | 23:1111ee8bcba4 | 242 | else |
AzureIoTClient | 23:1111ee8bcba4 | 243 | { |
AzureIoTClient | 23:1111ee8bcba4 | 244 | /* Codes_SRS_AMQP_MANAGEMENT_01_127: [ If the operation succeeded the result callback argument shall be `AMQP_MANAGEMENT_EXECUTE_OPERATION_OK`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 245 | execute_operation_result = AMQP_MANAGEMENT_EXECUTE_OPERATION_OK; |
AzureIoTClient | 23:1111ee8bcba4 | 246 | } |
AzureIoTClient | 23:1111ee8bcba4 | 247 | |
AzureIoTClient | 23:1111ee8bcba4 | 248 | /* Codes_SRS_AMQP_MANAGEMENT_01_126: [ If a corresponding correlation Id is found in the pending operations list, the callback associated with the pending operation shall be called. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 249 | /* Codes_SRS_AMQP_MANAGEMENT_01_166: [ The `message` shall be passed as argument to the callback. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 250 | operation_message->on_execute_operation_complete(operation_message->callback_context, execute_operation_result, status_code, status_description, message); |
AzureIoTClient | 23:1111ee8bcba4 | 251 | |
AzureIoTClient | 23:1111ee8bcba4 | 252 | free(operation_message); |
AzureIoTClient | 23:1111ee8bcba4 | 253 | |
AzureIoTClient | 23:1111ee8bcba4 | 254 | /* Codes_SRS_AMQP_MANAGEMENT_01_129: [ After calling the callback, the pending operation shall be removed from the pending operations list by calling `singlylinkedlist_remove`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 255 | if (singlylinkedlist_remove(amqp_management->pending_operations, list_item_handle) != 0) |
AzureIoTClient | 23:1111ee8bcba4 | 256 | { |
AzureIoTClient | 23:1111ee8bcba4 | 257 | LogError("Cannot remove pending operation"); |
AzureIoTClient | 23:1111ee8bcba4 | 258 | is_error = true; |
AzureIoTClient | 23:1111ee8bcba4 | 259 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 260 | } |
AzureIoTClient | 23:1111ee8bcba4 | 261 | else |
AzureIoTClient | 23:1111ee8bcba4 | 262 | { |
AzureIoTClient | 23:1111ee8bcba4 | 263 | found = true; |
AzureIoTClient | 23:1111ee8bcba4 | 264 | } |
AzureIoTClient | 23:1111ee8bcba4 | 265 | |
AzureIoTClient | 23:1111ee8bcba4 | 266 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 267 | } |
AzureIoTClient | 1:eab586236bfe | 268 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 269 | |
AzureIoTClient | 23:1111ee8bcba4 | 270 | /* Codes_SRS_AMQP_MANAGEMENT_01_115: [ Iterating through the pending operations shall be done by using `singlylinkedlist_get_head_item` and `singlylinkedlist_get_next_item` until the enm of the pending operations singly linked list is reached. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 271 | /* Codes_SRS_AMQP_MANAGEMENT_01_117: [ If iterating through the pending operations list fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 272 | list_item_handle = singlylinkedlist_get_next_item(list_item_handle); |
AzureIoTClient | 23:1111ee8bcba4 | 273 | } |
AzureIoTClient | 23:1111ee8bcba4 | 274 | |
AzureIoTClient | 23:1111ee8bcba4 | 275 | if (is_error) |
AzureIoTClient | 23:1111ee8bcba4 | 276 | { |
AzureIoTClient | 23:1111ee8bcba4 | 277 | /* Codes_SRS_AMQP_MANAGEMENT_01_117: [ If iterating through the pending operations list fails, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 278 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 279 | /* Codes_SRS_AMQP_MANAGEMENT_01_135: [ When an error occurs in creating AMQP values (for status code, etc.) `on_message_received` shall call `messaging_delivery_released` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 280 | result = messaging_delivery_released(); |
AzureIoTClient | 1:eab586236bfe | 281 | } |
AzureIoTClient | 23:1111ee8bcba4 | 282 | else |
AzureIoTClient | 23:1111ee8bcba4 | 283 | { |
AzureIoTClient | 23:1111ee8bcba4 | 284 | if (!found) |
AzureIoTClient | 23:1111ee8bcba4 | 285 | { |
AzureIoTClient | 23:1111ee8bcba4 | 286 | /* Codes_SRS_AMQP_MANAGEMENT_01_118: [ If no pending operation is found matching the correlation Id, an error shall be indicated by calling `on_amqp_management_error` and passing the `on_amqp_management_error_context` to it. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 287 | LogError("Could not match AMQP management response to request"); |
AzureIoTClient | 23:1111ee8bcba4 | 288 | amqp_management->on_amqp_management_error(amqp_management->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 289 | /* Codes_SRS_AMQP_MANAGEMENT_01_135: [ When an error occurs in creating AMQP values (for status code, etc.) `on_message_received` shall call `messaging_delivery_released` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 290 | result = messaging_delivery_rejected("amqp:internal-error", "Could not match AMQP management response to request"); |
AzureIoTClient | 23:1111ee8bcba4 | 291 | } |
AzureIoTClient | 23:1111ee8bcba4 | 292 | else |
AzureIoTClient | 23:1111ee8bcba4 | 293 | { |
AzureIoTClient | 23:1111ee8bcba4 | 294 | /* Codes_SRS_AMQP_MANAGEMENT_01_130: [ The `on_message_received` shall call `messaging_delivery_accepted` and return the created delivery AMQP value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 295 | result = messaging_delivery_accepted(); |
AzureIoTClient | 23:1111ee8bcba4 | 296 | } |
AzureIoTClient | 23:1111ee8bcba4 | 297 | } |
AzureIoTClient | 23:1111ee8bcba4 | 298 | |
AzureIoTClient | 23:1111ee8bcba4 | 299 | if (desc_value != NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 300 | { |
AzureIoTClient | 23:1111ee8bcba4 | 301 | /* Codes_SRS_AMQP_MANAGEMENT_01_131: [ All temporary values like AMQP values used as keys shall be freed before exiting the callback. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 302 | amqpvalue_destroy(desc_value); |
AzureIoTClient | 23:1111ee8bcba4 | 303 | } |
AzureIoTClient | 23:1111ee8bcba4 | 304 | |
AzureIoTClient | 23:1111ee8bcba4 | 305 | /* Codes_SRS_AMQP_MANAGEMENT_01_131: [ All temporary values like AMQP values used as keys shall be freed before exiting the callback. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 306 | amqpvalue_destroy(desc_key); |
AzureIoTClient | 1:eab586236bfe | 307 | } |
AzureIoTClient | 1:eab586236bfe | 308 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 309 | |
AzureIoTClient | 23:1111ee8bcba4 | 310 | /* Codes_SRS_AMQP_MANAGEMENT_01_131: [ All temporary values like AMQP values used as keys shall be freed before exiting the callback. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 311 | amqpvalue_destroy(value); |
AzureIoTClient | 6:641a9672db08 | 312 | } |
AzureIoTClient | 23:1111ee8bcba4 | 313 | |
AzureIoTClient | 23:1111ee8bcba4 | 314 | /* Codes_SRS_AMQP_MANAGEMENT_01_131: [ All temporary values like AMQP values used as keys shall be freed before exiting the callback. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 315 | amqpvalue_destroy(key); |
AzureIoTClient | 6:641a9672db08 | 316 | } |
AzureIoTClient | 6:641a9672db08 | 317 | } |
AzureIoTClient | 6:641a9672db08 | 318 | } |
AzureIoTClient | 6:641a9672db08 | 319 | } |
AzureIoTClient | 23:1111ee8bcba4 | 320 | |
AzureIoTClient | 23:1111ee8bcba4 | 321 | /* Codes_SRS_AMQP_MANAGEMENT_01_131: [ All temporary values like AMQP values used as keys shall be freed before exiting the callback. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 322 | properties_destroy(response_properties); |
AzureIoTClient | 6:641a9672db08 | 323 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 324 | |
AzureIoTClient | 23:1111ee8bcba4 | 325 | /* Codes_SRS_AMQP_MANAGEMENT_01_131: [ All temporary values like AMQP values used as keys shall be freed before exiting the callback. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 326 | application_properties_destroy(application_properties); |
AzureIoTClient | 6:641a9672db08 | 327 | } |
AzureIoTClient | 6:641a9672db08 | 328 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 329 | |
AzureIoTClient | 6:641a9672db08 | 330 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 331 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 332 | |
Azure.IoT Build | 0:6ae2f7bca550 | 333 | static void on_message_sender_state_changed(void* context, MESSAGE_SENDER_STATE new_state, MESSAGE_SENDER_STATE previous_state) |
Azure.IoT Build | 0:6ae2f7bca550 | 334 | { |
AzureIoTClient | 23:1111ee8bcba4 | 335 | if (context == NULL) |
AzureIoTClient | 6:641a9672db08 | 336 | { |
AzureIoTClient | 23:1111ee8bcba4 | 337 | /* Codes_SRS_AMQP_MANAGEMENT_01_137: [ When `on_message_sender_state_changed` is called with NULL `context`, it shall do nothing. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 338 | LogError("on_message_sender_state_changed called with NULL context"); |
AzureIoTClient | 23:1111ee8bcba4 | 339 | } |
AzureIoTClient | 23:1111ee8bcba4 | 340 | else |
AzureIoTClient | 23:1111ee8bcba4 | 341 | { |
AzureIoTClient | 23:1111ee8bcba4 | 342 | /* Codes_SRS_AMQP_MANAGEMENT_01_138: [ When `on_message_sender_state_changed` is called and the `new_state` is different than `previous_state`, the following actions shall be taken: ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 343 | /* Codes_SRS_AMQP_MANAGEMENT_01_148: [ When no state change is detected, `on_message_sender_state_changed` shall do nothing. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 344 | if (new_state != previous_state) |
AzureIoTClient | 22:524bded3f7a8 | 345 | { |
AzureIoTClient | 23:1111ee8bcba4 | 346 | AMQP_MANAGEMENT_INSTANCE* amqp_management_instance = (AMQP_MANAGEMENT_INSTANCE*)context; |
AzureIoTClient | 23:1111ee8bcba4 | 347 | switch (amqp_management_instance->amqp_management_state) |
AzureIoTClient | 23:1111ee8bcba4 | 348 | { |
AzureIoTClient | 23:1111ee8bcba4 | 349 | default: |
AzureIoTClient | 23:1111ee8bcba4 | 350 | break; |
AzureIoTClient | 22:524bded3f7a8 | 351 | |
AzureIoTClient | 23:1111ee8bcba4 | 352 | /* Codes_SRS_AMQP_MANAGEMENT_01_139: [ For the current state of AMQP management being `OPENING`: ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 353 | case AMQP_MANAGEMENT_STATE_OPENING: |
AzureIoTClient | 22:524bded3f7a8 | 354 | { |
AzureIoTClient | 23:1111ee8bcba4 | 355 | switch (new_state) |
AzureIoTClient | 23:1111ee8bcba4 | 356 | { |
AzureIoTClient | 23:1111ee8bcba4 | 357 | case MESSAGE_SENDER_STATE_OPENING: |
AzureIoTClient | 23:1111ee8bcba4 | 358 | /* Codes_SRS_AMQP_MANAGEMENT_01_165: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEING` the transition shall be ignored. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 359 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 360 | |
AzureIoTClient | 23:1111ee8bcba4 | 361 | default: |
AzureIoTClient | 23:1111ee8bcba4 | 362 | /* Codes_SRS_AMQP_MANAGEMENT_01_140: [ - If `new_state` is `MESSAGE_SENDER_STATE_IDLE`, `MESSAGE_SENDER_STATE_CLOSING` or `MESSAGE_SENDER_STATE_ERROR`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_ERROR`, while also passing the context passed in `amqp_management_open_async`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 363 | case MESSAGE_SENDER_STATE_IDLE: |
AzureIoTClient | 23:1111ee8bcba4 | 364 | case MESSAGE_SENDER_STATE_CLOSING: |
AzureIoTClient | 23:1111ee8bcba4 | 365 | case MESSAGE_SENDER_STATE_ERROR: |
AzureIoTClient | 23:1111ee8bcba4 | 366 | amqp_management_instance->amqp_management_state = AMQP_MANAGEMENT_STATE_IDLE; |
AzureIoTClient | 23:1111ee8bcba4 | 367 | amqp_management_instance->on_amqp_management_open_complete(amqp_management_instance->on_amqp_management_open_complete_context, AMQP_MANAGEMENT_OPEN_ERROR); |
AzureIoTClient | 23:1111ee8bcba4 | 368 | break; |
AzureIoTClient | 22:524bded3f7a8 | 369 | |
AzureIoTClient | 23:1111ee8bcba4 | 370 | case MESSAGE_SENDER_STATE_OPEN: |
AzureIoTClient | 23:1111ee8bcba4 | 371 | amqp_management_instance->sender_connected = -1; |
AzureIoTClient | 23:1111ee8bcba4 | 372 | /* Codes_SRS_AMQP_MANAGEMENT_01_142: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEN` and the message receiver did not yet indicate its state as `MESSAGE_RECEIVER_STATE_OPEN`, the `on_amqp_management_open_complete` callback shall not be called.]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 373 | if (amqp_management_instance->receiver_connected != 0) |
AzureIoTClient | 23:1111ee8bcba4 | 374 | { |
AzureIoTClient | 23:1111ee8bcba4 | 375 | /* Codes_SRS_AMQP_MANAGEMENT_01_141: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEN` and the message receiver already indicated its state as `MESSAGE_RECEIVER_STATE_OPEN`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_OK`, while also passing the context passed in `amqp_management_open_async`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 376 | amqp_management_instance->amqp_management_state = AMQP_MANAGEMENT_STATE_OPEN; |
AzureIoTClient | 23:1111ee8bcba4 | 377 | amqp_management_instance->on_amqp_management_open_complete(amqp_management_instance->on_amqp_management_open_complete_context, AMQP_MANAGEMENT_OPEN_OK); |
AzureIoTClient | 23:1111ee8bcba4 | 378 | } |
AzureIoTClient | 23:1111ee8bcba4 | 379 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 380 | } |
AzureIoTClient | 23:1111ee8bcba4 | 381 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 382 | } |
AzureIoTClient | 23:1111ee8bcba4 | 383 | /* Codes_SRS_AMQP_MANAGEMENT_01_144: [ For the current state of AMQP management being `OPEN`: ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 384 | case AMQP_MANAGEMENT_STATE_OPEN: |
AzureIoTClient | 23:1111ee8bcba4 | 385 | { |
AzureIoTClient | 23:1111ee8bcba4 | 386 | switch (new_state) |
AzureIoTClient | 23:1111ee8bcba4 | 387 | { |
AzureIoTClient | 23:1111ee8bcba4 | 388 | default: |
AzureIoTClient | 23:1111ee8bcba4 | 389 | /* Codes_SRS_AMQP_MANAGEMENT_01_143: [ - If `new_state` is `MESSAGE_SENDER_STATE_IDLE`, `MESSAGE_SENDER_STATE_OPENING`, `MESSAGE_SENDER_STATE_CLOSING` or `MESSAGE_SENDER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 390 | case MESSAGE_SENDER_STATE_IDLE: |
AzureIoTClient | 23:1111ee8bcba4 | 391 | case MESSAGE_SENDER_STATE_CLOSING: |
AzureIoTClient | 23:1111ee8bcba4 | 392 | case MESSAGE_SENDER_STATE_ERROR: |
AzureIoTClient | 23:1111ee8bcba4 | 393 | amqp_management_instance->amqp_management_state = AMQP_MANAGEMENT_STATE_ERROR; |
AzureIoTClient | 23:1111ee8bcba4 | 394 | amqp_management_instance->on_amqp_management_error(amqp_management_instance->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 395 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 396 | |
AzureIoTClient | 23:1111ee8bcba4 | 397 | case MESSAGE_SENDER_STATE_OPEN: |
AzureIoTClient | 23:1111ee8bcba4 | 398 | /* Codes_SRS_AMQP_MANAGEMENT_01_145: [ - If `new_state` is `MESSAGE_SENDER_STATE_OPEN`, `on_message_sender_state_changed` shall do nothing. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 399 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 400 | } |
AzureIoTClient | 23:1111ee8bcba4 | 401 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 402 | } |
AzureIoTClient | 23:1111ee8bcba4 | 403 | /* Codes_SRS_AMQP_MANAGEMENT_01_146: [ For the current state of AMQP management being `ERROR`: ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 404 | case AMQP_MANAGEMENT_STATE_ERROR: |
AzureIoTClient | 23:1111ee8bcba4 | 405 | /* Codes_SRS_AMQP_MANAGEMENT_01_147: [ - All state transitions shall be ignored. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 406 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 407 | } |
AzureIoTClient | 22:524bded3f7a8 | 408 | } |
AzureIoTClient | 6:641a9672db08 | 409 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 410 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 411 | |
Azure.IoT Build | 0:6ae2f7bca550 | 412 | static void on_message_receiver_state_changed(const void* context, MESSAGE_RECEIVER_STATE new_state, MESSAGE_RECEIVER_STATE previous_state) |
Azure.IoT Build | 0:6ae2f7bca550 | 413 | { |
AzureIoTClient | 23:1111ee8bcba4 | 414 | if (context == NULL) |
AzureIoTClient | 6:641a9672db08 | 415 | { |
AzureIoTClient | 23:1111ee8bcba4 | 416 | /* Codes_SRS_AMQP_MANAGEMENT_01_149: [ When `on_message_receiver_state_changed` is called with NULL `context`, it shall do nothing. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 417 | LogError("on_message_receiver_state_changed called with NULL context"); |
AzureIoTClient | 23:1111ee8bcba4 | 418 | } |
AzureIoTClient | 23:1111ee8bcba4 | 419 | else |
AzureIoTClient | 23:1111ee8bcba4 | 420 | { |
AzureIoTClient | 23:1111ee8bcba4 | 421 | /* Codes_SRS_AMQP_MANAGEMENT_01_150: [ When `on_message_receiver_state_changed` is called and the `new_state` is different than `previous_state`, the following actions shall be taken: ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 422 | /* Codes_SRS_AMQP_MANAGEMENT_01_160: [ When no state change is detected, `on_message_receiver_state_changed` shall do nothing. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 423 | if (new_state != previous_state) |
AzureIoTClient | 22:524bded3f7a8 | 424 | { |
AzureIoTClient | 23:1111ee8bcba4 | 425 | AMQP_MANAGEMENT_INSTANCE* amqp_management_instance = (AMQP_MANAGEMENT_INSTANCE*)context; |
AzureIoTClient | 23:1111ee8bcba4 | 426 | switch (amqp_management_instance->amqp_management_state) |
AzureIoTClient | 23:1111ee8bcba4 | 427 | { |
AzureIoTClient | 23:1111ee8bcba4 | 428 | default: |
AzureIoTClient | 23:1111ee8bcba4 | 429 | break; |
AzureIoTClient | 22:524bded3f7a8 | 430 | |
AzureIoTClient | 23:1111ee8bcba4 | 431 | /* Codes_SRS_AMQP_MANAGEMENT_01_151: [ For the current state of AMQP management being `OPENING`: ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 432 | case AMQP_MANAGEMENT_STATE_OPENING: |
AzureIoTClient | 22:524bded3f7a8 | 433 | { |
AzureIoTClient | 23:1111ee8bcba4 | 434 | switch (new_state) |
AzureIoTClient | 23:1111ee8bcba4 | 435 | { |
AzureIoTClient | 23:1111ee8bcba4 | 436 | case MESSAGE_RECEIVER_STATE_OPENING: |
AzureIoTClient | 23:1111ee8bcba4 | 437 | /* Codes_SRS_AMQP_MANAGEMENT_01_164: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_OPEING` the transition shall be ignored. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 438 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 439 | |
AzureIoTClient | 23:1111ee8bcba4 | 440 | default: |
AzureIoTClient | 23:1111ee8bcba4 | 441 | /* Codes_SRS_AMQP_MANAGEMENT_01_152: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_IDLE`, `MESSAGE_RECEIVER_STATE_CLOSING` or `MESSAGE_RECEIVER_STATE_ERROR`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_ERROR`, while also passing the context passed in `amqp_management_open_async`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 442 | case MESSAGE_RECEIVER_STATE_IDLE: |
AzureIoTClient | 23:1111ee8bcba4 | 443 | case MESSAGE_RECEIVER_STATE_CLOSING: |
AzureIoTClient | 23:1111ee8bcba4 | 444 | case MESSAGE_RECEIVER_STATE_ERROR: |
AzureIoTClient | 23:1111ee8bcba4 | 445 | amqp_management_instance->amqp_management_state = AMQP_MANAGEMENT_STATE_IDLE; |
AzureIoTClient | 23:1111ee8bcba4 | 446 | amqp_management_instance->on_amqp_management_open_complete(amqp_management_instance->on_amqp_management_open_complete_context, AMQP_MANAGEMENT_OPEN_ERROR); |
AzureIoTClient | 23:1111ee8bcba4 | 447 | break; |
AzureIoTClient | 22:524bded3f7a8 | 448 | |
AzureIoTClient | 23:1111ee8bcba4 | 449 | case MESSAGE_RECEIVER_STATE_OPEN: |
AzureIoTClient | 23:1111ee8bcba4 | 450 | amqp_management_instance->receiver_connected = -1; |
AzureIoTClient | 23:1111ee8bcba4 | 451 | /* Codes_SRS_AMQP_MANAGEMENT_01_154: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_OPEN` and the message sender did not yet indicate its state as `MESSAGE_RECEIVER_STATE_OPEN`, the `on_amqp_management_open_complete` callback shall not be called. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 452 | if (amqp_management_instance->sender_connected != 0) |
AzureIoTClient | 23:1111ee8bcba4 | 453 | { |
AzureIoTClient | 23:1111ee8bcba4 | 454 | /* Codes_SRS_AMQP_MANAGEMENT_01_153: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_OPEN` and the message sender already indicated its state as `MESSAGE_RECEIVER_STATE_OPEN`, the `on_amqp_management_open_complete` callback shall be called with `AMQP_MANAGEMENT_OPEN_OK`, while also passing the context passed in `amqp_management_open_async`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 455 | amqp_management_instance->amqp_management_state = AMQP_MANAGEMENT_STATE_OPEN; |
AzureIoTClient | 23:1111ee8bcba4 | 456 | amqp_management_instance->on_amqp_management_open_complete(amqp_management_instance->on_amqp_management_open_complete_context, AMQP_MANAGEMENT_OPEN_OK); |
AzureIoTClient | 23:1111ee8bcba4 | 457 | } |
AzureIoTClient | 23:1111ee8bcba4 | 458 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 459 | } |
AzureIoTClient | 23:1111ee8bcba4 | 460 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 461 | } |
AzureIoTClient | 23:1111ee8bcba4 | 462 | /* Codes_SRS_AMQP_MANAGEMENT_01_155: [ For the current state of AMQP management being `OPEN`: ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 463 | case AMQP_MANAGEMENT_STATE_OPEN: |
AzureIoTClient | 23:1111ee8bcba4 | 464 | { |
AzureIoTClient | 23:1111ee8bcba4 | 465 | switch (new_state) |
AzureIoTClient | 23:1111ee8bcba4 | 466 | { |
AzureIoTClient | 23:1111ee8bcba4 | 467 | default: |
AzureIoTClient | 23:1111ee8bcba4 | 468 | /* Codes_SRS_AMQP_MANAGEMENT_01_156: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_IDLE`, `MESSAGE_RECEIVER_STATE_OPENING`, `MESSAGE_RECEIVER_STATE_CLOSING` or `MESSAGE_RECEIVER_STATE_ERROR` the `on_amqp_management_error` callback shall be invoked while passing the `on_amqp_management_error_context` as argument. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 469 | case MESSAGE_RECEIVER_STATE_IDLE: |
AzureIoTClient | 23:1111ee8bcba4 | 470 | case MESSAGE_RECEIVER_STATE_CLOSING: |
AzureIoTClient | 23:1111ee8bcba4 | 471 | case MESSAGE_RECEIVER_STATE_ERROR: |
AzureIoTClient | 23:1111ee8bcba4 | 472 | amqp_management_instance->amqp_management_state = AMQP_MANAGEMENT_STATE_ERROR; |
AzureIoTClient | 23:1111ee8bcba4 | 473 | amqp_management_instance->on_amqp_management_error(amqp_management_instance->on_amqp_management_error_context); |
AzureIoTClient | 23:1111ee8bcba4 | 474 | break; |
Azure.IoT Build | 0:6ae2f7bca550 | 475 | |
AzureIoTClient | 23:1111ee8bcba4 | 476 | case MESSAGE_RECEIVER_STATE_OPEN: |
AzureIoTClient | 23:1111ee8bcba4 | 477 | /* Codes_SRS_AMQP_MANAGEMENT_01_157: [ - If `new_state` is `MESSAGE_RECEIVER_STATE_OPEN`, `on_message_receiver_state_changed` shall do nothing. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 478 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 479 | } |
AzureIoTClient | 23:1111ee8bcba4 | 480 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 481 | } |
AzureIoTClient | 23:1111ee8bcba4 | 482 | /* Codes_SRS_AMQP_MANAGEMENT_01_158: [ For the current state of AMQP management being `ERROR`: ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 483 | case AMQP_MANAGEMENT_STATE_ERROR: |
AzureIoTClient | 23:1111ee8bcba4 | 484 | /* Codes_SRS_AMQP_MANAGEMENT_01_159: [ - All state transitions shall be ignored. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 485 | break; |
AzureIoTClient | 23:1111ee8bcba4 | 486 | } |
AzureIoTClient | 22:524bded3f7a8 | 487 | } |
AzureIoTClient | 6:641a9672db08 | 488 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 489 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 490 | |
AzureIoTClient | 23:1111ee8bcba4 | 491 | static int set_message_id(MESSAGE_HANDLE message, uint64_t next_message_id) |
Azure.IoT Build | 0:6ae2f7bca550 | 492 | { |
AzureIoTClient | 23:1111ee8bcba4 | 493 | int result; |
AzureIoTClient | 23:1111ee8bcba4 | 494 | PROPERTIES_HANDLE properties; |
Azure.IoT Build | 0:6ae2f7bca550 | 495 | |
AzureIoTClient | 23:1111ee8bcba4 | 496 | /* Codes_SRS_AMQP_MANAGEMENT_01_094: [ In order to set the message Id on the message, the properties shall be obtained by calling `message_get_properties`. ]*/ |
AzureIoTClient | 6:641a9672db08 | 497 | if (message_get_properties(message, &properties) != 0) |
AzureIoTClient | 6:641a9672db08 | 498 | { |
AzureIoTClient | 23:1111ee8bcba4 | 499 | /* Codes_SRS_AMQP_MANAGEMENT_01_098: [ If any API fails while setting the message Id, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 500 | LogError("Could not retrieve message properties"); |
AzureIoTClient | 19:000ab4e6a2c1 | 501 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 502 | } |
AzureIoTClient | 6:641a9672db08 | 503 | else |
AzureIoTClient | 6:641a9672db08 | 504 | { |
AzureIoTClient | 23:1111ee8bcba4 | 505 | /* Codes_SRS_AMQP_MANAGEMENT_01_099: [ If the properties were not set on the message, a new properties instance shall be created by calling `properties_create`. ]*/ |
AzureIoTClient | 21:f9c433d8e6ca | 506 | if (properties == NULL) |
AzureIoTClient | 21:f9c433d8e6ca | 507 | { |
AzureIoTClient | 21:f9c433d8e6ca | 508 | properties = properties_create(); |
AzureIoTClient | 21:f9c433d8e6ca | 509 | } |
AzureIoTClient | 21:f9c433d8e6ca | 510 | |
AzureIoTClient | 21:f9c433d8e6ca | 511 | if (properties == NULL) |
AzureIoTClient | 6:641a9672db08 | 512 | { |
AzureIoTClient | 23:1111ee8bcba4 | 513 | /* Codes_SRS_AMQP_MANAGEMENT_01_098: [ If any API fails while setting the message Id, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 514 | LogError("Could not create message properties"); |
AzureIoTClient | 19:000ab4e6a2c1 | 515 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 516 | } |
AzureIoTClient | 6:641a9672db08 | 517 | else |
AzureIoTClient | 6:641a9672db08 | 518 | { |
AzureIoTClient | 23:1111ee8bcba4 | 519 | /* Codes_SRS_AMQP_MANAGEMENT_01_095: [ A message Id with the next ulong value to be used shall be created by calling `amqpvalue_create_message_id_ulong`. ]*/ |
AzureIoTClient | 21:f9c433d8e6ca | 520 | AMQP_VALUE message_id = amqpvalue_create_message_id_ulong(next_message_id); |
AzureIoTClient | 21:f9c433d8e6ca | 521 | if (message_id == NULL) |
AzureIoTClient | 21:f9c433d8e6ca | 522 | { |
AzureIoTClient | 23:1111ee8bcba4 | 523 | /* Codes_SRS_AMQP_MANAGEMENT_01_098: [ If any API fails while setting the message Id, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 524 | LogError("Could not create message id value"); |
AzureIoTClient | 21:f9c433d8e6ca | 525 | result = __FAILURE__; |
AzureIoTClient | 21:f9c433d8e6ca | 526 | } |
AzureIoTClient | 21:f9c433d8e6ca | 527 | else |
AzureIoTClient | 21:f9c433d8e6ca | 528 | { |
AzureIoTClient | 23:1111ee8bcba4 | 529 | /* Codes_SRS_AMQP_MANAGEMENT_01_096: [ The message Id value shall be set on the properties by calling `properties_set_message_id`. ]*/ |
AzureIoTClient | 21:f9c433d8e6ca | 530 | if (properties_set_message_id(properties, message_id) != 0) |
AzureIoTClient | 21:f9c433d8e6ca | 531 | { |
AzureIoTClient | 23:1111ee8bcba4 | 532 | /* Codes_SRS_AMQP_MANAGEMENT_01_098: [ If any API fails while setting the message Id, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 533 | LogError("Could not set message Id on the properties"); |
AzureIoTClient | 21:f9c433d8e6ca | 534 | result = __FAILURE__; |
AzureIoTClient | 21:f9c433d8e6ca | 535 | } |
AzureIoTClient | 23:1111ee8bcba4 | 536 | /* Codes_SRS_AMQP_MANAGEMENT_01_097: [ The properties thus modified to contain the message Id shall be set on the message by calling `message_set_properties`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 537 | else if (message_set_properties(message, properties) != 0) |
AzureIoTClient | 23:1111ee8bcba4 | 538 | { |
AzureIoTClient | 23:1111ee8bcba4 | 539 | /* Codes_SRS_AMQP_MANAGEMENT_01_098: [ If any API fails while setting the message Id, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 540 | LogError("Could not set message properties"); |
AzureIoTClient | 23:1111ee8bcba4 | 541 | result = __FAILURE__; |
AzureIoTClient | 23:1111ee8bcba4 | 542 | } |
AzureIoTClient | 23:1111ee8bcba4 | 543 | else |
AzureIoTClient | 23:1111ee8bcba4 | 544 | { |
AzureIoTClient | 23:1111ee8bcba4 | 545 | result = 0; |
AzureIoTClient | 23:1111ee8bcba4 | 546 | } |
AzureIoTClient | 21:f9c433d8e6ca | 547 | |
AzureIoTClient | 21:f9c433d8e6ca | 548 | amqpvalue_destroy(message_id); |
AzureIoTClient | 21:f9c433d8e6ca | 549 | } |
AzureIoTClient | 21:f9c433d8e6ca | 550 | |
AzureIoTClient | 23:1111ee8bcba4 | 551 | /* Codes_SRS_AMQP_MANAGEMENT_01_100: [ After setting the properties, the properties instance shall be freed by `properties_destroy`. ]*/ |
AzureIoTClient | 21:f9c433d8e6ca | 552 | properties_destroy(properties); |
AzureIoTClient | 6:641a9672db08 | 553 | } |
AzureIoTClient | 6:641a9672db08 | 554 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 555 | |
AzureIoTClient | 6:641a9672db08 | 556 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 557 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 558 | |
Azure.IoT Build | 0:6ae2f7bca550 | 559 | static int add_string_key_value_pair_to_map(AMQP_VALUE map, const char* key, const char* value) |
Azure.IoT Build | 0:6ae2f7bca550 | 560 | { |
AzureIoTClient | 6:641a9672db08 | 561 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 562 | |
AzureIoTClient | 23:1111ee8bcba4 | 563 | /* Codes_SRS_AMQP_MANAGEMENT_01_084: [ For each of the arguments `operation`, `type` and `locales` an AMQP value of type string shall be created by calling `amqpvalue_create_string` in order to be used as key in the application properties map. ]*/ |
AzureIoTClient | 6:641a9672db08 | 564 | AMQP_VALUE key_value = amqpvalue_create_string(key); |
AzureIoTClient | 23:1111ee8bcba4 | 565 | if (key_value == NULL) |
AzureIoTClient | 6:641a9672db08 | 566 | { |
AzureIoTClient | 23:1111ee8bcba4 | 567 | /* Codes_SRS_AMQP_MANAGEMENT_01_090: [ If any APIs used to create and set the application properties on the message fails, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 568 | LogError("Could not create key value for %s", key); |
AzureIoTClient | 19:000ab4e6a2c1 | 569 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 570 | } |
AzureIoTClient | 6:641a9672db08 | 571 | else |
AzureIoTClient | 6:641a9672db08 | 572 | { |
AzureIoTClient | 23:1111ee8bcba4 | 573 | /* Codes_SRS_AMQP_MANAGEMENT_01_085: [ For each of the arguments `operation`, `type` and `locales` an AMQP value of type string containing the argument value shall be created by calling `amqpvalue_create_string` in order to be used as value in the application properties map. ]*/ |
AzureIoTClient | 6:641a9672db08 | 574 | AMQP_VALUE value_value = amqpvalue_create_string(value); |
AzureIoTClient | 6:641a9672db08 | 575 | if (value_value == NULL) |
AzureIoTClient | 6:641a9672db08 | 576 | { |
AzureIoTClient | 23:1111ee8bcba4 | 577 | /* Codes_SRS_AMQP_MANAGEMENT_01_090: [ If any APIs used to create and set the application properties on the message fails, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 578 | LogError("Could not create value for key %s", key); |
AzureIoTClient | 19:000ab4e6a2c1 | 579 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 580 | } |
AzureIoTClient | 6:641a9672db08 | 581 | else |
AzureIoTClient | 6:641a9672db08 | 582 | { |
AzureIoTClient | 23:1111ee8bcba4 | 583 | /* Codes_SRS_AMQP_MANAGEMENT_01_086: [ The key/value pairs for `operation`, `type` and `locales` shall be added to the application properties map by calling `amqpvalue_set_map_value`. ]*/ |
AzureIoTClient | 6:641a9672db08 | 584 | if (amqpvalue_set_map_value(map, key_value, value_value) != 0) |
AzureIoTClient | 6:641a9672db08 | 585 | { |
AzureIoTClient | 23:1111ee8bcba4 | 586 | /* Codes_SRS_AMQP_MANAGEMENT_01_090: [ If any APIs used to create and set the application properties on the message fails, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 587 | LogError("Could not set the value in the map for key %s", key); |
AzureIoTClient | 19:000ab4e6a2c1 | 588 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 589 | } |
AzureIoTClient | 6:641a9672db08 | 590 | else |
AzureIoTClient | 6:641a9672db08 | 591 | { |
AzureIoTClient | 6:641a9672db08 | 592 | result = 0; |
AzureIoTClient | 6:641a9672db08 | 593 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 594 | |
AzureIoTClient | 23:1111ee8bcba4 | 595 | amqpvalue_destroy(value_value); |
AzureIoTClient | 6:641a9672db08 | 596 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 597 | |
AzureIoTClient | 23:1111ee8bcba4 | 598 | amqpvalue_destroy(key_value); |
AzureIoTClient | 6:641a9672db08 | 599 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 600 | |
AzureIoTClient | 6:641a9672db08 | 601 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 602 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 603 | |
AzureIoTClient | 39:e7c983378f41 | 604 | static int internal_set_status_code_key_name(AMQP_MANAGEMENT_HANDLE amqp_management, const char* status_code_key_name) |
AzureIoTClient | 39:e7c983378f41 | 605 | { |
AzureIoTClient | 39:e7c983378f41 | 606 | int result; |
AzureIoTClient | 39:e7c983378f41 | 607 | char* copied_status_code_key_name; |
AzureIoTClient | 39:e7c983378f41 | 608 | if (mallocAndStrcpy_s(&copied_status_code_key_name, status_code_key_name) != 0) |
AzureIoTClient | 39:e7c983378f41 | 609 | { |
AzureIoTClient | 39:e7c983378f41 | 610 | LogError("Cannot copy status code key name"); |
AzureIoTClient | 39:e7c983378f41 | 611 | result = __FAILURE__; |
AzureIoTClient | 39:e7c983378f41 | 612 | } |
AzureIoTClient | 39:e7c983378f41 | 613 | else |
AzureIoTClient | 39:e7c983378f41 | 614 | { |
AzureIoTClient | 39:e7c983378f41 | 615 | if (amqp_management->status_code_key_name != NULL) |
AzureIoTClient | 39:e7c983378f41 | 616 | { |
AzureIoTClient | 39:e7c983378f41 | 617 | free(amqp_management->status_code_key_name); |
AzureIoTClient | 39:e7c983378f41 | 618 | } |
AzureIoTClient | 39:e7c983378f41 | 619 | |
AzureIoTClient | 39:e7c983378f41 | 620 | amqp_management->status_code_key_name = copied_status_code_key_name; |
AzureIoTClient | 39:e7c983378f41 | 621 | result = 0; |
AzureIoTClient | 39:e7c983378f41 | 622 | } |
AzureIoTClient | 39:e7c983378f41 | 623 | |
AzureIoTClient | 39:e7c983378f41 | 624 | return result; |
AzureIoTClient | 39:e7c983378f41 | 625 | } |
AzureIoTClient | 39:e7c983378f41 | 626 | |
AzureIoTClient | 39:e7c983378f41 | 627 | static int internal_set_status_description_key_name(AMQP_MANAGEMENT_HANDLE amqp_management, const char* status_description_key_name) |
AzureIoTClient | 39:e7c983378f41 | 628 | { |
AzureIoTClient | 39:e7c983378f41 | 629 | int result; |
AzureIoTClient | 39:e7c983378f41 | 630 | char* copied_status_description_key_name; |
AzureIoTClient | 39:e7c983378f41 | 631 | if (mallocAndStrcpy_s(&copied_status_description_key_name, status_description_key_name) != 0) |
AzureIoTClient | 39:e7c983378f41 | 632 | { |
AzureIoTClient | 39:e7c983378f41 | 633 | LogError("Cannot copy status description key name"); |
AzureIoTClient | 39:e7c983378f41 | 634 | result = __FAILURE__; |
AzureIoTClient | 39:e7c983378f41 | 635 | } |
AzureIoTClient | 39:e7c983378f41 | 636 | else |
AzureIoTClient | 39:e7c983378f41 | 637 | { |
AzureIoTClient | 39:e7c983378f41 | 638 | if (amqp_management->status_description_key_name != NULL) |
AzureIoTClient | 39:e7c983378f41 | 639 | { |
AzureIoTClient | 39:e7c983378f41 | 640 | free(amqp_management->status_description_key_name); |
AzureIoTClient | 39:e7c983378f41 | 641 | } |
AzureIoTClient | 39:e7c983378f41 | 642 | |
AzureIoTClient | 39:e7c983378f41 | 643 | amqp_management->status_description_key_name = copied_status_description_key_name; |
AzureIoTClient | 39:e7c983378f41 | 644 | result = 0; |
AzureIoTClient | 39:e7c983378f41 | 645 | } |
AzureIoTClient | 39:e7c983378f41 | 646 | |
AzureIoTClient | 39:e7c983378f41 | 647 | return result; |
AzureIoTClient | 39:e7c983378f41 | 648 | } |
AzureIoTClient | 39:e7c983378f41 | 649 | |
AzureIoTClient | 22:524bded3f7a8 | 650 | AMQP_MANAGEMENT_HANDLE amqp_management_create(SESSION_HANDLE session, const char* management_node) |
Azure.IoT Build | 0:6ae2f7bca550 | 651 | { |
AzureIoTClient | 39:e7c983378f41 | 652 | AMQP_MANAGEMENT_INSTANCE* amqp_management; |
Azure.IoT Build | 0:6ae2f7bca550 | 653 | |
AzureIoTClient | 23:1111ee8bcba4 | 654 | if ((session == NULL) || |
AzureIoTClient | 23:1111ee8bcba4 | 655 | (management_node == NULL)) |
AzureIoTClient | 6:641a9672db08 | 656 | { |
AzureIoTClient | 23:1111ee8bcba4 | 657 | /* Codes_SRS_AMQP_MANAGEMENT_01_002: [ If `session` or `management_node` is NULL then `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 658 | LogError("Bad arguments: session = %p, management_node = %p", session, management_node); |
AzureIoTClient | 39:e7c983378f41 | 659 | amqp_management = NULL; |
AzureIoTClient | 23:1111ee8bcba4 | 660 | } |
AzureIoTClient | 23:1111ee8bcba4 | 661 | else if (strlen(management_node) == 0) |
AzureIoTClient | 23:1111ee8bcba4 | 662 | { |
AzureIoTClient | 23:1111ee8bcba4 | 663 | /* Codes_SRS_AMQP_MANAGEMENT_01_030: [ If `management_node` is an empty string, then `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 664 | LogError("Empty string management node"); |
AzureIoTClient | 39:e7c983378f41 | 665 | amqp_management = NULL; |
AzureIoTClient | 6:641a9672db08 | 666 | } |
AzureIoTClient | 6:641a9672db08 | 667 | else |
AzureIoTClient | 6:641a9672db08 | 668 | { |
AzureIoTClient | 23:1111ee8bcba4 | 669 | /* Codes_SRS_AMQP_MANAGEMENT_01_001: [ `amqp_management_create` shall create a new CBS instance and on success return a non-NULL handle to it. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 670 | amqp_management = (AMQP_MANAGEMENT_INSTANCE*)malloc(sizeof(AMQP_MANAGEMENT_INSTANCE)); |
AzureIoTClient | 39:e7c983378f41 | 671 | if (amqp_management == NULL) |
AzureIoTClient | 6:641a9672db08 | 672 | { |
AzureIoTClient | 23:1111ee8bcba4 | 673 | /* Codes_SRS_AMQP_MANAGEMENT_01_005: [ If allocating memory for the new handle fails, `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 674 | LogError("Cannot allocate memory for AMQP management handle"); |
AzureIoTClient | 23:1111ee8bcba4 | 675 | } |
AzureIoTClient | 23:1111ee8bcba4 | 676 | else |
AzureIoTClient | 23:1111ee8bcba4 | 677 | { |
AzureIoTClient | 39:e7c983378f41 | 678 | amqp_management->sender_connected = 0; |
AzureIoTClient | 39:e7c983378f41 | 679 | amqp_management->receiver_connected = 0; |
AzureIoTClient | 39:e7c983378f41 | 680 | amqp_management->on_amqp_management_open_complete = NULL; |
AzureIoTClient | 39:e7c983378f41 | 681 | amqp_management->on_amqp_management_open_complete_context = NULL; |
AzureIoTClient | 39:e7c983378f41 | 682 | amqp_management->on_amqp_management_error = NULL; |
AzureIoTClient | 39:e7c983378f41 | 683 | amqp_management->on_amqp_management_error_context = NULL; |
AzureIoTClient | 39:e7c983378f41 | 684 | amqp_management->amqp_management_state = AMQP_MANAGEMENT_STATE_IDLE; |
AzureIoTClient | 39:e7c983378f41 | 685 | amqp_management->status_code_key_name = NULL; |
AzureIoTClient | 39:e7c983378f41 | 686 | amqp_management->status_description_key_name = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 687 | |
AzureIoTClient | 23:1111ee8bcba4 | 688 | /* Codes_SRS_AMQP_MANAGEMENT_01_003: [ `amqp_management_create` shall create a singly linked list for pending operations by calling `singlylinkedlist_create`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 689 | amqp_management->pending_operations = singlylinkedlist_create(); |
AzureIoTClient | 39:e7c983378f41 | 690 | if (amqp_management->pending_operations == NULL) |
AzureIoTClient | 6:641a9672db08 | 691 | { |
AzureIoTClient | 23:1111ee8bcba4 | 692 | /* Codes_SRS_AMQP_MANAGEMENT_01_004: [ If `singlylinkedlist_create` fails, `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 693 | LogError("Cannot create pending operations list"); |
AzureIoTClient | 6:641a9672db08 | 694 | } |
AzureIoTClient | 6:641a9672db08 | 695 | else |
AzureIoTClient | 6:641a9672db08 | 696 | { |
AzureIoTClient | 39:e7c983378f41 | 697 | /* Codes_SRS_AMQP_MANAGEMENT_01_181: [ `amqp_management_create` shall set the status code key name to be used for parsing the status code to `statusCode`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 698 | if (internal_set_status_code_key_name(amqp_management, "statusCode") != 0) |
AzureIoTClient | 6:641a9672db08 | 699 | { |
AzureIoTClient | 39:e7c983378f41 | 700 | LogError("Cannot set status code key name"); |
AzureIoTClient | 6:641a9672db08 | 701 | } |
AzureIoTClient | 6:641a9672db08 | 702 | else |
AzureIoTClient | 6:641a9672db08 | 703 | { |
AzureIoTClient | 39:e7c983378f41 | 704 | /* Codes_SRS_AMQP_MANAGEMENT_01_182: [ `amqp_management_create` shall set the status description key name to be used for parsing the status description to `statusDescription`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 705 | if (internal_set_status_description_key_name(amqp_management, "statusDescription") != 0) |
AzureIoTClient | 6:641a9672db08 | 706 | { |
AzureIoTClient | 39:e7c983378f41 | 707 | LogError("Cannot set status description key name"); |
AzureIoTClient | 6:641a9672db08 | 708 | } |
AzureIoTClient | 6:641a9672db08 | 709 | else |
AzureIoTClient | 6:641a9672db08 | 710 | { |
AzureIoTClient | 39:e7c983378f41 | 711 | /* Codes_SRS_AMQP_MANAGEMENT_01_010: [ The `source` argument shall be a value created by calling `messaging_create_source` with `management_node` as argument. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 712 | AMQP_VALUE source = messaging_create_source(management_node); |
AzureIoTClient | 39:e7c983378f41 | 713 | if (source == NULL) |
AzureIoTClient | 6:641a9672db08 | 714 | { |
AzureIoTClient | 39:e7c983378f41 | 715 | /* Codes_SRS_AMQP_MANAGEMENT_01_012: [ If `messaging_create_source` fails then `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 716 | LogError("Failed creating source AMQP value"); |
AzureIoTClient | 6:641a9672db08 | 717 | } |
AzureIoTClient | 6:641a9672db08 | 718 | else |
AzureIoTClient | 6:641a9672db08 | 719 | { |
AzureIoTClient | 39:e7c983378f41 | 720 | /* Codes_SRS_AMQP_MANAGEMENT_01_011: [ The `target` argument shall be a value created by calling `messaging_create_target` with `management_node` as argument. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 721 | AMQP_VALUE target = messaging_create_target(management_node); |
AzureIoTClient | 39:e7c983378f41 | 722 | if (target == NULL) |
AzureIoTClient | 6:641a9672db08 | 723 | { |
AzureIoTClient | 39:e7c983378f41 | 724 | /* Codes_SRS_AMQP_MANAGEMENT_01_013: [ If `messaging_create_target` fails then `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 725 | LogError("Failed creating target AMQP value"); |
AzureIoTClient | 6:641a9672db08 | 726 | } |
AzureIoTClient | 6:641a9672db08 | 727 | else |
AzureIoTClient | 6:641a9672db08 | 728 | { |
AzureIoTClient | 39:e7c983378f41 | 729 | size_t management_node_length = strlen(management_node); |
AzureIoTClient | 23:1111ee8bcba4 | 730 | |
AzureIoTClient | 39:e7c983378f41 | 731 | char* sender_link_name = (char*)malloc(management_node_length + COUNT_CHARS(sender_suffix) + 1); |
AzureIoTClient | 39:e7c983378f41 | 732 | if (sender_link_name == NULL) |
AzureIoTClient | 6:641a9672db08 | 733 | { |
AzureIoTClient | 39:e7c983378f41 | 734 | /* Codes_SRS_AMQP_MANAGEMENT_01_033: [ If any other error occurs `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 735 | LogError("Failed allocating memory for sender link name"); |
AzureIoTClient | 6:641a9672db08 | 736 | } |
AzureIoTClient | 6:641a9672db08 | 737 | else |
AzureIoTClient | 6:641a9672db08 | 738 | { |
AzureIoTClient | 39:e7c983378f41 | 739 | char* receiver_link_name; |
AzureIoTClient | 39:e7c983378f41 | 740 | |
AzureIoTClient | 39:e7c983378f41 | 741 | (void)memcpy(sender_link_name, management_node, management_node_length); |
AzureIoTClient | 39:e7c983378f41 | 742 | (void)memcpy(sender_link_name + management_node_length, sender_suffix, COUNT_CHARS(sender_suffix) + 1); |
AzureIoTClient | 39:e7c983378f41 | 743 | |
AzureIoTClient | 39:e7c983378f41 | 744 | receiver_link_name = (char*)malloc(management_node_length + COUNT_CHARS(receiver_suffix) + 1); |
AzureIoTClient | 39:e7c983378f41 | 745 | if (receiver_link_name == NULL) |
AzureIoTClient | 6:641a9672db08 | 746 | { |
AzureIoTClient | 39:e7c983378f41 | 747 | /* Codes_SRS_AMQP_MANAGEMENT_01_033: [ If any other error occurs `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 748 | LogError("Failed allocating memory for receiver link name"); |
AzureIoTClient | 6:641a9672db08 | 749 | } |
AzureIoTClient | 6:641a9672db08 | 750 | else |
AzureIoTClient | 6:641a9672db08 | 751 | { |
AzureIoTClient | 39:e7c983378f41 | 752 | (void)memcpy(receiver_link_name, management_node, management_node_length); |
AzureIoTClient | 39:e7c983378f41 | 753 | (void)memcpy(receiver_link_name + management_node_length, receiver_suffix, COUNT_CHARS(receiver_suffix) + 1); |
AzureIoTClient | 39:e7c983378f41 | 754 | |
AzureIoTClient | 39:e7c983378f41 | 755 | /* Codes_SRS_AMQP_MANAGEMENT_01_006: [ `amqp_management_create` shall create a sender link by calling `link_create`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 756 | /* Codes_SRS_AMQP_MANAGEMENT_01_007: [ The `session` argument shall be set to `session`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 757 | /* Codes_SRS_AMQP_MANAGEMENT_01_008: [ The `name` argument shall be constructed by concatenating the `management_node` value with `-sender`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 758 | /* Codes_SRS_AMQP_MANAGEMENT_01_009: [ The `role` argument shall be `role_sender`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 759 | /* Codes_SRS_AMQP_MANAGEMENT_01_019: [ The `source` argument shall be the value created by calling `messaging_create_source`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 760 | /* Codes_SRS_AMQP_MANAGEMENT_01_020: [ The `target` argument shall be the value created by calling `messaging_create_target`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 761 | amqp_management->sender_link = link_create(session, sender_link_name, role_sender, source, target); |
AzureIoTClient | 39:e7c983378f41 | 762 | if (amqp_management->sender_link == NULL) |
AzureIoTClient | 6:641a9672db08 | 763 | { |
AzureIoTClient | 39:e7c983378f41 | 764 | /* Codes_SRS_AMQP_MANAGEMENT_01_014: [ If `link_create` fails when creating the sender link then `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 765 | LogError("Failed creating sender link"); |
AzureIoTClient | 6:641a9672db08 | 766 | } |
AzureIoTClient | 6:641a9672db08 | 767 | else |
AzureIoTClient | 6:641a9672db08 | 768 | { |
AzureIoTClient | 39:e7c983378f41 | 769 | /* Codes_SRS_AMQP_MANAGEMENT_01_015: [ `amqp_management_create` shall create a receiver link by calling `link_create`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 770 | /* Codes_SRS_AMQP_MANAGEMENT_01_016: [ The `session` argument shall be set to `session`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 771 | /* Codes_SRS_AMQP_MANAGEMENT_01_017: [ The `name` argument shall be constructed by concatenating the `management_node` value with `-receiver`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 772 | /* Codes_SRS_AMQP_MANAGEMENT_01_018: [ The `role` argument shall be `role_receiver`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 773 | /* Codes_SRS_AMQP_MANAGEMENT_01_019: [ The `source` argument shall be the value created by calling `messaging_create_source`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 774 | /* Codes_SRS_AMQP_MANAGEMENT_01_020: [ The `target` argument shall be the value created by calling `messaging_create_target`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 775 | amqp_management->receiver_link = link_create(session, receiver_link_name, role_receiver, source, target); |
AzureIoTClient | 39:e7c983378f41 | 776 | if (amqp_management->receiver_link == NULL) |
AzureIoTClient | 6:641a9672db08 | 777 | { |
AzureIoTClient | 39:e7c983378f41 | 778 | /* Codes_SRS_AMQP_MANAGEMENT_01_021: [ If `link_create` fails when creating the receiver link then `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 779 | LogError("Failed creating receiver link"); |
AzureIoTClient | 6:641a9672db08 | 780 | } |
AzureIoTClient | 6:641a9672db08 | 781 | else |
AzureIoTClient | 6:641a9672db08 | 782 | { |
AzureIoTClient | 39:e7c983378f41 | 783 | /* Codes_SRS_AMQP_MANAGEMENT_01_022: [ `amqp_management_create` shall create a message sender by calling `messagesender_create` and passing to it the sender link handle. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 784 | amqp_management->message_sender = messagesender_create(amqp_management->sender_link, on_message_sender_state_changed, amqp_management); |
AzureIoTClient | 39:e7c983378f41 | 785 | if (amqp_management->message_sender == NULL) |
AzureIoTClient | 39:e7c983378f41 | 786 | { |
AzureIoTClient | 39:e7c983378f41 | 787 | /* Codes_SRS_AMQP_MANAGEMENT_01_031: [ If `messagesender_create` fails then `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 788 | LogError("Failed creating message sender"); |
AzureIoTClient | 39:e7c983378f41 | 789 | } |
AzureIoTClient | 39:e7c983378f41 | 790 | else |
AzureIoTClient | 39:e7c983378f41 | 791 | { |
AzureIoTClient | 39:e7c983378f41 | 792 | /* Codes_SRS_AMQP_MANAGEMENT_01_023: [ `amqp_management_create` shall create a message receiver by calling `messagereceiver_create` and passing to it the receiver link handle. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 793 | amqp_management->message_receiver = messagereceiver_create(amqp_management->receiver_link, on_message_receiver_state_changed, amqp_management); |
AzureIoTClient | 39:e7c983378f41 | 794 | if (amqp_management->message_receiver == NULL) |
AzureIoTClient | 39:e7c983378f41 | 795 | { |
AzureIoTClient | 39:e7c983378f41 | 796 | /* Codes_SRS_AMQP_MANAGEMENT_01_032: [ If `messagereceiver_create` fails then `amqp_management_create` shall fail and return NULL. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 797 | LogError("Failed creating message receiver"); |
AzureIoTClient | 39:e7c983378f41 | 798 | link_destroy(amqp_management->receiver_link); |
AzureIoTClient | 39:e7c983378f41 | 799 | } |
AzureIoTClient | 39:e7c983378f41 | 800 | else |
AzureIoTClient | 39:e7c983378f41 | 801 | { |
AzureIoTClient | 39:e7c983378f41 | 802 | free(receiver_link_name); |
AzureIoTClient | 39:e7c983378f41 | 803 | free(sender_link_name); |
AzureIoTClient | 39:e7c983378f41 | 804 | amqpvalue_destroy(target); |
AzureIoTClient | 39:e7c983378f41 | 805 | amqpvalue_destroy(source); |
AzureIoTClient | 39:e7c983378f41 | 806 | |
AzureIoTClient | 39:e7c983378f41 | 807 | /* Codes_SRS_AMQP_MANAGEMENT_01_106: [ The message Id set on the message properties shall start at 0. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 808 | amqp_management->next_message_id = 0; |
AzureIoTClient | 39:e7c983378f41 | 809 | |
AzureIoTClient | 39:e7c983378f41 | 810 | goto all_ok; |
AzureIoTClient | 39:e7c983378f41 | 811 | } |
AzureIoTClient | 39:e7c983378f41 | 812 | |
AzureIoTClient | 39:e7c983378f41 | 813 | messagesender_destroy(amqp_management->message_sender); |
AzureIoTClient | 39:e7c983378f41 | 814 | } |
AzureIoTClient | 39:e7c983378f41 | 815 | |
AzureIoTClient | 39:e7c983378f41 | 816 | link_destroy(amqp_management->receiver_link); |
AzureIoTClient | 6:641a9672db08 | 817 | } |
AzureIoTClient | 39:e7c983378f41 | 818 | |
AzureIoTClient | 39:e7c983378f41 | 819 | link_destroy(amqp_management->sender_link); |
AzureIoTClient | 6:641a9672db08 | 820 | } |
AzureIoTClient | 39:e7c983378f41 | 821 | |
AzureIoTClient | 39:e7c983378f41 | 822 | free(receiver_link_name); |
AzureIoTClient | 6:641a9672db08 | 823 | } |
AzureIoTClient | 39:e7c983378f41 | 824 | |
AzureIoTClient | 39:e7c983378f41 | 825 | free(sender_link_name); |
AzureIoTClient | 6:641a9672db08 | 826 | } |
AzureIoTClient | 23:1111ee8bcba4 | 827 | |
AzureIoTClient | 39:e7c983378f41 | 828 | amqpvalue_destroy(target); |
AzureIoTClient | 6:641a9672db08 | 829 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 830 | |
AzureIoTClient | 39:e7c983378f41 | 831 | amqpvalue_destroy(source); |
AzureIoTClient | 6:641a9672db08 | 832 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 833 | |
AzureIoTClient | 39:e7c983378f41 | 834 | free(amqp_management->status_description_key_name); |
AzureIoTClient | 6:641a9672db08 | 835 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 836 | |
AzureIoTClient | 39:e7c983378f41 | 837 | free(amqp_management->status_code_key_name); |
AzureIoTClient | 6:641a9672db08 | 838 | } |
AzureIoTClient | 39:e7c983378f41 | 839 | |
AzureIoTClient | 39:e7c983378f41 | 840 | singlylinkedlist_destroy(amqp_management->pending_operations); |
AzureIoTClient | 6:641a9672db08 | 841 | } |
AzureIoTClient | 39:e7c983378f41 | 842 | |
AzureIoTClient | 39:e7c983378f41 | 843 | free(amqp_management); |
AzureIoTClient | 39:e7c983378f41 | 844 | amqp_management = NULL; |
AzureIoTClient | 6:641a9672db08 | 845 | } |
AzureIoTClient | 6:641a9672db08 | 846 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 847 | |
AzureIoTClient | 39:e7c983378f41 | 848 | all_ok: |
AzureIoTClient | 39:e7c983378f41 | 849 | return amqp_management; |
Azure.IoT Build | 0:6ae2f7bca550 | 850 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 851 | |
AzureIoTClient | 22:524bded3f7a8 | 852 | void amqp_management_destroy(AMQP_MANAGEMENT_HANDLE amqp_management) |
Azure.IoT Build | 0:6ae2f7bca550 | 853 | { |
AzureIoTClient | 23:1111ee8bcba4 | 854 | if (amqp_management == NULL) |
AzureIoTClient | 6:641a9672db08 | 855 | { |
AzureIoTClient | 23:1111ee8bcba4 | 856 | /* Codes_SRS_AMQP_MANAGEMENT_01_025: [ If `amqp_management` is NULL, `amqp_management_destroy` shall do nothing. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 857 | LogError("NULL amqp_management"); |
AzureIoTClient | 23:1111ee8bcba4 | 858 | } |
AzureIoTClient | 23:1111ee8bcba4 | 859 | else |
AzureIoTClient | 23:1111ee8bcba4 | 860 | { |
AzureIoTClient | 23:1111ee8bcba4 | 861 | /* Codes_SRS_AMQP_MANAGEMENT_01_024: [ `amqp_management_destroy` shall free all the resources allocated by `amqp_management_create`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 862 | if (amqp_management->amqp_management_state != AMQP_MANAGEMENT_STATE_IDLE) |
AzureIoTClient | 6:641a9672db08 | 863 | { |
AzureIoTClient | 23:1111ee8bcba4 | 864 | (void)amqp_management_close(amqp_management); |
AzureIoTClient | 6:641a9672db08 | 865 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 866 | |
AzureIoTClient | 23:1111ee8bcba4 | 867 | /* Codes_SRS_AMQP_MANAGEMENT_01_028: [ `amqp_management_destroy` shall free the message sender by calling `messagesender_destroy`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 868 | messagesender_destroy(amqp_management->message_sender); |
AzureIoTClient | 23:1111ee8bcba4 | 869 | /* Codes_SRS_AMQP_MANAGEMENT_01_029: [ `amqp_management_destroy` shall free the message receiver by calling `messagereceiver_destroy`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 870 | messagereceiver_destroy(amqp_management->message_receiver); |
AzureIoTClient | 23:1111ee8bcba4 | 871 | /* Codes_SRS_AMQP_MANAGEMENT_01_027: [ `amqp_management_destroy` shall free the sender and receiver links by calling `link_destroy`. ]*/ |
AzureIoTClient | 6:641a9672db08 | 872 | link_destroy(amqp_management->sender_link); |
AzureIoTClient | 6:641a9672db08 | 873 | link_destroy(amqp_management->receiver_link); |
AzureIoTClient | 39:e7c983378f41 | 874 | free(amqp_management->status_code_key_name); |
AzureIoTClient | 39:e7c983378f41 | 875 | free(amqp_management->status_description_key_name); |
AzureIoTClient | 23:1111ee8bcba4 | 876 | /* Codes_SRS_AMQP_MANAGEMENT_01_026: [ `amqp_management_destroy` shall free the singly linked list by calling `singlylinkedlist_destroy`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 877 | singlylinkedlist_destroy(amqp_management->pending_operations); |
AzureIoTClient | 21:f9c433d8e6ca | 878 | free(amqp_management); |
AzureIoTClient | 6:641a9672db08 | 879 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 880 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 881 | |
AzureIoTClient | 22:524bded3f7a8 | 882 | int amqp_management_open_async(AMQP_MANAGEMENT_HANDLE amqp_management, ON_AMQP_MANAGEMENT_OPEN_COMPLETE on_amqp_management_open_complete, void* on_amqp_management_open_complete_context, ON_AMQP_MANAGEMENT_ERROR on_amqp_management_error, void* on_amqp_management_error_context) |
Azure.IoT Build | 0:6ae2f7bca550 | 883 | { |
AzureIoTClient | 6:641a9672db08 | 884 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 885 | |
AzureIoTClient | 23:1111ee8bcba4 | 886 | /* Codes_SRS_AMQP_MANAGEMENT_01_044: [ `on_amqp_management_open_complete_context` and `on_amqp_management_error_context` shall be allowed to be NULL. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 887 | if ((amqp_management == NULL) || |
AzureIoTClient | 23:1111ee8bcba4 | 888 | (on_amqp_management_open_complete == NULL) || |
AzureIoTClient | 23:1111ee8bcba4 | 889 | (on_amqp_management_error == NULL)) |
AzureIoTClient | 6:641a9672db08 | 890 | { |
AzureIoTClient | 23:1111ee8bcba4 | 891 | /* Codes_SRS_AMQP_MANAGEMENT_01_038: [ If `amqp_management`, `on_amqp_management_open_complete` or `on_amqp_management_error` is NULL, `amqp_management_open_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 892 | LogError("Bad arguments: amqp_management = %p, on_amqp_management_open_complete = %p, on_amqp_management_error = %p", |
AzureIoTClient | 23:1111ee8bcba4 | 893 | amqp_management, |
AzureIoTClient | 23:1111ee8bcba4 | 894 | on_amqp_management_open_complete, |
AzureIoTClient | 23:1111ee8bcba4 | 895 | on_amqp_management_error); |
AzureIoTClient | 23:1111ee8bcba4 | 896 | result = __FAILURE__; |
AzureIoTClient | 23:1111ee8bcba4 | 897 | } |
AzureIoTClient | 23:1111ee8bcba4 | 898 | else if (amqp_management->amqp_management_state != AMQP_MANAGEMENT_STATE_IDLE) |
AzureIoTClient | 23:1111ee8bcba4 | 899 | { |
AzureIoTClient | 23:1111ee8bcba4 | 900 | /* Codes_SRS_AMQP_MANAGEMENT_01_043: [ If the AMQP management instance is already OPEN or OPENING, `amqp_management_open_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 901 | LogError("AMQP management instance already OPEN"); |
AzureIoTClient | 19:000ab4e6a2c1 | 902 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 903 | } |
AzureIoTClient | 6:641a9672db08 | 904 | else |
AzureIoTClient | 6:641a9672db08 | 905 | { |
AzureIoTClient | 23:1111ee8bcba4 | 906 | /* Codes_SRS_AMQP_MANAGEMENT_01_036: [ `amqp_management_open_async` shall start opening the AMQP management instance and save the callbacks so that they can be called when opening is complete. ]*/ |
AzureIoTClient | 22:524bded3f7a8 | 907 | amqp_management->on_amqp_management_open_complete = on_amqp_management_open_complete; |
AzureIoTClient | 22:524bded3f7a8 | 908 | amqp_management->on_amqp_management_open_complete_context = on_amqp_management_open_complete_context; |
AzureIoTClient | 22:524bded3f7a8 | 909 | amqp_management->on_amqp_management_error = on_amqp_management_error; |
AzureIoTClient | 22:524bded3f7a8 | 910 | amqp_management->on_amqp_management_error_context = on_amqp_management_error_context; |
AzureIoTClient | 22:524bded3f7a8 | 911 | amqp_management->amqp_management_state = AMQP_MANAGEMENT_STATE_OPENING; |
AzureIoTClient | 22:524bded3f7a8 | 912 | |
AzureIoTClient | 23:1111ee8bcba4 | 913 | /* Codes_SRS_AMQP_MANAGEMENT_01_040: [ `amqp_management_open_async` shall open the message receiver by calling `messagereceiver_open`. ]*/ |
AzureIoTClient | 6:641a9672db08 | 914 | if (messagereceiver_open(amqp_management->message_receiver, on_message_received, amqp_management) != 0) |
AzureIoTClient | 6:641a9672db08 | 915 | { |
AzureIoTClient | 23:1111ee8bcba4 | 916 | /* Codes_SRS_AMQP_MANAGEMENT_01_042: [ If `messagereceiver_open` fails, `amqp_management_open_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 917 | LogError("Failed opening message receiver"); |
AzureIoTClient | 22:524bded3f7a8 | 918 | amqp_management->amqp_management_state = AMQP_MANAGEMENT_STATE_IDLE; |
AzureIoTClient | 19:000ab4e6a2c1 | 919 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 920 | } |
AzureIoTClient | 6:641a9672db08 | 921 | else |
AzureIoTClient | 6:641a9672db08 | 922 | { |
AzureIoTClient | 23:1111ee8bcba4 | 923 | /* Codes_SRS_AMQP_MANAGEMENT_01_039: [ `amqp_management_open_async` shall open the message sender by calling `messagesender_open`. ]*/ |
AzureIoTClient | 6:641a9672db08 | 924 | if (messagesender_open(amqp_management->message_sender) != 0) |
AzureIoTClient | 6:641a9672db08 | 925 | { |
AzureIoTClient | 23:1111ee8bcba4 | 926 | /* Codes_SRS_AMQP_MANAGEMENT_01_041: [ If `messagesender_open` fails, `amqp_management_open_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 927 | LogError("Failed opening message sender"); |
AzureIoTClient | 22:524bded3f7a8 | 928 | amqp_management->amqp_management_state = AMQP_MANAGEMENT_STATE_IDLE; |
AzureIoTClient | 23:1111ee8bcba4 | 929 | (void)messagereceiver_close(amqp_management->message_receiver); |
AzureIoTClient | 19:000ab4e6a2c1 | 930 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 931 | } |
AzureIoTClient | 6:641a9672db08 | 932 | else |
AzureIoTClient | 6:641a9672db08 | 933 | { |
AzureIoTClient | 23:1111ee8bcba4 | 934 | /* Codes_SRS_AMQP_MANAGEMENT_01_037: [ On success it shall return 0. ]*/ |
AzureIoTClient | 6:641a9672db08 | 935 | result = 0; |
AzureIoTClient | 6:641a9672db08 | 936 | } |
AzureIoTClient | 6:641a9672db08 | 937 | } |
AzureIoTClient | 6:641a9672db08 | 938 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 939 | |
AzureIoTClient | 6:641a9672db08 | 940 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 941 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 942 | |
AzureIoTClient | 22:524bded3f7a8 | 943 | int amqp_management_close(AMQP_MANAGEMENT_HANDLE amqp_management) |
Azure.IoT Build | 0:6ae2f7bca550 | 944 | { |
AzureIoTClient | 6:641a9672db08 | 945 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 946 | |
AzureIoTClient | 6:641a9672db08 | 947 | if (amqp_management == NULL) |
AzureIoTClient | 6:641a9672db08 | 948 | { |
AzureIoTClient | 23:1111ee8bcba4 | 949 | /* Codes_SRS_AMQP_MANAGEMENT_01_047: [ If `amqp_management` is NULL, `amqp_management_close` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 950 | LogError("NULL amqp_management"); |
AzureIoTClient | 23:1111ee8bcba4 | 951 | result = __FAILURE__; |
AzureIoTClient | 23:1111ee8bcba4 | 952 | } |
AzureIoTClient | 23:1111ee8bcba4 | 953 | else if (amqp_management->amqp_management_state == AMQP_MANAGEMENT_STATE_IDLE) |
AzureIoTClient | 23:1111ee8bcba4 | 954 | { |
AzureIoTClient | 23:1111ee8bcba4 | 955 | /* Codes_SRS_AMQP_MANAGEMENT_01_049: [ `amqp_management_close` on an AMQP management instance that is not OPEN, shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 956 | LogError("AMQP management instance not open"); |
AzureIoTClient | 19:000ab4e6a2c1 | 957 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 958 | } |
AzureIoTClient | 6:641a9672db08 | 959 | else |
AzureIoTClient | 6:641a9672db08 | 960 | { |
AzureIoTClient | 23:1111ee8bcba4 | 961 | /* Codes_SRS_AMQP_MANAGEMENT_01_045: [ `amqp_management_close` shall close the AMQP management instance. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 962 | /* Codes_SRS_AMQP_MANAGEMENT_01_050: [ `amqp_management_close` shall close the message sender by calling `messagesender_close`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 963 | if (messagesender_close(amqp_management->message_sender) != 0) |
AzureIoTClient | 6:641a9672db08 | 964 | { |
AzureIoTClient | 23:1111ee8bcba4 | 965 | /* Codes_SRS_AMQP_MANAGEMENT_01_052: [ If `messagesender_close` fails, `amqp_management_close` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 966 | LogError("messagesender_close failed"); |
AzureIoTClient | 23:1111ee8bcba4 | 967 | result = __FAILURE__; |
AzureIoTClient | 23:1111ee8bcba4 | 968 | } |
AzureIoTClient | 23:1111ee8bcba4 | 969 | /* Codes_SRS_AMQP_MANAGEMENT_01_051: [ `amqp_management_close` shall close the message receiver by calling `messagereceiver_close`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 970 | else if (messagereceiver_close(amqp_management->message_receiver) != 0) |
AzureIoTClient | 23:1111ee8bcba4 | 971 | { |
AzureIoTClient | 23:1111ee8bcba4 | 972 | /* Codes_SRS_AMQP_MANAGEMENT_01_053: [ If `messagereceiver_close` fails, `amqp_management_close` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 973 | LogError("messagereceiver_close failed"); |
AzureIoTClient | 19:000ab4e6a2c1 | 974 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 975 | } |
AzureIoTClient | 6:641a9672db08 | 976 | else |
AzureIoTClient | 6:641a9672db08 | 977 | { |
AzureIoTClient | 23:1111ee8bcba4 | 978 | LIST_ITEM_HANDLE list_item_handle = singlylinkedlist_get_head_item(amqp_management->pending_operations); |
AzureIoTClient | 23:1111ee8bcba4 | 979 | while (list_item_handle != NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 980 | { |
AzureIoTClient | 23:1111ee8bcba4 | 981 | OPERATION_MESSAGE_INSTANCE* operation_message = (OPERATION_MESSAGE_INSTANCE*)singlylinkedlist_item_get_value(list_item_handle); |
AzureIoTClient | 23:1111ee8bcba4 | 982 | if (operation_message == NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 983 | { |
AzureIoTClient | 23:1111ee8bcba4 | 984 | LogError("Cannot obtain pending operation"); |
AzureIoTClient | 23:1111ee8bcba4 | 985 | } |
AzureIoTClient | 23:1111ee8bcba4 | 986 | else |
AzureIoTClient | 23:1111ee8bcba4 | 987 | { |
AzureIoTClient | 23:1111ee8bcba4 | 988 | /* Codes_SRS_AMQP_MANAGEMENT_01_054: [ All pending operations shall be indicated complete with the code `AMQP_MANAGEMENT_EXECUTE_OPERATION_INSTANCE_CLOSED`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 989 | operation_message->on_execute_operation_complete(operation_message->callback_context, AMQP_MANAGEMENT_EXECUTE_OPERATION_INSTANCE_CLOSED, 0, NULL, NULL); |
AzureIoTClient | 23:1111ee8bcba4 | 990 | free(operation_message); |
AzureIoTClient | 23:1111ee8bcba4 | 991 | } |
AzureIoTClient | 23:1111ee8bcba4 | 992 | |
AzureIoTClient | 23:1111ee8bcba4 | 993 | if (singlylinkedlist_remove(amqp_management->pending_operations, list_item_handle) != 0) |
AzureIoTClient | 23:1111ee8bcba4 | 994 | { |
AzureIoTClient | 23:1111ee8bcba4 | 995 | LogError("Cannot remove item"); |
AzureIoTClient | 23:1111ee8bcba4 | 996 | } |
AzureIoTClient | 23:1111ee8bcba4 | 997 | |
AzureIoTClient | 23:1111ee8bcba4 | 998 | list_item_handle = singlylinkedlist_get_head_item(amqp_management->pending_operations); |
AzureIoTClient | 23:1111ee8bcba4 | 999 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1000 | |
AzureIoTClient | 23:1111ee8bcba4 | 1001 | if (amqp_management->amqp_management_state == AMQP_MANAGEMENT_STATE_OPENING) |
AzureIoTClient | 23:1111ee8bcba4 | 1002 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1003 | /* Codes_SRS_AMQP_MANAGEMENT_01_048: [ `amqp_management_close` on an AMQP management instance that is OPENING shall trigger the `on_amqp_management_open_complete` callback with `AMQP_MANAGEMENT_OPEN_CANCELLED`, while also passing the context passed in `amqp_management_open_async`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1004 | amqp_management->on_amqp_management_open_complete(amqp_management->on_amqp_management_open_complete_context, AMQP_MANAGEMENT_OPEN_CANCELLED); |
AzureIoTClient | 23:1111ee8bcba4 | 1005 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1006 | |
AzureIoTClient | 22:524bded3f7a8 | 1007 | amqp_management->amqp_management_state = AMQP_MANAGEMENT_STATE_IDLE; |
AzureIoTClient | 23:1111ee8bcba4 | 1008 | |
AzureIoTClient | 23:1111ee8bcba4 | 1009 | /* Codes_SRS_AMQP_MANAGEMENT_01_046: [ On success it shall return 0. ]*/ |
AzureIoTClient | 6:641a9672db08 | 1010 | result = 0; |
AzureIoTClient | 6:641a9672db08 | 1011 | } |
AzureIoTClient | 6:641a9672db08 | 1012 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1013 | |
AzureIoTClient | 6:641a9672db08 | 1014 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 1015 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1016 | |
AzureIoTClient | 22:524bded3f7a8 | 1017 | int amqp_management_execute_operation_async(AMQP_MANAGEMENT_HANDLE amqp_management, const char* operation, const char* type, const char* locales, MESSAGE_HANDLE message, ON_AMQP_MANAGEMENT_EXECUTE_OPERATION_COMPLETE on_execute_operation_complete, void* on_execute_operation_complete_context) |
Azure.IoT Build | 0:6ae2f7bca550 | 1018 | { |
AzureIoTClient | 6:641a9672db08 | 1019 | int result; |
AzureIoTClient | 6:641a9672db08 | 1020 | |
AzureIoTClient | 6:641a9672db08 | 1021 | if ((amqp_management == NULL) || |
AzureIoTClient | 23:1111ee8bcba4 | 1022 | (operation == NULL) || |
AzureIoTClient | 23:1111ee8bcba4 | 1023 | (type == NULL) || |
AzureIoTClient | 23:1111ee8bcba4 | 1024 | (on_execute_operation_complete == NULL)) |
AzureIoTClient | 6:641a9672db08 | 1025 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1026 | /* Codes_SRS_AMQP_MANAGEMENT_01_057: [ If `amqp_management`, `operation`, `type` or `on_execute_operation_complete` is NULL, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1027 | LogError("Bad arguments: amqp_management = %p, operation = %p, type = %p", |
AzureIoTClient | 23:1111ee8bcba4 | 1028 | amqp_management, operation, type); |
AzureIoTClient | 23:1111ee8bcba4 | 1029 | result = __FAILURE__; |
AzureIoTClient | 23:1111ee8bcba4 | 1030 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1031 | /* Codes_SRS_AMQP_MANAGEMENT_01_081: [ If `amqp_management_execute_operation_async` is called when not OPEN, it shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1032 | else if ((amqp_management->amqp_management_state == AMQP_MANAGEMENT_STATE_IDLE) || |
AzureIoTClient | 23:1111ee8bcba4 | 1033 | /* Codes_SRS_AMQP_MANAGEMENT_01_104: [ If `amqp_management_execute_operation_async` is called when the AMQP management is in error, it shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1034 | (amqp_management->amqp_management_state == AMQP_MANAGEMENT_STATE_ERROR)) |
AzureIoTClient | 23:1111ee8bcba4 | 1035 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1036 | LogError("amqp_management_execute_operation_async called while not open or in error"); |
AzureIoTClient | 19:000ab4e6a2c1 | 1037 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 1038 | } |
AzureIoTClient | 6:641a9672db08 | 1039 | else |
AzureIoTClient | 6:641a9672db08 | 1040 | { |
AzureIoTClient | 6:641a9672db08 | 1041 | AMQP_VALUE application_properties; |
AzureIoTClient | 23:1111ee8bcba4 | 1042 | MESSAGE_HANDLE cloned_message; |
AzureIoTClient | 23:1111ee8bcba4 | 1043 | |
AzureIoTClient | 23:1111ee8bcba4 | 1044 | if (message == NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 1045 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1046 | /* Codes_SRS_AMQP_MANAGEMENT_01_102: [ If `message` is NULL, a new message shall be created by calling `message_create`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1047 | cloned_message = message_create(); |
AzureIoTClient | 23:1111ee8bcba4 | 1048 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1049 | else |
AzureIoTClient | 23:1111ee8bcba4 | 1050 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1051 | /* Codes_SRS_AMQP_MANAGEMENT_01_103: [ Otherwise the existing message shall be cloned by using `message_clone` before being modified accordingly and used for the pending operation. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1052 | cloned_message = message_clone(message); |
AzureIoTClient | 23:1111ee8bcba4 | 1053 | if (cloned_message == NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 1054 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1055 | LogError("Could not clone message"); |
AzureIoTClient | 23:1111ee8bcba4 | 1056 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1057 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1058 | |
AzureIoTClient | 23:1111ee8bcba4 | 1059 | if (cloned_message == NULL) |
AzureIoTClient | 6:641a9672db08 | 1060 | { |
AzureIoTClient | 19:000ab4e6a2c1 | 1061 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 1062 | } |
AzureIoTClient | 6:641a9672db08 | 1063 | else |
AzureIoTClient | 6:641a9672db08 | 1064 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1065 | /* Codes_SRS_AMQP_MANAGEMENT_01_055: [ `amqp_management_execute_operation_async` shall start an AMQP management operation. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1066 | /* Codes_SRS_AMQP_MANAGEMENT_01_082: [ `amqp_management_execute_operation_async` shall obtain the application properties from the message by calling `message_get_application_properties`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1067 | if (message_get_application_properties(cloned_message, &application_properties) != 0) |
AzureIoTClient | 6:641a9672db08 | 1068 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1069 | LogError("Could not get application properties"); |
AzureIoTClient | 19:000ab4e6a2c1 | 1070 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 1071 | } |
AzureIoTClient | 6:641a9672db08 | 1072 | else |
AzureIoTClient | 6:641a9672db08 | 1073 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1074 | if (application_properties == NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 1075 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1076 | /* Codes_SRS_AMQP_MANAGEMENT_01_083: [ If no application properties were set on the message, a new application properties instance shall be created by calling `amqpvalue_create_map`; ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1077 | application_properties = amqpvalue_create_map(); |
AzureIoTClient | 23:1111ee8bcba4 | 1078 | if (application_properties == NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 1079 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1080 | LogError("Could not create application properties"); |
AzureIoTClient | 23:1111ee8bcba4 | 1081 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1082 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1083 | |
AzureIoTClient | 23:1111ee8bcba4 | 1084 | if (application_properties == NULL) |
AzureIoTClient | 6:641a9672db08 | 1085 | { |
AzureIoTClient | 19:000ab4e6a2c1 | 1086 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 1087 | } |
AzureIoTClient | 6:641a9672db08 | 1088 | else |
AzureIoTClient | 6:641a9672db08 | 1089 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1090 | /* Codes_SRS_AMQP_MANAGEMENT_01_084: [ For each of the arguments `operation`, `type` and `locales` an AMQP value of type string shall be created by calling `amqpvalue_create_string` in order to be used as key in the application properties map. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1091 | /* Codes_SRS_AMQP_MANAGEMENT_01_085: [ For each of the arguments `operation`, `type` and `locales` an AMQP value of type string containing the argument value shall be created by calling `amqpvalue_create_string` in order to be used as value in the application properties map. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1092 | /* Codes_SRS_AMQP_MANAGEMENT_01_058: [ Request messages have the following application-properties: ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1093 | /* Codes_SRS_AMQP_MANAGEMENT_01_059: [ operation string Yes The management operation to be performed. ] */ |
AzureIoTClient | 23:1111ee8bcba4 | 1094 | if ((add_string_key_value_pair_to_map(application_properties, "operation", operation) != 0) || |
AzureIoTClient | 23:1111ee8bcba4 | 1095 | /* Codes_SRS_AMQP_MANAGEMENT_01_061: [ type string Yes The Manageable Entity Type of the Manageable Entity to be managed. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1096 | (add_string_key_value_pair_to_map(application_properties, "type", type) != 0) || |
AzureIoTClient | 23:1111ee8bcba4 | 1097 | /* Codes_SRS_AMQP_MANAGEMENT_01_093: [ If `locales` is NULL, no key/value pair shall be added for it in the application properties map. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1098 | /* Codes_SRS_AMQP_MANAGEMENT_01_063: [ locales string No A list of locales that the sending peer permits for incoming informational text in response messages. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1099 | ((locales != NULL) && (add_string_key_value_pair_to_map(application_properties, "locales", locales) != 0))) |
AzureIoTClient | 6:641a9672db08 | 1100 | { |
AzureIoTClient | 19:000ab4e6a2c1 | 1101 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 1102 | } |
AzureIoTClient | 6:641a9672db08 | 1103 | else |
AzureIoTClient | 6:641a9672db08 | 1104 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1105 | /* Codes_SRS_AMQP_MANAGEMENT_01_087: [ The application properties obtained after adding the key/value pairs shall be set on the message by calling `message_set_application_properties`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1106 | if (message_set_application_properties(cloned_message, application_properties) != 0) |
AzureIoTClient | 6:641a9672db08 | 1107 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1108 | /* Codes_SRS_AMQP_MANAGEMENT_01_090: [ If any APIs used to create and set the application properties on the message fails, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1109 | LogError("Could not set application properties"); |
AzureIoTClient | 23:1111ee8bcba4 | 1110 | result = __FAILURE__; |
AzureIoTClient | 23:1111ee8bcba4 | 1111 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1112 | else if (set_message_id(cloned_message, amqp_management->next_message_id) != 0) |
AzureIoTClient | 23:1111ee8bcba4 | 1113 | { |
AzureIoTClient | 19:000ab4e6a2c1 | 1114 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 1115 | } |
AzureIoTClient | 6:641a9672db08 | 1116 | else |
AzureIoTClient | 6:641a9672db08 | 1117 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1118 | OPERATION_MESSAGE_INSTANCE* pending_operation_message = (OPERATION_MESSAGE_INSTANCE*)malloc(sizeof(OPERATION_MESSAGE_INSTANCE)); |
AzureIoTClient | 23:1111ee8bcba4 | 1119 | if (pending_operation_message == NULL) |
AzureIoTClient | 6:641a9672db08 | 1120 | { |
AzureIoTClient | 19:000ab4e6a2c1 | 1121 | result = __FAILURE__; |
AzureIoTClient | 6:641a9672db08 | 1122 | } |
AzureIoTClient | 6:641a9672db08 | 1123 | else |
AzureIoTClient | 6:641a9672db08 | 1124 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1125 | LIST_ITEM_HANDLE added_item; |
AzureIoTClient | 23:1111ee8bcba4 | 1126 | pending_operation_message->callback_context = on_execute_operation_complete_context; |
AzureIoTClient | 23:1111ee8bcba4 | 1127 | pending_operation_message->on_execute_operation_complete = on_execute_operation_complete; |
AzureIoTClient | 23:1111ee8bcba4 | 1128 | pending_operation_message->message_id = amqp_management->next_message_id; |
AzureIoTClient | 23:1111ee8bcba4 | 1129 | |
AzureIoTClient | 23:1111ee8bcba4 | 1130 | /* Codes_SRS_AMQP_MANAGEMENT_01_091: [ Once the request message has been sent, an entry shall be stored in the pending operations list by calling `singlylinkedlist_add`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1131 | added_item = singlylinkedlist_add(amqp_management->pending_operations, pending_operation_message); |
AzureIoTClient | 23:1111ee8bcba4 | 1132 | if (added_item == NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 1133 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1134 | /* Codes_SRS_AMQP_MANAGEMENT_01_092: [ If `singlylinkedlist_add` fails then `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1135 | LogError("Could not add the operation to the pending operations list."); |
AzureIoTClient | 23:1111ee8bcba4 | 1136 | free(pending_operation_message); |
AzureIoTClient | 23:1111ee8bcba4 | 1137 | result = __FAILURE__; |
AzureIoTClient | 23:1111ee8bcba4 | 1138 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1139 | else |
AzureIoTClient | 23:1111ee8bcba4 | 1140 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1141 | /* Codes_SRS_AMQP_MANAGEMENT_01_088: [ `amqp_management_execute_operation_async` shall send the message by calling `messagesender_send`. ]*/ |
AzureIoTClient | 34:6be9c2058664 | 1142 | if (messagesender_send_async(amqp_management->message_sender, cloned_message, NULL, NULL, 0) == NULL) |
AzureIoTClient | 23:1111ee8bcba4 | 1143 | { |
AzureIoTClient | 34:6be9c2058664 | 1144 | /* Codes_SRS_AMQP_MANAGEMENT_01_089: [ If `messagesender_send_async` fails, `amqp_management_execute_operation_async` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1145 | LogError("Could not send request message"); |
AzureIoTClient | 23:1111ee8bcba4 | 1146 | (void)singlylinkedlist_remove(amqp_management->pending_operations, added_item); |
AzureIoTClient | 23:1111ee8bcba4 | 1147 | free(pending_operation_message); |
AzureIoTClient | 23:1111ee8bcba4 | 1148 | result = __FAILURE__; |
AzureIoTClient | 23:1111ee8bcba4 | 1149 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1150 | else |
AzureIoTClient | 23:1111ee8bcba4 | 1151 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1152 | /* Codes_SRS_AMQP_MANAGEMENT_01_107: [ The message Id set on the message properties shall be incremented with each operation. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1153 | amqp_management->next_message_id++; |
AzureIoTClient | 23:1111ee8bcba4 | 1154 | |
AzureIoTClient | 23:1111ee8bcba4 | 1155 | /* Codes_SRS_AMQP_MANAGEMENT_01_056: [ On success it shall return 0. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1156 | result = 0; |
AzureIoTClient | 23:1111ee8bcba4 | 1157 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1158 | } |
AzureIoTClient | 6:641a9672db08 | 1159 | } |
AzureIoTClient | 6:641a9672db08 | 1160 | } |
AzureIoTClient | 6:641a9672db08 | 1161 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1162 | |
AzureIoTClient | 23:1111ee8bcba4 | 1163 | /* Codes_SRS_AMQP_MANAGEMENT_01_101: [ After setting the application properties, the application properties instance shall be freed by `amqpvalue_destroy`. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1164 | amqpvalue_destroy(application_properties); |
AzureIoTClient | 6:641a9672db08 | 1165 | } |
AzureIoTClient | 6:641a9672db08 | 1166 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1167 | |
AzureIoTClient | 23:1111ee8bcba4 | 1168 | message_destroy(cloned_message); |
AzureIoTClient | 6:641a9672db08 | 1169 | } |
AzureIoTClient | 6:641a9672db08 | 1170 | } |
AzureIoTClient | 6:641a9672db08 | 1171 | return result; |
AzureIoTClient | 6:641a9672db08 | 1172 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1173 | |
AzureIoTClient | 23:1111ee8bcba4 | 1174 | void amqp_management_set_trace(AMQP_MANAGEMENT_HANDLE amqp_management, bool trace_on) |
AzureIoTClient | 6:641a9672db08 | 1175 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1176 | if (amqp_management == NULL) |
AzureIoTClient | 6:641a9672db08 | 1177 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1178 | /* Codes_SRS_AMQP_MANAGEMENT_01_163: [ If `amqp_management` is NULL, `amqp_management_set_trace` shal do nothing. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1179 | LogError("NULL amqp_management"); |
AzureIoTClient | 23:1111ee8bcba4 | 1180 | } |
AzureIoTClient | 23:1111ee8bcba4 | 1181 | else |
AzureIoTClient | 23:1111ee8bcba4 | 1182 | { |
AzureIoTClient | 23:1111ee8bcba4 | 1183 | /* Codes_SRS_AMQP_MANAGEMENT_01_161: [ `amqp_management_set_trace` shall call `messagesender_set_trace` to enable/disable tracing on the message sender. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1184 | messagesender_set_trace(amqp_management->message_sender, trace_on); |
AzureIoTClient | 23:1111ee8bcba4 | 1185 | /* Codes_SRS_AMQP_MANAGEMENT_01_162: [ `amqp_management_set_trace` shall call `messagereceiver_set_trace` to enable/disable tracing on the message receiver. ]*/ |
AzureIoTClient | 23:1111ee8bcba4 | 1186 | messagereceiver_set_trace(amqp_management->message_receiver, trace_on); |
AzureIoTClient | 6:641a9672db08 | 1187 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 1188 | } |
AzureIoTClient | 39:e7c983378f41 | 1189 | |
AzureIoTClient | 39:e7c983378f41 | 1190 | int amqp_management_set_override_status_code_key_name(AMQP_MANAGEMENT_HANDLE amqp_management, const char* override_status_code_key_name) |
AzureIoTClient | 39:e7c983378f41 | 1191 | { |
AzureIoTClient | 39:e7c983378f41 | 1192 | int result; |
AzureIoTClient | 39:e7c983378f41 | 1193 | |
AzureIoTClient | 39:e7c983378f41 | 1194 | /* Codes_SRS_AMQP_MANAGEMENT_01_171: [ If `amqp_management` is NULL, `amqp_management_set_override_status_code_key_name` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1195 | if ((amqp_management == NULL) || |
AzureIoTClient | 39:e7c983378f41 | 1196 | /* Codes_SRS_AMQP_MANAGEMENT_01_172: [ If `override_status_code_key_name` is NULL, `amqp_management_set_override_status_code_key_name` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1197 | (override_status_code_key_name == NULL)) |
AzureIoTClient | 39:e7c983378f41 | 1198 | { |
AzureIoTClient | 39:e7c983378f41 | 1199 | LogError("Bad arguments: amqp_management = %p, override_status_code_key_name = %s", |
AzureIoTClient | 39:e7c983378f41 | 1200 | amqp_management, P_OR_NULL(override_status_code_key_name)); |
AzureIoTClient | 39:e7c983378f41 | 1201 | result = __FAILURE__; |
AzureIoTClient | 39:e7c983378f41 | 1202 | } |
AzureIoTClient | 39:e7c983378f41 | 1203 | else |
AzureIoTClient | 39:e7c983378f41 | 1204 | { |
AzureIoTClient | 39:e7c983378f41 | 1205 | /* Codes_SRS_AMQP_MANAGEMENT_01_167: [ `amqp_management_set_override_status_code_key_name` shall set the status code key name used to parse the status code from the reply messages to `override_status_code_key_name`. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1206 | /* Codes_SRS_AMQP_MANAGEMENT_01_168: [ `amqp_management_set_override_status_code_key_name` shall copy the `override_status_code_key_name` string. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1207 | /* Codes_SRS_AMQP_MANAGEMENT_01_169: [ `amqp_management_set_override_status_code_key_name` shall free any string previously used for the status code key name. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1208 | if (internal_set_status_code_key_name(amqp_management, override_status_code_key_name) != 0) |
AzureIoTClient | 39:e7c983378f41 | 1209 | { |
AzureIoTClient | 39:e7c983378f41 | 1210 | /* Codes_SRS_AMQP_MANAGEMENT_01_173: [ If any error occurs in copying the `override_status_code_key_name` string, `amqp_management_set_override_status_code_key_name` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1211 | LogError("Cannot set status code key name"); |
AzureIoTClient | 39:e7c983378f41 | 1212 | result = __FAILURE__; |
AzureIoTClient | 39:e7c983378f41 | 1213 | } |
AzureIoTClient | 39:e7c983378f41 | 1214 | else |
AzureIoTClient | 39:e7c983378f41 | 1215 | { |
AzureIoTClient | 39:e7c983378f41 | 1216 | /* Codes_SRS_AMQP_MANAGEMENT_01_170: [ On success, `amqp_management_set_override_status_code_key_name` shall return 0. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1217 | result = 0; |
AzureIoTClient | 39:e7c983378f41 | 1218 | } |
AzureIoTClient | 39:e7c983378f41 | 1219 | } |
AzureIoTClient | 39:e7c983378f41 | 1220 | |
AzureIoTClient | 39:e7c983378f41 | 1221 | return result; |
AzureIoTClient | 39:e7c983378f41 | 1222 | } |
AzureIoTClient | 39:e7c983378f41 | 1223 | |
AzureIoTClient | 39:e7c983378f41 | 1224 | int amqp_management_set_override_status_description_key_name(AMQP_MANAGEMENT_HANDLE amqp_management, const char* override_status_description_key_name) |
AzureIoTClient | 39:e7c983378f41 | 1225 | { |
AzureIoTClient | 39:e7c983378f41 | 1226 | int result; |
AzureIoTClient | 39:e7c983378f41 | 1227 | |
AzureIoTClient | 39:e7c983378f41 | 1228 | /* Codes_SRS_AMQP_MANAGEMENT_01_178: [ If `amqp_management` is NULL, `amqp_management_set_override_status_description_key_name` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1229 | if ((amqp_management == NULL) || |
AzureIoTClient | 39:e7c983378f41 | 1230 | /* Tests_SRS_AMQP_MANAGEMENT_01_179: [ If `override_status_description_key_name` is NULL, `amqp_management_set_override_status_description_key_name` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1231 | (override_status_description_key_name == NULL)) |
AzureIoTClient | 39:e7c983378f41 | 1232 | { |
AzureIoTClient | 39:e7c983378f41 | 1233 | LogError("Bad arguments: amqp_management = %p, override_status_description_key_name = %s", |
AzureIoTClient | 39:e7c983378f41 | 1234 | amqp_management, P_OR_NULL(override_status_description_key_name)); |
AzureIoTClient | 39:e7c983378f41 | 1235 | result = __FAILURE__; |
AzureIoTClient | 39:e7c983378f41 | 1236 | } |
AzureIoTClient | 39:e7c983378f41 | 1237 | else |
AzureIoTClient | 39:e7c983378f41 | 1238 | { |
AzureIoTClient | 39:e7c983378f41 | 1239 | /* Codes_SRS_AMQP_MANAGEMENT_01_174: [ `amqp_management_set_override_status_description_key_name` shall set the status description key name used to parse the status description from the reply messages to `over ride_status_description_key_name`.]*/ |
AzureIoTClient | 39:e7c983378f41 | 1240 | /* Codes_SRS_AMQP_MANAGEMENT_01_175: [ `amqp_management_set_override_status_description_key_name` shall copy the `override_status_description_key_name` string. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1241 | /* Codes_SRS_AMQP_MANAGEMENT_01_176: [ `amqp_management_set_override_status_description_key_name` shall free any string previously used for the status description key name. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1242 | /* Codes_SRS_AMQP_MANAGEMENT_01_177: [ On success, `amqp_management_set_override_status_description_key_name` shall return 0. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1243 | if (internal_set_status_description_key_name(amqp_management, override_status_description_key_name) != 0) |
AzureIoTClient | 39:e7c983378f41 | 1244 | { |
AzureIoTClient | 39:e7c983378f41 | 1245 | /* Codes_SRS_AMQP_MANAGEMENT_01_180: [ If any error occurs in copying the `override_status_description_key_name` string, `amqp_management_set_override_status_description_key_name` shall fail and return a non-zero value. ]*/ |
AzureIoTClient | 39:e7c983378f41 | 1246 | LogError("Cannot set status description key name"); |
AzureIoTClient | 39:e7c983378f41 | 1247 | result = __FAILURE__; |
AzureIoTClient | 39:e7c983378f41 | 1248 | } |
AzureIoTClient | 39:e7c983378f41 | 1249 | else |
AzureIoTClient | 39:e7c983378f41 | 1250 | { |
AzureIoTClient | 39:e7c983378f41 | 1251 | result = 0; |
AzureIoTClient | 39:e7c983378f41 | 1252 | } |
AzureIoTClient | 39:e7c983378f41 | 1253 | } |
AzureIoTClient | 39:e7c983378f41 | 1254 | |
AzureIoTClient | 39:e7c983378f41 | 1255 | return result; |
AzureIoTClient | 39:e7c983378f41 | 1256 | } |