Update to ldns-1.6.7
[dragonfly.git] / contrib / ldns / ldns / host2str.h
CommitLineData
825eb42b
JL
1/**
2 * host2str.h - txt presentation of RRs
3 *
4 * a Net::DNS like library for C
5 *
6 * (c) NLnet Labs, 2005-2006
7 *
8 * See the file LICENSE for the license
9 */
10
11/**
12 * \file
13 *
14 * Contains functions to translate the main structures to their text
15 * representation, as well as functions to print them.
16 */
17
18#ifndef LDNS_HOST2STR_H
19#define LDNS_HOST2STR_H
20
21#include <ldns/common.h>
22#include <ldns/error.h>
23#include <ldns/rr.h>
24#include <ldns/rdata.h>
25#include <ldns/packet.h>
26#include <ldns/buffer.h>
27#include <ldns/resolver.h>
28#include <ldns/zone.h>
29#include <ctype.h>
30
31#include "ldns/util.h"
32
ac996e71
JL
33#ifdef __cplusplus
34extern "C" {
35#endif
36
825eb42b
JL
37#define LDNS_APL_IP4 1
38#define LDNS_APL_IP6 2
39#define LDNS_APL_MASK 0x7f
40#define LDNS_APL_NEGATION 0x80
41
42/**
43 * Converts an ldns packet opcode value to its mnemonic, and adds that
44 * to the output buffer
45 * \param[in] *output the buffer to add the data to
46 * \param[in] opcode to find the string representation of
47 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
48 */
49ldns_status
50ldns_pkt_opcode2buffer_str(ldns_buffer *output, ldns_pkt_opcode opcode);
51
52/**
53 * Converts an ldns packet rcode value to its mnemonic, and adds that
54 * to the output buffer
55 * \param[in] *output the buffer to add the data to
56 * \param[in] rcode to find the string representation of
57 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
58 */
59ldns_status
60ldns_pkt_rcode2buffer_str(ldns_buffer *output, ldns_pkt_rcode rcode);
61
62/**
63 * Converts an ldns algorithm type to its mnemonic, and adds that
64 * to the output buffer
65 * \param[in] *output the buffer to add the data to
66 * \param[in] algorithm to find the string representation of
67 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
68 */
69ldns_status
70ldns_algorithm2buffer_str(ldns_buffer *output,
71 ldns_algorithm algorithm);
72
73/**
74 * Converts an ldns certificate algorithm type to its mnemonic,
75 * and adds that to the output buffer
76 * \param[in] *output the buffer to add the data to
77 * \param[in] cert_algorithm to find the string representation of
78 * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
79 */
80ldns_status
81ldns_cert_algorithm2buffer_str(ldns_buffer *output,
82 ldns_cert_algorithm cert_algorithm);
83
84
85/**
86 * Converts a packet opcode to its mnemonic and returns that as
87 * an allocated null-terminated string.
88 * Remember to free it.
89 *
90 * \param[in] opcode the opcode to convert to text
91 * \return null terminated char * data, or NULL on error
92 */
93char *ldns_pkt_opcode2str(ldns_pkt_opcode opcode);
94
95/**
96 * Converts a packet rcode to its mnemonic and returns that as
97 * an allocated null-terminated string.
98 * Remember to free it.
99 *
100 * \param[in] rcode the rcode to convert to text
101 * \return null terminated char * data, or NULL on error
102 */
103char *ldns_pkt_rcode2str(ldns_pkt_rcode rcode);
104
105/**
106 * Converts a signing algorithms to its mnemonic and returns that as
107 * an allocated null-terminated string.
108 * Remember to free it.
109 *
110 * \param[in] algorithm the algorithm to convert to text
111 * \return null terminated char * data, or NULL on error
112 */
113char *ldns_pkt_algorithm2str(ldns_algorithm algorithm);
114
115/**
116 * Converts a cert algorithm to its mnemonic and returns that as
117 * an allocated null-terminated string.
118 * Remember to free it.
119 *
120 * \param[in] cert_algorithm to convert to text
121 * \return null terminated char * data, or NULL on error
122 */
123char *ldns_pkt_cert_algorithm2str(ldns_cert_algorithm cert_algorithm);
124
125/**
126 * Converts an LDNS_RDF_TYPE_A rdata element to string format and adds it to the output buffer
127 * \param[in] *rdf The rdata to convert
128 * \param[in] *output The buffer to add the data to
129 * \return LDNS_STATUS_OK on success, and error status on failure
130 */
131ldns_status ldns_rdf2buffer_str_a(ldns_buffer *output, const ldns_rdf *rdf);
132
133/**
134 * Converts an LDNS_RDF_TYPE_AAAA rdata element to string format and adds it to the output buffer
135 * \param[in] *rdf The rdata to convert
136 * \param[in] *output The buffer to add the data to
137 * \return LDNS_STATUS_OK on success, and error status on failure
138 */
139ldns_status ldns_rdf2buffer_str_aaaa(ldns_buffer *output, const ldns_rdf *rdf);
140
141/**
142 * Converts an LDNS_RDF_TYPE_STR rdata element to string format and adds it to the output buffer
143 * \param[in] *rdf The rdata to convert
144 * \param[in] *output The buffer to add the data to
145 * \return LDNS_STATUS_OK on success, and error status on failure
146 */
147ldns_status ldns_rdf2buffer_str_str(ldns_buffer *output, const ldns_rdf *rdf);
148
149/**
150 * Converts an LDNS_RDF_TYPE_B64 rdata element to string format and adds it to the output buffer
151 * \param[in] *rdf The rdata to convert
152 * \param[in] *output The buffer to add the data to
153 * \return LDNS_STATUS_OK on success, and error status on failure
154 */
155ldns_status ldns_rdf2buffer_str_b64(ldns_buffer *output, const ldns_rdf *rdf);
156
ac996e71
JL
157/**
158 * Converts an LDNS_RDF_TYPE_B32_EXT rdata element to string format and adds it to the output buffer
159 * \param[in] *rdf The rdata to convert
160 * \param[in] *output The buffer to add the data to
161 * \return LDNS_STATUS_OK on success, and error status on failure
162 */
163ldns_status ldns_rdf2buffer_str_b32_ext(ldns_buffer *output, const ldns_rdf *rdf);
164
825eb42b
JL
165/**
166 * Converts an LDNS_RDF_TYPE_HEX rdata element to string format and adds it to the output buffer
167 * \param[in] *rdf The rdata to convert
168 * \param[in] *output The buffer to add the data to
169 * \return LDNS_STATUS_OK on success, and error status on failure
170 */
171ldns_status ldns_rdf2buffer_str_hex(ldns_buffer *output, const ldns_rdf *rdf);
172
173/**
174 * Converts an LDNS_RDF_TYPE_TYPE rdata element to string format and adds it to the output buffer
175 * \param[in] *rdf The rdata to convert
176 * \param[in] *output The buffer to add the data to
177 * \return LDNS_STATUS_OK on success, and error status on failure
178 */
179ldns_status ldns_rdf2buffer_str_type(ldns_buffer *output, const ldns_rdf *rdf);
180
181/**
182 * Converts an LDNS_RDF_TYPE_CLASS rdata element to string format and adds it to the output buffer
183 * \param[in] *rdf The rdata to convert
184 * \param[in] *output The buffer to add the data to
185 * \return LDNS_STATUS_OK on success, and error status on failure
186 */
187ldns_status ldns_rdf2buffer_str_class(ldns_buffer *output, const ldns_rdf *rdf);
188
189/**
190 * Converts an LDNS_RDF_TYPE_ALG rdata element to string format and adds it to the output buffer
191 * \param[in] *rdf The rdata to convert
192 * \param[in] *output The buffer to add the data to
193 * \return LDNS_STATUS_OK on success, and error status on failure
194 */
195ldns_status ldns_rdf2buffer_str_alg(ldns_buffer *output, const ldns_rdf *rdf);
196
197/**
198 * Converts an ldns_rr_type value to its string representation,
199 * and places it in the given buffer
200 * \param[in] *output The buffer to add the data to
201 * \param[in] type the ldns_rr_type to convert
202 * \return LDNS_STATUS_OK on success, and error status on failure
203 */
204ldns_status ldns_rr_type2buffer_str(ldns_buffer *output,
205 const ldns_rr_type type);
206
207/**
208 * Converts an ldns_rr_type value to its string representation,
209 * and returns that string. For unknown types, the string
210 * "TYPE<id>" is returned. This function allocates data that must be
211 * freed by the caller
212 * \param[in] type the ldns_rr_type to convert
213 * \return a newly allocated string
214 */
215char *ldns_rr_type2str(const ldns_rr_type type);
216
217/**
218 * Converts an ldns_rr_class value to its string representation,
219 * and places it in the given buffer
220 * \param[in] *output The buffer to add the data to
221 * \param[in] klass the ldns_rr_class to convert
222 * \return LDNS_STATUS_OK on success, and error status on failure
223 */
224ldns_status ldns_rr_class2buffer_str(ldns_buffer *output,
225 const ldns_rr_class klass);
226
227/**
228 * Converts an ldns_rr_class value to its string representation,
229 * and returns that string. For unknown types, the string
230 * "CLASS<id>" is returned. This function allocates data that must be
231 * freed by the caller
232 * \param[in] klass the ldns_rr_class to convert
233 * \return a newly allocated string
234 */
235char *ldns_rr_class2str(const ldns_rr_class klass);
236
237
238/**
239 * Converts an LDNS_RDF_TYPE_CERT rdata element to string format and adds it to the output buffer
240 * \param[in] *rdf The rdata to convert
241 * \param[in] *output The buffer to add the data to
242 * \return LDNS_STATUS_OK on success, and error status on failure
243 */
244ldns_status ldns_rdf2buffer_str_cert_alg(ldns_buffer *output, const ldns_rdf *rdf);
245
246/**
247 * Converts an LDNS_RDF_TYPE_LOC rdata element to string format and adds it to the output buffer
248 * \param[in] *rdf The rdata to convert
249 * \param[in] *output The buffer to add the data to
250 * \return LDNS_STATUS_OK on success, and error status on failure
251 */
252ldns_status ldns_rdf2buffer_str_loc(ldns_buffer *output, const ldns_rdf *rdf);
253
254/**
255 * Converts an LDNS_RDF_TYPE_UNKNOWN rdata element to string format and adds it to the output buffer
256 * \param[in] *rdf The rdata to convert
257 * \param[in] *output The buffer to add the data to
258 * \return LDNS_STATUS_OK on success, and error status on failure
259 */
260ldns_status ldns_rdf2buffer_str_unknown(ldns_buffer *output, const ldns_rdf *rdf);
261
262/**
263 * Converts an LDNS_RDF_TYPE_NSAP rdata element to string format and adds it to the output buffer
264 * \param[in] *rdf The rdata to convert
265 * \param[in] *output The buffer to add the data to
266 * \return LDNS_STATUS_OK on success, and error status on failure
267 */
268ldns_status ldns_rdf2buffer_str_nsap(ldns_buffer *output, const ldns_rdf *rdf);
269
ac996e71
JL
270/**
271 * Converts an LDNS_RDF_TYPE_ATMA rdata element to string format and adds it to the output buffer
272 * \param[in] *rdf The rdata to convert
273 * \param[in] *output The buffer to add the data to
274 * \return LDNS_STATUS_OK on success, and error status on failure
275 */
276ldns_status ldns_rdf2buffer_str_atma(ldns_buffer *output, const ldns_rdf *rdf);
277
825eb42b
JL
278/**
279 * Converts an LDNS_RDF_TYPE_WKS rdata element to string format and adds it to the output buffer
280 * \param[in] *rdf The rdata to convert
281 * \param[in] *output The buffer to add the data to
282 * \return LDNS_STATUS_OK on success, and error status on failure
283 */
284ldns_status ldns_rdf2buffer_str_wks(ldns_buffer *output, const ldns_rdf *rdf);
285
286/**
287 * Converts an LDNS_RDF_TYPE_NSEC rdata element to string format and adds it to the output buffer
288 * \param[in] *rdf The rdata to convert
289 * \param[in] *output The buffer to add the data to
290 * \return LDNS_STATUS_OK on success, and error status on failure
291 */
292ldns_status ldns_rdf2buffer_str_nsec(ldns_buffer *output, const ldns_rdf *rdf);
293
294/**
295 * Converts an LDNS_RDF_TYPE_PERIOD rdata element to string format and adds it to the output buffer
296 * \param[in] *rdf The rdata to convert
297 * \param[in] *output The buffer to add the data to
298 * \return LDNS_STATUS_OK on success, and error status on failure
299 */
300ldns_status ldns_rdf2buffer_str_period(ldns_buffer *output, const ldns_rdf *rdf);
301
302/**
303 * Converts an LDNS_RDF_TYPE_TSIGTIME rdata element to string format and adds it to the output buffer
304 * \param[in] *rdf The rdata to convert
305 * \param[in] *output The buffer to add the data to
306 * \return LDNS_STATUS_OK on success, and error status on failure
307 */
308ldns_status ldns_rdf2buffer_str_tsigtime(ldns_buffer *output, const ldns_rdf *rdf);
309
310/**
311 * Converts an LDNS_RDF_TYPE_APL rdata element to string format and adds it to the output buffer
312 * \param[in] *rdf The rdata to convert
313 * \param[in] *output The buffer to add the data to
314 * \return LDNS_STATUS_OK on success, and error status on failure
315 */
316ldns_status ldns_rdf2buffer_str_apl(ldns_buffer *output, const ldns_rdf *rdf);
317
318/**
319 * Converts an LDNS_RDF_TYPE_INT16_DATA rdata element to string format and adds it to the output buffer
320 * \param[in] *rdf The rdata to convert
321 * \param[in] *output The buffer to add the data to
322 * \return LDNS_STATUS_OK on success, and error status on failure
323 */
324ldns_status ldns_rdf2buffer_str_int16_data(ldns_buffer *output, const ldns_rdf *rdf);
325
326/**
327 * Converts an LDNS_RDF_TYPE_IPSECKEY rdata element to string format and adds it to the output buffer
328 * \param[in] *rdf The rdata to convert
329 * \param[in] *output The buffer to add the data to
330 * \return LDNS_STATUS_OK on success, and error status on failure
331 */
332ldns_status ldns_rdf2buffer_str_ipseckey(ldns_buffer *output, const ldns_rdf *rdf);
333
334/**
335 * Converts an LDNS_RDF_TYPE_TSIG rdata element to string format and adds it to the output buffer
336 * \param[in] *rdf The rdata to convert
337 * \param[in] *output The buffer to add the data to
338 * \return LDNS_STATUS_OK on success, and error status on failure
339 */
340ldns_status ldns_rdf2buffer_str_tsig(ldns_buffer *output, const ldns_rdf *rdf);
341
342
343/**
344 * Converts the data in the rdata field to presentation
345 * format (as char *) and appends it to the given buffer
346 *
347 * \param[in] output pointer to the buffer to append the data to
348 * \param[in] rdf the pointer to the rdafa field containing the data
349 * \return status
350 */
351ldns_status ldns_rdf2buffer_str(ldns_buffer *output, const ldns_rdf *rdf);
352
353/**
354 * Converts the data in the resource record to presentation
355 * format (as char *) and appends it to the given buffer
356 *
357 * \param[in] output pointer to the buffer to append the data to
358 * \param[in] rr the pointer to the rr field to convert
359 * \return status
360 */
361ldns_status ldns_rr2buffer_str(ldns_buffer *output, const ldns_rr *rr);
362
363/**
364 * Converts the data in the DNS packet to presentation
365 * format (as char *) and appends it to the given buffer
366 *
367 * \param[in] output pointer to the buffer to append the data to
368 * \param[in] pkt the pointer to the packet to convert
369 * \return status
370 */
371ldns_status ldns_pkt2buffer_str(ldns_buffer *output, const ldns_pkt *pkt);
372
ac996e71
JL
373/**
374 * Converts an LDNS_RDF_TYPE_NSEC3_SALT rdata element to string format and adds it to the output buffer
375 * \param[in] *rdf The rdata to convert
376 * \param[in] *output The buffer to add the data to
377 * \return LDNS_STATUS_OK on success, and error status on failure
378 */
379ldns_status ldns_rdf2buffer_str_nsec3_salt(ldns_buffer *output, const ldns_rdf *rdf);
380
381
825eb42b
JL
382/**
383 * Converts the data in the DNS packet to presentation
384 * format (as char *) and appends it to the given buffer
385 *
386 * \param[in] output pointer to the buffer to append the data to
387 * \param[in] k the pointer to the private key to convert
388 * \return status
389 */
390ldns_status ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k);
391
392/**
ac996e71
JL
393 * Converts an LDNS_RDF_TYPE_INT8 rdata element to string format and adds it to the output buffer
394 * \param[in] *rdf The rdata to convert
395 * \param[in] *output The buffer to add the data to
396 * \return LDNS_STATUS_OK on success, and error status on failure
397 */
398ldns_status ldns_rdf2buffer_str_int8(ldns_buffer *output, const ldns_rdf *rdf);
399
400/**
401 * Converts an LDNS_RDF_TYPE_INT16 rdata element to string format and adds it to the output buffer
402 * \param[in] *rdf The rdata to convert
403 * \param[in] *output The buffer to add the data to
404 * \return LDNS_STATUS_OK on success, and error status on failure
825eb42b
JL
405 */
406ldns_status ldns_rdf2buffer_str_int16(ldns_buffer *output, const ldns_rdf *rdf);
407
ac996e71
JL
408/**
409 * Converts an LDNS_RDF_TYPE_INT32 rdata element to string format and adds it to the output buffer
410 * \param[in] *rdf The rdata to convert
411 * \param[in] *output The buffer to add the data to
412 * \return LDNS_STATUS_OK on success, and error status on failure
413 */
414ldns_status ldns_rdf2buffer_str_int32(ldns_buffer *output, const ldns_rdf *rdf);
415
416/**
417 * Converts an LDNS_RDF_TYPE_TIME rdata element to string format and adds it to the output buffer
418 * \param[in] *rdf The rdata to convert
419 * \param[in] *output The buffer to add the data to
420 * \return LDNS_STATUS_OK on success, and error status on failure
421 */
422ldns_status ldns_rdf2buffer_str_time(ldns_buffer *output, const ldns_rdf *rdf);
423
825eb42b
JL
424/**
425 * Converts the data in the rdata field to presentation format and
426 * returns that as a char *.
427 * Remember to free it.
428 *
429 * \param[in] rdf The rdata field to convert
430 * \return null terminated char * data, or NULL on error
431 */
432char *ldns_rdf2str(const ldns_rdf *rdf);
433
434/**
435 * Converts the data in the resource record to presentation format and
436 * returns that as a char *.
437 * Remember to free it.
438 *
439 * \param[in] rr The rdata field to convert
440 * \return null terminated char * data, or NULL on error
441 */
442char *ldns_rr2str(const ldns_rr *rr);
443
444/**
445 * Converts the data in the DNS packet to presentation format and
446 * returns that as a char *.
447 * Remember to free it.
448 *
449 * \param[in] pkt The rdata field to convert
450 * \return null terminated char * data, or NULL on error
451 */
452char *ldns_pkt2str(const ldns_pkt *pkt);
453
454/**
455 * Converts a private key to the test presentation fmt and
456 * returns that as a char *.
457 * Remember to free it.
458 *
459 * \param[in] k the key to convert to text
460 * \return null terminated char * data, or NULL on error
461 */
462char *ldns_key2str(const ldns_key *k);
463
464/**
465 * Converts a list of resource records to presentation format
466 * and returns that as a char *.
467 * Remember to free it.
468 *
469 * \param[in] rr_list the rr_list to convert to text
470 * \return null terminated char * data, or NULL on error
471 */
472char *ldns_rr_list2str(const ldns_rr_list *rr_list);
473
474/**
475 * Returns the data in the buffer as a null terminated char * string
476 * Buffer data must be char * type, and must be freed by the caller
477 *
478 * \param[in] buffer buffer containing char * data
479 * \return null terminated char * data, or NULL on error
480 */
481char *ldns_buffer2str(ldns_buffer *buffer);
482
483/**
484 * Prints the data in the rdata field to the given file stream
485 * (in presentation format)
486 *
487 * \param[in] output the file stream to print to
488 * \param[in] rdf the rdata field to print
489 * \return void
490 */
491void ldns_rdf_print(FILE *output, const ldns_rdf *rdf);
492
493/**
494 * Prints the data in the resource record to the given file stream
495 * (in presentation format)
496 *
497 * \param[in] output the file stream to print to
498 * \param[in] rr the resource record to print
499 * \return void
500 */
501void ldns_rr_print(FILE *output, const ldns_rr *rr);
502
503/**
504 * Prints the data in the DNS packet to the given file stream
505 * (in presentation format)
506 *
507 * \param[in] output the file stream to print to
508 * \param[in] pkt the packet to print
509 * \return void
510 */
511void ldns_pkt_print(FILE *output, const ldns_pkt *pkt);
512
513/**
514 * Converts a rr_list to presentation format and appends it to
515 * the output buffer
516 * \param[in] output the buffer to append output to
517 * \param[in] list the ldns_rr_list to print
518 * \return ldns_status
519 */
520ldns_status ldns_rr_list2buffer_str(ldns_buffer *output, const ldns_rr_list *list);
521
522/**
523 * Converts the header of a packet to presentation format and appends it to
524 * the output buffer
525 * \param[in] output the buffer to append output to
526 * \param[in] pkt the packet to convert the header of
527 * \return ldns_status
528 */
529ldns_status ldns_pktheader2buffer_str(ldns_buffer *output, const ldns_pkt *pkt);
530
531/**
532 * print a rr_list to output
533 * param[in] output the fd to print to
534 * param[in] list the rr_list to print
535 */
536void ldns_rr_list_print(FILE *output, const ldns_rr_list *list);
537
538/**
539 * Print a resolver (in sofar that is possible) state
540 * to output.
541 * \param[in] output the fd to print to
542 * \param[in] r the resolver to print
543 */
544void ldns_resolver_print(FILE *output, const ldns_resolver *r);
545
546/**
547 * Print a zone structure * to output. Note the SOA record
548 * is included in this output
549 * \param[in] output the fd to print to
550 * \param[in] z the zone to print
551 */
552void ldns_zone_print(FILE *output, const ldns_zone *z);
553
554/**
555 * Print the ldns_rdf containing a dname to the buffer
556 * \param[in] output the buffer to print to
557 * \param[in] dname the dname to print
558 * \return ldns_status message if the printing succeeded
559 */
560ldns_status ldns_rdf2buffer_str_dname(ldns_buffer *output, const ldns_rdf *dname);
561
ac996e71
JL
562#ifdef __cplusplus
563}
564#endif
825eb42b
JL
565
566#endif /* LDNS_HOST2STR_H */