Commit 94a3bcd1 authored by Mark Andrews's avatar Mark Andrews
Browse files

dns_rdata_tostruct() may require memory to be allocted and hence

	it will need to be freed, dns_rdata_freestruct().
	Changes to implement this.

	Added C++ support to rdatastruct.h
parent 189e18de
......@@ -80,8 +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 > $@
include/dns/rdatastruct.h: gen rdata/rdatastructpre.h rdata/rdatastructsuf.h
./gen -s ${srcdir} -i \
-P rdata/rdatastructpre.h -S rdata/rdatastructsuf.h > $@
code.h: gen
./gen -s ${srcdir} > code.h
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: gen.c,v 1.18 1999/05/05 01:55:07 marka Exp $ */
/* $Id: gen.c,v 1.19 1999/05/07 03:24:04 marka Exp $ */
#include <sys/types.h>
......@@ -59,12 +59,18 @@
#define FROMSTRUCTTYPE "type"
#define FROMSTRUCTDEF "use_default = ISC_TRUE"
#define TOSTRUCTDECL "dns_rdata_t *rdata, void *target"
#define TOSTRUCTARGS "rdata, target"
#define TOSTRUCTDECL "dns_rdata_t *rdata, void *target, isc_mem_t *mctx"
#define TOSTRUCTARGS "rdata, target, mctx"
#define TOSTRUCTCLASS "rdata->class"
#define TOSTRUCTTYPE "rdata->type"
#define TOSTRUCTDEF "use_default = ISC_TRUE"
#define FREESTRUCTDECL "void *source"
#define FREESTRUCTARGS "source"
#define FREESTRUCTCLASS "common->rdclass"
#define FREESTRUCTTYPE "common->rdtype"
#define FREESTRUCTDEF NULL
#define COMPAREDECL "dns_rdata_t *rdata1, dns_rdata_t *rdata2"
#define COMPAREARGS "rdata1, rdata2"
#define COMPARECLASS "rdata1->class"
......@@ -149,6 +155,10 @@ doswitch(char *name, char *function, char *args,
int lasttype = 0;
int subswitch = 0;
char buf1[11], buf2[11];
char *result = " result =";
if (res == NULL)
result = "";
for (tt = types; tt != NULL ; tt = tt->next) {
if (first) {
......@@ -157,7 +167,11 @@ doswitch(char *name, char *function, char *args,
first = 0;
}
if (tt->type != lasttype && subswitch) {
fprintf(stdout, "\t\tdefault: %s; break; \\\n", res);
if (res == NULL)
fprintf(stdout, "\t\tdefault: break; \\\n");
else
fprintf(stdout,
"\t\tdefault: %s; break; \\\n", res);
fputs(/*{*/ "\t\t} \\\n", stdout);
fputs("\t\tbreak; \\\n", stdout);
subswitch = 0;
......@@ -169,27 +183,36 @@ doswitch(char *name, char *function, char *args,
}
if (tt->class == 0)
fprintf(stdout,
"\tcase %d: result = %s_%s(%s); break;",
tt->type, function,
"\tcase %d:%s %s_%s(%s); break;",
tt->type, result, function,
funname(tt->typename, buf1), args);
else
fprintf(stdout,
"\t\tcase %d: result = %s_%s_%s(%s); break;",
tt->class, function,
"\t\tcase %d:%s %s_%s_%s(%s); break;",
tt->class, result, function,
funname(tt->classname, buf1),
funname(tt->typename, buf2), args);
fputs(" \\\n", stdout);
lasttype = tt->type;
}
if (subswitch) {
fprintf(stdout, "\t\tdefault: %s; break; \\\n", res);
if (res == NULL)
fprintf(stdout, "\t\tdefault: break; \\\n");
else
fprintf(stdout, "\t\tdefault: %s; break; \\\n", res);
fputs(/*{*/ "\t\t} \\\n", stdout);
fputs("\t\tbreak; \\\n", stdout);
}
if (first)
fprintf(stdout, "\n#define %s %s;\n", name, res);
else {
fprintf(stdout, "\tdefault: %s; break; \\\n", res);
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);
fputs(/*{*/ "\t}\n", stdout);
}
}
......@@ -332,9 +355,11 @@ main(int argc, char **argv) {
char buf1[11];
char filetype = 'c';
FILE *fd;
char *prefix = NULL;
char *suffix = NULL;
strcpy(srcdir, "");
while ((c = getopt(argc, argv, "ctis:")) != -1)
while ((c = getopt(argc, argv, "cits:P:S:")) != -1)
switch (c) {
case 'c':
code = 0;
......@@ -360,6 +385,12 @@ main(int argc, char **argv) {
case 's':
sprintf(srcdir, "%s/", optarg);
break;
case 'P':
prefix = optarg;
break;
case 'S':
suffix = optarg;
break;
case '?':
exit(1);
}
......@@ -402,6 +433,7 @@ main(int argc, char **argv) {
dodecl("int", "compare", COMPAREDECL);
dodecl("dns_result_t", "fromstruct", FROMSTRUCTDECL);
dodecl("dns_result_t", "tostruct", TOSTRUCTDECL);
dodecl("void", "freestruct", FREESTRUCTDECL);
doswitch("FROMTEXTSWITCH", "fromtext", FROMTEXTARGS,
FROMTEXTTYPE, FROMTEXTCLASS, FROMTEXTDEF);
......@@ -417,6 +449,8 @@ main(int argc, char **argv) {
FROMSTRUCTTYPE, FROMSTRUCTCLASS, FROMSTRUCTDEF);
doswitch("TOSTRUCTSWITCH", "tostruct", TOSTRUCTARGS,
TOSTRUCTTYPE, TOSTRUCTCLASS, TOSTRUCTDEF);
doswitch("FREESTRUCTSWITCH", "freestruct", FREESTRUCTARGS,
FREESTRUCTTYPE, FREESTRUCTCLASS, FREESTRUCTDEF);
fprintf(stdout, "\n#define TYPENAMES%s\n",
types != NULL ? " \\" : "");
......@@ -468,6 +502,13 @@ main(int argc, char **argv) {
cc->next != NULL ? " \\" : "");
fprintf(stdout, "#endif /* CLASSENUM */\n");
} else if (structs) {
if (prefix != NULL) {
if ((fd = fopen(prefix,"r")) != NULL) {
while (fgets(buf, sizeof buf, fd) != NULL)
fputs(buf, stdout);
fclose(fd);
}
}
for (tt = types; tt != NULL ; tt = tt->next) {
sprintf(buf, "%s/%s_%d.h",
tt->dirname, tt->typename, tt->type);
......@@ -477,6 +518,13 @@ main(int argc, char **argv) {
fclose(fd);
}
}
if (suffix != NULL) {
if ((fd = fopen(suffix,"r")) != NULL) {
while (fgets(buf, sizeof buf, fd) != NULL)
fputs(buf, stdout);
fclose(fd);
}
}
}
if (ferror(stdout) != 0)
......
......@@ -360,22 +360,32 @@ dns_result_t dns_rdata_fromstruct(dns_rdata_t *rdata,
* Resource Limit: Not enough space
*/
dns_result_t dns_rdata_tostruct(dns_rdata_t *rdata, void *target);
dns_result_t dns_rdata_tostruct(dns_rdata_t *rdata, void *target,
isc_mem_t *mctx);
/*
* Convert an rdata into its C structure representation.
*
* XXX Should we have a 'size' parameter as a sanity check on target?
*
* Requires:
*
* 'rdata' is a valid, non-empty rdata.
*
* 'target' points to a valid C struct for the class and type.
* 'target' to point to a valid pointer for the type and class.
*
* Result:
* Success
* Resource Limit: Not enough memory
*/
void dns_rdata_freestruct(void *source);
/*
* Free dynamic memory attached to 'source' (if any).
*
* Requires:
*
* 'source' to point to the structure previously filled in by
* dns_rdata_tostruct().
*/
ISC_LANG_ENDDECLS
#endif /* DNS_RDATA_H */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: rdata.c,v 1.41 1999/05/05 01:55:08 marka Exp $ */
/* $Id: rdata.c,v 1.42 1999/05/07 03:24:05 marka Exp $ */
#include <config.h>
......@@ -469,7 +469,7 @@ dns_rdata_fromstruct(dns_rdata_t *rdata, dns_rdataclass_t class,
}
dns_result_t
dns_rdata_tostruct(dns_rdata_t *rdata, void *target) {
dns_rdata_tostruct(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
dns_result_t result = DNS_R_NOTIMPLEMENTED;
isc_boolean_t use_default = ISC_FALSE;
......@@ -483,6 +483,14 @@ dns_rdata_tostruct(dns_rdata_t *rdata, void *target) {
return (result);
}
void
dns_rdata_freestruct(void *source) {
dns_rdatacommon_t *common = source;
REQUIRE(source != NULL);
FREESTRUCTSWITCH
}
dns_result_t
dns_rdataclass_fromtext(dns_rdataclass_t *classp, isc_textregion_t *source) {
int i = 0;
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: tsig_250.c,v 1.8 1999/05/05 00:18:59 marka Exp $ */
/* $Id: tsig_250.c,v 1.9 1999/05/07 03:24:05 marka Exp $ */
/* draft-ietf-dnsind-tsig-07.txt */
......@@ -294,13 +294,25 @@ fromstruct_any_tsig(dns_rdataclass_t class, dns_rdatatype_t type,
}
static dns_result_t
tostruct_any_tsig(dns_rdata_t *rdata, void *target) {
tostruct_any_tsig(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
REQUIRE(rdata->type == 250);
REQUIRE(rdata->class == 255);
target = target;
mctx = mctx;
return (DNS_R_NOTIMPLEMENTED);
}
static void
freestruct_any_tsig(void *source) {
dns_rdata_any_tsig_t *tsig = source;
REQUIRE(source != NULL);
REQUIRE(tsig->common.rdclass == 255);
REQUIRE(tsig->common.rdtype == 250);
REQUIRE(ISC_FALSE);
}
#endif /* RDATA_ANY_255_TSIG_250_C */
......@@ -15,11 +15,11 @@
* SOFTWARE.
*/
/* $Id: tsig_250.h,v 1.8 1999/05/05 01:55:08 marka Exp $ */
/* $Id: tsig_250.h,v 1.9 1999/05/07 03:24:05 marka Exp $ */
/* draft-ietf-dnsind-tsig-07.txt */
#ifndef RDATA_ANY_255_TSIG_250_H
#define RDATA_ANY_255_TSIG_250_H
#endif /* RDATA_ANY_255_TSIG_250_H */
typedef struct dns_rdata_any_tsig {
dns_rdatacommon_t common;
/*XXX*/
} dns_rdata_any_tsig_t;
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: afsdb_18.c,v 1.6 1999/05/05 00:18:59 marka Exp $ */
/* $Id: afsdb_18.c,v 1.7 1999/05/07 03:24:05 marka Exp $ */
/* RFC 1183 */
......@@ -179,12 +179,23 @@ fromstruct_afsdb(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
}
static dns_result_t
tostruct_afsdb(dns_rdata_t *rdata, void *target) {
tostruct_afsdb(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
REQUIRE(rdata->type == 18);
REQUIRE(target != NULL);
target = target;
mctx = mctx;
return (DNS_R_NOTIMPLEMENTED);
}
static void
freestruct_afsdb(void *source) {
dns_rdata_afsdb_t *afsdb = source;
REQUIRE(source != NULL);
REQUIRE(afsdb->common.rdtype == 18);
REQUIRE(ISC_FALSE);
}
#endif /* RDATA_GENERIC_AFSDB_18_C */
......@@ -15,10 +15,11 @@
* SOFTWARE.
*/
/* $Id: afsdb_18.h,v 1.6 1999/05/05 01:55:08 marka Exp $ */
/* $Id: afsdb_18.h,v 1.7 1999/05/07 03:24:05 marka Exp $ */
/* RFC 1183 */
#ifndef RDATA_GENERIC_AFSDB_18_H
#define RDATA_GENERIC_AFSDB_18_H
#endif /* RDATA_GENERIC_AFSDB_18_H */
typedef struct dns_rdata_afsdb {
dns_rdatacommon_t common;
/*XXX*/
} dns_rdata_afsdb_t;
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: cert_37.c,v 1.6 1999/05/05 00:19:00 marka Exp $ */
/* $Id: cert_37.c,v 1.7 1999/05/07 03:24:06 marka Exp $ */
/* draft-ietf-dnssec-certs-04.txt */
......@@ -169,12 +169,20 @@ fromstruct_cert(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
}
static dns_result_t
tostruct_cert(dns_rdata_t *rdata, void *target) {
tostruct_cert(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
REQUIRE(rdata->type == 37);
REQUIRE(target != NULL && target == NULL);
target = target;
mctx = mctx;
return (DNS_R_NOTIMPLEMENTED);
}
static void
freestruct_cert(void *target) {
REQUIRE(target != NULL && target != NULL);
REQUIRE(ISC_FALSE); /* XXX */
}
#endif /* RDATA_GENERIC_CERT_37_C */
......@@ -15,10 +15,7 @@
* SOFTWARE.
*/
/* $Id: cert_37.h,v 1.6 1999/05/05 01:55:08 marka Exp $ */
/* $Id: cert_37.h,v 1.7 1999/05/07 03:24:06 marka Exp $ */
/* draft-ietf-dnssec-certs-04.txt */
#ifndef RDATA_GENERIC_CERT_37_H
#define RDATA_GENERIC_CERT_37_H
#endif /* RDATA_GENERIC_CERT_37_H */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: cname_5.c,v 1.12 1999/05/05 00:19:00 marka Exp $ */
/* $Id: cname_5.c,v 1.13 1999/05/07 03:24:06 marka Exp $ */
#ifndef RDATA_GENERIC_CNAME_5_C
#define RDATA_GENERIC_CNAME_5_C
......@@ -140,12 +140,21 @@ fromstruct_cname(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
}
static dns_result_t
tostruct_cname(dns_rdata_t *rdata, void *target) {
tostruct_cname(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
REQUIRE(rdata->type == 5);
REQUIRE(target != NULL);
target = target;
mctx = mctx;
return (DNS_R_NOTIMPLEMENTED);
}
static void
freestruct_cname(void *source) {
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE);
}
#endif /* RDATA_GENERIC_CNAME_5_C */
......@@ -15,8 +15,5 @@
* SOFTWARE.
*/
/* $Id: cname_5.h,v 1.12 1999/05/05 01:55:08 marka Exp $ */
/* $Id: cname_5.h,v 1.13 1999/05/07 03:24:06 marka Exp $ */
#ifndef RDATA_GENERIC_CNAME_5_H
#define RDATA_GENERIC_CNAME_5_H
#endif /* RDATA_GENERIC_CNAME_5_H */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: dname_39.c,v 1.5 1999/05/05 00:19:00 marka Exp $ */
/* $Id: dname_39.c,v 1.6 1999/05/07 03:24:06 marka Exp $ */
/* draft-ietf-dnsind-dname-02.txt */
......@@ -140,12 +140,20 @@ fromstruct_dname(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
}
static dns_result_t
tostruct_dname(dns_rdata_t *rdata, void *target) {
tostruct_dname(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
REQUIRE(rdata->type == 39);
REQUIRE(target != NULL && target == NULL);
target = target;
mctx = mctx;
return (DNS_R_NOTIMPLEMENTED);
}
static void
freestruct_dname(void *source) {
REQUIRE(source != NULL && source != NULL);
REQUIRE(ISC_FALSE); /* XXX */
}
#endif /* RDATA_GENERIC_DNAME_39_C */
......@@ -15,10 +15,7 @@
* SOFTWARE.
*/
/* $Id: dname_39.h,v 1.5 1999/05/05 01:55:09 marka Exp $ */
/* $Id: dname_39.h,v 1.6 1999/05/07 03:24:06 marka Exp $ */
/* draft-ietf-dnsind-dname-02.txt */
#ifndef RDATA_GENERIC_DNAME_39_H
#define RDATA_GENERIC_DNAME_39_H
#endif /* RDATA_GENERIC_DNAME_39_H */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: gpos_27.c,v 1.3 1999/05/05 00:19:00 marka Exp $ */
/* $Id: gpos_27.c,v 1.4 1999/05/07 03:24:06 marka Exp $ */
/* RFC 1712 */
......@@ -122,12 +122,19 @@ fromstruct_gpos(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
}
static dns_result_t
tostruct_gpos(dns_rdata_t *rdata, void *target) {
tostruct_gpos(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
REQUIRE(rdata->type == 27);
target = target;
mctx = mctx;
return (DNS_R_NOTIMPLEMENTED);
}
static void
freestruct_gpos(void *source) {
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /* XXX */
}
#endif /* RDATA_GENERIC_GPOS_27_C */
......@@ -15,10 +15,7 @@
* SOFTWARE.
*/
/* $Id: gpos_27.h,v 1.3 1999/05/05 01:55:09 marka Exp $ */
/* $Id: gpos_27.h,v 1.4 1999/05/07 03:24:06 marka Exp $ */
/* RFC 1712 */
#ifndef RDATA_GENERIC_GPOS_27_H
#define RDATA_GENERIC_GPOS_27_H
#endif /* RDATA_GENERIC_GPOS_27_H */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: hinfo_13.c,v 1.11 1999/05/05 00:19:00 marka Exp $ */
/* $Id: hinfo_13.c,v 1.12 1999/05/07 03:24:07 marka Exp $ */
#ifndef RDATA_GENERIC_HINFO_13_C
#define RDATA_GENERIC_HINFO_13_C
......@@ -112,12 +112,19 @@ fromstruct_hinfo(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
}
static dns_result_t
tostruct_hinfo(dns_rdata_t *rdata, void *target) {
tostruct_hinfo(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
REQUIRE(rdata->type == 13);
target = target;
mctx = mctx;
return (DNS_R_NOTIMPLEMENTED);
}
static void
freestruct_hinfo(void *source) {
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /* XXX */
}
#endif /* RDATA_GENERIC_HINFO_13_C */
......@@ -15,8 +15,5 @@
* SOFTWARE.
*/
/* $Id: hinfo_13.h,v 1.11 1999/05/05 01:55:09 marka Exp $ */
/* $Id: hinfo_13.h,v 1.12 1999/05/07 03:24:07 marka Exp $ */
#ifndef RDATA_GENERIC_HINFO_13_H
#define RDATA_GENERIC_HINFO_13_H
#endif /* RDATA_GENERIC_HINFO_13_H */
......@@ -122,12 +122,19 @@ fromstruct_isdn(dns_rdataclass_t class, dns_rdatatype_t type, void *source,
}
static dns_result_t
tostruct_isdn(dns_rdata_t *rdata, void *target) {
tostruct_isdn(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
REQUIRE(rdata->type == 20);
target = target;
mctx = mctx;
return (DNS_R_NOTIMPLEMENTED);
}
static void
freestruct_isdn(void *source) {
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /*XXX*/
}
#endif /* RDATA_GENERIC_ISDN_20_C */
......@@ -19,6 +19,3 @@
/* RFC 1183 */
#ifndef RDATA_GENERIC_ISDN_20_H
#define RDATA_GENERIC_ISDN_20_H
#endif /* RDATA_GENERIC_ISDN_20_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment