Update to ldns-1.6.7
[dragonfly.git] / contrib / ldns / ldns / zone.h
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 mark_glue function 
121  *
122  * \param[in] z the zone to look for glue
123  * \return the rr_list with the glue
124  */
125 ldns_rr_list *ldns_zone_glue_rr_list(const ldns_zone *z);
126
127 /**
128  * Create a new zone from a file
129  * \param[out] z the new zone
130  * \param[in] *fp the filepointer to use
131  * \param[in] *origin the zones' origin
132  * \param[in] ttl default ttl to use
133  * \param[in] c default class to use (IN)
134  *
135  * \return ldns_status mesg with an error or LDNS_STATUS_OK
136  */
137 ldns_status ldns_zone_new_frm_fp(ldns_zone **z, FILE *fp, ldns_rdf *origin, uint32_t ttl, ldns_rr_class c);
138
139 /**
140  * Create a new zone from a file, keep track of the line numbering
141  * \param[out] z the new zone
142  * \param[in] *fp the filepointer to use
143  * \param[in] *origin the zones' origin
144  * \param[in] ttl default ttl to use
145  * \param[in] c default class to use (IN)
146  * \param[out] line_nr used for error msg, to get to the line number
147  *
148  * \return ldns_status mesg with an error or LDNS_STATUS_OK
149  */
150 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);
151
152 /**
153  * Frees the allocated memory for the zone, and the rr_list structure in it
154  * \param[in] zone the zone to free
155  */
156 void ldns_zone_free(ldns_zone *zone);
157
158 /**
159  * Frees the allocated memory for the zone, the soa rr in it, 
160  * and the rr_list structure in it, including the rr's in that. etc.
161  * \param[in] zone the zone to free
162  */
163 void ldns_zone_deep_free(ldns_zone *zone);
164
165 /**
166  * Sort the rrs in a zone, with the current impl. this is slow
167  * \param[in] zone the zone to sort
168  */
169 void ldns_zone_sort(ldns_zone *zone);
170
171 #ifdef __cplusplus
172 }
173 #endif
174
175 #endif /* LDNS_ZONE_H */