/src/dovecot/src/lib/buffer.h
Line | Count | Source |
1 | | #ifndef BUFFER_H |
2 | | #define BUFFER_H |
3 | | |
4 | | struct buffer { |
5 | | union { |
6 | | struct { |
7 | | const void *data; |
8 | | const size_t used; |
9 | | }; |
10 | | void *priv[9]; |
11 | | }; |
12 | | }; |
13 | | |
14 | | /* WARNING: Be careful with functions that return pointers to data. |
15 | | With dynamic buffers they are valid only as long as buffer is not |
16 | | realloc()ed. You shouldn't rely on it being valid if you have modified |
17 | | buffer in any way. */ |
18 | | |
19 | | /* Create a modifiable buffer from given data. Writes past this size will |
20 | | i_panic(). */ |
21 | | void buffer_create_from_data(buffer_t *buffer, void *data, size_t size); |
22 | | /* Create a non-modifiable buffer from given data. */ |
23 | | void buffer_create_from_const_data(buffer_t *buffer, |
24 | | const void *data, size_t size); |
25 | | #define buffer_create_from_data(b,d,s) \ |
26 | 0 | TYPE_CHECKS(void, \ |
27 | 0 | /* NOLINTBEGIN(bugprone-sizeof-expression) */ \ |
28 | 0 | COMPILE_ERROR_IF_TRUE(__builtin_object_size((d),1) < ((s)>0?(s):1)), \ |
29 | 0 | /* NOLINTEND(bugprone-sizeof-expression) */ \ |
30 | 0 | buffer_create_from_data((b), (d), (s))) |
31 | | #define buffer_create_from_const_data(b,d,s) \ |
32 | 0 | TYPE_CHECKS(void, \ |
33 | 0 | /* NOLINTBEGIN(bugprone-sizeof-expression) */ \ |
34 | 0 | COMPILE_ERROR_IF_TRUE(__builtin_object_size((d),1) < ((s)>0?(s):1)), \ |
35 | 0 | /* NOLINTEND(bugprone-sizeof-expression) */ \ |
36 | 0 | buffer_create_from_const_data((b), (d), (s))) |
37 | | |
38 | | /* Creates a dynamically growing buffer. Whenever write would exceed the |
39 | | current size it's grown. */ |
40 | | buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size); |
41 | | /* Create a dynamically growing buffer with a maximum size. Writes past the |
42 | | maximum size will i_panic(). Internally allow it to grow max_size+1 so |
43 | | str_c() NUL can be used. */ |
44 | | buffer_t *buffer_create_dynamic_max(pool_t pool, size_t init_size, |
45 | | size_t max_size); |
46 | | |
47 | | #define t_buffer_create(init_size) \ |
48 | 0 | buffer_create_dynamic(pool_datastack_create(), (init_size)) |
49 | | |
50 | | /* Free the memory used by buffer. Not needed if the memory is free'd |
51 | | directly from the memory pool. */ |
52 | | void buffer_free(buffer_t **buf); |
53 | | /* Free the memory used by buffer structure, but return the buffer data |
54 | | unfree'd. */ |
55 | | void *buffer_free_without_data(buffer_t **buf); |
56 | | |
57 | | /* Returns the pool buffer was created with. */ |
58 | | pool_t buffer_get_pool(const buffer_t *buf) ATTR_PURE; |
59 | | |
60 | | /* Write data to buffer at specified position. If pos is beyond the buffer's |
61 | | current size, it is zero-filled up to that point (even if data_size==0). */ |
62 | | void buffer_write(buffer_t *buf, size_t pos, |
63 | | const void *data, size_t data_size); |
64 | | void buffer_write_array(buffer_t *buf, size_t pos, |
65 | | const void *data, size_t count, size_t size); |
66 | | /* Append data to buffer. */ |
67 | | void buffer_append(buffer_t *buf, const void *data, size_t data_size); |
68 | | void buffer_append_array(buffer_t *buf, const void *data, |
69 | | size_t count, size_t size); |
70 | | /* Append character to buffer. */ |
71 | | void buffer_append_c(buffer_t *buf, unsigned char chr); |
72 | | |
73 | | /* Insert the provided data into the buffer at position pos. If pos points past |
74 | | the current buffer size, the gap is zero-filled. */ |
75 | | void buffer_insert(buffer_t *buf, size_t pos, |
76 | | const void *data, size_t data_size); |
77 | | void buffer_insert_array(buffer_t *buf, size_t pos, |
78 | | const void *data, size_t count, size_t size); |
79 | | /* Delete data with the indicated size from the buffer at position pos. The |
80 | | deleted block may cross the current buffer size boundary, which is ignored. |
81 | | */ |
82 | | void buffer_delete(buffer_t *buf, size_t pos, size_t size); |
83 | | /* Replace the data in the buffer with the indicated size at position pos with |
84 | | the provided data. This is a more optimized version of |
85 | | buffer_delete(buf, pos, size); buffer_insert(buf, pos, data, data_size); */ |
86 | | void buffer_replace(buffer_t *buf, size_t pos, size_t size, |
87 | | const void *data, size_t data_size); |
88 | | |
89 | | /* Fill buffer with zero bytes. */ |
90 | | void buffer_write_zero(buffer_t *buf, size_t pos, size_t data_size); |
91 | | void buffer_append_zero(buffer_t *buf, size_t data_size); |
92 | | void buffer_insert_zero(buffer_t *buf, size_t pos, size_t data_size); |
93 | | /* Terminate the buffer with a NUL character after the buffer's used size. |
94 | | The NUL will not be included in the used size. */ |
95 | | void buffer_nul_terminate(buffer_t *buf); |
96 | | |
97 | | /* Copy data from buffer to another. The buffers may be same in which case |
98 | | it's internal copying, possibly with overlapping positions (ie. memmove() |
99 | | like functionality). copy_size may be set to SIZE_MAX to copy the rest of |
100 | | the used data in buffer. */ |
101 | | void buffer_copy(buffer_t *dest, size_t dest_pos, |
102 | | const buffer_t *src, size_t src_pos, size_t copy_size); |
103 | | /* Append data to buffer from another. copy_size may be set to SIZE_MAX to |
104 | | copy the rest of the used data in buffer. */ |
105 | | void buffer_append_buf(buffer_t *dest, const buffer_t *src, |
106 | | size_t src_pos, size_t copy_size); |
107 | | |
108 | | /* Clone source buffer onto specified pool. Allocate extra_space extra space. */ |
109 | | static inline buffer_t * |
110 | | buffer_clone(pool_t pool, const buffer_t *src, size_t extra_space) |
111 | 0 | { |
112 | 0 | buffer_t *buf = buffer_create_dynamic(pool, src->used + extra_space); |
113 | 0 |
|
114 | 0 | buffer_append_buf(buf, src, 0, SIZE_MAX); |
115 | 0 | return buf; |
116 | 0 | } Unexecuted instantiation: smtp-server-cmd-data.c:buffer_clone Unexecuted instantiation: smtp-server-reply.c:buffer_clone Unexecuted instantiation: smtp-server-command.c:buffer_clone Unexecuted instantiation: smtp-server-transaction.c:buffer_clone Unexecuted instantiation: smtp-server-connection.c:buffer_clone Unexecuted instantiation: smtp-server.c:buffer_clone Unexecuted instantiation: smtp-syntax.c:buffer_clone Unexecuted instantiation: smtp-address.c:buffer_clone Unexecuted instantiation: smtp-params.c:buffer_clone Unexecuted instantiation: smtp-reply.c:buffer_clone Unexecuted instantiation: smtp-reply-parser.c:buffer_clone Unexecuted instantiation: smtp-command-parser.c:buffer_clone Unexecuted instantiation: smtp-server-cmd-helo.c:buffer_clone Unexecuted instantiation: smtp-server-cmd-mail.c:buffer_clone Unexecuted instantiation: smtp-server-cmd-rcpt.c:buffer_clone Unexecuted instantiation: smtp-server-cmd-xclient.c:buffer_clone Unexecuted instantiation: smtp-parser.c:buffer_clone Unexecuted instantiation: message-address.c:buffer_clone Unexecuted instantiation: message-date.c:buffer_clone Unexecuted instantiation: rfc822-parser.c:buffer_clone Unexecuted instantiation: settings.c:buffer_clone Unexecuted instantiation: settings-parser.c:buffer_clone Unexecuted instantiation: expansion-program.c:buffer_clone Unexecuted instantiation: var-expand.c:buffer_clone Unexecuted instantiation: var-expand-parser.c:buffer_clone Unexecuted instantiation: var-expand-lexer.c:buffer_clone Unexecuted instantiation: expansion-parameter.c:buffer_clone Unexecuted instantiation: expansion-filter.c:buffer_clone Unexecuted instantiation: expansion-filter-if.c:buffer_clone Unexecuted instantiation: array.c:buffer_clone Unexecuted instantiation: base64.c:buffer_clone Unexecuted instantiation: buffer.c:buffer_clone Unexecuted instantiation: connection.c:buffer_clone Unexecuted instantiation: data-stack.c:buffer_clone Unexecuted instantiation: event-filter.c:buffer_clone Unexecuted instantiation: event-filter-lexer.c:buffer_clone Unexecuted instantiation: event-log.c:buffer_clone Unexecuted instantiation: failures.c:buffer_clone Unexecuted instantiation: guid.c:buffer_clone Unexecuted instantiation: hash-method.c:buffer_clone Unexecuted instantiation: hex-binary.c:buffer_clone Unexecuted instantiation: iostream.c:buffer_clone Unexecuted instantiation: iostream-pump.c:buffer_clone Unexecuted instantiation: iostream-rawlog.c:buffer_clone Unexecuted instantiation: istream.c:buffer_clone Unexecuted instantiation: ioloop.c:buffer_clone Unexecuted instantiation: ioloop-notify-inotify.c:buffer_clone Unexecuted instantiation: ioloop-epoll.c:buffer_clone Unexecuted instantiation: lib.c:buffer_clone Unexecuted instantiation: lib-event.c:buffer_clone Unexecuted instantiation: lib-signals.c:buffer_clone Unexecuted instantiation: md4.c:buffer_clone Unexecuted instantiation: md5.c:buffer_clone Unexecuted instantiation: mempool.c:buffer_clone Unexecuted instantiation: module-dir.c:buffer_clone Unexecuted instantiation: path-util.c:buffer_clone Unexecuted instantiation: priorityq.c:buffer_clone Unexecuted instantiation: restrict-access.c:buffer_clone Unexecuted instantiation: sha1.c:buffer_clone Unexecuted instantiation: sha2.c:buffer_clone Unexecuted instantiation: sha3.c:buffer_clone Unexecuted instantiation: str.c:buffer_clone Unexecuted instantiation: str-sanitize.c:buffer_clone Unexecuted instantiation: strescape.c:buffer_clone Unexecuted instantiation: strfuncs.c:buffer_clone Unexecuted instantiation: unichar.c:buffer_clone Unexecuted instantiation: wildcard-match.c:buffer_clone Unexecuted instantiation: backtrace-string.c:buffer_clone Unexecuted instantiation: env-util.c:buffer_clone |
117 | | /* Clone source buffer onto datastack. Allocate extra_space extra space. */ |
118 | | static inline buffer_t * |
119 | | t_buffer_clone(const buffer_t *src, size_t extra_space) |
120 | 0 | { |
121 | 0 | buffer_t *buf = buffer_create_dynamic(pool_datastack_create(), |
122 | 0 | src->used + extra_space); |
123 | 0 |
|
124 | 0 | buffer_append_buf(buf, src, 0, SIZE_MAX); |
125 | 0 | return buf; |
126 | 0 | } Unexecuted instantiation: smtp-server-cmd-data.c:t_buffer_clone Unexecuted instantiation: smtp-server-reply.c:t_buffer_clone Unexecuted instantiation: smtp-server-command.c:t_buffer_clone Unexecuted instantiation: smtp-server-transaction.c:t_buffer_clone Unexecuted instantiation: smtp-server-connection.c:t_buffer_clone Unexecuted instantiation: smtp-server.c:t_buffer_clone Unexecuted instantiation: smtp-syntax.c:t_buffer_clone Unexecuted instantiation: smtp-address.c:t_buffer_clone Unexecuted instantiation: smtp-params.c:t_buffer_clone Unexecuted instantiation: smtp-reply.c:t_buffer_clone Unexecuted instantiation: smtp-reply-parser.c:t_buffer_clone Unexecuted instantiation: smtp-command-parser.c:t_buffer_clone Unexecuted instantiation: smtp-server-cmd-helo.c:t_buffer_clone Unexecuted instantiation: smtp-server-cmd-mail.c:t_buffer_clone Unexecuted instantiation: smtp-server-cmd-rcpt.c:t_buffer_clone Unexecuted instantiation: smtp-server-cmd-xclient.c:t_buffer_clone Unexecuted instantiation: smtp-parser.c:t_buffer_clone Unexecuted instantiation: message-address.c:t_buffer_clone Unexecuted instantiation: message-date.c:t_buffer_clone Unexecuted instantiation: rfc822-parser.c:t_buffer_clone Unexecuted instantiation: settings.c:t_buffer_clone Unexecuted instantiation: settings-parser.c:t_buffer_clone Unexecuted instantiation: expansion-program.c:t_buffer_clone Unexecuted instantiation: var-expand.c:t_buffer_clone Unexecuted instantiation: var-expand-parser.c:t_buffer_clone Unexecuted instantiation: var-expand-lexer.c:t_buffer_clone Unexecuted instantiation: expansion-parameter.c:t_buffer_clone Unexecuted instantiation: expansion-filter.c:t_buffer_clone Unexecuted instantiation: expansion-filter-if.c:t_buffer_clone Unexecuted instantiation: array.c:t_buffer_clone Unexecuted instantiation: base64.c:t_buffer_clone Unexecuted instantiation: buffer.c:t_buffer_clone Unexecuted instantiation: connection.c:t_buffer_clone Unexecuted instantiation: data-stack.c:t_buffer_clone Unexecuted instantiation: event-filter.c:t_buffer_clone Unexecuted instantiation: event-filter-lexer.c:t_buffer_clone Unexecuted instantiation: event-log.c:t_buffer_clone Unexecuted instantiation: failures.c:t_buffer_clone Unexecuted instantiation: guid.c:t_buffer_clone Unexecuted instantiation: hash-method.c:t_buffer_clone Unexecuted instantiation: hex-binary.c:t_buffer_clone Unexecuted instantiation: iostream.c:t_buffer_clone Unexecuted instantiation: iostream-pump.c:t_buffer_clone Unexecuted instantiation: iostream-rawlog.c:t_buffer_clone Unexecuted instantiation: istream.c:t_buffer_clone Unexecuted instantiation: ioloop.c:t_buffer_clone Unexecuted instantiation: ioloop-notify-inotify.c:t_buffer_clone Unexecuted instantiation: ioloop-epoll.c:t_buffer_clone Unexecuted instantiation: lib.c:t_buffer_clone Unexecuted instantiation: lib-event.c:t_buffer_clone Unexecuted instantiation: lib-signals.c:t_buffer_clone Unexecuted instantiation: md4.c:t_buffer_clone Unexecuted instantiation: md5.c:t_buffer_clone Unexecuted instantiation: mempool.c:t_buffer_clone Unexecuted instantiation: module-dir.c:t_buffer_clone Unexecuted instantiation: path-util.c:t_buffer_clone Unexecuted instantiation: priorityq.c:t_buffer_clone Unexecuted instantiation: restrict-access.c:t_buffer_clone Unexecuted instantiation: sha1.c:t_buffer_clone Unexecuted instantiation: sha2.c:t_buffer_clone Unexecuted instantiation: sha3.c:t_buffer_clone Unexecuted instantiation: str.c:t_buffer_clone Unexecuted instantiation: str-sanitize.c:t_buffer_clone Unexecuted instantiation: strescape.c:t_buffer_clone Unexecuted instantiation: strfuncs.c:t_buffer_clone Unexecuted instantiation: unichar.c:t_buffer_clone Unexecuted instantiation: wildcard-match.c:t_buffer_clone Unexecuted instantiation: backtrace-string.c:t_buffer_clone Unexecuted instantiation: env-util.c:t_buffer_clone |
127 | | |
128 | | /* Returns pointer to specified position in buffer. WARNING: The returned |
129 | | address may become invalid if you add more data to buffer. */ |
130 | | void *buffer_get_space_unsafe(buffer_t *buf, size_t pos, size_t size); |
131 | | /* Increase the buffer usage by given size, and return a pointer to beginning |
132 | | of it. */ |
133 | | void *buffer_append_space_unsafe(buffer_t *buf, size_t size); |
134 | | |
135 | | /* Like buffer_get_data(), but don't return it as const. Returns NULL if the |
136 | | buffer is non-modifiable. WARNING: The returned address may become invalid |
137 | | if you add more data to buffer. */ |
138 | | void *buffer_get_modifiable_data(const buffer_t *buf, size_t *used_size_r) |
139 | | ATTR_NULL(2); |
140 | | |
141 | | /* Set the "used size" of buffer, ie. 0 would set the buffer empty. |
142 | | Must not be used to grow buffer. The data after the buffer's new size will |
143 | | be effectively lost, because e.g. buffer_get_space_unsafe() will zero out |
144 | | the contents. */ |
145 | | void buffer_set_used_size(buffer_t *buf, size_t used_size); |
146 | | |
147 | | /* Clear the buffer. */ |
148 | | static inline void buffer_clear(buffer_t *buf) |
149 | 0 | { |
150 | 0 | buffer_set_used_size(buf, 0); |
151 | 0 | } Unexecuted instantiation: smtp-server-cmd-data.c:buffer_clear Unexecuted instantiation: smtp-server-reply.c:buffer_clear Unexecuted instantiation: smtp-server-command.c:buffer_clear Unexecuted instantiation: smtp-server-transaction.c:buffer_clear Unexecuted instantiation: smtp-server-connection.c:buffer_clear Unexecuted instantiation: smtp-server.c:buffer_clear Unexecuted instantiation: smtp-syntax.c:buffer_clear Unexecuted instantiation: smtp-address.c:buffer_clear Unexecuted instantiation: smtp-params.c:buffer_clear Unexecuted instantiation: smtp-reply.c:buffer_clear Unexecuted instantiation: smtp-reply-parser.c:buffer_clear Unexecuted instantiation: smtp-command-parser.c:buffer_clear Unexecuted instantiation: smtp-server-cmd-helo.c:buffer_clear Unexecuted instantiation: smtp-server-cmd-mail.c:buffer_clear Unexecuted instantiation: smtp-server-cmd-rcpt.c:buffer_clear Unexecuted instantiation: smtp-server-cmd-xclient.c:buffer_clear Unexecuted instantiation: smtp-parser.c:buffer_clear Unexecuted instantiation: message-address.c:buffer_clear Unexecuted instantiation: message-date.c:buffer_clear Unexecuted instantiation: rfc822-parser.c:buffer_clear Unexecuted instantiation: settings.c:buffer_clear Unexecuted instantiation: settings-parser.c:buffer_clear Unexecuted instantiation: expansion-program.c:buffer_clear Unexecuted instantiation: var-expand.c:buffer_clear Unexecuted instantiation: var-expand-parser.c:buffer_clear Unexecuted instantiation: var-expand-lexer.c:buffer_clear Unexecuted instantiation: expansion-parameter.c:buffer_clear Unexecuted instantiation: expansion-filter.c:buffer_clear Unexecuted instantiation: expansion-filter-if.c:buffer_clear Unexecuted instantiation: array.c:buffer_clear Unexecuted instantiation: base64.c:buffer_clear Unexecuted instantiation: buffer.c:buffer_clear Unexecuted instantiation: connection.c:buffer_clear Unexecuted instantiation: data-stack.c:buffer_clear Unexecuted instantiation: event-filter.c:buffer_clear Unexecuted instantiation: event-filter-lexer.c:buffer_clear Unexecuted instantiation: event-log.c:buffer_clear Unexecuted instantiation: failures.c:buffer_clear Unexecuted instantiation: guid.c:buffer_clear Unexecuted instantiation: hash-method.c:buffer_clear Unexecuted instantiation: hex-binary.c:buffer_clear Unexecuted instantiation: iostream.c:buffer_clear Unexecuted instantiation: iostream-pump.c:buffer_clear Unexecuted instantiation: iostream-rawlog.c:buffer_clear Unexecuted instantiation: istream.c:buffer_clear Unexecuted instantiation: ioloop.c:buffer_clear Unexecuted instantiation: ioloop-notify-inotify.c:buffer_clear Unexecuted instantiation: ioloop-epoll.c:buffer_clear Unexecuted instantiation: lib.c:buffer_clear Unexecuted instantiation: lib-event.c:buffer_clear Unexecuted instantiation: lib-signals.c:buffer_clear Unexecuted instantiation: md4.c:buffer_clear Unexecuted instantiation: md5.c:buffer_clear Unexecuted instantiation: mempool.c:buffer_clear Unexecuted instantiation: module-dir.c:buffer_clear Unexecuted instantiation: path-util.c:buffer_clear Unexecuted instantiation: priorityq.c:buffer_clear Unexecuted instantiation: restrict-access.c:buffer_clear Unexecuted instantiation: sha1.c:buffer_clear Unexecuted instantiation: sha2.c:buffer_clear Unexecuted instantiation: sha3.c:buffer_clear Unexecuted instantiation: str.c:buffer_clear Unexecuted instantiation: str-sanitize.c:buffer_clear Unexecuted instantiation: strescape.c:buffer_clear Unexecuted instantiation: strfuncs.c:buffer_clear Unexecuted instantiation: unichar.c:buffer_clear Unexecuted instantiation: wildcard-match.c:buffer_clear Unexecuted instantiation: backtrace-string.c:buffer_clear Unexecuted instantiation: env-util.c:buffer_clear |
152 | | /* Clear the buffer, but also make sure any contents is zeroed out. */ |
153 | | void buffer_clear_safe(buffer_t *_buf); |
154 | | |
155 | | /* Returns the current buffer size. */ |
156 | | size_t buffer_get_size(const buffer_t *buf) ATTR_PURE; |
157 | | /* Returns how many bytes we can write to buffer without increasing its size. |
158 | | With dynamic buffers this is buffer_get_size()-1, because the extra 1 byte |
159 | | is reserved for str_c()'s NUL. */ |
160 | | size_t buffer_get_writable_size(const buffer_t *buf) ATTR_PURE; |
161 | | /* Returns the maximum number of bytes we can append to the buffer. If the |
162 | | buffer is dynamic, this is always near SIZE_MAX. */ |
163 | | size_t buffer_get_avail_size(const buffer_t *buf) ATTR_PURE; |
164 | | |
165 | | /* Returns TRUE if buffer contents are identical. */ |
166 | | bool buffer_cmp(const buffer_t *buf1, const buffer_t *buf2); |
167 | | |
168 | | /* Returns pointer to beginning of buffer data. Current used size of buffer is |
169 | | stored in used_size if it's non-NULL. */ |
170 | | static inline const void * ATTR_NULL(2) |
171 | | buffer_get_data(const buffer_t *buf, size_t *used_size_r) |
172 | 0 | { |
173 | 0 | if (used_size_r != NULL) |
174 | 0 | *used_size_r = buf->used; |
175 | 0 | return buf->data; |
176 | 0 | } Unexecuted instantiation: smtp-server-cmd-data.c:buffer_get_data Unexecuted instantiation: smtp-server-reply.c:buffer_get_data Unexecuted instantiation: smtp-server-command.c:buffer_get_data Unexecuted instantiation: smtp-server-transaction.c:buffer_get_data Unexecuted instantiation: smtp-server-connection.c:buffer_get_data Unexecuted instantiation: smtp-server.c:buffer_get_data Unexecuted instantiation: smtp-syntax.c:buffer_get_data Unexecuted instantiation: smtp-address.c:buffer_get_data Unexecuted instantiation: smtp-params.c:buffer_get_data Unexecuted instantiation: smtp-reply.c:buffer_get_data Unexecuted instantiation: smtp-reply-parser.c:buffer_get_data Unexecuted instantiation: smtp-command-parser.c:buffer_get_data Unexecuted instantiation: smtp-server-cmd-helo.c:buffer_get_data Unexecuted instantiation: smtp-server-cmd-mail.c:buffer_get_data Unexecuted instantiation: smtp-server-cmd-rcpt.c:buffer_get_data Unexecuted instantiation: smtp-server-cmd-xclient.c:buffer_get_data Unexecuted instantiation: smtp-parser.c:buffer_get_data Unexecuted instantiation: message-address.c:buffer_get_data Unexecuted instantiation: message-date.c:buffer_get_data Unexecuted instantiation: rfc822-parser.c:buffer_get_data Unexecuted instantiation: settings.c:buffer_get_data Unexecuted instantiation: settings-parser.c:buffer_get_data Unexecuted instantiation: expansion-program.c:buffer_get_data Unexecuted instantiation: var-expand.c:buffer_get_data Unexecuted instantiation: var-expand-parser.c:buffer_get_data Unexecuted instantiation: var-expand-lexer.c:buffer_get_data Unexecuted instantiation: expansion-parameter.c:buffer_get_data Unexecuted instantiation: expansion-filter.c:buffer_get_data Unexecuted instantiation: expansion-filter-if.c:buffer_get_data Unexecuted instantiation: array.c:buffer_get_data Unexecuted instantiation: base64.c:buffer_get_data Unexecuted instantiation: buffer.c:buffer_get_data Unexecuted instantiation: connection.c:buffer_get_data Unexecuted instantiation: data-stack.c:buffer_get_data Unexecuted instantiation: event-filter.c:buffer_get_data Unexecuted instantiation: event-filter-lexer.c:buffer_get_data Unexecuted instantiation: event-log.c:buffer_get_data Unexecuted instantiation: failures.c:buffer_get_data Unexecuted instantiation: guid.c:buffer_get_data Unexecuted instantiation: hash-method.c:buffer_get_data Unexecuted instantiation: hex-binary.c:buffer_get_data Unexecuted instantiation: iostream.c:buffer_get_data Unexecuted instantiation: iostream-pump.c:buffer_get_data Unexecuted instantiation: iostream-rawlog.c:buffer_get_data Unexecuted instantiation: istream.c:buffer_get_data Unexecuted instantiation: ioloop.c:buffer_get_data Unexecuted instantiation: ioloop-notify-inotify.c:buffer_get_data Unexecuted instantiation: ioloop-epoll.c:buffer_get_data Unexecuted instantiation: lib.c:buffer_get_data Unexecuted instantiation: lib-event.c:buffer_get_data Unexecuted instantiation: lib-signals.c:buffer_get_data Unexecuted instantiation: md4.c:buffer_get_data Unexecuted instantiation: md5.c:buffer_get_data Unexecuted instantiation: mempool.c:buffer_get_data Unexecuted instantiation: module-dir.c:buffer_get_data Unexecuted instantiation: path-util.c:buffer_get_data Unexecuted instantiation: priorityq.c:buffer_get_data Unexecuted instantiation: restrict-access.c:buffer_get_data Unexecuted instantiation: sha1.c:buffer_get_data Unexecuted instantiation: sha2.c:buffer_get_data Unexecuted instantiation: sha3.c:buffer_get_data Unexecuted instantiation: str.c:buffer_get_data Unexecuted instantiation: str-sanitize.c:buffer_get_data Unexecuted instantiation: strescape.c:buffer_get_data Unexecuted instantiation: strfuncs.c:buffer_get_data Unexecuted instantiation: unichar.c:buffer_get_data Unexecuted instantiation: wildcard-match.c:buffer_get_data Unexecuted instantiation: backtrace-string.c:buffer_get_data Unexecuted instantiation: env-util.c:buffer_get_data |
177 | | |
178 | | /* Returns the current used buffer size. */ |
179 | | static inline size_t ATTR_PURE |
180 | | buffer_get_used_size(const buffer_t *buf) |
181 | 0 | { |
182 | 0 | return buf->used; |
183 | 0 | } Unexecuted instantiation: smtp-server-cmd-data.c:buffer_get_used_size Unexecuted instantiation: smtp-server-reply.c:buffer_get_used_size Unexecuted instantiation: smtp-server-command.c:buffer_get_used_size Unexecuted instantiation: smtp-server-transaction.c:buffer_get_used_size Unexecuted instantiation: smtp-server-connection.c:buffer_get_used_size Unexecuted instantiation: smtp-server.c:buffer_get_used_size Unexecuted instantiation: smtp-syntax.c:buffer_get_used_size Unexecuted instantiation: smtp-address.c:buffer_get_used_size Unexecuted instantiation: smtp-params.c:buffer_get_used_size Unexecuted instantiation: smtp-reply.c:buffer_get_used_size Unexecuted instantiation: smtp-reply-parser.c:buffer_get_used_size Unexecuted instantiation: smtp-command-parser.c:buffer_get_used_size Unexecuted instantiation: smtp-server-cmd-helo.c:buffer_get_used_size Unexecuted instantiation: smtp-server-cmd-mail.c:buffer_get_used_size Unexecuted instantiation: smtp-server-cmd-rcpt.c:buffer_get_used_size Unexecuted instantiation: smtp-server-cmd-xclient.c:buffer_get_used_size Unexecuted instantiation: smtp-parser.c:buffer_get_used_size Unexecuted instantiation: message-address.c:buffer_get_used_size Unexecuted instantiation: message-date.c:buffer_get_used_size Unexecuted instantiation: rfc822-parser.c:buffer_get_used_size Unexecuted instantiation: settings.c:buffer_get_used_size Unexecuted instantiation: settings-parser.c:buffer_get_used_size Unexecuted instantiation: expansion-program.c:buffer_get_used_size Unexecuted instantiation: var-expand.c:buffer_get_used_size Unexecuted instantiation: var-expand-parser.c:buffer_get_used_size Unexecuted instantiation: var-expand-lexer.c:buffer_get_used_size Unexecuted instantiation: expansion-parameter.c:buffer_get_used_size Unexecuted instantiation: expansion-filter.c:buffer_get_used_size Unexecuted instantiation: expansion-filter-if.c:buffer_get_used_size Unexecuted instantiation: array.c:buffer_get_used_size Unexecuted instantiation: base64.c:buffer_get_used_size Unexecuted instantiation: buffer.c:buffer_get_used_size Unexecuted instantiation: connection.c:buffer_get_used_size Unexecuted instantiation: data-stack.c:buffer_get_used_size Unexecuted instantiation: event-filter.c:buffer_get_used_size Unexecuted instantiation: event-filter-lexer.c:buffer_get_used_size Unexecuted instantiation: event-log.c:buffer_get_used_size Unexecuted instantiation: failures.c:buffer_get_used_size Unexecuted instantiation: guid.c:buffer_get_used_size Unexecuted instantiation: hash-method.c:buffer_get_used_size Unexecuted instantiation: hex-binary.c:buffer_get_used_size Unexecuted instantiation: iostream.c:buffer_get_used_size Unexecuted instantiation: iostream-pump.c:buffer_get_used_size Unexecuted instantiation: iostream-rawlog.c:buffer_get_used_size Unexecuted instantiation: istream.c:buffer_get_used_size Unexecuted instantiation: ioloop.c:buffer_get_used_size Unexecuted instantiation: ioloop-notify-inotify.c:buffer_get_used_size Unexecuted instantiation: ioloop-epoll.c:buffer_get_used_size Unexecuted instantiation: lib.c:buffer_get_used_size Unexecuted instantiation: lib-event.c:buffer_get_used_size Unexecuted instantiation: lib-signals.c:buffer_get_used_size Unexecuted instantiation: md4.c:buffer_get_used_size Unexecuted instantiation: md5.c:buffer_get_used_size Unexecuted instantiation: mempool.c:buffer_get_used_size Unexecuted instantiation: module-dir.c:buffer_get_used_size Unexecuted instantiation: path-util.c:buffer_get_used_size Unexecuted instantiation: priorityq.c:buffer_get_used_size Unexecuted instantiation: restrict-access.c:buffer_get_used_size Unexecuted instantiation: sha1.c:buffer_get_used_size Unexecuted instantiation: sha2.c:buffer_get_used_size Unexecuted instantiation: sha3.c:buffer_get_used_size Unexecuted instantiation: str.c:buffer_get_used_size Unexecuted instantiation: str-sanitize.c:buffer_get_used_size Unexecuted instantiation: strescape.c:buffer_get_used_size Unexecuted instantiation: strfuncs.c:buffer_get_used_size Unexecuted instantiation: unichar.c:buffer_get_used_size Unexecuted instantiation: wildcard-match.c:buffer_get_used_size Unexecuted instantiation: backtrace-string.c:buffer_get_used_size Unexecuted instantiation: env-util.c:buffer_get_used_size |
184 | | |
185 | | /* Crash if buffer was allocated from data stack and stack frame has changed. |
186 | | This can be used as an assert-like check to verify that it's valid to |
187 | | increase the buffer size here, instead of crashing only randomly when the |
188 | | buffer needs to be increased. */ |
189 | | void buffer_verify_pool(buffer_t *buf); |
190 | | |
191 | | /* This will truncate your byte buffer to contain at most |
192 | | given number of bits. |
193 | | |
194 | | 1 bits: 01 00000001 |
195 | | 2 bits: 03 00000011 |
196 | | 3 bits: 07 00000111 |
197 | | 4 bits: 0f 00001111 |
198 | | 5 bits: 1f 00011111 |
199 | | 6 bits: 3f 00111111 |
200 | | 7 bits: 7f 01111111 |
201 | | 8 bits: ff 11111111 |
202 | | 9 bits: 01ff 0000000111111111 |
203 | | 10 bits: 03ff 0000001111111111 |
204 | | 11 bits: 07ff 0000011111111111 |
205 | | 12 bits: 0fff 0000111111111111 |
206 | | 13 bits: 1fff 0001111111111111 |
207 | | 14 bits: 3fff 0011111111111111 |
208 | | 15 bits: 7fff 0111111111111111 |
209 | | 16 bits: ffff 1111111111111111 |
210 | | |
211 | | and so forth |
212 | | |
213 | | */ |
214 | | void buffer_truncate_rshift_bits(buffer_t *buf, size_t bits); |
215 | | |
216 | | enum buffer_append_result { |
217 | | /* Stream reached EOF successfully */ |
218 | | BUFFER_APPEND_OK = 0, |
219 | | /* Error was encountered */ |
220 | | BUFFER_APPEND_READ_ERROR = -1, |
221 | | /* Stream is non-blocking, call again later */ |
222 | | BUFFER_APPEND_READ_MORE = -2, |
223 | | /* Stream was consumed up to max_read_size */ |
224 | | BUFFER_APPEND_READ_MAX_SIZE = -3, |
225 | | }; |
226 | | |
227 | | /* Attempt to fully read a stream. Since this can be a network stream, it |
228 | | can return BUFFER_APPEND_READ_MORE, which means you need to call this |
229 | | function again. It is caller's responsibility to keep track of |
230 | | max_read_size in case more reading is needed. */ |
231 | | enum buffer_append_result |
232 | | buffer_append_full_istream(buffer_t *buf, struct istream *is, size_t max_read_size, |
233 | | const char **error_r); |
234 | | |
235 | | /* Attempt to fully read a file. BUFFER_APPEND_READ_MORE is never returned. */ |
236 | | enum buffer_append_result |
237 | | buffer_append_full_file(buffer_t *buf, const char *file, size_t max_read_size, |
238 | | const char **error_r); |
239 | | |
240 | | #endif |