"Fossies" - the Fresh Open Source Software Archive 
Member "snort-2.9.17/src/dynamic-preprocessors/dcerpc2/dce2_list.h" (16 Oct 2020, 10294 Bytes) of package /linux/misc/snort-2.9.17.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "dce2_list.h" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
2.9.16.1_vs_2.9.17.
1 /****************************************************************************
2 * Copyright (C) 2014-2020 Cisco and/or its affiliates. All rights reserved.
3 * Copyright (C) 2008-2013 Sourcefire, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License Version 2 as
7 * published by the Free Software Foundation. You may not use, modify or
8 * distribute this program under any other version of the GNU General
9 * Public License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 ****************************************************************************
21 * Provides list, queue and stack data structures and methods for use
22 * with the preprocessor.
23 *
24 * 8/17/2008 - Initial implementation ... Todd Wease <twease@sourcefire.com>
25 *
26 ****************************************************************************/
27
28 #ifndef _DCE2_LIST_H_
29 #define _DCE2_LIST_H_
30
31 #include "dce2_memory.h"
32 #include "dce2_utils.h"
33 #include "sf_types.h"
34 #include "snort_debug.h"
35
36 /********************************************************************
37 * Enumerations
38 ********************************************************************/
39 typedef enum _DCE2_ListType
40 {
41 DCE2_LIST_TYPE__NORMAL = 0, /* Don't do anything special */
42 DCE2_LIST_TYPE__SORTED, /* Sort list by key */
43 DCE2_LIST_TYPE__SPLAYED /* Move most recently accessed node to head */
44
45 } DCE2_ListType;
46
47 typedef enum _DCE2_ListFlags
48 {
49 DCE2_LIST_FLAG__NO_FLAG = 0x00, /* No flags */
50 DCE2_LIST_FLAG__NO_DUPS = 0x01, /* No duplicate keys in list */
51 DCE2_LIST_FLAG__INS_TAIL = 0x02 /* Insert at tail - default is to insert at head */
52
53 } DCE2_ListFlags;
54
55 /********************************************************************
56 * Callbacks
57 ********************************************************************/
58 typedef void (*DCE2_ListDataFree)(void *);
59 typedef void (*DCE2_ListKeyFree)(void *);
60 typedef int (*DCE2_ListKeyCompare)(const void *, const void *);
61
62 /********************************************************************
63 * Structures
64 ********************************************************************/
65 typedef struct _DCE2_ListNode
66 {
67 void *key;
68 void *data;
69 struct _DCE2_ListNode *prev;
70 struct _DCE2_ListNode *next;
71
72 } DCE2_ListNode;
73
74 typedef struct _DCE2_List
75 {
76 DCE2_ListType type;
77 DCE2_MemType mtype;
78 uint32_t num_nodes;
79 int flags;
80 DCE2_ListKeyCompare compare;
81 DCE2_ListDataFree data_free;
82 DCE2_ListKeyFree key_free;
83 struct _DCE2_ListNode *head;
84 struct _DCE2_ListNode *tail;
85 struct _DCE2_ListNode *current;
86 struct _DCE2_ListNode *next;
87 struct _DCE2_ListNode *prev;
88
89 } DCE2_List;
90
91 typedef struct _DCE2_QueueNode
92 {
93 void *data;
94 struct _DCE2_QueueNode *prev;
95 struct _DCE2_QueueNode *next;
96
97 } DCE2_QueueNode;
98
99 typedef DCE2_ListDataFree DCE2_QueueDataFree;
100
101 typedef struct _DCE2_Queue
102 {
103 uint32_t num_nodes;
104 DCE2_MemType mtype;
105 DCE2_QueueDataFree data_free;
106 struct _DCE2_QueueNode *current;
107 struct _DCE2_QueueNode *head;
108 struct _DCE2_QueueNode *tail;
109 struct _DCE2_QueueNode *next;
110 struct _DCE2_QueueNode *prev;
111
112 } DCE2_Queue;
113
114 typedef struct _DCE2_StackNode
115 {
116 void *data;
117 struct _DCE2_StackNode *prev;
118 struct _DCE2_StackNode *next;
119
120 } DCE2_StackNode;
121
122 typedef DCE2_ListDataFree DCE2_StackDataFree;
123
124 typedef struct _DCE2_Stack
125 {
126 uint32_t num_nodes;
127 DCE2_MemType mtype;
128 DCE2_StackDataFree data_free;
129 struct _DCE2_StackNode *current;
130 struct _DCE2_StackNode *head;
131 struct _DCE2_StackNode *tail;
132
133 } DCE2_Stack;
134
135 /* Circular queue */
136 typedef DCE2_ListDataFree DCE2_CQueueDataFree;
137
138 typedef struct _DCE2_CQueue
139 {
140 uint32_t num_nodes;
141 DCE2_MemType mtype;
142 DCE2_CQueueDataFree data_free;
143 int size;
144 int cur_idx;
145 void **queue;
146 int head_idx;
147 int tail_idx;
148
149 } DCE2_CQueue;
150
151 typedef DCE2_ListDataFree DCE2_CStackDataFree;
152
153 typedef struct _DCE2_CStack
154 {
155 uint32_t num_nodes;
156 DCE2_MemType mtype;
157 DCE2_CStackDataFree data_free;
158 int size;
159 void **stack;
160 int tail_idx;
161 int cur_idx;
162
163 } DCE2_CStack;
164
165 /********************************************************************
166 * Public function prototypes
167 ********************************************************************/
168 DCE2_List * DCE2_ListNew(DCE2_ListType, DCE2_ListKeyCompare, DCE2_ListDataFree,
169 DCE2_ListKeyFree, int, DCE2_MemType);
170 void * DCE2_ListFind(DCE2_List *, void *);
171 DCE2_Ret DCE2_ListFindKey(DCE2_List *, void *);
172 DCE2_Ret DCE2_ListInsert(DCE2_List *, void *, void *);
173 DCE2_Ret DCE2_ListRemove(DCE2_List *, void *);
174 void * DCE2_ListFirst(DCE2_List *);
175 void * DCE2_ListNext(DCE2_List *);
176 void * DCE2_ListLast(DCE2_List *);
177 void * DCE2_ListPrev(DCE2_List *);
178 void DCE2_ListRemoveCurrent(DCE2_List *);
179 static inline int DCE2_ListIsEmpty(DCE2_List *);
180 void DCE2_ListEmpty(DCE2_List *);
181 void DCE2_ListDestroy(DCE2_List *);
182
183 DCE2_Queue * DCE2_QueueNew(DCE2_QueueDataFree, DCE2_MemType);
184 DCE2_Ret DCE2_QueueEnqueue(DCE2_Queue *, void *);
185 void * DCE2_QueueDequeue(DCE2_Queue *);
186 void * DCE2_QueueFirst(DCE2_Queue *);
187 void * DCE2_QueueNext(DCE2_Queue *);
188 void * DCE2_QueueLast(DCE2_Queue *);
189 void * DCE2_QueuePrev(DCE2_Queue *);
190 void DCE2_QueueRemoveCurrent(DCE2_Queue *);
191 static inline int DCE2_QueueIsEmpty(DCE2_Queue *);
192 void DCE2_QueueEmpty(DCE2_Queue *);
193 void DCE2_QueueDestroy(DCE2_Queue *);
194
195 DCE2_Stack * DCE2_StackNew(DCE2_StackDataFree, DCE2_MemType);
196 DCE2_Ret DCE2_StackPush(DCE2_Stack *, void *);
197 void * DCE2_StackPop(DCE2_Stack *);
198 void * DCE2_StackFirst(DCE2_Stack *);
199 void * DCE2_StackNext(DCE2_Stack *);
200 void * DCE2_StackLast(DCE2_Stack *);
201 void * DCE2_StackPrev(DCE2_Stack *);
202 static inline int DCE2_StackIsEmpty(DCE2_Stack *);
203 void DCE2_StackEmpty(DCE2_Stack *);
204 void DCE2_StackDestroy(DCE2_Stack *);
205
206 DCE2_CQueue * DCE2_CQueueNew(int, DCE2_CQueueDataFree, DCE2_MemType);
207 DCE2_Ret DCE2_CQueueEnqueue(DCE2_CQueue *, void *);
208 void * DCE2_CQueueDequeue(DCE2_CQueue *);
209 void * DCE2_CQueueFirst(DCE2_CQueue *);
210 void * DCE2_CQueueNext(DCE2_CQueue *);
211 static inline int DCE2_CQueueIsEmpty(DCE2_CQueue *);
212 void DCE2_CQueueEmpty(DCE2_CQueue *);
213 void DCE2_CQueueDestroy(DCE2_CQueue *);
214
215 DCE2_CStack * DCE2_CStackNew(int, DCE2_CStackDataFree, DCE2_MemType);
216 DCE2_Ret DCE2_CStackPush(DCE2_CStack *, void *);
217 void * DCE2_CStackPop(DCE2_CStack *);
218 void * DCE2_CStackTop(DCE2_CStack *);
219 void * DCE2_CStackFirst(DCE2_CStack *);
220 void * DCE2_CStackNext(DCE2_CStack *);
221 static inline int DCE2_CStackIsEmpty(DCE2_CStack *);
222 void DCE2_CStackEmpty(DCE2_CStack *);
223 void DCE2_CStackDestroy(DCE2_CStack *);
224
225 /********************************************************************
226 * Function: DCE2_ListIsEmpty()
227 *
228 * Determines whether or not the list has any items in it
229 * currently.
230 *
231 * Arguments:
232 * DCE2_List *
233 * A pointer to the list object.
234 *
235 * Returns:
236 * int
237 * 1 if the list has zero nodes in it or the list object
238 * passed in is NULL.
239 * 0 if the list has one or more nodes in it.
240 *
241 ********************************************************************/
242 static inline int DCE2_ListIsEmpty(DCE2_List *list)
243 {
244 if (list == NULL) return 1;
245 if (list->num_nodes == 0) return 1;
246 return 0;
247 }
248
249 /********************************************************************
250 * Function: DCE2_QueueIsEmpty()
251 *
252 * Determines whether or not the queue has any items in it
253 * currently.
254 *
255 * Arguments:
256 * DCE2_Queue *
257 * A pointer to the queue object.
258 *
259 * Returns:
260 * int
261 * 1 if the queue has zero nodes in it or the queue object
262 * passed in is NULL.
263 * 0 if the queue has one or more nodes in it.
264 *
265 ********************************************************************/
266 static inline int DCE2_QueueIsEmpty(DCE2_Queue *queue)
267 {
268 if (queue == NULL) return 1;
269 if (queue->num_nodes == 0) return 1;
270 return 0;
271 }
272
273 /********************************************************************
274 * Function: DCE2_StackIsEmpty()
275 *
276 * Determines whether or not the stack has any items in it
277 * currently.
278 *
279 * Arguments:
280 * DCE2_Stack *
281 * A pointer to the stack object.
282 *
283 * Returns:
284 * int
285 * 1 if the stack has zero nodes in it or the stack object
286 * passed in is NULL.
287 * 0 if the stack has one or more nodes in it.
288 *
289 ********************************************************************/
290 static inline int DCE2_StackIsEmpty(DCE2_Stack *stack)
291 {
292 if (stack == NULL) return 1;
293 if (stack->num_nodes == 0) return 1;
294 return 0;
295 }
296
297 /********************************************************************
298 * Function: DCE2_CQueueIsEmpty()
299 *
300 * Determines whether or not the queue has any items in it
301 * currently.
302 *
303 * Arguments:
304 * DCE2_CQueue *
305 * A pointer to the queue object.
306 *
307 * Returns:
308 * int
309 * 1 if the queue has zero nodes in it or the queue object
310 * passed in is NULL.
311 * 0 if the queue has one or more nodes in it.
312 *
313 ********************************************************************/
314 static inline int DCE2_CQueueIsEmpty(DCE2_CQueue *cqueue)
315 {
316 if (cqueue == NULL) return 1;
317 if (cqueue->num_nodes == 0) return 1;
318 return 0;
319 }
320
321 /********************************************************************
322 * Function: DCE2_CStackIsEmpty()
323 *
324 * Determines whether or not the stack has any items in it
325 * currently.
326 *
327 * Arguments:
328 * DCE2_CStack *
329 * A pointer to the stack object.
330 *
331 * Returns:
332 * int
333 * 1 if the stack has zero nodes in it or the stack object
334 * passed in is NULL.
335 * 0 if the stack has one or more nodes in it.
336 *
337 ********************************************************************/
338 static inline int DCE2_CStackIsEmpty(DCE2_CStack *cstack)
339 {
340 if (cstack == NULL) return 1;
341 if (cstack->num_nodes == 0) return 1;
342 return 0;
343 }
344
345 #endif /* _DCE2_LIST_H_ */
346