Update deps

[?]
Dec 31, 2018, 5:35 PM
AYQZ2UIA3HDOJAXF7WZZBFBQGNBLB63PPCMXJYLGES4FVIPXITPQC

Dependencies

  • [2] V5HDBSZM Use jid for receiver address
  • [3] TDOR5XQU Accept destination
  • [4] NDDQQP2P Update deps
  • [5] X6L47BHQ Use different structure for established xmpp connection
  • [6] XGP44R5H Rework stopping xmpp connection
  • [7] HU3NZX5Z Process self-presence via new processing code
  • [8] PFC7OJQF Query roster
  • [9] AGIW6YR3 Use shared future for signal everywhere
  • [10] ZI4GJ72V Add message to xmpp command
  • [11] L77O4T7M Formatting and fixes
  • [12] PVCRPP3B Some servers don't send to in initial presence
  • [13] FVVPKFTL Initial commit
  • [14] QWE26TMV update deps
  • [15] BTOZT4JP Use failure
  • [16] EOHEZXX3 Move request processing to structure
  • [17] FV6BJ5K6 Send self-presence and store account info in Rc so it willbe used in some future in parallel
  • [18] IK3YDPTY Update deps
  • [19] PBRUH4BJ Rename optional XmppConnection to MaybeXmppConnection
  • [20] VS6AHRWI Move XMPP to separate dir
  • [21] 4LRBIGVT Show info about xmpp errors
  • [22] UCY2DO3D Try to read request body
  • [23] HOAZX2PB Reorganize roster processing. Output roster
  • [24] OGMBXBKP Move online to XmppConnection
  • [25] 5A5UVGNM Move receiver closing logic out of xmpp processing
  • [26] 5OBTKGDL Update deps
  • [27] QYY3KRGL Use failure instead Box<dyn Error>
  • [28] O2GM5J4F Don't split xmpp receiving and sending
  • [29] 3GEU7TC7 Welcome to 2018!

