Connect to xmpp server

[?]
Oct 28, 2018, 5:27 PM
E4YEIQYO6OX5U225LMB4YWIT5LK2VDBH5HVLV5C5HCIWQWVNVFOAC

Dependencies

  • [2] Z7OFWSBL Refactor account data
  • [3] PHPCAQ6Z Use env logger. Implement command loop
  • [4] AXDOLAOA Introduce xmpp client
  • [5] AVBHYHOA Stop xmpp thread by shudown
  • [6] F5UQL2FB Manage xmpp connection in cmd processing loop
  • [*] FVVPKFTL Initial commit
  • [*] HKSQO7JZ Enable hyper http server and configuration
  • [*] YGC7ZD7N Use logger

Change contents

  • edit in src/xmpp.rs at line 1
    [3.44]
    [3.44]
    use tokio::prelude::stream;
  • replacement in src/xmpp.rs at line 5
    [3.1][3.1:25]()
    use tokio_xmpp::Client;
    [3.1]
    [2.0]
    use tokio_xmpp::{Client, Event};
  • replacement in src/xmpp.rs at line 11
    [2.44][3.26:53](),[3.68][3.26:53]()
    inner: Option<Client>,
    [2.44]
    [3.91]
    inner: Option<(stream::SplitSink<Client>, stream::SplitStream<Client>)>,
  • replacement in src/xmpp.rs at line 24
    [3.380][3.380:445](),[3.445][2.125:179](),[2.179][3.159:205](),[3.159][3.159:205](),[3.205][2.180:259](),[2.259][3.268:370](),[3.268][3.268:370](),[3.370][2.260:335]()
    fn connect<E>(self) -> impl Future<Item = Self, Error = E> {
    let XmppConnection { account, inner } = self;
    let inner = inner.unwrap_or_else(|| {
    let mut res_client = Client::new(&account.jid, &account.password);
    while let Err(e) = res_client {
    error!("Cann't init xmpp client: {}", e);
    res_client = Client::new(&account.jid, &account.password);
    [3.380]
    [3.429]
    fn connect<E: 'static>(self) -> impl Future<Item = Self, Error = E> {
    info!("xmpp connection...");
    future::loop_fn(self, |XmppConnection { account, inner }| {
    if let Some(inner) = inner {
    Box::new(future::ok(future::Loop::Break(XmppConnection {
    account,
    inner: Some(inner),
    }))) as Box<Future<Item = _, Error = E>>
    } else {
    info!("xmpp initialization...");
    let mut res_client = Client::new(&account.jid, &account.password);
    while let Err(e) = res_client {
    error!("Cann't init xmpp client: {}", e);
    res_client = Client::new(&account.jid, &account.password);
    }
    let client = res_client.expect("Cann't init xmpp client");
    info!("xmpp initialized");
    // future to wait for online
    let (sink, stream) = client.split();
    Box::new(future::loop_fn(
    (sink, stream, account),
    |(sink, stream, account)| {
    stream.into_future().then(|r| match r {
    Ok((event, stream)) => match event {
    Some(Event::Online) => {
    info!("Online");
    future::ok(future::Loop::Break(future::Loop::Break(
    XmppConnection {
    account,
    inner: Some((sink, stream)),
    },
    )))
    }
    Some(Event::Stanza(s)) => {
    info!("xmpp stanza: {:?}", s);
    future::ok(future::Loop::Continue((sink, stream, account)))
    }
    _ => {
    warn!("Disconnected");
    future::ok(future::Loop::Break(future::Loop::Continue(
    XmppConnection {
    account,
    inner: None,
    },
    )))
    }
    },
    Err((e, _)) => {
    error!("xmpp receive error: {}", e);
    future::ok(future::Loop::Break(future::Loop::Continue(
    XmppConnection {
    account,
    inner: None,
    },
    )))
    }
    })
    },
    ))
  • edit in src/xmpp.rs at line 86
    [3.443][3.443:584](),[3.443][3.443:584](),[3.584][3.499:536](),[3.499][3.499:536](),[3.536][2.336:357](),[2.357][3.600:632](),[3.624][3.600:632](),[3.600][3.600:632]()
    let client = res_client.expect("Cann't init xmpp client");
    info!("xmpp initialized");
    client
    });
    future::ok(XmppConnection {
    account,
    inner: Some(inner),
  • replacement in src/xmpp.rs at line 108
    [3.364][3.866:899]()
    pub fn xmpp_process<F: 'static>(
    [3.364]
    [3.388]
    pub fn xmpp_process<F>(
  • replacement in src/xmpp.rs at line 114
    [3.140][3.140:174](),[3.140][3.140:174]()
    F: future::Future<Item = ()>,
    [3.140]
    [3.174]
    F: future::Future<Item = ()> + 'static,
  • edit in src/xmpp.rs at line 129
    [3.1222]
    [3.1222]
    info!("xmpp connected!");
  • edit in src/xmpp.rs at line 139
    [3.1613]
    [3.1613]
    info!("Got signal");
  • edit in src/xmpp.rs at line 145
    [3.1879]
    [3.1879]
    info!("Got cmd");
  • replacement in src/xmpp.rs at line 159
    [3.2523][3.2523:2573](),[3.2523][3.2523:2573]()
    Err(Either::B((_e, _a))) => {
    [3.2523]
    [3.2573]
    Err(Either::B((e, _a))) => {
  • edit in src/xmpp.rs at line 161
    [3.2623]
    [3.2623]
    error!("Cmd error: {}", e);
  • edit in src/main.rs at line 7
    [9.61]
    [10.0]
    extern crate minidom;
  • edit in Cargo.toml at line 19
    [10.269]
    [9.2214]
    minidom = "0.10"
  • edit in Cargo.lock at line 631
    [9.22421]
    [9.22421]
    ]
    [[package]]
    name = "minidom"
    version = "0.10.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    dependencies = [
    "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
    "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
    "quick-xml 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
  • edit in Cargo.lock at line 866
    [9.30186]
    [9.30186]
    source = "registry+https://github.com/rust-lang/crates.io-index"
    dependencies = [
    "encoding_rs 0.8.10 (registry+https://github.com/rust-lang/crates.io-index)",
    "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
    "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
    "memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
    ]
    [[package]]
    name = "quick-xml"
    version = "0.13.1"
  • edit in Cargo.lock at line 1070
    [10.2078]
    [9.35429]
    "minidom 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
  • edit in Cargo.lock at line 1875
    [9.72552]
    [9.72552]
    "checksum minidom 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "275024eea6c6ff4ace22f2750843831183785288eec1cff91a4e6b8898cf94f9"
  • edit in Cargo.lock at line 1903
    [9.76696]
    [9.76696]
    "checksum quick-xml 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1b62a38216952bff95085ad664b772492288a96a25544f48d25e7200de1d7db7"