1*657871a7Schristos /* $NetBSD: buffer_compat.h,v 1.1.1.4 2021/04/07 02:43:14 christos Exp $ */ 26ecf6635Schristos /* 36ecf6635Schristos * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 46ecf6635Schristos * 56ecf6635Schristos * Redistribution and use in source and binary forms, with or without 66ecf6635Schristos * modification, are permitted provided that the following conditions 76ecf6635Schristos * are met: 86ecf6635Schristos * 1. Redistributions of source code must retain the above copyright 96ecf6635Schristos * notice, this list of conditions and the following disclaimer. 106ecf6635Schristos * 2. Redistributions in binary form must reproduce the above copyright 116ecf6635Schristos * notice, this list of conditions and the following disclaimer in the 126ecf6635Schristos * documentation and/or other materials provided with the distribution. 136ecf6635Schristos * 3. The name of the author may not be used to endorse or promote products 146ecf6635Schristos * derived from this software without specific prior written permission. 156ecf6635Schristos * 166ecf6635Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 176ecf6635Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 186ecf6635Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 196ecf6635Schristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 206ecf6635Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 216ecf6635Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 226ecf6635Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 236ecf6635Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 246ecf6635Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 256ecf6635Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 266ecf6635Schristos */ 276ecf6635Schristos 28805a1ce9Schristos #ifndef EVENT2_BUFFER_COMPAT_H_INCLUDED_ 29805a1ce9Schristos #define EVENT2_BUFFER_COMPAT_H_INCLUDED_ 30805a1ce9Schristos 31805a1ce9Schristos #include <event2/visibility.h> 326ecf6635Schristos 336ecf6635Schristos /** @file event2/buffer_compat.h 346ecf6635Schristos 356ecf6635Schristos Obsolete and deprecated versions of the functions in buffer.h: provided 366ecf6635Schristos only for backward compatibility. 376ecf6635Schristos */ 386ecf6635Schristos 396ecf6635Schristos 406ecf6635Schristos /** 41805a1ce9Schristos Obsolete alias for evbuffer_readln(buffer, NULL, EVBUFFER_EOL_ANY). 426ecf6635Schristos 436ecf6635Schristos @deprecated This function is deprecated because its behavior is not correct 446ecf6635Schristos for almost any protocol, and also because it's wholly subsumed by 456ecf6635Schristos evbuffer_readln(). 466ecf6635Schristos 476ecf6635Schristos @param buffer the evbuffer to read from 486ecf6635Schristos @return pointer to a single line, or NULL if an error occurred 496ecf6635Schristos 506ecf6635Schristos */ 51805a1ce9Schristos EVENT2_EXPORT_SYMBOL 526ecf6635Schristos char *evbuffer_readline(struct evbuffer *buffer); 536ecf6635Schristos 546ecf6635Schristos /** Type definition for a callback that is invoked whenever data is added or 556ecf6635Schristos removed from an evbuffer. 566ecf6635Schristos 576ecf6635Schristos An evbuffer may have one or more callbacks set at a time. The order 586ecf6635Schristos in which they are executed is undefined. 596ecf6635Schristos 606ecf6635Schristos A callback function may add more callbacks, or remove itself from the 616ecf6635Schristos list of callbacks, or add or remove data from the buffer. It may not 626ecf6635Schristos remove another callback from the list. 636ecf6635Schristos 646ecf6635Schristos If a callback adds or removes data from the buffer or from another 656ecf6635Schristos buffer, this can cause a recursive invocation of your callback or 666ecf6635Schristos other callbacks. If you ask for an infinite loop, you might just get 676ecf6635Schristos one: watch out! 686ecf6635Schristos 696ecf6635Schristos @param buffer the buffer whose size has changed 706ecf6635Schristos @param old_len the previous length of the buffer 716ecf6635Schristos @param new_len the current length of the buffer 726ecf6635Schristos @param arg a pointer to user data 736ecf6635Schristos */ 746ecf6635Schristos typedef void (*evbuffer_cb)(struct evbuffer *buffer, size_t old_len, size_t new_len, void *arg); 756ecf6635Schristos 766ecf6635Schristos /** 776ecf6635Schristos Replace all callbacks on an evbuffer with a single new callback, or 786ecf6635Schristos remove them. 796ecf6635Schristos 806ecf6635Schristos Subsequent calls to evbuffer_setcb() replace callbacks set by previous 816ecf6635Schristos calls. Setting the callback to NULL removes any previously set callback. 826ecf6635Schristos 836ecf6635Schristos @deprecated This function is deprecated because it clears all previous 846ecf6635Schristos callbacks set on the evbuffer, which can cause confusing behavior if 856ecf6635Schristos multiple parts of the code all want to add their own callbacks on a 866ecf6635Schristos buffer. Instead, use evbuffer_add(), evbuffer_del(), and 876ecf6635Schristos evbuffer_setflags() to manage your own evbuffer callbacks without 886ecf6635Schristos interfering with callbacks set by others. 896ecf6635Schristos 906ecf6635Schristos @param buffer the evbuffer to be monitored 916ecf6635Schristos @param cb the callback function to invoke when the evbuffer is modified, 926ecf6635Schristos or NULL to remove all callbacks. 936ecf6635Schristos @param cbarg an argument to be provided to the callback function 94*657871a7Schristos @return 0 if successful, or -1 on error 956ecf6635Schristos */ 96805a1ce9Schristos EVENT2_EXPORT_SYMBOL 97*657871a7Schristos int evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg); 986ecf6635Schristos 996ecf6635Schristos 1006ecf6635Schristos /** 1016ecf6635Schristos Find a string within an evbuffer. 1026ecf6635Schristos 1036ecf6635Schristos @param buffer the evbuffer to be searched 1046ecf6635Schristos @param what the string to be searched for 1056ecf6635Schristos @param len the length of the search string 1066ecf6635Schristos @return a pointer to the beginning of the search string, or NULL if the search failed. 1076ecf6635Schristos */ 108805a1ce9Schristos EVENT2_EXPORT_SYMBOL 1096ecf6635Schristos unsigned char *evbuffer_find(struct evbuffer *buffer, const unsigned char *what, size_t len); 1106ecf6635Schristos 1116ecf6635Schristos /** deprecated in favor of calling the functions directly */ 1126ecf6635Schristos #define EVBUFFER_LENGTH(x) evbuffer_get_length(x) 1136ecf6635Schristos /** deprecated in favor of calling the functions directly */ 1146ecf6635Schristos #define EVBUFFER_DATA(x) evbuffer_pullup((x), -1) 1156ecf6635Schristos 1166ecf6635Schristos #endif 1176ecf6635Schristos 118