Coverage Report

Created: 2026-08-13 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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_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_api.c:amqp_heartbeat_send
Unexecuted instantiation: amqp_connection.c:amqp_heartbeat_send
Unexecuted instantiation: amqp_tcp_socket.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_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_api.c:amqp_heartbeat_recv
Unexecuted instantiation: amqp_connection.c:amqp_heartbeat_recv
Unexecuted instantiation: amqp_tcp_socket.c:amqp_heartbeat_recv
173
174
int amqp_try_recv(amqp_connection_state_t state);
175
176
27.9M
static inline void *amqp_offset(void *data, size_t offset) {
177
27.9M
  return (char *)data + offset;
178
27.9M
}
amqp_framing.c:amqp_offset
Line
Count
Source
176
39.1k
static inline void *amqp_offset(void *data, size_t offset) {
177
39.1k
  return (char *)data + offset;
178
39.1k
}
Unexecuted instantiation: amqp_mem.c:amqp_offset
Unexecuted instantiation: amqp_socket.c:amqp_offset
amqp_table.c:amqp_offset
Line
Count
Source
176
27.8M
static inline void *amqp_offset(void *data, size_t offset) {
177
27.8M
  return (char *)data + offset;
178
27.8M
}
Unexecuted instantiation: amqp_api.c:amqp_offset
Unexecuted instantiation: amqp_connection.c:amqp_offset
Unexecuted instantiation: amqp_tcp_socket.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
12.4M
                                       uint##bits##_t input) {               \
187
12.4M
    size_t o = *offset;                                                      \
188
12.4M
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
189
12.4M
      amqp_e##bits(input, amqp_offset(encoded.bytes, o));                    \
190
12.4M
      return 1;                                                              \
191
12.4M
    }                                                                        \
192
12.4M
    return 0;                                                                \
193
12.4M
  }                                                                          \
amqp_framing.c:amqp_encode_8
Line
Count
Source
186
8.04k
                                       uint##bits##_t input) {               \
187
8.04k
    size_t o = *offset;                                                      \
188
8.04k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
189
8.04k
      amqp_e##bits(input, amqp_offset(encoded.bytes, o));                    \
190
8.04k
      return 1;                                                              \
191
8.04k
    }                                                                        \
192
8.04k
    return 0;                                                                \
193
8.04k
  }                                                                          \
amqp_framing.c:amqp_encode_32
Line
Count
Source
186
776
                                       uint##bits##_t input) {               \
187
776
    size_t o = *offset;                                                      \
188
776
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
189
776
      amqp_e##bits(input, amqp_offset(encoded.bytes, o));                    \
190
776
      return 1;                                                              \
191
776
    }                                                                        \
192
776
    return 0;                                                                \
193
776
  }                                                                          \
amqp_framing.c:amqp_encode_16
Line
Count
Source
186
1.89k
                                       uint##bits##_t input) {               \
187
1.89k
    size_t o = *offset;                                                      \
188
1.89k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
189
1.89k
      amqp_e##bits(input, amqp_offset(encoded.bytes, o));                    \
190
1.89k
      return 1;                                                              \
191
1.89k
    }                                                                        \
192
1.89k
    return 0;                                                                \
193
1.89k
  }                                                                          \
amqp_framing.c:amqp_encode_64
Line
Count
Source
186
521
                                       uint##bits##_t input) {               \
187
521
    size_t o = *offset;                                                      \
188
521
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
189
521
      amqp_e##bits(input, amqp_offset(encoded.bytes, o));                    \
190
521
      return 1;                                                              \
191
521
    }                                                                        \
192
521
    return 0;                                                                \
193
521
  }                                                                          \
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
amqp_table.c:amqp_encode_8
Line
Count
Source
186
11.3M
                                       uint##bits##_t input) {               \
187
11.3M
    size_t o = *offset;                                                      \
188
11.3M
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
189
11.3M
      amqp_e##bits(input, amqp_offset(encoded.bytes, o));                    \
190
11.3M
      return 1;                                                              \
191
11.3M
    }                                                                        \
192
11.3M
    return 0;                                                                \
193
11.3M
  }                                                                          \
amqp_table.c:amqp_encode_32
Line
Count
Source
186
584k
                                       uint##bits##_t input) {               \
187
584k
    size_t o = *offset;                                                      \
188
584k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
189
584k
      amqp_e##bits(input, amqp_offset(encoded.bytes, o));                    \
190
584k
      return 1;                                                              \
191
584k
    }                                                                        \
192
584k
    return 0;                                                                \
193
584k
  }                                                                          \
amqp_table.c:amqp_encode_16
Line
Count
Source
186
328k
                                       uint##bits##_t input) {               \
187
328k
    size_t o = *offset;                                                      \
188
328k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
189
328k
      amqp_e##bits(input, amqp_offset(encoded.bytes, o));                    \
190
328k
      return 1;                                                              \
191
328k
    }                                                                        \
192
328k
    return 0;                                                                \
193
328k
  }                                                                          \
amqp_table.c:amqp_encode_64
Line
Count
Source
186
216k
                                       uint##bits##_t input) {               \
187
216k
    size_t o = *offset;                                                      \
188
216k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
189
216k
      amqp_e##bits(input, amqp_offset(encoded.bytes, o));                    \
190
216k
      return 1;                                                              \
191
216k
    }                                                                        \
192
216k
    return 0;                                                                \
193
216k
  }                                                                          \
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_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
194
                                                                             \
195
  static inline int amqp_decode_##bits(amqp_bytes_t encoded, size_t *offset, \
196
15.3M
                                       uint##bits##_t *output) {             \
197
15.3M
    size_t o = *offset;                                                      \
198
15.3M
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
199
15.3M
      *output = amqp_d##bits(amqp_offset(encoded.bytes, o));                 \
200
15.3M
      return 1;                                                              \
201
15.3M
    }                                                                        \
202
15.3M
    return 0;                                                                \
203
15.3M
  }
amqp_framing.c:amqp_decode_8
Line
Count
Source
196
11.2k
                                       uint##bits##_t *output) {             \
197
11.2k
    size_t o = *offset;                                                      \
198
11.2k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
199
10.9k
      *output = amqp_d##bits(amqp_offset(encoded.bytes, o));                 \
200
10.9k
      return 1;                                                              \
201
10.9k
    }                                                                        \
202
11.2k
    return 0;                                                                \
203
11.2k
  }
amqp_framing.c:amqp_decode_32
Line
Count
Source
196
1.35k
                                       uint##bits##_t *output) {             \
197
1.35k
    size_t o = *offset;                                                      \
198
1.35k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
199
1.30k
      *output = amqp_d##bits(amqp_offset(encoded.bytes, o));                 \
200
1.30k
      return 1;                                                              \
201
1.30k
    }                                                                        \
202
1.35k
    return 0;                                                                \
203
1.35k
  }
amqp_framing.c:amqp_decode_16
Line
Count
Source
196
2.95k
                                       uint##bits##_t *output) {             \
197
2.95k
    size_t o = *offset;                                                      \
198
2.95k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
199
2.89k
      *output = amqp_d##bits(amqp_offset(encoded.bytes, o));                 \
200
2.89k
      return 1;                                                              \
201
2.89k
    }                                                                        \
202
2.95k
    return 0;                                                                \
203
2.95k
  }
amqp_framing.c:amqp_decode_64
Line
Count
Source
196
662
                                       uint##bits##_t *output) {             \
197
662
    size_t o = *offset;                                                      \
198
662
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
199
618
      *output = amqp_d##bits(amqp_offset(encoded.bytes, o));                 \
200
618
      return 1;                                                              \
201
618
    }                                                                        \
202
662
    return 0;                                                                \
203
662
  }
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
815k
                                       uint##bits##_t *output) {             \
197
815k
    size_t o = *offset;                                                      \
198
815k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
199
815k
      *output = amqp_d##bits(amqp_offset(encoded.bytes, o));                 \
200
815k
      return 1;                                                              \
201
815k
    }                                                                        \
