Update jid dependency to 0.6.0: Jid split change

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2019-06-10 23:17:09 +02:00
parent 80bb6635a9
commit 1e3f940db9
9 changed files with 38 additions and 39 deletions

View file

@ -15,7 +15,7 @@ edition = "2018"
[dependencies]
minidom = "0.10.0"
jid = { version = "0.5.3", features = ["minidom"] }
jid = { version = "0.6.0", features = ["minidom"] }
base64 = "0.10"
digest = "0.8"
sha-1 = "0.8"

View file

@ -7,7 +7,7 @@
use crate::util::error::Error;
use crate::iq::{IqResultPayload, IqSetPayload};
use crate::ns;
use jid::Jid;
use jid::FullJid;
use minidom::Element;
use std::str::FromStr;
use std::convert::TryFrom;
@ -26,7 +26,7 @@ pub enum Bind {
Resource(String),
/// The full JID returned by the server for this client.
Jid(Jid),
Jid(FullJid),
}
impl Bind {
@ -61,7 +61,7 @@ impl TryFrom<Element> for Bind {
} else if child.is("jid", ns::BIND) {
check_no_attributes!(child, "jid");
check_no_children!(child, "jid");
bind = Bind::Jid(Jid::from_str(&child.text())?);
bind = Bind::Jid(FullJid::from_str(&child.text())?);
} else {
return Err(Error::ParseError("Unknown element in bind."));
}

View file

@ -101,6 +101,7 @@ generate_empty_element!(
#[cfg(test)]
mod tests {
use super::*;
use jid::BareJid;
#[cfg(target_pointer_width = "32")]
#[test]
@ -143,16 +144,14 @@ mod tests {
fn test_items() {
let elem: Element = "<blocklist xmlns='urn:xmpp:blocking'><item jid='coucou@coucou'/><item jid='domain'/></blocklist>".parse().unwrap();
let two_items = vec![
Jid {
Jid::Bare(BareJid {
node: Some(String::from("coucou")),
domain: String::from("coucou"),
resource: None,
},
Jid {
}),
Jid::Bare(BareJid {
node: None,
domain: String::from("domain"),
resource: None,
},
}),
];
let result_elem = elem.clone();

View file

@ -4,7 +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 jid::Jid;
use jid::BareJid;
generate_attribute!(
/// Whether a conference bookmark should be joined automatically.
@ -21,7 +21,7 @@ generate_element!(
autojoin: Default<Autojoin> = "autojoin",
/// The JID of the conference.
jid: Required<Jid> = "jid",
jid: Required<BareJid> = "jid",
/// A user-defined name for this conference.
name: Required<String> = "name",
@ -113,7 +113,7 @@ mod tests {
assert_eq!(storage.conferences[0].autojoin, Autojoin::True);
assert_eq!(
storage.conferences[0].jid,
Jid::bare("test-muc", "muc.localhost")
BareJid::new("test-muc", "muc.localhost")
);
assert_eq!(storage.conferences[0].name, "Test MUC");
assert_eq!(storage.conferences[0].clone().nick.unwrap(), "Coucou");

View file

@ -15,8 +15,8 @@
//! [`TryFrom<Element>`]: ../try_from/trait.TryFrom.html
//! [`Element`]: ../minidom/element/struct.Element.html
// Copyright (c) 2017-2018 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
// Copyright (c) 2017 Maxime “pep” Buquet <pep+code@bouah.net>
// Copyright (c) 2017-2019 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
// Copyright (c) 2017-2019 Maxime “pep” Buquet <pep@bouah.net>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@ -25,7 +25,7 @@
#![deny(missing_docs)]
pub use minidom::Element;
pub use jid::{Jid, JidParseError};
pub use jid::{Jid, BareJid, FullJid, JidParseError};
pub use std::convert::{TryFrom, TryInto};
pub use crate::util::error::Error;

View file

@ -7,7 +7,7 @@
use crate::util::error::Error;
use crate::ns;
use jid::Jid;
use jid::FullJid;
use minidom::Element;
use std::convert::TryFrom;
@ -82,7 +82,7 @@ Status, "status", MUC_USER, "code", {
#[derive(Debug, Clone, PartialEq)]
pub enum Actor {
/// The full JID associated with this user.
Jid(Jid),
Jid(FullJid),
/// The nickname of this user.
Nick(String),
@ -95,7 +95,7 @@ impl TryFrom<Element> for Actor {
check_self!(elem, "actor", MUC_USER);
check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]);
check_no_children!(elem, "actor");
let jid: Option<Jid> = get_attr!(elem, "jid", Option);
let jid: Option<FullJid> = get_attr!(elem, "jid", Option);
let nick = get_attr!(elem, "nick", Option);
match (jid, nick) {
@ -190,7 +190,7 @@ generate_element!(
affiliation: Required<Affiliation> = "affiliation",
/// The real JID of this user, if you are allowed to see it.
jid: Option<Jid> = "jid",
jid: Option<FullJid> = "jid",
/// The current nickname of this user.
nick: Option<String> = "nick",
@ -448,7 +448,7 @@ mod tests {
Actor::Jid(jid) => jid,
_ => panic!(),
};
assert_eq!(jid, "foo@bar/baz".parse::<Jid>().unwrap());
assert_eq!(jid, "foo@bar/baz".parse::<FullJid>().unwrap());
}
#[test]

View file

@ -5,7 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload};
use jid::Jid;
use jid::BareJid;
generate_elem_id!(
/// Represents a group a contact is part of.
@ -50,7 +50,7 @@ generate_element!(
Item, "item", ROSTER,
attributes: [
/// JID of this contact.
jid: Required<Jid> = "jid",
jid: Required<BareJid> = "jid",
/// Name of this contact.
name: OptionEmpty<String> = "name",
@ -172,7 +172,7 @@ mod tests {
assert_eq!(roster.items.len(), 4);
assert_eq!(
roster.items[0].jid,
Jid::from_str("romeo@example.net").unwrap()
BareJid::from_str("romeo@example.net").unwrap()
);
assert_eq!(roster.items[0].name, Some(String::from("Romeo")));
assert_eq!(roster.items[0].subscription, Subscription::Both);
@ -184,7 +184,7 @@ mod tests {
assert_eq!(
roster.items[3].jid,
Jid::from_str("contact@example.org").unwrap()
BareJid::from_str("contact@example.org").unwrap()
);
assert_eq!(roster.items[3].name, Some(String::from("MyContact")));
assert_eq!(roster.items[3].subscription, Subscription::None);
@ -213,7 +213,7 @@ mod tests {
assert_eq!(roster.items.len(), 1);
assert_eq!(
roster.items[0].jid,
Jid::from_str("test@example.org").unwrap()
BareJid::from_str("test@example.org").unwrap()
);
assert_eq!(roster.items[0].name, None);
assert_eq!(roster.items[0].groups.len(), 2);
@ -248,7 +248,7 @@ mod tests {
assert_eq!(roster.items.len(), 1);
assert_eq!(
roster.items[0].jid,
Jid::from_str("nurse@example.com").unwrap()
BareJid::from_str("nurse@example.com").unwrap()
);
assert_eq!(roster.items[0].name, Some(String::from("Nurse")));
assert_eq!(roster.items[0].groups.len(), 1);
@ -270,7 +270,7 @@ mod tests {
assert_eq!(roster.items.len(), 1);
assert_eq!(
roster.items[0].jid,
Jid::from_str("nurse@example.com").unwrap()
BareJid::from_str("nurse@example.com").unwrap()
);
assert!(roster.items[0].name.is_none());
assert!(roster.items[0].groups.is_empty());

View file

@ -4,17 +4,17 @@
// 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 jid::Jid;
use jid::BareJid;
generate_element!(
/// The stream opening for client-server communications.
Stream, "stream", STREAM,
attributes: [
/// The JID of the entity opening this stream.
from: Option<Jid> = "from",
from: Option<BareJid> = "from",
/// The JID of the entity receiving this stream opening.
to: Option<Jid> = "to",
to: Option<BareJid> = "to",
/// The id of the stream, used for authentication challenges.
id: Option<String> = "id",
@ -30,7 +30,7 @@ generate_element!(
impl Stream {
/// Creates a simple client→server `<stream:stream>` element.
pub fn new(to: Jid) -> Stream {
pub fn new(to: BareJid) -> Stream {
Stream {
from: None,
to: Some(to),
@ -42,7 +42,7 @@ impl Stream {
/// Sets the [@from](#structfield.from) attribute on this `<stream:stream>`
/// element.
pub fn with_from(mut self, from: Jid) -> Stream {
pub fn with_from(mut self, from: BareJid) -> Stream {
self.from = Some(from);
self
}
@ -92,7 +92,7 @@ mod tests {
fn test_simple() {
let elem: Element = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' xml:lang='en' version='1.0' id='abc' from='some-server.example'/>".parse().unwrap();
let stream = Stream::try_from(elem).unwrap();
assert_eq!(stream.from, Some(Jid::domain("some-server.example")));
assert_eq!(stream.from, Some(BareJid::domain("some-server.example")));
assert_eq!(stream.to, None);
assert_eq!(stream.id, Some(String::from("abc")));
assert_eq!(stream.version, Some(String::from("1.0")));

View file

@ -4,17 +4,17 @@
// 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 jid::Jid;
use jid::BareJid;
generate_element!(
/// The stream opening for WebSocket.
Open, "open", WEBSOCKET,
attributes: [
/// The JID of the entity opening this stream.
from: Option<Jid> = "from",
from: Option<BareJid> = "from",
/// The JID of the entity receiving this stream opening.
to: Option<Jid> = "to",
to: Option<BareJid> = "to",
/// The id of the stream, used for authentication challenges.
id: Option<String> = "id",
@ -30,7 +30,7 @@ generate_element!(
impl Open {
/// Creates a simple client→server `<open/>` element.
pub fn new(to: Jid) -> Open {
pub fn new(to: BareJid) -> Open {
Open {
from: None,
to: Some(to),
@ -42,7 +42,7 @@ impl Open {
/// Sets the [@from](#structfield.from) attribute on this `<open/>`
/// element.
pub fn with_from(mut self, from: Jid) -> Open {
pub fn with_from(mut self, from: BareJid) -> Open {
self.from = Some(from);
self
}