1/* $NetBSD: dbiterator.c,v 1.1 2024/02/18 20:57:31 christos Exp $ */ 2 3/* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16/*! \file */ 17 18#include <stdbool.h> 19 20#include <isc/util.h> 21 22#include <dns/dbiterator.h> 23#include <dns/name.h> 24 25void 26dns_dbiterator_destroy(dns_dbiterator_t **iteratorp) { 27 /* 28 * Destroy '*iteratorp'. 29 */ 30 31 REQUIRE(iteratorp != NULL); 32 REQUIRE(DNS_DBITERATOR_VALID(*iteratorp)); 33 34 (*iteratorp)->methods->destroy(iteratorp); 35 36 ENSURE(*iteratorp == NULL); 37} 38 39isc_result_t 40dns_dbiterator_first(dns_dbiterator_t *iterator) { 41 /* 42 * Move the node cursor to the first node in the database (if any). 43 */ 44 45 REQUIRE(DNS_DBITERATOR_VALID(iterator)); 46 47 return (iterator->methods->first(iterator)); 48} 49 50isc_result_t 51dns_dbiterator_last(dns_dbiterator_t *iterator) { 52 /* 53 * Move the node cursor to the first node in the database (if any). 54 */ 55 56 REQUIRE(DNS_DBITERATOR_VALID(iterator)); 57 58 return (iterator->methods->last(iterator)); 59} 60 61isc_result_t 62dns_dbiterator_seek(dns_dbiterator_t *iterator, const dns_name_t *name) { 63 /* 64 * Move the node cursor to the node with name 'name'. 65 */ 66 67 REQUIRE(DNS_DBITERATOR_VALID(iterator)); 68 69 return (iterator->methods->seek(iterator, name)); 70} 71 72isc_result_t 73dns_dbiterator_prev(dns_dbiterator_t *iterator) { 74 /* 75 * Move the node cursor to the previous node in the database (if any). 76 */ 77 78 REQUIRE(DNS_DBITERATOR_VALID(iterator)); 79 80 return (iterator->methods->prev(iterator)); 81} 82 83isc_result_t 84dns_dbiterator_next(dns_dbiterator_t *iterator) { 85 /* 86 * Move the node cursor to the next node in the database (if any). 87 */ 88 89 REQUIRE(DNS_DBITERATOR_VALID(iterator)); 90 91 return (iterator->methods->next(iterator)); 92} 93 94isc_result_t 95dns_dbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep, 96 dns_name_t *name) { 97 /* 98 * Return the current node. 99 */ 100 101 REQUIRE(DNS_DBITERATOR_VALID(iterator)); 102 REQUIRE(nodep != NULL && *nodep == NULL); 103 REQUIRE(name == NULL || dns_name_hasbuffer(name)); 104 105 return (iterator->methods->current(iterator, nodep, name)); 106} 107 108isc_result_t 109dns_dbiterator_pause(dns_dbiterator_t *iterator) { 110 /* 111 * Pause iteration. 112 */ 113 114 REQUIRE(DNS_DBITERATOR_VALID(iterator)); 115 116 return (iterator->methods->pause(iterator)); 117} 118 119isc_result_t 120dns_dbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name) { 121 /* 122 * Return the origin to which returned node names are relative. 123 */ 124 125 REQUIRE(DNS_DBITERATOR_VALID(iterator)); 126 REQUIRE(iterator->relative_names); 127 REQUIRE(dns_name_hasbuffer(name)); 128 129 return (iterator->methods->origin(iterator, name)); 130} 131 132void 133dns_dbiterator_setcleanmode(dns_dbiterator_t *iterator, bool mode) { 134 REQUIRE(DNS_DBITERATOR_VALID(iterator)); 135 136 iterator->cleaning = mode; 137} 138