HTP
0.3
|
00001 /*************************************************************************** 00002 * Copyright 2009-2010 Open Information Security Foundation 00003 * Copyright 2010-2011 Qualys, Inc. 00004 * 00005 * Licensed to You under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 ***************************************************************************/ 00017 00023 #ifndef _DSLIB_H 00024 #define _DSLIB_H 00025 00026 typedef struct list_t list_t; 00027 typedef struct list_array_t list_array_t; 00028 typedef struct list_linked_element_t list_linked_element_t; 00029 typedef struct list_linked_t list_linked_t; 00030 typedef struct table_t table_t; 00031 00032 #include "bstr.h" 00033 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif 00037 00038 // IMPORTANT This library is used internally by the parser and you should 00039 // not rely on it in your code. The implementation may change at 00040 // any time. 00041 00042 // Lists 00043 00044 #define list_push(L, E) (L)->push(L, E) 00045 #define list_pop(L) (L)->pop(L) 00046 #define list_empty(L) (L)->empty(L) 00047 #define list_get(L, N) (L)->get((list_t *)L, N) 00048 #define list_replace(L, N, E) (L)->replace((list_t *)L, N, E) 00049 #define list_add(L, N) (L)->push(L, N) 00050 #define list_size(L) (L)->size(L) 00051 #define list_iterator_reset(L) (L)->iterator_reset(L) 00052 #define list_iterator_next(L) (L)->iterator_next(L) 00053 #define list_destroy(L) (*(L))->destroy(L) 00054 #define list_shift(L) (L)->shift(L) 00055 00056 #define LIST_COMMON \ 00057 int (*push)(list_t *, void *); \ 00058 void *(*pop)(list_t *); \ 00059 int (*empty)(const list_t *); \ 00060 void *(*get)(const list_t *, size_t index); \ 00061 int (*replace)(list_t *, size_t index, void *); \ 00062 size_t (*size)(const list_t *); \ 00063 void (*iterator_reset)(list_t *); \ 00064 void *(*iterator_next)(list_t *); \ 00065 void (*destroy)(list_t **); \ 00066 void *(*shift)(list_t *) 00067 00068 struct list_t { 00069 LIST_COMMON; 00070 }; 00071 00072 struct list_linked_element_t { 00073 void *data; 00074 list_linked_element_t *next; 00075 }; 00076 00077 struct list_linked_t { 00078 LIST_COMMON; 00079 00080 list_linked_element_t *first; 00081 list_linked_element_t *last; 00082 }; 00083 00084 struct list_array_t { 00085 LIST_COMMON; 00086 00087 size_t first; 00088 size_t last; 00089 size_t max_size; 00090 size_t current_size; 00091 void **elements; 00092 00093 size_t iterator_index; 00094 }; 00095 00096 list_t *list_linked_create(void); 00097 void list_linked_destroy(list_linked_t **_l); 00098 00099 list_t *list_array_create(size_t size); 00100 void list_array_iterator_reset(list_array_t *l); 00101 void *list_array_iterator_next(list_array_t *l); 00102 void list_array_destroy(list_array_t **_l); 00103 00104 00105 // Table 00106 00107 struct table_t { 00108 list_t *list; 00109 }; 00110 00111 table_t *table_create(size_t size); 00112 int table_add(table_t *, bstr *, void *); 00113 int table_addn(table_t *, bstr *, void *); 00114 void table_set(table_t *, bstr *, void *); 00115 void *table_get(const table_t *, const bstr *); 00116 void *table_get_c(const table_t *, const char *); 00117 void table_iterator_reset(table_t *); 00118 bstr *table_iterator_next(table_t *, void **); 00119 size_t table_size(const table_t *t); 00120 void table_destroy(table_t **); 00121 void table_clear(table_t *); 00122 00123 #ifdef __cplusplus 00124 } 00125 #endif 00126 00127 #endif /* _DSLIB_H */ 00128