Browse Source

more rrs hnadled in printing; query context can be null

master
boB Rudis 5 years ago
parent
commit
cd8519507d
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 3
      DESCRIPTION
  2. 2
      NAMESPACE
  3. 1
      R/clandnstine-package.R
  4. 7
      R/is.R
  5. 47
      R/resolver.R
  6. 6
      man/gdns_query.Rd
  7. 14
      man/is_gctx.Rd

3
DESCRIPTION

@ -23,7 +23,8 @@ Depends:
Imports: Imports:
jsonlite, jsonlite,
Rcpp, Rcpp,
magrittr magrittr,
glue
Roxygen: list(markdown = TRUE) Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1 RoxygenNote: 6.1.1
LinkingTo: LinkingTo:

2
NAMESPACE

@ -23,7 +23,9 @@ export(gdns_set_tls_ca_file)
export(gdns_set_tls_ca_path) export(gdns_set_tls_ca_path)
export(gdns_set_transports) export(gdns_set_transports)
export(gdns_update_resolvers) export(gdns_update_resolvers)
export(is_gctx)
importFrom(Rcpp,sourceCpp) importFrom(Rcpp,sourceCpp)
importFrom(glue,glue_data)
importFrom(jsonlite,fromJSON) importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%") importFrom(magrittr,"%>%")
useDynLib(clandnstine, .registration = TRUE) useDynLib(clandnstine, .registration = TRUE)

1
R/clandnstine-package.R

@ -11,6 +11,7 @@
#' @docType package #' @docType package
#' @author Bob Rudis (bob@@rud.is) #' @author Bob Rudis (bob@@rud.is)
#' @keywords internal #' @keywords internal
#' @importFrom glue glue_data
#' @importFrom jsonlite fromJSON #' @importFrom jsonlite fromJSON
#' @useDynLib clandnstine, .registration = TRUE #' @useDynLib clandnstine, .registration = TRUE
#' @importFrom Rcpp sourceCpp #' @importFrom Rcpp sourceCpp

7
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")
}

47
R/resolver.R

@ -45,7 +45,6 @@ gdns_set_hosts<- function(gctx, hosts_file) {
int_gdns_set_hosts(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. #' 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()] #' @param gctx gdns resolver context created with [gdns_resolver()]
@ -157,7 +156,9 @@ gdns_get_root_servers <- function(gctx) {
#' - `zonemd` #' - `zonemd`
#' #'
#' @note Local hosts files are ignored when using this `getdns` API endpoint #' @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 name an entity to query for
#' @param rr_type what resource record type do you want to queyr for? See `Details`. #' @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 #' @param include_reporting if `TRUE` include debugging information for queries
@ -168,9 +169,13 @@ gdns_get_root_servers <- function(gctx) {
#' @examples #' @examples
#' x <- gdns_resolver() #' x <- gdns_resolver()
#' gdns_query(x, "example.com") #' 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) { include_reporting = FALSE) {
if (is.null(gctx)) gctx <- gdns_context()
stopifnot(is_gctx(gctx))
rr_class <- rr_class[1] rr_class <- rr_class[1]
if (!rr_class %in% c(1, 3, 4, 254, 255)) 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 #' Printer for gdns_response objects
#' #'
#' @param x a `gdns_response` object #' @param x a `gdns_response` object
@ -230,6 +220,20 @@ print.gdns_response <- function(x, ...) {
"\n", sep="" "\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" = { "16" = {
rd <- ans$rdata rd <- ans$rdata
typs <- ans$type typs <- ans$type
@ -249,6 +253,13 @@ print.gdns_response <- function(x, ...) {
"\n", sep="" "\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)) print(str(ans$rdata, give.attr = FALSE))
} }

6
man/gdns_query.Rd

@ -4,11 +4,13 @@
\alias{gdns_query} \alias{gdns_query}
\title{Arbitrary DNS queries} \title{Arbitrary DNS queries}
\usage{ \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) include_reporting = FALSE)
} }
\arguments{ \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} \item{name}{an entity to query for}

14
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
}
Loading…
Cancel
Save