1 /+ 2 low-level C bindings for rabbitmq-c 3 written by Laeeth Isharc at Symmetry Investments 2017 - 2019 4 +/ 5 6 /// 7 module symmetry.api.rabbitmq.bindings; 8 9 import core.stdc.string:memcpy; 10 11 version(OpenSSL) 12 { 13 import deimos.openssl.x509v3; 14 import deimos.openssl.bio; 15 } 16 17 alias ssize_t = ptrdiff_t; 18 struct amqp_time_t {} 19 version(Posix) import core.sys.posix.sys.types:pthread_mutex_t; 20 else struct pthread_mutex_t {} 21 22 alias DWORD = int; 23 24 version(Posix) 25 { 26 // import pthread; 27 public import core.sys.posix.sys.time: timeval; 28 } 29 30 else version(Windows) 31 { 32 public import core.sys.windows.winsock2: timeval; 33 } 34 35 36 extern(C) nothrow @nogc @system: 37 38 39 enum AMQP_VERSION_MAJOR = 0; 40 enum AMQP_VERSION_MINOR = 8; 41 enum AMQP_VERSION_PATCH = 1; 42 enum AMQP_VERSION_IS_RELEASE = 0; 43 44 auto AMQP_VERSION_CODE(int major, int minor, int patch, int release) 45 { 46 return 47 ((major << 24) | 48 (minor << 16) | 49 (patch << 8) | 50 (release)); 51 } 52 53 54 55 uint amqp_version_number(); 56 const(char)* amqp_version(); 57 enum AMQP_DEFAULT_FRAME_SIZE = 131072; 58 enum AMQP_DEFAULT_MAX_CHANNELS = 0; 59 enum AMQP_DEFAULT_HEARTBEAT = 0; 60 alias amqp_boolean_t = int; 61 alias amqp_method_number_t = uint; 62 alias amqp_flags_t = uint; 63 alias amqp_channel_t = ushort; 64 65 struct amqp_bytes_t 66 { 67 size_t len; /**< length of the buffer in bytes */ 68 void *bytes; /**< pointer to the beginning of the buffer */ 69 } 70 71 struct amqp_decimal_t 72 { 73 ubyte decimals; /**< the location of the decimal point */ 74 uint value; /**< the value before the decimal point is applied */ 75 } 76 77 struct amqp_table_t 78 { 79 int num_entries; /**< length of entries array */ 80 amqp_table_entry_t* entries; /**< an array of table entries */ 81 } 82 83 struct amqp_array_t 84 { 85 int num_entries; /**< Number of entries in the table */ 86 amqp_field_value_t* entries; /**< linked list of field values */ 87 } 88 89 struct amqp_field_value_t 90 { 91 ubyte kind; /**< the type of the entry /sa amqp_field_value_kind_t */ 92 union Value 93 { 94 amqp_boolean_t boolean; /**< boolean type AMQP_FIELD_KIND_BOOLEAN */ 95 char i8; /**< char type AMQP_FIELD_KIND_I8 */ 96 ubyte u8; /**< ubyte type AMQP_FIELD_KIND_U8 */ 97 short i16; /**< short type AMQP_FIELD_KIND_I16 */ 98 ushort u16; /**< ushort type AMQP_FIELD_KIND_U16 */ 99 int i32; /**< int type AMQP_FIELD_KIND_I32 */ 100 uint u32; /**< uint type AMQP_FIELD_KIND_U32 */ 101 long i64; /**< long type AMQP_FIELD_KIND_I64 */ 102 ulong u64; /**< ulong type AMQP_FIELD_KIND_U64, AMQP_FIELD_KIND_TIMESTAMP */ 103 float f32; /**< float type AMQP_FIELD_KIND_F32 */ 104 double f64; /**< double type AMQP_FIELD_KIND_F64 */ 105 amqp_decimal_t decimal; /**< amqp_decimal_t AMQP_FIELD_KIND_DECIMAL */ 106 amqp_bytes_t bytes; /**< amqp_bytes_t type AMQP_FIELD_KIND_UTF8, AMQP_FIELD_KIND_BYTES */ 107 amqp_table_t table; /**< amqp_table_t type AMQP_FIELD_KIND_TABLE */ 108 amqp_array_t array; /**< amqp_array_t type AMQP_FIELD_KIND_ARRAY */ 109 } 110 Value value; /**< a union of the value */ 111 } 112 113 114 struct amqp_table_entry_t 115 { 116 amqp_bytes_t key; /**< the table entry key. Its a null-terminated UTF-8 string, 117 * with a maximum size of 128 bytes */ 118 amqp_field_value_t value; /**< the table entry values */ 119 } 120 121 enum 122 { 123 AMQP_FIELD_KIND_BOOLEAN = 't', /**< boolean type. 0 = false, 1 = true @see amqp_boolean_t */ 124 AMQP_FIELD_KIND_I8 = 'b', /**< 8-bit signed integer, datatype: char* */ 125 AMQP_FIELD_KIND_U8 = 'B', /**< 8-bit unsigned integer, datatype: ubyte */ 126 AMQP_FIELD_KIND_I16 = 's', /**< 16-bit signed integer, datatype: short */ 127 AMQP_FIELD_KIND_U16 = 'u', /**< 16-bit unsigned integer, datatype: ushort */ 128 AMQP_FIELD_KIND_I32 = 'I', /**< 32-bit signed integer, datatype: int */ 129 AMQP_FIELD_KIND_U32 = 'i', /**< 32-bit unsigned integer, datatype: uint */ 130 AMQP_FIELD_KIND_I64 = 'l', /**< 64-bit signed integer, datatype: long */ 131 AMQP_FIELD_KIND_U64 = 'L', /**< 64-bit unsigned integer, datatype: ulong */ 132 AMQP_FIELD_KIND_F32 = 'f', /**< single-precision floating point value, datatype: float */ 133 AMQP_FIELD_KIND_F64 = 'd', /**< double-precision floating point value, datatype: double */ 134 AMQP_FIELD_KIND_DECIMAL = 'D', /**< amqp-decimal value, datatype: amqp_decimal_t */ 135 AMQP_FIELD_KIND_UTF8 = 'S', /**< UTF-8 null-terminated character string, datatype: amqp_bytes_t */ 136 AMQP_FIELD_KIND_ARRAY = 'A', /**< field array (repeated values of another datatype. datatype: amqp_array_t */ 137 AMQP_FIELD_KIND_TIMESTAMP = 'T',/**< 64-bit timestamp. datatype ulong */ 138 AMQP_FIELD_KIND_TABLE = 'F', /**< field table. encapsulates a table inside a table entry. datatype: amqp_table_t */ 139 AMQP_FIELD_KIND_VOID = 'V', /**< empty entry */ 140 AMQP_FIELD_KIND_BYTES = 'x' /**< unformatted byte string, datatype: amqp_bytes_t */ 141 } 142 143 struct amqp_pool_blocklist_t 144 { 145 int num_blocks; /**< Number of blocks in the block list */ 146 void** blocklist; /**< Array of memory blocks */ 147 } 148 149 struct amqp_pool_t 150 { 151 size_t pagesize; /**< the size of the page in bytes. 152 * allocations less than or equal to this size are 153 * allocated in the pages block list 154 * allocations greater than this are allocated in their 155 * own block in the large_blocks block list */ 156 157 amqp_pool_blocklist_t pages; /**< blocks that are the size of pagesize */ 158 amqp_pool_blocklist_t large_blocks; /**< allocations larger than the pagesize */ 159 160 int next_page; /**< an index to the next unused page block */ 161 char* alloc_block; /**< pointer to the current allocation block */ 162 size_t alloc_used; /**< number of bytes in the current allocation block that has been used */ 163 } 164 165 struct amqp_method_t 166 { 167 amqp_method_number_t id; /**< the method id number */ 168 void* decoded; /**< pointer to the decoded method, 169 * cast to the appropriate type to use */ 170 } 171 172 struct amqp_frame_t 173 { 174 ubyte frame_type; /**< frame type. The types: 175 * - AMQP_FRAME_METHOD - use the method union member 176 * - AMQP_FRAME_HEADER - use the properties union member 177 * - AMQP_FRAME_BODY - use the body_fragment union member 178 */ 179 amqp_channel_t channel; /**< the channel the frame was received on */ 180 union Payload 181 { 182 amqp_method_t method; /**< a method, use if frame_type == AMQP_FRAME_METHOD */ 183 struct Properties 184 { 185 ushort class_id; /**< the class for the properties */ 186 ulong body_size; /**< size of the body in bytes */ 187 void *decoded; /**< the decoded properties */ 188 amqp_bytes_t raw; /**< amqp-encoded properties structure */ 189 } 190 Properties properties; /**< message header, a.k.a., properties, 191 use if frame_type == AMQP_FRAME_HEADER */ 192 amqp_bytes_t body_fragment; /**< a body fragment, use if frame_type == AMQP_FRAME_BODY */ 193 struct ProtocolHeader 194 { 195 ubyte transport_high; /**< @internal first byte of handshake */ 196 ubyte transport_low; /**< @internal second byte of handshake */ 197 ubyte protocol_version_major; /**< @internal third byte of handshake */ 198 ubyte protocol_version_minor; /**< @internal fourth byte of handshake */ 199 } 200 ProtocolHeader protocol_header; /**< Used only when doing the initial handshake with the broker, 201 don't use otherwise */ 202 } 203 Payload payload; /**< the payload of the frame */ 204 } 205 206 enum 207 { 208 AMQP_RESPONSE_NONE = 0, /**< the library got an EOF from the socket */ 209 AMQP_RESPONSE_NORMAL, /**< response normal, the RPC completed successfully */ 210 AMQP_RESPONSE_LIBRARY_EXCEPTION,/**< library error, an error occurred in the library, examine the library_error */ 211 AMQP_RESPONSE_SERVER_EXCEPTION, /**< server exception, the broker returned an error, check replay */ 212 } 213 214 alias amqp_response_type_enum = typeof(AMQP_RESPONSE_NORMAL); 215 216 struct amqp_rpc_reply_t 217 { 218 amqp_response_type_enum reply_type; /**< the reply type: 219 * - AMQP_RESPONSE_NORMAL - the RPC completed successfully 220 * - AMQP_RESPONSE_SERVER_EXCEPTION - the broker returned 221 * an exception, check the reply field 222 * - AMQP_RESPONSE_LIBRARY_EXCEPTION - the library 223 * encountered an error, check the library_error field 224 */ 225 amqp_method_t reply; /**< in case of AMQP_RESPONSE_SERVER_EXCEPTION this 226 * field will be set to the method returned from the broker */ 227 int library_error; /**< in case of AMQP_RESPONSE_LIBRARY_EXCEPTION this 228 * field will be set to an error code. An error 229 * string can be retrieved using amqp_error_string */ 230 } 231 232 enum SaslMethod 233 { 234 undefined = AMQP_SASL_METHOD_UNDEFINED, 235 plain = AMQP_SASL_METHOD_PLAIN, 236 external = AMQP_SASL_METHOD_EXTERNAL, 237 } 238 alias amqp_sasl_method_enum = SaslMethod; 239 240 enum 241 { 242 AMQP_SASL_METHOD_UNDEFINED = -1, /**< Invalid SASL method */ 243 AMQP_SASL_METHOD_PLAIN = 0, /**< the PLAIN SASL method for authentication to the broker */ 244 AMQP_SASL_METHOD_EXTERNAL = 1 /**< the EXTERNAL SASL method for authentication to the broker */ 245 } 246 247 alias amqp_connection_state_t = amqp_connection_state_t_ *; 248 alias amqp_status_enum = int; 249 250 enum 251 { 252 AMQP_STATUS_OK = 0x0, /**< Operation successful */ 253 AMQP_STATUS_NO_MEMORY = -0x0001, /**< Memory allocation 254 failed */ 255 AMQP_STATUS_BAD_AMQP_DATA = -0x0002, /**< Incorrect or corrupt 256 data was received from 257 the broker. This is a 258 protocol error. */ 259 AMQP_STATUS_UNKNOWN_CLASS = -0x0003, /**< An unknown AMQP class 260 was received. This is 261 a protocol error. */ 262 AMQP_STATUS_UNKNOWN_METHOD = -0x0004, /**< An unknown AMQP method 263 was received. This is 264 a protocol error. */ 265 AMQP_STATUS_HOSTNAME_RESOLUTION_FAILED= -0x0005, /**< Unable to resolve the 266 * hostname */ 267 AMQP_STATUS_INCOMPATIBLE_AMQP_VERSION = -0x0006, /**< The broker advertised 268 an incompaible AMQP 269 version */ 270 AMQP_STATUS_CONNECTION_CLOSED = -0x0007, /**< The connection to the 271 broker has been closed 272 */ 273 AMQP_STATUS_BAD_URL = -0x0008, /**< malformed AMQP URL */ 274 AMQP_STATUS_SOCKET_ERROR = -0x0009, /**< A socket error 275 occurred */ 276 AMQP_STATUS_INVALID_PARAMETER = -0x000A, /**< An invalid parameter 277 was passed into the 278 function */ 279 AMQP_STATUS_TABLE_TOO_BIG = -0x000B, /**< The amqp_table_t object 280 cannot be serialized 281 because the output 282 buffer is too small */ 283 AMQP_STATUS_WRONG_METHOD = -0x000C, /**< The wrong method was 284 received */ 285 AMQP_STATUS_TIMEOUT = -0x000D, /**< Operation timed out */ 286 AMQP_STATUS_TIMER_FAILURE = -0x000E, /**< The underlying system 287 timer facility failed */ 288 AMQP_STATUS_HEARTBEAT_TIMEOUT = -0x000F, /**< Timed out waiting for 289 heartbeat */ 290 AMQP_STATUS_UNEXPECTED_STATE = -0x0010, /**< Unexpected protocol 291 state */ 292 AMQP_STATUS_SOCKET_CLOSED = -0x0011, /**< Underlying socket is 293 closed */ 294 AMQP_STATUS_SOCKET_INUSE = -0x0012, /**< Underlying socket is 295 already open */ 296 AMQP_STATUS_BROKER_UNSUPPORTED_SASL_METHOD = -0x0013, /**< Broker does not 297 support the requested 298 SASL mechanism */ 299 AMQP_STATUS_UNSUPPORTED = -0x0014, /**< Parameter is unsupported 300 in this version */ 301 _AMQP_STATUS_NEXT_VALUE = -0x0015, /**< Internal value */ 302 303 AMQP_STATUS_TCP_ERROR = -0x0100, /**< A generic TCP error 304 occurred */ 305 AMQP_STATUS_TCP_SOCKETLIB_INIT_ERROR = -0x0101, /**< An error occurred trying 306 to initialize the 307 socket library*/ 308 _AMQP_STATUS_TCP_NEXT_VALUE = -0x0102, /**< Internal value */ 309 310 AMQP_STATUS_SSL_ERROR = -0x0200, /**< A generic SSL error 311 occurred. */ 312 AMQP_STATUS_SSL_HOSTNAME_VERIFY_FAILED= -0x0201, /**< SSL validation of 313 hostname against 314 peer certificate 315 failed */ 316 AMQP_STATUS_SSL_PEER_VERIFY_FAILED = -0x0202, /**< SSL validation of peer 317 certificate failed. */ 318 AMQP_STATUS_SSL_CONNECTION_FAILED = -0x0203, /**< SSL handshake failed. */ 319 _AMQP_STATUS_SSL_NEXT_VALUE = -0x0204 /**< Internal value */ 320 } 321 322 enum amqp_delivery_mode_enum 323 { 324 AMQP_DELIVERY_NONPERSISTENT = 1, /**< Non-persistent message */ 325 AMQP_DELIVERY_PERSISTENT = 2 /**< Persistent message */ 326 } 327 328 // const causes problems with prototypes of functions 329 // const 330 __gshared amqp_bytes_t amqp_empty_bytes; 331 __gshared amqp_table_t amqp_empty_table; 332 __gshared amqp_array_t amqp_empty_array; 333 334 alias AMQP_EMPTY_BYTES = amqp_empty_bytes; 335 alias AMQP_EMPTY_TABLE = amqp_empty_table; 336 alias AMQP_EMPTY_ARRAY = amqp_empty_array; 337 void init_amqp_pool(amqp_pool_t *pool, size_t pagesize); 338 void recycle_amqp_pool(amqp_pool_t *pool); 339 void empty_amqp_pool(amqp_pool_t *pool); 340 void * amqp_pool_alloc(amqp_pool_t *pool, size_t amount); 341 void amqp_pool_alloc_bytes(amqp_pool_t *pool, size_t amount, amqp_bytes_t *output); 342 amqp_bytes_t amqp_cstring_bytes(const(char)* cstr); 343 amqp_bytes_t amqp_bytes_malloc_dup(amqp_bytes_t src); 344 amqp_bytes_t amqp_bytes_malloc(size_t amount); 345 void amqp_bytes_free(amqp_bytes_t bytes); 346 amqp_connection_state_t amqp_new_connection(); 347 int amqp_get_sockfd(amqp_connection_state_t state); 348 void amqp_set_sockfd(amqp_connection_state_t state, int sockfd); 349 int amqp_tune_connection(amqp_connection_state_t state, int channel_max, int frame_max, int heartbeat); 350 int amqp_get_channel_max(amqp_connection_state_t state); 351 int amqp_get_frame_max(amqp_connection_state_t state); 352 int amqp_get_heartbeat(amqp_connection_state_t state); 353 int amqp_destroy_connection(amqp_connection_state_t state); 354 int amqp_handle_input(amqp_connection_state_t state, amqp_bytes_t received_data, amqp_frame_t *decoded_frame); 355 amqp_boolean_t amqp_release_buffers_ok(amqp_connection_state_t state); 356 void amqp_release_buffers(amqp_connection_state_t state); 357 void amqp_maybe_release_buffers(amqp_connection_state_t state); 358 void amqp_maybe_release_buffers_on_channel(amqp_connection_state_t state, amqp_channel_t channel); 359 int amqp_send_frame(amqp_connection_state_t state, const(amqp_frame_t)* frame); 360 int amqp_table_entry_cmp(const(void)* entry1, const(void)* entry2); 361 int amqp_open_socket(const(char)* hostname, int portnumber); 362 int amqp_send_header(amqp_connection_state_t state); 363 amqp_boolean_t amqp_frames_enqueued(amqp_connection_state_t state); 364 int amqp_simple_wait_frame(amqp_connection_state_t state, amqp_frame_t *decoded_frame); 365 int amqp_simple_wait_frame_noblock(amqp_connection_state_t state, amqp_frame_t *decoded_frame, timeval *tv); 366 int amqp_simple_wait_method(amqp_connection_state_t state, amqp_channel_t expected_channel, amqp_method_number_t expected_method, amqp_method_t *output); 367 int amqp_send_method(amqp_connection_state_t state, amqp_channel_t channel, amqp_method_number_t id, void *decoded); 368 amqp_rpc_reply_t amqp_simple_rpc(amqp_connection_state_t state, amqp_channel_t channel, amqp_method_number_t request_id, amqp_method_number_t *expected_reply_ids, void *decoded_request_method); 369 void * amqp_simple_rpc_decoded(amqp_connection_state_t state, amqp_channel_t channel, amqp_method_number_t request_id, amqp_method_number_t reply_id, void *decoded_request_method); 370 amqp_rpc_reply_t amqp_get_rpc_reply(amqp_connection_state_t state); 371 amqp_rpc_reply_t amqp_login(amqp_connection_state_t state, const(char)* vhost, int channel_max, int frame_max, int heartbeat, amqp_sasl_method_enum sasl_method, ...); 372 amqp_rpc_reply_t amqp_login_with_properties(amqp_connection_state_t state, const(char)* vhost, int channel_max, int frame_max, int heartbeat, const amqp_table_t *properties, amqp_sasl_method_enum sasl_method, ...); 373 int amqp_basic_publish(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t exchange, amqp_bytes_t routing_key, 374 amqp_boolean_t mandatory, amqp_boolean_t immediate, const(amqp_basic_properties_t)* properties, amqp_bytes_t body_); 375 376 amqp_rpc_reply_t amqp_channel_close(amqp_connection_state_t state, amqp_channel_t channel, int code); 377 amqp_rpc_reply_t amqp_connection_close(amqp_connection_state_t state, int code); 378 int amqp_basic_ack(amqp_connection_state_t state, amqp_channel_t channel, ulong delivery_tag, amqp_boolean_t multiple); 379 amqp_rpc_reply_t amqp_basic_get(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_boolean_t no_ack); 380 int amqp_basic_reject(amqp_connection_state_t state, amqp_channel_t channel, ulong delivery_tag, amqp_boolean_t requeue); 381 int amqp_basic_nack(amqp_connection_state_t state, amqp_channel_t channel, ulong delivery_tag, amqp_boolean_t multiple, amqp_boolean_t requeue); 382 amqp_boolean_t amqp_data_in_buffer(amqp_connection_state_t state); 383 char* amqp_error_string(int err); 384 const(char)* amqp_error_string2(int err); 385 int amqp_decode_table(amqp_bytes_t encoded, amqp_pool_t *pool, amqp_table_t *output, size_t *offset); 386 int amqp_encode_table(amqp_bytes_t encoded, amqp_table_t *input, size_t *offset); 387 int amqp_table_clone(const amqp_table_t *original, amqp_table_t *clone, amqp_pool_t *pool); 388 389 390 struct amqp_message_t 391 { 392 amqp_basic_properties_t properties; /**< message properties */ 393 amqp_bytes_t body_; /**< message body */ 394 amqp_pool_t pool; /**< pool used to allocate properties */ 395 } 396 397 amqp_rpc_reply_t amqp_read_message(amqp_connection_state_t state, amqp_channel_t channel, amqp_message_t *message, int flags); 398 void amqp_destroy_message(amqp_message_t *message); 399 400 struct amqp_envelope_t 401 { 402 amqp_channel_t channel; /**< channel message was delivered on */ 403 amqp_bytes_t consumer_tag; /**< the consumer tag the message was delivered to */ 404 ulong delivery_tag; /**< the messages delivery tag */ 405 amqp_boolean_t redelivered; /**< flag indicating whether this message is being redelivered */ 406 amqp_bytes_t exchange; /**< exchange this message was published to */ 407 amqp_bytes_t routing_key; /**< the routing key this message was published with */ 408 amqp_message_t message; /**< the message */ 409 } 410 411 amqp_rpc_reply_t amqp_consume_message(amqp_connection_state_t state, amqp_envelope_t *envelope, timeval *timeout, int flags); 412 void amqp_destroy_envelope(amqp_envelope_t *envelope); 413 414 415 struct amqp_connection_info 416 { 417 char* user; /**< the username to authenticate with the broker, default on most broker is 'guest' */ 418 char* password; /**< the password to authenticate with the broker, default on most brokers is 'guest' */ 419 char* host; /**< the hostname of the broker */ 420 char* vhost; /**< the virtual host on the broker to connect to, a good default is "/" */ 421 int port; /**< the port that the broker is listening on, default on most brokers is 5672 */ 422 amqp_boolean_t ssl; 423 } 424 425 void amqp_default_connection_info(amqp_connection_info* parsed); 426 int amqp_parse_url(char* url, amqp_connection_info* parsed); 427 int amqp_socket_open(amqp_socket_t *self, const(char)*host, int port); 428 int amqp_socket_open_noblock(amqp_socket_t *self, const(char)*host, int port, timeval* timeout); 429 int amqp_socket_get_sockfd(amqp_socket_t *self); 430 amqp_socket_t * amqp_get_socket(amqp_connection_state_t state); 431 amqp_table_t * amqp_get_server_properties(amqp_connection_state_t state); 432 amqp_table_t * amqp_get_client_properties(amqp_connection_state_t state); 433 timeval* amqp_get_handshake_timeout(amqp_connection_state_t state); 434 int amqp_set_handshake_timeout(amqp_connection_state_t state, timeval* timeout); 435 timeval* amqp_get_rpc_timeout(amqp_connection_state_t state); 436 int amqp_set_rpc_timeout(amqp_connection_state_t state, timeval* timeout); 437 438 amqp_socket_t * amqp_tcp_socket_new(amqp_connection_state_t state); 439 void amqp_tcp_socket_set_sockfd(amqp_socket_t *self, int sockfd); 440 amqp_table_entry_t amqp_table_construct_utf8_entry(const(char)*key, const(char)*value); 441 amqp_table_entry_t amqp_table_construct_table_entry(const(char)*key, const amqp_table_t *value); 442 amqp_table_entry_t amqp_table_construct_bool_entry(const(char)*key, const int value); 443 amqp_table_entry_t *amqp_table_get_entry_by_key(const amqp_table_t *table, const amqp_bytes_t key); 444 445 version(OpenSSL) 446 { 447 amqp_socket_t * amqp_ssl_socket_new(amqp_connection_state_t state); 448 int amqp_ssl_socket_set_cacert(amqp_socket_t *self, const(char)*cacert); 449 int amqp_ssl_socket_set_key(amqp_socket_t *self, const(char)*cert, const(char)*key); 450 int amqp_ssl_socket_set_key_buffer(amqp_socket_t *self, const(char)*cert, const void *key, size_t n); 451 void amqp_ssl_socket_set_verify(amqp_socket_t *self, amqp_boolean_t verify); 452 void amqp_ssl_socket_set_verify_peer(amqp_socket_t *self, amqp_boolean_t verify); 453 void amqp_ssl_socket_set_verify_hostname(amqp_socket_t *self, amqp_boolean_t verify); 454 455 enum amqp_tls_version_t 456 { 457 AMQP_TLSv1 = 1, 458 AMQP_TLSv1_1 = 2, 459 AMQP_TLSv1_2 = 3, 460 AMQP_TLSvLATEST = 0xFFFF 461 } 462 463 int amqp_ssl_socket_set_ssl_versions(amqp_socket_t *self, amqp_tls_version_t min, amqp_tls_version_t max); 464 void amqp_set_initialize_ssl_library(amqp_boolean_t do_initialize); 465 } 466 467 468 enum amqp_socket_flag_enum 469 { 470 AMQP_SF_NONE = 0, 471 AMQP_SF_MORE = 1, 472 AMQP_SF_POLLIN = 2, 473 AMQP_SF_POLLOUT = 4, 474 AMQP_SF_POLLERR = 8 475 } 476 477 enum amqp_socket_close_enum 478 { 479 AMQP_SC_NONE = 0, 480 AMQP_SC_FORCE = 1 481 } 482 483 int amqp_os_socket_error(); 484 int amqp_os_socket_close(int sockfd); 485 486 /* Socket callbacks. */ 487 alias amqp_socket_send_fn = ssize_t function(void *, const void *, size_t, int); 488 alias amqp_socket_recv_fn = ssize_t function(void *, void *, size_t, int); 489 alias amqp_socket_open_fn = int function(void *, const(char)*, int, timeval*); 490 alias amqp_socket_close_fn = int function(void *, amqp_socket_close_enum); 491 alias amqp_socket_get_sockfd_fn = int function(void *); 492 alias amqp_socket_delete_fn = void function(void *); 493 494 /// V-table for amqp_socket_t 495 struct amqp_socket_class_t 496 { 497 amqp_socket_send_fn send; 498 amqp_socket_recv_fn recv; 499 amqp_socket_open_fn open; 500 amqp_socket_close_fn close; 501 amqp_socket_get_sockfd_fn get_sockfd; 502 amqp_socket_delete_fn delete_; 503 } 504 505 /** Abstract base class for amqp_socket_t */ 506 struct amqp_socket_t 507 { 508 amqp_socket_class_t *klass; 509 } 510 511 void amqp_set_socket(amqp_connection_state_t state, amqp_socket_t *socket); 512 ssize_t amqp_socket_send(amqp_socket_t *self, const void *buf, size_t len, int flags); 513 ssize_t amqp_try_send(amqp_connection_state_t state, const void *buf, size_t len, amqp_time_t deadline, int flags); 514 ssize_t amqp_socket_recv(amqp_socket_t *self, void *buf, size_t len, int flags); 515 int amqp_socket_close(amqp_socket_t *self, amqp_socket_close_enum force); 516 void amqp_socket_delete(amqp_socket_t *self); 517 int amqp_open_socket_noblock(const(char)* hostname, int portnumber, timeval* timeout); 518 int amqp_open_socket_inner(const(char)* hostname, int portnumber, amqp_time_t deadline); 519 int amqp_poll(int fd, int event, amqp_time_t deadline); 520 int amqp_send_method_inner(amqp_connection_state_t state, amqp_channel_t channel, amqp_method_number_t id, void *decoded, int flags, amqp_time_t deadline); 521 int amqp_queue_frame(amqp_connection_state_t state, amqp_frame_t *frame); 522 int amqp_put_back_frame(amqp_connection_state_t state, amqp_frame_t *frame); 523 int amqp_simple_wait_frame_on_channel(amqp_connection_state_t state, amqp_channel_t channel, amqp_frame_t *decoded_frame); 524 int sasl_mechanism_in_list(amqp_bytes_t mechanisms, amqp_sasl_method_enum method); 525 int amqp_merge_capabilities(const amqp_table_t *base, const amqp_table_t *add, amqp_table_t *result, amqp_pool_t *pool); 526 enum AMQ_COPYRIGHT = "Copyright (c) 2007-2014 VMWare Inc, Tony Garnock-Jones, and Alan Antonuk."; 527 528 enum amqp_connection_state_enum 529 { 530 CONNECTION_STATE_IDLE = 0, 531 CONNECTION_STATE_INITIAL, 532 CONNECTION_STATE_HEADER, 533 CONNECTION_STATE_BODY 534 } 535 536 enum amqp_status_private_enum 537 { 538 /* 0x00xx . AMQP_STATUS_*/ 539 /* 0x01xx . AMQP_STATUS_TCP_* */ 540 /* 0x02xx . AMQP_STATUS_SSL_* */ 541 AMQP_PRIVATE_STATUS_SOCKET_NEEDREAD = -0x1301, 542 AMQP_PRIVATE_STATUS_SOCKET_NEEDWRITE = -0x1302 543 } 544 545 /* 7 bytes up front, then payload, then 1 byte footer */ 546 enum HEADER_SIZE =7; 547 enum FOOTER_SIZE =1; 548 enum AMQP_PSEUDOFRAME_PROTOCOL_HEADER ='A'; 549 550 struct amqp_link_t 551 { 552 amqp_link_t* next; 553 void *data; 554 } 555 556 enum POOL_TABLE_SIZE=16; 557 558 struct amqp_pool_table_entry_t 559 { 560 amqp_pool_table_entry_t* next; 561 amqp_pool_t pool; 562 amqp_channel_t channel; 563 } 564 565 struct amqp_connection_state_t_ 566 { 567 amqp_pool_table_entry_t*[POOL_TABLE_SIZE] pool_table; 568 569 amqp_connection_state_enum state; 570 571 int channel_max; 572 int frame_max; 573 574 /* Heartbeat interval in seconds. If this is <= 0, then heartbeats are not 575 * enabled, and next_recv_heartbeat and next_send_heartbeat are set to 576 * infinite */ 577 int heartbeat; 578 amqp_time_t next_recv_heartbeat; 579 amqp_time_t next_send_heartbeat; 580 581 /* buffer for holding frame headers. Allows us to delay allocating 582 * the raw frame buffer until the type, channel, and size are all known 583 */ 584 char[HEADER_SIZE + 1] header_buffer; 585 amqp_bytes_t inbound_buffer; 586 587 size_t inbound_offset; 588 size_t target_size; 589 590 amqp_bytes_t outbound_buffer; 591 592 amqp_socket_t *socket; 593 594 amqp_bytes_t sock_inbound_buffer; 595 size_t sock_inbound_offset; 596 size_t sock_inbound_limit; 597 598 amqp_link_t *first_queued_frame; 599 amqp_link_t *last_queued_frame; 600 601 amqp_rpc_reply_t most_recent_api_result; 602 603 amqp_table_t server_properties; 604 amqp_table_t client_properties; 605 amqp_pool_t properties_pool; 606 607 timeval *handshake_timeout; 608 timeval internal_handshake_timeout; 609 timeval *rpc_timeout; 610 timeval internal_rpc_timeout; 611 } 612 613 amqp_pool_t *amqp_get_or_create_channel_pool(amqp_connection_state_t connection, amqp_channel_t channel); 614 amqp_pool_t *amqp_get_channel_pool(amqp_connection_state_t state, amqp_channel_t channel); 615 616 617 pragma(inline,true) 618 int amqp_heartbeat_send(amqp_connection_state_t state) 619 { 620 return state.heartbeat; 621 } 622 623 pragma(inline,true) 624 int amqp_heartbeat_recv(amqp_connection_state_t state) 625 { 626 return 2 * state.heartbeat; 627 } 628 629 630 int amqp_try_recv(amqp_connection_state_t state); 631 632 pragma(inline,true) 633 void *amqp_offset(void *data, size_t offset) 634 { 635 return cast(char* )data + offset; 636 } 637 638 pragma(inline,true) 639 int amqp_encode_bytes(amqp_bytes_t encoded, size_t *offset, amqp_bytes_t input) 640 { 641 size_t o = *offset; 642 /* The memcpy below has undefined behavior if the input is NULL. It is valid 643 * for a 0-length amqp_bytes_t to have .bytes == NULL. Thus we should check 644 * before encoding. 645 */ 646 if (input.len == 0) { 647 return 1; 648 } 649 if ((*offset = o + input.len) <= encoded.len) { 650 memcpy(amqp_offset(encoded.bytes, o), input.bytes, input.len); 651 return 1; 652 } else { 653 return 0; 654 } 655 } 656 657 pragma(inline,true) 658 int amqp_decode_bytes(amqp_bytes_t encoded, size_t *offset, amqp_bytes_t *output, size_t len) 659 { 660 size_t o = *offset; 661 if ((*offset = o + len) <= encoded.len) { 662 output.bytes = amqp_offset(encoded.bytes, o); 663 output.len = len; 664 return 1; 665 } else { 666 return 0; 667 } 668 } 669 670 void amqp_abort(const(char)*fmt, ...); 671 int amqp_bytes_equal(amqp_bytes_t r, amqp_bytes_t l); 672 673 pragma(inline,true) 674 amqp_rpc_reply_t amqp_rpc_reply_error(amqp_status_enum status) 675 { 676 amqp_rpc_reply_t reply; 677 reply.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; 678 reply.library_error = status; 679 return reply; 680 } 681 682 int amqp_send_frame_inner(amqp_connection_state_t state, const amqp_frame_t *frame, int flags, amqp_time_t deadline); 683 684 685 686 enum amqp_hostname_validation_result 687 { 688 AMQP_HVR_MATCH_FOUND, 689 AMQP_HVR_MATCH_NOT_FOUND, 690 AMQP_HVR_NO_SAN_PRESENT, 691 AMQP_HVR_MALFORMED_CERTIFICATE, 692 AMQP_HVR_ERROR 693 } 694 695 version(OpenSSL) 696 { 697 amqp_hostname_validation_result amqp_ssl_validate_hostname(const(char)*hostname, const X509* server_cert); 698 BIO_METHOD* amqp_openssl_bio(); 699 } 700 701 enum amqp_hostcheck_result 702 { 703 AMQP_HCR_NO_MATCH = 0, 704 AMQP_HCR_MATCH = 1 705 } 706 amqp_hostcheck_result amqp_hostcheck(const(char)*match_pattern, const(char)*hostname); 707 708 709 enum AMQP_PROTOCOL_VERSION_MAJOR=0; 710 enum AMQP_PROTOCOL_VERSION_MINOR=9; 711 enum AMQP_PROTOCOL_VERSION_REVISION=1; 712 enum AMQP_PROTOCOL_PORT= 5672; 713 enum AMQP_FRAME_METHOD=1; 714 enum AMQP_FRAME_HEADER=2; 715 enum AMQP_FRAME_BODY=3; 716 enum AMQP_FRAME_HEARTBEAT=8; 717 enum AMQP_FRAME_MIN_SIZE=4096; 718 enum AMQP_FRAME_END=206; 719 enum AMQP_REPLY_SUCCESS=200; 720 enum AMQP_CONTENT_TOO_LARGE= 311; 721 enum AMQP_NO_ROUTE= 312; 722 enum AMQP_NO_CONSUMERS= 313; 723 enum AMQP_ACCESS_REFUSED= 403; 724 enum AMQP_NOT_FOUND= 404; 725 enum AMQP_RESOURCE_LOCKED= 405; 726 enum AMQP_PRECONDITION_FAILED= 406; 727 enum AMQP_CONNECTION_FORCED=320; 728 enum AMQP_INVALID_PATH=402; 729 enum AMQP_FRAME_ERROR=501; 730 enum AMQP_SYNTAX_ERROR=502; 731 enum AMQP_COMMAND_INVALID=503; 732 enum AMQP_CHANNEL_ERROR=504; 733 enum AMQP_UNEXPECTED_FRAME=505; 734 enum AMQP_RESOURCE_ERROR=506; 735 enum AMQP_NOT_ALLOWED=530; 736 enum AMQP_NOT_IMPLEMENTED=540; 737 enum AMQP_INTERNAL_ERROR=541; 738 739 alias ReplySuccess = AMQP_REPLY_SUCCESS; 740 741 const(char)* amqp_constant_name(int constantNumber); 742 amqp_boolean_t amqp_constant_is_hard_error(int constantNumber); 743 const(char)* amqp_method_name(amqp_method_number_t methodNumber); 744 amqp_boolean_t amqp_method_has_content(amqp_method_number_t methodNumber); 745 int amqp_decode_method(amqp_method_number_t methodNumber, amqp_pool_t *pool, amqp_bytes_t encoded, void** decoded); 746 int amqp_decode_properties(ushort class_id, amqp_pool_t *pool, amqp_bytes_t encoded, void** decoded); 747 int amqp_encode_method(amqp_method_number_t methodNumber, void *decoded, amqp_bytes_t encoded); 748 int amqp_encode_properties(ushort class_id, void *decoded, amqp_bytes_t encoded); 749 enum amqp_method_number_t AMQP_CONNECTION_START_METHOD = 0x000A000A; 750 751 struct amqp_connection_start_t 752 { 753 ubyte version_major; /**< version-major */ 754 ubyte version_minor; /**< version-minor */ 755 amqp_table_t server_properties; /**< server-properties */ 756 amqp_bytes_t mechanisms; /**< mechanisms */ 757 amqp_bytes_t locales; /**< locales */ 758 } 759 760 enum amqp_method_number_t AMQP_CONNECTION_START_OK_METHOD = 0x000A000B; 761 struct amqp_connection_start_ok_t 762 { 763 amqp_table_t client_properties; /**< client-properties */ 764 amqp_bytes_t mechanism; /**< mechanism */ 765 amqp_bytes_t response; /**< response */ 766 amqp_bytes_t locale; /**< locale */ 767 } 768 769 enum amqp_method_number_t AMQP_CONNECTION_SECURE_METHOD= 0x000A0014; 770 struct amqp_connection_secure_t 771 { 772 amqp_bytes_t challenge; /**< challenge */ 773 } 774 775 enum amqp_method_number_t AMQP_CONNECTION_SECURE_OK_METHOD= 0x000A0015; 776 struct amqp_connection_secure_ok_t 777 { 778 amqp_bytes_t response; /**< response */ 779 } 780 781 enum amqp_method_number_t AMQP_CONNECTION_TUNE_METHOD = 0x000A001E; 782 struct amqp_connection_tune_t 783 { 784 ushort channel_max; /**< channel-max */ 785 uint frame_max; /**< frame-max */ 786 ushort heartbeat; /**< heartbeat */ 787 } 788 789 enum amqp_method_number_t AMQP_CONNECTION_TUNE_OK_METHOD= 0x000A001F; 790 struct amqp_connection_tune_ok_t 791 { 792 ushort channel_max; /**< channel-max */ 793 uint frame_max; /**< frame-max */ 794 ushort heartbeat; /**< heartbeat */ 795 } 796 797 enum amqp_method_number_t AMQP_CONNECTION_OPEN_METHOD= 0x000A0028; 798 struct amqp_connection_open_t 799 { 800 amqp_bytes_t virtual_host; /**< virtual-host */ 801 amqp_bytes_t capabilities; /**< capabilities */ 802 amqp_boolean_t insist; /**< insist */ 803 } 804 805 enum amqp_method_number_t AMQP_CONNECTION_OPEN_OK_METHOD = 0x000A0029; 806 struct amqp_connection_open_ok_t 807 { 808 amqp_bytes_t known_hosts; /**< known-hosts */ 809 } 810 811 enum amqp_method_number_t AMQP_CONNECTION_CLOSE_METHOD = 0x000A0032; 812 struct amqp_connection_close_t 813 { 814 ushort reply_code; /**< reply-code */ 815 amqp_bytes_t reply_text; /**< reply-text */ 816 ushort class_id; /**< class-id */ 817 ushort method_id; /**< method-id */ 818 } 819 820 enum amqp_method_number_t AMQP_CONNECTION_CLOSE_OK_METHOD = 0x000A0033; 821 struct amqp_connection_close_ok_t 822 { 823 char dummy; /**< Dummy field to avoid empty struct */ 824 } 825 826 enum amqp_method_number_t AMQP_CONNECTION_BLOCKED_METHOD = 0x000A003C; 827 struct amqp_connection_blocked_t 828 { 829 amqp_bytes_t reason; /**< reason */ 830 } 831 832 enum amqp_method_number_t AMQP_CONNECTION_UNBLOCKED_METHOD = 0x000A003D; 833 struct amqp_connection_unblocked_t 834 { 835 char dummy; /**< Dummy field to avoid empty struct */ 836 } 837 838 enum amqp_method_number_t AMQP_CHANNEL_OPEN_METHOD = 0x0014000A; 839 struct amqp_channel_open_t 840 { 841 amqp_bytes_t out_of_band; /**< out-of-band */ 842 } 843 844 enum amqp_method_number_t AMQP_CHANNEL_OPEN_OK_METHOD = 0x0014000B; 845 struct amqp_channel_open_ok_t 846 { 847 amqp_bytes_t channel_id; /**< channel-id */ 848 } 849 850 enum amqp_method_number_t AMQP_CHANNEL_FLOW_METHOD = 0x00140014; 851 struct amqp_channel_flow_t 852 { 853 amqp_boolean_t active; /**< active */ 854 } 855 856 enum amqp_method_number_t AMQP_CHANNEL_FLOW_OK_METHOD = 0x00140015; 857 struct amqp_channel_flow_ok_t 858 { 859 amqp_boolean_t active; /**< active */ 860 } 861 862 enum amqp_method_number_t AMQP_CHANNEL_CLOSE_METHOD = 0x00140028; 863 struct amqp_channel_close_t 864 { 865 ushort reply_code; /**< reply-code */ 866 amqp_bytes_t reply_text; /**< reply-text */ 867 ushort class_id; /**< class-id */ 868 ushort method_id; /**< method-id */ 869 } 870 871 enum amqp_method_number_t AMQP_CHANNEL_CLOSE_OK_METHOD = 0x00140029; 872 struct amqp_channel_close_ok_t 873 { 874 char dummy; /**< Dummy field to avoid empty struct */ 875 } 876 877 enum amqp_method_number_t AMQP_ACCESS_REQUEST_METHOD = 0x001E000A; 878 struct amqp_access_request_t 879 { 880 amqp_bytes_t realm; /**< realm */ 881 amqp_boolean_t exclusive; /**< exclusive */ 882 amqp_boolean_t passive; /**< passive */ 883 amqp_boolean_t active; /**< active */ 884 amqp_boolean_t write; /**< write */ 885 amqp_boolean_t read; /**< read */ 886 } 887 888 enum amqp_method_number_t AMQP_ACCESS_REQUEST_OK_METHOD= 0x001E000B; 889 struct amqp_access_request_ok_t 890 { 891 ushort ticket; /**< ticket */ 892 } 893 894 enum amqp_method_number_t AMQP_EXCHANGE_DECLARE_METHOD = 0x0028000A; 895 struct amqp_exchange_declare_t 896 { 897 ushort ticket; /**< ticket */ 898 amqp_bytes_t exchange; /**< exchange */ 899 amqp_bytes_t type; /**< type */ 900 amqp_boolean_t passive; /**< passive */ 901 amqp_boolean_t durable; /**< durable */ 902 amqp_boolean_t auto_delete; /**< auto-delete */ 903 amqp_boolean_t internal; /**< internal */ 904 amqp_boolean_t nowait; /**< nowait */ 905 amqp_table_t arguments; /**< arguments */ 906 } 907 908 enum amqp_method_number_t AMQP_EXCHANGE_DECLARE_OK_METHOD = 0x0028000B; 909 struct amqp_exchange_declare_ok_t 910 { 911 char dummy; /**< Dummy field to avoid empty struct */ 912 } 913 914 enum amqp_method_number_t AMQP_EXCHANGE_DELETE_METHOD = 0x00280014; 915 struct amqp_exchange_delete_t 916 { 917 ushort ticket; /**< ticket */ 918 amqp_bytes_t exchange; /**< exchange */ 919 amqp_boolean_t if_unused; /**< if-unused */ 920 amqp_boolean_t nowait; /**< nowait */ 921 } 922 923 enum amqp_method_number_t AMQP_EXCHANGE_DELETE_OK_METHOD = 0x00280015; 924 struct amqp_exchange_delete_ok_t 925 { 926 char dummy; /**< Dummy field to avoid empty struct */ 927 } 928 929 enum amqp_method_number_t AMQP_EXCHANGE_BIND_METHOD = 0x0028001E; 930 struct amqp_exchange_bind_t 931 { 932 ushort ticket; /**< ticket */ 933 amqp_bytes_t destination; /**< destination */ 934 amqp_bytes_t source; /**< source */ 935 amqp_bytes_t routing_key; /**< routing-key */ 936 amqp_boolean_t nowait; /**< nowait */ 937 amqp_table_t arguments; /**< arguments */ 938 } 939 940 enum amqp_method_number_t AMQP_EXCHANGE_BIND_OK_METHOD = 0x0028001F; 941 struct amqp_exchange_bind_ok_t 942 { 943 char dummy; /**< Dummy field to avoid empty struct */ 944 } 945 946 enum amqp_method_number_t AMQP_EXCHANGE_UNBIND_METHOD = 0x00280028; 947 struct amqp_exchange_unbind_t 948 { 949 ushort ticket; /**< ticket */ 950 amqp_bytes_t destination; /**< destination */ 951 amqp_bytes_t source; /**< source */ 952 amqp_bytes_t routing_key; /**< routing-key */ 953 amqp_boolean_t nowait; /**< nowait */ 954 amqp_table_t arguments; /**< arguments */ 955 } 956 957 enum amqp_method_number_t AMQP_EXCHANGE_UNBIND_OK_METHOD = 0x00280033; 958 struct amqp_exchange_unbind_ok_t 959 { 960 char dummy; /**< Dummy field to avoid empty struct */ 961 } 962 963 enum amqp_method_number_t AMQP_QUEUE_DECLARE_METHOD = 0x0032000A; 964 struct amqp_queue_declare_t 965 { 966 ushort ticket; /**< ticket */ 967 amqp_bytes_t queue; /**< queue */ 968 amqp_boolean_t passive; /**< passive */ 969 amqp_boolean_t durable; /**< durable */ 970 amqp_boolean_t exclusive; /**< exclusive */ 971 amqp_boolean_t auto_delete; /**< auto-delete */ 972 amqp_boolean_t nowait; /**< nowait */ 973 amqp_table_t arguments; /**< arguments */ 974 } 975 976 enum amqp_method_number_t AMQP_QUEUE_DECLARE_OK_METHOD= 0x0032000B; 977 struct amqp_queue_declare_ok_t 978 { 979 amqp_bytes_t queue; /**< queue */ 980 uint message_count; /**< message-count */ 981 uint consumer_count; /**< consumer-count */ 982 } 983 984 enum amqp_method_number_t AMQP_QUEUE_BIND_METHOD = 0x00320014; 985 struct amqp_queue_bind_t 986 { 987 ushort ticket; /**< ticket */ 988 amqp_bytes_t queue; /**< queue */ 989 amqp_bytes_t exchange; /**< exchange */ 990 amqp_bytes_t routing_key; /**< routing-key */ 991 amqp_boolean_t nowait; /**< nowait */ 992 amqp_table_t arguments; /**< arguments */ 993 } 994 995 enum amqp_method_number_t AMQP_QUEUE_BIND_OK_METHOD = 0x00320015; 996 struct amqp_queue_bind_ok_t 997 { 998 char dummy; /**< Dummy field to avoid empty struct */ 999 } 1000 1001 enum amqp_method_number_t AMQP_QUEUE_PURGE_METHOD =0x0032001E; 1002 struct amqp_queue_purge_t 1003 { 1004 ushort ticket; /**< ticket */ 1005 amqp_bytes_t queue; /**< queue */ 1006 amqp_boolean_t nowait; /**< nowait */ 1007 } 1008 1009 enum amqp_method_number_t AMQP_QUEUE_PURGE_OK_METHOD = 0x0032001F; 1010 struct amqp_queue_purge_ok_t 1011 { 1012 uint message_count; /**< message-count */ 1013 } 1014 1015 enum amqp_method_number_t AMQP_QUEUE_DELETE_METHOD = 0x00320028; 1016 struct amqp_queue_delete_t 1017 { 1018 ushort ticket; /**< ticket */ 1019 amqp_bytes_t queue; /**< queue */ 1020 amqp_boolean_t if_unused; /**< if-unused */ 1021 amqp_boolean_t if_empty; /**< if-empty */ 1022 amqp_boolean_t nowait; /**< nowait */ 1023 } 1024 1025 enum amqp_method_number_t AMQP_QUEUE_DELETE_OK_METHOD = 0x00320029; 1026 struct amqp_queue_delete_ok_t{ 1027 uint message_count; /**< message-count */ 1028 } 1029 1030 enum amqp_method_number_t AMQP_QUEUE_UNBIND_METHOD = 0x00320032; 1031 struct amqp_queue_unbind_t 1032 { 1033 ushort ticket; /**< ticket */ 1034 amqp_bytes_t queue; /**< queue */ 1035 amqp_bytes_t exchange; /**< exchange */ 1036 amqp_bytes_t routing_key; /**< routing-key */ 1037 amqp_table_t arguments; /**< arguments */ 1038 } 1039 1040 enum amqp_method_number_t AMQP_QUEUE_UNBIND_OK_METHOD = 0x00320033; 1041 struct amqp_queue_unbind_ok_t 1042 { 1043 char dummy; /**< Dummy field to avoid empty struct */ 1044 } 1045 1046 enum amqp_method_number_t AMQP_BASIC_QOS_METHOD = 0x003C000A; 1047 struct amqp_basic_qos_t 1048 { 1049 uint prefetch_size; /**< prefetch-size */ 1050 ushort prefetch_count; /**< prefetch-count */ 1051 amqp_boolean_t global; /**< global */ 1052 } 1053 1054 enum amqp_method_number_t AMQP_BASIC_QOS_OK_METHOD = 0x003C000B; 1055 struct amqp_basic_qos_ok_t 1056 { 1057 char dummy; /**< Dummy field to avoid empty struct */ 1058 } 1059 1060 enum amqp_method_number_t AMQP_BASIC_CONSUME_METHOD = 0x003C0014; 1061 struct amqp_basic_consume_t 1062 { 1063 ushort ticket; /**< ticket */ 1064 amqp_bytes_t queue; /**< queue */ 1065 amqp_bytes_t consumer_tag; /**< consumer-tag */ 1066 amqp_boolean_t no_local; /**< no-local */ 1067 amqp_boolean_t no_ack; /**< no-ack */ 1068 amqp_boolean_t exclusive; /**< exclusive */ 1069 amqp_boolean_t nowait; /**< nowait */ 1070 amqp_table_t arguments; /**< arguments */ 1071 } 1072 1073 enum amqp_method_number_t AMQP_BASIC_CONSUME_OK_METHOD = 0x003C0015; 1074 struct amqp_basic_consume_ok_t 1075 { 1076 amqp_bytes_t consumer_tag; /**< consumer-tag */ 1077 } 1078 1079 enum amqp_method_number_t AMQP_BASIC_CANCEL_METHOD= 0x003C001E; 1080 struct amqp_basic_cancel_t 1081 { 1082 amqp_bytes_t consumer_tag; /**< consumer-tag */ 1083 amqp_boolean_t nowait; /**< nowait */ 1084 } 1085 1086 enum amqp_method_number_t AMQP_BASIC_CANCEL_OK_METHOD = 0x003C001F; 1087 struct amqp_basic_cancel_ok_t 1088 { 1089 amqp_bytes_t consumer_tag; /**< consumer-tag */ 1090 } 1091 1092 enum amqp_method_number_t AMQP_BASIC_PUBLISH_METHOD = 0x003C0028; 1093 struct amqp_basic_publish_t 1094 { 1095 ushort ticket; /**< ticket */ 1096 amqp_bytes_t exchange; /**< exchange */ 1097 amqp_bytes_t routing_key; /**< routing-key */ 1098 amqp_boolean_t mandatory; /**< mandatory */ 1099 amqp_boolean_t immediate; /**< immediate */ 1100 } 1101 1102 enum amqp_method_number_t AMQP_BASIC_RETURN_METHOD = 0x003C0032; 1103 struct amqp_basic_return_t 1104 { 1105 ushort reply_code; /**< reply-code */ 1106 amqp_bytes_t reply_text; /**< reply-text */ 1107 amqp_bytes_t exchange; /**< exchange */ 1108 amqp_bytes_t routing_key; /**< routing-key */ 1109 } 1110 1111 enum amqp_method_number_t AMQP_BASIC_DELIVER_METHOD = 0x003C003C; 1112 struct amqp_basic_deliver_t 1113 { 1114 amqp_bytes_t consumer_tag; /**< consumer-tag */ 1115 ulong delivery_tag; /**< delivery-tag */ 1116 amqp_boolean_t redelivered; /**< redelivered */ 1117 amqp_bytes_t exchange; /**< exchange */ 1118 amqp_bytes_t routing_key; /**< routing-key */ 1119 } 1120 1121 enum amqp_method_number_t AMQP_BASIC_GET_METHOD = 0x003C0046; 1122 struct amqp_basic_get_t 1123 { 1124 ushort ticket; /**< ticket */ 1125 amqp_bytes_t queue; /**< queue */ 1126 amqp_boolean_t no_ack; /**< no-ack */ 1127 } 1128 1129 enum amqp_method_number_t AMQP_BASIC_GET_OK_METHOD = 0x003C0047; 1130 struct amqp_basic_get_ok_t 1131 { 1132 ulong delivery_tag; /**< delivery-tag */ 1133 amqp_boolean_t redelivered; /**< redelivered */ 1134 amqp_bytes_t exchange; /**< exchange */ 1135 amqp_bytes_t routing_key; /**< routing-key */ 1136 uint message_count; /**< message-count */ 1137 } 1138 1139 enum amqp_method_number_t AMQP_BASIC_GET_EMPTY_METHOD = 0x003C0048; 1140 struct amqp_basic_get_empty_t 1141 { 1142 amqp_bytes_t cluster_id; /**< cluster-id */ 1143 } 1144 1145 enum amqp_method_number_t AMQP_BASIC_ACK_METHOD = 0x003C0050; 1146 struct amqp_basic_ack_t 1147 { 1148 ulong delivery_tag; /**< delivery-tag */ 1149 amqp_boolean_t multiple; /**< multiple */ 1150 } 1151 1152 enum amqp_method_number_t AMQP_BASIC_REJECT_METHOD = 0x003C005A; 1153 struct amqp_basic_reject_t 1154 { 1155 ulong delivery_tag; /**< delivery-tag */ 1156 amqp_boolean_t requeue; /**< requeue */ 1157 } 1158 1159 enum amqp_method_number_t AMQP_BASIC_RECOVER_ASYNC_METHOD = 0x003C0064; 1160 struct amqp_basic_recover_async_t 1161 { 1162 amqp_boolean_t requeue; /**< requeue */ 1163 } 1164 1165 enum amqp_method_number_t AMQP_BASIC_RECOVER_METHOD = 0x003C006E; 1166 struct amqp_basic_recover_t 1167 { 1168 amqp_boolean_t requeue; /**< requeue */ 1169 } 1170 1171 enum amqp_method_number_t AMQP_BASIC_RECOVER_OK_METHOD = 0x003C006F; 1172 struct amqp_basic_recover_ok_t 1173 { 1174 char dummy; /**< Dummy field to avoid empty struct */ 1175 } 1176 1177 enum amqp_method_number_t AMQP_BASIC_NACK_METHOD = 0x003C0078; 1178 struct amqp_basic_nack_t 1179 { 1180 ulong delivery_tag; /**< delivery-tag */ 1181 amqp_boolean_t multiple; /**< multiple */ 1182 amqp_boolean_t requeue; /**< requeue */ 1183 } 1184 1185 enum amqp_method_number_t AMQP_TX_SELECT_METHOD = 0x005A000A; 1186 struct amqp_tx_select_t 1187 { 1188 char dummy; /**< Dummy field to avoid empty struct */ 1189 } 1190 1191 enum amqp_method_number_t AMQP_TX_SELECT_OK_METHOD= 0x005A000B; 1192 struct amqp_tx_select_ok_t 1193 { 1194 char dummy; /**< Dummy field to avoid empty struct */ 1195 } 1196 1197 enum amqp_method_number_t AMQP_TX_COMMIT_METHOD = 0x005A0014; 1198 struct amqp_tx_commit_t 1199 { 1200 char dummy; /**< Dummy field to avoid empty struct */ 1201 } 1202 1203 enum amqp_method_number_t AMQP_TX_COMMIT_OK_METHOD= 0x005A0015; 1204 struct amqp_tx_commit_ok_t 1205 { 1206 char dummy; /**< Dummy field to avoid empty struct */ 1207 } 1208 1209 enum amqp_method_number_t AMQP_TX_ROLLBACK_METHOD = 0x005A001E; 1210 struct amqp_tx_rollback_t 1211 { 1212 char dummy; /**< Dummy field to avoid empty struct */ 1213 } 1214 1215 enum amqp_method_number_t AMQP_TX_ROLLBACK_OK_METHOD= 0x005A001F; 1216 struct amqp_tx_rollback_ok_t 1217 { 1218 char dummy; /**< Dummy field to avoid empty struct */ 1219 } 1220 1221 enum amqp_method_number_t AMQP_CONFIRM_SELECT_METHOD= 0x0055000A; 1222 struct amqp_confirm_select_t 1223 { 1224 amqp_boolean_t nowait; /**< nowait */ 1225 } 1226 1227 enum amqp_method_number_t AMQP_CONFIRM_SELECT_OK_METHOD= 0x0055000B; 1228 struct amqp_confirm_select_ok_t 1229 { 1230 char dummy; /**< Dummy field to avoid empty struct */ 1231 } 1232 1233 /* Class property records. */ 1234 enum AMQP_CONNECTION_CLASS = 0x000A; 1235 /** connection class properties */ 1236 struct amqp_connection_properties_t 1237 { 1238 amqp_flags_t _flags; /**< bit-mask of set fields */ 1239 char dummy; /**< Dummy field to avoid empty struct */ 1240 } 1241 1242 enum AMQP_CHANNEL_CLASS = 0x0014; 1243 struct amqp_channel_properties_t 1244 { 1245 amqp_flags_t _flags; /**< bit-mask of set fields */ 1246 char dummy; /**< Dummy field to avoid empty struct */ 1247 } 1248 1249 enum AMQP_ACCESS_CLASS = 0x001E; 1250 struct amqp_access_properties_t_ 1251 { 1252 amqp_flags_t _flags; /**< bit-mask of set fields */ 1253 char dummy; /**< Dummy field to avoid empty struct */ 1254 } 1255 1256 enum AMQP_EXCHANGE_CLASS = 0x0028; 1257 struct amqp_exchange_properties_t 1258 { 1259 amqp_flags_t _flags; /**< bit-mask of set fields */ 1260 char dummy; /**< Dummy field to avoid empty struct */ 1261 } 1262 1263 enum AMQP_QUEUE_CLASS = 0x0032; 1264 struct amqp_queue_properties_t 1265 { 1266 amqp_flags_t _flags; /**< bit-mask of set fields */ 1267 char dummy; /**< Dummy field to avoid empty struct */ 1268 } 1269 1270 enum AMQP_BASIC_CLASS = 0x003C; 1271 enum AMQP_BASIC_CONTENT_TYPE_FLAG =(1 << 15); /**< basic.content-type property flag */ 1272 enum AMQP_BASIC_CONTENT_ENCODING_FLAG= (1 << 14); /**< basic.content-encoding property flag */ 1273 enum AMQP_BASIC_HEADERS_FLAG=(1 << 13); /**< basic.headers property flag */ 1274 enum AMQP_BASIC_DELIVERY_MODE_FLAG=(1 << 12); /**< basic.delivery-mode property flag */ 1275 enum AMQP_BASIC_PRIORITY_FLAG=(1 << 11); /**< basic.priority property flag */ 1276 enum AMQP_BASIC_CORRELATION_ID_FLAG=(1 << 10); /**< basic.correlation-id property flag */ 1277 enum AMQP_BASIC_REPLY_TO_FLAG=(1 << 9); /**< basic.reply-to property flag */ 1278 enum AMQP_BASIC_EXPIRATION_FLAG=(1 << 8); /**< basic.expiration property flag */ 1279 enum AMQP_BASIC_MESSAGE_ID_FLAG=(1 << 7); /**< basic.message-id property flag */ 1280 enum AMQP_BASIC_TIMESTAMP_FLAG=(1 << 6); /**< basic.timestamp property flag */ 1281 enum AMQP_BASIC_TYPE_FLAG=(1 << 5); /**< basic.type property flag */ 1282 enum AMQP_BASIC_USER_ID_FLAG=(1 << 4); /**< basic.user-id property flag */ 1283 enum AMQP_BASIC_APP_ID_FLAG=(1 << 3); /**< basic.app-id property flag */ 1284 enum AMQP_BASIC_CLUSTER_ID_FLAG=(1 << 2); /**< basic.cluster-id property flag */ 1285 1286 /** basic class properties */ 1287 struct amqp_basic_properties_t 1288 { 1289 amqp_flags_t _flags; /**< bit-mask of set fields */ 1290 amqp_bytes_t content_type; /**< content-type */ 1291 amqp_bytes_t content_encoding; /**< content-encoding */ 1292 amqp_table_t headers; /**< headers */ 1293 ubyte delivery_mode; /**< delivery-mode */ 1294 ubyte priority; /**< priority */ 1295 amqp_bytes_t correlation_id; /**< correlation-id */ 1296 amqp_bytes_t reply_to; /**< reply-to */ 1297 amqp_bytes_t expiration; /**< expiration */ 1298 amqp_bytes_t message_id; /**< message-id */ 1299 ulong timestamp; /**< timestamp */ 1300 amqp_bytes_t type; /**< type */ 1301 amqp_bytes_t user_id; /**< user-id */ 1302 amqp_bytes_t app_id; /**< app-id */ 1303 amqp_bytes_t cluster_id; /**< cluster-id */ 1304 } 1305 1306 enum AMQP_TX_CLASS = 0x005A; 1307 /** tx class properties */ 1308 struct amqp_tx_properties_t 1309 { 1310 amqp_flags_t _flags; /**< bit-mask of set fields */ 1311 char dummy; /**< Dummy field to avoid empty struct */ 1312 } 1313 1314 enum AMQP_CONFIRM_CLASS = 0x0055; 1315 struct amqp_confirm_properties_t 1316 { 1317 amqp_flags_t _flags; /**< bit-mask of set fields */ 1318 char dummy; /**< Dummy field to avoid empty struct */ 1319 } 1320 1321 amqp_channel_open_ok_t * amqp_channel_open(amqp_connection_state_t state, amqp_channel_t channel); 1322 amqp_channel_flow_ok_t * amqp_channel_flow(amqp_connection_state_t state, amqp_channel_t channel, amqp_boolean_t active); 1323 amqp_exchange_declare_ok_t* amqp_exchange_declare(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t exchange, amqp_bytes_t type, amqp_boolean_t passive, amqp_boolean_t durable, amqp_boolean_t auto_delete, amqp_boolean_t internal, amqp_table_t arguments); 1324 amqp_exchange_delete_ok_t * amqp_exchange_delete(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t exchange, amqp_boolean_t if_unused); 1325 amqp_exchange_bind_ok_t * amqp_exchange_bind(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t destination, amqp_bytes_t source, amqp_bytes_t routing_key, amqp_table_t arguments); 1326 amqp_exchange_unbind_ok_t * amqp_exchange_unbind(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t destination, amqp_bytes_t source, amqp_bytes_t routing_key, amqp_table_t arguments); 1327 amqp_queue_declare_ok_t * amqp_queue_declare(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_boolean_t passive, amqp_boolean_t durable, amqp_boolean_t exclusive, amqp_boolean_t auto_delete, amqp_table_t arguments); 1328 amqp_queue_bind_ok_t * amqp_queue_bind(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_bytes_t exchange, amqp_bytes_t routing_key, amqp_table_t arguments); 1329 amqp_queue_purge_ok_t * amqp_queue_purge(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue); 1330 amqp_queue_delete_ok_t * amqp_queue_delete(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_boolean_t if_unused, amqp_boolean_t if_empty); 1331 amqp_queue_unbind_ok_t * amqp_queue_unbind(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_bytes_t exchange, amqp_bytes_t routing_key, amqp_table_t arguments); 1332 amqp_basic_qos_ok_t * amqp_basic_qos(amqp_connection_state_t state, amqp_channel_t channel, uint prefetch_size, ushort prefetch_count, amqp_boolean_t global); 1333 amqp_basic_consume_ok_t * amqp_basic_consume(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t queue, amqp_bytes_t consumer_tag, amqp_boolean_t no_local, amqp_boolean_t no_ack, amqp_boolean_t exclusive, amqp_table_t arguments); 1334 amqp_basic_cancel_ok_t * amqp_basic_cancel(amqp_connection_state_t state, amqp_channel_t channel, amqp_bytes_t consumer_tag); 1335 amqp_basic_recover_ok_t * amqp_basic_recover(amqp_connection_state_t state, amqp_channel_t channel, amqp_boolean_t requeue); 1336 amqp_tx_select_ok_t * amqp_tx_select(amqp_connection_state_t state, amqp_channel_t channel); 1337 amqp_tx_commit_ok_t * amqp_tx_commit(amqp_connection_state_t state, amqp_channel_t channel); 1338 amqp_tx_rollback_ok_t * amqp_tx_rollback(amqp_connection_state_t state, amqp_channel_t channel); 1339 amqp_confirm_select_ok_t * amqp_confirm_select(amqp_connection_state_t state, amqp_channel_t channel); 1340 1341 //typedef SRWLOCK pthread_mutex_t; 1342 //enum PTHREAD_MUTEX_INITIALIZER SRWLOCK_INIT; 1343 DWORD pthread_self(); 1344 int pthread_mutex_init(pthread_mutex_t *, void *attr); 1345 int pthread_mutex_lock(pthread_mutex_t *); 1346 int pthread_mutex_unlock(pthread_mutex_t *); 1347 1348