mirror of https://github.com/getdnsapi/getdns.git
And not actually include on-board ldns2 (gldns)
This commit is contained in:
parent
83f53bd2ea
commit
3468ea13e6
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Meant to be run from this directory
|
||||
|
||||
svn co http://unbound.net/svn/trunk/ldns/
|
||||
for f in ldns/*.[ch]
|
||||
do
|
||||
sed -e 's/sldns_/gldns_/g' -e 's/LDNS_/GLDNS_/g' -e 's/include "ldns/include "gldns/g' -e 's/<ldns\/rrdef\.h>/"gldns\/rrdef.h"/g' $f > ${f#ldns/}
|
||||
done
|
||||
rm -r ldns
|
|
@ -0,0 +1,368 @@
|
|||
/*
|
||||
* keyraw.c - raw key operations and conversions
|
||||
*
|
||||
* (c) NLnet Labs, 2004-2008
|
||||
*
|
||||
* See the file LICENSE for the license
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* Implementation of raw DNSKEY functions (work on wire rdata).
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "gldns/keyraw.h"
|
||||
#include "gldns/rrdef.h"
|
||||
|
||||
#ifdef HAVE_SSL
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/md5.h>
|
||||
#ifdef HAVE_OPENSSL_ENGINE_H
|
||||
# include <openssl/engine.h>
|
||||
#endif
|
||||
#endif /* HAVE_SSL */
|
||||
|
||||
size_t
|
||||
gldns_rr_dnskey_key_size_raw(const unsigned char* keydata,
|
||||
const size_t len, int alg)
|
||||
{
|
||||
/* for DSA keys */
|
||||
uint8_t t;
|
||||
|
||||
/* for RSA keys */
|
||||
uint16_t exp;
|
||||
uint16_t int16;
|
||||
|
||||
switch ((gldns_algorithm)alg) {
|
||||
case GLDNS_DSA:
|
||||
case GLDNS_DSA_NSEC3:
|
||||
if (len > 0) {
|
||||
t = keydata[0];
|
||||
return (64 + t*8)*8;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case GLDNS_RSAMD5:
|
||||
case GLDNS_RSASHA1:
|
||||
case GLDNS_RSASHA1_NSEC3:
|
||||
#ifdef USE_SHA2
|
||||
case GLDNS_RSASHA256:
|
||||
case GLDNS_RSASHA512:
|
||||
#endif
|
||||
if (len > 0) {
|
||||
if (keydata[0] == 0) {
|
||||
/* big exponent */
|
||||
if (len > 3) {
|
||||
memmove(&int16, keydata + 1, 2);
|
||||
exp = ntohs(int16);
|
||||
return (len - exp - 3)*8;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
exp = keydata[0];
|
||||
return (len-exp-1)*8;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
#ifdef USE_GOST
|
||||
case GLDNS_ECC_GOST:
|
||||
return 512;
|
||||
#endif
|
||||
#ifdef USE_ECDSA
|
||||
case GLDNS_ECDSAP256SHA256:
|
||||
return 256;
|
||||
case GLDNS_ECDSAP384SHA384:
|
||||
return 384;
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t gldns_calc_keytag_raw(uint8_t* key, size_t keysize)
|
||||
{
|
||||
if(keysize < 4) {
|
||||
return 0;
|
||||
}
|
||||
/* look at the algorithm field, copied from 2535bis */
|
||||
if (key[3] == GLDNS_RSAMD5) {
|
||||
uint16_t ac16 = 0;
|
||||
if (keysize > 4) {
|
||||
memmove(&ac16, key + keysize - 3, 2);
|
||||
}
|
||||
ac16 = ntohs(ac16);
|
||||
return (uint16_t) ac16;
|
||||
} else {
|
||||
size_t i;
|
||||
uint32_t ac32 = 0;
|
||||
for (i = 0; i < keysize; ++i) {
|
||||
ac32 += (i & 1) ? key[i] : key[i] << 8;
|
||||
}
|
||||
ac32 += (ac32 >> 16) & 0xFFFF;
|
||||
return (uint16_t) (ac32 & 0xFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_SSL
|
||||
#ifdef USE_GOST
|
||||
/** store GOST engine reference loaded into OpenSSL library */
|
||||
ENGINE* gldns_gost_engine = NULL;
|
||||
|
||||
int
|
||||
gldns_key_EVP_load_gost_id(void)
|
||||
{
|
||||
static int gost_id = 0;
|
||||
const EVP_PKEY_ASN1_METHOD* meth;
|
||||
ENGINE* e;
|
||||
|
||||
if(gost_id) return gost_id;
|
||||
|
||||
/* see if configuration loaded gost implementation from other engine*/
|
||||
meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
|
||||
if(meth) {
|
||||
EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
|
||||
return gost_id;
|
||||
}
|
||||
|
||||
/* see if engine can be loaded already */
|
||||
e = ENGINE_by_id("gost");
|
||||
if(!e) {
|
||||
/* load it ourself, in case statically linked */
|
||||
ENGINE_load_builtin_engines();
|
||||
ENGINE_load_dynamic();
|
||||
e = ENGINE_by_id("gost");
|
||||
}
|
||||
if(!e) {
|
||||
/* no gost engine in openssl */
|
||||
return 0;
|
||||
}
|
||||
if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
|
||||
ENGINE_finish(e);
|
||||
ENGINE_free(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
|
||||
if(!meth) {
|
||||
/* algo not found */
|
||||
ENGINE_finish(e);
|
||||
ENGINE_free(e);
|
||||
return 0;
|
||||
}
|
||||
/* Note: do not ENGINE_finish and ENGINE_free the acquired engine
|
||||
* on some platforms this frees up the meth and unloads gost stuff */
|
||||
gldns_gost_engine = e;
|
||||
|
||||
EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
|
||||
return gost_id;
|
||||
}
|
||||
|
||||
void gldns_key_EVP_unload_gost(void)
|
||||
{
|
||||
if(gldns_gost_engine) {
|
||||
ENGINE_finish(gldns_gost_engine);
|
||||
ENGINE_free(gldns_gost_engine);
|
||||
gldns_gost_engine = NULL;
|
||||
}
|
||||
}
|
||||
#endif /* USE_GOST */
|
||||
|
||||
DSA *
|
||||
gldns_key_buf2dsa_raw(unsigned char* key, size_t len)
|
||||
{
|
||||
uint8_t T;
|
||||
uint16_t length;
|
||||
uint16_t offset;
|
||||
DSA *dsa;
|
||||
BIGNUM *Q; BIGNUM *P;
|
||||
BIGNUM *G; BIGNUM *Y;
|
||||
|
||||
if(len == 0)
|
||||
return NULL;
|
||||
T = (uint8_t)key[0];
|
||||
length = (64 + T * 8);
|
||||
offset = 1;
|
||||
|
||||
if (T > 8) {
|
||||
return NULL;
|
||||
}
|
||||
if(len < (size_t)1 + SHA_DIGEST_LENGTH + 3*length)
|
||||
return NULL;
|
||||
|
||||
Q = BN_bin2bn(key+offset, SHA_DIGEST_LENGTH, NULL);
|
||||
offset += SHA_DIGEST_LENGTH;
|
||||
|
||||
P = BN_bin2bn(key+offset, (int)length, NULL);
|
||||
offset += length;
|
||||
|
||||
G = BN_bin2bn(key+offset, (int)length, NULL);
|
||||
offset += length;
|
||||
|
||||
Y = BN_bin2bn(key+offset, (int)length, NULL);
|
||||
offset += length;
|
||||
|
||||
/* create the key and set its properties */
|
||||
if(!Q || !P || !G || !Y || !(dsa = DSA_new())) {
|
||||
BN_free(Q);
|
||||
BN_free(P);
|
||||
BN_free(G);
|
||||
BN_free(Y);
|
||||
return NULL;
|
||||
}
|
||||
#ifndef S_SPLINT_S
|
||||
dsa->p = P;
|
||||
dsa->q = Q;
|
||||
dsa->g = G;
|
||||
dsa->pub_key = Y;
|
||||
#endif /* splint */
|
||||
|
||||
return dsa;
|
||||
}
|
||||
|
||||
RSA *
|
||||
gldns_key_buf2rsa_raw(unsigned char* key, size_t len)
|
||||
{
|
||||
uint16_t offset;
|
||||
uint16_t exp;
|
||||
uint16_t int16;
|
||||
RSA *rsa;
|
||||
BIGNUM *modulus;
|
||||
BIGNUM *exponent;
|
||||
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
if (key[0] == 0) {
|
||||
if(len < 3)
|
||||
return NULL;
|
||||
memmove(&int16, key+1, 2);
|
||||
exp = ntohs(int16);
|
||||
offset = 3;
|
||||
} else {
|
||||
exp = key[0];
|
||||
offset = 1;
|
||||
}
|
||||
|
||||
/* key length at least one */
|
||||
if(len < (size_t)offset + exp + 1)
|
||||
return NULL;
|
||||
|
||||
/* Exponent */
|
||||
exponent = BN_new();
|
||||
if(!exponent) return NULL;
|
||||
(void) BN_bin2bn(key+offset, (int)exp, exponent);
|
||||
offset += exp;
|
||||
|
||||
/* Modulus */
|
||||
modulus = BN_new();
|
||||
if(!modulus) {
|
||||
BN_free(exponent);
|
||||
return NULL;
|
||||
}
|
||||
/* length of the buffer must match the key length! */
|
||||
(void) BN_bin2bn(key+offset, (int)(len - offset), modulus);
|
||||
|
||||
rsa = RSA_new();
|
||||
if(!rsa) {
|
||||
BN_free(exponent);
|
||||
BN_free(modulus);
|
||||
return NULL;
|
||||
}
|
||||
#ifndef S_SPLINT_S
|
||||
rsa->n = modulus;
|
||||
rsa->e = exponent;
|
||||
#endif /* splint */
|
||||
|
||||
return rsa;
|
||||
}
|
||||
|
||||
#ifdef USE_GOST
|
||||
EVP_PKEY*
|
||||
gldns_gost2pkey_raw(unsigned char* key, size_t keylen)
|
||||
{
|
||||
/* prefix header for X509 encoding */
|
||||
uint8_t asn[37] = { 0x30, 0x63, 0x30, 0x1c, 0x06, 0x06, 0x2a, 0x85,
|
||||
0x03, 0x02, 0x02, 0x13, 0x30, 0x12, 0x06, 0x07, 0x2a, 0x85,
|
||||
0x03, 0x02, 0x02, 0x23, 0x01, 0x06, 0x07, 0x2a, 0x85, 0x03,
|
||||
0x02, 0x02, 0x1e, 0x01, 0x03, 0x43, 0x00, 0x04, 0x40};
|
||||
unsigned char encoded[37+64];
|
||||
const unsigned char* pp;
|
||||
if(keylen != 64) {
|
||||
/* key wrong size */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create evp_key */
|
||||
memmove(encoded, asn, 37);
|
||||
memmove(encoded+37, key, 64);
|
||||
pp = (unsigned char*)&encoded[0];
|
||||
|
||||
return d2i_PUBKEY(NULL, &pp, (int)sizeof(encoded));
|
||||
}
|
||||
#endif /* USE_GOST */
|
||||
|
||||
#ifdef USE_ECDSA
|
||||
EVP_PKEY*
|
||||
gldns_ecdsa2pkey_raw(unsigned char* key, size_t keylen, uint8_t algo)
|
||||
{
|
||||
unsigned char buf[256+2]; /* sufficient for 2*384/8+1 */
|
||||
const unsigned char* pp = buf;
|
||||
EVP_PKEY *evp_key;
|
||||
EC_KEY *ec;
|
||||
/* check length, which uncompressed must be 2 bignums */
|
||||
if(algo == GLDNS_ECDSAP256SHA256) {
|
||||
if(keylen != 2*256/8) return NULL;
|
||||
ec = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
|
||||
} else if(algo == GLDNS_ECDSAP384SHA384) {
|
||||
if(keylen != 2*384/8) return NULL;
|
||||
ec = EC_KEY_new_by_curve_name(NID_secp384r1);
|
||||
} else ec = NULL;
|
||||
if(!ec) return NULL;
|
||||
if(keylen+1 > sizeof(buf))
|
||||
return NULL; /* sanity check */
|
||||
/* prepend the 0x02 (from docs) (or actually 0x04 from implementation
|
||||
* of openssl) for uncompressed data */
|
||||
buf[0] = POINT_CONVERSION_UNCOMPRESSED;
|
||||
memmove(buf+1, key, keylen);
|
||||
if(!o2i_ECPublicKey(&ec, &pp, (int)keylen+1)) {
|
||||
EC_KEY_free(ec);
|
||||
return NULL;
|
||||
}
|
||||
evp_key = EVP_PKEY_new();
|
||||
if(!evp_key) {
|
||||
EC_KEY_free(ec);
|
||||
return NULL;
|
||||
}
|
||||
if (!EVP_PKEY_assign_EC_KEY(evp_key, ec)) {
|
||||
EVP_PKEY_free(evp_key);
|
||||
EC_KEY_free(ec);
|
||||
return NULL;
|
||||
}
|
||||
return evp_key;
|
||||
}
|
||||
#endif /* USE_ECDSA */
|
||||
|
||||
int
|
||||
gldns_digest_evp(unsigned char* data, unsigned int len, unsigned char* dest,
|
||||
const EVP_MD* md)
|
||||
{
|
||||
EVP_MD_CTX* ctx;
|
||||
ctx = EVP_MD_CTX_create();
|
||||
if(!ctx)
|
||||
return 0;
|
||||
if(!EVP_DigestInit_ex(ctx, md, NULL) ||
|
||||
!EVP_DigestUpdate(ctx, data, len) ||
|
||||
!EVP_DigestFinal_ex(ctx, dest, NULL)) {
|
||||
EVP_MD_CTX_destroy(ctx);
|
||||
return 0;
|
||||
}
|
||||
EVP_MD_CTX_destroy(ctx);
|
||||
return 1;
|
||||
}
|
||||
#endif /* HAVE_SSL */
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* keyraw.h -- raw key and signature access and conversion
|
||||
*
|
||||
* Copyright (c) 2005-2008, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* See LICENSE for the license.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* raw key and signature access and conversion
|
||||
*
|
||||
* Since those functions heavily rely op cryptographic operations,
|
||||
* this module is dependent on openssl.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GLDNS_KEYRAW_H
|
||||
#define GLDNS_KEYRAW_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#if GLDNS_BUILD_CONFIG_HAVE_SSL
|
||||
# include <openssl/ssl.h>
|
||||
# include <openssl/evp.h>
|
||||
#endif /* GLDNS_BUILD_CONFIG_HAVE_SSL */
|
||||
|
||||
/**
|
||||
* get the length of the keydata in bits
|
||||
* \param[in] keydata the raw key data
|
||||
* \param[in] len the length of the keydata
|
||||
* \param[in] alg the cryptographic algorithm this is a key for
|
||||
* \return the keysize in bits, or 0 on error
|
||||
*/
|
||||
size_t gldns_rr_dnskey_key_size_raw(const unsigned char *keydata,
|
||||
const size_t len, int alg);
|
||||
|
||||
/**
|
||||
* Calculates keytag of DNSSEC key, operates on wireformat rdata.
|
||||
* \param[in] key the key as uncompressed wireformat rdata.
|
||||
* \param[in] keysize length of key data.
|
||||
* \return the keytag
|
||||
*/
|
||||
uint16_t gldns_calc_keytag_raw(uint8_t* key, size_t keysize);
|
||||
|
||||
#if GLDNS_BUILD_CONFIG_HAVE_SSL
|
||||
/**
|
||||
* Get the PKEY id for GOST, loads GOST into openssl as a side effect.
|
||||
* Only available if GOST is compiled into the library and openssl.
|
||||
* \return the gost id for EVP_CTX creation.
|
||||
*/
|
||||
int gldns_key_EVP_load_gost_id(void);
|
||||
|
||||
/** Release the engine reference held for the GOST engine. */
|
||||
void gldns_key_EVP_unload_gost(void);
|
||||
|
||||
/**
|
||||
* Like gldns_key_buf2dsa, but uses raw buffer.
|
||||
* \param[in] key the uncompressed wireformat of the key.
|
||||
* \param[in] len length of key data
|
||||
* \return a DSA * structure with the key material
|
||||
*/
|
||||
DSA *gldns_key_buf2dsa_raw(unsigned char* key, size_t len);
|
||||
|
||||
/**
|
||||
* Converts a holding buffer with key material to EVP PKEY in openssl.
|
||||
* Only available if ldns was compiled with GOST.
|
||||
* \param[in] key data to convert
|
||||
* \param[in] keylen length of the key data
|
||||
* \return the key or NULL on error.
|
||||
*/
|
||||
EVP_PKEY* gldns_gost2pkey_raw(unsigned char* key, size_t keylen);
|
||||
|
||||
/**
|
||||
* Converts a holding buffer with key material to EVP PKEY in openssl.
|
||||
* Only available if ldns was compiled with ECDSA.
|
||||
* \param[in] key data to convert
|
||||
* \param[in] keylen length of the key data
|
||||
* \param[in] algo precise algorithm to initialize ECC group values.
|
||||
* \return the key or NULL on error.
|
||||
*/
|
||||
EVP_PKEY* gldns_ecdsa2pkey_raw(unsigned char* key, size_t keylen, uint8_t algo);
|
||||
|
||||
/**
|
||||
* Like gldns_key_buf2rsa, but uses raw buffer.
|
||||
* \param[in] key the uncompressed wireformat of the key.
|
||||
* \param[in] len length of key data
|
||||
* \return a RSA * structure with the key material
|
||||
*/
|
||||
RSA *gldns_key_buf2rsa_raw(unsigned char* key, size_t len);
|
||||
|
||||
/**
|
||||
* Utility function to calculate hash using generic EVP_MD pointer.
|
||||
* \param[in] data the data to hash.
|
||||
* \param[in] len length of data.
|
||||
* \param[out] dest the destination of the hash, must be large enough.
|
||||
* \param[in] md the message digest to use.
|
||||
* \return true if worked, false on failure.
|
||||
*/
|
||||
int gldns_digest_evp(unsigned char* data, unsigned int len,
|
||||
unsigned char* dest, const EVP_MD* md);
|
||||
|
||||
#endif /* GLDNS_BUILD_CONFIG_HAVE_SSL */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GLDNS_KEYRAW_H */
|
|
@ -0,0 +1,470 @@
|
|||
/*
|
||||
* a generic (simple) parser. Use to parse rr's, private key
|
||||
* information and /etc/resolv.conf files
|
||||
*
|
||||
* a Net::DNS like library for C
|
||||
* LibDNS Team @ NLnet Labs
|
||||
* (c) NLnet Labs, 2005-2006
|
||||
* See the file LICENSE for the license
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "gldns/parse.h"
|
||||
#include "gldns/parseutil.h"
|
||||
#include "gldns/sbuffer.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <strings.h>
|
||||
|
||||
gldns_lookup_table gldns_directive_types[] = {
|
||||
{ GLDNS_DIR_TTL, "$TTL" },
|
||||
{ GLDNS_DIR_ORIGIN, "$ORIGIN" },
|
||||
{ GLDNS_DIR_INCLUDE, "$INCLUDE" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* add max_limit here? */
|
||||
ssize_t
|
||||
gldns_fget_token(FILE *f, char *token, const char *delim, size_t limit)
|
||||
{
|
||||
return gldns_fget_token_l(f, token, delim, limit, NULL);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
gldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr)
|
||||
{
|
||||
int c, prev_c;
|
||||
int p; /* 0 -> no parenthese seen, >0 nr of ( seen */
|
||||
int com, quoted;
|
||||
char *t;
|
||||
size_t i;
|
||||
const char *d;
|
||||
const char *del;
|
||||
|
||||
/* standard delimeters */
|
||||
if (!delim) {
|
||||
/* from isspace(3) */
|
||||
del = GLDNS_PARSE_NORMAL;
|
||||
} else {
|
||||
del = delim;
|
||||
}
|
||||
|
||||
p = 0;
|
||||
i = 0;
|
||||
com = 0;
|
||||
quoted = 0;
|
||||
prev_c = 0;
|
||||
t = token;
|
||||
if (del[0] == '"') {
|
||||
quoted = 1;
|
||||
}
|
||||
while ((c = getc(f)) != EOF) {
|
||||
if (c == '\r') /* carriage return */
|
||||
c = ' ';
|
||||
if (c == '(' && prev_c != '\\' && !quoted) {
|
||||
/* this only counts for non-comments */
|
||||
if (com == 0) {
|
||||
p++;
|
||||
}
|
||||
prev_c = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == ')' && prev_c != '\\' && !quoted) {
|
||||
/* this only counts for non-comments */
|
||||
if (com == 0) {
|
||||
p--;
|
||||
}
|
||||
prev_c = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p < 0) {
|
||||
/* more ) then ( - close off the string */
|
||||
*t = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* do something with comments ; */
|
||||
if (c == ';' && quoted == 0) {
|
||||
if (prev_c != '\\') {
|
||||
com = 1;
|
||||
}
|
||||
}
|
||||
if (c == '\"' && com == 0 && prev_c != '\\') {
|
||||
quoted = 1 - quoted;
|
||||
}
|
||||
|
||||
if (c == '\n' && com != 0) {
|
||||
/* comments */
|
||||
com = 0;
|
||||
*t = ' ';
|
||||
if (line_nr) {
|
||||
*line_nr = *line_nr + 1;
|
||||
}
|
||||
if (p == 0 && i > 0) {
|
||||
goto tokenread;
|
||||
} else {
|
||||
prev_c = c;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (com == 1) {
|
||||
*t = ' ';
|
||||
prev_c = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\n' && p != 0 && t > token) {
|
||||
/* in parentheses */
|
||||
if (line_nr) {
|
||||
*line_nr = *line_nr + 1;
|
||||
}
|
||||
*t++ = ' ';
|
||||
prev_c = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check if we hit the delim */
|
||||
for (d = del; *d; d++) {
|
||||
if (c == *d && i > 0 && prev_c != '\\' && p == 0) {
|
||||
if (c == '\n' && line_nr) {
|
||||
*line_nr = *line_nr + 1;
|
||||
}
|
||||
goto tokenread;
|
||||
}
|
||||
}
|
||||
if (c != '\0' && c != '\n') {
|
||||
i++;
|
||||
}
|
||||
if (limit > 0 && (i >= limit || (size_t)(t-token) >= limit)) {
|
||||
*t = '\0';
|
||||
return -1;
|
||||
}
|
||||
if (c != '\0' && c != '\n') {
|
||||
*t++ = c;
|
||||
}
|
||||
if (c == '\\' && prev_c == '\\')
|
||||
prev_c = 0;
|
||||
else prev_c = c;
|
||||
}
|
||||
*t = '\0';
|
||||
if (c == EOF) {
|
||||
return (ssize_t)i;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
/* nothing read */
|
||||
return -1;
|
||||
}
|
||||
if (p != 0) {
|
||||
return -1;
|
||||
}
|
||||
return (ssize_t)i;
|
||||
|
||||
tokenread:
|
||||
if(*del == '"')
|
||||
/* do not skip over quotes after the string, they are part
|
||||
* of the next string. But skip over whitespace (if needed)*/
|
||||
gldns_fskipcs_l(f, del+1, line_nr);
|
||||
else gldns_fskipcs_l(f, del, line_nr);
|
||||
*t = '\0';
|
||||
if (p != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (ssize_t)i;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
gldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data,
|
||||
const char *d_del, size_t data_limit)
|
||||
{
|
||||
return gldns_fget_keyword_data_l(f, keyword, k_del, data, d_del,
|
||||
data_limit, NULL);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
gldns_fget_keyword_data_l(FILE *f, const char *keyword, const char *k_del, char *data,
|
||||
const char *d_del, size_t data_limit, int *line_nr)
|
||||
{
|
||||
/* we assume: keyword|sep|data */
|
||||
char *fkeyword;
|
||||
ssize_t i;
|
||||
|
||||
if(strlen(keyword) >= GLDNS_MAX_KEYWORDLEN)
|
||||
return -1;
|
||||
fkeyword = (char*)malloc(GLDNS_MAX_KEYWORDLEN);
|
||||
if(!fkeyword)
|
||||
return -1;
|
||||
|
||||
i = gldns_fget_token(f, fkeyword, k_del, GLDNS_MAX_KEYWORDLEN);
|
||||
if(i==0 || i==-1) {
|
||||
free(fkeyword);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* case??? i instead of strlen? */
|
||||
if (strncmp(fkeyword, keyword, GLDNS_MAX_KEYWORDLEN - 1) == 0) {
|
||||
/* whee! */
|
||||
/* printf("%s\n%s\n", "Matching keyword", fkeyword); */
|
||||
i = gldns_fget_token_l(f, data, d_del, data_limit, line_nr);
|
||||
free(fkeyword);
|
||||
return i;
|
||||
} else {
|
||||
/*printf("no match for %s (read: %s)\n", keyword, fkeyword);*/
|
||||
free(fkeyword);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gldns_bgetc(gldns_buffer *buffer)
|
||||
{
|
||||
if (!gldns_buffer_available_at(buffer, buffer->_position, sizeof(uint8_t))) {
|
||||
gldns_buffer_set_position(buffer, gldns_buffer_limit(buffer));
|
||||
/* gldns_buffer_rewind(buffer);*/
|
||||
return EOF;
|
||||
}
|
||||
return (int)gldns_buffer_read_u8(buffer);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
gldns_bget_token(gldns_buffer *b, char *token, const char *delim, size_t limit)
|
||||
{
|
||||
return gldns_bget_token_par(b, token, delim, limit, NULL, NULL);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
gldns_bget_token_par(gldns_buffer *b, char *token, const char *delim,
|
||||
size_t limit, int* par, const char* skipw)
|
||||
{
|
||||
int c, lc;
|
||||
int p; /* 0 -> no parenthese seen, >0 nr of ( seen */
|
||||
int com, quoted;
|
||||
char *t;
|
||||
size_t i;
|
||||
const char *d;
|
||||
const char *del;
|
||||
|
||||
/* standard delimiters */
|
||||
if (!delim) {
|
||||
/* from isspace(3) */
|
||||
del = GLDNS_PARSE_NORMAL;
|
||||
} else {
|
||||
del = delim;
|
||||
}
|
||||
|
||||
p = (par?*par:0);
|
||||
i = 0;
|
||||
com = 0;
|
||||
quoted = 0;
|
||||
t = token;
|
||||
lc = 0;
|
||||
if (del[0] == '"') {
|
||||
quoted = 1;
|
||||
}
|
||||
|
||||
while ((c = gldns_bgetc(b)) != EOF) {
|
||||
if (c == '\r') /* carriage return */
|
||||
c = ' ';
|
||||
if (c == '(' && lc != '\\' && !quoted) {
|
||||
/* this only counts for non-comments */
|
||||
if (com == 0) {
|
||||
if(par) (*par)++;
|
||||
p++;
|
||||
}
|
||||
lc = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == ')' && lc != '\\' && !quoted) {
|
||||
/* this only counts for non-comments */
|
||||
if (com == 0) {
|
||||
if(par) (*par)--;
|
||||
p--;
|
||||
}
|
||||
lc = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p < 0) {
|
||||
/* more ) then ( */
|
||||
*t = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* do something with comments ; */
|
||||
if (c == ';' && quoted == 0) {
|
||||
if (lc != '\\') {
|
||||
com = 1;
|
||||
}
|
||||
}
|
||||
if (c == '"' && com == 0 && lc != '\\') {
|
||||
quoted = 1 - quoted;
|
||||
}
|
||||
|
||||
if (c == '\n' && com != 0) {
|
||||
/* comments */
|
||||
com = 0;
|
||||
*t = ' ';
|
||||
lc = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (com == 1) {
|
||||
*t = ' ';
|
||||
lc = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\n' && p != 0) {
|
||||
/* in parentheses */
|
||||
/* do not write ' ' if we want to skip spaces */
|
||||
if(!(skipw && (strchr(skipw, c)||strchr(skipw, ' '))))
|
||||
*t++ = ' ';
|
||||
lc = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check to skip whitespace at start, but also after ( */
|
||||
if(skipw && i==0 && !com && !quoted && lc != '\\') {
|
||||
if(strchr(skipw, c)) {
|
||||
lc = c;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* check if we hit the delim */
|
||||
for (d = del; *d; d++) {
|
||||
/* we can only exit if no parens or user tracks them */
|
||||
if (c == *d && lc != '\\' && (p == 0 || par)) {
|
||||
goto tokenread;
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
if (limit > 0 && (i >= limit || (size_t)(t-token) >= limit)) {
|
||||
*t = '\0';
|
||||
return -1;
|
||||
}
|
||||
*t++ = c;
|
||||
|
||||
if (c == '\\' && lc == '\\') {
|
||||
lc = 0;
|
||||
} else {
|
||||
lc = c;
|
||||
}
|
||||
}
|
||||
*t = '\0';
|
||||
if (i == 0) {
|
||||
/* nothing read */
|
||||
return -1;
|
||||
}
|
||||
if (!par && p != 0) {
|
||||
return -1;
|
||||
}
|
||||
return (ssize_t)i;
|
||||
|
||||
tokenread:
|
||||
if(*del == '"')
|
||||
/* do not skip over quotes after the string, they are part
|
||||
* of the next string. But skip over whitespace (if needed)*/
|
||||
gldns_bskipcs(b, del+1);
|
||||
else gldns_bskipcs(b, del);
|
||||
*t = '\0';
|
||||
|
||||
if (!par && p != 0) {
|
||||
return -1;
|
||||
}
|
||||
return (ssize_t)i;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gldns_bskipcs(gldns_buffer *buffer, const char *s)
|
||||
{
|
||||
int found;
|
||||
char c;
|
||||
const char *d;
|
||||
|
||||
while(gldns_buffer_available_at(buffer, buffer->_position, sizeof(char))) {
|
||||
c = (char) gldns_buffer_read_u8_at(buffer, buffer->_position);
|
||||
found = 0;
|
||||
for (d = s; *d; d++) {
|
||||
if (*d == c) {
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (found && buffer->_limit > buffer->_position) {
|
||||
buffer->_position += sizeof(char);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gldns_fskipcs(FILE *fp, const char *s)
|
||||
{
|
||||
gldns_fskipcs_l(fp, s, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
gldns_fskipcs_l(FILE *fp, const char *s, int *line_nr)
|
||||
{
|
||||
int found;
|
||||
int c;
|
||||
const char *d;
|
||||
|
||||
while ((c = fgetc(fp)) != EOF) {
|
||||
if (line_nr && c == '\n') {
|
||||
*line_nr = *line_nr + 1;
|
||||
}
|
||||
found = 0;
|
||||
for (d = s; *d; d++) {
|
||||
if (*d == c) {
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
/* with getc, we've read too far */
|
||||
ungetc(c, fp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ssize_t
|
||||
gldns_bget_keyword_data(gldns_buffer *b, const char *keyword, const char *k_del, char
|
||||
*data, const char *d_del, size_t data_limit)
|
||||
{
|
||||
/* we assume: keyword|sep|data */
|
||||
char *fkeyword;
|
||||
ssize_t i;
|
||||
|
||||
if(strlen(keyword) >= GLDNS_MAX_KEYWORDLEN)
|
||||
return -1;
|
||||
fkeyword = (char*)malloc(GLDNS_MAX_KEYWORDLEN);
|
||||
if(!fkeyword)
|
||||
return -1; /* out of memory */
|
||||
|
||||
i = gldns_bget_token(b, fkeyword, k_del, data_limit);
|
||||
if(i==0 || i==-1) {
|
||||
free(fkeyword);
|
||||
return -1; /* nothing read */
|
||||
}
|
||||
|
||||
/* case??? */
|
||||
if (strncmp(fkeyword, keyword, strlen(keyword)) == 0) {
|
||||
free(fkeyword);
|
||||
/* whee, the match! */
|
||||
/* retrieve it's data */
|
||||
i = gldns_bget_token(b, data, d_del, 0);
|
||||
return i;
|
||||
} else {
|
||||
free(fkeyword);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* parse.h
|
||||
*
|
||||
* a Net::DNS like library for C
|
||||
* LibDNS Team @ NLnet Labs
|
||||
* (c) NLnet Labs, 2005-2006
|
||||
* See the file LICENSE for the license
|
||||
*/
|
||||
|
||||
#ifndef GLDNS_PARSE_H
|
||||
#define GLDNS_PARSE_H
|
||||
|
||||
struct gldns_buffer;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define GLDNS_PARSE_SKIP_SPACE "\f\n\r\v"
|
||||
#define GLDNS_PARSE_NORMAL " \f\n\r\t\v"
|
||||
#define GLDNS_PARSE_NO_NL " \t"
|
||||
#define GLDNS_MAX_LINELEN 10230
|
||||
#define GLDNS_MAX_KEYWORDLEN 32
|
||||
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* Contains some low-level parsing functions, mostly used in the _frm_str
|
||||
* family of functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* different type of directives in zone files
|
||||
* We now deal with $TTL, $ORIGIN and $INCLUDE.
|
||||
* The latter is not implemented in ldns (yet)
|
||||
*/
|
||||
enum gldns_enum_directive
|
||||
{
|
||||
GLDNS_DIR_TTL,
|
||||
GLDNS_DIR_ORIGIN,
|
||||
GLDNS_DIR_INCLUDE
|
||||
};
|
||||
typedef enum gldns_enum_directive gldns_directive;
|
||||
|
||||
/**
|
||||
* returns a token/char from the stream F.
|
||||
* This function deals with ( and ) in the stream,
|
||||
* and ignores them when encountered
|
||||
* \param[in] *f the file to read from
|
||||
* \param[out] *token the read token is put here
|
||||
* \param[in] *delim chars at which the parsing should stop
|
||||
* \param[in] *limit how much to read. If 0 the builtin maximum is used
|
||||
* \return 0 on error of EOF of the stream F. Otherwise return the length of what is read
|
||||
*/
|
||||
ssize_t gldns_fget_token(FILE *f, char *token, const char *delim, size_t limit);
|
||||
|
||||
/**
|
||||
* returns a token/char from the stream F.
|
||||
* This function deals with ( and ) in the stream,
|
||||
* and ignores when it finds them.
|
||||
* \param[in] *f the file to read from
|
||||
* \param[out] *token the token is put here
|
||||
* \param[in] *delim chars at which the parsing should stop
|
||||
* \param[in] *limit how much to read. If 0 use builtin maximum
|
||||
* \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
|
||||
* \return 0 on error of EOF of F otherwise return the length of what is read
|
||||
*/
|
||||
ssize_t gldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr);
|
||||
|
||||
/**
|
||||
* returns a token/char from the buffer b.
|
||||
* This function deals with ( and ) in the buffer,
|
||||
* and ignores when it finds them.
|
||||
* \param[in] *b the buffer to read from
|
||||
* \param[out] *token the token is put here
|
||||
* \param[in] *delim chars at which the parsing should stop
|
||||
* \param[in] *limit how much to read. If 0 the builtin maximum is used
|
||||
* \param[in] *par if you pass nonNULL, set to 0 on first call, the parenthesis
|
||||
* state is stored in it, for use on next call. User must check it is back
|
||||
* to zero after last bget in string (for parse error). If you pass NULL,
|
||||
* the entire parenthesized string is read in.
|
||||
* \param[in] skipw string with whitespace to skip before the start of the
|
||||
* token, like " ", or " \t", or NULL for none.
|
||||
* \returns 0 on error of EOF of b. Otherwise return the length of what is read
|
||||
*/
|
||||
ssize_t gldns_bget_token_par(struct gldns_buffer *b, char *token, const char *delim, size_t limit, int* par, const char* skipw);
|
||||
|
||||
/**
|
||||
* returns a token/char from the buffer b.
|
||||
* This function deals with ( and ) in the buffer,
|
||||
* and ignores when it finds them.
|
||||
* \param[in] *b the buffer to read from
|
||||
* \param[out] *token the token is put here
|
||||
* \param[in] *delim chars at which the parsing should stop
|
||||
* \param[in] *limit how much to read. If 0 the builtin maximum is used
|
||||
* \returns 0 on error of EOF of b. Otherwise return the length of what is read
|
||||
*/
|
||||
ssize_t gldns_bget_token(struct gldns_buffer *b, char *token, const char *delim, size_t limit);
|
||||
|
||||
/*
|
||||
* searches for keyword and delim in a file. Gives everything back
|
||||
* after the keyword + k_del until we hit d_del
|
||||
* \param[in] f file pointer to read from
|
||||
* \param[in] keyword keyword to look for
|
||||
* \param[in] k_del keyword delimeter
|
||||
* \param[out] data the data found
|
||||
* \param[in] d_del the data delimeter
|
||||
* \param[in] data_limit maximum size the the data buffer
|
||||
* \return the number of character read
|
||||
*/
|
||||
ssize_t gldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit);
|
||||
|
||||
/*
|
||||
* searches for keyword and delim. Gives everything back
|
||||
* after the keyword + k_del until we hit d_del
|
||||
* \param[in] f file pointer to read from
|
||||
* \param[in] keyword keyword to look for
|
||||
* \param[in] k_del keyword delimeter
|
||||
* \param[out] data the data found
|
||||
* \param[in] d_del the data delimeter
|
||||
* \param[in] data_limit maximum size the the data buffer
|
||||
* \param[in] line_nr pointer to an integer containing the current line number (for
|
||||
debugging purposes)
|
||||
* \return the number of character read
|
||||
*/
|
||||
ssize_t gldns_fget_keyword_data_l(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit, int *line_nr);
|
||||
|
||||
/*
|
||||
* searches for keyword and delim in a buffer. Gives everything back
|
||||
* after the keyword + k_del until we hit d_del
|
||||
* \param[in] b buffer pointer to read from
|
||||
* \param[in] keyword keyword to look for
|
||||
* \param[in] k_del keyword delimeter
|
||||
* \param[out] data the data found
|
||||
* \param[in] d_del the data delimeter
|
||||
* \param[in] data_limit maximum size the the data buffer
|
||||
* \return the number of character read
|
||||
*/
|
||||
ssize_t gldns_bget_keyword_data(struct gldns_buffer *b, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit);
|
||||
|
||||
/**
|
||||
* returns the next character from a buffer. Advances the position pointer with 1.
|
||||
* When end of buffer is reached returns EOF. This is the buffer's equivalent
|
||||
* for getc().
|
||||
* \param[in] *buffer buffer to read from
|
||||
* \return EOF on failure otherwise return the character
|
||||
*/
|
||||
int gldns_bgetc(struct gldns_buffer *buffer);
|
||||
|
||||
/**
|
||||
* skips all of the characters in the given string in the buffer, moving
|
||||
* the position to the first character that is not in *s.
|
||||
* \param[in] *buffer buffer to use
|
||||
* \param[in] *s characters to skip
|
||||
* \return void
|
||||
*/
|
||||
void gldns_bskipcs(struct gldns_buffer *buffer, const char *s);
|
||||
|
||||
/**
|
||||
* skips all of the characters in the given string in the fp, moving
|
||||
* the position to the first character that is not in *s.
|
||||
* \param[in] *fp file to use
|
||||
* \param[in] *s characters to skip
|
||||
* \return void
|
||||
*/
|
||||
void gldns_fskipcs(FILE *fp, const char *s);
|
||||
|
||||
|
||||
/**
|
||||
* skips all of the characters in the given string in the fp, moving
|
||||
* the position to the first character that is not in *s.
|
||||
* \param[in] *fp file to use
|
||||
* \param[in] *s characters to skip
|
||||
* \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
|
||||
* \return void
|
||||
*/
|
||||
void gldns_fskipcs_l(FILE *fp, const char *s, int *line_nr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GLDNS_PARSE_H */
|
|
@ -0,0 +1,726 @@
|
|||
/*
|
||||
* parseutil.c - parse utilities for string and wire conversion
|
||||
*
|
||||
* (c) NLnet Labs, 2004-2006
|
||||
*
|
||||
* See the file LICENSE for the license
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* Utility functions for parsing, base32(DNS variant) and base64 encoding
|
||||
* and decoding, Hex, Time units, Escape codes.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "gldns/parseutil.h"
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
|
||||
gldns_lookup_table *
|
||||
gldns_lookup_by_name(gldns_lookup_table *table, const char *name)
|
||||
{
|
||||
while (table->name != NULL) {
|
||||
if (strcasecmp(name, table->name) == 0)
|
||||
return table;
|
||||
table++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gldns_lookup_table *
|
||||
gldns_lookup_by_id(gldns_lookup_table *table, int id)
|
||||
{
|
||||
while (table->name != NULL) {
|
||||
if (table->id == id)
|
||||
return table;
|
||||
table++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Number of days per month (except for February in leap years). */
|
||||
static const int mdays[] = {
|
||||
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
};
|
||||
|
||||
#define GLDNS_MOD(x,y) (((x) % (y) < 0) ? ((x) % (y) + (y)) : ((x) % (y)))
|
||||
#define GLDNS_DIV(x,y) (((x) % (y) < 0) ? ((x) / (y) - 1 ) : ((x) / (y)))
|
||||
|
||||
static int
|
||||
is_leap_year(int year)
|
||||
{
|
||||
return GLDNS_MOD(year, 4) == 0 && (GLDNS_MOD(year, 100) != 0
|
||||
|| GLDNS_MOD(year, 400) == 0);
|
||||
}
|
||||
|
||||
static int
|
||||
leap_days(int y1, int y2)
|
||||
{
|
||||
--y1;
|
||||
--y2;
|
||||
return (GLDNS_DIV(y2, 4) - GLDNS_DIV(y1, 4)) -
|
||||
(GLDNS_DIV(y2, 100) - GLDNS_DIV(y1, 100)) +
|
||||
(GLDNS_DIV(y2, 400) - GLDNS_DIV(y1, 400));
|
||||
}
|
||||
|
||||
/*
|
||||
* Code adapted from Python 2.4.1 sources (Lib/calendar.py).
|
||||
*/
|
||||
time_t
|
||||
gldns_mktime_from_utc(const struct tm *tm)
|
||||
{
|
||||
int year = 1900 + tm->tm_year;
|
||||
time_t days = 365 * ((time_t) year - 1970) + leap_days(1970, year);
|
||||
time_t hours;
|
||||
time_t minutes;
|
||||
time_t seconds;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < tm->tm_mon; ++i) {
|
||||
days += mdays[i];
|
||||
}
|
||||
if (tm->tm_mon > 1 && is_leap_year(year)) {
|
||||
++days;
|
||||
}
|
||||
days += tm->tm_mday - 1;
|
||||
|
||||
hours = days * 24 + tm->tm_hour;
|
||||
minutes = hours * 60 + tm->tm_min;
|
||||
seconds = minutes * 60 + tm->tm_sec;
|
||||
|
||||
return seconds;
|
||||
}
|
||||
|
||||
#if SIZEOF_TIME_T <= 4
|
||||
|
||||
static void
|
||||
gldns_year_and_yday_from_days_since_epoch(int64_t days, struct tm *result)
|
||||
{
|
||||
int year = 1970;
|
||||
int new_year;
|
||||
|
||||
while (days < 0 || days >= (int64_t) (is_leap_year(year) ? 366 : 365)) {
|
||||
new_year = year + (int) GLDNS_DIV(days, 365);
|
||||
days -= (new_year - year) * 365;
|
||||
days -= leap_days(year, new_year);
|
||||
year = new_year;
|
||||
}
|
||||
result->tm_year = year;
|
||||
result->tm_yday = (int) days;
|
||||
}
|
||||
|
||||
/* Number of days per month in a leap year. */
|
||||
static const int leap_year_mdays[] = {
|
||||
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
};
|
||||
|
||||
static void
|
||||
gldns_mon_and_mday_from_year_and_yday(struct tm *result)
|
||||
{
|
||||
int idays = result->tm_yday;
|
||||
const int *mon_lengths = is_leap_year(result->tm_year) ?
|
||||
leap_year_mdays : mdays;
|
||||
|
||||
result->tm_mon = 0;
|
||||
while (idays >= mon_lengths[result->tm_mon]) {
|
||||
idays -= mon_lengths[result->tm_mon++];
|
||||
}
|
||||
result->tm_mday = idays + 1;
|
||||
}
|
||||
|
||||
static void
|
||||
gldns_wday_from_year_and_yday(struct tm *result)
|
||||
{
|
||||
result->tm_wday = 4 /* 1-1-1970 was a thursday */
|
||||
+ GLDNS_MOD((result->tm_year - 1970), 7) * GLDNS_MOD(365, 7)
|
||||
+ leap_days(1970, result->tm_year)
|
||||
+ result->tm_yday;
|
||||
result->tm_wday = GLDNS_MOD(result->tm_wday, 7);
|
||||
if (result->tm_wday < 0) {
|
||||
result->tm_wday += 7;
|
||||
}
|
||||
}
|
||||
|
||||
static struct tm *
|
||||
gldns_gmtime64_r(int64_t clock, struct tm *result)
|
||||
{
|
||||
result->tm_isdst = 0;
|
||||
result->tm_sec = (int) GLDNS_MOD(clock, 60);
|
||||
clock = GLDNS_DIV(clock, 60);
|
||||
result->tm_min = (int) GLDNS_MOD(clock, 60);
|
||||
clock = GLDNS_DIV(clock, 60);
|
||||
result->tm_hour = (int) GLDNS_MOD(clock, 24);
|
||||
clock = GLDNS_DIV(clock, 24);
|
||||
|
||||
gldns_year_and_yday_from_days_since_epoch(clock, result);
|
||||
gldns_mon_and_mday_from_year_and_yday(result);
|
||||
gldns_wday_from_year_and_yday(result);
|
||||
result->tm_year -= 1900;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* SIZEOF_TIME_T <= 4 */
|
||||
|
||||
static int64_t
|
||||
gldns_serial_arithmitics_time(int32_t time, time_t now)
|
||||
{
|
||||
int32_t offset = time - (int32_t) now;
|
||||
return (int64_t) now + offset;
|
||||
}
|
||||
|
||||
struct tm *
|
||||
gldns_serial_arithmitics_gmtime_r(int32_t time, time_t now, struct tm *result)
|
||||
{
|
||||
#if SIZEOF_TIME_T <= 4
|
||||
int64_t secs_since_epoch = gldns_serial_arithmitics_time(time, now);
|
||||
return gldns_gmtime64_r(secs_since_epoch, result);
|
||||
#else
|
||||
time_t secs_since_epoch = gldns_serial_arithmitics_time(time, now);
|
||||
return gmtime_r(&secs_since_epoch, result);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
gldns_hexdigit_to_int(char ch)
|
||||
{
|
||||
switch (ch) {
|
||||
case '0': return 0;
|
||||
case '1': return 1;
|
||||
case '2': return 2;
|
||||
case '3': return 3;
|
||||
case '4': return 4;
|
||||
case '5': return 5;
|
||||
case '6': return 6;
|
||||
case '7': return 7;
|
||||
case '8': return 8;
|
||||
case '9': return 9;
|
||||
case 'a': case 'A': return 10;
|
||||
case 'b': case 'B': return 11;
|
||||
case 'c': case 'C': return 12;
|
||||
case 'd': case 'D': return 13;
|
||||
case 'e': case 'E': return 14;
|
||||
case 'f': case 'F': return 15;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t
|
||||
gldns_str2period(const char *nptr, const char **endptr)
|
||||
{
|
||||
int sign = 0;
|
||||
uint32_t i = 0;
|
||||
uint32_t seconds = 0;
|
||||
|
||||
for(*endptr = nptr; **endptr; (*endptr)++) {
|
||||
switch (**endptr) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
break;
|
||||
case '-':
|
||||
if(sign == 0) {
|
||||
sign = -1;
|
||||
} else {
|
||||
return seconds;
|
||||
}
|
||||
break;
|
||||
case '+':
|
||||
if(sign == 0) {
|
||||
sign = 1;
|
||||
} else {
|
||||
return seconds;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
case 'S':
|
||||
seconds += i;
|
||||
i = 0;
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
seconds += i * 60;
|
||||
i = 0;
|
||||
break;
|
||||
case 'h':
|
||||
case 'H':
|
||||
seconds += i * 60 * 60;
|
||||
i = 0;
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
seconds += i * 60 * 60 * 24;
|
||||
i = 0;
|
||||
break;
|
||||
case 'w':
|
||||
case 'W':
|
||||
seconds += i * 60 * 60 * 24 * 7;
|
||||
i = 0;
|
||||
break;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
i *= 10;
|
||||
i += (**endptr - '0');
|
||||
break;
|
||||
default:
|
||||
seconds += i;
|
||||
/* disregard signedness */
|
||||
return seconds;
|
||||
}
|
||||
}
|
||||
seconds += i;
|
||||
/* disregard signedness */
|
||||
return seconds;
|
||||
}
|
||||
|
||||
int
|
||||
gldns_parse_escape(uint8_t *ch_p, const char** str_p)
|
||||
{
|
||||
uint16_t val;
|
||||
|
||||
if ((*str_p)[0] && isdigit((*str_p)[0]) &&
|
||||
(*str_p)[1] && isdigit((*str_p)[1]) &&
|
||||
(*str_p)[2] && isdigit((*str_p)[2])) {
|
||||
|
||||
val = (uint16_t)(((*str_p)[0] - '0') * 100 +
|
||||
((*str_p)[1] - '0') * 10 +
|
||||
((*str_p)[2] - '0'));
|
||||
|
||||
if (val > 255) {
|
||||
goto error;
|
||||
}
|
||||
*ch_p = (uint8_t)val;
|
||||
*str_p += 3;
|
||||
return 1;
|
||||
|
||||
} else if ((*str_p)[0] && !isdigit((*str_p)[0])) {
|
||||
|
||||
*ch_p = (uint8_t)*(*str_p)++;
|
||||
return 1;
|
||||
}
|
||||
error:
|
||||
*str_p = NULL;
|
||||
return 0; /* GLDNS_WIREPARSE_ERR_SYNTAX_BAD_ESCAPE */
|
||||
}
|
||||
|
||||
/** parse one character, with escape codes */
|
||||
int
|
||||
gldns_parse_char(uint8_t *ch_p, const char** str_p)
|
||||
{
|
||||
switch (**str_p) {
|
||||
|
||||
case '\0': return 0;
|
||||
|
||||
case '\\': *str_p += 1;
|
||||
return gldns_parse_escape(ch_p, str_p);
|
||||
|
||||
default: *ch_p = (uint8_t)*(*str_p)++;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
size_t gldns_b32_ntop_calculate_size(size_t src_data_length)
|
||||
{
|
||||
return src_data_length == 0 ? 0 : ((src_data_length - 1) / 5 + 1) * 8;
|
||||
}
|
||||
|
||||
size_t gldns_b32_ntop_calculate_size_no_padding(size_t src_data_length)
|
||||
{
|
||||
return ((src_data_length + 3) * 8 / 5) - 4;
|
||||
}
|
||||
|
||||
static int
|
||||
gldns_b32_ntop_base(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz,
|
||||
int extended_hex, int add_padding)
|
||||
{
|
||||
size_t ret_sz;
|
||||
const char* b32 = extended_hex ? "0123456789abcdefghijklmnopqrstuv"
|
||||
: "abcdefghijklmnopqrstuvwxyz234567";
|
||||
|
||||
size_t c = 0; /* c is used to carry partial base32 character over
|
||||
* byte boundaries for sizes with a remainder.
|
||||
* (i.e. src_sz % 5 != 0)
|
||||
*/
|
||||
|
||||
ret_sz = add_padding ? gldns_b32_ntop_calculate_size(src_sz)
|
||||
: gldns_b32_ntop_calculate_size_no_padding(src_sz);
|
||||
|
||||
/* Do we have enough space? */
|
||||
if (dst_sz < ret_sz + 1)
|
||||
return -1;
|
||||
|
||||
/* We know the size; terminate the string */
|
||||
dst[ret_sz] = '\0';
|
||||
|
||||
/* First process all chunks of five */
|
||||
while (src_sz >= 5) {
|
||||
/* 00000... ........ ........ ........ ........ */
|
||||
dst[0] = b32[(src[0] ) >> 3];
|
||||
|
||||
/* .....111 11...... ........ ........ ........ */
|
||||
dst[1] = b32[(src[0] & 0x07) << 2 | src[1] >> 6];
|
||||
|
||||
/* ........ ..22222. ........ ........ ........ */
|
||||
dst[2] = b32[(src[1] & 0x3e) >> 1];
|
||||
|
||||
/* ........ .......3 3333.... ........ ........ */
|
||||
dst[3] = b32[(src[1] & 0x01) << 4 | src[2] >> 4];
|
||||
|
||||
/* ........ ........ ....4444 4....... ........ */
|
||||
dst[4] = b32[(src[2] & 0x0f) << 1 | src[3] >> 7];
|
||||
|
||||
/* ........ ........ ........ .55555.. ........ */
|
||||
dst[5] = b32[(src[3] & 0x7c) >> 2];
|
||||
|
||||
/* ........ ........ ........ ......66 666..... */
|
||||
dst[6] = b32[(src[3] & 0x03) << 3 | src[4] >> 5];
|
||||
|
||||
/* ........ ........ ........ ........ ...77777 */
|
||||
dst[7] = b32[(src[4] & 0x1f) ];
|
||||
|
||||
src_sz -= 5;
|
||||
src += 5;
|
||||
dst += 8;
|
||||
}
|
||||
/* Process what remains */
|
||||
switch (src_sz) {
|
||||
case 4: /* ........ ........ ........ ......66 666..... */
|
||||
dst[6] = b32[(src[3] & 0x03) << 3];
|
||||
|
||||
/* ........ ........ ........ .55555.. ........ */
|
||||
dst[5] = b32[(src[3] & 0x7c) >> 2];
|
||||
|
||||
/* ........ ........ ....4444 4....... ........ */
|
||||
c = src[3] >> 7 ;
|
||||
case 3: dst[4] = b32[(src[2] & 0x0f) << 1 | c];
|
||||
|
||||
/* ........ .......3 3333.... ........ ........ */
|
||||
c = src[2] >> 4 ;
|
||||
case 2: dst[3] = b32[(src[1] & 0x01) << 4 | c];
|
||||
|
||||
/* ........ ..22222. ........ ........ ........ */
|
||||
dst[2] = b32[(src[1] & 0x3e) >> 1];
|
||||
|
||||
/* .....111 11...... ........ ........ ........ */
|
||||
c = src[1] >> 6 ;
|
||||
case 1: dst[1] = b32[(src[0] & 0x07) << 2 | c];
|
||||
|
||||
/* 00000... ........ ........ ........ ........ */
|
||||
dst[0] = b32[ src[0] >> 3];
|
||||
}
|
||||
/* Add padding */
|
||||
if (add_padding) {
|
||||
switch (src_sz) {
|
||||
case 1: dst[2] = '=';
|
||||
dst[3] = '=';
|
||||
case 2: dst[4] = '=';
|
||||
case 3: dst[5] = '=';
|
||||
dst[6] = '=';
|
||||
case 4: dst[7] = '=';
|
||||
}
|
||||
}
|
||||
return (int)ret_sz;
|
||||
}
|
||||
|
||||
int
|
||||
gldns_b32_ntop(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz)
|
||||
{
|
||||
return gldns_b32_ntop_base(src, src_sz, dst, dst_sz, 0, 1);
|
||||
}
|
||||
|
||||
int
|
||||
gldns_b32_ntop_extended_hex(const uint8_t* src, size_t src_sz,
|
||||
char* dst, size_t dst_sz)
|
||||
{
|
||||
return gldns_b32_ntop_base(src, src_sz, dst, dst_sz, 1, 1);
|
||||
}
|
||||
|
||||
size_t gldns_b32_pton_calculate_size(size_t src_text_length)
|
||||
{
|
||||
return src_text_length * 5 / 8;
|
||||
}
|
||||
|
||||
static int
|
||||
gldns_b32_pton_base(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz,
|
||||
int extended_hex, int check_padding)
|
||||
{
|
||||
size_t i = 0;
|
||||
char ch = '\0';
|
||||
uint8_t buf[8];
|
||||
uint8_t* start = dst;
|
||||
|
||||
while (src_sz) {
|
||||
/* Collect 8 characters in buf (if possible) */
|
||||
for (i = 0; i < 8; i++) {
|
||||
|
||||
do {
|
||||
ch = *src++;
|
||||
--src_sz;
|
||||
|
||||
} while (isspace(ch) && src_sz > 0);
|
||||
|
||||
if (ch == '=' || ch == '\0')
|
||||
break;
|
||||
|
||||
else if (extended_hex)
|
||||
|
||||
if (ch >= '0' && ch <= '9')
|
||||
buf[i] = (uint8_t)ch - '0';
|
||||
else if (ch >= 'a' && ch <= 'v')
|
||||
buf[i] = (uint8_t)ch - 'a' + 10;
|
||||
else if (ch >= 'A' && ch <= 'V')
|
||||
buf[i] = (uint8_t)ch - 'A' + 10;
|
||||
else
|
||||
return -1;
|
||||
|
||||
else if (ch >= 'a' && ch <= 'z')
|
||||
buf[i] = (uint8_t)ch - 'a';
|
||||
else if (ch >= 'A' && ch <= 'Z')
|
||||
buf[i] = (uint8_t)ch - 'A';
|
||||
else if (ch >= '2' && ch <= '7')
|
||||
buf[i] = (uint8_t)ch - '2' + 26;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
/* Less that 8 characters. We're done. */
|
||||
if (i < 8)
|
||||
break;
|
||||
|
||||
/* Enough space available at the destination? */
|
||||
if (dst_sz < 5)
|
||||
return -1;
|
||||
|
||||
/* 00000... ........ ........ ........ ........ */
|
||||
/* .....111 11...... ........ ........ ........ */
|
||||
dst[0] = buf[0] << 3 | buf[1] >> 2;
|
||||
|
||||
/* .....111 11...... ........ ........ ........ */
|
||||
/* ........ ..22222. ........ ........ ........ */
|
||||
/* ........ .......3 3333.... ........ ........ */
|
||||
dst[1] = buf[1] << 6 | buf[2] << 1 | buf[3] >> 4;
|
||||
|
||||
/* ........ .......3 3333.... ........ ........ */
|
||||
/* ........ ........ ....4444 4....... ........ */
|
||||
dst[2] = buf[3] << 4 | buf[4] >> 1;
|
||||
|
||||
/* ........ ........ ....4444 4....... ........ */
|
||||
/* ........ ........ ........ .55555.. ........ */
|
||||
/* ........ ........ ........ ......66 666..... */
|
||||
dst[3] = buf[4] << 7 | buf[5] << 2 | buf[6] >> 3;
|
||||
|
||||
/* ........ ........ ........ ......66 666..... */
|
||||
/* ........ ........ ........ ........ ...77777 */
|
||||
dst[4] = buf[6] << 5 | buf[7];
|
||||
|
||||
dst += 5;
|
||||
dst_sz -= 5;
|
||||
}
|
||||
/* Not ending on a eight byte boundary? */
|
||||
if (i > 0 && i < 8) {
|
||||
|
||||
/* Enough space available at the destination? */
|
||||
if (dst_sz < (i + 1) / 2)
|
||||
return -1;
|
||||
|
||||
switch (i) {
|
||||
case 7: /* ........ ........ ........ ......66 666..... */
|
||||
/* ........ ........ ........ .55555.. ........ */
|
||||
/* ........ ........ ....4444 4....... ........ */
|
||||
dst[3] = buf[4] << 7 | buf[5] << 2 | buf[6] >> 3;
|
||||
|
||||
case 5: /* ........ ........ ....4444 4....... ........ */
|
||||
/* ........ .......3 3333.... ........ ........ */
|
||||
dst[2] = buf[3] << 4 | buf[4] >> 1;
|
||||
|
||||
case 4: /* ........ .......3 3333.... ........ ........ */
|
||||
/* ........ ..22222. ........ ........ ........ */
|
||||
/* .....111 11...... ........ ........ ........ */
|
||||
dst[1] = buf[1] << 6 | buf[2] << 1 | buf[3] >> 4;
|
||||
|
||||
case 2: /* .....111 11...... ........ ........ ........ */
|
||||
/* 00000... ........ ........ ........ ........ */
|
||||
dst[0] = buf[0] << 3 | buf[1] >> 2;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
dst += (i + 1) / 2;
|
||||
|
||||
if (check_padding) {
|
||||
/* Check remaining padding characters */
|
||||
if (ch != '=')
|
||||
return -1;
|
||||
|
||||
/* One down, 8 - i - 1 more to come... */
|
||||
for (i = 8 - i - 1; i > 0; i--) {
|
||||
|
||||
do {
|
||||
if (src_sz == 0)
|
||||
return -1;
|
||||
ch = *src++;
|
||||
src_sz--;
|
||||
|
||||
} while (isspace(ch));
|
||||
|
||||
if (ch != '=')
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dst - start;
|
||||
}
|
||||
|
||||
int
|
||||
gldns_b32_pton(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz)
|
||||
{
|
||||
return gldns_b32_pton_base(src, src_sz, dst, dst_sz, 0, 1);
|
||||
}
|
||||
|
||||
int
|
||||
gldns_b32_pton_extended_hex(const char* src, size_t src_sz,
|
||||
uint8_t* dst, size_t dst_sz)
|
||||
{
|
||||
return gldns_b32_pton_base(src, src_sz, dst, dst_sz, 1, 1);
|
||||
}
|
||||
|
||||
size_t gldns_b64_ntop_calculate_size(size_t srcsize)
|
||||
{
|
||||
return ((((srcsize + 2) / 3) * 4) + 1);
|
||||
}
|
||||
|
||||
/* RFC 1521, section 5.2.
|
||||
*
|
||||
* The encoding process represents 24-bit groups of input bits as output
|
||||
* strings of 4 encoded characters. Proceeding from left to right, a
|
||||
* 24-bit input group is formed by concatenating 3 8-bit input groups.
|
||||
* These 24 bits are then treated as 4 concatenated 6-bit groups, each
|
||||
* of which is translated into a single digit in the base64 alphabet.
|
||||
*
|
||||
* This routine does not insert spaces or linebreaks after 76 characters.
|
||||
*/
|
||||
int gldns_b64_ntop(uint8_t const *src, size_t srclength,
|
||||
char *target, size_t targsize)
|
||||
{
|
||||
const char* b64 =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
const char pad64 = '=';
|
||||
size_t i = 0, o = 0;
|
||||
if(targsize < gldns_b64_ntop_calculate_size(srclength))
|
||||
return -1;
|
||||
/* whole chunks: xxxxxxyy yyyyzzzz zzwwwwww */
|
||||
while(i+3 <= srclength) {
|
||||
if(o+4 > targsize) return -1;
|
||||
target[o] = b64[src[i] >> 2];
|
||||
target[o+1] = b64[ ((src[i]&0x03)<<4) | (src[i+1]>>4) ];
|
||||
target[o+2] = b64[ ((src[i+1]&0x0f)<<2) | (src[i+2]>>6) ];
|
||||
target[o+3] = b64[ (src[i+2]&0x3f) ];
|
||||
i += 3;
|
||||
o += 4;
|
||||
}
|
||||
/* remainder */
|
||||
switch(srclength - i) {
|
||||
case 2:
|
||||
/* two at end, converted into A B C = */
|
||||
target[o] = b64[src[i] >> 2];
|
||||
target[o+1] = b64[ ((src[i]&0x03)<<4) | (src[i+1]>>4) ];
|
||||
target[o+2] = b64[ ((src[i+1]&0x0f)<<2) ];
|
||||
target[o+3] = pad64;
|
||||
i += 2;
|
||||
o += 4;
|
||||
break;
|
||||
case 1:
|
||||
/* one at end, converted into A B = = */
|
||||
target[o] = b64[src[i] >> 2];
|
||||
target[o+1] = b64[ ((src[i]&0x03)<<4) ];
|
||||
target[o+2] = pad64;
|
||||
target[o+3] = pad64;
|
||||
i += 1;
|
||||
o += 4;
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
/* nothing */
|
||||
break;
|
||||
}
|
||||
/* assert: i == srclength */
|
||||
if(o+1 > targsize) return -1;
|
||||
target[o] = 0;
|
||||
return (int)o;
|
||||
}
|
||||
|
||||
size_t gldns_b64_pton_calculate_size(size_t srcsize)
|
||||
{
|
||||
return (((((srcsize + 3) / 4) * 3)) + 1);
|
||||
}
|
||||
|
||||
int gldns_b64_pton(char const *src, uint8_t *target, size_t targsize)
|
||||
{
|
||||
const uint8_t pad64 = 64; /* is 64th in the b64 array */
|
||||
const char* s = src;
|
||||
uint8_t in[4];
|
||||
size_t o = 0, incount = 0;
|
||||
|
||||
while(*s) {
|
||||
/* skip any character that is not base64 */
|
||||
/* conceptually we do:
|
||||
const char* b64 = pad'=' is appended to array
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
const char* d = strchr(b64, *s++);
|
||||
and use d-b64;
|
||||
*/
|
||||
char d = *s++;
|
||||
if(d <= 'Z' && d >= 'A')
|
||||
d -= 'A';
|
||||
else if(d <= 'z' && d >= 'a')
|
||||
d = d - 'a' + 26;
|
||||
else if(d <= '9' && d >= '0')
|
||||
d = d - '0' + 52;
|
||||
else if(d == '+')
|
||||
d = 62;
|
||||
else if(d == '/')
|
||||
d = 63;
|
||||
else if(d == '=')
|
||||
d = 64;
|
||||
else continue;
|
||||
in[incount++] = (uint8_t)d;
|
||||
if(incount != 4)
|
||||
continue;
|
||||
/* process whole block of 4 characters into 3 output bytes */
|
||||
if(in[3] == pad64 && in[2] == pad64) { /* A B = = */
|
||||
if(o+1 > targsize)
|
||||
return -1;
|
||||
target[o] = (in[0]<<2) | ((in[1]&0x30)>>4);
|
||||
o += 1;
|
||||
break; /* we are done */
|
||||
} else if(in[3] == pad64) { /* A B C = */
|
||||
if(o+2 > targsize)
|
||||
return -1;
|
||||
target[o] = (in[0]<<2) | ((in[1]&0x30)>>4);
|
||||
target[o+1]= ((in[1]&0x0f)<<4) | ((in[2]&0x3c)>>2);
|
||||
o += 2;
|
||||
break; /* we are done */
|
||||
} else {
|
||||
if(o+3 > targsize)
|
||||
return -1;
|
||||
/* write xxxxxxyy yyyyzzzz zzwwwwww */
|
||||
target[o] = (in[0]<<2) | ((in[1]&0x30)>>4);
|
||||
target[o+1]= ((in[1]&0x0f)<<4) | ((in[2]&0x3c)>>2);
|
||||
target[o+2]= ((in[2]&0x03)<<6) | in[3];
|
||||
o += 3;
|
||||
}
|
||||
incount = 0;
|
||||
}
|
||||
return (int)o;
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* parseutil.h - parse utilities for string and wire conversion
|
||||
*
|
||||
* (c) NLnet Labs, 2004
|
||||
*
|
||||
* See the file LICENSE for the license
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* Utility functions for parsing, base32(DNS variant) and base64 encoding
|
||||
* and decoding, Hex, Time units, Escape codes.
|
||||
*/
|
||||
|
||||
#ifndef GLDNS_PARSEUTIL_H
|
||||
#define GLDNS_PARSEUTIL_H
|
||||
struct tm;
|
||||
|
||||
/**
|
||||
* A general purpose lookup table
|
||||
*
|
||||
* Lookup tables are arrays of (id, name) pairs,
|
||||
* So you can for instance lookup the RCODE 3, which is "NXDOMAIN",
|
||||
* and vice versa. The lookup tables themselves are defined wherever needed,
|
||||
* for instance in host2str.c
|
||||
*/
|
||||
struct gldns_struct_lookup_table {
|
||||
int id;
|
||||
const char *name;
|
||||
};
|
||||
typedef struct gldns_struct_lookup_table gldns_lookup_table;
|
||||
|
||||
/**
|
||||
* Looks up the table entry by name, returns NULL if not found.
|
||||
* \param[in] table the lookup table to search in
|
||||
* \param[in] name what to search for
|
||||
* \return the item found
|
||||
*/
|
||||
gldns_lookup_table *gldns_lookup_by_name(gldns_lookup_table table[],
|
||||
const char *name);
|
||||
/**
|
||||
* Looks up the table entry by id, returns NULL if not found.
|
||||
* \param[in] table the lookup table to search in
|
||||
* \param[in] id what to search for
|
||||
* \return the item found
|
||||
*/
|
||||
gldns_lookup_table *gldns_lookup_by_id(gldns_lookup_table table[], int id);
|
||||
|
||||
/**
|
||||
* Convert TM to seconds since epoch (midnight, January 1st, 1970).
|
||||
* Like timegm(3), which is not always available.
|
||||
* \param[in] tm a struct tm* with the date
|
||||
* \return the seconds since epoch
|
||||
*/
|
||||
time_t gldns_mktime_from_utc(const struct tm *tm);
|
||||
|
||||
/**
|
||||
* The function interprets time as the number of seconds since epoch
|
||||
* with respect to now using serial arithmitics (rfc1982).
|
||||
* That number of seconds is then converted to broken-out time information.
|
||||
* This is especially usefull when converting the inception and expiration
|
||||
* fields of RRSIG records.
|
||||
*
|
||||
* \param[in] time number of seconds since epoch (midnight, January 1st, 1970)
|
||||
* to be intepreted as a serial arithmitics number relative to now.
|
||||
* \param[in] now number of seconds since epoch (midnight, January 1st, 1970)
|
||||
* to which the time value is compared to determine the final value.
|
||||
* \param[out] result the struct with the broken-out time information
|
||||
* \return result on success or NULL on error
|
||||
*/
|
||||
struct tm * gldns_serial_arithmitics_gmtime_r(int32_t time, time_t now, struct tm *result);
|
||||
|
||||
/**
|
||||
* converts a ttl value (like 5d2h) to a long.
|
||||
* \param[in] nptr the start of the string
|
||||
* \param[out] endptr points to the last char in case of error
|
||||
* \return the convert duration value
|
||||
*/
|
||||
uint32_t gldns_str2period(const char *nptr, const char **endptr);
|
||||
|
||||
/**
|
||||
* Returns the int value of the given (hex) digit
|
||||
* \param[in] ch the hex char to convert
|
||||
* \return the converted decimal value
|
||||
*/
|
||||
int gldns_hexdigit_to_int(char ch);
|
||||
|
||||
/**
|
||||
* calculates the size needed to store the result of b64_ntop
|
||||
*/
|
||||
size_t gldns_b64_ntop_calculate_size(size_t srcsize);
|
||||
|
||||
int gldns_b64_ntop(uint8_t const *src, size_t srclength,
|
||||
char *target, size_t targsize);
|
||||
|
||||
/**
|
||||
* calculates the size needed to store the result of gldns_b64_pton
|
||||
*/
|
||||
size_t gldns_b64_pton_calculate_size(size_t srcsize);
|
||||
|
||||
int gldns_b64_pton(char const *src, uint8_t *target, size_t targsize);
|
||||
|
||||
/**
|
||||
* calculates the size needed to store the result of b32_ntop
|
||||
*/
|
||||
size_t gldns_b32_ntop_calculate_size(size_t src_data_length);
|
||||
|
||||
size_t gldns_b32_ntop_calculate_size_no_padding(size_t src_data_length);
|
||||
|
||||
int gldns_b32_ntop(const uint8_t* src_data, size_t src_data_length,
|
||||
char* target_text_buffer, size_t target_text_buffer_size);
|
||||
|
||||
int gldns_b32_ntop_extended_hex(const uint8_t* src_data, size_t src_data_length,
|
||||
char* target_text_buffer, size_t target_text_buffer_size);
|
||||
|
||||
/**
|
||||
* calculates the size needed to store the result of b32_pton
|
||||
*/
|
||||
size_t gldns_b32_pton_calculate_size(size_t src_text_length);
|
||||
|
||||
int gldns_b32_pton(const char* src_text, size_t src_text_length,
|
||||
uint8_t* target_data_buffer, size_t target_data_buffer_size);
|
||||
|
||||
int gldns_b32_pton_extended_hex(const char* src_text, size_t src_text_length,
|
||||
uint8_t* target_data_buffer, size_t target_data_buffer_size);
|
||||
|
||||
/*
|
||||
* Checks whether the escaped value at **s is an octal value or
|
||||
* a 'normally' escaped character (and not eos)
|
||||
*
|
||||
* @param ch_p: the parsed character
|
||||
* @param str_p: the string. moved along for characters read.
|
||||
* The string pointer at *s is increased by either 0 (on error), 1 (on
|
||||
* normal escapes), or 3 (on octals)
|
||||
*
|
||||
* @return 0 on error
|
||||
*/
|
||||
int gldns_parse_escape(uint8_t *ch_p, const char** str_p);
|
||||
|
||||
/**
|
||||
* Parse one character, with escape codes,
|
||||
* @param ch_p: the parsed character
|
||||
* @param str_p: the string. moved along for characters read.
|
||||
* @return 0 on error
|
||||
*/
|
||||
int gldns_parse_char(uint8_t *ch_p, const char** str_p);
|
||||
|
||||
#endif /* GLDNS_PARSEUTIL_H */
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* pkthdr.h - packet header from wire conversion routines
|
||||
*
|
||||
* a Net::DNS like library for C
|
||||
*
|
||||
* (c) NLnet Labs, 2005-2006
|
||||
*
|
||||
* See the file LICENSE for the license
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* Contains functions that translate dns data from the wire format (as sent
|
||||
* by servers and clients) to the internal structures for the packet header.
|
||||
*/
|
||||
|
||||
#ifndef GLDNS_PKTHDR_H
|
||||
#define GLDNS_PKTHDR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* The length of the header */
|
||||
#define GLDNS_HEADER_SIZE 12
|
||||
|
||||
/* First octet of flags */
|
||||
#define GLDNS_RD_MASK 0x01U
|
||||
#define GLDNS_RD_SHIFT 0
|
||||
#define GLDNS_RD_WIRE(wirebuf) (*(wirebuf+2) & GLDNS_RD_MASK)
|
||||
#define GLDNS_RD_SET(wirebuf) (*(wirebuf+2) |= GLDNS_RD_MASK)
|
||||
#define GLDNS_RD_CLR(wirebuf) (*(wirebuf+2) &= ~GLDNS_RD_MASK)
|
||||
|
||||
#define GLDNS_TC_MASK 0x02U
|
||||
#define GLDNS_TC_SHIFT 1
|
||||
#define GLDNS_TC_WIRE(wirebuf) (*(wirebuf+2) & GLDNS_TC_MASK)
|
||||
#define GLDNS_TC_SET(wirebuf) (*(wirebuf+2) |= GLDNS_TC_MASK)
|
||||
#define GLDNS_TC_CLR(wirebuf) (*(wirebuf+2) &= ~GLDNS_TC_MASK)
|
||||
|
||||
#define GLDNS_AA_MASK 0x04U
|
||||
#define GLDNS_AA_SHIFT 2
|
||||
#define GLDNS_AA_WIRE(wirebuf) (*(wirebuf+2) & GLDNS_AA_MASK)
|
||||
#define GLDNS_AA_SET(wirebuf) (*(wirebuf+2) |= GLDNS_AA_MASK)
|
||||
#define GLDNS_AA_CLR(wirebuf) (*(wirebuf+2) &= ~GLDNS_AA_MASK)
|
||||
|
||||
#define GLDNS_OPCODE_MASK 0x78U
|
||||
#define GLDNS_OPCODE_SHIFT 3
|
||||
#define GLDNS_OPCODE_WIRE(wirebuf) ((*(wirebuf+2) & GLDNS_OPCODE_MASK) >> GLDNS_OPCODE_SHIFT)
|
||||
#define GLDNS_OPCODE_SET(wirebuf, opcode) \
|
||||
(*(wirebuf+2) = ((*(wirebuf+2)) & ~GLDNS_OPCODE_MASK) | ((opcode) << GLDNS_OPCODE_SHIFT))
|
||||
|
||||
#define GLDNS_QR_MASK 0x80U
|
||||
#define GLDNS_QR_SHIFT 7
|
||||
#define GLDNS_QR_WIRE(wirebuf) (*(wirebuf+2) & GLDNS_QR_MASK)
|
||||
#define GLDNS_QR_SET(wirebuf) (*(wirebuf+2) |= GLDNS_QR_MASK)
|
||||
#define GLDNS_QR_CLR(wirebuf) (*(wirebuf+2) &= ~GLDNS_QR_MASK)
|
||||
|
||||
/* Second octet of flags */
|
||||
#define GLDNS_RCODE_MASK 0x0fU
|
||||
#define GLDNS_RCODE_SHIFT 0
|
||||
#define GLDNS_RCODE_WIRE(wirebuf) (*(wirebuf+3) & GLDNS_RCODE_MASK)
|
||||
#define GLDNS_RCODE_SET(wirebuf, rcode) \
|
||||
(*(wirebuf+3) = ((*(wirebuf+3)) & ~GLDNS_RCODE_MASK) | (rcode))
|
||||
|
||||
#define GLDNS_CD_MASK 0x10U
|
||||
#define GLDNS_CD_SHIFT 4
|
||||
#define GLDNS_CD_WIRE(wirebuf) (*(wirebuf+3) & GLDNS_CD_MASK)
|
||||
#define GLDNS_CD_SET(wirebuf) (*(wirebuf+3) |= GLDNS_CD_MASK)
|
||||
#define GLDNS_CD_CLR(wirebuf) (*(wirebuf+3) &= ~GLDNS_CD_MASK)
|
||||
|
||||
#define GLDNS_AD_MASK 0x20U
|
||||
#define GLDNS_AD_SHIFT 5
|
||||
#define GLDNS_AD_WIRE(wirebuf) (*(wirebuf+3) & GLDNS_AD_MASK)
|
||||
#define GLDNS_AD_SET(wirebuf) (*(wirebuf+3) |= GLDNS_AD_MASK)
|
||||
#define GLDNS_AD_CLR(wirebuf) (*(wirebuf+3) &= ~GLDNS_AD_MASK)
|
||||
|
||||
#define GLDNS_Z_MASK 0x40U
|
||||
#define GLDNS_Z_SHIFT 6
|
||||
#define GLDNS_Z_WIRE(wirebuf) (*(wirebuf+3) & GLDNS_Z_MASK)
|
||||
#define GLDNS_Z_SET(wirebuf) (*(wirebuf+3) |= GLDNS_Z_MASK)
|
||||
#define GLDNS_Z_CLR(wirebuf) (*(wirebuf+3) &= ~GLDNS_Z_MASK)
|
||||
|
||||
#define GLDNS_RA_MASK 0x80U
|
||||
#define GLDNS_RA_SHIFT 7
|
||||
#define GLDNS_RA_WIRE(wirebuf) (*(wirebuf+3) & GLDNS_RA_MASK)
|
||||
#define GLDNS_RA_SET(wirebuf) (*(wirebuf+3) |= GLDNS_RA_MASK)
|
||||
#define GLDNS_RA_CLR(wirebuf) (*(wirebuf+3) &= ~GLDNS_RA_MASK)
|
||||
|
||||
/* Query ID */
|
||||
#define GLDNS_ID_WIRE(wirebuf) (gldns_read_uint16(wirebuf))
|
||||
#define GLDNS_ID_SET(wirebuf, id) (gldns_write_uint16(wirebuf, id))
|
||||
|
||||
/* Counter of the question section */
|
||||
#define GLDNS_QDCOUNT_OFF 4
|
||||
/*
|
||||
#define QDCOUNT(wirebuf) (ntohs(*(uint16_t *)(wirebuf+QDCOUNT_OFF)))
|
||||
*/
|
||||
#define GLDNS_QDCOUNT(wirebuf) (gldns_read_uint16(wirebuf+GLDNS_QDCOUNT_OFF))
|
||||
|
||||
/* Counter of the answer section */
|
||||
#define GLDNS_ANCOUNT_OFF 6
|
||||
#define GLDNS_ANCOUNT(wirebuf) (gldns_read_uint16(wirebuf+GLDNS_ANCOUNT_OFF))
|
||||
|
||||
/* Counter of the authority section */
|
||||
#define GLDNS_NSCOUNT_OFF 8
|
||||
#define GLDNS_NSCOUNT(wirebuf) (gldns_read_uint16(wirebuf+GLDNS_NSCOUNT_OFF))
|
||||
|
||||
/* Counter of the additional section */
|
||||
#define GLDNS_ARCOUNT_OFF 10
|
||||
#define GLDNS_ARCOUNT(wirebuf) (gldns_read_uint16(wirebuf+GLDNS_ARCOUNT_OFF))
|
||||
|
||||
/**
|
||||
* The sections of a packet
|
||||
*/
|
||||
enum gldns_enum_pkt_section {
|
||||
GLDNS_SECTION_QUESTION = 0,
|
||||
GLDNS_SECTION_ANSWER = 1,
|
||||
GLDNS_SECTION_AUTHORITY = 2,
|
||||
GLDNS_SECTION_ADDITIONAL = 3,
|
||||
/** bogus section, if not interested */
|
||||
GLDNS_SECTION_ANY = 4,
|
||||
/** used to get all non-question rrs from a packet */
|
||||
GLDNS_SECTION_ANY_NOQUESTION = 5
|
||||
};
|
||||
typedef enum gldns_enum_pkt_section gldns_pkt_section;
|
||||
|
||||
/* opcodes for pkt's */
|
||||
enum gldns_enum_pkt_opcode {
|
||||
GLDNS_PACKET_QUERY = 0,
|
||||
GLDNS_PACKET_IQUERY = 1,
|
||||
GLDNS_PACKET_STATUS = 2, /* there is no 3?? DNS is weird */
|
||||
GLDNS_PACKET_NOTIFY = 4,
|
||||
GLDNS_PACKET_UPDATE = 5
|
||||
};
|
||||
typedef enum gldns_enum_pkt_opcode gldns_pkt_opcode;
|
||||
|
||||
/* rcodes for pkts */
|
||||
enum gldns_enum_pkt_rcode {
|
||||
GLDNS_RCODE_NOERROR = 0,
|
||||
GLDNS_RCODE_FORMERR = 1,
|
||||
GLDNS_RCODE_SERVFAIL = 2,
|
||||
GLDNS_RCODE_NXDOMAIN = 3,
|
||||
GLDNS_RCODE_NOTIMPL = 4,
|
||||
GLDNS_RCODE_REFUSED = 5,
|
||||
GLDNS_RCODE_YXDOMAIN = 6,
|
||||
GLDNS_RCODE_YXRRSET = 7,
|
||||
GLDNS_RCODE_NXRRSET = 8,
|
||||
GLDNS_RCODE_NOTAUTH = 9,
|
||||
GLDNS_RCODE_NOTZONE = 10
|
||||
};
|
||||
typedef enum gldns_enum_pkt_rcode gldns_pkt_rcode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GLDNS_PKTHDR_H */
|
|
@ -0,0 +1,734 @@
|
|||
/* rrdef.c
|
||||
*
|
||||
* access functions to rr definitions list.
|
||||
* a Net::DNS like library for C
|
||||
* LibDNS Team @ NLnet Labs
|
||||
*
|
||||
* (c) NLnet Labs, 2004-2006
|
||||
* See the file LICENSE for the license
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* Defines resource record types and constants.
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "gldns/rrdef.h"
|
||||
#include "gldns/parseutil.h"
|
||||
|
||||
/* classes */
|
||||
static gldns_lookup_table gldns_rr_classes_data[] = {
|
||||
{ GLDNS_RR_CLASS_IN, "IN" },
|
||||
{ GLDNS_RR_CLASS_CH, "CH" },
|
||||
{ GLDNS_RR_CLASS_HS, "HS" },
|
||||
{ GLDNS_RR_CLASS_NONE, "NONE" },
|
||||
{ GLDNS_RR_CLASS_ANY, "ANY" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
gldns_lookup_table* gldns_rr_classes = gldns_rr_classes_data;
|
||||
|
||||
/* types */
|
||||
static const gldns_rdf_type type_0_wireformat[] = { GLDNS_RDF_TYPE_UNKNOWN };
|
||||
static const gldns_rdf_type type_a_wireformat[] = { GLDNS_RDF_TYPE_A };
|
||||
static const gldns_rdf_type type_ns_wireformat[] = { GLDNS_RDF_TYPE_DNAME };
|
||||
static const gldns_rdf_type type_md_wireformat[] = { GLDNS_RDF_TYPE_DNAME };
|
||||
static const gldns_rdf_type type_mf_wireformat[] = { GLDNS_RDF_TYPE_DNAME };
|
||||
static const gldns_rdf_type type_cname_wireformat[] = { GLDNS_RDF_TYPE_DNAME };
|
||||
static const gldns_rdf_type type_soa_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_INT32,
|
||||
GLDNS_RDF_TYPE_PERIOD, GLDNS_RDF_TYPE_PERIOD, GLDNS_RDF_TYPE_PERIOD,
|
||||
GLDNS_RDF_TYPE_PERIOD
|
||||
};
|
||||
static const gldns_rdf_type type_mb_wireformat[] = { GLDNS_RDF_TYPE_DNAME };
|
||||
static const gldns_rdf_type type_mg_wireformat[] = { GLDNS_RDF_TYPE_DNAME };
|
||||
static const gldns_rdf_type type_mr_wireformat[] = { GLDNS_RDF_TYPE_DNAME };
|
||||
static const gldns_rdf_type type_wks_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_A, GLDNS_RDF_TYPE_WKS
|
||||
};
|
||||
static const gldns_rdf_type type_ptr_wireformat[] = { GLDNS_RDF_TYPE_DNAME };
|
||||
static const gldns_rdf_type type_hinfo_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_STR, GLDNS_RDF_TYPE_STR
|
||||
};
|
||||
static const gldns_rdf_type type_minfo_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
static const gldns_rdf_type type_mx_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
static const gldns_rdf_type type_rp_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
static const gldns_rdf_type type_afsdb_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
static const gldns_rdf_type type_x25_wireformat[] = { GLDNS_RDF_TYPE_STR };
|
||||
static const gldns_rdf_type type_isdn_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_STR, GLDNS_RDF_TYPE_STR
|
||||
};
|
||||
static const gldns_rdf_type type_rt_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
static const gldns_rdf_type type_nsap_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_NSAP
|
||||
};
|
||||
static const gldns_rdf_type type_nsap_ptr_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_STR
|
||||
};
|
||||
static const gldns_rdf_type type_sig_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_TYPE, GLDNS_RDF_TYPE_ALG, GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_INT32,
|
||||
GLDNS_RDF_TYPE_TIME, GLDNS_RDF_TYPE_TIME, GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_B64
|
||||
};
|
||||
static const gldns_rdf_type type_key_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_B64
|
||||
};
|
||||
static const gldns_rdf_type type_px_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
static const gldns_rdf_type type_gpos_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_STR, GLDNS_RDF_TYPE_STR, GLDNS_RDF_TYPE_STR
|
||||
};
|
||||
static const gldns_rdf_type type_aaaa_wireformat[] = { GLDNS_RDF_TYPE_AAAA };
|
||||
static const gldns_rdf_type type_loc_wireformat[] = { GLDNS_RDF_TYPE_LOC };
|
||||
static const gldns_rdf_type type_nxt_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_UNKNOWN
|
||||
};
|
||||
static const gldns_rdf_type type_eid_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_HEX
|
||||
};
|
||||
static const gldns_rdf_type type_nimloc_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_HEX
|
||||
};
|
||||
static const gldns_rdf_type type_srv_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
static const gldns_rdf_type type_atma_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_ATMA
|
||||
};
|
||||
static const gldns_rdf_type type_naptr_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_STR, GLDNS_RDF_TYPE_STR, GLDNS_RDF_TYPE_STR, GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
static const gldns_rdf_type type_kx_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
static const gldns_rdf_type type_cert_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_CERT_ALG, GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_ALG, GLDNS_RDF_TYPE_B64
|
||||
};
|
||||
static const gldns_rdf_type type_a6_wireformat[] = { GLDNS_RDF_TYPE_UNKNOWN };
|
||||
static const gldns_rdf_type type_dname_wireformat[] = { GLDNS_RDF_TYPE_DNAME };
|
||||
static const gldns_rdf_type type_sink_wireformat[] = { GLDNS_RDF_TYPE_INT8,
|
||||
GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_B64
|
||||
};
|
||||
static const gldns_rdf_type type_apl_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_APL
|
||||
};
|
||||
static const gldns_rdf_type type_ds_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_ALG, GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_HEX
|
||||
};
|
||||
static const gldns_rdf_type type_sshfp_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_HEX
|
||||
};
|
||||
static const gldns_rdf_type type_ipseckey_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_IPSECKEY
|
||||
};
|
||||
static const gldns_rdf_type type_rrsig_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_TYPE, GLDNS_RDF_TYPE_ALG, GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_INT32,
|
||||
GLDNS_RDF_TYPE_TIME, GLDNS_RDF_TYPE_TIME, GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_B64
|
||||
};
|
||||
static const gldns_rdf_type type_nsec_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_NSEC
|
||||
};
|
||||
static const gldns_rdf_type type_dhcid_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_B64
|
||||
};
|
||||
static const gldns_rdf_type type_talink_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_DNAME, GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
/* nsec3 is some vars, followed by same type of data of nsec */
|
||||
static const gldns_rdf_type type_nsec3_wireformat[] = {
|
||||
/* GLDNS_RDF_TYPE_NSEC3_VARS, GLDNS_RDF_TYPE_NSEC3_NEXT_OWNER, GLDNS_RDF_TYPE_NSEC*/
|
||||
GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_INT8, GLDNS_RDF_TYPE_INT16, GLDNS_RDF_TYPE_NSEC3_SALT, GLDNS_RDF_TYPE_NSEC3_NEXT_OWNER, GLDNS_RDF_TYPE_NSEC
|
||||
};
|
||||
|
||||
static const gldns_rdf_type type_nsec3param_wireformat[] = {
|
||||
/* GLDNS_RDF_TYPE_NSEC3_PARAMS_VARS*/
|
||||
GLDNS_RDF_TYPE_INT8,
|
||||
GLDNS_RDF_TYPE_INT8,
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_NSEC3_SALT
|
||||
};
|
||||
|
||||
static const gldns_rdf_type type_dnskey_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_INT8,
|
||||
GLDNS_RDF_TYPE_ALG,
|
||||
GLDNS_RDF_TYPE_B64
|
||||
};
|
||||
static const gldns_rdf_type type_tkey_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_DNAME,
|
||||
GLDNS_RDF_TYPE_TIME,
|
||||
GLDNS_RDF_TYPE_TIME,
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_INT16_DATA,
|
||||
GLDNS_RDF_TYPE_INT16_DATA,
|
||||
};
|
||||
static const gldns_rdf_type type_tsig_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_DNAME,
|
||||
GLDNS_RDF_TYPE_TSIGTIME,
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_INT16_DATA,
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_INT16_DATA
|
||||
};
|
||||
static const gldns_rdf_type type_tlsa_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT8,
|
||||
GLDNS_RDF_TYPE_INT8,
|
||||
GLDNS_RDF_TYPE_INT8,
|
||||
GLDNS_RDF_TYPE_HEX
|
||||
};
|
||||
static const gldns_rdf_type type_hip_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_HIP
|
||||
};
|
||||
static const gldns_rdf_type type_nid_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_ILNP64
|
||||
};
|
||||
static const gldns_rdf_type type_l32_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_A
|
||||
};
|
||||
static const gldns_rdf_type type_l64_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_ILNP64
|
||||
};
|
||||
static const gldns_rdf_type type_lp_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_DNAME
|
||||
};
|
||||
static const gldns_rdf_type type_eui48_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_EUI48
|
||||
};
|
||||
static const gldns_rdf_type type_eui64_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_EUI64
|
||||
};
|
||||
#ifdef DRAFT_RRTYPES
|
||||
static const gldns_rdf_type type_uri_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
GLDNS_RDF_TYPE_LONG_STR
|
||||
};
|
||||
#endif
|
||||
static const gldns_rdf_type type_caa_wireformat[] = {
|
||||
GLDNS_RDF_TYPE_INT8,
|
||||
GLDNS_RDF_TYPE_TAG,
|
||||
GLDNS_RDF_TYPE_LONG_STR
|
||||
};
|
||||
|
||||
/* All RR's defined in 1035 are well known and can thus
|
||||
* be compressed. See RFC3597. These RR's are:
|
||||
* CNAME HINFO MB MD MF MG MINFO MR MX NULL NS PTR SOA TXT
|
||||
*/
|
||||
static gldns_rr_descriptor rdata_field_descriptors[] = {
|
||||
/* 0 */
|
||||
{ 0, NULL, 0, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 1 */
|
||||
{GLDNS_RR_TYPE_A, "A", 1, 1, type_a_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 2 */
|
||||
{GLDNS_RR_TYPE_NS, "NS", 1, 1, type_ns_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 1 },
|
||||
/* 3 */
|
||||
{GLDNS_RR_TYPE_MD, "MD", 1, 1, type_md_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 1 },
|
||||
/* 4 */
|
||||
{GLDNS_RR_TYPE_MF, "MF", 1, 1, type_mf_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 1 },
|
||||
/* 5 */
|
||||
{GLDNS_RR_TYPE_CNAME, "CNAME", 1, 1, type_cname_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 1 },
|
||||
/* 6 */
|
||||
{GLDNS_RR_TYPE_SOA, "SOA", 7, 7, type_soa_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 2 },
|
||||
/* 7 */
|
||||
{GLDNS_RR_TYPE_MB, "MB", 1, 1, type_mb_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 1 },
|
||||
/* 8 */
|
||||
{GLDNS_RR_TYPE_MG, "MG", 1, 1, type_mg_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 1 },
|
||||
/* 9 */
|
||||
{GLDNS_RR_TYPE_MR, "MR", 1, 1, type_mr_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 1 },
|
||||
/* 10 */
|
||||
{GLDNS_RR_TYPE_NULL, "NULL", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 11 */
|
||||
{GLDNS_RR_TYPE_WKS, "WKS", 2, 2, type_wks_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 12 */
|
||||
{GLDNS_RR_TYPE_PTR, "PTR", 1, 1, type_ptr_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 1 },
|
||||
/* 13 */
|
||||
{GLDNS_RR_TYPE_HINFO, "HINFO", 2, 2, type_hinfo_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 14 */
|
||||
{GLDNS_RR_TYPE_MINFO, "MINFO", 2, 2, type_minfo_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 2 },
|
||||
/* 15 */
|
||||
{GLDNS_RR_TYPE_MX, "MX", 2, 2, type_mx_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_COMPRESS, 1 },
|
||||
/* 16 */
|
||||
{GLDNS_RR_TYPE_TXT, "TXT", 1, 0, NULL, GLDNS_RDF_TYPE_STR, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 17 */
|
||||
{GLDNS_RR_TYPE_RP, "RP", 2, 2, type_rp_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 2 },
|
||||
/* 18 */
|
||||
{GLDNS_RR_TYPE_AFSDB, "AFSDB", 2, 2, type_afsdb_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* 19 */
|
||||
{GLDNS_RR_TYPE_X25, "X25", 1, 1, type_x25_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 20 */
|
||||
{GLDNS_RR_TYPE_ISDN, "ISDN", 1, 2, type_isdn_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 21 */
|
||||
{GLDNS_RR_TYPE_RT, "RT", 2, 2, type_rt_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* 22 */
|
||||
{GLDNS_RR_TYPE_NSAP, "NSAP", 1, 1, type_nsap_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 23 */
|
||||
{GLDNS_RR_TYPE_NSAP_PTR, "NSAP-PTR", 1, 1, type_nsap_ptr_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 24 */
|
||||
{GLDNS_RR_TYPE_SIG, "SIG", 9, 9, type_sig_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* 25 */
|
||||
{GLDNS_RR_TYPE_KEY, "KEY", 4, 4, type_key_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 26 */
|
||||
{GLDNS_RR_TYPE_PX, "PX", 3, 3, type_px_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 2 },
|
||||
/* 27 */
|
||||
{GLDNS_RR_TYPE_GPOS, "GPOS", 3, 3, type_gpos_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 28 */
|
||||
{GLDNS_RR_TYPE_AAAA, "AAAA", 1, 1, type_aaaa_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 29 */
|
||||
{GLDNS_RR_TYPE_LOC, "LOC", 1, 1, type_loc_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 30 */
|
||||
{GLDNS_RR_TYPE_NXT, "NXT", 2, 2, type_nxt_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* 31 */
|
||||
{GLDNS_RR_TYPE_EID, "EID", 1, 1, type_eid_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 32 */
|
||||
{GLDNS_RR_TYPE_NIMLOC, "NIMLOC", 1, 1, type_nimloc_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 33 */
|
||||
{GLDNS_RR_TYPE_SRV, "SRV", 4, 4, type_srv_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* 34 */
|
||||
{GLDNS_RR_TYPE_ATMA, "ATMA", 1, 1, type_atma_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 35 */
|
||||
{GLDNS_RR_TYPE_NAPTR, "NAPTR", 6, 6, type_naptr_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* 36 */
|
||||
{GLDNS_RR_TYPE_KX, "KX", 2, 2, type_kx_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* 37 */
|
||||
{GLDNS_RR_TYPE_CERT, "CERT", 4, 4, type_cert_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 38 */
|
||||
{GLDNS_RR_TYPE_A6, "A6", 1, 1, type_a6_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 39 */
|
||||
{GLDNS_RR_TYPE_DNAME, "DNAME", 1, 1, type_dname_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* 40 */
|
||||
{GLDNS_RR_TYPE_SINK, "SINK", 1, 1, type_sink_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 41 */
|
||||
{GLDNS_RR_TYPE_OPT, "OPT", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 42 */
|
||||
{GLDNS_RR_TYPE_APL, "APL", 0, 0, type_apl_wireformat, GLDNS_RDF_TYPE_APL, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 43 */
|
||||
{GLDNS_RR_TYPE_DS, "DS", 4, 4, type_ds_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 44 */
|
||||
{GLDNS_RR_TYPE_SSHFP, "SSHFP", 3, 3, type_sshfp_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 45 */
|
||||
{GLDNS_RR_TYPE_IPSECKEY, "IPSECKEY", 1, 1, type_ipseckey_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 46 */
|
||||
{GLDNS_RR_TYPE_RRSIG, "RRSIG", 9, 9, type_rrsig_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* 47 */
|
||||
{GLDNS_RR_TYPE_NSEC, "NSEC", 1, 2, type_nsec_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* 48 */
|
||||
{GLDNS_RR_TYPE_DNSKEY, "DNSKEY", 4, 4, type_dnskey_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 49 */
|
||||
{GLDNS_RR_TYPE_DHCID, "DHCID", 1, 1, type_dhcid_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 50 */
|
||||
{GLDNS_RR_TYPE_NSEC3, "NSEC3", 5, 6, type_nsec3_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 51 */
|
||||
{GLDNS_RR_TYPE_NSEC3PARAM, "NSEC3PARAM", 4, 4, type_nsec3param_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 52 */
|
||||
{GLDNS_RR_TYPE_TLSA, "TLSA", 4, 4, type_tlsa_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE53", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE54", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 55
|
||||
* Hip ends with 0 or more Rendezvous Servers represented as dname's.
|
||||
* Hence the GLDNS_RDF_TYPE_DNAME _variable field and the _maximum field
|
||||
* set to 0.
|
||||
*/
|
||||
{GLDNS_RR_TYPE_HIP, "HIP", 1, 1, type_hip_wireformat, GLDNS_RDF_TYPE_DNAME, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
|
||||
#ifdef DRAFT_RRTYPES
|
||||
/* 56 */
|
||||
{GLDNS_RR_TYPE_NINFO, "NINFO", 1, 0, NULL, GLDNS_RDF_TYPE_STR, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 57 */
|
||||
{GLDNS_RR_TYPE_RKEY, "RKEY", 4, 4, type_key_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
#else
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE56", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE57", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
#endif
|
||||
/* 58 */
|
||||
{GLDNS_RR_TYPE_TALINK, "TALINK", 2, 2, type_talink_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 2 },
|
||||
|
||||
/* 59 */
|
||||
{GLDNS_RR_TYPE_CDS, "CDS", 4, 4, type_ds_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 60 */
|
||||
{GLDNS_RR_TYPE_CDNSKEY, "CDNSKEY", 4, 4, type_dnskey_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE61", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE62", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE63", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE64", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE65", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE66", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE67", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE68", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE69", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE70", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE71", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE72", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE73", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE74", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE75", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE76", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE77", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE78", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE79", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE80", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE81", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE82", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE83", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE84", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE85", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE86", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE87", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE88", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE89", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE90", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE91", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE92", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE93", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE94", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE95", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE96", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE97", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE98", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
|
||||
/* 99 */
|
||||
{GLDNS_RR_TYPE_SPF, "SPF", 1, 0, NULL, GLDNS_RDF_TYPE_STR, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
|
||||
/* UINFO [IANA-Reserved] */
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE100", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* UID [IANA-Reserved] */
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE101", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* GID [IANA-Reserved] */
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE102", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* UNSPEC [IANA-Reserved] */
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE103", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
|
||||
/* 104 */
|
||||
{GLDNS_RR_TYPE_NID, "NID", 2, 2, type_nid_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 105 */
|
||||
{GLDNS_RR_TYPE_L32, "L32", 2, 2, type_l32_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 106 */
|
||||
{GLDNS_RR_TYPE_L64, "L64", 2, 2, type_l64_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 107 */
|
||||
{GLDNS_RR_TYPE_LP, "LP", 2, 2, type_lp_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
|
||||
/* 108 */
|
||||
{GLDNS_RR_TYPE_EUI48, "EUI48", 1, 1, type_eui48_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* 109 */
|
||||
{GLDNS_RR_TYPE_EUI64, "EUI64", 1, 1, type_eui64_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE110", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE111", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE112", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE113", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE114", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE115", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE116", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE117", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE118", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE119", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE120", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE121", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE122", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE123", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE124", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE125", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE126", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE127", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE128", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE129", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE130", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE131", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE132", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE133", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE134", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE135", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE136", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE137", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE138", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE139", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE140", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE141", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE142", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE143", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE144", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE145", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE146", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE147", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE148", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE149", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE150", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE151", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE152", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE153", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE154", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE155", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE156", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE157", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE158", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE159", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE160", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE161", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE162", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE163", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE164", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE165", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE166", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE167", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE168", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE169", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE170", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE171", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE172", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE173", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE174", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE175", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE176", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE177", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE178", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE179", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE180", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE181", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE182", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE183", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE184", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE185", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE186", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE187", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE188", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE189", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE190", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE191", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE192", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE193", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE194", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE195", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE196", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE197", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE198", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE199", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE200", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE201", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE202", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE203", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE204", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE205", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE206", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE207", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE208", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE209", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE210", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE211", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE212", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE213", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE214", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE215", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE216", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE217", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE218", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE219", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE220", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE221", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE222", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE223", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE224", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE225", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE226", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE227", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE228", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE229", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE230", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE231", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE232", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE233", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE234", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE235", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE236", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE237", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE238", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE239", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE240", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE241", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE242", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE243", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE244", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE245", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE246", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE247", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE248", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
|
||||
/* GLDNS_RDF_TYPE_INT16_DATA takes two fields (length and data) as one.
|
||||
* So, unlike RFC 2930 spec, we have 7 min/max rdf's i.s.o. 8/9.
|
||||
*/
|
||||
/* 249 */
|
||||
{GLDNS_RR_TYPE_TKEY, "TKEY", 7, 7, type_tkey_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
/* GLDNS_RDF_TYPE_INT16_DATA takes two fields (length and data) as one.
|
||||
* So, unlike RFC 2930 spec, we have 7 min/max rdf's i.s.o. 8/9.
|
||||
*/
|
||||
/* 250 */
|
||||
{GLDNS_RR_TYPE_TSIG, "TSIG", 7, 7, type_tsig_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 1 },
|
||||
|
||||
/* IXFR: A request for a transfer of an incremental zone transfer */
|
||||
{GLDNS_RR_TYPE_IXFR, "IXFR", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* AXFR: A request for a transfer of an entire zone */
|
||||
{GLDNS_RR_TYPE_AXFR, "AXFR", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* MAILB: A request for mailbox-related records (MB, MG or MR) */
|
||||
{GLDNS_RR_TYPE_MAILB, "MAILB", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* MAILA: A request for mail agent RRs (Obsolete - see MX) */
|
||||
{GLDNS_RR_TYPE_MAILA, "MAILA", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
/* ANY: A request for all (available) records */
|
||||
{GLDNS_RR_TYPE_ANY, "ANY", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
|
||||
#ifdef DRAFT_RRTYPES
|
||||
/* 256 */
|
||||
{GLDNS_RR_TYPE_URI, "URI", 3, 3, type_uri_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
#else
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE256", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
#endif
|
||||
/* 257 */
|
||||
{GLDNS_RR_TYPE_CAA, "CAA", 3, 3, type_caa_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
|
||||
/* split in array, no longer contiguous */
|
||||
|
||||
#ifdef DRAFT_RRTYPES
|
||||
/* 32768 */
|
||||
{GLDNS_RR_TYPE_TA, "TA", 4, 4, type_ds_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
#else
|
||||
{GLDNS_RR_TYPE_NULL, "TYPE32768", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
|
||||
#endif
|
||||
/* 32769 */
|
||||
{GLDNS_RR_TYPE_DLV, "DLV", 4, 4, type_ds_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 }
|
||||
};
|
||||
|
||||
/**
|
||||
* \def GLDNS_RDATA_FIELD_DESCRIPTORS_COUNT
|
||||
* computes the number of rdata fields
|
||||
*/
|
||||
#define GLDNS_RDATA_FIELD_DESCRIPTORS_COUNT \
|
||||
(sizeof(rdata_field_descriptors)/sizeof(rdata_field_descriptors[0]))
|
||||
|
||||
const gldns_rr_descriptor *
|
||||
gldns_rr_descript(uint16_t type)
|
||||
{
|
||||
size_t i;
|
||||
if (type < GLDNS_RDATA_FIELD_DESCRIPTORS_COMMON) {
|
||||
return &rdata_field_descriptors[type];
|
||||
} else {
|
||||
/* because not all array index equals type code */
|
||||
for (i = GLDNS_RDATA_FIELD_DESCRIPTORS_COMMON;
|
||||
i < GLDNS_RDATA_FIELD_DESCRIPTORS_COUNT;
|
||||
i++) {
|
||||
if (rdata_field_descriptors[i]._type == type) {
|
||||
return &rdata_field_descriptors[i];
|
||||
}
|
||||
}
|
||||
return &rdata_field_descriptors[0];
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
gldns_rr_descriptor_minimum(const gldns_rr_descriptor *descriptor)
|
||||
{
|
||||
if (descriptor) {
|
||||
return descriptor->_minimum;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
gldns_rr_descriptor_maximum(const gldns_rr_descriptor *descriptor)
|
||||
{
|
||||
if (descriptor) {
|
||||
if (descriptor->_variable != GLDNS_RDF_TYPE_NONE) {
|
||||
return 65535; /* cannot be more than 64k */
|
||||
} else {
|
||||
return descriptor->_maximum;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
gldns_rdf_type
|
||||
gldns_rr_descriptor_field_type(const gldns_rr_descriptor *descriptor,
|
||||
size_t index)
|
||||
{
|
||||
assert(descriptor != NULL);
|
||||
assert(index < descriptor->_maximum
|
||||
|| descriptor->_variable != GLDNS_RDF_TYPE_NONE);
|
||||
if (index < descriptor->_maximum) {
|
||||
return descriptor->_wireformat[index];
|
||||
} else {
|
||||
return descriptor->_variable;
|
||||
}
|
||||
}
|
||||
|
||||
gldns_rr_type
|
||||
gldns_get_rr_type_by_name(const char *name)
|
||||
{
|
||||
unsigned int i;
|
||||
const char *desc_name;
|
||||
const gldns_rr_descriptor *desc;
|
||||
|
||||
/* TYPEXX representation */
|
||||
if (strlen(name) > 4 && strncasecmp(name, "TYPE", 4) == 0) {
|
||||
return atoi(name + 4);
|
||||
}
|
||||
|
||||
/* Normal types */
|
||||
for (i = 0; i < (unsigned int) GLDNS_RDATA_FIELD_DESCRIPTORS_COUNT; i++) {
|
||||
desc = &rdata_field_descriptors[i];
|
||||
desc_name = desc->_name;
|
||||
if(desc_name &&
|
||||
strlen(name) == strlen(desc_name) &&
|
||||
strncasecmp(name, desc_name, strlen(desc_name)) == 0) {
|
||||
/* because not all array index equals type code */
|
||||
return desc->_type;
|
||||
}
|
||||
}
|
||||
|
||||
/* special cases for query types */
|
||||
if (strlen(name) == 4 && strncasecmp(name, "IXFR", 4) == 0) {
|
||||
return 251;
|
||||
} else if (strlen(name) == 4 && strncasecmp(name, "AXFR", 4) == 0) {
|
||||
return 252;
|
||||
} else if (strlen(name) == 5 && strncasecmp(name, "MAILB", 5) == 0) {
|
||||
return 253;
|
||||
} else if (strlen(name) == 5 && strncasecmp(name, "MAILA", 5) == 0) {
|
||||
return 254;
|
||||
} else if (strlen(name) == 3 && strncasecmp(name, "ANY", 3) == 0) {
|
||||
return 255;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
gldns_rr_class
|
||||
gldns_get_rr_class_by_name(const char *name)
|
||||
{
|
||||
gldns_lookup_table *lt;
|
||||
|
||||
/* CLASSXX representation */
|
||||
if (strlen(name) > 5 && strncasecmp(name, "CLASS", 5) == 0) {
|
||||
return atoi(name + 5);
|
||||
}
|
||||
|
||||
/* Normal types */
|
||||
lt = gldns_lookup_by_name(gldns_rr_classes, name);
|
||||
if (lt) {
|
||||
return lt->id;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,503 @@
|
|||
/*
|
||||
* rrdef.h
|
||||
*
|
||||
* RR definitions
|
||||
*
|
||||
* a Net::DNS like library for C
|
||||
*
|
||||
* (c) NLnet Labs, 2005-2006
|
||||
*
|
||||
* See the file LICENSE for the license
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* Defines resource record types and constants.
|
||||
*/
|
||||
|
||||
#ifndef GLDNS_RRDEF_H
|
||||
#define GLDNS_RRDEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Maximum length of a dname label */
|
||||
#define GLDNS_MAX_LABELLEN 63
|
||||
/** Maximum length of a complete dname */
|
||||
#define GLDNS_MAX_DOMAINLEN 255
|
||||
/** Maximum number of pointers in 1 dname */
|
||||
#define GLDNS_MAX_POINTERS 65535
|
||||
/** The bytes TTL, CLASS and length use up in an rr */
|
||||
#define GLDNS_RR_OVERHEAD 10
|
||||
|
||||
#define GLDNS_DNSSEC_KEYPROTO 3
|
||||
#define GLDNS_KEY_ZONE_KEY 0x0100 /* set for ZSK&KSK, rfc 4034 */
|
||||
#define GLDNS_KEY_SEP_KEY 0x0001 /* set for KSK, rfc 4034 */
|
||||
#define GLDNS_KEY_REVOKE_KEY 0x0080 /* used to revoke KSK, rfc 5011 */
|
||||
|
||||
/* The first fields are contiguous and can be referenced instantly */
|
||||
#define GLDNS_RDATA_FIELD_DESCRIPTORS_COMMON 258
|
||||
|
||||
/** lookuptable for rr classes */
|
||||
extern struct gldns_struct_lookup_table* gldns_rr_classes;
|
||||
|
||||
/**
|
||||
* The different RR classes.
|
||||
*/
|
||||
enum gldns_enum_rr_class
|
||||
{
|
||||
/** the Internet */
|
||||
GLDNS_RR_CLASS_IN = 1,
|
||||
/** Chaos class */
|
||||
GLDNS_RR_CLASS_CH = 3,
|
||||
/** Hesiod (Dyer 87) */
|
||||
GLDNS_RR_CLASS_HS = 4,
|
||||
/** None class, dynamic update */
|
||||
GLDNS_RR_CLASS_NONE = 254,
|
||||
/** Any class */
|
||||
GLDNS_RR_CLASS_ANY = 255,
|
||||
|
||||
GLDNS_RR_CLASS_FIRST = 0,
|
||||
GLDNS_RR_CLASS_LAST = 65535,
|
||||
GLDNS_RR_CLASS_COUNT = GLDNS_RR_CLASS_LAST - GLDNS_RR_CLASS_FIRST + 1
|
||||
};
|
||||
typedef enum gldns_enum_rr_class gldns_rr_class;
|
||||
|
||||
/**
|
||||
* Used to specify whether compression is allowed.
|
||||
*/
|
||||
enum gldns_enum_rr_compress
|
||||
{
|
||||
/** compression is allowed */
|
||||
GLDNS_RR_COMPRESS,
|
||||
GLDNS_RR_NO_COMPRESS
|
||||
};
|
||||
typedef enum gldns_enum_rr_compress gldns_rr_compress;
|
||||
|
||||
/**
|
||||
* The different RR types.
|
||||
*/
|
||||
enum gldns_enum_rr_type
|
||||
{
|
||||
/** a host address */
|
||||
GLDNS_RR_TYPE_A = 1,
|
||||
/** an authoritative name server */
|
||||
GLDNS_RR_TYPE_NS = 2,
|
||||
/** a mail destination (Obsolete - use MX) */
|
||||
GLDNS_RR_TYPE_MD = 3,
|
||||
/** a mail forwarder (Obsolete - use MX) */
|
||||
GLDNS_RR_TYPE_MF = 4,
|
||||
/** the canonical name for an alias */
|
||||
GLDNS_RR_TYPE_CNAME = 5,
|
||||
/** marks the start of a zone of authority */
|
||||
GLDNS_RR_TYPE_SOA = 6,
|
||||
/** a mailbox domain name (EXPERIMENTAL) */
|
||||
GLDNS_RR_TYPE_MB = 7,
|
||||
/** a mail group member (EXPERIMENTAL) */
|
||||
GLDNS_RR_TYPE_MG = 8,
|
||||
/** a mail rename domain name (EXPERIMENTAL) */
|
||||
GLDNS_RR_TYPE_MR = 9,
|
||||
/** a null RR (EXPERIMENTAL) */
|
||||
GLDNS_RR_TYPE_NULL = 10,
|
||||
/** a well known service description */
|
||||
GLDNS_RR_TYPE_WKS = 11,
|
||||
/** a domain name pointer */
|
||||
GLDNS_RR_TYPE_PTR = 12,
|
||||
/** host information */
|
||||
GLDNS_RR_TYPE_HINFO = 13,
|
||||
/** mailbox or mail list information */
|
||||
GLDNS_RR_TYPE_MINFO = 14,
|
||||
/** mail exchange */
|
||||
GLDNS_RR_TYPE_MX = 15,
|
||||
/** text strings */
|
||||
GLDNS_RR_TYPE_TXT = 16,
|
||||
/** RFC1183 */
|
||||
GLDNS_RR_TYPE_RP = 17,
|
||||
/** RFC1183 */
|
||||
GLDNS_RR_TYPE_AFSDB = 18,
|
||||
/** RFC1183 */
|
||||
GLDNS_RR_TYPE_X25 = 19,
|
||||
/** RFC1183 */
|
||||
GLDNS_RR_TYPE_ISDN = 20,
|
||||
/** RFC1183 */
|
||||
GLDNS_RR_TYPE_RT = 21,
|
||||
/** RFC1706 */
|
||||
GLDNS_RR_TYPE_NSAP = 22,
|
||||
/** RFC1348 */
|
||||
GLDNS_RR_TYPE_NSAP_PTR = 23,
|
||||
/** 2535typecode */
|
||||
GLDNS_RR_TYPE_SIG = 24,
|
||||
/** 2535typecode */
|
||||
GLDNS_RR_TYPE_KEY = 25,
|
||||
/** RFC2163 */
|
||||
GLDNS_RR_TYPE_PX = 26,
|
||||
/** RFC1712 */
|
||||
GLDNS_RR_TYPE_GPOS = 27,
|
||||
/** ipv6 address */
|
||||
GLDNS_RR_TYPE_AAAA = 28,
|
||||
/** LOC record RFC1876 */
|
||||
GLDNS_RR_TYPE_LOC = 29,
|
||||
/** 2535typecode */
|
||||
GLDNS_RR_TYPE_NXT = 30,
|
||||
/** draft-ietf-nimrod-dns-01.txt */
|
||||
GLDNS_RR_TYPE_EID = 31,
|
||||
/** draft-ietf-nimrod-dns-01.txt */
|
||||
GLDNS_RR_TYPE_NIMLOC = 32,
|
||||
/** SRV record RFC2782 */
|
||||
GLDNS_RR_TYPE_SRV = 33,
|
||||
/** http://www.jhsoft.com/rfc/af-saa-0069.000.rtf */
|
||||
GLDNS_RR_TYPE_ATMA = 34,
|
||||
/** RFC2915 */
|
||||
GLDNS_RR_TYPE_NAPTR = 35,
|
||||
/** RFC2230 */
|
||||
GLDNS_RR_TYPE_KX = 36,
|
||||
/** RFC2538 */
|
||||
GLDNS_RR_TYPE_CERT = 37,
|
||||
/** RFC2874 */
|
||||
GLDNS_RR_TYPE_A6 = 38,
|
||||
/** RFC2672 */
|
||||
GLDNS_RR_TYPE_DNAME = 39,
|
||||
/** dnsind-kitchen-sink-02.txt */
|
||||
GLDNS_RR_TYPE_SINK = 40,
|
||||
/** Pseudo OPT record... */
|
||||
GLDNS_RR_TYPE_OPT = 41,
|
||||
/** RFC3123 */
|
||||
GLDNS_RR_TYPE_APL = 42,
|
||||
/** RFC4034, RFC3658 */
|
||||
GLDNS_RR_TYPE_DS = 43,
|
||||
/** SSH Key Fingerprint */
|
||||
GLDNS_RR_TYPE_SSHFP = 44, /* RFC 4255 */
|
||||
/** IPsec Key */
|
||||
GLDNS_RR_TYPE_IPSECKEY = 45, /* RFC 4025 */
|
||||
/** DNSSEC */
|
||||
GLDNS_RR_TYPE_RRSIG = 46, /* RFC 4034 */
|
||||
GLDNS_RR_TYPE_NSEC = 47, /* RFC 4034 */
|
||||
GLDNS_RR_TYPE_DNSKEY = 48, /* RFC 4034 */
|
||||
|
||||
GLDNS_RR_TYPE_DHCID = 49, /* RFC 4701 */
|
||||
/* NSEC3 */
|
||||
GLDNS_RR_TYPE_NSEC3 = 50, /* RFC 5155 */
|
||||
GLDNS_RR_TYPE_NSEC3PARAM = 51, /* RFC 5155 */
|
||||
GLDNS_RR_TYPE_NSEC3PARAMS = 51,
|
||||
GLDNS_RR_TYPE_TLSA = 52, /* RFC 6698 */
|
||||
|
||||
GLDNS_RR_TYPE_HIP = 55, /* RFC 5205 */
|
||||
|
||||
/** draft-reid-dnsext-zs */
|
||||
GLDNS_RR_TYPE_NINFO = 56,
|
||||
/** draft-reid-dnsext-rkey */
|
||||
GLDNS_RR_TYPE_RKEY = 57,
|
||||
/** draft-ietf-dnsop-trust-history */
|
||||
GLDNS_RR_TYPE_TALINK = 58,
|
||||
GLDNS_RR_TYPE_CDS = 59, /** RFC 7344 */
|
||||
GLDNS_RR_TYPE_CDNSKEY = 60, /** RFC 7344 */
|
||||
|
||||
GLDNS_RR_TYPE_SPF = 99, /* RFC 4408 */
|
||||
|
||||
GLDNS_RR_TYPE_UINFO = 100,
|
||||
GLDNS_RR_TYPE_UID = 101,
|
||||
GLDNS_RR_TYPE_GID = 102,
|
||||
GLDNS_RR_TYPE_UNSPEC = 103,
|
||||
|
||||
GLDNS_RR_TYPE_NID = 104, /* RFC 6742 */
|
||||
GLDNS_RR_TYPE_L32 = 105, /* RFC 6742 */
|
||||
GLDNS_RR_TYPE_L64 = 106, /* RFC 6742 */
|
||||
GLDNS_RR_TYPE_LP = 107, /* RFC 6742 */
|
||||
|
||||
/** draft-jabley-dnsext-eui48-eui64-rrtypes */
|
||||
GLDNS_RR_TYPE_EUI48 = 108,
|
||||
GLDNS_RR_TYPE_EUI64 = 109,
|
||||
|
||||
GLDNS_RR_TYPE_TKEY = 249, /* RFC 2930 */
|
||||
GLDNS_RR_TYPE_TSIG = 250,
|
||||
GLDNS_RR_TYPE_IXFR = 251,
|
||||
GLDNS_RR_TYPE_AXFR = 252,
|
||||
/** A request for mailbox-related records (MB, MG or MR) */
|
||||
GLDNS_RR_TYPE_MAILB = 253,
|
||||
/** A request for mail agent RRs (Obsolete - see MX) */
|
||||
GLDNS_RR_TYPE_MAILA = 254,
|
||||
/** any type (wildcard) */
|
||||
GLDNS_RR_TYPE_ANY = 255,
|
||||
/** draft-faltstrom-uri-06 */
|
||||
GLDNS_RR_TYPE_URI = 256,
|
||||
GLDNS_RR_TYPE_CAA = 257, /* RFC 6844 */
|
||||
|
||||
/** DNSSEC Trust Authorities */
|
||||
GLDNS_RR_TYPE_TA = 32768,
|
||||
/* RFC 4431, 5074, DNSSEC Lookaside Validation */
|
||||
GLDNS_RR_TYPE_DLV = 32769,
|
||||
|
||||
/* type codes from nsec3 experimental phase
|
||||
GLDNS_RR_TYPE_NSEC3 = 65324,
|
||||
GLDNS_RR_TYPE_NSEC3PARAMS = 65325, */
|
||||
GLDNS_RR_TYPE_FIRST = 0,
|
||||
GLDNS_RR_TYPE_LAST = 65535,
|
||||
GLDNS_RR_TYPE_COUNT = GLDNS_RR_TYPE_LAST - GLDNS_RR_TYPE_FIRST + 1
|
||||
};
|
||||
typedef enum gldns_enum_rr_type gldns_rr_type;
|
||||
|
||||
/* RDATA */
|
||||
#define GLDNS_MAX_RDFLEN 65535
|
||||
|
||||
#define GLDNS_RDF_SIZE_BYTE 1
|
||||
#define GLDNS_RDF_SIZE_WORD 2
|
||||
#define GLDNS_RDF_SIZE_DOUBLEWORD 4
|
||||
#define GLDNS_RDF_SIZE_6BYTES 6
|
||||
#define GLDNS_RDF_SIZE_8BYTES 8
|
||||
#define GLDNS_RDF_SIZE_16BYTES 16
|
||||
|
||||
#define GLDNS_NSEC3_VARS_OPTOUT_MASK 0x01
|
||||
|
||||
#define GLDNS_APL_IP4 1
|
||||
#define GLDNS_APL_IP6 2
|
||||
#define GLDNS_APL_MASK 0x7f
|
||||
#define GLDNS_APL_NEGATION 0x80
|
||||
|
||||
/**
|
||||
* The different types of RDATA fields.
|
||||
*/
|
||||
enum gldns_enum_rdf_type
|
||||
{
|
||||
/** none */
|
||||
GLDNS_RDF_TYPE_NONE,
|
||||
/** domain name */
|
||||
GLDNS_RDF_TYPE_DNAME,
|
||||
/** 8 bits */
|
||||
GLDNS_RDF_TYPE_INT8,
|
||||
/** 16 bits */
|
||||
GLDNS_RDF_TYPE_INT16,
|
||||
/** 32 bits */
|
||||
GLDNS_RDF_TYPE_INT32,
|
||||
/** A record */
|
||||
GLDNS_RDF_TYPE_A,
|
||||
/** AAAA record */
|
||||
GLDNS_RDF_TYPE_AAAA,
|
||||
/** txt string */
|
||||
GLDNS_RDF_TYPE_STR,
|
||||
/** apl data */
|
||||
GLDNS_RDF_TYPE_APL,
|
||||
/** b32 string */
|
||||
GLDNS_RDF_TYPE_B32_EXT,
|
||||
/** b64 string */
|
||||
GLDNS_RDF_TYPE_B64,
|
||||
/** hex string */
|
||||
GLDNS_RDF_TYPE_HEX,
|
||||
/** nsec type codes */
|
||||
GLDNS_RDF_TYPE_NSEC,
|
||||
/** a RR type */
|
||||
GLDNS_RDF_TYPE_TYPE,
|
||||
/** a class */
|
||||
GLDNS_RDF_TYPE_CLASS,
|
||||
/** certificate algorithm */
|
||||
GLDNS_RDF_TYPE_CERT_ALG,
|
||||
/** a key algorithm */
|
||||
GLDNS_RDF_TYPE_ALG,
|
||||
/** unknown types */
|
||||
GLDNS_RDF_TYPE_UNKNOWN,
|
||||
/** time (32 bits) */
|
||||
GLDNS_RDF_TYPE_TIME,
|
||||
/** period */
|
||||
GLDNS_RDF_TYPE_PERIOD,
|
||||
/** tsig time 48 bits */
|
||||
GLDNS_RDF_TYPE_TSIGTIME,
|
||||
/** Represents the Public Key Algorithm, HIT and Public Key fields
|
||||
for the HIP RR types. A HIP specific rdf type is used because of
|
||||
the unusual layout in wireformat (see RFC 5205 Section 5) */
|
||||
GLDNS_RDF_TYPE_HIP,
|
||||
/** variable length any type rdata where the length
|
||||
is specified by the first 2 bytes */
|
||||
GLDNS_RDF_TYPE_INT16_DATA,
|
||||
/** protocol and port bitmaps */
|
||||
GLDNS_RDF_TYPE_SERVICE,
|
||||
/** location data */
|
||||
GLDNS_RDF_TYPE_LOC,
|
||||
/** well known services */
|
||||
GLDNS_RDF_TYPE_WKS,
|
||||
/** NSAP */
|
||||
GLDNS_RDF_TYPE_NSAP,
|
||||
/** ATMA */
|
||||
GLDNS_RDF_TYPE_ATMA,
|
||||
/** IPSECKEY */
|
||||
GLDNS_RDF_TYPE_IPSECKEY,
|
||||
/** nsec3 hash salt */
|
||||
GLDNS_RDF_TYPE_NSEC3_SALT,
|
||||
/** nsec3 base32 string (with length byte on wire */
|
||||
GLDNS_RDF_TYPE_NSEC3_NEXT_OWNER,
|
||||
|
||||
/** 4 shorts represented as 4 * 16 bit hex numbers
|
||||
* seperated by colons. For NID and L64.
|
||||
*/
|
||||
GLDNS_RDF_TYPE_ILNP64,
|
||||
|
||||
/** 6 * 8 bit hex numbers seperated by dashes. For EUI48. */
|
||||
GLDNS_RDF_TYPE_EUI48,
|
||||
/** 8 * 8 bit hex numbers seperated by dashes. For EUI64. */
|
||||
GLDNS_RDF_TYPE_EUI64,
|
||||
|
||||
/** A non-zero sequence of US-ASCII letters and numbers in lower case.
|
||||
* For CAA.
|
||||
*/
|
||||
GLDNS_RDF_TYPE_TAG,
|
||||
|
||||
/** A <character-string> encoding of the value field as specified
|
||||
* [RFC1035], Section 5.1., encoded as remaining rdata.
|
||||
* For CAA.
|
||||
*/
|
||||
GLDNS_RDF_TYPE_LONG_STR,
|
||||
|
||||
/* Aliases */
|
||||
GLDNS_RDF_TYPE_BITMAP = GLDNS_RDF_TYPE_NSEC
|
||||
};
|
||||
typedef enum gldns_enum_rdf_type gldns_rdf_type;
|
||||
|
||||
/**
|
||||
* Algorithms used in dns
|
||||
*/
|
||||
enum gldns_enum_algorithm
|
||||
{
|
||||
GLDNS_RSAMD5 = 1, /* RFC 4034,4035 */
|
||||
GLDNS_DH = 2,
|
||||
GLDNS_DSA = 3,
|
||||
GLDNS_ECC = 4,
|
||||
GLDNS_RSASHA1 = 5,
|
||||
GLDNS_DSA_NSEC3 = 6,
|
||||
GLDNS_RSASHA1_NSEC3 = 7,
|
||||
GLDNS_RSASHA256 = 8, /* RFC 5702 */
|
||||
GLDNS_RSASHA512 = 10, /* RFC 5702 */
|
||||
GLDNS_ECC_GOST = 12, /* RFC 5933 */
|
||||
GLDNS_ECDSAP256SHA256 = 13, /* RFC 6605 */
|
||||
GLDNS_ECDSAP384SHA384 = 14, /* RFC 6605 */
|
||||
GLDNS_INDIRECT = 252,
|
||||
GLDNS_PRIVATEDNS = 253,
|
||||
GLDNS_PRIVATEOID = 254
|
||||
};
|
||||
typedef enum gldns_enum_algorithm gldns_algorithm;
|
||||
|
||||
/**
|
||||
* Hashing algorithms used in the DS record
|
||||
*/
|
||||
enum gldns_enum_hash
|
||||
{
|
||||
GLDNS_SHA1 = 1, /* RFC 4034 */
|
||||
GLDNS_SHA256 = 2, /* RFC 4509 */
|
||||
GLDNS_HASH_GOST = 3, /* RFC 5933 */
|
||||
GLDNS_SHA384 = 4 /* RFC 6605 */
|
||||
};
|
||||
typedef enum gldns_enum_hash gldns_hash;
|
||||
|
||||
/**
|
||||
* algorithms used in CERT rrs
|
||||
*/
|
||||
enum gldns_enum_cert_algorithm
|
||||
{
|
||||
GLDNS_CERT_PKIX = 1,
|
||||
GLDNS_CERT_SPKI = 2,
|
||||
GLDNS_CERT_PGP = 3,
|
||||
GLDNS_CERT_IPKIX = 4,
|
||||
GLDNS_CERT_ISPKI = 5,
|
||||
GLDNS_CERT_IPGP = 6,
|
||||
GLDNS_CERT_ACPKIX = 7,
|
||||
GLDNS_CERT_IACPKIX = 8,
|
||||
GLDNS_CERT_URI = 253,
|
||||
GLDNS_CERT_OID = 254
|
||||
};
|
||||
typedef enum gldns_enum_cert_algorithm gldns_cert_algorithm;
|
||||
|
||||
/**
|
||||
* EDNS option codes
|
||||
*/
|
||||
enum gldns_enum_edns_option
|
||||
{
|
||||
GLDNS_EDNS_LLQ = 1, /* http://files.dns-sd.org/draft-sekar-dns-llq.txt */
|
||||
GLDNS_EDNS_UL = 2, /* http://files.dns-sd.org/draft-sekar-dns-ul.txt */
|
||||
GLDNS_EDNS_NSID = 3, /* RFC5001 */
|
||||
/* 4 draft-cheshire-edns0-owner-option */
|
||||
GLDNS_EDNS_DAU = 5, /* RFC6975 */
|
||||
GLDNS_EDNS_DHU = 6, /* RFC6975 */
|
||||
GLDNS_EDNS_N3U = 7, /* RFC6975 */
|
||||
GLDNS_EDNS_CLIENT_SUBNET = 8 /* draft-vandergaast-edns-client-subnet */
|
||||
};
|
||||
typedef enum gldns_enum_edns_option gldns_edns_option;
|
||||
|
||||
#define GLDNS_EDNS_MASK_DO_BIT 0x8000
|
||||
|
||||
/**
|
||||
* Contains all information about resource record types.
|
||||
*
|
||||
* This structure contains, for all rr types, the rdata fields that are defined.
|
||||
*/
|
||||
struct gldns_struct_rr_descriptor
|
||||
{
|
||||
/** Type of the RR that is described here */
|
||||
gldns_rr_type _type;
|
||||
/** Textual name of the RR type. */
|
||||
const char *_name;
|
||||
/** Minimum number of rdata fields in the RRs of this type. */
|
||||
uint8_t _minimum;
|
||||
/** Maximum number of rdata fields in the RRs of this type. */
|
||||
uint8_t _maximum;
|
||||
/** Wireformat specification for the rr, i.e. the types of rdata fields in their respective order. */
|
||||
const gldns_rdf_type *_wireformat;
|
||||
/** Special rdf types */
|
||||
gldns_rdf_type _variable;
|
||||
/** Specifies whether compression can be used for dnames in this RR type. */
|
||||
gldns_rr_compress _compress;
|
||||
/** The number of DNAMEs in the _wireformat string, for parsing. */
|
||||
uint8_t _dname_count;
|
||||
};
|
||||
typedef struct gldns_struct_rr_descriptor gldns_rr_descriptor;
|
||||
|
||||
/**
|
||||
* returns the resource record descriptor for the given rr type.
|
||||
*
|
||||
* \param[in] type the type value of the rr type
|
||||
*\return the gldns_rr_descriptor for this type
|
||||
*/
|
||||
const gldns_rr_descriptor *gldns_rr_descript(uint16_t type);
|
||||
|
||||
/**
|
||||
* returns the minimum number of rdata fields of the rr type this descriptor describes.
|
||||
*
|
||||
* \param[in] descriptor for an rr type
|
||||
* \return the minimum number of rdata fields
|
||||
*/
|
||||
size_t gldns_rr_descriptor_minimum(const gldns_rr_descriptor *descriptor);
|
||||
|
||||
/**
|
||||
* returns the maximum number of rdata fields of the rr type this descriptor describes.
|
||||
*
|
||||
* \param[in] descriptor for an rr type
|
||||
* \return the maximum number of rdata fields
|
||||
*/
|
||||
size_t gldns_rr_descriptor_maximum(const gldns_rr_descriptor *descriptor);
|
||||
|
||||
/**
|
||||
* returns the rdf type for the given rdata field number of the rr type for the given descriptor.
|
||||
*
|
||||
* \param[in] descriptor for an rr type
|
||||
* \param[in] field the field number
|
||||
* \return the rdf type for the field
|
||||
*/
|
||||
gldns_rdf_type gldns_rr_descriptor_field_type(const gldns_rr_descriptor *descriptor, size_t field);
|
||||
|
||||
/**
|
||||
* retrieves a rrtype by looking up its name.
|
||||
* \param[in] name a string with the name
|
||||
* \return the type which corresponds with the name
|
||||
*/
|
||||
gldns_rr_type gldns_get_rr_type_by_name(const char *name);
|
||||
|
||||
/**
|
||||
* retrieves a class by looking up its name.
|
||||
* \param[in] name string with the name
|
||||
* \return the cass which corresponds with the name
|
||||
*/
|
||||
gldns_rr_class gldns_get_rr_class_by_name(const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GLDNS_RRDEF_H */
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* buffer.c -- generic memory buffer .
|
||||
*
|
||||
* Copyright (c) 2001-2008, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* See LICENSE for the license.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* This file contains the definition of gldns_buffer, and functions to manipulate those.
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "gldns/sbuffer.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
gldns_buffer *
|
||||
gldns_buffer_new(size_t capacity)
|
||||
{
|
||||
gldns_buffer *buffer = (gldns_buffer*)malloc(sizeof(gldns_buffer));
|
||||
|
||||
if (!buffer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer->_data = (uint8_t *) malloc(capacity);
|
||||
if (!buffer->_data) {
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer->_position = 0;
|
||||
buffer->_limit = buffer->_capacity = capacity;
|
||||
buffer->_fixed = 0;
|
||||
buffer->_status_err = 0;
|
||||
|
||||
gldns_buffer_invariant(buffer);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void
|
||||
gldns_buffer_new_frm_data(gldns_buffer *buffer, void *data, size_t size)
|
||||
{
|
||||
assert(data != NULL);
|
||||
|
||||
buffer->_position = 0;
|
||||
buffer->_limit = buffer->_capacity = size;
|
||||
buffer->_fixed = 0;
|
||||
buffer->_data = malloc(size);
|
||||
if(!buffer->_data) {
|
||||
buffer->_status_err = 1;
|
||||
return;
|
||||
}
|
||||
memcpy(buffer->_data, data, size);
|
||||
buffer->_status_err = 0;
|
||||
|
||||
gldns_buffer_invariant(buffer);
|
||||
}
|
||||
|
||||
void
|
||||
gldns_buffer_init_frm_data(gldns_buffer *buffer, void *data, size_t size)
|
||||
{
|
||||
memset(buffer, 0, sizeof(*buffer));
|
||||
buffer->_data = data;
|
||||
buffer->_capacity = buffer->_limit = size;
|
||||
buffer->_fixed = 1;
|
||||
}
|
||||
|
||||
int
|
||||
gldns_buffer_set_capacity(gldns_buffer *buffer, size_t capacity)
|
||||
{
|
||||
void *data;
|
||||
|
||||
gldns_buffer_invariant(buffer);
|
||||
assert(buffer->_position <= capacity);
|
||||
|
||||
data = (uint8_t *) realloc(buffer->_data, capacity);
|
||||
if (!data) {
|
||||
buffer->_status_err = 1;
|
||||
return 0;
|
||||
} else {
|
||||
buffer->_data = data;
|
||||
buffer->_limit = buffer->_capacity = capacity;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gldns_buffer_reserve(gldns_buffer *buffer, size_t amount)
|
||||
{
|
||||
gldns_buffer_invariant(buffer);
|
||||
assert(!buffer->_fixed);
|
||||
if (buffer->_capacity < buffer->_position + amount) {
|
||||
size_t new_capacity = buffer->_capacity * 3 / 2;
|
||||
|
||||
if (new_capacity < buffer->_position + amount) {
|
||||
new_capacity = buffer->_position + amount;
|
||||
}
|
||||
if (!gldns_buffer_set_capacity(buffer, new_capacity)) {
|
||||
buffer->_status_err = 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
buffer->_limit = buffer->_capacity;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
gldns_buffer_printf(gldns_buffer *buffer, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int written = 0;
|
||||
size_t remaining;
|
||||
|
||||
if (gldns_buffer_status_ok(buffer)) {
|
||||
gldns_buffer_invariant(buffer);
|
||||
assert(buffer->_limit == buffer->_capacity);
|
||||
|
||||
remaining = gldns_buffer_remaining(buffer);
|
||||
va_start(args, format);
|
||||
written = vsnprintf((char *) gldns_buffer_current(buffer), remaining,
|
||||
format, args);
|
||||
va_end(args);
|
||||
if (written == -1) {
|
||||
buffer->_status_err = 1;
|
||||
return -1;
|
||||
} else if ((size_t) written >= remaining) {
|
||||
if (!gldns_buffer_reserve(buffer, (size_t) written + 1)) {
|
||||
buffer->_status_err = 1;
|
||||
return -1;
|
||||
}
|
||||
va_start(args, format);
|
||||
written = vsnprintf((char *) gldns_buffer_current(buffer),
|
||||
gldns_buffer_remaining(buffer), format, args);
|
||||
va_end(args);
|
||||
if (written == -1) {
|
||||
buffer->_status_err = 1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
buffer->_position += written;
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
void
|
||||
gldns_buffer_free(gldns_buffer *buffer)
|
||||
{
|
||||
if (!buffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!buffer->_fixed)
|
||||
free(buffer->_data);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void *
|
||||
gldns_buffer_export(gldns_buffer *buffer)
|
||||
{
|
||||
buffer->_fixed = 1;
|
||||
return buffer->_data;
|
||||
}
|
||||
|
||||
void
|
||||
gldns_buffer_copy(gldns_buffer* result, gldns_buffer* from)
|
||||
{
|
||||
size_t tocopy = gldns_buffer_limit(from);
|
||||
|
||||
if(tocopy > gldns_buffer_capacity(result))
|
||||
tocopy = gldns_buffer_capacity(result);
|
||||
gldns_buffer_clear(result);
|
||||
gldns_buffer_write(result, gldns_buffer_begin(from), tocopy);
|
||||
gldns_buffer_flip(result);
|
||||
}
|
|
@ -0,0 +1,706 @@
|
|||
/*
|
||||
* buffer.h -- generic memory buffer.
|
||||
*
|
||||
* Copyright (c) 2005-2008, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* See LICENSE for the license.
|
||||
*
|
||||
*
|
||||
* The buffer module implements a generic buffer. The API is based on
|
||||
* the java.nio.Buffer interface.
|
||||
*/
|
||||
|
||||
#ifndef GLDNS_SBUFFER_H
|
||||
#define GLDNS_SBUFFER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef S_SPLINT_S
|
||||
# define INLINE
|
||||
#else
|
||||
# ifdef SWIG
|
||||
# define INLINE static
|
||||
# else
|
||||
# define INLINE static inline
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copy data allowing for unaligned accesses in network byte order
|
||||
* (big endian).
|
||||
*/
|
||||
INLINE uint16_t
|
||||
gldns_read_uint16(const void *src)
|
||||
{
|
||||
#ifdef ALLOW_UNALIGNED_ACCESSES
|
||||
return ntohs(*(uint16_t *) src);
|
||||
#else
|
||||
uint8_t *p = (uint8_t *) src;
|
||||
return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
|
||||
#endif
|
||||
}
|
||||
|
||||
INLINE uint32_t
|
||||
gldns_read_uint32(const void *src)
|
||||
{
|
||||
#ifdef ALLOW_UNALIGNED_ACCESSES
|
||||
return ntohl(*(uint32_t *) src);
|
||||
#else
|
||||
uint8_t *p = (uint8_t *) src;
|
||||
return ( ((uint32_t) p[0] << 24)
|
||||
| ((uint32_t) p[1] << 16)
|
||||
| ((uint32_t) p[2] << 8)
|
||||
| (uint32_t) p[3]);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy data allowing for unaligned accesses in network byte order
|
||||
* (big endian).
|
||||
*/
|
||||
INLINE void
|
||||
gldns_write_uint16(void *dst, uint16_t data)
|
||||
{
|
||||
#ifdef ALLOW_UNALIGNED_ACCESSES
|
||||
* (uint16_t *) dst = htons(data);
|
||||
#else
|
||||
uint8_t *p = (uint8_t *) dst;
|
||||
p[0] = (uint8_t) ((data >> 8) & 0xff);
|
||||
p[1] = (uint8_t) (data & 0xff);
|
||||
#endif
|
||||
}
|
||||
|
||||
INLINE void
|
||||
gldns_write_uint32(void *dst, uint32_t data)
|
||||
{
|
||||
#ifdef ALLOW_UNALIGNED_ACCESSES
|
||||
* (uint32_t *) dst = htonl(data);
|
||||
#else
|
||||
uint8_t *p = (uint8_t *) dst;
|
||||
p[0] = (uint8_t) ((data >> 24) & 0xff);
|
||||
p[1] = (uint8_t) ((data >> 16) & 0xff);
|
||||
p[2] = (uint8_t) ((data >> 8) & 0xff);
|
||||
p[3] = (uint8_t) (data & 0xff);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \file sbuffer.h
|
||||
*
|
||||
* This file contains the definition of gldns_buffer, and functions to manipulate those.
|
||||
*/
|
||||
|
||||
/**
|
||||
* implementation of buffers to ease operations
|
||||
*
|
||||
* gldns_buffers can contain arbitrary information, per octet. You can write
|
||||
* to the current end of a buffer, read from the current position, and
|
||||
* access any data within it.
|
||||
*/
|
||||
struct gldns_buffer
|
||||
{
|
||||
/** The current position used for reading/writing */
|
||||
size_t _position;
|
||||
|
||||
/** The read/write limit */
|
||||
size_t _limit;
|
||||
|
||||
/** The amount of data the buffer can contain */
|
||||
size_t _capacity;
|
||||
|
||||
/** The data contained in the buffer */
|
||||
uint8_t *_data;
|
||||
|
||||
/** If the buffer is fixed it cannot be resized */
|
||||
unsigned _fixed : 1;
|
||||
|
||||
/** The current state of the buffer. If writing to the buffer fails
|
||||
* for any reason, this value is changed. This way, you can perform
|
||||
* multiple writes in sequence and check for success afterwards. */
|
||||
unsigned _status_err : 1;
|
||||
};
|
||||
typedef struct gldns_buffer gldns_buffer;
|
||||
|
||||
#ifdef NDEBUG
|
||||
INLINE void
|
||||
gldns_buffer_invariant(gldns_buffer *ATTR_UNUSED(buffer))
|
||||
{
|
||||
}
|
||||
#else
|
||||
INLINE void
|
||||
gldns_buffer_invariant(gldns_buffer *buffer)
|
||||
{
|
||||
assert(buffer != NULL);
|
||||
assert(buffer->_position <= buffer->_limit);
|
||||
assert(buffer->_limit <= buffer->_capacity);
|
||||
assert(buffer->_data != NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* creates a new buffer with the specified capacity.
|
||||
*
|
||||
* \param[in] capacity the size (in bytes) to allocate for the buffer
|
||||
* \return the created buffer
|
||||
*/
|
||||
gldns_buffer *gldns_buffer_new(size_t capacity);
|
||||
|
||||
/**
|
||||
* creates a buffer with the specified data. The data IS copied
|
||||
* and MEMORY allocations are done. The buffer is not fixed and can
|
||||
* be resized using buffer_reserve().
|
||||
*
|
||||
* \param[in] buffer pointer to the buffer to put the data in
|
||||
* \param[in] data the data to encapsulate in the buffer
|
||||
* \param[in] size the size of the data
|
||||
*/
|
||||
void gldns_buffer_new_frm_data(gldns_buffer *buffer, void *data, size_t size);
|
||||
|
||||
/**
|
||||
* Setup a buffer with the data pointed to. No data copied, no memory allocs.
|
||||
* The buffer is fixed.
|
||||
* \param[in] buffer pointer to the buffer to put the data in
|
||||
* \param[in] data the data to encapsulate in the buffer
|
||||
* \param[in] size the size of the data
|
||||
*/
|
||||
void gldns_buffer_init_frm_data(gldns_buffer *buffer, void *data, size_t size);
|
||||
|
||||
/**
|
||||
* clears the buffer and make it ready for writing. The buffer's limit
|
||||
* is set to the capacity and the position is set to 0.
|
||||
* \param[in] buffer the buffer to clear
|
||||
*/
|
||||
INLINE void gldns_buffer_clear(gldns_buffer *buffer)
|
||||
{
|
||||
gldns_buffer_invariant(buffer);
|
||||
|
||||
/* reset status here? */
|
||||
|
||||
buffer->_position = 0;
|
||||
buffer->_limit = buffer->_capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* makes the buffer ready for reading the data that has been written to
|
||||
* the buffer. The buffer's limit is set to the current position and
|
||||
* the position is set to 0.
|
||||
*
|
||||
* \param[in] buffer the buffer to flip
|
||||
* \return void
|
||||
*/
|
||||
INLINE void gldns_buffer_flip(gldns_buffer *buffer)
|
||||
{
|
||||
gldns_buffer_invariant(buffer);
|
||||
|
||||
buffer->_limit = buffer->_position;
|
||||
buffer->_position = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* make the buffer ready for re-reading the data. The buffer's
|
||||
* position is reset to 0.
|
||||
* \param[in] buffer the buffer to rewind
|
||||
*/
|
||||
INLINE void gldns_buffer_rewind(gldns_buffer *buffer)
|
||||
{
|
||||
gldns_buffer_invariant(buffer);
|
||||
|
||||
buffer->_position = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the current position in the buffer (as a number of bytes)
|
||||
* \param[in] buffer the buffer
|
||||
* \return the current position
|
||||
*/
|
||||
INLINE size_t
|
||||
gldns_buffer_position(gldns_buffer *buffer)
|
||||
{
|
||||
return buffer->_position;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the buffer's position to MARK. The position must be less than
|
||||
* or equal to the buffer's limit.
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] mark the mark to use
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_set_position(gldns_buffer *buffer, size_t mark)
|
||||
{
|
||||
assert(mark <= buffer->_limit);
|
||||
buffer->_position = mark;
|
||||
}
|
||||
|
||||
/**
|
||||
* changes the buffer's position by COUNT bytes. The position must not
|
||||
* be moved behind the buffer's limit or before the beginning of the
|
||||
* buffer.
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] count the count to use
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_skip(gldns_buffer *buffer, ssize_t count)
|
||||
{
|
||||
assert(buffer->_position + count <= buffer->_limit);
|
||||
buffer->_position += count;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the maximum size of the buffer
|
||||
* \param[in] buffer
|
||||
* \return the size
|
||||
*/
|
||||
INLINE size_t
|
||||
gldns_buffer_limit(gldns_buffer *buffer)
|
||||
{
|
||||
return buffer->_limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* changes the buffer's limit. If the buffer's position is greater
|
||||
* than the new limit the position is set to the limit.
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] limit the new limit
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_set_limit(gldns_buffer *buffer, size_t limit)
|
||||
{
|
||||
assert(limit <= buffer->_capacity);
|
||||
buffer->_limit = limit;
|
||||
if (buffer->_position > buffer->_limit)
|
||||
buffer->_position = buffer->_limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of bytes the buffer can hold.
|
||||
* \param[in] buffer the buffer
|
||||
* \return the number of bytes
|
||||
*/
|
||||
INLINE size_t
|
||||
gldns_buffer_capacity(gldns_buffer *buffer)
|
||||
{
|
||||
return buffer->_capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* changes the buffer's capacity. The data is reallocated so any
|
||||
* pointers to the data may become invalid. The buffer's limit is set
|
||||
* to the buffer's new capacity.
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] capacity the capacity to use
|
||||
* \return whether this failed or succeeded
|
||||
*/
|
||||
int gldns_buffer_set_capacity(gldns_buffer *buffer, size_t capacity);
|
||||
|
||||
/**
|
||||
* ensures BUFFER can contain at least AMOUNT more bytes. The buffer's
|
||||
* capacity is increased if necessary using buffer_set_capacity().
|
||||
*
|
||||
* The buffer's limit is always set to the (possibly increased)
|
||||
* capacity.
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] amount amount to use
|
||||
* \return whether this failed or succeeded
|
||||
*/
|
||||
int gldns_buffer_reserve(gldns_buffer *buffer, size_t amount);
|
||||
|
||||
/**
|
||||
* returns a pointer to the data at the indicated position.
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at position
|
||||
* \return the pointer to the data
|
||||
*/
|
||||
INLINE uint8_t *
|
||||
gldns_buffer_at(const gldns_buffer *buffer, size_t at)
|
||||
{
|
||||
assert(at <= buffer->_limit);
|
||||
return buffer->_data + at;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a pointer to the beginning of the buffer (the data at
|
||||
* position 0).
|
||||
* \param[in] buffer the buffer
|
||||
* \return the pointer
|
||||
*/
|
||||
INLINE uint8_t *
|
||||
gldns_buffer_begin(const gldns_buffer *buffer)
|
||||
{
|
||||
return gldns_buffer_at(buffer, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a pointer to the end of the buffer (the data at the buffer's
|
||||
* limit).
|
||||
* \param[in] buffer the buffer
|
||||
* \return the pointer
|
||||
*/
|
||||
INLINE uint8_t *
|
||||
gldns_buffer_end(gldns_buffer *buffer)
|
||||
{
|
||||
return gldns_buffer_at(buffer, buffer->_limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a pointer to the data at the buffer's current position.
|
||||
* \param[in] buffer the buffer
|
||||
* \return the pointer
|
||||
*/
|
||||
INLINE uint8_t *
|
||||
gldns_buffer_current(gldns_buffer *buffer)
|
||||
{
|
||||
return gldns_buffer_at(buffer, buffer->_position);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of bytes remaining between the indicated position and
|
||||
* the limit.
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at indicated position
|
||||
* \return number of bytes
|
||||
*/
|
||||
INLINE size_t
|
||||
gldns_buffer_remaining_at(gldns_buffer *buffer, size_t at)
|
||||
{
|
||||
gldns_buffer_invariant(buffer);
|
||||
assert(at <= buffer->_limit);
|
||||
return buffer->_limit - at;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of bytes remaining between the buffer's position and
|
||||
* limit.
|
||||
* \param[in] buffer the buffer
|
||||
* \return the number of bytes
|
||||
*/
|
||||
INLINE size_t
|
||||
gldns_buffer_remaining(gldns_buffer *buffer)
|
||||
{
|
||||
return gldns_buffer_remaining_at(buffer, buffer->_position);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the buffer has at least COUNT more bytes available.
|
||||
* Before reading or writing the caller needs to ensure enough space
|
||||
* is available!
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at indicated position
|
||||
* \param[in] count how much is available
|
||||
* \return true or false (as int?)
|
||||
*/
|
||||
INLINE int
|
||||
gldns_buffer_available_at(gldns_buffer *buffer, size_t at, size_t count)
|
||||
{
|
||||
return count <= gldns_buffer_remaining_at(buffer, at);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the buffer has count bytes available at the current position
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] count how much is available
|
||||
* \return true or false (as int?)
|
||||
*/
|
||||
INLINE int
|
||||
gldns_buffer_available(gldns_buffer *buffer, size_t count)
|
||||
{
|
||||
return gldns_buffer_available_at(buffer, buffer->_position, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* writes the given data to the buffer at the specified position
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at the position (in number of bytes) to write the data at
|
||||
* \param[in] data pointer to the data to write to the buffer
|
||||
* \param[in] count the number of bytes of data to write
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_write_at(gldns_buffer *buffer, size_t at, const void *data, size_t count)
|
||||
{
|
||||
assert(gldns_buffer_available_at(buffer, at, count));
|
||||
memcpy(buffer->_data + at, data, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* writes count bytes of data to the current position of the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] data the data to write
|
||||
* \param[in] count the lenght of the data to write
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_write(gldns_buffer *buffer, const void *data, size_t count)
|
||||
{
|
||||
gldns_buffer_write_at(buffer, buffer->_position, data, count);
|
||||
buffer->_position += count;
|
||||
}
|
||||
|
||||
/**
|
||||
* copies the given (null-delimited) string to the specified position at the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at the position in the buffer
|
||||
* \param[in] str the string to write
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_write_string_at(gldns_buffer *buffer, size_t at, const char *str)
|
||||
{
|
||||
gldns_buffer_write_at(buffer, at, str, strlen(str));
|
||||
}
|
||||
|
||||
/**
|
||||
* copies the given (null-delimited) string to the current position at the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] str the string to write
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_write_string(gldns_buffer *buffer, const char *str)
|
||||
{
|
||||
gldns_buffer_write(buffer, str, strlen(str));
|
||||
}
|
||||
|
||||
/**
|
||||
* writes the given byte of data at the given position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at the position in the buffer
|
||||
* \param[in] data the 8 bits to write
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_write_u8_at(gldns_buffer *buffer, size_t at, uint8_t data)
|
||||
{
|
||||
assert(gldns_buffer_available_at(buffer, at, sizeof(data)));
|
||||
buffer->_data[at] = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* writes the given byte of data at the current position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] data the 8 bits to write
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_write_u8(gldns_buffer *buffer, uint8_t data)
|
||||
{
|
||||
gldns_buffer_write_u8_at(buffer, buffer->_position, data);
|
||||
buffer->_position += sizeof(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* writes the given 2 byte integer at the given position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at the position in the buffer
|
||||
* \param[in] data the 16 bits to write
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_write_u16_at(gldns_buffer *buffer, size_t at, uint16_t data)
|
||||
{
|
||||
assert(gldns_buffer_available_at(buffer, at, sizeof(data)));
|
||||
gldns_write_uint16(buffer->_data + at, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* writes the given 2 byte integer at the current position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] data the 16 bits to write
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_write_u16(gldns_buffer *buffer, uint16_t data)
|
||||
{
|
||||
gldns_buffer_write_u16_at(buffer, buffer->_position, data);
|
||||
buffer->_position += sizeof(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* writes the given 4 byte integer at the given position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at the position in the buffer
|
||||
* \param[in] data the 32 bits to write
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_write_u32_at(gldns_buffer *buffer, size_t at, uint32_t data)
|
||||
{
|
||||
assert(gldns_buffer_available_at(buffer, at, sizeof(data)));
|
||||
gldns_write_uint32(buffer->_data + at, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* writes the given 4 byte integer at the current position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] data the 32 bits to write
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_write_u32(gldns_buffer *buffer, uint32_t data)
|
||||
{
|
||||
gldns_buffer_write_u32_at(buffer, buffer->_position, data);
|
||||
buffer->_position += sizeof(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* copies count bytes of data at the given position to the given data-array
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at the position in the buffer to start
|
||||
* \param[out] data buffer to copy to
|
||||
* \param[in] count the length of the data to copy
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_read_at(gldns_buffer *buffer, size_t at, void *data, size_t count)
|
||||
{
|
||||
assert(gldns_buffer_available_at(buffer, at, count));
|
||||
memcpy(data, buffer->_data + at, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* copies count bytes of data at the current position to the given data-array
|
||||
* \param[in] buffer the buffer
|
||||
* \param[out] data buffer to copy to
|
||||
* \param[in] count the length of the data to copy
|
||||
*/
|
||||
INLINE void
|
||||
gldns_buffer_read(gldns_buffer *buffer, void *data, size_t count)
|
||||
{
|
||||
gldns_buffer_read_at(buffer, buffer->_position, data, count);
|
||||
buffer->_position += count;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the byte value at the given position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at the position in the buffer
|
||||
* \return 1 byte integer
|
||||
*/
|
||||
INLINE uint8_t
|
||||
gldns_buffer_read_u8_at(gldns_buffer *buffer, size_t at)
|
||||
{
|
||||
assert(gldns_buffer_available_at(buffer, at, sizeof(uint8_t)));
|
||||
return buffer->_data[at];
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the byte value at the current position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \return 1 byte integer
|
||||
*/
|
||||
INLINE uint8_t
|
||||
gldns_buffer_read_u8(gldns_buffer *buffer)
|
||||
{
|
||||
uint8_t result = gldns_buffer_read_u8_at(buffer, buffer->_position);
|
||||
buffer->_position += sizeof(uint8_t);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the 2-byte integer value at the given position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at position in the buffer
|
||||
* \return 2 byte integer
|
||||
*/
|
||||
INLINE uint16_t
|
||||
gldns_buffer_read_u16_at(gldns_buffer *buffer, size_t at)
|
||||
{
|
||||
assert(gldns_buffer_available_at(buffer, at, sizeof(uint16_t)));
|
||||
return gldns_read_uint16(buffer->_data + at);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the 2-byte integer value at the current position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \return 2 byte integer
|
||||
*/
|
||||
INLINE uint16_t
|
||||
gldns_buffer_read_u16(gldns_buffer *buffer)
|
||||
{
|
||||
uint16_t result = gldns_buffer_read_u16_at(buffer, buffer->_position);
|
||||
buffer->_position += sizeof(uint16_t);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the 4-byte integer value at the given position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \param[in] at position in the buffer
|
||||
* \return 4 byte integer
|
||||
*/
|
||||
INLINE uint32_t
|
||||
gldns_buffer_read_u32_at(gldns_buffer *buffer, size_t at)
|
||||
{
|
||||
assert(gldns_buffer_available_at(buffer, at, sizeof(uint32_t)));
|
||||
return gldns_read_uint32(buffer->_data + at);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the 4-byte integer value at the current position in the buffer
|
||||
* \param[in] buffer the buffer
|
||||
* \return 4 byte integer
|
||||
*/
|
||||
INLINE uint32_t
|
||||
gldns_buffer_read_u32(gldns_buffer *buffer)
|
||||
{
|
||||
uint32_t result = gldns_buffer_read_u32_at(buffer, buffer->_position);
|
||||
buffer->_position += sizeof(uint32_t);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the status of the buffer
|
||||
* \param[in] buffer
|
||||
* \return the status
|
||||
*/
|
||||
INLINE int
|
||||
gldns_buffer_status(gldns_buffer *buffer)
|
||||
{
|
||||
return (int)buffer->_status_err;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if the status of the buffer is GLDNS_STATUS_OK, false otherwise
|
||||
* \param[in] buffer the buffer
|
||||
* \return true or false
|
||||
*/
|
||||
INLINE int
|
||||
gldns_buffer_status_ok(gldns_buffer *buffer)
|
||||
{
|
||||
if (buffer) {
|
||||
return gldns_buffer_status(buffer) == 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* prints to the buffer, increasing the capacity if required using
|
||||
* buffer_reserve(). The buffer's position is set to the terminating '\\0'
|
||||
* Returns the number of characters written (not including the
|
||||
* terminating '\\0') or -1 on failure.
|
||||
*/
|
||||
int gldns_buffer_printf(gldns_buffer *buffer, const char *format, ...)
|
||||
ATTR_FORMAT(printf, 2, 3);
|
||||
|
||||
/**
|
||||
* frees the buffer.
|
||||
* \param[in] *buffer the buffer to be freed
|
||||
* \return void
|
||||
*/
|
||||
void gldns_buffer_free(gldns_buffer *buffer);
|
||||
|
||||
/**
|
||||
* Makes the buffer fixed and returns a pointer to the data. The
|
||||
* caller is responsible for free'ing the result.
|
||||
* \param[in] *buffer the buffer to be exported
|
||||
* \return void
|
||||
*/
|
||||
void *gldns_buffer_export(gldns_buffer *buffer);
|
||||
|
||||
/**
|
||||
* Copy contents of the from buffer to the result buffer and then flips
|
||||
* the result buffer. Data will be silently truncated if the result buffer is
|
||||
* too small.
|
||||
* \param[out] *result resulting buffer which is copied to.
|
||||
* \param[in] *from what to copy to result.
|
||||
*/
|
||||
void gldns_buffer_copy(gldns_buffer* result, gldns_buffer* from);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GLDNS_SBUFFER_H */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,541 @@
|
|||
/**
|
||||
* str2wire.h - read txt presentation of RRs
|
||||
*
|
||||
* (c) NLnet Labs, 2005-2006
|
||||
*
|
||||
* See the file LICENSE for the license
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* Parses text to wireformat.
|
||||
*/
|
||||
|
||||
#ifndef GLDNS_STR2WIRE_H
|
||||
#define GLDNS_STR2WIRE_H
|
||||
|
||||
/* include rrdef for MAX_DOMAINLEN constant */
|
||||
#include "gldns/rrdef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
struct gldns_struct_lookup_table;
|
||||
|
||||
/** buffer to read an RR, cannot be larger than 64K because of packet size */
|
||||
#define GLDNS_RR_BUF_SIZE 65535 /* bytes */
|
||||
#define GLDNS_DEFAULT_TTL 3600
|
||||
|
||||
/*
|
||||
* To convert class and type to string see
|
||||
* gldns_get_rr_class_by_name(str)
|
||||
* gldns_get_rr_type_by_name(str)
|
||||
* from rrdef.h
|
||||
*/
|
||||
|
||||
/**
|
||||
* Convert text string into dname wireformat, mallocless, with user buffer.
|
||||
* @param str: the text string with the domain name.
|
||||
* @param buf: the result buffer, suggested size GLDNS_MAX_DOMAINLEN+1
|
||||
* @param len: length of the buffer on input, length of the result on output.
|
||||
* @return 0 on success, otherwise an error.
|
||||
*/
|
||||
int gldns_str2wire_dname_buf(const char* str, uint8_t* buf, size_t* len);
|
||||
|
||||
/**
|
||||
* Same as gldns_str2wire_dname_buf, but concatenates origin if the domain
|
||||
* name is relative (does not end in '.').
|
||||
* @param str: the text string with the domain name.
|
||||
* @param buf: the result buffer, suggested size GLDNS_MAX_DOMAINLEN+1
|
||||
* @param len: length of the buffer on input, length of the result on output.
|
||||
* @param origin: the origin to append or NULL (nothing is appended).
|
||||
* @param origin_len: length of origin.
|
||||
* @return 0 on success, otherwise an error.
|
||||
*/
|
||||
int gldns_str2wire_dname_buf_origin(const char* str, uint8_t* buf, size_t* len,
|
||||
uint8_t* origin, size_t origin_len);
|
||||
|
||||
/**
|
||||
* Convert text string into dname wireformat
|
||||
* @param str: the text string with the domain name.
|
||||
* @param len: returned length of wireformat.
|
||||
* @return wireformat dname (malloced) or NULL on failure.
|
||||
*/
|
||||
uint8_t* gldns_str2wire_dname(const char* str, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert text RR to wireformat, with user buffer.
|
||||
* @param str: the RR data in text presentation format.
|
||||
* @param rr: the buffer where the result is stored into. This buffer has
|
||||
* the wire-dname(uncompressed), type, class, ttl, rdatalen, rdata.
|
||||
* These values are probably not aligned, and in network format.
|
||||
* Use the gldns_wirerr_get_xxx functions to access them safely.
|
||||
* buffer size GLDNS_RR_BUF_SIZE is suggested.
|
||||
* @param len: on input the length of the buffer, on output the amount of
|
||||
* the buffer used for the rr.
|
||||
* @param dname_len: if non-NULL, filled with the dname length as result.
|
||||
* Because after the dname you find the type, class, ttl, rdatalen, rdata.
|
||||
* @param default_ttl: TTL used if no TTL available.
|
||||
* @param origin: used for origin dname (if not NULL)
|
||||
* @param origin_len: length of origin.
|
||||
* @param prev: used for prev_rr dname (if not NULL)
|
||||
* @param prev_len: length of prev.
|
||||
* @return 0 on success, an error on failure.
|
||||
*/
|
||||
int gldns_str2wire_rr_buf(const char* str, uint8_t* rr, size_t* len,
|
||||
size_t* dname_len, uint32_t default_ttl, uint8_t* origin,
|
||||
size_t origin_len, uint8_t* prev, size_t prev_len);
|
||||
|
||||
/**
|
||||
* Same as gldns_str2wire_rr_buf, but there is no rdata, it returns an RR
|
||||
* with zero rdata and no ttl. It has name, type, class.
|
||||
* You can access those with the gldns_wirerr_get_type and class functions.
|
||||
* @param str: the RR data in text presentation format.
|
||||
* @param rr: the buffer where the result is stored into.
|
||||
* @param len: on input the length of the buffer, on output the amount of
|
||||
* the buffer used for the rr.
|
||||
* @param dname_len: if non-NULL, filled with the dname length as result.
|
||||
* Because after the dname you find the type, class, ttl, rdatalen, rdata.
|
||||
* @param origin: used for origin dname (if not NULL)
|
||||
* @param origin_len: length of origin.
|
||||
* @param prev: used for prev_rr dname (if not NULL)
|
||||
* @param prev_len: length of prev.
|
||||
* @return 0 on success, an error on failure.
|
||||
*/
|
||||
int gldns_str2wire_rr_question_buf(const char* str, uint8_t* rr, size_t* len,
|
||||
size_t* dname_len, uint8_t* origin, size_t origin_len, uint8_t* prev,
|
||||
size_t prev_len);
|
||||
|
||||
/**
|
||||
* Get the type of the RR.
|
||||
* @param rr: the RR in wire format.
|
||||
* @param len: rr length.
|
||||
* @param dname_len: dname length to skip.
|
||||
* @return type in host byteorder
|
||||
*/
|
||||
uint16_t gldns_wirerr_get_type(uint8_t* rr, size_t len, size_t dname_len);
|
||||
|
||||
/**
|
||||
* Get the class of the RR.
|
||||
* @param rr: the RR in wire format.
|
||||
* @param len: rr length.
|
||||
* @param dname_len: dname length to skip.
|
||||
* @return class in host byteorder
|
||||
*/
|
||||
uint16_t gldns_wirerr_get_class(uint8_t* rr, size_t len, size_t dname_len);
|
||||
|
||||
/**
|
||||
* Get the ttl of the RR.
|
||||
* @param rr: the RR in wire format.
|
||||
* @param len: rr length.
|
||||
* @param dname_len: dname length to skip.
|
||||
* @return ttl in host byteorder
|
||||
*/
|
||||
uint32_t gldns_wirerr_get_ttl(uint8_t* rr, size_t len, size_t dname_len);
|
||||
|
||||
/**
|
||||
* Get the rdata length of the RR.
|
||||
* @param rr: the RR in wire format.
|
||||
* @param len: rr length.
|
||||
* @param dname_len: dname length to skip.
|
||||
* @return rdata length in host byteorder
|
||||
* If the rdata length is larger than the rr-len allows, it is truncated.
|
||||
* So, that it is safe to read the data length returned
|
||||
* from this function from the rdata pointer of gldns_wirerr_get_rdata.
|
||||
*/
|
||||
uint16_t gldns_wirerr_get_rdatalen(uint8_t* rr, size_t len, size_t dname_len);
|
||||
|
||||
/**
|
||||
* Get the rdata pointer of the RR.
|
||||
* @param rr: the RR in wire format.
|
||||
* @param len: rr length.
|
||||
* @param dname_len: dname length to skip.
|
||||
* @return rdata pointer
|
||||
*/
|
||||
uint8_t* gldns_wirerr_get_rdata(uint8_t* rr, size_t len, size_t dname_len);
|
||||
|
||||
/**
|
||||
* Get the rdata pointer of the RR. prefixed with rdata length.
|
||||
* @param rr: the RR in wire format.
|
||||
* @param len: rr length.
|
||||
* @param dname_len: dname length to skip.
|
||||
* @return pointer to rdatalength, followed by the rdata.
|
||||
*/
|
||||
uint8_t* gldns_wirerr_get_rdatawl(uint8_t* rr, size_t len, size_t dname_len);
|
||||
|
||||
/**
|
||||
* Parse result codes
|
||||
*/
|
||||
#define GLDNS_WIREPARSE_MASK 0x0fff
|
||||
#define GLDNS_WIREPARSE_SHIFT 12
|
||||
#define GLDNS_WIREPARSE_ERROR(e) ((e)&GLDNS_WIREPARSE_MASK)
|
||||
#define GLDNS_WIREPARSE_OFFSET(e) (((e)&~GLDNS_WIREPARSE_MASK)>>GLDNS_WIREPARSE_SHIFT)
|
||||
/* use lookuptable to get error string, gldns_wireparse_errors */
|
||||
#define GLDNS_WIREPARSE_ERR_OK 0
|
||||
#define GLDNS_WIREPARSE_ERR_GENERAL 342
|
||||
#define GLDNS_WIREPARSE_ERR_DOMAINNAME_OVERFLOW 343
|
||||
#define GLDNS_WIREPARSE_ERR_DOMAINNAME_UNDERFLOW 344
|
||||
#define GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL 345
|
||||
#define GLDNS_WIREPARSE_ERR_LABEL_OVERFLOW 346
|
||||
#define GLDNS_WIREPARSE_ERR_EMPTY_LABEL 347
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_BAD_ESCAPE 348
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX 349
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_TTL 350
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_TYPE 351
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_CLASS 352
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_RDATA 353
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_MISSING_VALUE 354
|
||||
#define GLDNS_WIREPARSE_ERR_INVALID_STR 355
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_B64 356
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_B32_EXT 357
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_HEX 358
|
||||
#define GLDNS_WIREPARSE_ERR_CERT_BAD_ALGORITHM 359
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_TIME 360
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_PERIOD 361
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_ILNP64 362
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_EUI48 363
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_EUI64 364
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_TAG 365
|
||||
#define GLDNS_WIREPARSE_ERR_NOT_IMPL 366
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_INT 367
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_IP4 368
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_IP6 369
|
||||
#define GLDNS_WIREPARSE_ERR_SYNTAX_INTEGER_OVERFLOW 370
|
||||
#define GLDNS_WIREPARSE_ERR_INCLUDE 371
|
||||
#define GLDNS_WIREPARSE_ERR_PARENTHESIS 372
|
||||
|
||||
/**
|
||||
* Get reference to a constant string for the (parse) error.
|
||||
* @param e: error return value
|
||||
* @return string.
|
||||
*/
|
||||
const char* gldns_get_errorstr_parse(int e);
|
||||
|
||||
/**
|
||||
* wire parse state for parsing files
|
||||
*/
|
||||
struct gldns_file_parse_state {
|
||||
/** the origin domain name, if len!=0. uncompressed wireformat */
|
||||
uint8_t origin[GLDNS_MAX_DOMAINLEN+1];
|
||||
/** length of origin domain name, in bytes. 0 if not set. */
|
||||
size_t origin_len;
|
||||
/** the previous domain name, if len!=0. uncompressed wireformat*/
|
||||
uint8_t prev_rr[GLDNS_MAX_DOMAINLEN+1];
|
||||
/** length of the previous domain name, in bytes. 0 if not set. */
|
||||
size_t prev_rr_len;
|
||||
/** default TTL, this is used if the text does not specify a TTL,
|
||||
* host byteorder */
|
||||
uint32_t default_ttl;
|
||||
/** line number information */
|
||||
int lineno;
|
||||
};
|
||||
|
||||
/**
|
||||
* Read one RR from zonefile with buffer for the data.
|
||||
* @param in: file that is read from (one RR, multiple lines if it spans them).
|
||||
* @param rr: this is malloced by the user and the result is stored here,
|
||||
* if an RR is read. If no RR is read this is signalled with the
|
||||
* return len set to 0 (for ORIGIN, TTL directives).
|
||||
* @param len: on input, the length of the rr buffer. on output the rr len.
|
||||
* Buffer size of 64k should be enough.
|
||||
* @param dname_len: returns the length of the dname initial part of the rr.
|
||||
* @param parse_state: pass a pointer to user-allocated struct.
|
||||
* Contents are maintained by this function.
|
||||
* If you pass NULL then ORIGIN and TTL directives are not honored.
|
||||
* You can start out with a particular origin by pre-filling it.
|
||||
* otherwise, zero the structure before passing it.
|
||||
* lineno is incremented when a newline is passed by the parser,
|
||||
* you should initialize it at 1 at the start of the file.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len,
|
||||
struct gldns_file_parse_state* parse_state);
|
||||
|
||||
/**
|
||||
* Convert one rdf in rdata to wireformat and parse from string.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @param rdftype: the type of the rdf.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_rdf_buf(const char* str, uint8_t* rd, size_t* len,
|
||||
gldns_rdf_type rdftype);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_INT8 from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_int8_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_INT16 from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_int16_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_INT32 from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_int32_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_A from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_a_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_AAAA from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_aaaa_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_STR from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_str_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_APL from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_apl_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_B64 from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_b64_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_B32_EXT from string to wireformat.
|
||||
* And also GLDNS_RDF_TYPE_NSEC3_NEXT_OWNER.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_b32_ext_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_HEX from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_hex_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_NSEC from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_nsec_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_TYPE from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_type_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_CLASS from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_class_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_CERT_ALG from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_cert_alg_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_ALG from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_alg_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_TIME from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_time_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_PERIOD from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_period_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_LOC from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_loc_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_WKS from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_NSAP from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_nsap_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_ATMA from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_atma_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_IPSECKEY from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_ipseckey_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_NSEC3_SALT from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_nsec3_salt_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_ILNP64 from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_ilnp64_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_EUI48 from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_eui48_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_EUI64 from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_eui64_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_TAG from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_tag_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_LONG_STR from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_long_str_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_HIP from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_hip_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
/**
|
||||
* Convert rdf of type GLDNS_RDF_TYPE_INT16_DATA from string to wireformat.
|
||||
* @param str: the text to convert for this rdata element.
|
||||
* @param rd: rdata buffer for the wireformat.
|
||||
* @param len: length of rd buffer on input, used length on output.
|
||||
* @return 0 on success, error on failure.
|
||||
*/
|
||||
int gldns_str2wire_int16_data_buf(const char* str, uint8_t* rd, size_t* len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GLDNS_STR2WIRE_H */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,984 @@
|
|||
/**
|
||||
* wire2str.h - txt presentation of RRs
|
||||
*
|
||||
* (c) NLnet Labs, 2005-2006
|
||||
*
|
||||
* See the file LICENSE for the license
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* Contains functions to translate the wireformat to text
|
||||
* representation, as well as functions to print them.
|
||||
*/
|
||||
|
||||
#ifndef GLDNS_WIRE2STR_H
|
||||
#define GLDNS_WIRE2STR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
struct gldns_struct_lookup_table;
|
||||
|
||||
/* lookup tables for standard DNS stuff */
|
||||
/** Taken from RFC 2535, section 7. */
|
||||
extern struct gldns_struct_lookup_table* gldns_algorithms;
|
||||
/** DS record hash algorithms */
|
||||
extern struct gldns_struct_lookup_table* gldns_hashes;
|
||||
/** Taken from RFC 2538, section 2.1. */
|
||||
extern struct gldns_struct_lookup_table* gldns_cert_algorithms;
|
||||
/** Response codes */
|
||||
extern struct gldns_struct_lookup_table* gldns_rcodes;
|
||||
/** Operation codes */
|
||||
extern struct gldns_struct_lookup_table* gldns_opcodes;
|
||||
/** EDNS flags */
|
||||
extern struct gldns_struct_lookup_table* gldns_edns_flags;
|
||||
/** EDNS option codes */
|
||||
extern struct gldns_struct_lookup_table* gldns_edns_options;
|
||||
/** error string from wireparse */
|
||||
extern struct gldns_struct_lookup_table* gldns_wireparse_errors;
|
||||
|
||||
/**
|
||||
* Convert wireformat packet to a string representation
|
||||
* @param data: wireformat packet data (starting at ID bytes).
|
||||
* @param len: length of packet.
|
||||
* @return string(malloced) or NULL on failure.
|
||||
*/
|
||||
char* gldns_wire2str_pkt(uint8_t* data, size_t len);
|
||||
|
||||
/**
|
||||
* Convert wireformat RR to a string representation.
|
||||
* @param rr: the wireformat RR, in uncompressed form. Starts at the domain
|
||||
* name start, ends with the rdata of the RR.
|
||||
* @param len: length of the rr wireformat.
|
||||
* @return string(malloced) or NULL on failure.
|
||||
*/
|
||||
char* gldns_wire2str_rr(uint8_t* rr, size_t len);
|
||||
|
||||
/**
|
||||
* Conver wire dname to a string.
|
||||
* @param dname: the dname in uncompressed wireformat.
|
||||
* @param dname_len: length of the dname.
|
||||
* @return string or NULL on failure.
|
||||
*/
|
||||
char* gldns_wire2str_dname(uint8_t* dname, size_t dname_len);
|
||||
|
||||
/**
|
||||
* Convert wire RR type to a string, 'MX', 'TYPE1234'...
|
||||
* @param rrtype: the RR type in host order.
|
||||
* @return malloced string with the RR type or NULL on malloc failure.
|
||||
*/
|
||||
char* gldns_wire2str_type(uint16_t rrtype);
|
||||
|
||||
/**
|
||||
* Convert wire RR class to a string, 'IN', 'CLASS1'.
|
||||
* @param rrclass: the RR class in host order.
|
||||
* @return malloced string with the RR class or NULL on malloc failure.
|
||||
*/
|
||||
char* gldns_wire2str_class(uint16_t rrclass);
|
||||
|
||||
/**
|
||||
* Convert wire packet rcode to a string, 'NOERROR', 'NXDOMAIN'...
|
||||
* @param rcode: as integer, host order
|
||||
* @return malloced string with the rcode or NULL on malloc failure.
|
||||
*/
|
||||
char* gldns_wire2str_rcode(int rcode);
|
||||
|
||||
/**
|
||||
* Print to string, move string along for next content. With va_list.
|
||||
* @param str: string buffer. Adjusted at end to after the output.
|
||||
* @param slen: length of the string buffer. Adjusted at end.
|
||||
* @param format: printf format string.
|
||||
* @param args: arguments for printf.
|
||||
* @return number of characters needed. Can be larger than slen.
|
||||
*/
|
||||
int gldns_str_vprint(char** str, size_t* slen, const char* format, va_list args);
|
||||
|
||||
/**
|
||||
* Print to string, move string along for next content.
|
||||
* @param str: string buffer. Adjusted at end to after the output.
|
||||
* @param slen: length of the string buffer. Adjusted at end.
|
||||
* @param format: printf format string and arguments for it.
|
||||
* @return number of characters needed. Can be larger than slen.
|
||||
*/
|
||||
int gldns_str_print(char** str, size_t* slen, const char* format, ...)
|
||||
ATTR_FORMAT(printf, 3, 4);
|
||||
|
||||
/**
|
||||
* Convert wireformat packet to a string representation with user buffer
|
||||
* It appends every RR with default comments.
|
||||
* For more formatter options use the function: TBD(TODO)
|
||||
* @param data: wireformat packet data (starting at ID bytes).
|
||||
* @param data_len: length of packet.
|
||||
* @param str: the string buffer for the output.
|
||||
* If you pass NULL as the str the return value of the function is
|
||||
* the str_len you need for the entire packet. It does not include
|
||||
* the 0 byte at the end.
|
||||
* @param str_len: the size of the string buffer. If more is needed, it'll
|
||||
* silently truncate the output to fit in the buffer.
|
||||
* @return the number of characters for this element, excluding zerobyte.
|
||||
* Is larger than str_len if output was truncated.
|
||||
*/
|
||||
int gldns_wire2str_pkt_buf(uint8_t* data, size_t data_len, char* str,
|
||||
size_t str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat packet to a string representation with user buffer
|
||||
* It appends every RR with default comments.
|
||||
* For more formatter options use the function: TBD(TODO)
|
||||
* @param data: wireformat packet data (starting at ID bytes).
|
||||
* @param data_len: length of packet.
|
||||
* @param str: the string buffer for the output.
|
||||
* @param str_len: the size of the string buffer.
|
||||
* @return number of characters for string.
|
||||
* returns the number of characters that are needed (except terminating null),
|
||||
* so it may return a value larger than str_len.
|
||||
* On error you get less output (i.e. shorter output in str (null terminated))
|
||||
* On exit the data, data_len, str and str_len values are adjusted to move them
|
||||
* from their original position along the input and output for the content
|
||||
* that has been consumed (and produced) by this function. If the end of the
|
||||
* output string is reached, *str_len is set to 0. The output string is null
|
||||
* terminated (shortening the output if necessary). If the end of the input
|
||||
* is reached *data_len is set to 0.
|
||||
*/
|
||||
int gldns_wire2str_pkt_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat rr to string, with user buffers. It shifts the arguments
|
||||
* to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param pkt: packet for decompression, if NULL no decompression.
|
||||
* @param pktlen: length of packet buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_rr_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len, uint8_t* pkt, size_t pktlen);
|
||||
|
||||
/**
|
||||
* Scan wireformat question rr to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param pkt: packet for decompression, if NULL no decompression.
|
||||
* @param pktlen: length of packet buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_rrquestion_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len, uint8_t* pkt, size_t pktlen);
|
||||
|
||||
/**
|
||||
* Scan wireformat RR to string in unknown RR format, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param pkt: packet for decompression, if NULL no decompression.
|
||||
* @param pktlen: length of packet buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_rr_unknown_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len, uint8_t* pkt, size_t pktlen);
|
||||
|
||||
/**
|
||||
* Print to string the RR-information comment in default format,
|
||||
* with user buffers. Moves string along.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param rr: wireformat data.
|
||||
* @param rrlen: length of data buffer.
|
||||
* @param dname_off: offset in buffer behind owner dname, the compressed size
|
||||
* of the owner name.
|
||||
* @param rrtype: type of the RR, host format.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_rr_comment_print(char** str, size_t* str_len, uint8_t* rr,
|
||||
size_t rrlen, size_t dname_off, uint16_t rrtype);
|
||||
|
||||
/**
|
||||
* Scan wireformat packet header to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_header_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat rdata to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer. The length of the rdata in the
|
||||
* buffer. The rdatalen itself has already been scanned, the data
|
||||
* points to the rdata after the rdatalen.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param rrtype: RR type of Rdata, host format.
|
||||
* @param pkt: packet for decompression, if NULL no decompression.
|
||||
* @param pktlen: length of packet buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_rdata_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len, uint16_t rrtype, uint8_t* pkt, size_t pktlen);
|
||||
|
||||
/**
|
||||
* Scan wireformat rdata to string in unknown format, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer, the length of the rdata in buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_rdata_unknown_scan(uint8_t** data, size_t* data_len,
|
||||
char** str, size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat domain name to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param pkt: packet for decompression, if NULL no decompression.
|
||||
* @param pktlen: length of packet buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_dname_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len, uint8_t* pkt, size_t pktlen);
|
||||
|
||||
/**
|
||||
* Scan wireformat rr type to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_type_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat rr class to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_class_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat rr ttl to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_ttl_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
|
||||
/**
|
||||
* Print host format rr type to string. Moves string along, user buffers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param rrtype: host format rr type.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_type_print(char** str, size_t* str_len, uint16_t rrtype);
|
||||
|
||||
/**
|
||||
* Print host format rr class to string. Moves string along, user buffers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param rrclass: host format rr class.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_class_print(char** str, size_t* str_len, uint16_t rrclass);
|
||||
|
||||
/**
|
||||
* Print host format rcode to string. Moves string along, user buffers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param rcode: host format rcode number.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_rcode_print(char** str, size_t* str_len, int rcode);
|
||||
|
||||
/**
|
||||
* Print host format opcode to string. Moves string along, user buffers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param opcode: host format opcode number.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_opcode_print(char** str, size_t* str_len, int opcode);
|
||||
|
||||
/**
|
||||
* Print host format EDNS0 option to string. Moves string along, user buffers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param opcode: host format option number.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_edns_option_code_print(char** str, size_t* str_len,
|
||||
uint16_t opcode);
|
||||
|
||||
/**
|
||||
* Convert RR to string presentation format, on one line. User buffer.
|
||||
* @param rr: wireformat RR data
|
||||
* @param rr_len: length of the rr wire data.
|
||||
* @param str: the string buffer to write to.
|
||||
* If you pass NULL as the str, the return value of the function is
|
||||
* the str_len you need for the entire packet. It does not include
|
||||
* the 0 byte at the end.
|
||||
* @param str_len: the size of the string buffer. If more is needed, it'll
|
||||
* silently truncate the output to fit in the buffer.
|
||||
* @return the number of characters for this element, excluding zerobyte.
|
||||
* Is larger than str_len if output was truncated.
|
||||
*/
|
||||
int gldns_wire2str_rr_buf(uint8_t* rr, size_t rr_len, char* str,
|
||||
size_t str_len);
|
||||
|
||||
/**
|
||||
* 3597 printout of an RR in unknown rr format.
|
||||
* There are more format and comment options available for printout
|
||||
* with the function: TBD(TODO)
|
||||
* @param rr: wireformat RR data
|
||||
* @param rr_len: length of the rr wire data.
|
||||
* @param str: the string buffer to write to.
|
||||
* If you pass NULL as the str, the return value of the function is
|
||||
* the str_len you need for the entire rr. It does not include
|
||||
* the 0 byte at the end.
|
||||
* @param str_len: the size of the string buffer. If more is needed, it'll
|
||||
* silently truncate the output to fit in the buffer.
|
||||
* @return the number of characters for this element, excluding zerobyte.
|
||||
* Is larger than str_len if output was truncated.
|
||||
*/
|
||||
int gldns_wire2str_rr_unknown_buf(uint8_t* rr, size_t rr_len, char* str,
|
||||
size_t str_len);
|
||||
|
||||
/**
|
||||
* This creates the comment to print after the RR. ; keytag=... , and other
|
||||
* basic comments for RRs.
|
||||
* There are more format and comment options available for printout
|
||||
* with the function: TBD(TODO)
|
||||
* @param rr: wireformat RR data
|
||||
* @param rr_len: length of the rr wire data.
|
||||
* @param dname_len: length of the dname in front of the RR.
|
||||
* @param str: the string buffer to write to.
|
||||
* If you pass NULL as the str, the return value of the function is
|
||||
* the str_len you need for the entire comment. It does not include
|
||||
* the 0 byte at the end.
|
||||
* @param str_len: the size of the string buffer. If more is needed, it'll
|
||||
* silently truncate the output to fit in the buffer.
|
||||
* @return the number of characters for this element, excluding zerobyte.
|
||||
* Is larger than str_len if output was truncated.
|
||||
*/
|
||||
int gldns_wire2str_rr_comment_buf(uint8_t* rr, size_t rr_len, size_t dname_len,
|
||||
char* str, size_t str_len);
|
||||
|
||||
/**
|
||||
* Convert RDATA to string presentation format, on one line. User buffer.
|
||||
* @param rdata: wireformat rdata part of an RR.
|
||||
* @param rdata_len: length of the rr wire data.
|
||||
* @param str: the string buffer to write to.
|
||||
* If you pass NULL as the str, the return value of the function is
|
||||
* the str_len you need for the entire packet. It does not include
|
||||
* the 0 byte at the end.
|
||||
* @param str_len: the size of the string buffer. If more is needed, it'll
|
||||
* silently truncate the output to fit in the buffer.
|
||||
* @param rrtype: rr type of the data
|
||||
* @return the number of characters for this element, excluding zerobyte.
|
||||
* Is larger than str_len if output was truncated.
|
||||
*/
|
||||
int gldns_wire2str_rdata_buf(uint8_t* rdata, size_t rdata_len, char* str,
|
||||
size_t str_len, uint16_t rrtype);
|
||||
|
||||
/**
|
||||
* Convert wire RR type to a string, 'MX', 'TYPE12'. With user buffer.
|
||||
* @param rrtype: the RR type in host order.
|
||||
* @param str: the string to write to.
|
||||
* @param len: length of str.
|
||||
* @return the number of characters for this element, excluding zerobyte.
|
||||
* Is larger than str_len if output was truncated.
|
||||
*/
|
||||
int gldns_wire2str_type_buf(uint16_t rrtype, char* str, size_t len);
|
||||
|
||||
/**
|
||||
* Convert wire RR class to a string, 'IN', 'CLASS12'. With user buffer.
|
||||
* @param rrclass: the RR class in host order.
|
||||
* @param str: the string to write to.
|
||||
* @param len: length of str.
|
||||
* @return the number of characters for this element, excluding zerobyte.
|
||||
* Is larger than str_len if output was truncated.
|
||||
*/
|
||||
int gldns_wire2str_class_buf(uint16_t rrclass, char* str, size_t len);
|
||||
|
||||
/**
|
||||
* Convert wire RR rcode to a string, 'NOERROR', 'NXDOMAIN'. With user buffer.
|
||||
* @param rcode: rcode as integer in host order
|
||||
* @param str: the string to write to.
|
||||
* @param len: length of str.
|
||||
* @return the number of characters for this element, excluding zerobyte.
|
||||
* Is larger than str_len if output was truncated.
|
||||
*/
|
||||
int gldns_wire2str_rcode_buf(int rcode, char* str, size_t len);
|
||||
|
||||
/**
|
||||
* Convert wire dname to a string, "example.com.". With user buffer.
|
||||
* @param dname: the dname in uncompressed wireformat.
|
||||
* @param dname_len: length of the dname.
|
||||
* @param str: the string to write to.
|
||||
* @param len: length of string.
|
||||
* @return the number of characters for this element, excluding zerobyte.
|
||||
* Is larger than str_len if output was truncated.
|
||||
*/
|
||||
int gldns_wire2str_dname_buf(uint8_t* dname, size_t dname_len, char* str,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* Scan wireformat rdf field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param rdftype: the type of the rdata field, enum gldns_rdf_type.
|
||||
* @param pkt: packet for decompression, if NULL no decompression.
|
||||
* @param pktlen: length of packet buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_rdf_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len, int rdftype, uint8_t* pkt, size_t pktlen);
|
||||
|
||||
/**
|
||||
* Scan wireformat int8 field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_int8_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat int16 field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_int16_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat int32 field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_int32_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat period field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_period_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat tsigtime field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_tsigtime_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat ip4 A field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_a_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat ip6 AAAA field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_aaaa_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat str field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_str_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat apl field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_apl_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat b32_ext field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_b32_ext_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat b64 field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_b64_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat hex field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_hex_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat nsec bitmap field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_nsec_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat nsec3_salt field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_nsec3_salt_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat cert_alg field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_cert_alg_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat alg field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_alg_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat type unknown field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_unknown_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat time field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_time_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat LOC field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_loc_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat WKS field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_wks_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat NSAP field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_nsap_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat ATMA field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_atma_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat IPSECKEY field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param pkt: packet for decompression, if NULL no decompression.
|
||||
* @param pktlen: length of packet buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_ipseckey_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len, uint8_t* pkt, size_t pktlen);
|
||||
|
||||
/**
|
||||
* Scan wireformat HIP (algo, HIT, pubkey) field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_hip_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat int16_data field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_int16_data_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat nsec3_next_owner field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_nsec3_next_owner_scan(uint8_t** data, size_t* data_len,
|
||||
char** str, size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat ILNP64 field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_ilnp64_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat EUI48 field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_eui48_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat EUI64 field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_eui64_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat TAG field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_tag_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat long_str field to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
* Can return -1 on failure.
|
||||
*/
|
||||
int gldns_wire2str_long_str_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len);
|
||||
|
||||
/**
|
||||
* Print EDNS LLQ option data to string. User buffers, moves string pointers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param option_data: buffer with EDNS option code data.
|
||||
* @param option_len: length of the data for this option.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_edns_llq_print(char** str, size_t* str_len,
|
||||
uint8_t* option_data, size_t option_len);
|
||||
|
||||
/**
|
||||
* Print EDNS UL option data to string. User buffers, moves string pointers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param option_data: buffer with EDNS option code data.
|
||||
* @param option_len: length of the data for this option.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_edns_ul_print(char** str, size_t* str_len,
|
||||
uint8_t* option_data, size_t option_len);
|
||||
|
||||
/**
|
||||
* Print EDNS NSID option data to string. User buffers, moves string pointers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param option_data: buffer with EDNS option code data.
|
||||
* @param option_len: length of the data for this option.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_edns_nsid_print(char** str, size_t* str_len,
|
||||
uint8_t* option_data, size_t option_len);
|
||||
|
||||
/**
|
||||
* Print EDNS DAU option data to string. User buffers, moves string pointers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param option_data: buffer with EDNS option code data.
|
||||
* @param option_len: length of the data for this option.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_edns_dau_print(char** str, size_t* str_len,
|
||||
uint8_t* option_data, size_t option_len);
|
||||
|
||||
/**
|
||||
* Print EDNS DHU option data to string. User buffers, moves string pointers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param option_data: buffer with EDNS option code data.
|
||||
* @param option_len: length of the data for this option.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_edns_dhu_print(char** str, size_t* str_len,
|
||||
uint8_t* option_data, size_t option_len);
|
||||
|
||||
/**
|
||||
* Print EDNS N3U option data to string. User buffers, moves string pointers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param option_data: buffer with EDNS option code data.
|
||||
* @param option_len: length of the data for this option.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_edns_n3u_print(char** str, size_t* str_len,
|
||||
uint8_t* option_data, size_t option_len);
|
||||
|
||||
/**
|
||||
* Print EDNS SUBNET option data to string. User buffers, moves string pointers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param option_data: buffer with EDNS option code data.
|
||||
* @param option_len: length of the data for this option.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_edns_subnet_print(char** str, size_t* str_len,
|
||||
uint8_t* option_data, size_t option_len);
|
||||
|
||||
/**
|
||||
* Print an EDNS option as OPT: VALUE. User buffers, moves string pointers.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param option_code: host format EDNS option code.
|
||||
* @param option_data: buffer with EDNS option code data.
|
||||
* @param option_len: length of the data for this option.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_edns_option_print(char** str, size_t* str_len,
|
||||
uint16_t option_code, uint8_t* option_data, size_t option_len);
|
||||
|
||||
/**
|
||||
* Scan wireformat EDNS OPT to string, with user buffers.
|
||||
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
|
||||
* @param data: wireformat data.
|
||||
* @param data_len: length of data buffer.
|
||||
* @param str: string buffer.
|
||||
* @param str_len: length of string buffer.
|
||||
* @param pkt: packet with header and other info (may be NULL)
|
||||
* @param pktlen: length of packet buffer.
|
||||
* @return number of characters (except null) needed to print.
|
||||
*/
|
||||
int gldns_wire2str_edns_scan(uint8_t** data, size_t* data_len, char** str,
|
||||
size_t* str_len, uint8_t* pkt, size_t pktlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GLDNS_WIRE2STR_H */
|
Loading…
Reference in New Issue