1290001Sglebius/* 2290001Sglebius * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3290001Sglebius * 4290001Sglebius * Redistribution and use in source and binary forms, with or without 5290001Sglebius * modification, are permitted provided that the following conditions 6290001Sglebius * are met: 7290001Sglebius * 1. Redistributions of source code must retain the above copyright 8290001Sglebius * notice, this list of conditions and the following disclaimer. 9290001Sglebius * 2. Redistributions in binary form must reproduce the above copyright 10290001Sglebius * notice, this list of conditions and the following disclaimer in the 11290001Sglebius * documentation and/or other materials provided with the distribution. 12290001Sglebius * 3. The name of the author may not be used to endorse or promote products 13290001Sglebius * derived from this software without specific prior written permission. 14290001Sglebius * 15290001Sglebius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16290001Sglebius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17290001Sglebius * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18290001Sglebius * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19290001Sglebius * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20290001Sglebius * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21290001Sglebius * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22290001Sglebius * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23290001Sglebius * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24290001Sglebius * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25290001Sglebius */ 26290001Sglebius 27290001Sglebius#ifndef EVENT2_BUFFER_COMPAT_H_INCLUDED_ 28290001Sglebius#define EVENT2_BUFFER_COMPAT_H_INCLUDED_ 29290001Sglebius 30290001Sglebius#include <event2/visibility.h> 31290001Sglebius 32290001Sglebius/** @file event2/buffer_compat.h 33290001Sglebius 34290001Sglebius Obsolete and deprecated versions of the functions in buffer.h: provided 35290001Sglebius only for backward compatibility. 36290001Sglebius */ 37290001Sglebius 38290001Sglebius 39290001Sglebius/** 40290001Sglebius Obsolete alias for evbuffer_readln(buffer, NULL, EOL_STYLE_ANY). 41290001Sglebius 42290001Sglebius @deprecated This function is deprecated because its behavior is not correct 43290001Sglebius for almost any protocol, and also because it's wholly subsumed by 44290001Sglebius evbuffer_readln(). 45290001Sglebius 46290001Sglebius @param buffer the evbuffer to read from 47290001Sglebius @return pointer to a single line, or NULL if an error occurred 48290001Sglebius 49290001Sglebius*/ 50290001SglebiusEVENT2_EXPORT_SYMBOL 51290001Sglebiuschar *evbuffer_readline(struct evbuffer *buffer); 52290001Sglebius 53290001Sglebius/** Type definition for a callback that is invoked whenever data is added or 54290001Sglebius removed from an evbuffer. 55290001Sglebius 56290001Sglebius An evbuffer may have one or more callbacks set at a time. The order 57290001Sglebius in which they are executed is undefined. 58290001Sglebius 59290001Sglebius A callback function may add more callbacks, or remove itself from the 60290001Sglebius list of callbacks, or add or remove data from the buffer. It may not 61290001Sglebius remove another callback from the list. 62290001Sglebius 63290001Sglebius If a callback adds or removes data from the buffer or from another 64290001Sglebius buffer, this can cause a recursive invocation of your callback or 65290001Sglebius other callbacks. If you ask for an infinite loop, you might just get 66290001Sglebius one: watch out! 67290001Sglebius 68290001Sglebius @param buffer the buffer whose size has changed 69290001Sglebius @param old_len the previous length of the buffer 70290001Sglebius @param new_len the current length of the buffer 71290001Sglebius @param arg a pointer to user data 72290001Sglebius*/ 73290001Sglebiustypedef void (*evbuffer_cb)(struct evbuffer *buffer, size_t old_len, size_t new_len, void *arg); 74290001Sglebius 75290001Sglebius/** 76290001Sglebius Replace all callbacks on an evbuffer with a single new callback, or 77290001Sglebius remove them. 78290001Sglebius 79290001Sglebius Subsequent calls to evbuffer_setcb() replace callbacks set by previous 80290001Sglebius calls. Setting the callback to NULL removes any previously set callback. 81290001Sglebius 82290001Sglebius @deprecated This function is deprecated because it clears all previous 83290001Sglebius callbacks set on the evbuffer, which can cause confusing behavior if 84290001Sglebius multiple parts of the code all want to add their own callbacks on a 85290001Sglebius buffer. Instead, use evbuffer_add(), evbuffer_del(), and 86290001Sglebius evbuffer_setflags() to manage your own evbuffer callbacks without 87290001Sglebius interfering with callbacks set by others. 88290001Sglebius 89290001Sglebius @param buffer the evbuffer to be monitored 90290001Sglebius @param cb the callback function to invoke when the evbuffer is modified, 91290001Sglebius or NULL to remove all callbacks. 92290001Sglebius @param cbarg an argument to be provided to the callback function 93290001Sglebius */ 94290001SglebiusEVENT2_EXPORT_SYMBOL 95290001Sglebiusvoid evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg); 96290001Sglebius 97290001Sglebius 98290001Sglebius/** 99290001Sglebius Find a string within an evbuffer. 100290001Sglebius 101290001Sglebius @param buffer the evbuffer to be searched 102290001Sglebius @param what the string to be searched for 103290001Sglebius @param len the length of the search string 104290001Sglebius @return a pointer to the beginning of the search string, or NULL if the search failed. 105290001Sglebius */ 106290001SglebiusEVENT2_EXPORT_SYMBOL 107290001Sglebiusunsigned char *evbuffer_find(struct evbuffer *buffer, const unsigned char *what, size_t len); 108290001Sglebius 109290001Sglebius/** deprecated in favor of calling the functions directly */ 110290001Sglebius#define EVBUFFER_LENGTH(x) evbuffer_get_length(x) 111290001Sglebius/** deprecated in favor of calling the functions directly */ 112290001Sglebius#define EVBUFFER_DATA(x) evbuffer_pullup((x), -1) 113290001Sglebius 114290001Sglebius#endif 115290001Sglebius 116