diff --git a/zbus/src/address/mod.rs b/zbus/src/address/mod.rs index 27175a910..5e389edb2 100644 --- a/zbus/src/address/mod.rs +++ b/zbus/src/address/mod.rs @@ -191,7 +191,7 @@ mod tests { #[cfg(windows)] use crate::address::transport::{Autolaunch, AutolaunchScope}; use crate::{ - address::transport::{Unix, UnixPath}, + address::transport::{Unix, UnixSocket}, Error, }; use std::str::FromStr; @@ -240,17 +240,17 @@ mod tests { } assert_eq!( Address::from_str("unix:path=/tmp/dbus-foo").unwrap(), - Transport::Unix(Unix::new(UnixPath::File("/tmp/dbus-foo".into()))).into(), + Transport::Unix(Unix::new(UnixSocket::File("/tmp/dbus-foo".into()))).into(), ); #[cfg(target_os = "linux")] assert_eq!( Address::from_str("unix:abstract=/tmp/dbus-foo").unwrap(), - Transport::Unix(Unix::new(UnixPath::Abstract("/tmp/dbus-foo".into()))).into(), + Transport::Unix(Unix::new(UnixSocket::Abstract("/tmp/dbus-foo".into()))).into(), ); let guid = crate::Guid::generate(); assert_eq!( Address::from_str(&format!("unix:path=/tmp/dbus-foo,guid={guid}")).unwrap(), - Address::from(Transport::Unix(Unix::new(UnixPath::File( + Address::from(Transport::Unix(Unix::new(UnixSocket::File( "/tmp/dbus-foo".into() )))) .set_guid(guid.clone()) @@ -320,32 +320,32 @@ mod tests { ); assert_eq!( Address::from_str("unix:dir=/some/dir").unwrap(), - Transport::Unix(Unix::new(UnixPath::Dir("/some/dir".into()))).into(), + Transport::Unix(Unix::new(UnixSocket::Dir("/some/dir".into()))).into(), ); assert_eq!( Address::from_str("unix:tmpdir=/some/dir").unwrap(), - Transport::Unix(Unix::new(UnixPath::TmpDir("/some/dir".into()))).into(), + Transport::Unix(Unix::new(UnixSocket::TmpDir("/some/dir".into()))).into(), ); } #[test] fn stringify_dbus_addresses() { assert_eq!( - Address::from(Transport::Unix(Unix::new(UnixPath::File( + Address::from(Transport::Unix(Unix::new(UnixSocket::File( "/tmp/dbus-foo".into() )))) .to_string(), "unix:path=/tmp/dbus-foo", ); assert_eq!( - Address::from(Transport::Unix(Unix::new(UnixPath::Dir( + Address::from(Transport::Unix(Unix::new(UnixSocket::Dir( "/tmp/dbus-foo".into() )))) .to_string(), "unix:dir=/tmp/dbus-foo", ); assert_eq!( - Address::from(Transport::Unix(Unix::new(UnixPath::TmpDir( + Address::from(Transport::Unix(Unix::new(UnixSocket::TmpDir( "/tmp/dbus-foo".into() )))) .to_string(), @@ -354,7 +354,7 @@ mod tests { // FIXME: figure out how to handle abstract on Windows #[cfg(target_os = "linux")] assert_eq!( - Address::from(Transport::Unix(Unix::new(UnixPath::Abstract( + Address::from(Transport::Unix(Unix::new(UnixSocket::Abstract( "/tmp/dbus-foo".into() )))) .to_string(), diff --git a/zbus/src/address/transport/launchd.rs b/zbus/src/address/transport/launchd.rs index f87b1c4cb..8887faa09 100644 --- a/zbus/src/address/transport/launchd.rs +++ b/zbus/src/address/transport/launchd.rs @@ -1,4 +1,4 @@ -use super::{Transport, Unix, UnixPath}; +use super::{Transport, Unix, UnixSocket}; use crate::{process::run, Result}; use std::collections::HashMap; @@ -39,7 +39,7 @@ impl Launchd { crate::Error::Address(format!("Unable to parse launchctl output as UTF-8: {}", e)) })?; - Ok(Transport::Unix(Unix::new(UnixPath::File( + Ok(Transport::Unix(Unix::new(UnixSocket::File( addr.trim().into(), )))) } diff --git a/zbus/src/address/transport/mod.rs b/zbus/src/address/transport/mod.rs index 4260f9bd4..29b326f6e 100644 --- a/zbus/src/address/transport/mod.rs +++ b/zbus/src/address/transport/mod.rs @@ -27,7 +27,7 @@ use std::{ }; mod unix; -pub use unix::{Unix, UnixPath}; +pub use unix::{Unix, UnixSocket}; mod tcp; pub use tcp::{Tcp, TcpTransportFamily}; #[cfg(windows)] @@ -88,14 +88,14 @@ impl Transport { // https://github.com/haraldh/rust_uds_windows/issues/14 let addr = match unix.take_path() { #[cfg(unix)] - UnixPath::File(path) => SocketAddr::from_pathname(path)?, + UnixSocket::File(path) => SocketAddr::from_pathname(path)?, #[cfg(windows)] - UnixPath::File(path) => path, + UnixSocket::File(path) => path, #[cfg(target_os = "linux")] - UnixPath::Abstract(name) => { + UnixSocket::Abstract(name) => { SocketAddr::from_abstract_name(name.as_encoded_bytes())? } - UnixPath::Dir(_) | UnixPath::TmpDir(_) => { + UnixSocket::Dir(_) | UnixSocket::TmpDir(_) => { // you can't connect to a unix:dir return Err(Error::Unsupported); } diff --git a/zbus/src/address/transport/unix.rs b/zbus/src/address/transport/unix.rs index 740a55ced..9ce7de0f7 100644 --- a/zbus/src/address/transport/unix.rs +++ b/zbus/src/address/transport/unix.rs @@ -1,7 +1,10 @@ +#[cfg(target_os = "linux")] +use std::ffi::OsString; use std::{ collections::HashMap, - ffi::{OsStr, OsString}, + ffi::OsStr, fmt::{Display, Formatter}, + path::PathBuf, }; #[cfg(unix)] @@ -10,22 +13,22 @@ use super::encode_percents; /// A Unix domain socket transport in a D-Bus address. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Unix { - path: UnixPath, + path: UnixSocket, } impl Unix { /// Create a new Unix transport with the given path. - pub fn new(path: UnixPath) -> Self { + pub fn new(path: UnixSocket) -> Self { Self { path } } /// The path. - pub fn path(&self) -> &UnixPath { + pub fn path(&self) -> &UnixSocket { &self.path } /// Take the path, consuming `self`. - pub fn take_path(self) -> UnixPath { + pub fn take_path(self) -> UnixSocket { self.path } @@ -36,17 +39,17 @@ impl Unix { let dir = opts.get("dir"); let tmpdir = opts.get("tmpdir"); let path = match (path, abs, dir, tmpdir) { - (Some(p), None, None, None) => UnixPath::File(OsString::from(p)), + (Some(p), None, None, None) => UnixSocket::File(PathBuf::from(p)), #[cfg(target_os = "linux")] - (None, Some(p), None, None) => UnixPath::Abstract(OsString::from(p)), + (None, Some(p), None, None) => UnixSocket::Abstract(OsString::from(p)), #[cfg(not(target_os = "linux"))] (None, Some(_), None, None) => { return Err(crate::Error::Address( "abstract sockets currently Linux-only".to_owned(), )); } - (None, None, Some(p), None) => UnixPath::Dir(OsString::from(p)), - (None, None, None, Some(p)) => UnixPath::TmpDir(OsString::from(p)), + (None, None, Some(p), None) => UnixSocket::Dir(PathBuf::from(p)), + (None, None, None, Some(p)) => UnixSocket::TmpDir(PathBuf::from(p)), _ => { return Err(crate::Error::Address("unix: address is invalid".to_owned())); } @@ -65,9 +68,9 @@ impl Display for Unix { /// A Unix domain socket path in a D-Bus address. #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] -pub enum UnixPath { +pub enum UnixSocket { /// A path to a unix domain socket on the filesystem. - File(OsString), + File(PathBuf), /// A abstract unix domain socket name. #[cfg(target_os = "linux")] Abstract(OsString), @@ -78,16 +81,16 @@ pub enum UnixPath { /// This address is mostly relevant to server (typically bus broker) implementations. /// /// [UNIX domain socket address]: https://dbus.freedesktop.org/doc/dbus-specification.html#transports-unix-domain-sockets-addresses - Dir(OsString), + Dir(PathBuf), /// The same as UnixDir, except that on platforms with abstract sockets, the server may attempt /// to create an abstract socket whose name starts with this directory instead of a path-based /// socket. /// /// This address is mostly relevant to server (typically bus broker) implementations. - TmpDir(OsString), + TmpDir(PathBuf), } -impl Display for UnixPath { +impl Display for UnixSocket { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt_unix_path(f: &mut Formatter<'_>, path: &OsStr) -> std::fmt::Result { #[cfg(unix)] @@ -104,22 +107,22 @@ impl Display for UnixPath { } match self { - UnixPath::File(path) => { + UnixSocket::File(path) => { f.write_str("path=")?; - fmt_unix_path(f, path)?; + fmt_unix_path(f, path.as_os_str())?; } #[cfg(target_os = "linux")] - UnixPath::Abstract(name) => { + UnixSocket::Abstract(name) => { f.write_str("abstract=")?; fmt_unix_path(f, name)?; } - UnixPath::Dir(path) => { + UnixSocket::Dir(path) => { f.write_str("dir=")?; - fmt_unix_path(f, path)?; + fmt_unix_path(f, path.as_os_str())?; } - UnixPath::TmpDir(path) => { + UnixSocket::TmpDir(path) => { f.write_str("tmpdir=")?; - fmt_unix_path(f, path)?; + fmt_unix_path(f, path.as_os_str())?; } } diff --git a/zbus/src/blocking/connection/builder.rs b/zbus/src/blocking/connection/builder.rs index 3e2ce9d6e..06144508a 100644 --- a/zbus/src/blocking/connection/builder.rs +++ b/zbus/src/blocking/connection/builder.rs @@ -15,6 +15,7 @@ use zvariant::{ObjectPath, Str}; use crate::{ address::Address, blocking::Connection, + connection::socket::BoxedSplit, names::{UniqueName, WellKnownName}, object_server::Interface, utils::block_on, @@ -68,6 +69,11 @@ impl<'a> Builder<'a> { Self(crate::connection::Builder::tcp_stream(stream)) } + /// Create a builder for connection that will use the given socket. + pub fn socket>(socket: S) -> Self { + Self(crate::connection::Builder::socket(socket)) + } + /// Specify the mechanisms to use during authentication. pub fn auth_mechanisms(self, auth_mechanisms: &[AuthMechanism]) -> Self { Self(self.0.auth_mechanisms(auth_mechanisms)) diff --git a/zbus/src/blocking/mod.rs b/zbus/src/blocking/mod.rs index 37c26550b..517c54846 100644 --- a/zbus/src/blocking/mod.rs +++ b/zbus/src/blocking/mod.rs @@ -26,27 +26,27 @@ pub use object_server::ObjectServer; pub mod proxy; pub use proxy::Proxy; -#[deprecated(note = "Use `proxy::Builder` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::Builder` instead")] #[doc(hidden)] pub use proxy::Builder as ProxyBuilder; -#[deprecated(note = "Use `proxy::OwnerChangedIterator` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::OwnerChangedIterator` instead")] #[doc(hidden)] pub use proxy::OwnerChangedIterator; -#[deprecated(note = "Use `proxy::PropertyChanged` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::PropertyChanged` instead")] #[doc(hidden)] pub use proxy::PropertyChanged; -#[deprecated(note = "Use `proxy::PropertyIterator` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::PropertyIterator` instead")] #[doc(hidden)] pub use proxy::PropertyIterator; -#[deprecated(note = "Use `proxy::SignalIterator` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::SignalIterator` instead")] #[doc(hidden)] pub use proxy::SignalIterator; -#[deprecated(note = "Use `object_server::InterfaceRef` instead")] +#[deprecated(since = "4.0.0", note = "Use `object_server::InterfaceRef` instead")] #[doc(hidden)] pub use object_server::InterfaceRef; -#[deprecated(note = "Use `connection::Builder` instead")] +#[deprecated(since = "4.0.0", note = "Use `connection::Builder` instead")] #[doc(hidden)] pub use connection::Builder; diff --git a/zbus/src/connection/builder.rs b/zbus/src/connection/builder.rs index 1ce40adce..34fe6788c 100644 --- a/zbus/src/connection/builder.rs +++ b/zbus/src/connection/builder.rs @@ -33,7 +33,7 @@ use crate::{ use super::{ handshake::{AuthMechanism, Authenticated}, - socket::{BoxedSplit, ReadHalf, Socket, Split, WriteHalf}, + socket::{BoxedSplit, ReadHalf, Split, WriteHalf}, }; const DEFAULT_MAX_QUEUED: usize = 64; @@ -160,7 +160,7 @@ impl<'a> Builder<'a> { } /// Create a builder for connection that will use the given socket. - pub fn socket(socket: S) -> Self { + pub fn socket>(socket: S) -> Self { Self::new(Target::Socket(socket.into())) } diff --git a/zbus/src/lib.rs b/zbus/src/lib.rs index e444bfd60..e1ec6cc3a 100644 --- a/zbus/src/lib.rs +++ b/zbus/src/lib.rs @@ -50,34 +50,34 @@ pub use guid::*; pub mod message; pub use message::Message; -#[deprecated(note = "Use `message::Builder` instead")] +#[deprecated(since = "4.0.0", note = "Use `message::Builder` instead")] #[doc(hidden)] pub use message::Builder as MessageBuilder; -#[deprecated(note = "Use `message::EndianSig` instead")] +#[deprecated(since = "4.0.0", note = "Use `message::EndianSig` instead")] #[doc(hidden)] pub use message::EndianSig; #[doc(hidden)] pub use message::Flags as MessageFlags; -#[deprecated(note = "Use `message::Header` instead")] +#[deprecated(since = "4.0.0", note = "Use `message::Header` instead")] #[doc(hidden)] pub use message::Header as MessageHeader; -#[deprecated(note = "Use `message::PrimaryHeader` instead")] +#[deprecated(since = "4.0.0", note = "Use `message::PrimaryHeader` instead")] #[doc(hidden)] pub use message::PrimaryHeader as MessagePrimaryHeader; -#[deprecated(note = "Use `message::Sequence` instead")] +#[deprecated(since = "4.0.0", note = "Use `message::Sequence` instead")] #[doc(hidden)] pub use message::Sequence as MessageSequence; -#[deprecated(note = "Use `message::Type` instead")] +#[deprecated(since = "4.0.0", note = "Use `message::Type` instead")] #[doc(hidden)] pub use message::Type as MessageType; -#[deprecated(note = "Use `message::NATIVE_ENDIAN_SIG` instead")] +#[deprecated(since = "4.0.0", note = "Use `message::NATIVE_ENDIAN_SIG` instead")] #[doc(hidden)] pub use message::NATIVE_ENDIAN_SIG; pub mod connection; pub use connection::{handshake::AuthMechanism, Connection}; -#[deprecated(note = "Use `connection::Builder` instead")] +#[deprecated(since = "4.0.0", note = "Use `connection::Builder` instead")] #[doc(hidden)] pub use connection::Builder as ConnectionBuilder; @@ -89,60 +89,66 @@ pub use abstractions::*; pub mod match_rule; pub use match_rule::{MatchRule, OwnedMatchRule}; -#[deprecated(note = "Use `match_rule::Builder` instead")] +#[deprecated(since = "4.0.0", note = "Use `match_rule::Builder` instead")] #[doc(hidden)] pub use match_rule::Builder as MatchRuleBuilder; -#[deprecated(note = "Use `match_rule::PathSpec` instead")] +#[deprecated(since = "4.0.0", note = "Use `match_rule::PathSpec` instead")] #[doc(hidden)] pub use match_rule::PathSpec as MatchRulePathSpec; pub mod proxy; pub use proxy::Proxy; -#[deprecated(note = "Use `proxy::Builder` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::Builder` instead")] #[doc(hidden)] pub use proxy::Builder as ProxyBuilder; -#[deprecated(note = "Use `proxy::CacheProperties` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::CacheProperties` instead")] #[doc(hidden)] pub use proxy::CacheProperties; -#[deprecated(note = "Use `proxy::MethodFlags` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::MethodFlags` instead")] #[doc(hidden)] pub use proxy::MethodFlags; -#[deprecated(note = "Use `proxy::OwnerChangedStream` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::OwnerChangedStream` instead")] #[doc(hidden)] pub use proxy::OwnerChangedStream; -#[deprecated(note = "Use `proxy::PropertyChanged` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::PropertyChanged` instead")] #[doc(hidden)] pub use proxy::PropertyChanged; -#[deprecated(note = "Use `proxy::PropertyStream` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::PropertyStream` instead")] #[doc(hidden)] pub use proxy::PropertyStream; -#[deprecated(note = "Use `proxy::ProxyDefault` instead")] +#[deprecated(since = "4.0.0", note = "Use `proxy::ProxyDefault` instead")] #[doc(hidden)] pub use proxy::ProxyDefault; pub mod object_server; pub use object_server::ObjectServer; -#[deprecated(note = "Use `object_server::DispatchResult` instead")] +#[deprecated(since = "4.0.0", note = "Use `object_server::DispatchResult` instead")] #[doc(hidden)] pub use object_server::DispatchResult; -#[deprecated(note = "Use `object_server::Interface` instead")] +#[deprecated(since = "4.0.0", note = "Use `object_server::Interface` instead")] #[doc(hidden)] pub use object_server::Interface; -#[deprecated(note = "Use `object_server::InterfaceDeref` instead")] +#[deprecated(since = "4.0.0", note = "Use `object_server::InterfaceDeref` instead")] #[doc(hidden)] pub use object_server::InterfaceDeref; -#[deprecated(note = "Use `object_server::InterfaceDerefMut` instead")] +#[deprecated( + since = "4.0.0", + note = "Use `object_server::InterfaceDerefMut` instead" +)] #[doc(hidden)] pub use object_server::InterfaceDerefMut; -#[deprecated(note = "Use `object_server::InterfaceRef` instead")] +#[deprecated(since = "4.0.0", note = "Use `object_server::InterfaceRef` instead")] #[doc(hidden)] pub use object_server::InterfaceRef; -#[deprecated(note = "Use `object_server::ResponseDispatchNotifier` instead")] +#[deprecated( + since = "4.0.0", + note = "Use `object_server::ResponseDispatchNotifier` instead" +)] #[doc(hidden)] pub use object_server::ResponseDispatchNotifier; -#[deprecated(note = "Use `object_server::SignalContext` instead")] +#[deprecated(since = "4.0.0", note = "Use `object_server::SignalContext` instead")] #[doc(hidden)] pub use object_server::SignalContext; @@ -152,7 +158,7 @@ pub use utils::*; #[macro_use] pub mod fdo; -#[deprecated(note = "Use `connection::Socket` instead")] +#[deprecated(since = "4.0.0", note = "Use `connection::Socket` instead")] #[doc(hidden)] pub use connection::Socket; diff --git a/zbus/src/message/builder.rs b/zbus/src/message/builder.rs index e7738e2c6..8fb5daa36 100644 --- a/zbus/src/message/builder.rs +++ b/zbus/src/message/builder.rs @@ -1,9 +1,9 @@ -#[cfg(unix)] -use std::os::fd::OwnedFd; use std::{ io::{Cursor, Write}, sync::Arc, }; +#[cfg(unix)] +use zvariant::OwnedFd; use enumflags2::BitFlags; use zbus_names::{BusName, ErrorName, InterfaceName, MemberName, UniqueName}; diff --git a/zbus/src/message/mod.rs b/zbus/src/message/mod.rs index 758dcf422..de2f4b21c 100644 --- a/zbus/src/message/mod.rs +++ b/zbus/src/message/mod.rs @@ -205,25 +205,37 @@ impl Message { } /// The object to send a call to, or the object a signal is emitted from. - #[deprecated(note = "Use `Message::header` with `message::Header::path` instead")] + #[deprecated( + since = "4.0.0", + note = "Use `Message::header` with `message::Header::path` instead" + )] pub fn path(&self) -> Option> { self.inner.quick_fields.path(self) } /// The interface to invoke a method call on, or that a signal is emitted from. - #[deprecated(note = "Use `Message::header` with `message::Header::interface` instead")] + #[deprecated( + since = "4.0.0", + note = "Use `Message::header` with `message::Header::interface` instead" + )] pub fn interface(&self) -> Option> { self.inner.quick_fields.interface(self) } /// The member, either the method name or signal name. - #[deprecated(note = "Use `Message::header` with `message::Header::member` instead")] + #[deprecated( + since = "4.0.0", + note = "Use `Message::header` with `message::Header::member` instead" + )] pub fn member(&self) -> Option> { self.inner.quick_fields.member(self) } /// The serial number of the message this message is a reply to. - #[deprecated(note = "Use `Message::header` with `message::Header::reply_serial` instead")] + #[deprecated( + since = "4.0.0", + note = "Use `Message::header` with `message::Header::reply_serial` instead" + )] pub fn reply_serial(&self) -> Option { self.inner.quick_fields.reply_serial() } diff --git a/zbus_macros/src/proxy.rs b/zbus_macros/src/proxy.rs index 7fe85a895..6b08e7a62 100644 --- a/zbus_macros/src/proxy.rs +++ b/zbus_macros/src/proxy.rs @@ -994,7 +994,7 @@ fn gen_proxy_signal( impl #signal_name_ident { #[doc = "Try to construct a "] #[doc = #signal_name] - #[doc = " from a [::zbus::message::Message]."] + #[doc = " from a [`zbus::Message`]."] pub fn from_message(msg: M) -> ::std::option::Option where M: ::std::convert::Into<#zbus::message::Message>, @@ -1014,6 +1014,11 @@ fn gen_proxy_signal( _ => None, } } + + #[doc = "The reference to the underlying [`zbus::Message`]."] + pub fn message(&self) -> &#zbus::message::Message { + self.0.message() + } } impl ::std::convert::From<#signal_name_ident> for #zbus::message::Message { diff --git a/zvariant/src/serialized/written.rs b/zvariant/src/serialized/written.rs index 97ccee1cb..6d144333c 100644 --- a/zvariant/src/serialized/written.rs +++ b/zvariant/src/serialized/written.rs @@ -1,6 +1,6 @@ -use std::ops::Deref; #[cfg(unix)] -use std::os::fd::OwnedFd; +use crate::OwnedFd; +use std::ops::Deref; use crate::serialized::Context;