From e4cc69607c91db43cf154326aaba8afbe97a4c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 4 Apr 2017 18:40:30 +0200 Subject: Handle some iq of type='error' as valid ping response fix #3251 --- src/xmpp/biboumi_component.cpp | 14 +++++++++++++- tests/end_to_end/__main__.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index df96d62..dc57eeb 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -564,6 +564,12 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) else if (type == "error") { stanza_error.disable(); + const auto it = this->waiting_iq.find(id); + if (it != this->waiting_iq.end()) + { + it->second(bridge, stanza); + this->waiting_iq.erase(it); + } } } catch (const IRCNotConnected& ex) @@ -807,8 +813,14 @@ void BiboumiComponent::send_ping_request(const std::string& from, { log_error("Received a corresponding ping result, but the 'to' from " "the response mismatches the 'from' of the request"); + return; } - else + const std::string type = stanza.get_tag("type"); + const XmlNode* error = stanza.get_child("error", COMPONENT_NS); + // Check if what we receive is considered a valid response. And yes, those errors are valid responses + if (type == "result" || + (type == "error" && error && (error->get_child("feature-not-implemented", STANZA_NS) || + error->get_child("service-unavailable", STANZA_NS)))) bridge->send_irc_ping_result({from, bridge}, id); }; this->waiting_iq[id] = result_cb; diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index fd833e2..09ef501 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -1101,6 +1101,44 @@ if __name__ == '__main__': ), partial(expect_stanza, "/message[@from='#biboumi\\40louiz.org\\3a80%{irc_server_one}'][@type='groupchat']/subject[not(text())]"), ]), + Scenario("self_ping_with_error", + [ + handshake_sequence(), + partial(send_stanza, + ""), + connection_sequence("irc.localhost", '{jid_one}/{resource_one}'), + partial(expect_stanza, + "/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"), + partial(expect_stanza, + ("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']", + "/presence/muc_user:x/muc_user:status[@code='110']") + ), + partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"), + + # Send a ping to ourself + partial(send_stanza, + ""), + # We receive our own ping request, + partial(expect_stanza, + "/iq[@from='{lower_nick_one}%{irc_server_one}'][@type='get'][@to='{jid_one}/{resource_one}'][@id='gnip_tsrif']"), + # Respond to the request with an error + partial(send_stanza, + ""), + partial(expect_stanza, + "/iq[@from='#foo%{irc_server_one}/{nick_one}'][@type='result'][@to='{jid_one}/{resource_one}'][@id='first_ping']"), + + # Send a ping to ourself + partial(send_stanza, + ""), + # We receive our own ping request, + partial(expect_stanza, + "/iq[@from='{lower_nick_one}%{irc_server_one}'][@type='get'][@to='{jid_one}/{resource_one}'][@id='gnip_tsrif']"), + # Respond to the request with an error + partial(send_stanza, + ""), + partial(expect_stanza, + "/iq[@from='#foo%{irc_server_one}/{nick_one}'][@type='result'][@to='{jid_one}/{resource_one}'][@id='first_ping']"), + ]), Scenario("self_ping_on_real_channel", [ handshake_sequence(), -- cgit v1.2.3