mirror of https://github.com/getdnsapi/getdns.git
Print rr type ints as type and dnames as dname
This commit is contained in:
parent
692f458690
commit
650b6dbda4
40
src/dict.c
40
src/dict.c
|
@ -40,6 +40,7 @@
|
||||||
#include "types-internal.h"
|
#include "types-internal.h"
|
||||||
#include "util-internal.h"
|
#include "util-internal.h"
|
||||||
#include "dict.h"
|
#include "dict.h"
|
||||||
|
#include "rr-dict.h"
|
||||||
|
|
||||||
/*---------------------------------------- getdns_dict_find */
|
/*---------------------------------------- getdns_dict_find */
|
||||||
/**
|
/**
|
||||||
|
@ -491,6 +492,18 @@ getdns_indent(size_t indent)
|
||||||
return spaces + 80 - (indent < 80 ? indent : 0);
|
return spaces + 80 - (indent < 80 ? indent : 0);
|
||||||
} /* getdns_indent */
|
} /* getdns_indent */
|
||||||
|
|
||||||
|
static int
|
||||||
|
priv_getdns_bindata_is_dname(struct getdns_bindata *bindata)
|
||||||
|
{
|
||||||
|
size_t i = 0, n_labels = 0;
|
||||||
|
while (i < bindata->size) {
|
||||||
|
i += bindata->data[i] + 1;
|
||||||
|
n_labels++;
|
||||||
|
}
|
||||||
|
return i == bindata->size && n_labels > 1 &&
|
||||||
|
bindata->data[bindata->size - 1] == 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*---------------------------------------- getdns_pp_bindata */
|
/*---------------------------------------- getdns_pp_bindata */
|
||||||
/**
|
/**
|
||||||
* private function to pretty print bindata to a ldns_buffer
|
* private function to pretty print bindata to a ldns_buffer
|
||||||
|
@ -506,6 +519,7 @@ getdns_pp_bindata(ldns_buffer * buf, size_t indent,
|
||||||
{
|
{
|
||||||
size_t i, p = ldns_buffer_position(buf);
|
size_t i, p = ldns_buffer_position(buf);
|
||||||
uint8_t *dptr;
|
uint8_t *dptr;
|
||||||
|
char *dname;
|
||||||
|
|
||||||
if (ldns_buffer_printf(buf, " <bindata ") < 0)
|
if (ldns_buffer_printf(buf, " <bindata ") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -516,9 +530,22 @@ getdns_pp_bindata(ldns_buffer * buf, size_t indent,
|
||||||
while (i < bindata->size - 1 && isprint(bindata->data[i]))
|
while (i < bindata->size - 1 && isprint(bindata->data[i]))
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
if (i >= bindata->size - 1) { /* all chars were printable */
|
if (bindata->size > 1 && i >= bindata->size - 1) { /* all printable? */
|
||||||
if (ldns_buffer_printf(buf, "for \"%s\">", bindata->data) < 0)
|
if (ldns_buffer_printf(buf, "of \"%s\">", bindata->data) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
} else if (bindata->size == 1 && *bindata->data == 0) {
|
||||||
|
if (ldns_buffer_printf(buf, "for .>") < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
} else if (priv_getdns_bindata_is_dname(bindata)) {
|
||||||
|
dname = getdns_convert_dns_name_to_fqdn((char *)bindata->data);
|
||||||
|
if (ldns_buffer_printf(buf, "for %s>", dname) < 0) {
|
||||||
|
free(dname);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
free(dname);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (ldns_buffer_printf(buf, "of 0x") < 0)
|
if (ldns_buffer_printf(buf, "of 0x") < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -641,6 +668,7 @@ getdns_pp_dict(ldns_buffer * buf, size_t indent,
|
||||||
{
|
{
|
||||||
size_t i, length, p = ldns_buffer_position(buf);
|
size_t i, length, p = ldns_buffer_position(buf);
|
||||||
struct getdns_dict_item *item;
|
struct getdns_dict_item *item;
|
||||||
|
const char *strval;
|
||||||
|
|
||||||
if (dict == NULL)
|
if (dict == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -659,6 +687,14 @@ getdns_pp_dict(ldns_buffer * buf, size_t indent,
|
||||||
|
|
||||||
switch (item->dtype) {
|
switch (item->dtype) {
|
||||||
case t_int:
|
case t_int:
|
||||||
|
if ((strcmp(item->node.key, "type") == 0 ||
|
||||||
|
strcmp(item->node.key, "type_covered") == 0) &&
|
||||||
|
(strval = priv_getdns_rr_type_name(item->data.n))) {
|
||||||
|
if (ldns_buffer_printf(
|
||||||
|
buf, " GETDNS_RRTYPE_%s", strval) < 0)
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (ldns_buffer_printf(buf, " %d", item->data.n) < 0)
|
if (ldns_buffer_printf(buf, " %d", item->data.n) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -563,6 +563,12 @@ rr_def_lookup(uint16_t rr_type)
|
||||||
return rr_defs;
|
return rr_defs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
priv_getdns_rr_type_name(int rr_type)
|
||||||
|
{
|
||||||
|
return rr_def_lookup(rr_type)->name;
|
||||||
|
}
|
||||||
|
|
||||||
static getdns_return_t
|
static getdns_return_t
|
||||||
priv_getdns_equip_dict_with_rdfs(struct getdns_dict *rdata, ldns_rr *rr)
|
priv_getdns_equip_dict_with_rdfs(struct getdns_dict *rdata, ldns_rr *rr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
getdns_return_t priv_getdns_create_dict_from_rr(
|
getdns_return_t priv_getdns_create_dict_from_rr(
|
||||||
struct getdns_context *context, ldns_rr *rr, struct getdns_dict** rr_dict);
|
struct getdns_context *context, ldns_rr *rr, struct getdns_dict** rr_dict);
|
||||||
|
|
||||||
|
const char *priv_getdns_rr_type_name(int rr_type);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* rrs.h */
|
/* rrs.h */
|
||||||
|
|
Loading…
Reference in New Issue