Commit b44baa89 authored by Lubos Slovak's avatar Lubos Slovak

Minor changes to rdata and dname API+file comments

Destructor functions now take ** to set the given pointer to NULL.
RDATA structure now contains pointer to next RDATA, so they may
  create a linked list. (Will be used in RRSet).

Added file comments and \addtogroup statements.

Modified tests accordingly.

refs #88
parent d40a5dc4
......@@ -214,8 +214,9 @@ const struct dnslib_node *dnslib_dname_node( const dnslib_dname_t *dname )
/*----------------------------------------------------------------------------*/
void dnslib_dname_free( dnslib_dname_t *dname )
void dnslib_dname_free( dnslib_dname_t **dname )
{
free(dname->name);
free(dname);
free((*dname)->name);
free(*dname);
*dname = NULL;
}
/*!
* \file dname.h
* \author Lubos Slovak <lubos.slovak@nic.cz>
*
* \brief Domain name structure and API for manipulating it.
*
* \addtogroup dnslib
* @{
*/
#ifndef _CUTEDNS_DNAME_H
#define _CUTEDNS_DNAME_H
......@@ -118,8 +128,14 @@ const struct dnslib_node *dnslib_dname_node( const dnslib_dname_t *dname );
*
* \param dname Domain name to be destroyed.
*
* \note Frees also the data within the struct.
* Frees also the data within the struct. This is somewhat different behaviour
* than that of RDATA and RRSet structures which do not deallocate their
* contents.
*
* Sets the given pointer to NULL.
*/
void dnslib_dname_free( dnslib_dname_t *dname );
void dnslib_dname_free( dnslib_dname_t **dname );
#endif /* _CUTEDNS_DNAME_H */
/*! @} */
......@@ -82,8 +82,9 @@ const dnslib_rdata_item_t *dnslib_rdata_get_item( const dnslib_rdata_t *rdata,
/*----------------------------------------------------------------------------*/
void dnslib_rdata_free( dnslib_rdata_t *rdata )
void dnslib_rdata_free( dnslib_rdata_t **rdata )
{
free(rdata->items);
free(rdata);
free((*rdata)->items);
free(*rdata);
*rdata = NULL;
}
/*!
* \file rdata.h
* \author Lubos Slovak <lubos.slovak@nic.cz>
*
* \brief Structures representing RDATA and its items and API for manipulating
* both.
*
* \addtogroup dnslib
* @{
*/
#ifndef _CUTEDNS_RDATA_H
#define _CUTEDNS_RDATA_H
......@@ -42,6 +53,7 @@ typedef union dnslib_rdata_item dnslib_rdata_item_t;
struct dnslib_rdata {
dnslib_rdata_item_t *items; /*!< RDATA items comprising this RDATA. */
uint count; /*! < Count of RDATA items in this RDATA. */
struct dnslib_rdata *next; /*!< Next RDATA item in a linked list. */
};
typedef struct dnslib_rdata dnslib_rdata_t;
......@@ -116,9 +128,14 @@ const dnslib_rdata_item_t *dnslib_rdata_get_item( const dnslib_rdata_t *rdata,
* \param rdata RDATA structure to be destroyed.
*
* Contents of RDATA items are not deallocated, as it is not clear whether the
* particular item is a domain name (which cannot be deallocated here) or raw
* data (which could have been).
* particular item is a domain name (which should not be deallocated here) or
* raw data (which could be). But this is actually higher-level logic, so maybe
* a parameter to decide whether to free the items or not would be better.
*
* Sets the given pointer to NULL.
*/
void dnslib_rdata_free( dnslib_rdata_t *rdata );
void dnslib_rdata_free( dnslib_rdata_t **rdata );
#endif /* _CUTEDNS_RDATA_H */
/*! @} */
......@@ -47,9 +47,14 @@ static int test_dname_create()
|| dnslib_dname_name(dname) != NULL
|| dnslib_dname_size(dname) != 0
|| dnslib_dname_node(dname) != NULL) {
diag("New domain name not initialized properly!");
return 0;
}
dnslib_dname_free(&dname);
if (dname != NULL) {
diag("Pointer to the structure not set to NULL when deallocating!");
return 0;
}
dnslib_dname_free(dname);
return 1;
}
......@@ -111,7 +116,7 @@ static int test_dname_create_from_str()
dname = dnslib_dname_new_from_str(test_domains[i].str,
strlen(test_domains[i].str), NODE_ADDRESS);
errors += check_domain_name(dname, i);
dnslib_dname_free(dname);
dnslib_dname_free(&dname);
}
return (errors == 0);
......@@ -133,7 +138,7 @@ static int test_dname_create_from_wire()
(uint8_t *)test_domains[i].wire, test_domains[i].size,
NODE_ADDRESS);
errors += check_domain_name(dname, i);
dnslib_dname_free(dname);
dnslib_dname_free(&dname);
}
return (errors == 0);
......@@ -160,7 +165,7 @@ static int test_dname_to_str()
++errors;
}
free(name_str);
dnslib_dname_free(dname);
dnslib_dname_free(&dname);
}
return (errors == 0);
......
......@@ -90,17 +90,17 @@ static int test_rdata_create( uint count )
const dnslib_rdata_item_t *item;
if ((item = dnslib_rdata_get_item(rdata, i)) == NULL) {
diag("Missing RDATA item on position %d", i);
dnslib_rdata_free(rdata);
dnslib_rdata_free(&rdata);
return 0;
} else if (item->dname != NULL) {
diag("RDATA item on position %d not properly initialized: %p"
" (should be NULL).", i, item->dname);
dnslib_rdata_free(rdata);
dnslib_rdata_free(&rdata);
return 0;
}
}
dnslib_rdata_free(rdata);
dnslib_rdata_free(&rdata);
return 1;
}
......@@ -216,10 +216,10 @@ static int test_rdata_set_item()
rdata = dnslib_rdata_new(test_rdatas[i].items);
set_rdata(rdata, i);
if (check_rdata(rdata, i) != 0) {
dnslib_rdata_free(rdata);
dnslib_rdata_free(&rdata);
return 0;
}
dnslib_rdata_free(rdata);
dnslib_rdata_free(&rdata);
}
return 1;
......@@ -243,14 +243,14 @@ static int test_rdata_set_items()
for (int i = 0; i < TEST_RDATAS; ++i) {
rdata = dnslib_rdata_new(test_rdatas[i].items);
if (!set_rdata_all(rdata, i)) {
dnslib_rdata_free(rdata);
dnslib_rdata_free(&rdata);
return 0;
}
if (check_rdata(rdata, i) != 0) {
dnslib_rdata_free(rdata);
dnslib_rdata_free(&rdata);
return 0;
}
dnslib_rdata_free(rdata);
dnslib_rdata_free(&rdata);
}
return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment