symtab.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2007, 2009, 2011-2013  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1996-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 DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id$ */
00019 
00020 #ifndef ISC_SYMTAB_H
00021 #define ISC_SYMTAB_H 1
00022 
00023 /*****
00024  ***** Module Info
00025  *****/
00026 
00027 /*! \file isc/symtab.h
00028  * \brief Provides a simple memory-based symbol table.
00029  *
00030  * Keys are C strings, and key comparisons are case-insensitive.  A type may
00031  * be specified when looking up, defining, or undefining.  A type value of
00032  * 0 means "match any type"; any other value will only match the given
00033  * type.
00034  *
00035  * It's possible that a client will attempt to define a <key, type, value>
00036  * tuple when a tuple with the given key and type already exists in the table.
00037  * What to do in this case is specified by the client.  Possible policies are:
00038  *
00039  *\li   #isc_symexists_reject   Disallow the define, returning #ISC_R_EXISTS
00040  *\li   #isc_symexists_replace  Replace the old value with the new.  The
00041  *                              undefine action (if provided) will be called
00042  *                              with the old <key, type, value> tuple.
00043  *\li   #isc_symexists_add      Add the new tuple, leaving the old tuple in
00044  *                              the table.  Subsequent lookups will retrieve
00045  *                              the most-recently-defined tuple.
00046  *
00047  * A lookup of a key using type 0 will return the most-recently defined
00048  * symbol with that key.  An undefine of a key using type 0 will undefine the
00049  * most-recently defined symbol with that key.  Trying to define a key with
00050  * type 0 is illegal.
00051  *
00052  * The symbol table library does not make a copy the key field, so the
00053  * caller must ensure that any key it passes to isc_symtab_define() will not
00054  * change until it calls isc_symtab_undefine() or isc_symtab_destroy().
00055  *
00056  * A user-specified action will be called (if provided) when a symbol is
00057  * undefined.  It can be used to free memory associated with keys and/or
00058  * values.
00059  *
00060  * A symbol table is implemented as a hash table of lists; the size of the
00061  * hash table is set by the 'size' parameter to isc_symtbl_create().  When
00062  * the number of entries in the symbol table reaches three quarters of this
00063  * value, the hash table is reallocated with size doubled, in order to
00064  * optimize lookup performance.  This has a negative effect on insertion
00065  * performance, which can be mitigated by sizing the table appropriately
00066  * when creating it.
00067  *
00068  * \li MP:
00069  *      The callers of this module must ensure any required synchronization.
00070  *
00071  * \li Reliability:
00072  *      No anticipated impact.
00073  *
00074  * \li Resources:
00075  *      TBS
00076  *
00077  * \li Security:
00078  *      No anticipated impact.
00079  *
00080  * \li Standards:
00081  *      None.
00082  */
00083 
00084 /***
00085  *** Imports.
00086  ***/
00087 
00088 #include <isc/lang.h>
00089 #include <isc/types.h>
00090 
00091 /*
00092  *** Symbol Tables.
00093  ***/
00094 /*% Symbol table value. */
00095 typedef union isc_symvalue {
00096         void *                          as_pointer;
00097         const void *                    as_cpointer;
00098         int                             as_integer;
00099         unsigned int                    as_uinteger;
00100 } isc_symvalue_t;
00101 
00102 typedef void (*isc_symtabaction_t)(char *key, unsigned int type,
00103                                    isc_symvalue_t value, void *userarg);
00104 /*% Symbol table exists. */
00105 typedef enum {
00106         isc_symexists_reject = 0,       /*%< Disallow the define */
00107         isc_symexists_replace = 1,      /*%< Replace the old value with the new */
00108         isc_symexists_add = 2           /*%< Add the new tuple */
00109 } isc_symexists_t;
00110 
00111 ISC_LANG_BEGINDECLS
00112 
00113 /*% Create a symbol table. */
00114 isc_result_t
00115 isc_symtab_create(isc_mem_t *mctx, unsigned int size,
00116                   isc_symtabaction_t undefine_action, void *undefine_arg,
00117                   isc_boolean_t case_sensitive, isc_symtab_t **symtabp);
00118 
00119 /*% Destroy a symbol table. */
00120 void
00121 isc_symtab_destroy(isc_symtab_t **symtabp);
00122 
00123 /*% Lookup a symbol table. */
00124 isc_result_t
00125 isc_symtab_lookup(isc_symtab_t *symtab, const char *key, unsigned int type,
00126                   isc_symvalue_t *value);
00127 
00128 /*% Define a symbol table. */
00129 isc_result_t
00130 isc_symtab_define(isc_symtab_t *symtab, const char *key, unsigned int type,
00131                   isc_symvalue_t value, isc_symexists_t exists_policy);
00132 
00133 /*% Undefine a symbol table. */
00134 isc_result_t
00135 isc_symtab_undefine(isc_symtab_t *symtab, const char *key, unsigned int type);
00136 
00137 /*% Return the number of items in a symbol table. */
00138 unsigned int
00139 isc_symtab_count(isc_symtab_t *symtab);
00140 ISC_LANG_ENDDECLS
00141 
00142 #endif /* ISC_SYMTAB_H */

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