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