Update to ldns-1.6.7
[dragonfly.git] / contrib / ldns / ldns / host2wire.h
1 /*
2  * host2wire.h - 2wire conversion routines
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 all functions to translate the main structures to wire format
15  */
16
17 #ifndef LDNS_HOST2WIRE_H
18 #define LDNS_HOST2WIRE_H
19
20 #include <ldns/common.h>
21 #include <ldns/error.h>
22 #include <ldns/rr.h>
23 #include <ldns/rdata.h>
24 #include <ldns/packet.h>
25 #include <ldns/buffer.h>
26 #include <ctype.h>
27
28 #include "ldns/util.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /**
35  * Copies the dname data to the buffer in wire format
36  * \param[out] *buffer buffer to append the result to
37  * \param[in] *name rdata dname to convert
38  * \return ldns_status
39  */
40 ldns_status ldns_dname2buffer_wire(ldns_buffer *buffer, const ldns_rdf *name);
41
42 /**
43  * Copies the rdata data to the buffer in wire format
44  * \param[out] *output buffer to append the result to
45  * \param[in] *rdf rdata to convert
46  * \return ldns_status
47  */
48 ldns_status ldns_rdf2buffer_wire(ldns_buffer *output, const ldns_rdf *rdf);
49
50 /**
51  * Copies the rdata data to the buffer in wire format
52  * If the rdata is a dname, the letters will be lowercased
53  * during the conversion
54  * \param[out] *output buffer to append the result to
55  * \param[in] *rdf rdata to convert
56  * \return ldns_status
57  */
58 ldns_status ldns_rdf2buffer_wire_canonical(ldns_buffer *output,
59                                                                    const ldns_rdf *rdf);
60
61 /**
62  * Copies the rr data to the buffer in wire format
63  * \param[out] *output buffer to append the result to
64  * \param[in] *rr resource record to convert
65  * \param[in] section the section in the packet this rr is supposed to be in
66  *            (to determine whether to add rdata or not)
67  * \return ldns_status
68  */
69 ldns_status ldns_rr2buffer_wire(ldns_buffer *output,
70                                                   const ldns_rr *rr,
71                                                   int section);
72
73 /**
74  * Copies the rr data to the buffer in wire format, in canonical format
75  * according to RFC3597 (every dname in rdata fields of RR's mentioned in
76  * that RFC will be lowercased)
77  * \param[out] *output buffer to append the result to
78  * \param[in] *rr resource record to convert
79  * \param[in] section the section in the packet this rr is supposed to be in
80  *            (to determine whether to add rdata or not)
81  * \return ldns_status
82  */
83 ldns_status ldns_rr2buffer_wire_canonical(ldns_buffer *output,
84                                                                   const ldns_rr *rr,
85                                                                   int section);
86
87
88 /**
89  * Converts a rrsig to wireformat BUT EXCLUDE the rrsig rdata
90  * This is needed in DNSSEC verification
91  * \param[out] output buffer to append the result to
92  * \param[in] sigrr signature rr to operate on
93  * \return ldns_status
94  */
95 ldns_status ldns_rrsig2buffer_wire(ldns_buffer *output, const ldns_rr *sigrr);
96
97 /**
98  * Converts an rr's rdata to wireformat, while excluding
99  * the ownername and all the stuff before the rdata.
100  * This is needed in DNSSEC keytag calculation, the ds
101  * calcalution from the key and maybe elsewhere.
102  *
103  * \param[out] *output buffer where to put the result
104  * \param[in] *rr rr to operate on
105  * \return ldns_status
106  */
107 ldns_status ldns_rr_rdata2buffer_wire(ldns_buffer *output, const ldns_rr *rr);
108
109 /**
110  * Copies the packet data to the buffer in wire format
111  * \param[out] *output buffer to append the result to
112  * \param[in] *pkt packet to convert
113  * \return ldns_status
114  */
115 ldns_status ldns_pkt2buffer_wire(ldns_buffer *output, const ldns_pkt *pkt);
116
117 /**
118  * Copies the rr_list data to the buffer in wire format
119  * \param[out] *output buffer to append the result to
120  * \param[in] *rrlist rr_list to to convert
121  * \return ldns_status
122  */
123 ldns_status ldns_rr_list2buffer_wire(ldns_buffer *output, const ldns_rr_list *rrlist);
124
125 /**
126  * Allocates an array of uint8_t at dest, and puts the wireformat of the
127  * given rdf in that array. The result_size value contains the
128  * length of the array, if it succeeds, and 0 otherwise (in which case
129  * the function also returns NULL)
130  *
131  * \param[out] dest pointer to the array of bytes to be created
132  * \param[in] rdf the rdata field to convert
133  * \param[out] size the size of the converted result
134  */
135 ldns_status ldns_rdf2wire(uint8_t **dest, const ldns_rdf *rdf, size_t *size);
136
137 /**
138  * Allocates an array of uint8_t at dest, and puts the wireformat of the
139  * given rr in that array. The result_size value contains the
140  * length of the array, if it succeeds, and 0 otherwise (in which case
141  * the function also returns NULL)
142  *
143  * If the section argument is LDNS_SECTION_QUESTION, data like ttl and rdata
144  * are not put into the result
145  *
146  * \param[out] dest pointer to the array of bytes to be created
147  * \param[in] rr the rr to convert
148  * \param[out] size the size of the converted result
149  */
150 ldns_status ldns_rr2wire(uint8_t **dest, const ldns_rr *rr, int, size_t *size);
151
152 /**
153  * Allocates an array of uint8_t at dest, and puts the wireformat of the
154  * given packet in that array. The result_size value contains the
155  * length of the array, if it succeeds, and 0 otherwise (in which case
156  * the function also returns NULL)
157  */
158 ldns_status ldns_pkt2wire(uint8_t **dest, const ldns_pkt *p, size_t *size);
159
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif /* LDNS_HOST2WIRE_H */