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