Commit ac43d7b9 authored by Lubos Slovak's avatar Lubos Slovak

Comments to dname API + minor fix.

Fixed creating dname struct from wire format (was not copying).
refs #5, #88
parent 930dd52e
......@@ -105,7 +105,7 @@ dnslib_dname_t *dnslib_dname_new_from_wire( uint8_t *name, uint size,
return NULL;
}
dname->name = name;
memcpy(dname->name, name, size);
dname->size = size;
dname->node = node;
......
......@@ -6,11 +6,21 @@
#include "node.h"
/*----------------------------------------------------------------------------*/
/*!
* \brief Structure for representing a domain name.
*
* Stores the domain name in wire format.
*
* \todo Consider restricting to FQDN only (see dnslib_dname_new_from_str()).
*/
struct dnslib_dname {
uint8_t *name; // wire format of a domain name; always ends with 0!!
uint size; // is this needed? every dname should end with \0 or pointer
dnslib_node_t *node; // NULL if not in zone
uint8_t *name; /*!< Wire format of the domain name. */
/*!
* \brief Size of the domain name in octets.
* \todo Is this needed? Every dname should end with \0 or pointer.
*/
uint size;
dnslib_node_t *node; /*!< Zone node the domain name belongs to. */
};
typedef struct dname dnslib_dname_t;
......@@ -18,32 +28,67 @@ typedef struct dname dnslib_dname_t;
/*----------------------------------------------------------------------------*/
/*!
* \brief Creates empty dname structure (no name, no owner node).
*
* \return Newly allocated and initialized dname structure.
* \todo Possibly useless.
*/
dnslib_dname_t *dnslib_dname_new();
/*!
* \note \a name must be 0-terminated.
* \note \a node may be NULL.
* \brief Creates a dname structure from domain name given in presentation
* format.
*
* \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 node Zone node the domain name belongs to. Set to NULL if not
* applicable.
*
* The resulting domain name is stored in wire format and ALWAYS ENDS WITH 0,
* e.g. is a FQDN even if the given domain name was not.
*
* \return Newly allocated and initialized dname structure representing the
* given domain name.
*
* \todo Check if the FQDN issue is OK.
*/
dnslib_dname_t *dnslib_dname_new_from_str( char *name, uint size,
dnslib_node_t *node );
/*!
* \note Copies the name.
* \brief Creates a dname structure from domain name given in wire format.
*
* \param name Domain name in wire format.
* \param size Size of the domain name in octets.
*
* \return Newly allocated and initialized dname structure representing the
* given domain name.
*
* \note The name is copied into the structure.
* \note If the given name is not a FQDN, the result will be neither. This
* does not correspond to the behaviour of dnslib_dname_new_from_str().
* \todo Address the FQDN issue.
*/
dnslib_dname_t *dnslib_dname_new_from_wire( uint8_t *name, uint size );
/*!
* \note Allocates new memory, remember to free it. Returns 0-terminated string.
* \brief Converts the given domain name to string representation.
*
* \param dname Domain name to be converted.
*
* \return 0-terminated string representing the given domain name in
* presentation format.
* \note Allocates new memory, remember to free it.
*/
char *dnslib_dname_to_str( dnslib_dname_t *dname );
/*!
* \brief Destroys the given domain name.
*
* \param dname Domain name to be destroyed.
*
* \note Frees also the data within the struct.
*/
void dnslib_dname_free( dnslib_dname *dname );
#endif /* _CUTEDNS_DNAME_H */
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