1 /* dlist.h
2  * Definitions for dynamic lists
3  * taken from http://www.vorlesungen.uos.de/informatik/cc02/src/dlist/dlist.h
4  *
5  * Yersinia
6  * By David Barroso <tomac@yersinia.net> and Alfredo Andres <aandreswork@hotmail.com>
7  * Copyright 2005-2017 Alfredo Andres and David Barroso
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23 
24 #ifndef _DLIST_H_
25 #define _DLIST_H_
26 
27 #ifdef HAVE_PTHREAD_H
28 #include <pthread.h>
29 #endif
30 
31 #ifdef SOLARIS
32 typedef uint32_t u_int32_t;
33 typedef uint16_t u_int16_t;
34 typedef uint8_t  u_int8_t;
35 #endif
36 
37 struct dlist {
38     void         *data;
39     struct dlist *next;
40     struct dlist *prev;
41 };
42 
43 typedef struct dlist dlist_t;
44 
45 struct list {
46    dlist_t *list;
47    int (*cmp)(void *, void *);
48    pthread_mutex_t mutex;
49 };
50 
51 typedef struct list list_t;
52 
53 void*
54 dlist_data(dlist_t *list);
55 
56 dlist_t*
57 dlist_next(dlist_t* list, dlist_t* p);
58 
59 dlist_t*
60 dlist_prev(dlist_t* list, dlist_t* p);
61 
62 dlist_t*
63 dlist_append(dlist_t *list, const void *data);
64 
65 dlist_t*
66 dlist_prepend(dlist_t *list, const void *data);
67 
68 dlist_t*
69 dlist_remove(dlist_t *list, const void *data);
70 
71 dlist_t*
72 dlist_delete(dlist_t *list);
73 
74 u_int32_t
75 dlist_length(dlist_t *list);
76 
77 dlist_t*
78 dlist_last(dlist_t *list);
79 
80 void
81 dlist_foreach(dlist_t *list,
82               void (*func) (void *data, void *user), void *user);
83 
84 dlist_t*
85 dlist_find(dlist_t *list, const void *data);
86 
87 dlist_t *dlist_search( dlist_t *list, int (*cmp) (void *data, void *pattern), void *pattern);
88 
89 extern void write_log( u_int16_t mode, char *msg, ... );
90 #endif
91