"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/isccc/include/isccc/symtab.h" (7 Sep 2020, 4228 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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