]> git.saurik.com Git - apple/ipsec.git/blob - ipsec-tools/racoon/genlist.h
ipsec-317.220.1.tar.gz
[apple/ipsec.git] / ipsec-tools / racoon / genlist.h
1 /* $Id: genlist.h,v 1.2 2004/07/12 20:43:50 ludvigm Exp $ */
2
3 /*
4 * Copyright (C) 2004 SuSE Linux AG, Nuernberg, Germany.
5 * Contributed by: Michal Ludvig <mludvig@suse.cz>, SUSE Labs
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 #ifndef _GENLIST_H
34 #define _GENLIST_H
35
36 #include <sys/queue.h>
37
38 /* See the bottom of genlist.c for example use. */
39
40 /* This declares 'struct genlist' */
41 TAILQ_HEAD(genlist, genlist_entry);
42
43 /* This is where the data are actually stored. */
44 struct genlist_entry {
45 void *data;
46 TAILQ_ENTRY(genlist_entry) chain;
47 };
48
49 /* This function returns an initialized list head. */
50 struct genlist *genlist_init (void);
51
52 /* Insert an entry at the beginning/end og the list. */
53 struct genlist_entry *genlist_insert (struct genlist *head, void *data);
54 struct genlist_entry *genlist_append (struct genlist *head, void *data);
55
56 /* Create a function with this prototype for use with genlist_foreach().
57 * See genlist_foreach() description below for details. */
58 typedef void *(genlist_func_t) (void *entry, void *arg);
59
60 /* Traverse the list and call 'func' for each entry. As long as func() returns
61 * NULL the list traversal continues, once it returns non-NULL (usually the
62 * 'entry' arg), the list traversal exits and the return value is returned
63 * further from genlist_foreach(). Optional 'arg' may be passed to func(), e.g.
64 * for some lookup purposes, etc. */
65 void *genlist_foreach (struct genlist *head, genlist_func_t func, void *arg);
66
67 /* Get first entry in list if head is not NULL, otherwise get next
68 * entry based on saved position in list from previous call as stored in buf.
69 * If buf is NULL no position is saved */
70 void *genlist_next (struct genlist *head, struct genlist_entry **buf);
71
72 /* Create a function with this prototype for use with genlist_free()
73 * to free any storage associated with genlist_entry.data */
74 typedef void (genlist_freedata_t) (void *entry);
75
76 /* Free all storage associated with list at head using func to free any
77 * alloc()d data in data field of genlist_entry */
78 void genlist_free (struct genlist *head, genlist_freedata_t func);
79
80 #endif /* _GENLIST_H */