1266077Sdes/**
2266077Sdes * str2wire.h -  read txt presentation of RRs
3266077Sdes *
4266077Sdes * (c) NLnet Labs, 2005-2006
5266077Sdes *
6266077Sdes * See the file LICENSE for the license
7266077Sdes */
8266077Sdes
9266077Sdes/**
10266077Sdes * \file
11266077Sdes *
12266077Sdes * Parses text to wireformat.
13266077Sdes */
14266077Sdes
15266077Sdes#ifndef LDNS_STR2WIRE_H
16266077Sdes#define LDNS_STR2WIRE_H
17266077Sdes
18266077Sdes/* include rrdef for MAX_DOMAINLEN constant */
19287915Sdes#include <sldns/rrdef.h>
20266077Sdes
21266077Sdes#ifdef __cplusplus
22266077Sdesextern "C" {
23266077Sdes#endif
24266077Sdesstruct sldns_struct_lookup_table;
25266077Sdes
26266077Sdes/** buffer to read an RR, cannot be larger than 64K because of packet size */
27266077Sdes#define LDNS_RR_BUF_SIZE 65535 /* bytes */
28266077Sdes#define LDNS_DEFAULT_TTL	3600
29266077Sdes
30266077Sdes/*
31266077Sdes * To convert class and type to string see
32266077Sdes * sldns_get_rr_class_by_name(str)
33266077Sdes * sldns_get_rr_type_by_name(str)
34266077Sdes * from rrdef.h
35266077Sdes */
36266077Sdes
37266077Sdes/**
38266077Sdes * Convert text string into dname wireformat, mallocless, with user buffer.
39266077Sdes * @param str: the text string with the domain name.
40266077Sdes * @param buf: the result buffer, suggested size LDNS_MAX_DOMAINLEN+1
41266077Sdes * @param len: length of the buffer on input, length of the result on output.
42266077Sdes * @return 0 on success, otherwise an error.
43266077Sdes */
44266077Sdesint sldns_str2wire_dname_buf(const char* str, uint8_t* buf, size_t* len);
45266077Sdes
46266077Sdes/**
47266077Sdes * Same as sldns_str2wire_dname_buf, but concatenates origin if the domain
48266077Sdes * name is relative (does not end in '.').
49266077Sdes * @param str: the text string with the domain name.
50266077Sdes * @param buf: the result buffer, suggested size LDNS_MAX_DOMAINLEN+1
51266077Sdes * @param len: length of the buffer on input, length of the result on output.
52266077Sdes * @param origin: the origin to append or NULL (nothing is appended).
53266077Sdes * @param origin_len: length of origin.
54266077Sdes * @return 0 on success, otherwise an error.
55266077Sdes */
56266077Sdesint sldns_str2wire_dname_buf_origin(const char* str, uint8_t* buf, size_t* len,
57266077Sdes	uint8_t* origin, size_t origin_len);
58266077Sdes
59266077Sdes/**
60266077Sdes * Convert text string into dname wireformat
61266077Sdes * @param str: the text string with the domain name.
62266077Sdes * @param len: returned length of wireformat.
63266077Sdes * @return wireformat dname (malloced) or NULL on failure.
64266077Sdes */
65266077Sdesuint8_t* sldns_str2wire_dname(const char* str, size_t* len);
66266077Sdes
67266077Sdes/**
68266077Sdes * Convert text RR to wireformat, with user buffer.
69266077Sdes * @param str: the RR data in text presentation format.
70266077Sdes * @param rr: the buffer where the result is stored into.  This buffer has
71266077Sdes * 	the wire-dname(uncompressed), type, class, ttl, rdatalen, rdata.
72266077Sdes * 	These values are probably not aligned, and in network format.
73266077Sdes * 	Use the sldns_wirerr_get_xxx functions to access them safely.
74266077Sdes * 	buffer size LDNS_RR_BUF_SIZE is suggested.
75266077Sdes * @param len: on input the length of the buffer, on output the amount of
76266077Sdes * 	the buffer used for the rr.
77266077Sdes * @param dname_len: if non-NULL, filled with the dname length as result.
78266077Sdes * 	Because after the dname you find the type, class, ttl, rdatalen, rdata.
79266077Sdes * @param default_ttl: TTL used if no TTL available.
80266077Sdes * @param origin: used for origin dname (if not NULL)
81266077Sdes * @param origin_len: length of origin.
82266077Sdes * @param prev: used for prev_rr dname (if not NULL)
83266077Sdes * @param prev_len: length of prev.
84266077Sdes * @return 0 on success, an error on failure.
85266077Sdes */
86266077Sdesint sldns_str2wire_rr_buf(const char* str, uint8_t* rr, size_t* len,
87266077Sdes	size_t* dname_len, uint32_t default_ttl, uint8_t* origin,
88266077Sdes	size_t origin_len, uint8_t* prev, size_t prev_len);
89266077Sdes
90266077Sdes/**
91266077Sdes * Same as sldns_str2wire_rr_buf, but there is no rdata, it returns an RR
92266077Sdes * with zero rdata and no ttl.  It has name, type, class.
93266077Sdes * You can access those with the sldns_wirerr_get_type and class functions.
94266077Sdes * @param str: the RR data in text presentation format.
95266077Sdes * @param rr: the buffer where the result is stored into.
96266077Sdes * @param len: on input the length of the buffer, on output the amount of
97266077Sdes * 	the buffer used for the rr.
98266077Sdes * @param dname_len: if non-NULL, filled with the dname length as result.
99266077Sdes * 	Because after the dname you find the type, class, ttl, rdatalen, rdata.
100266077Sdes * @param origin: used for origin dname (if not NULL)
101266077Sdes * @param origin_len: length of origin.
102266077Sdes * @param prev: used for prev_rr dname (if not NULL)
103266077Sdes * @param prev_len: length of prev.
104266077Sdes * @return 0 on success, an error on failure.
105266077Sdes */
106266077Sdesint sldns_str2wire_rr_question_buf(const char* str, uint8_t* rr, size_t* len,
107266077Sdes	size_t* dname_len, uint8_t* origin, size_t origin_len, uint8_t* prev,
108266077Sdes	size_t prev_len);
109266077Sdes
110266077Sdes/**
111266077Sdes * Get the type of the RR.
112266077Sdes * @param rr: the RR in wire format.
113266077Sdes * @param len: rr length.
114266077Sdes * @param dname_len: dname length to skip.
115266077Sdes * @return type in host byteorder
116266077Sdes */
117266077Sdesuint16_t sldns_wirerr_get_type(uint8_t* rr, size_t len, size_t dname_len);
118266077Sdes
119266077Sdes/**
120266077Sdes * Get the class of the RR.
121266077Sdes * @param rr: the RR in wire format.
122266077Sdes * @param len: rr length.
123266077Sdes * @param dname_len: dname length to skip.
124266077Sdes * @return class in host byteorder
125266077Sdes */
126266077Sdesuint16_t sldns_wirerr_get_class(uint8_t* rr, size_t len, size_t dname_len);
127266077Sdes
128266077Sdes/**
129266077Sdes * Get the ttl of the RR.
130266077Sdes * @param rr: the RR in wire format.
131266077Sdes * @param len: rr length.
132266077Sdes * @param dname_len: dname length to skip.
133266077Sdes * @return ttl in host byteorder
134266077Sdes */
135266077Sdesuint32_t sldns_wirerr_get_ttl(uint8_t* rr, size_t len, size_t dname_len);
136266077Sdes
137266077Sdes/**
138266077Sdes * Get the rdata length of the RR.
139266077Sdes * @param rr: the RR in wire format.
140266077Sdes * @param len: rr length.
141266077Sdes * @param dname_len: dname length to skip.
142266077Sdes * @return rdata length in host byteorder
143266077Sdes * 	If the rdata length is larger than the rr-len allows, it is truncated.
144266077Sdes * 	So, that it is safe to read the data length returned
145266077Sdes * 	from this function from the rdata pointer of sldns_wirerr_get_rdata.
146266077Sdes */
147266077Sdesuint16_t sldns_wirerr_get_rdatalen(uint8_t* rr, size_t len, size_t dname_len);
148266077Sdes
149266077Sdes/**
150266077Sdes * Get the rdata pointer of the RR.
151266077Sdes * @param rr: the RR in wire format.
152266077Sdes * @param len: rr length.
153266077Sdes * @param dname_len: dname length to skip.
154266077Sdes * @return rdata pointer
155266077Sdes */
156266077Sdesuint8_t* sldns_wirerr_get_rdata(uint8_t* rr, size_t len, size_t dname_len);
157266077Sdes
158266077Sdes/**
159266077Sdes * Get the rdata pointer of the RR. prefixed with rdata length.
160266077Sdes * @param rr: the RR in wire format.
161266077Sdes * @param len: rr length.
162266077Sdes * @param dname_len: dname length to skip.
163266077Sdes * @return pointer to rdatalength, followed by the rdata.
164266077Sdes */
165266077Sdesuint8_t* sldns_wirerr_get_rdatawl(uint8_t* rr, size_t len, size_t dname_len);
166266077Sdes
167266077Sdes/**
168266077Sdes * Parse result codes
169266077Sdes */
170266077Sdes#define LDNS_WIREPARSE_MASK 0x0fff
171266077Sdes#define LDNS_WIREPARSE_SHIFT 12
172266077Sdes#define LDNS_WIREPARSE_ERROR(e) ((e)&LDNS_WIREPARSE_MASK)
173266077Sdes#define LDNS_WIREPARSE_OFFSET(e) (((e)&~LDNS_WIREPARSE_MASK)>>LDNS_WIREPARSE_SHIFT)
174266077Sdes/* use lookuptable to get error string, sldns_wireparse_errors */
175266077Sdes#define LDNS_WIREPARSE_ERR_OK 0
176266077Sdes#define LDNS_WIREPARSE_ERR_GENERAL 342
177266077Sdes#define LDNS_WIREPARSE_ERR_DOMAINNAME_OVERFLOW 343
178266077Sdes#define LDNS_WIREPARSE_ERR_DOMAINNAME_UNDERFLOW 344
179266077Sdes#define LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL 345
180266077Sdes#define LDNS_WIREPARSE_ERR_LABEL_OVERFLOW 346
181266077Sdes#define LDNS_WIREPARSE_ERR_EMPTY_LABEL 347
182266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_BAD_ESCAPE 348
183266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX 349
184266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_TTL 350
185266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_TYPE 351
186266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_CLASS 352
187266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_RDATA 353
188266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_MISSING_VALUE 354
189266077Sdes#define LDNS_WIREPARSE_ERR_INVALID_STR 355
190266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_B64 356
191266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_B32_EXT 357
192266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_HEX 358
193266077Sdes#define LDNS_WIREPARSE_ERR_CERT_BAD_ALGORITHM 359
194266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_TIME 360
195266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_PERIOD 361
196266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_ILNP64 362
197266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_EUI48 363
198266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_EUI64 364
199266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_TAG 365
200266077Sdes#define LDNS_WIREPARSE_ERR_NOT_IMPL 366
201266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_INT 367
202266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_IP4 368
203266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_IP6 369
204266077Sdes#define LDNS_WIREPARSE_ERR_SYNTAX_INTEGER_OVERFLOW 370
205266077Sdes#define LDNS_WIREPARSE_ERR_INCLUDE 371
206266077Sdes#define LDNS_WIREPARSE_ERR_PARENTHESIS 372
207266077Sdes
208266077Sdes/**
209266077Sdes * Get reference to a constant string for the (parse) error.
210266077Sdes * @param e: error return value
211266077Sdes * @return string.
212266077Sdes */
213266077Sdesconst char* sldns_get_errorstr_parse(int e);
214266077Sdes
215266077Sdes/**
216266077Sdes * wire parse state for parsing files
217266077Sdes */
218266077Sdesstruct sldns_file_parse_state {
219266077Sdes	/** the origin domain name, if len!=0. uncompressed wireformat */
220266077Sdes	uint8_t origin[LDNS_MAX_DOMAINLEN+1];
221266077Sdes	/** length of origin domain name, in bytes. 0 if not set. */
222266077Sdes	size_t origin_len;
223266077Sdes	/** the previous domain name, if len!=0. uncompressed wireformat*/
224266077Sdes	uint8_t prev_rr[LDNS_MAX_DOMAINLEN+1];
225266077Sdes	/** length of the previous domain name, in bytes. 0 if not set. */
226266077Sdes	size_t prev_rr_len;
227266077Sdes	/** default TTL, this is used if the text does not specify a TTL,
228266077Sdes	 * host byteorder */
229266077Sdes	uint32_t default_ttl;
230266077Sdes	/** line number information */
231266077Sdes	int lineno;
232266077Sdes};
233266077Sdes
234266077Sdes/**
235266077Sdes * Read one RR from zonefile with buffer for the data.
236266077Sdes * @param in: file that is read from (one RR, multiple lines if it spans them).
237266077Sdes * @param rr: this is malloced by the user and the result is stored here,
238266077Sdes * 	if an RR is read.  If no RR is read this is signalled with the
239266077Sdes * 	return len set to 0 (for ORIGIN, TTL directives).
240356345Scy * 	The read line is available in the rr_buf (zero terminated), for
241356345Scy * 	$DIRECTIVE style elements.
242266077Sdes * @param len: on input, the length of the rr buffer.  on output the rr len.
243266077Sdes * 	Buffer size of 64k should be enough.
244266077Sdes * @param dname_len: returns the length of the dname initial part of the rr.
245266077Sdes * @param parse_state: pass a pointer to user-allocated struct.
246266077Sdes * 	Contents are maintained by this function.
247266077Sdes * 	If you pass NULL then ORIGIN and TTL directives are not honored.
248266077Sdes * 	You can start out with a particular origin by pre-filling it.
249266077Sdes * 	otherwise, zero the structure before passing it.
250266077Sdes * 	lineno is incremented when a newline is passed by the parser,
251266077Sdes * 	you should initialize it at 1 at the start of the file.
252266077Sdes * @return 0 on success, error on failure.
253266077Sdes */
254266077Sdesint sldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len,
255266077Sdes	struct sldns_file_parse_state* parse_state);
256266077Sdes
257266077Sdes/**
258266077Sdes * Convert one rdf in rdata to wireformat and parse from string.
259266077Sdes * @param str: the text to convert for this rdata element.
260266077Sdes * @param rd: rdata buffer for the wireformat.
261266077Sdes * @param len: length of rd buffer on input, used length on output.
262266077Sdes * @param rdftype: the type of the rdf.
263266077Sdes * @return 0 on success, error on failure.
264266077Sdes */
265266077Sdesint sldns_str2wire_rdf_buf(const char* str, uint8_t* rd, size_t* len,
266266077Sdes	sldns_rdf_type rdftype);
267266077Sdes
268266077Sdes/**
269266077Sdes * Convert rdf of type LDNS_RDF_TYPE_INT8 from string to wireformat.
270266077Sdes * @param str: the text to convert for this rdata element.
271266077Sdes * @param rd: rdata buffer for the wireformat.
272266077Sdes * @param len: length of rd buffer on input, used length on output.
273266077Sdes * @return 0 on success, error on failure.
274266077Sdes */
275266077Sdesint sldns_str2wire_int8_buf(const char* str, uint8_t* rd, size_t* len);
276266077Sdes
277266077Sdes/**
278266077Sdes * Convert rdf of type LDNS_RDF_TYPE_INT16 from string to wireformat.
279266077Sdes * @param str: the text to convert for this rdata element.
280266077Sdes * @param rd: rdata buffer for the wireformat.
281266077Sdes * @param len: length of rd buffer on input, used length on output.
282266077Sdes * @return 0 on success, error on failure.
283266077Sdes */
284266077Sdesint sldns_str2wire_int16_buf(const char* str, uint8_t* rd, size_t* len);
285266077Sdes
286266077Sdes/**
287266077Sdes * Convert rdf of type LDNS_RDF_TYPE_INT32 from string to wireformat.
288266077Sdes * @param str: the text to convert for this rdata element.
289266077Sdes * @param rd: rdata buffer for the wireformat.
290266077Sdes * @param len: length of rd buffer on input, used length on output.
291266077Sdes * @return 0 on success, error on failure.
292266077Sdes */
293266077Sdesint sldns_str2wire_int32_buf(const char* str, uint8_t* rd, size_t* len);
294266077Sdes
295266077Sdes/**
296266077Sdes * Convert rdf of type LDNS_RDF_TYPE_A from string to wireformat.
297266077Sdes * @param str: the text to convert for this rdata element.
298266077Sdes * @param rd: rdata buffer for the wireformat.
299266077Sdes * @param len: length of rd buffer on input, used length on output.
300266077Sdes * @return 0 on success, error on failure.
301266077Sdes */
302266077Sdesint sldns_str2wire_a_buf(const char* str, uint8_t* rd, size_t* len);
303266077Sdes
304266077Sdes/**
305266077Sdes * Convert rdf of type LDNS_RDF_TYPE_AAAA from string to wireformat.
306266077Sdes * @param str: the text to convert for this rdata element.
307266077Sdes * @param rd: rdata buffer for the wireformat.
308266077Sdes * @param len: length of rd buffer on input, used length on output.
309266077Sdes * @return 0 on success, error on failure.
310266077Sdes */
311266077Sdesint sldns_str2wire_aaaa_buf(const char* str, uint8_t* rd, size_t* len);
312266077Sdes
313266077Sdes/**
314266077Sdes * Convert rdf of type LDNS_RDF_TYPE_STR from string to wireformat.
315266077Sdes * @param str: the text to convert for this rdata element.
316266077Sdes * @param rd: rdata buffer for the wireformat.
317266077Sdes * @param len: length of rd buffer on input, used length on output.
318266077Sdes * @return 0 on success, error on failure.
319266077Sdes */
320266077Sdesint sldns_str2wire_str_buf(const char* str, uint8_t* rd, size_t* len);
321266077Sdes
322266077Sdes/**
323266077Sdes * Convert rdf of type LDNS_RDF_TYPE_APL from string to wireformat.
324266077Sdes * @param str: the text to convert for this rdata element.
325266077Sdes * @param rd: rdata buffer for the wireformat.
326266077Sdes * @param len: length of rd buffer on input, used length on output.
327266077Sdes * @return 0 on success, error on failure.
328266077Sdes */
329266077Sdesint sldns_str2wire_apl_buf(const char* str, uint8_t* rd, size_t* len);
330266077Sdes
331266077Sdes/**
332266077Sdes * Convert rdf of type LDNS_RDF_TYPE_B64 from string to wireformat.
333266077Sdes * @param str: the text to convert for this rdata element.
334266077Sdes * @param rd: rdata buffer for the wireformat.
335266077Sdes * @param len: length of rd buffer on input, used length on output.
336266077Sdes * @return 0 on success, error on failure.
337266077Sdes */
338266077Sdesint sldns_str2wire_b64_buf(const char* str, uint8_t* rd, size_t* len);
339266077Sdes
340266077Sdes/**
341266077Sdes * Convert rdf of type LDNS_RDF_TYPE_B32_EXT from string to wireformat.
342266077Sdes * And also LDNS_RDF_TYPE_NSEC3_NEXT_OWNER.
343266077Sdes * @param str: the text to convert for this rdata element.
344266077Sdes * @param rd: rdata buffer for the wireformat.
345266077Sdes * @param len: length of rd buffer on input, used length on output.
346266077Sdes * @return 0 on success, error on failure.
347266077Sdes */
348266077Sdesint sldns_str2wire_b32_ext_buf(const char* str, uint8_t* rd, size_t* len);
349266077Sdes
350266077Sdes/**
351266077Sdes * Convert rdf of type LDNS_RDF_TYPE_HEX from string to wireformat.
352266077Sdes * @param str: the text to convert for this rdata element.
353266077Sdes * @param rd: rdata buffer for the wireformat.
354266077Sdes * @param len: length of rd buffer on input, used length on output.
355266077Sdes * @return 0 on success, error on failure.
356266077Sdes */
357266077Sdesint sldns_str2wire_hex_buf(const char* str, uint8_t* rd, size_t* len);
358266077Sdes
359266077Sdes/**
360266077Sdes * Convert rdf of type LDNS_RDF_TYPE_NSEC from string to wireformat.
361266077Sdes * @param str: the text to convert for this rdata element.
362266077Sdes * @param rd: rdata buffer for the wireformat.
363266077Sdes * @param len: length of rd buffer on input, used length on output.
364266077Sdes * @return 0 on success, error on failure.
365266077Sdes */
366266077Sdesint sldns_str2wire_nsec_buf(const char* str, uint8_t* rd, size_t* len);
367266077Sdes
368266077Sdes/**
369266077Sdes * Convert rdf of type LDNS_RDF_TYPE_TYPE from string to wireformat.
370266077Sdes * @param str: the text to convert for this rdata element.
371266077Sdes * @param rd: rdata buffer for the wireformat.
372266077Sdes * @param len: length of rd buffer on input, used length on output.
373266077Sdes * @return 0 on success, error on failure.
374266077Sdes */
375266077Sdesint sldns_str2wire_type_buf(const char* str, uint8_t* rd, size_t* len);
376266077Sdes
377266077Sdes/**
378266077Sdes * Convert rdf of type LDNS_RDF_TYPE_CLASS from string to wireformat.
379266077Sdes * @param str: the text to convert for this rdata element.
380266077Sdes * @param rd: rdata buffer for the wireformat.
381266077Sdes * @param len: length of rd buffer on input, used length on output.
382266077Sdes * @return 0 on success, error on failure.
383266077Sdes */
384266077Sdesint sldns_str2wire_class_buf(const char* str, uint8_t* rd, size_t* len);
385266077Sdes
386266077Sdes/**
387266077Sdes * Convert rdf of type LDNS_RDF_TYPE_CERT_ALG from string to wireformat.
388266077Sdes * @param str: the text to convert for this rdata element.
389266077Sdes * @param rd: rdata buffer for the wireformat.
390266077Sdes * @param len: length of rd buffer on input, used length on output.
391266077Sdes * @return 0 on success, error on failure.
392266077Sdes */
393266077Sdesint sldns_str2wire_cert_alg_buf(const char* str, uint8_t* rd, size_t* len);
394266077Sdes
395266077Sdes/**
396266077Sdes * Convert rdf of type LDNS_RDF_TYPE_ALG from string to wireformat.
397266077Sdes * @param str: the text to convert for this rdata element.
398266077Sdes * @param rd: rdata buffer for the wireformat.
399266077Sdes * @param len: length of rd buffer on input, used length on output.
400266077Sdes * @return 0 on success, error on failure.
401266077Sdes */
402266077Sdesint sldns_str2wire_alg_buf(const char* str, uint8_t* rd, size_t* len);
403266077Sdes
404266077Sdes/**
405266077Sdes * Convert rdf of type LDNS_RDF_TYPE_TIME from string to wireformat.
406266077Sdes * @param str: the text to convert for this rdata element.
407266077Sdes * @param rd: rdata buffer for the wireformat.
408266077Sdes * @param len: length of rd buffer on input, used length on output.
409266077Sdes * @return 0 on success, error on failure.
410266077Sdes */
411266077Sdesint sldns_str2wire_time_buf(const char* str, uint8_t* rd, size_t* len);
412266077Sdes
413266077Sdes/**
414266077Sdes * Convert rdf of type LDNS_RDF_TYPE_PERIOD from string to wireformat.
415266077Sdes * @param str: the text to convert for this rdata element.
416266077Sdes * @param rd: rdata buffer for the wireformat.
417266077Sdes * @param len: length of rd buffer on input, used length on output.
418266077Sdes * @return 0 on success, error on failure.
419266077Sdes */
420266077Sdesint sldns_str2wire_period_buf(const char* str, uint8_t* rd, size_t* len);
421266077Sdes
422266077Sdes/**
423356345Scy * Convert rdf of type LDNS_RDF_TYPE_TSIGTIME from string to wireformat.
424356345Scy * @param str: the text to convert for this rdata element.
425356345Scy * @param rd: rdata buffer for the wireformat.
426356345Scy * @param len: length of rd buffer on input, used length on output.
427356345Scy * @return 0 on success, error on failure.
428356345Scy */
429356345Scyint sldns_str2wire_tsigtime_buf(const char* str, uint8_t* rd, size_t* len);
430356345Scy
431356345Scy/**
432356345Scy * Convert rdf of type LDNS_RDF_TYPE_TSIGERROR from string to wireformat.
433356345Scy * @param str: the text to convert for this rdata element.
434356345Scy * @param rd: rdata buffer for the wireformat.
435356345Scy * @param len: length of rd buffer on input, used length on output.
436356345Scy * @return 0 on success, error on failure.
437356345Scy */
438356345Scyint sldns_str2wire_tsigerror_buf(const char* str, uint8_t* rd, size_t* len);
439356345Scy
440356345Scy/**
441266077Sdes * Convert rdf of type LDNS_RDF_TYPE_LOC from string to wireformat.
442266077Sdes * @param str: the text to convert for this rdata element.
443266077Sdes * @param rd: rdata buffer for the wireformat.
444266077Sdes * @param len: length of rd buffer on input, used length on output.
445266077Sdes * @return 0 on success, error on failure.
446266077Sdes */
447266077Sdesint sldns_str2wire_loc_buf(const char* str, uint8_t* rd, size_t* len);
448266077Sdes
449266077Sdes/**
450266077Sdes * Convert rdf of type LDNS_RDF_TYPE_WKS from string to wireformat.
451266077Sdes * @param str: the text to convert for this rdata element.
452266077Sdes * @param rd: rdata buffer for the wireformat.
453266077Sdes * @param len: length of rd buffer on input, used length on output.
454266077Sdes * @return 0 on success, error on failure.
455266077Sdes */
456266077Sdesint sldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len);
457266077Sdes
458266077Sdes/**
459266077Sdes * Convert rdf of type LDNS_RDF_TYPE_NSAP from string to wireformat.
460266077Sdes * @param str: the text to convert for this rdata element.
461266077Sdes * @param rd: rdata buffer for the wireformat.
462266077Sdes * @param len: length of rd buffer on input, used length on output.
463266077Sdes * @return 0 on success, error on failure.
464266077Sdes */
465266077Sdesint sldns_str2wire_nsap_buf(const char* str, uint8_t* rd, size_t* len);
466266077Sdes
467266077Sdes/**
468266077Sdes * Convert rdf of type LDNS_RDF_TYPE_ATMA from string to wireformat.
469266077Sdes * @param str: the text to convert for this rdata element.
470266077Sdes * @param rd: rdata buffer for the wireformat.
471266077Sdes * @param len: length of rd buffer on input, used length on output.
472266077Sdes * @return 0 on success, error on failure.
473266077Sdes */
474266077Sdesint sldns_str2wire_atma_buf(const char* str, uint8_t* rd, size_t* len);
475266077Sdes
476266077Sdes/**
477266077Sdes * Convert rdf of type LDNS_RDF_TYPE_IPSECKEY from string to wireformat.
478266077Sdes * @param str: the text to convert for this rdata element.
479266077Sdes * @param rd: rdata buffer for the wireformat.
480266077Sdes * @param len: length of rd buffer on input, used length on output.
481266077Sdes * @return 0 on success, error on failure.
482266077Sdes */
483266077Sdesint sldns_str2wire_ipseckey_buf(const char* str, uint8_t* rd, size_t* len);
484266077Sdes
485266077Sdes/**
486266077Sdes * Convert rdf of type LDNS_RDF_TYPE_NSEC3_SALT from string to wireformat.
487266077Sdes * @param str: the text to convert for this rdata element.
488266077Sdes * @param rd: rdata buffer for the wireformat.
489266077Sdes * @param len: length of rd buffer on input, used length on output.
490266077Sdes * @return 0 on success, error on failure.
491266077Sdes */
492266077Sdesint sldns_str2wire_nsec3_salt_buf(const char* str, uint8_t* rd, size_t* len);
493266077Sdes
494266077Sdes/**
495266077Sdes * Convert rdf of type LDNS_RDF_TYPE_ILNP64 from string to wireformat.
496266077Sdes * @param str: the text to convert for this rdata element.
497266077Sdes * @param rd: rdata buffer for the wireformat.
498266077Sdes * @param len: length of rd buffer on input, used length on output.
499266077Sdes * @return 0 on success, error on failure.
500266077Sdes */
501266077Sdesint sldns_str2wire_ilnp64_buf(const char* str, uint8_t* rd, size_t* len);
502266077Sdes
503266077Sdes/**
504266077Sdes * Convert rdf of type LDNS_RDF_TYPE_EUI48 from string to wireformat.
505266077Sdes * @param str: the text to convert for this rdata element.
506266077Sdes * @param rd: rdata buffer for the wireformat.
507266077Sdes * @param len: length of rd buffer on input, used length on output.
508266077Sdes * @return 0 on success, error on failure.
509266077Sdes */
510266077Sdesint sldns_str2wire_eui48_buf(const char* str, uint8_t* rd, size_t* len);
511266077Sdes
512266077Sdes/**
513266077Sdes * Convert rdf of type LDNS_RDF_TYPE_EUI64 from string to wireformat.
514266077Sdes * @param str: the text to convert for this rdata element.
515266077Sdes * @param rd: rdata buffer for the wireformat.
516266077Sdes * @param len: length of rd buffer on input, used length on output.
517266077Sdes * @return 0 on success, error on failure.
518266077Sdes */
519266077Sdesint sldns_str2wire_eui64_buf(const char* str, uint8_t* rd, size_t* len);
520266077Sdes
521266077Sdes/**
522266077Sdes * Convert rdf of type LDNS_RDF_TYPE_TAG from string to wireformat.
523266077Sdes * @param str: the text to convert for this rdata element.
524266077Sdes * @param rd: rdata buffer for the wireformat.
525266077Sdes * @param len: length of rd buffer on input, used length on output.
526266077Sdes * @return 0 on success, error on failure.
527266077Sdes */
528266077Sdesint sldns_str2wire_tag_buf(const char* str, uint8_t* rd, size_t* len);
529266077Sdes
530266077Sdes/**
531266077Sdes * Convert rdf of type LDNS_RDF_TYPE_LONG_STR from string to wireformat.
532266077Sdes * @param str: the text to convert for this rdata element.
533266077Sdes * @param rd: rdata buffer for the wireformat.
534266077Sdes * @param len: length of rd buffer on input, used length on output.
535266077Sdes * @return 0 on success, error on failure.
536266077Sdes */
537266077Sdesint sldns_str2wire_long_str_buf(const char* str, uint8_t* rd, size_t* len);
538266077Sdes
539266077Sdes/**
540266077Sdes * Convert rdf of type LDNS_RDF_TYPE_HIP from string to wireformat.
541266077Sdes * @param str: the text to convert for this rdata element.
542266077Sdes * @param rd: rdata buffer for the wireformat.
543266077Sdes * @param len: length of rd buffer on input, used length on output.
544266077Sdes * @return 0 on success, error on failure.
545266077Sdes */
546266077Sdesint sldns_str2wire_hip_buf(const char* str, uint8_t* rd, size_t* len);
547266077Sdes
548266077Sdes/**
549266077Sdes * Convert rdf of type LDNS_RDF_TYPE_INT16_DATA from string to wireformat.
550266077Sdes * @param str: the text to convert for this rdata element.
551266077Sdes * @param rd: rdata buffer for the wireformat.
552266077Sdes * @param len: length of rd buffer on input, used length on output.
553266077Sdes * @return 0 on success, error on failure.
554266077Sdes */
555266077Sdesint sldns_str2wire_int16_data_buf(const char* str, uint8_t* rd, size_t* len);
556266077Sdes
557356345Scy/**
558356345Scy * Strip whitespace from the start and the end of line.
559356345Scy * @param line: modified with 0 to shorten it.
560356345Scy * @return new start with spaces skipped.
561356345Scy */
562356345Scychar * sldns_strip_ws(char *line);
563266077Sdes#ifdef __cplusplus
564266077Sdes}
565266077Sdes#endif
566266077Sdes
567266077Sdes#endif /* LDNS_STR2WIRE_H */
568