feat(client): redesign native UI, themes, settings and avatars

Separate conversation drafts and voice view state, add native settings and restricted CSS themes, implement validated avatar cropping, and refresh dependencies with documented desktop compatibility backports.
This commit is contained in:
Loki 2026-10-24 14:23:48 +02:00
parent 44d284a568
commit 8e5ab56611
Signed by: boba
GPG key ID: 253067914055423B
276 changed files with 53546 additions and 3399 deletions

64
patches/zbus-lockstep/Cargo.toml vendored Normal file
View file

@ -0,0 +1,64 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "zbus-lockstep"
version = "0.5.2"
authors = [
"Luuk van der Duim <luukvanderduim@gmail.com>",
"Tait Hoyem<tait@tait.tech>",
]
build = false
include = [
"src/**/*",
"LICENSE-MIT",
"README.md",
]
publish = true
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Keep types in lockstep with DBus XML definitions"
documentation = "https://docs.rs/zbus-lockstep"
readme = "README.md"
keywords = [
"type-safety",
"zbus",
"DBus",
"IPC",
]
license = "MIT"
repository = "https://github.com/luukvanderduim/zbus-lockstep"
[badges.maintenance]
status = "actively-developed"
[lib]
name = "zbus_lockstep"
path = "src/lib.rs"
[dependencies.zbus_xml]
version = "6"
[dev-dependencies.tempfile]
version = "3"
[dev-dependencies.version-sync]
version = "0.9"
[dependencies.zbus]
version = "6.1"
default-features = false
features = ["default-rt", "proxy", "service", "object-manager"]

23
patches/zbus-lockstep/LICENSE-MIT vendored Normal file
View file

@ -0,0 +1,23 @@
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

102
patches/zbus-lockstep/README.md vendored Normal file
View file

@ -0,0 +1,102 @@
# zbus-lockstep
[![CI](https://github.com/luukvanderduim/zbus-lockstep/actions/workflows/rust.yml/badge.svg)](https://github.com/luukvanderduim/zbus-lockstep/actions/workflows/rust.yml)
![Maintenance](https://img.shields.io/badge/maintenance-actively--developed-brightgreen.svg)
[![crates-io](https://img.shields.io/crates/v/zbus-lockstep.svg)](https://crates.io/crates/zbus-lockstep)
[![api-docs](https://docs.rs/zbus-lockstep/badge.svg)](https://docs.rs/zbus-lockstep)
`zbus-lockstep` helps keep type definitions in lockstep with DBus XML descriptions, using [`zbus-xml`](<https://github.com/dbus2/zbus>).
It offers means to match your type's signature - [`<T as zvariant::Type>::signature()`](https://docs.rs/zvariant/latest/zvariant/trait.Type.html#tymethod.signature) - with a corresponding signature retrieved from a DBus XML file.
This way `zbus-lockstep` prevents definitions from drifting apart.
## Motivation
In the context of IPC over `DBus` - especially when there are multiple implementations of servers and/or clients - it is necessary for each implementation to send what others expect and that expectations are in accordance with what is sent over the bus.
The `XML` protocol-descriptions may act as a shared frame of reference or "single source of all truth" for all implementers.
Having a single point of reference helps all implementers meet expectations on protocol conformance.
Keeping the types you send over `DBus` in lockstep with currently valid protocol-descriptions will reduce chances of miscommunication or failure to communicate.
## Usage
Add `zbus-lockstep` to `Cargo.toml`'s dev-dependencies:
```toml
[dev-dependencies]
zbus-lockstep = "0.5.2"
```
Consider the followwing XML description, an interface with a single signal.
```XML
<node>
<interface name="org.example.Node">
<signal name="RemoveNode">
<arg name="nodeRemoved" type="(so)"/>
</signal>
</interface>
</node>
```
The type in our implementation might look like this:
```rust
#[derive(Type)]
struct Node {
name: String,
path: OwnedObjectPath,
}
```
The derive macro in this example implements the [`zvariant::Type`](https://docs.rs/zvariant/latest/zvariant/trait.Type.html).
This means we can now call `<Node as Type::signature()`, which will return a [`zvariant::Signature`](https://docs.rs/zvariant/latest/zvariant/struct.Signature.html) of the type.
The test below shows how `zbus-lockstep` may be used given what we know about the type.
```rust
use zbus_lockstep;
#[test]
fn test_get_signal_body_type_remove_node() {
let xml = PathBuf::from("../xml/test_definition_file.xml");
let iface = "org.example.Node";
let member = "RemoveNode";
let signature = get_signal_body_type(xml, iface, member, None).unwrap();
assert_eq!(signature, Signature::from_str_unchecked("(so)"));
}
```
Alongside the functions, macros are provided which - if the path to the
definitions is known - can retrieve signatures more succinctly.
```rust
#[test]
fn macro_retrieve_signal_body_remove_node() {
std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
use zbus_lockstep;
let sig = signal_body_type_signature!("RemoveNode");
assert_eq!(sig, zvariant::Signature::from_str_unchecked("(so)"));
}
```
## Note
When using XML descriptions as point of reference, you should ensure that the descriptions in use are always the most recent available.
Automated synchronizing would be preferred.
## Acknowledgement
This crate started out as a fork of Tait Hoyem's [zbus-xml-match](https://github.com/TTWNO/zbus-xml-match).
## LICENSE
MIT

9
patches/zbus-lockstep/VNOX-PATCH.md vendored Normal file
View file

@ -0,0 +1,9 @@
# Vnox maintenance patch: zbus-lockstep 0.5.2
Source: published crates.io zbus-lockstep 0.5.2, original licenses included.
This is a maintained-parent compatibility backport, not a fork of an unmaintained D-Bus codec. Vnox updates dependencies/imports to maintained zbus 6, which merged zvariant and zbus_names. The original package version identifies its API baseline; no version is spoofed to suppress RustSec.
The Slint Winit patch additionally uses Winit's supported crossfont CSD backend to avoid the unmaintained ttf-parser chain while retaining Wayland client-side title decorations.
Remove this patch once upstream publishes the equivalent migration. Changes must be tested with full client build, native rendering, accessibility/portal interfaces and RustSec audit.

29
patches/zbus-lockstep/src/error.rs vendored Normal file
View file

@ -0,0 +1,29 @@
#[non_exhaustive]
#[derive(Debug)]
pub enum LockstepError {
ArgumentNotFound(String),
InterfaceNotFound(String),
MemberNotFound(String),
PropertyNotFound(String),
}
impl std::error::Error for LockstepError {}
impl std::fmt::Display for LockstepError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LockstepError::ArgumentNotFound(name) => {
write!(f, "Argument \"{name}\" not found.")
}
LockstepError::InterfaceNotFound(name) => {
write!(f, "Interface \"{name}\" not found.")
}
LockstepError::MemberNotFound(name) => {
write!(f, "Member \"{name}\" not found.")
}
LockstepError::PropertyNotFound(name) => {
write!(f, "Property \"{name}\" not found.")
}
}
}
}

410
patches/zbus-lockstep/src/lib.rs vendored Normal file
View file

@ -0,0 +1,410 @@
//! # zbus-lockstep
//!
//! Is a collection of helpers for retrieving `DBus` type signatures from XML descriptions.
//! Useful for comparing these with your types' signatures to ensure that they are compatible.
//!
//! It offers functions that retrieve the signature of a method's argument type, of a method's
//! return type, pf a signal's body type or of a property's type from `DBus` XML.
//!
//! These functions require that you provide the file path to the XML file, the interface name,
//! and the interface member wherein the signature resides.
//!
//! Corresponding to each of these functions, macros are provided which do not
//! require you to exactly point out where the signature is found. These will just search
//! by interface member name.
//!
//! The macros assume that the file path to the XML files is either:
//!
//! - `xml` or `XML`, the default path for `DBus` XML files - or is set by the
//! - `LOCKSTEP_XML_PATH`, the env variable that overrides the default.
#![doc(html_root_url = "https://docs.rs/zbus-lockstep/0.5.2")]
#![allow(clippy::missing_errors_doc)]
mod error;
mod macros;
use std::{io::Read, str::FromStr};
pub use error::LockstepError;
pub use macros::resolve_xml_path;
pub use zbus_xml::{
self,
ArgDirection::{In, Out},
Node,
};
use zbus::wire::Signature;
use LockstepError::{ArgumentNotFound, InterfaceNotFound, MemberNotFound, PropertyNotFound};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub enum MsgType {
Method,
Signal,
Property,
}
/// Retrieve a signal's body type signature from `DBus` XML.
///
/// If you provide an argument name, then the signature of that argument is returned.
/// If you do not provide an argument name, then the signature of all arguments is returned.
///
/// # Examples
///
/// ```rust
/// # use std::fs::File;
/// # use std::io::{Seek, SeekFrom, Write};
/// # use tempfile::tempfile;
/// use zbus::wire::{Signature, Type, OwnedObjectPath};
/// use zbus_lockstep::get_signal_body_type;
///
/// let xml = r#"<?xml version="1.0" encoding="UTF-8"?>
/// <node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
/// <interface name="org.freedesktop.bolt1.Manager">
/// <signal name="DeviceAdded">
/// <arg name="device" type="o"/>
/// </signal>
/// </interface>
/// </node>
/// "#;
///
/// let mut xml_file: File = tempfile().unwrap();
/// xml_file.write_all(xml.as_bytes()).unwrap();
/// xml_file.seek(SeekFrom::Start(0)).unwrap();
///
/// #[derive(Debug, PartialEq, Type)]
/// #[zvariant(signature = "o")]
/// struct DeviceEvent {
/// device: OwnedObjectPath,
/// }
///
/// let interface_name = "org.freedesktop.bolt1.Manager";
/// let member_name = "DeviceAdded";
///
/// let signature = get_signal_body_type(xml_file, interface_name, member_name, None).unwrap();
///
/// assert_eq!(&signature, DeviceEvent::SIGNATURE);
/// ```
pub fn get_signal_body_type(
mut xml: impl Read,
interface_name: &str,
member_name: &str,
arg: Option<&str>,
) -> Result<Signature> {
let node = Node::from_reader(&mut xml)?;
let interfaces = node.interfaces();
let interface = interfaces
.iter()
.find(|iface| iface.name() == interface_name)
.ok_or(InterfaceNotFound(interface_name.to_owned()))?;
let mut signals = interface.signals();
let signal = signals
.find(|signal| signal.name() == member_name)
.ok_or(MemberNotFound(member_name.to_owned()))?;
let signature = {
if let Some(arg_name) = arg {
let args = signal.args();
let arg = args
.iter()
.find(|arg| arg.name() == Some(arg_name))
.ok_or(ArgumentNotFound(arg_name.to_owned()))?;
arg.ty().to_string()
} else {
signal
.args()
.iter()
.map(|arg| arg.ty().to_string())
.collect::<String>()
}
};
Ok(Signature::from_str(&signature).map_err(|_| "Invalid signature")?)
}
/// Retrieve the signature of a property's type from XML.
///
/// # Examples
///
/// ```rust
/// use std::fs::File;
/// use std::io::{Seek, SeekFrom, Write};
/// use tempfile::tempfile;
/// use zbus::wire::Type;
/// use zbus_lockstep::get_property_type;
///
/// #[derive(Debug, PartialEq, Type)]
/// struct InUse(bool);
///
/// let xml = String::from(r#"
/// <node>
/// <interface name="org.freedesktop.GeoClue2.Manager">
/// <property type="b" name="InUse" access="read"/>
/// </interface>
/// </node>
/// "#);
///
/// let mut xml_file: File = tempfile().unwrap();
/// xml_file.write_all(xml.as_bytes()).unwrap();
/// xml_file.seek(SeekFrom::Start(0)).unwrap();
///
/// let interface_name = "org.freedesktop.GeoClue2.Manager";
/// let property_name = "InUse";
///
/// let signature = get_property_type(xml_file, interface_name, property_name).unwrap();
/// assert_eq!(signature, *InUse::SIGNATURE);
/// ```
pub fn get_property_type(
mut xml: impl Read,
interface_name: &str,
property_name: &str,
) -> Result<Signature> {
let node = Node::from_reader(&mut xml)?;
let interfaces = node.interfaces();
let interface = interfaces
.iter()
.find(|iface| iface.name() == interface_name)
.ok_or(InterfaceNotFound(interface_name.to_string()))?;
let mut properties = interface.properties();
let property = properties
.find(|property| property.name() == property_name)
.ok_or(PropertyNotFound(property_name.to_owned()))?;
let signature = property.ty().to_string();
Ok(Signature::from_str(&signature).map_err(|_| "Invalid signature")?)
}
/// Retrieve the signature of a method's return type from XML.
///
/// If you provide an argument name, then the signature of that argument is returned.
/// If you do not provide an argument name, then the signature of all arguments is returned.
///
///
/// # Examples
///
/// ```rust
/// use std::fs::File;
/// use std::io::{Seek, SeekFrom, Write};
/// use tempfile::tempfile;
/// use zbus::wire::Type;
/// use zbus_lockstep::get_method_return_type;
///
/// #[derive(Debug, PartialEq, Type)]
/// #[repr(u32)]
/// enum Role {
/// Invalid,
/// TitleBar,
/// MenuBar,
/// ScrollBar,
/// }
///
/// let xml = String::from(r#"
/// <node>
/// <interface name="org.a11y.atspi.Accessible">
/// <method name="GetRole">
/// <arg name="role" type="u" direction="out"/>
/// </method>
/// </interface>
/// </node>
/// "#);
///
/// let mut xml_file: File = tempfile().unwrap();
/// xml_file.write_all(xml.as_bytes()).unwrap();
/// xml_file.seek(SeekFrom::Start(0)).unwrap();
///
/// let interface_name = "org.a11y.atspi.Accessible";
/// let member_name = "GetRole";
///
/// let signature = get_method_return_type(xml_file, interface_name, member_name, None).unwrap();
/// assert_eq!(signature, *Role::SIGNATURE);
/// ```
pub fn get_method_return_type(
mut xml: impl Read,
interface_name: &str,
member_name: &str,
arg_name: Option<&str>,
) -> Result<Signature> {
let node = Node::from_reader(&mut xml)?;
let interfaces = node.interfaces();
let interface = interfaces
.iter()
.find(|iface| iface.name() == interface_name)
.ok_or(InterfaceNotFound(interface_name.to_string()))?;
let mut methods = interface.methods();
let method = methods
.find(|method| method.name() == member_name)
.ok_or(MemberNotFound(member_name.to_string()))?;
let args = method.args();
let signature = {
if let Some(known_arg_name) = arg_name {
args.iter()
.find(|arg| arg.name() == Some(known_arg_name))
.ok_or(ArgumentNotFound(known_arg_name.to_string()))?
.ty()
.to_string()
} else {
args.iter()
.filter(|arg| arg.direction() == Some(Out))
.map(|arg| arg.ty().to_string())
.collect::<String>()
}
};
Ok(Signature::from_str(&signature).map_err(|_| "Invalid signature")?)
}
/// Retrieve the signature of a method's argument type from XML.
///
/// Useful when one or more arguments, used to call a method, outline a useful type.
///
/// If you provide an argument name, then the signature of that argument is returned.
/// If you do not provide an argument name, then the signature of all arguments to the call is
/// returned.
///
/// # Examples
///
/// ```rust
/// use std::fs::File;
/// use std::collections::HashMap;
/// use std::io::{Seek, SeekFrom, Write};
/// use tempfile::tempfile;
/// use zbus::wire::{Type, Variant as Value};
/// use zbus_lockstep::get_method_args_type;
///
/// let xml = r#"<?xml version="1.0" encoding="UTF-8"?>
/// <node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
/// <interface name="org.freedesktop.Notifications">
/// <method name="Notify">
/// <arg type="s" name="app_name" direction="in"/>
/// <arg type="u" name="replaces_id" direction="in"/>
/// <arg type="s" name="app_icon" direction="in"/>
/// <arg type="s" name="summary" direction="in"/>
/// <arg type="s" name="body" direction="in"/>
/// <arg type="as" name="actions" direction="in"/>
/// <arg type="a{sv}" name="hints" direction="in"/>
/// <arg type="i" name="expire_timeout" direction="in"/>
/// <arg type="u" name="id" direction="out"/>
/// </method>
/// </interface>
/// </node>
/// "#;
///
/// #[derive(Debug, PartialEq, Type)]
/// struct Notification<'a> {
/// app_name: String,
/// replaces_id: u32,
/// app_icon: String,
/// summary: String,
/// body: String,
/// actions: Vec<String>,
/// hints: HashMap<String, Value<'a>>,
/// expire_timeout: i32,
/// }
///
/// let mut xml_file = tempfile().unwrap();
/// xml_file.write_all(xml.as_bytes()).unwrap();
/// xml_file.seek(SeekFrom::Start(0)).unwrap();
///
/// let interface_name = "org.freedesktop.Notifications";
/// let member_name = "Notify";
///
/// let signature = get_method_args_type(xml_file, interface_name, member_name, None).unwrap();
/// assert_eq!(&signature, Notification::SIGNATURE);
/// ```
pub fn get_method_args_type(
mut xml: impl Read,
interface_name: &str,
member_name: &str,
arg_name: Option<&str>,
) -> Result<Signature> {
let node = Node::from_reader(&mut xml)?;
let interfaces = node.interfaces();
let interface = interfaces
.iter()
.find(|iface| iface.name() == interface_name)
.ok_or(InterfaceNotFound(interface_name.to_owned()))?;
let mut methods = interface.methods();
let method = methods
.find(|method| method.name() == member_name)
.ok_or(member_name.to_owned())?;
let args = method.args();
let signature = if let Some(known_arg_name) = arg_name {
args.iter()
.find(|arg| arg.name() == Some(known_arg_name))
.ok_or(ArgumentNotFound(known_arg_name.to_string()))?
.ty()
.to_string()
} else {
args.iter()
.filter(|arg| arg.direction() == Some(In))
.map(|arg| arg.ty().to_string())
.collect::<String>()
};
Ok(Signature::from_str(&signature).map_err(|_| "Invalid signature")?)
}
#[cfg(test)]
mod test {
use std::io::{Seek, SeekFrom, Write};
use tempfile::tempfile;
use zbus::wire::{OwnedObjectPath, Type};
use crate::get_signal_body_type;
#[test]
fn test_get_signature_of_cache_add_accessible() {
#[derive(Debug, PartialEq, Type)]
struct Accessible {
name: String,
path: OwnedObjectPath,
}
#[derive(Debug, PartialEq, Type)]
struct CacheItem {
obj: Accessible,
application: Accessible,
parent: Accessible,
index_in_parent: i32,
child_count: i32,
interfaces: Vec<String>,
name: String,
role: u32,
description: String,
state_set: Vec<u32>,
}
let xml = r#"<?xml version="1.0" encoding="UTF-8"?>
<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<interface name="org.a11y.atspi.Cache">
<signal name="AddAccessible">
<arg name="nodeAdded" type="((so)(so)(so)iiassusau)"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QSpiAccessibleCacheItem"/>
</signal>
</interface>
</node>
"#;
let mut xml_file = tempfile().unwrap();
xml_file.write_all(xml.as_bytes()).unwrap();
xml_file.seek(SeekFrom::Start(0)).unwrap();
let interface_name = "org.a11y.atspi.Cache";
let member_name = "AddAccessible";
let signature = get_signal_body_type(xml_file, interface_name, member_name, None).unwrap();
assert_eq!(signature, *CacheItem::SIGNATURE);
}
}

886
patches/zbus-lockstep/src/macros.rs vendored Normal file
View file

@ -0,0 +1,886 @@
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]
use std::{fs, path::PathBuf, str::FromStr};
use crate::Result;
/// Resolve XML path from either:
///
/// - provided argument,
/// - default location (`xml/`, `XML/`, `../xml` or `../XML`) or
/// - env_variable (`LOCKSTEP_XML_PATH`)
///
/// If no XML path is provided, it tries to find the default XML path.
/// If the environment variable is set, it overrides the default, or
/// argument path.
///
/// # Example
///
/// ```rust
/// # use zbus_lockstep::resolve_xml_path;
/// # use std::path::PathBuf;
/// # fn main() {
/// // path to XML files
/// std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
///
/// let xml_path = resolve_xml_path(None).unwrap();
/// assert_eq!(xml_path, PathBuf::from("../xml").canonicalize().unwrap());
/// # }
/// ```
/// # Panics
///
/// Panics if no XML path is provided and the default XML path is not found.
pub fn resolve_xml_path(xml: Option<&str>) -> Result<PathBuf> {
let mut xml = xml;
let current_dir: PathBuf = PathBuf::from(
std::env::var("CARGO_MANIFEST_DIR")
.expect("the CARGO_MANIFEST_DIR environment variable should be set"),
);
// We want to know the name of the crate we are expanded in.
let crate_name = std::env::var("CARGO_PKG_NAME").unwrap_or_else(|_| String::from("unknown"));
let current_dir_lower_case = current_dir.join("xml");
let current_dir_upper_case = current_dir.join("XML");
let parent_dir_lower_case = current_dir.join("../xml");
let parent_dir_upper_case = current_dir.join("../XML");
let crate_dir_lower_case = current_dir.join(&crate_name).join("xml");
let crate_dir_upper_case = current_dir.join(&crate_name).join("XML");
// If no XML path is provided, try to find the default XML path.
if xml.is_none() {
if current_dir_lower_case.exists() {
xml = Some(
current_dir_lower_case
.to_str()
.expect("current_dir_lower_case is valid UTF-8"),
);
}
if current_dir_upper_case.exists() {
xml = Some(
current_dir_upper_case
.to_str()
.expect("current_dir_upper_case is valid UTF-8"),
);
}
if parent_dir_lower_case.exists() {
xml = Some(
parent_dir_lower_case
.to_str()
.expect("parent_dir_lower_case is valid UTF-8"),
);
}
if parent_dir_upper_case.exists() {
xml = Some(
parent_dir_upper_case
.to_str()
.expect("parent_dir_upper_case is valid UTF-8"),
);
}
if crate_dir_lower_case.exists() {
xml = Some(
crate_dir_lower_case
.to_str()
.expect("crate_dir_lower_case is valid UTF-8"),
);
}
if crate_dir_upper_case.exists() {
xml = Some(
crate_dir_upper_case
.to_str()
.expect("crate_dir_upper_case is valid UTF-8"),
);
}
}
let env_xml_path = std::env::var("LOCKSTEP_XML_PATH");
if env_xml_path.is_ok() {
// Override the default, or argument path if the environment variable is set.
xml = env_xml_path.as_ref().map(|s| s.as_str()).ok();
}
// If no XML path is provided and the default XML path is not found, panic.
if xml.is_none() {
panic!(
"No XML path provided and default XML path not found. Current dir: \"{}\" ",
current_dir.to_str().expect("current_dir is valid UTF-8")
);
}
// Convert, canonicalize and return the XML path.
let xml = PathBuf::from_str(xml.unwrap())?;
Ok(xml.canonicalize()?)
}
/// A generic helper to find the file path and interface name of a member.
#[doc(hidden)]
#[macro_export]
macro_rules! find_definition_in_dbus_xml {
($xml_path_buf:expr, $member:expr, $iface:expr, $msg_type:expr) => {{
use $crate::MsgType;
let xml_path_buf: std::path::PathBuf = $xml_path_buf;
let member: &str = $member;
let iface: Option<String> = $iface;
let msg_type: MsgType = $msg_type;
let mut xml_file_path = None;
let mut interface_name = None;
let read_dir = std::fs::read_dir(&xml_path_buf).expect("Failed to read XML directory");
// Walk the XML files in the directory.
for entry in read_dir {
let entry = entry.expect("Failed to read entry");
// Skip directories and non-XML files.
if entry.path().is_dir() || entry.path().extension() != Some(std::ffi::OsStr::new("xml")) {
continue;
}
let entry_path = entry.path().clone();
let file = std::fs::File::open(entry.path()).expect("Failed to open file");
let node = $crate::zbus_xml::Node::from_reader(file).expect("Failed to parse XML file");
for interface in node.interfaces() {
// If called with an `iface` arg, skip he interfaces that do not match.
if iface.is_some() && interface.name().as_str() != iface.clone().unwrap() {
continue;
}
match msg_type {
MsgType::Method => {
for dbus_item in interface.methods() {
if dbus_item.name() == member {
if interface_name.is_some() {
panic!(
"Multiple interfaces offer the same {:?} member: {}, please specify the interface name.",
msg_type, member
);
}
interface_name = Some(interface.name().to_string());
xml_file_path = Some(entry_path.clone());
}
}
}
MsgType::Signal => {
for dbus_item in interface.signals() {
if dbus_item.name() == member {
if interface_name.is_some() {
panic!(
"Multiple interfaces offer the same {:?} member: {}, please specify the interface name.",
msg_type, member
);
}
interface_name = Some(interface.name().to_string());
xml_file_path = Some(entry_path.clone());
}
}
}
MsgType::Property => {
for dbus_item in interface.properties() {
if dbus_item.name() == member {
if interface_name.is_some() {
panic!(
"Multiple interfaces offer the same {:?} member: {}, please specify the interface name.",
msg_type, member
);
}
interface_name = Some(interface.name().to_string());
xml_file_path = Some(entry_path.clone());
}
}
}
};
}
}
// If the interface member was not found, return an error.
if xml_file_path.is_none() {
panic!("Member not found in XML files.");
}
(xml_file_path.unwrap(), interface_name.unwrap())
}};
}
/// Retrieve the signature of a method's return type.
///
/// This macro will take a method member name and return the signature of the
/// return type.
///
/// Essentially a wrapper around [`zbus_lockstep::get_method_return_type`],
/// but this macro tries to do its job with less arguments.
///
/// It will search in the XML specification of the method for the return type
/// and return the signature of that type.
///
/// If multiple interfaces offer the same method, you will need to specify the
/// interface name as well.
///
/// This macro can be called with or without the interface name.
///
/// # Examples
///
/// Basic usage:
///
/// ```rust
/// use std::str::FromStr;
/// use zbus_lockstep::method_return_signature;
/// use zbus::wire::Signature;
///
/// std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
///
/// let sig = method_return_signature!("RequestName");
/// assert_eq!(&sig, &Signature::from_str("u").expect("Valid signature pattern"));
/// ```
/// The macro supports colling arguments with identifiers as well as without.
/// The macro may also be called with an interface name or interface and argument name:
///
/// ```rust
/// # use zbus_lockstep::{method_return_signature};
/// # std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
/// let _sig = method_return_signature!("RequestName", "org.example.Node", "grape");
///
/// // or alternatively
///
/// let _sig = method_return_signature!(member: "RequestName", interface: "org.example.Node", argument: "grape");
/// ```
#[macro_export]
macro_rules! method_return_signature {
($member:expr) => {{
use $crate::MsgType;
let member = $member;
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, None, MsgType::Method);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_method_return_type(file, &interface_name, member, None)
.expect("Failed to get method arguments type signature")
}};
(member: $member:expr) => {
$crate::method_return_signature!($member)
};
($member:expr, $interface:expr) => {{
let member = $member;
use $crate::MsgType;
let interface = Some($interface.to_string());
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, interface, MsgType::Method);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_method_return_type(file, &interface_name, member, None)
.expect("Failed to get method arguments type signature")
}};
(member: $member:expr, interface: $interface:expr) => {
$crate::method_return_signature!($member, $interface)
};
($member:expr, $interface:expr, $argument:expr) => {{
let member = $member;
use $crate::MsgType;
let interface = Some($interface.to_string());
let argument = Some($argument);
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, interface, MsgType::Method);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_method_return_type(file, &interface_name, member, argument)
.expect("Failed to get method argument(s) type signature")
}};
(member: $member:expr, interface: $interface:expr, argument: $argument:expr) => {
$crate::method_return_signature!($member, $interface, $argument)
};
}
/// Retrieve the signature of a method's arguments.
///
/// Essentially a wrapper around [`zbus_lockstep::get_method_args_type`],
/// but this macro tries to do its job with less arguments.
///
/// This macro will take a method member name and return the signature of the
/// arguments type.
///
/// It will search in the XML specification of the method for the arguments type
/// and return the signature of that type.
///
/// If multiple interfaces offer the same member, you will need to
/// specify the interface name as well.
///
/// This macro can be called with or without the interface name.
///
/// # Examples
///
/// ```rust
/// use std::str::FromStr;
/// use zbus_lockstep::method_args_signature;
/// use zbus::wire::Signature;
///
/// std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
///
/// let sig = method_args_signature!("RequestName");
/// assert_eq!(&sig, &Signature::from_str("(su)").expect("Valid signature pattern"));
/// ```
/// The macro supports colling arguments with identifiers as well as without.
/// The macro may also be called with an interface name or interface and argument name:
///
/// ```rust
/// # use zbus_lockstep::{method_args_signature};
/// # std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
/// let _sig = method_args_signature!("RequestName", "org.example.Node", "apple");
///
/// // or alternatively
///
/// let _sig = method_args_signature!(member: "RequestName", interface: "org.example.Node", argument: "apple");
/// ```
#[macro_export]
macro_rules! method_args_signature {
($member:expr) => {{
use $crate::MsgType;
let member = $member;
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, None, MsgType::Method);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_method_args_type(file, &interface_name, member, None)
.expect("Failed to get method arguments type signature")
}};
(member: $member:expr) => {
$crate::method_args_signature!($member)
};
($member:expr, $interface:expr) => {{
use $crate::MsgType;
let member = $member;
let interface = Some($interface.to_string());
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, interface, MsgType::Method);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_method_args_type(file, &interface_name, member, None)
.expect("Failed to get method arguments type signature")
}};
(member: $member:expr, interface: $interface:expr) => {
$crate::method_args_signature!($member, $interface)
};
($member:expr, $interface:expr, $argument:expr) => {{
use $crate::MsgType;
let member = $member;
let interface = Some($interface.to_string());
let argument = Some($argument);
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, interface, MsgType::Method);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_method_args_type(file, &interface_name, member, argument)
.expect("Failed to get method argument(s) type signature")
}};
(member: $member:expr, interface: $interface:expr, argument: $argument:expr) => {
$crate::method_args_signature!($member, $interface, $argument)
};
}
/// Retrieve the signature of a signal's body type.
///
/// Essentially a wrapper around [`zbus_lockstep::get_signal_body_type`],
/// but this macro tries to find it with less arguments.
///
/// This macro will take a signal member name and return the signature of the
/// signal body type.
///
/// If multiple interfaces offer the same member, you will need to
/// specify the interface name as well.
///
/// This macro can be called with or without the interface name.
///
/// # Examples
///
/// ```rust
/// use std::str::FromStr;
/// use zbus_lockstep::signal_body_type_signature;
/// use zbus::wire::Signature;
///
/// std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
///
/// let sig = signal_body_type_signature!("AddNode");
/// assert_eq!(&sig, &Signature::from_str("(so)").expect("Valid signature pattern"));
/// ```
/// The macro supports colling arguments with identifiers as well as without.
/// The macro may also be called with an interface name or interface and argument name:
///
/// ```rust
/// # use zbus_lockstep::{signal_body_type_signature};
/// # std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
/// let _sig = signal_body_type_signature!("Alert", "org.example.Node", "color");
///
/// // or alternatively
///
/// let _sig = signal_body_type_signature!(member: "Alert", interface: "org.example.Node", argument: "color");
/// ```
#[macro_export]
macro_rules! signal_body_type_signature {
($member:expr) => {{
use $crate::MsgType;
let member = $member;
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, None, MsgType::Signal);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_signal_body_type(file, &interface_name, member, None)
.expect("Failed to get method arguments type signature")
}};
(member: $member:expr) => {
$crate::signal_body_type_signature!($member)
};
($member:expr, $interface:expr) => {{
use $crate::MsgType;
let member = $member;
let interface = Some($interface.to_string());
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, interface, MsgType::Signal);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_signal_body_type(file, &interface_name, member, None)
.expect("Failed to get method arguments type signature")
}};
(member: $member:expr, interface: $interface:expr) => {
$crate::signal_body_type_signature!($member, $interface)
};
($member:expr, $interface:expr, $argument:expr) => {{
use $crate::MsgType;
let member = $member;
let interface = Some($interface.to_string());
let argument = Some($argument);
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, interface, MsgType::Signal);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_signal_body_type(file, &interface_name, member, argument)
.expect("Failed to get method argument(s) type signature")
}};
(member: $member:expr, interface: $interface:expr, argument: $argument:expr) => {
$crate::signal_body_type_signature!($member, $interface, $argument)
};
}
/// Retrieve the signature of a property's type.
///
/// Essentially a wrapper around [`zbus_lockstep::get_property_type`],
/// but this macro tries to do with less arguments.
///
/// This macro will take a property name and return the signature of the
/// property's type.
///
/// If multiple interfaces offer the same member, you will need to
/// specify the interface name as well.
///
/// This macro can be called with or without the interface name.
///
/// # Examples
///
/// ```rust
/// use std::str::FromStr;
/// use zbus_lockstep::property_type_signature;
/// use zbus::wire::Signature;
///
/// std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
///
/// let sig = property_type_signature!("Features");
/// assert_eq!(&sig, &Signature::from_str("as").expect("Valid signature pattern"));
/// ```
/// The member name and/or interface name can be used tp identify the arguments:
///
/// ```rust
/// # use zbus_lockstep::{property_type_signature};
/// # std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
/// let _sig = property_type_signature!(member: "Features", interface: "org.example.Node");
/// ```
#[macro_export]
macro_rules! property_type_signature {
($member:expr) => {{
use $crate::MsgType;
let member = $member;
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, None, MsgType::Property);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_property_type(file, &interface_name, member)
.expect("Failed to get property type signature")
}};
(member: $member:expr) => {
$crate::property_type_signature!($member)
};
($member:expr, $interface:expr) => {{
use $crate::MsgType;
let member = $member;
let interface = Some($interface.to_string());
// Looking for default path or path specified by environment variable.
let current_dir: std::path::PathBuf = std::env::current_dir().unwrap();
let xml_path = $crate::resolve_xml_path(None).expect(&format!(
"Failed to resolve XML path, current dir: {}",
current_dir.to_str().unwrap()
));
// Find the definition of the method in the XML specification.
let (file_path, interface_name) =
$crate::find_definition_in_dbus_xml!(xml_path, member, interface, MsgType::Property);
let file = std::fs::File::open(file_path).expect("Failed to open file");
$crate::get_property_type(file, &interface_name, member)
.expect("Failed to get property type signature")
}};
(member: $member:expr, interface: $interface:expr) => {
$crate::property_type_signature!($member, $interface)
};
}
#[cfg(test)]
mod test {
use std::str::FromStr;
use zbus::wire::Signature;
use crate::signal_body_type_signature;
#[test]
fn test_signal_body_signature_macro() {
// path to XML files can be set by environment variable
// std::env::set_var("LOCKSTEP_XML_PATH", "../xml");
// But `resolve_xml_path` can find the `xml` in parent by itself.
let sig = crate::signal_body_type_signature!("AddNode");
assert_eq!(
&sig,
&zbus::wire::Signature::from_str("(so)").expect("Valid signature pattern")
);
}
#[test]
fn test_signal_body_signature_macro_with_identifier() {
let sig = crate::signal_body_type_signature!(member: "AddNode");
assert_eq!(
sig,
Signature::from_str("(so)").expect("Valid signature pattern")
);
}
#[test]
fn test_signal_body_signature_macro_with_interface() {
let sig = crate::signal_body_type_signature!("AddNode", "org.example.Node");
assert_eq!(
sig,
Signature::from_str("(so)").expect("Valid signature pattern")
);
}
#[test]
fn test_signal_body_signature_macro_with_interface_and_identifiers() {
let sig =
crate::signal_body_type_signature!(member: "AddNode", interface: "org.example.Node");
assert_eq!(
sig,
Signature::from_str("(so)").expect("Valid signature pattern")
);
}
#[test]
fn test_signal_body_signature_macro_with_argument_and_interface() {
let sig = crate::signal_body_type_signature!("Alert", "org.example.Node", "volume");
assert_eq!(
sig,
Signature::from_str("d").expect("Valid signature pattern")
);
}
#[test]
fn test_signal_body_signature_macro_with_argument_and_identifiers_and_interface() {
let sig = crate::signal_body_type_signature!(
member: "Alert",
interface: "org.example.Node",
argument: "urgent"
);
assert_eq!(
sig,
Signature::from_str("b").expect("Valid signature pattern")
);
}
#[test]
fn test_method_args_signature_macro() {
let sig = crate::method_args_signature!("RequestName");
assert_eq!(
sig,
Signature::from_str("(su)").expect("Valid signature pattern")
);
}
#[test]
fn test_method_args_signature_macro_with_identifier() {
let sig = crate::method_args_signature!(member: "RequestName");
assert_eq!(
sig,
Signature::from_str("(su)").expect("Valid signature pattern")
);
}
#[test]
fn test_method_args_signature_macro_with_interface() {
let sig = crate::method_args_signature!("RequestName", "org.example.Node");
assert_eq!(
sig,
Signature::from_str("(su)").expect("Valid signature pattern")
);
}
#[test]
fn test_method_args_signature_macro_with_interface_and_identifiers() {
let sig =
crate::method_args_signature!(member: "RequestName", interface: "org.example.Node");
assert_eq!(
sig,
Signature::from_str("(su)").expect("Valid signature pattern")
);
}
#[test]
fn test_method_args_signature_macro_with_argument_and_interface() {
let sig = crate::method_args_signature!("RequestName", "org.example.Node", "apple");
assert_eq!(
sig,
Signature::from_str("s").expect("Valid signature pattern")
);
}
#[test]
fn test_method_args_signature_macro_with_argument_and_identifiers_and_interface() {
let sig = crate::method_args_signature!(
member: "RequestName",
interface: "org.example.Node",
argument: "orange"
);
assert_eq!(
sig,
Signature::from_str("u").expect("Valid signature pattern")
);
}
#[test]
fn test_method_return_signature_macro() {
let sig = crate::method_return_signature!("RequestName");
assert_eq!(
sig,
Signature::from_str("u").expect("Valid signatuee pattern")
);
}
#[test]
fn test_method_return_signature_macro_with_identifier() {
let sig = crate::method_return_signature!(member: "RequestName");
assert_eq!(
sig,
Signature::from_str("u").expect("Valid signature pattern")
);
}
#[test]
fn test_method_return_signature_macro_with_interface() {
let sig = crate::method_return_signature!("RequestName", "org.example.Node");
assert_eq!(
sig,
Signature::from_str("u").expect("Valid signature pattern")
);
}
#[test]
fn test_method_return_signature_macro_with_interface_and_identifiers() {
let sig =
crate::method_return_signature!(member: "RequestName", interface: "org.example.Node");
assert_eq!(
sig,
Signature::from_str("u").expect("Vlaid signature pattern")
);
}
#[test]
fn test_method_return_signature_macro_with_argument_and_interface() {
let sig = crate::method_return_signature!("RequestName", "org.example.Node", "grape");
assert_eq!(
sig,
Signature::from_str("u").expect("Vlaid signature pattern")
);
}
#[test]
fn test_method_return_signature_macro_with_argument_and_identifiers_and_interface() {
let sig = crate::method_return_signature!(
member: "RequestName",
interface: "org.example.Node",
argument: "grape"
);
assert_eq!(
sig,
Signature::from_str("u").expect("Vlaid signature pattern")
);
}
#[test]
fn test_property_type_signature_macro() {
let sig = crate::property_type_signature!("Features");
assert_eq!(
sig,
Signature::from_str("as").expect("Vlaid signature pattern")
);
}
#[test]
fn test_property_type_signature_macro_with_identifier() {
let sig = crate::property_type_signature!(member: "Features");
assert_eq!(
sig,
Signature::from_str("as").expect("Vlaid signature pattern")
);
}
#[test]
fn test_property_type_signature_macro_with_interface() {
let sig = crate::property_type_signature!("Features", "org.example.Node");
assert_eq!(
sig,
Signature::from_str("as").expect("Vlaid signature pattern")
);
}
#[test]
fn test_property_type_signature_macro_with_interface_and_identifiers() {
let sig =
crate::property_type_signature!(member: "Features", interface: "org.example.Node");
assert_eq!(
sig,
Signature::from_str("as").expect("Vlaid signature pattern")
);
}
}