Change contents

  • edit in src/xmpp/stanzas.rs at line 2
    [3.57][2.0:26]()
    use xmpp_parsers::iq::Iq;
  • edit in src/xmpp/stanzas.rs at line 3
    [3.141][2.27:61]()
    use xmpp_parsers::roster::Roster;
  • edit in src/xmpp/stanzas.rs at line 12
    [3.419][2.62:272]()
    pub fn make_get_roster(id: &str) -> Element {
    let mut get_roster = Iq::from_get(Roster {
    ver: None,
    items: vec![],
    });
    get_roster.id = Some(id.to_string());
    get_roster.into()
    }
  • edit in src/xmpp/mod.rs at line 9
    [3.47][3.72:73](),[3.72][3.72:73](),[3.73][3.0:105]()
    pub struct MaybeXmppConnection {
    account: std::rc::Rc<config::Account>,
    inner: Option<Client>,
    }
  • replacement in src/xmpp/mod.rs at line 12
    [3.74][3.107:126]()
    inner: Client,
    [3.74]
    [3.126]
    inner: Option<(stream::SplitSink<Client>, stream::SplitStream<Client>)>,
  • replacement in src/xmpp/mod.rs at line 15
    [3.129][3.129:358](),[3.353][3.356:359](),[3.77][3.356:359](),[3.77][3.356:359](),[3.358][3.356:359](),[3.356][3.356:359](),[3.359][3.359:478]()
    impl From<XmppConnection> for MaybeXmppConnection {
    fn from(from: XmppConnection) -> MaybeXmppConnection {
    MaybeXmppConnection {
    account: from.account,
    inner: Some(from.inner),
    }
    }
    }
    impl MaybeXmppConnection {
    fn new(account: config::Account) -> MaybeXmppConnection {
    MaybeXmppConnection {
    [3.129]
    [3.479]
    impl XmppConnection {
    fn new(account: config::Account) -> XmppConnection {
    XmppConnection {
  • replacement in src/xmpp/mod.rs at line 24
    [3.554][3.0:302]()
    /// don't connect if stop_future resolved
    fn connect<F>(
    self,
    stop_future: F,
    ) -> impl Future<Item = XmppConnection, Error = failure::Error>
    where
    F: future::Future + Clone + 'static,
    <F as hyper::rt::Future>::Error: Into<failure::Error> + Send,
    {
    [3.554]
    [3.653]
    /// Error shoud be !
    fn connect<E: 'static>(self) -> impl Future<Item = Self, Error = E> {
  • replacement in src/xmpp/mod.rs at line 27
    [3.690][3.782:841]()
    let MaybeXmppConnection { account, inner } = self;
    [3.690]
    [3.744]
    let XmppConnection { account, inner } = self;
  • replacement in src/xmpp/mod.rs at line 30
    [3.782][3.842:910](),[3.910][3.303:355]()
    Box::new(future::ok(XmppConnection { account, inner }))
    as Box<Future<Item = _, Error = _>>
    [3.782]
    [3.944]
    Box::new(future::ok(XmppConnection {
    account,
    inner: Some(inner),
    })) as Box<Future<Item = _, Error = E>>
  • replacement in src/xmpp/mod.rs at line 35
    [3.961][3.356:1088](),[3.1088][2.273:349]()
    Box::new(
    stop_future
    .clone()
    .select2(
    future::loop_fn(account, move |account| {
    info!("xmpp initialization...");
    let res_client = Client::new(&account.jid, &account.password);
    match res_client {
    Err(_e) => Box::new(future::ok(future::Loop::Continue(account)))
    as Box<Future<Item = _, Error = _>>,
    Ok(client) => {
    info!("xmpp initialized");
    let stop_future2 = stop_future.clone();
    let stop_future3 = stop_future.clone();
    [3.961]
    [3.1476]
    Box::new(future::loop_fn(account, |account| {
    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");
  • replacement in src/xmpp/mod.rs at line 45
    [3.1477][3.1089:1636](),[3.1636][2.350:533](),[2.533][3.1727:2319](),[3.1727][3.1727:2319]()
    // future to wait for online
    Box::new(
    XmppConnection {
    inner: client,
    account,
    }
    .processing(XmppConnection::online, stop_future.clone())
    .map(|(conn, _)| conn)
    .map_err(|(acc, _)| acc)
    .and_then(|conn| conn.initial_roster(stop_future2))
    .and_then(|conn| conn.self_presence(stop_future3))
    .then(
    |r| match r {
    Ok(conn) => future::ok(future::Loop::Break(conn)),
    Err(acc) => future::ok(future::Loop::Continue(acc)),
    },
    ),
    )
    }
    }
    })
    .map_err(|_: ()| ()),
    )
    [3.1477]
    [3.2319]
    // future to wait for online
    Self::online(client.split(), account)
    .and_then(Self::self_presence)
  • replacement in src/xmpp/mod.rs at line 49
    [3.2359][3.2359:2804](),[3.2359][3.2359:2804]()
    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"))
    }
    }),
    )
    [3.2359]
    [3.1858]
    Ok(conn) => future::ok(future::Loop::Break(conn)),
    Err(acc) => future::ok(future::Loop::Continue(acc)),
    })
    }))
  • edit in src/xmpp/mod.rs at line 55
    [3.2890][3.3373:3375]()
    }
  • replacement in src/xmpp/mod.rs at line 56
    [3.2998][3.3376:3427](),[3.3427][3.2805:2913](),[3.2913][3.3535:3776](),[3.1190][3.3535:3776](),[3.3535][3.3535:3776](),[3.3776][3.2914:3096](),[3.3096][3.3958:4014](),[3.1312][3.3958:4014](),[3.3958][3.3958:4014](),[3.4014][3.3097:3130](),[3.3130][2.534:602](),[3.3199][3.4116:4611](),[2.602][3.4116:4611](),[3.602][3.4116:4611](),[3.1358][3.4116:4611](),[3.4116][3.4116:4611]()
    impl XmppConnection {
    /// base XMPP processing
    fn xmpp_processing(&mut self, event: &Event) {
    info!("Incoming xmpp event: {:?}", event);
    }
    /// process event from xmpp stream
    /// returns from future when condition met
    /// or stop future was resolved
    fn processing<S, F, T, E>(
    self,
    stop_condition: S,
    stop_future: F,
    ) -> impl Future<
    Item = (Self, Result<Either<F, T>, failure::Error>),
    Error = (
    std::rc::Rc<config::Account>,
    Result<Either<F, T>, failure::Error>,
    ),
    >
    where
    F: Future<Item = T, Error = E>,
    E: Into<failure::Error>,
    S: FnMut(&mut Self, Event) -> Result<bool, failure::Error>,
    {
    future::loop_fn(
    (self, stop_future, stop_condition),
    |(xmpp, stop_future, mut stop_condition)| {
    let XmppConnection { inner, account } = xmpp;
    inner.into_future().select2(stop_future).then(|r| match r {
    Ok(Either::A(((event, client), b))) => {
    if let Some(event) = event {
    let mut xmpp = XmppConnection {
    inner: client,
    [3.2998]
    [3.3955]
    /// get connection and wait for online status and set presence
    /// returns error if something went wrong
    fn online(
    (sink, stream): (stream::SplitSink<Client>, stream::SplitStream<Client>),
    account: std::rc::Rc<config::Account>,
    ) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>> {
    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(XmppConnection {
  • replacement in src/xmpp/mod.rs at line 71
    [3.3996][3.4612:4701](),[3.4701][2.603:672](),[2.672][3.3270:3702](),[3.3270][3.3270:3702](),[3.3702][3.5203:5335](),[3.1647][3.5203:5335](),[3.5203][3.5203:5335]()
    };
    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, Err(e))),
    }
    } else {
    future::err((account, Ok(Either::A(b))))
    [3.3996]
    [3.4505]
    inner: Some((sink, stream)),
    }))
  • replacement in src/xmpp/mod.rs at line 74
    [3.4531][3.5336:5779]()
    }
    Ok(Either::B((t, a))) => {
    if let Some(inner) = a.into_inner() {
    future::ok(future::Loop::Break((
    XmppConnection { inner, account },
    Ok(Either::B(t)),
    )))
    } else {
    future::err((account, Ok(Either::B(t))))
    [3.4531]
    [3.4974]
    Some(Event::Stanza(s)) => {
    info!("xmpp stanza: {:?}", s);
    future::ok(future::Loop::Continue((sink, stream, account)))
  • replacement in src/xmpp/mod.rs at line 78
    [3.5000][3.5780:5802](),[3.5802][3.3703:3792](),[3.3792][3.5891:6129](),[3.1837][3.5891:6129](),[3.5891][3.5891:6129](),[3.6129][3.3793:3840](),[3.3840][3.6176:6241](),[3.1878][3.6176:6241](),[3.6176][3.6176:6241](),[3.6241][3.3841:3907]()
    }
    Err(Either::A((_e, b))) => future::err((account, Ok(Either::A(b)))),
    Err(Either::B((e, a))) => {
    if let Some(inner) = a.into_inner() {
    future::ok(future::Loop::Break((
    XmppConnection { inner, account },
    Err(e.into()),
    )))
    } else {
    future::err((account, Err(e.into())))
    [3.5000]
    [3.5513]
    _ => {
    warn!("Disconnected");
    future::err(account)
  • edit in src/xmpp/mod.rs at line 82
    [3.5539]
    [3.5539]
    },
    Err((e, _)) => {
    error!("xmpp receive error: {}", e);
    future::err(account)
  • replacement in src/xmpp/mod.rs at line 89
    [3.5595][3.6308:6318]()
    )
    [3.5595]
    [3.3349]
    ))
  • replacement in src/xmpp/mod.rs at line 92
    [3.3356][3.6319:6432](),[3.6432][2.673:746](),[2.746][3.3982:4396](),[3.3982][3.3982:4396](),[3.4396][3.3687:3693](),[3.3137][3.3687:3693](),[3.3687][3.3687:3693]()
    /// get connection and wait for online status and set presence
    /// returns error if something went wrong
    fn online(&mut self, event: Event) -> Result<bool, failure::Error> {
    match event {
    Event::Online => {
    info!("Online!");
    Ok(true)
    }
    Event::Stanza(s) => {
    warn!("Stanza before online: {:?}", s);
    Ok(false)
    }
    _ => {
    error!("Disconnected while online");
    Err(format_err!("Disconnected while online"))
    }
    }
    }
    [3.3356]
    [3.3693]
    fn self_presence(self) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>> {
    let XmppConnection { account, inner } = self;
    if let Some((sink, stream)) = inner {
    use tokio::prelude::Sink;
  • replacement in src/xmpp/mod.rs at line 97
    [3.3694][2.747:2496]()
    fn initial_roster<F, E>(
    self,
    stop_future: F,
    ) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>
    where
    F: Future<Error = E>,
    E: Into<failure::Error>,
    {
    let XmppConnection {
    account,
    inner: client,
    } = self;
    use tokio::prelude::Sink;
    let id_get_roster: String = "id_get_roster0".to_string();
    let get_roster = stanzas::make_get_roster(&id_get_roster);
    let account2 = account.clone();
    info!("Quering roster... {:?}", get_roster);
    client
    .send(get_roster)
    .map_err(move |e| {
    error!("Error on querying roster: {}", e);
    (account2, Err(failure::SyncFailure::new(e).into()))
    })
    .and_then(move |client| {
    XmppConnection {
    inner: client,
    account,
    }
    .processing(
    move |_conn, event| {
    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_get_roster {
    match iq.payload {
    xmpp_parsers::iq::IqType::Error(_e) => {
    Err(format_err!("Get error instead of roster"))
    }
    _ => Ok(true),
    [3.3694]
    [2.2496]
    let presence = stanzas::make_presence(&account);
    info!("Sending presence...");
    Box::new(
    sink.send(presence)
    .map_err(|e| {
    error!("Error on send self-presence: {}", e);
    "Cann't send self-presence".to_owned()
    })
    .join(
    future::loop_fn((account.clone(), stream), |(account, stream)| {
    stream
    .into_future()
    .map_err(|(e, _)| {
    error!("Error on reading self-presence: {}", e);
    "Cann't read self-presence".to_owned()
    })
    .and_then(|(event, stream)| match event {
    Some(event) => {
    if let tokio_xmpp::Event::Stanza(e) = event {
    info!("Get stanza: {:?}", e);
    if e.name() == "presence"
    && e.attr("from")
    .map_or(false, |f| f == account.jid)
    && e.attr("to").map_or(false, |f| f == account.jid)
    {
    info!("Self presence");
    future::ok(future::Loop::Break(stream))
    } else {
    future::ok(future::Loop::Continue((
    account, stream,
    )))
  • replacement in src/xmpp/mod.rs at line 130
    [2.2591][2.2591:2645]()
    Ok(false)
    [2.2591]
    [2.2645]
    future::err("Got wrong event".to_owned())
  • edit in src/xmpp/mod.rs at line 132
    [2.2687][2.2687:2813]()
    } else {
    Err(format_err!("Iq stanza without id"))
  • replacement in src/xmpp/mod.rs at line 133
    [2.2851][2.2851:3693](),[2.3693][3.4397:4614](),[3.3694][3.4397:4614](),[3.4614][2.3694:3789](),[2.3789][3.7173:7207](),[3.3790][3.7173:7207](),[3.3315][3.7173:7207](),[3.7173][3.7173:7207](),[3.6217][3.784:785](),[3.1012][3.784:785](),[3.1649][3.784:785](),[3.2775][3.784:785](),[3.1428][3.784:785](),[3.1927][3.784:785](),[3.7207][3.784:785](),[3.784][3.784:785](),[3.785][3.7208:7265](),[3.3354][3.7303:7343](),[3.7303][3.7303:7343](),[3.7343][2.3790:3844](),[2.3844][3.4615:5257](),[3.7343][3.4615:5257](),[3.5257][2.3845:3934](),[2.3934][3.5257:5558](),[3.5257][3.5257:5558]()
    }
    Err(_e) => Ok(false),
    }
    } else {
    Err(format_err!("Wrong event while waiting roster"))
    }
    },
    stop_future,
    )
    })
    .then(|r| match r {
    Err((account, e)) => {
    error!(
    "Cann't wait roster: {}",
    e.err().map_or_else(
    || std::borrow::Cow::Borrowed("None"),
    |e| e.to_string().into()
    )
    );
    future::err(account)
    }
    Ok((conn, _)) => future::ok(conn),
    })
    }
    fn self_presence<F, E>(
    self,
    stop_future: F,
    ) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>
    where
    F: Future<Error = E>,
    E: Into<failure::Error>,
    {
    let XmppConnection {
    account,
    inner: client,
    } = self;
    use tokio::prelude::Sink;
    let presence = stanzas::make_presence(&account);
    let account2 = account.clone();
    info!("Sending presence... {:?}", presence);
    client
    .send(presence)
    .map_err(|e| {
    error!("Error on send self-presence: {}", e);
    (account2, Err(failure::SyncFailure::new(e).into()))
    })
    .and_then(move |client| {
    XmppConnection {
    inner: client,
    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 {
    Err(format_err!("Wrong event while waiting self-presence"))
    [2.2851]
    [3.5558]
    None => future::err("Got closed stream".to_owned()),
    })
    })
    .map_err(|e| format!("waiting self-presence: {}", e)),
    )
    .then(|r| match r {
    Err(e) => {
    error!("Self-presence waiting error: {}", e);
    future::err(account)
  • replacement in src/xmpp/mod.rs at line 143
    [3.5584][3.5584:5705](),[3.5584][3.5584:5705](),[3.5705][2.3935:3975](),[2.3975][3.5744:5926](),[3.5744][3.5744:5926]()
    },
    stop_future,
    )
    })
    .then(|r| match r {
    Err((account, _e)) => {
    error!("Cann't wait self-presence");
    future::err(account)
    }
    Ok((conn, _)) => future::ok(conn),
    })
    [3.5584]
    [3.3783]
    Ok(inner) => future::ok(XmppConnection {
    account,
    inner: Some(inner),
    }),
    }),
    )
    } else {
    warn!("Don't gen connection on self-presence");
    Box::new(future::err(account)) as Box<Future<Item = _, Error = _>>
    }
  • replacement in src/xmpp/mod.rs at line 157
    [3.60][2.3976:4055]()
    pub struct XmppCommand {
    pub xmpp_to: jid::Jid,
    pub message: String,
    }
    [3.60]
    [3.3816]
    pub struct XmppCommand;
  • replacement in src/xmpp/mod.rs at line 162
    [3.3891][3.8744:8775]()
    conn: MaybeXmppConnection,
    [3.3891]
    [3.3917]
    conn: XmppConnection,
  • replacement in src/xmpp/mod.rs at line 166
    [3.133][3.8776:8859]()
    fn new(cmd_recv: S, signal: F, conn: MaybeXmppConnection) -> XmppState<F, S> {
    [3.133]
    [3.4038]
    fn new(cmd_recv: S, signal: F, conn: XmppConnection) -> XmppState<F, S> {
  • replacement in src/xmpp/mod.rs at line 181
    [3.4311][3.5927:6054]()
    F: future::Future + Clone + 'static,
    <F as hyper::rt::Future>::Error: std::fmt::Display + Into<failure::Error> + Send,
    [3.4311]
    [3.465]
    F: future::Future<Item = ()> + 'static,
  • replacement in src/xmpp/mod.rs at line 184
    [3.5814][3.8988:9038](),[3.4357][3.8988:9038]()
    let conn = MaybeXmppConnection::new(account);
    [3.4357]
    [3.4526]
    let signal = signal.map_err(|_| format_err!("Wrong shutdown signal"));
    let conn = XmppConnection::new(account);
  • replacement in src/xmpp/mod.rs at line 194
    [3.4692][3.6055:6123]()
    conn.connect(signal.clone())
    .and_then(|conn| {
    [3.4692]
    [3.4761]
    signal
    .select2(conn.connect().and_then(|conn| {
  • replacement in src/xmpp/mod.rs at line 203
    [3.675][3.6124:6205]()
    .map(|(cmd, cmd_recv)| (cmd, cmd_recv, conn))
    })
    [3.675]
    [3.731]
    .map(|f| (f, conn))
    }))
  • replacement in src/xmpp/mod.rs at line 207
    [3.5146][3.6206:6779]()
    Ok((cmd, cmd_recv, conn)) => {
    if let Some(_cmd) = cmd {
    info!("Got cmd");
    // got cmd, continue
    future::ok(future::Loop::Continue(XmppState::new(
    cmd_recv,
    signal,
    conn.into(),
    )))
    } else {
    future::ok(future::Loop::Break((None, conn.into())))
    }
    [3.5146]
    [3.6239]
    Ok(Either::A((_x, b))) => {
    info!("Got signal");
    // got signal, breaks
    Box::new(b.map(|b| future::Loop::Break((Some((b.0).1), b.1))))
    as Box<Future<Item = _, Error = _>>
    }
    Ok(Either::B((x, a))) => {
    info!("Got cmd");
    // got cmd, continue
    Box::new(future::ok(future::Loop::Continue(XmppState::new(
    (x.0).1,
    a,
    x.1,
    )))) as Box<Future<Item = _, Error = _>>
  • replacement in src/xmpp/mod.rs at line 222
    [3.6261][3.6780:6812]()
    Err(e) => {
    [3.6261]
    [3.6240]
    Err(Either::A((e, b))) => {
    // got signal error, breaks
    error!("Signal error: {}", e);
    Box::new(b.map(|b| future::Loop::Break((Some((b.0).1), b.1))))
    as Box<Future<Item = _, Error = _>>
    }
    Err(Either::B((e, _a))) => {
  • replacement in src/xmpp/mod.rs at line 231
    [3.6342][2.4056:4095]()
    future::err(e)
    [3.6342]
    [3.6572]
    Box::new(future::err(format_err!("Cmd error")))
    as Box<Future<Item = _, Error = _>>
  • replacement in src/xmpp/mod.rs at line 237
    [3.900][3.9860:9934]()
    .and_then(|(opt_cmd_recv, _conn): (Option<S>, MaybeXmppConnection)| {
    [3.900]
    [3.969]
    .and_then(|(opt_cmd_recv, _conn): (Option<S>, XmppConnection)| {
  • replacement in src/xmpp/mod.rs at line 247
    [3.1354][3.6876:6913]()
    Box::new(future::ok(()))
    [3.1354]
    [3.1422]
    Box::new(future::err(format_err!("cmd receiver gone")))
  • edit in src/main.rs at line 22
    [3.3921]
    [3.3953]
    use hyper::service::service_fn;
  • replacement in src/main.rs at line 28
    [3.4066][2.4096:4140]()
    use tokio::prelude::{Future, Sink, Stream};
    [3.4066]
    [3.4092]
    use tokio::prelude::Sink;
  • edit in src/main.rs at line 38
    [3.4260][2.4141:5074](),[2.5074][3.4701:4702](),[3.4701][3.4701:4702](),[3.4702][2.5075:9738]()
    struct ServiceCmd {
    cmd_send: tokio_channel::mpsc::Sender<XmppCommand>,
    }
    impl hyper::service::Service for ServiceCmd {
    type ReqBody = Body;
    type ResBody = Body;
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    type Future =
    Box<dyn Future<Item = Response<Self::ResBody>, Error = Self::Error> + Send + 'static>;
    fn call(&mut self, req: Request<Self::ReqBody>) -> Self::Future {
    let xmpp_to_opt = req.headers().get("X-XMPP-To");
    let xmpp_to_res: Result<jid::Jid, failure::Error> = xmpp_to_opt.map_or_else(
    || Err(format_err!("No X-XMPP-To header")),
    |xmpp_to| {
    std::str::from_utf8(xmpp_to.as_bytes())
    .map_err(|e| e.into())
    .and_then(|s| {
    std::str::FromStr::from_str(s).map_err(|e: jid::JidParseError| e.into())
    })
    },
    );
    match xmpp_to_res {
    Err(err) => {
    warn!("Unknown destination: {}", err);
    Box::new(tokio::prelude::future::result(
    Response::builder()
    .status(hyper::StatusCode::BAD_REQUEST)
    .body(Body::from(format!("Unknown destination: {}", err)))
    .map_err(|e| {
    Box::new(e) as Box<dyn std::error::Error + Sync + Send + 'static>
    }),
    )) as Box<Future<Item = _, Error = _> + Send + 'static>
    }
    Ok(xmpp_to) => {
    info!("Got request. Reading body...");
    let cmd_send = self.cmd_send.clone();
    Box::new(
    req.into_body()
    .map_err(|e| {
    Box::new(e) as Box<dyn std::error::Error + Sync + Send + 'static>
    })
    .fold(String::new(), |mut acc, ch| {
    std::str::from_utf8(&*ch).map(|s| {
    acc.push_str(s);
    acc
    })
    })
    .and_then(move |message: String| {
    if !message.is_empty() {
    Box::new(
    cmd_send
    .clone()
    .send(XmppCommand { xmpp_to, message })
    .then(|r| match r {
    Ok(_) => tokio::prelude::future::ok(Response::new(
    Body::from("Accepted"),
    )),
    Err(e) => {
    error!("Command sent error: {}", e);
    tokio::prelude::future::result(
    Response::builder()
    .status(hyper::StatusCode::BAD_REQUEST)
    .body(Body::from(format!(
    "Command sent error: {}",
    e
    ))),
    )
    }
    })
    .map_err(|e| {
    Box::new(e)
    as Box<
    dyn std::error::Error + Sync + Send + 'static,
    >
    }),
    )
    } else {
    warn!("Empty message");
    Box::new(tokio::prelude::future::result(
    Response::builder()
    .status(hyper::StatusCode::BAD_REQUEST)
    .body(Body::from("Empty message"))
    .map_err(|e| {
    Box::new(e)
    as Box<
    dyn std::error::Error + Sync + Send + 'static,
    >
    }),
    ))
    as Box<Future<Item = _, Error = _> + Send + 'static>
    }
    }),
    ) as Box<Future<Item = _, Error = _> + Send + 'static>
    }
    }
    }
    }
    struct MakeServiceCmd {
    cmd_send: tokio_channel::mpsc::Sender<XmppCommand>,
    }
    impl<Ctx> hyper::service::MakeService<Ctx> for MakeServiceCmd {
    type ReqBody = Body;
    type ResBody = Body;
    type Error = Box<dyn std::error::Error + Sync + Send + 'static>;
    type Service = ServiceCmd;
    type Future = tokio::prelude::future::FutureResult<ServiceCmd, Self::MakeError>;
    type MakeError = hyper::http::Error;
    fn make_service(&mut self, _ctx: Ctx) -> Self::Future {
    tokio::prelude::future::ok(ServiceCmd {
    cmd_send: self.cmd_send.clone(),
    })
    }
    }
  • replacement in src/main.rs at line 63
    [3.4954][3.6914:7021]()
    .map_err(|e| {
    error!("Cann't get CTRL+C signal: {}", e.0);
    e.0
    })
    [3.4954]
    [3.5020]
    .map_err(|e| error!("Cann't get CTRL+C signal: {}", e.0))
  • replacement in src/main.rs at line 69
    [3.5155][2.9740:9784]()
    .serve(MakeServiceCmd { cmd_send })
    [3.5155]
    [3.5935]
    .serve(move || {
    let cmd_send = cmd_send.clone();
    service_fn(move |_req: Request<Body>| {
    info!("Got request");
    cmd_send.clone().send(XmppCommand {}).then(|r| match r {
    Ok(_) => tokio::prelude::future::ok(Response::new(Body::from("Accepted"))),
    Err(e) => {
    error!("Command sent error: {}", e);
    tokio::prelude::future::result(
    Response::builder()
    .status(hyper::StatusCode::BAD_REQUEST)
    .body(Body::from(format!("Command sent error: {}", e))),
    )
    }
    })
    })
    })
  • replacement in src/main.rs at line 97
    [3.6389][3.7022:7110]()
    let result = ctrt.block_on(xmpp_process(ctrl_c.clone(), recv, config.account));
    [3.6389]
    [3.6536]
    let result = ctrt.block_on(xmpp_process(
    ctrl_c.clone().map(|_| ()),
    recv,
    config.account,
    ));
  • replacement in Cargo.toml at line 23
    [3.7111][2.9785:9878]()
    try_from = "=0.2.2" # dependency of xmpp-parsers
    jid = "=0.5.2" # dependency of xmpp-parsers
    [3.7111]
  • replacement in Cargo.lock at line 603
    [3.3558][3.26771:26849](),[2.12571][3.26771:26849](),[3.10594][3.26771:26849](),[3.7688][3.26771:26849](),[3.5210][3.26771:26849](),[3.7327][3.26771:26849](),[3.7967][3.26771:26849](),[3.26771][3.26771:26849]()
    "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
    [2.12571]
    [3.26849]
    "serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)",
  • edit in Cargo.lock at line 1116
    [2.15026][2.15026:15096]()
    "jid 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
  • edit in Cargo.lock at line 1125
    [3.44807][2.15329:15404]()
    "try_from 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  • replacement in Cargo.lock at line 1145
    [3.45396][3.45396:45415](),[3.45396][3.45396:45415](),[3.45396][3.45396:45415](),[3.45396][3.45396:45415](),[3.45396][3.45396:45415](),[3.45396][3.45396:45415](),[3.45396][3.45396:45415](),[3.45396][3.45396:45415]()
    version = "1.0.33"
    [3.45396]
    [3.45415]
    version = "1.0.34"
  • replacement in Cargo.lock at line 1984
    [3.12481][3.92248:92402](),[2.21640][3.92248:92402](),[3.20129][3.92248:92402](),[3.15588][3.92248:92402](),[3.12956][3.92248:92402](),[3.16471][3.92248:92402](),[3.16499][3.92248:92402](),[3.92248][3.92248:92402]()
    "checksum serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "c37ccd6be3ed1fdf419ee848f7c758eb31b054d7cd3ae3600e3bae0adf569811"
    [2.21640]
    [3.92402]
    "checksum serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)" = "bdf540260cfee6da923831f4776ddc495ada940c30117977c70f1313a6130545"