1eaad808eSchristos /** 2eaad808eSchristos * str2wire.h - read txt presentation of RRs 3eaad808eSchristos * 4eaad808eSchristos * (c) NLnet Labs, 2005-2006 5eaad808eSchristos * 6eaad808eSchristos * See the file LICENSE for the license 7eaad808eSchristos */ 8eaad808eSchristos 9eaad808eSchristos /** 10eaad808eSchristos * \file 11eaad808eSchristos * 12eaad808eSchristos * Parses text to wireformat. 13eaad808eSchristos */ 14eaad808eSchristos 15eaad808eSchristos #ifndef LDNS_STR2WIRE_H 16eaad808eSchristos #define LDNS_STR2WIRE_H 17eaad808eSchristos 18eaad808eSchristos /* include rrdef for MAX_DOMAINLEN constant */ 19eaad808eSchristos #include <sldns/rrdef.h> 20eaad808eSchristos 21eaad808eSchristos #ifdef __cplusplus 22eaad808eSchristos extern "C" { 23eaad808eSchristos #endif 24eaad808eSchristos struct sldns_struct_lookup_table; 25eaad808eSchristos 26*17b85d8bSchristos #define LDNS_IP4ADDRLEN (32/8) 27*17b85d8bSchristos #define LDNS_IP6ADDRLEN (128/8) 28*17b85d8bSchristos 29eaad808eSchristos /** buffer to read an RR, cannot be larger than 64K because of packet size */ 30eaad808eSchristos #define LDNS_RR_BUF_SIZE 65535 /* bytes */ 31eaad808eSchristos #define LDNS_DEFAULT_TTL 3600 32eaad808eSchristos 33*17b85d8bSchristos /* SVCB keys currently defined in draft-ietf-dnsop-svcb-https */ 34*17b85d8bSchristos #define SVCB_KEY_MANDATORY 0 35*17b85d8bSchristos #define SVCB_KEY_ALPN 1 36*17b85d8bSchristos #define SVCB_KEY_NO_DEFAULT_ALPN 2 37*17b85d8bSchristos #define SVCB_KEY_PORT 3 38*17b85d8bSchristos #define SVCB_KEY_IPV4HINT 4 39*17b85d8bSchristos #define SVCB_KEY_ECH 5 40*17b85d8bSchristos #define SVCB_KEY_IPV6HINT 6 41*17b85d8bSchristos #define SVCPARAMKEY_COUNT 7 42*17b85d8bSchristos 43*17b85d8bSchristos #define MAX_NUMBER_OF_SVCPARAMS 64 44*17b85d8bSchristos 45*17b85d8bSchristos #define SVCB_MAX_COMMA_SEPARATED_VALUES 1000 46*17b85d8bSchristos 47eaad808eSchristos /* 48eaad808eSchristos * To convert class and type to string see 49eaad808eSchristos * sldns_get_rr_class_by_name(str) 50eaad808eSchristos * sldns_get_rr_type_by_name(str) 51eaad808eSchristos * from rrdef.h 52eaad808eSchristos */ 53eaad808eSchristos 54eaad808eSchristos /** 55eaad808eSchristos * Convert text string into dname wireformat, mallocless, with user buffer. 56eaad808eSchristos * @param str: the text string with the domain name. 57eaad808eSchristos * @param buf: the result buffer, suggested size LDNS_MAX_DOMAINLEN+1 58eaad808eSchristos * @param len: length of the buffer on input, length of the result on output. 59eaad808eSchristos * @return 0 on success, otherwise an error. 60eaad808eSchristos */ 61eaad808eSchristos int sldns_str2wire_dname_buf(const char* str, uint8_t* buf, size_t* len); 62eaad808eSchristos 63eaad808eSchristos /** 64eaad808eSchristos * Same as sldns_str2wire_dname_buf, but concatenates origin if the domain 65eaad808eSchristos * name is relative (does not end in '.'). 66eaad808eSchristos * @param str: the text string with the domain name. 67eaad808eSchristos * @param buf: the result buffer, suggested size LDNS_MAX_DOMAINLEN+1 68eaad808eSchristos * @param len: length of the buffer on input, length of the result on output. 69eaad808eSchristos * @param origin: the origin to append or NULL (nothing is appended). 70eaad808eSchristos * @param origin_len: length of origin. 71eaad808eSchristos * @return 0 on success, otherwise an error. 72eaad808eSchristos */ 73eaad808eSchristos int sldns_str2wire_dname_buf_origin(const char* str, uint8_t* buf, size_t* len, 74eaad808eSchristos uint8_t* origin, size_t origin_len); 75eaad808eSchristos 76eaad808eSchristos /** 77eaad808eSchristos * Convert text string into dname wireformat 78eaad808eSchristos * @param str: the text string with the domain name. 79eaad808eSchristos * @param len: returned length of wireformat. 80eaad808eSchristos * @return wireformat dname (malloced) or NULL on failure. 81eaad808eSchristos */ 82eaad808eSchristos uint8_t* sldns_str2wire_dname(const char* str, size_t* len); 83eaad808eSchristos 84eaad808eSchristos /** 85eaad808eSchristos * Convert text RR to wireformat, with user buffer. 86eaad808eSchristos * @param str: the RR data in text presentation format. 87eaad808eSchristos * @param rr: the buffer where the result is stored into. This buffer has 88eaad808eSchristos * the wire-dname(uncompressed), type, class, ttl, rdatalen, rdata. 89eaad808eSchristos * These values are probably not aligned, and in network format. 90eaad808eSchristos * Use the sldns_wirerr_get_xxx functions to access them safely. 91eaad808eSchristos * buffer size LDNS_RR_BUF_SIZE is suggested. 92eaad808eSchristos * @param len: on input the length of the buffer, on output the amount of 93eaad808eSchristos * the buffer used for the rr. 94eaad808eSchristos * @param dname_len: if non-NULL, filled with the dname length as result. 95eaad808eSchristos * Because after the dname you find the type, class, ttl, rdatalen, rdata. 96eaad808eSchristos * @param default_ttl: TTL used if no TTL available. 97eaad808eSchristos * @param origin: used for origin dname (if not NULL) 98eaad808eSchristos * @param origin_len: length of origin. 99eaad808eSchristos * @param prev: used for prev_rr dname (if not NULL) 100eaad808eSchristos * @param prev_len: length of prev. 101eaad808eSchristos * @return 0 on success, an error on failure. 102eaad808eSchristos */ 103eaad808eSchristos int sldns_str2wire_rr_buf(const char* str, uint8_t* rr, size_t* len, 104eaad808eSchristos size_t* dname_len, uint32_t default_ttl, uint8_t* origin, 105eaad808eSchristos size_t origin_len, uint8_t* prev, size_t prev_len); 106eaad808eSchristos 107eaad808eSchristos /** 108eaad808eSchristos * Same as sldns_str2wire_rr_buf, but there is no rdata, it returns an RR 109eaad808eSchristos * with zero rdata and no ttl. It has name, type, class. 110eaad808eSchristos * You can access those with the sldns_wirerr_get_type and class functions. 111eaad808eSchristos * @param str: the RR data in text presentation format. 112eaad808eSchristos * @param rr: the buffer where the result is stored into. 113eaad808eSchristos * @param len: on input the length of the buffer, on output the amount of 114eaad808eSchristos * the buffer used for the rr. 115eaad808eSchristos * @param dname_len: if non-NULL, filled with the dname length as result. 116eaad808eSchristos * Because after the dname you find the type, class, ttl, rdatalen, rdata. 117eaad808eSchristos * @param origin: used for origin dname (if not NULL) 118eaad808eSchristos * @param origin_len: length of origin. 119eaad808eSchristos * @param prev: used for prev_rr dname (if not NULL) 120eaad808eSchristos * @param prev_len: length of prev. 121eaad808eSchristos * @return 0 on success, an error on failure. 122eaad808eSchristos */ 123eaad808eSchristos int sldns_str2wire_rr_question_buf(const char* str, uint8_t* rr, size_t* len, 124eaad808eSchristos size_t* dname_len, uint8_t* origin, size_t origin_len, uint8_t* prev, 125eaad808eSchristos size_t prev_len); 126eaad808eSchristos 127eaad808eSchristos /** 128eaad808eSchristos * Get the type of the RR. 129eaad808eSchristos * @param rr: the RR in wire format. 130eaad808eSchristos * @param len: rr length. 131eaad808eSchristos * @param dname_len: dname length to skip. 132eaad808eSchristos * @return type in host byteorder 133eaad808eSchristos */ 134eaad808eSchristos uint16_t sldns_wirerr_get_type(uint8_t* rr, size_t len, size_t dname_len); 135eaad808eSchristos 136eaad808eSchristos /** 137eaad808eSchristos * Get the class of the RR. 138eaad808eSchristos * @param rr: the RR in wire format. 139eaad808eSchristos * @param len: rr length. 140eaad808eSchristos * @param dname_len: dname length to skip. 141eaad808eSchristos * @return class in host byteorder 142eaad808eSchristos */ 143eaad808eSchristos uint16_t sldns_wirerr_get_class(uint8_t* rr, size_t len, size_t dname_len); 144eaad808eSchristos 145eaad808eSchristos /** 146eaad808eSchristos * Get the ttl of the RR. 147eaad808eSchristos * @param rr: the RR in wire format. 148eaad808eSchristos * @param len: rr length. 149eaad808eSchristos * @param dname_len: dname length to skip. 150eaad808eSchristos * @return ttl in host byteorder 151eaad808eSchristos */ 152eaad808eSchristos uint32_t sldns_wirerr_get_ttl(uint8_t* rr, size_t len, size_t dname_len); 153eaad808eSchristos 154eaad808eSchristos /** 155eaad808eSchristos * Get the rdata length of the RR. 156eaad808eSchristos * @param rr: the RR in wire format. 157eaad808eSchristos * @param len: rr length. 158eaad808eSchristos * @param dname_len: dname length to skip. 159eaad808eSchristos * @return rdata length in host byteorder 160eaad808eSchristos * If the rdata length is larger than the rr-len allows, it is truncated. 161eaad808eSchristos * So, that it is safe to read the data length returned 162eaad808eSchristos * from this function from the rdata pointer of sldns_wirerr_get_rdata. 163eaad808eSchristos */ 164eaad808eSchristos uint16_t sldns_wirerr_get_rdatalen(uint8_t* rr, size_t len, size_t dname_len); 165eaad808eSchristos 166eaad808eSchristos /** 167eaad808eSchristos * Get the rdata pointer of the RR. 168eaad808eSchristos * @param rr: the RR in wire format. 169eaad808eSchristos * @param len: rr length. 170eaad808eSchristos * @param dname_len: dname length to skip. 171eaad808eSchristos * @return rdata pointer 172eaad808eSchristos */ 173eaad808eSchristos uint8_t* sldns_wirerr_get_rdata(uint8_t* rr, size_t len, size_t dname_len); 174eaad808eSchristos 175eaad808eSchristos /** 176eaad808eSchristos * Get the rdata pointer of the RR. prefixed with rdata length. 177eaad808eSchristos * @param rr: the RR in wire format. 178eaad808eSchristos * @param len: rr length. 179eaad808eSchristos * @param dname_len: dname length to skip. 180eaad808eSchristos * @return pointer to rdatalength, followed by the rdata. 181eaad808eSchristos */ 182eaad808eSchristos uint8_t* sldns_wirerr_get_rdatawl(uint8_t* rr, size_t len, size_t dname_len); 183eaad808eSchristos 184eaad808eSchristos /** 185eaad808eSchristos * Parse result codes 186eaad808eSchristos */ 187eaad808eSchristos #define LDNS_WIREPARSE_MASK 0x0fff 188eaad808eSchristos #define LDNS_WIREPARSE_SHIFT 12 189eaad808eSchristos #define LDNS_WIREPARSE_ERROR(e) ((e)&LDNS_WIREPARSE_MASK) 190*17b85d8bSchristos #define LDNS_WIREPARSE_OFFSET(e) ((((unsigned)(e))&~LDNS_WIREPARSE_MASK)>>LDNS_WIREPARSE_SHIFT) 191eaad808eSchristos /* use lookuptable to get error string, sldns_wireparse_errors */ 192eaad808eSchristos #define LDNS_WIREPARSE_ERR_OK 0 193eaad808eSchristos #define LDNS_WIREPARSE_ERR_GENERAL 342 194eaad808eSchristos #define LDNS_WIREPARSE_ERR_DOMAINNAME_OVERFLOW 343 195eaad808eSchristos #define LDNS_WIREPARSE_ERR_DOMAINNAME_UNDERFLOW 344 196eaad808eSchristos #define LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL 345 197eaad808eSchristos #define LDNS_WIREPARSE_ERR_LABEL_OVERFLOW 346 198eaad808eSchristos #define LDNS_WIREPARSE_ERR_EMPTY_LABEL 347 199eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_BAD_ESCAPE 348 200eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX 349 201eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_TTL 350 202eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_TYPE 351 203eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_CLASS 352 204eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_RDATA 353 205eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_MISSING_VALUE 354 206eaad808eSchristos #define LDNS_WIREPARSE_ERR_INVALID_STR 355 207eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_B64 356 208eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_B32_EXT 357 209eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_HEX 358 210eaad808eSchristos #define LDNS_WIREPARSE_ERR_CERT_BAD_ALGORITHM 359 211eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_TIME 360 212eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_PERIOD 361 213eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_ILNP64 362 214eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_EUI48 363 215eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_EUI64 364 216eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_TAG 365 217eaad808eSchristos #define LDNS_WIREPARSE_ERR_NOT_IMPL 366 218eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_INT 367 219eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_IP4 368 220eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_IP6 369 221eaad808eSchristos #define LDNS_WIREPARSE_ERR_SYNTAX_INTEGER_OVERFLOW 370 222eaad808eSchristos #define LDNS_WIREPARSE_ERR_INCLUDE 371 223eaad808eSchristos #define LDNS_WIREPARSE_ERR_PARENTHESIS 372 224*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_UNKNOWN_KEY 373 225*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_MISSING_PARAM 374 226*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_TOO_MANY_PARAMS 375 227*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_DUPLICATE_KEYS 376 228*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_MANDATORY_TOO_MANY_KEYS 377 229*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_MANDATORY_MISSING_PARAM 378 230*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_MANDATORY_DUPLICATE_KEY 379 231*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_MANDATORY_IN_MANDATORY 380 232*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_PORT_VALUE_SYNTAX 381 233*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_IPV4_TOO_MANY_ADDRESSES 382 234*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_IPV6_TOO_MANY_ADDRESSES 383 235*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_ALPN_KEY_TOO_LARGE 384 236*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCB_NO_DEFAULT_ALPN_VALUE 385 237*17b85d8bSchristos #define LDNS_WIREPARSE_ERR_SVCPARAM_BROKEN_RDATA 386 238eaad808eSchristos 239eaad808eSchristos /** 240eaad808eSchristos * Get reference to a constant string for the (parse) error. 241eaad808eSchristos * @param e: error return value 242eaad808eSchristos * @return string. 243eaad808eSchristos */ 244eaad808eSchristos const char* sldns_get_errorstr_parse(int e); 245eaad808eSchristos 246eaad808eSchristos /** 247eaad808eSchristos * wire parse state for parsing files 248eaad808eSchristos */ 249eaad808eSchristos struct sldns_file_parse_state { 250eaad808eSchristos /** the origin domain name, if len!=0. uncompressed wireformat */ 251eaad808eSchristos uint8_t origin[LDNS_MAX_DOMAINLEN+1]; 252eaad808eSchristos /** length of origin domain name, in bytes. 0 if not set. */ 253eaad808eSchristos size_t origin_len; 254eaad808eSchristos /** the previous domain name, if len!=0. uncompressed wireformat*/ 255eaad808eSchristos uint8_t prev_rr[LDNS_MAX_DOMAINLEN+1]; 256eaad808eSchristos /** length of the previous domain name, in bytes. 0 if not set. */ 257eaad808eSchristos size_t prev_rr_len; 258eaad808eSchristos /** default TTL, this is used if the text does not specify a TTL, 259eaad808eSchristos * host byteorder */ 260eaad808eSchristos uint32_t default_ttl; 261eaad808eSchristos /** line number information */ 262eaad808eSchristos int lineno; 263eaad808eSchristos }; 264eaad808eSchristos 265eaad808eSchristos /** 266eaad808eSchristos * Read one RR from zonefile with buffer for the data. 267eaad808eSchristos * @param in: file that is read from (one RR, multiple lines if it spans them). 268eaad808eSchristos * @param rr: this is malloced by the user and the result is stored here, 269eaad808eSchristos * if an RR is read. If no RR is read this is signalled with the 270eaad808eSchristos * return len set to 0 (for ORIGIN, TTL directives). 271762909a6Schristos * The read line is available in the rr_buf (zero terminated), for 272762909a6Schristos * $DIRECTIVE style elements. 273eaad808eSchristos * @param len: on input, the length of the rr buffer. on output the rr len. 274eaad808eSchristos * Buffer size of 64k should be enough. 275eaad808eSchristos * @param dname_len: returns the length of the dname initial part of the rr. 276eaad808eSchristos * @param parse_state: pass a pointer to user-allocated struct. 277eaad808eSchristos * Contents are maintained by this function. 278eaad808eSchristos * If you pass NULL then ORIGIN and TTL directives are not honored. 279eaad808eSchristos * You can start out with a particular origin by pre-filling it. 280eaad808eSchristos * otherwise, zero the structure before passing it. 281eaad808eSchristos * lineno is incremented when a newline is passed by the parser, 282eaad808eSchristos * you should initialize it at 1 at the start of the file. 283eaad808eSchristos * @return 0 on success, error on failure. 284eaad808eSchristos */ 285eaad808eSchristos int sldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len, 286eaad808eSchristos struct sldns_file_parse_state* parse_state); 287eaad808eSchristos 288eaad808eSchristos /** 289eaad808eSchristos * Convert one rdf in rdata to wireformat and parse from string. 290eaad808eSchristos * @param str: the text to convert for this rdata element. 291eaad808eSchristos * @param rd: rdata buffer for the wireformat. 292eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 293eaad808eSchristos * @param rdftype: the type of the rdf. 294eaad808eSchristos * @return 0 on success, error on failure. 295eaad808eSchristos */ 296eaad808eSchristos int sldns_str2wire_rdf_buf(const char* str, uint8_t* rd, size_t* len, 297eaad808eSchristos sldns_rdf_type rdftype); 298eaad808eSchristos 299eaad808eSchristos /** 300eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_INT8 from string to wireformat. 301eaad808eSchristos * @param str: the text to convert for this rdata element. 302eaad808eSchristos * @param rd: rdata buffer for the wireformat. 303eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 304eaad808eSchristos * @return 0 on success, error on failure. 305eaad808eSchristos */ 306eaad808eSchristos int sldns_str2wire_int8_buf(const char* str, uint8_t* rd, size_t* len); 307eaad808eSchristos 308eaad808eSchristos /** 309eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_INT16 from string to wireformat. 310eaad808eSchristos * @param str: the text to convert for this rdata element. 311eaad808eSchristos * @param rd: rdata buffer for the wireformat. 312eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 313eaad808eSchristos * @return 0 on success, error on failure. 314eaad808eSchristos */ 315eaad808eSchristos int sldns_str2wire_int16_buf(const char* str, uint8_t* rd, size_t* len); 316eaad808eSchristos 317eaad808eSchristos /** 318eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_INT32 from string to wireformat. 319eaad808eSchristos * @param str: the text to convert for this rdata element. 320eaad808eSchristos * @param rd: rdata buffer for the wireformat. 321eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 322eaad808eSchristos * @return 0 on success, error on failure. 323eaad808eSchristos */ 324eaad808eSchristos int sldns_str2wire_int32_buf(const char* str, uint8_t* rd, size_t* len); 325eaad808eSchristos 326eaad808eSchristos /** 327eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_A from string to wireformat. 328eaad808eSchristos * @param str: the text to convert for this rdata element. 329eaad808eSchristos * @param rd: rdata buffer for the wireformat. 330eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 331eaad808eSchristos * @return 0 on success, error on failure. 332eaad808eSchristos */ 333eaad808eSchristos int sldns_str2wire_a_buf(const char* str, uint8_t* rd, size_t* len); 334eaad808eSchristos 335eaad808eSchristos /** 336eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_AAAA from string to wireformat. 337eaad808eSchristos * @param str: the text to convert for this rdata element. 338eaad808eSchristos * @param rd: rdata buffer for the wireformat. 339eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 340eaad808eSchristos * @return 0 on success, error on failure. 341eaad808eSchristos */ 342eaad808eSchristos int sldns_str2wire_aaaa_buf(const char* str, uint8_t* rd, size_t* len); 343eaad808eSchristos 344eaad808eSchristos /** 345eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_STR from string to wireformat. 346eaad808eSchristos * @param str: the text to convert for this rdata element. 347eaad808eSchristos * @param rd: rdata buffer for the wireformat. 348eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 349eaad808eSchristos * @return 0 on success, error on failure. 350eaad808eSchristos */ 351eaad808eSchristos int sldns_str2wire_str_buf(const char* str, uint8_t* rd, size_t* len); 352eaad808eSchristos 353eaad808eSchristos /** 354eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_APL from string to wireformat. 355eaad808eSchristos * @param str: the text to convert for this rdata element. 356eaad808eSchristos * @param rd: rdata buffer for the wireformat. 357eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 358eaad808eSchristos * @return 0 on success, error on failure. 359eaad808eSchristos */ 360eaad808eSchristos int sldns_str2wire_apl_buf(const char* str, uint8_t* rd, size_t* len); 361eaad808eSchristos 362eaad808eSchristos /** 363eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_B64 from string to wireformat. 364eaad808eSchristos * @param str: the text to convert for this rdata element. 365eaad808eSchristos * @param rd: rdata buffer for the wireformat. 366eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 367eaad808eSchristos * @return 0 on success, error on failure. 368eaad808eSchristos */ 369eaad808eSchristos int sldns_str2wire_b64_buf(const char* str, uint8_t* rd, size_t* len); 370eaad808eSchristos 371eaad808eSchristos /** 372eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_B32_EXT from string to wireformat. 373eaad808eSchristos * And also LDNS_RDF_TYPE_NSEC3_NEXT_OWNER. 374eaad808eSchristos * @param str: the text to convert for this rdata element. 375eaad808eSchristos * @param rd: rdata buffer for the wireformat. 376eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 377eaad808eSchristos * @return 0 on success, error on failure. 378eaad808eSchristos */ 379eaad808eSchristos int sldns_str2wire_b32_ext_buf(const char* str, uint8_t* rd, size_t* len); 380eaad808eSchristos 381eaad808eSchristos /** 382eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_HEX from string to wireformat. 383eaad808eSchristos * @param str: the text to convert for this rdata element. 384eaad808eSchristos * @param rd: rdata buffer for the wireformat. 385eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 386eaad808eSchristos * @return 0 on success, error on failure. 387eaad808eSchristos */ 388eaad808eSchristos int sldns_str2wire_hex_buf(const char* str, uint8_t* rd, size_t* len); 389eaad808eSchristos 390eaad808eSchristos /** 391eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_NSEC from string to wireformat. 392eaad808eSchristos * @param str: the text to convert for this rdata element. 393eaad808eSchristos * @param rd: rdata buffer for the wireformat. 394eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 395eaad808eSchristos * @return 0 on success, error on failure. 396eaad808eSchristos */ 397eaad808eSchristos int sldns_str2wire_nsec_buf(const char* str, uint8_t* rd, size_t* len); 398eaad808eSchristos 399eaad808eSchristos /** 400eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_TYPE from string to wireformat. 401eaad808eSchristos * @param str: the text to convert for this rdata element. 402eaad808eSchristos * @param rd: rdata buffer for the wireformat. 403eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 404eaad808eSchristos * @return 0 on success, error on failure. 405eaad808eSchristos */ 406eaad808eSchristos int sldns_str2wire_type_buf(const char* str, uint8_t* rd, size_t* len); 407eaad808eSchristos 408eaad808eSchristos /** 409eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_CLASS from string to wireformat. 410eaad808eSchristos * @param str: the text to convert for this rdata element. 411eaad808eSchristos * @param rd: rdata buffer for the wireformat. 412eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 413eaad808eSchristos * @return 0 on success, error on failure. 414eaad808eSchristos */ 415eaad808eSchristos int sldns_str2wire_class_buf(const char* str, uint8_t* rd, size_t* len); 416eaad808eSchristos 417eaad808eSchristos /** 418eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_CERT_ALG from string to wireformat. 419eaad808eSchristos * @param str: the text to convert for this rdata element. 420eaad808eSchristos * @param rd: rdata buffer for the wireformat. 421eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 422eaad808eSchristos * @return 0 on success, error on failure. 423eaad808eSchristos */ 424eaad808eSchristos int sldns_str2wire_cert_alg_buf(const char* str, uint8_t* rd, size_t* len); 425eaad808eSchristos 426eaad808eSchristos /** 427eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_ALG from string to wireformat. 428eaad808eSchristos * @param str: the text to convert for this rdata element. 429eaad808eSchristos * @param rd: rdata buffer for the wireformat. 430eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 431eaad808eSchristos * @return 0 on success, error on failure. 432eaad808eSchristos */ 433eaad808eSchristos int sldns_str2wire_alg_buf(const char* str, uint8_t* rd, size_t* len); 434eaad808eSchristos 435eaad808eSchristos /** 436eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_TIME from string to wireformat. 437eaad808eSchristos * @param str: the text to convert for this rdata element. 438eaad808eSchristos * @param rd: rdata buffer for the wireformat. 439eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 440eaad808eSchristos * @return 0 on success, error on failure. 441eaad808eSchristos */ 442eaad808eSchristos int sldns_str2wire_time_buf(const char* str, uint8_t* rd, size_t* len); 443eaad808eSchristos 444eaad808eSchristos /** 445eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_PERIOD from string to wireformat. 446eaad808eSchristos * @param str: the text to convert for this rdata element. 447eaad808eSchristos * @param rd: rdata buffer for the wireformat. 448eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 449eaad808eSchristos * @return 0 on success, error on failure. 450eaad808eSchristos */ 451eaad808eSchristos int sldns_str2wire_period_buf(const char* str, uint8_t* rd, size_t* len); 452eaad808eSchristos 453eaad808eSchristos /** 454762909a6Schristos * Convert rdf of type LDNS_RDF_TYPE_TSIGTIME from string to wireformat. 455762909a6Schristos * @param str: the text to convert for this rdata element. 456762909a6Schristos * @param rd: rdata buffer for the wireformat. 457762909a6Schristos * @param len: length of rd buffer on input, used length on output. 458762909a6Schristos * @return 0 on success, error on failure. 459762909a6Schristos */ 460762909a6Schristos int sldns_str2wire_tsigtime_buf(const char* str, uint8_t* rd, size_t* len); 461762909a6Schristos 462762909a6Schristos /** 463762909a6Schristos * Convert rdf of type LDNS_RDF_TYPE_TSIGERROR from string to wireformat. 464762909a6Schristos * @param str: the text to convert for this rdata element. 465762909a6Schristos * @param rd: rdata buffer for the wireformat. 466762909a6Schristos * @param len: length of rd buffer on input, used length on output. 467762909a6Schristos * @return 0 on success, error on failure. 468762909a6Schristos */ 469762909a6Schristos int sldns_str2wire_tsigerror_buf(const char* str, uint8_t* rd, size_t* len); 470762909a6Schristos 471762909a6Schristos /** 472eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_LOC from string to wireformat. 473eaad808eSchristos * @param str: the text to convert for this rdata element. 474eaad808eSchristos * @param rd: rdata buffer for the wireformat. 475eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 476eaad808eSchristos * @return 0 on success, error on failure. 477eaad808eSchristos */ 478eaad808eSchristos int sldns_str2wire_loc_buf(const char* str, uint8_t* rd, size_t* len); 479eaad808eSchristos 480eaad808eSchristos /** 481eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_WKS from string to wireformat. 482eaad808eSchristos * @param str: the text to convert for this rdata element. 483eaad808eSchristos * @param rd: rdata buffer for the wireformat. 484eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 485eaad808eSchristos * @return 0 on success, error on failure. 486eaad808eSchristos */ 487eaad808eSchristos int sldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len); 488eaad808eSchristos 489eaad808eSchristos /** 490eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_NSAP from string to wireformat. 491eaad808eSchristos * @param str: the text to convert for this rdata element. 492eaad808eSchristos * @param rd: rdata buffer for the wireformat. 493eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 494eaad808eSchristos * @return 0 on success, error on failure. 495eaad808eSchristos */ 496eaad808eSchristos int sldns_str2wire_nsap_buf(const char* str, uint8_t* rd, size_t* len); 497eaad808eSchristos 498eaad808eSchristos /** 499eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_ATMA from string to wireformat. 500eaad808eSchristos * @param str: the text to convert for this rdata element. 501eaad808eSchristos * @param rd: rdata buffer for the wireformat. 502eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 503eaad808eSchristos * @return 0 on success, error on failure. 504eaad808eSchristos */ 505eaad808eSchristos int sldns_str2wire_atma_buf(const char* str, uint8_t* rd, size_t* len); 506eaad808eSchristos 507eaad808eSchristos /** 508eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_IPSECKEY from string to wireformat. 509eaad808eSchristos * @param str: the text to convert for this rdata element. 510eaad808eSchristos * @param rd: rdata buffer for the wireformat. 511eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 512eaad808eSchristos * @return 0 on success, error on failure. 513eaad808eSchristos */ 514eaad808eSchristos int sldns_str2wire_ipseckey_buf(const char* str, uint8_t* rd, size_t* len); 515eaad808eSchristos 516eaad808eSchristos /** 517eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_NSEC3_SALT from string to wireformat. 518eaad808eSchristos * @param str: the text to convert for this rdata element. 519eaad808eSchristos * @param rd: rdata buffer for the wireformat. 520eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 521eaad808eSchristos * @return 0 on success, error on failure. 522eaad808eSchristos */ 523eaad808eSchristos int sldns_str2wire_nsec3_salt_buf(const char* str, uint8_t* rd, size_t* len); 524eaad808eSchristos 525eaad808eSchristos /** 526eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_ILNP64 from string to wireformat. 527eaad808eSchristos * @param str: the text to convert for this rdata element. 528eaad808eSchristos * @param rd: rdata buffer for the wireformat. 529eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 530eaad808eSchristos * @return 0 on success, error on failure. 531eaad808eSchristos */ 532eaad808eSchristos int sldns_str2wire_ilnp64_buf(const char* str, uint8_t* rd, size_t* len); 533eaad808eSchristos 534eaad808eSchristos /** 535eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_EUI48 from string to wireformat. 536eaad808eSchristos * @param str: the text to convert for this rdata element. 537eaad808eSchristos * @param rd: rdata buffer for the wireformat. 538eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 539eaad808eSchristos * @return 0 on success, error on failure. 540eaad808eSchristos */ 541eaad808eSchristos int sldns_str2wire_eui48_buf(const char* str, uint8_t* rd, size_t* len); 542eaad808eSchristos 543eaad808eSchristos /** 544eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_EUI64 from string to wireformat. 545eaad808eSchristos * @param str: the text to convert for this rdata element. 546eaad808eSchristos * @param rd: rdata buffer for the wireformat. 547eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 548eaad808eSchristos * @return 0 on success, error on failure. 549eaad808eSchristos */ 550eaad808eSchristos int sldns_str2wire_eui64_buf(const char* str, uint8_t* rd, size_t* len); 551eaad808eSchristos 552eaad808eSchristos /** 553eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_TAG from string to wireformat. 554eaad808eSchristos * @param str: the text to convert for this rdata element. 555eaad808eSchristos * @param rd: rdata buffer for the wireformat. 556eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 557eaad808eSchristos * @return 0 on success, error on failure. 558eaad808eSchristos */ 559eaad808eSchristos int sldns_str2wire_tag_buf(const char* str, uint8_t* rd, size_t* len); 560eaad808eSchristos 561eaad808eSchristos /** 562eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_LONG_STR from string to wireformat. 563eaad808eSchristos * @param str: the text to convert for this rdata element. 564eaad808eSchristos * @param rd: rdata buffer for the wireformat. 565eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 566eaad808eSchristos * @return 0 on success, error on failure. 567eaad808eSchristos */ 568eaad808eSchristos int sldns_str2wire_long_str_buf(const char* str, uint8_t* rd, size_t* len); 569eaad808eSchristos 570eaad808eSchristos /** 571eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_HIP from string to wireformat. 572eaad808eSchristos * @param str: the text to convert for this rdata element. 573eaad808eSchristos * @param rd: rdata buffer for the wireformat. 574eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 575eaad808eSchristos * @return 0 on success, error on failure. 576eaad808eSchristos */ 577eaad808eSchristos int sldns_str2wire_hip_buf(const char* str, uint8_t* rd, size_t* len); 578eaad808eSchristos 579eaad808eSchristos /** 580eaad808eSchristos * Convert rdf of type LDNS_RDF_TYPE_INT16_DATA from string to wireformat. 581eaad808eSchristos * @param str: the text to convert for this rdata element. 582eaad808eSchristos * @param rd: rdata buffer for the wireformat. 583eaad808eSchristos * @param len: length of rd buffer on input, used length on output. 584eaad808eSchristos * @return 0 on success, error on failure. 585eaad808eSchristos */ 586eaad808eSchristos int sldns_str2wire_int16_data_buf(const char* str, uint8_t* rd, size_t* len); 587eaad808eSchristos 588d6959bcfSchristos /** 589d6959bcfSchristos * Strip whitespace from the start and the end of line. 590d6959bcfSchristos * @param line: modified with 0 to shorten it. 591d6959bcfSchristos * @return new start with spaces skipped. 592d6959bcfSchristos */ 593d6959bcfSchristos char * sldns_strip_ws(char *line); 594eaad808eSchristos #ifdef __cplusplus 595eaad808eSchristos } 596eaad808eSchristos #endif 597eaad808eSchristos 598eaad808eSchristos #endif /* LDNS_STR2WIRE_H */ 599