Browse Source

more rrs hnadled in printing; query context can be null

boB Rudis 9 months ago
parent
commit
cd8519507d
No known key found for this signature in database
8 changed files with 60 additions and 22 deletions
  1. 2
    1
      DESCRIPTION
  2. 2
    0
      NAMESPACE
  3. 1
    1
      R/aaa.R
  4. 1
    0
      R/clandnstine-package.R
  5. 7
    0
      R/is.R
  6. 29
    18
      R/resolver.R
  7. 4
    2
      man/gdns_query.Rd
  8. 14
    0
      man/is_gctx.Rd

+ 2
- 1
DESCRIPTION View File

@@ -23,7 +23,8 @@ Depends:
23 23
 Imports:
24 24
     jsonlite,
25 25
     Rcpp,
26
-    magrittr
26
+    magrittr,
27
+    glue
27 28
 Roxygen: list(markdown = TRUE)
28 29
 RoxygenNote: 6.1.1
29 30
 LinkingTo: 

+ 2
- 0
NAMESPACE View File

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

+ 1
- 1
R/aaa.R View File

@@ -89,4 +89,4 @@ ta = 32768,
89 89
 dlv = 32769
90 90
 )
91 91
 
92
-rr_types_rev <- set_names(names(rr_types), as.character(rr_types))
92
+rr_types_rev <- set_names(names(rr_types), as.character(rr_types))

+ 1
- 0
R/clandnstine-package.R View File

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

+ 7
- 0
R/is.R View File

@@ -0,0 +1,7 @@
1
+#' Test whether an object is a `gctx` context
2
+#'
3
+#' @param x object
4
+#' @export
5
+is_gctx <- function(x) {
6
+   inherits(x, "gctx")
7
+}

+ 29
- 18
R/resolver.R View File

@@ -45,7 +45,6 @@ gdns_set_hosts<- function(gctx, hosts_file) {
45 45
   int_gdns_set_hosts(gctx, hosts_file)
46 46
 }
47 47
 
48
-
49 48
 #' Retrieve the list of addresses in use for looking up top-level domains in use by the context.
50 49
 #'
51 50
 #' @param gctx gdns resolver context created with [gdns_resolver()]
@@ -157,7 +156,9 @@ gdns_get_root_servers <- function(gctx) {
157 156
 #' - `zonemd`
158 157
 #'
159 158
 #' @note Local hosts files are ignored when using this `getdns` API endpoint
160
-#' @param gctx gdns resolver context created with [gdns_resolver()]
159
+#' @param gctx gdns resolver context created with [gdns_resolver()]. If `NULL` a
160
+#'        temporary context will be created but is not ideal since there is overhead
161
+#'        associated with context creation and garbage collection.
161 162
 #' @param name an entity to query for
162 163
 #' @param rr_type what resource record type do you want to queyr for? See `Details`.
163 164
 #' @param include_reporting if `TRUE` include debugging information for queries
@@ -168,9 +169,13 @@ gdns_get_root_servers <- function(gctx) {
168 169
 #' @examples
169 170
 #' x <- gdns_resolver()
170 171
 #' gdns_query(x, "example.com")
171
-gdns_query <- function(gctx, name, rr_type = "txt", rr_class = 1L,
172
+gdns_query <- function(gctx = NULL, name, rr_type = "txt", rr_class = 1L,
172 173
                        include_reporting = FALSE) {
173 174
 
175
+  if (is.null(gctx)) gctx <- gdns_context()
176
+
177
+  stopifnot(is_gctx(gctx))
178
+
174 179
   rr_class <- rr_class[1]
175 180
   if (!rr_class %in% c(1, 3, 4, 254, 255)) rr_class <- 1
176 181
 
@@ -187,21 +192,6 @@ gdns_query <- function(gctx, name, rr_type = "txt", rr_class = 1L,
187 192
 
188 193
 }
189 194
 
190
-list(
191
-  `1` = "ipv4_address",
192
-  `2` = "nsdname",
193
-  `6` = c("expire", "minimum", "mname", "refresh", "retry", "rname", "serial"),
194
-  `16` = "txt_strings",
195
-  `28` = "ipv6_address",
196
-  `43` = c("algorithm", "digest", "digest_type", "key_tag"),
197
-  `46` = c(
198
-    "algorithm", "key_tag", "labels", "original_ttl", "signature",
199
-    "signature_expiration", "signature_inception", "signers_name", "type_covered"
200
-  ),
201
-  `47` = c("next_domain_name", "type_bit_maps"),
202
-  `48` = c("algorithm", "flags", "protocol", "public_key")
203
-) -> rr_fields
204
-
205 195
 #' Printer for gdns_response objects
206 196
 #'
207 197
 #' @param x a `gdns_response` object
@@ -230,6 +220,20 @@ print.gdns_response <- function(x, ...) {
230 220
         "\n", sep=""
231 221
       )
232 222
     },
223
+    "2" ={
224
+      cat(
225
+        "Answer: ",
226
+        paste0(ans$rdata$nsdname, collapse=", "),
227
+        "\n", sep=""
228
+      )
229
+    },
230
+    "15" = {
231
+      cat(
232
+        "Answer: \n",
233
+        paste0(glue::glue_data(ans$rdata, "{preference} {exchange}"), collapse="\n"),
234
+        "\n", sep=""
235
+      )
236
+    },
233 237
     "16" = {
234 238
       rd <- ans$rdata
235 239
       typs <- ans$type
@@ -249,6 +253,13 @@ print.gdns_response <- function(x, ...) {
249 253
         "\n", sep=""
250 254
       )
251 255
     },
256
+    "257" = {
257
+      cat(
258
+        "Answer: \n",
259
+        paste0(glue::glue_data(ans$rdata, "{flags} {tag} {value}"), collapse="\n"),
260
+        "\n", sep=""
261
+      )
262
+    },
252 263
     {
253 264
       print(str(ans$rdata, give.attr = FALSE))
254 265
     }

+ 4
- 2
man/gdns_query.Rd View File

@@ -4,11 +4,13 @@
4 4
 \alias{gdns_query}
5 5
 \title{Arbitrary DNS queries}
6 6
 \usage{
7
-gdns_query(gctx, name, rr_type = "txt", rr_class = 1L,
7
+gdns_query(gctx = NULL, name, rr_type = "txt", rr_class = 1L,
8 8
   include_reporting = FALSE)
9 9
 }
10 10
 \arguments{
11
-\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}. If \code{NULL} a
12
+temporary context will be created but is not ideal since there is overhead
13
+associated with context creation and garbage collection.}
12 14
 
13 15
 \item{name}{an entity to query for}
14 16
 

+ 14
- 0
man/is_gctx.Rd View File

@@ -0,0 +1,14 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/is.R
3
+\name{is_gctx}
4
+\alias{is_gctx}
5
+\title{Test whether an object is a \code{gctx} context}
6
+\usage{
7
+is_gctx(x)
8
+}
9
+\arguments{
10
+\item{x}{object}
11
+}
12
+\description{
13
+Test whether an object is a \code{gctx} context
14
+}

Loading…
Cancel
Save