A small memory footprint AMQP implimentation
Dependents: iothub_client_sample_amqp remote_monitoring simplesample_amqp
cbs.c@0:6ae2f7bca550, 2016-04-08 (annotated)
- Committer:
- Azure.IoT Build
- Date:
- Fri Apr 08 12:01:10 2016 -0700
- Revision:
- 0:6ae2f7bca550
- Child:
- 5:ae49385aff34
1.0.4
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 | #ifdef _CRTDBG_MAP_ALLOC |
Azure.IoT Build | 0:6ae2f7bca550 | 6 | #include <crtdbg.h> |
Azure.IoT Build | 0:6ae2f7bca550 | 7 | #endif |
Azure.IoT Build | 0:6ae2f7bca550 | 8 | |
Azure.IoT Build | 0:6ae2f7bca550 | 9 | #include <stdio.h> |
Azure.IoT Build | 0:6ae2f7bca550 | 10 | #include <string.h> |
Azure.IoT Build | 0:6ae2f7bca550 | 11 | #include "azure_uamqp_c/cbs.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 12 | #include "azure_uamqp_c/amqp_management.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 13 | #include "azure_uamqp_c/amqpalloc.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 14 | #include "azure_uamqp_c/session.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 15 | #include "azure_uamqp_c/consolelogger.h" |
Azure.IoT Build | 0:6ae2f7bca550 | 16 | |
Azure.IoT Build | 0:6ae2f7bca550 | 17 | typedef struct CBS_INSTANCE_TAG |
Azure.IoT Build | 0:6ae2f7bca550 | 18 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 19 | AMQP_MANAGEMENT_HANDLE amqp_management; |
Azure.IoT Build | 0:6ae2f7bca550 | 20 | } CBS_INSTANCE; |
Azure.IoT Build | 0:6ae2f7bca550 | 21 | |
Azure.IoT Build | 0:6ae2f7bca550 | 22 | static int add_string_key_value_pair_to_map(AMQP_VALUE map, const char* key, const char* value) |
Azure.IoT Build | 0:6ae2f7bca550 | 23 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 24 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 25 | |
Azure.IoT Build | 0:6ae2f7bca550 | 26 | AMQP_VALUE key_value = amqpvalue_create_string(key); |
Azure.IoT Build | 0:6ae2f7bca550 | 27 | if (key == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 28 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 29 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 30 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 31 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 32 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 33 | AMQP_VALUE value_value = amqpvalue_create_string(value); |
Azure.IoT Build | 0:6ae2f7bca550 | 34 | if (value_value == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 35 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 36 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 37 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 38 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 39 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 40 | if (amqpvalue_set_map_value(map, key_value, value_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 41 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 42 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 43 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 44 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 45 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 46 | result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 47 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 48 | |
Azure.IoT Build | 0:6ae2f7bca550 | 49 | amqpvalue_destroy(key_value); |
Azure.IoT Build | 0:6ae2f7bca550 | 50 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 51 | |
Azure.IoT Build | 0:6ae2f7bca550 | 52 | amqpvalue_destroy(value_value); |
Azure.IoT Build | 0:6ae2f7bca550 | 53 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 54 | |
Azure.IoT Build | 0:6ae2f7bca550 | 55 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 56 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 57 | |
Azure.IoT Build | 0:6ae2f7bca550 | 58 | static int set_pending_operation_properties(MESSAGE_HANDLE message) |
Azure.IoT Build | 0:6ae2f7bca550 | 59 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 60 | int result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 61 | |
Azure.IoT Build | 0:6ae2f7bca550 | 62 | PROPERTIES_HANDLE properties = properties_create(); |
Azure.IoT Build | 0:6ae2f7bca550 | 63 | if (properties == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 64 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 65 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 66 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 67 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 68 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 69 | AMQP_VALUE reply_to = amqpvalue_create_address_string("cbs"); |
Azure.IoT Build | 0:6ae2f7bca550 | 70 | if (reply_to == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 71 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 72 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 73 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 74 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 75 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 76 | if (properties_set_reply_to(properties, reply_to) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 77 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 78 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 79 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 80 | |
Azure.IoT Build | 0:6ae2f7bca550 | 81 | amqpvalue_destroy(reply_to); |
Azure.IoT Build | 0:6ae2f7bca550 | 82 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 83 | |
Azure.IoT Build | 0:6ae2f7bca550 | 84 | AMQP_VALUE message_id = amqpvalue_create_message_id_ulong(0x43); |
Azure.IoT Build | 0:6ae2f7bca550 | 85 | if (message_id == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 86 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 87 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 88 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 89 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 90 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 91 | if (properties_set_message_id(properties, message_id) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 92 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 93 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 94 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 95 | |
Azure.IoT Build | 0:6ae2f7bca550 | 96 | amqpvalue_destroy(message_id); |
Azure.IoT Build | 0:6ae2f7bca550 | 97 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 98 | |
Azure.IoT Build | 0:6ae2f7bca550 | 99 | if (message_set_properties(message, properties) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 100 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 101 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 102 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 103 | |
Azure.IoT Build | 0:6ae2f7bca550 | 104 | properties_destroy(properties); |
Azure.IoT Build | 0:6ae2f7bca550 | 105 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 106 | |
Azure.IoT Build | 0:6ae2f7bca550 | 107 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 108 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 109 | |
Azure.IoT Build | 0:6ae2f7bca550 | 110 | CBS_HANDLE cbs_create(SESSION_HANDLE session, ON_AMQP_MANAGEMENT_STATE_CHANGED on_amqp_management_state_changed, void* callback_context) |
Azure.IoT Build | 0:6ae2f7bca550 | 111 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 112 | CBS_INSTANCE* result; |
Azure.IoT Build | 0:6ae2f7bca550 | 113 | |
Azure.IoT Build | 0:6ae2f7bca550 | 114 | if (session == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 115 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 116 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 117 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 118 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 119 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 120 | result = (CBS_INSTANCE*)amqpalloc_malloc(sizeof(CBS_INSTANCE)); |
Azure.IoT Build | 0:6ae2f7bca550 | 121 | if (result != NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 122 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 123 | result->amqp_management = amqpmanagement_create(session, "$cbs", on_amqp_management_state_changed, callback_context); |
Azure.IoT Build | 0:6ae2f7bca550 | 124 | if (result->amqp_management == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 125 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 126 | amqpalloc_free(result); |
Azure.IoT Build | 0:6ae2f7bca550 | 127 | result = NULL; |
Azure.IoT Build | 0:6ae2f7bca550 | 128 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 129 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 130 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 131 | |
Azure.IoT Build | 0:6ae2f7bca550 | 132 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 133 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 134 | |
Azure.IoT Build | 0:6ae2f7bca550 | 135 | void cbs_destroy(CBS_HANDLE cbs) |
Azure.IoT Build | 0:6ae2f7bca550 | 136 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 137 | if (cbs != NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 138 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 139 | (void)cbs_close(cbs); |
Azure.IoT Build | 0:6ae2f7bca550 | 140 | amqpmanagement_destroy(cbs->amqp_management); |
Azure.IoT Build | 0:6ae2f7bca550 | 141 | amqpalloc_free(cbs); |
Azure.IoT Build | 0:6ae2f7bca550 | 142 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 143 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 144 | |
Azure.IoT Build | 0:6ae2f7bca550 | 145 | int cbs_open(CBS_HANDLE cbs) |
Azure.IoT Build | 0:6ae2f7bca550 | 146 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 147 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 148 | |
Azure.IoT Build | 0:6ae2f7bca550 | 149 | if (cbs == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 150 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 151 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 152 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 153 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 154 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 155 | if (amqpmanagement_open(cbs->amqp_management) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 156 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 157 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 158 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 159 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 160 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 161 | result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 162 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 163 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 164 | |
Azure.IoT Build | 0:6ae2f7bca550 | 165 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 166 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 167 | |
Azure.IoT Build | 0:6ae2f7bca550 | 168 | int cbs_close(CBS_HANDLE cbs) |
Azure.IoT Build | 0:6ae2f7bca550 | 169 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 170 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 171 | |
Azure.IoT Build | 0:6ae2f7bca550 | 172 | if (cbs == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 173 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 174 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 175 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 176 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 177 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 178 | if (amqpmanagement_close(cbs->amqp_management) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 179 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 180 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 181 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 182 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 183 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 184 | result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 185 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 186 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 187 | |
Azure.IoT Build | 0:6ae2f7bca550 | 188 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 189 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 190 | |
Azure.IoT Build | 0:6ae2f7bca550 | 191 | int cbs_put_token(CBS_HANDLE cbs, const char* type, const char* audience, const char* token, ON_CBS_OPERATION_COMPLETE on_operation_complete, void* context) |
Azure.IoT Build | 0:6ae2f7bca550 | 192 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 193 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 194 | |
Azure.IoT Build | 0:6ae2f7bca550 | 195 | if ((cbs == NULL) || |
Azure.IoT Build | 0:6ae2f7bca550 | 196 | (token == NULL)) |
Azure.IoT Build | 0:6ae2f7bca550 | 197 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 198 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 199 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 200 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 201 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 202 | MESSAGE_HANDLE message = message_create(); |
Azure.IoT Build | 0:6ae2f7bca550 | 203 | if (message == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 204 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 205 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 206 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 207 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 208 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 209 | AMQP_VALUE token_value = amqpvalue_create_string(token); |
Azure.IoT Build | 0:6ae2f7bca550 | 210 | if (token_value == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 211 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 212 | message_destroy(message); |
Azure.IoT Build | 0:6ae2f7bca550 | 213 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 214 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 215 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 216 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 217 | if (message_set_body_amqp_value(message, token_value) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 218 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 219 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 220 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 221 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 222 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 223 | AMQP_VALUE application_properties = amqpvalue_create_map(); |
Azure.IoT Build | 0:6ae2f7bca550 | 224 | if (application_properties == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 225 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 226 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 227 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 228 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 229 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 230 | if (add_string_key_value_pair_to_map(application_properties, "name", audience) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 231 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 232 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 233 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 234 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 235 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 236 | if (message_set_application_properties(message, application_properties) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 237 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 238 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 239 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 240 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 241 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 242 | if (set_pending_operation_properties(message) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 243 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 244 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 245 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 246 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 247 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 248 | if (amqpmanagement_start_operation(cbs->amqp_management, "put-token", type, NULL, message, (ON_OPERATION_COMPLETE)on_operation_complete, context) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 249 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 250 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 251 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 252 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 253 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 254 | result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 255 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 256 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 257 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 258 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 259 | |
Azure.IoT Build | 0:6ae2f7bca550 | 260 | amqpvalue_destroy(application_properties); |
Azure.IoT Build | 0:6ae2f7bca550 | 261 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 262 | |
Azure.IoT Build | 0:6ae2f7bca550 | 263 | amqpvalue_destroy(token_value); |
Azure.IoT Build | 0:6ae2f7bca550 | 264 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 265 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 266 | |
Azure.IoT Build | 0:6ae2f7bca550 | 267 | message_destroy(message); |
Azure.IoT Build | 0:6ae2f7bca550 | 268 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 269 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 270 | |
Azure.IoT Build | 0:6ae2f7bca550 | 271 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 272 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 273 | |
Azure.IoT Build | 0:6ae2f7bca550 | 274 | int cbs_delete_token(CBS_HANDLE cbs, const char* type, const char* audience, ON_CBS_OPERATION_COMPLETE on_operation_complete, void* context) |
Azure.IoT Build | 0:6ae2f7bca550 | 275 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 276 | int result; |
Azure.IoT Build | 0:6ae2f7bca550 | 277 | |
Azure.IoT Build | 0:6ae2f7bca550 | 278 | if (cbs == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 279 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 280 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 281 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 282 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 283 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 284 | MESSAGE_HANDLE message = message_create(); |
Azure.IoT Build | 0:6ae2f7bca550 | 285 | if (message == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 286 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 287 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 288 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 289 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 290 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 291 | AMQP_VALUE application_properties = amqpvalue_create_map(); |
Azure.IoT Build | 0:6ae2f7bca550 | 292 | if (application_properties == NULL) |
Azure.IoT Build | 0:6ae2f7bca550 | 293 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 294 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 295 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 296 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 297 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 298 | if (add_string_key_value_pair_to_map(application_properties, "name", audience) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 299 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 300 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 301 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 302 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 303 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 304 | if (message_set_application_properties(message, application_properties) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 305 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 306 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 307 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 308 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 309 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 310 | if (set_pending_operation_properties(message) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 311 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 312 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 313 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 314 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 315 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 316 | if (amqpmanagement_start_operation(cbs->amqp_management, "delete-token", type, NULL, message, (ON_OPERATION_COMPLETE)on_operation_complete, context) != 0) |
Azure.IoT Build | 0:6ae2f7bca550 | 317 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 318 | result = __LINE__; |
Azure.IoT Build | 0:6ae2f7bca550 | 319 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 320 | else |
Azure.IoT Build | 0:6ae2f7bca550 | 321 | { |
Azure.IoT Build | 0:6ae2f7bca550 | 322 | result = 0; |
Azure.IoT Build | 0:6ae2f7bca550 | 323 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 324 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 325 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 326 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 327 | |
Azure.IoT Build | 0:6ae2f7bca550 | 328 | amqpvalue_destroy(application_properties); |
Azure.IoT Build | 0:6ae2f7bca550 | 329 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 330 | |
Azure.IoT Build | 0:6ae2f7bca550 | 331 | message_destroy(message); |
Azure.IoT Build | 0:6ae2f7bca550 | 332 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 333 | } |
Azure.IoT Build | 0:6ae2f7bca550 | 334 | |
Azure.IoT Build | 0:6ae2f7bca550 | 335 | return result; |
Azure.IoT Build | 0:6ae2f7bca550 | 336 | } |