about summary refs log tree commit diff
path: root/lisp
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-01-22T18·04+0000
committerVincent Ambo <tazjin@google.com>2020-01-22T18·04+0000
commite50c362244be69c12a6d4f320c6ca00475d2de34 (patch)
tree6cda941b2f2d9c66a3b935e8b9a369f0b5d2ca21 /lisp
parent98cc5f9fac9c2739e08486548a4c678e8d48965b (diff)
feat(lisp/dns): Check in very early DNS-over-HTTPS client r/448
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/dns/default.nix15
-rw-r--r--lisp/dns/resolver.lisp29
2 files changed, 44 insertions, 0 deletions
diff --git a/lisp/dns/default.nix b/lisp/dns/default.nix
new file mode 100644
index 000000000000..c41b02f97ca8
--- /dev/null
+++ b/lisp/dns/default.nix
@@ -0,0 +1,15 @@
+{ pkgs, ... }:
+
+pkgs.nix.buildLisp.library {
+  name = "dns";
+
+  deps = with pkgs.third_party.lisp; [
+    alexandria
+    cl-json
+    drakma
+  ];
+
+  srcs = [
+    ./resolver.lisp
+  ];
+}
diff --git a/lisp/dns/resolver.lisp b/lisp/dns/resolver.lisp
new file mode 100644
index 000000000000..774be525cb20
--- /dev/null
+++ b/lisp/dns/resolver.lisp
@@ -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"))