2017-06-03 23:37:46 +00:00
|
|
|
extern crate futures;
|
|
|
|
extern crate tokio_core;
|
|
|
|
extern crate tokio_xmpp;
|
2017-06-04 22:42:35 +00:00
|
|
|
extern crate rustls;
|
2017-06-03 23:37:46 +00:00
|
|
|
|
2017-06-04 22:42:35 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
use std::io::BufReader;
|
|
|
|
use std::fs::File;
|
2017-06-03 23:37:46 +00:00
|
|
|
use tokio_core::reactor::Core;
|
|
|
|
use futures::{Future, Stream};
|
2017-06-04 22:42:35 +00:00
|
|
|
use tokio_xmpp::{Packet, TcpClient, StartTlsClient};
|
|
|
|
use rustls::ClientConfig;
|
2017-06-03 23:37:46 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
use std::net::ToSocketAddrs;
|
|
|
|
let addr = "[2a01:4f8:a0:33d0::5]:5222"
|
|
|
|
.to_socket_addrs().unwrap()
|
|
|
|
.next().unwrap();
|
|
|
|
|
2017-06-04 22:42:35 +00:00
|
|
|
let mut config = ClientConfig::new();
|
|
|
|
let mut certfile = BufReader::new(File::open("/usr/share/ca-certificates/CAcert/root.crt").unwrap());
|
|
|
|
config.root_store.add_pem_file(&mut certfile).unwrap();
|
|
|
|
let arc_config = Arc::new(config);
|
|
|
|
|
2017-06-03 23:37:46 +00:00
|
|
|
let mut core = Core::new().unwrap();
|
|
|
|
let client = TcpClient::connect(
|
|
|
|
&addr,
|
|
|
|
&core.handle()
|
2017-06-04 22:42:35 +00:00
|
|
|
).and_then(|stream| StartTlsClient::from_stream(stream, arc_config)
|
2017-06-03 23:37:46 +00:00
|
|
|
).and_then(|stream| {
|
|
|
|
stream.for_each(|event| {
|
|
|
|
match event {
|
|
|
|
Packet::Stanza(el) => println!("<< {}", el),
|
|
|
|
_ => println!("!! {:?}", event),
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
});
|
2017-06-04 22:42:35 +00:00
|
|
|
match core.run(client) {
|
|
|
|
Ok(_) => (),
|
|
|
|
Err(e) => {
|
|
|
|
println!("Fatal: {}", e);
|
|
|
|
()
|
|
|
|
}
|
|
|
|
}
|
2017-06-03 23:37:46 +00:00
|
|
|
}
|