resolv-conf: Parse edns0, refactor some words, and add a unit test.

windows-drag
Doug Coleman 2019-03-21 22:52:17 -05:00
parent ebc1c1ef58
commit d575ac084f
2 changed files with 27 additions and 3 deletions

View File

@ -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

View File

@ -68,6 +68,7 @@ ERROR: unsupported-resolv.conf-option string ;
{ [ "rotate" ?head ] [ drop t >>rotate? ] } { [ "rotate" ?head ] [ drop t >>rotate? ] }
{ [ "no-check-names" ?head ] [ drop t >>no-check-names? ] } { [ "no-check-names" ?head ] [ drop t >>no-check-names? ] }
{ [ "inet6" ?head ] [ drop t >>inet6? ] } { [ "inet6" ?head ] [ drop t >>inet6? ] }
{ [ "edns0" ?head ] [ drop t >>edns0? ] }
[ unsupported-resolv.conf-option ] [ unsupported-resolv.conf-option ]
} cond drop ; } cond drop ;
@ -86,12 +87,17 @@ ERROR: unsupported-resolv.conf-line string ;
PRIVATE> PRIVATE>
: parse-resolve.conf ( path -- resolv.conf ) : lines>resolv.conf ( lines -- resolv.conf )
[ <resolv.conf> ] dip [ <resolv.conf> ] dip
utf8 file-lines
[ [ blank? ] trim ] map harvest [ [ blank? ] trim ] map harvest
[ "#" head? ] reject [ "#" head? ] reject
[ parse-resolv.conf-line ] each ; [ 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 ) : default-resolv.conf ( -- resolv.conf )
"/etc/resolv.conf" parse-resolve.conf ; "/etc/resolv.conf" path>resolv.conf ;