xref: /freebsd/contrib/ldns/ldns/zone.h (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1 /**
2  * zone.h
3  *
4  * zone definitions
5  *  - what is it
6  *  - get_glue function
7  *  - search etc
8  *
9  * a Net::DNS like library for C
10  *
11  * (c) NLnet Labs, 2005-2006
12  *
13  * See the file LICENSE for the license
14  */
15 
16 /**
17  * \file
18  *
19  * Defines the ldns_zone structure and functions to manipulate it.
20  */
21 
22 
23 #ifndef LDNS_ZONE_H
24 #define LDNS_ZONE_H
25 
26 #include <ldns/common.h>
27 #include <ldns/rdata.h>
28 #include <ldns/rr.h>
29 #include <ldns/error.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /**
36  * DNS Zone
37  *
38  * A list of RR's with some
39  * extra information which comes from the SOA RR
40  * Note: nothing has been done to make this efficient (yet).
41  */
42 struct ldns_struct_zone
43 {
44 	/** the soa defines a zone */
45 	ldns_rr 	*_soa;
46 	/* basicly a zone is a list of rr's */
47 	ldns_rr_list 	*_rrs;
48 	/* we could change this to be a b-tree etc etc todo */
49 };
50 typedef struct ldns_struct_zone ldns_zone;
51 
52 /**
53  * create a new ldns_zone structure
54  * \return a pointer to a ldns_zone structure
55  */
56 ldns_zone * ldns_zone_new(void);
57 
58 /**
59  * Return the soa record of a zone
60  * \param[in] z the zone to read from
61  * \return the soa record in the zone
62  */
63 ldns_rr * ldns_zone_soa(const ldns_zone *z);
64 
65 /**
66  * Returns the number of resource records in the zone, NOT counting the SOA record
67  * \param[in] z the zone to read from
68  * \return the number of rr's in the zone
69  */
70 size_t ldns_zone_rr_count(const ldns_zone *z);
71 
72 /**
73  * Set the zone's soa record
74  * \param[in] z the zone to put the new soa in
75  * \param[in] soa the soa to set
76  */
77 void ldns_zone_set_soa(ldns_zone *z, ldns_rr *soa);
78 
79 /**
80  * Get a list of a zone's content. Note that the SOA
81  * isn't included in this list. You need to get the
82  * with ldns_zone_soa.
83  * \param[in] z the zone to read from
84  * \return the rrs from this zone
85  */
86 ldns_rr_list * ldns_zone_rrs(const ldns_zone *z);
87 
88 /**
89  * Set the zone's contents
90  * \param[in] z the zone to put the new soa in
91  * \param[in] rrlist the rrlist to use
92  */
93 void ldns_zone_set_rrs(ldns_zone *z, ldns_rr_list *rrlist);
94 
95 /**
96  * push an rrlist to a zone structure. This function use pointer
97  * copying, so the rr_list structure inside z is modified!
98  * \param[in] z the zone to add to
99  * \param[in] list the list to add
100  * \return a true on succes otherwise falsed
101  */
102 bool ldns_zone_push_rr_list(ldns_zone *z, ldns_rr_list *list);
103 
104 /**
105  * push an single rr to a zone structure. This function use pointer
106  * copying, so the rr_list structure inside z is modified!
107  * \param[in] z the zone to add to
108  * \param[in] rr the rr to add
109  * \return a true on succes otherwise falsed
110  */
111 bool ldns_zone_push_rr(ldns_zone *z, ldns_rr *rr);
112 
113 /**
114  * Retrieve all resource records from the zone that are glue
115  * records. The resulting list does are pointer references
116  * to the zone's data.
117  *
118  * Due to the current zone implementation (as a list of rr's), this
119  * function is extremely slow. Another (probably better) way to do this
120  * is to use an ldns_dnssec_zone structure and the
121  * ldns_dnssec_mark_and_get_glue() function.
122  *
123  * \param[in] z the zone to look for glue
124  * \return the rr_list with the glue
125  */
126 ldns_rr_list *ldns_zone_glue_rr_list(const ldns_zone *z);
127 
128 /**
129  * Create a new zone from a file
130  * \param[out] z the new zone
131  * \param[in] *fp the filepointer to use
132  * \param[in] *origin the zones' origin
133  * \param[in] ttl default ttl to use
134  * \param[in] c default class to use (IN)
135  *
136  * \return ldns_status mesg with an error or LDNS_STATUS_OK
137  */
138 ldns_status ldns_zone_new_frm_fp(ldns_zone **z, FILE *fp, ldns_rdf *origin, uint32_t ttl, ldns_rr_class c);
139 
140 /**
141  * Create a new zone from a file, keep track of the line numbering
142  * \param[out] z the new zone
143  * \param[in] *fp the filepointer to use
144  * \param[in] *origin the zones' origin
145  * \param[in] ttl default ttl to use
146  * \param[in] c default class to use (IN)
147  * \param[out] line_nr used for error msg, to get to the line number
148  *
149  * \return ldns_status mesg with an error or LDNS_STATUS_OK
150  */
151 ldns_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);
152 
153 /**
154  * Frees the allocated memory for the zone, and the rr_list structure in it
155  * \param[in] zone the zone to free
156  */
157 void ldns_zone_free(ldns_zone *zone);
158 
159 /**
160  * Frees the allocated memory for the zone, the soa rr in it,
161  * and the rr_list structure in it, including the rr's in that. etc.
162  * \param[in] zone the zone to free
163  */
164 void ldns_zone_deep_free(ldns_zone *zone);
165 
166 /**
167  * Sort the rrs in a zone, with the current impl. this is slow
168  * \param[in] zone the zone to sort
169  */
170 void ldns_zone_sort(ldns_zone *zone);
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif /* LDNS_ZONE_H */
177