From cd8519507da250650f4783e5e69f3ba4a7e04153 Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Thu, 14 Feb 2019 23:11:02 -0500 Subject: [PATCH] more rrs hnadled in printing; query context can be null --- DESCRIPTION | 3 ++- NAMESPACE | 2 ++ R/aaa.R | 2 +- R/clandnstine-package.R | 1 + R/is.R | 7 +++++++ R/resolver.R | 47 +++++++++++++++++++++++++++++------------------ man/gdns_query.Rd | 6 ++++-- man/is_gctx.Rd | 14 ++++++++++++++ 8 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 R/is.R create mode 100644 man/is_gctx.Rd diff --git a/DESCRIPTION b/DESCRIPTION index eb8b605..aa03742 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,7 +23,8 @@ Depends: Imports: jsonlite, Rcpp, - magrittr + magrittr, + glue Roxygen: list(markdown = TRUE) RoxygenNote: 6.1.1 LinkingTo: diff --git a/NAMESPACE b/NAMESPACE index 7e501e6..a3663c5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,7 +23,9 @@ export(gdns_set_tls_ca_file) export(gdns_set_tls_ca_path) export(gdns_set_transports) export(gdns_update_resolvers) +export(is_gctx) importFrom(Rcpp,sourceCpp) +importFrom(glue,glue_data) importFrom(jsonlite,fromJSON) importFrom(magrittr,"%>%") useDynLib(clandnstine, .registration = TRUE) diff --git a/R/aaa.R b/R/aaa.R index bb2a6c8..cb25a4b 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -89,4 +89,4 @@ ta = 32768, dlv = 32769 ) -rr_types_rev <- set_names(names(rr_types), as.character(rr_types)) \ No newline at end of file +rr_types_rev <- set_names(names(rr_types), as.character(rr_types)) diff --git a/R/clandnstine-package.R b/R/clandnstine-package.R index 7c102ad..5a19be4 100644 --- a/R/clandnstine-package.R +++ b/R/clandnstine-package.R @@ -11,6 +11,7 @@ #' @docType package #' @author Bob Rudis (bob@@rud.is) #' @keywords internal +#' @importFrom glue glue_data #' @importFrom jsonlite fromJSON #' @useDynLib clandnstine, .registration = TRUE #' @importFrom Rcpp sourceCpp diff --git a/R/is.R b/R/is.R new file mode 100644 index 0000000..22a24b1 --- /dev/null +++ b/R/is.R @@ -0,0 +1,7 @@ +#' Test whether an object is a `gctx` context +#' +#' @param x object +#' @export +is_gctx <- function(x) { + inherits(x, "gctx") +} diff --git a/R/resolver.R b/R/resolver.R index ed815b2..273edcc 100644 --- a/R/resolver.R +++ b/R/resolver.R @@ -45,7 +45,6 @@ gdns_set_hosts<- function(gctx, hosts_file) { int_gdns_set_hosts(gctx, hosts_file) } - #' Retrieve the list of addresses in use for looking up top-level domains in use by the context. #' #' @param gctx gdns resolver context created with [gdns_resolver()] @@ -157,7 +156,9 @@ gdns_get_root_servers <- function(gctx) { #' - `zonemd` #' #' @note Local hosts files are ignored when using this `getdns` API endpoint -#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @param gctx gdns resolver context created with [gdns_resolver()]. If `NULL` a +#' temporary context will be created but is not ideal since there is overhead +#' associated with context creation and garbage collection. #' @param name an entity to query for #' @param rr_type what resource record type do you want to queyr for? See `Details`. #' @param include_reporting if `TRUE` include debugging information for queries @@ -168,9 +169,13 @@ gdns_get_root_servers <- function(gctx) { #' @examples #' x <- gdns_resolver() #' gdns_query(x, "example.com") -gdns_query <- function(gctx, name, rr_type = "txt", rr_class = 1L, +gdns_query <- function(gctx = NULL, name, rr_type = "txt", rr_class = 1L, include_reporting = FALSE) { + if (is.null(gctx)) gctx <- gdns_context() + + stopifnot(is_gctx(gctx)) + rr_class <- rr_class[1] if (!rr_class %in% c(1, 3, 4, 254, 255)) rr_class <- 1 @@ -187,21 +192,6 @@ gdns_query <- function(gctx, name, rr_type = "txt", rr_class = 1L, } -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 @@ -230,6 +220,20 @@ print.gdns_response <- function(x, ...) { "\n", sep="" ) }, + "2" ={ + cat( + "Answer: ", + paste0(ans$rdata$nsdname, collapse=", "), + "\n", sep="" + ) + }, + "15" = { + cat( + "Answer: \n", + paste0(glue::glue_data(ans$rdata, "{preference} {exchange}"), collapse="\n"), + "\n", sep="" + ) + }, "16" = { rd <- ans$rdata typs <- ans$type @@ -249,6 +253,13 @@ print.gdns_response <- function(x, ...) { "\n", sep="" ) }, + "257" = { + cat( + "Answer: \n", + paste0(glue::glue_data(ans$rdata, "{flags} {tag} {value}"), collapse="\n"), + "\n", sep="" + ) + }, { print(str(ans$rdata, give.attr = FALSE)) } diff --git a/man/gdns_query.Rd b/man/gdns_query.Rd index 9deac59..96a9dea 100644 --- a/man/gdns_query.Rd +++ b/man/gdns_query.Rd @@ -4,11 +4,13 @@ \alias{gdns_query} \title{Arbitrary DNS queries} \usage{ -gdns_query(gctx, name, rr_type = "txt", rr_class = 1L, +gdns_query(gctx = NULL, name, rr_type = "txt", rr_class = 1L, include_reporting = FALSE) } \arguments{ -\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}. If \code{NULL} a +temporary context will be created but is not ideal since there is overhead +associated with context creation and garbage collection.} \item{name}{an entity to query for} diff --git a/man/is_gctx.Rd b/man/is_gctx.Rd new file mode 100644 index 0000000..3620a2e --- /dev/null +++ b/man/is_gctx.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/is.R +\name{is_gctx} +\alias{is_gctx} +\title{Test whether an object is a \code{gctx} context} +\usage{ +is_gctx(x) +} +\arguments{ +\item{x}{object} +} +\description{ +Test whether an object is a \code{gctx} context +}