Browse Source

custom print for replies needs work

boB Rudis 10 months ago
parent
commit
df515e3250
No known key found for this signature in database
1 changed files with 50 additions and 9 deletions
  1. 50
    9
      R/resolver.R

+ 50
- 9
R/resolver.R View File

@@ -131,14 +131,20 @@ gdns_query <- function(gctx, name, rr_type = "txt") {
131 131
 
132 132
 }
133 133
 
134
-list(`1` = "ipv4_address", `2` = "nsdname", `6` = c("expire",
135
-"minimum", "mname", "refresh", "retry", "rname", "serial"), `16` = "txt_strings",
136
-    `28` = "ipv6_address", `43` = c("algorithm", "digest", "digest_type",
137
-    "key_tag"), `46` = c("algorithm", "key_tag", "labels", "original_ttl",
138
-    "signature", "signature_expiration", "signature_inception",
139
-    "signers_name", "type_covered"), `47` = c("next_domain_name",
140
-    "type_bit_maps"), `48` = c("algorithm", "flags", "protocol",
141
-    "public_key")) -> rr_fields
134
+list(
135
+  `1` = "ipv4_address",
136
+  `2` = "nsdname",
137
+  `6` = c("expire", "minimum", "mname", "refresh", "retry", "rname", "serial"),
138
+  `16` = "txt_strings",
139
+  `28` = "ipv6_address",
140
+  `43` = c("algorithm", "digest", "digest_type", "key_tag"),
141
+  `46` = c(
142
+    "algorithm", "key_tag", "labels", "original_ttl", "signature",
143
+    "signature_expiration", "signature_inception", "signers_name", "type_covered"
144
+  ),
145
+  `47` = c("next_domain_name", "type_bit_maps"),
146
+  `48` = c("algorithm", "flags", "protocol", "public_key")
147
+) -> rr_fields
142 148
 
143 149
 #' Printer for gdns_response objects
144 150
 #'
@@ -155,7 +161,42 @@ print.gdns_response <- function(x, ...) {
155 161
     "\n", sep=""
156 162
   )
157 163
 
158
-  print(str(x$replies_tree$answer[[1]]))
164
+  qtype <- as.character(x$replies_tree$question$qtype[[1]])
165
+  ans <- x$replies_tree$answer[[1]]
166
+  ans$rdata$rdata_raw <- NULL
167
+
168
+  switch(
169
+    qtype,
170
+    "1" = {
171
+      cat(
172
+        "Answer: ",
173
+        paste0(unlist(x$just_address_answers$address_data), collapse="\n"),
174
+        "\n", sep=""
175
+      )
176
+    },
177
+    "16" = {
178
+      rd <- ans$rdata
179
+      typs <- ans$type
180
+      typs <- which(typs == 16)
181
+      if (length(typs)) {
182
+        cat(
183
+          "Answer: ",
184
+          paste0(unlist(rd$txt_strings[typs]), collapse="\n"),
185
+          "\n", sep=""
186
+        )
187
+      }
188
+    },
189
+    "28" = {
190
+      cat(
191
+        "Answer: ",
192
+        paste0(unlist(x$just_address_answers$address_data), collapse="\n"),
193
+        "\n", sep=""
194
+      )
195
+    },
196
+    {
197
+      print(str(ans$rdata, give.attr = FALSE))
198
+    }
199
+  )
159 200
 
160 201
 }
161 202
 

Loading…
Cancel
Save