mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-11 05:30:00 -04:00
Implemented dns_rdatatype_fromtext(), dns_rdatatype_totext(),
dns_rdataclass_fromtext() and dns_rdataclass_totext().
This commit is contained in:
parent
3d5cad69ec
commit
a98551ef59
3 changed files with 127 additions and 15 deletions
|
|
@ -27,6 +27,8 @@
|
|||
#include <isc/lex.h>
|
||||
#include <dns/rdata.h>
|
||||
#include <dns/compress.h>
|
||||
#include <dns/rdataclass.h>
|
||||
#include <dns/rdatatype.h>
|
||||
|
||||
isc_mem_t *mctx;
|
||||
isc_lex_t *lex;
|
||||
|
|
@ -42,7 +44,7 @@ main(int argc, char *argv[]) {
|
|||
int stats = 0;
|
||||
unsigned int options = 0;
|
||||
unsigned int parens = 0;
|
||||
int type;
|
||||
dns_rdatatype_t type;
|
||||
char outbuf[1024];
|
||||
char inbuf[1024];
|
||||
char wirebuf[1024];
|
||||
|
|
@ -134,14 +136,31 @@ main(int argc, char *argv[]) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (token.type != isc_tokentype_number)
|
||||
if (token.type == isc_tokentype_number) {
|
||||
type = token.value.as_ulong;
|
||||
isc_buffer_init(&tbuf, outbuf, sizeof(outbuf),
|
||||
ISC_BUFFERTYPE_TEXT);
|
||||
result = dns_rdatatype_totext(type, &tbuf);
|
||||
fprintf(stdout, "type = %.*s(%d)\n",
|
||||
(int)tbuf.used, (char*)tbuf.base, type);
|
||||
} else if (token.type == isc_tokentype_string) {
|
||||
result = dns_rdatatype_fromtext(&type,
|
||||
&token.value.as_textregion);
|
||||
if (result != DNS_R_SUCCESS) {
|
||||
fprintf(stdout,
|
||||
"dns_rdatatype_fromtext returned %s(%d)\n",
|
||||
dns_result_totext(result), result);
|
||||
fflush(stdout);
|
||||
continue;
|
||||
}
|
||||
fprintf(stdout, "type = %.*s(%d)\n",
|
||||
(int)token.value.as_textregion.length,
|
||||
token.value.as_textregion.base, type);
|
||||
} else
|
||||
continue;
|
||||
|
||||
dns_rdata_init(&rdata);
|
||||
|
||||
type = token.value.as_ulong;
|
||||
fprintf(stdout, "type = %d\n", type);
|
||||
fflush(stdout);
|
||||
dns_rdata_init(&rdata);
|
||||
isc_buffer_init(&dbuf, inbuf, sizeof(inbuf),
|
||||
ISC_BUFFERTYPE_BINARY);
|
||||
result = dns_rdata_fromtext(&rdata, 1, type, lex,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: gen.c,v 1.7 1999/01/20 05:20:18 marka Exp $ */
|
||||
/* $Id: gen.c,v 1.8 1999/01/20 06:51:29 marka Exp $ */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
|
|
@ -93,7 +93,8 @@ char copyright[] =
|
|||
|
||||
struct cc {
|
||||
struct cc *next;
|
||||
int type;
|
||||
int class;
|
||||
char classname[11];
|
||||
} *classes;
|
||||
|
||||
struct tt {
|
||||
|
|
@ -241,16 +242,17 @@ add(int class, char *classname, int type, char *typename, char *dirname) {
|
|||
return;
|
||||
|
||||
newcc = (struct cc *)malloc(sizeof *newcc);
|
||||
newcc->type = type;
|
||||
newcc->class = class;
|
||||
strcpy(newcc->classname, classname);
|
||||
cc = classes;
|
||||
oldcc = NULL;
|
||||
|
||||
while ((cc != NULL) && (cc->type < type)) {
|
||||
while ((cc != NULL) && (cc->class < class)) {
|
||||
oldcc = cc;
|
||||
cc = cc->next;
|
||||
}
|
||||
|
||||
if ((cc != NULL) && cc->type == type) {
|
||||
if ((cc != NULL) && cc->class == class) {
|
||||
free((char *)newcc);
|
||||
return;
|
||||
}
|
||||
|
|
@ -296,6 +298,7 @@ main(int argc, char **argv) {
|
|||
char classname[11];
|
||||
struct dirent *dp;
|
||||
struct tt *tt;
|
||||
struct cc *cc;
|
||||
struct tm *tm;
|
||||
time_t now;
|
||||
char year[11];
|
||||
|
|
@ -361,13 +364,21 @@ main(int argc, char **argv) {
|
|||
lasttype = 0;
|
||||
for (tt = types; tt != NULL ; tt = tt->next)
|
||||
if (tt->type != lasttype)
|
||||
fprintf(stdout,
|
||||
"\t{ %d, \"%s\" },%s\n",
|
||||
fprintf(stdout, "\t{ %d, \"%s\" },%s\n",
|
||||
lasttype = tt->type, tt->typename,
|
||||
tt->next != NULL ? " \\" : "");
|
||||
|
||||
fputs("\n", stdout);
|
||||
for (tt = types; tt ; tt = tt->next)
|
||||
fprintf(stdout, "\n#define CLASSNAMES%s\n",
|
||||
classes != NULL ? " \\" : "");
|
||||
|
||||
for (cc = classes; cc != NULL; cc = cc->next)
|
||||
fprintf(stdout, "\t{ %d, \"%s\" },%s\n", cc->class,
|
||||
cc->classname, cc->next != NULL ? " \\" : "");
|
||||
|
||||
|
||||
fputs("\n", stdout);
|
||||
for (tt = types; tt != NULL ; tt = tt->next)
|
||||
fprintf(stdout, "#include \"%s/%s_%d.h\"\n",
|
||||
tt->dirname, tt->typename, tt->type);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: rdata.c,v 1.5 1999/01/20 05:20:18 marka Exp $ */
|
||||
/* $Id: rdata.c,v 1.6 1999/01/20 06:51:30 marka Exp $ */
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/lex.h>
|
||||
|
|
@ -23,6 +23,8 @@
|
|||
#include <dns/result.h>
|
||||
#include <dns/rdata.h>
|
||||
#include <dns/region.h>
|
||||
#include <dns/rdataclass.h>
|
||||
#include <dns/rdatatype.h>
|
||||
#include <stdio.h>
|
||||
#include <isc/assertions.h>
|
||||
|
||||
|
|
@ -48,6 +50,10 @@ static unsigned short uint16_fromregion(isc_region_t *region);
|
|||
|
||||
#include "code.h"
|
||||
|
||||
struct tbl {
|
||||
int value;
|
||||
char *name;
|
||||
} types[] = { TYPENAMES {0, NULL} }, classes[] = { CLASSNAMES { 0, NULL} };
|
||||
/***
|
||||
*** Initialization
|
||||
***/
|
||||
|
|
@ -281,6 +287,82 @@ dns_rdata_tostruct(dns_rdata_t *rdata, void *target) {
|
|||
return (result);
|
||||
}
|
||||
|
||||
dns_result_t
|
||||
dns_rdataclass_fromtext(dns_rdataclass_t *classp, isc_textregion_t *source) {
|
||||
int i = 0;
|
||||
unsigned int n;
|
||||
|
||||
while (classes[i].name != NULL) {
|
||||
n = strlen(classes[i].name);
|
||||
if (n == source->length &&
|
||||
strncasecmp(source->base, classes[i].name, n) == 0) {
|
||||
*classp = classes[i].value;
|
||||
return(DNS_R_SUCCESS);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (DNS_R_UNKNOWN);
|
||||
}
|
||||
|
||||
dns_result_t
|
||||
dns_rdataclass_totext(dns_rdataclass_t class, isc_buffer_t *target) {
|
||||
int i = 0;
|
||||
unsigned int n;
|
||||
isc_region_t region;
|
||||
|
||||
while (classes[i].name != NULL) {
|
||||
if (classes[i].value == class) {
|
||||
isc_buffer_available(target, ®ion);
|
||||
if ((n = strlen(classes[i].name)) > region.length)
|
||||
return (DNS_R_NOSPACE);
|
||||
memcpy(region.base, classes[i].name, n);
|
||||
isc_buffer_add(target, n);
|
||||
return(DNS_R_SUCCESS);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (DNS_R_UNKNOWN);
|
||||
}
|
||||
|
||||
dns_result_t
|
||||
dns_rdatatype_fromtext(dns_rdatatype_t *typep, isc_textregion_t *source) {
|
||||
int i = 0;
|
||||
unsigned int n;
|
||||
|
||||
while (types[i].name != NULL) {
|
||||
n = strlen(types[i].name);
|
||||
if (n == source->length &&
|
||||
strncasecmp(source->base, types[i].name, n) == 0) {
|
||||
*typep = types[i].value;
|
||||
return(DNS_R_SUCCESS);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (DNS_R_UNKNOWN);
|
||||
}
|
||||
|
||||
dns_result_t
|
||||
dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target) {
|
||||
int i = 0;
|
||||
unsigned int n;
|
||||
isc_region_t region;
|
||||
|
||||
while (types[i].name != NULL) {
|
||||
if (types[i].value == type) {
|
||||
isc_buffer_available(target, ®ion);
|
||||
if ((n = strlen(types[i].name)) > region.length)
|
||||
return (DNS_R_NOSPACE);
|
||||
memcpy(region.base, types[i].name, n);
|
||||
isc_buffer_add(target, n);
|
||||
return(DNS_R_SUCCESS);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (DNS_R_UNKNOWN);
|
||||
}
|
||||
|
||||
/* Private function */
|
||||
|
||||
static unsigned int
|
||||
name_length(dns_name_t *name) {
|
||||
return (name->length);
|
||||
|
|
|
|||
Loading…
Reference in a new issue