1825eb42bSJan Lentfer /** 2825eb42bSJan Lentfer * zone.h 3825eb42bSJan Lentfer * 4825eb42bSJan Lentfer * zone definitions 5825eb42bSJan Lentfer * - what is it 6825eb42bSJan Lentfer * - get_glue function 7825eb42bSJan Lentfer * - search etc 8825eb42bSJan Lentfer * 9825eb42bSJan Lentfer * a Net::DNS like library for C 10825eb42bSJan Lentfer * 11825eb42bSJan Lentfer * (c) NLnet Labs, 2005-2006 12825eb42bSJan Lentfer * 13825eb42bSJan Lentfer * See the file LICENSE for the license 14825eb42bSJan Lentfer */ 15825eb42bSJan Lentfer 16825eb42bSJan Lentfer /** 17825eb42bSJan Lentfer * \file 18825eb42bSJan Lentfer * 19825eb42bSJan Lentfer * Defines the ldns_zone structure and functions to manipulate it. 20825eb42bSJan Lentfer */ 21825eb42bSJan Lentfer 22825eb42bSJan Lentfer 23825eb42bSJan Lentfer #ifndef LDNS_ZONE_H 24825eb42bSJan Lentfer #define LDNS_ZONE_H 25825eb42bSJan Lentfer 26825eb42bSJan Lentfer #include <ldns/common.h> 27825eb42bSJan Lentfer #include <ldns/rdata.h> 28825eb42bSJan Lentfer #include <ldns/rr.h> 29825eb42bSJan Lentfer #include <ldns/error.h> 30825eb42bSJan Lentfer 31ac996e71SJan Lentfer #ifdef __cplusplus 32ac996e71SJan Lentfer extern "C" { 33ac996e71SJan Lentfer #endif 34ac996e71SJan Lentfer 35825eb42bSJan Lentfer /** 36825eb42bSJan Lentfer * DNS Zone 37825eb42bSJan Lentfer * 38825eb42bSJan Lentfer * A list of RR's with some 39825eb42bSJan Lentfer * extra information which comes from the SOA RR 40825eb42bSJan Lentfer * Note: nothing has been done to make this efficient (yet). 41825eb42bSJan Lentfer */ 42825eb42bSJan Lentfer struct ldns_struct_zone 43825eb42bSJan Lentfer { 44825eb42bSJan Lentfer /** the soa defines a zone */ 45825eb42bSJan Lentfer ldns_rr *_soa; 46819dec71SDaniel Fojt /* basically a zone is a list of rr's */ 47825eb42bSJan Lentfer ldns_rr_list *_rrs; 48825eb42bSJan Lentfer /* we could change this to be a b-tree etc etc todo */ 49825eb42bSJan Lentfer }; 50825eb42bSJan Lentfer typedef struct ldns_struct_zone ldns_zone; 51825eb42bSJan Lentfer 52825eb42bSJan Lentfer /** 53825eb42bSJan Lentfer * create a new ldns_zone structure 54825eb42bSJan Lentfer * \return a pointer to a ldns_zone structure 55825eb42bSJan Lentfer */ 56825eb42bSJan Lentfer ldns_zone * ldns_zone_new(void); 57825eb42bSJan Lentfer 58825eb42bSJan Lentfer /** 59825eb42bSJan Lentfer * Return the soa record of a zone 60825eb42bSJan Lentfer * \param[in] z the zone to read from 61825eb42bSJan Lentfer * \return the soa record in the zone 62825eb42bSJan Lentfer */ 63825eb42bSJan Lentfer ldns_rr * ldns_zone_soa(const ldns_zone *z); 64825eb42bSJan Lentfer 65825eb42bSJan Lentfer /** 66825eb42bSJan Lentfer * Returns the number of resource records in the zone, NOT counting the SOA record 67825eb42bSJan Lentfer * \param[in] z the zone to read from 68825eb42bSJan Lentfer * \return the number of rr's in the zone 69825eb42bSJan Lentfer */ 70825eb42bSJan Lentfer size_t ldns_zone_rr_count(const ldns_zone *z); 71825eb42bSJan Lentfer 72825eb42bSJan Lentfer /** 73825eb42bSJan Lentfer * Set the zone's soa record 74825eb42bSJan Lentfer * \param[in] z the zone to put the new soa in 75825eb42bSJan Lentfer * \param[in] soa the soa to set 76825eb42bSJan Lentfer */ 77825eb42bSJan Lentfer void ldns_zone_set_soa(ldns_zone *z, ldns_rr *soa); 78825eb42bSJan Lentfer 79825eb42bSJan Lentfer /** 80825eb42bSJan Lentfer * Get a list of a zone's content. Note that the SOA 81825eb42bSJan Lentfer * isn't included in this list. You need to get the 82825eb42bSJan Lentfer * with ldns_zone_soa. 83825eb42bSJan Lentfer * \param[in] z the zone to read from 84825eb42bSJan Lentfer * \return the rrs from this zone 85825eb42bSJan Lentfer */ 86825eb42bSJan Lentfer ldns_rr_list * ldns_zone_rrs(const ldns_zone *z); 87825eb42bSJan Lentfer 88825eb42bSJan Lentfer /** 89825eb42bSJan Lentfer * Set the zone's contents 90825eb42bSJan Lentfer * \param[in] z the zone to put the new soa in 91825eb42bSJan Lentfer * \param[in] rrlist the rrlist to use 92825eb42bSJan Lentfer */ 93825eb42bSJan Lentfer void ldns_zone_set_rrs(ldns_zone *z, ldns_rr_list *rrlist); 94825eb42bSJan Lentfer 95825eb42bSJan Lentfer /** 96825eb42bSJan Lentfer * push an rrlist to a zone structure. This function use pointer 97825eb42bSJan Lentfer * copying, so the rr_list structure inside z is modified! 98825eb42bSJan Lentfer * \param[in] z the zone to add to 99825eb42bSJan Lentfer * \param[in] list the list to add 100*ee791febSAntonio Huete Jimenez * \return a true on success otherwise false 101825eb42bSJan Lentfer */ 1025340022aSzrj bool ldns_zone_push_rr_list(ldns_zone *z, const ldns_rr_list *list); 103825eb42bSJan Lentfer 104825eb42bSJan Lentfer /** 105825eb42bSJan Lentfer * push an single rr to a zone structure. This function use pointer 106825eb42bSJan Lentfer * copying, so the rr_list structure inside z is modified! 107825eb42bSJan Lentfer * \param[in] z the zone to add to 108825eb42bSJan Lentfer * \param[in] rr the rr to add 109*ee791febSAntonio Huete Jimenez * \return a true on success otherwise false 110825eb42bSJan Lentfer */ 111825eb42bSJan Lentfer bool ldns_zone_push_rr(ldns_zone *z, ldns_rr *rr); 112825eb42bSJan Lentfer 113825eb42bSJan Lentfer /** 114825eb42bSJan Lentfer * Retrieve all resource records from the zone that are glue 115825eb42bSJan Lentfer * records. The resulting list does are pointer references 116825eb42bSJan Lentfer * to the zone's data. 117825eb42bSJan Lentfer * 118825eb42bSJan Lentfer * Due to the current zone implementation (as a list of rr's), this 119825eb42bSJan Lentfer * function is extremely slow. Another (probably better) way to do this 120b5dedccaSJan Lentfer * is to use an ldns_dnssec_zone structure and the 121b5dedccaSJan Lentfer * ldns_dnssec_mark_and_get_glue() function. 122825eb42bSJan Lentfer * 123825eb42bSJan Lentfer * \param[in] z the zone to look for glue 124825eb42bSJan Lentfer * \return the rr_list with the glue 125825eb42bSJan Lentfer */ 126825eb42bSJan Lentfer ldns_rr_list *ldns_zone_glue_rr_list(const ldns_zone *z); 127825eb42bSJan Lentfer 128825eb42bSJan Lentfer /** 129825eb42bSJan Lentfer * Create a new zone from a file 130825eb42bSJan Lentfer * \param[out] z the new zone 131825eb42bSJan Lentfer * \param[in] *fp the filepointer to use 132825eb42bSJan Lentfer * \param[in] *origin the zones' origin 133825eb42bSJan Lentfer * \param[in] ttl default ttl to use 134825eb42bSJan Lentfer * \param[in] c default class to use (IN) 135825eb42bSJan Lentfer * 136825eb42bSJan Lentfer * \return ldns_status mesg with an error or LDNS_STATUS_OK 137825eb42bSJan Lentfer */ 1385340022aSzrj ldns_status ldns_zone_new_frm_fp(ldns_zone **z, FILE *fp, const ldns_rdf *origin, uint32_t ttl, ldns_rr_class c); 139825eb42bSJan Lentfer 140825eb42bSJan Lentfer /** 141825eb42bSJan Lentfer * Create a new zone from a file, keep track of the line numbering 142825eb42bSJan Lentfer * \param[out] z the new zone 143825eb42bSJan Lentfer * \param[in] *fp the filepointer to use 144825eb42bSJan Lentfer * \param[in] *origin the zones' origin 145825eb42bSJan Lentfer * \param[in] ttl default ttl to use 146825eb42bSJan Lentfer * \param[in] c default class to use (IN) 147825eb42bSJan Lentfer * \param[out] line_nr used for error msg, to get to the line number 148825eb42bSJan Lentfer * 149825eb42bSJan Lentfer * \return ldns_status mesg with an error or LDNS_STATUS_OK 150825eb42bSJan Lentfer */ 1515340022aSzrj ldns_status ldns_zone_new_frm_fp_l(ldns_zone **z, FILE *fp, const ldns_rdf *origin, uint32_t ttl, ldns_rr_class c, int *line_nr); 152825eb42bSJan Lentfer 153825eb42bSJan Lentfer /** 154825eb42bSJan Lentfer * Frees the allocated memory for the zone, and the rr_list structure in it 155825eb42bSJan Lentfer * \param[in] zone the zone to free 156825eb42bSJan Lentfer */ 157825eb42bSJan Lentfer void ldns_zone_free(ldns_zone *zone); 158825eb42bSJan Lentfer 159825eb42bSJan Lentfer /** 160825eb42bSJan Lentfer * Frees the allocated memory for the zone, the soa rr in it, 161825eb42bSJan Lentfer * and the rr_list structure in it, including the rr's in that. etc. 162825eb42bSJan Lentfer * \param[in] zone the zone to free 163825eb42bSJan Lentfer */ 164825eb42bSJan Lentfer void ldns_zone_deep_free(ldns_zone *zone); 165825eb42bSJan Lentfer 166825eb42bSJan Lentfer /** 167825eb42bSJan Lentfer * Sort the rrs in a zone, with the current impl. this is slow 168825eb42bSJan Lentfer * \param[in] zone the zone to sort 169825eb42bSJan Lentfer */ 170825eb42bSJan Lentfer void ldns_zone_sort(ldns_zone *zone); 171825eb42bSJan Lentfer 172ac996e71SJan Lentfer #ifdef __cplusplus 173ac996e71SJan Lentfer } 174ac996e71SJan Lentfer #endif 175ac996e71SJan Lentfer 176825eb42bSJan Lentfer #endif /* LDNS_ZONE_H */ 177