Skip to content
Snippets Groups Projects
Commit d815ebf7 authored by Lubos Slovak's avatar Lubos Slovak
Browse files

Added function for adding dname if not present.

refs #920 @20m
parent a3bfc8c6
No related branches found
No related tags found
No related merge requests found
......@@ -104,6 +104,36 @@ int dnslib_dname_table_add_dname(dnslib_dname_table_t *table,
return DNSLIB_EOK;
}
int dnslib_dname_table_add_dname2(dnslib_dname_table_t *table,
dnslib_dname_t **dname)
{
dnslib_dname_t *found_dname = NULL;
int ret;
char *name = dnslib_dname_to_str(*dname);
printf("Inserting name %s to dname table.\n", name);
free(name);
if ((!(found_dname =
dnslib_dname_table_find_dname(table ,*dname))) &&
(ret = dnslib_dname_table_add_dname(table, *dname))
!= DNSLIB_EOK) {
printf("Error!\n");
return ret;
} else if (found_dname != NULL && found_dname != *dname) {
/*! \todo Remove the check for equality. */
name = dnslib_dname_to_str(found_dname);
printf("Already there: %s (%p)\n", name, found_dname);
free(name);
dnslib_dname_free(dname);
*dname = found_dname;
}
printf("Done.\n");
return DNSLIB_EOK;
}
void dnslib_dname_table_free(dnslib_dname_table_t **table)
{
if (table == NULL || *table == NULL) {
......
......@@ -80,6 +80,21 @@ dnslib_dname_t *dnslib_dname_table_find_dname(const dnslib_dname_table_t *table,
int dnslib_dname_table_add_dname(dnslib_dname_table_t *table,
dnslib_dname_t *dname);
/*!
* \brief Adds domain name to domain name table and checks for duplicates.
*
* \param table Domain name table to be added to.
* \param dname Domain name to be added.
*
* \note This function encapsulates dname in a structure and saves it to a tree.
* \note If a duplicate is found, \a dname is replaced by the name from table.
*
* \retval DNSLIB_EOK on success.
* \retval DNSLIB_ENOMEM when memory runs out.
*/
int dnslib_dname_table_add_dname2(dnslib_dname_table_t *table,
dnslib_dname_t **dname);
/*!
* \brief Frees dname table without its nodes. Sets pointer to NULL.
*
......
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