/src/rtpproxy/external/libre/include/re_mbuf.h
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * @file re_mbuf.h Interface to memory buffers |
3 | | * |
4 | | * Copyright (C) 2010 Creytiv.com |
5 | | */ |
6 | | |
7 | | |
8 | | #include <stdarg.h> |
9 | | |
10 | | |
11 | | #ifndef RELEASE |
12 | | #define MBUF_DEBUG 1 /**< Mbuf debugging (0 or 1) */ |
13 | | #endif |
14 | | |
15 | | #if MBUF_DEBUG |
16 | | /** Check that mbuf position does not exceed end */ |
17 | | #define MBUF_CHECK_POS(mb) \ |
18 | | if ((mb) && (mb)->pos > (mb)->end) { \ |
19 | | BREAKPOINT; \ |
20 | | } |
21 | | /** Check that mbuf end does not exceed size */ |
22 | | #define MBUF_CHECK_END(mb) \ |
23 | | if ((mb) && (mb)->end > (mb)->size) { \ |
24 | | BREAKPOINT; \ |
25 | | } |
26 | | #else |
27 | | #define MBUF_CHECK_POS(mb) |
28 | | #define MBUF_CHECK_END(mb) |
29 | | #endif |
30 | | |
31 | | /** Defines a memory buffer */ |
32 | | struct mbuf { |
33 | | uint8_t *buf; /**< Buffer memory */ |
34 | | size_t size; /**< Size of buffer */ |
35 | | size_t pos; /**< Position in buffer */ |
36 | | size_t end; /**< End of buffer */ |
37 | | }; |
38 | | |
39 | | |
40 | | struct pl; |
41 | | struct re_printf; |
42 | | |
43 | | struct mbuf *mbuf_alloc(size_t size); |
44 | | struct mbuf *mbuf_alloc_ref(struct mbuf *mbr); |
45 | | void mbuf_init(struct mbuf *mb); |
46 | | void mbuf_reset(struct mbuf *mb); |
47 | | int mbuf_resize(struct mbuf *mb, size_t size); |
48 | | void mbuf_trim(struct mbuf *mb); |
49 | | int mbuf_shift(struct mbuf *mb, ssize_t shift); |
50 | | int mbuf_write_mem(struct mbuf *mb, const uint8_t *buf, size_t size); |
51 | | int mbuf_write_u8(struct mbuf *mb, uint8_t v); |
52 | | int mbuf_write_u16(struct mbuf *mb, uint16_t v); |
53 | | int mbuf_write_u32(struct mbuf *mb, uint32_t v); |
54 | | int mbuf_write_u64(struct mbuf *mb, uint64_t v); |
55 | | int mbuf_write_str(struct mbuf *mb, const char *str); |
56 | | int mbuf_write_pl(struct mbuf *mb, const struct pl *pl); |
57 | | int mbuf_read_mem(struct mbuf *mb, uint8_t *buf, size_t size); |
58 | | uint8_t mbuf_read_u8(struct mbuf *mb); |
59 | | uint16_t mbuf_read_u16(struct mbuf *mb); |
60 | | uint32_t mbuf_read_u32(struct mbuf *mb); |
61 | | uint64_t mbuf_read_u64(struct mbuf *mb); |
62 | | int mbuf_read_str(struct mbuf *mb, char *str, size_t size); |
63 | | int mbuf_strdup(struct mbuf *mb, char **strp, size_t len); |
64 | | int mbuf_vprintf(struct mbuf *mb, const char *fmt, va_list ap); |
65 | | int mbuf_printf(struct mbuf *mb, const char *fmt, ...); |
66 | | int mbuf_write_pl_skip(struct mbuf *mb, const struct pl *pl, |
67 | | const struct pl *skip); |
68 | | int mbuf_fill(struct mbuf *mb, uint8_t c, size_t n); |
69 | | int mbuf_debug(struct re_printf *pf, const struct mbuf *mb); |
70 | | |
71 | | |
72 | | /** |
73 | | * Get the buffer from the current position |
74 | | * |
75 | | * @param mb Memory buffer |
76 | | * |
77 | | * @return Current buffer |
78 | | */ |
79 | | static inline uint8_t *mbuf_buf(const struct mbuf *mb) |
80 | 197 | { |
81 | 197 | return mb ? mb->buf + mb->pos : (uint8_t *)NULL; |
82 | 197 | } Unexecuted instantiation: addr.c:mbuf_buf Unexecuted instantiation: attr.c:mbuf_buf Unexecuted instantiation: cand.c:mbuf_buf Unexecuted instantiation: candpair.c:mbuf_buf Unexecuted instantiation: comp.c:mbuf_buf Unexecuted instantiation: ctrans.c:mbuf_buf Unexecuted instantiation: endian.c:mbuf_buf Unexecuted instantiation: hdr.c:mbuf_buf Unexecuted instantiation: icem.c:mbuf_buf Unexecuted instantiation: icesdp.c:mbuf_buf Unexecuted instantiation: icestr.c:mbuf_buf Unexecuted instantiation: mbuf.c:mbuf_buf Line | Count | Source | 80 | 197 | { | 81 | 197 | return mb ? mb->buf + mb->pos : (uint8_t *)NULL; | 82 | 197 | } |
Unexecuted instantiation: ntop.c:mbuf_buf Unexecuted instantiation: pl.c:mbuf_buf Unexecuted instantiation: pton.c:mbuf_buf Unexecuted instantiation: rand.c:mbuf_buf Unexecuted instantiation: rep.c:mbuf_buf Unexecuted instantiation: stun.c:mbuf_buf Unexecuted instantiation: stunsrv.c:mbuf_buf Unexecuted instantiation: util.c:mbuf_buf Unexecuted instantiation: rtpp_ice_lite.c:mbuf_buf |
83 | | |
84 | | |
85 | | /** |
86 | | * Get number of bytes left in a memory buffer, from current position to end |
87 | | * |
88 | | * @param mb Memory buffer |
89 | | * |
90 | | * @return Number of bytes left |
91 | | */ |
92 | | static inline size_t mbuf_get_left(const struct mbuf *mb) |
93 | 192k | { |
94 | 192k | return (mb && (mb->end > mb->pos)) ? (mb->end - mb->pos) : 0; |
95 | 192k | } Line | Count | Source | 93 | 2.66k | { | 94 | 2.66k | return (mb && (mb->end > mb->pos)) ? (mb->end - mb->pos) : 0; | 95 | 2.66k | } |
Line | Count | Source | 93 | 48.2k | { | 94 | 48.2k | return (mb && (mb->end > mb->pos)) ? (mb->end - mb->pos) : 0; | 95 | 48.2k | } |
Unexecuted instantiation: cand.c:mbuf_get_left Unexecuted instantiation: candpair.c:mbuf_get_left Unexecuted instantiation: comp.c:mbuf_get_left Unexecuted instantiation: ctrans.c:mbuf_get_left Unexecuted instantiation: endian.c:mbuf_get_left Line | Count | Source | 93 | 10.0k | { | 94 | 10.0k | return (mb && (mb->end > mb->pos)) ? (mb->end - mb->pos) : 0; | 95 | 10.0k | } |
Unexecuted instantiation: icem.c:mbuf_get_left Unexecuted instantiation: icesdp.c:mbuf_get_left Unexecuted instantiation: icestr.c:mbuf_get_left Line | Count | Source | 93 | 103k | { | 94 | 103k | return (mb && (mb->end > mb->pos)) ? (mb->end - mb->pos) : 0; | 95 | 103k | } |
Line | Count | Source | 93 | 27.3k | { | 94 | 27.3k | return (mb && (mb->end > mb->pos)) ? (mb->end - mb->pos) : 0; | 95 | 27.3k | } |
Unexecuted instantiation: ntop.c:mbuf_get_left Unexecuted instantiation: pl.c:mbuf_get_left Unexecuted instantiation: pton.c:mbuf_get_left Unexecuted instantiation: rand.c:mbuf_get_left Unexecuted instantiation: rep.c:mbuf_get_left Unexecuted instantiation: stun.c:mbuf_get_left Unexecuted instantiation: stunsrv.c:mbuf_get_left Unexecuted instantiation: util.c:mbuf_get_left Unexecuted instantiation: rtpp_ice_lite.c:mbuf_get_left |
96 | | |
97 | | |
98 | | /** |
99 | | * Get available space in buffer (size - pos) |
100 | | * |
101 | | * @param mb Memory buffer |
102 | | * |
103 | | * @return Number of bytes available in buffer |
104 | | */ |
105 | | static inline size_t mbuf_get_space(const struct mbuf *mb) |
106 | 0 | { |
107 | 0 | return (mb && (mb->size > mb->pos)) ? (mb->size - mb->pos) : 0; |
108 | 0 | } Unexecuted instantiation: addr.c:mbuf_get_space Unexecuted instantiation: attr.c:mbuf_get_space Unexecuted instantiation: cand.c:mbuf_get_space Unexecuted instantiation: candpair.c:mbuf_get_space Unexecuted instantiation: comp.c:mbuf_get_space Unexecuted instantiation: ctrans.c:mbuf_get_space Unexecuted instantiation: endian.c:mbuf_get_space Unexecuted instantiation: hdr.c:mbuf_get_space Unexecuted instantiation: icem.c:mbuf_get_space Unexecuted instantiation: icesdp.c:mbuf_get_space Unexecuted instantiation: icestr.c:mbuf_get_space Unexecuted instantiation: mbuf.c:mbuf_get_space Unexecuted instantiation: msg.c:mbuf_get_space Unexecuted instantiation: ntop.c:mbuf_get_space Unexecuted instantiation: pl.c:mbuf_get_space Unexecuted instantiation: pton.c:mbuf_get_space Unexecuted instantiation: rand.c:mbuf_get_space Unexecuted instantiation: rep.c:mbuf_get_space Unexecuted instantiation: stun.c:mbuf_get_space Unexecuted instantiation: stunsrv.c:mbuf_get_space Unexecuted instantiation: util.c:mbuf_get_space Unexecuted instantiation: rtpp_ice_lite.c:mbuf_get_space |
109 | | |
110 | | |
111 | | /** |
112 | | * Set absolute position |
113 | | * |
114 | | * @param mb Memory buffer |
115 | | * @param pos Position |
116 | | */ |
117 | | static inline void mbuf_set_pos(struct mbuf *mb, size_t pos) |
118 | 0 | { |
119 | 0 | mb->pos = pos; |
120 | 0 | MBUF_CHECK_POS(mb); |
121 | 0 | } Unexecuted instantiation: addr.c:mbuf_set_pos Unexecuted instantiation: attr.c:mbuf_set_pos Unexecuted instantiation: cand.c:mbuf_set_pos Unexecuted instantiation: candpair.c:mbuf_set_pos Unexecuted instantiation: comp.c:mbuf_set_pos Unexecuted instantiation: ctrans.c:mbuf_set_pos Unexecuted instantiation: endian.c:mbuf_set_pos Unexecuted instantiation: hdr.c:mbuf_set_pos Unexecuted instantiation: icem.c:mbuf_set_pos Unexecuted instantiation: icesdp.c:mbuf_set_pos Unexecuted instantiation: icestr.c:mbuf_set_pos Unexecuted instantiation: mbuf.c:mbuf_set_pos Unexecuted instantiation: msg.c:mbuf_set_pos Unexecuted instantiation: ntop.c:mbuf_set_pos Unexecuted instantiation: pl.c:mbuf_set_pos Unexecuted instantiation: pton.c:mbuf_set_pos Unexecuted instantiation: rand.c:mbuf_set_pos Unexecuted instantiation: rep.c:mbuf_set_pos Unexecuted instantiation: stun.c:mbuf_set_pos Unexecuted instantiation: stunsrv.c:mbuf_set_pos Unexecuted instantiation: util.c:mbuf_set_pos Unexecuted instantiation: rtpp_ice_lite.c:mbuf_set_pos |
122 | | |
123 | | |
124 | | /** |
125 | | * Set absolute end |
126 | | * |
127 | | * @param mb Memory buffer |
128 | | * @param end End position |
129 | | */ |
130 | | static inline void mbuf_set_end(struct mbuf *mb, size_t end) |
131 | 0 | { |
132 | 0 | mb->end = end; |
133 | 0 | MBUF_CHECK_END(mb); |
134 | 0 | } Unexecuted instantiation: addr.c:mbuf_set_end Unexecuted instantiation: attr.c:mbuf_set_end Unexecuted instantiation: cand.c:mbuf_set_end Unexecuted instantiation: candpair.c:mbuf_set_end Unexecuted instantiation: comp.c:mbuf_set_end Unexecuted instantiation: ctrans.c:mbuf_set_end Unexecuted instantiation: endian.c:mbuf_set_end Unexecuted instantiation: hdr.c:mbuf_set_end Unexecuted instantiation: icem.c:mbuf_set_end Unexecuted instantiation: icesdp.c:mbuf_set_end Unexecuted instantiation: icestr.c:mbuf_set_end Unexecuted instantiation: mbuf.c:mbuf_set_end Unexecuted instantiation: msg.c:mbuf_set_end Unexecuted instantiation: ntop.c:mbuf_set_end Unexecuted instantiation: pl.c:mbuf_set_end Unexecuted instantiation: pton.c:mbuf_set_end Unexecuted instantiation: rand.c:mbuf_set_end Unexecuted instantiation: rep.c:mbuf_set_end Unexecuted instantiation: stun.c:mbuf_set_end Unexecuted instantiation: stunsrv.c:mbuf_set_end Unexecuted instantiation: util.c:mbuf_set_end Unexecuted instantiation: rtpp_ice_lite.c:mbuf_set_end |
135 | | |
136 | | |
137 | | /** |
138 | | * Advance position +/- N bytes |
139 | | * |
140 | | * @param mb Memory buffer |
141 | | * @param n Number of bytes to advance |
142 | | */ |
143 | | static inline void mbuf_advance(struct mbuf *mb, ssize_t n) |
144 | 0 | { |
145 | 0 | mb->pos += n; |
146 | 0 | MBUF_CHECK_POS(mb); |
147 | 0 | } Unexecuted instantiation: addr.c:mbuf_advance Unexecuted instantiation: attr.c:mbuf_advance Unexecuted instantiation: cand.c:mbuf_advance Unexecuted instantiation: candpair.c:mbuf_advance Unexecuted instantiation: comp.c:mbuf_advance Unexecuted instantiation: ctrans.c:mbuf_advance Unexecuted instantiation: endian.c:mbuf_advance Unexecuted instantiation: hdr.c:mbuf_advance Unexecuted instantiation: icem.c:mbuf_advance Unexecuted instantiation: icesdp.c:mbuf_advance Unexecuted instantiation: icestr.c:mbuf_advance Unexecuted instantiation: mbuf.c:mbuf_advance Unexecuted instantiation: msg.c:mbuf_advance Unexecuted instantiation: ntop.c:mbuf_advance Unexecuted instantiation: pl.c:mbuf_advance Unexecuted instantiation: pton.c:mbuf_advance Unexecuted instantiation: rand.c:mbuf_advance Unexecuted instantiation: rep.c:mbuf_advance Unexecuted instantiation: stun.c:mbuf_advance Unexecuted instantiation: stunsrv.c:mbuf_advance Unexecuted instantiation: util.c:mbuf_advance Unexecuted instantiation: rtpp_ice_lite.c:mbuf_advance |
148 | | |
149 | | |
150 | | /** |
151 | | * Rewind position and end to the beginning of buffer |
152 | | * |
153 | | * @param mb Memory buffer |
154 | | */ |
155 | | static inline void mbuf_rewind(struct mbuf *mb) |
156 | 0 | { |
157 | 0 | mb->pos = mb->end = 0; |
158 | 0 | } Unexecuted instantiation: addr.c:mbuf_rewind Unexecuted instantiation: attr.c:mbuf_rewind Unexecuted instantiation: cand.c:mbuf_rewind Unexecuted instantiation: candpair.c:mbuf_rewind Unexecuted instantiation: comp.c:mbuf_rewind Unexecuted instantiation: ctrans.c:mbuf_rewind Unexecuted instantiation: endian.c:mbuf_rewind Unexecuted instantiation: hdr.c:mbuf_rewind Unexecuted instantiation: icem.c:mbuf_rewind Unexecuted instantiation: icesdp.c:mbuf_rewind Unexecuted instantiation: icestr.c:mbuf_rewind Unexecuted instantiation: mbuf.c:mbuf_rewind Unexecuted instantiation: msg.c:mbuf_rewind Unexecuted instantiation: ntop.c:mbuf_rewind Unexecuted instantiation: pl.c:mbuf_rewind Unexecuted instantiation: pton.c:mbuf_rewind Unexecuted instantiation: rand.c:mbuf_rewind Unexecuted instantiation: rep.c:mbuf_rewind Unexecuted instantiation: stun.c:mbuf_rewind Unexecuted instantiation: stunsrv.c:mbuf_rewind Unexecuted instantiation: util.c:mbuf_rewind Unexecuted instantiation: rtpp_ice_lite.c:mbuf_rewind |
159 | | |
160 | | |
161 | | /** |
162 | | * Set position to the end of the buffer |
163 | | * |
164 | | * @param mb Memory buffer |
165 | | */ |
166 | | static inline void mbuf_skip_to_end(struct mbuf *mb) |
167 | 0 | { |
168 | 0 | mb->pos = mb->end; |
169 | 0 | } Unexecuted instantiation: addr.c:mbuf_skip_to_end Unexecuted instantiation: attr.c:mbuf_skip_to_end Unexecuted instantiation: cand.c:mbuf_skip_to_end Unexecuted instantiation: candpair.c:mbuf_skip_to_end Unexecuted instantiation: comp.c:mbuf_skip_to_end Unexecuted instantiation: ctrans.c:mbuf_skip_to_end Unexecuted instantiation: endian.c:mbuf_skip_to_end Unexecuted instantiation: hdr.c:mbuf_skip_to_end Unexecuted instantiation: icem.c:mbuf_skip_to_end Unexecuted instantiation: icesdp.c:mbuf_skip_to_end Unexecuted instantiation: icestr.c:mbuf_skip_to_end Unexecuted instantiation: mbuf.c:mbuf_skip_to_end Unexecuted instantiation: msg.c:mbuf_skip_to_end Unexecuted instantiation: ntop.c:mbuf_skip_to_end Unexecuted instantiation: pl.c:mbuf_skip_to_end Unexecuted instantiation: pton.c:mbuf_skip_to_end Unexecuted instantiation: rand.c:mbuf_skip_to_end Unexecuted instantiation: rep.c:mbuf_skip_to_end Unexecuted instantiation: stun.c:mbuf_skip_to_end Unexecuted instantiation: stunsrv.c:mbuf_skip_to_end Unexecuted instantiation: util.c:mbuf_skip_to_end Unexecuted instantiation: rtpp_ice_lite.c:mbuf_skip_to_end |