From: Ian Jackson Date: Sun, 25 Jul 2021 18:38:06 +0000 (+0100) Subject: config: Substitutions prefer %{...} to %(...)s, document, etc. X-Git-Tag: hippotat/1.0.0~441 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=61e5e6f6f32aa750ba645574e8e101e10d71c202;p=hippotat.git config: Substitutions prefer %{...} to %(...)s, document, etc. Signed-off-by: Ian Jackson --- diff --git a/README.config b/README.config index cde9e13..cc921c1 100644 --- a/README.config +++ b/README.config @@ -71,11 +71,13 @@ Exceptional settings: Command to run to create and communicate with local network interface. Passed to sh -c. Must speak SLIP on stdin/stdout. The following interpolations aare substituted: - %(local)s %(peer)s %(rnets)s %(ifname)s + %{local} %{peer} %{rnets} %{ifname} on server on client - Plus %(mtu)s (and %% to indicate a literal %). - ["userv root ipif %(local)s,%(peer)s,%(mtu)s,slip '%(rnets)s'"] + Plus %{mtu} and %% to indicate a literal %. + (For compatibility with older hippotat, %(var)s is supported too + but this is deprecated since the extra `s` is confusing.) + ["userv root ipif %{local},%{peer},%{mtu},slip '%{rnets}'"] On server: applies to all clients; not looked up in client-specific sections. diff --git a/src/config.rs b/src/config.rs index c38b580..4b94b3e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -58,7 +58,7 @@ ifname_client = hippo%d ifname_server = shippo%d max_clock_skew = 300 -ipif = userv root ipif %(local)s,%(peer)s,%(mtu)s,slip,%(ifname)s '%(rnets)s' +ipif = userv root ipif %{local},%{peer},%{mtu},slip,%{ifname} '%{rnets}' mtu = 1500 @@ -694,11 +694,11 @@ impl InstanceConfig { .collect::>(); let bad = parking_lot::Mutex::new(vec![]); *var = regex_replace_all!( - r#"%(?:%|\((\w+)\)s|.)"#, + r#"%(?:%|\((\w+)\)s|\{(\w+)\}|.)"#, &var, - |whole, k| (|| Ok::<_,String>({ + |whole, k1, k2| (|| Ok::<_,String>({ if whole == "%%" { "%" } - else if k != "" { + else if let Some(&k) = [k1,k2].iter().find(|&&s| s != "") { substs.get(k).ok_or_else( || format!("unknown key %({})s", k) )?