mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-08 20:12:06 -04:00
2575. [func] New functions dns_name_fromstring() and
dns_name_tostring(), to simplify conversion of a string to a dns_name structure and vice versa. [RT #19451]
This commit is contained in:
parent
ed4475f3f5
commit
3f8be559f0
3 changed files with 96 additions and 2 deletions
5
CHANGES
5
CHANGES
|
|
@ -1,3 +1,8 @@
|
|||
2575. [func] New functions dns_name_fromstring() and
|
||||
dns_name_tostring(), to simplify conversion
|
||||
of a string to a dns_name structure and vice
|
||||
versa. [RT #19451]
|
||||
|
||||
2574. [doc] Document nsupdate -g and -o. [RT #19351]
|
||||
|
||||
2573. [bug] Replacing a non-CNAME record with a CNAME record in a
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: name.h,v 1.128 2009/01/17 23:47:43 tbox Exp $ */
|
||||
/* $Id: name.h,v 1.129 2009/03/11 07:02:34 each Exp $ */
|
||||
|
||||
#ifndef DNS_NAME_H
|
||||
#define DNS_NAME_H 1
|
||||
|
|
@ -1129,6 +1129,42 @@ dns_name_format(dns_name_t *name, char *cp, unsigned int size);
|
|||
*
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
dns_name_tostring(dns_name_t *source, char **target, isc_mem_t *mctx);
|
||||
/*%<
|
||||
* Convert 'name' to string format, allocating sufficient memory to
|
||||
* hold it (free with isc_mem_free()).
|
||||
*
|
||||
* Differs from dns_name_format in that it allocates its own memory.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'name' is a valid name.
|
||||
*\li 'target' is not NULL.
|
||||
*\li '*target' is NULL.
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
*\li ISC_R_SUCCESS
|
||||
*
|
||||
*\li Any error that dns_name_totext() can return.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
dns_name_fromstring(dns_name_t *target, const char *src, isc_mem_t *mctx);
|
||||
/*%<
|
||||
* Convert a string to a name and place it in target, allocating memory
|
||||
* as necessary.
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
*\li #ISC_R_SUCCESS
|
||||
*
|
||||
*\li Any error that dns_name_fromtext() can return.
|
||||
*
|
||||
*\li Any error that dns_name_dup() can return.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
dns_name_settotextfilter(dns_name_totextfilter_t proc);
|
||||
/*%<
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: name.c,v 1.165 2008/04/01 23:47:10 tbox Exp $ */
|
||||
/* $Id: name.c,v 1.166 2009/03/11 07:02:34 each Exp $ */
|
||||
|
||||
/*! \file */
|
||||
|
||||
|
|
@ -34,6 +34,7 @@
|
|||
#include <isc/util.h>
|
||||
|
||||
#include <dns/compress.h>
|
||||
#include <dns/fixedname.h>
|
||||
#include <dns/name.h>
|
||||
#include <dns/result.h>
|
||||
|
||||
|
|
@ -2340,6 +2341,58 @@ dns_name_format(dns_name_t *name, char *cp, unsigned int size) {
|
|||
snprintf(cp, size, "<unknown>");
|
||||
}
|
||||
|
||||
/*
|
||||
* dns_name_tostring() -- similar to dns_name_format() but allocates its own
|
||||
* memory.
|
||||
*/
|
||||
isc_result_t
|
||||
dns_name_tostring(dns_name_t *name, char **target, isc_mem_t *mctx) {
|
||||
isc_result_t result;
|
||||
isc_buffer_t buf;
|
||||
isc_region_t reg;
|
||||
char *p, txt[DNS_NAME_FORMATSIZE];
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(target != NULL && *target == NULL);
|
||||
|
||||
isc_buffer_init(&buf, txt, sizeof(txt));
|
||||
result = dns_name_totext(name, ISC_FALSE, &buf);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
|
||||
isc_buffer_usedregion(&buf, ®);
|
||||
p = isc_mem_allocate(mctx, reg.length + 1);
|
||||
memcpy(p, (char *) reg.base, (int) reg.length);
|
||||
p[reg.length] = '\0';
|
||||
|
||||
*target = p;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* dns_name_fromstring() -- convert directly from a string to a name,
|
||||
* allocating memory as needed
|
||||
*/
|
||||
isc_result_t
|
||||
dns_name_fromstring(dns_name_t *target, const char *src, isc_mem_t *mctx) {
|
||||
isc_result_t result;
|
||||
isc_buffer_t buf;
|
||||
dns_fixedname_t fn;
|
||||
dns_name_t *name;
|
||||
|
||||
isc_buffer_init(&buf, src, strlen(src));
|
||||
isc_buffer_add(&buf, strlen(src));
|
||||
dns_fixedname_init(&fn);
|
||||
name = dns_fixedname_name(&fn);
|
||||
|
||||
result = dns_name_fromtext(name, &buf, dns_rootname, ISC_FALSE, NULL);
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
|
||||
result = dns_name_dup(name, mctx, target);
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_name_copy(dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) {
|
||||
unsigned char *ndata;
|
||||
|
|
|
|||
Loading…
Reference in a new issue