From 9973229a70ce3702424ccc13ac189713c2389b7e Mon Sep 17 00:00:00 2001 From: Ron Waldon-Howe Date: Sun, 27 Oct 2024 14:58:07 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=BA=20Support=20``=20elements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We leave operating-system-specific details like UNIX-sockets to consumers --- src/config.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/config.rs b/src/config.rs index 20c96ed..cf5880b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,25 +26,37 @@ pub struct BusConfig { #[query(".allow_anonymous")] // TODO: consider finding a way to make this `bool` instead of `Option<()>` pub allow_anonymous: Option<()>, + /// If `Some`, the bus daemon becomes a real daemon (forks into the background, etc.). #[query(".fork")] // TODO: consider finding a way to make this `bool` instead of `Option<()>` pub fork: Option<()>, + /// If `Some`, the bus daemon keeps its original umask when forking. /// This may be useful to avoid affecting the behavior of child processes. #[query(".keep_umask")] // TODO: consider finding a way to make this `bool` instead of `Option<()>` pub keep_umask: Option<()>, + + /// Address(es) that the bus should listen on. + /// The address is in the standard D-Bus format that contains a transport name plus possible parameters/options. + #[query(".listen")] + // TODO: consider finding a way to make this `Vec` instead of `Option>` + pub listen: Option>, + /// The bus daemon will write its pid to the specified file. #[query(".pidfile")] pub pidfile: Option, + /// If `Some`, the bus daemon will log to syslog. #[query(".syslog")] // TODO: consider finding a way to make this `bool` instead of `Option<()>` pub syslog: Option<()>, + /// This element only controls which message bus specific environment variables are set in activated clients. #[query(".type")] pub r#type: Option, + /// The user account the daemon should run as, as either a username or a UID. /// If the daemon cannot change to this UID on startup, it will exit. /// If this element is not present, the daemon will not change or care about its UID. @@ -187,6 +199,32 @@ mod tests { ); } + #[test] + fn bus_config_parse_with_listen_ok() { + let input = r#" + + unix:path=/tmp/foo + tcp:host=localhost,port=1234 + tcp:host=localhost,port=0,family=ipv4 + + "#; + + let busconfig = BusConfig::parse(input).expect("should parse XML input"); + + assert_eq!( + busconfig, + BusConfig { + listen: Some(vec![ + String::from("unix:path=/tmp/foo"), + String::from("tcp:host=localhost,port=1234"), + String::from("tcp:host=localhost,port=0,family=ipv4"), + ]), + ..Default::default() + } + ); + } + #[test] fn bus_config_parse_with_pidfile_ok() { let input = r#"