202
815k
    return 0;                                                                \
203
815k
  }
amqp_table.c:amqp_decode_8
Line
Count
Source
196
13.7M
                                       uint##bits##_t *output) {             \
197
13.7M
    size_t o = *offset;                                                      \
198
13.7M
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
199
13.7M
      *output = amqp_d##bits(amqp_offset(encoded.bytes, o));                 \
200
13.7M
      return 1;                                                              \
201
13.7M
    }                                                                        \
202
13.7M
    return 0;                                                                \
203
13.7M
  }
amqp_table.c:amqp_decode_16
Line
Count
Source
196
381k
                                       uint##bits##_t *output) {             \
197
381k
    size_t o = *offset;                                                      \
198
381k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
199
381k
      *output = amqp_d##bits(amqp_offset(encoded.bytes, o));                 \
200
381k
      return 1;                                                              \
201
381k
    }                                                                        \
202
381k
    return 0;                                                                \
203
381k
  }
amqp_table.c:amqp_decode_64
Line
Count
Source
196
319k
                                       uint##bits##_t *output) {             \
197
319k
    size_t o = *offset;                                                      \
198
319k
    if ((*offset = o + bits / 8) <= encoded.len) {                           \
199
319k
      *output = amqp_d##bits(amqp_offset(encoded.bytes, o));                 \
200
319k
      return 1;                                                              \
201
319k
    }                                                                        \
202
319k
    return 0;                                                                \
