"Fossies" - the Fresh Open Source Software Archive

Member "knot-2.8.3/src/knot/zone/zone-tree.h" (16 Jul 2019, 4417 Bytes) of package /linux/misc/dns/knot-2.8.3.tar.xz:


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. For more information about "zone-tree.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.8.0_vs_2.8.1.

    1 /*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
    2 
    3     This program is free software: you can redistribute it and/or modify
    4     it under the terms of the GNU General Public License as published by
    5     the Free Software Foundation, either version 3 of the License, or
    6     (at your option) any later version.
    7 
    8     This program is distributed in the hope that it will be useful,
    9     but WITHOUT ANY WARRANTY; without even the implied warranty of
   10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11     GNU General Public License for more details.
   12 
   13     You should have received a copy of the GNU General Public License
   14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
   15  */
   16 
   17 #pragma once
   18 
   19 #include "contrib/qp-trie/trie.h"
   20 #include "knot/zone/node.h"
   21 
   22 typedef trie_t zone_tree_t;
   23 
   24 /*!
   25  * \brief Signature of callback for zone apply functions.
   26  */
   27 typedef int (*zone_tree_apply_cb_t)(zone_node_t **node, void *data);
   28 
   29 /*!
   30  * \brief Creates the zone tree.
   31  *
   32  * \return created zone tree structure.
   33  */
   34 zone_tree_t *zone_tree_create(void);
   35 
   36 /*!
   37  * \brief Return number of nodes in the zone tree.
   38  *
   39  * \param tree Zone tree.
   40  *
   41  * \return number of nodes in tree.
   42  */
   43 inline static size_t zone_tree_count(const zone_tree_t *tree)
   44 {
   45     if (tree == NULL) {
   46         return 0;
   47     }
   48 
   49     return trie_weight(tree);
   50 }
   51 
   52 /*!
   53  * \brief Checks if the zone tree is empty.
   54  *
   55  * \param tree Zone tree to check.
   56  *
   57  * \return Nonzero if the zone tree is empty.
   58  */
   59 inline static bool zone_tree_is_empty(const zone_tree_t *tree)
   60 {
   61     return zone_tree_count(tree) == 0;
   62 }
   63 
   64 /*!
   65  * \brief Inserts the given node into the zone tree.
   66  *
   67  * \param tree Zone tree to insert the node into.
   68  * \param node Node to insert.
   69  *
   70  * \retval KNOT_EOK
   71  * \retval KNOT_EINVAL
   72  * \retval KNOT_ENOMEM
   73  */
   74 int zone_tree_insert(zone_tree_t *tree, zone_node_t *node);
   75 
   76 /*!
   77  * \brief Finds node with the given owner in the zone tree.
   78  *
   79  * \param tree Zone tree to search in.
   80  * \param owner Owner of the node to find.
   81  *
   82  * \retval Found node or NULL.
   83  */
   84 zone_node_t *zone_tree_get(zone_tree_t *tree, const knot_dname_t *owner);
   85 
   86 /*!
   87  * \brief Tries to find the given domain name in the zone tree and returns the
   88  *        associated node and previous node in canonical order.
   89  *
   90  * \param tree Zone to search in.
   91  * \param owner Owner of the node to find.
   92  * \param found Found node.
   93  * \param previous Previous node in canonical order (i.e. the one directly
   94  *                 preceding \a owner in canonical order, regardless if the name
   95  *                 is in the zone or not).
   96  *
   97  * \retval > 0 if the domain name was found. In such case \a found holds the
   98  *             zone node with \a owner as its owner.
   99  *             \a previous is set properly.
  100  * \retval 0 if the domain name was not found. \a found may hold any (or none)
  101  *           node. \a previous is set properly.
  102  * \retval KNOT_EINVAL
  103  * \retval KNOT_ENOMEM
  104  */
  105 int zone_tree_get_less_or_equal(zone_tree_t *tree,
  106                                 const knot_dname_t *owner,
  107                                 zone_node_t **found,
  108                                 zone_node_t **previous);
  109 
  110 /*!
  111  * \brief Remove a node from a tree with no checks.
  112  *
  113  * \param tree  The tree to remove from.
  114  * \param owner The node to remove.
  115  */
  116 void zone_tree_remove_node(zone_tree_t *tree, const knot_dname_t *owner);
  117 
  118 /*!
  119  * \brief Delete a node that has no RRSets and no children.
  120  *
  121  * \param tree  The tree to remove from.
  122  * \param node  The node to remove.
  123  * \param also_remove_from   Another tree that every deleted node shall be removed from.
  124  */
  125 void zone_tree_delete_empty(zone_tree_t *tree, zone_node_t *node, zone_tree_t *also_remove_from);
  126 
  127 /*!
  128  * \brief Applies the given function to each node in the zone in order.
  129  *
  130  * \param tree Zone tree to apply the function to.
  131  * \param function Function to be applied to each node of the zone.
  132  * \param data Arbitrary data to be passed to the function.
  133  *
  134  * \retval KNOT_EOK
  135  * \retval KNOT_EINVAL
  136  */
  137 int zone_tree_apply(zone_tree_t *tree, zone_tree_apply_cb_t function, void *data);
  138 
  139 /*!
  140  * \brief Destroys the zone tree, not touching the saved data.
  141  *
  142  * \param tree Zone tree to be destroyed.
  143  */
  144 void zone_tree_free(zone_tree_t **tree);
  145 
  146 /*!
  147  * \brief Destroys the zone tree, together with the saved data.
  148  *
  149  * \param tree Zone tree to be destroyed.
  150  */
  151 void zone_tree_deep_free(zone_tree_t **tree);