From d575ac084f3841602933b0bf3cf7958c17f43afe Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 21 Mar 2019 22:52:17 -0500 Subject: [PATCH] resolv-conf: Parse edns0, refactor some words, and add a unit test. --- extra/resolv-conf/resolv-conf-tests.factor | 18 ++++++++++++++++++ extra/resolv-conf/resolv-conf.factor | 12 +++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 extra/resolv-conf/resolv-conf-tests.factor diff --git a/extra/resolv-conf/resolv-conf-tests.factor b/extra/resolv-conf/resolv-conf-tests.factor new file mode 100644 index 0000000000..59c52cffe2 --- /dev/null +++ b/extra/resolv-conf/resolv-conf-tests.factor @@ -0,0 +1,18 @@ +! Copyright (C) 2019 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test resolv-conf ; +IN: resolv-conf.tests +{ + T{ resolv.conf + { nameserver V{ "127.0.0.53" } } + { domain V{ } } + { lookup V{ } } + { search V{ "localdomain" } } + { sortlist V{ } } + { options T{ options { edns0? t } } } + } +} [ + "nameserver 127.0.0.53 + options edns0 + search localdomain" string>resolv.conf +] unit-test \ No newline at end of file diff --git a/extra/resolv-conf/resolv-conf.factor b/extra/resolv-conf/resolv-conf.factor index f5c098c8a8..8a271e42ea 100644 --- a/extra/resolv-conf/resolv-conf.factor +++ b/extra/resolv-conf/resolv-conf.factor @@ -68,6 +68,7 @@ ERROR: unsupported-resolv.conf-option string ; { [ "rotate" ?head ] [ drop t >>rotate? ] } { [ "no-check-names" ?head ] [ drop t >>no-check-names? ] } { [ "inet6" ?head ] [ drop t >>inet6? ] } + { [ "edns0" ?head ] [ drop t >>edns0? ] } [ unsupported-resolv.conf-option ] } cond drop ; @@ -86,12 +87,17 @@ ERROR: unsupported-resolv.conf-line string ; PRIVATE> -: parse-resolve.conf ( path -- resolv.conf ) +: lines>resolv.conf ( lines -- resolv.conf ) [ ] dip - utf8 file-lines [ [ blank? ] trim ] map harvest [ "#" head? ] reject [ parse-resolv.conf-line ] each ; +: string>resolv.conf ( string -- resolv.conf ) + string-lines lines>resolv.conf ; + +: path>resolv.conf ( path -- resolv.conf ) + utf8 file-lines lines>resolv.conf ; + : default-resolv.conf ( -- resolv.conf ) - "/etc/resolv.conf" parse-resolve.conf ; + "/etc/resolv.conf" path>resolv.conf ;