diff --git a/src/body.rs b/src/body.rs
index 7c5fcae4..64624695 100644
--- a/src/body.rs
+++ b/src/body.rs
@@ -2,8 +2,7 @@ use minidom::Element;
use error::Error;
-// TODO: also support components and servers.
-use ns::JABBER_CLIENT_NS;
+use ns;
#[derive(Debug)]
pub struct Body {
@@ -11,7 +10,8 @@ pub struct Body {
}
pub fn parse_body(root: &Element) -> Result
{
- if !root.is("body", JABBER_CLIENT_NS) {
+ // TODO: also support components and servers.
+ if !root.is("body", ns::JABBER_CLIENT) {
return Err(Error::ParseError("This is not a body element."));
}
for _ in root.children() {
diff --git a/src/chatstates.rs b/src/chatstates.rs
index 1651e3a5..5a9a4dc4 100644
--- a/src/chatstates.rs
+++ b/src/chatstates.rs
@@ -2,7 +2,7 @@ use minidom::Element;
use error::Error;
-use ns::CHATSTATES_NS;
+use ns;
#[derive(Debug)]
pub enum ChatState {
@@ -17,15 +17,15 @@ pub fn parse_chatstate(root: &Element) -> Result {
for _ in root.children() {
return Err(Error::ParseError("Unknown child in chatstate element."));
}
- if root.is("active", CHATSTATES_NS) {
+ if root.is("active", ns::CHATSTATES) {
Ok(ChatState::Active)
- } else if root.is("composing", CHATSTATES_NS) {
+ } else if root.is("composing", ns::CHATSTATES) {
Ok(ChatState::Composing)
- } else if root.is("gone", CHATSTATES_NS) {
+ } else if root.is("gone", ns::CHATSTATES) {
Ok(ChatState::Gone)
- } else if root.is("inactive", CHATSTATES_NS) {
+ } else if root.is("inactive", ns::CHATSTATES) {
Ok(ChatState::Inactive)
- } else if root.is("paused", CHATSTATES_NS) {
+ } else if root.is("paused", ns::CHATSTATES) {
Ok(ChatState::Paused)
} else {
Err(Error::ParseError("This is not a chatstate element."))
diff --git a/src/data_forms.rs b/src/data_forms.rs
index 342c0c45..4ea50c96 100644
--- a/src/data_forms.rs
+++ b/src/data_forms.rs
@@ -5,7 +5,7 @@ use std::str::FromStr;
use minidom::Element;
use error::Error;
-use ns::{DATA_FORMS_NS, MEDIA_ELEMENT_NS};
+use ns;
use media_element::{MediaElement, parse_media_element};
@@ -52,7 +52,7 @@ pub struct DataForm {
}
pub fn parse_data_form(root: &Element) -> Result {
- if !root.is("x", DATA_FORMS_NS) {
+ if !root.is("x", ns::DATA_FORMS) {
return Err(Error::ParseError("This is not a data form element."));
}
@@ -63,16 +63,16 @@ pub fn parse_data_form(root: &Element) -> Result {
let mut fields = vec!();
let mut form_type = None;
for field in root.children() {
- if field.is("field", DATA_FORMS_NS) {
+ if field.is("field", ns::DATA_FORMS) {
let var = field.attr("var").ok_or(Error::ParseError("Field must have a 'var' attribute."))?;
let field_type = field.attr("type").unwrap_or("text-single");
let label = field.attr("label").and_then(|label| label.parse().ok());
let mut values = vec!();
let mut media = vec!();
for element in field.children() {
- if element.is("value", DATA_FORMS_NS) {
+ if element.is("value", ns::DATA_FORMS) {
values.push(element.text());
- } else if element.is("media", MEDIA_ELEMENT_NS) {
+ } else if element.is("media", ns::MEDIA_ELEMENT) {
match parse_media_element(element) {
Ok(media_element) => media.push(media_element),
Err(_) => (), // TODO: is it really nice to swallow this error?
diff --git a/src/disco.rs b/src/disco.rs
index 4b2d0334..39befce5 100644
--- a/src/disco.rs
+++ b/src/disco.rs
@@ -3,7 +3,7 @@ extern crate minidom;
use minidom::Element;
use error::Error;
-use ns::{DISCO_INFO_NS, DATA_FORMS_NS};
+use ns;
use data_forms::{DataForm, DataFormType, parse_data_form};
@@ -29,7 +29,7 @@ pub struct Disco {
}
pub fn parse_disco(root: &Element) -> Result {
- if !root.is("query", DISCO_INFO_NS) {
+ if !root.is("query", ns::DISCO_INFO) {
return Err(Error::ParseError("This is not a disco#info element."));
}
@@ -41,13 +41,13 @@ pub fn parse_disco(root: &Element) -> Result {
.and_then(|node| node.parse().ok());
for child in root.children() {
- if child.is("feature", DISCO_INFO_NS) {
+ if child.is("feature", ns::DISCO_INFO) {
let feature = child.attr("var")
.ok_or(Error::ParseError("Feature must have a 'var' attribute."))?;
features.push(Feature {
var: feature.to_owned(),
});
- } else if child.is("identity", DISCO_INFO_NS) {
+ } else if child.is("identity", ns::DISCO_INFO) {
let category = child.attr("category")
.ok_or(Error::ParseError("Identity must have a 'category' attribute."))?;
if category == "" {
@@ -70,7 +70,7 @@ pub fn parse_disco(root: &Element) -> Result {
xml_lang: xml_lang.to_owned(),
name: name,
});
- } else if child.is("x", DATA_FORMS_NS) {
+ } else if child.is("x", ns::DATA_FORMS) {
let data_form = parse_data_form(child)?;
match data_form.type_ {
DataFormType::Result_ => (),
@@ -93,7 +93,7 @@ pub fn parse_disco(root: &Element) -> Result {
if features.is_empty() {
return Err(Error::ParseError("There must be at least one feature in disco#info."));
}
- if !features.contains(&Feature { var: DISCO_INFO_NS.to_owned() }) {
+ if !features.contains(&Feature { var: ns::DISCO_INFO.to_owned() }) {
return Err(Error::ParseError("disco#info feature not present in disco#info."));
}
*/
@@ -108,12 +108,12 @@ pub fn parse_disco(root: &Element) -> Result {
pub fn serialise_disco(disco: &Disco) -> Element {
let mut root = Element::builder("query")
- .ns(DISCO_INFO_NS)
+ .ns(ns::DISCO_INFO)
.attr("node", disco.node.clone())
.build();
for identity in &disco.identities {
let identity_element = Element::builder("identity")
- .ns(DISCO_INFO_NS)
+ .ns(ns::DISCO_INFO)
.attr("category", identity.category.clone())
.attr("type", identity.type_.clone())
.attr("xml:lang", identity.xml_lang.clone())
@@ -123,7 +123,7 @@ pub fn serialise_disco(disco: &Disco) -> Element {
}
for feature in &disco.features {
let feature_element = Element::builder("feature")
- .ns(DISCO_INFO_NS)
+ .ns(ns::DISCO_INFO)
.attr("var", feature.var.clone())
.build();
root.append_child(feature_element);
diff --git a/src/ibb.rs b/src/ibb.rs
index 64363c35..fb368a56 100644
--- a/src/ibb.rs
+++ b/src/ibb.rs
@@ -4,7 +4,7 @@ use minidom::Element;
use error::Error;
-use ns::IBB_NS;
+use ns;
#[derive(Debug)]
pub enum Stanza {
@@ -49,7 +49,7 @@ fn required_attr(root: &Element, attr: &str, err: Error) -> Result Result {
- if root.is("open", IBB_NS) {
+ if root.is("open", ns::IBB) {
let block_size = required_attr(root, "block-size", Error::ParseError("Required attribute 'block-size' missing in open element."))?;
let sid = required_attr(root, "sid", Error::ParseError("Required attribute 'sid' missing in open element."))?;
let stanza = root.attr("stanza")
diff --git a/src/jingle.rs b/src/jingle.rs
index a2fc331d..40ba69da 100644
--- a/src/jingle.rs
+++ b/src/jingle.rs
@@ -5,7 +5,7 @@ use std::str::FromStr;
use minidom::Element;
use error::Error;
-use ns::JINGLE_NS;
+use ns;
#[derive(Debug, PartialEq)]
pub enum Action {
@@ -209,7 +209,7 @@ pub struct Jingle {
}
pub fn parse_jingle(root: &Element) -> Result {
- if !root.is("jingle", JINGLE_NS) {
+ if !root.is("jingle", ns::JINGLE) {
return Err(Error::ParseError("This is not a Jingle element."));
}
@@ -227,7 +227,7 @@ pub fn parse_jingle(root: &Element) -> Result {
let mut reason_element = None;
for child in root.children() {
- if child.is("content", JINGLE_NS) {
+ if child.is("content", ns::JINGLE) {
let creator = child.attr("creator")
.ok_or(Error::ParseError("Content must have a 'creator' attribute."))?
.parse()?;
@@ -276,14 +276,14 @@ pub fn parse_jingle(root: &Element) -> Result {
transport: transport,
security: security.to_owned(),
});
- } else if child.is("reason", JINGLE_NS) {
+ } else if child.is("reason", ns::JINGLE) {
if reason_element.is_some() {
return Err(Error::ParseError("Jingle must not have more than one reason."));
}
let mut reason = None;
let mut text = None;
for stuff in child.children() {
- if stuff.ns() != Some(JINGLE_NS) {
+ if stuff.ns() != Some(ns::JINGLE) {
return Err(Error::ParseError("Reason contains a foreign element."));
}
let name = stuff.name();
diff --git a/src/media_element.rs b/src/media_element.rs
index 7d774008..db40dfc6 100644
--- a/src/media_element.rs
+++ b/src/media_element.rs
@@ -2,7 +2,7 @@ use minidom::Element;
use error::Error;
-use ns::MEDIA_ELEMENT_NS;
+use ns;
#[derive(Debug)]
pub struct URI {
@@ -18,7 +18,7 @@ pub struct MediaElement {
}
pub fn parse_media_element(root: &Element) -> Result {
- if !root.is("media", MEDIA_ELEMENT_NS) {
+ if !root.is("media", ns::MEDIA_ELEMENT) {
return Err(Error::ParseError("This is not a media element."));
}
@@ -26,7 +26,7 @@ pub fn parse_media_element(root: &Element) -> Result {
let height = root.attr("height").and_then(|height| height.parse().ok());
let mut uris = vec!();
for uri in root.children() {
- if uri.is("uri", MEDIA_ELEMENT_NS) {
+ if uri.is("uri", ns::MEDIA_ELEMENT) {
let type_ = uri.attr("type").ok_or(Error::ParseError("Attribute type on uri is mandatory."))?;
let text = uri.text().trim().to_owned();
if text == "" {
diff --git a/src/ns.rs b/src/ns.rs
index 49293f4f..a1848e52 100644
--- a/src/ns.rs
+++ b/src/ns.rs
@@ -1,9 +1,9 @@
-pub const JABBER_CLIENT_NS: &'static str = "jabber:client";
-pub const DISCO_INFO_NS: &'static str = "http://jabber.org/protocol/disco#info";
-pub const DATA_FORMS_NS: &'static str = "jabber:x:data";
-pub const MEDIA_ELEMENT_NS: &'static str = "urn:xmpp:media-element";
-pub const JINGLE_NS: &'static str = "urn:xmpp:jingle:1";
-pub const PING_NS: &'static str = "urn:xmpp:ping";
-pub const CHATSTATES_NS: &'static str = "http://jabber.org/protocol/chatstates";
-pub const IBB_NS: &'static str = "http://jabber.org/protocol/ibb";
-pub const RECEIPTS_NS: &'static str = "urn:xmpp:receipts";
+pub const JABBER_CLIENT: &'static str = "jabber:client";
+pub const DISCO_INFO: &'static str = "http://jabber.org/protocol/disco#info";
+pub const DATA_FORMS: &'static str = "jabber:x:data";
+pub const MEDIA_ELEMENT: &'static str = "urn:xmpp:media-element";
+pub const JINGLE: &'static str = "urn:xmpp:jingle:1";
+pub const PING: &'static str = "urn:xmpp:ping";
+pub const CHATSTATES: &'static str = "http://jabber.org/protocol/chatstates";
+pub const IBB: &'static str = "http://jabber.org/protocol/ibb";
+pub const RECEIPTS: &'static str = "urn:xmpp:receipts";
diff --git a/src/ping.rs b/src/ping.rs
index de7aeb7b..adb0f45c 100644
--- a/src/ping.rs
+++ b/src/ping.rs
@@ -2,14 +2,14 @@ use minidom::Element;
use error::Error;
-use ns::PING_NS;
+use ns;
#[derive(Debug)]
pub struct Ping {
}
pub fn parse_ping(root: &Element) -> Result {
- if !root.is("ping", PING_NS) {
+ if !root.is("ping", ns::PING) {
return Err(Error::ParseError("This is not a ping element."));
}
diff --git a/src/receipts.rs b/src/receipts.rs
index a19dff1c..a45a54c1 100644
--- a/src/receipts.rs
+++ b/src/receipts.rs
@@ -2,7 +2,7 @@ use minidom::Element;
use error::Error;
-use ns::RECEIPTS_NS;
+use ns;
#[derive(Debug)]
pub enum Receipt {
@@ -14,9 +14,9 @@ pub fn parse_receipt(root: &Element) -> Result {
for _ in root.children() {
return Err(Error::ParseError("Unknown child in receipt element."));
}
- if root.is("request", RECEIPTS_NS) {
+ if root.is("request", ns::RECEIPTS) {
Ok(Receipt::Request)
- } else if root.is("received", RECEIPTS_NS) {
+ } else if root.is("received", ns::RECEIPTS) {
let id = root.attr("id").unwrap_or("").to_owned();
Ok(Receipt::Received(id))
} else {