rdataslab.c revision f9f2e770a992cb0ed2234b2f985162273059c6d3
/*
* Copyright (C) 1999-2001 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.31 2002/02/21 23:51:49 bwelling Exp $ */
#include <config.h>
#include <stdlib.h>
#include <dns/rdataset.h>
#include <dns/rdataslab.h>
/* Note: the "const void *" are just to make qsort happy. */
static int
}
{
unsigned char *rawbuf;
unsigned int buflen;
unsigned int nitems;
unsigned int nalloc;
unsigned int i;
if (nitems == 0)
return (ISC_R_FAILURE);
return (ISC_R_NOMEMORY);
/*
* Save all of the rdata members into an array.
*/
if (result != ISC_R_SUCCESS)
goto free_rdatas;
dns_rdata_init(&rdatas[i]);
}
if (result != ISC_R_NOMORE)
goto free_rdatas;
if (i != nalloc) {
/*
* Somehow we iterated over fewer rdatas than
* dns_rdataset_count() said there were!
*/
goto free_rdatas;
}
/*
* Remove duplicates and compute the total storage required.
*
* If an rdata is not a duplicate, accumulate the storage size
* required for the rdata. 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.
*/
for (i = 1; i < nalloc; i++) {
nitems--;
} else
}
/*
* Don't forget the last item!
*/
/*
* Ensure that singleton types are actually singletons.
*/
/*
* We have a singleton type, but there's more than one
* RR in the rdataset.
*/
goto free_rdatas;
}
/*
* Allocate the memory, set up a buffer, start copying in
* data.
*/
goto free_rdatas;
}
rawbuf += reservelen;
for (i = 0; i < nalloc; i++) {
continue;
}
return (result);
}
static void
}
static isc_result_t
unsigned int count;
if (count == 0) {
return (ISC_R_NOMORE);
}
raw += 2;
/*
* The private4 field is the number of rdata beyond the cursor
* position, so we decrement the total count by one before storing
* it.
*/
count--;
return (ISC_R_SUCCESS);
}
static isc_result_t
unsigned int count;
unsigned int length;
unsigned char *raw;
if (count == 0)
return (ISC_R_NOMORE);
count--;
return (ISC_R_SUCCESS);
}
static void
isc_region_t r;
raw += 2;
}
static void
/*
* Reset iterator state.
*/
}
static unsigned int
unsigned int count;
return (count);
}
static dns_rdatasetmethods_t rdataset_methods = {
};
void
{
/*
* Reset iterator state.
*/
}
unsigned int
unsigned char *current;
while (count > 0) {
count--;
}
}
/*
* Make the dns_rdata_t 'rdata' refer to the slab item
* beginning at '*current', which is part of a slab of type
* 'type' and class 'rdclass', and advance '*current' to
* point to the next item in the slab.
*/
static inline void
rdata_from_slab(unsigned char **current,
{
}
/*
* Return true iff 'slab' (slab data of type 'type' and class 'rdclass')
* contains an rdata identical to 'rdata'. This does case insensitive
* comparisons per DNSSEC.
*/
static inline isc_boolean_t
{
unsigned int count, i;
unsigned char *current;
for (i = 0; i < count; i++) {
return (ISC_TRUE);
}
return (ISC_FALSE);
}
{
unsigned int oadded = 0;
unsigned int nadded = 0;
unsigned int nncount = 0;
/*
* XXX Need parameter to allow "delete rdatasets in nslab" merge,
* or perhaps another merge routine for this purpose.
*/
/*
* Yes, this is inefficient!
*/
/*
* Figure out the length of the old slab's data.
*/
olength = 0;
}
/*
* Start figuring out the target length and count.
*/
/*
* Add in the length of rdata in the new slab that aren't in
* the old slab.
*/
do {
{
/*
* This rdata isn't in the old slab.
*/
tcount++;
nncount++;
}
ncount--;
} while (ncount > 0);
if (((flags & DNS_RDATASLAB_EXACT) != 0) &&
return (DNS_R_NOTEXACT);
return (DNS_R_UNCHANGED);
/*
* Ensure that singleton types are actually singletons.
*/
/*
* We have a singleton type, but there's more than one
* RR in the rdataset.
*/
return (DNS_R_SINGLETON);
}
/*
* Copy the reserved area from the new slab.
*/
return (ISC_R_NOMEMORY);
/*
* Write the new count.
*/
/*
* Merge the two slabs.
*/
if (ncount > 0) {
do {
}
else
if (fromold) {
oadded++;
&ordata);
}
} else {
nadded++;
do {
&nrdata));
}
}
}
return (ISC_R_SUCCESS);
}
{
/*
* Yes, this is inefficient!
*/
/*
* Start figuring out the target length and count.
*/
tcount = 0;
rcount = 0;
/*
* Add in the length of rdata in the mslab that aren't in
* the sslab.
*/
do {
unsigned char *mrdatabegin = mcurrent;
break;
}
/*
* This rdata isn't in the sslab, and thus isn't
* being subtracted.
*/
tcount++;
} else
rcount++;
mcount--;
} while (mcount > 0);
/*
* Check that all the records originally existed. The numeric
* check only works as rdataslabs do not contain duplicates.
*/
return (DNS_R_NOTEXACT);
/*
* Don't continue if the new rdataslab would be empty.
*/
if (tcount == 0)
return (DNS_R_NXRRSET);
/*
* If nothing is going to change, we can stop.
*/
if (rcount == 0)
return (DNS_R_UNCHANGED);
/*
* Copy the reserved area from the mslab.
*/
return (ISC_R_NOMEMORY);
/*
* Write the new count.
*/
/*
* Copy the parts of mslab not in sslab.
*/
do {
unsigned char *mrdatabegin = mcurrent;
break;
}
/*
* This rdata isn't in the sslab, and thus should be
* copied to the tslab.
*/
}
mcount--;
} while (mcount > 0);
return (ISC_R_SUCCESS);
}
unsigned int reservelen)
{
return (ISC_FALSE);
while (count1 > 0) {
return (ISC_FALSE);
count1--;
}
return (ISC_TRUE);
}