203
319k
  }
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_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
204
205
2.65M
static inline int is_bigendian(void) {
206
2.65M
  union {
207
2.65M
    uint32_t i;
208
2.65M
    char c[4];
209
2.65M
  } bint = {0x01020304};
210
2.65M
  return bint.c[0] == 1;
211
2.65M
}
amqp_framing.c:is_bigendian
Line
Count
Source
205
8.00k
static inline int is_bigendian(void) {
206
8.00k
  union {
207
8.00k
    uint32_t i;
208
8.00k
    char c[4];
209
8.00k
  } bint = {0x01020304};
210
8.00k
  return bint.c[0] == 1;
211
8.00k
}
Unexecuted instantiation: amqp_mem.c:is_bigendian
Unexecuted instantiation: amqp_socket.c:is_bigendian
amqp_table.c:is_bigendian
Line
Count
Source
205
2.64M
static inline int is_bigendian(void) {
206
2.64M
  union {
207
2.64M
    uint32_t i;
208
2.64M
    char c[4];
209
2.64M
  } bint = {0x01020304};
210
2.64M
  return bint.c[0] == 1;
211
2.64M
}
Unexecuted instantiation: amqp_api.c:is_bigendian
Unexecuted instantiation: amqp_connection.c:is_bigendian
Unexecuted instantiation: amqp_tcp_socket.c:is_bigendian
212
213
11.3M
static inline void amqp_e8(uint8_t val, void *data) {
214
11.3M
  memcpy(data, &val, sizeof(val));
215
11.3M
}
amqp_framing.c:amqp_e8
Line
Count
Source
213
8.04k
static inline void amqp_e8(uint8_t val, void *data) {
214
8.04k
  memcpy(data, &val, sizeof(val));
215
8.04k
}
Unexecuted instantiation: amqp_mem.c:amqp_e8
Unexecuted instantiation: amqp_socket.c:amqp_e8
amqp_table.c:amqp_e8
Line
Count
Source
213
11.3M
static inline void amqp_e8(uint8_t val, void *data) {
214
11.3M
  memcpy(data, &val, sizeof(val));
215
11.3M
}
Unexecuted instantiation: amqp_api.c:amqp_e8
Unexecuted instantiation: amqp_connection.c:amqp_e8
Unexecuted instantiation: amqp_tcp_socket.c:amqp_e8
216
217
13.7M
static inline uint8_t amqp_d8(void *data) {
218
13.7M
  uint8_t val;
219
13.7M
  memcpy(&val, data, sizeof(val));
220
13.7M
  return val;
221
13.7M
}
amqp_framing.c:amqp_d8
Line
Count
Source
217
10.9k
static inline uint8_t amqp_d8(void *data) {
218
10.9k
  uint8_t val;
219
10.9k
  memcpy(&val, data, sizeof(val));
220
10.9k
  return val;
221
10.9k
}
Unexecuted instantiation: amqp_mem.c:amqp_d8
Unexecuted instantiation: amqp_socket.c:amqp_d8
amqp_table.c:amqp_d8
Line
Count
Source
217
13.7M
static inline uint8_t amqp_d8(void *data) {
218
13.7M
  uint8_t val;
219
13.7M
  memcpy(&val, data, sizeof(val));
220
13.7M
  return val;
221
13.7M
}
Unexecuted instantiation: amqp_api.c:amqp_d8
Unexecuted instantiation: amqp_connection.c:amqp_d8
Unexecuted instantiation: amqp_tcp_socket.c:amqp_d8
222
223
330k
static inline void amqp_e16(uint16_t val, void *data) {
224
330k
  if (!is_bigendian()) {
225
330k
    val = ((val & 0xFF00u) >> 8u) | ((val & 0x00FFu) << 8u);
226
330k
  }
227
330k
  memcpy(data, &val, sizeof(val));
228
330k
}
amqp_framing.c:amqp_e16
Line
Count
Source
223
1.89k
static inline void amqp_e16(uint16_t val, void *data) {
224
1.89k
  if (!is_bigendian()) {
225
1.89k
    val = ((val & 0xFF00u) >> 8u) | ((val & 0x00FFu) << 8u);
226
1.89k
  }
227
1.89k
  memcpy(data, &val, sizeof(val));
228
1.89k
}
Unexecuted instantiation: amqp_mem.c:amqp_e16
Unexecuted instantiation: amqp_socket.c:amqp_e16
amqp_table.c:amqp_e16
Line
Count
Source
223
328k
static inline void amqp_e16(uint16_t val, void *data) {
224
328k
  if (!is_bigendian()) {
225
328k
    val = ((val & 0xFF00u) >> 8u) | ((val & 0x00FFu) << 8u);
226
328k
  }
227
328k
  memcpy(data, &val, sizeof(val));
228
328k
}
Unexecuted instantiation: amqp_api.c:amqp_e16
Unexecuted instantiation: amqp_connection.c:amqp_e16
Unexecuted instantiation: amqp_tcp_socket.c:amqp_e16
229
230
384k
static inline uint16_t amqp_d16(void *data) {
231
384k
  uint16_t val;
232
384k
  memcpy(&val, data, sizeof(val));
233
384k
  if (!is_bigendian()) {
234
384k
    val = ((val & 0xFF00u) >> 8u) | ((val & 0x00FFu) << 8u);
235
384k
  }
236
384k
  return val;
237
384k
}
amqp_framing.c:amqp_d16
Line
Count
Source
230
2.89k
static inline uint16_t amqp_d16(void *data) {
231
2.89k
  uint16_t val;
232
2.89k
  memcpy(&val, data, sizeof(val));
233
2.89k
  if (!is_bigendian()) {
234
2.89k
    val = ((val & 0xFF00u) >> 8u) | ((val & 0x00FFu) << 8u);
235
2.89k
  }
236
2.89k
  return val;
237
2.89k
}
Unexecuted instantiation: amqp_mem.c:amqp_d16
Unexecuted instantiation: amqp_socket.c:amqp_d16
amqp_table.c:amqp_d16
Line
Count
Source
230
381k
static inline uint16_t amqp_d16(void *data) {
231
381k
  uint16_t val;
232
381k
  memcpy(&val, data, sizeof(val));
233
381k
  if (!is_bigendian()) {
234
381k
    val = ((val & 0xFF00u) >> 8u) | ((val & 0x00FFu) << 8u);
235
381k
  }
236
381k
  return val;
237
381k
}
Unexecuted instantiation: amqp_api.c:amqp_d16
Unexecuted instantiation: amqp_connection.c:amqp_d16
Unexecuted instantiation: amqp_tcp_socket.c:amqp_d16
238
239
584k
static inline void amqp_e32(uint32_t val, void *data) {
240
584k
  if (!is_bigendian()) {
241
584k
    val = ((val & 0xFF000000u) >> 24u) | ((val & 0x00FF0000u) >> 8u) |
242
584k
          ((val & 0x0000FF00u) << 8u) | ((val & 0x000000FFu) << 24u);
243
584k
  }
244
584k
  memcpy(data, &val, sizeof(val));
245
584k
}
amqp_framing.c:amqp_e32
Line
Count
Source
239
776
static inline void amqp_e32(uint32_t val, void *data) {
240
776
  if (!is_bigendian()) {
241
776
    val = ((val & 0xFF000000u) >> 24u) | ((val & 0x00FF0000u) >> 8u) |
242
776
          ((val & 0x0000FF00u) << 8u) | ((val & 0x000000FFu) << 24u);
243
776
  }
244
776
  memcpy(data, &val, sizeof(val));
245
776
}
Unexecuted instantiation: amqp_mem.c:amqp_e32
Unexecuted instantiation: amqp_socket.c:amqp_e32
amqp_table.c:amqp_e32
Line
Count
Source
239
584k
static inline void amqp_e32(uint32_t val, void *data) {
240
584k
  if (!is_bigendian()) {
241
584k
    val = ((val & 0xFF000000u) >> 24u) | ((val & 0x00FF0000u) >> 8u) |
242
584k
          ((val & 0x0000FF00u) << 8u) | ((val & 0x000000FFu) << 24u);
243
584k
  }
244
584k
  memcpy(data, &val, sizeof(val));
245
584k
}
Unexecuted instantiation: amqp_api.c:amqp_e32
Unexecuted instantiation: amqp_connection.c:amqp_e32
Unexecuted instantiation: amqp_tcp_socket.c:amqp_e32
246
247
816k
static inline uint32_t amqp_d32(void *data) {
248
816k
  uint32_t val;
249
816k
  memcpy(&val, data, sizeof(val));
250
816k
  if (!is_bigendian()) {
251
816k
    val = ((val & 0xFF000000u) >> 24u) | ((val & 0x00FF0000u) >> 8u) |
252
816k
          ((val & 0x0000FF00u) << 8u) | ((val & 0x000000FFu) << 24u);
253
816k
  }
254
816k
  return val;
255
816k
}
amqp_framing.c:amqp_d32
Line
Count
Source
247
1.30k
static inline uint32_t amqp_d32(void *data) {
248
1.30k
  uint32_t val;
249
1.30k
  memcpy(&val, data, sizeof(val));
250
1.30k
  if (!is_bigendian()) {
251
1.30k
    val = ((val & 0xFF000000u) >> 24u) | ((val & 0x00FF0000u) >> 8u) |
252
1.30k
          ((val & 0x0000FF00u) << 8u) | ((val & 0x000000FFu) << 24u);
253
1.30k
  }
254
1.30k
  return val;
255
1.30k
}
Unexecuted instantiation: amqp_mem.c:amqp_d32
Unexecuted instantiation: amqp_socket.c:amqp_d32
amqp_table.c:amqp_d32
Line
Count
Source
247
815k
static inline uint32_t amqp_d32(void *data) {
248
815k
  uint32_t val;
249
815k
  memcpy(&val, data, sizeof(val));
250
815k
  if (!is_bigendian()) {
251
815k
    val = ((val & 0xFF000000u) >> 24u) | ((val & 0x00FF0000u) >> 8u) |
252
815k
          ((val & 0x0000FF00u) << 8u) | ((val & 0x000000FFu) << 24u);
253
815k
  }
254
815k
  return val;
255
815k
}
Unexecuted instantiation: amqp_api.c:amqp_d32
Unexecuted instantiation: amqp_connection.c:amqp_d32
Unexecuted instantiation: amqp_tcp_socket.c:amqp_d32
256
257
217k
static inline void amqp_e64(uint64_t val, void *data) {
258
217k
  if (!is_bigendian()) {
259
217k
    val = ((val & 0xFF00000000000000u) >> 56u) |
260
217k
          ((val & 0x00FF000000000000u) >> 40u) |
261
217k
          ((val & 0x0000FF0000000000u) >> 24u) |
262
217k
          ((val & 0x000000FF00000000u) >> 8u) |
263
217k
          ((val & 0x00000000FF000000u) << 8u) |
264
217k
          ((val & 0x0000000000FF0000u) << 24u) |
265
217k
          ((val & 0x000000000000FF00u) << 40u) |
266
217k
          ((val & 0x00000000000000FFu) << 56u);
267
217k
  }
268
217k
  memcpy(data, &val, sizeof(val));
269
217k
}
amqp_framing.c:amqp_e64
Line
Count
Source
257
521
static inline void amqp_e64(uint64_t val, void *data) {
258
521
  if (!is_bigendian()) {
259
521
    val = ((val & 0xFF00000000000000u) >> 56u) |
260
521
          ((val & 0x00FF000000000000u) >> 40u) |
261
521
          ((val & 0x0000FF0000000000u) >> 24u) |
262
521
          ((val & 0x000000FF00000000u) >> 8u) |
263
521
          ((val & 0x00000000FF000000u) << 8u) |
264
521
          ((val & 0x0000000000FF0000u) << 24u) |
265
521
          ((val & 0x000000000000FF00u) << 40u) |
266
521
          ((val & 0x00000000000000FFu) << 56u);
267
521
  }
268
521
  memcpy(data, &val, sizeof(val));
269
521
}
Unexecuted instantiation: amqp_mem.c:amqp_e64
Unexecuted instantiation: amqp_socket.c:amqp_e64
amqp_table.c:amqp_e64
Line
Count
Source
257
216k
static inline void amqp_e64(uint64_t val, void *data) {
258
216k
  if (!is_bigendian()) {
259
216k
    val = ((val & 0xFF00000000000000u) >> 56u) |
260
216k
          ((val & 0x00FF000000000000u) >> 40u) |
261
216k
          ((val & 0x0000FF0000000000u) >> 24u) |
262
216k
          ((val & 0x000000FF00000000u) >> 8u) |
263
216k
          ((val & 0x00000000FF000000u) << 8u) |
264
216k
          ((val & 0x0000000000FF0000u) << 24u) |
265
216k
          ((val & 0x000000000000FF00u) << 40u) |
266
216k
          ((val & 0x00000000000000FFu) << 56u);
267
216k
  }
268
216k
  memcpy(data, &val, sizeof(val));
269
216k
}
Unexecuted instantiation: amqp_api.c:amqp_e64
Unexecuted instantiation: amqp_connection.c:amqp_e64
Unexecuted instantiation: amqp_tcp_socket.c:amqp_e64
270
271
320k
static inline uint64_t amqp_d64(void *data) {
272
320k
  uint64_t val;
273
320k
  memcpy(&val, data, sizeof(val));
274
320k
  if (!is_bigendian()) {
275
320k
    val = ((val & 0xFF00000000000000u) >> 56u) |
276
320k
          ((val & 0x00FF000000000000u) >> 40u) |
277
320k
          ((val & 0x0000FF0000000000u) >> 24u) |
278
320k
          ((val & 0x000000FF00000000u) >> 8u) |
279
320k
          ((val & 0x00000000FF000000u) << 8u) |
280
320k
          ((val & 0x0000000000FF0000u) << 24u) |
281
320k
          ((val & 0x000000000000FF00u) << 40u) |
282
320k
          ((val & 0x00000000000000FFu) << 56u);
283
320k
  }
284
320k
  return val;
285
320k
}
amqp_framing.c:amqp_d64
Line
Count
Source
271
618
static inline uint64_t amqp_d64(void *data) {
272
618
  uint64_t val;
273
618
  memcpy(&val, data, sizeof(val));
274
618
  if (!is_bigendian()) {
275
618
    val = ((val & 0xFF00000000000000u) >> 56u) |
276
618
          ((val & 0x00FF000000000000u) >> 40u) |
277
618
          ((val & 0x0000FF0000000000u) >> 24u) |
278
618
          ((val & 0x000000FF00000000u) >> 8u) |
279
618
          ((val & 0x00000000FF000000u) << 8u) |
280
618
          ((val & 0x0000000000FF0000u) << 24u) |
281
618
          ((val & 0x000000000000FF00u) << 40u) |
282
618
          ((val & 0x00000000000000FFu) << 56u);
283
618
  }
284
618
  return val;
285
618
}
Unexecuted instantiation: amqp_mem.c:amqp_d64
Unexecuted instantiation: amqp_socket.c:amqp_d64
amqp_table.c:amqp_d64
Line
Count
Source
271
319k
static inline uint64_t amqp_d64(void *data) {
272
319k
  uint64_t val;
273
319k
  memcpy(&val, data, sizeof(val));
274
319k
  if (!is_bigendian()) {
275
319k
    val = ((val & 0xFF00000000000000u) >> 56u) |
276
319k
          ((val & 0x00FF000000000000u) >> 40u) |
277
319k
          ((val & 0x0000FF0000000000u) >> 24u) |
278
319k
          ((val & 0x000000FF00000000u) >> 8u) |
279
319k
          ((val & 0x00000000FF000000u) << 8u) |
280
319k
          ((val & 0x0000000000FF0000u) << 24u) |
281
319k
          ((val & 0x000000000000FF00u) << 40u) |
282
319k
          ((val & 0x00000000000000FFu) << 56u);
283
319k
  }
284
319k
  return val;
285
319k
}
Unexecuted instantiation: amqp_api.c:amqp_d64
Unexecuted instantiation: amqp_connection.c:amqp_d64
Unexecuted instantiation: amqp_tcp_socket.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
55.7k
                                    amqp_bytes_t input) {
294
55.7k
  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
55.7k
  if (input.len == 0) {
300
24.1k
    return 1;
301
24.1k
  }
302
31.5k
  *offset = o + input.len;
303
  /* Compare against remaining space rather than o + input.len to avoid size_t
304
   * overflow; o <= encoded.len, so encoded.len - o cannot underflow. */
305
31.5k
  if (o <= encoded.len && input.len <= encoded.len - o) {
306
31.5k
    memcpy(amqp_offset(encoded.bytes, o), input.bytes, input.len);
307
31.5k
    return 1;
308
31.5k
  } else {
309
0
    return 0;
310
0
  }
311
31.5k
}
amqp_framing.c:amqp_encode_bytes
Line
Count
Source
293
6.58k
                                    amqp_bytes_t input) {
294
6.58k
  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
6.58k
  if (input.len == 0) {
300
2.72k
    return 1;
301
2.72k
  }
302
3.85k
  *offset = o + input.len;
303
  /* Compare against remaining space rather than o + input.len to avoid size_t
304
   * overflow; o <= encoded.len, so encoded.len - o cannot underflow. */
305
3.85k
  if (o <= encoded.len && input.len <= encoded.len - o) {
306
3.85k
    memcpy(amqp_offset(encoded.bytes, o), input.bytes, input.len);
307
3.85k
    return 1;
308
3.85k
  } else {
309
0
    return 0;
310
0
  }
311
3.85k
}
Unexecuted instantiation: amqp_mem.c:amqp_encode_bytes
Unexecuted instantiation: amqp_socket.c:amqp_encode_bytes
amqp_table.c:amqp_encode_bytes
Line
Count
Source
293
49.1k
                                    amqp_bytes_t input) {
294
49.1k
  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
49.1k
  if (input.len == 0) {
300
21.4k
    return 1;
301
21.4k
  }
302
27.7k
  *offset = o + input.len;
303
  /* Compare against remaining space rather than o + input.len to avoid size_t
304
   * overflow; o <= encoded.len, so encoded.len - o cannot underflow. */
305
27.7k
  if (o <= encoded.len && input.len <= encoded.len - o) {
306
27.7k
    memcpy(amqp_offset(encoded.bytes, o), input.bytes, input.len);
307
27.7k
    return 1;
308
27.7k
  } else {
309
0
    return 0;
310
0
  }
311
27.7k
}
Unexecuted instantiation: amqp_api.c:amqp_encode_bytes
Unexecuted instantiation: amqp_connection.c:amqp_encode_bytes
Unexecuted instantiation: amqp_tcp_socket.c:amqp_encode_bytes
312
313
static inline int amqp_decode_bytes(amqp_bytes_t encoded, size_t *offset,
314
129k
                                    amqp_bytes_t *output, size_t len) {
315
129k
  size_t o = *offset;
316
129k
  *offset = o + len;
317
  /* Compare against remaining space rather than o + len: with len read from the
318
   * wire (uint32_t), o + len can overflow size_t on 32-bit platforms and wrap
319
   * past the check, yielding an out-of-bounds amqp_bytes_t. o <= encoded.len,
320
   * so encoded.len - o cannot underflow. */
321
129k
  if (o <= encoded.len && len <= encoded.len - o) {
322
128k
    output->bytes = amqp_offset(encoded.bytes, o);
323
128k
    output->len = len;
324
128k
    return 1;
325
128k
  } else {
326
1.16k
    return 0;
327
1.16k
  }
328
129k
}
amqp_framing.c:amqp_decode_bytes
Line
Count
Source
314
9.34k
                                    amqp_bytes_t *output, size_t len) {
315
9.34k
  size_t o = *offset;
316
9.34k
  *offset = o + len;
317
  /* Compare against remaining space rather than o + len: with len read from the
318
   * wire (uint32_t), o + len can overflow size_t on 32-bit platforms and wrap
319
   * past the check, yielding an out-of-bounds amqp_bytes_t. o <= encoded.len,
320
   * so encoded.len - o cannot underflow. */
321
9.34k
  if (o <= encoded.len && len <= encoded.len - o) {
322
8.26k
    output->bytes = amqp_offset(encoded.bytes, o);
323
8.26k
    output->len = len;
324
8.26k
    return 1;
325
8.26k
  } else {
326
1.07k
    return 0;
327
1.07k
  }
328
9.34k
}
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
314
120k
                                    amqp_bytes_t *output, size_t len) {
315
120k
  size_t o = *offset;
316
120k
  *offset = o + len;
317
  /* Compare against remaining space rather than o + len: with len read from the
318
   * wire (uint32_t), o + len can overflow size_t on 32-bit platforms and wrap
319
   * past the check, yielding an out-of-bounds amqp_bytes_t. o <= encoded.len,
320
   * so encoded.len - o cannot underflow. */
321
120k
  if (o <= encoded.len && len <= encoded.len - o) {
322
120k
    output->bytes = amqp_offset(encoded.bytes, o);
323
120k
    output->len = len;
324
120k
    return 1;
325
120k
  } else {
326
84
    return 0;
327
84
  }
328
120k
}
Unexecuted instantiation: amqp_api.c:amqp_decode_bytes
Unexecuted instantiation: amqp_connection.c:amqp_decode_bytes
Unexecuted instantiation: amqp_tcp_socket.c:amqp_decode_bytes
329
330
AMQP_NORETURN
331
void amqp_abort(const char *fmt, ...);
332
333
int amqp_bytes_equal(amqp_bytes_t r, amqp_bytes_t l);
334
335
0
static inline amqp_rpc_reply_t amqp_rpc_reply_error(amqp_status_enum status) {
336
0
  amqp_rpc_reply_t reply;
337
0
  reply.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION;
338
0
  reply.library_error = status;
339
0
  return reply;
340
0
}
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_api.c:amqp_rpc_reply_error
Unexecuted instantiation: amqp_connection.c:amqp_rpc_reply_error
Unexecuted instantiation: amqp_tcp_socket.c:amqp_rpc_reply_error
341
342
int amqp_send_frame_inner(amqp_connection_state_t state,
343
                          const amqp_frame_t *frame, int flags,
344
                          amqp_time_t deadline);
345
#endif