Merge branch 'sonnyx/master'
This commit is contained in:
commit
c880820c4a
12 changed files with 625 additions and 637 deletions
1178
Cargo.lock
generated
1178
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
22
Cargo.toml
22
Cargo.toml
|
@ -12,17 +12,17 @@ keywords = ["xmpp", "tokio"]
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
futures = "0.1"
|
||||
tokio = "0.1"
|
||||
tokio-io = "0.1"
|
||||
tokio-codec = "0.1"
|
||||
bytes = "0.4"
|
||||
xml5ever = "0.14"
|
||||
futures = "0.1"
|
||||
idna = "0.2"
|
||||
native-tls = "0.2"
|
||||
tokio-tls = "0.2"
|
||||
sasl = "0.4"
|
||||
trust-dns-resolver = "0.11"
|
||||
trust-dns-proto = "0.7"
|
||||
xmpp-parsers = "0.13"
|
||||
idna = "0.1"
|
||||
quick-xml = "0.13"
|
||||
tokio = "0.1"
|
||||
tokio-codec = "0.1"
|
||||
trust-dns-resolver = "0.12"
|
||||
trust-dns-proto = "0.8"
|
||||
tokio-io = "0.1"
|
||||
tokio-tls = "0.2"
|
||||
quick-xml = "0.16"
|
||||
xml5ever = "0.15"
|
||||
xmpp-parsers = "0.15"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use futures::{future, Sink, Stream};
|
||||
use std::convert::TryFrom;
|
||||
use std::env::args;
|
||||
use std::process::exit;
|
||||
use tokio::runtime::current_thread::Runtime;
|
||||
|
@ -6,7 +7,6 @@ use tokio_xmpp::{Client, xmpp_codec::Packet};
|
|||
use xmpp_parsers::{
|
||||
Element,
|
||||
Jid,
|
||||
TryFrom,
|
||||
ns,
|
||||
iq::{
|
||||
Iq,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use futures::{future, Future, Sink, Stream};
|
||||
use std::convert::TryFrom;
|
||||
use std::env::args;
|
||||
use std::fs::{create_dir_all, File};
|
||||
use std::io::{self, Write};
|
||||
|
@ -21,7 +22,7 @@ use xmpp_parsers::{
|
|||
NodeName,
|
||||
},
|
||||
stanza_error::{StanzaError, ErrorType, DefinedCondition},
|
||||
Jid, TryFrom,
|
||||
Jid,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
|
@ -116,7 +117,7 @@ fn main() {
|
|||
let from = message.from.clone().unwrap();
|
||||
if let Some(body) = message.get_best_body(vec!["en"]) {
|
||||
if body.1 .0 == "die" {
|
||||
println!("Secret die command triggered by {}", from);
|
||||
println!("Secret die command triggered by {}", from.clone());
|
||||
wait_for_stream_end = true;
|
||||
tx.start_send(Packet::StreamEnd).unwrap();
|
||||
}
|
||||
|
@ -133,7 +134,7 @@ fn main() {
|
|||
let _metadata = AvatarMetadata::try_from(payload).unwrap();
|
||||
println!(
|
||||
"[1m{}[0m has published an avatar, downloading...",
|
||||
from
|
||||
from.clone()
|
||||
);
|
||||
let iq = download_avatar(&from);
|
||||
tx.start_send(Packet::Stanza(iq.into())).unwrap();
|
||||
|
@ -218,11 +219,11 @@ fn handle_iq_result(pubsub: PubSub, from: &Jid) {
|
|||
}
|
||||
|
||||
fn save_avatar(from: &Jid, id: String, data: &[u8]) -> io::Result<()> {
|
||||
let directory = format!("data/{}", from);
|
||||
let filename = format!("data/{}/{}", from, id);
|
||||
let directory = format!("data/{}", from.clone());
|
||||
let filename = format!("data/{}/{}", from.clone(), id);
|
||||
println!(
|
||||
"Saving avatar from [1m{}[0m to [4m{}[0m.",
|
||||
from, filename
|
||||
from.clone(), filename
|
||||
);
|
||||
create_dir_all(directory)?;
|
||||
let mut file = File::create(filename)?;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use futures::{future, Future, Sink, Stream};
|
||||
use std::convert::TryFrom;
|
||||
use std::env::args;
|
||||
use std::process::exit;
|
||||
use tokio::runtime::current_thread::Runtime;
|
||||
use tokio_xmpp::{Client, Packet};
|
||||
use xmpp_parsers::{Jid, Element, TryFrom};
|
||||
use xmpp_parsers::{Jid, Element};
|
||||
use xmpp_parsers::message::{Body, Message, MessageType};
|
||||
use xmpp_parsers::presence::{Presence, Show as PresenceShow, Type as PresenceType};
|
||||
|
||||
|
@ -56,7 +57,7 @@ fn main() {
|
|||
{
|
||||
match (message.from, message.bodies.get("")) {
|
||||
(Some(ref from), Some(ref body)) if body.0 == "die" => {
|
||||
println!("Secret die command triggered by {}", from);
|
||||
println!("Secret die command triggered by {}", from.clone());
|
||||
wait_for_stream_end = true;
|
||||
tx.start_send(Packet::StreamEnd).unwrap();
|
||||
}
|
||||
|
@ -87,7 +88,7 @@ fn main() {
|
|||
// Construct a <presence/>
|
||||
fn make_presence() -> Element {
|
||||
let mut presence = Presence::new(PresenceType::None);
|
||||
presence.show = PresenceShow::Chat;
|
||||
presence.show = Some(PresenceShow::Chat);
|
||||
presence
|
||||
.statuses
|
||||
.insert(String::from("en"), String::from("Echoing messages."));
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use futures::{future, Sink, Stream};
|
||||
use std::convert::TryFrom;
|
||||
use std::env::args;
|
||||
use std::process::exit;
|
||||
use std::str::FromStr;
|
||||
use tokio::runtime::current_thread::Runtime;
|
||||
use tokio_xmpp::Component;
|
||||
use xmpp_parsers::{Jid, Element, TryFrom};
|
||||
use xmpp_parsers::{Jid, Element};
|
||||
use xmpp_parsers::message::{Body, Message, MessageType};
|
||||
use xmpp_parsers::presence::{Presence, Show as PresenceShow, Type as PresenceType};
|
||||
|
||||
|
@ -31,7 +32,7 @@ fn main() {
|
|||
|
||||
// Make the two interfaces for sending and receiving independent
|
||||
// of each other so we can move one into a closure.
|
||||
println!("Got it: {}", component.jid);
|
||||
println!("Got it: {}", component.jid.clone());
|
||||
let (mut sink, stream) = component.split();
|
||||
// Wrap sink in Option so that we can take() it for the send(self)
|
||||
// to consume and return it back when ready.
|
||||
|
@ -83,7 +84,7 @@ fn make_presence(from: Jid, to: Jid) -> Element {
|
|||
let mut presence = Presence::new(PresenceType::None);
|
||||
presence.from = Some(from);
|
||||
presence.to = Some(to);
|
||||
presence.show = PresenceShow::Chat;
|
||||
presence.show = Some(PresenceShow::Chat);
|
||||
presence
|
||||
.statuses
|
||||
.insert(String::from("en"), String::from("Echoing messages."));
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use std::str::FromStr;
|
||||
use std::collections::HashSet;
|
||||
use std::convert::TryFrom;
|
||||
use futures::{Future, Poll, Stream, future::{ok, err, IntoFuture}};
|
||||
use sasl::client::mechanisms::{Anonymous, Plain, Scram};
|
||||
use sasl::client::Mechanism;
|
||||
use sasl::common::scram::{Sha1, Sha256};
|
||||
use sasl::common::Credentials;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use xmpp_parsers::TryFrom;
|
||||
use xmpp_parsers::sasl::{Auth, Challenge, Failure, Mechanism as XMPPMechanism, Response, Success};
|
||||
|
||||
use crate::xmpp_codec::Packet;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use futures::{sink, Async, Future, Poll, Stream};
|
||||
use std::convert::TryFrom;
|
||||
use std::mem::replace;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use xmpp_parsers::TryFrom;
|
||||
use xmpp_parsers::bind::Bind;
|
||||
use xmpp_parsers::Jid;
|
||||
use xmpp_parsers::bind::{BindQuery, BindResponse};
|
||||
use xmpp_parsers::iq::{Iq, IqType};
|
||||
|
||||
use crate::xmpp_codec::Packet;
|
||||
|
@ -32,8 +33,13 @@ impl<S: AsyncWrite> ClientBind<S> {
|
|||
ClientBind::Unsupported(stream)
|
||||
}
|
||||
Some(_) => {
|
||||
let resource = stream.jid.resource.clone();
|
||||
let iq = Iq::from_set(BIND_REQ_ID, Bind::new(resource));
|
||||
let resource;
|
||||
if let Jid::Full(jid) = stream.jid.clone() {
|
||||
resource = Some(jid.resource);
|
||||
} else {
|
||||
resource = None;
|
||||
}
|
||||
let iq = Iq::from_set(BIND_REQ_ID, BindQuery::new(resource));
|
||||
let send = stream.send_stanza(iq);
|
||||
ClientBind::WaitSend(send)
|
||||
}
|
||||
|
@ -68,11 +74,8 @@ impl<S: AsyncRead + AsyncWrite> Future for ClientBind<S> {
|
|||
match iq.payload {
|
||||
IqType::Result(payload) => {
|
||||
payload
|
||||
.and_then(|payload| Bind::try_from(payload).ok())
|
||||
.map(|bind| match bind {
|
||||
Bind::Jid(jid) => stream.jid = jid,
|
||||
_ => {}
|
||||
});
|
||||
.and_then(|payload| BindResponse::try_from(payload).ok())
|
||||
.map(|bind| stream.jid = bind.into());
|
||||
Ok(Async::Ready(stream))
|
||||
}
|
||||
_ => Err(ProtocolError::InvalidBindResponse)?,
|
||||
|
|
|
@ -60,11 +60,11 @@ impl Client {
|
|||
}
|
||||
|
||||
fn make_connect(jid: Jid, password: String) -> impl Future<Item = XMPPStream, Error = Error> {
|
||||
let username = jid.node.as_ref().unwrap().to_owned();
|
||||
let username = jid.clone().node().unwrap();
|
||||
let jid1 = jid.clone();
|
||||
let jid2 = jid.clone();
|
||||
let password = password;
|
||||
done(idna::domain_to_ascii(&jid.domain))
|
||||
done(idna::domain_to_ascii(&jid.domain()))
|
||||
.map_err(|_| Error::Idna)
|
||||
.and_then(|domain| {
|
||||
done(Connecter::from_lookup(
|
||||
|
|
|
@ -70,7 +70,7 @@ impl<S: AsyncRead + AsyncWrite> Future for StartTlsClient<S> {
|
|||
let stream = xmpp_stream.stream.into_inner();
|
||||
let connect =
|
||||
TlsConnector::from(NativeTlsConnector::builder().build().unwrap())
|
||||
.connect(&self.jid.domain, stream);
|
||||
.connect(&self.jid.clone().domain(), stream);
|
||||
let new_state = StartTlsClientState::StartingTls(connect);
|
||||
retry = true;
|
||||
(new_state, Ok(Async::NotReady))
|
||||
|
|
|
@ -26,7 +26,7 @@ enum StreamStartState<S: AsyncWrite> {
|
|||
impl<S: AsyncWrite> StreamStart<S> {
|
||||
pub fn from_stream(stream: Framed<S, XMPPCodec>, jid: Jid, ns: String) -> Self {
|
||||
let attrs = [
|
||||
("to".to_owned(), jid.domain.clone()),
|
||||
("to".to_owned(), jid.clone().domain()),
|
||||
("version".to_owned(), "1.0".to_owned()),
|
||||
("xmlns".to_owned(), ns.clone()),
|
||||
("xmlns:stream".to_owned(), NS_XMPP_STREAM.to_owned()),
|
||||
|
|
|
@ -501,7 +501,7 @@ mod tests {
|
|||
text = text + "A";
|
||||
}
|
||||
let stanza = Element::builder("message")
|
||||
.append(Element::builder("body").append(&text).build())
|
||||
.append(Element::builder("body").append(text.as_ref()).build())
|
||||
.build();
|
||||
let framed = framed.send(Packet::Stanza(stanza)).wait().expect("send");
|
||||
assert_eq!(
|
||||
|
|
Loading…
Reference in a new issue