confrrset.c revision da47a1b89683200737dbc5b750d44fbe2e1991b6
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley/*
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * Copyright (C) 1999, 2000 Internet Software Consortium.
134ba0e08a0ae9a564a8d8628fc633377d3fc239Bob Halley *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * purpose with or without fee is hereby granted, provided that the above
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * copyright notice and this permission notice appear in all copies.
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * SOFTWARE.
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence */
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence/* $Id: confrrset.c,v 1.10 2000/03/28 22:58:24 brister Exp $ */
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence#include <config.h>
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence#include <isc/assertions.h>
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley#include <isc/magic.h>
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley#include <dns/confrrset.h>
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley#include <dns/confcommon.h>
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyisc_result_t
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleydns_c_rrsolist_clear(dns_c_rrsolist_t *olist)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley{
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley dns_c_rrso_t *elem;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley REQUIRE(DNS_C_RRSOLIST_VALID(olist));
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley elem = ISC_LIST_HEAD(olist->elements);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley while (elem != NULL) {
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley ISC_LIST_UNLINK(olist->elements, elem, next);
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff dns_c_rrso_delete(&elem);
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff elem = ISC_LIST_HEAD(olist->elements);
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff }
90407942d3afe50f04ccea361de3b164a5a1702dMichael Graff
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff return (ISC_R_SUCCESS);
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff}
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halleyisc_result_t
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halleydns_c_rrsolist_append(dns_c_rrsolist_t *dest,
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley dns_c_rrsolist_t *src)
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley{
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley dns_c_rrso_t *oldelem;
dc97fe4ed08488d314ab5bc8e99ed839542cf411David Lawrence dns_c_rrso_t *newelem;
dc97fe4ed08488d314ab5bc8e99ed839542cf411David Lawrence isc_result_t res;
dc97fe4ed08488d314ab5bc8e99ed839542cf411David Lawrence
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley REQUIRE(DNS_C_RRSOLIST_VALID(dest));
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley REQUIRE(DNS_C_RRSOLIST_VALID(src));
8d4257cff01b3821abcb9a21f46c6c6a43bb1e72Bob Halley
50453ad879d0d93854de5a3385776bd799e8f35cBob Halley oldelem = ISC_LIST_HEAD(src->elements);
50453ad879d0d93854de5a3385776bd799e8f35cBob Halley while (oldelem != NULL) {
50453ad879d0d93854de5a3385776bd799e8f35cBob Halley res = dns_c_rrso_copy(dest->mem, &newelem, oldelem);
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellington if (res != ISC_R_SUCCESS) {
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellington return (res);
7005cfed8cd3296d356883dcb414979f22e06b13Brian Wellington }
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley ISC_LIST_APPEND(dest->elements, newelem, next);
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley oldelem = ISC_LIST_NEXT(oldelem, next);
194b6a25192581bbc8ec731e32e8989042b202a4Michael Graff }
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff
a30e7fc23415fd238d067a8a871607bca36068baMichael Graff return (ISC_R_SUCCESS);
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley}
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley
194b6a25192581bbc8ec731e32e8989042b202a4Michael Graff
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graffisc_result_t
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graffdns_c_rrsolist_new(isc_mem_t *mem, dns_c_rrsolist_t **rval)
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff{
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff dns_c_rrsolist_t *ro;
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff
8313838954d67250d0ed7edf67fba5da0790d1a7Michael Graff ro = isc_mem_get(mem, sizeof *ro);
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff if (ro == NULL) {
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff return (ISC_R_NOMEMORY);
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff }
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff
0eb2572d79822d02ea05448ce4e5f1759c73d171Michael Graff ISC_LIST_INIT(ro->elements);
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence ro->mem = mem;
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence ro->magic = DNS_C_RRSOLIST_MAGIC;
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence *rval = ro;
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence return (ISC_R_SUCCESS);
876753d5ce1be48f3218fb4875fac501f8adfd6cDavid Lawrence}
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrenceisc_result_t
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrencedns_c_rrso_new(isc_mem_t *mem, dns_c_rrso_t **res,
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence dns_rdataclass_t oclass,
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence dns_rdatatype_t otype, char *name, dns_c_ordering_t ordering)
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence{
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence dns_c_rrso_t *newo;
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence REQUIRE(mem != NULL);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence REQUIRE(res != NULL);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence if (name == NULL) {
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence name = "*";
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence }
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence newo = isc_mem_get(mem, sizeof *newo);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence if (newo == NULL) {
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence return (ISC_R_NOMEMORY);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence }
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence newo->magic = DNS_C_RRSO_MAGIC;
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence newo->mem = mem;
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrence newo->otype = otype;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley newo->oclass = oclass;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley newo->ordering = ordering;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley ISC_LINK_INIT(newo, next);
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley newo->name = isc_mem_strdup(mem, name);
5c00d1c90030a311d2700970fa7cffc8f828a48cBob Halley if (newo->name == NULL) {
134ba0e08a0ae9a564a8d8628fc633377d3fc239Bob Halley newo->magic = 0;
134ba0e08a0ae9a564a8d8628fc633377d3fc239Bob Halley isc_mem_put(mem, newo, sizeof *newo);
134ba0e08a0ae9a564a8d8628fc633377d3fc239Bob Halley return (ISC_R_NOMEMORY);
203596d27c225ea195e4faad4f19388c6e96ac80Bob Halley }
203596d27c225ea195e4faad4f19388c6e96ac80Bob Halley
203596d27c225ea195e4faad4f19388c6e96ac80Bob Halley *res = newo;
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley return (ISC_R_SUCCESS);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley}
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
15bfd48fc5552ff1aae766021f42a250c001a098Michael Graffisc_result_t
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graffdns_c_rrsolist_delete(dns_c_rrsolist_t **list)
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff{
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff dns_c_rrso_t *elem, *q;
15bfd48fc5552ff1aae766021f42a250c001a098Michael Graff dns_c_rrsolist_t *l;
15bfd48fc5552ff1aae766021f42a250c001a098Michael Graff isc_result_t r;
15bfd48fc5552ff1aae766021f42a250c001a098Michael Graff
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff REQUIRE(list != NULL);
882350d11c90de9de6fc1cead25690c8114b0b95Michael Graff REQUIRE(DNS_C_RRSOLIST_VALID(*list));
l = *list;
elem = ISC_LIST_HEAD(l->elements);
while (elem != NULL) {
q = ISC_LIST_NEXT(elem, next);
ISC_LIST_UNLINK(l->elements, elem, next);
r = dns_c_rrso_delete(&elem);
if (r != ISC_R_SUCCESS) {
return (r);
}
elem = q;
}
l->magic = 0;
isc_mem_put(l->mem, l, sizeof *l);
*list = NULL;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_c_rrso_delete(dns_c_rrso_t **order)
{
dns_c_rrso_t *oldo;
REQUIRE(order != NULL);
REQUIRE(DNS_C_RRSO_VALID(*order));
oldo = *order;
REQUIRE(oldo->name != NULL);
isc_mem_free(oldo->mem, oldo->name);
oldo->magic = 0;
isc_mem_put(oldo->mem, oldo, sizeof *oldo);
*order = NULL;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_c_rrso_copy(isc_mem_t *mem, dns_c_rrso_t **dest,
dns_c_rrso_t *source)
{
dns_c_rrso_t *newo;
isc_result_t res;
REQUIRE(DNS_C_RRSO_VALID(*dest));
REQUIRE(DNS_C_RRSO_VALID(source));
res = dns_c_rrso_new(mem, &newo, source->oclass,
source->otype, source->name,
source->ordering);
if (res == ISC_R_SUCCESS) {
*dest = newo;
} else {
*dest = NULL;
}
return (res);
}
isc_result_t
dns_c_rrsolist_copy(isc_mem_t *mem, dns_c_rrsolist_t **dest,
dns_c_rrsolist_t *source)
{
dns_c_rrsolist_t *nlist;
dns_c_rrso_t *elem;
dns_c_rrso_t *newe;
isc_result_t res;
REQUIRE(DNS_C_RRSOLIST_VALID(source));
REQUIRE(dest != NULL);
res = dns_c_rrsolist_new(mem, &nlist);
if (res != DNS_R_SUCCESS) {
return (res);
}
elem = ISC_LIST_HEAD(source->elements);
while (elem != NULL) {
res = dns_c_rrso_copy(mem, &newe, elem);
if (res != DNS_R_SUCCESS) {
dns_c_rrsolist_delete(&nlist);
return (res);
}
ISC_LIST_APPEND(nlist->elements, newe, next);
elem = ISC_LIST_NEXT(elem, next);
}
*dest = nlist;
return (ISC_R_SUCCESS);
}
void
dns_c_rrsolist_print(FILE *fp, int indent,
dns_c_rrsolist_t *rrlist)
{
dns_c_rrso_t *or;
REQUIRE(DNS_C_RRSOLIST_VALID(rrlist));
if (ISC_LIST_EMPTY(rrlist->elements)) {
return;
}
dns_c_printtabs(fp, indent);
fprintf(fp, "rrset-order {\n");
or = ISC_LIST_HEAD(rrlist->elements);
while (or != NULL) {
dns_c_rrso_print(fp, indent + 1, or);
or = ISC_LIST_NEXT(or, next);
}
dns_c_printtabs(fp, indent);
fprintf(fp, "};\n");
}
void
dns_c_rrso_print(FILE *fp, int indent, dns_c_rrso_t *order)
{
REQUIRE(DNS_C_RRSO_VALID(order));
dns_c_printtabs(fp, indent);
fputs("class ", fp);
if (order->oclass == dns_rdataclass_any) {
fputc('*', fp);
} else {
dns_c_dataclass_tostream(fp, order->oclass);
}
fputs(" type ", fp);
if (order->otype == dns_rdatatype_any) {
fputc('*', fp);
} else {
dns_c_datatype_tostream(fp, order->otype);
}
fprintf(fp, " name \"%s\"", order->name);
fprintf(fp, " order %s",
dns_c_ordering2string(order->ordering, ISC_TRUE));
fputs(";\n", fp);
}