2017-06-11 14:48:31 +01:00
|
|
|
// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
|
|
|
|
//
|
|
|
|
|
// 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/.
|
|
|
|
|
|
2017-07-20 20:03:15 +01:00
|
|
|
use try_from::TryFrom;
|
2017-06-11 14:48:31 +01:00
|
|
|
|
2018-05-14 16:12:56 +02:00
|
|
|
use minidom::Element;
|
2017-06-11 14:48:31 +01:00
|
|
|
use jid::Jid;
|
2017-10-31 19:41:45 +00:00
|
|
|
use date::DateTime;
|
2017-06-11 14:48:31 +01:00
|
|
|
|
|
|
|
|
use error::Error;
|
|
|
|
|
|
|
|
|
|
use ns;
|
|
|
|
|
|
|
|
|
|
use data_forms::DataForm;
|
|
|
|
|
|
2017-10-10 19:45:08 +01:00
|
|
|
generate_id!(NodeName);
|
|
|
|
|
generate_id!(ItemId);
|
|
|
|
|
generate_id!(SubscriptionId);
|
|
|
|
|
|
2017-06-11 14:48:31 +01:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Item {
|
|
|
|
|
payload: Option<Element>,
|
2017-10-10 19:45:08 +01:00
|
|
|
node: Option<NodeName>,
|
|
|
|
|
id: Option<ItemId>,
|
2017-06-11 14:48:31 +01:00
|
|
|
publisher: Option<Jid>,
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 19:27:29 +01:00
|
|
|
impl TryFrom<Element> for Item {
|
|
|
|
|
type Err = Error;
|
|
|
|
|
|
|
|
|
|
fn try_from(elem: Element) -> Result<Item, Error> {
|
|
|
|
|
check_self!(elem, "item", ns::PUBSUB_EVENT);
|
|
|
|
|
check_no_unknown_attributes!(elem, "item", ["id", "node", "publisher"]);
|
|
|
|
|
let mut payloads = elem.children().cloned().collect::<Vec<_>>();
|
|
|
|
|
let payload = payloads.pop();
|
|
|
|
|
if !payloads.is_empty() {
|
|
|
|
|
return Err(Error::ParseError("More than a single payload in item element."));
|
|
|
|
|
}
|
|
|
|
|
Ok(Item {
|
|
|
|
|
payload,
|
|
|
|
|
id: get_attr!(elem, "id", optional),
|
|
|
|
|
node: get_attr!(elem, "node", optional),
|
|
|
|
|
publisher: get_attr!(elem, "publisher", optional),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-11 14:48:31 +01:00
|
|
|
impl From<Item> for Element {
|
|
|
|
|
fn from(item: Item) -> Element {
|
|
|
|
|
Element::builder("item")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.attr("id", item.id)
|
|
|
|
|
.attr("node", item.node)
|
2017-07-29 06:28:20 +01:00
|
|
|
.attr("publisher", item.publisher)
|
2017-06-11 14:48:31 +01:00
|
|
|
.append(item.payload)
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 00:50:57 +01:00
|
|
|
generate_attribute!(Subscription, "subscription", {
|
|
|
|
|
None => "none",
|
|
|
|
|
Pending => "pending",
|
|
|
|
|
Subscribed => "subscribed",
|
|
|
|
|
Unconfigured => "unconfigured",
|
|
|
|
|
}, Default = None);
|
2017-06-11 14:48:31 +01:00
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum PubSubEvent {
|
|
|
|
|
/*
|
|
|
|
|
Collection {
|
|
|
|
|
},
|
|
|
|
|
*/
|
|
|
|
|
Configuration {
|
2017-10-10 19:45:08 +01:00
|
|
|
node: NodeName,
|
2017-06-11 14:48:31 +01:00
|
|
|
form: Option<DataForm>,
|
|
|
|
|
},
|
|
|
|
|
Delete {
|
2017-10-10 19:45:08 +01:00
|
|
|
node: NodeName,
|
2017-06-11 14:48:31 +01:00
|
|
|
redirect: Option<String>,
|
|
|
|
|
},
|
|
|
|
|
EmptyItems {
|
2017-10-10 19:45:08 +01:00
|
|
|
node: NodeName,
|
2017-06-11 14:48:31 +01:00
|
|
|
},
|
|
|
|
|
PublishedItems {
|
2017-10-10 19:45:08 +01:00
|
|
|
node: NodeName,
|
2017-06-11 14:48:31 +01:00
|
|
|
items: Vec<Item>,
|
|
|
|
|
},
|
|
|
|
|
RetractedItems {
|
2017-10-10 19:45:08 +01:00
|
|
|
node: NodeName,
|
|
|
|
|
items: Vec<ItemId>,
|
2017-06-11 14:48:31 +01:00
|
|
|
},
|
|
|
|
|
Purge {
|
2017-10-10 19:45:08 +01:00
|
|
|
node: NodeName,
|
2017-06-11 14:48:31 +01:00
|
|
|
},
|
|
|
|
|
Subscription {
|
2017-10-10 19:45:08 +01:00
|
|
|
node: NodeName,
|
2017-10-31 19:41:45 +00:00
|
|
|
expiry: Option<DateTime>,
|
2017-06-11 14:48:31 +01:00
|
|
|
jid: Option<Jid>,
|
2017-10-10 19:45:08 +01:00
|
|
|
subid: Option<SubscriptionId>,
|
2017-06-11 14:48:31 +01:00
|
|
|
subscription: Option<Subscription>,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 19:45:08 +01:00
|
|
|
fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
|
2017-06-11 14:48:31 +01:00
|
|
|
let mut is_retract = None;
|
|
|
|
|
let mut items = vec!();
|
|
|
|
|
let mut retracts = vec!();
|
|
|
|
|
for child in elem.children() {
|
|
|
|
|
if child.is("item", ns::PUBSUB_EVENT) {
|
|
|
|
|
match is_retract {
|
|
|
|
|
None => is_retract = Some(false),
|
|
|
|
|
Some(false) => (),
|
|
|
|
|
Some(true) => return Err(Error::ParseError("Mix of item and retract in items element.")),
|
|
|
|
|
}
|
2017-10-10 19:27:29 +01:00
|
|
|
items.push(Item::try_from(child.clone())?);
|
2017-06-11 14:48:31 +01:00
|
|
|
} else if child.is("retract", ns::PUBSUB_EVENT) {
|
|
|
|
|
match is_retract {
|
|
|
|
|
None => is_retract = Some(true),
|
|
|
|
|
Some(true) => (),
|
|
|
|
|
Some(false) => return Err(Error::ParseError("Mix of item and retract in items element.")),
|
|
|
|
|
}
|
2017-10-10 19:27:29 +01:00
|
|
|
check_no_children!(child, "retract");
|
|
|
|
|
check_no_unknown_attributes!(child, "retract", ["id"]);
|
2017-06-11 14:48:31 +01:00
|
|
|
let id = get_attr!(child, "id", required);
|
|
|
|
|
retracts.push(id);
|
|
|
|
|
} else {
|
|
|
|
|
return Err(Error::ParseError("Invalid child in items element."));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(match is_retract {
|
|
|
|
|
None => PubSubEvent::EmptyItems { node },
|
|
|
|
|
Some(false) => PubSubEvent::PublishedItems { node, items },
|
|
|
|
|
Some(true) => PubSubEvent::RetractedItems { node, items: retracts },
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TryFrom<Element> for PubSubEvent {
|
2017-07-20 20:03:15 +01:00
|
|
|
type Err = Error;
|
2017-06-11 14:48:31 +01:00
|
|
|
|
|
|
|
|
fn try_from(elem: Element) -> Result<PubSubEvent, Error> {
|
2017-10-10 19:27:29 +01:00
|
|
|
check_self!(elem, "event", ns::PUBSUB_EVENT);
|
2017-10-31 15:47:38 +00:00
|
|
|
check_no_attributes!(elem, "event");
|
2017-10-10 19:27:29 +01:00
|
|
|
|
2017-06-11 14:48:31 +01:00
|
|
|
let mut payload = None;
|
|
|
|
|
for child in elem.children() {
|
|
|
|
|
let node = get_attr!(child, "node", required);
|
|
|
|
|
if child.is("configuration", ns::PUBSUB_EVENT) {
|
|
|
|
|
let mut payloads = child.children().cloned().collect::<Vec<_>>();
|
|
|
|
|
let item = payloads.pop();
|
|
|
|
|
if !payloads.is_empty() {
|
|
|
|
|
return Err(Error::ParseError("More than a single payload in configuration element."));
|
|
|
|
|
}
|
|
|
|
|
let form = match item {
|
|
|
|
|
None => None,
|
|
|
|
|
Some(payload) => Some(DataForm::try_from(payload)?),
|
|
|
|
|
};
|
|
|
|
|
payload = Some(PubSubEvent::Configuration { node, form });
|
|
|
|
|
} else if child.is("delete", ns::PUBSUB_EVENT) {
|
|
|
|
|
let mut redirect = None;
|
|
|
|
|
for item in child.children() {
|
|
|
|
|
if item.is("redirect", ns::PUBSUB_EVENT) {
|
|
|
|
|
if redirect.is_some() {
|
|
|
|
|
return Err(Error::ParseError("More than one redirect in delete element."));
|
|
|
|
|
}
|
|
|
|
|
let uri = get_attr!(item, "uri", required);
|
|
|
|
|
redirect = Some(uri);
|
|
|
|
|
} else {
|
|
|
|
|
return Err(Error::ParseError("Unknown child in delete element."));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
payload = Some(PubSubEvent::Delete { node, redirect });
|
|
|
|
|
} else if child.is("items", ns::PUBSUB_EVENT) {
|
|
|
|
|
payload = Some(parse_items(child.clone(), node)?);
|
|
|
|
|
} else if child.is("purge", ns::PUBSUB_EVENT) {
|
|
|
|
|
for _ in child.children() {
|
|
|
|
|
return Err(Error::ParseError("Unknown child in purge element."));
|
|
|
|
|
}
|
|
|
|
|
payload = Some(PubSubEvent::Purge { node });
|
|
|
|
|
} else if child.is("subscription", ns::PUBSUB_EVENT) {
|
|
|
|
|
for _ in child.children() {
|
|
|
|
|
return Err(Error::ParseError("Unknown child in purge element."));
|
|
|
|
|
}
|
|
|
|
|
payload = Some(PubSubEvent::Subscription {
|
|
|
|
|
node: node,
|
|
|
|
|
expiry: get_attr!(child, "expiry", optional),
|
|
|
|
|
jid: get_attr!(child, "jid", optional),
|
|
|
|
|
subid: get_attr!(child, "subid", optional),
|
|
|
|
|
subscription: get_attr!(child, "subscription", optional),
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return Err(Error::ParseError("Unknown child in event element."));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(payload.ok_or(Error::ParseError("No payload in event element."))?)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<PubSubEvent> for Element {
|
|
|
|
|
fn from(event: PubSubEvent) -> Element {
|
|
|
|
|
let payload = match event {
|
|
|
|
|
PubSubEvent::Configuration { node, form } => {
|
|
|
|
|
Element::builder("configuration")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.attr("node", node)
|
|
|
|
|
.append(form)
|
|
|
|
|
.build()
|
|
|
|
|
},
|
|
|
|
|
PubSubEvent::Delete { node, redirect } => {
|
|
|
|
|
Element::builder("purge")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.attr("node", node)
|
2017-07-21 01:19:34 +01:00
|
|
|
.append(redirect.map(|redirect| {
|
|
|
|
|
Element::builder("redirect")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.attr("uri", redirect)
|
|
|
|
|
.build()
|
2017-06-11 14:48:31 +01:00
|
|
|
}))
|
|
|
|
|
.build()
|
|
|
|
|
},
|
|
|
|
|
PubSubEvent::EmptyItems { node } => {
|
|
|
|
|
Element::builder("items")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.attr("node", node)
|
|
|
|
|
.build()
|
|
|
|
|
},
|
|
|
|
|
PubSubEvent::PublishedItems { node, items } => {
|
|
|
|
|
Element::builder("items")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.attr("node", node)
|
|
|
|
|
.append(items)
|
|
|
|
|
.build()
|
|
|
|
|
},
|
|
|
|
|
PubSubEvent::RetractedItems { node, items } => {
|
|
|
|
|
Element::builder("items")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.attr("node", node)
|
2017-10-10 19:45:08 +01:00
|
|
|
.append(items.into_iter().map(|id| {
|
|
|
|
|
Element::builder("retract")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.attr("id", id)
|
|
|
|
|
.build()
|
|
|
|
|
}).collect::<Vec<_>>())
|
2017-06-11 14:48:31 +01:00
|
|
|
.build()
|
|
|
|
|
},
|
|
|
|
|
PubSubEvent::Purge { node } => {
|
|
|
|
|
Element::builder("purge")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.attr("node", node)
|
|
|
|
|
.build()
|
|
|
|
|
},
|
|
|
|
|
PubSubEvent::Subscription { node, expiry, jid, subid, subscription } => {
|
|
|
|
|
Element::builder("subscription")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.attr("node", node)
|
2017-10-31 19:41:45 +00:00
|
|
|
.attr("expiry", expiry)
|
2017-07-29 06:28:20 +01:00
|
|
|
.attr("jid", jid)
|
2017-06-11 14:48:31 +01:00
|
|
|
.attr("subid", subid)
|
|
|
|
|
.attr("subscription", subscription)
|
|
|
|
|
.build()
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
Element::builder("event")
|
|
|
|
|
.ns(ns::PUBSUB_EVENT)
|
|
|
|
|
.append(payload)
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
use std::str::FromStr;
|
2017-08-19 00:04:18 +01:00
|
|
|
use compare_elements::NamespaceAwareCompare;
|
2017-06-11 14:48:31 +01:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_simple() {
|
|
|
|
|
let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event'><items node='coucou'/></event>".parse().unwrap();
|
|
|
|
|
let event = PubSubEvent::try_from(elem).unwrap();
|
|
|
|
|
match event {
|
2017-10-10 19:45:08 +01:00
|
|
|
PubSubEvent::EmptyItems { node } => assert_eq!(node, NodeName(String::from("coucou"))),
|
2017-06-11 14:48:31 +01:00
|
|
|
_ => panic!(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_simple_items() {
|
|
|
|
|
let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event'><items node='coucou'><item id='test' node='huh?' publisher='test@coucou'/></items></event>".parse().unwrap();
|
|
|
|
|
let event = PubSubEvent::try_from(elem).unwrap();
|
|
|
|
|
match event {
|
|
|
|
|
PubSubEvent::PublishedItems { node, items } => {
|
2017-10-10 19:45:08 +01:00
|
|
|
assert_eq!(node, NodeName(String::from("coucou")));
|
|
|
|
|
assert_eq!(items[0].id, Some(ItemId(String::from("test"))));
|
|
|
|
|
assert_eq!(items[0].node, Some(NodeName(String::from("huh?"))));
|
2017-06-11 14:48:31 +01:00
|
|
|
assert_eq!(items[0].publisher, Some(Jid::from_str("test@coucou").unwrap()));
|
|
|
|
|
assert_eq!(items[0].payload, None);
|
|
|
|
|
},
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_simple_pep() {
|
|
|
|
|
let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event'><items node='something'><item><foreign xmlns='example:namespace'/></item></items></event>".parse().unwrap();
|
|
|
|
|
let event = PubSubEvent::try_from(elem).unwrap();
|
|
|
|
|
match event {
|
|
|
|
|
PubSubEvent::PublishedItems { node, items } => {
|
2017-10-10 19:45:08 +01:00
|
|
|
assert_eq!(node, NodeName(String::from("something")));
|
2017-06-11 14:48:31 +01:00
|
|
|
assert_eq!(items[0].id, None);
|
|
|
|
|
assert_eq!(items[0].node, None);
|
|
|
|
|
assert_eq!(items[0].publisher, None);
|
|
|
|
|
match items[0].payload {
|
|
|
|
|
Some(ref elem) => assert!(elem.is("foreign", "example:namespace")),
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_simple_retract() {
|
|
|
|
|
let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event'><items node='something'><retract id='coucou'/><retract id='test'/></items></event>".parse().unwrap();
|
|
|
|
|
let event = PubSubEvent::try_from(elem).unwrap();
|
|
|
|
|
match event {
|
|
|
|
|
PubSubEvent::RetractedItems { node, items } => {
|
2017-10-10 19:45:08 +01:00
|
|
|
assert_eq!(node, NodeName(String::from("something")));
|
|
|
|
|
assert_eq!(items[0], ItemId(String::from("coucou")));
|
|
|
|
|
assert_eq!(items[1], ItemId(String::from("test")));
|
2017-06-11 14:48:31 +01:00
|
|
|
},
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_simple_delete() {
|
|
|
|
|
let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event'><delete node='coucou'><redirect uri='hello'/></delete></event>".parse().unwrap();
|
|
|
|
|
let event = PubSubEvent::try_from(elem).unwrap();
|
|
|
|
|
match event {
|
|
|
|
|
PubSubEvent::Delete { node, redirect } => {
|
2017-10-10 19:45:08 +01:00
|
|
|
assert_eq!(node, NodeName(String::from("coucou")));
|
2017-06-11 14:48:31 +01:00
|
|
|
assert_eq!(redirect, Some(String::from("hello")));
|
|
|
|
|
},
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_simple_purge() {
|
|
|
|
|
let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event'><purge node='coucou'/></event>".parse().unwrap();
|
|
|
|
|
let event = PubSubEvent::try_from(elem).unwrap();
|
|
|
|
|
match event {
|
|
|
|
|
PubSubEvent::Purge { node } => {
|
2017-10-10 19:45:08 +01:00
|
|
|
assert_eq!(node, NodeName(String::from("coucou")));
|
2017-06-11 14:48:31 +01:00
|
|
|
},
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_simple_configure() {
|
|
|
|
|
let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event'><configuration node='coucou'><x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>http://jabber.org/protocol/pubsub#node_config</value></field></x></configuration></event>".parse().unwrap();
|
|
|
|
|
let event = PubSubEvent::try_from(elem).unwrap();
|
|
|
|
|
match event {
|
|
|
|
|
PubSubEvent::Configuration { node, form: _ } => {
|
2017-10-10 19:45:08 +01:00
|
|
|
assert_eq!(node, NodeName(String::from("coucou")));
|
2017-06-11 14:48:31 +01:00
|
|
|
//assert_eq!(form.type_, Result_);
|
|
|
|
|
},
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_invalid() {
|
|
|
|
|
let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event'><coucou node='test'/></event>".parse().unwrap();
|
|
|
|
|
let error = PubSubEvent::try_from(elem).unwrap_err();
|
|
|
|
|
let message = match error {
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
|
|
|
|
assert_eq!(message, "Unknown child in event element.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_invalid_attribute() {
|
|
|
|
|
let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event' coucou=''/>".parse().unwrap();
|
|
|
|
|
let error = PubSubEvent::try_from(elem).unwrap_err();
|
|
|
|
|
let message = match error {
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
|
|
|
|
assert_eq!(message, "Unknown attribute in event element.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ex221_subscription() {
|
|
|
|
|
let elem: Element = r#"
|
|
|
|
|
<event xmlns='http://jabber.org/protocol/pubsub#event'>
|
|
|
|
|
<subscription
|
|
|
|
|
expiry='2006-02-28T23:59:59+00:00'
|
|
|
|
|
jid='francisco@denmark.lit'
|
|
|
|
|
node='princely_musings'
|
|
|
|
|
subid='ba49252aaa4f5d320c24d3766f0bdcade78c78d3'
|
|
|
|
|
subscription='subscribed'/>
|
|
|
|
|
</event>
|
|
|
|
|
"#.parse().unwrap();
|
|
|
|
|
let event = PubSubEvent::try_from(elem.clone()).unwrap();
|
|
|
|
|
match event.clone() {
|
|
|
|
|
PubSubEvent::Subscription { node, expiry, jid, subid, subscription } => {
|
2017-10-10 19:45:08 +01:00
|
|
|
assert_eq!(node, NodeName(String::from("princely_musings")));
|
|
|
|
|
assert_eq!(subid, Some(SubscriptionId(String::from("ba49252aaa4f5d320c24d3766f0bdcade78c78d3"))));
|
2017-06-11 14:48:31 +01:00
|
|
|
assert_eq!(subscription, Some(Subscription::Subscribed));
|
|
|
|
|
assert_eq!(jid, Some(Jid::from_str("francisco@denmark.lit").unwrap()));
|
|
|
|
|
assert_eq!(expiry, Some("2006-02-28T23:59:59Z".parse().unwrap()));
|
|
|
|
|
},
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let elem2: Element = event.into();
|
2017-08-19 00:04:18 +01:00
|
|
|
assert!(elem.compare_to(&elem2));
|
2017-06-11 14:48:31 +01:00
|
|
|
}
|
|
|
|
|
}
|