Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / ntpd.aug
1 (*
2 Module: Ntpd
3     Parses OpenNTPD's ntpd.conf
4
5 Author: Jasper Lievisse Adriaanse <jasper@jasper.la>
6
7 About: Reference
8     This lens is used to parse OpenNTPD's configuration file, ntpd.conf.
9     http://openntpd.org/
10
11 About: Usage Example
12     To be documented
13
14 About: License
15     This file is licensed under the LGPL v2+, like the rest of Augeas.
16
17 About: Configuration files
18   This lens applies to /etc/ntpd.conf.
19 See <filter>.
20 *)
21
22 module Ntpd =
23 autoload xfm
24
25 (************************************************************************
26  * Group: Utility variables/functions
27  ************************************************************************)
28
29 (* View: comment *)
30 let comment = Util.comment
31 (* View: empty *)
32 let empty   = Util.empty
33 (* View: eol *)
34 let eol     = Util.eol
35 (* View: space *)
36 let space   = Sep.space
37 (* View: word *)
38 let word    = Rx.word
39 (* View: device_re *)
40 let device_re = Rx.device_name | /\*/
41
42 (* View: address_re *)
43 let address_re = Rx.ip | /\*/ | Rx.hostname
44
45 (* View: stratum_re
46    value between 1 and 15 *)
47 let stratum_re = /1[0-5]|[1-9]/
48
49 (* View: refid_re
50    string with length < 5 *)
51 let refid_re = /[A-Za-z0-9_.-]{1,5}/
52
53 (* View: weight_re
54    value between 1 and 10 *)
55 let weight_re = /10|[1-9]/
56
57 (* View: rtable_re
58    0 - RT_TABLE_MAX *)
59 let rtable_re = Rx.byte
60
61 (* View: correction_re
62    should actually only match between -127000000 and 127000000 *)
63 let correction_re = Rx.relinteger_noplus
64
65 (************************************************************************
66  * View: key_opt_rtable_line
67  *   A subnode with a keyword, an optional routing table id and an end
68  *   of line.
69  *
70  *   Parameters:
71  *     kw:regexp - the pattern to match as key
72  *     sto:lens  - the storing lens
73  ************************************************************************)
74 let key_opt_rtable_line (kw:regexp) (sto:lens) =
75     let rtable = [ Util.del_str "rtable" . space . label "rtable"
76                    . store rtable_re ]
77       in [ key kw . space . sto . (space . rtable)? . eol ]
78
79 (************************************************************************
80  * View: key_opt_weight_rtable_line
81  *   A subnode with a keyword, an optional routing table id, an optional
82  *   weight-value and an end of line.
83  *   of line.
84  *
85  *   Parameters:
86  *     kw:regexp - the pattern to match as key
87  *     sto:lens  - the storing lens
88  ************************************************************************)
89 let key_opt_weight_rtable_line (kw:regexp) (sto:lens) =
90     let rtable = [ Util.del_str "rtable" . space . label "rtable" . store rtable_re ]
91         in let weight = [ Util.del_str "weight" . space . label "weight"
92                           . store weight_re ]
93         in [ key kw . space . sto . (space . weight)? . (space . rtable)? . eol ]
94
95 (************************************************************************
96  * View: opt_value
97  *   A subnode for optional values.
98  *
99  *   Parameters:
100  *     s:string - the option name and subtree label
101  *     r:regexp  - the pattern to match as store
102  ************************************************************************)
103 let opt_value (s:string) (r:regexp) =
104   Build.key_value s space (store r)
105
106 (************************************************************************
107  * Group: Keywords
108  ************************************************************************)
109
110 (* View: listen
111    listen on address [rtable table-id] *)
112 let listen =
113   let addr = [ label "address" . store address_re ]
114     in key_opt_rtable_line "listen on" addr
115
116 (* View: server
117    server address [weight weight-value] [rtable table-id] *)
118 let server =
119   let addr = [ label "address" . store address_re ]
120     in key_opt_weight_rtable_line "server" addr
121
122 (* View: servers
123    servers address [weight weight-value] [rtable table-id] *)
124 let servers =
125   let addr = [ label "address" . store address_re ]
126     in key_opt_weight_rtable_line "servers" addr
127
128 (* View: sensor
129    sensor device [correction microseconds] [weight weight-value] [refid
130              string] [stratum stratum-value] *)
131 let sensor =
132   let device = [ label "device" . store device_re ]
133     in let correction = opt_value "correction" correction_re
134       in let weight = opt_value "weight" weight_re
135         in let refid = opt_value "refid" refid_re
136           in let stratum = opt_value "stratum" stratum_re
137             in [ key "sensor" . space . device
138                  . (space . correction)?
139                  . (space . weight)?
140                  . (space . refid)?
141                  . (space . stratum)?
142                  . eol ]
143
144 (************************************************************************
145  * Group: Lens
146  ************************************************************************)
147
148 (* View: keyword *)
149 let keyword = listen | server | servers | sensor
150
151 (* View: lns *)
152 let lns = ( empty | comment | keyword )*
153
154 (* View: filter *)
155 let filter = (incl "/etc/ntpd.conf")
156
157 let xfm = transform lns filter