YEMBT7TB3QXWE2HZOWEBYCXBUZQIWQZI5KKNMLB77CMAXVNBQSFAC DCMDASHVXPPJMD7UDRII7XCIGDO5YDUBDXPZVI7TLXBJSAK7OI6AC CCLGGFKRUNXBM6IOGEYJOFULCSVOL6C5PFAGCKEWNXOZIKPWLLWQC FV6BJ5K64QG63YI2PTII44ZEBAYNJBQZ5FSBHW65EPHGBKFGUW4AC JY4F7VBCS4S2YYXT7JQBLPSCWW3K4H3NXH6G5WGJFWWQXN2YPIQAC VS6AHRWIPIMQNQAFX7INQGSUB72OW2K6HM6NGOV76RBRF6COQFRQC LL3D5CXKPWIGTQ7MFK4YXDGDZOKD6CU5WCIWV3FG6TPGQOGD75QAC LQXBWNFT7IKPKDARJA5F42TUMJ7ORNFK4PV53VWHVGVEY4WTAWZAC DYRPAV6TEJMS74SJZFIZGWBRKUHAUTZ5DZLUYYKVXY522JLSD5KQC FVVPKFTLD5VOGVDF7MOSSKQ3KPCT4HDGTNTTC6I6B4TWXOTPCJ7AC HKSQO7JZEW6GXKPDJD4VJSYCJJBUDLKVN7SGUU5ZEMIVGII455RAC LNUU5R56C3AX27TD3SNYWZASUQHM5WQLAXXI6E7OBM57PZBLXYJQC use tokio_xmpp::{Client, Event, Packet};use tokio::prelude::future::{self, Either};use tokio::prelude::stream;use tokio::prelude::{Future, Stream};use std::collections::{HashMap, VecDeque};use std::time::{Duration, Instant};use super::stanzas;use super::element_processor;use crate::config;#[derive(Debug)]pub enum XmppCommand {/// Send message to someone by jidChat {xmpp_to: xmpp_parsers::Jid,message: String,},/// Send message to MUCChatroom { muc_id: String, message: String },/// Send ping request to the server to test connectionPing,/// Check iq requests if some have expired timeoutsTimeoutCleanup,}/// trait of processing iq/// each function consumes handlers and/// returns false if connection should be resettrait IqHandler {/// process resultfn result(self: Box<Self>,conn: &mut XmppConnection,opt_element: Option<xmpp_parsers::Element>,) -> bool;/// process errorfn error(self: Box<Self>,conn: &mut XmppConnection,error: xmpp_parsers::stanza_error::StanzaError,) -> bool;/// process tmeoutfn timeout(self: Box<Self>, conn: &mut XmppConnection) -> bool;}struct AddRosterIqHandler {jid: xmpp_parsers::Jid,}impl IqHandler for AddRosterIqHandler {fn result(self: Box<Self>,conn: &mut XmppConnection,opt_element: Option<xmpp_parsers::Element>,) -> bool {match opt_element {Some(element) => {warn!("Wrong payload when adding {} to roster: {}",self.jid,String::from(&element));}None => {if conn.state.data.roster.contains_key(&self.jid) {info!("Jid {} updated to roster", self.jid);} else {info!("Jid {} added in roster", self.jid);conn.state.data.roster.insert(self.jid.clone(),(xmpp_parsers::roster::Subscription::None,xmpp_parsers::roster::Ask::None,),);}conn.process_jid(&self.jid);}}true}fn error(self: Box<Self>,_conn: &mut XmppConnection,_error: xmpp_parsers::stanza_error::StanzaError,) -> bool {true}fn timeout(self: Box<Self>, _conn: &mut XmppConnection) -> bool {true // ignore}}struct PingIqHandler {}impl IqHandler for PingIqHandler {fn result(self: Box<Self>,_conn: &mut XmppConnection,_opt_element: Option<xmpp_parsers::Element>,) -> bool {info!("ping successed");true}fn error(self: Box<Self>,_conn: &mut XmppConnection,_error: xmpp_parsers::stanza_error::StanzaError,) -> bool {false}fn timeout(self: Box<Self>, _conn: &mut XmppConnection) -> bool {false}}struct InitRosterIqHandler {}impl IqHandler for InitRosterIqHandler {fn result(self: Box<Self>,conn: &mut XmppConnection,opt_element: Option<xmpp_parsers::Element>,) -> bool {if let Some(result) = opt_element {use std::convert::TryInto;match result.try_into() as Result<xmpp_parsers::roster::Roster, _> {Ok(roster) => {conn.state.data.roster_init = true;conn.state.data.roster.clear();info!("Got first roster:");for i in roster.items {info!(" >>> {:?}", i);conn.state.data.roster.insert(i.jid, (i.subscription, i.ask));}true}Err(e) => {error!("Cann't parse roster: {}", e);false}}} else {error!("No roster responded");false}}fn error(self: Box<Self>,_conn: &mut XmppConnection,_error: xmpp_parsers::stanza_error::StanzaError,) -> bool {false}fn timeout(self: Box<Self>, _conn: &mut XmppConnection) -> bool {false}}#[derive(Default)]struct XmppData {/// known roster dataroster: HashMap<xmpp_parsers::Jid,(xmpp_parsers::roster::Subscription,xmpp_parsers::roster::Ask,),>,/// if roster was initialized/// ToDo: remove it as it is used only for initializationroster_init: bool,/// if self-presence accepted/// ToDo: remove it as it is used only for initializationself_presence: bool,/// ids countercounter: usize,/// stanzas to sendsend_queue: VecDeque<minidom::Element>,/// outgoing mailboxoutgoing_mailbox: HashMap<xmpp_parsers::Jid, Vec<String>>,/// muc id to muc jidmucs: HashMap<String, xmpp_parsers::Jid>,/// map from iq's id to handler of this type of iqspending_ids: HashMap<String, (Instant, Box<dyn IqHandler>)>,}struct XmppState {client: Client,data: XmppData,}pub struct XmppConnection {account: std::rc::Rc<config::Account>,state: XmppState,}trait IqRequestHandler {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq;}struct IqRequestUnknown {element: xmpp_parsers::Element,type_: &'static str,}impl IqRequestHandler for IqRequestUnknown {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {warn!("Unsupported IQ {} request from {:?}: {}",self.type_,from,String::from(&self.element));stanzas::make_iq_unsupported_error(id, conn.state.client.jid.clone(), from)}}struct IqSetRoster {}impl IqRequestHandler for IqSetRoster {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {info!("Got roster push {} from {:?}", id, from);stanzas::make_roster_push_answer(id, conn.state.client.jid.clone(), from)}}struct IqGetPing {}impl IqRequestHandler for IqGetPing {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {info!("Got ping {} from {:?}", id, from);stanzas::make_pong(id, conn.state.client.jid.clone(), from)}}struct IqGetDiscoInfo {}impl IqRequestHandler for IqGetDiscoInfo {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {info!("Got disco query {} from {:?}", id, from);stanzas::make_disco_info_result(id, conn.state.client.jid.clone(), from)}}struct IqGetDiscoItems {}impl IqRequestHandler for IqGetDiscoItems {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {info!("Got disco items query {} from {:?}", id, from);stanzas::make_disco_items_result(id, conn.state.client.jid.clone(), from)}}struct IqGetDiscoCommands {}impl IqRequestHandler for IqGetDiscoCommands {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {info!("Got disco commands query {} from {:?}", id, from);stanzas::make_disco_items_commands(id, conn.state.client.jid.clone(), from)}}lazy_static! {static ref INCOMING: element_processor::Processor<XmppConnection, bool, xmpp_parsers::Element> = {let mut incoming = element_processor::Processor::new(&|_, e| {warn!("Unknown stanza {}", String::from(&e));true});incoming.register(&XmppConnection::incoming_iq_processing);incoming.register(&XmppConnection::incoming_presence_processing);incoming.register(&XmppConnection::incoming_message_processing);incoming};static ref INCOMING_IQ_SET: element_processor::Processor<XmppConnection, Box<dyn IqRequestHandler>, xmpp_parsers::Element> = {let mut iq_set =element_processor::Processor::new(&|_conn: &mut XmppConnection, element| {Box::new(IqRequestUnknown {element,type_: "set",}) as Box<dyn IqRequestHandler>});iq_set.register(&XmppConnection::incoming_iq_processing_set_roster);iq_set};static ref INCOMING_IQ_GET: element_processor::Processor<XmppConnection, Box<dyn IqRequestHandler>, xmpp_parsers::Element> = {let mut iq_get =element_processor::Processor::new(&|_conn: &mut XmppConnection, element| {Box::new(IqRequestUnknown {element,type_: "get",}) as Box<dyn IqRequestHandler>});iq_get.register(&XmppConnection::incoming_iq_processing_get_ping);iq_get.register(&XmppConnection::incoming_iq_processing_get_disco_info);iq_get.register(&XmppConnection::incoming_iq_processing_get_disco_items);iq_get};}pub struct MaybeXmppConnection {account: std::rc::Rc<config::Account>,state: Option<XmppState>,}impl From<XmppConnection> for MaybeXmppConnection {fn from(from: XmppConnection) -> MaybeXmppConnection {MaybeXmppConnection {account: from.account,state: Some(from.state),}}}impl From<config::Account> for MaybeXmppConnection {fn from(from: config::Account) -> MaybeXmppConnection {MaybeXmppConnection {account: std::rc::Rc::new(from),state: None,}}}impl From<std::rc::Rc<config::Account>> for MaybeXmppConnection {fn from(from: std::rc::Rc<config::Account>) -> MaybeXmppConnection {MaybeXmppConnection {account: from,state: None,}}}impl MaybeXmppConnection {/// connects if nothing connected/// don't connect only if stop_future resolvedpub fn connect<F>(self,stop_future: F,) -> impl Future<Item = XmppConnection, Error = failure::Error>whereF: future::Future + Clone + 'static,<F as hyper::rt::Future>::Error: Into<failure::Error> + Send,{info!("xmpp connection...");let MaybeXmppConnection { account, state } = self;if let Some(state) = state {Box::new(future::ok(XmppConnection { account, state }))as Box<dyn Future<Item = _, Error = _>>} else {Box::new(stop_future.clone().select2(future::loop_fn(account, move |account| {info!("xmpp initialization...");let client =Client::new_with_jid(account.jid.clone(), &account.password);info!("xmpp initialized");let stop_future2 = stop_future.clone();let stop_future3 = stop_future.clone();let stop_future4 = stop_future.clone();// future to wait for onlineBox::new(XmppConnection {state: XmppState {client,data: std::default::Default::default(),},account,}.processing(XmppConnection::online, stop_future.clone()).map_err(|(acc, _)| acc).and_then(|(conn, r)| match r {Ok(Either::A(_)) => future::ok(conn),Ok(Either::B(_)) => future::err(conn.account),Err(_e) => future::err(conn.account),}).and_then(|conn| conn.initial_roster(stop_future2)).and_then(|conn| conn.self_presence(stop_future3)).and_then(|conn| conn.enter_mucs(stop_future4)).then(|r| match r {Ok(conn) => future::ok(future::Loop::Break(conn)),Err(acc) => future::ok(future::Loop::Continue(acc)),}),)}).map_err(|_: ()| ()),).then(|r| match r {Ok(Either::A((_x, _b))) => future::err(format_err!("Stop XMMP connection")),Ok(Either::B((x, _a))) => future::ok(x),Err(Either::A((e, _b))) => future::err(e.into()),Err(Either::B((_, _a))) => {future::err(format_err!("Cann't initiate XMPP connection"))}}),)}}}impl XmppConnection {/// base XMPP processing/// Returns false on error to disconnectfn xmpp_processing(&mut self, event: &Event) -> bool {match event {Event::Stanza(stanza) => INCOMING.process(self, stanza.clone()),Event::Online => true,e => {warn!("Unexpected event {:?}", e);false}}}/// Process roster push/// see RFC 6212 2.1.6. Roster Pushfn incoming_iq_processing_set_roster(&mut self,roster: xmpp_parsers::roster::Roster,) -> Box<dyn IqRequestHandler> {for i in roster.items {if let Some(ref mut rdata) = self.state.data.roster.get_mut(&i.jid) {info!("Update {} in roster", i.jid);rdata.0 = i.subscription;rdata.1 = i.ask;} else {info!("Add {} to roster", i.jid);self.state.data.roster.insert(i.jid.clone(), (i.subscription, i.ask));}self.process_jid(&i.jid);}Box::new(IqSetRoster {})}/// Enforce to answer to IQ "set"fn incoming_iq_processing_set(&mut self,id: String,from: Option<xmpp_parsers::Jid>,element: minidom::Element,) -> xmpp_parsers::iq::Iq {INCOMING_IQ_SET.process(self, element).process(self, id, from)}/// Process ping request/// see XEP-0199: XMPP Pingfn incoming_iq_processing_get_ping(&mut self,_ping: xmpp_parsers::ping::Ping,) -> Box<dyn IqRequestHandler> {Box::new(IqGetPing {})}/// Process disco query/// see XEP-0030: Service Discoveryfn incoming_iq_processing_get_disco_info(&mut self,disco: xmpp_parsers::disco::DiscoInfoQuery,) -> Box<dyn IqRequestHandler> {if let Some(ref node) = disco.node {warn!("Unsupported node {}", node);Box::new(IqRequestUnknown {element: disco.into(),type_: "get",})} else {Box::new(IqGetDiscoInfo {})}}/// Process disco items query/// see XEP-0030: Service Discoveryfn incoming_iq_processing_get_disco_items(&mut self,disco: xmpp_parsers::disco::DiscoItemsQuery,) -> Box<dyn IqRequestHandler> {match &disco.node {Some(node) if node == "http://jabber.org/protocol/commands" => {Box::new(IqGetDiscoCommands {})}Some(node) => {warn!("Unsupported node {}", node);Box::new(IqRequestUnknown {element: disco.into(),type_: "get",})}None => Box::new(IqGetDiscoItems {}),}}/// Enforce to answer to IQ "get"fn incoming_iq_processing_get(&mut self,id: String,from: Option<xmpp_parsers::Jid>,element: minidom::Element,) -> xmpp_parsers::iq::Iq {INCOMING_IQ_GET.process(self, element).process(self, id, from)}fn incoming_iq_processing(&mut self, iq: xmpp_parsers::iq::Iq) -> bool {match iq.payload {xmpp_parsers::iq::IqType::Set(element) => {let iq_answer = self.incoming_iq_processing_set(iq.id, iq.from, element);self.state.data.send_queue.push_back(iq_answer.into());}xmpp_parsers::iq::IqType::Error(e) => {if let Some((_, handler)) = self.state.data.pending_ids.remove_entry(&iq.id) {return handler.1.error(self, e);}error!("iq error: {:?}", e);return false;}xmpp_parsers::iq::IqType::Get(element) => {let iq_answer = self.incoming_iq_processing_get(iq.id, iq.from, element);self.state.data.send_queue.push_back(iq_answer.into());}xmpp_parsers::iq::IqType::Result(opt_element) => {if let Some((_, handler)) = self.state.data.pending_ids.remove_entry(&iq.id) {return handler.1.result(self, opt_element);}warn!("Unwanted iq result id {} from {:?}: {:?}",iq.id,iq.from,opt_element.map(|e| String::from(&e)));}}true}fn incoming_presence_processing(&mut self, presence: xmpp_parsers::presence::Presence) -> bool {if presence.from.as_ref() == Some(&self.state.client.jid) {info!("Self-presence accepted");self.state.data.self_presence = true;} else {warn!("Incoming presence stanza: {:?}", presence);}true}fn incoming_message_processing(&mut self, message: xmpp_parsers::message::Message) -> bool {for payload in message.payloads.iter() {use std::convert::TryInto;if let Some(_delay) =payload.clone().try_into().ok() as Option<xmpp_parsers::delay::Delay>{return true; // ignore delayed messages}}warn!("Incoming message stanza: {:?}", message);true}/// process event from xmpp stream/// returns from future when condition met/// or stop future was resolved./// Return item if connection was preserved or error otherwise./// Second part is a state of stop_futurepub fn processing<S, F, T, E>(self,stop_condition: S,stop_future: F,) -> impl Future<Item = (Self, Result<Either<F, T>, E>),Error = (std::rc::Rc<config::Account>, Result<Either<F, T>, E>),>whereF: Future<Item = T, Error = E> + 'static,S: FnMut(&mut Self, Event) -> Result<bool, ()> + 'static,T: 'static,E: 'static,{future::loop_fn((self, stop_future, stop_condition),|(xmpp, stop_future, mut stop_condition)| {// ToDo: check timeouts if iqslet XmppConnection {state: XmppState { client, mut data },account,} = xmpp;if let Some(send_element) = data.send_queue.pop_front() {use tokio::prelude::Sink;info!("Sending {}", String::from(&send_element));Box::new(client.send(Packet::Stanza(send_element)).select2(stop_future).then(move |r| match r {Ok(Either::A((client, b))) => {Box::new(future::ok(future::Loop::Continue((XmppConnection {state: XmppState { client, data },account,},b,stop_condition,))))as Box<dyn Future<Item = _, Error = _>>}Ok(Either::B((t, a))) => Box::new(a.then(|r| match r {Ok(client) => future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Ok(Either::B(t)),))),Err(se) => {warn!("XMPP sending error: {}", se);future::err((account, Ok(Either::B(t))))}})),Err(Either::A((e, b))) => {warn!("XMPP sending error: {}", e);Box::new(future::err((account, Ok(Either::A(b)))))}Err(Either::B((e, a))) => Box::new(a.then(|r| match r {Ok(client) => future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Err(e),))),Err(se) => {warn!("XMPP sending error: {}", se);future::err((account, Err(e)))}})),}),) as Box<dyn Future<Item = _, Error = _>>} else {Box::new(client.into_future().select2(stop_future).then(move |r| match r {Ok(Either::A(((event, client), b))) => {if let Some(event) = event {let mut xmpp = XmppConnection {state: XmppState { client, data },account,};if xmpp.xmpp_processing(&event) {match stop_condition(&mut xmpp, event) {Ok(true) => future::ok(future::Loop::Break((xmpp,Ok(Either::A(b)),))),Ok(false) => future::ok(future::Loop::Continue((xmpp,b,stop_condition,))),Err(_e) => {future::err((xmpp.account, Ok(Either::A(b))))}}} else {future::err((xmpp.account, Ok(Either::A(b))))}} else {future::err((account, Ok(Either::A(b))))}}Ok(Either::B((t, a))) => {if let Some(client) = a.into_inner() {future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Ok(Either::B(t)),)))} else {future::err((account, Ok(Either::B(t))))}}Err(Either::A((e, b))) => {warn!("XMPP error: {}", e.0);future::err((account, Ok(Either::A(b))))}Err(Either::B((e, a))) => {if let Some(client) = a.into_inner() {future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Err(e),)))} else {future::err((account, Err(e)))}}}),)}},)}/// get connection and wait for online status and set presence/// returns error if something went wrong and xmpp connection is brokenfn online(&mut self, event: Event) -> Result<bool, ()> {match event {Event::Online => {info!("Online!");Ok(true)}Event::Stanza(s) => {warn!("Stanza before online: {}", String::from(&s));Ok(false)}_ => {error!("Disconnected while online");Err(())}}}fn initial_roster<F, E>(self,stop_future: F,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>whereF: Future<Error = E> + 'static,E: 'static,{let XmppConnection {account,state: XmppState { client, mut data },} = self;use tokio::prelude::Sink;data.counter += 1;let id_init_roster = format!("id_init_roster{}", data.counter);let get_roster = stanzas::make_get_roster(&id_init_roster);let account2 = account.clone();info!("Quering roster... {}", String::from(&get_roster));data.pending_ids.insert(id_init_roster.clone(),(Instant::now() + Duration::from_secs(60),Box::new(InitRosterIqHandler {}),),);client.send(Packet::Stanza(get_roster)).map_err(move |e| {error!("Error on querying roster: {}", e);account2}).and_then(move |client| {XmppConnection {state: XmppState { client, data },account,}.processing(move |conn, _| Ok(conn.state.data.roster_init), stop_future).map_err(|(account, _)| account).and_then(|(conn, r)| match r {Ok(Either::A(_)) => future::ok(conn),Ok(Either::B(_)) => future::err(conn.account),Err(_e) => future::err(conn.account),})})}fn self_presence<F, E>(self,stop_future: F,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>whereF: Future<Error = E> + 'static,E: Into<failure::Error> + 'static,{let XmppConnection {account,state: XmppState { client, data },} = self;use tokio::prelude::Sink;let presence = stanzas::make_presence(&account);let account2 = account.clone();info!("Sending presence... {}", String::from(&presence));client.send(Packet::Stanza(presence)).map_err(|e| {error!("Error on send self-presence: {}", e);account2}).and_then(move |client| {XmppConnection {state: XmppState { client, data },account,}.processing(move |conn, _| Ok(conn.state.data.self_presence),stop_future,).map_err(|(account, _)| account).and_then(|(conn, r)| match r {Ok(Either::A(_)) => future::ok(conn),Ok(Either::B(_)) => future::err(conn.account),Err(_e) => future::err(conn.account),})})}fn process_jid(&mut self, xmpp_to: &xmpp_parsers::Jid) {if let Some(ref mut mailbox) = self.state.data.outgoing_mailbox.get_mut(xmpp_to) {if !mailbox.is_empty() {if let Some(ref mut rdata) = self.state.data.roster.get_mut(xmpp_to) {info!("Jid {} in roster", xmpp_to);let sub_to = match rdata.0 {xmpp_parsers::roster::Subscription::To => true,xmpp_parsers::roster::Subscription::Both => true,_ => false,};if sub_to {info!("Subscribed to {}", xmpp_to);self.state.data.send_queue.extend(mailbox.drain(..).map(|message| {stanzas::make_chat_message(xmpp_to.clone(), message)}),);} else if rdata.1 == xmpp_parsers::roster::Ask::None {info!("Not subscribed to {}", xmpp_to);self.state.data.send_queue.push_back(stanzas::make_ask_subscribe(xmpp_to.clone()));}let sub_from = match rdata.0 {xmpp_parsers::roster::Subscription::From => true,xmpp_parsers::roster::Subscription::Both => true,_ => false,};if !sub_from {info!("Not subscription from {}", xmpp_to);self.state.data.send_queue.push_back(stanzas::make_allow_subscribe(xmpp_to.clone()));}} else {info!("Jid {} not in roster", xmpp_to);self.state.data.counter += 1;let id_add_roster = format!("id_add_roster{}", self.state.data.counter);let add_roster = stanzas::make_add_roster(&id_add_roster, xmpp_to.clone());info!("Adding jid {} to roster id {}", xmpp_to, id_add_roster);self.state.data.pending_ids.insert(id_add_roster,(Instant::now() + Duration::from_secs(60),Box::new(AddRosterIqHandler {jid: xmpp_to.clone(),}),),);self.state.data.send_queue.push_back(add_roster);}}}}pub fn process_command(&mut self, cmd: XmppCommand) {info!("Got command");match cmd {XmppCommand::Chat { xmpp_to, message } => {self.state.data.outgoing_mailbox.entry(xmpp_to.clone()).or_default().push(message);self.process_jid(&xmpp_to);}XmppCommand::Chatroom { muc_id, message } => {if let Some(muc) = self.state.data.mucs.get(&muc_id) {self.state.data.send_queue.push_back(stanzas::make_muc_message(muc.clone(), message));} else {error!("Not found MUC {}", muc_id);}}XmppCommand::Ping => {self.state.data.counter += 1;let id_ping = format!("id_ping{}", self.state.data.counter);let ping = stanzas::make_ping(&id_ping, self.state.client.jid.clone());self.state.data.send_queue.push_back(ping);self.state.data.pending_ids.insert(id_ping,(Instant::now() + Duration::from_secs(30),Box::new(PingIqHandler {}),),);}XmppCommand::TimeoutCleanup => {let now = Instant::now();let timeouted: Vec<String> = self.state.data.pending_ids.iter().filter_map(|(id, (timeout, _))| {if now >= *timeout {Some(id.to_string())} else {None}}).collect();let mut correct = true;timeouted.into_iter().for_each(|id| {if let Some((_, handler)) = self.state.data.pending_ids.remove(&id) {correct &= handler.timeout(&mut self);}})}}}pub fn shutdown(self) -> impl Future<Item = (), Error = failure::Error> {info!("Shutdown connection");let XmppConnection { account, state } = self;stream::iter_ok(state.data.mucs.values().map(std::clone::Clone::clone).collect::<Vec<_>>(),).fold(state, move |XmppState { client, data }, muc_jid| {let muc_presence =stanzas::make_muc_presence_leave(account.jid.clone(), muc_jid.clone());info!("Sending muc leave presence... {}",String::from(&muc_presence));use tokio::prelude::Sink;client.send(Packet::Stanza(muc_presence)).map_err(|e| {error!("Error on send muc presence: {}", e);e}).and_then(|client| future::ok(XmppState { client, data }))}).map(|_| ())}fn enter_mucs<F, E>(self,_stop_future: F,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>whereF: Future<Error = E> + 'static,E: Into<failure::Error> + 'static,{let XmppConnection { account, state } = self;let account2 = account.clone();let account3 = account.clone();stream::iter_ok(account.chatrooms.clone()).fold(state, move |XmppState { client, mut data }, muc_jid| {data.counter += 1;let id_muc_presence = format!("id_muc_presence{}", data.counter);let muc_presence = stanzas::make_muc_presence(&id_muc_presence,account2.jid.clone(),muc_jid.1.clone(),);info!("Sending muc presence... {}", String::from(&muc_presence));let account4 = account2.clone();use tokio::prelude::Sink;client.send(Packet::Stanza(muc_presence)).map_err(|e| {error!("Error on send muc presence: {}", e);account4}).and_then(|client| {data.mucs.insert(muc_jid.0, muc_jid.1);future::ok(XmppState { client, data })})}).map(|state| XmppConnection {account: account3,state,})}}
use tokio_xmpp::{Client, Event, Packet};use tokio::prelude::future::{self, Either};use tokio::prelude::stream;use tokio::prelude::{Future, Stream};use std::collections::{HashMap, VecDeque};use std::time::{Duration, Instant};use super::stanzas;use super::element_processor;use crate::config;#[derive(Debug)]pub enum XmppCommand {/// Send message to someone by jidChat {xmpp_to: xmpp_parsers::Jid,message: String,},/// Send message to MUCChatroom { muc_id: String, message: String },/// Send ping request to the server to test connectionPing,/// Check iq requests if some have expired timeoutsTimeoutCleanup,}/// trait of processing iq/// each function consumes handlers and/// returns false if connection should be resettrait IqHandler {/// process resultfn result(self: Box<Self>,conn: &mut XmppConnection,opt_element: Option<xmpp_parsers::Element>,) -> bool;/// process errorfn error(self: Box<Self>,conn: &mut XmppConnection,error: xmpp_parsers::stanza_error::StanzaError,) -> bool;/// process tmeoutfn timeout(self: Box<Self>, conn: &mut XmppConnection) -> bool;}struct AddRosterIqHandler {jid: xmpp_parsers::Jid,}impl IqHandler for AddRosterIqHandler {fn result(self: Box<Self>,conn: &mut XmppConnection,opt_element: Option<xmpp_parsers::Element>,) -> bool {match opt_element {Some(element) => {warn!("Wrong payload when adding {} to roster: {}",self.jid,String::from(&element));}None => {if conn.state.data.roster.contains_key(&self.jid) {info!("Jid {} updated to roster", self.jid);} else {info!("Jid {} added in roster", self.jid);conn.state.data.roster.insert(self.jid.clone(),(xmpp_parsers::roster::Subscription::None,xmpp_parsers::roster::Ask::None,),);}conn.process_jid(&self.jid);}}true}fn error(self: Box<Self>,_conn: &mut XmppConnection,_error: xmpp_parsers::stanza_error::StanzaError,) -> bool {true}fn timeout(self: Box<Self>, _conn: &mut XmppConnection) -> bool {true // ignore}}struct PingIqHandler {}impl IqHandler for PingIqHandler {fn result(self: Box<Self>,_conn: &mut XmppConnection,_opt_element: Option<xmpp_parsers::Element>,) -> bool {info!("ping successed");true}fn error(self: Box<Self>,_conn: &mut XmppConnection,_error: xmpp_parsers::stanza_error::StanzaError,) -> bool {false}fn timeout(self: Box<Self>, _conn: &mut XmppConnection) -> bool {false}}struct InitRosterIqHandler {}impl IqHandler for InitRosterIqHandler {fn result(self: Box<Self>,conn: &mut XmppConnection,opt_element: Option<xmpp_parsers::Element>,) -> bool {if let Some(result) = opt_element {use std::convert::TryInto;match result.try_into() as Result<xmpp_parsers::roster::Roster, _> {Ok(roster) => {conn.state.data.roster_init = true;conn.state.data.roster.clear();info!("Got first roster:");for i in roster.items {info!(" >>> {:?}", i);conn.state.data.roster.insert(i.jid, (i.subscription, i.ask));}true}Err(e) => {error!("Cann't parse roster: {}", e);false}}} else {error!("No roster responded");false}}fn error(self: Box<Self>,_conn: &mut XmppConnection,_error: xmpp_parsers::stanza_error::StanzaError,) -> bool {false}fn timeout(self: Box<Self>, _conn: &mut XmppConnection) -> bool {false}}#[derive(Default)]struct XmppData {/// known roster dataroster: HashMap<xmpp_parsers::Jid,(xmpp_parsers::roster::Subscription,xmpp_parsers::roster::Ask,),>,/// if roster was initialized/// ToDo: remove it as it is used only for initializationroster_init: bool,/// if self-presence accepted/// ToDo: remove it as it is used only for initializationself_presence: bool,/// ids countercounter: usize,/// stanzas to sendsend_queue: VecDeque<minidom::Element>,/// outgoing mailboxoutgoing_mailbox: HashMap<xmpp_parsers::Jid, Vec<String>>,/// muc id to muc jidmucs: HashMap<String, xmpp_parsers::Jid>,/// map from iq's id to handler of this type of iqspending_ids: HashMap<String, (Instant, Box<dyn IqHandler>)>,}struct XmppState {client: Client,data: XmppData,}pub struct XmppConnection {account: std::rc::Rc<config::Account>,state: XmppState,}trait IqRequestHandler {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq;}struct IqRequestUnknown {element: xmpp_parsers::Element,type_: &'static str,}impl IqRequestHandler for IqRequestUnknown {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {warn!("Unsupported IQ {} request from {:?}: {}",self.type_,from,String::from(&self.element));stanzas::make_iq_unsupported_error(id, conn.state.client.jid.clone(), from)}}struct IqSetRoster {}impl IqRequestHandler for IqSetRoster {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {info!("Got roster push {} from {:?}", id, from);stanzas::make_roster_push_answer(id, conn.state.client.jid.clone(), from)}}struct IqGetPing {}impl IqRequestHandler for IqGetPing {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {info!("Got ping {} from {:?}", id, from);stanzas::make_pong(id, conn.state.client.jid.clone(), from)}}struct IqGetVersion {}impl IqRequestHandler for IqGetVersion {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {info!("Got version query {} from {:?}", id, from);stanzas::make_version(id, conn.state.client.jid.clone(), from)}}struct IqGetDiscoInfo {}impl IqRequestHandler for IqGetDiscoInfo {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {info!("Got disco query {} from {:?}", id, from);stanzas::make_disco_info_result(id, conn.state.client.jid.clone(), from)}}struct IqGetDiscoItems {}impl IqRequestHandler for IqGetDiscoItems {fn process(self: Box<Self>,conn: &mut XmppConnection,id: String,from: Option<xmpp_parsers::Jid>,) -> xmpp_parsers::iq::Iq {info!("Got disco items query {} from {:?}", id, from);stanzas::make_disco_items_result(id, conn.state.client.jid.clone(), from)}}lazy_static! {static ref INCOMING: element_processor::Processor<XmppConnection, bool, xmpp_parsers::Element> = {let mut incoming = element_processor::Processor::new(&|_, e| {warn!("Unknown stanza {}", String::from(&e));true});incoming.register(&XmppConnection::incoming_iq_processing);incoming.register(&XmppConnection::incoming_presence_processing);incoming.register(&XmppConnection::incoming_message_processing);incoming};static ref INCOMING_IQ_SET: element_processor::Processor<XmppConnection, Box<dyn IqRequestHandler>, xmpp_parsers::Element> = {let mut iq_set =element_processor::Processor::new(&|_conn: &mut XmppConnection, element| {Box::new(IqRequestUnknown {element,type_: "set",}) as Box<dyn IqRequestHandler>});iq_set.register(&XmppConnection::incoming_iq_processing_set_roster);iq_set};static ref INCOMING_IQ_GET: element_processor::Processor<XmppConnection, Box<dyn IqRequestHandler>, xmpp_parsers::Element> = {let mut iq_get =element_processor::Processor::new(&|_conn: &mut XmppConnection, element| {Box::new(IqRequestUnknown {element,type_: "get",}) as Box<dyn IqRequestHandler>});iq_get.register(&XmppConnection::incoming_iq_processing_get_ping);iq_get.register(&XmppConnection::incoming_iq_processing_get_disco_info);iq_get.register(&XmppConnection::incoming_iq_processing_get_disco_items);iq_get.register(&XmppConnection::incoming_iq_processing_get_version);iq_get};}pub struct MaybeXmppConnection {account: std::rc::Rc<config::Account>,state: Option<XmppState>,}impl From<XmppConnection> for MaybeXmppConnection {fn from(from: XmppConnection) -> MaybeXmppConnection {MaybeXmppConnection {account: from.account,state: Some(from.state),}}}impl From<config::Account> for MaybeXmppConnection {fn from(from: config::Account) -> MaybeXmppConnection {MaybeXmppConnection {account: std::rc::Rc::new(from),state: None,}}}impl From<std::rc::Rc<config::Account>> for MaybeXmppConnection {fn from(from: std::rc::Rc<config::Account>) -> MaybeXmppConnection {MaybeXmppConnection {account: from,state: None,}}}impl MaybeXmppConnection {/// connects if nothing connected/// don't connect only if stop_future resolvedpub fn connect<F>(self,stop_future: F,) -> impl Future<Item = XmppConnection, Error = failure::Error>whereF: future::Future + Clone + 'static,<F as hyper::rt::Future>::Error: Into<failure::Error> + Send,{info!("xmpp connection...");let MaybeXmppConnection { account, state } = self;if let Some(state) = state {Box::new(future::ok(XmppConnection { account, state }))as Box<dyn Future<Item = _, Error = _>>} else {Box::new(stop_future.clone().select2(future::loop_fn(account, move |account| {info!("xmpp initialization...");let client =Client::new_with_jid(account.jid.clone(), &account.password);info!("xmpp initialized");let stop_future2 = stop_future.clone();let stop_future3 = stop_future.clone();let stop_future4 = stop_future.clone();// future to wait for onlineBox::new(XmppConnection {state: XmppState {client,data: std::default::Default::default(),},account,}.processing(XmppConnection::online, stop_future.clone()).map_err(|(acc, _)| acc).and_then(|(conn, r)| match r {Ok(Either::A(_)) => future::ok(conn),Ok(Either::B(_)) => future::err(conn.account),Err(_e) => future::err(conn.account),}).and_then(|conn| conn.initial_roster(stop_future2)).and_then(|conn| conn.self_presence(stop_future3)).and_then(|conn| conn.enter_mucs(stop_future4)).then(|r| match r {Ok(conn) => future::ok(future::Loop::Break(conn)),Err(acc) => future::ok(future::Loop::Continue(acc)),}),)}).map_err(|_: ()| ()),).then(|r| match r {Ok(Either::A((_x, _b))) => future::err(format_err!("Stop XMMP connection")),Ok(Either::B((x, _a))) => future::ok(x),Err(Either::A((e, _b))) => future::err(e.into()),Err(Either::B((_, _a))) => {future::err(format_err!("Cann't initiate XMPP connection"))}}),)}}}impl XmppConnection {/// base XMPP processing/// Returns false on error to disconnectfn xmpp_processing(&mut self, event: &Event) -> bool {match event {Event::Stanza(stanza) => INCOMING.process(self, stanza.clone()),Event::Online => true,e => {warn!("Unexpected event {:?}", e);false}}}/// Process roster push/// see RFC 6212 2.1.6. Roster Pushfn incoming_iq_processing_set_roster(&mut self,roster: xmpp_parsers::roster::Roster,) -> Box<dyn IqRequestHandler> {for i in roster.items {if let Some(ref mut rdata) = self.state.data.roster.get_mut(&i.jid) {info!("Update {} in roster", i.jid);rdata.0 = i.subscription;rdata.1 = i.ask;} else {info!("Add {} to roster", i.jid);self.state.data.roster.insert(i.jid.clone(), (i.subscription, i.ask));}self.process_jid(&i.jid);}Box::new(IqSetRoster {})}/// Enforce to answer to IQ "set"fn incoming_iq_processing_set(&mut self,id: String,from: Option<xmpp_parsers::Jid>,element: minidom::Element,) -> xmpp_parsers::iq::Iq {INCOMING_IQ_SET.process(self, element).process(self, id, from)}/// Process ping request/// see XEP-0199: XMPP Pingfn incoming_iq_processing_get_ping(&mut self,_ping: xmpp_parsers::ping::Ping,) -> Box<dyn IqRequestHandler> {Box::new(IqGetPing {})}/// Process disco query/// see XEP-0030: Service Discoveryfn incoming_iq_processing_get_disco_info(&mut self,disco: xmpp_parsers::disco::DiscoInfoQuery,) -> Box<dyn IqRequestHandler> {if let Some(ref node) = disco.node {warn!("Unsupported node {}", node);Box::new(IqRequestUnknown {element: disco.into(),type_: "get",})} else {Box::new(IqGetDiscoInfo {})}}/// Process disco items query/// see XEP-0030: Service Discoveryfn incoming_iq_processing_get_disco_items(&mut self,disco: xmpp_parsers::disco::DiscoItemsQuery,) -> Box<dyn IqRequestHandler> {if let Some(ref node) = disco.node {warn!("Unsupported node {}", node);Box::new(IqRequestUnknown {element: disco.into(),type_: "get",})} else {Box::new(IqGetDiscoItems {})}}/// Process version query/// see XEP-0092: Software Versionfn incoming_iq_processing_get_version(&mut self,_version: xmpp_parsers::version::VersionQuery,) -> Box<dyn IqRequestHandler> {Box::new(IqGetVersion {})}/// Enforce to answer to IQ "get"fn incoming_iq_processing_get(&mut self,id: String,from: Option<xmpp_parsers::Jid>,element: minidom::Element,) -> xmpp_parsers::iq::Iq {INCOMING_IQ_GET.process(self, element).process(self, id, from)}fn incoming_iq_processing(&mut self, iq: xmpp_parsers::iq::Iq) -> bool {match iq.payload {xmpp_parsers::iq::IqType::Set(element) => {let iq_answer = self.incoming_iq_processing_set(iq.id, iq.from, element);self.state.data.send_queue.push_back(iq_answer.into());}xmpp_parsers::iq::IqType::Error(e) => {if let Some((_, handler)) = self.state.data.pending_ids.remove_entry(&iq.id) {return handler.1.error(self, e);}error!("iq error: {:?}", e);return false;}xmpp_parsers::iq::IqType::Get(element) => {let iq_answer = self.incoming_iq_processing_get(iq.id, iq.from, element);self.state.data.send_queue.push_back(iq_answer.into());}xmpp_parsers::iq::IqType::Result(opt_element) => {if let Some((_, handler)) = self.state.data.pending_ids.remove_entry(&iq.id) {return handler.1.result(self, opt_element);}warn!("Unwanted iq result id {} from {:?}: {:?}",iq.id,iq.from,opt_element.map(|e| String::from(&e)));}}true}fn incoming_presence_processing(&mut self, presence: xmpp_parsers::presence::Presence) -> bool {if presence.from.as_ref() == Some(&self.state.client.jid) {info!("Self-presence accepted");self.state.data.self_presence = true;} else {warn!("Incoming presence stanza: {:?}", presence);}true}fn incoming_message_processing(&mut self, message: xmpp_parsers::message::Message) -> bool {for payload in message.payloads.iter() {use std::convert::TryInto;if let Some(_delay) =payload.clone().try_into().ok() as Option<xmpp_parsers::delay::Delay>{return true; // ignore delayed messages}}warn!("Incoming message stanza: {:?}", message);true}/// process event from xmpp stream/// returns from future when condition met/// or stop future was resolved./// Return item if connection was preserved or error otherwise./// Second part is a state of stop_futurepub fn processing<S, F, T, E>(self,stop_condition: S,stop_future: F,) -> impl Future<Item = (Self, Result<Either<F, T>, E>),Error = (std::rc::Rc<config::Account>, Result<Either<F, T>, E>),>whereF: Future<Item = T, Error = E> + 'static,S: FnMut(&mut Self, Event) -> Result<bool, ()> + 'static,T: 'static,E: 'static,{future::loop_fn((self, stop_future, stop_condition),|(xmpp, stop_future, mut stop_condition)| {// ToDo: check timeouts if iqslet XmppConnection {state: XmppState { client, mut data },account,} = xmpp;if let Some(send_element) = data.send_queue.pop_front() {use tokio::prelude::Sink;info!("Sending {}", String::from(&send_element));Box::new(client.send(Packet::Stanza(send_element)).select2(stop_future).then(move |r| match r {Ok(Either::A((client, b))) => {Box::new(future::ok(future::Loop::Continue((XmppConnection {state: XmppState { client, data },account,},b,stop_condition,))))as Box<dyn Future<Item = _, Error = _>>}Ok(Either::B((t, a))) => Box::new(a.then(|r| match r {Ok(client) => future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Ok(Either::B(t)),))),Err(se) => {warn!("XMPP sending error: {}", se);future::err((account, Ok(Either::B(t))))}})),Err(Either::A((e, b))) => {warn!("XMPP sending error: {}", e);Box::new(future::err((account, Ok(Either::A(b)))))}Err(Either::B((e, a))) => Box::new(a.then(|r| match r {Ok(client) => future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Err(e),))),Err(se) => {warn!("XMPP sending error: {}", se);future::err((account, Err(e)))}})),}),) as Box<dyn Future<Item = _, Error = _>>} else {Box::new(client.into_future().select2(stop_future).then(move |r| match r {Ok(Either::A(((event, client), b))) => {if let Some(event) = event {let mut xmpp = XmppConnection {state: XmppState { client, data },account,};if xmpp.xmpp_processing(&event) {match stop_condition(&mut xmpp, event) {Ok(true) => future::ok(future::Loop::Break((xmpp,Ok(Either::A(b)),))),Ok(false) => future::ok(future::Loop::Continue((xmpp,b,stop_condition,))),Err(_e) => {future::err((xmpp.account, Ok(Either::A(b))))}}} else {future::err((xmpp.account, Ok(Either::A(b))))}} else {future::err((account, Ok(Either::A(b))))}}Ok(Either::B((t, a))) => {if let Some(client) = a.into_inner() {future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Ok(Either::B(t)),)))} else {future::err((account, Ok(Either::B(t))))}}Err(Either::A((e, b))) => {warn!("XMPP error: {}", e.0);future::err((account, Ok(Either::A(b))))}Err(Either::B((e, a))) => {if let Some(client) = a.into_inner() {future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Err(e),)))} else {future::err((account, Err(e)))}}}),)}},)}/// get connection and wait for online status and set presence/// returns error if something went wrong and xmpp connection is brokenfn online(&mut self, event: Event) -> Result<bool, ()> {match event {Event::Online => {info!("Online!");Ok(true)}Event::Stanza(s) => {warn!("Stanza before online: {}", String::from(&s));Ok(false)}_ => {error!("Disconnected while online");Err(())}}}fn initial_roster<F, E>(self,stop_future: F,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>whereF: Future<Error = E> + 'static,E: 'static,{let XmppConnection {account,state: XmppState { client, mut data },} = self;use tokio::prelude::Sink;data.counter += 1;let id_init_roster = format!("id_init_roster{}", data.counter);let get_roster = stanzas::make_get_roster(&id_init_roster);let account2 = account.clone();info!("Quering roster... {}", String::from(&get_roster));data.pending_ids.insert(id_init_roster.clone(),(Instant::now() + Duration::from_secs(60),Box::new(InitRosterIqHandler {}),),);client.send(Packet::Stanza(get_roster)).map_err(move |e| {error!("Error on querying roster: {}", e);account2}).and_then(move |client| {XmppConnection {state: XmppState { client, data },account,}.processing(move |conn, _| Ok(conn.state.data.roster_init), stop_future).map_err(|(account, _)| account).and_then(|(conn, r)| match r {Ok(Either::A(_)) => future::ok(conn),Ok(Either::B(_)) => future::err(conn.account),Err(_e) => future::err(conn.account),})})}fn self_presence<F, E>(self,stop_future: F,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>whereF: Future<Error = E> + 'static,E: Into<failure::Error> + 'static,{let XmppConnection {account,state: XmppState { client, data },} = self;use tokio::prelude::Sink;let presence = stanzas::make_presence(&account);let account2 = account.clone();info!("Sending presence... {}", String::from(&presence));client.send(Packet::Stanza(presence)).map_err(|e| {error!("Error on send self-presence: {}", e);account2}).and_then(move |client| {XmppConnection {state: XmppState { client, data },account,}.processing(move |conn, _| Ok(conn.state.data.self_presence),stop_future,).map_err(|(account, _)| account).and_then(|(conn, r)| match r {Ok(Either::A(_)) => future::ok(conn),Ok(Either::B(_)) => future::err(conn.account),Err(_e) => future::err(conn.account),})})}fn process_jid(&mut self, xmpp_to: &xmpp_parsers::Jid) {if let Some(ref mut mailbox) = self.state.data.outgoing_mailbox.get_mut(xmpp_to) {if !mailbox.is_empty() {if let Some(ref mut rdata) = self.state.data.roster.get_mut(xmpp_to) {info!("Jid {} in roster", xmpp_to);let sub_to = match rdata.0 {xmpp_parsers::roster::Subscription::To => true,xmpp_parsers::roster::Subscription::Both => true,_ => false,};if sub_to {info!("Subscribed to {}", xmpp_to);self.state.data.send_queue.extend(mailbox.drain(..).map(|message| {stanzas::make_chat_message(xmpp_to.clone(), message)}),);} else if rdata.1 == xmpp_parsers::roster::Ask::None {info!("Not subscribed to {}", xmpp_to);self.state.data.send_queue.push_back(stanzas::make_ask_subscribe(xmpp_to.clone()));}let sub_from = match rdata.0 {xmpp_parsers::roster::Subscription::From => true,xmpp_parsers::roster::Subscription::Both => true,_ => false,};if !sub_from {info!("Not subscription from {}", xmpp_to);self.state.data.send_queue.push_back(stanzas::make_allow_subscribe(xmpp_to.clone()));}} else {info!("Jid {} not in roster", xmpp_to);self.state.data.counter += 1;let id_add_roster = format!("id_add_roster{}", self.state.data.counter);let add_roster = stanzas::make_add_roster(&id_add_roster, xmpp_to.clone());info!("Adding jid {} to roster id {}", xmpp_to, id_add_roster);self.state.data.pending_ids.insert(id_add_roster,(Instant::now() + Duration::from_secs(60),Box::new(AddRosterIqHandler {jid: xmpp_to.clone(),}),),);self.state.data.send_queue.push_back(add_roster);}}}}pub fn process_command(&mut self, cmd: XmppCommand) {info!("Got command");match cmd {XmppCommand::Chat { xmpp_to, message } => {self.state.data.outgoing_mailbox.entry(xmpp_to.clone()).or_default().push(message);self.process_jid(&xmpp_to);}XmppCommand::Chatroom { muc_id, message } => {if let Some(muc) = self.state.data.mucs.get(&muc_id) {self.state.data.send_queue.push_back(stanzas::make_muc_message(muc.clone(), message));} else {error!("Not found MUC {}", muc_id);}}XmppCommand::Ping => {self.state.data.counter += 1;let id_ping = format!("id_ping{}", self.state.data.counter);let ping = stanzas::make_ping(&id_ping, self.state.client.jid.clone());self.state.data.send_queue.push_back(ping);self.state.data.pending_ids.insert(id_ping,(Instant::now() + Duration::from_secs(30),Box::new(PingIqHandler {}),),);}XmppCommand::TimeoutCleanup => {let now = Instant::now();let timeouted: Vec<String> = self.state.data.pending_ids.iter().filter_map(|(id, (timeout, _))| {if now >= *timeout {Some(id.to_string())} else {None}}).collect();let mut correct = true;timeouted.into_iter().for_each(|id| {if let Some((_, handler)) = self.state.data.pending_ids.remove(&id) {correct &= handler.timeout(&mut self);}})}}}pub fn shutdown(self) -> impl Future<Item = (), Error = failure::Error> {info!("Shutdown connection");let XmppConnection { account, state } = self;stream::iter_ok(state.data.mucs.values().map(std::clone::Clone::clone).collect::<Vec<_>>(),).fold(state, move |XmppState { client, data }, muc_jid| {let muc_presence =stanzas::make_muc_presence_leave(account.jid.clone(), muc_jid.clone());info!("Sending muc leave presence... {}",String::from(&muc_presence));use tokio::prelude::Sink;client.send(Packet::Stanza(muc_presence)).map_err(|e| {error!("Error on send muc presence: {}", e);e}).and_then(|client| future::ok(XmppState { client, data }))}).map(|_| ())}fn enter_mucs<F, E>(self,_stop_future: F,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>whereF: Future<Error = E> + 'static,E: Into<failure::Error> + 'static,{let XmppConnection { account, state } = self;let account2 = account.clone();let account3 = account.clone();stream::iter_ok(account.chatrooms.clone()).fold(state, move |XmppState { client, mut data }, muc_jid| {data.counter += 1;let id_muc_presence = format!("id_muc_presence{}", data.counter);let muc_presence = stanzas::make_muc_presence(&id_muc_presence,account2.jid.clone(),muc_jid.1.clone(),);info!("Sending muc presence... {}", String::from(&muc_presence));let account4 = account2.clone();use tokio::prelude::Sink;client.send(Packet::Stanza(muc_presence)).map_err(|e| {error!("Error on send muc presence: {}", e);account4}).and_then(|client| {data.mucs.insert(muc_jid.0, muc_jid.1);future::ok(XmppState { client, data })})}).map(|state| XmppConnection {account: account3,state,})}}
let mut add_roster = Iq::from_set(Roster {items: vec![Item {jid,name: None,subscription: xmpp_parsers::roster::Subscription::None,ask: xmpp_parsers::roster::Ask::None,groups: vec![],}],ver: None,});add_roster.id = Some(id.to_string());add_roster.into()
Iq::from_set(id,Roster {items: vec![Item {jid,name: None,subscription: xmpp_parsers::roster::Subscription::None,ask: xmpp_parsers::roster::Ask::None,groups: vec![],}],ver: None,},).into()
}pub fn make_muc_presence_leave(from: xmpp_parsers::Jid, to: xmpp_parsers::Jid) -> Element {let mut presence = Presence::new(PresenceType::Unavailable);presence.from = Some(from);presence.to = Some(to);presence.into()}pub fn make_ping(id: &str, from: xmpp_parsers::Jid) -> Element {let mut ping = Iq::from_get(id, Ping);ping.to = Some(from.clone().into_domain_jid());ping.from = Some(from);ping.into()}pub fn make_pong(id: String, from: xmpp_parsers::Jid, to: Option<xmpp_parsers::Jid>) -> Iq {let mut pong = Iq::from_result(id, None as Option<Roster>);pong.from = Some(from);pong.to = to;pong}pub fn make_version(id: String, from: xmpp_parsers::Jid, to: Option<xmpp_parsers::Jid>) -> Iq {let mut version = Iq::from_result(id,Some(VersionResult {name: "SendXmppDRust".to_string(),version: "0.1.0".to_string(),os: None,}),);version.from = Some(from);version.to = to;version}pub fn make_iq_unsupported_error(id: String,from: xmpp_parsers::Jid,to: Option<xmpp_parsers::Jid>,) -> Iq {let mut error = Iq::from_error(id,StanzaError {type_: ErrorType::Cancel,by: Some(from.clone()),defined_condition: DefinedCondition::ServiceUnavailable,texts: std::collections::BTreeMap::new(),other: None,},);error.from = Some(from);error.to = to;error}pub fn make_disco_info_result(id: String,from: xmpp_parsers::Jid,to: Option<xmpp_parsers::Jid>,) -> Iq {let mut result = Iq::from_result(id,Some(DiscoInfoResult {node: None,identities: vec![Identity {category: "client".to_string(),type_: "bot".to_string(),name: None,lang: None,}],features: vec![Feature {var: "http://jabber.org/protocol/disco#info".to_string(),},Feature {var: "urn:xmpp:ping".to_string(),},],extensions: vec![],}),);result.from = Some(from);result.to = to;result}pub fn make_disco_items_result(id: String,from: xmpp_parsers::Jid,to: Option<xmpp_parsers::Jid>,) -> Iq {let mut result = Iq::from_result(id,Some(DiscoItemsResult {node: None,items: vec![],}),);result.from = Some(from);result.to = to;result
#[derive(Default)]struct XmppData {/// known roster dataroster: HashMap<xmpp_parsers::Jid,(xmpp_parsers::roster::Subscription,xmpp_parsers::roster::Ask,),>,/// ids countercounter: usize,/// map from id of adding item to roster and jid of itempending_add_roster_ids: HashMap<String, xmpp_parsers::Jid>,/// stanzas to sendsend_queue: VecDeque<minidom::Element>,/// outgoing mailboxoutgoing_mailbox: HashMap<xmpp_parsers::Jid, Vec<String>>,/// muc id to muc jidmucs: HashMap<String, xmpp_parsers::Jid>,}struct XmppState {client: Client,data: XmppData,}struct MaybeXmppConnection {account: std::rc::Rc<config::Account>,state: Option<XmppState>,}struct XmppConnection {account: std::rc::Rc<config::Account>,state: XmppState,}impl From<XmppConnection> for MaybeXmppConnection {fn from(from: XmppConnection) -> MaybeXmppConnection {MaybeXmppConnection {account: from.account,state: Some(from.state),}}}impl From<config::Account> for MaybeXmppConnection {fn from(from: config::Account) -> MaybeXmppConnection {MaybeXmppConnection {account: std::rc::Rc::new(from),state: None,}}}impl From<std::rc::Rc<config::Account>> for MaybeXmppConnection {fn from(from: std::rc::Rc<config::Account>) -> MaybeXmppConnection {MaybeXmppConnection {account: from,state: None,}}}impl MaybeXmppConnection {/// connects if nothing connected/// don't connect only if stop_future resolvedfn connect<F>(self,stop_future: F,) -> impl Future<Item = XmppConnection, Error = failure::Error>whereF: future::Future + Clone + 'static,<F as hyper::rt::Future>::Error: Into<failure::Error> + Send,{info!("xmpp connection...");let MaybeXmppConnection { account, state } = self;if let Some(state) = state {Box::new(future::ok(XmppConnection { account, state }))as Box<dyn Future<Item = _, Error = _>>} else {Box::new(stop_future.clone().select2(future::loop_fn(account, move |account| {info!("xmpp initialization...");let client =Client::new_with_jid(account.jid.clone(), &account.password);info!("xmpp initialized");let stop_future2 = stop_future.clone();let stop_future3 = stop_future.clone();let stop_future4 = stop_future.clone();// future to wait for onlineBox::new(XmppConnection {state: XmppState {client,data: std::default::Default::default(),},account,}.processing(XmppConnection::online, stop_future.clone()).map_err(|(acc, _)| acc).and_then(|(conn, r)| match r {Ok(Either::A(_)) => future::ok(conn),Ok(Either::B(_)) => future::err(conn.account),Err(_e) => future::err(conn.account),}).and_then(|conn| conn.initial_roster(stop_future2)).and_then(|conn| conn.self_presence(stop_future3)).and_then(|conn| conn.enter_mucs(stop_future4)).then(|r| match r {Ok(conn) => future::ok(future::Loop::Break(conn)),Err(acc) => future::ok(future::Loop::Continue(acc)),}),)}).map_err(|_: ()| ()),).then(|r| match r {Ok(Either::A((_x, _b))) => future::err(format_err!("Stop XMMP connection")),Ok(Either::B((x, _a))) => future::ok(x),Err(Either::A((e, _b))) => future::err(e.into()),Err(Either::B((_, _a))) => {future::err(format_err!("Cann't initiate XMPP connection"))}}),)}}}impl XmppConnection {/// base XMPP processingfn xmpp_processing(mut self,event: &Event,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>> {match event {Event::Stanza(stanza) => {info!("Incoming xmpp event: {:?}", stanza);let stanza = stanza.clone();use try_from::TryInto;if let Some(iq) = stanza.try_into().ok() as Option<xmpp_parsers::iq::Iq> {if let Some(id) = iq.id {if let Some((_, jid)) =self.state.data.pending_add_roster_ids.remove_entry(&id){if let xmpp_parsers::iq::IqType::Result(None) = iq.payload {if self.state.data.roster.contains_key(&jid) {info!("Jid {} updated to roster", jid);} else {info!("Jid {} added in roster", jid);self.state.data.roster.insert(jid.clone(),(xmpp_parsers::roster::Subscription::None,xmpp_parsers::roster::Ask::None,),);}self.process_jid(&jid);} else {warn!("Wrong payload when adding {} to roster: {:?}",jid, iq.payload);}}}if let xmpp_parsers::iq::IqType::Set(element) = iq.payload {if let Some(roster) =element.try_into().ok() as Option<xmpp_parsers::roster::Roster>{for i in roster.items {if let Some(ref mut rdata) = self.state.data.roster.get_mut(&i.jid){info!("Update {} in roster", i.jid);rdata.0 = i.subscription;rdata.1 = i.ask;} else {info!("Add {} to roster", i.jid);self.state.data.roster.insert(i.jid.clone(), (i.subscription, i.ask));}self.process_jid(&i.jid);}}}}future::ok(self)}Event::Online => future::ok(self),e => {warn!("Unexpected event {:?}", e);future::err(self.account)}}}/// process event from xmpp stream/// returns from future when condition met/// or stop future was resolved./// Return item if connection was preserved or error otherwise./// Second part is a state of stop_futurefn processing<S, F, T, E>(self,stop_condition: S,stop_future: F,) -> impl Future<Item = (Self, Result<Either<F, T>, E>),Error = (std::rc::Rc<config::Account>, Result<Either<F, T>, E>),>whereF: Future<Item = T, Error = E> + 'static,S: FnMut(&mut Self, Event) -> Result<bool, ()> + 'static,T: 'static,E: 'static,{future::loop_fn((self, stop_future, stop_condition),|(xmpp, stop_future, mut stop_condition)| {let XmppConnection {state: XmppState { client, mut data },account,} = xmpp;if let Some(send_element) = data.send_queue.pop_front() {use tokio::prelude::Sink;info!("Sending {:?}", send_element);Box::new(client.send(Packet::Stanza(send_element)).select2(stop_future).then(move |r| match r {Ok(Either::A((client, b))) => {Box::new(future::ok(future::Loop::Continue((XmppConnection {state: XmppState { client, data },account,},b,stop_condition,))))as Box<dyn Future<Item = _, Error = _>>}Ok(Either::B((t, a))) => Box::new(a.then(|r| match r {Ok(client) => future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Ok(Either::B(t)),))),Err(se) => {warn!("XMPP sending error: {}", se);future::err((account, Ok(Either::B(t))))}})),Err(Either::A((e, b))) => {warn!("XMPP sending error: {}", e);Box::new(future::err((account, Ok(Either::A(b)))))}Err(Either::B((e, a))) => Box::new(a.then(|r| match r {Ok(client) => future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Err(e),))),Err(se) => {warn!("XMPP sending error: {}", se);future::err((account, Err(e)))}})),}),) as Box<dyn Future<Item = _, Error = _>>} else {Box::new(client.into_future().select2(stop_future).then(move |r| match r {Ok(Either::A(((event, client), b))) => {if let Some(event) = event {let xmpp = XmppConnection {state: XmppState { client, data },account,};Box::new(xmpp.xmpp_processing(&event).then(|r| match r {Ok(mut xmpp) => {match stop_condition(&mut xmpp, event) {Ok(true) => future::ok(future::Loop::Break((xmpp,Ok(Either::A(b)),))),Ok(false) => {future::ok(future::Loop::Continue((xmpp,b,stop_condition,)))}Err(_e) => future::err((xmpp.account,Ok(Either::A(b)),)),}}Err(account) => {future::err((account, Ok(Either::A(b))))}}))as Box<dyn Future<Item = _, Error = _>>} else {Box::new(future::err((account, Ok(Either::A(b)))))}}Ok(Either::B((t, a))) => {Box::new(if let Some(client) = a.into_inner() {future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Ok(Either::B(t)),)))} else {future::err((account, Ok(Either::B(t))))})}Err(Either::A((e, b))) => {warn!("XMPP error: {}", e.0);Box::new(future::err((account, Ok(Either::A(b)))))}Err(Either::B((e, a))) => {Box::new(if let Some(client) = a.into_inner() {future::ok(future::Loop::Break((XmppConnection {state: XmppState { client, data },account,},Err(e),)))} else {future::err((account, Err(e)))})}}),)}},)}
/// get connection and wait for online status and set presence/// returns error if something went wrong and xmpp connection is brokenfn online(&mut self, event: Event) -> Result<bool, ()> {match event {Event::Online => {info!("Online!");Ok(true)}Event::Stanza(s) => {warn!("Stanza before online: {:?}", s);Ok(false)}_ => {error!("Disconnected while online");Err(())}}}
mod xmpp_connection;use xmpp_connection::MaybeXmppConnection;
fn process_initial_roster(&mut self, event: Event, id_init_roster: &str) -> Result<bool, ()> {if let Event::Stanza(s) = event {use try_from::TryInto;match s.try_into() as Result<xmpp_parsers::iq::Iq, _> {Ok(iq) => {if let Some(id) = iq.id {if id == id_init_roster {match iq.payload {xmpp_parsers::iq::IqType::Error(_e) => {error!("Get error instead of roster");Err(())}xmpp_parsers::iq::IqType::Result(Some(result)) => {match result.try_into()as Result<xmpp_parsers::roster::Roster, _>{Ok(roster) => {self.state.data.roster.clear();info!("Got first roster:");for i in roster.items {info!(" >>> {:?}", i);self.state.data.roster.insert(i.jid, (i.subscription, i.ask));}Ok(true)}Err(e) => {error!("Cann't parse roster: {}", e);Err(())}}}_ => {error!("Unknown result of roster");Err(())}}} else {Ok(false)}} else {error!("Iq stanza without id");Err(())}}Err(_e) => Ok(false),}} else {error!("Wrong event while waiting roster");Err(())}}fn initial_roster<F, E>(self,stop_future: F,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>whereF: Future<Error = E> + 'static,E: 'static,{let XmppConnection {account,state: XmppState { client, mut data },} = self;use tokio::prelude::Sink;data.counter += 1;let id_init_roster = format!("id_init_roster{}", data.counter);let get_roster = stanzas::make_get_roster(&id_init_roster);let account2 = account.clone();info!("Quering roster... {:?}", get_roster);client.send(Packet::Stanza(get_roster)).map_err(move |e| {error!("Error on querying roster: {}", e);account2}).and_then(move |client| {XmppConnection {state: XmppState { client, data },account,}.processing(move |conn, event| conn.process_initial_roster(event, &id_init_roster),stop_future,).map_err(|(account, _)| account).and_then(|(conn, r)| match r {Ok(Either::A(_)) => future::ok(conn),Ok(Either::B(_)) => future::err(conn.account),Err(_e) => future::err(conn.account),})})}
pub use xmpp_connection::XmppCommand;
fn self_presence<F, E>(self,stop_future: F,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>whereF: Future<Error = E> + 'static,E: Into<failure::Error> + 'static,{let XmppConnection {account,state: XmppState { client, data },} = self;use tokio::prelude::Sink;let presence = stanzas::make_presence(&account);let account2 = account.clone();info!("Sending presence... {:?}", presence);client.send(Packet::Stanza(presence)).map_err(|e| {error!("Error on send self-presence: {}", e);account2}).and_then(move |client| {XmppConnection {state: XmppState { client, data },account,}.processing(move |conn, event| {if let Event::Stanza(s) = event {if s.name() == "presence"&& s.attr("from").map_or(false, |f| f == conn.account.jid)&& s.attr("to").map_or(false, |f| f == conn.account.jid){Ok(true)} else {Ok(false)}} else {error!("Wrong event while waiting self-presence");Err(())}},stop_future,).map_err(|(account, _)| account).and_then(|(conn, r)| match r {Ok(Either::A(_)) => future::ok(conn),Ok(Either::B(_)) => future::err(conn.account),Err(_e) => future::err(conn.account),})})}fn process_jid(&mut self, xmpp_to: &xmpp_parsers::Jid) {if let Some(ref mut mailbox) = self.state.data.outgoing_mailbox.get_mut(xmpp_to) {if !mailbox.is_empty() {if let Some(ref mut rdata) = self.state.data.roster.get_mut(xmpp_to) {info!("Jid {} in roster", xmpp_to);let sub_to = match rdata.0 {xmpp_parsers::roster::Subscription::To => true,xmpp_parsers::roster::Subscription::Both => true,_ => false,};if sub_to {info!("Subscribed to {}", xmpp_to);self.state.data.send_queue.extend(mailbox.drain(..).map(|message| {stanzas::make_chat_message(xmpp_to.clone(), message)}),);} else if rdata.1 == xmpp_parsers::roster::Ask::None {info!("Not subscribed to {}", xmpp_to);self.state.data.send_queue.push_back(stanzas::make_ask_subscribe(xmpp_to.clone()));}} else {info!("Jid {} not in roster", xmpp_to);self.state.data.counter += 1;let id_add_roster = format!("id_add_roster{}", self.state.data.counter);let add_roster = stanzas::make_add_roster(&id_add_roster, xmpp_to.clone());self.state.data.pending_add_roster_ids.insert(id_add_roster, xmpp_to.clone());info!("Adding jid to roster... {:?}", add_roster);self.state.data.send_queue.push_back(add_roster);}}}}fn process_command(&mut self, cmd: XmppCommand) {info!("Got command");match cmd {XmppCommand::Chat { xmpp_to, message } => {self.state.data.outgoing_mailbox.entry(xmpp_to.clone()).or_default().push(message);self.process_jid(&xmpp_to);}XmppCommand::Chatroom { muc_id, message } => {if let Some(muc) = self.state.data.mucs.get(&muc_id) {self.state.data.send_queue.push_back(stanzas::make_muc_message(muc.clone(), message));} else {error!("Not found MUC {}", muc_id);}}}}fn enter_mucs<F, E>(self,_stop_future: F,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>whereF: Future<Error = E> + 'static,E: Into<failure::Error> + 'static,{let XmppConnection { account, state } = self;let account2 = account.clone();let account3 = account.clone();stream::iter_ok(account.chatrooms.clone()).fold(state, move |XmppState { client, mut data }, muc_jid| {data.counter += 1;let id_muc_presence = format!("id_muc_presence{}", data.counter);let muc_presence = stanzas::make_muc_presence(&id_muc_presence,account2.jid.clone(),muc_jid.1.clone(),);info!("Sending muc presence... {:?}", muc_presence);let account4 = account2.clone();use tokio::prelude::Sink;client.send(Packet::Stanza(muc_presence)).map_err(|e| {error!("Error on send muc presence: {}", e);account4}).and_then(|client| {data.mucs.insert(muc_jid.0, muc_jid.1);future::ok(XmppState { client, data })})}).map(|state| XmppConnection {account: account3,state,})}}#[derive(Debug)]pub enum XmppCommand {Chat {xmpp_to: xmpp_parsers::Jid,message: String,},Chatroom {muc_id: String,message: String,},}
type Func<S, T, E> = dyn Fn(&mut S, E) -> T + Sync;pub struct Processor<S: 'static, T: 'static, E: Clone + 'static> {processors: Vec<Box<Func<S, Option<T>, E>>>,default: &'static Func<S, T, E>,}impl<S: 'static, T: 'static, E: Clone + 'static> Processor<S, T, E> {pub fn new<F>(f: &'static F) -> Processor<S, T, E>whereF: Fn(&mut S, E) -> T + Sync + 'static,{Processor {processors: vec![],default: f,}}pub fn register<F, A>(&mut self, f: &'static F)whereF: Fn(&mut S, A) -> T + Sync + 'static,A: std::convert::TryFrom<E>,{self.processors.push(Box::new(move |s, e: E| {use std::convert::TryInto;(e.try_into().ok() as Option<A>).map(|a| f(s, a))}));}pub fn process(&self, s: &mut S, e: E) -> T {for processor in self.processors.iter() {match processor(s, e.clone()) {Some(t) => return t,None => continue,}}(*self.default)(s, e)}}
type Func<S, T, E> = dyn Fn(&mut S, E) -> T + Sync;pub struct Processor<S: 'static, T: 'static, E: Clone + 'static> {processors: Vec<Box<Func<S, Option<T>, E>>>,default: &'static Func<S, T, E>,}impl<S: 'static, T: 'static, E: Clone + 'static> Processor<S, T, E> {pub fn new<F>(f: &'static F) -> Processor<S, T, E>whereF: Fn(&mut S, E) -> T + Sync + 'static,{Processor {processors: vec![],default: f,}}pub fn register<F, A>(&mut self, f: &'static F)whereF: Fn(&mut S, A) -> T + Sync + 'static,A: std::convert::TryFrom<E>,{self.processors.push(Box::new(move |s, e: E| {use std::convert::TryInto;(e.try_into().ok() as Option<A>).map(|a| f(s, a))}));}pub fn process(&self, s: &mut S, e: E) -> T {for processor in self.processors.iter() {match processor(s, e.clone()) {Some(t) => return t,None => continue,}}(*self.default)(s, e)}}
if let Some(ping) = config.account.ping {let ping = tokio::timer::Interval::new_interval(std::time::Duration::from_secs(ping));rt.spawn(ping.map_err(|e| {error!("Ping error: {}", e);}).for_each(move |_| {cmd_send.clone().send(XmppCommand::Ping).map_err(|e| {error!("Ping command error: {}", e);}).map(|_| ())}).select(ctrl_c.clone().map(|_| ()).map_err(|e| error!("ping server error: {}", e)),).map(|_| ()).map_err(|_| ()),);}
}fn deserialize_jid_map<'de, D>(deserializer: D,) -> Result<HashMap<String, xmpp_parsers::Jid>, D::Error>whereD: serde::Deserializer<'de>,{use serde::Deserialize;let s = HashMap::<String, String>::deserialize(deserializer)?;let size = s.len();s.into_iter().map(|(k, v)| (k, std::str::FromStr::from_str(&v))).take_while(|(_k, r)| r.is_ok()).fold(Ok(HashMap::with_capacity(size)), |res, (k, r)| match res {Ok(mut res) => match r {Ok(v) => {res.insert(k, v);Ok(res)}Err(e) => Err(e),},Err(e) => Err(e),}).map_err(serde::de::Error::custom)
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)","rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)","rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)","textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)","textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
source = "registry+https://github.com/rust-lang/crates.io-index"dependencies = ["libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",][[package]]name = "crossbeam"version = "0.6.0"source = "registry+https://github.com/rust-lang/crates.io-index"dependencies = ["cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)","crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)","crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)","crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)","lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)","num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)","parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",][[package]]name = "crossbeam-channel"version = "0.3.8"
"crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)","smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)","syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)","syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)","num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)","num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)","http 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)","http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
"h2 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)","http 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"h2 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)","http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)","tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)","tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)","serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)","serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)","serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)","serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.9.40 (registry+https://github.com/rust-lang/crates.io-index)","schannel 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)","schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)","openssl-sys 0.9.40 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)","openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)","rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)","rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)","rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)","rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)","memchr 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)","regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)","memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)","regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)","env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)","env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)","serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)","tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)","serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)","tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)","try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)","xmpp-parsers 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)","xmpp-parsers 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)","syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)","syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)",
"arc-swap 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"arc-swap 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)","redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)","redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)","new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)","new_debug_unreachable 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)","syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)","syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)","redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)","redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)","redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)","redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-current-thread 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)","tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","tokio-fs 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)","tokio-sync 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)","tokio-sync 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)","tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)","tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)","tokio-threadpool 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)","tokio-threadpool 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)","lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)","lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)","tokio-sync 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)","libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"signal-hook 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"signal-hook 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)","tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)","winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)","crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)","crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)","crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",][[package]]name = "tokio-trace-core"version = "0.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"dependencies = ["lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)","futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)","tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)","tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)","tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)","tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
][[package]]name = "xmpp-parsers"version = "0.13.1"source = "registry+https://github.com/rust-lang/crates.io-index"dependencies = ["base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)","blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)","chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)","digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)","jid 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)","minidom 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)","sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)","sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)","sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e"
"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c"
"checksum arc-swap 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1025aeae2b664ca0ea726a89d574fe8f4e77dd712d443236ad1de00379450cf6"
"checksum arc-swap 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)" = "a57a5698f85c6fd92f19dad87ff2d822fc4ba79dd85c13914d8c4dad589cb815"
"checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5"
"checksum backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f106c02a3604afcdc0df5d36cc47b44b55917dbaf3d808f71c163a0ddba64637"
"checksum block-buffer 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "509de513cca6d92b6aacf9c61acfe7eaa160837323a81068d690cc1f8e5740da"
"checksum block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49665c62e0e700857531fa5d3763e91b539ff1abeebd56808d378b495870d60d"
"checksum bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "40ade3d27603c2cb345eb0912aec461a6dec7e06a4ae48589904e808335c7afa"
"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
"checksum cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "4390a3b5f4f6bce9c1d0c00128379df433e53777fdd30e92f16a529332baec4e""checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
"checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83""checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4"
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
"checksum crossbeam 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad4c7ea749d9fb09e23c5cb17e3b70650860553a0e2744e38446b1803bf7db94""checksum crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f0ed1a4de2235cabda8558ff5840bffb97fcb64c97827f354a451307df5f72b""checksum crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "05e44b8cf3e1a625844d1750e1f7820da46044ff6d28f4d43e455ba3e5bb2c13"
"checksum crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71"
"checksum encoding_rs 0.8.15 (registry+https://github.com/rust-lang/crates.io-index)" = "fd251508d65030820f3a4317af2248180db337fdb25d89967956242580277813""checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e"
"checksum encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "4155785c79f2f6701f185eb2e6b4caf0555ec03477cb4c70db67b465311620ed""checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a"
"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
"checksum futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "62941eff9507c8177d448bd83a44d9b9760856e184081d8cd79ba9f03dd24981"
"checksum h2 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ddb2b25a33e231484694267af28fec74ac63b5ccf51ee2065a5e313b834d836e"
"checksum h2 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "85ab6286db06040ddefb71641b50017c06874614001a134b423783e2db2920bd"
"checksum http 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1a10e5b573b9a0146545010f50772b9e8b1dd0a256564cc4307694c68832a2f5"
"checksum http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "eed324f0f0daf6ec10c474f150505af2c143f251722bf9dbd1261bd1f2ee2c1a"
"checksum hyper 0.12.23 (registry+https://github.com/rust-lang/crates.io-index)" = "860faf61a9957c9cb0e23e69f1c8290e92f6eb660fcdd1f2d6777043a2ae1a46"
"checksum hyper 0.12.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4f2777434f26af6e4ce4fdcdccd3bed9d861d11e87bcbe72c0f51ddaca8ff848"
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047""checksum linked-hash-map 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7860ec297f7008ff7a1e3382d7f7e1dcd69efc94751a2284bafc3d013c2aa939"
"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917""checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
"checksum lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d06ff7ff06f729ce5f4e227876cb88d10bc59cd4ae1e09fbb2bde15c850dc21"
"checksum lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c"
"checksum memchr 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1dd4eaac298c32ce07eb6ed9242eda7d82955b9170b7d6db59b2e02cc63fcb8"
"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
"checksum new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cdc457076c78ab54d5e0d6fa7c47981757f1e34dc39ff92787f217dede586c4"
"checksum new_debug_unreachable 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f40f005c60db6e03bae699e414c58bf9aa7ea02a2d0b9bfbcf19286cc4c82b30"
"checksum num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5a69d464bdc213aaaff628444e99578ede64e9c854025aa43b9796530afa9238"
"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
"checksum openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ec7bd7ca4cce6dbdc77e7c1230682740d307d1218a87fb0349a571272be749f9"
"checksum openssl 0.10.20 (registry+https://github.com/rust-lang/crates.io-index)" = "5a0d6b781aac4ac1bd6cafe2a2f0ad8c16ae8e1dd5184822a16c50139f8838d9"
"checksum openssl-sys 0.9.40 (registry+https://github.com/rust-lang/crates.io-index)" = "1bb974e77de925ef426b6bc82fce15fd45bdcbeb5728bffcfc7cdeeb7ce1c2d6"
"checksum openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)" = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d"
"checksum quick-xml 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98d8d2d671bd29c6122a98b45ce3106391e89ba378f731274de677f1eff06e5f"
"checksum quick-xml 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)" = "22fcc48ecef4609b243e8c01ff4695d08ee0fc9d5bdbc54630e1a5fe8bb40953"
"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db"
"checksum rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b7c690732391ae0abafced5015ffb53656abfaec61b342290e5eb56b286a679d""checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05"
"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071""checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85"
"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252"
"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f""checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861"
"checksum regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "559008764a17de49a3146b234641644ed37d118d1ef641a0bb573d146edc6ce0""checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96"
"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619"
"checksum rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc78bfd5acd7bf3e89cffcf899e5cb1a52d6fafa8dec2739ad70c9577a57288"
"checksum schannel 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0e1a231dc10abf6749cfa5d7767f25888d484201accbd919b66ab5413c502d56"
"checksum schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f6abf258d99c3c1c5c2131d99d064e94b7b3dd5f416483057f308fea253339"
"checksum serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)" = "2e20fde37801e83c891a2dc4ebd3b81f0da4d1fb67a9e0a2a3b921e2536a58ee""checksum serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)" = "633e97856567e518b59ffb2ad7c7a4fd4c5d91d9c7f32dd38a27b2bf7e8114ea""checksum serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "27dce848e7467aa0e2fcaf0a413641499c0b745452aaca1194d24dedde9e13c9"
"checksum serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "aa5f7c20820475babd2c077c3ab5f8c77a31c15e16ea38687b4c02d3e48680f4""checksum serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "58fc82bec244f168b23d1963b45c8bf5726e9a15a9d146a067f9081aeed2de79""checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
"checksum signal-hook 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1f272d1b7586bec132ed427f532dd418d8beca1ca7f2caf7df35569b1415a4b4"
"checksum signal-hook 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "97a47ae722318beceb0294e6f3d601205a1e6abaa4437d9d33e3a212233e3021"
"checksum smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "88aea073965ab29f6edb5493faf96ad662fb18aa9eeb186a3b7057951605ed15"
"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
"checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9"
"checksum syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)" = "66c8865bf5a7cbb662d8b011950060b3c8743dca141b054bf7195b20d314d8e2"
"checksum tempfile 3.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "37daa55a7240c4931c84559f03b3cad7d19535840d1c4a0cc4e9b2fb0dcf70ff"
"checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a"
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "e0500b88064f08bebddd0c0bed39e19f5c567a5f30975bee52b0c0d3e2eeb38c"
"checksum tokio 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "65641e515a437b308ab131a82ce3042ff9795bef5d6c5a9be4eb24195c417fd9"
"checksum tokio-current-thread 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "331c8acc267855ec06eb0c94618dcbbfea45bed2d20b77252940095273fb58f6""checksum tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30c6dbf2d1ad1de300b393910e8a3aa272b724a400b6531da03eed99e329fbf0""checksum tokio-fs 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0e9cbbc8a3698b7ab652340f46633364f9eaa928ddaaee79d8b8f356dd79a09d""checksum tokio-io 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b53aeb9d3f5ccf2ebb29e19788f96987fa1355f8fe45ea193928eaaaf3ae820f""checksum tokio-reactor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "afbcdb0f0d2a1e4c440af82d7bbf0bf91a8a8c0575bcd20c05d15be7e9d3a02f"
"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443""checksum tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "83ea44c6c0773cc034771693711c35c677b4b5a4b21b9e7071704c54de7d555e""checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af""checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926""checksum tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6af16bfac7e112bea8b0442542161bfc41cbfa4466b580bdda7d18cb88b911ce"
"checksum tokio-sync 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3742b64166c1ee9121f1921aea5a726098458926a6b732d906ef23b1f3ef6f4f"
"checksum tokio-sync 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "fda385df506bf7546e70872767f71e81640f1f251bdf2fd8eb81a0eaec5fe022"
"checksum tokio-threadpool 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c3fd86cb15547d02daa2b21aadaf4e37dee3368df38a526178a5afa3c034d2fb"
"checksum tokio-threadpool 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "ec5759cf26cf9659555f36c431b515e3d05f66831741c85b4b5d5dfb9cf1323c"
"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
"checksum toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "87c5890a989fa47ecdc7bcb4c63a77a82c18f306714104b1decfd722db17b39e"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
"checksum xmpp-parsers 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5094cec449beca92f82ae4d7fe13cda058005849766d71b86c23e6217f61a357"