2 * Portions Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 * Portions Copyright (C) 2001 Internet Software Consortium.
4 * Portions Copyright (C) 2001 Nominum, Inc.
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.
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.
19 /* $Id: symtab.h,v 1.3.18.2 2005/04/29 00:17:14 marka Exp $ */
21 #ifndef ISCCC_SYMTAB_H
22 #define ISCCC_SYMTAB_H 1
30 * Provides a simple memory-based symbol table.
32 * Keys are C strings. A type may be specified when looking up,
33 * defining, or undefining. A type value of 0 means "match any type";
34 * any other value will only match the given type.
36 * It's possible that a client will attempt to define a <key, type,
37 * value> tuple when a tuple with the given key and type already
38 * exists in the table. What to do in this case is specified by the
39 * client. Possible policies are:
41 *\li isccc_symexists_reject Disallow the define, returning #ISC_R_EXISTS
42 *\li isccc_symexists_replace Replace the old value with the new. The
43 * undefine action (if provided) will be called
44 * with the old <key, type, value> tuple.
45 *\li isccc_symexists_add Add the new tuple, leaving the old tuple in
46 * the table. Subsequent lookups will retrieve
47 * the most-recently-defined tuple.
49 * A lookup of a key using type 0 will return the most-recently
50 * defined symbol with that key. An undefine of a key using type 0
51 * will undefine the most-recently defined symbol with that key.
52 * Trying to define a key with type 0 is illegal.
54 * The symbol table library does not make a copy the key field, so the
55 * caller must ensure that any key it passes to isccc_symtab_define()
56 * will not change until it calls isccc_symtab_undefine() or
57 * isccc_symtab_destroy().
59 * A user-specified action will be called (if provided) when a symbol
60 * is undefined. It can be used to free memory associated with keys
69 #include <isccc/types.h>
75 typedef union isccc_symvalue {
78 unsigned int as_uinteger;
81 typedef void (*isccc_symtabundefaction_t)(char *key, unsigned int type,
82 isccc_symvalue_t value, void *userarg);
84 typedef isc_boolean_t (*isccc_symtabforeachaction_t)(char *key,
86 isccc_symvalue_t value,
90 isccc_symexists_reject = 0,
91 isccc_symexists_replace = 1,
92 isccc_symexists_add = 2
98 isccc_symtab_create(unsigned int size,
99 isccc_symtabundefaction_t undefine_action, void *undefine_arg,
100 isc_boolean_t case_sensitive, isccc_symtab_t **symtabp);
103 isccc_symtab_destroy(isccc_symtab_t **symtabp);
106 isccc_symtab_lookup(isccc_symtab_t *symtab, const char *key, unsigned int type,
107 isccc_symvalue_t *value);
110 isccc_symtab_define(isccc_symtab_t *symtab, char *key, unsigned int type,
111 isccc_symvalue_t value, isccc_symexists_t exists_policy);
114 isccc_symtab_undefine(isccc_symtab_t *symtab, const char *key, unsigned int type);
117 isccc_symtab_foreach(isccc_symtab_t *symtab, isccc_symtabforeachaction_t action,
122 #endif /* ISCCC_SYMTAB_H */