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

implement and build dns_rdataslab_fromrdataset()

parent 22f735ac
......@@ -13,7 +13,7 @@ CDEFINES =
CWARNINGS =
OBJS = name.o rbt.o rdata.o rdatalist.o rdataset.o \
result.o version.o
result.o version.o rdataslab.o
SUBDIRS = include
TARGETS = timestamp
......
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* 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.
*/
#ifndef DNS_RDATASLAB_H
#define DNS_RDATASLAB_H 1
/*
* DNS Rdata Slab
*
* Implements storage of rdatasets into slabs of memory.
*
* MP:
* Clients of this module must impose any required synchronization.
*
* Reliability:
* This module deals with low-level byte streams. Errors in any of
* the functions are likely to crash the server or corrupt memory.
*
* Resources:
* None.
*
* Security:
*
* Very little range checking is done in these functions for rdata
* copied in or out. It is assumed that the caller knows what is
* going on.
*
* Standards:
* None.
*/
/***
*** Imports
***/
#include <isc/region.h>
#include <dns/types.h>
#include <dns/rdataset.h>
/***
*** Functions
***/
dns_result_t
dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
isc_region_t *region, unsigned int reservelen);
/*
* Slabify a rdataset. The slab area will be allocated and returned
* in 'region'.
*
* Requires:
* 'rdataset' is valid.
*
* Ensures:
* 'region' will have base pointing to the start of allocated memory,
* with the slabified region beginning at region->base + reservelen.
* region->length contains the total length allocated.
*
* Returns:
* DNS_R_SUCCESS - successful completion
* DNS_R_NOMEM - no memory.
* <XXX others>
*/
dns_result_t
dns_rdataslab_tordataset(dns_rdataset_t *rdataset, isc_region_t *region,
unsigned int reservelen);
/*
* Unslabify a rdataset. The slab is not deallocated.
*
* Requires:
* 'rdataset' is valid.
*
* 'region' points to a region of memory that contains the slabified
* data at offset 'reservelen'.
*
* Ensures:
* 'rdataset' contains the structure version of data in 'region'.
*
* Returns:
* DNS_R_SUCCESS - successful completion
* DNS_R_NOMEM - no memory.
* <XXX others>
*/
#endif /* DNS_RDATADLAB_H */
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* 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.
*/
/* $Id: rdataslab.c,v 1.1 1999/01/27 08:44:10 explorer Exp $ */
#include <config.h>
#include <isc/region.h>
#include <isc/buffer.h>
#include <isc/assertions.h>
#include <dns/types.h>
#include <dns/result.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rdatatype.h>
#include <dns/rdataset.h>
#include <dns/rdataslab.h>
dns_result_t
dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
isc_region_t *region, unsigned int reservelen)
{
dns_rdata_t rdata;
unsigned char *rawbuf;
unsigned int buflen;
dns_result_t result;
unsigned int nitems;
result = dns_rdataset_first(rdataset);
REQUIRE(result == DNS_R_SUCCESS);
buflen = reservelen + 2;
nitems = 0;
/*
* Run through the rdataset list once, counting up the size
* of all the rdata members within it. We do not store the
* class, type, etc, just the rdata, so our overhead is 2 bytes
* for the number of records, and 2 for each rdata length, and
* then the rdata itself.
*/
do {
dns_rdataset_current(rdataset, &rdata);
buflen += (2 + rdata.length);
nitems++;
result = dns_rdataset_next(rdataset);
} while (result == DNS_R_SUCCESS);
if (result != DNS_R_NOMORE)
return (result);
/*
* Allocate the memory, set up a buffer, start copying in
* data.
*/
rawbuf = isc_mem_get(mctx, buflen);
if (rawbuf == NULL)
return (DNS_R_NOMEMORY);
region->base = rawbuf;
region->length = buflen;
rawbuf += reservelen;
*rawbuf++ = (nitems & 0xff00) >> 8;
*rawbuf++ = (nitems & 0x00ff);
result = dns_rdataset_first(rdataset);
REQUIRE(result == DNS_R_SUCCESS);
do {
dns_rdataset_current(rdataset, &rdata);
*rawbuf++ = (rdata.length & 0xff00) >> 8;
*rawbuf++ = (rdata.length & 0x00ff);
memcpy(rawbuf, rdata.data, rdata.length);
rawbuf += rdata.length;
result = dns_rdataset_next(rdataset);
} while (result == DNS_R_SUCCESS);
if (result != DNS_R_NOMORE) {
isc_mem_put(mctx, region->base, region->length);
region->base = NULL;
region->length = 0;
return (result);
}
return (DNS_R_SUCCESS);
}
dns_result_t
dns_rdataslab_tordataset(dns_rdataset_t *rdataset, isc_region_t *region,
unsigned int reservelen)
{
/* XXX shut up compiler */
rdataset = rdataset;
region = region;
reservelen = reservelen;
return (DNS_R_NOTIMPLEMENTED);
}
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