Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / dnsmasq.aug
1 (* Dnsmasq module for Augeas
2  Author: Free Ekanayaka <free@64studio.com>
3
4  Reference: man dnsmasq (8)
5
6  "Format is one option per line, legal options are the same
7   as the long options legal on the command line. See
8  "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details."
9
10 *)
11
12 module Dnsmasq =
13
14    autoload xfm
15
16 (************************************************************************
17  *                           USEFUL PRIMITIVES
18  *************************************************************************)
19
20 let eol          = Util.eol
21 let spc          = Util.del_ws_spc
22 let comment      = Util.comment
23 let empty        = Util.empty
24
25 let sep_eq       = Sep.equal
26 let sto_to_eol   = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
27
28 let slash        = Util.del_str "/"
29 let sto_no_slash = store /([^\/ \t\n]+)/
30 let domains      = slash . [ label "domain" . sto_no_slash . slash ]+
31
32 (************************************************************************
33  *                            SIMPLE ENTRIES
34  *************************************************************************)
35
36 let entry_re   = Rx.word - /(address|server)/
37 let entry      = [ key entry_re . (sep_eq . sto_to_eol)? . eol ]
38
39 (************************************************************************
40  *                          STRUCTURED ENTRIES
41  *************************************************************************)
42
43 let address       = [ key "address" . sep_eq . domains . sto_no_slash . eol ]
44
45 let server        =
46      let port     = [ Build.xchgs "#" "port" . store Rx.integer ]
47   in let source   = [ Build.xchgs "@" "source" . store /[^#\/ \t\n]+/ . port? ]
48   in let srv_spec = store /(#|([^#@\/ \t\n]+))/ . port? . source?
49   in [ key "server" . sep_eq . domains? . srv_spec? . eol ]
50
51 (************************************************************************
52  *                                LENS
53  *************************************************************************)
54
55 let lns = (comment|empty|address|server|entry) *
56
57 let filter            = incl "/etc/dnsmasq.conf"
58                       . incl "/etc/dnsmasq.d/*"
59                       . excl ".*"
60                       . Util.stdexcl
61
62 let xfm                = transform lns filter