Update minidom dependency to 0.11

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2019-07-25 00:20:38 +02:00 • committed by Emmanuel Gil Peyrot
commit a1ae45add8
22 changed files with 236 additions and 168 deletions

View file

@ -14,8 +14,8 @@ license = "MPL-2.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
minidom = "0.10.0" minidom = "0.11.0"
jid = { version = "0.6.0", features = ["minidom"] } jid = { version = "0.7.0", features = ["minidom"] }
base64 = "0.10" base64 = "0.10"
digest = "0.8" digest = "0.8"
sha-1 = "0.8" sha-1 = "0.8"

View file

@ -63,13 +63,13 @@ impl From<BindQuery> for Element {
fn from(bind: BindQuery) -> Element { fn from(bind: BindQuery) -> Element {
Element::builder("bind") Element::builder("bind")
.ns(ns::BIND) .ns(ns::BIND)
.append(match bind.resource { .append_all((match bind.resource {
None => vec![], None => vec![],
Some(resource) => vec![Element::builder("resource") Some(resource) => vec![Element::builder("resource")
.ns(ns::BIND) .ns(ns::BIND)
.append(resource) .append(resource)
.build()], .build()],
}) }).into_iter())
.build() .build()
} }
} }

View file

@ -51,12 +51,12 @@ macro_rules! generate_blocking_element {
fn from(elem: $elem) -> Element { fn from(elem: $elem) -> Element {
Element::builder($name) Element::builder($name)
.ns(ns::BLOCKING) .ns(ns::BLOCKING)
.append(elem.items.into_iter().map(|jid| { .append_all(elem.items.into_iter().map(|jid| {
Element::builder("item") Element::builder("item")
.ns(ns::BLOCKING) .ns(ns::BLOCKING)
.attr("jid", jid) .attr("jid", jid)
.build() .build()
}).collect::<Vec<_>>()) }))
.build() .build()
} }
} }

View file

@ -7,7 +7,7 @@
use crate::util::error::Error; use crate::util::error::Error;
use crate::media_element::MediaElement; use crate::media_element::MediaElement;
use crate::ns; use crate::ns;
use minidom::Element; use minidom::{Element, Node};
use std::convert::TryFrom; use std::convert::TryFrom;
generate_element!( generate_element!(
@ -152,13 +152,13 @@ impl From<Field> for Element {
.attr("var", field.var) .attr("var", field.var)
.attr("type", field.type_) .attr("type", field.type_)
.attr("label", field.label) .attr("label", field.label)
.append(if field.required { .append_all((if field.required {
Some(Element::builder("required").ns(ns::DATA_FORMS).build()) Some(Element::builder("required").ns(ns::DATA_FORMS).build())
} else { } else {
None None
}) }).into_iter())
.append(field.options) .append_all(field.options.iter().cloned().map(Element::from).map(Node::Element).into_iter())
.append( .append_all(
field field
.values .values
.into_iter() .into_iter()
@ -168,9 +168,8 @@ impl From<Field> for Element {
.append(value) .append(value)
.build() .build()
}) })
.collect::<Vec<_>>(),
) )
.append(field.media) .append_all(field.media.iter().cloned().map(Element::from).map(Node::Element))
.build() .build()
} }
} }
@ -275,21 +274,21 @@ impl From<DataForm> for Element {
Element::builder("x") Element::builder("x")
.ns(ns::DATA_FORMS) .ns(ns::DATA_FORMS)
.attr("type", form.type_) .attr("type", form.type_)
.append( .append_all(
form.title form.title
.map(|title| Element::builder("title").ns(ns::DATA_FORMS).append(title)), .map(|title| Element::builder("title").ns(ns::DATA_FORMS).append(title)),
) )
.append(form.instructions.map(|text| { .append_all(form.instructions.map(|text| {
Element::builder("instructions") Element::builder("instructions")
.ns(ns::DATA_FORMS) .ns(ns::DATA_FORMS)
.append(text) .append(text)
})) }))
.append(if let Some(form_type) = form.form_type { .append_all((if let Some(form_type) = form.form_type {
vec![Element::builder("field").ns(ns::DATA_FORMS).attr("var", "FORM_TYPE").attr("type", "hidden").append(Element::builder("value").ns(ns::DATA_FORMS).append(form_type).build()).build()] vec![Element::builder("field").ns(ns::DATA_FORMS).attr("var", "FORM_TYPE").attr("type", "hidden").append(Element::builder("value").ns(ns::DATA_FORMS).append(form_type).build()).build()]
} else { } else {
vec![] vec![]
}) }).into_iter())
.append(form.fields) .append_all(form.fields.iter().cloned().map(Element::from).map(Node::Element))
.build() .build()
} }
} }

