Skip to content
Snippets Groups Projects
Commit 875500e9 authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Removed dname -> node reverse pointer and updated implementation.

refs #19
parent 0271cfef
No related branches found
No related tags found
1 merge request!51Dname Refactor
...@@ -41,7 +41,6 @@ static knot_dname_t *knot_dname_new() ...@@ -41,7 +41,6 @@ static knot_dname_t *knot_dname_new()
knot_dname_t *dname = malloc(sizeof(knot_dname_t)); knot_dname_t *dname = malloc(sizeof(knot_dname_t));
dname->name = NULL; dname->name = NULL;
dname->node = NULL;
dname->count = 1; dname->count = 1;
dname->size = 0; dname->size = 0;
...@@ -126,8 +125,7 @@ static int knot_label_is_equal(const uint8_t *lb1, const uint8_t *lb2) ...@@ -126,8 +125,7 @@ static int knot_label_is_equal(const uint8_t *lb1, const uint8_t *lb2)
/* API functions */ /* API functions */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
knot_dname_t *knot_dname_new_from_str(const char *name, uint size, knot_dname_t *knot_dname_new_from_str(const char *name, uint size)
struct knot_node *node)
{ {
if (name == NULL || size == 0) { if (name == NULL || size == 0) {
return NULL; return NULL;
...@@ -154,14 +152,12 @@ knot_dname_t *knot_dname_new_from_str(const char *name, uint size, ...@@ -154,14 +152,12 @@ knot_dname_t *knot_dname_new_from_str(const char *name, uint size,
} }
assert(dname->name != NULL); assert(dname->name != NULL);
dname->node = node;
return dname; return dname;
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
knot_dname_t *knot_dname_new_from_wire(const uint8_t *name, uint size, knot_dname_t *knot_dname_new_from_wire(const uint8_t *name, uint size)
struct knot_node *node)
{ {
if (name == NULL) { /* && size != 0) { !OS: Nerozumjaju */ if (name == NULL) { /* && size != 0) { !OS: Nerozumjaju */
dbg_dname("No name given!\n"); dbg_dname("No name given!\n");
...@@ -185,7 +181,6 @@ knot_dname_t *knot_dname_new_from_wire(const uint8_t *name, uint size, ...@@ -185,7 +181,6 @@ knot_dname_t *knot_dname_new_from_wire(const uint8_t *name, uint size,
/*! \todo this won't work for non-linear names */ /*! \todo this won't work for non-linear names */
memcpy(dname->name, name, size); memcpy(dname->name, name, size);
dname->size = size; dname->size = size;
dname->node = node;
return dname; return dname;
} }
...@@ -200,7 +195,7 @@ knot_dname_t *knot_dname_parse_from_wire(const uint8_t *wire, ...@@ -200,7 +195,7 @@ knot_dname_t *knot_dname_parse_from_wire(const uint8_t *wire,
if (parsed < 0) if (parsed < 0)
return NULL; return NULL;
knot_dname_t *dname = knot_dname_new_from_wire(name, parsed, NULL); knot_dname_t *dname = knot_dname_new_from_wire(name, parsed);
if (dname) if (dname)
*pos += parsed; *pos += parsed;
...@@ -211,7 +206,6 @@ knot_dname_t *knot_dname_parse_from_wire(const uint8_t *wire, ...@@ -211,7 +206,6 @@ knot_dname_t *knot_dname_parse_from_wire(const uint8_t *wire,
knot_dname_t *knot_dname_deep_copy(const knot_dname_t *dname) knot_dname_t *knot_dname_deep_copy(const knot_dname_t *dname)
{ {
//return knot_dname_new_from_wire(dname->name, dname->size, dname->node);
/* dname_new_from_wire() does not accept non-FQDN dnames, so we /* dname_new_from_wire() does not accept non-FQDN dnames, so we
* do the copy by hand. It's faster anyway */ * do the copy by hand. It's faster anyway */
...@@ -231,8 +225,6 @@ knot_dname_t *knot_dname_deep_copy(const knot_dname_t *dname) ...@@ -231,8 +225,6 @@ knot_dname_t *knot_dname_deep_copy(const knot_dname_t *dname)
memcpy(copy->name, dname->name, dname->size); memcpy(copy->name, dname->name, dname->size);
copy->size = dname->size; copy->size = dname->size;
copy->node = dname->node;
return copy; return copy;
} }
...@@ -353,81 +345,6 @@ uint knot_dname_size(const knot_dname_t *dname) ...@@ -353,81 +345,6 @@ uint knot_dname_size(const knot_dname_t *dname)
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
const struct knot_node *knot_dname_node(const knot_dname_t *dname)
{
if (dname == NULL) {
return NULL;
}
knot_node_t *node = dname->node;
/*
* If the zone contains new zone contents (during an update), we should
* return new node. Check if the node has the new node set. If it does
* not, it means this is already the new node. If it has, return the
* new node. If the new node is empty, return NULL, as the node will be
* deleted later.
*/
dbg_dname_exec_detail(
dbg_dname_detail("Getting node from dname: node: %p, zone: %p\n", node,
knot_node_zone(node));
if (node != NULL && knot_node_zone(node) != NULL
&& knot_zone_contents(knot_node_zone(node)) != NULL) {
dbg_dname_detail("zone contents gen: %d, new node of the node: "
"%p, is empty: %d\n",
knot_zone_contents_gen_is_new(knot_zone_contents(
knot_node_zone(node))),
knot_node_new_node(node),
knot_node_new_node(node)
? knot_node_is_empty(knot_node_new_node(node))
: -1);
}
);
if (node && knot_node_zone(node)
&& knot_zone_contents(knot_node_zone(node))
&& knot_zone_contents_gen_is_new(knot_zone_contents(
knot_node_zone(node)))
&& knot_node_new_node(node) != NULL) {
node = knot_node_get_new_node(node);
if (knot_node_is_empty(node)) {
node = NULL;
}
}
return node;
}
/*----------------------------------------------------------------------------*/
void knot_dname_set_node(knot_dname_t *dname, knot_node_t *node)
{
dname->node = node;
}
/*----------------------------------------------------------------------------*/
void knot_dname_update_node(knot_dname_t *dname)
{
dbg_dname_exec_detail(
char *name = knot_dname_to_str(dname);
dbg_dname_detail("Updating node pointer in dname %p: %s. Before: %p\n",
dname, name, dname->node);
free(name);
);
knot_node_update_ref(&dname->node);
dbg_dname_detail("After: %p\n", dname->node);
if (knot_node_is_empty(dname->node)) {
dbg_dname_detail("Node is empty, setting to NULL.\n");
dname->node = NULL;
}
}
/*----------------------------------------------------------------------------*/
int knot_dname_is_fqdn(const knot_dname_t *dname) int knot_dname_is_fqdn(const knot_dname_t *dname)
{ {
return (dname->name[dname->size - 1] == '\0'); return (dname->name[dname->size - 1] == '\0');
......
...@@ -31,9 +31,6 @@ ...@@ -31,9 +31,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
struct knot_node;
/*----------------------------------------------------------------------------*/
/*! /*!
* \brief Structure for representing a domain name. * \brief Structure for representing a domain name.
* *
...@@ -43,7 +40,6 @@ struct knot_node; ...@@ -43,7 +40,6 @@ struct knot_node;
*/ */
struct knot_dname { struct knot_dname {
uint8_t *name; /*!< Wire format of the domain name. */ uint8_t *name; /*!< Wire format of the domain name. */
struct knot_node *node; /*!< Zone node the domain name belongs to. */
uint32_t count; /*!< Reference counter. */ uint32_t count; /*!< Reference counter. */
uint8_t size; /*!< Length of the domain name. */ uint8_t size; /*!< Length of the domain name. */
}; };
...@@ -66,14 +62,11 @@ typedef struct knot_dname knot_dname_t; ...@@ -66,14 +62,11 @@ typedef struct knot_dname knot_dname_t;
* *
* \param name Domain name in presentation format (labels separated by dots). * \param name Domain name in presentation format (labels separated by dots).
* \param size Size of the domain name (count of characters with all dots). * \param size Size of the domain name (count of characters with all dots).
* \param node Zone node the domain name belongs to. Set to NULL if not
* applicable.
* *
* \return Newly allocated and initialized dname structure representing the * \return Newly allocated and initialized dname structure representing the
* given domain name. * given domain name.
*/ */
knot_dname_t *knot_dname_new_from_str(const char *name, unsigned int size, knot_dname_t *knot_dname_new_from_str(const char *name, unsigned int size);
struct knot_node *node);
/*! /*!
* \brief Creates a dname structure from domain name given in wire format. * \brief Creates a dname structure from domain name given in wire format.
...@@ -85,8 +78,6 @@ knot_dname_t *knot_dname_new_from_str(const char *name, unsigned int size, ...@@ -85,8 +78,6 @@ knot_dname_t *knot_dname_new_from_str(const char *name, unsigned int size,
* *
* \param name Domain name in wire format. * \param name Domain name in wire format.
* \param size Size of the domain name in octets. * \param size Size of the domain name in octets.
* \param node Zone node the domain name belongs to. Set to NULL if not
* applicable.
* *
* \return Newly allocated and initialized dname structure representing the * \return Newly allocated and initialized dname structure representing the
* given domain name. * given domain name.
...@@ -100,9 +91,7 @@ knot_dname_t *knot_dname_new_from_str(const char *name, unsigned int size, ...@@ -100,9 +91,7 @@ knot_dname_t *knot_dname_new_from_str(const char *name, unsigned int size,
* \warning Actually, right now this function does not accept non-FQDN dnames. * \warning Actually, right now this function does not accept non-FQDN dnames.
* For some reason there is a check for this. * For some reason there is a check for this.
*/ */
knot_dname_t *knot_dname_new_from_wire(const uint8_t *name, knot_dname_t *knot_dname_new_from_wire(const uint8_t *name, unsigned int size);
unsigned int size,
struct knot_node *node);
/*! /*!
* \brief Parse dname from wire. * \brief Parse dname from wire.
...@@ -163,19 +152,6 @@ const uint8_t *knot_dname_name(const knot_dname_t *dname); ...@@ -163,19 +152,6 @@ const uint8_t *knot_dname_name(const knot_dname_t *dname);
*/ */
unsigned int knot_dname_size(const knot_dname_t *dname); unsigned int knot_dname_size(const knot_dname_t *dname);
/*!
* \brief Returns the zone node the domain name belongs to.
*
* \param dname Domain name to get the zone node of.
*
* \return Zone node the domain name belongs to or NULL if none.
*/
const struct knot_node *knot_dname_node(const knot_dname_t *dname);
void knot_dname_update_node(knot_dname_t *dname);
void knot_dname_set_node(knot_dname_t *dname, struct knot_node *node);
/*! /*!
* \brief Checks if the given domain name is a fully-qualified domain name. * \brief Checks if the given domain name is a fully-qualified domain name.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment