Merge branch 'vendor/GCC'
[dragonfly.git] / contrib / bind-9.3 / lib / isccc / include / isccc / symtab.h
1 /*
2  * Portions Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Portions Copyright (C) 2001  Internet Software Consortium.
4  * Portions Copyright (C) 2001  Nominum, Inc.
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
12  * OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
13  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18
19 /* $Id: symtab.h,v 1.2.206.1 2004/03/06 08:15:22 marka Exp $ */
20
21 #ifndef ISCCC_SYMTAB_H
22 #define ISCCC_SYMTAB_H 1
23
24 /*****
25  ***** Module Info
26  *****/
27
28 /*
29  * Symbol Table
30  *
31  * Provides a simple memory-based symbol table.
32  *
33  * Keys are C strings.  A type may be specified when looking up,
34  * defining, or undefining.  A type value of 0 means "match any type";
35  * any other value will only match the given type.
36  *
37  * It's possible that a client will attempt to define a <key, type,
38  * value> tuple when a tuple with the given key and type already
39  * exists in the table.  What to do in this case is specified by the
40  * client.  Possible policies are:
41  *
42  *      isccc_symexists_reject  Disallow the define, returning ISC_R_EXISTS
43  *      isccc_symexists_replace Replace the old value with the new.  The
44  *                              undefine action (if provided) will be called
45  *                              with the old <key, type, value> tuple.
46  *      isccc_symexists_add     Add the new tuple, leaving the old tuple in
47  *                              the table.  Subsequent lookups will retrieve
48  *                              the most-recently-defined tuple.
49  *
50  * A lookup of a key using type 0 will return the most-recently
51  * defined symbol with that key.  An undefine of a key using type 0
52  * will undefine the most-recently defined symbol with that key.
53  * Trying to define a key with type 0 is illegal.
54  *
55  * The symbol table library does not make a copy the key field, so the
56  * caller must ensure that any key it passes to isccc_symtab_define()
57  * will not change until it calls isccc_symtab_undefine() or
58  * isccc_symtab_destroy().
59  *
60  * A user-specified action will be called (if provided) when a symbol
61  * is undefined.  It can be used to free memory associated with keys
62  * and/or values.
63  */
64
65 /***
66  *** Imports.
67  ***/
68
69 #include <isc/lang.h>
70 #include <isccc/types.h>
71
72 /***
73  *** Symbol Tables.
74  ***/
75
76 typedef union isccc_symvalue {
77         void *                          as_pointer;
78         int                             as_integer;
79         unsigned int                    as_uinteger;
80 } isccc_symvalue_t;
81
82 typedef void (*isccc_symtabundefaction_t)(char *key, unsigned int type,
83                                         isccc_symvalue_t value, void *userarg);
84
85 typedef isc_boolean_t (*isccc_symtabforeachaction_t)(char *key,
86                                                    unsigned int type,
87                                                    isccc_symvalue_t value,
88                                                    void *userarg);
89
90 typedef enum {
91         isccc_symexists_reject = 0,
92         isccc_symexists_replace = 1,
93         isccc_symexists_add = 2
94 } isccc_symexists_t;
95
96 ISC_LANG_BEGINDECLS
97
98 isc_result_t
99 isccc_symtab_create(unsigned int size,
100                   isccc_symtabundefaction_t undefine_action, void *undefine_arg,
101                   isc_boolean_t case_sensitive, isccc_symtab_t **symtabp);
102
103 void
104 isccc_symtab_destroy(isccc_symtab_t **symtabp);
105
106 isc_result_t
107 isccc_symtab_lookup(isccc_symtab_t *symtab, const char *key, unsigned int type,
108                   isccc_symvalue_t *value);
109
110 isc_result_t
111 isccc_symtab_define(isccc_symtab_t *symtab, char *key, unsigned int type,
112                   isccc_symvalue_t value, isccc_symexists_t exists_policy);
113
114 isc_result_t
115 isccc_symtab_undefine(isccc_symtab_t *symtab, const char *key, unsigned int type);
116
117 void
118 isccc_symtab_foreach(isccc_symtab_t *symtab, isccc_symtabforeachaction_t action,
119                    void *arg);
120
121 ISC_LANG_ENDDECLS
122
123 #endif /* ISCCC_SYMTAB_H */