1
0
mirror of https://gitlab.com/xmpp-rs/xmpp-rs.git synced 2024-06-26 08:58:27 +02:00

macros: Remove use requirement on ns.

This commit is contained in:
Emmanuel Gil Peyrot 2018-05-14 16:30:28 +02:00
parent d9aaa3e9ce
commit 93b018e5ac
41 changed files with 112 additions and 141 deletions

View File

@ -4,9 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use ns;
generate_empty_element!(Attention, "attention", ns::ATTENTION);
generate_empty_element!(Attention, "attention", ATTENTION);
#[cfg(test)]
mod tests {

View File

@ -33,7 +33,7 @@ impl TryFrom<Element> for Bind {
type Err = Error;
fn try_from(elem: Element) -> Result<Bind, Error> {
check_self!(elem, "bind", ns::BIND);
check_self!(elem, "bind", BIND);
check_no_attributes!(elem, "bind");
let mut bind = Bind::None;

View File

@ -13,7 +13,7 @@ use error::Error;
use ns;
generate_empty_element!(BlocklistRequest, "blocklist", ns::BLOCKING);
generate_empty_element!(BlocklistRequest, "blocklist", BLOCKING);
macro_rules! generate_blocking_element {
($elem:ident, $name:tt) => (
@ -26,11 +26,11 @@ macro_rules! generate_blocking_element {
type Err = Error;
fn try_from(elem: Element) -> Result<$elem, Error> {
check_self!(elem, $name, ns::BLOCKING);
check_self!(elem, $name, BLOCKING);
check_no_attributes!(elem, $name);
let mut items = vec!();
for child in elem.children() {
check_self!(child, "item", ns::BLOCKING);
check_self!(child, "item", BLOCKING);
check_no_unknown_attributes!(child, "item", ["jid"]);
check_no_children!(child, "item");
items.push(get_attr!(child, "jid", required));
@ -59,7 +59,7 @@ generate_blocking_element!(BlocklistResult, "blocklist");
generate_blocking_element!(Block, "block");
generate_blocking_element!(Unblock, "unblock");
generate_empty_element!(Blocked, "blocked", ns::BLOCKING_ERRORS);
generate_empty_element!(Blocked, "blocked", BLOCKING_ERRORS);
#[cfg(test)]
mod tests {

View File

@ -32,7 +32,7 @@ impl TryFrom<Element> for Caps {
type Err = Error;
fn try_from(elem: Element) -> Result<Caps, Error> {
check_self!(elem, "c", ns::CAPS, "caps");
check_self!(elem, "c", CAPS, "caps");
check_no_children!(elem, "caps");
check_no_unknown_attributes!(elem, "caps", ["hash", "ver", "ext", "node"]);
let ver: String = get_attr!(elem, "ver", required);

View File

@ -6,12 +6,10 @@
#![deny(missing_docs)]
use ns;
generate_element_enum!(
/// Enum representing chatstate elements part of the
/// `http://jabber.org/protocol/chatstates` namespace.
ChatState, "chatstate", ns::CHATSTATES, {
ChatState, "chatstate", CHATSTATES, {
/// `<active xmlns='http://jabber.org/protocol/chatstates'/>`
Active => "active",
@ -35,6 +33,7 @@ mod tests {
use try_from::TryFrom;
use minidom::Element;
use error::Error;
use ns;
#[test]
fn test_simple() {

View File

@ -5,12 +5,10 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use helpers::PlainText;
use ns;
use sha1::Sha1;
use digest::Digest;
generate_element_with_text!(Handshake, "handshake", ns::COMPONENT,
generate_element_with_text!(Handshake, "handshake", COMPONENT,
data: PlainText<Option<String>>
);

View File

@ -23,7 +23,7 @@ impl TryFrom<Element> for Option_ {
type Err = Error;
fn try_from(elem: Element) -> Result<Option_, Error> {
check_self!(elem, "option", ns::DATA_FORMS);
check_self!(elem, "option", DATA_FORMS);
check_no_unknown_attributes!(elem, "option", ["label"]);
let mut value = None;
for child in elem.children() {
@ -90,7 +90,7 @@ impl TryFrom<Element> for Field {
type Err = Error;
fn try_from(elem: Element) -> Result<Field, Error> {
check_self!(elem, "field", ns::DATA_FORMS);
check_self!(elem, "field", DATA_FORMS);
check_no_unknown_attributes!(elem, "field", ["label", "type", "var"]);
let mut field = Field {
var: get_attr!(elem, "var", required),
@ -167,7 +167,7 @@ impl TryFrom<Element> for DataForm {
type Err = Error;
fn try_from(elem: Element) -> Result<DataForm, Error> {
check_self!(elem, "x", ns::DATA_FORMS);
check_self!(elem, "x", DATA_FORMS);
check_no_unknown_attributes!(elem, "x", ["type"]);
let type_ = get_attr!(elem, "type", required);
let mut form = DataForm {

View File

@ -8,10 +8,9 @@ use date::DateTime;
use jid::Jid;
use ns;
use helpers::PlainText;
generate_element_with_text!(Delay, "delay", ns::DELAY,
generate_element_with_text!(Delay, "delay", DELAY,
[
from: Option<Jid> = "from" => optional,
stamp: DateTime = "stamp" => required

View File

@ -21,7 +21,7 @@ generate_element_with_only_attributes!(
///
/// It should only be used in an `<iq type='get'/>`, as it can only represent
/// the request, and not a result.
DiscoInfoQuery, "query", ns::DISCO_INFO, [
DiscoInfoQuery, "query", DISCO_INFO, [
/// Node on which we are doing the discovery.
node: Option<String> = "node" => optional,
]);
@ -29,7 +29,7 @@ DiscoInfoQuery, "query", ns::DISCO_INFO, [
generate_element_with_only_attributes!(
/// Structure representing a `<feature xmlns='http://jabber.org/protocol/disco#info'/>` element.
#[derive(PartialEq)]
Feature, "feature", ns::DISCO_INFO, [
Feature, "feature", DISCO_INFO, [
/// Namespace of the feature we want to represent.
var: String = "var" => required,
]);
@ -54,7 +54,7 @@ impl TryFrom<Element> for Identity {
type Err = Error;
fn try_from(elem: Element) -> Result<Identity, Error> {
check_self!(elem, "identity", ns::DISCO_INFO, "disco#info identity");
check_self!(elem, "identity", DISCO_INFO, "disco#info identity");
check_no_children!(elem, "disco#info identity");
check_no_unknown_attributes!(elem, "disco#info identity", ["category", "type", "xml:lang", "name"]);
@ -112,7 +112,7 @@ impl TryFrom<Element> for DiscoInfoResult {
type Err = Error;
fn try_from(elem: Element) -> Result<DiscoInfoResult, Error> {
check_self!(elem, "query", ns::DISCO_INFO, "disco#info result");
check_self!(elem, "query", DISCO_INFO, "disco#info result");
check_no_unknown_attributes!(elem, "disco#info result", ["node"]);
let mut result = DiscoInfoResult {
@ -185,14 +185,14 @@ generate_element_with_only_attributes!(
///
/// It should only be used in an `<iq type='get'/>`, as it can only represent
/// the request, and not a result.
DiscoItemsQuery, "query", ns::DISCO_ITEMS, [
DiscoItemsQuery, "query", DISCO_ITEMS, [
/// Node on which we are doing the discovery.
node: Option<String> = "node" => optional,
]);
generate_element_with_only_attributes!(
/// Structure representing an `<item xmlns='http://jabber.org/protocol/disco#items'/>` element.
Item, "item", ns::DISCO_ITEMS, [
Item, "item", DISCO_ITEMS, [
/// JID of the entity pointed by this item.
jid: Jid = "jid" => required,
/// Node of the entity pointed by this item.
@ -207,14 +207,14 @@ generate_element_with_children!(
///
/// It should only be used in an `<iq type='result'/>`, as it can only
/// represent the result, and not a request.
DiscoItemsResult, "query", ns::DISCO_ITEMS,
DiscoItemsResult, "query", DISCO_ITEMS,
attributes: [
/// Node on which we have done this discovery.
node: Option<String> = "node" => optional
],
children: [
/// List of items pointed by this entity.
items: Vec<Item> = ("item", ns::DISCO_ITEMS) => Item
items: Vec<Item> = ("item", DISCO_ITEMS) => Item
]
);

View File

@ -29,7 +29,7 @@ impl TryFrom<Element> for ECaps2 {
type Err = Error;
fn try_from(elem: Element) -> Result<ECaps2, Error> {
check_self!(elem, "c", ns::ECAPS2, "ecaps2");
check_self!(elem, "c", ECAPS2, "ecaps2");
check_no_attributes!(elem, "ecaps2");
let mut hashes = vec!();
for child in elem.children() {

View File

@ -4,11 +4,9 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use ns;
generate_element_with_only_attributes!(
/// Structure representing an `<encryption xmlns='urn:xmpp:eme:0'/>` element.
ExplicitMessageEncryption, "encryption", ns::EME, [
ExplicitMessageEncryption, "encryption", EME, [
/// Namespace of the encryption scheme used.
namespace: String = "namespace" => required,

View File

@ -26,7 +26,7 @@ impl TryFrom<Element> for Forwarded {
type Err = Error;
fn try_from(elem: Element) -> Result<Forwarded, Error> {
check_self!(elem, "forwarded", ns::FORWARD);
check_self!(elem, "forwarded", FORWARD);
let mut delay = None;
let mut stanza = None;
for child in elem.children() {

View File

@ -10,7 +10,6 @@ use minidom::IntoAttributeValue;
use error::Error;
use ns;
use helpers::Base64;
use base64;
@ -69,7 +68,7 @@ impl IntoAttributeValue for Algo {
generate_element_with_text!(
#[derive(PartialEq)]
Hash, "hash", ns::HASHES,
Hash, "hash", HASHES,
[
algo: Algo = "algo" => required
],

View File

@ -4,7 +4,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use ns;
use helpers::Base64;
generate_attribute!(Stanza, "stanza", {
@ -12,13 +11,13 @@ generate_attribute!(Stanza, "stanza", {
Message => "message",
}, Default = Iq);
generate_element_with_only_attributes!(Open, "open", ns::IBB, [
generate_element_with_only_attributes!(Open, "open", IBB, [
block_size: u16 = "block-size" => required,
sid: String = "sid" => required,
stanza: Stanza = "stanza" => default,
]);
generate_element_with_text!(Data, "data", ns::IBB,
generate_element_with_text!(Data, "data", IBB,
[
seq: u16 = "seq" => required,
sid: String = "sid" => required
@ -26,7 +25,7 @@ generate_element_with_text!(Data, "data", ns::IBB,
data: Base64<Vec<u8>>
);
generate_element_with_only_attributes!(Close, "close", ns::IBB, [
generate_element_with_only_attributes!(Close, "close", IBB, [
sid: String = "sid" => required,
]);

View File

@ -29,7 +29,7 @@ impl TryFrom<Element> for Query {
type Err = Error;
fn try_from(elem: Element) -> Result<Query, Error> {
check_self!(elem, "query", ns::REGISTER, "IBR query");
check_self!(elem, "query", REGISTER, "IBR query");
let mut query = Query {
registered: false,
fields: HashMap::new(),

View File

@ -6,9 +6,7 @@
use date::DateTime;
use ns;
generate_element_with_only_attributes!(Idle, "idle", ns::IDLE, [
generate_element_with_only_attributes!(Idle, "idle", IDLE, [
since: DateTime = "since" => required,
]);

View File

@ -207,7 +207,7 @@ impl TryFrom<Element> for Iq {
type Err = Error;
fn try_from(root: Element) -> Result<Iq, Error> {
check_self!(root, "iq", ns::DEFAULT_NS);
check_self!(root, "iq", DEFAULT_NS);
let from = get_attr!(root, "from", optional);
let to = get_attr!(root, "to", optional);
let id = get_attr!(root, "id", optional);

View File

@ -119,7 +119,7 @@ impl TryFrom<Element> for Content {
type Err = Error;
fn try_from(elem: Element) -> Result<Content, Error> {
check_self!(elem, "content", ns::JINGLE);
check_self!(elem, "content", JINGLE);
let mut content = Content {
creator: get_attr!(elem, "creator", required),
@ -250,7 +250,7 @@ impl TryFrom<Element> for ReasonElement {
type Err = Error;
fn try_from(elem: Element) -> Result<ReasonElement, Error> {
check_self!(elem, "reason", ns::JINGLE);
check_self!(elem, "reason", JINGLE);
let mut reason = None;
let mut text = None;
for child in elem.children() {
@ -340,7 +340,7 @@ impl TryFrom<Element> for Jingle {
type Err = Error;
fn try_from(root: Element) -> Result<Jingle, Error> {
check_self!(root, "jingle", ns::JINGLE, "Jingle");
check_self!(root, "jingle", JINGLE, "Jingle");
let mut jingle = Jingle {
action: get_attr!(root, "action", required),

View File

@ -20,13 +20,13 @@ use ns;
generate_element_with_children!(
#[derive(PartialEq, Default)]
Range, "range", ns::JINGLE_FT,
Range, "range", JINGLE_FT,
attributes: [
offset: u64 = "offset" => default,
length: Option<u64> = "length" => optional
],
children: [
hashes: Vec<Hash> = ("hash", ns::HASHES) => Hash
hashes: Vec<Hash> = ("hash", HASHES) => Hash
]
);
@ -109,7 +109,7 @@ impl TryFrom<Element> for File {
type Err = Error;
fn try_from(elem: Element) -> Result<File, Error> {
check_self!(elem, "file", ns::JINGLE_FT);
check_self!(elem, "file", JINGLE_FT);
check_no_attributes!(elem, "file");
let mut file = File {
@ -218,7 +218,7 @@ impl TryFrom<Element> for Description {
type Err = Error;
fn try_from(elem: Element) -> Result<Description, Error> {
check_self!(elem, "description", ns::JINGLE_FT, "JingleFT description");
check_self!(elem, "description", JINGLE_FT, "JingleFT description");
check_no_attributes!(elem, "JingleFT description");
let mut file = None;
for child in elem.children() {
@ -256,7 +256,7 @@ impl TryFrom<Element> for Checksum {
type Err = Error;
fn try_from(elem: Element) -> Result<Checksum, Error> {
check_self!(elem, "checksum", ns::JINGLE_FT);
check_self!(elem, "checksum", JINGLE_FT);
check_no_unknown_attributes!(elem, "checksum", ["name", "creator"]);
let mut file = None;
for child in elem.children() {
@ -287,7 +287,7 @@ impl From<Checksum> for Element {
}
}
generate_element_with_only_attributes!(Received, "received", ns::JINGLE_FT, [
generate_element_with_only_attributes!(Received, "received", JINGLE_FT, [
name: ContentId = "name" => required,
creator: Creator = "creator" => required,
]);

View File

@ -4,13 +4,11 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use ns;
use ibb::Stanza;
generate_id!(StreamId);
generate_element_with_only_attributes!(Transport, "transport", ns::JINGLE_IBB, [
generate_element_with_only_attributes!(Transport, "transport", JINGLE_IBB, [
block_size: u16 = "block-size" => required,
sid: StreamId = "sid" => required,
stanza: Stanza = "stanza" => default,

View File

@ -30,7 +30,7 @@ generate_id!(CandidateId);
generate_id!(StreamId);
generate_element_with_only_attributes!(Candidate, "candidate", ns::JINGLE_S5B, [
generate_element_with_only_attributes!(Candidate, "candidate", JINGLE_S5B, [
cid: CandidateId = "cid" => required,
host: IpAddr = "host" => required,
jid: Jid = "jid" => required,
@ -110,7 +110,7 @@ impl TryFrom<Element> for Transport {
type Err = Error;
fn try_from(elem: Element) -> Result<Transport, Error> {
check_self!(elem, "transport", ns::JINGLE_S5B);
check_self!(elem, "transport", JINGLE_S5B);
let sid = get_attr!(elem, "sid", required);
let dstaddr = get_attr!(elem, "dstaddr", optional);
let mode = get_attr!(elem, "mode", default);

View File

@ -104,10 +104,10 @@ macro_rules! generate_attribute {
}
macro_rules! generate_element_enum {
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, {$($(#[$enum_meta:meta])* $enum:ident => $enum_name:tt),+,}) => (
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, {$($(#[$enum_meta:meta])* $enum:ident => $enum_name:tt),+,}) => (
generate_element_enum!($(#[$meta])* $elem, $name, $ns, {$($(#[$enum_meta])* $enum => $enum_name),+});
);
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, {$($(#[$enum_meta:meta])* $enum:ident => $enum_name:tt),+}) => (
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, {$($(#[$enum_meta:meta])* $enum:ident => $enum_name:tt),+}) => (
$(#[$meta])*
#[derive(Debug, Clone, PartialEq)]
pub enum $elem {
@ -132,7 +132,7 @@ macro_rules! generate_element_enum {
fn from(elem: $elem) -> ::minidom::Element {
::minidom::Element::builder(match elem {
$($elem::$enum => $enum_name,)+
}).ns($ns)
}).ns(::ns::$ns)
.build()
}
}
@ -140,10 +140,10 @@ macro_rules! generate_element_enum {
}
macro_rules! generate_attribute_enum {
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, $attr:tt, {$($(#[$enum_meta:meta])* $enum:ident => $enum_name:tt),+,}) => (
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, $attr:tt, {$($(#[$enum_meta:meta])* $enum:ident => $enum_name:tt),+,}) => (
generate_attribute_enum!($(#[$meta])* $elem, $name, $ns, $attr, {$($(#[$enum_meta])* $enum => $enum_name),+});
);
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, $attr:tt, {$($(#[$enum_meta:meta])* $enum:ident => $enum_name:tt),+}) => (
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, $attr:tt, {$($(#[$enum_meta:meta])* $enum:ident => $enum_name:tt),+}) => (
$(#[$meta])*
#[derive(Debug, Clone, PartialEq)]
pub enum $elem {
@ -167,7 +167,7 @@ macro_rules! generate_attribute_enum {
impl From<$elem> for ::minidom::Element {
fn from(elem: $elem) -> ::minidom::Element {
::minidom::Element::builder($name)
.ns($ns)
.ns(::ns::$ns)
.attr($attr, match elem {
$($elem::$enum => $enum_name,)+
})
@ -178,19 +178,19 @@ macro_rules! generate_attribute_enum {
}
macro_rules! check_self {
($elem:ident, $name:tt, $ns:expr) => (
($elem:ident, $name:tt, $ns:ident) => (
check_self!($elem, $name, $ns, $name);
);
($elem:ident, $name:tt, $ns:expr, $pretty_name:tt) => (
if !$elem.is($name, $ns) {
($elem:ident, $name:tt, $ns:ident, $pretty_name:tt) => (
if !$elem.is($name, ::ns::$ns) {
return Err(::error::Error::ParseError(concat!("This is not a ", $pretty_name, " element.")));
}
);
}
macro_rules! check_ns_only {
($elem:ident, $name:tt, $ns:expr) => (
if !$elem.has_ns($ns) {
($elem:ident, $name:tt, $ns:ident) => (
if !$elem.has_ns(::ns::$ns) {
return Err(::error::Error::ParseError(concat!("This is not a ", $name, " element.")));
}
);
@ -226,7 +226,7 @@ macro_rules! check_no_unknown_attributes {
}
macro_rules! generate_empty_element {
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr) => (
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident) => (
$(#[$meta])*
#[derive(Debug, Clone)]
pub struct $elem;
@ -245,7 +245,7 @@ macro_rules! generate_empty_element {
impl From<$elem> for ::minidom::Element {
fn from(_: $elem) -> ::minidom::Element {
::minidom::Element::builder($name)
.ns($ns)
.ns(::ns::$ns)
.build()
}
}
@ -253,10 +253,10 @@ macro_rules! generate_empty_element {
}
macro_rules! generate_element_with_only_attributes {
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+,]) => (
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+,]) => (
generate_element_with_only_attributes!($(#[$meta])* $elem, $name, $ns, [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*]);
);
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+]) => (
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+]) => (
$(#[$meta])*
#[derive(Debug, Clone)]
pub struct $elem {
@ -284,7 +284,7 @@ macro_rules! generate_element_with_only_attributes {
impl From<$elem> for ::minidom::Element {
fn from(elem: $elem) -> ::minidom::Element {
::minidom::Element::builder($name)
.ns($ns)
.ns(::ns::$ns)
$(
.attr($attr_name, elem.$attr)
)*
@ -314,7 +314,7 @@ macro_rules! generate_id {
}
macro_rules! generate_elem_id {
($elem:ident, $name:tt, $ns:expr) => (
($elem:ident, $name:tt, $ns:ident) => (
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct $elem(pub String);
impl ::std::str::FromStr for $elem {
@ -337,7 +337,7 @@ macro_rules! generate_elem_id {
impl From<$elem> for ::minidom::Element {
fn from(elem: $elem) -> ::minidom::Element {
::minidom::Element::builder($name)
.ns($ns)
.ns(::ns::$ns)
.append(elem.0)
.build()
}
@ -346,10 +346,10 @@ macro_rules! generate_elem_id {
}
macro_rules! generate_element_with_text {
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, $text_ident:ident: $codec:ident < $text_type:ty >) => (
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, $text_ident:ident: $codec:ident < $text_type:ty >) => (
generate_element_with_text!($(#[$meta])* $elem, $name, $ns, [], $text_ident: $codec<$text_type>);
);
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),*], $text_ident:ident: $codec:ident < $text_type:ty >) => (
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),*], $text_ident:ident: $codec:ident < $text_type:ty >) => (
$(#[$meta])*
#[derive(Debug, Clone)]
pub struct $elem {
@ -379,7 +379,7 @@ macro_rules! generate_element_with_text {
impl From<$elem> for ::minidom::Element {
fn from(elem: $elem) -> ::minidom::Element {
::minidom::Element::builder($name)
.ns($ns)
.ns(::ns::$ns)
$(
.attr($attr_name, elem.$attr)
)*
@ -391,7 +391,7 @@ macro_rules! generate_element_with_text {
}
macro_rules! generate_element_with_children {
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:expr, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+], children: [$($(#[$child_meta:meta])* $child_ident:ident: Vec<$child_type:ty> = ($child_name:tt, $child_ns:expr) => $child_constructor:ident),+]) => (
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+], children: [$($(#[$child_meta:meta])* $child_ident:ident: Vec<$child_type:ty> = ($child_name:tt, $child_ns:ident) => $child_constructor:ident),+]) => (
$(#[$meta])*
#[derive(Debug, Clone)]
pub struct $elem {
@ -414,7 +414,7 @@ macro_rules! generate_element_with_children {
let mut parsed_children = vec!();
for child in elem.children() {
$(
if child.is($child_name, $child_ns) {
if child.is($child_name, ::ns::$child_ns) {
let parsed_child = $child_constructor::try_from(child.clone())?;
parsed_children.push(parsed_child);
continue;
@ -436,7 +436,7 @@ macro_rules! generate_element_with_children {
impl From<$elem> for ::minidom::Element {
fn from(elem: $elem) -> ::minidom::Element {
::minidom::Element::builder($name)
.ns($ns)
.ns(::ns::$ns)
$(
.attr($attr_name, elem.$attr)
)*

View File

@ -55,7 +55,7 @@ impl TryFrom<Element> for Query {
type Err = Error;
fn try_from(elem: Element) -> Result<Query, Error> {
check_self!(elem, "query", ns::MAM);
check_self!(elem, "query", MAM);
check_no_unknown_attributes!(elem, "query", ["queryid", "node"]);
let mut form = None;
let mut set = None;
@ -78,7 +78,7 @@ impl TryFrom<Element> for Result_ {
type Err = Error;
fn try_from(elem: Element) -> Result<Result_, Error> {
check_self!(elem, "result", ns::MAM);
check_self!(elem, "result", MAM);
check_no_unknown_attributes!(elem, "result", ["queryid", "id"]);
let mut forwarded = None;
for child in elem.children() {
@ -103,7 +103,7 @@ impl TryFrom<Element> for Fin {
type Err = Error;
fn try_from(elem: Element) -> Result<Fin, Error> {
check_self!(elem, "fin", ns::MAM);
check_self!(elem, "fin", MAM);
check_no_unknown_attributes!(elem, "fin", ["complete"]);
let mut set = None;
for child in elem.children() {
@ -128,7 +128,7 @@ impl TryFrom<Element> for Prefs {
type Err = Error;
fn try_from(elem: Element) -> Result<Prefs, Error> {
check_self!(elem, "prefs", ns::MAM);
check_self!(elem, "prefs", MAM);
check_no_unknown_attributes!(elem, "prefs", ["default"]);
let mut always = vec!();
let mut never = vec!();

View File

@ -4,23 +4,22 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use ns;
use helpers::TrimmedPlainText;
generate_element_with_text!(URI, "uri", ns::MEDIA_ELEMENT,
generate_element_with_text!(URI, "uri", MEDIA_ELEMENT,
[
type_: String = "type" => required
],
uri: TrimmedPlainText<String>
);
generate_element_with_children!(MediaElement, "media", ns::MEDIA_ELEMENT,
generate_element_with_children!(MediaElement, "media", MEDIA_ELEMENT,
attributes: [
width: Option<usize> = "width" => optional,
height: Option<usize> = "height" => optional
],
children: [
uris: Vec<URI> = ("uri", ns::MEDIA_ELEMENT) => URI
uris: Vec<URI> = ("uri", MEDIA_ELEMENT) => URI
]
);

View File

@ -115,9 +115,9 @@ generate_attribute!(MessageType, "type", {
type Lang = String;
generate_elem_id!(Body, "body", ns::DEFAULT_NS);
generate_elem_id!(Subject, "subject", ns::DEFAULT_NS);
generate_elem_id!(Thread, "thread", ns::DEFAULT_NS);
generate_elem_id!(Body, "body", DEFAULT_NS);
generate_elem_id!(Subject, "subject", DEFAULT_NS);
generate_elem_id!(Thread, "thread", DEFAULT_NS);
/// The main structure representing the `<message/>` stanza.
#[derive(Debug, Clone)]
@ -188,7 +188,7 @@ impl TryFrom<Element> for Message {
type Err = Error;
fn try_from(root: Element) -> Result<Message, Error> {
check_self!(root, "message", ns::DEFAULT_NS);
check_self!(root, "message", DEFAULT_NS);
let from = get_attr!(root, "from", optional);
let to = get_attr!(root, "to", optional);
let id = get_attr!(root, "id", optional);

View File

@ -4,9 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use ns;
generate_element_with_only_attributes!(Replace, "replace", ns::MESSAGE_CORRECT, [
generate_element_with_only_attributes!(Replace, "replace", MESSAGE_CORRECT, [
id: String = "id" => required,
]);

View File

@ -6,11 +6,9 @@
#![deny(missing_docs)]
use ns;
generate_element_enum!(
/// Enum representing all of the possible values of the XEP-0107 moods.
MoodEnum, "mood", ns::MOOD, {
MoodEnum, "mood", MOOD, {
/// Impressed with fear or apprehension; in fear; apprehensive.
Afraid => "afraid",

View File

@ -22,7 +22,7 @@ impl TryFrom<Element> for Muc {
type Err = Error;
fn try_from(elem: Element) -> Result<Muc, Error> {
check_self!(elem, "x", ns::MUC);
check_self!(elem, "x", MUC);
check_no_attributes!(elem, "x");
let mut password = None;

View File

@ -17,7 +17,7 @@ use ns;
generate_attribute_enum!(
/// Lists all of the possible status codes used in MUC presences.
Status, "status", ns::MUC_USER, "code", {
Status, "status", MUC_USER, "code", {
/// Inform user that any occupant is allowed to see the user's full JID
NonAnonymousRoom => 100,
@ -92,7 +92,7 @@ impl TryFrom<Element> for Actor {
type Err = Error;
fn try_from(elem: Element) -> Result<Actor, Error> {
check_self!(elem, "actor", ns::MUC_USER);
check_self!(elem, "actor", MUC_USER);
check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]);
for _ in elem.children() {
return Err(Error::ParseError("Unknown child in actor element."));
@ -121,11 +121,11 @@ impl From<Actor> for Element {
}
}
generate_element_with_only_attributes!(Continue, "continue", ns::MUC_USER, [
generate_element_with_only_attributes!(Continue, "continue", MUC_USER, [
thread: Option<String> = "thread" => optional,
]);
generate_elem_id!(Reason, "reason", ns::MUC_USER);
generate_elem_id!(Reason, "reason", MUC_USER);
generate_attribute!(Affiliation, "affiliation", {
Owner => "owner",
@ -157,7 +157,7 @@ impl TryFrom<Element> for Item {
type Err = Error;
fn try_from(elem: Element) -> Result<Item, Error> {
check_self!(elem, "item", ns::MUC_USER);
check_self!(elem, "item", MUC_USER);
check_no_unknown_attributes!(elem, "item", ["affiliation", "jid", "nick", "role"]);
let mut actor: Option<Actor> = None;
let mut continue_: Option<Continue> = None;
@ -216,7 +216,7 @@ impl TryFrom<Element> for MucUser {
type Err = Error;
fn try_from(elem: Element) -> Result<MucUser, Error> {
check_self!(elem, "x", ns::MUC_USER);
check_self!(elem, "x", MUC_USER);
check_no_attributes!(elem, "x");
let mut status = vec!();
let mut items = vec!();

View File

@ -5,9 +5,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use ns;
generate_empty_element!(Ping, "ping", ns::PING);
generate_empty_element!(Ping, "ping", PING);
#[cfg(test)]
mod tests {

View File

@ -248,7 +248,7 @@ impl TryFrom<Element> for Presence {
type Err = Error;
fn try_from(root: Element) -> Result<Presence, Error> {
check_self!(root, "presence", ns::DEFAULT_NS);
check_self!(root, "presence", DEFAULT_NS);
let mut show = None;
let mut priority = None;
let mut presence = Presence {

View File

@ -32,7 +32,7 @@ impl TryFrom<Element> for Item {
type Err = Error;
fn try_from(elem: Element) -> Result<Item, Error> {
check_self!(elem, "item", ns::PUBSUB_EVENT);
check_self!(elem, "item", PUBSUB_EVENT);
check_no_unknown_attributes!(elem, "item", ["id", "node", "publisher"]);
let mut payloads = elem.children().cloned().collect::<Vec<_>>();
let payload = payloads.pop();
@ -141,7 +141,7 @@ impl TryFrom<Element> for PubSubEvent {
type Err = Error;
fn try_from(elem: Element) -> Result<PubSubEvent, Error> {
check_self!(elem, "event", ns::PUBSUB_EVENT);
check_self!(elem, "event", PUBSUB_EVENT);
check_no_attributes!(elem, "event");
let mut payload = None;

View File

@ -4,11 +4,9 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use ns;
generate_empty_element!(Request, "request", RECEIPTS);
generate_empty_element!(Request, "request", ns::RECEIPTS);
generate_element_with_only_attributes!(Received, "received", ns::RECEIPTS, [
generate_element_with_only_attributes!(Received, "received", RECEIPTS, [
id: Option<String> = "id" => optional,
]);
@ -17,6 +15,7 @@ mod tests {
use super::*;
use try_from::TryFrom;
use minidom::Element;
use ns;
#[test]
fn test_simple() {

View File

@ -6,9 +6,7 @@
use jid::Jid;
use ns;
generate_elem_id!(Group, "group", ns::ROSTER);
generate_elem_id!(Group, "group", ROSTER);
generate_attribute!(Subscription, "subscription", {
None => "none",
@ -21,7 +19,7 @@ generate_attribute!(Subscription, "subscription", {
generate_element_with_children!(
/// Contact from the users contact list.
#[derive(PartialEq)]
Item, "item", ns::ROSTER,
Item, "item", ROSTER,
attributes: [
/// JID of this contact.
jid: Jid = "jid" => required,
@ -35,13 +33,13 @@ generate_element_with_children!(
children: [
/// Groups this contact is part of.
groups: Vec<Group> = ("group", ns::ROSTER) => Group
groups: Vec<Group> = ("group", ROSTER) => Group
]
);
generate_element_with_children!(
/// The contact list of the user.
Roster, "query", ns::ROSTER,
Roster, "query", ROSTER,
attributes: [
/// Version of the contact list.
///
@ -52,7 +50,7 @@ generate_element_with_children!(
],
children: [
/// List of the contacts of the user.
items: Vec<Item> = ("item", ns::ROSTER) => Item
items: Vec<Item> = ("item", ROSTER) => Item
]
);

View File

@ -28,7 +28,7 @@ impl TryFrom<Element> for Set {
type Err = Error;
fn try_from(elem: Element) -> Result<Set, Error> {
check_self!(elem, "set", ns::RSM, "RSM set");
check_self!(elem, "set", RSM, "RSM set");
let mut set = Set {
after: None,
before: None,

View File

@ -4,7 +4,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use ns;
use helpers::Base64;
generate_attribute!(Mechanism, "mechanism", {
@ -13,22 +12,22 @@ generate_attribute!(Mechanism, "mechanism", {
Anonymous => "ANONYMOUS",
});
generate_element_with_text!(Auth, "auth", ns::SASL,
generate_element_with_text!(Auth, "auth", SASL,
[
mechanism: Mechanism = "mechanism" => required
],
data: Base64<Vec<u8>>
);
generate_element_with_text!(Challenge, "challenge", ns::SASL,
generate_element_with_text!(Challenge, "challenge", SASL,
data: Base64<Vec<u8>>
);
generate_element_with_text!(Response, "response", ns::SASL,
generate_element_with_text!(Response, "response", SASL,
data: Base64<Vec<u8>>
);
generate_element_with_text!(Success, "success", ns::SASL,
generate_element_with_text!(Success, "success", SASL,
data: Base64<Vec<u8>>
);

View File

@ -21,7 +21,7 @@ generate_attribute!(ErrorType, "type", {
Wait => "wait",
});
generate_element_enum!(DefinedCondition, "condition", ns::XMPP_STANZAS, {
generate_element_enum!(DefinedCondition, "condition", XMPP_STANZAS, {
BadRequest => "bad-request",
Conflict => "conflict",
FeatureNotImplemented => "feature-not-implemented",
@ -61,7 +61,7 @@ impl TryFrom<Element> for StanzaError {
type Err = Error;
fn try_from(elem: Element) -> Result<StanzaError, Error> {
check_self!(elem, "error", ns::DEFAULT_NS);
check_self!(elem, "error", DEFAULT_NS);
let type_ = get_attr!(elem, "type", required);
let by = get_attr!(elem, "by", optional);

View File

@ -6,14 +6,12 @@
use jid::Jid;
use ns;
generate_element_with_only_attributes!(StanzaId, "stanza-id", ns::SID, [
generate_element_with_only_attributes!(StanzaId, "stanza-id", SID, [
id: String = "id" => required,
by: Jid = "by" => required,
]);
generate_element_with_only_attributes!(OriginId, "origin-id", ns::SID, [
generate_element_with_only_attributes!(OriginId, "origin-id", SID, [
id: String = "id" => required,
]);

View File

@ -5,9 +5,8 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use jid::Jid;
use ns;
generate_element_with_only_attributes!(Stream, "stream", ns::STREAM, [
generate_element_with_only_attributes!(Stream, "stream", STREAM, [
from: Option<Jid> = "from" => optional,
to: Option<Jid> = "to" => optional,
id: Option<String> = "id" => optional,

View File

@ -20,7 +20,7 @@ impl TryFrom<Element> for Version {
type Err = Error;
fn try_from(elem: Element) -> Result<Version, Error> {
check_self!(elem, "query", ns::VERSION, "version");
check_self!(elem, "query", VERSION, "version");
check_no_attributes!(elem, "version");
let mut name = None;
let mut version = None;

View File

@ -5,9 +5,8 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use jid::Jid;
use ns;
generate_element_with_only_attributes!(Open, "open", ns::WEBSOCKET, [
generate_element_with_only_attributes!(Open, "open", WEBSOCKET, [
from: Option<Jid> = "from" => optional,
to: Option<Jid> = "to" => optional,
id: Option<String> = "id" => optional,