Commit 4fd3e348 authored by Mark Andrews's avatar Mark Andrews
Browse files

dns_rdata_tostruct() conversion

parent a560a0bf
......@@ -38,8 +38,14 @@ OBJS = callbacks.o compress.o db.o dbiterator.o dbtable.o \
rdata.o rdatalist.o rdataset.o rdatasetiter.o rdataslab.o \
result.o version.o
OSRC = callbacks.c compress.c db.c dbiterator.c dbtable.c \
master.c name.c rbt.c rbtdb.c rbtdb64.c \
rdata.c rdatalist.c rdataset.c rdatasetiter.c rdataslab.c \
result.c version.c
SUBDIRS = include
TARGETS = include/dns/enumtype.h include/dns/enumclass.h timestamp
TARGETS = include/dns/enumtype.h include/dns/enumclass.h \
include/dns/rdatastruct.h timestamp
@BIND9_MAKE_RULES@
......@@ -64,6 +70,7 @@ install:: timestamp installdirs
clean distclean::
rm -f libdns.a timestamp
rm -f gen code.h include/dns/enumtype.h include/dns/enumclass.h
rm -f include/dns/rdatastruct.h
rdata.o: code.h
......@@ -73,6 +80,9 @@ include/dns/enumtype.h: gen
include/dns/enumclass.h: gen
./gen -s ${srcdir} -c > $@
include/dns/rdatastruct.h: gen
./gen -s ${srcdir} -i > $@
code.h: gen
./gen -s ${srcdir} > code.h
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: gen.c,v 1.17 1999/04/29 06:10:27 explorer Exp $ */
/* $Id: gen.c,v 1.18 1999/05/05 01:55:07 marka Exp $ */
#include <sys/types.h>
......@@ -112,7 +112,7 @@ char * funname(char *, char *);
void doswitch(char *, char *, char *, char *, char *, char *);
void dodecl(char *, char *, char *);
void add(int, char *, int, char *, char *);
void sd(int, char *, char *);
void sd(int, char *, char *, char);
char *
upper(char *s) {
......@@ -284,8 +284,9 @@ add(int class, char *classname, int type, char *typename, char *dirname) {
}
void
sd(int class, char *classname, char *dir) {
sd(int class, char *classname, char *dir, char filetype) {
char buf[sizeof "0123456789_65535.h"];
char fmt[sizeof "%10[-0-9a-z]_%d.h"];
DIR *d;
int type;
char typename[11];
......@@ -294,14 +295,14 @@ sd(int class, char *classname, char *dir) {
if ((d = opendir(dir)) == NULL)
return;
sprintf(fmt,"%s%c", "%10[-0-9a-z]_%d.", filetype);
while ((dp = readdir(d)) != NULL) {
if (sscanf(dp->d_name, "%10[-0-9a-z]_%d.h",
typename, &type) != 2)
if (sscanf(dp->d_name, fmt, typename, &type) != 2)
continue;
if ((type > 65535) || (type < 0))
continue;
sprintf(buf, "%s_%d.h", typename, type);
sprintf(buf, "%s_%d.%c", typename, type, filetype);
if (strcmp(buf, dp->d_name) != 0)
continue;
add(class, classname, type, typename, dir);
......@@ -326,21 +327,35 @@ main(int argc, char **argv) {
int code = 1;
int class_enum = 0;
int type_enum = 0;
int structs = 0;
int c;
char buf1[11];
char filetype = 'c';
FILE *fd;
strcpy(srcdir, "");
while ((c = getopt(argc, argv, "cts:")) != -1)
while ((c = getopt(argc, argv, "ctis:")) != -1)
switch (c) {
case 'c':
code = 0;
type_enum = 0;
class_enum = 1;
filetype = 'c';
structs = 0;
break;
case 't':
code = 0;
class_enum = 0;
type_enum = 1;
filetype = 'c';
structs = 0;
break;
case 'i':
code = 0;
class_enum = 0;
type_enum = 0;
structs = 1;
filetype = 'h';
break;
case 's':
sprintf(srcdir, "%s/", optarg);
......@@ -363,11 +378,11 @@ main(int argc, char **argv) {
sprintf(buf, "%srdata/%s_%d", srcdir, classname, class);
if (strcmp(buf + 6 + strlen(srcdir), dp->d_name) != 0)
continue;
sd(class, classname, buf);
sd(class, classname, buf, filetype);
}
sprintf(buf, "%srdata/generic", srcdir);
sd(0, "", buf);
closedir(d);
sprintf(buf, "%srdata/generic", srcdir);
sd(0, "", buf, filetype);
if (time(&now) != -1) {
if ((tm = localtime(&now)) != NULL && tm->tm_year > 98)
......@@ -426,7 +441,7 @@ main(int argc, char **argv) {
fputs("\n", stdout);
for (tt = types; tt != NULL ; tt = tt->next)
fprintf(stdout, "#include \"%s/%s_%d.h\"\n",
fprintf(stdout, "#include \"%s/%s_%d.c\"\n",
tt->dirname, tt->typename, tt->type);
} else if (type_enum) {
fprintf(stdout, "#ifndef TYPEENUM\n");
......@@ -452,8 +467,16 @@ main(int argc, char **argv) {
cc->class,
cc->next != NULL ? " \\" : "");
fprintf(stdout, "#endif /* CLASSENUM */\n");
} else if (structs) {
for (tt = types; tt != NULL ; tt = tt->next) {
sprintf(buf, "%s/%s_%d.h",
tt->dirname, tt->typename, tt->type);
if ((fd = fopen(buf,"r")) != NULL) {
while (fgets(buf, sizeof buf, fd) != NULL)
fputs(buf, stdout);
fclose(fd);
}
}
}
if (ferror(stdout) != 0)
......
Makefile
enumtype.h
enumclass.h
rdatastruct.h
......@@ -70,6 +70,7 @@ typedef unsigned int dns_result_t;
#define DNS_R_BADDB 43
#define DNS_R_ZONECUT 44
#define DNS_R_FORMERR 45
#define DNS_R_BADZONE 46 /* XXX MPA*/
#define DNS_R_LASTENTRY 45 /* Last entry on list. */
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: rdata.c,v 1.40 1999/05/03 19:56:53 halley Exp $ */
/* $Id: rdata.c,v 1.41 1999/05/05 01:55:08 marka Exp $ */
#include <config.h>
......@@ -38,6 +38,7 @@
#include <dns/cert.h>
#include <dns/secalg.h>
#include <dns/fixedname.h>
#include <dns/rdatastruct.h>
#define RETERR(x) do { \
dns_result_t __r = (x); \
......
......@@ -15,292 +15,11 @@
* SOFTWARE.
*/
/* $Id: tsig_250.h,v 1.7 1999/02/24 06:31:32 marka Exp $ */
/* $Id: tsig_250.h,v 1.8 1999/05/05 01:55:08 marka Exp $ */
/* draft-ietf-dnsind-tsig-07.txt */
#ifndef RDATA_ANY_255_TSIG_250_H
#define RDATA_ANY_255_TSIG_250_H
#include <isc/str.h>
static dns_result_t
fromtext_any_tsig(dns_rdataclass_t class, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
isc_boolean_t downcase, isc_buffer_t *target)
{
isc_token_t token;
dns_name_t name;
isc_uint64_t sigtime;
isc_buffer_t buffer;
char *e;
REQUIRE(type == 250);
REQUIRE(class == 255);
/* Algorithm Name */
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
ISC_BUFFERTYPE_TEXT);
origin = (origin != NULL) ? origin : dns_rootname;
RETERR(dns_name_fromtext(&name, &buffer, origin, downcase, target));
/* Time Signed: 48 bits */
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
sigtime = isc_strtouq(token.value.as_pointer, &e, 10);
if (*e != 0)
return (DNS_R_SYNTAX);
if ((sigtime >> 48) != 0)
return(DNS_R_RANGE);
RETERR(uint16_tobuffer(sigtime >> 32, target));
RETERR(uint32_tobuffer(sigtime & 0xffffffff, target));
/* Fudge */
RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
if (token.value.as_ulong > 0xffff)
return (DNS_R_RANGE);
RETERR(uint16_tobuffer(token.value.as_ulong, target));
/* Signature Size */
RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
if (token.value.as_ulong > 0xffff)
return (DNS_R_RANGE);
RETERR(uint16_tobuffer(token.value.as_ulong, target));
/* Signature */
RETERR(base64_tobuffer(lexer, target, token.value.as_ulong));
/* Original ID */
RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
if (token.value.as_ulong > 0xffff)
return (DNS_R_RANGE);
RETERR(uint16_tobuffer(token.value.as_ulong, target));
/* Error */
RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
if (token.value.as_ulong > 0xffff)
return (DNS_R_RANGE);
RETERR(uint16_tobuffer(token.value.as_ulong, target));
/* Other Len */
RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
if (token.value.as_ulong > 0xffff)
return (DNS_R_RANGE);
RETERR(uint16_tobuffer(token.value.as_ulong, target));
/* Other Data */
return (base64_tobuffer(lexer, target, token.value.as_ulong));
}
static dns_result_t
totext_any_tsig(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
isc_region_t sr;
isc_region_t sigr;
char buf[sizeof "281474976710655 "];
char *bufp;
dns_name_t name;
dns_name_t prefix;
isc_boolean_t sub;
isc_uint64_t sigtime;
unsigned short n;
REQUIRE(rdata->type == 250);
REQUIRE(rdata->class == 255);
dns_rdata_toregion(rdata, &sr);
/* Algorithm Name */
dns_name_init(&name, NULL);
dns_name_init(&prefix, NULL);
dns_name_fromregion(&name, &sr);
sub = name_prefix(&name, origin, &prefix);
RETERR(dns_name_totext(&prefix, sub, target));
RETERR(str_totext(" ", target));
isc_region_consume(&sr, name_length(&name));
/* Time Signed */
sigtime = ((isc_uint64_t)sr.base[0] << 40) |
((isc_uint64_t)sr.base[1] << 32) |
(sr.base[2] << 24) | (sr.base[3] << 16) |
(sr.base[4] << 8) | sr.base[5];
isc_region_consume(&sr, 6);
bufp = &buf[sizeof buf - 1];
*bufp-- = 0;
*bufp-- = ' ';
do {
*bufp-- = decdigits[sigtime % 10];
sigtime /= 10;
} while (sigtime != 0);
bufp++;
RETERR(str_totext(bufp, target));
/* Fudge */
n = uint16_fromregion(&sr);
isc_region_consume(&sr, 2);
sprintf(buf, "%u ", n);
RETERR(str_totext(buf, target));
/* Signature Size */
n = uint16_fromregion(&sr);
isc_region_consume(&sr, 2);
sprintf(buf, "%u ", n);
RETERR(str_totext(buf, target));
/* Signature */
REQUIRE(n <= sr.length);
sigr = sr;
sigr.length = n;
RETERR(base64_totext(&sigr, target));
RETERR(str_totext(" ", target));
isc_region_consume(&sr, n);
/* Original ID */
n = uint16_fromregion(&sr);
isc_region_consume(&sr, 2);
sprintf(buf, "%u ", n);
RETERR(str_totext(buf, target));
/* Error */
n = uint16_fromregion(&sr);
isc_region_consume(&sr, 2);
sprintf(buf, "%u ", n);
RETERR(str_totext(buf, target));
/* Other Size */
n = uint16_fromregion(&sr);
isc_region_consume(&sr, 2);
sprintf(buf, "%u ", n);
RETERR(str_totext(buf, target));
/* Other */
return (base64_totext(&sr, target));
}
static dns_result_t
fromwire_any_tsig(dns_rdataclass_t class, dns_rdatatype_t type,
isc_buffer_t *source, dns_decompress_t *dctx,
isc_boolean_t downcase, isc_buffer_t *target)
{
isc_region_t sr;
dns_name_t name;
unsigned long n;
REQUIRE(type == 250);
REQUIRE(class == 255);
if (dns_decompress_edns(dctx) >= 1 || !dns_decompress_strict(dctx))
dns_decompress_setmethods(dctx, DNS_COMPRESS_ALL);
else
dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
/* Algorithm Name */
dns_name_init(&name, NULL);
RETERR(dns_name_fromwire(&name, source, dctx, downcase, target));
isc_buffer_active(source, &sr);
/* Time Signed + Fudge */
if (sr.length < 8)
return (DNS_R_UNEXPECTEDEND);
RETERR(mem_tobuffer(target, sr.base, 8));
isc_region_consume(&sr, 8);
isc_buffer_forward(source, 8);
/* Signature Length + Signature */
if (sr.length < 2)
return (DNS_R_UNEXPECTEDEND);
n = uint16_fromregion(&sr);
if (sr.length < n + 2)
return (DNS_R_UNEXPECTEDEND);
RETERR(mem_tobuffer(target, sr.base, n + 2));
isc_region_consume(&sr, n + 2);
isc_buffer_forward(source, n + 2);
/* Original ID + Error */
if (sr.length < 4)
return (DNS_R_UNEXPECTEDEND);
RETERR(mem_tobuffer(target, sr.base, 4));
isc_region_consume(&sr, 4);
isc_buffer_forward(source, 4);
/* Other Length + Other */
if (sr.length < 2)
return (DNS_R_UNEXPECTEDEND);
n = uint16_fromregion(&sr);
if (sr.length < n + 2)
return (DNS_R_UNEXPECTEDEND);
isc_buffer_forward(source, n + 2);
return (mem_tobuffer(target, sr.base, n + 2));
}
static dns_result_t
towire_any_tsig(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
isc_region_t sr;
dns_name_t name;
REQUIRE(rdata->type == 250);
REQUIRE(rdata->class == 255);
if (dns_compress_getedns(cctx) >= 1)
dns_compress_setmethods(cctx, DNS_COMPRESS_ALL);
else
dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
dns_rdata_toregion(rdata, &sr);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &sr);
RETERR(dns_name_towire(&name, cctx, target));
isc_region_consume(&sr, name_length(&name));
return (mem_tobuffer(target, sr.base, sr.length));
}
static int
compare_any_tsig(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
isc_region_t r1;
isc_region_t r2;
dns_name_t name1;
dns_name_t name2;
int result;
REQUIRE(rdata1->type == rdata2->type);
REQUIRE(rdata1->class == rdata2->class);
REQUIRE(rdata1->type == 250);
REQUIRE(rdata1->class == 255);
dns_rdata_toregion(rdata1, &r1);
dns_rdata_toregion(rdata2, &r2);
dns_name_init(&name1, NULL);
dns_name_init(&name2, NULL);
dns_name_fromregion(&name1, &r1);
dns_name_fromregion(&name2, &r2);
result = dns_name_rdatacompare(&name1, &name2);
if (result != 0)
return (result);
isc_region_consume(&r1, name_length(&name1));
isc_region_consume(&r2, name_length(&name2));
return (compare_region(&r1, &r2));
}
static dns_result_t
fromstruct_any_tsig(dns_rdataclass_t class, dns_rdatatype_t type,
void *source, isc_buffer_t *target)
{
REQUIRE(type == 250);
REQUIRE(class == 255);
source = source;
target = target;
return (DNS_R_NOTIMPLEMENTED);
}
static dns_result_t
tostruct_any_tsig(dns_rdata_t *rdata, void *target) {
REQUIRE(rdata->type == 250);
REQUIRE(rdata->class == 255);
target = target;
return (DNS_R_NOTIMPLEMENTED);
}
#endif /* RDATA_ANY_255_TSIG_250_H */
......@@ -15,176 +15,10 @@
* SOFTWARE.
*/
/* $Id: afsdb_18.h,v 1.5 1999/02/24 06:31:32 marka Exp $ */
/* $Id: afsdb_18.h,v 1.6 1999/05/05 01:55:08 marka Exp $ */
/* RFC 1183 */
#ifndef RDATA_GENERIC_AFSDB_18_H
#define RDATA_GENERIC_AFSDB_18_H
static dns_result_t
fromtext_afsdb(dns_rdataclass_t class, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
isc_boolean_t downcase, isc_buffer_t *target)
{
isc_token_t token;
isc_buffer_t buffer;
dns_name_t name;
REQUIRE(type == 18);
class = class; /*unused*/
/* subtype */
RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
RETERR(uint16_tobuffer(token.value.as_ulong, target));
/* hostname */
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
dns_name_init(&name, NULL);
buffer_fromregion(&buffer, &token.value.as_region,
ISC_BUFFERTYPE_TEXT);
origin = (origin != NULL) ? origin : dns_rootname;
return (dns_name_fromtext(&name, &buffer, origin, downcase, target));
}
static dns_result_t
totext_afsdb(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
dns_name_t name;
dns_name_t prefix;
isc_region_t region;
char buf[sizeof "64000 "];
isc_boolean_t sub;
unsigned int num;
REQUIRE(rdata->type == 18);
dns_name_init(&name, NULL);
dns_name_init(&prefix, NULL);
dns_rdata_toregion(rdata, &region);
num = uint16_fromregion(&region);
isc_region_consume(&region, 2);
sprintf(buf, "%u ", num);
RETERR(str_totext(buf, target));
dns_name_fromregion(&name, &region);
sub = name_prefix(&name, origin, &prefix);
return(dns_name_totext(&prefix, sub, target));
}
static dns_result_t
fromwire_afsdb(dns_rdataclass_t class, dns_rdatatype_t type,
isc_buffer_t *source, dns_decompress_t *dctx,
isc_boolean_t downcase, isc_buffer_t *target)
{
dns_name_t name;
isc_region_t sr;
isc_region_t tr;
REQUIRE(type == 18);
class = class; /*unused*/
if (dns_decompress_edns(dctx) >= 1 || !dns_decompress_strict(dctx))
dns_decompress_setmethods(dctx, DNS_COMPRESS_ALL);
else
dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
dns_name_init(&name, NULL);
isc_buffer_active(source, &sr);
isc_buffer_available(target, &tr);
if (tr.length < 2)
return (DNS_R_NOSPACE);
if (sr.length < 2)
return (DNS_R_UNEXPECTEDEND);
memcpy(tr.base, sr.base, 2);
isc_buffer_forward(source, 2);
isc_buffer_add(target, 2);
return (dns_name_fromwire(&name, source, dctx, downcase, target));
}
static dns_result_t
towire_afsdb(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
isc_region_t tr;
isc_region_t sr;
dns_name_t name;
REQUIRE(rdata->type == 18);
if (dns_compress_getedns(cctx) >= 1)
dns_compress_setmethods(cctx, DNS_COMPRESS_ALL);
else
dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
isc_buffer_available(target, &tr);
dns_rdata_toregion(rdata, &sr);
if (tr.length < 2)
return (DNS_R_NOSPACE);
memcpy(tr.base, sr.base, 2);
isc_region_consume(&sr, 2);
isc_buffer_add(target, 2);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &sr);
return (dns_name_towire(&name, cctx, target));
}
static int
compare_afsdb(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {