4 * the .h file with defs for the per rr
7 * a Net::DNS like library for C
9 * (c) NLnet Labs, 2005-2006
11 * See the file LICENSE for the license
13 #ifndef LDNS_RR_FUNCTIONS_H
14 #define LDNS_RR_FUNCTIONS_H
23 * Defines some extra convenience functions for ldns_rr structures
28 * returns the address of a LDNS_RR_TYPE_A rr
29 * \param[in] r the resource record
30 * \return a ldns_rdf* with the address or NULL on failure
32 ldns_rdf* ldns_rr_a_address(const ldns_rr *r);
35 * sets the address of a LDNS_RR_TYPE_A rr
36 * \param[in] r the rr to use
37 * \param[in] f the address to set
38 * \return true on success, false otherwise
40 bool ldns_rr_a_set_address(ldns_rr *r, ldns_rdf *f);
44 * returns the name of a LDNS_RR_TYPE_NS rr
45 * \param[in] r the resource record
46 * \return a ldns_rdf* with the name or NULL on failure
48 ldns_rdf* ldns_rr_ns_nsdname(const ldns_rr *r);
52 * returns the mx pref. of a LDNS_RR_TYPE_MX rr
53 * \param[in] r the resource record
54 * \return a ldns_rdf* with the preference or NULL on failure
56 ldns_rdf* ldns_rr_mx_preference(const ldns_rr *r);
58 * returns the mx host of a LDNS_RR_TYPE_MX rr
59 * \param[in] r the resource record
60 * \return a ldns_rdf* with the name of the MX host or NULL on failure
62 ldns_rdf* ldns_rr_mx_exchange(const ldns_rr *r);
66 * returns the type covered of a LDNS_RR_TYPE_RRSIG rr
67 * \param[in] r the resource record
68 * \return a ldns_rdf* with the type covered or NULL on failure
70 ldns_rdf* ldns_rr_rrsig_typecovered(const ldns_rr *r);
72 * sets the typecovered of a LDNS_RR_TYPE_RRSIG rr
73 * \param[in] r the rr to use
74 * \param[in] f the typecovered to set
75 * \return true on success, false otherwise
77 bool ldns_rr_rrsig_set_typecovered(ldns_rr *r, ldns_rdf *f);
79 * returns the algorithm of a LDNS_RR_TYPE_RRSIG RR
80 * \param[in] r the resource record
81 * \return a ldns_rdf* with the algorithm or NULL on failure
83 ldns_rdf* ldns_rr_rrsig_algorithm(const ldns_rr *r);
85 * sets the algorithm of a LDNS_RR_TYPE_RRSIG rr
86 * \param[in] r the rr to use
87 * \param[in] f the algorithm to set
88 * \return true on success, false otherwise
90 bool ldns_rr_rrsig_set_algorithm(ldns_rr *r, ldns_rdf *f);
92 * returns the number of labels of a LDNS_RR_TYPE_RRSIG RR
93 * \param[in] r the resource record
94 * \return a ldns_rdf* with the number of labels or NULL on failure
96 ldns_rdf *ldns_rr_rrsig_labels(const ldns_rr *r);
98 * sets the number of labels of a LDNS_RR_TYPE_RRSIG rr
99 * \param[in] r the rr to use
100 * \param[in] f the number of labels to set
101 * \return true on success, false otherwise
103 bool ldns_rr_rrsig_set_labels(ldns_rr *r, ldns_rdf *f);
105 * returns the original TTL of a LDNS_RR_TYPE_RRSIG RR
106 * \param[in] r the resource record
107 * \return a ldns_rdf* with the original TTL or NULL on failure
109 ldns_rdf* ldns_rr_rrsig_origttl(const ldns_rr *r);
111 * sets the original TTL of a LDNS_RR_TYPE_RRSIG rr
112 * \param[in] r the rr to use
113 * \param[in] f the original TTL to set
114 * \return true on success, false otherwise
116 bool ldns_rr_rrsig_set_origttl(ldns_rr *r, ldns_rdf *f);
118 * returns the expiration time of a LDNS_RR_TYPE_RRSIG RR
119 * \param[in] r the resource record
120 * \return a ldns_rdf* with the expiration time or NULL on failure
122 ldns_rdf* ldns_rr_rrsig_expiration(const ldns_rr *r);
124 * sets the expireation date of a LDNS_RR_TYPE_RRSIG rr
125 * \param[in] r the rr to use
126 * \param[in] f the expireation date to set
127 * \return true on success, false otherwise
129 bool ldns_rr_rrsig_set_expiration(ldns_rr *r, ldns_rdf *f);
131 * returns the inception time of a LDNS_RR_TYPE_RRSIG RR
132 * \param[in] r the resource record
133 * \return a ldns_rdf* with the inception time or NULL on failure
135 ldns_rdf* ldns_rr_rrsig_inception(const ldns_rr *r);
137 * sets the inception date of a LDNS_RR_TYPE_RRSIG rr
138 * \param[in] r the rr to use
139 * \param[in] f the inception date to set
140 * \return true on success, false otherwise
142 bool ldns_rr_rrsig_set_inception(ldns_rr *r, ldns_rdf *f);
144 * returns the keytag of a LDNS_RR_TYPE_RRSIG RR
145 * \param[in] r the resource record
146 * \return a ldns_rdf* with the keytag or NULL on failure
148 ldns_rdf* ldns_rr_rrsig_keytag(const ldns_rr *r);
150 * sets the keytag of a LDNS_RR_TYPE_RRSIG rr
151 * \param[in] r the rr to use
152 * \param[in] f the keytag to set
153 * \return true on success, false otherwise
155 bool ldns_rr_rrsig_set_keytag(ldns_rr *r, ldns_rdf *f);
157 * returns the signers name of a LDNS_RR_TYPE_RRSIG RR
158 * \param[in] r the resource record
159 * \return a ldns_rdf* with the signers name or NULL on failure
161 ldns_rdf* ldns_rr_rrsig_signame(const ldns_rr *r);
163 * sets the signers name of a LDNS_RR_TYPE_RRSIG rr
164 * \param[in] r the rr to use
165 * \param[in] f the signers name to set
166 * \return true on success, false otherwise
168 bool ldns_rr_rrsig_set_signame(ldns_rr *r, ldns_rdf *f);
170 * returns the signature data of a LDNS_RR_TYPE_RRSIG RR
171 * \param[in] r the resource record
172 * \return a ldns_rdf* with the signature data or NULL on failure
174 ldns_rdf* ldns_rr_rrsig_sig(const ldns_rr *r);
176 * sets the signature data of a LDNS_RR_TYPE_RRSIG rr
177 * \param[in] r the rr to use
178 * \param[in] f the signature data to set
179 * \return true on success, false otherwise
181 bool ldns_rr_rrsig_set_sig(ldns_rr *r, ldns_rdf *f);
185 * returns the flags of a LDNS_RR_TYPE_DNSKEY rr
186 * \param[in] r the resource record
187 * \return a ldns_rdf* with the flags or NULL on failure
189 ldns_rdf* ldns_rr_dnskey_flags(const ldns_rr *r);
191 * sets the flags of a LDNS_RR_TYPE_DNSKEY rr
192 * \param[in] r the rr to use
193 * \param[in] f the flags to set
194 * \return true on success, false otherwise
196 bool ldns_rr_dnskey_set_flags(ldns_rr *r, ldns_rdf *f);
198 * returns the protocol of a LDNS_RR_TYPE_DNSKEY rr
199 * \param[in] r the resource record
200 * \return a ldns_rdf* with the protocol or NULL on failure
202 ldns_rdf* ldns_rr_dnskey_protocol(const ldns_rr *r);
204 * sets the protocol of a LDNS_RR_TYPE_DNSKEY rr
205 * \param[in] r the rr to use
206 * \param[in] f the protocol to set
207 * \return true on success, false otherwise
209 bool ldns_rr_dnskey_set_protocol(ldns_rr *r, ldns_rdf *f);
211 * returns the algorithm of a LDNS_RR_TYPE_DNSKEY rr
212 * \param[in] r the resource record
213 * \return a ldns_rdf* with the algorithm or NULL on failure
215 ldns_rdf* ldns_rr_dnskey_algorithm(const ldns_rr *r);
217 * sets the algorithm of a LDNS_RR_TYPE_DNSKEY rr
218 * \param[in] r the rr to use
219 * \param[in] f the algorithm to set
220 * \return true on success, false otherwise
222 bool ldns_rr_dnskey_set_algorithm(ldns_rr *r, ldns_rdf *f);
224 * returns the key data of a LDNS_RR_TYPE_DNSKEY rr
225 * \param[in] r the resource record
226 * \return a ldns_rdf* with the key data or NULL on failure
228 ldns_rdf* ldns_rr_dnskey_key(const ldns_rr *r);
230 * sets the key data of a LDNS_RR_TYPE_DNSKEY rr
231 * \param[in] r the rr to use
232 * \param[in] f the key data to set
233 * \return true on success, false otherwise
235 bool ldns_rr_dnskey_set_key(ldns_rr *r, ldns_rdf *f);
238 * get the length of the keydata in bits
239 * \param[in] keydata the raw key data
240 * \param[in] len the length of the keydata
241 * \param[in] alg the cryptographic algorithm this is a key for
242 * \return the keysize in bits, or 0 on error
244 size_t ldns_rr_dnskey_key_size_raw(const unsigned char *keydata,
246 const ldns_algorithm alg);
249 * get the length of the keydata in bits
250 * \param[in] key the key rr to use
251 * \return the keysize in bits
253 size_t ldns_rr_dnskey_key_size(const ldns_rr *key);
256 * The type of function to be passed to ldns_rr_soa_increment_func,
257 * ldns_rr_soa_increment_func_data or ldns_rr_soa_increment_int.
258 * The function will be called with as the first argument the current serial
259 * number of the SOA RR to be updated, and as the second argument a value
260 * given when calling ldns_rr_soa_increment_func_data or
261 * ldns_rr_soa_increment_int. With ldns_rr_soa_increment_int the pointer
262 * value holds the integer value passed to ldns_rr_soa_increment_int,
263 * and it should be cast to intptr_t to be used as an integer by the
264 * serial modifying function.
266 typedef uint32_t (*ldns_soa_serial_increment_func_t)(uint32_t, void*);
269 * Function to be used with dns_rr_soa_increment_func_int, to set the soa
271 * \param[in] unused the (unused) current serial number.
272 * \param[in] data the serial number to be set.
274 uint32_t ldns_soa_serial_identity(uint32_t unused, void *data);
277 * Function to be used with dns_rr_soa_increment_func, to increment the soa
278 * serial number with one.
279 * \param[in] s the current serial number.
280 * \param[in] unused unused.
282 uint32_t ldns_soa_serial_increment(uint32_t s, void *unused);
285 * Function to be used with dns_rr_soa_increment_func_int, to increment the soa
286 * serial number with a certain amount.
287 * \param[in] s the current serial number.
288 * \param[in] data the amount to add to the current serial number.
290 uint32_t ldns_soa_serial_increment_by(uint32_t s, void *data);
293 * Function to be used with ldns_rr_soa_increment_func or
294 * ldns_rr_soa_increment_func_int to set the soa serial to the number of
295 * seconds since unix epoch (1-1-1970 00:00).
296 * When data is given (i.e. the function is called via
297 * ldns_rr_soa_increment_func_int), it is used as the current time.
298 * When the resulting serial number is smaller than the current serial number,
299 * the current serial number is increased by one.
300 * \param[in] s the current serial number.
301 * \param[in] data the time in seconds since 1-1-1970 00:00
303 uint32_t ldns_soa_serial_unixtime(uint32_t s, void *data);
306 * Function to be used with ldns_rr_soa_increment_func or
307 * ldns_rr_soa_increment_func_int to set the soa serial to the current date
308 * succeeded by a two digit iteration (datecounter).
309 * When data is given (i.e. the function is called via
310 * ldns_rr_soa_increment_func_int), it is used as the current time.
311 * When the resulting serial number is smaller than the current serial number,
312 * the current serial number is increased by one.
313 * \param[in] s the current serial number.
314 * \param[in] data the time in seconds since 1-1-1970 00:00
316 uint32_t ldns_soa_serial_datecounter(uint32_t s, void *data);
319 * Increment the serial number of the given SOA by one.
320 * \param[in] soa The soa rr to be incremented
322 void ldns_rr_soa_increment(
326 * Increment the serial number of the given SOA with the given function.
327 * Included functions to be used here are: ldns_rr_soa_increment,
328 * ldns_soa_serial_unixtime and ldns_soa_serial_datecounter.
329 * \param[in] soa The soa rr to be incremented
330 * \param[in] f the function to use to increment the soa rr.
332 void ldns_rr_soa_increment_func(
333 ldns_rr *soa, ldns_soa_serial_increment_func_t f);
336 * Increment the serial number of the given SOA with the given function
337 * passing it the given data argument.
338 * \param[in] soa The soa rr to be incremented
339 * \param[in] f the function to use to increment the soa rr.
340 * \param[in] data this argument will be passed to f as the second argument.
342 void ldns_rr_soa_increment_func_data(
343 ldns_rr *soa, ldns_soa_serial_increment_func_t f, void *data);
346 * Increment the serial number of the given SOA with the given function
347 * using data as an argument for the function.
348 * Included functions to be used here are: ldns_soa_serial_identity,
349 * ldns_rr_soa_increment_by, ldns_soa_serial_unixtime and
350 * ldns_soa_serial_datecounter.
351 * \param[in] soa The soa rr to be incremented
352 * \param[in] f the function to use to increment the soa rr.
353 * \param[in] data this argument will be passed to f as the second argument
354 * (by casting it to void*).
356 void ldns_rr_soa_increment_func_int(
357 ldns_rr *soa, ldns_soa_serial_increment_func_t f, int data);
363 #endif /* LDNS_RR_FUNCTIONS_H */