rabbitmq-c  0.2
C AMQP Client library for RabbitMQ
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
amqp.h
Go to the documentation of this file.
1 
2 /*
3  * ***** BEGIN LICENSE BLOCK *****
4  * Version: MIT
5  *
6  * Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc.
7  * All Rights Reserved.
8  *
9  * Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010
10  * VMware, Inc. and Tony Garnock-Jones. All Rights Reserved.
11  *
12  * Permission is hereby granted, free of charge, to any person
13  * obtaining a copy of this software and associated documentation
14  * files (the "Software"), to deal in the Software without
15  * restriction, including without limitation the rights to use, copy,
16  * modify, merge, publish, distribute, sublicense, and/or sell copies
17  * of the Software, and to permit persons to whom the Software is
18  * furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be
21  * included in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  * ***** END LICENSE BLOCK *****
32  */
33 
34 #ifndef AMQP_H
35 #define AMQP_H
36 
37 #ifdef __cplusplus
38 #define AMQP_BEGIN_DECLS extern "C" {
39 #define AMQP_END_DECLS }
40 #else
41 
42 #define AMQP_BEGIN_DECLS
43 #define AMQP_END_DECLS
44 
45 #endif
46 
47 
56 #if defined(_WIN32) && defined(_MSC_VER)
57 # if defined(AMQP_BUILD) && !defined(AMQP_STATIC)
58 # define AMQP_PUBLIC_FUNCTION __declspec(dllexport)
59 # define AMQP_PUBLIC_VARIABLE __declspec(dllexport) extern
60 # else
61 # define AMQP_PUBLIC_FUNCTION
62 # if !defined(AMQP_STATIC)
63 # define AMQP_PUBLIC_VARIABLE __declspec(dllimport) extern
64 # else
65 # define AMQP_PUBLIC_VARIABLE extern
66 # endif
67 # endif
68 # define AMQP_CALL __cdecl
69 
70 #elif defined(_WIN32) && defined(__BORLANDC__)
71 # if defined(AMQP_BUILD) && !defined(AMQP_STATIC)
72 # define AMQP_PUBLIC_FUNCTION __declspec(dllexport)
73 # define AMQP_PUBLIC_VARIABLE __declspec(dllexport) extern
74 # else
75 # define AMQP_PUBLIC_FUNCTION
76 # if !defined(AMQP_STATIC)
77 # define AMQP_PUBLIC_VARIABLE __declspec(dllimport) extern
78 # else
79 # define AMQP_PUBLIC_VARIABLE extern
80 # endif
81 # endif
82 # define AMQP_CALL __cdecl
83 
84 #elif defined(_WIN32) && defined(__MINGW32__)
85 # if defined(AMQP_BUILD) && !defined(AMQP_STATIC)
86 # define AMQP_PUBLIC_FUNCTION __declspec(dllexport)
87 # define AMQP_PUBLIC_VARIABLE __declspec(dllexport)
88 # else
89 # define AMQP_PUBLIC_FUNCTION
90 # if !defined(AMQP_STATIC)
91 # define AMQP_PUBLIC_VARIABLE __declspec(dllimport) extern
92 # else
93 # define AMQP_PUBLIC_VARIABLE extern
94 # endif
95 # endif
96 # define AMQP_CALL __cdecl
97 
98 #elif defined(_WIN32) && defined(__CYGWIN__)
99 # if defined(AMQP_BUILD) && !defined(AMQP_STATIC)
100 # define AMQP_PUBLIC_FUNCTION __declspec(dllexport)
101 # define AMQP_PUBLIC_VARIABLE __declspec(dllexport)
102 # else
103 # define AMQP_PUBLIC_FUNCTION
104 # if !defined(AMQP_STATIC)
105 # define AMQP_PUBLIC_VARIABLE __declspec(dllimport) extern
106 # else
107 # define AMQP_PUBLIC_VARIABLE extern
108 # endif
109 # endif
110 # define AMQP_CALL __cdecl
111 
112 #elif defined(__GNUC__) && __GNUC__ >= 4
113 # define AMQP_PUBLIC_FUNCTION \
114  __attribute__ ((visibility ("default")))
115 # define AMQP_PUBLIC_VARIABLE \
116  __attribute__ ((visibility ("default"))) extern
117 # define AMQP_CALL
118 #else
119 
120 # define AMQP_PUBLIC_FUNCTION
121 # define AMQP_PUBLIC_VARIABLE extern
122 # define AMQP_CALL
123 
124 #endif
125 
126 #include <stddef.h>
127 #include <stdint.h>
128 
129 AMQP_BEGIN_DECLS
130 
134 typedef int amqp_boolean_t;
135 
139 typedef uint32_t amqp_method_number_t;
140 
144 typedef uint32_t amqp_flags_t;
145 
149 typedef uint16_t amqp_channel_t;
150 
154 typedef struct amqp_bytes_t_ {
155  size_t len;
156  void *bytes;
157 } amqp_bytes_t;
158 
162 typedef struct amqp_decimal_t_ {
163  uint8_t decimals;
164  uint32_t value;
166 
174 typedef struct amqp_table_t_ {
176  struct amqp_table_entry_t_ *entries;
177 } amqp_table_t;
178 
184 typedef struct amqp_array_t_ {
186  struct amqp_field_value_t_ *entries;
187 } amqp_array_t;
188 
189 /*
190  0-9 0-9-1 Qpid/Rabbit Type Remarks
191 ---------------------------------------------------------------------------
192  t t Boolean
193  b b Signed 8-bit
194  B Unsigned 8-bit
195  U s Signed 16-bit (A1)
196  u Unsigned 16-bit
197  I I I Signed 32-bit
198  i Unsigned 32-bit
199  L l Signed 64-bit (B)
200  l Unsigned 64-bit
201  f f 32-bit float
202  d d 64-bit float
203  D D D Decimal
204  s Short string (A2)
205  S S S Long string
206  A Nested Array
207  T T T Timestamp (u64)
208  F F F Nested Table
209  V V V Void
210  x Byte array
211 
212 Remarks:
213 
214  A1, A2: Notice how the types **CONFLICT** here. In Qpid and Rabbit,
215  's' means a signed 16-bit integer; in 0-9-1, it means a
216  short string.
217 
218  B: Notice how the signednesses **CONFLICT** here. In Qpid and Rabbit,
219  'l' means a signed 64-bit integer; in 0-9-1, it means an unsigned
220  64-bit integer.
221 
222 I'm going with the Qpid/Rabbit types, where there's a conflict, and
223 the 0-9-1 types otherwise. 0-8 is a subset of 0-9, which is a subset
224 of the other two, so this will work for both 0-8 and 0-9-1 branches of
225 the code.
226 */
227 
231 typedef struct amqp_field_value_t_ {
232  uint8_t kind;
233  union {
235  int8_t i8;
236  uint8_t u8;
237  int16_t i16;
238  uint16_t u16;
239  int32_t i32;
240  uint32_t u32;
241  int64_t i64;
242  uint64_t u64;
243  float f32;
244  double f64;
249  } value;
251 
255 typedef struct amqp_table_entry_t_ {
260 
264 typedef enum {
284 
288 typedef struct amqp_pool_blocklist_t_ {
290  void **blocklist;
292 
296 typedef struct amqp_pool_t_ {
297  size_t pagesize;
306  int next_page;
307  char *alloc_block;
308  size_t alloc_used;
309 } amqp_pool_t;
310 
314 typedef struct amqp_method_t_ {
316  void *decoded;
318 } amqp_method_t;
319 
323 typedef struct amqp_frame_t_ {
324  uint8_t frame_type;
330  union {
332  struct {
333  uint16_t class_id;
334  uint64_t body_size;
335  void *decoded;
337  } properties;
340  struct {
341  uint8_t transport_high;
342  uint8_t transport_low;
343  uint8_t protocol_version_major;
344  uint8_t protocol_version_minor;
345  } protocol_header;
347  } payload;
348 } amqp_frame_t;
349 
353 typedef enum amqp_response_type_enum_ {
359 
363 typedef struct amqp_rpc_reply_t_ {
373  int library_error;
377 
381 typedef enum amqp_sasl_method_enum_ {
384 
388 typedef struct amqp_connection_state_t_ *amqp_connection_state_t;
389 
395 AMQP_PUBLIC_FUNCTION
396 char const *
397 AMQP_CALL amqp_version(void);
398 
402 AMQP_PUBLIC_VARIABLE const amqp_bytes_t amqp_empty_bytes;
403 
407 AMQP_PUBLIC_VARIABLE const amqp_table_t amqp_empty_table;
408 
412 AMQP_PUBLIC_VARIABLE const amqp_array_t amqp_empty_array;
413 
414 /* Compatibility macros for the above, to avoid the need to update
415  code written against earlier versions of librabbitmq. */
416 #define AMQP_EMPTY_BYTES amqp_empty_bytes
417 #define AMQP_EMPTY_TABLE amqp_empty_table
418 #define AMQP_EMPTY_ARRAY amqp_empty_array
436 AMQP_PUBLIC_FUNCTION
437 void
438 AMQP_CALL init_amqp_pool(amqp_pool_t *pool, size_t pagesize);
439 
454 AMQP_PUBLIC_FUNCTION
455 void
456 AMQP_CALL recycle_amqp_pool(amqp_pool_t *pool);
457 
465 AMQP_PUBLIC_FUNCTION
466 void
467 AMQP_CALL empty_amqp_pool(amqp_pool_t *pool);
468 
477 AMQP_PUBLIC_FUNCTION
478 void *
479 AMQP_CALL amqp_pool_alloc(amqp_pool_t *pool, size_t amount);
480 
492 AMQP_PUBLIC_FUNCTION
493 void
494 AMQP_CALL amqp_pool_alloc_bytes(amqp_pool_t *pool, size_t amount, amqp_bytes_t *output);
495 
512 AMQP_PUBLIC_FUNCTION
514 AMQP_CALL amqp_cstring_bytes(char const *cstr);
515 
528 AMQP_PUBLIC_FUNCTION
530 AMQP_CALL amqp_bytes_malloc_dup(amqp_bytes_t src);
531 
541 AMQP_PUBLIC_FUNCTION
543 AMQP_CALL amqp_bytes_malloc(size_t amount);
544 
555 AMQP_PUBLIC_FUNCTION
556 void
557 AMQP_CALL amqp_bytes_free(amqp_bytes_t bytes);
558 
565 AMQP_PUBLIC_FUNCTION
567 AMQP_CALL amqp_new_connection(void);
568 
576 AMQP_PUBLIC_FUNCTION
577 int
579 
586 AMQP_PUBLIC_FUNCTION
587 void
588 AMQP_CALL amqp_set_sockfd(amqp_connection_state_t state, int sockfd);
589 
607 AMQP_PUBLIC_FUNCTION
608 int
610  int channel_max,
611  int frame_max,
612  int heartbeat);
613 
622 AMQP_PUBLIC_FUNCTION
623 int
625 
635 AMQP_PUBLIC_FUNCTION
636 int
638 
650 AMQP_PUBLIC_FUNCTION
651 int
653  amqp_bytes_t received_data,
654  amqp_frame_t *decoded_frame);
655 
666 AMQP_PUBLIC_FUNCTION
669 
679 AMQP_PUBLIC_FUNCTION
680 void
682 
690 AMQP_PUBLIC_FUNCTION
691 void
693 
701 AMQP_PUBLIC_FUNCTION
702 int
703 AMQP_CALL amqp_send_frame(amqp_connection_state_t state, amqp_frame_t const *frame);
704 
714 AMQP_PUBLIC_FUNCTION
715 int
716 AMQP_CALL amqp_table_entry_cmp(void const *entry1, void const *entry2);
717 
729 AMQP_PUBLIC_FUNCTION
730 int
731 AMQP_CALL amqp_open_socket(char const *hostname, int portnumber);
732 
739 AMQP_PUBLIC_FUNCTION
740 int
742 
752 AMQP_PUBLIC_FUNCTION
755 
763 AMQP_PUBLIC_FUNCTION
764 int
766  amqp_frame_t *decoded_frame);
767 
781 AMQP_PUBLIC_FUNCTION
782 int
784  amqp_channel_t expected_channel,
785  amqp_method_number_t expected_method,
786  amqp_method_t *output);
787 
797 AMQP_PUBLIC_FUNCTION
798 int
800  amqp_channel_t channel,
802  void *decoded);
803 
814 AMQP_PUBLIC_FUNCTION
817  amqp_channel_t channel,
818  amqp_method_number_t request_id,
819  amqp_method_number_t *expected_reply_ids,
820  void *decoded_request_method);
821 
832 AMQP_PUBLIC_FUNCTION
833 void *
835  amqp_channel_t channel,
836  amqp_method_number_t request_id,
837  amqp_method_number_t reply_id,
838  void *decoded_request_method);
839 
858 AMQP_PUBLIC_FUNCTION
861 
888 AMQP_PUBLIC_FUNCTION
890 AMQP_CALL amqp_login(amqp_connection_state_t state, char const *vhost,
891  int channel_max, int frame_max, int heartbeat,
892  amqp_sasl_method_enum sasl_method, ...);
893 
894 struct amqp_basic_properties_t_;
895 
916 AMQP_PUBLIC_FUNCTION
917 int
919  amqp_bytes_t exchange, amqp_bytes_t routing_key,
920  amqp_boolean_t mandatory, amqp_boolean_t immediate,
921  struct amqp_basic_properties_t_ const *properties,
922  amqp_bytes_t body);
923 
932 AMQP_PUBLIC_FUNCTION
935  int code);
936 
948 AMQP_PUBLIC_FUNCTION
950 AMQP_CALL amqp_connection_close(amqp_connection_state_t state, int code);
951 
965 AMQP_PUBLIC_FUNCTION
966 int
967 AMQP_CALL amqp_basic_ack(amqp_connection_state_t state, amqp_channel_t channel,
968  uint64_t delivery_tag, amqp_boolean_t multiple);
969 
984 AMQP_PUBLIC_FUNCTION
986 AMQP_CALL amqp_basic_get(amqp_connection_state_t state, amqp_channel_t channel,
987  amqp_bytes_t queue, amqp_boolean_t no_ack);
988 
1002 AMQP_PUBLIC_FUNCTION
1003 int
1005  uint64_t delivery_tag, amqp_boolean_t requeue);
1006 
1017 AMQP_PUBLIC_FUNCTION
1020 
1030 AMQP_PUBLIC_FUNCTION
1031 char *
1032 AMQP_CALL amqp_error_string(int err);
1033 
1049 AMQP_PUBLIC_FUNCTION
1050 int
1051 AMQP_CALL amqp_decode_table(amqp_bytes_t encoded, amqp_pool_t *pool,
1052  amqp_table_t *output, size_t *offset);
1053 
1067 AMQP_PUBLIC_FUNCTION
1068 int
1069 AMQP_CALL amqp_encode_table(amqp_bytes_t encoded, amqp_table_t *input, size_t *offset);
1070 
1075  char *user;
1076  char *password;
1077  char *host;
1078  char *vhost;
1079  int port;
1080 };
1081 
1094 AMQP_PUBLIC_FUNCTION
1095 void
1096 AMQP_CALL amqp_default_connection_info(struct amqp_connection_info *parsed);
1097 
1113 AMQP_PUBLIC_FUNCTION
1114 int
1115 AMQP_CALL amqp_parse_url(char *url, struct amqp_connection_info *parsed);
1116 
1117 AMQP_END_DECLS
1118 
1119 #include <amqp_framing.h>
1120 
1121 #endif /* AMQP_H */