From 12eeb4d11eee5b8e6514f0ce8bf7508cc2d6d7a1 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 12 Nov 2014 08:10:46 +0100 Subject: Implement the PING on a server or the gateway itself fix #2575 --- src/bridge/bridge.cpp | 11 +++++++++++ src/bridge/bridge.hpp | 6 ++++++ src/xmpp/xmpp_component.cpp | 5 +++++ 3 files changed, 22 insertions(+) (limited to 'src') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index ed61c6b..a7d8fe6 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -355,6 +355,17 @@ void Bridge::send_irc_participant_ping_request(const Iid& iid, const std::string this->send_irc_user_ping_request(iid.get_server(), nick, iq_id, to_jid, from_jid); } +void Bridge::on_gateway_ping(const std::string& irc_hostname, const std::string& iq_id, const std::string& to_jid, + const std::string& from_jid) +{ + Jid jid(from_jid); + if (irc_hostname.empty() || this->get_irc_client(irc_hostname)) + this->xmpp->send_iq_result(iq_id, to_jid, jid.local); + else + this->xmpp->send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "service-unavailable", + "", true); +} + void Bridge::send_irc_version_request(const std::string& irc_hostname, const std::string& target, const std::string& iq_id, const std::string& to_jid, const std::string& from_jid) diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 6d09fff..cf39545 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -85,6 +85,12 @@ public: void send_irc_participant_ping_request(const Iid& iid, const std::string& nick, const std::string& iq_id, const std::string& to_jid, const std::string& from_jid); + /** + * Directly send back a result if it's a gateway ping or if we are + * connected to the given IRC server, an error otherwise. + */ + void on_gateway_ping(const std::string& irc_hostname, const std::string& iq_id, const std::string& to_jid, + const std::string& from_jid); /*** ** diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp index 516b932..5a5aed4 100644 --- a/src/xmpp/xmpp_component.cpp +++ b/src/xmpp/xmpp_component.cpp @@ -568,6 +568,11 @@ void XmppComponent::handle_iq(const Stanza& stanza) bridge->send_irc_participant_ping_request(iid, to.resource, id, from, to_str); } + else + { // Ping a channel, a server or the gateway itself + bridge->on_gateway_ping(iid.get_server(), + id, from, to_str); + } stanza_error.disable(); } } -- cgit v1.2.3