diff --git a/parsers/src/data_forms_validate.rs b/parsers/src/data_forms_validate.rs index 07a330d6..757aeb32 100644 --- a/parsers/src/data_forms_validate.rs +++ b/parsers/src/data_forms_validate.rs @@ -8,9 +8,9 @@ use std::fmt::{Display, Formatter}; use std::str::FromStr; use minidom::{Element, IntoAttributeValue}; -use xso::error::FromElementError; +use xso::{error::FromElementError, FromXml, IntoXml}; -use crate::ns::XDATA_VALIDATE; +use crate::ns::{self, XDATA_VALIDATE}; use crate::Error; /// Validation Method @@ -66,16 +66,17 @@ pub enum Method { Regex(String), } -generate_element!( - /// Selection Ranges in "list-multi" - ListRange, "list-range", XDATA_VALIDATE, - attributes: [ - /// The 'min' attribute specifies the minimum allowable number of selected/entered values. - min: Option = "min", - /// The 'max' attribute specifies the maximum allowable number of selected/entered values. - max: Option = "max", - ] -); +/// Selection Ranges in "list-multi" +#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::XDATA_VALIDATE, name = "list-range")] +pub struct ListRange { + /// The 'min' attribute specifies the minimum allowable number of selected/entered values. + #[xml(attribute(default))] + pub min: Option, + /// The 'max' attribute specifies the maximum allowable number of selected/entered values. + #[xml(attribute(default))] + pub max: Option, +} /// Enum representing errors that can occur while parsing a `Datatype`. #[derive(Debug, Clone, PartialEq)] diff --git a/parsers/src/extdisco.rs b/parsers/src/extdisco.rs index 2a09f89b..264812df 100644 --- a/parsers/src/extdisco.rs +++ b/parsers/src/extdisco.rs @@ -4,9 +4,12 @@ // 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::{FromXml, IntoXml}; + use crate::data_forms::DataForm; use crate::date::DateTime; use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; +use crate::ns; generate_attribute!( /// When sending a push update, the action value indicates if the service is being added or @@ -97,14 +100,14 @@ generate_element!( impl IqGetPayload for Service {} -generate_element!( - /// Structure representing a `` element. - ServicesQuery, "services", EXT_DISCO, - attributes: [ - /// TODO - type_: Option = "type", - ] -); +/// Structure representing a `` element. +#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::EXT_DISCO, name = "services")] +pub struct ServicesQuery { + /// TODO + #[xml(attribute(default, name = "type"))] + pub type_: Option, +} impl IqGetPayload for ServicesQuery {} diff --git a/parsers/src/mix.rs b/parsers/src/mix.rs index 28399347..06453245 100644 --- a/parsers/src/mix.rs +++ b/parsers/src/mix.rs @@ -203,15 +203,14 @@ impl Mix { } } -generate_element!( - /// Create a new MIX channel. - #[derive(Default)] - Create, "create", MIX_CORE, - attributes: [ - /// The requested channel identifier. - channel: Option = "channel", - ] -); +/// Create a new MIX channel. +#[derive(FromXml, IntoXml, PartialEq, Clone, Debug, Default)] +#[xml(namespace = ns::MIX_CORE, name = "create")] +pub struct Create { + /// The requested channel identifier. + #[xml(attribute(default))] + pub channel: Option, +} impl IqSetPayload for Create {} impl IqResultPayload for Create {} diff --git a/parsers/src/muc/muc.rs b/parsers/src/muc/muc.rs index 494fedba..c5bde638 100644 --- a/parsers/src/muc/muc.rs +++ b/parsers/src/muc/muc.rs @@ -5,27 +5,32 @@ // 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::{FromXml, IntoXml}; + use crate::date::DateTime; +use crate::ns; use crate::presence::PresencePayload; -generate_element!( - /// Represents the query for messages before our join. - #[derive(Default)] - History, "history", MUC, - attributes: [ - /// How many characters of history to send, in XML characters. - maxchars: Option = "maxchars", +/// Represents the query for messages before our join. +#[derive(FromXml, IntoXml, PartialEq, Debug, Clone, Default)] +#[xml(namespace = ns::MUC, name = "history")] +pub struct History { + /// How many characters of history to send, in XML characters. + #[xml(attribute(default))] + pub maxchars: Option, - /// How many messages to send. - maxstanzas: Option = "maxstanzas", + /// How many messages to send. + #[xml(attribute(default))] + pub maxstanzas: Option, - /// Only send messages received in these last seconds. - seconds: Option = "seconds", + /// Only send messages received in these last seconds. + #[xml(attribute(default))] + pub seconds: Option, - /// Only send messages after this date. - since: Option = "since", - ] -); + /// Only send messages after this date. + #[xml(attribute(default))] + pub since: Option, +} impl History { /// Create a new empty history element. diff --git a/parsers/src/muc/user.rs b/parsers/src/muc/user.rs index 857b8dda..22a77e36 100644 --- a/parsers/src/muc/user.rs +++ b/parsers/src/muc/user.rs @@ -5,11 +5,15 @@ // 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::{ + error::{Error, FromElementError}, + FromXml, IntoXml, +}; + use crate::message::MessagePayload; use crate::ns; use crate::presence::PresencePayload; use crate::Element; -use xso::error::{Error, FromElementError}; use jid::FullJid; @@ -125,15 +129,15 @@ impl From for Element { } } -generate_element!( - /// Used to continue a one-to-one discussion in a room, with more than one - /// participant. - Continue, "continue", MUC_USER, - attributes: [ - /// The thread to continue in this room. - thread: Option = "thread", - ] -); +/// Used to continue a one-to-one discussion in a room, with more than one +/// participant. +#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::MUC_USER, name = "continue")] +pub struct Continue { + /// The thread to continue in this room. + #[xml(attribute(default))] + pub thread: Option, +} generate_elem_id!( /// A reason for inviting, declining, etc. a request. @@ -527,17 +531,16 @@ mod tests { #[test] fn test_continue_invalid() { - let elem: Element = " - - " - .parse() - .unwrap(); + let elem: Element = + "" + .parse() + .unwrap(); let continue_ = Continue::try_from(elem).unwrap_err(); let message = match continue_ { FromElementError::Invalid(Error::Other(string)) => string, _ => panic!(), }; - assert_eq!(message, "Unknown child in continue element.".to_owned()); + assert_eq!(message, "Unknown child in Continue element.".to_owned()); } #[test] diff --git a/parsers/src/pubsub/pubsub.rs b/parsers/src/pubsub/pubsub.rs index 82f32da9..5046da81 100644 --- a/parsers/src/pubsub/pubsub.rs +++ b/parsers/src/pubsub/pubsub.rs @@ -54,14 +54,14 @@ generate_element!( ] ); -generate_element!( - /// Request to create a new node. - Create, "create", PUBSUB, - attributes: [ - /// The node name to create, if `None` the service will generate one. - node: Option = "node", - ] -); +/// Request to create a new node. +#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::PUBSUB, name = "create")] +pub struct Create { + /// The node name to create, if `None` the service will generate one. + #[xml(attribute(default))] + pub node: Option, +} generate_element!( /// Request for a default node configuration.