1238104Sdes/** 2238104Sdes * zone.h 3238104Sdes * 4238104Sdes * zone definitions 5238104Sdes * - what is it 6238104Sdes * - get_glue function 7238104Sdes * - search etc 8238104Sdes * 9238104Sdes * a Net::DNS like library for C 10238104Sdes * 11238104Sdes * (c) NLnet Labs, 2005-2006 12238104Sdes * 13238104Sdes * See the file LICENSE for the license 14238104Sdes */ 15238104Sdes 16238104Sdes/** 17238104Sdes * \file 18238104Sdes * 19238104Sdes * Defines the ldns_zone structure and functions to manipulate it. 20238104Sdes */ 21238104Sdes 22238104Sdes 23238104Sdes#ifndef LDNS_ZONE_H 24238104Sdes#define LDNS_ZONE_H 25238104Sdes 26238104Sdes#include <ldns/common.h> 27238104Sdes#include <ldns/rdata.h> 28238104Sdes#include <ldns/rr.h> 29238104Sdes#include <ldns/error.h> 30238104Sdes 31238104Sdes#ifdef __cplusplus 32238104Sdesextern "C" { 33238104Sdes#endif 34238104Sdes 35238104Sdes/** 36238104Sdes * DNS Zone 37238104Sdes * 38238104Sdes * A list of RR's with some 39238104Sdes * extra information which comes from the SOA RR 40238104Sdes * Note: nothing has been done to make this efficient (yet). 41238104Sdes */ 42238104Sdesstruct ldns_struct_zone 43238104Sdes{ 44238104Sdes /** the soa defines a zone */ 45238104Sdes ldns_rr *_soa; 46238104Sdes /* basicly a zone is a list of rr's */ 47238104Sdes ldns_rr_list *_rrs; 48238104Sdes /* we could change this to be a b-tree etc etc todo */ 49238104Sdes}; 50238104Sdestypedef struct ldns_struct_zone ldns_zone; 51238104Sdes 52238104Sdes/** 53238104Sdes * create a new ldns_zone structure 54238104Sdes * \return a pointer to a ldns_zone structure 55238104Sdes */ 56238104Sdesldns_zone * ldns_zone_new(void); 57238104Sdes 58238104Sdes/** 59238104Sdes * Return the soa record of a zone 60238104Sdes * \param[in] z the zone to read from 61238104Sdes * \return the soa record in the zone 62238104Sdes */ 63238104Sdesldns_rr * ldns_zone_soa(const ldns_zone *z); 64238104Sdes 65238104Sdes/** 66238104Sdes * Returns the number of resource records in the zone, NOT counting the SOA record 67238104Sdes * \param[in] z the zone to read from 68238104Sdes * \return the number of rr's in the zone 69238104Sdes */ 70238104Sdessize_t ldns_zone_rr_count(const ldns_zone *z); 71238104Sdes 72238104Sdes/** 73238104Sdes * Set the zone's soa record 74238104Sdes * \param[in] z the zone to put the new soa in 75238104Sdes * \param[in] soa the soa to set 76238104Sdes */ 77238104Sdesvoid ldns_zone_set_soa(ldns_zone *z, ldns_rr *soa); 78238104Sdes 79238104Sdes/** 80238104Sdes * Get a list of a zone's content. Note that the SOA 81238104Sdes * isn't included in this list. You need to get the 82238104Sdes * with ldns_zone_soa. 83238104Sdes * \param[in] z the zone to read from 84238104Sdes * \return the rrs from this zone 85238104Sdes */ 86238104Sdesldns_rr_list * ldns_zone_rrs(const ldns_zone *z); 87238104Sdes 88238104Sdes/** 89238104Sdes * Set the zone's contents 90238104Sdes * \param[in] z the zone to put the new soa in 91238104Sdes * \param[in] rrlist the rrlist to use 92238104Sdes */ 93238104Sdesvoid ldns_zone_set_rrs(ldns_zone *z, ldns_rr_list *rrlist); 94238104Sdes 95238104Sdes/** 96238104Sdes * push an rrlist to a zone structure. This function use pointer 97238104Sdes * copying, so the rr_list structure inside z is modified! 98238104Sdes * \param[in] z the zone to add to 99238104Sdes * \param[in] list the list to add 100238104Sdes * \return a true on succes otherwise falsed 101238104Sdes */ 102238104Sdesbool ldns_zone_push_rr_list(ldns_zone *z, ldns_rr_list *list); 103238104Sdes 104238104Sdes/** 105238104Sdes * push an single rr to a zone structure. This function use pointer 106238104Sdes * copying, so the rr_list structure inside z is modified! 107238104Sdes * \param[in] z the zone to add to 108238104Sdes * \param[in] rr the rr to add 109238104Sdes * \return a true on succes otherwise falsed 110238104Sdes */ 111238104Sdesbool ldns_zone_push_rr(ldns_zone *z, ldns_rr *rr); 112238104Sdes 113238104Sdes/** 114238104Sdes * Retrieve all resource records from the zone that are glue 115238104Sdes * records. The resulting list does are pointer references 116238104Sdes * to the zone's data. 117238104Sdes * 118238104Sdes * Due to the current zone implementation (as a list of rr's), this 119238104Sdes * function is extremely slow. Another (probably better) way to do this 120238104Sdes * is to use an ldns_dnssec_zone structure and the 121238104Sdes * ldns_dnssec_mark_and_get_glue() function. 122238104Sdes * 123238104Sdes * \param[in] z the zone to look for glue 124238104Sdes * \return the rr_list with the glue 125238104Sdes */ 126238104Sdesldns_rr_list *ldns_zone_glue_rr_list(const ldns_zone *z); 127238104Sdes 128238104Sdes/** 129238104Sdes * Create a new zone from a file 130238104Sdes * \param[out] z the new zone 131238104Sdes * \param[in] *fp the filepointer to use 132238104Sdes * \param[in] *origin the zones' origin 133238104Sdes * \param[in] ttl default ttl to use 134238104Sdes * \param[in] c default class to use (IN) 135238104Sdes * 136238104Sdes * \return ldns_status mesg with an error or LDNS_STATUS_OK 137238104Sdes */ 138238104Sdesldns_status ldns_zone_new_frm_fp(ldns_zone **z, FILE *fp, ldns_rdf *origin, uint32_t ttl, ldns_rr_class c); 139238104Sdes 140238104Sdes/** 141238104Sdes * Create a new zone from a file, keep track of the line numbering 142238104Sdes * \param[out] z the new zone 143238104Sdes * \param[in] *fp the filepointer to use 144238104Sdes * \param[in] *origin the zones' origin 145238104Sdes * \param[in] ttl default ttl to use 146238104Sdes * \param[in] c default class to use (IN) 147238104Sdes * \param[out] line_nr used for error msg, to get to the line number 148238104Sdes * 149238104Sdes * \return ldns_status mesg with an error or LDNS_STATUS_OK 150238104Sdes */ 151238104Sdesldns_status ldns_zone_new_frm_fp_l(ldns_zone **z, FILE *fp, ldns_rdf *origin, uint32_t ttl, ldns_rr_class c, int *line_nr); 152238104Sdes 153238104Sdes/** 154238104Sdes * Frees the allocated memory for the zone, and the rr_list structure in it 155238104Sdes * \param[in] zone the zone to free 156238104Sdes */ 157238104Sdesvoid ldns_zone_free(ldns_zone *zone); 158238104Sdes 159238104Sdes/** 160238104Sdes * Frees the allocated memory for the zone, the soa rr in it, 161238104Sdes * and the rr_list structure in it, including the rr's in that. etc. 162238104Sdes * \param[in] zone the zone to free 163238104Sdes */ 164238104Sdesvoid ldns_zone_deep_free(ldns_zone *zone); 165238104Sdes 166238104Sdes/** 167238104Sdes * Sort the rrs in a zone, with the current impl. this is slow 168238104Sdes * \param[in] zone the zone to sort 169238104Sdes */ 170238104Sdesvoid ldns_zone_sort(ldns_zone *zone); 171238104Sdes 172238104Sdes#ifdef __cplusplus 173238104Sdes} 174238104Sdes#endif 175238104Sdes 176238104Sdes#endif /* LDNS_ZONE_H */ 177