View file

@ -6,7 +6,7 @@
use crate::util::error::Error; use crate::util::error::Error;
use chrono::{DateTime as ChronoDateTime, FixedOffset}; use chrono::{DateTime as ChronoDateTime, FixedOffset};
use minidom::{ElementEmitter, IntoAttributeValue, IntoElements}; use minidom::{IntoAttributeValue, Node};
use std::str::FromStr; use std::str::FromStr;
/// Implements the DateTime profile of XEP-0082, which represents a /// Implements the DateTime profile of XEP-0082, which represents a
@ -46,9 +46,9 @@ impl IntoAttributeValue for DateTime {
} }
} }
impl IntoElements for DateTime { impl Into<Node> for DateTime {
fn into_elements(self, emitter: &mut ElementEmitter) { fn into(self) -> Node {
emitter.append_text_node(self.0.to_rfc3339()) Node::Text(self.0.to_rfc3339())
} }
} }

View file

@ -9,7 +9,7 @@ use crate::util::error::Error;
use crate::iq::{IqGetPayload, IqResultPayload}; use crate::iq::{IqGetPayload, IqResultPayload};
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;
use minidom::Element; use minidom::{Element, Node};
use std::convert::TryFrom; use std::convert::TryFrom;
generate_element!( generate_element!(
@ -178,9 +178,9 @@ impl From<DiscoInfoResult> for Element {
Element::builder("query") Element::builder("query")
.ns(ns::DISCO_INFO) .ns(ns::DISCO_INFO)
.attr("node", disco.node) .attr("node", disco.node)
.append(disco.identities) .append_all(disco.identities.into_iter())
.append(disco.features) .append_all(disco.features.into_iter())
.append(disco.extensions) .append_all(disco.extensions.iter().cloned().map(Element::from).map(Node::Element))
.build() .build()
} }
} }

View file

@ -8,7 +8,7 @@ use crate::data_forms::DataForm;
use crate::util::error::Error; use crate::util::error::Error;
use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload};
use crate::ns; use crate::ns;
use minidom::Element; use minidom::{Element, Node};
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryFrom; use std::convert::TryFrom;
@ -93,24 +93,23 @@ impl From<Query> for Element {
fn from(query: Query) -> Element { fn from(query: Query) -> Element {
Element::builder("query") Element::builder("query")
.ns(ns::REGISTER) .ns(ns::REGISTER)
.append(if query.registered { .append_all((if query.registered {
Some(Element::builder("registered").ns(ns::REGISTER)) Some(Element::builder("registered").ns(ns::REGISTER))
} else { } else {
None None
}) }).into_iter())
.append( .append_all(
query query
.fields .fields
.into_iter() .into_iter()
.map(|(name, value)| Element::builder(name).ns(ns::REGISTER).append(value)) .map(|(name, value)| Element::builder(name).ns(ns::REGISTER).append(value))
.collect::<Vec<_>>(),
) )
.append(if query.remove { .append_all((if query.remove {
Some(Element::builder("remove").ns(ns::REGISTER)) Some(Element::builder("remove").ns(ns::REGISTER))
} else { } else {
None None
}) }).into_iter())
.append(query.form) .append_all(query.form.map(Element::from).map(Node::Element).into_iter())
.build() .build()
} }
} }

View file

@ -8,7 +8,7 @@ use crate::util::error::Error;
use crate::iq::IqSetPayload; use crate::iq::IqSetPayload;
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;
use minidom::Element; use minidom::{Element, Node};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::str::FromStr; use std::str::FromStr;
use std::convert::TryFrom; use std::convert::TryFrom;
@ -413,14 +413,14 @@ impl From<ReasonElement> for Element {
Element::builder("reason") Element::builder("reason")
.ns(ns::JINGLE) .ns(ns::JINGLE)
.append(Element::from(reason.reason)) .append(Element::from(reason.reason))
.append( .append_all(
reason.texts.into_iter().map(|(lang, text)| { reason.texts.into_iter().map(|(lang, text)| {
Element::builder("text") Element::builder("text")
.ns(ns::JINGLE) .ns(ns::JINGLE)
.attr("xml:lang", lang) .attr("xml:lang", lang)
.append(text) .append(text)
.build() .build()
}).collect::<Vec<_>>()) }))
.build() .build()
} }
} }
@ -542,8 +542,8 @@ impl From<Jingle> for Element {
.attr("initiator", jingle.initiator) .attr("initiator", jingle.initiator)
.attr("responder", jingle.responder) .attr("responder", jingle.responder)
.attr("sid", jingle.sid) .attr("sid", jingle.sid)
.append(jingle.contents) .append_all(jingle.contents.into_iter())
.append(jingle.reason) .append_all(jingle.reason.map(Element::from).map(Node::Element).into_iter())
.build() .build()
} }
} }

