mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
parsers: replace some generate_element! usage with derive macros
This commit is contained in:
parent
212c5c4a83
commit
0bae5d3346
6 changed files with 92 additions and 69 deletions
|
@ -4,6 +4,8 @@
|
|||
// 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::iq::{IqGetPayload, IqResultPayload};
|
||||
use crate::ns;
|
||||
use crate::Element;
|
||||
|
@ -90,14 +92,14 @@ generate_element!(
|
|||
]
|
||||
);
|
||||
|
||||
generate_element!(
|
||||
/// Get URL
|
||||
Get, "get", HTTP_UPLOAD,
|
||||
attributes: [
|
||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::HTTP_UPLOAD, name = "get")]
|
||||
pub struct Get {
|
||||
/// URL
|
||||
url: Required<String> = "url",
|
||||
]
|
||||
);
|
||||
#[xml(attribute)]
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
generate_element!(
|
||||
/// Requesting a slot
|
||||
|
|
|
@ -4,17 +4,20 @@
|
|||
// 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 crate::message::MessagePayload;
|
||||
use xso::{FromXml, IntoXml};
|
||||
|
||||
use crate::message::MessagePayload;
|
||||
use crate::ns;
|
||||
|
||||
generate_element!(
|
||||
/// Defines that the message containing this payload should replace a
|
||||
/// previous message, identified by the id.
|
||||
Replace, "replace", MESSAGE_CORRECT,
|
||||
attributes: [
|
||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::MESSAGE_CORRECT, name = "replace")]
|
||||
pub struct Replace {
|
||||
/// The 'id' attribute of the message getting corrected.
|
||||
id: Required<String> = "id",
|
||||
]
|
||||
);
|
||||
#[xml(attribute)]
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
impl MessagePayload for Replace {}
|
||||
|
||||
|
@ -47,7 +50,7 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_invalid_attribute() {
|
||||
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0' coucou=''/>"
|
||||
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0' id='coucou' coucou=''/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Replace::try_from(elem).unwrap_err();
|
||||
|
@ -55,12 +58,13 @@ mod tests {
|
|||
FromElementError::Invalid(Error::Other(string)) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "Unknown attribute in replace element.");
|
||||
assert_eq!(message, "Unknown attribute in Replace element.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_child() {
|
||||
let elem: Element = "<replace xmlns='urn:xmpp:message-correct:0'><coucou/></replace>"
|
||||
let elem: Element =
|
||||
"<replace xmlns='urn:xmpp:message-correct:0' id='coucou'><coucou/></replace>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Replace::try_from(elem).unwrap_err();
|
||||
|
@ -68,7 +72,7 @@ mod tests {
|
|||
FromElementError::Invalid(Error::Other(string)) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "Unknown child in replace element.");
|
||||
assert_eq!(message, "Unknown child in Replace element.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -81,7 +85,10 @@ mod tests {
|
|||
FromElementError::Invalid(Error::Other(string)) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "Required attribute 'id' missing.");
|
||||
assert_eq!(
|
||||
message,
|
||||
"Required attribute field 'id' on Replace element missing."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -4,21 +4,23 @@
|
|||
// 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::message::MessagePayload;
|
||||
use crate::ns;
|
||||
use crate::presence::PresencePayload;
|
||||
|
||||
generate_element!(
|
||||
/// Unique identifier given to a MUC participant.
|
||||
///
|
||||
/// It allows clients to identify a MUC participant across reconnects and
|
||||
/// renames. It thus prevents impersonification of anonymous users.
|
||||
OccupantId, "occupant-id", OID,
|
||||
|
||||
attributes: [
|
||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::OID, name = "occupant-id")]
|
||||
pub struct OccupantId {
|
||||
/// The id associated to the sending user by the MUC service.
|
||||
id: Required<String> = "id",
|
||||
]
|
||||
);
|
||||
#[xml(attribute)]
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
impl MessagePayload for OccupantId {}
|
||||
impl PresencePayload for OccupantId {}
|
||||
|
@ -52,7 +54,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_invalid_child() {
|
||||
let elem: Element = "<occupant-id xmlns='urn:xmpp:occupant-id:0'><coucou/></occupant-id>"
|
||||
let elem: Element =
|
||||
"<occupant-id xmlns='urn:xmpp:occupant-id:0' id='foo'><coucou/></occupant-id>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = OccupantId::try_from(elem).unwrap_err();
|
||||
|
@ -60,7 +63,7 @@ mod tests {
|
|||
FromElementError::Invalid(Error::Other(string)) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "Unknown child in occupant-id element.");
|
||||
assert_eq!(message, "Unknown child in OccupantId element.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -73,7 +76,10 @@ mod tests {
|
|||
FromElementError::Invalid(Error::Other(string)) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "Required attribute 'id' missing.");
|
||||
assert_eq!(
|
||||
message,
|
||||
"Required attribute field 'id' on OccupantId element missing."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
// 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::iq::{IqGetPayload, IqResultPayload, IqSetPayload};
|
||||
use crate::ns;
|
||||
|
@ -73,14 +75,14 @@ generate_element!(
|
|||
]
|
||||
);
|
||||
|
||||
generate_element!(
|
||||
/// A redirect element.
|
||||
Redirect, "redirect", PUBSUB_OWNER,
|
||||
attributes: [
|
||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::PUBSUB_OWNER, name = "redirect")]
|
||||
pub struct Redirect {
|
||||
/// The node this node will be redirected to.
|
||||
uri: Required<String> = "uri",
|
||||
]
|
||||
);
|
||||
#[xml(attribute)]
|
||||
pub uri: String,
|
||||
}
|
||||
|
||||
generate_element!(
|
||||
/// Request to delete a node.
|
||||
|
|
|
@ -17,15 +17,15 @@ pub struct Request;
|
|||
|
||||
impl MessagePayload for Request {}
|
||||
|
||||
generate_element!(
|
||||
/// Notes that a previous message has correctly been received, it is
|
||||
/// referenced by its 'id' attribute.
|
||||
Received, "received", RECEIPTS,
|
||||
attributes: [
|
||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::RECEIPTS, name = "received")]
|
||||
pub struct Received {
|
||||
/// The 'id' attribute of the received message.
|
||||
id: Required<String> = "id",
|
||||
]
|
||||
);
|
||||
#[xml(attribute)]
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
impl MessagePayload for Received {}
|
||||
|
||||
|
@ -69,7 +69,10 @@ mod tests {
|
|||
FromElementError::Invalid(Error::Other(string)) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "Required attribute 'id' missing.");
|
||||
assert_eq!(
|
||||
message,
|
||||
"Required attribute field 'id' on Received element missing."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
// 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::message::MessagePayload;
|
||||
use crate::ns;
|
||||
use jid::Jid;
|
||||
|
||||
generate_element!(
|
||||
|
@ -22,15 +25,15 @@ generate_element!(
|
|||
|
||||
impl MessagePayload for StanzaId {}
|
||||
|
||||
generate_element!(
|
||||
/// A hack for MUC before version 1.31 to track a message which may have
|
||||
/// its 'id' attribute changed.
|
||||
OriginId, "origin-id", SID,
|
||||
attributes: [
|
||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::SID, name = "origin-id")]
|
||||
pub struct OriginId {
|
||||
/// The id this client set for this stanza.
|
||||
id: Required<String> = "id",
|
||||
]
|
||||
);
|
||||
#[xml(attribute)]
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
impl MessagePayload for OriginId {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue