1 | /* |
2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * 3. The name of the author may not be used to endorse or promote products |
13 | * derived from this software without specific prior written permission. |
14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | #ifndef _EVENT2_BUFFER_COMPAT_H_ |
28 | #define _EVENT2_BUFFER_COMPAT_H_ |
29 | |
30 | /** @file event2/buffer_compat.h |
31 | |
32 | Obsolete and deprecated versions of the functions in buffer.h: provided |
33 | only for backward compatibility. |
34 | */ |
35 | |
36 | |
37 | /** |
38 | Obsolete alias for evbuffer_readln(buffer, NULL, EOL_STYLE_ANY). |
39 | |
40 | @deprecated This function is deprecated because its behavior is not correct |
41 | for almost any protocol, and also because it's wholly subsumed by |
42 | evbuffer_readln(). |
43 | |
44 | @param buffer the evbuffer to read from |
45 | @return pointer to a single line, or NULL if an error occurred |
46 | |
47 | */ |
48 | char *evbuffer_readline(struct evbuffer *buffer); |
49 | |
50 | /** Type definition for a callback that is invoked whenever data is added or |
51 | removed from an evbuffer. |
52 | |
53 | An evbuffer may have one or more callbacks set at a time. The order |
54 | in which they are executed is undefined. |
55 | |
56 | A callback function may add more callbacks, or remove itself from the |
57 | list of callbacks, or add or remove data from the buffer. It may not |
58 | remove another callback from the list. |
59 | |
60 | If a callback adds or removes data from the buffer or from another |
61 | buffer, this can cause a recursive invocation of your callback or |
62 | other callbacks. If you ask for an infinite loop, you might just get |
63 | one: watch out! |
64 | |
65 | @param buffer the buffer whose size has changed |
66 | @param old_len the previous length of the buffer |
67 | @param new_len the current length of the buffer |
68 | @param arg a pointer to user data |
69 | */ |
70 | typedef void (*evbuffer_cb)(struct evbuffer *buffer, size_t old_len, size_t new_len, void *arg); |
71 | |
72 | /** |
73 | Replace all callbacks on an evbuffer with a single new callback, or |
74 | remove them. |
75 | |
76 | Subsequent calls to evbuffer_setcb() replace callbacks set by previous |
77 | calls. Setting the callback to NULL removes any previously set callback. |
78 | |
79 | @deprecated This function is deprecated because it clears all previous |
80 | callbacks set on the evbuffer, which can cause confusing behavior if |
81 | multiple parts of the code all want to add their own callbacks on a |
82 | buffer. Instead, use evbuffer_add(), evbuffer_del(), and |
83 | evbuffer_setflags() to manage your own evbuffer callbacks without |
84 | interfering with callbacks set by others. |
85 | |
86 | @param buffer the evbuffer to be monitored |
87 | @param cb the callback function to invoke when the evbuffer is modified, |
88 | or NULL to remove all callbacks. |
89 | @param cbarg an argument to be provided to the callback function |
90 | */ |
91 | void evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg); |
92 | |
93 | |
94 | /** |
95 | Find a string within an evbuffer. |
96 | |
97 | @param buffer the evbuffer to be searched |
98 | @param what the string to be searched for |
99 | @param len the length of the search string |
100 | @return a pointer to the beginning of the search string, or NULL if the search failed. |
101 | */ |
102 | unsigned char *evbuffer_find(struct evbuffer *buffer, const unsigned char *what, size_t len); |
103 | |
104 | /** deprecated in favor of calling the functions directly */ |
105 | #define EVBUFFER_LENGTH(x) evbuffer_get_length(x) |
106 | /** deprecated in favor of calling the functions directly */ |
107 | #define EVBUFFER_DATA(x) evbuffer_pullup((x), -1) |
108 | |
109 | #endif |
110 | |
111 | |