// Copyright (c) 2019 Emmanuel Gil Peyrot // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. use xso::{AsXml, FromXml}; use crate::forwarding::Forwarded; use crate::iq::IqSetPayload; use crate::message::MessagePayload; use crate::ns; /// Enable carbons for this session. #[derive(FromXml, AsXml, PartialEq, Debug, Clone)] #[xml(namespace = ns::CARBONS, name = "enable")] pub struct Enable; impl IqSetPayload for Enable {} /// Disable a previously-enabled carbons. #[derive(FromXml, AsXml, PartialEq, Debug, Clone)] #[xml(namespace = ns::CARBONS, name = "disable")] pub struct Disable; impl IqSetPayload for Disable {} /// Request the enclosing message to not be copied to other carbons-enabled /// resources of the user. #[derive(FromXml, AsXml, PartialEq, Debug, Clone)] #[xml(namespace = ns::CARBONS, name = "private")] pub struct Private; impl MessagePayload for Private {} /// Wrapper for a message received on another resource. #[derive(FromXml, AsXml, PartialEq, Debug, Clone)] #[xml(namespace = ns::CARBONS, name = "received")] pub struct Received { /// Wrapper for the enclosed message. #[xml(child)] pub forwarded: Forwarded, } impl MessagePayload for Received {} /// Wrapper for a message sent from another resource. #[derive(FromXml, AsXml, PartialEq, Debug, Clone)] #[xml(namespace = ns::CARBONS, name = "sent")] pub struct Sent { /// Wrapper for the enclosed message. #[xml(child)] pub forwarded: Forwarded, } impl MessagePayload for Sent {} #[cfg(test)] mod tests { use super::*; use minidom::Element; #[cfg(target_pointer_width = "32")] #[test] fn test_size() { assert_size!(Enable, 0); assert_size!(Disable, 0); assert_size!(Private, 0); assert_size!(Received, 140); assert_size!(Sent, 140); } #[cfg(target_pointer_width = "64")] #[test] fn test_size() { assert_size!(Enable, 0); assert_size!(Disable, 0); assert_size!(Private, 0); assert_size!(Received, 264); assert_size!(Sent, 264); } #[test] fn empty_elements() { let elem: Element = "".parse().unwrap(); Enable::try_from(elem).unwrap(); let elem: Element = "".parse().unwrap(); Disable::try_from(elem).unwrap(); let elem: Element = "".parse().unwrap(); Private::try_from(elem).unwrap(); } #[test] fn forwarded_elements() { let elem: Element = " " .parse() .unwrap(); let received = Received::try_from(elem).unwrap(); assert!(received.forwarded.stanza.is_some()); let elem: Element = " " .parse() .unwrap(); let sent = Sent::try_from(elem).unwrap(); assert!(sent.forwarded.stanza.is_some()); } #[test] fn test_serialize_received() { let reference: Element = "" .parse() .unwrap(); let elem: Element = "" .parse() .unwrap(); let forwarded = Forwarded::try_from(elem).unwrap(); let received = Received { forwarded: forwarded, }; let serialized: Element = received.into(); assert_eq!(serialized, reference); } #[test] fn test_serialize_sent() { let reference: Element = "" .parse() .unwrap(); let elem: Element = "" .parse() .unwrap(); let forwarded = Forwarded::try_from(elem).unwrap(); let sent = Sent { forwarded: forwarded, }; let serialized: Element = sent.into(); assert_eq!(serialized, reference); } }