]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ldns/ldns/host2str.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ldns / ldns / host2str.h
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
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
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  * Represent a NULL pointer (instead of a pointer to a ldns_rr as "; (null)" 
44  * as opposed to outputting nothing at all in such a case.
45  */
46 /*      Flag Name                       Flag Nr.        Has data associated
47         ---------------------------------------------------------------------*/
48 #define LDNS_COMMENT_NULLS              (1 <<  0)
49 /** Show key id with DNSKEY RR's as comment */
50 #define LDNS_COMMENT_KEY_ID             (1 <<  1)
51 /** Show if a DNSKEY is a ZSK or KSK as comment */
52 #define LDNS_COMMENT_KEY_TYPE           (1 <<  2)
53 /** Show DNSKEY key size as comment */
54 #define LDNS_COMMENT_KEY_SIZE           (1 <<  3)
55 /** Provide bubblebabble representation for DS RR's as comment */
56 #define LDNS_COMMENT_BUBBLEBABBLE       (1 <<  4)
57 /** Show when a NSEC3 RR has the optout flag set as comment */
58 #define LDNS_COMMENT_FLAGS              (1 <<  5)
59 /** Show the unhashed owner and next owner names for NSEC3 RR's as comment */
60 #define LDNS_COMMENT_NSEC3_CHAIN        (1 <<  6)       /* yes */
61 /** Print mark up */
62 #define LDNS_COMMENT_LAYOUT             (1 <<  7)
63 /** Also comment KEY_ID with RRSIGS **/
64 #define LDNS_COMMENT_RRSIGS             (1 <<  8)
65 #define LDNS_FMT_ZEROIZE_RRSIGS         (1 <<  9)
66 #define LDNS_FMT_PAD_SOA_SERIAL         (1 << 10)
67 #define LDNS_FMT_RFC3597                (1 << 11)       /* yes */
68
69 #define LDNS_FMT_FLAGS_WITH_DATA                            2
70
71 /** Show key id, type and size as comment for DNSKEY RR's */
72 #define LDNS_COMMENT_KEY                (LDNS_COMMENT_KEY_ID  \
73                                         |LDNS_COMMENT_KEY_TYPE\
74                                         |LDNS_COMMENT_KEY_SIZE)
75
76 /**
77  * Output format specifier
78  *
79  * Determines how Packets, Resource Records and Resource record data fiels are
80  * formatted when printing or converting to string.
81  * Currently it is only used to specify what aspects of a Resource Record are
82  * annotated in the comment section of the textual representation the record.
83  * This is speciefed with flags and potential exra data (such as for example
84  * a lookup map of hashes to real names for annotation NSEC3 records).
85  */
86 struct ldns_struct_output_format
87 {
88         /** Specification of how RR's should be formatted in text */
89         int   flags;
90         /** Potential extra data to be used with formatting RR's in text */
91         void *data;
92 };
93 typedef struct ldns_struct_output_format ldns_output_format;
94
95 /**
96  * Output format struct with additional data for flags that use them.
97  * This struct may not be initialized directly. Use ldns_output_format_init
98  * to initialize.
99  */
100 struct ldns_struct_output_format_storage
101 {       int   flags;
102         ldns_rbtree_t* hashmap;    /* for LDNS_COMMENT_NSEC3_CHAIN */
103         ldns_rdf*      bitmap;     /* for LDNS_FMT_RFC3597     */
104 };
105 typedef struct ldns_struct_output_format_storage ldns_output_format_storage;
106
107 /**
108  * Standard output format record that disables commenting in the textual 
109  * representation of Resource Records completely.
110  */
111 extern const ldns_output_format *ldns_output_format_nocomments;
112 /**
113  * Standard output format record that annotated only DNSKEY RR's with commenti
114  * text.
115  */
116 extern const ldns_output_format *ldns_output_format_onlykeyids;
117 /**
118  * The default output format record. Same as ldns_output_format_onlykeyids.
119  */
120 extern const ldns_output_format *ldns_output_format_default;
121 /**
122  * Standard output format record that shows all DNSKEY related information in
123  * the comment text, plus the optout flag when set with NSEC3's, plus the
124  * bubblebabble representation of DS RR's.
125  */
126 extern const ldns_output_format *ldns_output_format_bubblebabble;
127
128 /**
129  * Initialize output format storage to the default value.
130  * \param[in] fmt A reference to an output_format_ storage struct
131  * \return The initialized storage struct typecasted to ldns_output_format
132  */
133 INLINE
134 ldns_output_format* ldns_output_format_init(ldns_output_format_storage* fmt) {
135         fmt->flags   = ldns_output_format_default->flags;
136         fmt->hashmap = NULL;
137         fmt->bitmap  = NULL;
138         return (ldns_output_format*)fmt;
139 }
140
141 /**
142  * Set an ouput format flag.
143  */
144 INLINE void ldns_output_format_set(ldns_output_format* fmt, int flag) {
145         fmt->flags |= flag;
146 }
147
148 /**
149  * Clear an ouput format flag.
150  */
151 INLINE void ldns_output_format_clear(ldns_output_format* fmt, int flag) {
152         fmt->flags &= !flag;
153 }
154
155 /**
156  * Makes sure the LDNS_FMT_RFC3597 is set in the output format.
157  * Marks the type to be printed in RFC3597 format.
158  * /param[in] fmt the output format to update
159  * /param[in] the type to be printed in RFC3597 format
160  * /return LDNS_STATUS_OK on success
161  */
162 ldns_status
163 ldns_output_format_set_type(ldns_output_format* fmt, ldns_rr_type type);
164
165 /**
166  * Makes sure the LDNS_FMT_RFC3597 is set in the output format.
167  * Marks the type to not be printed in RFC3597 format. When no other types
168  * have been marked before, all known types (except the given one) will be
169  * marked for printing in RFC3597 format.
170  * /param[in] fmt the output format to update
171  * /param[in] the type not to be printed in RFC3597 format
172  * /return LDNS_STATUS_OK on success
173  */
174 ldns_status
175 ldns_output_format_clear_type(ldns_output_format* fmt, ldns_rr_type type);
176
177 /**
178  * Converts an ldns packet opcode value to its mnemonic, and adds that
179  * to the output buffer
180  * \param[in] *output the buffer to add the data to
181  * \param[in] opcode to find the string representation of
182  * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
183  */
184 ldns_status
185 ldns_pkt_opcode2buffer_str(ldns_buffer *output, ldns_pkt_opcode opcode);
186
187 /**
188  * Converts an ldns packet rcode value to its mnemonic, and adds that
189  * to the output buffer
190  * \param[in] *output the buffer to add the data to
191  * \param[in] rcode to find the string representation of
192  * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
193  */
194 ldns_status
195 ldns_pkt_rcode2buffer_str(ldns_buffer *output, ldns_pkt_rcode rcode);
196
197 /**
198  * Converts an ldns algorithm type to its mnemonic, and adds that
199  * to the output buffer
200  * \param[in] *output the buffer to add the data to
201  * \param[in] algorithm to find the string representation of
202  * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
203  */
204 ldns_status
205 ldns_algorithm2buffer_str(ldns_buffer *output,
206                           ldns_algorithm algorithm);
207
208 /**
209  * Converts an ldns certificate algorithm type to its mnemonic, 
210  * and adds that to the output buffer
211  * \param[in] *output the buffer to add the data to
212  * \param[in] cert_algorithm to find the string representation of
213  * \return LDNS_STATUS_OK on success, or a buffer failure mode on error
214  */
215 ldns_status
216 ldns_cert_algorithm2buffer_str(ldns_buffer *output,
217                                ldns_cert_algorithm cert_algorithm);
218
219
220 /**
221  * Converts a packet opcode to its mnemonic and returns that as
222  * an allocated null-terminated string.
223  * Remember to free it.
224  *
225  * \param[in] opcode the opcode to convert to text
226  * \return null terminated char * data, or NULL on error
227  */
228 char *ldns_pkt_opcode2str(ldns_pkt_opcode opcode);
229
230 /**
231  * Converts a packet rcode to its mnemonic and returns that as
232  * an allocated null-terminated string.
233  * Remember to free it.
234  *
235  * \param[in] rcode the rcode to convert to text
236  * \return null terminated char * data, or NULL on error
237  */
238 char *ldns_pkt_rcode2str(ldns_pkt_rcode rcode);
239
240 /**
241  * Converts a signing algorithms to its mnemonic and returns that as
242  * an allocated null-terminated string.
243  * Remember to free it.
244  *
245  * \param[in] algorithm the algorithm to convert to text
246  * \return null terminated char * data, or NULL on error
247  */
248 char *ldns_pkt_algorithm2str(ldns_algorithm algorithm);
249
250 /**
251  * Converts a cert algorithm to its mnemonic and returns that as
252  * an allocated null-terminated string.
253  * Remember to free it.
254  *
255  * \param[in] cert_algorithm to convert to text
256  * \return null terminated char * data, or NULL on error
257  */
258 char *ldns_pkt_cert_algorithm2str(ldns_cert_algorithm cert_algorithm);
259
260 /** 
261  * Converts an LDNS_RDF_TYPE_A rdata element to string format and adds it to the output buffer 
262  * \param[in] *rdf The rdata to convert
263  * \param[in] *output The buffer to add the data to
264  * \return LDNS_STATUS_OK on success, and error status on failure
265  */
266 ldns_status ldns_rdf2buffer_str_a(ldns_buffer *output, const ldns_rdf *rdf);
267
268 /** 
269  * Converts an LDNS_RDF_TYPE_AAAA rdata element to string format and adds it to the output buffer 
270  * \param[in] *rdf The rdata to convert
271  * \param[in] *output The buffer to add the data to
272  * \return LDNS_STATUS_OK on success, and error status on failure
273  */
274 ldns_status ldns_rdf2buffer_str_aaaa(ldns_buffer *output, const ldns_rdf *rdf);
275
276 /** 
277  * Converts an LDNS_RDF_TYPE_STR rdata element to string format and adds it to the output buffer 
278  * \param[in] *rdf The rdata to convert
279  * \param[in] *output The buffer to add the data to
280  * \return LDNS_STATUS_OK on success, and error status on failure
281  */
282 ldns_status ldns_rdf2buffer_str_str(ldns_buffer *output, const ldns_rdf *rdf);
283
284 /** 
285  * Converts an LDNS_RDF_TYPE_B64 rdata element to string format and adds it to the output buffer 
286  * \param[in] *rdf The rdata to convert
287  * \param[in] *output The buffer to add the data to
288  * \return LDNS_STATUS_OK on success, and error status on failure
289  */
290 ldns_status ldns_rdf2buffer_str_b64(ldns_buffer *output, const ldns_rdf *rdf);
291
292 /** 
293  * Converts an LDNS_RDF_TYPE_B32_EXT rdata element to string format and adds it to the output buffer 
294  * \param[in] *rdf The rdata to convert
295  * \param[in] *output The buffer to add the data to
296  * \return LDNS_STATUS_OK on success, and error status on failure
297  */
298 ldns_status ldns_rdf2buffer_str_b32_ext(ldns_buffer *output, const ldns_rdf *rdf);
299
300 /** 
301  * Converts an LDNS_RDF_TYPE_HEX rdata element to string format and adds it to the output buffer 
302  * \param[in] *rdf The rdata to convert
303  * \param[in] *output The buffer to add the data to
304  * \return LDNS_STATUS_OK on success, and error status on failure
305  */
306 ldns_status ldns_rdf2buffer_str_hex(ldns_buffer *output, const ldns_rdf *rdf);
307
308 /** 
309  * Converts an LDNS_RDF_TYPE_TYPE rdata element to string format and adds it to the output buffer 
310  * \param[in] *rdf The rdata to convert
311  * \param[in] *output The buffer to add the data to
312  * \return LDNS_STATUS_OK on success, and error status on failure
313  */
314 ldns_status ldns_rdf2buffer_str_type(ldns_buffer *output, const ldns_rdf *rdf);
315
316 /** 
317  * Converts an LDNS_RDF_TYPE_CLASS rdata element to string format and adds it to the output buffer 
318  * \param[in] *rdf The rdata to convert
319  * \param[in] *output The buffer to add the data to
320  * \return LDNS_STATUS_OK on success, and error status on failure
321  */
322 ldns_status ldns_rdf2buffer_str_class(ldns_buffer *output, const ldns_rdf *rdf);
323
324 /** 
325  * Converts an LDNS_RDF_TYPE_ALG rdata element to string format and adds it to the output buffer 
326  * \param[in] *rdf The rdata to convert
327  * \param[in] *output The buffer to add the data to
328  * \return LDNS_STATUS_OK on success, and error status on failure
329  */
330 ldns_status ldns_rdf2buffer_str_alg(ldns_buffer *output, const ldns_rdf *rdf);
331
332 /**
333  * Converts an ldns_rr_type value to its string representation,
334  * and places it in the given buffer
335  * \param[in] *output The buffer to add the data to
336  * \param[in] type the ldns_rr_type to convert
337  * \return LDNS_STATUS_OK on success, and error status on failure
338  */
339 ldns_status ldns_rr_type2buffer_str(ldns_buffer *output,
340                                     const ldns_rr_type type);
341
342 /**
343  * Converts an ldns_rr_type value to its string representation,
344  * and returns that string. For unknown types, the string
345  * "TYPE<id>" is returned. This function allocates data that must be
346  * freed by the caller
347  * \param[in] type the ldns_rr_type to convert
348  * \return a newly allocated string
349  */
350 char *ldns_rr_type2str(const ldns_rr_type type);
351
352 /**
353  * Converts an ldns_rr_class value to its string representation,
354  * and places it in the given buffer
355  * \param[in] *output The buffer to add the data to
356  * \param[in] klass the ldns_rr_class to convert
357  * \return LDNS_STATUS_OK on success, and error status on failure
358  */
359 ldns_status ldns_rr_class2buffer_str(ldns_buffer *output,
360                                      const ldns_rr_class klass);
361
362 /**
363  * Converts an ldns_rr_class value to its string representation,
364  * and returns that string. For unknown types, the string
365  * "CLASS<id>" is returned. This function allocates data that must be
366  * freed by the caller
367  * \param[in] klass the ldns_rr_class to convert
368  * \return a newly allocated string
369  */
370 char *ldns_rr_class2str(const ldns_rr_class klass);
371
372
373 /** 
374  * Converts an LDNS_RDF_TYPE_CERT 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  */
379 ldns_status ldns_rdf2buffer_str_cert_alg(ldns_buffer *output, const ldns_rdf *rdf);
380
381 /** 
382  * Converts an LDNS_RDF_TYPE_LOC rdata element to string format and adds it to the output buffer 
383  * \param[in] *rdf The rdata to convert
384  * \param[in] *output The buffer to add the data to
385  * \return LDNS_STATUS_OK on success, and error status on failure
386  */
387 ldns_status ldns_rdf2buffer_str_loc(ldns_buffer *output, const ldns_rdf *rdf);
388
389 /** 
390  * Converts an LDNS_RDF_TYPE_UNKNOWN rdata element to string format and adds it to the output buffer 
391  * \param[in] *rdf The rdata to convert
392  * \param[in] *output The buffer to add the data to
393  * \return LDNS_STATUS_OK on success, and error status on failure
394  */
395 ldns_status ldns_rdf2buffer_str_unknown(ldns_buffer *output, const ldns_rdf *rdf);
396
397 /** 
398  * Converts an LDNS_RDF_TYPE_NSAP rdata element to string format and adds it to the output buffer 
399  * \param[in] *rdf The rdata to convert
400  * \param[in] *output The buffer to add the data to
401  * \return LDNS_STATUS_OK on success, and error status on failure
402  */
403 ldns_status ldns_rdf2buffer_str_nsap(ldns_buffer *output, const ldns_rdf *rdf);
404
405 /** 
406  * Converts an LDNS_RDF_TYPE_ATMA rdata element to string format and adds it to the output buffer 
407  * \param[in] *rdf The rdata to convert
408  * \param[in] *output The buffer to add the data to
409  * \return LDNS_STATUS_OK on success, and error status on failure
410  */
411 ldns_status ldns_rdf2buffer_str_atma(ldns_buffer *output, const ldns_rdf *rdf);
412
413 /** 
414  * Converts an LDNS_RDF_TYPE_WKS rdata element to string format and adds it to the output buffer 
415  * \param[in] *rdf The rdata to convert
416  * \param[in] *output The buffer to add the data to
417  * \return LDNS_STATUS_OK on success, and error status on failure
418  */
419 ldns_status ldns_rdf2buffer_str_wks(ldns_buffer *output, const ldns_rdf *rdf);
420
421 /** 
422  * Converts an LDNS_RDF_TYPE_NSEC rdata element to string format and adds it to the output buffer 
423  * \param[in] *rdf The rdata to convert
424  * \param[in] *output The buffer to add the data to
425  * \return LDNS_STATUS_OK on success, and error status on failure
426  */
427 ldns_status ldns_rdf2buffer_str_nsec(ldns_buffer *output, const ldns_rdf *rdf);
428
429 /** 
430  * Converts an LDNS_RDF_TYPE_PERIOD rdata element to string format and adds it to the output buffer 
431  * \param[in] *rdf The rdata to convert
432  * \param[in] *output The buffer to add the data to
433  * \return LDNS_STATUS_OK on success, and error status on failure
434  */
435 ldns_status ldns_rdf2buffer_str_period(ldns_buffer *output, const ldns_rdf *rdf);
436
437 /** 
438  * Converts an LDNS_RDF_TYPE_TSIGTIME rdata element to string format and adds it to the output buffer 
439  * \param[in] *rdf The rdata to convert
440  * \param[in] *output The buffer to add the data to
441  * \return LDNS_STATUS_OK on success, and error status on failure
442  */
443 ldns_status ldns_rdf2buffer_str_tsigtime(ldns_buffer *output, const ldns_rdf *rdf);
444
445 /** 
446  * Converts an LDNS_RDF_TYPE_APL rdata element to string format and adds it to the output buffer 
447  * \param[in] *rdf The rdata to convert
448  * \param[in] *output The buffer to add the data to
449  * \return LDNS_STATUS_OK on success, and error status on failure
450  */
451 ldns_status ldns_rdf2buffer_str_apl(ldns_buffer *output, const ldns_rdf *rdf);
452
453 /** 
454  * Converts an LDNS_RDF_TYPE_INT16_DATA rdata element to string format and adds it to the output buffer 
455  * \param[in] *rdf The rdata to convert
456  * \param[in] *output The buffer to add the data to
457  * \return LDNS_STATUS_OK on success, and error status on failure
458  */
459 ldns_status ldns_rdf2buffer_str_int16_data(ldns_buffer *output, const ldns_rdf *rdf);
460
461 /** 
462  * Converts an LDNS_RDF_TYPE_IPSECKEY rdata element to string format and adds it to the output buffer 
463  * \param[in] *rdf The rdata to convert
464  * \param[in] *output The buffer to add the data to
465  * \return LDNS_STATUS_OK on success, and error status on failure
466  */
467 ldns_status ldns_rdf2buffer_str_ipseckey(ldns_buffer *output, const ldns_rdf *rdf);
468
469 /**
470  * Converts the data in the rdata field to presentation
471  * format (as char *) and appends it to the given buffer
472  *
473  * \param[in] output pointer to the buffer to append the data to
474  * \param[in] rdf the pointer to the rdafa field containing the data
475  * \return status
476  */
477 ldns_status ldns_rdf2buffer_str(ldns_buffer *output, const ldns_rdf *rdf);
478
479 /**
480  * Converts the data in the resource record to presentation
481  * format (as char *) and appends it to the given buffer.
482  * The presentation format of DNSKEY record is annotated with comments giving
483  * the id, type and size of the key.
484  *
485  * \param[in] output pointer to the buffer to append the data to
486  * \param[in] rr the pointer to the rr field to convert
487  * \return status
488  */
489 ldns_status ldns_rr2buffer_str(ldns_buffer *output, const ldns_rr *rr);
490
491 /**
492  * Converts the data in the resource record to presentation
493  * format (as char *) and appends it to the given buffer.
494  * The presentation format is annotated with comments giving
495  * additional information on the record.
496  *
497  * \param[in] output pointer to the buffer to append the data to
498  * \param[in] fmt how to format the textual representation of the 
499  *            resource record.
500  * \param[in] rr the pointer to the rr field to convert
501  * \return status
502  */
503 ldns_status ldns_rr2buffer_str_fmt(ldns_buffer *output, 
504                 const ldns_output_format *fmt, const ldns_rr *rr);
505
506 /**
507  * Converts the data in the DNS packet to presentation
508  * format (as char *) and appends it to the given buffer
509  *
510  * \param[in] output pointer to the buffer to append the data to
511  * \param[in] pkt the pointer to the packet to convert
512  * \return status
513  */
514 ldns_status ldns_pkt2buffer_str(ldns_buffer *output, const ldns_pkt *pkt);
515
516 /**
517  * Converts the data in the DNS packet to presentation
518  * format (as char *) and appends it to the given buffer
519  *
520  * \param[in] output pointer to the buffer to append the data to
521  * \param[in] fmt how to format the textual representation of the packet
522  * \param[in] pkt the pointer to the packet to convert
523  * \return status
524  */
525 ldns_status ldns_pkt2buffer_str_fmt(ldns_buffer *output,
526                 const ldns_output_format *fmt, const ldns_pkt *pkt);
527
528 /** 
529  * Converts an LDNS_RDF_TYPE_NSEC3_SALT rdata element to string format and adds it to the output buffer 
530  * \param[in] *rdf The rdata to convert
531  * \param[in] *output The buffer to add the data to
532  * \return LDNS_STATUS_OK on success, and error status on failure
533  */
534 ldns_status ldns_rdf2buffer_str_nsec3_salt(ldns_buffer *output, const ldns_rdf *rdf);
535
536
537 /**
538  * Converts the data in the DNS packet to presentation
539  * format (as char *) and appends it to the given buffer
540  *
541  * \param[in] output pointer to the buffer to append the data to
542  * \param[in] k the pointer to the private key to convert
543  * \return status
544  */
545 ldns_status ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k);
546
547 /**
548  * Converts an LDNS_RDF_TYPE_INT8 rdata element to string format and adds it to the output buffer
549  * \param[in] *rdf The rdata to convert
550  * \param[in] *output The buffer to add the data to
551  * \return LDNS_STATUS_OK on success, and error status on failure
552  */
553 ldns_status ldns_rdf2buffer_str_int8(ldns_buffer *output, const ldns_rdf *rdf);
554
555 /**
556  * Converts an LDNS_RDF_TYPE_INT16 rdata element to string format and adds it to the output buffer
557  * \param[in] *rdf The rdata to convert
558  * \param[in] *output The buffer to add the data to
559  * \return LDNS_STATUS_OK on success, and error status on failure
560  */
561 ldns_status ldns_rdf2buffer_str_int16(ldns_buffer *output, const ldns_rdf *rdf);
562
563 /**
564  * Converts an LDNS_RDF_TYPE_INT32 rdata element to string format and adds it to the output buffer
565  * \param[in] *rdf The rdata to convert
566  * \param[in] *output The buffer to add the data to
567  * \return LDNS_STATUS_OK on success, and error status on failure
568  */
569 ldns_status ldns_rdf2buffer_str_int32(ldns_buffer *output, const ldns_rdf *rdf);
570
571 /**
572  * Converts an LDNS_RDF_TYPE_TIME rdata element to string format and adds it to the output buffer
573  * \param[in] *rdf The rdata to convert
574  * \param[in] *output The buffer to add the data to
575  * \return LDNS_STATUS_OK on success, and error status on failure
576  */
577 ldns_status ldns_rdf2buffer_str_time(ldns_buffer *output, const ldns_rdf *rdf);
578
579 /** 
580  * Converts an LDNS_RDF_TYPE_ILNP64 rdata element to 4 hexadecimal numbers
581  * separated by colons and adds it to the output buffer 
582  * \param[in] *rdf The rdata to convert
583  * \param[in] *output The buffer to add the data to
584  * \return LDNS_STATUS_OK on success, and error status on failure
585  */
586 ldns_status ldns_rdf2buffer_str_ilnp64(ldns_buffer *output,
587                 const ldns_rdf *rdf);
588
589 /** 
590  * Converts an LDNS_RDF_TYPE_EUI48 rdata element to 6 hexadecimal numbers
591  * separated by dashes and adds it to the output buffer 
592  * \param[in] *rdf The rdata to convert
593  * \param[in] *output The buffer to add the data to
594  * \return LDNS_STATUS_OK on success, and error status on failure
595  */
596 ldns_status ldns_rdf2buffer_str_eui48(ldns_buffer *output,
597                 const ldns_rdf *rdf);
598
599 /** 
600  * Converts an LDNS_RDF_TYPE_EUI64 rdata element to 8 hexadecimal numbers
601  * separated by dashes and adds it to the output buffer 
602  * \param[in] *rdf The rdata to convert
603  * \param[in] *output The buffer to add the data to
604  * \return LDNS_STATUS_OK on success, and error status on failure
605  */
606 ldns_status ldns_rdf2buffer_str_eui64(ldns_buffer *output,
607                 const ldns_rdf *rdf);
608
609 /** 
610  * Adds the LDNS_RDF_TYPE_TAG rdata to the output buffer,
611  * provided it contains only alphanumeric characters.
612  * \param[in] *rdf The rdata to convert
613  * \param[in] *output The buffer to add the data to
614  * \return LDNS_STATUS_OK on success, and error status on failure
615  */
616 ldns_status ldns_rdf2buffer_str_tag(ldns_buffer *output,
617                 const ldns_rdf *rdf);
618
619 /** 
620  * Adds the LDNS_RDF_TYPE_LONG_STR rdata to the output buffer, in-between 
621  * double quotes and all non printable characters properly escaped.
622  * \param[in] *rdf The rdata to convert
623  * \param[in] *output The buffer to add the data to
624  * \return LDNS_STATUS_OK on success, and error status on failure
625  */
626 ldns_status ldns_rdf2buffer_str_long_str(ldns_buffer *output,
627                 const ldns_rdf *rdf);
628
629 /** 
630  * Converts an LDNS_RDF_TYPE_HIP rdata element to presentation format for
631  * the algorithm, HIT and Public Key and adds it the output buffer .
632  * \param[in] *rdf The rdata to convert
633  * \param[in] *output The buffer to add the data to
634  * \return LDNS_STATUS_OK on success, and error status on failure
635  */
636 ldns_status ldns_rdf2buffer_str_hip(ldns_buffer *output,
637                 const ldns_rdf *rdf);
638
639 /**
640  * Converts the data in the rdata field to presentation format and
641  * returns that as a char *.
642  * Remember to free it.
643  *
644  * \param[in] rdf The rdata field to convert
645  * \return null terminated char * data, or NULL on error
646  */
647 char *ldns_rdf2str(const ldns_rdf *rdf);
648
649 /**
650  * Converts the data in the resource record to presentation format and
651  * returns that as a char *.
652  * Remember to free it.
653  *
654  * \param[in] rr The rdata field to convert
655  * \return null terminated char * data, or NULL on error
656  */
657 char *ldns_rr2str(const ldns_rr *rr);
658
659 /**
660  * Converts the data in the resource record to presentation format and
661  * returns that as a char *.
662  * Remember to free it.
663  *
664  * \param[in] fmt how to format the resource record
665  * \param[in] rr The rdata field to convert
666  * \return null terminated char * data, or NULL on error
667  */
668 char *ldns_rr2str_fmt(const ldns_output_format *fmt, const ldns_rr *rr);
669
670 /**
671  * Converts the data in the DNS packet to presentation format and
672  * returns that as a char *.
673  * Remember to free it.
674  *
675  * \param[in] pkt The rdata field to convert
676  * \return null terminated char * data, or NULL on error
677  */
678 char *ldns_pkt2str(const ldns_pkt *pkt);
679
680 /**
681  * Converts the data in the DNS packet to presentation format and
682  * returns that as a char *.
683  * Remember to free it.
684  *
685  * \param[in] fmt how to format the packet
686  * \param[in] pkt The rdata field to convert
687  * \return null terminated char * data, or NULL on error
688  */
689 char *ldns_pkt2str_fmt(const ldns_output_format *fmt, const ldns_pkt *pkt);
690
691 /**
692  * Converts a private key to the test presentation fmt and
693  * returns that as a char *.
694  * Remember to free it.
695  *
696  * \param[in] k the key to convert to text
697  * \return null terminated char * data, or NULL on error
698  */
699 char *ldns_key2str(const ldns_key *k);
700
701 /**
702  * Converts a list of resource records to presentation format
703  * and returns that as a char *.
704  * Remember to free it.
705  *
706  * \param[in] rr_list the rr_list to convert to text
707  * \return null terminated char * data, or NULL on error
708  */
709 char *ldns_rr_list2str(const ldns_rr_list *rr_list);
710
711 /**
712  * Converts a list of resource records to presentation format
713  * and returns that as a char *.
714  * Remember to free it.
715  *
716  * \param[in] fmt how to format the list of resource records
717  * \param[in] rr_list the rr_list to convert to text
718  * \return null terminated char * data, or NULL on error
719  */
720 char *ldns_rr_list2str_fmt(
721                 const ldns_output_format *fmt, const ldns_rr_list *rr_list);
722
723 /**
724  * Returns a copy of the data in the buffer as a null terminated
725  * char * string. The returned string must be freed by the caller.
726  * The buffer must be in write modus and may thus not have been flipped.
727  *
728  * \param[in] buffer buffer containing char * data
729  * \return null terminated char * data, or NULL on error
730  */
731 char *ldns_buffer2str(ldns_buffer *buffer);
732
733 /**
734  * Exports and returns the data in the buffer as a null terminated
735  * char * string. The returned string must be freed by the caller.
736  * The buffer must be in write modus and may thus not have been flipped.
737  * The buffer is fixed after this function returns.
738  *
739  * \param[in] buffer buffer containing char * data
740  * \return null terminated char * data, or NULL on error
741  */
742 char *ldns_buffer_export2str(ldns_buffer *buffer);
743
744 /**
745  * Prints the data in the rdata field to the given file stream
746  * (in presentation format)
747  *
748  * \param[in] output the file stream to print to
749  * \param[in] rdf the rdata field to print
750  * \return void
751  */
752 void ldns_rdf_print(FILE *output, const ldns_rdf *rdf);
753
754 /**
755  * Prints the data in the resource record to the given file stream
756  * (in presentation format)
757  *
758  * \param[in] output the file stream to print to
759  * \param[in] rr the resource record to print
760  * \return void
761  */
762 void ldns_rr_print(FILE *output, const ldns_rr *rr);
763
764 /**
765  * Prints the data in the resource record to the given file stream
766  * (in presentation format)
767  *
768  * \param[in] output the file stream to print to
769  * \param[in] fmt format of the textual representation
770  * \param[in] rr the resource record to print
771  * \return void
772  */
773 void ldns_rr_print_fmt(FILE *output, 
774                 const ldns_output_format *fmt, const ldns_rr *rr);
775
776 /**
777  * Prints the data in the DNS packet to the given file stream
778  * (in presentation format)
779  *
780  * \param[in] output the file stream to print to
781  * \param[in] pkt the packet to print
782  * \return void
783  */
784 void ldns_pkt_print(FILE *output, const ldns_pkt *pkt);
785
786 /**
787  * Prints the data in the DNS packet to the given file stream
788  * (in presentation format)
789  *
790  * \param[in] output the file stream to print to
791  * \param[in] fmt format of the textual representation
792  * \param[in] pkt the packet to print
793  * \return void
794  */
795 void ldns_pkt_print_fmt(FILE *output, 
796                 const ldns_output_format *fmt, const ldns_pkt *pkt);
797
798 /**
799  * Converts a rr_list to presentation format and appends it to
800  * the output buffer
801  * \param[in] output the buffer to append output to
802  * \param[in] list the ldns_rr_list to print
803  * \return ldns_status
804  */
805 ldns_status ldns_rr_list2buffer_str(ldns_buffer *output, const ldns_rr_list *list);
806
807 /**
808  * Converts a rr_list to presentation format and appends it to
809  * the output buffer
810  * \param[in] output the buffer to append output to
811  * \param[in] fmt format of the textual representation
812  * \param[in] list the ldns_rr_list to print
813  * \return ldns_status
814  */
815 ldns_status ldns_rr_list2buffer_str_fmt(ldns_buffer *output, 
816                 const ldns_output_format *fmt, const ldns_rr_list *list);
817
818 /**
819  * Converts the header of a packet to presentation format and appends it to
820  * the output buffer
821  * \param[in] output the buffer to append output to
822  * \param[in] pkt the packet to convert the header of
823  * \return ldns_status
824  */
825 ldns_status ldns_pktheader2buffer_str(ldns_buffer *output, const ldns_pkt *pkt);
826
827 /**
828  * print a rr_list to output
829  * \param[in] output the fd to print to
830  * \param[in] list the rr_list to print
831  */
832 void ldns_rr_list_print(FILE *output, const ldns_rr_list *list);
833
834 /**
835  * print a rr_list to output
836  * \param[in] output the fd to print to
837  * \param[in] fmt format of the textual representation
838  * \param[in] list the rr_list to print
839  */
840 void ldns_rr_list_print_fmt(FILE *output, 
841                 const ldns_output_format *fmt, const ldns_rr_list *list);
842
843 /**
844  * Print a resolver (in sofar that is possible) state
845  * to output.
846  * \param[in] output the fd to print to
847  * \param[in] r the resolver to print
848  */
849 void ldns_resolver_print(FILE *output, const ldns_resolver *r);
850
851 /**
852  * Print a resolver (in sofar that is possible) state
853  * to output.
854  * \param[in] output the fd to print to
855  * \param[in] fmt format of the textual representation
856  * \param[in] r the resolver to print
857  */
858 void ldns_resolver_print_fmt(FILE *output, 
859                 const ldns_output_format *fmt, const ldns_resolver *r);
860
861 /**
862  * Print a zone structure * to output. Note the SOA record
863  * is included in this output
864  * \param[in] output the fd to print to
865  * \param[in] z the zone to print
866  */
867 void ldns_zone_print(FILE *output, const ldns_zone *z);
868
869 /**
870  * Print a zone structure * to output. Note the SOA record
871  * is included in this output
872  * \param[in] output the fd to print to
873  * \param[in] fmt format of the textual representation
874  * \param[in] z the zone to print
875  */
876 void ldns_zone_print_fmt(FILE *output, 
877                 const ldns_output_format *fmt, const ldns_zone *z);
878
879 /**
880  * Print the ldns_rdf containing a dname to the buffer
881  * \param[in] output the buffer to print to
882  * \param[in] dname the dname to print
883  * \return ldns_status message if the printing succeeded
884  */
885 ldns_status ldns_rdf2buffer_str_dname(ldns_buffer *output, const ldns_rdf *dname);
886
887 #ifdef __cplusplus
888 }
889 #endif
890
891 #endif /* LDNS_HOST2STR_H */