diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-11-12 07:51:10 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-11-12 08:13:02 +0100 |
commit | 4a8bcd3cbde0a41902999db7acc346de020cf564 (patch) | |
tree | df2085fd195418f44ad09045e8e06ffff4bf2bdb /src | |
parent | c20bdd68796c0fc31441ffe059a462a0d423cc77 (diff) | |
download | biboumi-4a8bcd3cbde0a41902999db7acc346de020cf564.tar.gz biboumi-4a8bcd3cbde0a41902999db7acc346de020cf564.tar.bz2 biboumi-4a8bcd3cbde0a41902999db7acc346de020cf564.tar.xz biboumi-4a8bcd3cbde0a41902999db7acc346de020cf564.zip |
Implement PING to in-room participant
ref #2575
Diffstat (limited to 'src')
-rw-r--r-- | src/bridge/bridge.cpp | 30 | ||||
-rw-r--r-- | src/bridge/bridge.hpp | 7 | ||||
-rw-r--r-- | src/xmpp/xmpp_component.cpp | 5 |
3 files changed, 41 insertions, 1 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 08fd569..ed61c6b 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -326,13 +326,41 @@ void Bridge::send_irc_user_ping_request(const std::string& irc_hostname, const s this->add_waiting_irc(std::move(cb)); } +void Bridge::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) +{ + IrcClient* irc = this->get_irc_client(iid.get_server()); + if (!irc) + { + this->xmpp->send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "item-not-found", + "Not connected to IRC server"s + iid.get_server(), true); + return; + } + IrcChannel* chan = irc->get_channel(iid.get_local()); + if (!chan->joined) + { + this->xmpp->send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "not-allowed", + "", true); + return; + } + if (chan->get_self()->nick != nick && !chan->find_user(nick)) + { + this->xmpp->send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "item-not-found", + "Recipient not in room", true); + return; + } + + // The user is in the room, send it a direct PING + this->send_irc_user_ping_request(iid.get_server(), nick, iq_id, to_jid, from_jid); +} + 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) { Iid iid(target + "!" + irc_hostname); this->send_private_message(iid, "\01VERSION\01"); - // TODO, add a timer to remove that waiting iq if the server does not // respond with a matching command before n seconds irc_responder_callback_t cb = [this, target, iq_id, to_jid, irc_hostname, from_jid](const std::string& hostname, const IrcMessage& message) -> bool diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index f7edfaa..6d09fff 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -78,6 +78,13 @@ public: void send_irc_user_ping_request(const std::string& irc_hostname, const std::string& nick, const std::string& iq_id, const std::string& to_jid, const std::string& from_jid); + /** + * First check if the participant is in the room, before sending a direct + * CTCP PING request to the IRC user + */ + 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); /*** ** diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp index 5f76bd3..794b45b 100644 --- a/src/xmpp/xmpp_component.cpp +++ b/src/xmpp/xmpp_component.cpp @@ -563,6 +563,11 @@ void XmppComponent::handle_iq(const Stanza& stanza) bridge->send_irc_user_ping_request(iid.get_server(), iid.get_local(), id, from, to_str); } + else if (iid.is_channel && !to.resource.empty()) + { // Ping a room participant (we check if the nick is in the room) + bridge->send_irc_participant_ping_request(iid, + to.resource, id, from, to_str); + } stanza_error.disable(); } } |