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