diff --git a/Cargo.toml b/Cargo.toml index cf7735a0..aacdbc4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,4 @@ rustc-serialize = "*" jid = "*" domain = "0.2.1" xmpp-parsers = "0.6.0" +idna = "*" diff --git a/src/client/mod.rs b/src/client/mod.rs index b5d7e8fc..77641110 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -5,10 +5,11 @@ use tokio_core::reactor::Handle; use tokio_core::net::TcpStream; use tokio_io::{AsyncRead, AsyncWrite}; use tokio_tls::TlsStream; -use futures::{Future, Stream, Poll, Async, Sink, StartSend, AsyncSink}; +use futures::{future, Future, Stream, Poll, Async, Sink, StartSend, AsyncSink}; use minidom::Element; use jid::{Jid, JidParseError}; use sasl::common::{Credentials, ChannelBinding}; +use idna; use super::xmpp_codec::Packet; use super::xmpp_stream; @@ -53,19 +54,27 @@ impl Client { let jid1 = jid.clone(); let jid2 = jid.clone(); let password = password; + let domain = match idna::domain_to_ascii(&jid.domain) { + Ok(domain) => + domain, + Err(e) => + return Box::new(future::err(format!("{:?}", e))), + }; Box::new( - Connecter::from_lookup(handle, &jid.domain, "_xmpp-client._tcp", 5222) + Connecter::from_lookup(handle, &domain, "_xmpp-client._tcp", 5222) .expect("Connector::from_lookup") .and_then(move |tcp_stream| xmpp_stream::XMPPStream::start(tcp_stream, jid1, NS_JABBER_CLIENT.to_owned()) .map_err(|e| format!("{}", e)) ).and_then(|xmpp_stream| { if Self::can_starttls(&xmpp_stream) { - Self::starttls(xmpp_stream) + Ok(Self::starttls(xmpp_stream)) } else { - panic!("No STARTTLS") + Err("No STARTTLS".to_owned()) } - }).and_then(|tls_stream| + }).and_then(|starttls| + starttls + ).and_then(|tls_stream| XMPPStream::start(tls_stream, jid2, NS_JABBER_CLIENT.to_owned()) .map_err(|e| format!("{}", e)) ).and_then(move |xmpp_stream| { diff --git a/src/lib.rs b/src/lib.rs index 348c03b2..ce8ccb7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,7 @@ extern crate sasl; extern crate rustc_serialize as serialize; extern crate jid; extern crate domain; +extern crate idna; pub mod xmpp_codec; pub mod xmpp_stream;