/src/librabbitmq/librabbitmq/amqp_private.h
Line | Count | Source |
1 | | // Copyright 2007 - 2021, Alan Antonuk and the rabbitmq-c contributors. |
2 | | // SPDX-License-Identifier: mit |
3 | | |
4 | | #ifndef librabbitmq_amqp_private_h |
5 | | #define librabbitmq_amqp_private_h |
6 | | |
7 | | #ifdef HAVE_CONFIG_H |
8 | | #include "config.h" |
9 | | #endif |
10 | | |
11 | | #define AMQ_COPYRIGHT \ |
12 | 0 | "Copyright (c) 2007-2014 VMWare Inc, Tony Garnock-Jones," \ |
13 | 0 | " and Alan Antonuk." |
14 | | |
15 | | #include "rabbitmq-c/amqp.h" |
16 | | #include "rabbitmq-c/framing.h" |
17 | | #include <string.h> |
18 | | |
19 | | #if ((defined(_WIN32)) || (defined(__MINGW32__)) || (defined(__MINGW64__))) |
20 | | #ifndef WINVER |
21 | | /* WINVER 0x0502 is WinXP SP2+, Windows Server 2003 SP1+ |
22 | | * See: |
23 | | * http://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx#macros_for_conditional_declarations |
24 | | */ |
25 | | #define WINVER 0x0502 |
26 | | #endif |
27 | | #ifndef WIN32_LEAN_AND_MEAN |
28 | | #define WIN32_LEAN_AND_MEAN |
29 | | #endif |
30 | | #include <winsock2.h> |
31 | | #else |
32 | | #include <arpa/inet.h> |
33 | | #include <sys/uio.h> |
34 | | #endif |
35 | | |
36 | | /* GCC attributes */ |
37 | | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) |
38 | | #define AMQP_NORETURN __attribute__((__noreturn__)) |
39 | | #define AMQP_UNUSED __attribute__((__unused__)) |
40 | | #elif defined(_MSC_VER) |
41 | | #define AMQP_NORETURN __declspec(noreturn) |
42 | | #define AMQP_UNUSED __pragma(warning(suppress : 4100)) |
43 | | #else |
44 | | #define AMQP_NORETURN |
45 | | #define AMQP_UNUSED |
46 | | #endif |
47 | | |
48 | | #if (defined(_MSC_VER) && (_MSC_VER <= 1800)) || \ |
49 | | (defined(__BORLANDC__) && (__BORLANDC__ <= 0x0564)) |
50 | | #define inline __inline |
51 | | #endif |
52 | | |
53 | | char *amqp_os_error_string(int err); |
54 | | |
55 | | #include "amqp_socket.h" |
56 | | #include "amqp_time.h" |
57 | | |
58 | | /* |
59 | | * Connection states: XXX FIX THIS |
60 | | * |
61 | | * - CONNECTION_STATE_INITIAL: The initial state, when we cannot be |
62 | | * sure if the next thing we will get is the first AMQP frame, or a |
63 | | * protocol header from the server. |
64 | | * |
65 | | * - CONNECTION_STATE_IDLE: The normal state between |
66 | | * frames. Connections may only be reconfigured, and the |
67 | | * connection's pools recycled, when in this state. Whenever we're |
68 | | * in this state, the inbound_buffer's bytes pointer must be NULL; |
69 | | * any other state, and it must point to a block of memory allocated |
70 | | * from the frame_pool. |
71 | | * |
72 | | * - CONNECTION_STATE_HEADER: Some bytes of an incoming frame have |
73 | | * been seen, but not a complete frame header's worth. |
74 | | * |
75 | | * - CONNECTION_STATE_BODY: A complete frame header has been seen, but |
76 | | * the frame is not yet complete. When it is completed, it will be |
77 | | * returned, and the connection will return to IDLE state. |
78 | | * |
79 | | */ |
80 | | typedef enum amqp_connection_state_enum_ { |
81 | | CONNECTION_STATE_IDLE = 0, |
82 | | CONNECTION_STATE_INITIAL, |
83 | | CONNECTION_STATE_HEADER, |
84 | | CONNECTION_STATE_BODY |
85 | | } amqp_connection_state_enum; |
86 | | |
87 | | typedef enum amqp_status_private_enum_ { |
88 | | /* 0x00xx -> AMQP_STATUS_*/ |
89 | | /* 0x01xx -> AMQP_STATUS_TCP_* */ |
90 | | /* 0x02xx -> AMQP_STATUS_SSL_* */ |
91 | | AMQP_PRIVATE_STATUS_SOCKET_NEEDREAD = -0x1301, |
92 | | AMQP_PRIVATE_STATUS_SOCKET_NEEDWRITE = -0x1302 |
93 | | } amqp_status_private_enum; |
94 | | |
95 | | /* 7 bytes up front, then payload, then 1 byte footer */ |
96 | 0 | #define HEADER_SIZE 7 |
97 | 0 | #define FOOTER_SIZE 1 |
98 | | |
99 | 0 | #define AMQP_PSEUDOFRAME_PROTOCOL_HEADER 'A' |
100 | | |
101 | | typedef struct amqp_link_t_ { |
102 | | struct amqp_link_t_ *next; |
103 | | void *data; |
104 | | } amqp_link_t; |
105 | | |
106 | 0 | #define POOL_TABLE_SIZE 16 |
107 | | |
108 | | typedef struct amqp_pool_table_entry_t_ { |
109 | | struct amqp_pool_table_entry_t_ *next; |
110 | | amqp_pool_t pool; |
111 | | amqp_channel_t channel; |
112 | | } amqp_pool_table_entry_t; |
113 | | |
114 | | struct amqp_connection_state_t_ { |
115 | | amqp_pool_table_entry_t *pool_table[POOL_TABLE_SIZE]; |
116 | | |
117 | | amqp_connection_state_enum state; |
118 | | |
119 | | int channel_max; |
120 | | int frame_max; |
121 | | |
122 | | /* Heartbeat interval in seconds. If this is <= 0, then heartbeats are not |
123 | | * enabled, and next_recv_heartbeat and next_send_heartbeat are set to |
124 | | * infinite */ |
125 | | int heartbeat; |
126 | | amqp_time_t next_recv_heartbeat; |
127 | | amqp_time_t next_send_heartbeat; |
128 | | |
129 | | /* buffer for holding frame headers. Allows us to delay allocating |
130 | | * the raw frame buffer until the type, channel, and size are all known |
131 | | */ |
132 | | char header_buffer[HEADER_SIZE + 1]; |
133 | | amqp_bytes_t inbound_buffer; |
134 | | |
135 | | size_t inbound_offset; |
136 | | size_t target_size; |
137 | | |
138 | | amqp_bytes_t outbound_buffer; |
139 | | |
140 | | amqp_socket_t *socket; |
141 | | |
142 | | amqp_bytes_t sock_inbound_buffer; |
143 | | size_t sock_inbound_offset; |
144 | | size_t sock_inbound_limit; |
145 | | |
146 | | amqp_link_t *first_queued_frame; |
147 | | amqp_link_t *last_queued_frame; |
148 | | |
149 | | amqp_rpc_reply_t most_recent_api_result; |
150 | | |
151 | | amqp_table_t server_properties; |
152 | | amqp_table_t client_properties; |
153 | | amqp_pool_t properties_pool; |
154 | | |
155 | | struct timeval *handshake_timeout; |
156 | | struct timeval internal_handshake_timeout; |
157 | | struct timeval *rpc_timeout; |
158 | | struct timeval internal_rpc_timeout; |
159 | | }; |
160 | | |
161 | | amqp_pool_t *amqp_get_or_create_channel_pool(amqp_connection_state_t connection, |
162 | | amqp_channel_t channel); |
163 | | amqp_pool_t *amqp_get_channel_pool(amqp_connection_state_t state, |
164 | | amqp_channel_t channel); |
165 | | |
166 | 0 | static inline int amqp_heartbeat_send(amqp_connection_state_t state) { |
167 | 0 | return state->heartbeat; |
168 | 0 | } Unexecuted instantiation: amqp_api.c:amqp_heartbeat_send Unexecuted instantiation: amqp_connection.c:amqp_heartbeat_send Unexecuted instantiation: amqp_framing.c:amqp_heartbeat_send Unexecuted instantiation: amqp_mem.c:amqp_heartbeat_send Unexecuted instantiation: amqp_socket.c:amqp_heartbeat_send Unexecuted instantiation: amqp_table.c:amqp_heartbeat_send Unexecuted instantiation: amqp_tcp_socket.c:amqp_heartbeat_send Unexecuted instantiation: amqp_url.c:amqp_heartbeat_send |
169 | | |
170 | 0 | static inline int amqp_heartbeat_recv(amqp_connection_state_t state) { |
171 | 0 | return 2 * state->heartbeat; |
172 | 0 | } Unexecuted instantiation: amqp_api.c:amqp_heartbeat_recv Unexecuted instantiation: amqp_connection.c:amqp_heartbeat_recv Unexecuted instantiation: amqp_framing.c:amqp_heartbeat_recv Unexecuted instantiation: amqp_mem.c:amqp_heartbeat_recv Unexecuted instantiation: amqp_socket.c:amqp_heartbeat_recv Unexecuted instantiation: amqp_table.c:amqp_heartbeat_recv Unexecuted instantiation: amqp_tcp_socket.c:amqp_heartbeat_recv Unexecuted instantiation: amqp_url.c:amqp_heartbeat_recv |
173 | | |
174 | | int amqp_try_recv(amqp_connection_state_t state); |
175 | | |
176 | 20.2M | static inline void *amqp_offset(void *data, size_t offset) { |
177 | 20.2M | return (char *)data + offset; |
178 | 20.2M | } Unexecuted instantiation: amqp_api.c:amqp_offset Unexecuted instantiation: amqp_connection.c:amqp_offset Unexecuted instantiation: amqp_framing.c:amqp_offset Unexecuted instantiation: amqp_mem.c:amqp_offset Unexecuted instantiation: amqp_socket.c:amqp_offset Line | Count | Source | 176 | 20.2M | static inline void *amqp_offset(void *data, size_t offset) { | 177 | 20.2M | return (char *)data + offset; | 178 | 20.2M | } |
Unexecuted instantiation: amqp_tcp_socket.c:amqp_offset Unexecuted instantiation: amqp_url.c:amqp_offset |
179 | | |
180 | | /* This macro defines the encoding and decoding functions associated with a |
181 | | simple type. */ |
182 | | |
183 | | #define DECLARE_CODEC_BASE_TYPE(bits) \ |
184 | | \ |
185 | | static inline int amqp_encode_##bits(amqp_bytes_t encoded, size_t *offset, \ |
186 | 0 | uint##bits##_t input) { \ |
187 | 0 | size_t o = *offset; \ |
188 | 0 | if ((*offset = o + bits / 8) <= encoded.len) { \ |
189 | 0 | amqp_e##bits(input, amqp_offset(encoded.bytes, o)); \ |
190 | 0 | return 1; \ |
191 | 0 | } \ |
192 | 0 | return 0; \ |
193 | 0 | } \ Unexecuted instantiation: amqp_api.c:amqp_encode_8 Unexecuted instantiation: amqp_api.c:amqp_encode_16 Unexecuted instantiation: amqp_api.c:amqp_encode_32 Unexecuted instantiation: amqp_api.c:amqp_encode_64 Unexecuted instantiation: amqp_connection.c:amqp_encode_8 Unexecuted instantiation: amqp_connection.c:amqp_encode_16 Unexecuted instantiation: amqp_connection.c:amqp_encode_32 Unexecuted instantiation: amqp_connection.c:amqp_encode_64 Unexecuted instantiation: amqp_framing.c:amqp_encode_8 Unexecuted instantiation: amqp_framing.c:amqp_encode_32 Unexecuted instantiation: amqp_framing.c:amqp_encode_16 Unexecuted instantiation: amqp_framing.c:amqp_encode_64 Unexecuted instantiation: amqp_mem.c:amqp_encode_8 Unexecuted instantiation: amqp_mem.c:amqp_encode_16 Unexecuted instantiation: amqp_mem.c:amqp_encode_32 Unexecuted instantiation: amqp_mem.c:amqp_encode_64 Unexecuted instantiation: amqp_socket.c:amqp_encode_8 Unexecuted instantiation: amqp_socket.c:amqp_encode_16 Unexecuted instantiation: amqp_socket.c:amqp_encode_32 Unexecuted instantiation: amqp_socket.c:amqp_encode_64 Unexecuted instantiation: amqp_table.c:amqp_encode_8 Unexecuted instantiation: amqp_table.c:amqp_encode_32 Unexecuted instantiation: amqp_table.c:amqp_encode_16 Unexecuted instantiation: amqp_table.c:amqp_encode_64 Unexecuted instantiation: amqp_tcp_socket.c:amqp_encode_8 Unexecuted instantiation: amqp_tcp_socket.c:amqp_encode_16 Unexecuted instantiation: amqp_tcp_socket.c:amqp_encode_32 Unexecuted instantiation: amqp_tcp_socket.c:amqp_encode_64 Unexecuted instantiation: amqp_url.c:amqp_encode_8 Unexecuted instantiation: amqp_url.c:amqp_encode_16 Unexecuted instantiation: amqp_url.c:amqp_encode_32 Unexecuted instantiation: amqp_url.c:amqp_encode_64 |
194 | | \ |
195 | | static inline int amqp_decode_##bits(amqp_bytes_t encoded, size_t *offset, \ |
196 | 19.6M | uint##bits##_t *output) { \ |
197 | 19.6M | size_t o = *offset; \ |
198 | 19.6M | if ((*offset = o + bits / 8) <= encoded.len) { \ |
199 | 19.6M | *output = amqp_d##bits(amqp_offset(encoded.bytes, o)); \ |
200 | 19.6M | return 1; \ |
201 | 19.6M | } \ |
202 | 19.6M | return 0; \ |
203 | 19.6M | } Unexecuted instantiation: amqp_api.c:amqp_decode_8 Unexecuted instantiation: amqp_api.c:amqp_decode_16 Unexecuted instantiation: amqp_api.c:amqp_decode_32 Unexecuted instantiation: amqp_api.c:amqp_decode_64 Unexecuted instantiation: amqp_connection.c:amqp_decode_8 Unexecuted instantiation: amqp_connection.c:amqp_decode_16 Unexecuted instantiation: amqp_connection.c:amqp_decode_32 Unexecuted instantiation: amqp_connection.c:amqp_decode_64 Unexecuted instantiation: amqp_framing.c:amqp_decode_8 Unexecuted instantiation: amqp_framing.c:amqp_decode_32 Unexecuted instantiation: amqp_framing.c:amqp_decode_16 Unexecuted instantiation: amqp_framing.c:amqp_decode_64 Unexecuted instantiation: amqp_mem.c:amqp_decode_8 Unexecuted instantiation: amqp_mem.c:amqp_decode_16 Unexecuted instantiation: amqp_mem.c:amqp_decode_32 Unexecuted instantiation: amqp_mem.c:amqp_decode_64 Unexecuted instantiation: amqp_socket.c:amqp_decode_8 Unexecuted instantiation: amqp_socket.c:amqp_decode_16 Unexecuted instantiation: amqp_socket.c:amqp_decode_32 Unexecuted instantiation: amqp_socket.c:amqp_decode_64 amqp_table.c:amqp_decode_32 Line | Count | Source | 196 | 342k | uint##bits##_t *output) { \ | 197 | 342k | size_t o = *offset; \ | 198 | 342k | if ((*offset = o + bits / 8) <= encoded.len) { \ | 199 | 341k | *output = amqp_d##bits(amqp_offset(encoded.bytes, o)); \ | 200 | 341k | return 1; \ | 201 | 341k | } \ | 202 | 342k | return 0; \ | 203 | 342k | } |
amqp_table.c:amqp_decode_8 Line | Count | Source | 196 | 18.4M | uint##bits##_t *output) { \ | 197 | 18.4M | size_t o = *offset; \ | 198 | 18.4M | if ((*offset = o + bits / 8) <= encoded.len) { \ | 199 | 18.4M | *output = amqp_d##bits(amqp_offset(encoded.bytes, o)); \ | 200 | 18.4M | return 1; \ | 201 | 18.4M | } \ | 202 | 18.4M | return 0; \ | 203 | 18.4M | } |
amqp_table.c:amqp_decode_16 Line | Count | Source | 196 | 723k | uint##bits##_t *output) { \ | 197 | 723k | size_t o = *offset; \ | 198 | 723k | if ((*offset = o + bits / 8) <= encoded.len) { \ | 199 | 723k | *output = amqp_d##bits(amqp_offset(encoded.bytes, o)); \ | 200 | 723k | return 1; \ | 201 | 723k | } \ | 202 | 723k | return 0; \ | 203 | 723k | } |
amqp_table.c:amqp_decode_64 Line | Count | Source | 196 | 174k | uint##bits##_t *output) { \ | 197 | 174k | size_t o = *offset; \ | 198 | 174k | if ((*offset = o + bits / 8) <= encoded.len) { \ | 199 | 174k | *output = amqp_d##bits(amqp_offset(encoded.bytes, o)); \ | 200 | 174k | return 1; \ | 201 | 174k | } \ | 202 | 174k | return 0; \ | 203 | 174k | } |
Unexecuted instantiation: amqp_tcp_socket.c:amqp_decode_8 Unexecuted instantiation: amqp_tcp_socket.c:amqp_decode_16 Unexecuted instantiation: amqp_tcp_socket.c:amqp_decode_32 Unexecuted instantiation: amqp_tcp_socket.c:amqp_decode_64 Unexecuted instantiation: amqp_url.c:amqp_decode_8 Unexecuted instantiation: amqp_url.c:amqp_decode_16 Unexecuted instantiation: amqp_url.c:amqp_decode_32 Unexecuted instantiation: amqp_url.c:amqp_decode_64 |
204 | | |
205 | 1.24M | static inline int is_bigendian(void) { |
206 | 1.24M | union { |
207 | 1.24M | uint32_t i; |
208 | 1.24M | char c[4]; |
209 | 1.24M | } bint = {0x01020304}; |
210 | 1.24M | return bint.c[0] == 1; |
211 | 1.24M | } Unexecuted instantiation: amqp_api.c:is_bigendian Unexecuted instantiation: amqp_connection.c:is_bigendian Unexecuted instantiation: amqp_framing.c:is_bigendian Unexecuted instantiation: amqp_mem.c:is_bigendian Unexecuted instantiation: amqp_socket.c:is_bigendian amqp_table.c:is_bigendian Line | Count | Source | 205 | 1.24M | static inline int is_bigendian(void) { | 206 | 1.24M | union { | 207 | 1.24M | uint32_t i; | 208 | 1.24M | char c[4]; | 209 | 1.24M | } bint = {0x01020304}; | 210 | 1.24M | return bint.c[0] == 1; | 211 | 1.24M | } |
Unexecuted instantiation: amqp_tcp_socket.c:is_bigendian Unexecuted instantiation: amqp_url.c:is_bigendian |
212 | | |
213 | 0 | static inline void amqp_e8(uint8_t val, void *data) { |
214 | 0 | memcpy(data, &val, sizeof(val)); |
215 | 0 | } Unexecuted instantiation: amqp_api.c:amqp_e8 Unexecuted instantiation: amqp_connection.c:amqp_e8 Unexecuted instantiation: amqp_framing.c:amqp_e8 Unexecuted instantiation: amqp_mem.c:amqp_e8 Unexecuted instantiation: amqp_socket.c:amqp_e8 Unexecuted instantiation: amqp_table.c:amqp_e8 Unexecuted instantiation: amqp_tcp_socket.c:amqp_e8 Unexecuted instantiation: amqp_url.c:amqp_e8 |
216 | | |
217 | 18.4M | static inline uint8_t amqp_d8(void *data) { |
218 | 18.4M | uint8_t val; |
219 | 18.4M | memcpy(&val, data, sizeof(val)); |
220 | 18.4M | return val; |
221 | 18.4M | } Unexecuted instantiation: amqp_api.c:amqp_d8 Unexecuted instantiation: amqp_connection.c:amqp_d8 Unexecuted instantiation: amqp_framing.c:amqp_d8 Unexecuted instantiation: amqp_mem.c:amqp_d8 Unexecuted instantiation: amqp_socket.c:amqp_d8 Line | Count | Source | 217 | 18.4M | static inline uint8_t amqp_d8(void *data) { | 218 | 18.4M | uint8_t val; | 219 | 18.4M | memcpy(&val, data, sizeof(val)); | 220 | 18.4M | return val; | 221 | 18.4M | } |
Unexecuted instantiation: amqp_tcp_socket.c:amqp_d8 Unexecuted instantiation: amqp_url.c:amqp_d8 |
222 | | |
223 | 0 | static inline void amqp_e16(uint16_t val, void *data) { |
224 | 0 | if (!is_bigendian()) { |
225 | 0 | val = ((val & 0xFF00u) >> 8u) | ((val & 0x00FFu) << 8u); |
226 | 0 | } |
227 | 0 | memcpy(data, &val, sizeof(val)); |
228 | 0 | } Unexecuted instantiation: amqp_api.c:amqp_e16 Unexecuted instantiation: amqp_connection.c:amqp_e16 Unexecuted instantiation: amqp_framing.c:amqp_e16 Unexecuted instantiation: amqp_mem.c:amqp_e16 Unexecuted instantiation: amqp_socket.c:amqp_e16 Unexecuted instantiation: amqp_table.c:amqp_e16 Unexecuted instantiation: amqp_tcp_socket.c:amqp_e16 Unexecuted instantiation: amqp_url.c:amqp_e16 |
229 | | |
230 | 723k | static inline uint16_t amqp_d16(void *data) { |
231 | 723k | uint16_t val; |
232 | 723k | memcpy(&val, data, sizeof(val)); |
233 | 723k | if (!is_bigendian()) { |
234 | 723k | val = ((val & 0xFF00u) >> 8u) | ((val & 0x00FFu) << 8u); |
235 | 723k | } |
236 | 723k | return val; |
237 | 723k | } Unexecuted instantiation: amqp_api.c:amqp_d16 Unexecuted instantiation: amqp_connection.c:amqp_d16 Unexecuted instantiation: amqp_framing.c:amqp_d16 Unexecuted instantiation: amqp_mem.c:amqp_d16 Unexecuted instantiation: amqp_socket.c:amqp_d16 Line | Count | Source | 230 | 723k | static inline uint16_t amqp_d16(void *data) { | 231 | 723k | uint16_t val; | 232 | 723k | memcpy(&val, data, sizeof(val)); | 233 | 723k | if (!is_bigendian()) { | 234 | 723k | val = ((val & 0xFF00u) >> 8u) | ((val & 0x00FFu) << 8u); | 235 | 723k | } | 236 | 723k | return val; | 237 | 723k | } |
Unexecuted instantiation: amqp_tcp_socket.c:amqp_d16 Unexecuted instantiation: amqp_url.c:amqp_d16 |
238 | | |
239 | 0 | static inline void amqp_e32(uint32_t val, void *data) { |
240 | 0 | if (!is_bigendian()) { |
241 | 0 | val = ((val & 0xFF000000u) >> 24u) | ((val & 0x00FF0000u) >> 8u) | |
242 | 0 | ((val & 0x0000FF00u) << 8u) | ((val & 0x000000FFu) << 24u); |
243 | 0 | } |
244 | 0 | memcpy(data, &val, sizeof(val)); |
245 | 0 | } Unexecuted instantiation: amqp_api.c:amqp_e32 Unexecuted instantiation: amqp_connection.c:amqp_e32 Unexecuted instantiation: amqp_framing.c:amqp_e32 Unexecuted instantiation: amqp_mem.c:amqp_e32 Unexecuted instantiation: amqp_socket.c:amqp_e32 Unexecuted instantiation: amqp_table.c:amqp_e32 Unexecuted instantiation: amqp_tcp_socket.c:amqp_e32 Unexecuted instantiation: amqp_url.c:amqp_e32 |
246 | | |
247 | 341k | static inline uint32_t amqp_d32(void *data) { |
248 | 341k | uint32_t val; |
249 | 341k | memcpy(&val, data, sizeof(val)); |
250 | 341k | if (!is_bigendian()) { |
251 | 341k | val = ((val & 0xFF000000u) >> 24u) | ((val & 0x00FF0000u) >> 8u) | |
252 | 341k | ((val & 0x0000FF00u) << 8u) | ((val & 0x000000FFu) << 24u); |
253 | 341k | } |
254 | 341k | return val; |
255 | 341k | } Unexecuted instantiation: amqp_api.c:amqp_d32 Unexecuted instantiation: amqp_connection.c:amqp_d32 Unexecuted instantiation: amqp_framing.c:amqp_d32 Unexecuted instantiation: amqp_mem.c:amqp_d32 Unexecuted instantiation: amqp_socket.c:amqp_d32 Line | Count | Source | 247 | 341k | static inline uint32_t amqp_d32(void *data) { | 248 | 341k | uint32_t val; | 249 | 341k | memcpy(&val, data, sizeof(val)); | 250 | 341k | if (!is_bigendian()) { | 251 | 341k | val = ((val & 0xFF000000u) >> 24u) | ((val & 0x00FF0000u) >> 8u) | | 252 | 341k | ((val & 0x0000FF00u) << 8u) | ((val & 0x000000FFu) << 24u); | 253 | 341k | } | 254 | 341k | return val; | 255 | 341k | } |
Unexecuted instantiation: amqp_tcp_socket.c:amqp_d32 Unexecuted instantiation: amqp_url.c:amqp_d32 |
256 | | |
257 | 0 | static inline void amqp_e64(uint64_t val, void *data) { |
258 | 0 | if (!is_bigendian()) { |
259 | 0 | val = ((val & 0xFF00000000000000u) >> 56u) | |
260 | 0 | ((val & 0x00FF000000000000u) >> 40u) | |
261 | 0 | ((val & 0x0000FF0000000000u) >> 24u) | |
262 | 0 | ((val & 0x000000FF00000000u) >> 8u) | |
263 | 0 | ((val & 0x00000000FF000000u) << 8u) | |
264 | 0 | ((val & 0x0000000000FF0000u) << 24u) | |
265 | 0 | ((val & 0x000000000000FF00u) << 40u) | |
266 | 0 | ((val & 0x00000000000000FFu) << 56u); |
267 | 0 | } |
268 | 0 | memcpy(data, &val, sizeof(val)); |
269 | 0 | } Unexecuted instantiation: amqp_api.c:amqp_e64 Unexecuted instantiation: amqp_connection.c:amqp_e64 Unexecuted instantiation: amqp_framing.c:amqp_e64 Unexecuted instantiation: amqp_mem.c:amqp_e64 Unexecuted instantiation: amqp_socket.c:amqp_e64 Unexecuted instantiation: amqp_table.c:amqp_e64 Unexecuted instantiation: amqp_tcp_socket.c:amqp_e64 Unexecuted instantiation: amqp_url.c:amqp_e64 |
270 | | |
271 | 174k | static inline uint64_t amqp_d64(void *data) { |
272 | 174k | uint64_t val; |
273 | 174k | memcpy(&val, data, sizeof(val)); |
274 | 174k | if (!is_bigendian()) { |
275 | 174k | val = ((val & 0xFF00000000000000u) >> 56u) | |
276 | 174k | ((val & 0x00FF000000000000u) >> 40u) | |
277 | 174k | ((val & 0x0000FF0000000000u) >> 24u) | |
278 | 174k | ((val & 0x000000FF00000000u) >> 8u) | |
279 | 174k | ((val & 0x00000000FF000000u) << 8u) | |
280 | 174k | ((val & 0x0000000000FF0000u) << 24u) | |
281 | 174k | ((val & 0x000000000000FF00u) << 40u) | |
282 | 174k | ((val & 0x00000000000000FFu) << 56u); |
283 | 174k | } |
284 | 174k | return val; |
285 | 174k | } Unexecuted instantiation: amqp_api.c:amqp_d64 Unexecuted instantiation: amqp_connection.c:amqp_d64 Unexecuted instantiation: amqp_framing.c:amqp_d64 Unexecuted instantiation: amqp_mem.c:amqp_d64 Unexecuted instantiation: amqp_socket.c:amqp_d64 Line | Count | Source | 271 | 174k | static inline uint64_t amqp_d64(void *data) { | 272 | 174k | uint64_t val; | 273 | 174k | memcpy(&val, data, sizeof(val)); | 274 | 174k | if (!is_bigendian()) { | 275 | 174k | val = ((val & 0xFF00000000000000u) >> 56u) | | 276 | 174k | ((val & 0x00FF000000000000u) >> 40u) | | 277 | 174k | ((val & 0x0000FF0000000000u) >> 24u) | | 278 | 174k | ((val & 0x000000FF00000000u) >> 8u) | | 279 | 174k | ((val & 0x00000000FF000000u) << 8u) | | 280 | 174k | ((val & 0x0000000000FF0000u) << 24u) | | 281 | 174k | ((val & 0x000000000000FF00u) << 40u) | | 282 | 174k | ((val & 0x00000000000000FFu) << 56u); | 283 | 174k | } | 284 | 174k | return val; | 285 | 174k | } |
Unexecuted instantiation: amqp_tcp_socket.c:amqp_d64 Unexecuted instantiation: amqp_url.c:amqp_d64 |
286 | | |
287 | | DECLARE_CODEC_BASE_TYPE(8) |
288 | | DECLARE_CODEC_BASE_TYPE(16) |
289 | | DECLARE_CODEC_BASE_TYPE(32) |
290 | | DECLARE_CODEC_BASE_TYPE(64) |
291 | | |
292 | | static inline int amqp_encode_bytes(amqp_bytes_t encoded, size_t *offset, |
293 | 0 | amqp_bytes_t input) { |
294 | 0 | size_t o = *offset; |
295 | | /* The memcpy below has undefined behavior if the input is NULL. It is valid |
296 | | * for a 0-length amqp_bytes_t to have .bytes == NULL. Thus we should check |
297 | | * before encoding. |
298 | | */ |
299 | 0 | if (input.len == 0) { |
300 | 0 | return 1; |
301 | 0 | } |
302 | 0 | if ((*offset = o + input.len) <= encoded.len) { |
303 | 0 | memcpy(amqp_offset(encoded.bytes, o), input.bytes, input.len); |
304 | 0 | return 1; |
305 | 0 | } else { |
306 | 0 | return 0; |
307 | 0 | } |
308 | 0 | } Unexecuted instantiation: amqp_api.c:amqp_encode_bytes Unexecuted instantiation: amqp_connection.c:amqp_encode_bytes Unexecuted instantiation: amqp_framing.c:amqp_encode_bytes Unexecuted instantiation: amqp_mem.c:amqp_encode_bytes Unexecuted instantiation: amqp_socket.c:amqp_encode_bytes Unexecuted instantiation: amqp_table.c:amqp_encode_bytes Unexecuted instantiation: amqp_tcp_socket.c:amqp_encode_bytes Unexecuted instantiation: amqp_url.c:amqp_encode_bytes |
309 | | |
310 | | static inline int amqp_decode_bytes(amqp_bytes_t encoded, size_t *offset, |
311 | 577k | amqp_bytes_t *output, size_t len) { |
312 | 577k | size_t o = *offset; |
313 | 577k | if ((*offset = o + len) <= encoded.len) { |
314 | 577k | output->bytes = amqp_offset(encoded.bytes, o); |
315 | 577k | output->len = len; |
316 | 577k | return 1; |
317 | 577k | } else { |
318 | 94 | return 0; |
319 | 94 | } |
320 | 577k | } Unexecuted instantiation: amqp_api.c:amqp_decode_bytes Unexecuted instantiation: amqp_connection.c:amqp_decode_bytes Unexecuted instantiation: amqp_framing.c:amqp_decode_bytes Unexecuted instantiation: amqp_mem.c:amqp_decode_bytes Unexecuted instantiation: amqp_socket.c:amqp_decode_bytes amqp_table.c:amqp_decode_bytes Line | Count | Source | 311 | 577k | amqp_bytes_t *output, size_t len) { | 312 | 577k | size_t o = *offset; | 313 | 577k | if ((*offset = o + len) <= encoded.len) { | 314 | 577k | output->bytes = amqp_offset(encoded.bytes, o); | 315 | 577k | output->len = len; | 316 | 577k | return 1; | 317 | 577k | } else { | 318 | 94 | return 0; | 319 | 94 | } | 320 | 577k | } |
Unexecuted instantiation: amqp_tcp_socket.c:amqp_decode_bytes Unexecuted instantiation: amqp_url.c:amqp_decode_bytes |
321 | | |
322 | | AMQP_NORETURN |
323 | | void amqp_abort(const char *fmt, ...); |
324 | | |
325 | | int amqp_bytes_equal(amqp_bytes_t r, amqp_bytes_t l); |
326 | | |
327 | 0 | static inline amqp_rpc_reply_t amqp_rpc_reply_error(amqp_status_enum status) { |
328 | 0 | amqp_rpc_reply_t reply; |
329 | 0 | reply.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; |
330 | 0 | reply.library_error = status; |
331 | 0 | return reply; |
332 | 0 | } Unexecuted instantiation: amqp_api.c:amqp_rpc_reply_error Unexecuted instantiation: amqp_connection.c:amqp_rpc_reply_error Unexecuted instantiation: amqp_framing.c:amqp_rpc_reply_error Unexecuted instantiation: amqp_mem.c:amqp_rpc_reply_error Unexecuted instantiation: amqp_socket.c:amqp_rpc_reply_error Unexecuted instantiation: amqp_table.c:amqp_rpc_reply_error Unexecuted instantiation: amqp_tcp_socket.c:amqp_rpc_reply_error Unexecuted instantiation: amqp_url.c:amqp_rpc_reply_error |
333 | | |
334 | | int amqp_send_frame_inner(amqp_connection_state_t state, |
335 | | const amqp_frame_t *frame, int flags, |
336 | | amqp_time_t deadline); |
337 | | #endif |