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