From 9dd440a4f8ff676fcb003db8be3db9a1f6ef0f06 Mon Sep 17 00:00:00 2001 From: Lubos Slovak <lubos.slovak@nic.cz> Date: Thu, 11 Nov 2010 11:53:18 +0100 Subject: [PATCH] Very first API for node. Just basic functions declared: - creating node - destroying node - adding RRSet - getting RRSet - getting parent of a node refs #88 --- src/dnslib/node.h | 89 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 4 deletions(-) diff --git a/src/dnslib/node.h b/src/dnslib/node.h index 1cf33e5ed..32e5d4e3e 100644 --- a/src/dnslib/node.h +++ b/src/dnslib/node.h @@ -1,17 +1,98 @@ +/*! + * \file node.h + * \author Lubos Slovak <lubos.slovak@nic.cz> + * + * \brief Structure representing one done in domain name tree and API for + * manipulating it. + * + * \addtogroup dnslib + * @{ + */ + #ifndef _CUTEDNS_NODE_H #define _CUTEDNS_NODE_H #include "dname.h" #include "skip-list.h" +#include "rrset.h" +/*----------------------------------------------------------------------------*/ +/*! + * \brief Structure representing one node in a domain name tree, i.e. one domain + * name in a zone. + * + * RRSets are ordered by type and stored in a skip-list to allow fast lookup. + * + * \todo How to return all RRSets?? An array? Or return the skip list and let + * the user iterate over it? + */ struct dnslib_node { - dnslib_dname_t *owner; - struct dnslib_node *parent; - skip_list *rrsets; // key - RRTYPE (uint16_t); value - dnslib_rrset_t * + dnslib_dname_t *owner; /*!< Domain name being the owner of this node. */ + struct dnslib_node *parent; /*!< Parent node in the name hierarchy. */ + /*! \brief Type-ordered list of RRSets belonging to this node. */ + skip_list *rrsets; - struct dnslib_node *next; // temporary + /*! \brief Next node in a general list of nodes. Temporary. */ + struct dnslib_node *next; }; typedef struct dnslib_node dnslib_node_t; +/*----------------------------------------------------------------------------*/ +/*! + * \brief Creates and initializes new node structure. + * + * \param owner Owner of the created node. + * \param parent Parent of the created node. + * + * \return Newly created node or NULL if an error occured. + */ +dnslib_node_t *dnslib_node_new( dnslib_dname_t *owner, dnslib_node *parent ); + +/*! + * \brief Adds an RRSet to the node. + * + * \param node Node to add the RRSet to. + * \param rrset RRSet to add. + * + * \retval 0 on success. + * \retval <> 0 on failure. + * + * \todo Specify return values according to implementation. + */ +int dnslib_node_add_rrset( dnslib_node_t *node, dnslib_rrset_t *rrset ); + +/*! + * \brief Returns the RRSet of the given type from the node. + * + * \param node Node to get the RRSet from. + * \param type Type of the RRSet to retrieve. + * + * \return RRSet from node \a node having type \a type, or NULL if no such + * RRSet exists in this node. + */ +const dnslib_rrset_t *dnslib_node_get_rrset( const dnslib_node_t *node, + uint16_t type ); + +/*! + * \brief Returns the parent of the node. + * + * \param node Node to get the parent of. + * + * \return Parent node of the given node or NULL if no parent has been set (e.g. + * node in a zone apex has no parent). + */ +const dnslib_node_t *dnslib_node_get_parent( const dnslib_node_t *node ); + +/*! + * \brief Destroys the node structure. + * + * \param node Node to be destroyed. + * + * Sets the given pointer to NULL. + */ +void dnslib_node_free( dnslib_node_t **node ); + #endif /* _CUTEDNS_NODE_H */ + +/*! @} */ -- GitLab