HTP
0.3
|
00001 /*************************************************************************** 00002 * Copyright (c) 2009-2010, Open Information Security Foundation 00003 * Copyright (c) 2009-2012, Qualys, Inc. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are 00008 * met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the Qualys, Inc. nor the names of its 00016 * contributors may be used to endorse or promote products derived from 00017 * this software 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 THE COPYRIGHT 00023 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00025 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00026 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00027 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00029 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 ***************************************************************************/ 00031 00037 #ifndef _DSLIB_H 00038 #define _DSLIB_H 00039 00040 typedef struct list_t list_t; 00041 typedef struct list_array_t list_array_t; 00042 typedef struct list_linked_element_t list_linked_element_t; 00043 typedef struct list_linked_t list_linked_t; 00044 typedef struct table_t table_t; 00045 00046 #include "bstr.h" 00047 00048 #ifdef __cplusplus 00049 extern "C" { 00050 #endif 00051 00052 // IMPORTANT This library is used internally by the parser and you should 00053 // not rely on it in your code. The implementation may change at 00054 // any time. 00055 00056 // Lists 00057 00058 #define list_push(L, E) (L)->push(L, E) 00059 #define list_pop(L) (L)->pop(L) 00060 #define list_empty(L) (L)->empty(L) 00061 #define list_get(L, N) (L)->get((list_t *)L, N) 00062 #define list_replace(L, N, E) (L)->replace((list_t *)L, N, E) 00063 #define list_add(L, N) (L)->push(L, N) 00064 #define list_size(L) (L)->size(L) 00065 #define list_iterator_reset(L) (L)->iterator_reset(L) 00066 #define list_iterator_next(L) (L)->iterator_next(L) 00067 #define list_destroy(L) (*(L))->destroy(L) 00068 #define list_shift(L) (L)->shift(L) 00069 00070 #define LIST_COMMON \ 00071 int (*push)(list_t *, void *); \ 00072 void *(*pop)(list_t *); \ 00073 int (*empty)(const list_t *); \ 00074 void *(*get)(const list_t *, size_t index); \ 00075 int (*replace)(list_t *, size_t index, void *); \ 00076 size_t (*size)(const list_t *); \ 00077 void (*iterator_reset)(list_t *); \ 00078 void *(*iterator_next)(list_t *); \ 00079 void (*destroy)(list_t **); \ 00080 void *(*shift)(list_t *) 00081 00082 struct list_t { 00083 LIST_COMMON; 00084 }; 00085 00086 struct list_linked_element_t { 00087 void *data; 00088 list_linked_element_t *next; 00089 }; 00090 00091 struct list_linked_t { 00092 LIST_COMMON; 00093 00094 list_linked_element_t *first; 00095 list_linked_element_t *last; 00096 }; 00097 00098 struct list_array_t { 00099 LIST_COMMON; 00100 00101 size_t first; 00102 size_t last; 00103 size_t max_size; 00104 size_t current_size; 00105 void **elements; 00106 00107 size_t iterator_index; 00108 }; 00109 00110 list_t *list_linked_create(void); 00111 void list_linked_destroy(list_linked_t **_l); 00112 00113 list_t *list_array_create(size_t size); 00114 void list_array_iterator_reset(list_array_t *l); 00115 void *list_array_iterator_next(list_array_t *l); 00116 void list_array_destroy(list_array_t **_l); 00117 00118 00119 // Table 00120 00121 struct table_t { 00122 list_t *list; 00123 }; 00124 00125 table_t *table_create(size_t size); 00126 int table_add(table_t *, bstr *, void *); 00127 int table_addn(table_t *, bstr *, void *); 00128 void table_set(table_t *, bstr *, void *); 00129 void *table_get(const table_t *, const bstr *); 00130 void *table_get_c(const table_t *, const char *); 00131 void table_iterator_reset(table_t *); 00132 bstr *table_iterator_next(table_t *, void **); 00133 size_t table_size(const table_t *t); 00134 void table_destroy(table_t **); 00135 void table_clear(table_t *); 00136 00137 #ifdef __cplusplus 00138 } 00139 #endif 00140 00141 #endif /* _DSLIB_H */ 00142