Commit 63249972 authored by Michael Graff's avatar Michael Graff
Browse files

add attributes (line singleton, exlcusive, meta, etc) to rdata C files, and

build a table of them using gen.c.  This means the names are stored twice,
but that will change in the near future.  This will speed up number to text
conversions for rdatatypes, and I plan on speeding up text->number as
well, soon.
parent a4e2a43f
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: gen.c,v 1.32 2000/03/17 17:45:01 gson Exp $ */
/* $Id: gen.c,v 1.33 2000/04/07 03:54:03 explorer Exp $ */
#include <config.h>
......@@ -132,6 +132,11 @@ struct tt {
char dirname[256]; /* XXX Should be max path length */
} *types;
struct ttnam {
char typename[11];
char macroname[11];
} typenames[256];
char * upper(char *);
char * funname(char *, char *);
void doswitch(char *, char *, char *, char *, char *, char *);
......@@ -139,18 +144,28 @@ void dodecl(char *, char *, char *);
void add(int, char *, int, char *, char *);
void sd(int, char *, char *, char);
/*
* If you use more than 10 of these in, say, a printf(), you'll have problems.
*/
char *
upper(char *s) {
static char buf[11];
char *b = buf;
static int buf_to_use = 0;
static char buf[10][11];
char *b;
int c;
buf_to_use++;
if (buf_to_use > 9)
buf_to_use = 0;
b = buf[buf_to_use];
while ((c = (*s++) & 0xff)) {
*b++ = islower(c) ? toupper(c) : c;
}
*b = '\0';
return (buf);
return (buf[buf_to_use]);
}
char *
......@@ -260,11 +275,28 @@ void
add(int rdclass, char *classname, int type, char *typename, char *dirname) {
struct tt *newtt = (struct tt *)malloc(sizeof *newtt);
struct tt *tt, *oldtt;
struct ttnam *ttn;
struct cc *newcc;
struct cc *cc, *oldcc;
if (newtt == NULL)
if (newtt == NULL) {
fprintf(stderr, "malloc() failed\n");
exit(1);
}
ttn = &typenames[type];
if (ttn->typename[0] == 0) {
if (strlen(typename) > sizeof(ttn->typename) - 1) {
fprintf(stderr, "Error: type name %s is too long\n",
typename);
exit(1);
}
strcpy(ttn->typename, typename);
} else if (strcmp(typename, ttn->typename) != 0) {
fprintf(stderr, "Error: type %d has two names: %s, %s\n",
type, ttn->typename, typename);
exit(1);
}
newtt->next = NULL;
newtt->rdclass = rdclass;
......@@ -360,6 +392,7 @@ main(int argc, char **argv) {
char classname[11];
struct tt *tt;
struct cc *cc;
struct ttnam *ttn;
struct tm *tm;
time_t now;
char year[11];
......@@ -368,13 +401,21 @@ main(int argc, char **argv) {
int class_enum = 0;
int type_enum = 0;
int structs = 0;
int c;
int c, i;
char buf1[11];
char filetype = 'c';
FILE *fd;
char *prefix = NULL;
char *suffix = NULL;
isc_dir_t dir;
int special;
for (i = 0 ; i <= 255 ; i++) {
memset(typenames[i].typename, 0,
sizeof(typenames[i].typename));
memset(typenames[i].macroname, 0,
sizeof(typenames[i].macroname));
}
strcpy(srcdir, "");
while ((c = isc_commandline_parse(argc, argv, "cits:P:S:")) != -1)
......@@ -445,6 +486,7 @@ main(int argc, char **argv) {
fprintf(stdout, copyright, year);
if (code) {
#if 0
dodecl("isc_result_t", "fromtext", FROMTEXTDECL);
dodecl("isc_result_t", "totext", TOTEXTDECL);
dodecl("isc_result_t", "fromwire", FROMWIREDECL);
......@@ -455,6 +497,13 @@ main(int argc, char **argv) {
dodecl("void", "freestruct", FREESTRUCTDECL);
dodecl("isc_result_t", "additionaldata", ADDITIONALDATADECL);
dodecl("isc_result_t", "digest", DIGESTDECL);
#endif
fputs("\n\n", stdout);
for (tt = types; tt != NULL ; tt = tt->next)
fprintf(stdout, "#include \"%s/%s_%d.c\"\n",
tt->dirname, tt->typename, tt->type);
fputs("\n\n", stdout);
doswitch("FROMTEXTSWITCH", "fromtext", FROMTEXTARGS,
FROMTEXTTYPE, FROMTEXTCLASS, FROMTEXTDEF);
......@@ -490,6 +539,133 @@ main(int argc, char **argv) {
upper(tt->typename),
tt->next != NULL ? " \\" : "");
/*
* Change "invalid" characters to valid ones. In this
* case, only worry about the - in the nsap-ptr and other
* type names.
*/
for (i = 0 ; i <= 255 ; i++) {
ttn = &typenames[i];
if (ttn->typename[0] == 0)
continue;
strcpy(ttn->macroname, ttn->typename);
c = strlen(ttn->macroname);
while (c > 0) {
if (ttn->macroname[c - 1] == '-')
ttn->macroname[c - 1] = '_';
c--;
}
}
#define PRINT_COMMA(x) (x == 255 ? "" : ",")
printf("\ntypedef struct {\n");
printf("\tchar *name;\n");
printf("\tunsigned int flags;\n");
printf("} typeattr_t;\n");
printf("static typeattr_t typeattr[] = {\n");
for (i = 0 ; i <= 255 ; i++) {
ttn = &typenames[i];
special = 0;
switch (i) {
case 0:
printf("\t{ \"RESERVED0\", "
"DNS_RDATATYPEATTR_RESERVED }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 31:
printf("\t{ \"EID\", "
"DNS_RDATATYPEATTR_RESERVED }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 32:
printf("\t{ \"NIMLOC\", "
"DNS_RDATATYPEATTR_RESERVED }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 34:
printf("\t{ \"ATMA\", "
"DNS_RDATATYPEATTR_RESERVED }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 100:
printf("\t{ \"UINFO\", "
"DNS_RDATATYPEATTR_RESERVED }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 101:
printf("\t{ \"UID\", "
"DNS_RDATATYPEATTR_RESERVED }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 102:
printf("\t{ \"GID\", "
"DNS_RDATATYPEATTR_RESERVED }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 251:
printf("\t{ \"IXFR\", "
"DNS_RDATATYPEATTR_META }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 252:
printf("\t{ \"AXFR\", "
"DNS_RDATATYPEATTR_META }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 253:
printf("\t{ \"MAILB\", "
"DNS_RDATATYPEATTR_META }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 254:
printf("\t{ \"MAILA\", "
"DNS_RDATATYPEATTR_META }%s\n",
PRINT_COMMA(i));
special = 1;
break;
case 255:
printf("\t{ \"ANY\", "
"DNS_RDATATYPEATTR_META }%s\n",
PRINT_COMMA(i));
special = 1;
break;
default:
if (ttn->typename[0] == 0) {
printf("\t{ \"RRTYPE%d\", "
"DNS_RDATATYPEATTR_UNKNOWN"
"}%s\n", i, PRINT_COMMA(i));
} else {
printf("\t{ \"%s\", "
"RRTYPE_%s_ATTRIBUTES }%s\n",
upper(ttn->typename),
upper(ttn->macroname),
PRINT_COMMA(i));
}
break;
}
if (special == 1 && ttn->typename[0] != 0) {
fprintf(stderr, "Error! Special processing for %s, but type is defined in a file also\n",
ttn->typename);
exit(1);
}
}
printf("};\n");
fputs("\n", stdout);
fprintf(stdout, "\n#define CLASSNAMES%s\n",
classes != NULL ? " \\" : "");
......@@ -499,11 +675,7 @@ main(int argc, char **argv) {
cc->rdclass, upper(cc->classname),
cc->next != NULL ? " \\" : "");
fputs("\n", stdout);
for (tt = types; tt != NULL ; tt = tt->next)
fprintf(stdout, "#include \"%s/%s_%d.c\"\n",
tt->dirname, tt->typename, tt->type);
} else if (type_enum) {
fprintf(stdout, "#ifndef TYPEENUM\n");
fprintf(stdout, "#define TYPEENUM%s\n",
......
......@@ -528,6 +528,33 @@ dns_rdata_digest(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg);
* Many other results are possible if not successful.
*/
unsigned int
dns_rdatatype_attributes(dns_rdatatype_t rdtype);
/*
* Return attributes for the given type.
*
* Requires:
* 'rdtype' are known.
*
* Returns:
* a bitmask consisting of the following flags.
*/
/* only one may exist for a name */
#define DNS_RDATATYPEATTR_SINGLETON 0x00000001U
/* requires no other data be present */
#define DNS_RDATATYPEATTR_EXCLUSIVE 0x00000002U
/* Is a meta type */
#define DNS_RDATATYPEATTR_META 0x00000004U
/* Is a DNSSEC type, like SIG or NXT */
#define DNS_RDATATYPEATTR_DNSSEC 0x00000008U
/* Is a zone cut authority type XXXMLG */
#define DNS_RDATATYPEATTR_ZONECUTAUTH 0x00000010U
/* Is reserved (unusable) */
#define DNS_RDATATYPEATTR_RESERVED 0x00000020U
/* Is an unknown type */
#define DNS_RDATATYPEATTR_UNKNOWN 0x00000040U
dns_rdatatype_t
dns_rdata_covers(dns_rdata_t *rdata);
/*
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: rdata.c,v 1.73 2000/04/06 22:02:10 explorer Exp $ */
/* $Id: rdata.c,v 1.74 2000/04/07 03:54:04 explorer Exp $ */
#include <config.h>
......@@ -641,6 +641,15 @@ dns_rdata_digest(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
return (result);
}
unsigned int
dns_rdatatype_attributes(dns_rdatatype_t type)
{
if (type > 255)
return (DNS_RDATATYPEATTR_UNKNOWN);
return (typeattr[type].flags);
}
#define NUMBERSIZE sizeof("037777777777") /* 2^32-1 octal + NUL */
static isc_result_t
......@@ -747,11 +756,17 @@ dns_rdatatype_fromtext(dns_rdatatype_t *typep, isc_textregion_t *source) {
return (DNS_R_UNKNOWN);
}
/* XXXRTH This should probably be a switch() */
isc_result_t
dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target) {
return (dns_mnemonic_totext(type, target, types));
dns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target)
{
char buf[sizeof "RRTYPE4294967296"];
if (type > 255) {
sprintf(buf, "RRTYPE%u", type);
return (str_totext(buf, target));
}
return (str_totext(typeattr[type].name, target));
}
/* XXXRTH Should we use a hash table here? */
......@@ -1553,7 +1568,9 @@ ismeta(unsigned int code, struct tbl *table) {
isc_boolean_t
dns_rdatatype_ismeta(dns_rdatatype_t type) {
return (ismeta(type, types));
if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_META) != 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
isc_boolean_t
......@@ -1562,15 +1579,21 @@ dns_rdataclass_ismeta(dns_rdataclass_t rdclass) {
}
isc_boolean_t
dns_rdatatype_isdnssec(dns_rdatatype_t type) {
return ((type == dns_rdatatype_sig ||
type == dns_rdatatype_key ||
type == dns_rdatatype_nxt) ?
ISC_TRUE : ISC_FALSE);
dns_rdatatype_isdnssec(dns_rdatatype_t type)
{
if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_DNSSEC) != 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
isc_boolean_t
dns_rdatatype_iszonecutauth(dns_rdatatype_t type) {
dns_rdatatype_iszonecutauth(dns_rdatatype_t type)
{
if ((dns_rdatatype_attributes(type)
& (DNS_RDATATYPEATTR_DNSSEC | DNS_RDATATYPEATTR_ZONECUTAUTH))
!= 0)
return (ISC_TRUE);
return (ISC_FALSE);
return (type == dns_rdatatype_ns ||
dns_rdatatype_isdnssec(type) ?
ISC_TRUE : ISC_FALSE);
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: tsig_250.c,v 1.26 2000/04/06 22:02:40 explorer Exp $ */
/* $Id: tsig_250.c,v 1.27 2000/04/07 03:54:06 explorer Exp $ */
/* Reviewed: Thu Mar 16 13:39:43 PST 2000 by gson */
......@@ -26,6 +26,8 @@
#include <isc/str.h>
#define RRTYPE_TSIG_ATTRIBUTES (DNS_RDATATYPEATTR_META)
static inline isc_result_t
fromtext_any_tsig(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: afsdb_18.c,v 1.20 2000/04/06 22:02:41 explorer Exp $ */
/* $Id: afsdb_18.c,v 1.21 2000/04/07 03:54:07 explorer Exp $ */
/* Reviewed: Wed Mar 15 14:59:00 PST 2000 by explorer */
......@@ -24,6 +24,8 @@
#ifndef RDATA_GENERIC_AFSDB_18_C
#define RDATA_GENERIC_AFSDB_18_C
#define RRTYPE_AFSDB_ATTRIBUTES (0)
static inline isc_result_t
fromtext_afsdb(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: cert_37.c,v 1.21 2000/04/06 22:02:42 explorer Exp $ */
/* $Id: cert_37.c,v 1.22 2000/04/07 03:54:08 explorer Exp $ */
/* Reviewed: Wed Mar 15 21:14:32 EST 2000 by tale */
......@@ -24,6 +24,8 @@
#ifndef RDATA_GENERIC_CERT_37_C
#define RDATA_GENERIC_CERT_37_C
#define RRTYPE_CERT_ATTRIBUTES (0)
static inline isc_result_t
fromtext_cert(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,13 +15,15 @@
* SOFTWARE.
*/
/* $Id: cname_5.c,v 1.23 2000/04/06 22:02:43 explorer Exp $ */
/* $Id: cname_5.c,v 1.24 2000/04/07 03:54:09 explorer Exp $ */
/* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
#ifndef RDATA_GENERIC_CNAME_5_C
#define RDATA_GENERIC_CNAME_5_C
#define RRTYPE_CNAME_ATTRIBUTES (DNS_RDATATYPEATTR_EXCLUSIVE | DNS_RDATATYPEATTR_SINGLETON)
static inline isc_result_t
fromtext_cname(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: dname_39.c,v 1.16 2000/04/06 22:02:45 explorer Exp $ */
/* $Id: dname_39.c,v 1.17 2000/04/07 03:54:10 explorer Exp $ */
/* Reviewed: Wed Mar 15 16:52:38 PST 2000 by explorer */
......@@ -24,6 +24,8 @@
#ifndef RDATA_GENERIC_DNAME_39_C
#define RDATA_GENERIC_DNAME_39_C
#define RRTYPE_DNAME_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)
static inline isc_result_t
fromtext_dname(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: gpos_27.c,v 1.15 2000/04/06 22:02:46 explorer Exp $ */
/* $Id: gpos_27.c,v 1.16 2000/04/07 03:54:12 explorer Exp $ */
/* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
......@@ -24,6 +24,8 @@
#ifndef RDATA_GENERIC_GPOS_27_C
#define RDATA_GENERIC_GPOS_27_C
#define RRTYPE_GPOS_ATTRIBUTES (0)
static inline isc_result_t
fromtext_gpos(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: hinfo_13.c,v 1.21 2000/04/06 22:02:47 explorer Exp $ */
/* $Id: hinfo_13.c,v 1.22 2000/04/07 03:54:13 explorer Exp $ */
/*
* Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley.
......@@ -24,6 +24,8 @@
#ifndef RDATA_GENERIC_HINFO_13_C
#define RDATA_GENERIC_HINFO_13_C
#define RRTYPE_HINFO_ATTRIBUTES (0)
static inline isc_result_t
fromtext_hinfo(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: isdn_20.c,v 1.15 2000/04/06 22:02:49 explorer Exp $ */
/* $Id: isdn_20.c,v 1.16 2000/04/07 03:54:14 explorer Exp $ */
/* Reviewed: Wed Mar 15 16:53:11 PST 2000 by bwelling */
......@@ -24,6 +24,8 @@
#ifndef RDATA_GENERIC_ISDN_20_C
#define RDATA_GENERIC_ISDN_20_C
#define RRTYPE_ISDN_ATTRIBUTES (0)
static inline isc_result_t
fromtext_isdn(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: key_25.c,v 1.18 2000/04/06 22:02:50 explorer Exp $ */
/* $Id: key_25.c,v 1.19 2000/04/07 03:54:15 explorer Exp $ */
/*
* Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley.
......@@ -26,6 +26,8 @@
#ifndef RDATA_GENERIC_KEY_25_C
#define RDATA_GENERIC_KEY_25_C
#define RRTYPE_KEY_ATTRIBUTES (DNS_RDATATYPEATTR_DNSSEC)
static inline isc_result_t
fromtext_key(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: loc_29.c,v 1.13 2000/04/06 22:02:51 explorer Exp $ */
/* $Id: loc_29.c,v 1.14 2000/04/07 03:54:16 explorer Exp $ */
/* Reviewed: Wed Mar 15 18:13:09 PST 2000 by explorer */
......@@ -24,6 +24,8 @@
#ifndef RDATA_GENERIC_LOC_29_C
#define RDATA_GENERIC_LOC_29_C
#define RRTYPE_LOC_ATTRIBUTES (0)
static inline isc_result_t
fromtext_loc(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,13 +15,15 @@
* SOFTWARE.
*/
/* $Id: mb_7.c,v 1.23 2000/04/06 22:02:53 explorer Exp $ */
/* $Id: mb_7.c,v 1.24 2000/04/07 03:54:17 explorer Exp $ */
/* Reviewed: Wed Mar 15 17:31:26 PST 2000 by bwelling */
#ifndef RDATA_GENERIC_MB_7_C
#define RDATA_GENERIC_MB_7_C
#define RRTYPE_MB_ATTRIBUTES (0)
static inline isc_result_t
fromtext_mb(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,13 +15,15 @@
* SOFTWARE.
*/
/* $Id: md_3.c,v 1.24 2000/04/06 22:02:54 explorer Exp $ */
/* $Id: md_3.c,v 1.25 2000/04/07 03:54:18 explorer Exp $ */
/* Reviewed: Wed Mar 15 17:48:20 PST 2000 by bwelling */
#ifndef RDATA_GENERIC_MD_3_C
#define RDATA_GENERIC_MD_3_C
#define RRTYPE_MD_ATTRIBUTES (0)
static inline isc_result_t
fromtext_md(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......
......@@ -15,13 +15,15 @@
* SOFTWARE.
*/