libUPnP
1.6.17
|
00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2000-2003 Intel Corporation 00004 * All rights reserved. 00005 * Copyright (c) 2012 France Telecom All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * - Redistributions of source code must retain the above copyright notice, 00011 * this list of conditions and the following disclaimer. 00012 * - Redistributions in binary form must reproduce the above copyright notice, 00013 * this list of conditions and the following disclaimer in the documentation 00014 * and/or other materials provided with the distribution. 00015 * - Neither name of Intel Corporation nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software 00017 * without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 00023 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00024 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00025 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00027 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 ******************************************************************************/ 00032 00033 #ifndef GENLIB_UTIL_MEMBUFFER_H 00034 #define GENLIB_UTIL_MEMBUFFER_H 00035 00040 #include <stdlib.h> 00041 #include "upnputil.h" 00042 00043 #define MINVAL( a, b ) ( (a) < (b) ? (a) : (b) ) 00044 #define MAXVAL( a, b ) ( (a) > (b) ? (a) : (b) ) 00045 00047 typedef struct { 00049 char *buf; 00051 size_t length; 00052 } memptr; 00053 00056 typedef struct { 00058 char *buf; 00060 size_t length; 00062 size_t capacity; 00064 size_t size_inc; 00066 #define MEMBUF_DEF_SIZE_INC (size_t)5 00067 } membuffer; 00068 00069 #ifdef __cplusplus 00070 extern "C" { 00071 #endif /* __cplusplus */ 00072 00080 char *str_alloc( 00082 const char *str, 00084 size_t str_len); 00085 00096 int memptr_cmp( 00098 memptr *m, 00100 const char *s); 00101 00114 int memptr_cmp_nocase( 00116 memptr *m, 00118 const char *s); 00119 00128 int membuffer_set_size( 00130 membuffer *m, 00132 size_t new_length); 00133 00140 void membuffer_init( 00142 membuffer *m); 00143 00147 void membuffer_destroy( 00149 membuffer *m); 00150 00159 int membuffer_assign( 00161 membuffer *m, 00163 const void *buf, 00165 size_t buf_len); 00166 00174 int membuffer_assign_str( 00176 membuffer *m, 00178 const char *c_str); 00179 00185 int membuffer_append( 00187 membuffer *m, 00189 const void *buf, 00191 size_t buf_len); 00192 00198 int membuffer_append_str( 00200 membuffer *m, 00202 const char *c_str); 00203 00211 int membuffer_insert( 00213 membuffer * m, 00215 const void *buf, 00217 size_t buf_len, 00219 size_t index); 00220 00226 void membuffer_delete( 00229 membuffer * m, 00231 size_t index, 00233 size_t num_bytes); 00234 00235 /* 00236 * \brief Detaches current buffer and returns it. The caller must free the 00237 * returned buffer using free(). After this call, length becomes 0. 00238 * 00239 * \return A pointer to the current buffer. 00240 */ 00241 char *membuffer_detach( 00243 membuffer *m); 00244 00245 /* 00246 * \brief Free existing memory in membuffer and assign the new buffer in its 00247 * place. 00248 * 00249 * \note 'new_buf' must be allocted using malloc or realloc so that it can be 00250 * freed using free(). 00251 */ 00252 void membuffer_attach( 00254 membuffer *m, 00257 char *new_buf, 00259 size_t buf_len); 00260 00261 #ifdef __cplusplus 00262 } /* extern "C" */ 00263 #endif /* __cplusplus */ 00264 00265 #endif /* GENLIB_UTIL_MEMBUFFER_H */