Checks for self XEP-0163 support

O01eg
Oct 22, 2021, 9:59 AM
TRSLPEEJUTUZXFDXLNUYPGTHZREGH5KGFHQFHVCD2AXOD5YAGBNQC

Dependencies

Change contents

  • edit in "src/xmpp/xmpp_connection.rs" at line 188
    [3.4815]
    [3.4815]
    struct SelfDiscoveryIqHandler {}
  • edit in "src/xmpp/xmpp_connection.rs" at line 191
    [3.4816]
    [3.4816]
    impl IqHandler for SelfDiscoveryIqHandler {
    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::disco::DiscoInfoResult, _> {
    Ok(self_discovery) => {
    conn.state.data.self_discovery_init = true;
    conn.state.data.self_pubsub_pep = false;
    for i in self_discovery.identities {
    if i.category == "pubsub" && i.type_ == "pep" {
    conn.state.data.self_pubsub_pep = true;
    break;
    }
    }
    info!(
    "Support XEP-0163: Personal Eventing Protocol: {}",
    conn.state.data.self_pubsub_pep
    );
    true
    }
    Err(e) => {
    error!("Cann't parse self discovery: {}", e);
    false
    }
    }
    } else {
    error!("No self discovery");
    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
    }
    }
  • edit in "src/xmpp/xmpp_connection.rs" at line 272
    [3.5630]
    [3.5630]
    /// if self discovery was initialized
    /// ToDo: remove it as it is used only for initialization
    self_discovery_init: bool,
    /// if XEP-0163 Personal Eventing Protocol supported
    self_pubsub_pep: bool,
  • replacement in "src/xmpp/xmpp_connection.rs" at line 541
    [3.14221][3.14221:14274]()
    match (connected, stopped) {
    [3.14221]
    [3.14274]
    let (connected, stopped) = match (connected, stopped) {
  • edit in "src/xmpp/xmpp_connection.rs" at line 544
    [3.14424]
    [3.14424]
    }
    (connected, stopped) => (connected, stopped),
    };
    match (connected, stopped) {
    (Ok(connection), Either::Left(stop_future)) => {
    connection.self_discovery(stop_future).await
  • edit in "src/xmpp/xmpp_connection.rs" at line 1198
    [8.1466]
    [8.1466]
    async fn self_discovery<F>(
    mut self,
    mut stop_future: F,
    ) -> (Result<Self, std::rc::Rc<config::Account>>, Either<F, ()>)
    where
    F: std::future::Future<Output = ()> + Unpin,
    {
    self.state.data.counter += 1;
    let id_self_discovery = format!("id_self_discovery{}", self.state.data.counter);
    let self_discovery = stanzas::make_disco_get(
    id_self_discovery.clone(),
    Some(self.account.jid.clone()),
    Some(xmpp_parsers::BareJid::from(self.account.jid.clone()).into()),
    );
    self.state.data.pending_ids.insert(
    id_self_discovery,
    IqWait::new(60, SelfDiscoveryIqHandler {}),
    );
    info!(
    "Sending self discovery... {}",
    String::from(&self_discovery)
    );
    let opt_stop_future = {
    let send_future = self.state.client.send_stanza(self_discovery);
    tokio::pin!(send_future);
    match futures_util::future::select(stop_future, send_future).await {
    Either::Left(((), _)) => None,
    Either::Right((Ok(_), stop_future)) => Some(stop_future),
    Either::Right((Err(e), f)) => {
    error!("Send self discovery error: {}", e);
    return (Err(self.account), Either::Left(f));
    }
    }
    };
    if let Some(f) = opt_stop_future {
    stop_future = f;
    } else {
    return (Ok(self), Either::Right(()));
    }
    (Ok(self), Either::Left(stop_future))
    }
  • replacement in "src/xmpp/stanzas.rs" at line 2
    [3.32592][3.32592:32673]()
    use xmpp_parsers::disco::{DiscoInfoResult, DiscoItemsResult, Feature, Identity};
    [3.32592]
    [3.32673]
    use xmpp_parsers::disco::{DiscoInfoQuery, DiscoInfoResult, DiscoItemsResult, Feature, Identity};
  • edit in "src/xmpp/stanzas.rs" at line 232
    [3.38862]
    pub fn make_disco_get(
    id: String,
    from: Option<xmpp_parsers::Jid>,
    to: Option<xmpp_parsers::Jid>,
    ) -> Element {
    let mut get = Iq::from_get(id, DiscoInfoQuery { node: None });
    get.from = from;
    get.to = to;
    get.into()
    }
  • edit in "README.md" at line 15
    [3.56150]
    [3.56150]
    At start send self-discovery to server.
  • edit in "README.md" at line 29
    [3.56393]
    [3.56393]
    #### XEP-0163: Personal Eventing Protocol
  • edit in "README.md" at line 32
    [3.56394]
    [3.56394]
    Checks if own server supports it.
  • replacement in "Cargo.toml" at line 18
    [3.69328][3.1137:1156]()
    env_logger = "0.8"
    [3.69328]
    [3.1289]
    env_logger = "0.9"
  • replacement in "Cargo.lock" at line 237
    [3.77466][2.1730:1748]()
    version = "0.8.4"
    [3.77466]
    [3.77484]
    version = "0.9.0"
  • replacement in "Cargo.lock" at line 239
    [3.77549][2.1749:1827]()
    checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3"
    [3.77549]
    [3.77627]
    checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"