Commit a104a4b0 authored by Marek Vavrusa's avatar Marek Vavrusa

knot_dname_parse_from_wire() able to write to existing dname.

This enables functionality when name is preallocated.
parent 525c3f68
......@@ -481,8 +481,9 @@ knot_dname_t *knot_dname_new_from_wire(const uint8_t *name, uint size,
/*----------------------------------------------------------------------------*/
knot_dname_t *knot_dname_parse_from_wire(const uint8_t *wire,
size_t *pos, size_t size,
knot_node_t *node)
size_t *pos, size_t size,
knot_node_t *node,
knot_dname_t *dname)
{
uint8_t name[KNOT_MAX_DNAME_LENGTH];
uint8_t labels[KNOT_MAX_DNAME_LABELS];
......@@ -549,7 +550,10 @@ knot_dname_t *knot_dname_parse_from_wire(const uint8_t *wire,
*pos += 1;
}
knot_dname_t *dname = knot_dname_new();
/* Allocate if NULL. */
if (dname == NULL) {
dname = knot_dname_new();
}
if (dname == NULL) {
ERR_ALLOC_FAILED;
......
......@@ -124,9 +124,22 @@ knot_dname_t *knot_dname_new_from_wire(const uint8_t *name,
unsigned int size,
struct knot_node *node);
/*!
* \brief Parse dname from wire.
*
* \param wire Message in wire format.
* \param pos Position of the domain name on wire.
* \param size Domain name length.
* \param node Zone node the domain name belongs to. Set to NULL if not
* applicable.
* \param dname Destination dname (will allocate new when NULL).
*
* \return parsed domain name or NULL.
*/
knot_dname_t *knot_dname_parse_from_wire(const uint8_t *wire,
size_t *pos, size_t size,
struct knot_node *node);
size_t *pos, size_t size,
struct knot_node *node,
knot_dname_t *dname);
/*!
* \brief Initializes domain name by the name given in wire format.
......
......@@ -239,7 +239,7 @@ int knot_rdata_from_wire(knot_rdata_t *rdata, const uint8_t *wire,
case KNOT_RDATA_WF_LITERAL_DNAME:
pos2 = *pos;
dname = knot_dname_parse_from_wire(
wire, &pos2, total_size, NULL);
wire, &pos2, total_size, NULL, NULL);
if (dname == NULL) {
free(items);
return KNOT_ERROR;
......@@ -305,7 +305,7 @@ int knot_rdata_from_wire(knot_rdata_t *rdata, const uint8_t *wire,
case 3:
pos2 = *pos;
dname = knot_dname_parse_from_wire(
wire, &pos2, total_size, NULL);
wire, &pos2, total_size, NULL, NULL);
if (dname == NULL) {
knot_rdata_free_items(items, i,
desc->type, 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