View file

@ -9,7 +9,7 @@ use crate::util::error::Error;
use crate::hashes::Hash; use crate::hashes::Hash;
use crate::jingle::{ContentId, Creator}; use crate::jingle::{ContentId, Creator};
use crate::ns; use crate::ns;
use minidom::Element; use minidom::{Element, Node};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::str::FromStr; use std::str::FromStr;
use std::convert::TryFrom; use std::convert::TryFrom;
@ -196,43 +196,53 @@ impl From<File> for Element {
let mut root = Element::builder("file").ns(ns::JINGLE_FT); let mut root = Element::builder("file").ns(ns::JINGLE_FT);
if let Some(date) = file.date { if let Some(date) = file.date {
root = root.append( root = root.append(
Node::Element(
Element::builder("date") Element::builder("date")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(date) .append(date)
.build(), .build()
)
); );
} }
if let Some(media_type) = file.media_type { if let Some(media_type) = file.media_type {
root = root.append( root = root.append(
Node::Element(
Element::builder("media-type") Element::builder("media-type")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(media_type) .append(media_type)
.build(), .build()
)
); );
} }
if let Some(name) = file.name { if let Some(name) = file.name {
root = root.append( root = root.append(
Node::Element(
Element::builder("name") Element::builder("name")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(name) .append(name)
.build(), .build()
)
); );
} }
for (lang, desc) in file.descs.into_iter() { for (lang, desc) in file.descs.into_iter() {
root = root.append( root = root.append(
Node::Element(
Element::builder("desc") Element::builder("desc")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.attr("xml:lang", lang) .attr("xml:lang", lang)
.append(desc.0) .append(desc.0)
.build(), .build()
)
); );
} }
if let Some(size) = file.size { if let Some(size) = file.size {
root = root.append( root = root.append(
Node::Element(
Element::builder("size") Element::builder("size")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(format!("{}", size)) .append(format!("{}", size))
.build(), .build()
)
); );
} }
if let Some(range) = file.range { if let Some(range) = file.range {
@ -282,7 +292,7 @@ impl From<Description> for Element {
fn from(description: Description) -> Element { fn from(description: Description) -> Element {
Element::builder("description") Element::builder("description")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(description.file) .append(Node::Element(description.file.into()))
.build() .build()
} }
} }
@ -334,7 +344,7 @@ impl From<Checksum> for Element {
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.attr("name", checksum.name) .attr("name", checksum.name)
.attr("creator", checksum.creator) .attr("creator", checksum.creator)
.append(checksum.file) .append(Node::Element(checksum.file.into()))
.build() .build()
} }
} }

View file

@ -247,26 +247,31 @@ impl From<Transport> for Element {
.attr("sid", transport.sid) .attr("sid", transport.sid)
.attr("dstaddr", transport.dstaddr) .attr("dstaddr", transport.dstaddr)
.attr("mode", transport.mode) .attr("mode", transport.mode)
.append(match transport.payload { .append_all(match transport.payload {
TransportPayload::Candidates(candidates) => candidates TransportPayload::Candidates(candidates) => candidates
.into_iter() .into_iter()
.map(Element::from) .map(Element::from)
.collect::<Vec<_>>(), .collect::<Vec<_>>()
.into_iter(),
TransportPayload::Activated(cid) => vec![Element::builder("activated") TransportPayload::Activated(cid) => vec![Element::builder("activated")
.ns(ns::JINGLE_S5B) .ns(ns::JINGLE_S5B)
.attr("cid", cid) .attr("cid", cid)
.build()], .build()]
.into_iter(),
TransportPayload::CandidateError => vec![Element::builder("candidate-error") TransportPayload::CandidateError => vec![Element::builder("candidate-error")
.ns(ns::JINGLE_S5B) .ns(ns::JINGLE_S5B)
.build()], .build()]
.into_iter(),
TransportPayload::CandidateUsed(cid) => vec![Element::builder("candidate-used") TransportPayload::CandidateUsed(cid) => vec![Element::builder("candidate-used")
.ns(ns::JINGLE_S5B) .ns(ns::JINGLE_S5B)
.attr("cid", cid) .attr("cid", cid)
.build()], .build()]
TransportPayload::ProxyError => { .into_iter(),
vec![Element::builder("proxy-error").ns(ns::JINGLE_S5B).build()] TransportPayload::ProxyError => vec![Element::builder("proxy-error")
} .ns(ns::JINGLE_S5B)
TransportPayload::None => vec![], .build()]
.into_iter(),
TransportPayload::None => vec![].into_iter(),
}) })
.build() .build()
} }

