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