Przeglądaj źródła

started work on query response pretty printer

master
boB Rudis 1 rok temu
rodzic
commit
d3eadcdc78
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: 1D7529BE14E2BBA9
5 zmienionych plików z 72 dodań i 6 usunięć
  1. +1
    -0
      NAMESPACE
  2. +5
    -1
      R/aaa.R
  3. +39
    -1
      R/resolver.R
  4. +17
    -0
      man/print.gdns_response.Rd
  5. +10
    -4
      src/resolver.cpp

+ 1
- 0
NAMESPACE Wyświetl plik

@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(print,gctx)
S3method(print,gdns_response)
export("%>%")
export(gdns_get_address)
export(gdns_lib_version)


+ 5
- 1
R/aaa.R Wyświetl plik

@@ -1,3 +1,5 @@
set_names <- function (object = nm, nm) { names(object) <- nm ; object }

rr_types <- c(
a = 1,
ns = 2,
@@ -85,4 +87,6 @@ avc = 258,
doa = 259,
ta = 32768,
dlv = 32769
)
)

rr_types_rev <- set_names(names(rr_types), as.character(rr_types))

+ 39
- 1
R/resolver.R Wyświetl plik

@@ -123,9 +123,47 @@ gdns_query <- function(gctx, name, rr_type = "txt") {
res <- int_gdns_query(gctx, name, unname(as.integer(rr_types[rr_type])))
if (length(res)) {
out <- jsonlite::fromJSON(res)
class(out) <- c("gdns_response", "list")
out
} else {
NULL
}

}
}

list(`1` = "ipv4_address", `2` = "nsdname", `6` = c("expire",
"minimum", "mname", "refresh", "retry", "rname", "serial"), `16` = "txt_strings",
`28` = "ipv6_address", `43` = c("algorithm", "digest", "digest_type",
"key_tag"), `46` = c("algorithm", "key_tag", "labels", "original_ttl",
"signature", "signature_expiration", "signature_inception",
"signers_name", "type_covered"), `47` = c("next_domain_name",
"type_bit_maps"), `48` = c("algorithm", "flags", "protocol",
"public_key")) -> rr_fields

#' Printer for gdns_response objects
#'
#' @param x a `gdns_response` object
#' @param ... ignored
#' @keywords internal
#' @export
print.gdns_response <- function(x, ...) {

cat(
"Query: ",
x$replies_tree$question$qname[1], " ",
toupper(rr_types_rev[x$replies_tree$question$qtype[1]]),
"\n", sep=""
)

print(str(
x$replies_tree$answer[[1]]$rdata[
rr_fields[[as.character(unique(x$replies_tree$answer[[1]]$type))]]
], 1
))

}






+ 17
- 0
man/print.gdns_response.Rd Wyświetl plik

@@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/resolver.R
\name{print.gdns_response}
\alias{print.gdns_response}
\title{Printer for gdns_response objects}
\usage{
\method{print}{gdns_response}(x, ...)
}
\arguments{
\item{x}{a \code{gdns_response} object}

\item{...}{ignored}
}
\description{
Printer for gdns_response objects
}
\keyword{internal}

+ 10
- 4
src/resolver.cpp Wyświetl plik

@@ -22,7 +22,8 @@ void check_is_xptr(SEXP s) {
// [[Rcpp::export]]
SEXP is_null_xptr_(SEXP s) {
check_is_xptr(s);
return Rf_ScalarLogical(R_ExternalPtrAddr(s) == NULL);
void *r = (void *)R_ExternalPtrAddr(s);
return wrap(r == NULL);
}

static void gctx_finalizer(SEXP ptr) {
@@ -92,6 +93,8 @@ CharacterVector gdns_get_address(SEXP gctx, std::string host) {
std::vector< std::string > out;
bool ok = false;

check_is_xptr(gctx);

getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);

if (gctx == NULL) return(CharacterVector());
@@ -145,6 +148,8 @@ CharacterVector int_get_resolvers(SEXP gctx) {
getdns_list *addrs;
std::vector< std::string > out;

check_is_xptr(gctx);

getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
if (gctx == NULL) return(CharacterVector());

@@ -193,15 +198,16 @@ CharacterVector int_get_resolvers(SEXP gctx) {
CharacterVector int_gdns_query(SEXP gctx, std::string name, uint16_t rr) {

uint32_t err;
size_t sz;
// size_t sz;
getdns_return_t r;
getdns_dict *resp = NULL;
getdns_list *results;
// getdns_list *results;
std::string out;
bool ok = false;

getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
check_is_xptr(gctx);

getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
if (gctx == NULL) return(CharacterVector());

if ((r = getdns_general_sync(ctxt, name.c_str(), rr, NULL, &resp))) {


Ładowanie…
Anuluj
Zapisz