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