1extern crate futures;
2extern crate tokio_core;
3extern crate tokio_xmpp;
4extern crate rustls;
5
6use std::sync::Arc;
7use std::io::BufReader;
8use std::fs::File;
9use tokio_core::reactor::Core;
10use futures::{Future, Stream};
11use tokio_xmpp::TcpClient;
12use tokio_xmpp::xmpp_codec::Packet;
13use rustls::ClientConfig;
14
15fn main() {
16 use std::net::ToSocketAddrs;
17 let addr = "[2a01:4f8:a0:33d0::5]:5222"
18 .to_socket_addrs().unwrap()
19 .next().unwrap();
20
21 let mut config = ClientConfig::new();
22 let mut certfile = BufReader::new(File::open("/usr/share/ca-certificates/CAcert/root.crt").unwrap());
23 config.root_store.add_pem_file(&mut certfile).unwrap();
24 let arc_config = Arc::new(config);
25
26 let mut core = Core::new().unwrap();
27 let client = TcpClient::connect(
28 &addr,
29 &core.handle()
30 ).and_then(|stream| {
31 if stream.can_starttls() {
32 stream.starttls(arc_config)
33 } else {
34 panic!("No STARTTLS")
35 }
36 }).and_then(|stream| {
37 stream.for_each(|event| {
38 match event {
39 Packet::Stanza(el) => println!("<< {}", el),
40 _ => println!("!! {:?}", event),
41 }
42 Ok(())
43 })
44 });
45 match core.run(client) {
46 Ok(_) => (),
47 Err(e) => {
48 println!("Fatal: {}", e);
49 ()
50 }
51 }
52}