mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Use check_no_children!() where it makes sense.
This commit is contained in:
parent
93b018e5ac
commit
3d495ccf41
6 changed files with 13 additions and 37 deletions
|
@ -33,9 +33,7 @@ fn get_sid(elem: Element) -> Result<SessionId, Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_empty_and_get_sid(elem: Element) -> Result<SessionId, Error> {
|
fn check_empty_and_get_sid(elem: Element) -> Result<SessionId, Error> {
|
||||||
for _ in elem.children() {
|
check_no_children!(elem, "Jingle message");
|
||||||
return Err(Error::ParseError("Unknown child in Jingle message element."));
|
|
||||||
}
|
|
||||||
get_sid(elem)
|
get_sid(elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,18 +199,14 @@ impl TryFrom<Element> for Message {
|
||||||
let mut payloads = vec!();
|
let mut payloads = vec!();
|
||||||
for elem in root.children() {
|
for elem in root.children() {
|
||||||
if elem.is("body", ns::DEFAULT_NS) {
|
if elem.is("body", ns::DEFAULT_NS) {
|
||||||
for _ in elem.children() {
|
check_no_children!(elem, "body");
|
||||||
return Err(Error::ParseError("Unknown child in body element."));
|
|
||||||
}
|
|
||||||
let lang = get_attr!(elem, "xml:lang", default);
|
let lang = get_attr!(elem, "xml:lang", default);
|
||||||
let body = Body(elem.text());
|
let body = Body(elem.text());
|
||||||
if bodies.insert(lang, body).is_some() {
|
if bodies.insert(lang, body).is_some() {
|
||||||
return Err(Error::ParseError("Body element present twice for the same xml:lang."));
|
return Err(Error::ParseError("Body element present twice for the same xml:lang."));
|
||||||
}
|
}
|
||||||
} else if elem.is("subject", ns::DEFAULT_NS) {
|
} else if elem.is("subject", ns::DEFAULT_NS) {
|
||||||
for _ in elem.children() {
|
check_no_children!(elem, "subject");
|
||||||
return Err(Error::ParseError("Unknown child in subject element."));
|
|
||||||
}
|
|
||||||
let lang = get_attr!(elem, "xml:lang", default);
|
let lang = get_attr!(elem, "xml:lang", default);
|
||||||
let subject = Subject(elem.text());
|
let subject = Subject(elem.text());
|
||||||
if subjects.insert(lang, subject).is_some() {
|
if subjects.insert(lang, subject).is_some() {
|
||||||
|
@ -220,9 +216,7 @@ impl TryFrom<Element> for Message {
|
||||||
if thread.is_some() {
|
if thread.is_some() {
|
||||||
return Err(Error::ParseError("Thread element present twice."));
|
return Err(Error::ParseError("Thread element present twice."));
|
||||||
}
|
}
|
||||||
for _ in elem.children() {
|
check_no_children!(elem, "thread");
|
||||||
return Err(Error::ParseError("Unknown child in thread element."));
|
|
||||||
}
|
|
||||||
thread = Some(Thread(elem.text()));
|
thread = Some(Thread(elem.text()));
|
||||||
} else {
|
} else {
|
||||||
payloads.push(elem.clone())
|
payloads.push(elem.clone())
|
||||||
|
|
|
@ -94,9 +94,7 @@ impl TryFrom<Element> for Actor {
|
||||||
fn try_from(elem: Element) -> Result<Actor, Error> {
|
fn try_from(elem: Element) -> Result<Actor, Error> {
|
||||||
check_self!(elem, "actor", MUC_USER);
|
check_self!(elem, "actor", MUC_USER);
|
||||||
check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]);
|
check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]);
|
||||||
for _ in elem.children() {
|
check_no_children!(elem, "actor");
|
||||||
return Err(Error::ParseError("Unknown child in actor element."));
|
|
||||||
}
|
|
||||||
let jid: Option<Jid> = get_attr!(elem, "jid", optional);
|
let jid: Option<Jid> = get_attr!(elem, "jid", optional);
|
||||||
let nick = get_attr!(elem, "nick", optional);
|
let nick = get_attr!(elem, "nick", optional);
|
||||||
|
|
||||||
|
|
|
@ -267,15 +267,11 @@ impl TryFrom<Element> for Presence {
|
||||||
return Err(Error::ParseError("More than one show element in a presence."));
|
return Err(Error::ParseError("More than one show element in a presence."));
|
||||||
}
|
}
|
||||||
check_no_attributes!(elem, "show");
|
check_no_attributes!(elem, "show");
|
||||||
for _ in elem.children() {
|
check_no_children!(elem, "show");
|
||||||
return Err(Error::ParseError("Unknown child in show element."));
|
|
||||||
}
|
|
||||||
show = Some(Show::from_str(elem.text().as_ref())?);
|
show = Some(Show::from_str(elem.text().as_ref())?);
|
||||||
} else if elem.is("status", ns::DEFAULT_NS) {
|
} else if elem.is("status", ns::DEFAULT_NS) {
|
||||||
check_no_unknown_attributes!(elem, "status", ["xml:lang"]);
|
check_no_unknown_attributes!(elem, "status", ["xml:lang"]);
|
||||||
for _ in elem.children() {
|
check_no_children!(elem, "status");
|
||||||
return Err(Error::ParseError("Unknown child in status element."));
|
|
||||||
}
|
|
||||||
let lang = get_attr!(elem, "xml:lang", default);
|
let lang = get_attr!(elem, "xml:lang", default);
|
||||||
if presence.statuses.insert(lang, elem.text()).is_some() {
|
if presence.statuses.insert(lang, elem.text()).is_some() {
|
||||||
return Err(Error::ParseError("Status element present twice for the same xml:lang."));
|
return Err(Error::ParseError("Status element present twice for the same xml:lang."));
|
||||||
|
@ -284,10 +280,8 @@ impl TryFrom<Element> for Presence {
|
||||||
if priority.is_some() {
|
if priority.is_some() {
|
||||||
return Err(Error::ParseError("More than one priority element in a presence."));
|
return Err(Error::ParseError("More than one priority element in a presence."));
|
||||||
}
|
}
|
||||||
check_no_attributes!(elem, "status");
|
check_no_attributes!(elem, "priority");
|
||||||
for _ in elem.children() {
|
check_no_children!(elem, "priority");
|
||||||
return Err(Error::ParseError("Unknown child in priority element."));
|
|
||||||
}
|
|
||||||
priority = Some(Priority::from_str(elem.text().as_ref())?);
|
priority = Some(Priority::from_str(elem.text().as_ref())?);
|
||||||
} else {
|
} else {
|
||||||
presence.payloads.push(elem.clone());
|
presence.payloads.push(elem.clone());
|
||||||
|
|
|
@ -175,14 +175,10 @@ impl TryFrom<Element> for PubSubEvent {
|
||||||
} else if child.is("items", ns::PUBSUB_EVENT) {
|
} else if child.is("items", ns::PUBSUB_EVENT) {
|
||||||
payload = Some(parse_items(child.clone(), node)?);
|
payload = Some(parse_items(child.clone(), node)?);
|
||||||
} else if child.is("purge", ns::PUBSUB_EVENT) {
|
} else if child.is("purge", ns::PUBSUB_EVENT) {
|
||||||
for _ in child.children() {
|
check_no_children!(child, "purge");
|
||||||
return Err(Error::ParseError("Unknown child in purge element."));
|
|
||||||
}
|
|
||||||
payload = Some(PubSubEvent::Purge { node });
|
payload = Some(PubSubEvent::Purge { node });
|
||||||
} else if child.is("subscription", ns::PUBSUB_EVENT) {
|
} else if child.is("subscription", ns::PUBSUB_EVENT) {
|
||||||
for _ in child.children() {
|
check_no_children!(child, "subscription");
|
||||||
return Err(Error::ParseError("Unknown child in purge element."));
|
|
||||||
}
|
|
||||||
payload = Some(PubSubEvent::Subscription {
|
payload = Some(PubSubEvent::Subscription {
|
||||||
node: node,
|
node: node,
|
||||||
expiry: get_attr!(child, "expiry", optional),
|
expiry: get_attr!(child, "expiry", optional),
|
||||||
|
|
|
@ -71,9 +71,7 @@ impl TryFrom<Element> for StanzaError {
|
||||||
|
|
||||||
for child in elem.children() {
|
for child in elem.children() {
|
||||||
if child.is("text", ns::XMPP_STANZAS) {
|
if child.is("text", ns::XMPP_STANZAS) {
|
||||||
for _ in child.children() {
|
check_no_children!(child, "text");
|
||||||
return Err(Error::ParseError("Unknown element in error text."));
|
|
||||||
}
|
|
||||||
let lang = get_attr!(elem, "xml:lang", default);
|
let lang = get_attr!(elem, "xml:lang", default);
|
||||||
if texts.insert(lang, child.text()).is_some() {
|
if texts.insert(lang, child.text()).is_some() {
|
||||||
return Err(Error::ParseError("Text element present twice for the same xml:lang."));
|
return Err(Error::ParseError("Text element present twice for the same xml:lang."));
|
||||||
|
@ -82,9 +80,7 @@ impl TryFrom<Element> for StanzaError {
|
||||||
if defined_condition.is_some() {
|
if defined_condition.is_some() {
|
||||||
return Err(Error::ParseError("Error must not have more than one defined-condition."));
|
return Err(Error::ParseError("Error must not have more than one defined-condition."));
|
||||||
}
|
}
|
||||||
for _ in child.children() {
|
check_no_children!(child, "defined-condition");
|
||||||
return Err(Error::ParseError("Unknown element in defined-condition."));
|
|
||||||
}
|
|
||||||
let condition = DefinedCondition::try_from(child.clone())?;
|
let condition = DefinedCondition::try_from(child.clone())?;
|
||||||
defined_condition = Some(condition);
|
defined_condition = Some(condition);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue