Move Error, helpers and macros into a util module.

This commit is contained in:
Emmanuel Gil Peyrot 2019-01-13 12:39:51 +01:00
commit 409a1dafa9
46 changed files with 98 additions and 107 deletions

View file

@ -19,7 +19,7 @@ impl MessagePayload for Attention {}
mod tests { mod tests {
use super::*; use super::*;
#[cfg(not(feature = "disable-validation"))] #[cfg(not(feature = "disable-validation"))]
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::iq::{IqResultPayload, IqSetPayload}; use crate::iq::{IqResultPayload, IqSetPayload};
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload};
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;

View file

@ -72,7 +72,7 @@ impl Storage {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -6,7 +6,7 @@
use crate::data_forms::DataForm; use crate::data_forms::DataForm;
use crate::disco::{DiscoInfoQuery, DiscoInfoResult, Feature, Identity}; use crate::disco::{DiscoInfoQuery, DiscoInfoResult, Feature, Identity};
use crate::error::Error; use crate::util::error::Error;
use crate::hashes::{Algo, Hash}; use crate::hashes::{Algo, Hash};
use crate::ns; use crate::ns;
use crate::presence::PresencePayload; use crate::presence::PresencePayload;

View file

@ -32,7 +32,7 @@ impl MessagePayload for ChatState {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::util::error::Error;
use crate::ns; use crate::ns;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::helpers::PlainText; use crate::util::helpers::PlainText;
use digest::Digest; use digest::Digest;
use sha1::Sha1; use sha1::Sha1;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::media_element::MediaElement; use crate::media_element::MediaElement;
use crate::ns; use crate::ns;
use minidom::Element; use minidom::Element;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use chrono::{DateTime as ChronoDateTime, FixedOffset}; use chrono::{DateTime as ChronoDateTime, FixedOffset};
use minidom::{ElementEmitter, IntoAttributeValue, IntoElements}; use minidom::{ElementEmitter, IntoAttributeValue, IntoElements};
use std::str::FromStr; use std::str::FromStr;

View file

@ -5,7 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::date::DateTime; use crate::date::DateTime;
use crate::helpers::PlainText; use crate::util::helpers::PlainText;
use crate::message::MessagePayload; use crate::message::MessagePayload;
use crate::presence::PresencePayload; use crate::presence::PresencePayload;
use jid::Jid; use jid::Jid;
@ -32,7 +32,7 @@ impl PresencePayload for Delay {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use std::str::FromStr; use std::str::FromStr;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -5,7 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::data_forms::{DataForm, DataFormType}; use crate::data_forms::{DataForm, DataFormType};
use crate::error::Error; use crate::util::error::Error;
use crate::iq::{IqGetPayload, IqResultPayload}; use crate::iq::{IqGetPayload, IqResultPayload};
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;
@ -236,7 +236,7 @@ impl IqResultPayload for DiscoItemsResult {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
use std::str::FromStr; use std::str::FromStr;
#[cfg(target_pointer_width = "32")] #[cfg(target_pointer_width = "32")]

View file

@ -156,7 +156,7 @@ pub fn query_ecaps2(hash: Hash) -> DiscoInfoQuery {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -24,7 +24,7 @@ impl MessagePayload for ExplicitMessageEncryption {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -26,7 +26,7 @@ generate_element!(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -4,8 +4,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::helpers::Base64; use crate::util::helpers::Base64;
use base64; use base64;
use minidom::IntoAttributeValue; use minidom::IntoAttributeValue;
use std::str::FromStr; use std::str::FromStr;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::helpers::Base64; use crate::util::helpers::Base64;
use crate::iq::IqSetPayload; use crate::iq::IqSetPayload;
generate_id!( generate_id!(
@ -72,7 +72,7 @@ impl IqSetPayload for Close {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use std::error::Error as StdError; use std::error::Error as StdError;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -5,7 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::data_forms::DataForm; use crate::data_forms::DataForm;
use crate::error::Error; use crate::util::error::Error;
use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload};
use crate::ns; use crate::ns;
use minidom::Element; use minidom::Element;
@ -118,7 +118,7 @@ impl From<Query> for Element {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
#[cfg(target_pointer_width = "32")] #[cfg(target_pointer_width = "32")]
#[test] #[test]

View file

@ -21,7 +21,7 @@ impl PresencePayload for Idle {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use std::error::Error as StdError; use std::error::Error as StdError;
use std::str::FromStr; use std::str::FromStr;

View file

@ -5,7 +5,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::ns; use crate::ns;
use crate::stanza_error::StanzaError; use crate::stanza_error::StanzaError;
use jid::Jid; use jid::Jid;
@ -218,7 +218,7 @@ impl From<Iq> for Element {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
use crate::disco::DiscoInfoQuery; use crate::disco::DiscoInfoQuery;
use crate::stanza_error::{DefinedCondition, ErrorType}; use crate::stanza_error::{DefinedCondition, ErrorType};

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::iq::IqSetPayload; use crate::iq::IqSetPayload;
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;

View file

@ -5,7 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::date::DateTime; use crate::date::DateTime;
use crate::error::Error; use crate::util::error::Error;
use crate::hashes::Hash; use crate::hashes::Hash;
use crate::jingle::{ContentId, Creator}; use crate::jingle::{ContentId, Creator};
use crate::ns; use crate::ns;

View file

@ -24,7 +24,7 @@ attributes: [
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use std::error::Error as StdError; use std::error::Error as StdError;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::jingle::SessionId; use crate::jingle::SessionId;
use crate::ns; use crate::ns;
use minidom::Element; use minidom::Element;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;
use minidom::Element; use minidom::Element;
@ -275,7 +275,7 @@ impl From<Transport> for Element {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
use std::str::FromStr; use std::str::FromStr;
#[cfg(target_pointer_width = "32")] #[cfg(target_pointer_width = "32")]

View file

@ -26,20 +26,11 @@
pub use minidom::Element; pub use minidom::Element;
/// Error type returned by every parser on failure.
pub mod error;
/// XML namespace definitions used through XMPP. /// XML namespace definitions used through XMPP.
pub mod ns; pub mod ns;
/// Various helpers.
mod helpers;
/// Helper macros to parse and serialise more easily.
#[macro_use] #[macro_use]
mod macros; mod util;
#[cfg(test)]
/// Namespace-aware comparison for tests
mod compare_elements;
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core /// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
pub mod bind; pub mod bind;

View file

@ -5,7 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::data_forms::DataForm; use crate::data_forms::DataForm;
use crate::error::Error; use crate::util::error::Error;
use crate::forwarding::Forwarded; use crate::forwarding::Forwarded;
use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload};
use crate::message::MessagePayload; use crate::message::MessagePayload;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::helpers::TrimmedPlainText; use crate::util::helpers::TrimmedPlainText;
generate_element!( generate_element!(
/// Represents an URI used in a media element. /// Represents an URI used in a media element.
@ -46,7 +46,7 @@ generate_element!(
mod tests { mod tests {
use super::*; use super::*;
use crate::data_forms::DataForm; use crate::data_forms::DataForm;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use std::error::Error as StdError; use std::error::Error as StdError;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;
use minidom::Element; use minidom::Element;
@ -254,7 +254,7 @@ impl From<Message> for Element {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
use std::str::FromStr; use std::str::FromStr;
#[cfg(target_pointer_width = "32")] #[cfg(target_pointer_width = "32")]

View file

@ -21,7 +21,7 @@ impl MessagePayload for Replace {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -102,8 +102,8 @@ impl Muc {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use std::str::FromStr; use std::str::FromStr;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -5,7 +5,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;
use minidom::Element; use minidom::Element;
@ -238,7 +238,7 @@ generate_element!(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
use std::error::Error as StdError; use std::error::Error as StdError;
#[test] #[test]

View file

@ -15,7 +15,7 @@ generate_elem_id!(
mod tests { mod tests {
use super::*; use super::*;
#[cfg(not(feature = "disable-validation"))] #[cfg(not(feature = "disable-validation"))]
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -21,7 +21,7 @@ impl IqGetPayload for Ping {}
mod tests { mod tests {
use super::*; use super::*;
#[cfg(not(feature = "disable-validation"))] #[cfg(not(feature = "disable-validation"))]
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -5,7 +5,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::ns; use crate::ns;
use jid::Jid; use jid::Jid;
use minidom::{Element, ElementEmitter, IntoAttributeValue, IntoElements}; use minidom::{Element, ElementEmitter, IntoAttributeValue, IntoElements};
@ -354,7 +354,7 @@ impl From<Presence> for Element {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
#[cfg(target_pointer_width = "32")] #[cfg(target_pointer_width = "32")]
#[test] #[test]

View file

@ -6,7 +6,7 @@
use crate::data_forms::DataForm; use crate::data_forms::DataForm;
use crate::date::DateTime; use crate::date::DateTime;
use crate::error::Error; use crate::util::error::Error;
use crate::ns; use crate::ns;
use crate::pubsub::{ItemId, NodeName, Subscription, SubscriptionId}; use crate::pubsub::{ItemId, NodeName, Subscription, SubscriptionId};
use jid::Jid; use jid::Jid;
@ -298,7 +298,7 @@ impl From<PubSubEvent> for Element {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
use std::str::FromStr; use std::str::FromStr;
#[test] #[test]

View file

@ -5,7 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::data_forms::DataForm; use crate::data_forms::DataForm;
use crate::error::Error; use crate::util::error::Error;
use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload};
use crate::ns; use crate::ns;
use crate::pubsub::{ItemId, NodeName, Subscription, SubscriptionId}; use crate::pubsub::{ItemId, NodeName, Subscription, SubscriptionId};
@ -540,7 +540,7 @@ impl From<PubSub> for Element {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
#[test] #[test]
fn create() { fn create() {

View file

@ -92,8 +92,8 @@ impl IqResultPayload for Roster {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use std::str::FromStr; use std::str::FromStr;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::ns; use crate::ns;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;
@ -180,7 +180,7 @@ impl From<SetResult> for Element {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
#[cfg(target_pointer_width = "32")] #[cfg(target_pointer_width = "32")]
#[test] #[test]

View file

@ -4,8 +4,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::helpers::Base64; use crate::util::helpers::Base64;
use crate::ns; use crate::ns;
use minidom::Element; use minidom::Element;
use std::collections::BTreeMap; use std::collections::BTreeMap;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use crate::message::MessagePayload; use crate::message::MessagePayload;
use crate::ns; use crate::ns;
use crate::presence::PresencePayload; use crate::presence::PresencePayload;

View file

@ -37,7 +37,7 @@ impl MessagePayload for OriginId {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::error::Error; use crate::util::error::Error;
use minidom::Element; use minidom::Element;
use std::str::FromStr; use std::str::FromStr;
use try_from::TryFrom; use try_from::TryFrom;

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::error::Error; use crate::util::error::Error;
use base64; use base64;
/// Codec for plain text content. /// Codec for plain text content.

View file

@ -25,7 +25,7 @@ macro_rules! get_attr {
match $elem.attr($attr) { match $elem.attr($attr) {
Some($value) => $func, Some($value) => $func,
None => { None => {
return Err(crate::error::Error::ParseError(concat!( return Err(crate::util::error::Error::ParseError(concat!(
"Required attribute '", "Required attribute '",
$attr, $attr,
"' missing." "' missing."
@ -58,11 +58,11 @@ macro_rules! generate_attribute {
),+ ),+
} }
impl ::std::str::FromStr for $elem { impl ::std::str::FromStr for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn from_str(s: &str) -> Result<$elem, crate::error::Error> { fn from_str(s: &str) -> Result<$elem, crate::util::error::Error> {
Ok(match s { Ok(match s {
$($b => $elem::$a),+, $($b => $elem::$a),+,
_ => return Err(crate::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), _ => return Err(crate::util::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))),
}) })
} }
} }
@ -84,11 +84,11 @@ macro_rules! generate_attribute {
),+ ),+
} }
impl ::std::str::FromStr for $elem { impl ::std::str::FromStr for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn from_str(s: &str) -> Result<$elem, crate::error::Error> { fn from_str(s: &str) -> Result<$elem, crate::util::error::Error> {
Ok(match s { Ok(match s {
$($b => $elem::$a),+, $($b => $elem::$a),+,
_ => return Err(crate::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), _ => return Err(crate::util::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))),
}) })
} }
} }
@ -117,11 +117,11 @@ macro_rules! generate_attribute {
None, None,
} }
impl ::std::str::FromStr for $elem { impl ::std::str::FromStr for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn from_str(s: &str) -> Result<Self, crate::error::Error> { fn from_str(s: &str) -> Result<Self, crate::util::error::Error> {
Ok(match s { Ok(match s {
$value => $elem::$symbol, $value => $elem::$symbol,
_ => return Err(crate::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), _ => return Err(crate::util::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))),
}) })
} }
} }
@ -149,12 +149,12 @@ macro_rules! generate_attribute {
False, False,
} }
impl ::std::str::FromStr for $elem { impl ::std::str::FromStr for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn from_str(s: &str) -> Result<Self, crate::error::Error> { fn from_str(s: &str) -> Result<Self, crate::util::error::Error> {
Ok(match s { Ok(match s {
"true" | "1" => $elem::True, "true" | "1" => $elem::True,
"false" | "0" => $elem::False, "false" | "0" => $elem::False,
_ => return Err(crate::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))), _ => return Err(crate::util::error::Error::ParseError(concat!("Unknown value for '", $name, "' attribute."))),
}) })
} }
} }
@ -188,14 +188,14 @@ macro_rules! generate_element_enum {
),+ ),+
} }
impl ::try_from::TryFrom<::minidom::Element> for $elem { impl ::try_from::TryFrom<::minidom::Element> for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::error::Error> { fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::util::error::Error> {
check_ns_only!(elem, $name, $ns); check_ns_only!(elem, $name, $ns);
check_no_children!(elem, $name); check_no_children!(elem, $name);
check_no_attributes!(elem, $name); check_no_attributes!(elem, $name);
Ok(match elem.name() { Ok(match elem.name() {
$($enum_name => $elem::$enum,)+ $($enum_name => $elem::$enum,)+
_ => return Err(crate::error::Error::ParseError(concat!("This is not a ", $name, " element."))), _ => return Err(crate::util::error::Error::ParseError(concat!("This is not a ", $name, " element."))),
}) })
} }
} }
@ -227,14 +227,14 @@ macro_rules! generate_attribute_enum {
),+ ),+
} }
impl ::try_from::TryFrom<::minidom::Element> for $elem { impl ::try_from::TryFrom<::minidom::Element> for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::error::Error> { fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::util::error::Error> {
check_ns_only!(elem, $name, $ns); check_ns_only!(elem, $name, $ns);
check_no_children!(elem, $name); check_no_children!(elem, $name);
check_no_unknown_attributes!(elem, $name, [$attr]); check_no_unknown_attributes!(elem, $name, [$attr]);
Ok(match get_attr!(elem, $attr, required) { Ok(match get_attr!(elem, $attr, required) {
$($enum_name => $elem::$enum,)+ $($enum_name => $elem::$enum,)+
_ => return Err(crate::error::Error::ParseError(concat!("Invalid ", $name, " ", $attr, " value."))), _ => return Err(crate::util::error::Error::ParseError(concat!("Invalid ", $name, " ", $attr, " value."))),
}) })
} }
} }
@ -257,7 +257,7 @@ macro_rules! check_self {
}; };
($elem:ident, $name:tt, $ns:ident, $pretty_name:tt) => { ($elem:ident, $name:tt, $ns:ident, $pretty_name:tt) => {
if !$elem.is($name, crate::ns::$ns) { if !$elem.is($name, crate::ns::$ns) {
return Err(crate::error::Error::ParseError(concat!( return Err(crate::util::error::Error::ParseError(concat!(
"This is not a ", "This is not a ",
$pretty_name, $pretty_name,
" element." " element."
@ -269,7 +269,7 @@ macro_rules! check_self {
macro_rules! check_ns_only { macro_rules! check_ns_only {
($elem:ident, $name:tt, $ns:ident) => { ($elem:ident, $name:tt, $ns:ident) => {
if !$elem.has_ns(crate::ns::$ns) { if !$elem.has_ns(crate::ns::$ns) {
return Err(crate::error::Error::ParseError(concat!( return Err(crate::util::error::Error::ParseError(concat!(
"This is not a ", "This is not a ",
$name, $name,
" element." " element."
@ -282,7 +282,7 @@ macro_rules! check_no_children {
($elem:ident, $name:tt) => { ($elem:ident, $name:tt) => {
#[cfg(not(feature = "disable-validation"))] #[cfg(not(feature = "disable-validation"))]
for _ in $elem.children() { for _ in $elem.children() {
return Err(crate::error::Error::ParseError(concat!( return Err(crate::util::error::Error::ParseError(concat!(
"Unknown child in ", "Unknown child in ",
$name, $name,
" element." " element."
@ -295,7 +295,7 @@ macro_rules! check_no_attributes {
($elem:ident, $name:tt) => { ($elem:ident, $name:tt) => {
#[cfg(not(feature = "disable-validation"))] #[cfg(not(feature = "disable-validation"))]
for _ in $elem.attrs() { for _ in $elem.attrs() {
return Err(crate::error::Error::ParseError(concat!( return Err(crate::util::error::Error::ParseError(concat!(
"Unknown attribute in ", "Unknown attribute in ",
$name, $name,
" element." " element."
@ -313,7 +313,7 @@ macro_rules! check_no_unknown_attributes {
continue; continue;
} }
)* )*
return Err(crate::error::Error::ParseError(concat!("Unknown attribute in ", $name, " element."))); return Err(crate::util::error::Error::ParseError(concat!("Unknown attribute in ", $name, " element.")));
} }
); );
} }
@ -325,9 +325,9 @@ macro_rules! generate_empty_element {
pub struct $elem; pub struct $elem;
impl ::try_from::TryFrom<::minidom::Element> for $elem { impl ::try_from::TryFrom<::minidom::Element> for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::error::Error> { fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::util::error::Error> {
check_self!(elem, $name, $ns); check_self!(elem, $name, $ns);
check_no_children!(elem, $name); check_no_children!(elem, $name);
check_no_attributes!(elem, $name); check_no_attributes!(elem, $name);
@ -351,8 +351,8 @@ macro_rules! generate_id {
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct $elem(pub String); pub struct $elem(pub String);
impl ::std::str::FromStr for $elem { impl ::std::str::FromStr for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn from_str(s: &str) -> Result<$elem, crate::error::Error> { fn from_str(s: &str) -> Result<$elem, crate::util::error::Error> {
// TODO: add a way to parse that differently when needed. // TODO: add a way to parse that differently when needed.
Ok($elem(String::from(s))) Ok($elem(String::from(s)))
} }
@ -371,15 +371,15 @@ macro_rules! generate_elem_id {
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct $elem(pub String); pub struct $elem(pub String);
impl ::std::str::FromStr for $elem { impl ::std::str::FromStr for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn from_str(s: &str) -> Result<$elem, crate::error::Error> { fn from_str(s: &str) -> Result<$elem, crate::util::error::Error> {
// TODO: add a way to parse that differently when needed. // TODO: add a way to parse that differently when needed.
Ok($elem(String::from(s))) Ok($elem(String::from(s)))
} }
} }
impl ::try_from::TryFrom<::minidom::Element> for $elem { impl ::try_from::TryFrom<::minidom::Element> for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::error::Error> { fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::util::error::Error> {
check_self!(elem, $name, $ns); check_self!(elem, $name, $ns);
check_no_children!(elem, $name); check_no_children!(elem, $name);
check_no_attributes!(elem, $name); check_no_attributes!(elem, $name);
@ -440,7 +440,7 @@ macro_rules! do_parse_elem {
}; };
($temp:ident: Option = $constructor:ident => $elem:ident, $name:tt, $parent_name:tt) => { ($temp:ident: Option = $constructor:ident => $elem:ident, $name:tt, $parent_name:tt) => {
if $temp.is_some() { if $temp.is_some() {
return Err(crate::error::Error::ParseError(concat!( return Err(crate::util::error::Error::ParseError(concat!(
"Element ", "Element ",
$parent_name, $parent_name,
" must not have more than one ", " must not have more than one ",
@ -452,7 +452,7 @@ macro_rules! do_parse_elem {
}; };
($temp:ident: Required = $constructor:ident => $elem:ident, $name:tt, $parent_name:tt) => { ($temp:ident: Required = $constructor:ident => $elem:ident, $name:tt, $parent_name:tt) => {
if $temp.is_some() { if $temp.is_some() {
return Err(crate::error::Error::ParseError(concat!( return Err(crate::util::error::Error::ParseError(concat!(
"Element ", "Element ",
$parent_name, $parent_name,
" must not have more than one ", " must not have more than one ",
@ -472,7 +472,7 @@ macro_rules! finish_parse_elem {
$temp $temp
}; };
($temp:ident: Required = $name:tt, $parent_name:tt) => { ($temp:ident: Required = $name:tt, $parent_name:tt) => {
$temp.ok_or(crate::error::Error::ParseError(concat!( $temp.ok_or(crate::util::error::Error::ParseError(concat!(
"Missing child ", "Missing child ",
$name, $name,
" in ", " in ",
@ -540,9 +540,9 @@ macro_rules! generate_element {
} }
impl ::try_from::TryFrom<::minidom::Element> for $elem { impl ::try_from::TryFrom<::minidom::Element> for $elem {
type Err = crate::error::Error; type Err = crate::util::error::Error;
fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::error::Error> { fn try_from(elem: ::minidom::Element) -> Result<$elem, crate::util::error::Error> {
check_self!(elem, $name, $ns); check_self!(elem, $name, $ns);
check_no_unknown_attributes!(elem, $name, [$($attr_name),*]); check_no_unknown_attributes!(elem, $name, [$($attr_name),*]);
$( $(
@ -555,7 +555,7 @@ macro_rules! generate_element {
continue; continue;
} }
)* )*
return Err(crate::error::Error::ParseError(concat!("Unknown child in ", $name, " element."))); return Err(crate::util::error::Error::ParseError(concat!("Unknown child in ", $name, " element.")));
} }
Ok($elem { Ok($elem {
$( $(

View file

@ -41,7 +41,7 @@ impl IqResultPayload for VersionResult {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::compare_elements::NamespaceAwareCompare; use crate::util::compare_elements::NamespaceAwareCompare;
use minidom::Element; use minidom::Element;
use try_from::TryFrom; use try_from::TryFrom;