View file

@ -13,7 +13,7 @@ use crate::ns;
use crate::pubsub::NodeName; use crate::pubsub::NodeName;
use crate::rsm::{SetQuery, SetResult}; use crate::rsm::{SetQuery, SetResult};
use jid::Jid; use jid::Jid;
use minidom::Element; use minidom::{Element, Node};
use std::convert::TryFrom; use std::convert::TryFrom;
generate_id!( generate_id!(
@ -161,20 +161,29 @@ impl TryFrom<Element> for Prefs {
} }
} }
fn serialise_jid_list(name: &str, jids: Vec<Jid>) -> Option<Element> { fn serialise_jid_list(name: &str, jids: Vec<Jid>) -> ::std::option::IntoIter<Node> {
if jids.is_empty() { if jids.is_empty() {
None None.into_iter()
} else { } else {
Some( Some(
Element::builder(name) Element::builder(name)
.ns(ns::MAM) .ns(ns::MAM)
.append( .append_all(
jids.into_iter() jids.into_iter()
.map(|jid| Element::builder("jid").ns(ns::MAM).append(jid).build()) .map(|jid|
.collect::<Vec<_>>(), Node::Element(
Element::builder("jid")
.ns(ns::MAM)
.append(Node::Text(String::from(jid)))
.build()
.into()
) )
.build(),
) )
.into_iter(),
)
.build()
.into(),
).into_iter()
} }
} }
@ -183,8 +192,8 @@ impl From<Prefs> for Element {
Element::builder("prefs") Element::builder("prefs")
.ns(ns::MAM) .ns(ns::MAM)
.attr("default", prefs.default_) .attr("default", prefs.default_)
.append(serialise_jid_list("always", prefs.always)) .append_all(serialise_jid_list("always", prefs.always))
.append(serialise_jid_list("never", prefs.never)) .append_all(serialise_jid_list("never", prefs.never))
.build() .build()
} }
} }

View file

@ -212,7 +212,7 @@ impl From<Message> for Element {
.attr("to", message.to) .attr("to", message.to)
.attr("id", message.id) .attr("id", message.id)
.attr("type", message.type_) .attr("type", message.type_)
.append( .append_all(
message message
.subjects .subjects
.into_iter() .into_iter()
@ -227,9 +227,8 @@ impl From<Message> for Element {
); );
subject subject
}) })
.collect::<Vec<_>>(),
) )
.append( .append_all(
message message
.bodies .bodies
.into_iter() .into_iter()
@ -244,9 +243,8 @@ impl From<Message> for Element {
); );
body body
}) })
.collect::<Vec<_>>(),
) )
.append(message.payloads) .append_all(message.payloads.into_iter())
.build() .build()
} }
} }

View file

