12b15cb3dSCy Schubert /* 22b15cb3dSCy Schubert * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 32b15cb3dSCy Schubert * 42b15cb3dSCy Schubert * Redistribution and use in source and binary forms, with or without 52b15cb3dSCy Schubert * modification, are permitted provided that the following conditions 62b15cb3dSCy Schubert * are met: 72b15cb3dSCy Schubert * 1. Redistributions of source code must retain the above copyright 82b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer. 92b15cb3dSCy Schubert * 2. Redistributions in binary form must reproduce the above copyright 102b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer in the 112b15cb3dSCy Schubert * documentation and/or other materials provided with the distribution. 122b15cb3dSCy Schubert * 3. The name of the author may not be used to endorse or promote products 132b15cb3dSCy Schubert * derived from this software without specific prior written permission. 142b15cb3dSCy Schubert * 152b15cb3dSCy Schubert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 162b15cb3dSCy Schubert * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 172b15cb3dSCy Schubert * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 182b15cb3dSCy Schubert * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 192b15cb3dSCy Schubert * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 202b15cb3dSCy Schubert * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 212b15cb3dSCy Schubert * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 222b15cb3dSCy Schubert * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 232b15cb3dSCy Schubert * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 242b15cb3dSCy Schubert * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 252b15cb3dSCy Schubert */ 262b15cb3dSCy Schubert 272b15cb3dSCy Schubert #ifndef EVENT2_BUFFER_COMPAT_H_INCLUDED_ 282b15cb3dSCy Schubert #define EVENT2_BUFFER_COMPAT_H_INCLUDED_ 292b15cb3dSCy Schubert 302b15cb3dSCy Schubert #include <event2/visibility.h> 312b15cb3dSCy Schubert 322b15cb3dSCy Schubert /** @file event2/buffer_compat.h 332b15cb3dSCy Schubert 342b15cb3dSCy Schubert Obsolete and deprecated versions of the functions in buffer.h: provided 352b15cb3dSCy Schubert only for backward compatibility. 362b15cb3dSCy Schubert */ 372b15cb3dSCy Schubert 382b15cb3dSCy Schubert 392b15cb3dSCy Schubert /** 40*a466cc55SCy Schubert Obsolete alias for evbuffer_readln(buffer, NULL, EVBUFFER_EOL_ANY). 412b15cb3dSCy Schubert 422b15cb3dSCy Schubert @deprecated This function is deprecated because its behavior is not correct 432b15cb3dSCy Schubert for almost any protocol, and also because it's wholly subsumed by 442b15cb3dSCy Schubert evbuffer_readln(). 452b15cb3dSCy Schubert 462b15cb3dSCy Schubert @param buffer the evbuffer to read from 472b15cb3dSCy Schubert @return pointer to a single line, or NULL if an error occurred 482b15cb3dSCy Schubert 492b15cb3dSCy Schubert */ 502b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 512b15cb3dSCy Schubert char *evbuffer_readline(struct evbuffer *buffer); 522b15cb3dSCy Schubert 532b15cb3dSCy Schubert /** Type definition for a callback that is invoked whenever data is added or 542b15cb3dSCy Schubert removed from an evbuffer. 552b15cb3dSCy Schubert 562b15cb3dSCy Schubert An evbuffer may have one or more callbacks set at a time. The order 572b15cb3dSCy Schubert in which they are executed is undefined. 582b15cb3dSCy Schubert 592b15cb3dSCy Schubert A callback function may add more callbacks, or remove itself from the 602b15cb3dSCy Schubert list of callbacks, or add or remove data from the buffer. It may not 612b15cb3dSCy Schubert remove another callback from the list. 622b15cb3dSCy Schubert 632b15cb3dSCy Schubert If a callback adds or removes data from the buffer or from another 642b15cb3dSCy Schubert buffer, this can cause a recursive invocation of your callback or 652b15cb3dSCy Schubert other callbacks. If you ask for an infinite loop, you might just get 662b15cb3dSCy Schubert one: watch out! 672b15cb3dSCy Schubert 682b15cb3dSCy Schubert @param buffer the buffer whose size has changed 692b15cb3dSCy Schubert @param old_len the previous length of the buffer 702b15cb3dSCy Schubert @param new_len the current length of the buffer 712b15cb3dSCy Schubert @param arg a pointer to user data 722b15cb3dSCy Schubert */ 732b15cb3dSCy Schubert typedef void (*evbuffer_cb)(struct evbuffer *buffer, size_t old_len, size_t new_len, void *arg); 742b15cb3dSCy Schubert 752b15cb3dSCy Schubert /** 762b15cb3dSCy Schubert Replace all callbacks on an evbuffer with a single new callback, or 772b15cb3dSCy Schubert remove them. 782b15cb3dSCy Schubert 792b15cb3dSCy Schubert Subsequent calls to evbuffer_setcb() replace callbacks set by previous 802b15cb3dSCy Schubert calls. Setting the callback to NULL removes any previously set callback. 812b15cb3dSCy Schubert 822b15cb3dSCy Schubert @deprecated This function is deprecated because it clears all previous 832b15cb3dSCy Schubert callbacks set on the evbuffer, which can cause confusing behavior if 842b15cb3dSCy Schubert multiple parts of the code all want to add their own callbacks on a 852b15cb3dSCy Schubert buffer. Instead, use evbuffer_add(), evbuffer_del(), and 862b15cb3dSCy Schubert evbuffer_setflags() to manage your own evbuffer callbacks without 872b15cb3dSCy Schubert interfering with callbacks set by others. 882b15cb3dSCy Schubert 892b15cb3dSCy Schubert @param buffer the evbuffer to be monitored 902b15cb3dSCy Schubert @param cb the callback function to invoke when the evbuffer is modified, 912b15cb3dSCy Schubert or NULL to remove all callbacks. 922b15cb3dSCy Schubert @param cbarg an argument to be provided to the callback function 93*a466cc55SCy Schubert @return 0 if successful, or -1 on error 942b15cb3dSCy Schubert */ 952b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 96*a466cc55SCy Schubert int evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg); 972b15cb3dSCy Schubert 982b15cb3dSCy Schubert 992b15cb3dSCy Schubert /** 1002b15cb3dSCy Schubert Find a string within an evbuffer. 1012b15cb3dSCy Schubert 1022b15cb3dSCy Schubert @param buffer the evbuffer to be searched 1032b15cb3dSCy Schubert @param what the string to be searched for 1042b15cb3dSCy Schubert @param len the length of the search string 1052b15cb3dSCy Schubert @return a pointer to the beginning of the search string, or NULL if the search failed. 1062b15cb3dSCy Schubert */ 1072b15cb3dSCy Schubert EVENT2_EXPORT_SYMBOL 1082b15cb3dSCy Schubert unsigned char *evbuffer_find(struct evbuffer *buffer, const unsigned char *what, size_t len); 1092b15cb3dSCy Schubert 1102b15cb3dSCy Schubert /** deprecated in favor of calling the functions directly */ 1112b15cb3dSCy Schubert #define EVBUFFER_LENGTH(x) evbuffer_get_length(x) 1122b15cb3dSCy Schubert /** deprecated in favor of calling the functions directly */ 1132b15cb3dSCy Schubert #define EVBUFFER_DATA(x) evbuffer_pullup((x), -1) 1142b15cb3dSCy Schubert 1152b15cb3dSCy Schubert #endif 1162b15cb3dSCy Schubert 117