feat(lisp/dns): Check in very early DNS-over-HTTPS client
This includes very barebones support for querying TXT and MX records right now. The returned structure is not turned into a more convenient format and error handling is, well, NIL.
This commit is contained in:
parent
98cc5f9fac
commit
e50c362244
3 changed files with 45 additions and 0 deletions
|
@ -32,6 +32,7 @@ let
|
||||||
fun = readTree ./fun;
|
fun = readTree ./fun;
|
||||||
nix = readTree ./nix;
|
nix = readTree ./nix;
|
||||||
ops = readTree ./ops;
|
ops = readTree ./ops;
|
||||||
|
lisp = readTree ./lisp;
|
||||||
presentations = readTree ./presentations;
|
presentations = readTree ./presentations;
|
||||||
third_party = readTree ./third_party;
|
third_party = readTree ./third_party;
|
||||||
tools = readTree ./tools;
|
tools = readTree ./tools;
|
||||||
|
|
15
lisp/dns/default.nix
Normal file
15
lisp/dns/default.nix
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
pkgs.nix.buildLisp.library {
|
||||||
|
name = "dns";
|
||||||
|
|
||||||
|
deps = with pkgs.third_party.lisp; [
|
||||||
|
alexandria
|
||||||
|
cl-json
|
||||||
|
drakma
|
||||||
|
];
|
||||||
|
|
||||||
|
srcs = [
|
||||||
|
./resolver.lisp
|
||||||
|
];
|
||||||
|
}
|
29
lisp/dns/resolver.lisp
Normal file
29
lisp/dns/resolver.lisp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
;; Initial implementation is a simple client for
|
||||||
|
;; https://developers.google.com/speed/public-dns/docs/doh/json
|
||||||
|
|
||||||
|
(defpackage #:dns
|
||||||
|
(:documentation "Simple DNS resolver in Common Lisp")
|
||||||
|
(:use #:cl)
|
||||||
|
(:export #:lookup-txt #:lookup-mx))
|
||||||
|
|
||||||
|
(defvar *doh-base-url* "https://dns.google/resolve"
|
||||||
|
"Base URL of the service providing DNS-over-HTTP(S). Defaults to the
|
||||||
|
Google-hosted API.")
|
||||||
|
|
||||||
|
(defun lookup-generic (name type)
|
||||||
|
(multiple-value-bind (body)
|
||||||
|
(drakma:http-request *doh-base-url*
|
||||||
|
:decode-content t
|
||||||
|
:want-stream t
|
||||||
|
:parameters `(("type" . ,type)
|
||||||
|
("name" . ,name)
|
||||||
|
("ct" . "application/x-javascript")))
|
||||||
|
(cl-json:decode-json body)))
|
||||||
|
|
||||||
|
(defun lookup-txt (name)
|
||||||
|
"Look up the TXT records at NAME."
|
||||||
|
(lookup-generic name "TXT"))
|
||||||
|
|
||||||
|
(defun lookup-mx (name)
|
||||||
|
"Look up the MX records at NAME."
|
||||||
|
(lookup-generic name "MX"))
|
Loading…
Reference in a new issue