jingle, jingle_s5b: Add missing checks for unknown attributes and children.

This commit is contained in:
Emmanuel Gil Peyrot 2018-05-15 01:47:12 +02:00
parent 71dc5ad6c8
commit f52c28fb35
2 changed files with 5 additions and 0 deletions

View file

@ -120,6 +120,7 @@ impl TryFrom<Element> for Content {
fn try_from(elem: Element) -> Result<Content, Error> { fn try_from(elem: Element) -> Result<Content, Error> {
check_self!(elem, "content", JINGLE); check_self!(elem, "content", JINGLE);
check_no_unknown_attributes!(elem, "content", ["creator", "disposition", "name", "senders"]);
let mut content = Content { let mut content = Content {
creator: get_attr!(elem, "creator", required), creator: get_attr!(elem, "creator", required),
@ -146,6 +147,8 @@ impl TryFrom<Element> for Content {
return Err(Error::ParseError("Content must not have more than one security.")); return Err(Error::ParseError("Content must not have more than one security."));
} }
content.security = Some(child.clone()); content.security = Some(child.clone());
} else {
return Err(Error::ParseError("Unknown child in content element."));
} }
} }
Ok(content) Ok(content)
@ -341,6 +344,7 @@ impl TryFrom<Element> for Jingle {
fn try_from(root: Element) -> Result<Jingle, Error> { fn try_from(root: Element) -> Result<Jingle, Error> {
check_self!(root, "jingle", JINGLE, "Jingle"); check_self!(root, "jingle", JINGLE, "Jingle");
check_no_unknown_attributes!(root, "Jingle", ["action", "initiator", "responder", "sid"]);
let mut jingle = Jingle { let mut jingle = Jingle {
action: get_attr!(root, "action", required), action: get_attr!(root, "action", required),

View file

@ -111,6 +111,7 @@ impl TryFrom<Element> for Transport {
fn try_from(elem: Element) -> Result<Transport, Error> { fn try_from(elem: Element) -> Result<Transport, Error> {
check_self!(elem, "transport", JINGLE_S5B); check_self!(elem, "transport", JINGLE_S5B);
check_no_unknown_attributes!(elem, "transport", ["sid", "dstaddr", "mode"]);
let sid = get_attr!(elem, "sid", required); let sid = get_attr!(elem, "sid", required);
let dstaddr = get_attr!(elem, "dstaddr", optional); let dstaddr = get_attr!(elem, "dstaddr", optional);
let mode = get_attr!(elem, "mode", default); let mode = get_attr!(elem, "mode", default);