Browse Source

more getters/setters

boB Rudis 9 months ago
parent
commit
81d09a3714
No known key found for this signature in database

+ 1
- 1
DESCRIPTION View File

@@ -1,6 +1,6 @@
1 1
 Package: clandnstine
2 2
 Type: Package
3
-Title: Perform 'DNS' over 'TLS' Queries
3
+Title: Perform Secure-by-default 'DNS' Queries
4 4
 Version: 0.1.0
5 5
 Date: 2019-01-18
6 6
 Authors@R: c(

+ 10
- 0
NAMESPACE View File

@@ -5,12 +5,22 @@ S3method(print,gdns_response)
5 5
 export("%>%")
6 6
 export(gdns_context)
7 7
 export(gdns_get_address)
8
+export(gdns_get_hosts)
9
+export(gdns_get_resolution_type)
10
+export(gdns_get_resolvconf)
8 11
 export(gdns_get_timeout)
12
+export(gdns_get_tls_ca_file)
13
+export(gdns_get_tls_ca_path)
14
+export(gdns_get_transports)
9 15
 export(gdns_lib_version)
10 16
 export(gdns_query)
11 17
 export(gdns_set_hosts)
18
+export(gdns_set_resolution_type)
12 19
 export(gdns_set_round_robin_upstreams)
13 20
 export(gdns_set_timeout)
21
+export(gdns_set_tls_ca_file)
22
+export(gdns_set_tls_ca_path)
23
+export(gdns_set_transports)
14 24
 export(gdns_update_resolvers)
15 25
 importFrom(Rcpp,sourceCpp)
16 26
 importFrom(jsonlite,fromJSON)

+ 84
- 3
R/RcppExports.R View File

@@ -48,6 +48,76 @@ int_gdns_set_hosts <- function(gctx, hosts) {
48 48
     .Call(`_clandnstine_int_gdns_set_hosts`, gctx, hosts)
49 49
 }
50 50
 
51
+#' Internal version of set_transports()
52
+#' @keywords internal
53
+int_gdns_set_transports <- function(gctx, trans) {
54
+    .Call(`_clandnstine_int_gdns_set_transports`, gctx, trans)
55
+}
56
+
57
+#' Internal version of gdns_set_resolution_type()
58
+#' @keywords internal
59
+int_gdns_set_resolution_type <- function(gctx, res_type) {
60
+    .Call(`_clandnstine_int_gdns_set_resolution_type`, gctx, res_type)
61
+}
62
+
63
+#' Retreive what transports are used for DNS lookups.
64
+#'
65
+#' @param gctx gdns resolver context created with [gdns_resolver()]
66
+#' @export
67
+gdns_get_transports <- function(gctx) {
68
+    .Call(`_clandnstine_gdns_get_transports`, gctx)
69
+}
70
+
71
+#' Retreive the value of the localnames namespace
72
+#'
73
+#' @param gctx gdns resolver context created with [gdns_resolver()]
74
+#' @export
75
+gdns_get_hosts <- function(gctx) {
76
+    .Call(`_clandnstine_gdns_get_hosts`, gctx)
77
+}
78
+
79
+#' Retreive the value with which the context's upstream recursive servers and suffixes were initialized
80
+#'
81
+#' @param gctx gdns resolver context created with [gdns_resolver()]
82
+#' @export
83
+gdns_get_resolvconf <- function(gctx) {
84
+    .Call(`_clandnstine_gdns_get_resolvconf`, gctx)
85
+}
86
+
87
+#' Retreive the value with which the context's upstream recursive servers and suffixes were initialized
88
+#'
89
+#' @param gctx gdns resolver context created with [gdns_resolver()]
90
+#' @export
91
+gdns_get_tls_ca_path <- function(gctx) {
92
+    .Call(`_clandnstine_gdns_get_tls_ca_path`, gctx)
93
+}
94
+
95
+#' Retreive the file location with CA certificates for verification purposes
96
+#'
97
+#' @param gctx gdns resolver context created with [gdns_resolver()]
98
+#' @export
99
+gdns_get_tls_ca_file <- function(gctx) {
100
+    .Call(`_clandnstine_gdns_get_tls_ca_file`, gctx)
101
+}
102
+
103
+#' Specify where the location for CA certificates for verification purposes are located
104
+#'
105
+#' @param gctx gdns resolver context created with [gdns_resolver()]
106
+#' @param ca_path directory with Certificate Authority certificates
107
+#' @export
108
+gdns_set_tls_ca_path <- function(gctx, ca_path) {
109
+    .Call(`_clandnstine_gdns_set_tls_ca_path`, gctx, ca_path)
110
+}
111
+
112
+#' Specify the file with CA certificates for verification purposes
113
+#'
114
+#' @param gctx gdns resolver context created with [gdns_resolver()]
115
+#' @param ca_file file with Certificate Authority certificates
116
+#' @export
117
+gdns_set_tls_ca_file <- function(gctx, ca_file) {
118
+    .Call(`_clandnstine_gdns_set_tls_ca_file`, gctx, ca_file)
119
+}
120
+
51 121
 #' Test whether an object is an external pointer
52 122
 #'
53 123
 #' @param x object to test
@@ -64,10 +134,10 @@ is_null_xptr_ <- function(s) {
64 134
     .Call(`_clandnstine_is_null_xptr_`, s)
65 135
 }
66 136
 
67
-#' Internal version of gdns_resolver
137
+#' Internal version of gdns_context
68 138
 #' @keywords internal
69
-int_gdns_resolver <- function(resolvers) {
70
-    .Call(`_clandnstine_int_gdns_resolver`, resolvers)
139
+int_gdns_context <- function(resolvers) {
140
+    .Call(`_clandnstine_int_gdns_context`, resolvers)
71 141
 }
72 142
 
73 143
 #' Resolve a host to an addrss
@@ -91,3 +161,14 @@ int_gdns_query <- function(gctx, name, rr, include_reporting = FALSE) {
91 161
     .Call(`_clandnstine_int_gdns_query`, gctx, name, rr, include_reporting)
92 162
 }
93 163
 
164
+#' Get the current resolution type setting
165
+#'
166
+#' @param gctx gdns resolver context created with [gdns_resolver()]
167
+#' @export
168
+#' @examples
169
+#' x <- gdns_context()
170
+#' gdns_get_resolution_type(x)
171
+gdns_get_resolution_type <- function(gctx) {
172
+    .Call(`_clandnstine_gdns_get_resolution_type`, gctx)
173
+}
174
+

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

@@ -1,4 +1,4 @@
1
-#' Perform 'DNS' over 'TLS' Queries
1
+#' Perform Secure-by-default 'DNS' Queries
2 2
 #'
3 3
 #' Something something 'DNS. Something something 'TLS'.
4 4
 #' Something something 'getdns API/library'.

+ 3
- 1
R/print-context.R View File

@@ -12,7 +12,9 @@ print.gctx <- function(x, ...) {
12 12
       "<gdns v", gdns_lib_version(),
13 13
       " resolver context; resolvers: [",
14 14
       paste0(int_get_resolvers(x), collapse=", "),
15
-      "]; timeout: ", prettyNum(gdns_get_timeout(x), big.mark=","), " ms",
15
+      "]; timeout: ", prettyNum(gdns_get_timeout(x), big.mark=","),
16
+      " ms; lookup transport(s): [", paste0(gdns_get_transports(x), collapse=", "),
17
+      "]; resolution type: ", gdns_get_resolution_type(x),
16 18
       ">", "\n", sep = ""
17 19
     )
18 20
   }

+ 2
- 1
R/resolver.R View File

@@ -10,7 +10,7 @@
10 10
 #' x <- gdns_context()
11 11
 #' x <- gdns_context("1.1.1.1")
12 12
 gdns_context <- function(resolvers = "9.9.9.9") {
13
-  int_gdns_resolver(resolvers)
13
+  int_gdns_context(resolvers)
14 14
 }
15 15
 
16 16
 #' Changes the list of resolvers in an already created context for use in resolution functions
@@ -141,6 +141,7 @@ gdns_set_hosts<- function(gctx, hosts_file) {
141 141
 #' - `x25`
142 142
 #' - `zonemd`
143 143
 #'
144
+#' @note Local hosts files are ignored when using this `getdns` API endpoint
144 145
 #' @param gctx gdns resolver context created with [gdns_resolver()]
145 146
 #' @param name an entity to query for
146 147
 #' @param rr_type what resource record type do you want to queyr for? See `Details`.

+ 21
- 0
R/set-res-types.R View File

@@ -0,0 +1,21 @@
1
+.res_types <- c("stub" = 520L, "recursive" = 521L)
2
+
3
+#' Specify whether DNS queries are performed with recursive lookups or as a stub resolver
4
+#'
5
+#' @param gctx gdns resolver context created with [gdns_resolver()]
6
+#' @param res_type length 1 character vector of either "`stub`" or "`recursive`"
7
+#' @export
8
+#' @examples
9
+#' x <- gdns_context()
10
+#' x <- gdns_set_resolution_type(x, "stub")
11
+gdns_set_resolution_type <- function(gctx, res_type = c("stub", "recursive")) {
12
+
13
+  match.arg(
14
+    unique(tolower(trimws(res_type))), c("stub", "recursive")
15
+  ) -> transports
16
+
17
+  res_type <- unname(.res_types[res_type])
18
+
19
+  int_gdns_set_resolution_type(gctx, res_type)
20
+
21
+}

+ 24
- 0
R/set-transports.R View File

@@ -0,0 +1,24 @@
1
+.transport_trans <- c("tls" = 1202L, "tcp" = 1201L, "udp" = 1200L)
2
+
3
+#' Specifies what transport(s) is/ar used for DNS lookups
4
+#'
5
+#' @param gctx gdns resolver context created with [gdns_resolver()]
6
+#' @param transports character vector of any/all of "`udp`", "`tcp`" or "`tls`".
7
+#'        Order matters as it specifies that the library will use to try to
8
+#'        perform the lookups.
9
+#' @export
10
+#' @examples
11
+#' x <- gdns_context()
12
+#' x <- gdns_set_transports(x, "tls")
13
+gdns_set_transports <- function(gctx, transports = c("tls", "udp", "tcp")) {
14
+
15
+  match.arg(
16
+    unique(tolower(trimws(transports))), c("tls", "udp", "tcp"),
17
+    several.ok = TRUE
18
+  ) -> transports
19
+
20
+  transports <- unname(.transport_trans[transports])
21
+
22
+  int_gdns_set_transports(gctx, transports)
23
+
24
+}

+ 12
- 3
README.Rmd View File

@@ -14,7 +14,7 @@ options(width=120)
14 14
 
15 15
 # clandnstine
16 16
 
17
-Perform 'DNS' over 'TLS' Queries
17
+Perform Secure-by-default 'DNS' Queries
18 18
 
19 19
 ## Description
20 20
 
@@ -35,7 +35,7 @@ I've gotten this running on macOS and Ubuntu 16.04. For the latter I had to ensu
35 35
 
36 36
 ## TODO/WAT
37 37
 
38
-I finally grok the getdns api so the package api is going to change wildly and fast. It's only going to support DNS over TLS but will support all types of DNS queries. 
38
+I finally grok the getdns api so the package api is going to change wildly and fast. The default mode will be to perform queries using DNS over TLS but also supports UDP and TCP transports.
39 39
 
40 40
 ## Why?
41 41
 
@@ -85,15 +85,22 @@ It's stupid slow, consumes more CPU and bandwidth but forces adversaries to work
85 85
 
86 86
 The following functions are implemented:
87 87
 
88
-
89 88
 - `gdns_context`:  Create a gdns DNS over TLS context and populate it with a resolver for use in resolution functions
90 89
 - `gdns_get_address`:  Resolve a host to an addrss
90
+- `gdns_get_resolution_type`:	Get the current resolution type setting
91 91
 - `gdns_get_timeout`:  Retreive the number of milliseconds to wait for request to return
92
+- `gdns_get_tls_ca_file`:	Retreive the file location with CA certificates for verification purposes
93
+- `gdns_get_tls_ca_path`:	Retreive the value with which the context's upstream recursive servers and suffixes were initialized
94
+- `gdns_get_transports`:	Retreive what transports are used for DNS lookups.
92 95
 - `gdns_lib_version`:  Return gdns library version
93 96
 - `gdns_query`:  Arbitrary DNS queries
94 97
 - `gdns_set_hosts`:  Initialized the context's local names namespace with values from the given hosts file.
98
+- `gdns_set_resolution_type`:	Specify whether DNS queries are performed with recursive lookups or as a stub resolver
95 99
 - `gdns_set_round_robin_upstreams`:  Set/unset context to round robin queries over the available upstreams when resolving with the stub resolution type.
96 100
 - `gdns_set_timeout`:  Specify the number of milliseconds to wait for request to return
101
+- `gdns_set_tls_ca_file`:	Specify the file with CA certificates for verification purposes
102
+- `gdns_set_tls_ca_path`:	Specify where the location for CA certificates for verification purposes are located
103
+- `gdns_set_transports`:	Specifies what transport(s) is/ar used for DNS lookups
97 104
 - `gdns_update_resolvers`: Changes the list of resolvers in an already created context for use in resolution functions
98 105
 
99 106
 ## Installation
@@ -129,6 +136,8 @@ gdns_lib_version()
129 136
 
130 137
 (gdns_update_resolvers(x, "1.1.1.1"))
131 138
 
139
+(gdns_set_transports(x, c("udp", "tls", "tcp")))
140
+
132 141
 (gdns_get_address(x, "rud.is"))
133 142
 
134 143
 (gdns_get_address(x, "yahoo.com"))

+ 33
- 15
README.md View File

@@ -7,7 +7,7 @@ Status](https://codecov.io/gh/hrbrmstr/clandnstine/branch/master/graph/badge.svg
7 7
 
8 8
 # clandnstine
9 9
 
10
-Perform ‘DNS’ over ‘TLS’ Queries
10
+Perform Secure-by-default ‘DNS’ Queries
11 11
 
12 12
 ## Description
13 13
 
@@ -36,8 +36,8 @@ extract it and `config`/`make`/`make install` (plus `ldconfig` after).
36 36
 ## TODO/WAT
37 37
 
38 38
 I finally grok the getdns api so the package api is going to change
39
-wildly and fast. It’s only going to support DNS over TLS but will
40
-support all types of DNS queries.
39
+wildly and fast. The default mode will be to perform queries using DNS
40
+over TLS but also supports UDP and TCP transports.
41 41
 
42 42
 ## Why?
43 43
 
@@ -114,17 +114,32 @@ The following functions are implemented:
114 114
   - `gdns_context`: Create a gdns DNS over TLS context and populate it
115 115
     with a resolver for use in resolution functions
116 116
   - `gdns_get_address`: Resolve a host to an addrss
117
+  - `gdns_get_resolution_type`: Get the current resolution type setting
117 118
   - `gdns_get_timeout`: Retreive the number of milliseconds to wait for
118 119
     request to return
120
+  - `gdns_get_tls_ca_file`: Retreive the file location with CA
121
+    certificates for verification purposes
122
+  - `gdns_get_tls_ca_path`: Retreive the value with which the context’s
123
+    upstream recursive servers and suffixes were initialized
124
+  - `gdns_get_transports`: Retreive what transports are used for DNS
125
+    lookups.
119 126
   - `gdns_lib_version`: Return gdns library version
120 127
   - `gdns_query`: Arbitrary DNS queries
121 128
   - `gdns_set_hosts`: Initialized the context’s local names namespace
122 129
     with values from the given hosts file.
130
+  - `gdns_set_resolution_type`: Specify whether DNS queries are
131
+    performed with recursive lookups or as a stub resolver
123 132
   - `gdns_set_round_robin_upstreams`: Set/unset context to round robin
124 133
     queries over the available upstreams when resolving with the stub
125 134
     resolution type.
126 135
   - `gdns_set_timeout`: Specify the number of milliseconds to wait for
127 136
     request to return
137
+  - `gdns_set_tls_ca_file`: Specify the file with CA certificates for
138
+    verification purposes
139
+  - `gdns_set_tls_ca_path`: Specify where the location for CA
140
+    certificates for verification purposes are located
141
+  - `gdns_set_transports`: Specifies what transport(s) is/ar used for
142
+    DNS lookups
128 143
   - `gdns_update_resolvers`: Changes the list of resolvers in an already
129 144
     created context for use in resolution functions
130 145
 
@@ -153,27 +168,30 @@ gdns_lib_version()
153 168
 ## [1] "1.5.1"
154 169
 
155 170
 (x <- gdns_context())
156
-## <gdns v1.5.1 resolver context; resolvers: [9.9.9.9]; timeout: 5,000 ms>
171
+## <gdns v1.5.1 resolver context; resolvers: [9.9.9.9]; timeout: 5,000 ms; lookup transport(s): [tls]; resolution type: stub>
157 172
 
158 173
 (x <- gdns_context("1.1.1.1"))
159
-## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]; timeout: 5,000 ms>
174
+## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]; timeout: 5,000 ms; lookup transport(s): [tls]; resolution type: stub>
160 175
 
161 176
 (x <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9")))
162
-## <gdns v1.5.1 resolver context; resolvers: [8.8.8.8, 1.1.1.1, 9.9.9.9]; timeout: 5,000 ms>
177
+## <gdns v1.5.1 resolver context; resolvers: [8.8.8.8, 1.1.1.1, 9.9.9.9]; timeout: 5,000 ms; lookup transport(s): [tls]; resolution type: stub>
163 178
 
164 179
 (gdns_set_timeout(x, 2000))
165
-## <gdns v1.5.1 resolver context; resolvers: [8.8.8.8, 1.1.1.1, 9.9.9.9]; timeout: 2,000 ms>
180
+## <gdns v1.5.1 resolver context; resolvers: [8.8.8.8, 1.1.1.1, 9.9.9.9]; timeout: 2,000 ms; lookup transport(s): [tls]; resolution type: stub>
166 181
 
167 182
 (gdns_update_resolvers(x, "1.1.1.1"))
168
-## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]; timeout: 2,000 ms>
183
+## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]; timeout: 2,000 ms; lookup transport(s): [tls]; resolution type: stub>
184
+
185
+(gdns_set_transports(x, c("udp", "tls", "tcp")))
186
+## <gdns v1.5.1 resolver context; resolvers: [1.1.1.1]; timeout: 2,000 ms; lookup transport(s): [udp, tls, tcp]; resolution type: stub>
169 187
 
170 188
 (gdns_get_address(x, "rud.is"))
171 189
 ## [1] "2604:a880:800:10::6bc:2001" "104.236.112.222"
172 190
 
173 191
 (gdns_get_address(x, "yahoo.com"))
174
-##  [1] "2001:4998:44:41d::4"   "2001:4998:58:1836::10" "2001:4998:58:1836::11" "2001:4998:c:1023::4"  
175
-##  [5] "2001:4998:c:1023::5"   "2001:4998:44:41d::3"   "98.138.219.232"        "72.30.35.9"           
176
-##  [9] "72.30.35.10"           "98.137.246.7"          "98.137.246.8"          "98.138.219.231"
192
+##  [1] "2001:4998:58:1836::10" "2001:4998:58:1836::11" "2001:4998:c:1023::4"   "2001:4998:c:1023::5"  
193
+##  [5] "2001:4998:44:41d::3"   "2001:4998:44:41d::4"   "72.30.35.9"            "72.30.35.10"          
194
+##  [9] "98.137.246.7"          "98.137.246.8"          "98.138.219.231"        "98.138.219.232"
177 195
 
178 196
 (gdns_get_address(x, "yahoo.commmm"))
179 197
 ## character(0)
@@ -186,7 +204,7 @@ str(leno <- gdns_query(x, "lenovo.com", "txt"), 1)
186 204
 ## List of 5
187 205
 ##  $ answer_type   : int 800
188 206
 ##  $ canonical_name: chr "lenovo.com."
189
-##  $ replies_full  : int [1, 1:936] 55 119 129 128 0 1 0 8 0 0 ...
207
+##  $ replies_full  : int [1, 1:600] 165 144 129 128 0 1 0 8 0 0 ...
190 208
 ##  $ replies_tree  :'data.frame':  1 obs. of  7 variables:
191 209
 ##  $ status        : int 900
192 210
 ##  - attr(*, "class")= chr [1:2] "gdns_response" "list"
@@ -209,9 +227,9 @@ Yep. Advertising even in DNS `TXT` records (see item number
209 227
 
210 228
 | Lang | \# Files |  (%) | LoC |  (%) | Blank lines |  (%) | \# Lines |  (%) |
211 229
 | :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
212
-| C++  |        3 | 0.25 | 369 | 0.59 |         112 | 0.55 |       77 | 0.20 |
213
-| R    |        8 | 0.67 | 242 | 0.38 |          42 | 0.20 |      220 | 0.57 |
214
-| Rmd  |        1 | 0.08 |  18 | 0.03 |          51 | 0.25 |       89 | 0.23 |
230
+| C++  |        3 | 0.21 | 608 | 0.65 |         196 | 0.62 |      138 | 0.27 |
231
+| R    |       10 | 0.71 | 306 | 0.33 |          68 | 0.22 |      280 | 0.54 |
232
+| Rmd  |        1 | 0.07 |  19 | 0.02 |          51 | 0.16 |       97 | 0.19 |
215 233
 
216 234
 ## Code of Conduct
217 235
 

+ 1
- 1
man/clandnstine.Rd View File

@@ -4,7 +4,7 @@
4 4
 \name{clandnstine}
5 5
 \alias{clandnstine}
6 6
 \alias{clandnstine-package}
7
-\title{Perform 'DNS' over 'TLS' Queries}
7
+\title{Perform Secure-by-default 'DNS' Queries}
8 8
 \description{
9 9
 Something something 'DNS. Something something 'TLS'.
10 10
 Something something 'getdns API/library'.

+ 14
- 0
man/gdns_get_hosts.Rd View File

@@ -0,0 +1,14 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{gdns_get_hosts}
4
+\alias{gdns_get_hosts}
5
+\title{Retreive the value of the localnames namespace}
6
+\usage{
7
+gdns_get_hosts(gctx)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+}
12
+\description{
13
+Retreive the value of the localnames namespace
14
+}

+ 18
- 0
man/gdns_get_resolution_type.Rd View File

@@ -0,0 +1,18 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{gdns_get_resolution_type}
4
+\alias{gdns_get_resolution_type}
5
+\title{Get the current resolution type setting}
6
+\usage{
7
+gdns_get_resolution_type(gctx)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+}
12
+\description{
13
+Get the current resolution type setting
14
+}
15
+\examples{
16
+x <- gdns_context()
17
+gdns_get_resolution_type(x)
18
+}

+ 14
- 0
man/gdns_get_resolvconf.Rd View File

@@ -0,0 +1,14 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{gdns_get_resolvconf}
4
+\alias{gdns_get_resolvconf}
5
+\title{Retreive the value with which the context's upstream recursive servers and suffixes were initialized}
6
+\usage{
7
+gdns_get_resolvconf(gctx)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+}
12
+\description{
13
+Retreive the value with which the context's upstream recursive servers and suffixes were initialized
14
+}

+ 14
- 0
man/gdns_get_tls_ca_file.Rd View File

@@ -0,0 +1,14 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{gdns_get_tls_ca_file}
4
+\alias{gdns_get_tls_ca_file}
5
+\title{Retreive the file location with CA certificates for verification purposes}
6
+\usage{
7
+gdns_get_tls_ca_file(gctx)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+}
12
+\description{
13
+Retreive the file location with CA certificates for verification purposes
14
+}

+ 14
- 0
man/gdns_get_tls_ca_path.Rd View File

@@ -0,0 +1,14 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{gdns_get_tls_ca_path}
4
+\alias{gdns_get_tls_ca_path}
5
+\title{Retreive the value with which the context's upstream recursive servers and suffixes were initialized}
6
+\usage{
7
+gdns_get_tls_ca_path(gctx)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+}
12
+\description{
13
+Retreive the value with which the context's upstream recursive servers and suffixes were initialized
14
+}

+ 14
- 0
man/gdns_get_transports.Rd View File

@@ -0,0 +1,14 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{gdns_get_transports}
4
+\alias{gdns_get_transports}
5
+\title{Retreive what transports are used for DNS lookups.}
6
+\usage{
7
+gdns_get_transports(gctx)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+}
12
+\description{
13
+Retreive what transports are used for DNS lookups.
14
+}

+ 3
- 0
man/gdns_query.Rd View File

@@ -117,6 +117,9 @@ Valid values for \code{rr_type}:
117 117
 \item \code{zonemd}
118 118
 }
119 119
 }
120
+\note{
121
+Local hosts files are ignored when using this \code{getdns} API endpoint
122
+}
120 123
 \examples{
121 124
 x <- gdns_resolver()
122 125
 gdns_query(x, "example.com")

+ 20
- 0
man/gdns_set_resolution_type.Rd View File

@@ -0,0 +1,20 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/set-res-types.R
3
+\name{gdns_set_resolution_type}
4
+\alias{gdns_set_resolution_type}
5
+\title{Specify whether DNS queries are performed with recursive lookups or as a stub resolver}
6
+\usage{
7
+gdns_set_resolution_type(gctx, res_type = c("stub", "recursive"))
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+
12
+\item{res_type}{length 1 character vector of either "\code{stub}" or "\code{recursive}"}
13
+}
14
+\description{
15
+Specify whether DNS queries are performed with recursive lookups or as a stub resolver
16
+}
17
+\examples{
18
+x <- gdns_context()
19
+x <- gdns_set_resolution_type(x, "stub")
20
+}

+ 16
- 0
man/gdns_set_tls_ca_file.Rd View File

@@ -0,0 +1,16 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{gdns_set_tls_ca_file}
4
+\alias{gdns_set_tls_ca_file}
5
+\title{Specify the file with CA certificates for verification purposes}
6
+\usage{
7
+gdns_set_tls_ca_file(gctx, ca_file)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+
12
+\item{ca_file}{file with Certificate Authority certificates}
13
+}
14
+\description{
15
+Specify the file with CA certificates for verification purposes
16
+}

+ 16
- 0
man/gdns_set_tls_ca_path.Rd View File

@@ -0,0 +1,16 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{gdns_set_tls_ca_path}
4
+\alias{gdns_set_tls_ca_path}
5
+\title{Specify where the location for CA certificates for verification purposes are located}
6
+\usage{
7
+gdns_set_tls_ca_path(gctx, ca_path)
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+
12
+\item{ca_path}{directory with Certificate Authority certificates}
13
+}
14
+\description{
15
+Specify where the location for CA certificates for verification purposes are located
16
+}

+ 22
- 0
man/gdns_set_transports.Rd View File

@@ -0,0 +1,22 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/set-transports.R
3
+\name{gdns_set_transports}
4
+\alias{gdns_set_transports}
5
+\title{Specifies what transport(s) is/ar used for DNS lookups}
6
+\usage{
7
+gdns_set_transports(gctx, transports = c("tls", "udp", "tcp"))
8
+}
9
+\arguments{
10
+\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}}
11
+
12
+\item{transports}{character vector of any/all of "\code{udp}", "\code{tcp}" or "\code{tls}".
13
+Order matters as it specifies that the library will use to try to
14
+perform the lookups.}
15
+}
16
+\description{
17
+Specifies what transport(s) is/ar used for DNS lookups
18
+}
19
+\examples{
20
+x <- gdns_context()
21
+x <- gdns_set_transports(x, "tls")
22
+}

+ 12
- 0
man/int_gdns_context.Rd View File

@@ -0,0 +1,12 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{int_gdns_context}
4
+\alias{int_gdns_context}
5
+\title{Internal version of gdns_context}
6
+\usage{
7
+int_gdns_context(resolvers)
8
+}
9
+\description{
10
+Internal version of gdns_context
11
+}
12
+\keyword{internal}

+ 0
- 12
man/int_gdns_resolver.Rd View File

@@ -1,12 +0,0 @@
1
-% Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/RcppExports.R
3
-\name{int_gdns_resolver}
4
-\alias{int_gdns_resolver}
5
-\title{Internal version of gdns_resolver}
6
-\usage{
7
-int_gdns_resolver(resolvers)
8
-}
9
-\description{
10
-Internal version of gdns_resolver
11
-}
12
-\keyword{internal}

+ 12
- 0
man/int_gdns_set_resolution_type.Rd View File

@@ -0,0 +1,12 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{int_gdns_set_resolution_type}
4
+\alias{int_gdns_set_resolution_type}
5
+\title{Internal version of gdns_set_resolution_type()}
6
+\usage{
7
+int_gdns_set_resolution_type(gctx, res_type)
8
+}
9
+\description{
10
+Internal version of gdns_set_resolution_type()
11
+}
12
+\keyword{internal}

+ 12
- 0
man/int_gdns_set_transports.Rd View File

@@ -0,0 +1,12 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/RcppExports.R
3
+\name{int_gdns_set_transports}
4
+\alias{int_gdns_set_transports}
5
+\title{Internal version of set_transports()}
6
+\usage{
7
+int_gdns_set_transports(gctx, trans)
8
+}
9
+\description{
10
+Internal version of set_transports()
11
+}
12
+\keyword{internal}

+ 129
- 5
src/RcppExports.cpp View File

@@ -74,6 +74,109 @@ BEGIN_RCPP
74 74
     return rcpp_result_gen;
75 75
 END_RCPP
76 76
 }
77
+// int_gdns_set_transports
78
+SEXP int_gdns_set_transports(SEXP gctx, IntegerVector trans);
79
+RcppExport SEXP _clandnstine_int_gdns_set_transports(SEXP gctxSEXP, SEXP transSEXP) {
80
+BEGIN_RCPP
81
+    Rcpp::RObject rcpp_result_gen;
82
+    Rcpp::RNGScope rcpp_rngScope_gen;
83
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
84
+    Rcpp::traits::input_parameter< IntegerVector >::type trans(transSEXP);
85
+    rcpp_result_gen = Rcpp::wrap(int_gdns_set_transports(gctx, trans));
86
+    return rcpp_result_gen;
87
+END_RCPP
88
+}
89
+// int_gdns_set_resolution_type
90
+SEXP int_gdns_set_resolution_type(SEXP gctx, int res_type);
91
+RcppExport SEXP _clandnstine_int_gdns_set_resolution_type(SEXP gctxSEXP, SEXP res_typeSEXP) {
92
+BEGIN_RCPP
93
+    Rcpp::RObject rcpp_result_gen;
94
+    Rcpp::RNGScope rcpp_rngScope_gen;
95
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
96
+    Rcpp::traits::input_parameter< int >::type res_type(res_typeSEXP);
97
+    rcpp_result_gen = Rcpp::wrap(int_gdns_set_resolution_type(gctx, res_type));
98
+    return rcpp_result_gen;
99
+END_RCPP
100
+}
101
+// gdns_get_transports
102
+CharacterVector gdns_get_transports(SEXP gctx);
103
+RcppExport SEXP _clandnstine_gdns_get_transports(SEXP gctxSEXP) {
104
+BEGIN_RCPP
105
+    Rcpp::RObject rcpp_result_gen;
106
+    Rcpp::RNGScope rcpp_rngScope_gen;
107
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
108
+    rcpp_result_gen = Rcpp::wrap(gdns_get_transports(gctx));
109
+    return rcpp_result_gen;
110
+END_RCPP
111
+}
112
+// gdns_get_hosts
113
+CharacterVector gdns_get_hosts(SEXP gctx);
114
+RcppExport SEXP _clandnstine_gdns_get_hosts(SEXP gctxSEXP) {
115
+BEGIN_RCPP
116
+    Rcpp::RObject rcpp_result_gen;
117
+    Rcpp::RNGScope rcpp_rngScope_gen;
118
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
119
+    rcpp_result_gen = Rcpp::wrap(gdns_get_hosts(gctx));
120
+    return rcpp_result_gen;
121
+END_RCPP
122
+}
123
+// gdns_get_resolvconf
124
+CharacterVector gdns_get_resolvconf(SEXP gctx);
125
+RcppExport SEXP _clandnstine_gdns_get_resolvconf(SEXP gctxSEXP) {
126
+BEGIN_RCPP
127
+    Rcpp::RObject rcpp_result_gen;
128
+    Rcpp::RNGScope rcpp_rngScope_gen;
129
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
130
+    rcpp_result_gen = Rcpp::wrap(gdns_get_resolvconf(gctx));
131
+    return rcpp_result_gen;
132
+END_RCPP
133
+}
134
+// gdns_get_tls_ca_path
135
+StringVector gdns_get_tls_ca_path(SEXP gctx);
136
+RcppExport SEXP _clandnstine_gdns_get_tls_ca_path(SEXP gctxSEXP) {
137
+BEGIN_RCPP
138
+    Rcpp::RObject rcpp_result_gen;
139
+    Rcpp::RNGScope rcpp_rngScope_gen;
140
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
141
+    rcpp_result_gen = Rcpp::wrap(gdns_get_tls_ca_path(gctx));
142
+    return rcpp_result_gen;
143
+END_RCPP
144
+}
145
+// gdns_get_tls_ca_file
146
+StringVector gdns_get_tls_ca_file(SEXP gctx);
147
+RcppExport SEXP _clandnstine_gdns_get_tls_ca_file(SEXP gctxSEXP) {
148
+BEGIN_RCPP
149
+    Rcpp::RObject rcpp_result_gen;
150
+    Rcpp::RNGScope rcpp_rngScope_gen;
151
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
152
+    rcpp_result_gen = Rcpp::wrap(gdns_get_tls_ca_file(gctx));
153
+    return rcpp_result_gen;
154
+END_RCPP
155
+}
156
+// gdns_set_tls_ca_path
157
+SEXP gdns_set_tls_ca_path(SEXP gctx, std::string ca_path);
158
+RcppExport SEXP _clandnstine_gdns_set_tls_ca_path(SEXP gctxSEXP, SEXP ca_pathSEXP) {
159
+BEGIN_RCPP
160
+    Rcpp::RObject rcpp_result_gen;
161
+    Rcpp::RNGScope rcpp_rngScope_gen;
162
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
163
+    Rcpp::traits::input_parameter< std::string >::type ca_path(ca_pathSEXP);
164
+    rcpp_result_gen = Rcpp::wrap(gdns_set_tls_ca_path(gctx, ca_path));
165
+    return rcpp_result_gen;
166
+END_RCPP
167
+}
168
+// gdns_set_tls_ca_file
169
+SEXP gdns_set_tls_ca_file(SEXP gctx, std::string ca_file);
170
+RcppExport SEXP _clandnstine_gdns_set_tls_ca_file(SEXP gctxSEXP, SEXP ca_fileSEXP) {
171
+BEGIN_RCPP
172
+    Rcpp::RObject rcpp_result_gen;
173
+    Rcpp::RNGScope rcpp_rngScope_gen;
174
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
175
+    Rcpp::traits::input_parameter< std::string >::type ca_file(ca_fileSEXP);
176
+    rcpp_result_gen = Rcpp::wrap(gdns_set_tls_ca_file(gctx, ca_file));
177
+    return rcpp_result_gen;
178
+END_RCPP
179
+}
77 180
 // check_is_xptr
78 181
 void check_is_xptr(SEXP s);
79 182
 RcppExport SEXP _clandnstine_check_is_xptr(SEXP sSEXP) {
@@ -95,14 +198,14 @@ BEGIN_RCPP
95 198
     return rcpp_result_gen;
96 199
 END_RCPP
97 200
 }
98
-// int_gdns_resolver
99
-SEXP int_gdns_resolver(std::vector< std::string > resolvers);
100
-RcppExport SEXP _clandnstine_int_gdns_resolver(SEXP resolversSEXP) {
201
+// int_gdns_context
202
+SEXP int_gdns_context(std::vector< std::string > resolvers);
203
+RcppExport SEXP _clandnstine_int_gdns_context(SEXP resolversSEXP) {
101 204
 BEGIN_RCPP
102 205
     Rcpp::RObject rcpp_result_gen;
103 206
     Rcpp::RNGScope rcpp_rngScope_gen;
104 207
     Rcpp::traits::input_parameter< std::vector< std::string > >::type resolvers(resolversSEXP);
105
-    rcpp_result_gen = Rcpp::wrap(int_gdns_resolver(resolvers));
208
+    rcpp_result_gen = Rcpp::wrap(int_gdns_context(resolvers));
106 209
     return rcpp_result_gen;
107 210
 END_RCPP
108 211
 }
@@ -143,6 +246,17 @@ BEGIN_RCPP
143 246
     return rcpp_result_gen;
144 247
 END_RCPP
145 248
 }
249
+// gdns_get_resolution_type
250
+CharacterVector gdns_get_resolution_type(SEXP gctx);
251
+RcppExport SEXP _clandnstine_gdns_get_resolution_type(SEXP gctxSEXP) {
252
+BEGIN_RCPP
253
+    Rcpp::RObject rcpp_result_gen;
254
+    Rcpp::RNGScope rcpp_rngScope_gen;
255
+    Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP);
256
+    rcpp_result_gen = Rcpp::wrap(gdns_get_resolution_type(gctx));
257
+    return rcpp_result_gen;
258
+END_RCPP
259
+}
146 260
 
147 261
 static const R_CallMethodDef CallEntries[] = {
148 262
     {"_clandnstine_gdns_lib_version", (DL_FUNC) &_clandnstine_gdns_lib_version, 0},
@@ -151,12 +265,22 @@ static const R_CallMethodDef CallEntries[] = {
151 265
     {"_clandnstine_gdns_get_timeout", (DL_FUNC) &_clandnstine_gdns_get_timeout, 1},
152 266
     {"_clandnstine_gdns_set_round_robin_upstreams", (DL_FUNC) &_clandnstine_gdns_set_round_robin_upstreams, 2},
153 267
     {"_clandnstine_int_gdns_set_hosts", (DL_FUNC) &_clandnstine_int_gdns_set_hosts, 2},
268
+    {"_clandnstine_int_gdns_set_transports", (DL_FUNC) &_clandnstine_int_gdns_set_transports, 2},
269
+    {"_clandnstine_int_gdns_set_resolution_type", (DL_FUNC) &_clandnstine_int_gdns_set_resolution_type, 2},
270
+    {"_clandnstine_gdns_get_transports", (DL_FUNC) &_clandnstine_gdns_get_transports, 1},
271
+    {"_clandnstine_gdns_get_hosts", (DL_FUNC) &_clandnstine_gdns_get_hosts, 1},
272
+    {"_clandnstine_gdns_get_resolvconf", (DL_FUNC) &_clandnstine_gdns_get_resolvconf, 1},
273
+    {"_clandnstine_gdns_get_tls_ca_path", (DL_FUNC) &_clandnstine_gdns_get_tls_ca_path, 1},
274
+    {"_clandnstine_gdns_get_tls_ca_file", (DL_FUNC) &_clandnstine_gdns_get_tls_ca_file, 1},
275
+    {"_clandnstine_gdns_set_tls_ca_path", (DL_FUNC) &_clandnstine_gdns_set_tls_ca_path, 2},
276
+    {"_clandnstine_gdns_set_tls_ca_file", (DL_FUNC) &_clandnstine_gdns_set_tls_ca_file, 2},
154 277
     {"_clandnstine_check_is_xptr", (DL_FUNC) &_clandnstine_check_is_xptr, 1},
155 278
     {"_clandnstine_is_null_xptr_", (DL_FUNC) &_clandnstine_is_null_xptr_, 1},
156
-    {"_clandnstine_int_gdns_resolver", (DL_FUNC) &_clandnstine_int_gdns_resolver, 1},
279
+    {"_clandnstine_int_gdns_context", (DL_FUNC) &_clandnstine_int_gdns_context, 1},
157 280
     {"_clandnstine_gdns_get_address", (DL_FUNC) &_clandnstine_gdns_get_address, 2},
158 281
     {"_clandnstine_int_get_resolvers", (DL_FUNC) &_clandnstine_int_get_resolvers, 1},
159 282
     {"_clandnstine_int_gdns_query", (DL_FUNC) &_clandnstine_int_gdns_query, 4},
283
+    {"_clandnstine_gdns_get_resolution_type", (DL_FUNC) &_clandnstine_gdns_get_resolution_type, 1},
160 284
     {NULL, NULL, 0}
161 285
 };
162 286
 

+ 233
- 2
src/clandnstine-main.cpp View File

@@ -13,7 +13,6 @@ std::string gdns_lib_version() {
13 13
   return(std::string(getdns_get_version()));
14 14
 }
15 15
 
16
-
17 16
 //' Internal version of gdns_update_resolvers
18 17
 //' @keywords internal
19 18
 // [[Rcpp::export]]
@@ -141,4 +140,236 @@ SEXP int_gdns_set_hosts(SEXP gctx, std::string hosts) {
141 140
 
142 141
   return(gctx);
143 142
 
144
-}
143
+}
144
+
145
+//' Internal version of set_transports()
146
+//' @keywords internal
147
+// [[Rcpp::export]]
148
+SEXP int_gdns_set_transports(SEXP gctx, IntegerVector trans) {
149
+
150
+  check_is_xptr(gctx);
151
+
152
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
153
+
154
+  if (gctx == NULL) return(R_NilValue);
155
+
156
+  getdns_return_t r;
157
+
158
+  getdns_transport_list_t tls_transport[trans.size()];
159
+  for (int i=0; i<trans.size(); i++) {
160
+    switch(trans[i]) {
161
+    case 1200 : tls_transport[i] = GETDNS_TRANSPORT_UDP; break;
162
+    case 1201 : tls_transport[i] = GETDNS_TRANSPORT_TCP; break;
163
+    case 1202 : tls_transport[i] = GETDNS_TRANSPORT_TLS; break;
164
+    }
165
+  }
166
+
167
+  if ((r = getdns_context_set_dns_transport_list(ctxt, trans.size(), tls_transport))) {
168
+    Rf_error(getdns_get_errorstr_by_id(r));
169
+  }
170
+
171
+  return(gctx);
172
+}
173
+
174
+
175
+//' Internal version of gdns_set_resolution_type()
176
+//' @keywords internal
177
+// [[Rcpp::export]]
178
+SEXP int_gdns_set_resolution_type(SEXP gctx, int res_type) {
179
+
180
+  check_is_xptr(gctx);
181
+
182
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
183
+
184
+  if (gctx == NULL) return(R_NilValue);
185
+
186
+  getdns_return_t r;
187
+
188
+  if ((r = getdns_context_set_resolution_type(ctxt, res_type == 520 ? GETDNS_RESOLUTION_STUB : GETDNS_RESOLUTION_RECURSING))) {
189
+    Rf_error(getdns_get_errorstr_by_id(r));
190
+  }
191
+
192
+  return(gctx);
193
+
194
+}
195
+
196
+//' Retreive what transports are used for DNS lookups.
197
+//'
198
+//' @param gctx gdns resolver context created with [gdns_resolver()]
199
+//' @export
200
+// [[Rcpp::export]]
201
+CharacterVector gdns_get_transports(SEXP gctx) {
202
+
203
+  check_is_xptr(gctx);
204
+
205
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
206
+
207
+  if (gctx == NULL) return(R_NilValue);
208
+
209
+  getdns_return_t r;
210
+  size_t sz;
211
+  getdns_transport_list_t *trans;
212
+
213
+  if ((r = getdns_context_get_dns_transport_list(ctxt, &sz, &trans))) {
214
+    Rf_error(getdns_get_errorstr_by_id(r));
215
+  }
216
+
217
+  CharacterVector out(sz);
218
+
219
+  for (int i=0; i<sz; i++) {
220
+    switch(trans[i]) {
221
+    case GETDNS_TRANSPORT_UDP : out[i] = "udp"; break;
222
+    case GETDNS_TRANSPORT_TCP : out[i] = "tcp"; break;
223
+    case GETDNS_TRANSPORT_TLS : out[i] = "tls"; break;
224
+    }
225
+  }
226
+
227
+  if (trans) free(trans);
228
+
229
+  return(out);
230
+
231
+}
232
+
233
+//' Retreive the value of the localnames namespace
234
+//'
235
+//' @param gctx gdns resolver context created with [gdns_resolver()]
236
+//' @export
237
+// [[Rcpp::export]]
238
+CharacterVector gdns_get_hosts(SEXP gctx) {
239
+
240
+  check_is_xptr(gctx);
241
+
242
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
243
+
244
+  if (gctx == NULL) return(R_NilValue);
245
+
246
+  getdns_return_t r;
247
+  const char *hosts;
248
+
249
+  if ((r = getdns_context_get_hosts(ctxt, &hosts))) {
250
+    Rf_error(getdns_get_errorstr_by_id(r));
251
+  }
252
+
253
+  return(std::string(hosts));
254
+
255
+}
256
+
257
+//' Retreive the value with which the context's upstream recursive servers and suffixes were initialized
258
+//'
259
+//' @param gctx gdns resolver context created with [gdns_resolver()]
260
+//' @export
261
+// [[Rcpp::export]]
262
+CharacterVector gdns_get_resolvconf(SEXP gctx) {
263
+
264
+  check_is_xptr(gctx);
265
+
266
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
267
+
268
+  if (gctx == NULL) return(R_NilValue);
269
+
270
+  getdns_return_t r;
271
+  const char *resolv;
272
+
273
+  if ((r = getdns_context_get_resolvconf(ctxt, &resolv))) {
274
+    Rf_error(getdns_get_errorstr_by_id(r));
275
+  }
276
+
277
+  return(std::string(resolv));
278
+
279
+}
280
+
281
+//' Retreive the value with which the context's upstream recursive servers and suffixes were initialized
282
+//'
283
+//' @param gctx gdns resolver context created with [gdns_resolver()]
284
+//' @export
285
+// [[Rcpp::export]]
286
+StringVector gdns_get_tls_ca_path(SEXP gctx) {
287
+
288
+  check_is_xptr(gctx);
289
+
290
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
291
+
292
+  if (gctx == NULL) return(R_NilValue);
293
+
294
+  getdns_return_t r;
295
+  const char *ca_path;
296
+
297
+  if ((r = getdns_context_get_tls_ca_path(ctxt, &ca_path))) {
298
+    Rf_error(getdns_get_errorstr_by_id(r));
299
+  }
300
+
301
+  return(ca_path ? std::string(ca_path) : CharacterVector());
302
+
303
+}
304
+
305
+//' Retreive the file location with CA certificates for verification purposes
306
+//'
307
+//' @param gctx gdns resolver context created with [gdns_resolver()]
308
+//' @export
309
+// [[Rcpp::export]]
310
+StringVector gdns_get_tls_ca_file(SEXP gctx) {
311
+
312
+  check_is_xptr(gctx);
313
+
314
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
315
+
316
+  if (gctx == NULL) return(R_NilValue);
317
+
318
+  getdns_return_t r;
319
+  const char *ca_file;
320
+
321
+  if ((r = getdns_context_get_tls_ca_path(ctxt, &ca_file))) {
322
+    Rf_error(getdns_get_errorstr_by_id(r));
323
+  }
324
+
325
+  return(ca_file ? std::string(ca_file) : CharacterVector());
326
+
327
+}
328
+
329
+//' Specify where the location for CA certificates for verification purposes are located
330
+//'
331
+//' @param gctx gdns resolver context created with [gdns_resolver()]
332
+//' @param ca_path directory with Certificate Authority certificates
333
+//' @export
334
+// [[Rcpp::export]]
335
+SEXP gdns_set_tls_ca_path(SEXP gctx, std::string ca_path) {
336
+
337
+  check_is_xptr(gctx);
338
+
339
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
340
+
341
+  if (gctx == NULL) return(R_NilValue);
342
+
343
+  getdns_return_t r;
344
+
345
+  if ((r = getdns_context_set_tls_ca_path(ctxt, ca_path.c_str()))) {
346
+    Rf_error(getdns_get_errorstr_by_id(r));
347
+  }
348
+
349
+  return(gctx);
350
+
351
+}
352
+
353
+//' Specify the file with CA certificates for verification purposes
354
+//'
355
+//' @param gctx gdns resolver context created with [gdns_resolver()]
356
+//' @param ca_file file with Certificate Authority certificates
357
+//' @export
358
+// [[Rcpp::export]]
359
+SEXP gdns_set_tls_ca_file(SEXP gctx, std::string ca_file) {
360
+
361
+  check_is_xptr(gctx);
362
+
363
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
364
+
365
+  if (gctx == NULL) return(R_NilValue);
366
+
367
+  getdns_return_t r;
368
+
369
+  if ((r = getdns_context_set_tls_ca_file(ctxt, ca_file.c_str()))) {
370
+    Rf_error(getdns_get_errorstr_by_id(r));
371
+  }
372
+
373
+  return(gctx);
374
+
375
+}

+ 32
- 3
src/resolver.cpp View File

@@ -33,10 +33,10 @@ static void gctx_finalizer(SEXP ptr) {
33 33
   R_ClearExternalPtr(ptr); /* not really needed */
34 34
 }
35 35
 
36
-//' Internal version of gdns_resolver
36
+//' Internal version of gdns_context
37 37
 //' @keywords internal
38 38
 // [[Rcpp::export]]
39
-SEXP int_gdns_resolver(std::vector< std::string > resolvers) {
39
+SEXP int_gdns_context(std::vector< std::string > resolvers) {
40 40
 
41 41
   bool ok = false;
42 42
   SEXP ptr;
@@ -245,4 +245,33 @@ CharacterVector int_gdns_query(SEXP gctx, std::string name, uint16_t rr,
245 245
 
246 246
   if (ok) return(wrap(out)); else return(CharacterVector());
247 247
 
248
-}
248
+}
249
+
250
+//' Get the current resolution type setting
251
+//'
252
+//' @param gctx gdns resolver context created with [gdns_resolver()]
253
+//' @export
254
+//' @examples
255
+//' x <- gdns_context()
256
+//' gdns_get_resolution_type(x)
257
+// [[Rcpp::export]]
258
+CharacterVector gdns_get_resolution_type(SEXP gctx) {
259
+
260
+  check_is_xptr(gctx);
261
+
262
+  getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx);
263
+
264
+  if (gctx == NULL) return(CharacterVector());
265
+
266
+  getdns_return_t r;
267
+  getdns_resolution_t res_type;
268
+
269
+  if ((r = getdns_context_get_resolution_type(ctxt, &res_type))) {
270
+    Rf_error(getdns_get_errorstr_by_id(r));
271
+  }
272
+
273
+  std::string out = res_type == GETDNS_RESOLUTION_STUB ? "stub" : "recursive";
274
+
275
+  return(wrap(out));
276
+
277
+}

+ 23
- 2
tests/testthat/test-clandnstine.R View File

@@ -3,12 +3,24 @@ test_that("basic wrapper works", {
3 3
 
4 4
   expect_is(gdns_lib_version(), "character")
5 5
 
6
-  r <- gns_context()
6
+  r <- gdns_context()
7
+  expect_is(r, "gctx")
8
+
9
+  expect_is(gdns_lib_version(), "character")
10
+
11
+  expect_equal(gdns_get_resolution_type(r), "stub")
7 12
 
8 13
   x <- gdns_get_address(r, "example.com")
9 14
   expect_true(all(c("2606:2800:220:1:248:1893:25c8:1946", "93.184.216.34") %in% x))
10 15
 
11
-  r <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9"))
16
+  expect_error(gdns_set_timeout(x, 3000))
17
+
18
+  expect_is(gdns_update_resolvers(r, c("8.8.8.8", "1.1.1.1", "9.9.9.9")), "gctx")
19
+  expect_is(gdns_set_round_robin_upstreams(r, TRUE), "gctx")
20
+  expect_is(gdns_set_hosts(r, "/etc/hosts"), "gctx")
21
+  expect_is(gdns_set_timeout(r, 2000), "gctx")
22
+
23
+  expect_error(gdns_set_hosts(r, "/etc/hostssss"))
12 24
 
13 25
   x <- gdns_get_address(r, "example.com")
14 26
   expect_true(all(c("2606:2800:220:1:248:1893:25c8:1946", "93.184.216.34") %in% x))
@@ -22,4 +34,13 @@ test_that("basic wrapper works", {
22 34
   expect_equal(x$canonical_name, "example.com.")
23 35
   expect_true(grepl("spf", unlist(x$replies_tree$answer[[1]]$rdata$txt_strings)))
24 36
 
37
+  expect_equal(gdns_get_transports(r), "tls")
38
+  expect_is(gdns_set_transports(r, c("udp", "tls")), "gctx")
39
+  expect_equal(gdns_get_transports(r), c("udp", "tls"))
40
+
41
+  expect_true(
42
+    all(c("2606:2800:220:1:248:1893:25c8:1946", "93.184.216.34") %in%
43
+          gdns_get_address(r, "example.com"))
44
+  )
45
+
25 46
 })

Loading…
Cancel
Save