From 6559c857446d2e5c4ac82d0490fa5b2c1d61b935 Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Wed, 23 Jan 2019 06:05:10 -0500 Subject: [PATCH] additional getters/setters --- NAMESPACE | 7 +- R/RcppExports.R | 40 +++++++++ R/print-context.R | 3 +- R/resolver.R | 36 +++++++- README.Rmd | 24 ++++-- README.md | 48 +++++++---- man/gdns_context.Rd | 25 ++++++ man/gdns_get_timeout.Rd | 14 ++++ man/gdns_resolver.Rd | 25 ------ man/gdns_set_hosts.Rd | 21 +++++ man/gdns_set_round_robin_upstreams.Rd | 18 ++++ man/gdns_set_timeout.Rd | 16 ++++ man/gdns_update_resolvers.Rd | 24 ++++++ man/int_gdns_set_hosts.Rd | 12 +++ man/int_gdns_update_resolvers.Rd | 12 +++ src/RcppExports.cpp | 64 +++++++++++++++ src/clandnstine-main.cpp | 150 +++++++++++++++++++++++++++++----- tests/testthat/test-clandnstine.R | 4 +- 18 files changed, 468 insertions(+), 75 deletions(-) create mode 100644 man/gdns_context.Rd create mode 100644 man/gdns_get_timeout.Rd delete mode 100644 man/gdns_resolver.Rd create mode 100644 man/gdns_set_hosts.Rd create mode 100644 man/gdns_set_round_robin_upstreams.Rd create mode 100644 man/gdns_set_timeout.Rd create mode 100644 man/gdns_update_resolvers.Rd create mode 100644 man/int_gdns_set_hosts.Rd create mode 100644 man/int_gdns_update_resolvers.Rd diff --git a/NAMESPACE b/NAMESPACE index ca1db06..a59b8e2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,10 +3,15 @@ S3method(print,gctx) S3method(print,gdns_response) export("%>%") +export(gdns_context) export(gdns_get_address) +export(gdns_get_timeout) export(gdns_lib_version) export(gdns_query) -export(gdns_resolver) +export(gdns_set_hosts) +export(gdns_set_round_robin_upstreams) +export(gdns_set_timeout) +export(gdns_update_resolvers) importFrom(Rcpp,sourceCpp) importFrom(jsonlite,fromJSON) importFrom(magrittr,"%>%") diff --git a/R/RcppExports.R b/R/RcppExports.R index e9f09aa..b2fe2fb 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -8,6 +8,46 @@ gdns_lib_version <- function() { .Call(`_clandnstine_gdns_lib_version`) } +#' Internal version of gdns_update_resolvers +#' @keywords internal +int_gdns_update_resolvers <- function(gctx, resolvers) { + .Call(`_clandnstine_int_gdns_update_resolvers`, gctx, resolvers) +} + +#' Specify the number of milliseconds to wait for request to return +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @param timeout number of milliseconds (integer; i.e. not-fractional) +#' @export +gdns_set_timeout <- function(gctx, timeout) { + .Call(`_clandnstine_gdns_set_timeout`, gctx, timeout) +} + +#' Retreive the number of milliseconds to wait for request to return +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @export +gdns_get_timeout <- function(gctx) { + .Call(`_clandnstine_gdns_get_timeout`, gctx) +} + +#' Set/unset context to round robin queries over the available upstreams +#' when resolving with the stub resolution type. +#' +#' @md +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @param flag if `TRUE` (the default) round robin queries when using more than one stub resolver, +#' @export +gdns_set_round_robin_upstreams <- function(gctx, flag = TRUE) { + .Call(`_clandnstine_gdns_set_round_robin_upstreams`, gctx, flag) +} + +#' Internal version of gdns_set_hosts() +#' @keywords internal +int_gdns_set_hosts <- function(gctx, hosts) { + .Call(`_clandnstine_int_gdns_set_hosts`, gctx, hosts) +} + #' Test whether an object is an external pointer #' #' @param x object to test diff --git a/R/print-context.R b/R/print-context.R index a72e532..d24860f 100644 --- a/R/print-context.R +++ b/R/print-context.R @@ -12,7 +12,8 @@ print.gctx <- function(x, ...) { "\n", sep = "" + "]; timeout: ", prettyNum(gdns_get_timeout(x), big.mark=","), " ms", + ">", "\n", sep = "" ) } } \ No newline at end of file diff --git a/R/resolver.R b/R/resolver.R index 761205b..4a5a327 100644 --- a/R/resolver.R +++ b/R/resolver.R @@ -7,12 +7,42 @@ #' Defaults to Quad9 (`9.9.9.9`). #' @export #' @examples -#' x <- gdns_resolver() -#' x <- gdns_resolver("1.1.1.1") -gdns_resolver <- function(resolvers = "9.9.9.9") { +#' x <- gdns_context() +#' x <- gdns_context("1.1.1.1") +gdns_context <- function(resolvers = "9.9.9.9") { int_gdns_resolver(resolvers) } +#' Changes the list of resolvers in an already created context for use in resolution functions +#' +#' @note [DNS Privacy](https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers#DNSPrivacyTestServers-DoTservers) +#' maintains a list of DNS over TLS servers. +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @param resolvers character vector of valid DNS over TLS resolvers +#' @export +#' @examples +#' x <- gdns_context() +#' x <- gdns_update_resolvers("1.1.1.1") +gdns_update_resolvers<- function(gctx, resolvers) { + int_gdns_update_resolvers(gctx, resolvers) +} + +#' Initialized the context's local names namespace with values from the given hosts file. +#' +#' @param gctx gdns resolver context created with [gdns_resolver()] +#' @param hosts_file path to a valid `hosts` file (e.g. "`/etc/hosts`). This value +#' will be [path.expand()]ed. +#' @export +#' @examples +#' x <- gdns_context() +#' x <- gdns_set_hosts(x, "/etc/hosts") +gdns_set_hosts<- function(gctx, hosts_file) { + hosts_file <- path.expand(hosts_file[1]) + stopifnot(file.exists(hosts_file)) + int_gdns_set_hosts(gctx, hosts_file) +} + + #' Arbitrary DNS queries #' #' Perform any valid resource record inquiry for a given name. See `Details`. diff --git a/README.Rmd b/README.Rmd index f4b9157..2761b98 100644 --- a/README.Rmd +++ b/README.Rmd @@ -85,10 +85,16 @@ It's stupid slow, consumes more CPU and bandwidth but forces adversaries to work The following functions are implemented: -- `gdns_get_address`: Resolve a host to an addrss -- `gdns_lib_version`: Return gdns library version -- `gdns_query`: Arbitrary DNS queries -- `gdns_resolver`: Create a gdns DNS over TLS context and populate it with a resolver for use in resolution functions + +- `gdns_context`: Create a gdns DNS over TLS context and populate it with a resolver for use in resolution functions +- `gdns_get_address`: Resolve a host to an addrss +- `gdns_get_timeout`: Retreive the number of milliseconds to wait for request to return +- `gdns_lib_version`: Return gdns library version +- `gdns_query`: Arbitrary DNS queries +- `gdns_set_hosts`: Initialized the context's local names namespace with values from the given hosts file. +- `gdns_set_round_robin_upstreams`: Set/unset context to round robin queries over the available upstreams when resolving with the stub resolution type. +- `gdns_set_timeout`: Specify the number of milliseconds to wait for request to return +- `gdns_update_resolvers`: Changes the list of resolvers in an already created context for use in resolution functions ## Installation @@ -113,11 +119,15 @@ packageVersion("clandnstine") ```{r addr} gdns_lib_version() -(x <- gdns_resolver()) +(x <- gdns_context()) + +(x <- gdns_context("1.1.1.1")) + +(x <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9"))) -(x <- gdns_resolver("1.1.1.1")) +(gdns_set_timeout(x, 2000)) -(x <- gdns_resolver(c("8.8.8.8", "1.1.1.1", "9.9.9.9"))) +(gdns_update_resolvers(x, "1.1.1.1")) (gdns_get_address(x, "rud.is")) diff --git a/README.md b/README.md index b4d5d56..2c27161 100644 --- a/README.md +++ b/README.md @@ -111,11 +111,22 @@ to work pretty hard to try to figure out what you’re looking for. The following functions are implemented: + - `gdns_context`: Create a gdns DNS over TLS context and populate it + with a resolver for use in resolution functions - `gdns_get_address`: Resolve a host to an addrss + - `gdns_get_timeout`: Retreive the number of milliseconds to wait for + request to return - `gdns_lib_version`: Return gdns library version - `gdns_query`: Arbitrary DNS queries - - `gdns_resolver`: Create a gdns DNS over TLS context and populate it - with a resolver for use in resolution functions + - `gdns_set_hosts`: Initialized the context’s local names namespace + with values from the given hosts file. + - `gdns_set_round_robin_upstreams`: Set/unset context to round robin + queries over the available upstreams when resolving with the stub + resolution type. + - `gdns_set_timeout`: Specify the number of milliseconds to wait for + request to return + - `gdns_update_resolvers`: Changes the list of resolvers in an already + created context for use in resolution functions ## Installation @@ -141,22 +152,28 @@ packageVersion("clandnstine") gdns_lib_version() ## [1] "1.5.1" -(x <- gdns_resolver()) -## +(x <- gdns_context()) +## + +(x <- gdns_context("1.1.1.1")) +## + +(x <- gdns_context(c("8.8.8.8", "1.1.1.1", "9.9.9.9"))) +## -(x <- gdns_resolver("1.1.1.1")) -## +(gdns_set_timeout(x, 2000)) +## -(x <- gdns_resolver(c("8.8.8.8", "1.1.1.1", "9.9.9.9"))) -## +(gdns_update_resolvers(x, "1.1.1.1")) +## (gdns_get_address(x, "rud.is")) ## [1] "2604:a880:800:10::6bc:2001" "104.236.112.222" (gdns_get_address(x, "yahoo.com")) -## [1] "2001:4998:c:1023::5" "2001:4998:58:1836::11" "2001:4998:44:41d::3" "2001:4998:44:41d::4" -## [5] "2001:4998:c:1023::4" "2001:4998:58:1836::10" "98.138.219.231" "98.138.219.232" -## [9] "98.137.246.8" "72.30.35.9" "72.30.35.10" "98.137.246.7" +## [1] "2001:4998:44:41d::4" "2001:4998:58:1836::10" "2001:4998:58:1836::11" "2001:4998:c:1023::4" +## [5] "2001:4998:c:1023::5" "2001:4998:44:41d::3" "98.138.219.232" "72.30.35.9" +## [9] "72.30.35.10" "98.137.246.7" "98.137.246.8" "98.138.219.231" (gdns_get_address(x, "yahoo.commmm")) ## character(0) @@ -169,9 +186,10 @@ str(leno <- gdns_query(x, "lenovo.com", "txt"), 1) ## List of 5 ## $ answer_type : int 800 ## $ canonical_name: chr "lenovo.com." -## $ replies_full : int [1, 1:600] 135 135 129 128 0 1 0 8 0 0 ... +## $ replies_full : int [1, 1:936] 55 119 129 128 0 1 0 8 0 0 ... ## $ replies_tree :'data.frame': 1 obs. of 7 variables: ## $ status : int 900 +## - attr(*, "class")= chr [1:2] "gdns_response" "list" sort(unlist(leno$replies_tree$answer[[1]]$rdata$txt_strings)) ## [1] "a82c74b37aa84e7c8580f0e32f4d795d" @@ -191,9 +209,9 @@ Yep. Advertising even in DNS `TXT` records (see item number | Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | | :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: | -| C++ | 3 | 0.25 | 240 | 0.59 | 66 | 0.49 | 61 | 0.19 | -| R | 8 | 0.67 | 154 | 0.38 | 20 | 0.15 | 171 | 0.54 | -| Rmd | 1 | 0.08 | 16 | 0.04 | 48 | 0.36 | 84 | 0.27 | +| C++ | 3 | 0.25 | 369 | 0.59 | 112 | 0.55 | 77 | 0.20 | +| R | 8 | 0.67 | 242 | 0.38 | 42 | 0.20 | 220 | 0.57 | +| Rmd | 1 | 0.08 | 18 | 0.03 | 51 | 0.25 | 89 | 0.23 | ## Code of Conduct diff --git a/man/gdns_context.Rd b/man/gdns_context.Rd new file mode 100644 index 0000000..51078d7 --- /dev/null +++ b/man/gdns_context.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/resolver.R +\name{gdns_context} +\alias{gdns_context} +\title{Create a gdns DNS over TLS context and populate it with a resolver +for use in resolution functions} +\usage{ +gdns_context(resolvers = "9.9.9.9") +} +\arguments{ +\item{resolvers}{character vector of valid DNS over TLS resolvers; +Defaults to Quad9 (\code{9.9.9.9}).} +} +\description{ +Create a gdns DNS over TLS context and populate it with a resolver +for use in resolution functions +} +\note{ +\href{https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers#DNSPrivacyTestServers-DoTservers}{DNS Privacy} +maintains a list of DNS over TLS servers. +} +\examples{ +x <- gdns_context() +x <- gdns_context("1.1.1.1") +} diff --git a/man/gdns_get_timeout.Rd b/man/gdns_get_timeout.Rd new file mode 100644 index 0000000..ec0eb5c --- /dev/null +++ b/man/gdns_get_timeout.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_get_timeout} +\alias{gdns_get_timeout} +\title{Retreive the number of milliseconds to wait for request to return} +\usage{ +gdns_get_timeout(gctx) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} +} +\description{ +Retreive the number of milliseconds to wait for request to return +} diff --git a/man/gdns_resolver.Rd b/man/gdns_resolver.Rd deleted file mode 100644 index 33681da..0000000 --- a/man/gdns_resolver.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/resolver.R -\name{gdns_resolver} -\alias{gdns_resolver} -\title{Create a gdns DNS over TLS context and populate it with a resolver -for use in resolution functions} -\usage{ -gdns_resolver(resolvers = "9.9.9.9") -} -\arguments{ -\item{resolvers}{character vector of valid DNS over TLS resolvers; -Defaults to Quad9 (\code{9.9.9.9}).} -} -\description{ -Create a gdns DNS over TLS context and populate it with a resolver -for use in resolution functions -} -\note{ -\href{https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers#DNSPrivacyTestServers-DoTservers}{DNS Privacy} -maintains a list of DNS over TLS servers. -} -\examples{ -x <- gdns_resolver() -x <- gdns_resolver("1.1.1.1") -} diff --git a/man/gdns_set_hosts.Rd b/man/gdns_set_hosts.Rd new file mode 100644 index 0000000..f7dd5b9 --- /dev/null +++ b/man/gdns_set_hosts.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/resolver.R +\name{gdns_set_hosts} +\alias{gdns_set_hosts} +\title{Initialized the context's local names namespace with values from the given hosts file.} +\usage{ +gdns_set_hosts(gctx, hosts_file) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} + +\item{hosts_file}{path to a valid \code{hosts} file (e.g. "\code{/etc/hosts}). This value +will be \code{\link[=path.expand]{path.expand()}}ed.} +} +\description{ +Initialized the context's local names namespace with values from the given hosts file. +} +\examples{ +x <- gdns_context() +x <- gdns_set_hosts(x, "/etc/hosts") +} diff --git a/man/gdns_set_round_robin_upstreams.Rd b/man/gdns_set_round_robin_upstreams.Rd new file mode 100644 index 0000000..98295cd --- /dev/null +++ b/man/gdns_set_round_robin_upstreams.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_set_round_robin_upstreams} +\alias{gdns_set_round_robin_upstreams} +\title{Set/unset context to round robin queries over the available upstreams +when resolving with the stub resolution type.} +\usage{ +gdns_set_round_robin_upstreams(gctx, flag = TRUE) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} + +\item{flag}{if \code{TRUE} (the default) round robin queries when using more than one stub resolver,} +} +\description{ +Set/unset context to round robin queries over the available upstreams +when resolving with the stub resolution type. +} diff --git a/man/gdns_set_timeout.Rd b/man/gdns_set_timeout.Rd new file mode 100644 index 0000000..1cd0218 --- /dev/null +++ b/man/gdns_set_timeout.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{gdns_set_timeout} +\alias{gdns_set_timeout} +\title{Specify the number of milliseconds to wait for request to return} +\usage{ +gdns_set_timeout(gctx, timeout) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} + +\item{timeout}{number of milliseconds (integer; i.e. not-fractional)} +} +\description{ +Specify the number of milliseconds to wait for request to return +} diff --git a/man/gdns_update_resolvers.Rd b/man/gdns_update_resolvers.Rd new file mode 100644 index 0000000..0d9f21d --- /dev/null +++ b/man/gdns_update_resolvers.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/resolver.R +\name{gdns_update_resolvers} +\alias{gdns_update_resolvers} +\title{Changes the list of resolvers in an already created context for use in resolution functions} +\usage{ +gdns_update_resolvers(gctx, resolvers) +} +\arguments{ +\item{gctx}{gdns resolver context created with \code{\link[=gdns_resolver]{gdns_resolver()}}} + +\item{resolvers}{character vector of valid DNS over TLS resolvers} +} +\description{ +Changes the list of resolvers in an already created context for use in resolution functions +} +\note{ +\href{https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Test+Servers#DNSPrivacyTestServers-DoTservers}{DNS Privacy} +maintains a list of DNS over TLS servers. +} +\examples{ +x <- gdns_context() +x <- gdns_update_resolvers("1.1.1.1") +} diff --git a/man/int_gdns_set_hosts.Rd b/man/int_gdns_set_hosts.Rd new file mode 100644 index 0000000..54ca76f --- /dev/null +++ b/man/int_gdns_set_hosts.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{int_gdns_set_hosts} +\alias{int_gdns_set_hosts} +\title{Internal version of gdns_set_hosts()} +\usage{ +int_gdns_set_hosts(gctx, hosts) +} +\description{ +Internal version of gdns_set_hosts() +} +\keyword{internal} diff --git a/man/int_gdns_update_resolvers.Rd b/man/int_gdns_update_resolvers.Rd new file mode 100644 index 0000000..ce723b0 --- /dev/null +++ b/man/int_gdns_update_resolvers.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{int_gdns_update_resolvers} +\alias{int_gdns_update_resolvers} +\title{Internal version of gdns_update_resolvers} +\usage{ +int_gdns_update_resolvers(gctx, resolvers) +} +\description{ +Internal version of gdns_update_resolvers +} +\keyword{internal} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 1b5d582..34c2478 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -15,6 +15,65 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// int_gdns_update_resolvers +SEXP int_gdns_update_resolvers(SEXP gctx, std::vector< std::string > resolvers); +RcppExport SEXP _clandnstine_int_gdns_update_resolvers(SEXP gctxSEXP, SEXP resolversSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + Rcpp::traits::input_parameter< std::vector< std::string > >::type resolvers(resolversSEXP); + rcpp_result_gen = Rcpp::wrap(int_gdns_update_resolvers(gctx, resolvers)); + return rcpp_result_gen; +END_RCPP +} +// gdns_set_timeout +SEXP gdns_set_timeout(SEXP gctx, long timeout); +RcppExport SEXP _clandnstine_gdns_set_timeout(SEXP gctxSEXP, SEXP timeoutSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + Rcpp::traits::input_parameter< long >::type timeout(timeoutSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_set_timeout(gctx, timeout)); + return rcpp_result_gen; +END_RCPP +} +// gdns_get_timeout +DoubleVector gdns_get_timeout(SEXP gctx); +RcppExport SEXP _clandnstine_gdns_get_timeout(SEXP gctxSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_get_timeout(gctx)); + return rcpp_result_gen; +END_RCPP +} +// gdns_set_round_robin_upstreams +SEXP gdns_set_round_robin_upstreams(SEXP gctx, bool flag); +RcppExport SEXP _clandnstine_gdns_set_round_robin_upstreams(SEXP gctxSEXP, SEXP flagSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + Rcpp::traits::input_parameter< bool >::type flag(flagSEXP); + rcpp_result_gen = Rcpp::wrap(gdns_set_round_robin_upstreams(gctx, flag)); + return rcpp_result_gen; +END_RCPP +} +// int_gdns_set_hosts +SEXP int_gdns_set_hosts(SEXP gctx, std::string hosts); +RcppExport SEXP _clandnstine_int_gdns_set_hosts(SEXP gctxSEXP, SEXP hostsSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< SEXP >::type gctx(gctxSEXP); + Rcpp::traits::input_parameter< std::string >::type hosts(hostsSEXP); + rcpp_result_gen = Rcpp::wrap(int_gdns_set_hosts(gctx, hosts)); + return rcpp_result_gen; +END_RCPP +} // check_is_xptr void check_is_xptr(SEXP s); RcppExport SEXP _clandnstine_check_is_xptr(SEXP sSEXP) { @@ -87,6 +146,11 @@ END_RCPP static const R_CallMethodDef CallEntries[] = { {"_clandnstine_gdns_lib_version", (DL_FUNC) &_clandnstine_gdns_lib_version, 0}, + {"_clandnstine_int_gdns_update_resolvers", (DL_FUNC) &_clandnstine_int_gdns_update_resolvers, 2}, + {"_clandnstine_gdns_set_timeout", (DL_FUNC) &_clandnstine_gdns_set_timeout, 2}, + {"_clandnstine_gdns_get_timeout", (DL_FUNC) &_clandnstine_gdns_get_timeout, 1}, + {"_clandnstine_gdns_set_round_robin_upstreams", (DL_FUNC) &_clandnstine_gdns_set_round_robin_upstreams, 2}, + {"_clandnstine_int_gdns_set_hosts", (DL_FUNC) &_clandnstine_int_gdns_set_hosts, 2}, {"_clandnstine_check_is_xptr", (DL_FUNC) &_clandnstine_check_is_xptr, 1}, {"_clandnstine_is_null_xptr_", (DL_FUNC) &_clandnstine_is_null_xptr_, 1}, {"_clandnstine_int_gdns_resolver", (DL_FUNC) &_clandnstine_int_gdns_resolver, 1}, diff --git a/src/clandnstine-main.cpp b/src/clandnstine-main.cpp index 7104549..0c39fa7 100644 --- a/src/clandnstine-main.cpp +++ b/src/clandnstine-main.cpp @@ -4,7 +4,7 @@ #include using namespace Rcpp; - +extern void check_is_xptr(SEXP s); //' Return gdns library version //' //' @export @@ -14,23 +14,131 @@ std::string gdns_lib_version() { } -// CharacterVector int_gdns_list_to_r() { -// -// getdns_list *gl; -// -// std::string out; -// -// // if (!lst) return(CharacterVector()); -// // -// // char *res = getdns_print_json_list(lst, 0); -// // if (res) { -// // out = std::string(res); -// // free(res); -// // } else { -// // return(CharacterVector()); -// // } -// -// return(wrap(out)); -// -// } -// +//' Internal version of gdns_update_resolvers +//' @keywords internal +// [[Rcpp::export]] +SEXP int_gdns_update_resolvers(SEXP gctx, std::vector< std::string > resolvers) { + + check_is_xptr(gctx); + + getdns_context *ctxt = (getdns_context *)R_ExternalPtrAddr(gctx); + + if (gctx == NULL) return(R_NilValue); + + getdns_return_t r; + + // TODO Validate we don't need to free these + getdns_dict *resolver_dict = getdns_dict_create(); + getdns_list *resolver_list = getdns_list_create(); + + for (int i = 0; i