Use minidom 0.6.1’s Element::has_ns(), to simplify namespace comparisons.

This commit is contained in:
Emmanuel Gil Peyrot 2017-08-27 01:04:56 +01:00
parent c853a1ff4b
commit f69f567448
4 changed files with 4 additions and 8 deletions

View file

@ -38,8 +38,7 @@ impl TryFrom<Element> for ChatState {
type Err = Error; type Err = Error;
fn try_from(elem: Element) -> Result<ChatState, Error> { fn try_from(elem: Element) -> Result<ChatState, Error> {
let ns = elem.ns(); if !elem.has_ns(ns::CHATSTATES) {
if ns.as_ref().map(|ns| ns.as_str()) != Some(ns::CHATSTATES) {
return Err(Error::ParseError("This is not a chatstate element.")); return Err(Error::ParseError("This is not a chatstate element."));
} }
for _ in elem.children() { for _ in elem.children() {

View file

@ -208,8 +208,7 @@ impl TryFrom<Element> for ReasonElement {
let mut reason = None; let mut reason = None;
let mut text = None; let mut text = None;
for child in elem.children() { for child in elem.children() {
let child_ns = child.ns(); if !child.has_ns(ns::JINGLE) {
if child_ns.as_ref().map(|ns| ns.as_str()) != Some(ns::JINGLE) {
return Err(Error::ParseError("Reason contains a foreign element.")); return Err(Error::ParseError("Reason contains a foreign element."));
} }
match child.name() { match child.name() {

View file

@ -47,8 +47,7 @@ impl TryFrom<Element> for JingleMI {
type Err = Error; type Err = Error;
fn try_from(elem: Element) -> Result<JingleMI, Error> { fn try_from(elem: Element) -> Result<JingleMI, Error> {
let ns = elem.ns(); if !elem.has_ns(ns::JINGLE_MESSAGE) {
if ns.as_ref().map(|ns| ns.as_str()) != Some(ns::JINGLE_MESSAGE) {
return Err(Error::ParseError("This is not a Jingle message element.")); return Err(Error::ParseError("This is not a Jingle message element."));
} }
Ok(match elem.name() { Ok(match elem.name() {

View file

@ -136,7 +136,6 @@ impl TryFrom<Element> for StanzaError {
let mut other = None; let mut other = None;
for child in elem.children() { for child in elem.children() {
let child_ns = child.ns();
if child.is("text", ns::XMPP_STANZAS) { if child.is("text", ns::XMPP_STANZAS) {
for _ in child.children() { for _ in child.children() {
return Err(Error::ParseError("Unknown element in error text.")); return Err(Error::ParseError("Unknown element in error text."));
@ -145,7 +144,7 @@ impl TryFrom<Element> for StanzaError {
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."));
} }
} else if child_ns.as_ref().map(|ns| ns.as_str()) == Some(ns::XMPP_STANZAS) { } else if child.has_ns(ns::XMPP_STANZAS) {
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."));
} }