1999-01-19 02:20:26 +00:00
|
|
|
/*
|
2000-02-03 23:50:32 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000 Internet Software Consortium.
|
1999-01-19 02:20:26 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2000-04-19 18:33:09 +00:00
|
|
|
/* $Id: gen.c,v 1.38 2000/04/19 18:33:09 explorer Exp $ */
|
1999-07-03 20:55:16 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
1999-01-19 05:38:36 +00:00
|
|
|
|
1999-01-19 02:20:26 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
1999-10-25 17:04:55 +00:00
|
|
|
#include <stdlib.h>
|
1999-01-19 02:20:26 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
1999-10-08 22:57:20 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include "gen-win32.h"
|
|
|
|
#else
|
|
|
|
#include "gen-unix.h"
|
|
|
|
#endif
|
1999-01-19 02:20:26 +00:00
|
|
|
|
1999-08-02 22:18:31 +00:00
|
|
|
#define FROMTEXTDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_lex_t *lexer, dns_name_t *origin, isc_boolean_t downcase, isc_buffer_t *target"
|
|
|
|
#define FROMTEXTARGS "rdclass, type, lexer, origin, downcase, target"
|
|
|
|
#define FROMTEXTCLASS "rdclass"
|
1999-01-19 02:20:26 +00:00
|
|
|
#define FROMTEXTTYPE "type"
|
1999-01-20 05:20:24 +00:00
|
|
|
#define FROMTEXTDEF "use_default = ISC_TRUE"
|
1999-01-19 02:20:26 +00:00
|
|
|
|
1999-06-08 10:35:23 +00:00
|
|
|
#define TOTEXTDECL "dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, isc_buffer_t *target"
|
|
|
|
#define TOTEXTARGS "rdata, tctx, target"
|
1999-08-02 22:18:31 +00:00
|
|
|
#define TOTEXTCLASS "rdata->rdclass"
|
1999-01-19 02:20:26 +00:00
|
|
|
#define TOTEXTTYPE "rdata->type"
|
1999-01-20 05:20:24 +00:00
|
|
|
#define TOTEXTDEF "use_default = ISC_TRUE"
|
1999-01-19 02:20:26 +00:00
|
|
|
|
1999-08-02 22:18:31 +00:00
|
|
|
#define FROMWIREDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_buffer_t *source, dns_decompress_t *dctx, isc_boolean_t downcase, isc_buffer_t *target"
|
|
|
|
#define FROMWIREARGS "rdclass, type, source, dctx, downcase, target"
|
|
|
|
#define FROMWIRECLASS "rdclass"
|
1999-01-19 02:20:26 +00:00
|
|
|
#define FROMWIRETYPE "type"
|
1999-01-20 05:20:24 +00:00
|
|
|
#define FROMWIREDEF "use_default = ISC_TRUE"
|
1999-01-19 02:20:26 +00:00
|
|
|
|
|
|
|
#define TOWIREDECL "dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target"
|
|
|
|
#define TOWIREARGS "rdata, cctx, target"
|
1999-08-02 22:18:31 +00:00
|
|
|
#define TOWIRECLASS "rdata->rdclass"
|
1999-01-19 02:20:26 +00:00
|
|
|
#define TOWIRETYPE "rdata->type"
|
1999-01-20 05:20:24 +00:00
|
|
|
#define TOWIREDEF "use_default = ISC_TRUE"
|
1999-01-19 02:20:26 +00:00
|
|
|
|
1999-08-02 22:18:31 +00:00
|
|
|
#define FROMSTRUCTDECL "dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source, isc_buffer_t *target"
|
|
|
|
#define FROMSTRUCTARGS "rdclass, type, source, target"
|
|
|
|
#define FROMSTRUCTCLASS "rdclass"
|
1999-01-19 02:20:26 +00:00
|
|
|
#define FROMSTRUCTTYPE "type"
|
1999-01-20 05:20:24 +00:00
|
|
|
#define FROMSTRUCTDEF "use_default = ISC_TRUE"
|
1999-01-19 02:20:26 +00:00
|
|
|
|
1999-05-07 03:24:15 +00:00
|
|
|
#define TOSTRUCTDECL "dns_rdata_t *rdata, void *target, isc_mem_t *mctx"
|
|
|
|
#define TOSTRUCTARGS "rdata, target, mctx"
|
1999-08-02 22:18:31 +00:00
|
|
|
#define TOSTRUCTCLASS "rdata->rdclass"
|
1999-01-19 02:20:26 +00:00
|
|
|
#define TOSTRUCTTYPE "rdata->type"
|
1999-01-20 05:20:24 +00:00
|
|
|
#define TOSTRUCTDEF "use_default = ISC_TRUE"
|
1999-01-19 02:20:26 +00:00
|
|
|
|
1999-05-07 03:24:15 +00:00
|
|
|
#define FREESTRUCTDECL "void *source"
|
|
|
|
#define FREESTRUCTARGS "source"
|
|
|
|
#define FREESTRUCTCLASS "common->rdclass"
|
|
|
|
#define FREESTRUCTTYPE "common->rdtype"
|
|
|
|
#define FREESTRUCTDEF NULL
|
|
|
|
|
1999-01-19 02:20:26 +00:00
|
|
|
#define COMPAREDECL "dns_rdata_t *rdata1, dns_rdata_t *rdata2"
|
|
|
|
#define COMPAREARGS "rdata1, rdata2"
|
1999-08-02 22:18:31 +00:00
|
|
|
#define COMPARECLASS "rdata1->rdclass"
|
1999-01-19 02:20:26 +00:00
|
|
|
#define COMPARETYPE "rdata1->type"
|
1999-01-20 05:20:24 +00:00
|
|
|
#define COMPAREDEF "use_default = ISC_TRUE"
|
1999-01-19 02:20:26 +00:00
|
|
|
|
1999-08-02 22:18:31 +00:00
|
|
|
#define ADDITIONALDATADECL \
|
|
|
|
"dns_rdata_t *rdata, dns_additionaldatafunc_t add, void *arg"
|
|
|
|
#define ADDITIONALDATAARGS "rdata, add, arg"
|
|
|
|
#define ADDITIONALDATACLASS "rdata->rdclass"
|
|
|
|
#define ADDITIONALDATATYPE "rdata->type"
|
|
|
|
#define ADDITIONALDATADEF "use_default = ISC_TRUE"
|
|
|
|
|
1999-08-31 22:08:19 +00:00
|
|
|
#define DIGESTDECL \
|
|
|
|
"dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg"
|
|
|
|
#define DIGESTARGS "rdata, digest, arg"
|
|
|
|
#define DIGESTCLASS "rdata->rdclass"
|
|
|
|
#define DIGESTTYPE "rdata->type"
|
|
|
|
#define DIGESTDEF "use_default = ISC_TRUE"
|
|
|
|
|
1999-01-19 02:20:26 +00:00
|
|
|
char copyright[] =
|
|
|
|
"/*\n\
|
|
|
|
* Copyright (C) 1998%s Internet Software Consortium.\n\
|
|
|
|
*\n\
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any\n\
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above\n\
|
|
|
|
* copyright notice and this permission notice appear in all copies.\n\
|
|
|
|
*\n\
|
|
|
|
* THE SOFTWARE IS PROVIDED \"AS IS\" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\n\
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\n\
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\n\
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\n\
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\n\
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\n\
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\n\
|
|
|
|
* SOFTWARE.\n\
|
|
|
|
*/\n\
|
|
|
|
\n\
|
|
|
|
/* THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT */\n\
|
|
|
|
\n";
|
|
|
|
|
|
|
|
struct cc {
|
|
|
|
struct cc *next;
|
1999-08-02 22:18:31 +00:00
|
|
|
int rdclass;
|
1999-01-20 06:51:30 +00:00
|
|
|
char classname[11];
|
1999-01-19 02:20:26 +00:00
|
|
|
} *classes;
|
|
|
|
|
|
|
|
struct tt {
|
|
|
|
struct tt *next;
|
1999-08-02 22:18:31 +00:00
|
|
|
int rdclass;
|
1999-01-19 02:20:26 +00:00
|
|
|
int type;
|
|
|
|
char classname[11];
|
|
|
|
char typename[11];
|
1999-02-18 01:24:32 +00:00
|
|
|
char dirname[256]; /* XXX Should be max path length */
|
1999-01-19 02:20:26 +00:00
|
|
|
} *types;
|
|
|
|
|
2000-04-07 03:54:52 +00:00
|
|
|
struct ttnam {
|
|
|
|
char typename[11];
|
|
|
|
char macroname[11];
|
2000-04-19 18:32:26 +00:00
|
|
|
char attr[256];
|
2000-04-07 03:54:52 +00:00
|
|
|
} typenames[256];
|
|
|
|
|
1999-01-19 02:20:26 +00:00
|
|
|
char * upper(char *);
|
1999-02-02 22:34:20 +00:00
|
|
|
char * funname(char *, char *);
|
1999-01-19 02:20:26 +00:00
|
|
|
void doswitch(char *, char *, char *, char *, char *, char *);
|
|
|
|
void dodecl(char *, char *, char *);
|
|
|
|
void add(int, char *, int, char *, char *);
|
1999-05-05 01:55:13 +00:00
|
|
|
void sd(int, char *, char *, char);
|
2000-04-19 18:32:26 +00:00
|
|
|
void insert_into_typenames(int, char *, char *);
|
1999-01-19 02:20:26 +00:00
|
|
|
|
2000-04-07 03:54:52 +00:00
|
|
|
/*
|
|
|
|
* If you use more than 10 of these in, say, a printf(), you'll have problems.
|
|
|
|
*/
|
1999-01-19 02:20:26 +00:00
|
|
|
char *
|
|
|
|
upper(char *s) {
|
2000-04-07 03:54:52 +00:00
|
|
|
static int buf_to_use = 0;
|
2000-04-19 18:32:26 +00:00
|
|
|
static char buf[10][256];
|
2000-04-07 03:54:52 +00:00
|
|
|
char *b;
|
1999-10-25 17:04:55 +00:00
|
|
|
int c;
|
1999-01-19 02:20:26 +00:00
|
|
|
|
2000-04-07 03:54:52 +00:00
|
|
|
buf_to_use++;
|
|
|
|
if (buf_to_use > 9)
|
|
|
|
buf_to_use = 0;
|
|
|
|
|
|
|
|
b = buf[buf_to_use];
|
2000-04-19 18:32:26 +00:00
|
|
|
memset(b, 0, 256);
|
2000-04-07 03:54:52 +00:00
|
|
|
|
2000-04-19 18:33:09 +00:00
|
|
|
while ((c = (*s++) & 0xff))
|
1999-01-19 02:20:26 +00:00
|
|
|
*b++ = islower(c) ? toupper(c) : c;
|
|
|
|
*b = '\0';
|
2000-04-07 03:54:52 +00:00
|
|
|
return (buf[buf_to_use]);
|
1999-01-19 02:20:26 +00:00
|
|
|
}
|
|
|
|
|
1999-02-02 22:34:20 +00:00
|
|
|
char *
|
|
|
|
funname(char *s, char *buf) {
|
|
|
|
char *b = buf;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
while ((c = *s++)) {
|
|
|
|
*b++ = (c == '-') ? '_' : c;
|
|
|
|
}
|
|
|
|
*b = '\0';
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
1999-01-19 02:20:26 +00:00
|
|
|
void
|
|
|
|
doswitch(char *name, char *function, char *args,
|
|
|
|
char *tsw, char *csw, char *res)
|
|
|
|
{
|
|
|
|
struct tt *tt;
|
|
|
|
int first = 1;
|
|
|
|
int lasttype = 0;
|
|
|
|
int subswitch = 0;
|
1999-02-02 22:34:20 +00:00
|
|
|
char buf1[11], buf2[11];
|
1999-05-07 03:24:15 +00:00
|
|
|
char *result = " result =";
|
|
|
|
|
|
|
|
if (res == NULL)
|
|
|
|
result = "";
|
1999-01-19 02:20:26 +00:00
|
|
|
|
|
|
|
for (tt = types; tt != NULL ; tt = tt->next) {
|
|
|
|
if (first) {
|
|
|
|
fprintf(stdout, "\n#define %s \\\n", name);
|
|
|
|
fprintf(stdout, "\tswitch (%s) { \\\n" /*}*/, tsw);
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
if (tt->type != lasttype && subswitch) {
|
1999-05-07 03:24:15 +00:00
|
|
|
if (res == NULL)
|
|
|
|
fprintf(stdout, "\t\tdefault: break; \\\n");
|
|
|
|
else
|
|
|
|
fprintf(stdout,
|
|
|
|
"\t\tdefault: %s; break; \\\n", res);
|
1999-01-19 02:20:26 +00:00
|
|
|
fputs(/*{*/ "\t\t} \\\n", stdout);
|
1999-01-19 04:40:48 +00:00
|
|
|
fputs("\t\tbreak; \\\n", stdout);
|
1999-01-19 02:20:26 +00:00
|
|
|
subswitch = 0;
|
|
|
|
}
|
1999-08-02 22:18:31 +00:00
|
|
|
if (tt->rdclass && tt->type != lasttype) {
|
1999-01-19 02:20:26 +00:00
|
|
|
fprintf(stdout, "\tcase %d: switch (%s) { \\\n" /*}*/,
|
1999-01-19 04:31:30 +00:00
|
|
|
tt->type, csw);
|
1999-01-19 02:20:26 +00:00
|
|
|
subswitch = 1;
|
|
|
|
}
|
1999-08-02 22:18:31 +00:00
|
|
|
if (tt->rdclass == 0)
|
1999-01-19 02:20:26 +00:00
|
|
|
fprintf(stdout,
|
1999-05-07 03:24:15 +00:00
|
|
|
"\tcase %d:%s %s_%s(%s); break;",
|
|
|
|
tt->type, result, function,
|
1999-02-02 22:34:20 +00:00
|
|
|
funname(tt->typename, buf1), args);
|
1999-01-19 02:20:26 +00:00
|
|
|
else
|
|
|
|
fprintf(stdout,
|
1999-05-07 03:24:15 +00:00
|
|
|
"\t\tcase %d:%s %s_%s_%s(%s); break;",
|
1999-08-02 22:18:31 +00:00
|
|
|
tt->rdclass, result, function,
|
1999-02-02 22:34:20 +00:00
|
|
|
funname(tt->classname, buf1),
|
|
|
|
funname(tt->typename, buf2), args);
|
1999-01-19 02:20:26 +00:00
|
|
|
fputs(" \\\n", stdout);
|
|
|
|
lasttype = tt->type;
|
|
|
|
}
|
|
|
|
if (subswitch) {
|
1999-05-07 03:24:15 +00:00
|
|
|
if (res == NULL)
|
|
|
|
fprintf(stdout, "\t\tdefault: break; \\\n");
|
|
|
|
else
|
|
|
|
fprintf(stdout, "\t\tdefault: %s; break; \\\n", res);
|
1999-01-27 13:38:21 +00:00
|
|
|
fputs(/*{*/ "\t\t} \\\n", stdout);
|
1999-01-19 04:40:48 +00:00
|
|
|
fputs("\t\tbreak; \\\n", stdout);
|
1999-01-19 02:20:26 +00:00
|
|
|
}
|
1999-05-07 03:24:15 +00:00
|
|
|
if (first) {
|
|
|
|
if (res == NULL)
|
|
|
|
fprintf(stdout, "\n#define %s\n", name);
|
|
|
|
else
|
|
|
|
fprintf(stdout, "\n#define %s %s;\n", name, res);
|
|
|
|
} else {
|
|
|
|
if (res == NULL)
|
|
|
|
fprintf(stdout, "\tdefault: break; \\\n");
|
|
|
|
else
|
|
|
|
fprintf(stdout, "\tdefault: %s; break; \\\n", res);
|
1999-01-19 02:20:26 +00:00
|
|
|
fputs(/*{*/ "\t}\n", stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dodecl(char *type, char *function, char *args) {
|
|
|
|
struct tt *tt;
|
1999-02-02 22:34:20 +00:00
|
|
|
char buf1[11], buf2[11];
|
1999-01-19 02:20:26 +00:00
|
|
|
|
|
|
|
fputs("\n", stdout);
|
|
|
|
for (tt = types; tt ; tt = tt->next)
|
1999-08-02 22:18:31 +00:00
|
|
|
if (tt->rdclass)
|
1999-01-19 02:20:26 +00:00
|
|
|
fprintf(stdout,
|
1999-08-12 01:32:42 +00:00
|
|
|
"static inline %s %s_%s_%s(%s);\n",
|
1999-02-02 22:34:20 +00:00
|
|
|
type, function,
|
|
|
|
funname(tt->classname, buf1),
|
|
|
|
funname(tt->typename, buf2), args);
|
1999-01-19 02:20:26 +00:00
|
|
|
else
|
|
|
|
fprintf(stdout,
|
1999-08-12 01:32:42 +00:00
|
|
|
"static inline %s %s_%s(%s);\n",
|
1999-02-02 22:34:20 +00:00
|
|
|
type, function,
|
|
|
|
funname(tt->typename, buf1), args);
|
1999-01-19 02:20:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-19 18:32:26 +00:00
|
|
|
insert_into_typenames(int type, char *typename, char *attr)
|
|
|
|
{
|
2000-04-07 03:54:52 +00:00
|
|
|
struct ttnam *ttn;
|
2000-04-19 18:32:26 +00:00
|
|
|
int c;
|
|
|
|
char tmp[256];
|
2000-04-07 03:54:52 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
1999-01-19 02:20:26 +00:00
|
|
|
|
2000-04-19 18:32:26 +00:00
|
|
|
strcpy(ttn->macroname, ttn->typename);
|
|
|
|
c = strlen(ttn->macroname);
|
|
|
|
while (c > 0) {
|
|
|
|
if (ttn->macroname[c - 1] == '-')
|
|
|
|
ttn->macroname[c - 1] = '_';
|
|
|
|
c--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == NULL) {
|
|
|
|
sprintf(tmp, "RRTYPE_%s_ATTRIBUTES", upper(ttn->macroname));
|
|
|
|
attr = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ttn->attr[0] != 0 && strcmp(attr, ttn->attr) != 0) {
|
|
|
|
fprintf(stderr, "Error: type %d has different attributes: "
|
|
|
|
"%s, %s\n", type, ttn->attr, attr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(attr) > sizeof(ttn->attr) - 1) {
|
|
|
|
fprintf(stderr, "Error: attr (%s) [name %s] is too long\n",
|
|
|
|
attr, typename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
strcpy(ttn->attr, attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 cc *newcc;
|
|
|
|
struct cc *cc, *oldcc;
|
|
|
|
|
|
|
|
insert_into_typenames(type, typename, NULL);
|
|
|
|
|
|
|
|
if (newtt == NULL) {
|
|
|
|
fprintf(stderr, "malloc() failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1999-01-19 02:20:26 +00:00
|
|
|
newtt->next = NULL;
|
1999-08-02 22:18:31 +00:00
|
|
|
newtt->rdclass = rdclass;
|
1999-01-19 02:20:26 +00:00
|
|
|
newtt->type = type;
|
|
|
|
strcpy(newtt->classname, classname);
|
|
|
|
strcpy(newtt->typename, typename);
|
|
|
|
strcpy(newtt->dirname, dirname);
|
|
|
|
|
|
|
|
tt = types;
|
|
|
|
oldtt = NULL;
|
|
|
|
|
1999-01-20 05:20:24 +00:00
|
|
|
while ((tt != NULL) && (tt->type < type)) {
|
1999-01-19 02:20:26 +00:00
|
|
|
oldtt = tt;
|
|
|
|
tt = tt->next;
|
|
|
|
}
|
|
|
|
|
1999-08-02 22:18:31 +00:00
|
|
|
while ((tt != NULL) && (tt->type == type) && (tt->rdclass < rdclass)) {
|
1999-01-19 02:20:26 +00:00
|
|
|
if (strcmp(tt->typename, typename) != 0)
|
|
|
|
exit(1);
|
|
|
|
oldtt = tt;
|
|
|
|
tt = tt->next;
|
|
|
|
}
|
|
|
|
|
1999-08-02 22:18:31 +00:00
|
|
|
if ((tt != NULL) && (tt->type == type) && (tt->rdclass == rdclass))
|
1999-01-19 02:20:26 +00:00
|
|
|
exit(1);
|
|
|
|
|
|
|
|
newtt->next = tt;
|
1999-01-20 05:20:24 +00:00
|
|
|
if (oldtt != NULL)
|
1999-01-19 02:20:26 +00:00
|
|
|
oldtt->next = newtt;
|
|
|
|
else
|
|
|
|
types = newtt;
|
|
|
|
|
|
|
|
/* do a class switch for this type */
|
|
|
|
|
1999-08-02 22:18:31 +00:00
|
|
|
if (rdclass == 0)
|
1999-01-19 02:20:26 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
newcc = (struct cc *)malloc(sizeof *newcc);
|
1999-08-02 22:18:31 +00:00
|
|
|
newcc->rdclass = rdclass;
|
1999-01-20 06:51:30 +00:00
|
|
|
strcpy(newcc->classname, classname);
|
1999-01-19 02:20:26 +00:00
|
|
|
cc = classes;
|
|
|
|
oldcc = NULL;
|
|
|
|
|
1999-08-02 22:18:31 +00:00
|
|
|
while ((cc != NULL) && (cc->rdclass < rdclass)) {
|
1999-01-19 02:20:26 +00:00
|
|
|
oldcc = cc;
|
|
|
|
cc = cc->next;
|
|
|
|
}
|
|
|
|
|
1999-08-02 22:18:31 +00:00
|
|
|
if ((cc != NULL) && cc->rdclass == rdclass) {
|
1999-01-19 02:20:26 +00:00
|
|
|
free((char *)newcc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newcc->next = cc;
|
1999-01-20 05:20:24 +00:00
|
|
|
if (oldcc != NULL)
|
1999-01-19 02:20:26 +00:00
|
|
|
oldcc->next = newcc;
|
|
|
|
else
|
|
|
|
classes = newcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-10-08 22:57:20 +00:00
|
|
|
sd(int rdclass, char *classname, char *dirname, char filetype) {
|
1999-01-19 02:20:26 +00:00
|
|
|
char buf[sizeof "0123456789_65535.h"];
|
1999-05-05 01:55:13 +00:00
|
|
|
char fmt[sizeof "%10[-0-9a-z]_%d.h"];
|
1999-01-19 02:20:26 +00:00
|
|
|
int type;
|
|
|
|
char typename[11];
|
1999-10-08 22:57:20 +00:00
|
|
|
isc_dir_t dir;
|
1999-01-19 02:20:26 +00:00
|
|
|
|
1999-10-08 22:57:20 +00:00
|
|
|
if (!start_directory(dirname, &dir))
|
1999-01-19 02:20:26 +00:00
|
|
|
return;
|
|
|
|
|
1999-05-05 01:55:13 +00:00
|
|
|
sprintf(fmt,"%s%c", "%10[-0-9a-z]_%d.", filetype);
|
1999-10-08 22:57:20 +00:00
|
|
|
while (next_file(&dir)) {
|
|
|
|
if (sscanf(dir.filename, fmt, typename, &type) != 2)
|
1999-01-19 02:20:26 +00:00
|
|
|
continue;
|
|
|
|
if ((type > 65535) || (type < 0))
|
|
|
|
continue;
|
|
|
|
|
1999-05-05 01:55:13 +00:00
|
|
|
sprintf(buf, "%s_%d.%c", typename, type, filetype);
|
1999-10-08 22:57:20 +00:00
|
|
|
if (strcmp(buf, dir.filename) != 0)
|
1999-01-19 02:20:26 +00:00
|
|
|
continue;
|
1999-10-08 22:57:20 +00:00
|
|
|
add(rdclass, classname, type, typename, dirname);
|
1999-01-19 02:20:26 +00:00
|
|
|
}
|
1999-10-08 22:57:20 +00:00
|
|
|
|
|
|
|
end_directory(&dir);
|
1999-01-19 02:20:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
1999-02-18 01:24:32 +00:00
|
|
|
char buf[256]; /* XXX Should be max path length */
|
|
|
|
char srcdir[256]; /* XXX Should be max path length */
|
1999-08-02 22:18:31 +00:00
|
|
|
int rdclass;
|
1999-01-19 02:20:26 +00:00
|
|
|
char classname[11];
|
|
|
|
struct tt *tt;
|
1999-01-20 06:51:30 +00:00
|
|
|
struct cc *cc;
|
2000-04-07 03:54:52 +00:00
|
|
|
struct ttnam *ttn;
|
1999-01-19 02:20:26 +00:00
|
|
|
struct tm *tm;
|
|
|
|
time_t now;
|
|
|
|
char year[11];
|
1999-01-19 05:16:32 +00:00
|
|
|
int lasttype;
|
1999-01-28 05:03:25 +00:00
|
|
|
int code = 1;
|
|
|
|
int class_enum = 0;
|
|
|
|
int type_enum = 0;
|
1999-05-05 01:55:13 +00:00
|
|
|
int structs = 0;
|
2000-04-07 03:54:52 +00:00
|
|
|
int c, i;
|
1999-02-02 22:34:20 +00:00
|
|
|
char buf1[11];
|
1999-05-05 01:55:13 +00:00
|
|
|
char filetype = 'c';
|
|
|
|
FILE *fd;
|
1999-05-07 03:24:15 +00:00
|
|
|
char *prefix = NULL;
|
|
|
|
char *suffix = NULL;
|
1999-10-08 22:57:20 +00:00
|
|
|
isc_dir_t dir;
|
2000-04-07 03:54:52 +00:00
|
|
|
|
2000-04-19 18:32:26 +00:00
|
|
|
for (i = 0 ; i <= 255 ; i++)
|
|
|
|
memset(&typenames[i], 0, sizeof(typenames[i]));
|
1999-01-28 05:03:25 +00:00
|
|
|
|
1999-02-18 01:24:32 +00:00
|
|
|
strcpy(srcdir, "");
|
1999-10-08 22:57:20 +00:00
|
|
|
while ((c = isc_commandline_parse(argc, argv, "cits:P:S:")) != -1)
|
1999-01-28 05:03:25 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
code = 0;
|
|
|
|
type_enum = 0;
|
|
|
|
class_enum = 1;
|
1999-05-05 01:55:13 +00:00
|
|
|
filetype = 'c';
|
|
|
|
structs = 0;
|
1999-01-28 05:03:25 +00:00
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
code = 0;
|
|
|
|
class_enum = 0;
|
|
|
|
type_enum = 1;
|
1999-05-05 01:55:13 +00:00
|
|
|
filetype = 'c';
|
|
|
|
structs = 0;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
code = 0;
|
|
|
|
class_enum = 0;
|
|
|
|
type_enum = 0;
|
|
|
|
structs = 1;
|
|
|
|
filetype = 'h';
|
1999-01-28 05:03:25 +00:00
|
|
|
break;
|
1999-02-18 01:24:32 +00:00
|
|
|
case 's':
|
1999-10-08 22:57:20 +00:00
|
|
|
sprintf(srcdir, "%s/", isc_commandline_argument);
|
1999-02-18 01:24:32 +00:00
|
|
|
break;
|
1999-05-07 03:24:15 +00:00
|
|
|
case 'P':
|
1999-10-08 22:57:20 +00:00
|
|
|
prefix = isc_commandline_argument;
|
1999-05-07 03:24:15 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
1999-10-08 22:57:20 +00:00
|
|
|
suffix = isc_commandline_argument;
|
1999-05-07 03:24:15 +00:00
|
|
|
break;
|
1999-01-28 05:03:25 +00:00
|
|
|
case '?':
|
|
|
|
exit(1);
|
|
|
|
}
|
1999-01-19 02:20:26 +00:00
|
|
|
|
1999-02-18 01:24:32 +00:00
|
|
|
sprintf(buf, "%srdata", srcdir);
|
1999-10-08 22:57:20 +00:00
|
|
|
|
|
|
|
if (!start_directory(buf, &dir))
|
1999-01-19 02:20:26 +00:00
|
|
|
exit(1);
|
|
|
|
|
1999-10-08 22:57:20 +00:00
|
|
|
while (next_file(&dir)) {
|
|
|
|
if (sscanf(dir.filename, "%10[0-9a-z]_%d",
|
1999-08-02 22:18:31 +00:00
|
|
|
classname, &rdclass) != 2)
|
1999-01-19 02:20:26 +00:00
|
|
|
continue;
|
1999-08-02 22:18:31 +00:00
|
|
|
if ((rdclass > 65535) || (rdclass < 0))
|
1999-01-19 02:20:26 +00:00
|
|
|
continue;
|
|
|
|
|
1999-08-02 22:18:31 +00:00
|
|
|
sprintf(buf, "%srdata/%s_%d", srcdir, classname, rdclass);
|
1999-10-08 22:57:20 +00:00
|
|
|
if (strcmp(buf + 6 + strlen(srcdir), dir.filename) != 0)
|
1999-01-19 02:20:26 +00:00
|
|
|
continue;
|
1999-08-02 22:18:31 +00:00
|
|
|
sd(rdclass, classname, buf, filetype);
|
1999-01-19 02:20:26 +00:00
|
|
|
}
|
1999-10-08 22:57:20 +00:00
|
|
|
end_directory(&dir);
|
1999-05-05 01:55:13 +00:00
|
|
|
sprintf(buf, "%srdata/generic", srcdir);
|
|
|
|
sd(0, "", buf, filetype);
|
1999-01-19 02:20:26 +00:00
|
|
|
|
|
|
|
if (time(&now) != -1) {
|
|
|
|
if ((tm = localtime(&now)) != NULL && tm->tm_year > 98)
|
|
|
|
sprintf(year, "-%d", tm->tm_year + 1900);
|
|
|
|
else
|
|
|
|
year[0] = 0;
|
|
|
|
} else
|
|
|
|
year[0] = 0;
|
|
|
|
|
|
|
|
fprintf(stdout, copyright, year);
|
|
|
|
|
1999-01-28 05:03:25 +00:00
|
|
|
if (code) {
|
2000-04-07 03:54:52 +00:00
|
|
|
#if 0
|
1999-12-23 00:09:04 +00:00
|
|
|
dodecl("isc_result_t", "fromtext", FROMTEXTDECL);
|
|
|
|
dodecl("isc_result_t", "totext", TOTEXTDECL);
|
|
|
|
dodecl("isc_result_t", "fromwire", FROMWIREDECL);
|
|
|
|
dodecl("isc_result_t", "towire", TOWIREDECL);
|
1999-01-28 05:03:25 +00:00
|
|
|
dodecl("int", "compare", COMPAREDECL);
|
1999-12-23 00:09:04 +00:00
|
|
|
dodecl("isc_result_t", "fromstruct", FROMSTRUCTDECL);
|
|
|
|
dodecl("isc_result_t", "tostruct", TOSTRUCTDECL);
|
1999-05-07 03:24:15 +00:00
|
|
|
dodecl("void", "freestruct", FREESTRUCTDECL);
|
1999-12-23 00:09:04 +00:00
|
|
|
dodecl("isc_result_t", "additionaldata", ADDITIONALDATADECL);
|
|
|
|
dodecl("isc_result_t", "digest", DIGESTDECL);
|
2000-04-07 03:54:52 +00:00
|
|
|
#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);
|
1999-01-28 05:03:25 +00:00
|
|
|
|
|
|
|
doswitch("FROMTEXTSWITCH", "fromtext", FROMTEXTARGS,
|
|
|
|
FROMTEXTTYPE, FROMTEXTCLASS, FROMTEXTDEF);
|
|
|
|
doswitch("TOTEXTSWITCH", "totext", TOTEXTARGS,
|
|
|
|
TOTEXTTYPE, TOTEXTCLASS, TOTEXTDEF);
|
|
|
|
doswitch("FROMWIRESWITCH", "fromwire", FROMWIREARGS,
|
|
|
|
FROMWIRETYPE, FROMWIRECLASS, FROMWIREDEF);
|
|
|
|
doswitch("TOWIRESWITCH", "towire", TOWIREARGS,
|
|
|
|
TOWIRETYPE, TOWIRECLASS, TOWIREDEF);
|
|
|
|
doswitch("COMPARESWITCH", "compare", COMPAREARGS,
|
|
|
|
COMPARETYPE, COMPARECLASS, COMPAREDEF);
|
|
|
|
doswitch("FROMSTRUCTSWITCH", "fromstruct", FROMSTRUCTARGS,
|
|
|
|
FROMSTRUCTTYPE, FROMSTRUCTCLASS, FROMSTRUCTDEF);
|
|
|
|
doswitch("TOSTRUCTSWITCH", "tostruct", TOSTRUCTARGS,
|
|
|
|
TOSTRUCTTYPE, TOSTRUCTCLASS, TOSTRUCTDEF);
|
1999-05-07 03:24:15 +00:00
|
|
|
doswitch("FREESTRUCTSWITCH", "freestruct", FREESTRUCTARGS,
|
|
|
|
FREESTRUCTTYPE, FREESTRUCTCLASS, FREESTRUCTDEF);
|
1999-08-02 22:18:31 +00:00
|
|
|
doswitch("ADDITIONALDATASWITCH", "additionaldata",
|
|
|
|
ADDITIONALDATAARGS, ADDITIONALDATATYPE,
|
|
|
|
ADDITIONALDATACLASS, ADDITIONALDATADEF);
|
1999-08-31 22:08:19 +00:00
|
|
|
doswitch("DIGESTSWITCH", "digest",
|
|
|
|
DIGESTARGS, DIGESTTYPE,
|
|
|
|
DIGESTCLASS, DIGESTDEF);
|
1999-01-28 05:03:25 +00:00
|
|
|
|
|
|
|
fprintf(stdout, "\n#define TYPENAMES%s\n",
|
|
|
|
types != NULL ? " \\" : "");
|
|
|
|
|
|
|
|
lasttype = 0;
|
|
|
|
for (tt = types; tt != NULL ; tt = tt->next)
|
|
|
|
if (tt->type != lasttype)
|
1999-04-29 06:10:27 +00:00
|
|
|
fprintf(stdout, "\t{ %d, \"%s\", 0 },%s\n",
|
1999-01-28 05:03:25 +00:00
|
|
|
lasttype = tt->type,
|
|
|
|
upper(tt->typename),
|
|
|
|
tt->next != NULL ? " \\" : "");
|
|
|
|
|
2000-04-07 03:54:52 +00:00
|
|
|
#define PRINT_COMMA(x) (x == 255 ? "" : ",")
|
|
|
|
|
2000-04-14 20:13:49 +00:00
|
|
|
#define METANOTQUESTION "DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_NOTQUESTION"
|
|
|
|
#define METAQUESTIONONLY "DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_QUESTIONONLY"
|
2000-04-19 18:32:26 +00:00
|
|
|
#define RESERVED "DNS_RDATATYPEATTR_RESERVED"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add in reserved/special types. This will let us
|
|
|
|
* sort them without special cases.
|
|
|
|
*/
|
|
|
|
insert_into_typenames(0, "reserved0", RESERVED);
|
|
|
|
insert_into_typenames(31, "eid", RESERVED);
|
|
|
|
insert_into_typenames(32, "nimloc", RESERVED);
|
|
|
|
insert_into_typenames(34, "atma", RESERVED);
|
|
|
|
insert_into_typenames(100, "uinfo", RESERVED);
|
|
|
|
insert_into_typenames(101, "uid", RESERVED);
|
|
|
|
insert_into_typenames(102, "gid", RESERVED);
|
|
|
|
insert_into_typenames(251, "ixfr", METAQUESTIONONLY);
|
|
|
|
insert_into_typenames(252, "axfr", METAQUESTIONONLY);
|
|
|
|
insert_into_typenames(253, "mailb", METAQUESTIONONLY);
|
|
|
|
insert_into_typenames(254, "maila", METAQUESTIONONLY);
|
|
|
|
insert_into_typenames(255, "any", METAQUESTIONONLY);
|
2000-04-14 20:13:49 +00:00
|
|
|
|
2000-04-07 03:54:52 +00:00
|
|
|
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];
|
2000-04-19 18:32:26 +00:00
|
|
|
if (ttn->typename[0] == 0) {
|
|
|
|
printf("\t{ \"RRTYPE%d\", "
|
|
|
|
"DNS_RDATATYPEATTR_UNKNOWN"
|
|
|
|
"}%s\n", i, PRINT_COMMA(i));
|
|
|
|
} else {
|
|
|
|
printf("\t{ \"%s\", %s }%s\n",
|
2000-04-07 03:54:52 +00:00
|
|
|
upper(ttn->typename),
|
2000-04-19 18:32:26 +00:00
|
|
|
upper(ttn->attr),
|
2000-04-07 03:54:52 +00:00
|
|
|
PRINT_COMMA(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("};\n");
|
|
|
|
|
|
|
|
|
1999-01-28 05:03:25 +00:00
|
|
|
fputs("\n", stdout);
|
|
|
|
fprintf(stdout, "\n#define CLASSNAMES%s\n",
|
|
|
|
classes != NULL ? " \\" : "");
|
|
|
|
|
|
|
|
for (cc = classes; cc != NULL; cc = cc->next)
|
1999-08-02 22:18:31 +00:00
|
|
|
fprintf(stdout, "\t{ %d, \"%s\", 0 },%s\n",
|
|
|
|
cc->rdclass, upper(cc->classname),
|
1999-01-28 05:03:25 +00:00
|
|
|
cc->next != NULL ? " \\" : "");
|
|
|
|
|
|
|
|
fputs("\n", stdout);
|
|
|
|
} else if (type_enum) {
|
|
|
|
fprintf(stdout, "#ifndef TYPEENUM\n");
|
|
|
|
fprintf(stdout, "#define TYPEENUM%s\n",
|
|
|
|
types != NULL ? " \\" : "");
|
|
|
|
|
|
|
|
lasttype = 0;
|
|
|
|
for (tt = types; tt != NULL ; tt = tt->next)
|
|
|
|
if (tt->type != lasttype)
|
1999-02-04 06:38:43 +00:00
|
|
|
fprintf(stdout, "\t dns_rdatatype_%s = %d,%s\n",
|
1999-02-02 22:34:20 +00:00
|
|
|
funname(tt->typename, buf1),
|
1999-01-28 05:03:25 +00:00
|
|
|
lasttype = tt->type,
|
|
|
|
tt->next != NULL ? " \\" : "");
|
|
|
|
fprintf(stdout, "#endif /* TYPEENUM */\n");
|
|
|
|
} else if (class_enum) {
|
|
|
|
fprintf(stdout, "#ifndef CLASSENUM\n");
|
|
|
|
fprintf(stdout, "#define CLASSENUM%s\n",
|
|
|
|
classes != NULL ? " \\" : "");
|
|
|
|
|
|
|
|
for (cc = classes; cc != NULL; cc = cc->next)
|
1999-02-04 06:38:43 +00:00
|
|
|
fprintf(stdout, "\t dns_rdataclass_%s = %d,%s\n",
|
1999-02-02 22:34:20 +00:00
|
|
|
funname(cc->classname, buf1),
|
1999-08-02 22:18:31 +00:00
|
|
|
cc->rdclass,
|
1999-01-28 05:03:25 +00:00
|
|
|
cc->next != NULL ? " \\" : "");
|
|
|
|
fprintf(stdout, "#endif /* CLASSENUM */\n");
|
1999-05-05 01:55:13 +00:00
|
|
|
} else if (structs) {
|
1999-05-07 03:24:15 +00:00
|
|
|
if (prefix != NULL) {
|
|
|
|
if ((fd = fopen(prefix,"r")) != NULL) {
|
|
|
|
while (fgets(buf, sizeof buf, fd) != NULL)
|
|
|
|
fputs(buf, stdout);
|
|
|
|
fclose(fd);
|
|
|
|
}
|
|
|
|
}
|
1999-05-05 01:55:13 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
1999-05-07 03:24:15 +00:00
|
|
|
if (suffix != NULL) {
|
|
|
|
if ((fd = fopen(suffix,"r")) != NULL) {
|
|
|
|
while (fgets(buf, sizeof buf, fd) != NULL)
|
|
|
|
fputs(buf, stdout);
|
|
|
|
fclose(fd);
|
|
|
|
}
|
|
|
|
}
|
1999-01-28 05:03:25 +00:00
|
|
|
}
|
1999-01-19 02:20:26 +00:00
|
|
|
|
|
|
|
if (ferror(stdout) != 0)
|
|
|
|
exit(1);
|
|
|
|
|
1999-10-05 19:50:53 +00:00
|
|
|
return (0);
|
1999-01-19 02:20:26 +00:00
|
|
|
}
|