rdatalist.c revision fd9f6afdff9faf55411dfd5f828529601cab0511
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson/*
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1999, 2000 Internet Software Consortium.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson *
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * copyright notice and this permission notice appear in all copies.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson *
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * SOFTWARE.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson */
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
fc8a6561cbb0a1fea849950a3217aacd3b8f1eacDavid Lawrence#include <config.h>
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson#include <stddef.h>
f80ea74e1984e0b1dbe48dd86ecdd3a2380393cbBob Halley
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson#include <isc/util.h>
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson#include <dns/rdata.h>
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson#include <dns/rdatalist.h>
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson#include <dns/rdataset.h>
fc8a6561cbb0a1fea849950a3217aacd3b8f1eacDavid Lawrence
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafssonstatic void rdatalist_disassociate(dns_rdataset_t *rdatasetp);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic isc_result_t rdatalist_first(dns_rdataset_t *rdataset);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic isc_result_t rdatalist_next(dns_rdataset_t *rdataset);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic void rdatalist_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic void rdatalist_clone(dns_rdataset_t *source, dns_rdataset_t *target);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic unsigned int rdatalist_count(dns_rdataset_t *rdataset);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic dns_rdatasetmethods_t methods = {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist_disassociate,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist_first,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist_next,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist_current,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist_clone,
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist_count
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson};
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonvoid
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_rdatalist_init(dns_rdatalist_t *rdatalist) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson /*
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Initialize rdatalist.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson */
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist->rdclass = 0;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist->type = 0;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist->covers = 0;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist->ttl = 0;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson ISC_LIST_INIT(rdatalist->rdata);
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson ISC_LINK_INIT(rdatalist, link);
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson}
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafssonisc_result_t
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafssondns_rdatalist_tordataset(dns_rdatalist_t *rdatalist,
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson dns_rdataset_t *rdataset) {
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson /*
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson * Make 'rdataset' refer to the rdata in 'rdatalist'.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson */
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson REQUIRE(rdatalist != NULL);
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafsson REQUIRE(DNS_RDATASET_VALID(rdataset));
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson REQUIRE(! dns_rdataset_isassociated(rdataset));
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->methods = &methods;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->rdclass = rdatalist->rdclass;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->type = rdatalist->type;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->covers = rdatalist->covers;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->ttl = rdatalist->ttl;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->trust = 0;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->private1 = rdatalist;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->private2 = NULL;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->private3 = NULL;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->private4 = NULL;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->private5 = NULL;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson return (ISC_R_SUCCESS);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson}
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic void
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonrdatalist_disassociate(dns_rdataset_t *rdataset) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson UNUSED(rdataset);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson}
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic isc_result_t
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafssonrdatalist_first(dns_rdataset_t *rdataset) {
ed04318ef686581fc9a20965a5be02abfb4f1bd5Andreas Gustafsson dns_rdatalist_t *rdatalist;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdatalist = rdataset->private1;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->private2 = ISC_LIST_HEAD(rdatalist->rdata);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson if (rdataset->private2 == NULL)
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson return (ISC_R_NOMORE);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson return (ISC_R_SUCCESS);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson}
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic isc_result_t
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonrdatalist_next(dns_rdataset_t *rdataset) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson dns_rdata_t *rdata;
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdata = rdataset->private2;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson if (rdata == NULL)
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson return (ISC_R_NOMORE);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdataset->private2 = ISC_LIST_NEXT(rdata, link);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson if (rdataset->private2 == NULL)
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson return (ISC_R_NOMORE);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson return (ISC_R_SUCCESS);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson}
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic void
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafssonrdatalist_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson dns_rdata_t *list_rdata;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson list_rdata = rdataset->private2;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson INSIST(list_rdata != NULL);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson *rdata = *list_rdata;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson ISC_LINK_INIT(rdata, link);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson}
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonstatic void
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssonrdatalist_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson *target = *source;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson /*
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Reset iterator state.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson */
f80ea74e1984e0b1dbe48dd86ecdd3a2380393cbBob Halley target->private2 = NULL;
f80ea74e1984e0b1dbe48dd86ecdd3a2380393cbBob Halley}
f80ea74e1984e0b1dbe48dd86ecdd3a2380393cbBob Halley
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafssonstatic unsigned int
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafssonrdatalist_count(dns_rdataset_t *rdataset) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson dns_rdatalist_t *rdatalist;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson dns_rdata_t *rdata;
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson unsigned int count;
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson
7618f0551eb745354ee695907e568b0be1f2c8f5Andreas Gustafsson rdatalist = rdataset->private1;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson count = 0;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson for (rdata = ISC_LIST_HEAD(rdatalist->rdata);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdata != NULL;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson rdata = ISC_LIST_NEXT(rdata, link))
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson count++;
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson return (count);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson}
9b0e18da3d5c2290f90b285d122d368173f17c63Andreas Gustafsson