9 * a Net::DNS like library for C
11 * (c) NLnet Labs, 2005-2006
13 * See the file LICENSE for the license
19 * Defines the ldns_zone structure and functions to manipulate it.
26 #include <ldns/common.h>
27 #include <ldns/rdata.h>
29 #include <ldns/error.h>
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).
42 struct ldns_struct_zone
44 /** the soa defines a zone */
46 /* basicly a zone is a list of rr's */
48 /* we could change this to be a b-tree etc etc todo */
50 typedef struct ldns_struct_zone ldns_zone;
53 * create a new ldns_zone structure
54 * \return a pointer to a ldns_zone structure
56 ldns_zone * ldns_zone_new(void);
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
63 ldns_rr * ldns_zone_soa(const ldns_zone *z);
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
70 size_t ldns_zone_rr_count(const ldns_zone *z);
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
77 void ldns_zone_set_soa(ldns_zone *z, ldns_rr *soa);
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
83 * \param[in] z the zone to read from
84 * \return the rrs from this zone
86 ldns_rr_list * ldns_zone_rrs(const ldns_zone *z);
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
93 void ldns_zone_set_rrs(ldns_zone *z, ldns_rr_list *rrlist);
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
102 bool ldns_zone_push_rr_list(ldns_zone *z, ldns_rr_list *list);
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
111 bool ldns_zone_push_rr(ldns_zone *z, ldns_rr *rr);
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.
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.
123 * \param[in] z the zone to look for glue
124 * \return the rr_list with the glue
126 ldns_rr_list *ldns_zone_glue_rr_list(const ldns_zone *z);
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)
136 * \return ldns_status mesg with an error or LDNS_STATUS_OK
138 ldns_status ldns_zone_new_frm_fp(ldns_zone **z, FILE *fp, ldns_rdf *origin, uint32_t ttl, ldns_rr_class c);
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
149 * \return ldns_status mesg with an error or LDNS_STATUS_OK
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);
154 * Frees the allocated memory for the zone, and the rr_list structure in it
155 * \param[in] zone the zone to free
157 void ldns_zone_free(ldns_zone *zone);
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
164 void ldns_zone_deep_free(ldns_zone *zone);
167 * Sort the rrs in a zone, with the current impl. this is slow
168 * \param[in] zone the zone to sort
170 void ldns_zone_sort(ldns_zone *zone);
176 #endif /* LDNS_ZONE_H */