jingle_message, muc, presence, version: Always use the check_no_attributes macro.

This commit is contained in:
Emmanuel Gil Peyrot 2018-05-12 17:59:04 +02:00
commit e0438f9b88
5 changed files with 9 additions and 37 deletions

View file

@ -25,6 +25,7 @@ impl TryFrom<Element> for Muc {
if !elem.is("x", ns::MUC) {
return Err(Error::ParseError("This is not an x element."));
}
check_no_attributes!(elem, "x");
let mut password = None;
for child in elem.children() {
@ -35,10 +36,6 @@ impl TryFrom<Element> for Muc {
}
}
for _ in elem.attrs() {
return Err(Error::ParseError("Unknown attribute in x element."));
}
Ok(Muc {
password: password,
})

View file

@ -96,14 +96,10 @@ impl TryFrom<Element> for Actor {
if !elem.is("actor", ns::MUC_USER) {
return Err(Error::ParseError("This is not a actor element."));
}
check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]);
for _ in elem.children() {
return Err(Error::ParseError("Unknown child in actor element."));
}
for (attr, _) in elem.attrs() {
if attr != "jid" && attr != "nick" {
return Err(Error::ParseError("Unknown attribute in actor element."));
}
}
let jid: Option<Jid> = get_attr!(elem, "jid", optional);
let nick = get_attr!(elem, "nick", optional);
@ -167,6 +163,7 @@ impl TryFrom<Element> for Item {
if !elem.is("item", ns::MUC_USER) {
return Err(Error::ParseError("This is not a item element."));
}
check_no_unknown_attributes!(elem, "item", ["affiliation", "jid", "nick", "role"]);
let mut actor: Option<Actor> = None;
let mut continue_: Option<Continue> = None;
let mut reason: Option<Reason> = None;
@ -181,12 +178,6 @@ impl TryFrom<Element> for Item {
return Err(Error::ParseError("Unknown child in item element."));
}
}
for (attr, _) in elem.attrs() {
if attr != "affiliation" && attr != "jid" &&
attr != "nick" && attr != "role" {
return Err(Error::ParseError("Unknown attribute in item element."));
}
}
let affiliation: Affiliation = get_attr!(elem, "affiliation", required);
let jid: Option<Jid> = get_attr!(elem, "jid", optional);
@ -233,6 +224,7 @@ impl TryFrom<Element> for MucUser {
if !elem.is("x", ns::MUC_USER) {
return Err(Error::ParseError("This is not an x element."));
}
check_no_attributes!(elem, "x");
let mut status = vec!();
let mut items = vec!();
for child in elem.children() {
@ -244,9 +236,6 @@ impl TryFrom<Element> for MucUser {
return Err(Error::ParseError("Unknown child in x element."));
}
}
for _ in elem.attrs() {
return Err(Error::ParseError("Unknown attribute in x element."));
}
Ok(MucUser {
status,
items,