iq: Implement the Iq*Payload traits on every possible payload.

This commit is contained in:
Emmanuel Gil Peyrot 2018-05-16 15:08:17 +02:00
commit 412eafb363
11 changed files with 64 additions and 0 deletions

View file

@ -12,6 +12,7 @@ use minidom::Element;
use error::Error; use error::Error;
use jid::Jid; use jid::Jid;
use ns; use ns;
use iq::{IqSetPayload, IqResultPayload};
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum Bind { pub enum Bind {
@ -29,6 +30,9 @@ impl Bind {
} }
} }
impl IqSetPayload for Bind {}
impl IqResultPayload for Bind {}
impl TryFrom<Element> for Bind { impl TryFrom<Element> for Bind {
type Err = Error; type Err = Error;

View file

@ -12,9 +12,12 @@ use minidom::Element;
use error::Error; use error::Error;
use ns; use ns;
use iq::{IqGetPayload, IqSetPayload, IqResultPayload};
generate_empty_element!(BlocklistRequest, "blocklist", BLOCKING); generate_empty_element!(BlocklistRequest, "blocklist", BLOCKING);
impl IqGetPayload for BlocklistRequest {}
macro_rules! generate_blocking_element { macro_rules! generate_blocking_element {
($elem:ident, $name:tt) => ( ($elem:ident, $name:tt) => (
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -59,6 +62,10 @@ generate_blocking_element!(BlocklistResult, "blocklist");
generate_blocking_element!(Block, "block"); generate_blocking_element!(Block, "block");
generate_blocking_element!(Unblock, "unblock"); generate_blocking_element!(Unblock, "unblock");
impl IqResultPayload for BlocklistResult {}
impl IqSetPayload for Block {}
impl IqSetPayload for Unblock {}
generate_empty_element!(Blocked, "blocked", BLOCKING_ERRORS); generate_empty_element!(Blocked, "blocked", BLOCKING_ERRORS);
#[cfg(test)] #[cfg(test)]

View file

@ -14,6 +14,7 @@ use jid::Jid;
use error::Error; use error::Error;
use ns; use ns;
use iq::{IqGetPayload, IqResultPayload};
use data_forms::{DataForm, DataFormType}; use data_forms::{DataForm, DataFormType};
generate_element_with_only_attributes!( generate_element_with_only_attributes!(
@ -26,6 +27,8 @@ DiscoInfoQuery, "query", DISCO_INFO, [
node: Option<String> = "node" => optional, node: Option<String> = "node" => optional,
]); ]);
impl IqGetPayload for DiscoItemsQuery {}
generate_element_with_only_attributes!( generate_element_with_only_attributes!(
/// Structure representing a `<feature xmlns='http://jabber.org/protocol/disco#info'/>` element. /// Structure representing a `<feature xmlns='http://jabber.org/protocol/disco#info'/>` element.
#[derive(PartialEq)] #[derive(PartialEq)]
@ -108,6 +111,8 @@ pub struct DiscoInfoResult {
pub extensions: Vec<DataForm>, pub extensions: Vec<DataForm>,
} }
impl IqResultPayload for DiscoInfoResult {}
impl TryFrom<Element> for DiscoInfoResult { impl TryFrom<Element> for DiscoInfoResult {
type Err = Error; type Err = Error;
@ -190,6 +195,8 @@ DiscoItemsQuery, "query", DISCO_ITEMS, [
node: Option<String> = "node" => optional, node: Option<String> = "node" => optional,
]); ]);
impl IqGetPayload for DiscoInfoResult {}
generate_element_with_only_attributes!( generate_element_with_only_attributes!(
/// Structure representing an `<item xmlns='http://jabber.org/protocol/disco#items'/>` element. /// Structure representing an `<item xmlns='http://jabber.org/protocol/disco#items'/>` element.
Item, "item", DISCO_ITEMS, [ Item, "item", DISCO_ITEMS, [
@ -218,6 +225,8 @@ generate_element_with_children!(
] ]
); );
impl IqResultPayload for DiscoItemsResult {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -5,6 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use helpers::Base64; use helpers::Base64;
use iq::IqSetPayload;
generate_attribute!(Stanza, "stanza", { generate_attribute!(Stanza, "stanza", {
Iq => "iq", Iq => "iq",
@ -17,6 +18,8 @@ generate_element_with_only_attributes!(Open, "open", IBB, [
stanza: Stanza = "stanza" => default, stanza: Stanza = "stanza" => default,
]); ]);
impl IqSetPayload for Open {}
generate_element_with_text!(Data, "data", IBB, generate_element_with_text!(Data, "data", IBB,
[ [
seq: u16 = "seq" => required, seq: u16 = "seq" => required,
@ -25,10 +28,14 @@ generate_element_with_text!(Data, "data", IBB,
data: Base64<Vec<u8>> data: Base64<Vec<u8>>
); );
impl IqSetPayload for Data {}
generate_element_with_only_attributes!(Close, "close", IBB, [ generate_element_with_only_attributes!(Close, "close", IBB, [
sid: String = "sid" => required, sid: String = "sid" => required,
]); ]);
impl IqSetPayload for Close {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -11,6 +11,7 @@ use minidom::Element;
use error::Error; use error::Error;
use iq::{IqGetPayload, IqSetPayload, IqResultPayload};
use data_forms::DataForm; use data_forms::DataForm;
use ns; use ns;
@ -25,6 +26,10 @@ pub struct Query {
//pub oob: Option<Oob>, //pub oob: Option<Oob>,
} }
impl IqGetPayload for Query;
impl IqSetPayload for Query;
impl IqResultPayload for Query;
impl TryFrom<Element> for Query { impl TryFrom<Element> for Query {
type Err = Error; type Err = Error;

View file

@ -12,6 +12,7 @@ use jid::Jid;
use error::Error; use error::Error;
use ns; use ns;
use iq::IqSetPayload;
generate_attribute!(Action, "action", { generate_attribute!(Action, "action", {
ContentAccept => "content-accept", ContentAccept => "content-accept",
@ -305,6 +306,8 @@ pub struct Jingle {
pub other: Vec<Element>, pub other: Vec<Element>,
} }
impl IqSetPayload for Jingle {}
impl Jingle { impl Jingle {
pub fn new(action: Action, sid: SessionId) -> Jingle { pub fn new(action: Action, sid: SessionId) -> Jingle {
Jingle { Jingle {

View file

@ -11,6 +11,7 @@ use jid::Jid;
use error::Error; use error::Error;
use iq::{IqGetPayload, IqSetPayload, IqResultPayload};
use data_forms::DataForm; use data_forms::DataForm;
use rsm::Set; use rsm::Set;
use forwarding::Forwarded; use forwarding::Forwarded;
@ -25,6 +26,10 @@ pub struct Query {
pub set: Option<Set>, pub set: Option<Set>,
} }
impl IqGetPayload for Query {}
impl IqSetPayload for Query {}
impl IqResultPayload for Query {}
generate_element_with_children!( generate_element_with_children!(
Result_, "result", MAM, Result_, "result", MAM,
attributes: [ attributes: [
@ -42,6 +47,8 @@ pub struct Fin {
pub set: Set, pub set: Set,
} }
impl IqResultPayload for Fin {}
generate_attribute!(DefaultPrefs, "default", { generate_attribute!(DefaultPrefs, "default", {
Always => "always", Always => "always",
Never => "never", Never => "never",
@ -55,6 +62,10 @@ pub struct Prefs {
pub never: Vec<Jid>, pub never: Vec<Jid>,
} }
impl IqGetPayload for Prefs {}
impl IqSetPayload for Prefs {}
impl IqResultPayload for Prefs {}
impl TryFrom<Element> for Query { impl TryFrom<Element> for Query {
type Err = Error; type Err = Error;

View file

@ -5,8 +5,12 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use iq::IqGetPayload;
generate_empty_element!(Ping, "ping", PING); generate_empty_element!(Ping, "ping", PING);
impl IqGetPayload for Ping {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -15,6 +15,7 @@ use error::Error;
use ns; use ns;
use iq::{IqGetPayload, IqSetPayload, IqResultPayload};
use data_forms::DataForm; use data_forms::DataForm;
use pubsub::{NodeName, ItemId, Subscription, SubscriptionId}; use pubsub::{NodeName, ItemId, Subscription, SubscriptionId};
@ -364,6 +365,10 @@ pub enum PubSub {
Unsubscribe(Unsubscribe), Unsubscribe(Unsubscribe),
} }
impl IqGetPayload for PubSub {}
impl IqSetPayload for PubSub {}
impl IqResultPayload for PubSub {}
impl TryFrom<Element> for PubSub { impl TryFrom<Element> for PubSub {
type Err = Error; type Err = Error;

View file

@ -5,6 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use jid::Jid; use jid::Jid;
use iq::{IqGetPayload, IqSetPayload, IqResultPayload};
generate_elem_id!(Group, "group", ROSTER); generate_elem_id!(Group, "group", ROSTER);
@ -54,6 +55,10 @@ generate_element_with_children!(
] ]
); );
impl IqGetPayload for Roster {}
impl IqSetPayload for Roster {}
impl IqResultPayload for Roster {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -8,6 +8,7 @@ use try_from::TryFrom;
use minidom::Element; use minidom::Element;
use error::Error; use error::Error;
use ns; use ns;
use iq::{IqGetPayload, IqResultPayload};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Version { pub struct Version {
@ -16,6 +17,9 @@ pub struct Version {
pub os: Option<String>, pub os: Option<String>,
} }
impl IqGetPayload for Version {}
impl IqResultPayload for Version {}
impl TryFrom<Element> for Version { impl TryFrom<Element> for Version {
type Err = Error; type Err = Error;