symtab.h

Go to the documentation of this file.
00001 /*
00002  * Portions Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
00003  * Portions Copyright (C) 2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
00010  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
00011  * OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
00012  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00013  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00014  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00015  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00016  *
00017  * Portions Copyright (C) 2001  Nominum, Inc.
00018  *
00019  * Permission to use, copy, modify, and/or distribute this software for any
00020  * purpose with or without fee is hereby granted, provided that the above
00021  * copyright notice and this permission notice appear in all copies.
00022  *
00023  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
00024  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
00025  * OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY
00026  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00027  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00028  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00029  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00030  */
00031 
00032 /* $Id: symtab.h,v 1.10 2007/08/28 07:20:43 tbox Exp $ */
00033 
00034 #ifndef ISCCC_SYMTAB_H
00035 #define ISCCC_SYMTAB_H 1
00036 
00037 /*****
00038  ***** Module Info
00039  *****/
00040 
00041 /*! \file isccc/symtab.h
00042  * \brief
00043  * Provides a simple memory-based symbol table.
00044  *
00045  * Keys are C strings.  A type may be specified when looking up,
00046  * defining, or undefining.  A type value of 0 means "match any type";
00047  * any other value will only match the given type.
00048  *
00049  * It's possible that a client will attempt to define a <key, type,
00050  * value> tuple when a tuple with the given key and type already
00051  * exists in the table.  What to do in this case is specified by the
00052  * client.  Possible policies are:
00053  *
00054  *\li   isccc_symexists_reject  Disallow the define, returning #ISC_R_EXISTS
00055  *\li   isccc_symexists_replace Replace the old value with the new.  The
00056  *                              undefine action (if provided) will be called
00057  *                              with the old <key, type, value> tuple.
00058  *\li   isccc_symexists_add     Add the new tuple, leaving the old tuple in
00059  *                              the table.  Subsequent lookups will retrieve
00060  *                              the most-recently-defined tuple.
00061  *
00062  * A lookup of a key using type 0 will return the most-recently
00063  * defined symbol with that key.  An undefine of a key using type 0
00064  * will undefine the most-recently defined symbol with that key.
00065  * Trying to define a key with type 0 is illegal.
00066  *
00067  * The symbol table library does not make a copy the key field, so the
00068  * caller must ensure that any key it passes to isccc_symtab_define()
00069  * will not change until it calls isccc_symtab_undefine() or
00070  * isccc_symtab_destroy().
00071  *
00072  * A user-specified action will be called (if provided) when a symbol
00073  * is undefined.  It can be used to free memory associated with keys
00074  * and/or values.
00075  */
00076 
00077 /***
00078  *** Imports.
00079  ***/
00080 
00081 #include <isc/lang.h>
00082 #include <isccc/types.h>
00083 
00084 /***
00085  *** Symbol Tables.
00086  ***/
00087 
00088 typedef union isccc_symvalue {
00089         void *                          as_pointer;
00090         int                             as_integer;
00091         unsigned int                    as_uinteger;
00092 } isccc_symvalue_t;
00093 
00094 typedef void (*isccc_symtabundefaction_t)(char *key, unsigned int type,
00095                                         isccc_symvalue_t value, void *userarg);
00096 
00097 typedef isc_boolean_t (*isccc_symtabforeachaction_t)(char *key,
00098                                                    unsigned int type,
00099                                                    isccc_symvalue_t value,
00100                                                    void *userarg);
00101 
00102 typedef enum {
00103         isccc_symexists_reject = 0,
00104         isccc_symexists_replace = 1,
00105         isccc_symexists_add = 2
00106 } isccc_symexists_t;
00107 
00108 ISC_LANG_BEGINDECLS
00109 
00110 isc_result_t
00111 isccc_symtab_create(unsigned int size,
00112                   isccc_symtabundefaction_t undefine_action, void *undefine_arg,
00113                   isc_boolean_t case_sensitive, isccc_symtab_t **symtabp);
00114 
00115 void
00116 isccc_symtab_destroy(isccc_symtab_t **symtabp);
00117 
00118 isc_result_t
00119 isccc_symtab_lookup(isccc_symtab_t *symtab, const char *key, unsigned int type,
00120                   isccc_symvalue_t *value);
00121 
00122 isc_result_t
00123 isccc_symtab_define(isccc_symtab_t *symtab, char *key, unsigned int type,
00124                   isccc_symvalue_t value, isccc_symexists_t exists_policy);
00125 
00126 isc_result_t
00127 isccc_symtab_undefine(isccc_symtab_t *symtab, const char *key, unsigned int type);
00128 
00129 void
00130 isccc_symtab_foreach(isccc_symtab_t *symtab, isccc_symtabforeachaction_t action,
00131                    void *arg);
00132 
00133 ISC_LANG_ENDDECLS
00134 
00135 #endif /* ISCCC_SYMTAB_H */

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha