Commit 9281e7aa authored by Mark Andrews's avatar Mark Andrews
Browse files

Implement / convert to new API for tostuct() and freestruct().

Define dns_rdata_loc_t structure.
x25 length is only 8 bits.
parent 62fb5ecc
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: afsdb_18.c,v 1.24 2000/05/04 22:19:06 gson Exp $ */
/* $Id: afsdb_18.c,v 1.25 2000/05/05 05:49:39 marka Exp $ */
/* Reviewed: Wed Mar 15 14:59:00 PST 2000 by explorer */
......@@ -178,14 +178,30 @@ fromstruct_afsdb(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_afsdb(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
{
isc_region_t region;
dns_rdata_afsdb_t *afsdb = target;
dns_name_t name;
REQUIRE(rdata->type == 18);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
afsdb->common.rdclass = rdata->rdclass;
afsdb->common.rdtype = rdata->type;
ISC_LINK_INIT(&afsdb->common, link);
return (ISC_R_NOTIMPLEMENTED);
dns_name_init(&afsdb->server, NULL);
dns_rdata_toregion(rdata, &region);
afsdb->subtype = uint16_fromregion(&region);
isc_region_consume(&region, 2);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &region);
RETERR(name_duporclone(&name, mctx, &afsdb->server));
afsdb->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
......@@ -195,10 +211,12 @@ freestruct_afsdb(void *source)
REQUIRE(source != NULL);
REQUIRE(afsdb->common.rdtype == 18);
REQUIRE(ISC_FALSE);
UNUSED(source);
UNUSED(afsdb);
if (afsdb->mctx == NULL)
return;
dns_name_free(&afsdb->server, afsdb->mctx);
afsdb->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: cert_37.c,v 1.24 2000/04/28 01:23:59 gson Exp $ */
/* $Id: cert_37.c,v 1.25 2000/05/05 05:49:40 marka Exp $ */
/* Reviewed: Wed Mar 15 21:14:32 EST 2000 by tale */
......@@ -162,23 +162,51 @@ fromstruct_cert(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_cert(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
dns_rdata_cert_t *cert = target;
isc_region_t region;
REQUIRE(rdata->type == 37);
REQUIRE(target != NULL && target == NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
return (ISC_R_NOTIMPLEMENTED);
cert->common.rdclass = rdata->rdclass;
cert->common.rdtype = rdata->type;
ISC_LINK_INIT(&cert->common, link);
dns_rdata_toregion(rdata, &region);
cert->type = uint16_fromregion(&region);
isc_region_consume(&region, 2);
cert->key_tag = uint16_fromregion(&region);
isc_region_consume(&region, 2);
cert->algorithm = uint8_fromregion(&region);
isc_region_consume(&region, 1);
cert->length = region.length;
if (cert->length > 0) {
cert->certificate = mem_maybedup(mctx, region.base,
region.length);
if (cert->certificate == NULL)
return (ISC_R_NOMEMORY);
} else
cert->certificate = NULL;
cert->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_cert(void *target) {
dns_rdata_cert_t *cert = target;
REQUIRE(target != NULL && target != NULL);
REQUIRE(ISC_FALSE); /* XXX */
REQUIRE(cert->common.rdtype == 37);
UNUSED(target);
if (cert->mctx == NULL)
return;
if (cert->certificate != NULL)
isc_mem_free(cert->mctx, cert->certificate);
cert->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: cname_5.c,v 1.28 2000/05/04 22:19:07 gson Exp $ */
/* $Id: cname_5.c,v 1.29 2000/05/05 05:49:42 marka Exp $ */
/* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
......@@ -142,24 +142,38 @@ fromstruct_cname(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_cname(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
{
isc_region_t region;
dns_rdata_cname_t *cname = target;
dns_name_t name;
REQUIRE(rdata->type == 5);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
cname->common.rdclass = rdata->rdclass;
cname->common.rdtype = rdata->type;
ISC_LINK_INIT(&cname->common, link);
return (ISC_R_NOTIMPLEMENTED);
dns_name_init(&name, NULL);
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
dns_name_init(&cname->cname, NULL);
RETERR(name_duporclone(&name, mctx, &cname->cname));
cname->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_cname(void *source)
{
UNUSED(source);
dns_rdata_cname_t *cname = source;
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE);
if (cname->mctx == NULL)
return;
dns_name_free(&cname->cname, cname->mctx);
cname->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: dname_39.c,v 1.20 2000/05/04 22:19:09 gson Exp $ */
/* $Id: dname_39.c,v 1.21 2000/05/05 05:49:43 marka Exp $ */
/* Reviewed: Wed Mar 15 16:52:38 PST 2000 by explorer */
......@@ -142,23 +142,39 @@ fromstruct_dname(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_dname(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
{
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
isc_region_t region;
dns_rdata_dname_t *dname = target;
dns_name_t name;
REQUIRE(rdata->type == 39);
REQUIRE(target != NULL);
return (ISC_R_NOTIMPLEMENTED);
dname->common.rdclass = rdata->rdclass;
dname->common.rdtype = rdata->type;
ISC_LINK_INIT(&dname->common, link);
dns_name_init(&name, NULL);
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
dns_name_init(&dname->dname, NULL);
RETERR(name_duporclone(&name, mctx, &dname->dname));
dname->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_dname(void *source)
{
dns_rdata_dname_t *dname = source;
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /* XXX */
REQUIRE(dname->common.rdtype == 39);
if (dname->mctx == NULL)
return;
UNUSED(source);
dns_name_free(&dname->dname, dname->mctx);
dname->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: gpos_27.c,v 1.17 2000/04/28 01:24:01 gson Exp $ */
/* $Id: gpos_27.c,v 1.18 2000/05/05 05:49:44 marka Exp $ */
/* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
......@@ -132,23 +132,77 @@ fromstruct_gpos(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_gpos(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
{
dns_rdata_gpos_t *gpos = target;
isc_region_t region;
REQUIRE(rdata->type == 27);
REQUIRE(target != NULL);
gpos->common.rdclass = rdata->rdclass;
gpos->common.rdtype = rdata->type;
ISC_LINK_INIT(&gpos->common, link);
gpos->long_len = uint8_fromregion(&region);
isc_region_consume(&region, 1);
if (gpos->long_len != 0) {
gpos->longitude = mem_maybedup(mctx, region.base,
gpos->long_len);
if (gpos->longitude == NULL)
return (ISC_R_NOMEMORY);
isc_region_consume(&region, gpos->long_len);
} else
gpos->longitude = NULL;
gpos->lat_len = uint8_fromregion(&region);
isc_region_consume(&region, 1);
if (gpos->lat_len > 0) {
gpos->latitude = mem_maybedup(mctx, region.base, gpos->lat_len);
if (gpos->latitude == NULL)
goto cleanup_longitude;
isc_region_consume(&region, gpos->lat_len);
} else
gpos->latitude = NULL;
gpos->alt_len = uint8_fromregion(&region);
isc_region_consume(&region, 1);
if (gpos->lat_len > 0) {
gpos->altitude = mem_maybedup(mctx, region.base, gpos->alt_len);
if (gpos->altitude == NULL)
goto cleanup_latitude;
} else
gpos->altitude = NULL;
gpos->mctx = mctx;
return (ISC_R_SUCCESS);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
cleanup_latitude:
if (mctx != NULL && gpos->longitude != NULL)
isc_mem_free(mctx, gpos->longitude);
return (ISC_R_NOTIMPLEMENTED);
cleanup_longitude:
if (mctx != NULL && gpos->latitude != NULL)
isc_mem_free(mctx, gpos->latitude);
return (ISC_R_NOMEMORY);
}
static inline void
freestruct_gpos(void *source)
{
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /* XXX */
dns_rdata_gpos_t *gpos = source;
UNUSED(source);
REQUIRE(source != NULL);
REQUIRE(gpos->common.rdtype == 27);
if (gpos->mctx == NULL)
return;
if (gpos->longitude != NULL)
isc_mem_free(gpos->mctx, gpos->longitude);
if (gpos->latitude != NULL)
isc_mem_free(gpos->mctx, gpos->latitude);
if (gpos->altitude != NULL)
isc_mem_free(gpos->mctx, gpos->altitude);
gpos->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: hinfo_13.c,v 1.23 2000/04/28 01:24:01 gson Exp $ */
/* $Id: hinfo_13.c,v 1.24 2000/05/05 05:49:45 marka Exp $ */
/*
* Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley.
......@@ -119,22 +119,58 @@ fromstruct_hinfo(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_hinfo(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
dns_rdata_hinfo_t *hinfo = target;
isc_region_t region;
REQUIRE(rdata->type == 13);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
hinfo->common.rdclass = rdata->rdclass;
hinfo->common.rdtype = rdata->type;
ISC_LINK_INIT(&hinfo->common, link);
return (ISC_R_NOTIMPLEMENTED);
dns_rdata_toregion(rdata, &region);
hinfo->cpu_len = uint8_fromregion(&region);
isc_region_consume(&region, 1);
if (hinfo->cpu_len > 0) {
hinfo->cpu = mem_maybedup(mctx, region.base, hinfo->cpu_len);
if (hinfo->cpu == NULL)
return (ISC_R_NOMEMORY);
isc_region_consume(&region, hinfo->cpu_len);
} else
hinfo->cpu = NULL;
hinfo->os_len = uint8_fromregion(&region);
isc_region_consume(&region, 1);
if (hinfo->os_len > 0) {
hinfo->os = mem_maybedup(mctx, region.base, hinfo->os_len);
if (hinfo->os == NULL)
goto cleanup;
} else
hinfo->os = NULL;
hinfo->mctx = mctx;
return (ISC_R_SUCCESS);
cleanup:
if (mctx != NULL && hinfo->cpu != NULL)
isc_mem_free(mctx, hinfo->cpu);
return (ISC_R_NOMEMORY);
}
static inline void
freestruct_hinfo(void *source) {
dns_rdata_hinfo_t *hinfo = source;
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /* XXX */
UNUSED(source);
if (hinfo->mctx == NULL)
return;
if (hinfo->cpu != NULL)
isc_mem_free(hinfo->mctx, hinfo->cpu);
if (hinfo->os != NULL)
isc_mem_free(hinfo->mctx, hinfo->os);
hinfo->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: isdn_20.c,v 1.17 2000/04/28 01:24:01 gson Exp $ */
/* $Id: isdn_20.c,v 1.18 2000/05/05 05:49:46 marka Exp $ */
/* Reviewed: Wed Mar 15 16:53:11 PST 2000 by bwelling */
......@@ -126,21 +126,61 @@ fromstruct_isdn(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_isdn(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
dns_rdata_isdn_t *isdn = target;
isc_region_t r;
REQUIRE(rdata->type == 20);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
isdn->common.rdclass = rdata->rdclass;
isdn->common.rdtype = rdata->type;
ISC_LINK_INIT(&isdn->common, link);
return (ISC_R_NOTIMPLEMENTED);
dns_rdata_toregion(rdata, &r);
isdn->isdn_len = uint8_fromregion(&r);
isc_region_consume(&r, 1);
if (isdn->isdn_len > 0) {
isdn->isdn = mem_maybedup(mctx, r.base, isdn->isdn_len);
if (isdn->isdn == NULL)
return (ISC_R_NOMEMORY);
isc_region_consume(&r, isdn->isdn_len);
} else
isdn->isdn = NULL;
isdn->subaddress_len = uint8_fromregion(&r);
isc_region_consume(&r, 1);
if (isdn->subaddress_len > 0) {
isdn->subaddress = mem_maybedup(mctx, r.base,
isdn->subaddress_len);
if (isdn->subaddress == NULL)
goto cleanup;
} else
isdn->subaddress = NULL;
isdn->mctx = mctx;
return (ISC_R_SUCCESS);
cleanup:
if (mctx != NULL && isdn->isdn != NULL)
isc_mem_free(mctx, isdn->isdn);
return (ISC_R_NOMEMORY);
}
static inline void
freestruct_isdn(void *source) {
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /*XXX*/
dns_rdata_isdn_t *isdn = source;
UNUSED(source);
REQUIRE(source != NULL);
if (isdn->mctx == NULL)
return;
if (isdn->isdn != NULL)
isc_mem_free(isdn->mctx, isdn->isdn);
if (isdn->subaddress != NULL)
isc_mem_free(isdn->mctx, isdn->subaddress);
isdn->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: key_25.c,v 1.23 2000/04/28 02:08:30 marka Exp $ */
/* $Id: key_25.c,v 1.24 2000/05/05 05:49:47 marka Exp $ */
/*
* Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley.
......@@ -199,19 +199,16 @@ fromstruct_key(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_key(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
dns_rdata_key_t *key;
dns_rdata_key_t *key = target;
isc_region_t sr;
UNUSED(target);
UNUSED(mctx);
REQUIRE(rdata->type == 25);
REQUIRE(target != NULL);
key = (dns_rdata_key_t *) target;
key->common.rdclass = rdata->rdclass;
key->common.rdtype = rdata->type;
ISC_LINK_INIT(&key->common, link);
key->mctx = mctx;
dns_rdata_toregion(rdata, &sr);
/* Flags */
......@@ -235,15 +232,13 @@ tostruct_key(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
/* Data */
key->datalen = sr.length;
if (key->datalen > 0) {
key->data = isc_mem_get(mctx, key->datalen);
key->data = mem_maybedup(mctx, sr.base, key->datalen);
if (key->data == NULL)
return (ISC_R_NOMEMORY);
memcpy(key->data, sr.base, key->datalen);
isc_region_consume(&sr, key->datalen);
}
else
} else
key->data = NULL;
key->mctx = mctx;
return (ISC_R_SUCCESS);
}
......@@ -254,8 +249,12 @@ freestruct_key(void *source) {
REQUIRE(source != NULL);
REQUIRE(key->common.rdtype == 25);
if (key->datalen > 0)
isc_mem_put(key->mctx, key->data, key->datalen);
if (key->mctx == NULL)
return;
if (key->data != NULL)
isc_mem_free(key->mctx, key->data);
key->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: loc_29.c,v 1.16 2000/04/28 01:24:02 gson Exp $ */
/* $Id: loc_29.c,v 1.17 2000/05/05 05:49:48 marka Exp $ */
/* Reviewed: Wed Mar 15 18:13:09 PST 2000 by explorer */
......@@ -583,20 +583,47 @@ fromstruct_loc(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_loc(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
{
dns_rdata_loc_t *loc = target;
isc_region_t r;
isc_uint8_t version;
REQUIRE(rdata->type == 29);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
return (ISC_R_NOTIMPLEMENTED);
dns_rdata_toregion(rdata, &r);
version = uint8_fromregion(&r);
if (version != 0)
return (ISC_R_NOTIMPLEMENTED);
loc->common.rdclass = rdata->rdclass;
loc->common.rdtype = rdata->type;
ISC_LINK_INIT(&loc->common, link);
loc->v.v0.version = version;
isc_region_consume(&r, 1);
loc->v.v0.size = uint8_fromregion(&r);
isc_region_consume(&r, 1);
loc->v.v0.horizontal = uint8_fromregion(&r);
isc_region_consume(&r, 1);
loc->v.v0.vertical = uint8_fromregion(&r);
isc_region_consume(&r, 1);
loc->v.v0.latitude = uint32_fromregion(&r);
isc_region_consume(&r, 4);
loc->v.v0.longitude = uint32_fromregion(&r);
isc_region_consume(&r, 4);
loc->v.v0.altitude = uint32_fromregion(&r);
isc_region_consume(&r, 4);
return (ISC_R_SUCCESS);
}
static inline void
freestruct_loc(void *source)
{