diff options
| author | Max Audron <audron@cocaine.farm> | 2025-03-01 20:00:36 +0100 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2025-03-01 20:02:12 +0100 |
| commit | 09bdd93113e46a5ee909190d23a2638c5f4f010b (patch) | |
| tree | 8bf27da0c09317302e6c3b2d2020ac2b7403b650 /src/message/signalproxy | |
| parent | add UserType implementation for required signalproxy objects (diff) | |
implement rpc calls
Diffstat (limited to '')
| -rw-r--r-- | src/message/signalproxy/mod.rs | 5 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall.rs | 62 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/bufferinfo.rs | 36 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/client.rs | 60 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/identity.rs | 142 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/message.rs | 109 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/mod.rs | 136 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/network.rs | 141 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/objectrenamed.rs | 43 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/passwordchange.rs | 88 |
10 files changed, 758 insertions, 64 deletions
diff --git a/src/message/signalproxy/mod.rs b/src/message/signalproxy/mod.rs index 062b400..5107e9b 100644 --- a/src/message/signalproxy/mod.rs +++ b/src/message/signalproxy/mod.rs @@ -5,6 +5,8 @@ use crate::{ serialize::Serialize, }; +use rpccall::RpcCall; + use log::debug; use num_derive::{FromPrimitive, ToPrimitive}; @@ -12,7 +14,7 @@ mod heartbeat; mod initdata; mod initrequest; pub mod objects; -mod rpccall; +pub mod rpccall; mod syncmessage; pub mod translation; @@ -21,7 +23,6 @@ pub use translation::*; pub use heartbeat::*; pub use initdata::*; pub use initrequest::*; -pub use rpccall::*; pub use syncmessage::*; use once_cell::sync::OnceCell; diff --git a/src/message/signalproxy/rpccall.rs b/src/message/signalproxy/rpccall.rs deleted file mode 100644 index 833fad9..0000000 --- a/src/message/signalproxy/rpccall.rs +++ /dev/null @@ -1,62 +0,0 @@ -use crate::error::ProtocolError; -use crate::message::MessageType; -use crate::primitive::Message; -use crate::primitive::{Variant, VariantList}; -use crate::serialize::{Deserialize, Serialize}; - -#[derive(Clone, Debug, std::cmp::PartialEq)] -pub enum RpcCall { - DisplayMessage(DisplayMessage), - NotImplemented, -} - -#[derive(Clone, Debug, std::cmp::PartialEq)] -pub struct DisplayMessage { - pub message: Message, -} - -// #[derive(Clone, Debug, std::cmp::PartialEq)] -// pub struct RpcCall { -// pub slot_name: String, -// pub params: VariantList, -// } - -impl Serialize for RpcCall { - fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> { - let mut res = VariantList::new(); - - res.push(Variant::i32(MessageType::RpcCall as i32)); - - match self { - RpcCall::DisplayMessage(msg) => { - res.push(Variant::ByteArray("2displayMsg(Message)".to_string())); - res.push(Variant::Message(msg.message.clone())); - } - RpcCall::NotImplemented => todo!(), - } - - res.serialize() - } -} - -impl Deserialize for RpcCall { - fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> { - let (size, mut res) = VariantList::parse(&b)?; - - res.remove(0); - - let rpc = match_variant!(res.remove(0), Variant::ByteArray); - - match rpc.as_str() { - "2displayMsg(Message)" => { - return Ok(( - size, - RpcCall::DisplayMessage(DisplayMessage { - message: match_variant!(res.remove(0), Variant::Message), - }), - )) - } - _ => return Ok((size, RpcCall::NotImplemented)), - } - } -} diff --git a/src/message/signalproxy/rpccall/bufferinfo.rs b/src/message/signalproxy/rpccall/bufferinfo.rs new file mode 100644 index 0000000..7ba2757 --- /dev/null +++ b/src/message/signalproxy/rpccall/bufferinfo.rs @@ -0,0 +1,36 @@ +use crate::primitive::{BufferInfo, Variant}; + +use super::{Direction, RpcCallType}; + +#[derive(Clone, Debug, PartialEq)] +pub struct BufferInfoUpdated { + buffer: BufferInfo, +} + +impl RpcCallType for BufferInfoUpdated { + const NAME: &str = "2bufferInfoUpdated(BufferInfo)"; + const DIRECTION: Direction = Direction::ServerToClient; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.buffer.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + buffer: match_variant!(input.remove(0), Variant::BufferInfo), + } + .into(), + )) + } +} diff --git a/src/message/signalproxy/rpccall/client.rs b/src/message/signalproxy/rpccall/client.rs new file mode 100644 index 0000000..5fb5326 --- /dev/null +++ b/src/message/signalproxy/rpccall/client.rs @@ -0,0 +1,60 @@ +use crate::primitive::Variant; + +use super::{Direction, RpcCallType}; + +#[derive(Clone, Debug, PartialEq)] +pub struct KickClient { + /// Client id of client to be kicked. Ids can be found in [CoreInfo] + id: i32, +} + +impl RpcCallType for KickClient { + const NAME: &str = "2kickClient(int)"; + const DIRECTION: Direction = Direction::ClientToServer; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.id.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + id: match_variant!(input.remove(0), Variant::i32), + } + .into(), + )) + } +} + +/// Requests the current client to disconnect from the core. Only this client sees this message. +#[derive(Clone, Debug, PartialEq)] +pub struct DisconnectFromCore; + +impl RpcCallType for DisconnectFromCore { + const NAME: &str = "2disconnectFromCore()"; + const DIRECTION: Direction = Direction::ServerToClient; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![Variant::ByteArray(Self::NAME.to_string())]) + } + + fn from_network( + size: usize, + _input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok((size, Self {}.into())) + } +} diff --git a/src/message/signalproxy/rpccall/identity.rs b/src/message/signalproxy/rpccall/identity.rs new file mode 100644 index 0000000..288dec5 --- /dev/null +++ b/src/message/signalproxy/rpccall/identity.rs @@ -0,0 +1,142 @@ +use crate::{ + message::objects::Identity, + primitive::{IdentityId, Variant, VariantMap}, +}; + +use super::{Direction, RpcCallType}; + +#[derive(Clone, Debug, PartialEq)] +pub struct CreateIdentity { + identity: Identity, + /// Always Empty + additional: VariantMap, +} + +impl RpcCallType for CreateIdentity { + const NAME: &str = "2createIdentity(Identity,QVariantMap)"; + const DIRECTION: Direction = Direction::ClientToServer; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.identity.clone().into(), + self.additional.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + CreateIdentity { + identity: match_variant!(input.remove(0), Variant::Identity), + additional: match_variant!(input.remove(0), Variant::VariantMap), + } + .into(), + )) + } +} + +#[derive(Clone, Debug, PartialEq)] +pub struct RemoveIdentity { + identity_id: IdentityId, +} + +impl RpcCallType for RemoveIdentity { + const NAME: &str = "2removeIdentity(IdentityId)"; + const DIRECTION: Direction = Direction::ClientToServer; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + Variant::IdentityId(self.identity_id.clone()), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + identity_id: match_variant!(input.remove(0), Variant::IdentityId), + } + .into(), + )) + } +} + +#[derive(Clone, Debug, PartialEq)] +pub struct IdentityCreated { + identity: Identity, +} + +impl RpcCallType for IdentityCreated { + const NAME: &str = "2identityCreated(Identity)"; + const DIRECTION: Direction = Direction::ServerToClient; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.identity.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + IdentityCreated { + identity: match_variant!(input.remove(0), Variant::Identity), + } + .into(), + )) + } +} + +#[derive(Clone, Debug, PartialEq)] +pub struct IdentityRemoved { + identity_id: IdentityId, +} + +impl RpcCallType for IdentityRemoved { + const NAME: &str = "2identityRemoved(IdentityId)"; + const DIRECTION: Direction = Direction::ServerToClient; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + Variant::IdentityId(self.identity_id.clone()), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + identity_id: match_variant!(input.remove(0), Variant::IdentityId), + } + .into(), + )) + } +} diff --git a/src/message/signalproxy/rpccall/message.rs b/src/message/signalproxy/rpccall/message.rs new file mode 100644 index 0000000..93888b5 --- /dev/null +++ b/src/message/signalproxy/rpccall/message.rs @@ -0,0 +1,109 @@ +use crate::primitive::{BufferInfo, Message, Variant}; + +use super::{Direction, RpcCall, RpcCallType}; + +/// Called when a new IRC message has been received, and the client should display or store it. +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub struct DisplayMessage { + pub message: Message, +} + +impl RpcCallType for DisplayMessage { + const NAME: &str = "2displayMessage(Message)"; + const DIRECTION: Direction = Direction::ServerToClient; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.message.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + RpcCall::DisplayMessage(DisplayMessage { + message: match_variant!(input.remove(0), Variant::Message), + }), + )) + } +} + +/// Status message for an IRC network to be shown in the client’s status bar (if available). +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub struct DisplayStatusMessage { + pub network: String, + pub message: String, +} + +impl RpcCallType for DisplayStatusMessage { + const NAME: &str = "2displayStatusMsg(QString,QString)"; + const DIRECTION: Direction = Direction::ServerToClient; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.network.clone().into(), + self.message.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + DisplayStatusMessage { + network: match_variant!(input.remove(0), Variant::String), + message: match_variant!(input.remove(0), Variant::String), + } + .into(), + )) + } +} + +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub struct SendInput { + buffer: BufferInfo, + message: String, +} + +impl RpcCallType for SendInput { + const NAME: &str = "2sendInput(BufferInfo,QString)"; + const DIRECTION: Direction = Direction::ClientToServer; + + fn to_network(&self) -> Result<Vec<Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.buffer.clone().into(), + self.message.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + buffer: match_variant!(input.remove(0), Variant::BufferInfo), + message: match_variant!(input.remove(0), Variant::String), + } + .into(), + )) + } +} diff --git a/src/message/signalproxy/rpccall/mod.rs b/src/message/signalproxy/rpccall/mod.rs new file mode 100644 index 0000000..378d626 --- /dev/null +++ b/src/message/signalproxy/rpccall/mod.rs @@ -0,0 +1,136 @@ +//! Remote Procedure Calls between client and server +//! +//! RpcCalls are serialized to a VariantList first containing the i32 representation of +//! [MessageType::RpcCall], then a ByteArray of the RPC Call Name and the arguments of the call as their own +//! types. +//! +//! In this module you can find structs for each RPC Call as well as the [RpcCall] enum that implements the +//! mapping and de-/serialization. Each struct has an impl of [RpcCallType] that has the meta information for +//! the name of the rpc call as well as it's direction + +use crate::error::ProtocolError; +use crate::message::MessageType; +use crate::primitive::{Variant, VariantList}; +use crate::serialize::{Deserialize, Serialize}; + +use libquassel_derive::From; + +mod bufferinfo; +mod client; +mod identity; +mod message; +mod network; +mod objectrenamed; +mod passwordchange; + +pub use bufferinfo::*; +pub use client::*; +pub use identity::*; +pub use message::*; +pub use network::*; +pub use objectrenamed::*; +pub use passwordchange::*; + +#[derive(Clone, Debug, PartialEq, From)] +pub enum RpcCall { + DisplayMessage(DisplayMessage), + DisplayStatusMessage(DisplayStatusMessage), + SendInput(SendInput), + CreateIdentity(CreateIdentity), + RemoveIdentity(RemoveIdentity), + IdentityCreated(IdentityCreated), + IdentityRemoved(IdentityRemoved), + CreateNetwork(CreateNetwork), + RemoveNetwork(RemoveNetwork), + NetworkCreated(NetworkCreated), + NetworkRemoved(NetworkRemoved), + ChangePassword(ChangePassword), + PasswordChanged(PasswordChanged), + KickClient(KickClient), + DisconnectFromCore(DisconnectFromCore), + ObjectRename(ObjectRenamed), + BufferInfoUpdated(BufferInfoUpdated), + NotImplemented, +} + +/// Direction of RPC Call +pub enum Direction { + ClientToServer, + ServerToClient, +} + +pub trait RpcCallType { + /// String name of the call. Serialized as a [Variant::ByteArray] + const NAME: &str; + /// Whether the call is from the server to the client, or client to server + const DIRECTION: Direction; + + /// Convert Self to network representation including it's [Self::NAME] + fn to_network(&self) -> Result<Vec<Variant>, ProtocolError>; + /// Create Self from network representation + fn from_network(size: usize, input: &mut VariantList) -> Result<(usize, RpcCall), crate::ProtocolError> + where + Self: Sized; +} + +impl Serialize for RpcCall { + fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> { + let mut res = VariantList::new(); + + res.push(Variant::i32(MessageType::RpcCall as i32)); + + match self { + RpcCall::DisplayMessage(msg) => res.extend(msg.to_network()?), + RpcCall::DisplayStatusMessage(msg) => res.extend(msg.to_network()?), + RpcCall::SendInput(msg) => res.extend(msg.to_network()?), + RpcCall::CreateIdentity(msg) => res.extend(msg.to_network()?), + RpcCall::RemoveIdentity(msg) => res.extend(msg.to_network()?), + RpcCall::IdentityCreated(msg) => res.extend(msg.to_network()?), + RpcCall::IdentityRemoved(msg) => res.extend(msg.to_network()?), + RpcCall::CreateNetwork(msg) => res.extend(msg.to_network()?), + RpcCall::RemoveNetwork(msg) => res.extend(msg.to_network()?), + RpcCall::NetworkCreated(msg) => res.extend(msg.to_network()?), + RpcCall::NetworkRemoved(msg) => res.extend(msg.to_network()?), + RpcCall::ChangePassword(msg) => res.extend(msg.to_network()?), + RpcCall::PasswordChanged(msg) => res.extend(msg.to_network()?), + RpcCall::KickClient(msg) => res.extend(msg.to_network()?), + RpcCall::DisconnectFromCore(msg) => res.extend(msg.to_network()?), + RpcCall::ObjectRename(msg) => res.extend(msg.to_network()?), + RpcCall::BufferInfoUpdated(msg) => res.extend(msg.to_network()?), + RpcCall::NotImplemented => todo!(), + } + + res.serialize() + } +} + +impl Deserialize for RpcCall { + fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> { + let (size, mut res) = VariantList::parse(&b)?; + + res.remove(0); + + let rpc = match_variant!(res.remove(0), Variant::ByteArray); + + match rpc.as_str() { + DisplayMessage::NAME => DisplayMessage::from_network(size, &mut res), + DisplayStatusMessage::NAME => DisplayStatusMessage::from_network(size, &mut res), + SendInput::NAME => SendInput::from_network(size, &mut res), + CreateIdentity::NAME => CreateIdentity::from_network(size, &mut res), + RemoveIdentity::NAME => RemoveIdentity::from_network(size, &mut res), + IdentityCreated::NAME => IdentityCreated::from_network(size, &mut res), + IdentityRemoved::NAME => IdentityRemoved::from_network(size, &mut res), + CreateNetwork::NAME => CreateNetwork::from_network(size, &mut res), + RemoveNetwork::NAME => RemoveNetwork::from_network(size, &mut res), + NetworkCreated::NAME => NetworkCreated::from_network(size, &mut res), + NetworkRemoved::NAME => NetworkRemoved::from_network(size, &mut res), + ChangePassword::NAME => ChangePassword::from_network(size, &mut res), + PasswordChanged::NAME => PasswordChanged::from_network(size, &mut res), + KickClient::NAME => KickClient::from_network(size, &mut res), + DisconnectFromCore::NAME => DisconnectFromCore::from_network(size, &mut res), + ObjectRenamed::NAME => ObjectRenamed::from_network(size, &mut res), + BufferInfoUpdated::NAME => BufferInfoUpdated::from_network(size, &mut res), + _ => return Ok((size, RpcCall::NotImplemented)), + } + } +} diff --git a/src/message/signalproxy/rpccall/network.rs b/src/message/signalproxy/rpccall/network.rs new file mode 100644 index 0000000..18f9f74 --- /dev/null +++ b/src/message/signalproxy/rpccall/network.rs @@ -0,0 +1,141 @@ +use crate::{ + message::objects::NetworkInfo, + primitive::{NetworkId, StringList, Variant}, +}; + +use super::{Direction, RpcCallType}; + +#[derive(Clone, Debug, PartialEq)] +pub struct CreateNetwork { + network: NetworkInfo, + channels: StringList, +} + +impl RpcCallType for CreateNetwork { + const NAME: &str = "2createNetwork(NetworkInfo,QStringList)"; + const DIRECTION: Direction = Direction::ClientToServer; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.network.clone().into(), + self.channels.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + network: match_variant!(input.remove(0), Variant::NetworkInfo), + channels: match_variant!(input.remove(0), Variant::StringList), + } + .into(), + )) + } +} + +#[derive(Clone, Debug, PartialEq)] +pub struct RemoveNetwork { + network_id: NetworkId, +} + +impl RpcCallType for RemoveNetwork { + const NAME: &str = "2removeNetwork(NetworkId)"; + const DIRECTION: Direction = Direction::ClientToServer; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.network_id.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + network_id: match_variant!(input.remove(0), Variant::NetworkId), + } + .into(), + )) + } +} + +#[derive(Clone, Debug, PartialEq)] +pub struct NetworkCreated { + network_id: NetworkId, +} + +impl RpcCallType for NetworkCreated { + const NAME: &str = "2networkCreated(NetworkId)"; + const DIRECTION: Direction = Direction::ClientToServer; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.network_id.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + network_id: match_variant!(input.remove(0), Variant::NetworkId), + } + .into(), + )) + } +} + +#[derive(Clone, Debug, PartialEq)] +pub struct NetworkRemoved { + network_id: NetworkId, +} + +impl RpcCallType for NetworkRemoved { + const NAME: &str = "2networkRemoved(NetworkId)"; + const DIRECTION: Direction = Direction::ClientToServer; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.network_id.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + network_id: match_variant!(input.remove(0), Variant::NetworkId), + } + .into(), + )) + } +} diff --git a/src/message/signalproxy/rpccall/objectrenamed.rs b/src/message/signalproxy/rpccall/objectrenamed.rs new file mode 100644 index 0000000..d103345 --- /dev/null +++ b/src/message/signalproxy/rpccall/objectrenamed.rs @@ -0,0 +1,43 @@ +use crate::primitive::Variant; + +use super::{Direction, RpcCallType}; + +/// Called whenever an object has been renamed, and the object store should update its name. All future sync calls for this object will use the new name instead. +#[derive(Clone, Debug, PartialEq)] +pub struct ObjectRenamed { + classname: String, + newname: String, + oldname: String, +} + +impl RpcCallType for ObjectRenamed { + const NAME: &str = "__objectRenamed__"; + const DIRECTION: Direction = Direction::ServerToClient; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + Variant::ByteArray(self.classname.clone()), + self.newname.clone().into(), + self.oldname.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + classname: match_variant!(input.remove(0), Variant::ByteArray), + oldname: match_variant!(input.remove(0), Variant::String), + newname: match_variant!(input.remove(0), Variant::String), + } + .into(), + )) + } +} diff --git a/src/message/signalproxy/rpccall/passwordchange.rs b/src/message/signalproxy/rpccall/passwordchange.rs new file mode 100644 index 0000000..38bfc97 --- /dev/null +++ b/src/message/signalproxy/rpccall/passwordchange.rs @@ -0,0 +1,88 @@ +use crate::primitive::{PeerPtr, Variant}; + +use super::{Direction, RpcCallType}; + +#[derive(Clone, Debug, PartialEq)] +pub struct ChangePassword { + /// Always zero, only has a value within of the core itself. + peer: PeerPtr, + /// Username + user: String, + /// Old Password + before: String, + // New Password + after: String, +} + +impl RpcCallType for ChangePassword { + const NAME: &str = "2changePassword(PeerPtr,QString,QString,QString)"; + const DIRECTION: Direction = Direction::ClientToServer; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.peer.clone().into(), + self.user.clone().into(), + self.before.clone().into(), + self.after.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + peer: match_variant!(input.remove(0), Variant::PeerPtr), + user: match_variant!(input.remove(0), Variant::String), + before: match_variant!(input.remove(0), Variant::String), + after: match_variant!(input.remove(0), Variant::String), + } + .into(), + )) + } +} + +/// Returns if the recent password change attempt has been a success. +/// This is one of the few responses which only gets sent to the client which sent the original request. +#[derive(Clone, Debug, PartialEq)] +pub struct PasswordChanged { + /// Always zero, only has a value within of the core itself. + peer: PeerPtr, + success: bool, +} + +impl RpcCallType for PasswordChanged { + const NAME: &str = "2passwordChanged(PeerPtr,bool)"; + const DIRECTION: Direction = Direction::ServerToClient; + + fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> { + Ok(vec![ + Variant::ByteArray(Self::NAME.to_string()), + self.peer.clone().into(), + self.success.clone().into(), + ]) + } + + fn from_network( + size: usize, + input: &mut crate::primitive::VariantList, + ) -> Result<(usize, super::RpcCall), crate::ProtocolError> + where + Self: Sized, + { + Ok(( + size, + Self { + peer: match_variant!(input.remove(0), Variant::PeerPtr), + success: match_variant!(input.remove(0), Variant::bool), + } + .into(), + )) + } +} |
