Commit 00a8e188 authored by Lubos Slovak's avatar Lubos Slovak

Chopping leftmost label from dname.

Not tested yet.
parent 03604a52
......@@ -234,13 +234,37 @@ int dnslib_dname_is_fqdn(const dnslib_dname_t *dname)
/*----------------------------------------------------------------------------*/
dnslib_dname_t *dnslib_dname_left_chop(const dnslib_dname_t *dname)
{
dnslib_dname_t *parent = dnslib_dname_new();
if (parent == NULL) {
return NULL;
}
parent->size = dname->size - dname->name[0] - 1;
parent->name = (uint8_t *)malloc(parent->size);
if (parent->name == NULL) {
ERR_ALLOC_FAILED;
dnslib_dname_free(&parent);
return NULL;
}
memcpy(parent->name, &dname->name[dname->name[0] + 1], parent->size);
return parent;
}
/*----------------------------------------------------------------------------*/
void dnslib_dname_free(dnslib_dname_t **dname)
{
if (dname == NULL || *dname == NULL) {
return;
}
free((*dname)->name);
if ((*dname)->name != NULL) {
free((*dname)->name);
}
free(*dname);
*dname = NULL;
}
......
......@@ -138,6 +138,16 @@ const struct dnslib_node *dnslib_dname_node(const dnslib_dname_t *dname);
*/
int dnslib_dname_is_fqdn(const dnslib_dname_t *dname);
/*!
* \brief Creates new domain name by removing leftmost label from \a dname.
*
* \param dname Domain name to removing the first label from.
*
* \return New domain name with the same labels as \a dname, except for the
* leftmost label, which is removed.
*/
dnslib_dname_t *dnslib_dname_left_chop(const dnslib_dname_t *dname);
/*!
* \brief Destroys the given domain name.
*
......
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