@ -8,7 +8,7 @@
use crate::util::error::Error; use crate::util::error::Error;
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;
use minidom::{Element, ElementEmitter, IntoAttributeValue, IntoElements}; use minidom::{Element, IntoAttributeValue, Node};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::str::FromStr; use std::str::FromStr;
use std::convert::TryFrom; use std::convert::TryFrom;
@ -48,18 +48,17 @@ impl FromStr for Show {
} }
} }
impl IntoElements for Show { impl Into<Node> for Show {
fn into_elements(self, emitter: &mut ElementEmitter) { fn into(self) -> Node {
emitter.append_child(
Element::builder("show") Element::builder("show")
.append(match self { .append(match self {
Show::Away => Some("away"), Show::Away => "away",
Show::Chat => Some("chat"), Show::Chat => "chat",
Show::Dnd => Some("dnd"), Show::Dnd => "dnd",
Show::Xa => Some("xa"), Show::Xa => "xa",
}) })
.build(), .build()
) .into()
} }
} }
@ -310,8 +309,8 @@ impl From<Presence> for Element {
.attr("to", presence.to) .attr("to", presence.to)
.attr("id", presence.id) .attr("id", presence.id)
.attr("type", presence.type_) .attr("type", presence.type_)
.append(presence.show) .append_all(presence.show.into_iter())
.append( .append_all(
presence presence
.statuses .statuses
.into_iter() .into_iter()
@ -327,9 +326,8 @@ impl From<Presence> for Element {
.append(status) .append(status)
.build() .build()
}) })
.collect::<Vec<_>>(),
) )
.append(if presence.priority == 0 { .append_all((if presence.priority == 0 {
None None
} else { } else {
Some( Some(
@ -337,8 +335,8 @@ impl From<Presence> for Element {
.append(format!("{}", presence.priority)) .append(format!("{}", presence.priority))
.build() .build()
) )
}) }).into_iter())
.append(presence.payloads) .append_all(presence.payloads.into_iter())
.build() .build()
} }
} }

View file

@ -10,7 +10,7 @@ use crate::util::error::Error;
use crate::ns; use crate::ns;
use crate::pubsub::{ItemId, NodeName, Subscription, SubscriptionId, Item as PubSubItem}; use crate::pubsub::{ItemId, NodeName, Subscription, SubscriptionId, Item as PubSubItem};
use jid::Jid; use jid::Jid;
use minidom::Element; use minidom::{Element, Node};
use std::convert::TryFrom; use std::convert::TryFrom;
/// Event wrapper for a PubSub `<item/>`. /// Event wrapper for a PubSub `<item/>`.
@ -198,12 +198,12 @@ impl From<PubSubEvent> for Element {
PubSubEvent::Configuration { node, form } => Element::builder("configuration") PubSubEvent::Configuration { node, form } => Element::builder("configuration")
.ns(ns::PUBSUB_EVENT) .ns(ns::PUBSUB_EVENT)
.attr("node", node) .attr("node", node)
.append(form) .append_all(form.map(Element::from).map(Node::Element).into_iter())
.build(), .build(),
PubSubEvent::Delete { node, redirect } => Element::builder("purge") PubSubEvent::Delete { node, redirect } => Element::builder("purge")
.ns(ns::PUBSUB_EVENT) .ns(ns::PUBSUB_EVENT)
.attr("node", node) .attr("node", node)
.append(redirect.map(|redirect| { .append_all(redirect.map(|redirect| {
Element::builder("redirect") Element::builder("redirect")
.ns(ns::PUBSUB_EVENT) .ns(ns::PUBSUB_EVENT)
.attr("uri", redirect) .attr("uri", redirect)
@ -213,12 +213,12 @@ impl From<PubSubEvent> for Element {
PubSubEvent::PublishedItems { node, items } => Element::builder("items") PubSubEvent::PublishedItems { node, items } => Element::builder("items")
.ns(ns::PUBSUB_EVENT) .ns(ns::PUBSUB_EVENT)
.attr("node", node) .attr("node", node)
.append(items) .append_all(items.into_iter())
.build(), .build(),
PubSubEvent::RetractedItems { node, items } => Element::builder("items") PubSubEvent::RetractedItems { node, items } => Element::builder("items")
.ns(ns::PUBSUB_EVENT) .ns(ns::PUBSUB_EVENT)
.attr("node", node) .attr("node", node)
.append( .append_all(
items items
.into_iter() .into_iter()
.map(|id| { .map(|id| {
@ -227,7 +227,6 @@ impl From<PubSubEvent> for Element {
.attr("id", id) .attr("id", id)
.build() .build()
}) })
.collect::<Vec<_>>(),
) )
.build(), .build(),
PubSubEvent::Purge { node } => Element::builder("purge") PubSubEvent::Purge { node } => Element::builder("purge")

View file

@ -219,11 +219,11 @@ impl From<SubscribeOptions> for Element {
fn from(subscribe_options: SubscribeOptions) -> Element { fn from(subscribe_options: SubscribeOptions) -> Element {
Element::builder("subscribe-options") Element::builder("subscribe-options")
.ns(ns::PUBSUB) .ns(ns::PUBSUB)
.append(if subscribe_options.required { .append_all((if subscribe_options.required {
vec![Element::builder("required").ns(ns::PUBSUB).build()] vec![Element::builder("required").ns(ns::PUBSUB).build()]
} else { } else {
vec![] vec![]
}) }).into_iter())
.build() .build()
} }
} }
@ -473,7 +473,7 @@ impl From<PubSub> for Element {
fn from(pubsub: PubSub) -> Element { fn from(pubsub: PubSub) -> Element {
Element::builder("pubsub") Element::builder("pubsub")
.ns(ns::PUBSUB) .ns(ns::PUBSUB)
.append(match pubsub { .append_all((match pubsub {
PubSub::Create { create, configure } => { PubSub::Create { create, configure } => {
let mut elems = vec![Element::from(create)]; let mut elems = vec![Element::from(create)];
if let Some(configure) = configure { if let Some(configure) = configure {
@ -498,7 +498,7 @@ impl From<PubSub> for Element {
PubSub::Subscription(subscription) => vec![Element::from(subscription)], PubSub::Subscription(subscription) => vec![Element::from(subscription)],
PubSub::Subscriptions(subscriptions) => vec![Element::from(subscriptions)], PubSub::Subscriptions(subscriptions) => vec![Element::from(subscriptions)],
PubSub::Unsubscribe(unsubscribe) => vec![Element::from(unsubscribe)], PubSub::Unsubscribe(unsubscribe) => vec![Element::from(unsubscribe)],
}) }).into_iter())
.build() .build()
} }
} }

View file

@ -6,7 +6,7 @@
use crate::util::error::Error; use crate::util::error::Error;
use crate::ns; use crate::ns;
use minidom::Element; use minidom::{Element, Node};
use std::convert::TryFrom; use std::convert::TryFrom;
/// Requests paging through a potentially big set of items (represented by an /// Requests paging through a potentially big set of items (represented by an
@ -72,23 +72,23 @@ impl From<SetQuery> for Element {
fn from(set: SetQuery) -> Element { fn from(set: SetQuery) -> Element {
Element::builder("set") Element::builder("set")
.ns(ns::RSM) .ns(ns::RSM)
.append(set.max.map(|max| { .append_all(set.max.map(|max| {
Element::builder("max") Element::builder("max")
.ns(ns::RSM) .ns(ns::RSM)
.append(format!("{}", max)) .append(format!("{}", max))
.build() .build()
})) }))
.append( .append_all(
set.after set.after
.map(|after| Element::builder("after").ns(ns::RSM).append(after).build()), .map(|after| Element::builder("after").ns(ns::RSM).append(after).build()),
) )
.append(set.before.map(|before| { .append_all(set.before.map(|before| {
Element::builder("before") Element::builder("before")
.ns(ns::RSM) .ns(ns::RSM)
.append(before) .append(before)
.build() .build()
})) }))
.append(set.index.map(|index| { .append_all(set.index.map(|index| {
Element::builder("index") Element::builder("index")
.ns(ns::RSM) .ns(ns::RSM)
.append(format!("{}", index)) .append(format!("{}", index))
@ -162,12 +162,12 @@ impl From<SetResult> for Element {
}); });
Element::builder("set") Element::builder("set")
.ns(ns::RSM) .ns(ns::RSM)
.append(first) .append_all(first.map(Element::from).map(Node::Element).into_iter())
.append( .append_all(
set.last set.last
.map(|last| Element::builder("last").ns(ns::RSM).append(last).build()), .map(|last| Element::builder("last").ns(ns::RSM).append(last).build()),
) )
.append(set.count.map(|count| { .append_all(set.count.map(|count| {
Element::builder("count") Element::builder("count")
.ns(ns::RSM) .ns(ns::RSM)
.append(format!("{}", count)) .append(format!("{}", count))

View file

@ -203,7 +203,7 @@ impl From<Failure> for Element {
Element::builder("failure") Element::builder("failure")
.ns(ns::SASL) .ns(ns::SASL)
.append(failure.defined_condition) .append(failure.defined_condition)
.append( .append_all(
failure failure
.texts .texts
.into_iter() .into_iter()
@ -214,7 +214,6 @@ impl From<Failure> for Element {
.append(text) .append(text)
.build() .build()
}) })
.collect::<Vec<_>>(),
) )
.build() .build()
} }

View file

@ -9,7 +9,7 @@ use crate::message::MessagePayload;
use crate::ns; use crate::ns;
use crate::presence::PresencePayload; use crate::presence::PresencePayload;
use jid::Jid; use jid::Jid;
use minidom::Element; use minidom::{Element, Node};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::convert::TryFrom; use std::convert::TryFrom;
@ -294,15 +294,16 @@ impl From<StanzaError> for Element {
.attr("type", err.type_) .attr("type", err.type_)
.attr("by", err.by) .attr("by", err.by)
.append(err.defined_condition) .append(err.defined_condition)
.append( .append_all(
err.texts.into_iter().map(|(lang, text)| { err.texts.into_iter().map(|(lang, text)| {
Element::builder("text") Element::builder("text")
.ns(ns::XMPP_STANZAS) .ns(ns::XMPP_STANZAS)
.attr("xml:lang", lang) .attr("xml:lang", lang)
.append(text) .append(text)
.build() .build()
}).collect::<Vec<_>>()) })
.append(err.other) )
.append_all(err.other.map(Element::from).map(Node::Element).into_iter())
.build() .build()
} }
} }

View file

@ -149,13 +149,13 @@ impl From<Tune> for Element {
fn from(tune: Tune) -> Element { fn from(tune: Tune) -> Element {
Element::builder("tune") Element::builder("tune")
.ns(ns::TUNE) .ns(ns::TUNE)
.append(tune.artist) .append_all(tune.artist)
.append(tune.length) .append_all(tune.length)
.append(tune.rating) .append_all(tune.rating)
.append(tune.source) .append_all(tune.source)
.append(tune.title) .append_all(tune.title)
.append(tune.track) .append_all(tune.track)
.append(tune.uri) .append_all(tune.uri)
.build() .build()
} }
} }

View file

@ -34,8 +34,8 @@ impl TrimmedPlainText {
}) })
} }
pub fn encode(string: &str) -> String { pub fn encode(string: &str) -> Option<String> {
string.to_owned() Some(string.to_owned())
} }
} }

View file

@ -253,6 +253,11 @@ macro_rules! generate_element_enum {
.build() .build()
} }
} }
impl From<$elem> for ::minidom::Node {
fn from(elem: $elem) -> ::minidom::Node {
::minidom::Node::Element(elem.into())
}
}
); );
} }
@ -291,6 +296,11 @@ macro_rules! generate_attribute_enum {
.build() .build()
} }
} }
impl From<$elem> for ::minidom::Node {
fn from(elem: $elem) -> ::minidom::Node {
::minidom::Node::Element(elem.into())
}
}
); );
} }
@ -385,6 +395,12 @@ macro_rules! generate_empty_element {
.build() .build()
} }
} }
impl From<$elem> for ::minidom::Node {
fn from(elem: $elem) -> ::minidom::Node {
::minidom::Node::Element(elem.into())
}
}
); );
} }
@ -441,6 +457,12 @@ macro_rules! generate_elem_id {
.build() .build()
} }
} }
impl From<$elem> for ::minidom::Node {
fn from(elem: $elem) -> ::minidom::Node {
::minidom::Node::Element(elem.into())
}
}
); );
} }
@ -547,22 +569,38 @@ macro_rules! finish_parse_elem {
} }
macro_rules! generate_serialiser { macro_rules! generate_serialiser {
($parent:ident, $elem:ident, Required, String, ($name:tt, $ns:ident)) => { ($builder:ident, $parent:ident, $elem:ident, Required, String, ($name:tt, $ns:ident)) => {
$builder.append(::minidom::Node::Element(
::minidom::Element::builder($name) ::minidom::Element::builder($name)
.ns(crate::ns::$ns) .ns(crate::ns::$ns)
.append($parent.$elem) .append(::minidom::Node::Text($parent.$elem))
.build() .build()
)
)
}; };
($parent:ident, $elem:ident, Option, String, ($name:tt, $ns:ident)) => { ($builder:ident, $parent:ident, $elem:ident, Option, String, ($name:tt, $ns:ident)) => {
$parent.$elem.map(|elem| { $builder.append_all($parent.$elem.map(|elem| {
::minidom::Element::builder($name) ::minidom::Element::builder($name)
.ns(crate::ns::$ns) .ns(crate::ns::$ns)
.append(elem) .append(::minidom::Node::Text(elem))
.build() .build()
}) }).into_iter()
)
}; };
($parent:ident, $elem:ident, $_:ident, $constructor:ident, ($name:tt, $ns:ident)) => { ($builder:ident, $parent:ident, $elem:ident, Option, $constructor:ident, ($name:tt, $ns:ident)) => {
$parent.$elem $builder.append_all($parent.$elem.map(|elem| {
::minidom::Element::builder($name)
.ns(crate::ns::$ns)
.append(::minidom::Node::Element(::minidom::Element::from(elem)))
.build()
}).into_iter()
)
};
($builder:ident, $parent:ident, $elem:ident, Vec, $constructor:ident, ($name:tt, $ns:ident)) => {
$builder.append_all($parent.$elem.into_iter())
};
($builder:ident, $parent:ident, $elem:ident, $_:ident, $constructor:ident, ($name:tt, $ns:ident)) => {
$builder.append(::minidom::Node::Element(::minidom::Element::from($parent.$elem)))
}; };
} }
@ -637,18 +675,25 @@ macro_rules! generate_element {
impl From<$elem> for ::minidom::Element { impl From<$elem> for ::minidom::Element {
fn from(elem: $elem) -> ::minidom::Element { fn from(elem: $elem) -> ::minidom::Element {
::minidom::Element::builder($name) let mut builder = ::minidom::Element::builder($name)
.ns(crate::ns::$ns) .ns(crate::ns::$ns);
$( $(
.attr($attr_name, elem.$attr) builder = builder.attr($attr_name, elem.$attr);
)* )*
$( $(
.append(generate_serialiser!(elem, $child_ident, $coucou, $child_constructor, ($child_name, $child_ns))) builder = generate_serialiser!(builder, elem, $child_ident, $coucou, $child_constructor, ($child_name, $child_ns));
)* )*
$( $(
.append($codec::encode(&elem.$text_ident)) builder = builder.append_all($codec::encode(&elem.$text_ident).map(::minidom::Node::Text).into_iter());
)* )*
.build()
builder.build()
}
}
impl From<$elem> for ::minidom::Node {
fn from(elem: $elem) -> ::minidom::Node {
::minidom::Node::Element(elem.into())
} }
} }
); );
@ -691,11 +736,17 @@ macro_rules! impl_pubsub_item {
.ns(ns::$ns) .ns(ns::$ns)
.attr("id", item.0.id) .attr("id", item.0.id)
.attr("publisher", item.0.publisher) .attr("publisher", item.0.publisher)
.append(item.0.payload) .append_all(item.0.payload.map(::minidom::Node::Element).into_iter())
.build() .build()
} }
} }
impl From<$item> for ::minidom::Node {
fn from(item: $item) -> ::minidom::Node {
::minidom::Node::Element(item.into())
}
}
impl ::std::ops::Deref for $item { impl ::std::ops::Deref for $item {
type Target = crate::pubsub::Item; type Target = crate::pubsub::Item;

View file

@ -98,14 +98,14 @@ impl From<XhtmlIm> for Element {
fn from(wrapper: XhtmlIm) -> Element { fn from(wrapper: XhtmlIm) -> Element {
Element::builder("html") Element::builder("html")
.ns(ns::XHTML_IM) .ns(ns::XHTML_IM)
.append(wrapper.bodies.into_iter().map(|(ref lang, ref body)| { .append_all(wrapper.bodies.into_iter().map(|(ref lang, ref body)| {
if lang.is_empty() { if lang.is_empty() {
assert!(body.xml_lang.is_none()); assert!(body.xml_lang.is_none());
} else { } else {
assert_eq!(Some(lang), body.xml_lang.as_ref()); assert_eq!(Some(lang), body.xml_lang.as_ref());
} }
Element::from(body.clone()) Element::from(body.clone())
}).collect::<Vec<_>>()) }))
.build() .build()
} }
} }
@ -174,7 +174,7 @@ impl From<Body> for Element {
.ns(ns::XHTML) .ns(ns::XHTML)
.attr("style", get_style_string(body.style)) .attr("style", get_style_string(body.style))
.attr("xml:lang", body.xml_lang) .attr("xml:lang", body.xml_lang)
.append(children_to_nodes(body.children)) .append_all(children_to_nodes(body.children))
.build() .build()
} }
} }
@ -338,7 +338,7 @@ impl From<Tag> for Element {
}; };
let mut builder = Element::builder(name) let mut builder = Element::builder(name)
.ns(ns::XHTML) .ns(ns::XHTML)
.append(children_to_nodes(children)); .append_all(children_to_nodes(children));
for (key, value) in attrs { for (key, value) in attrs {
builder = builder.attr(key, value); builder = builder.attr(key, value);
} }