diff options
author | Florent Le Coz <louiz@louiz.org> | 2015-02-26 05:02:08 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2015-02-26 05:02:08 +0100 |
commit | c01befb054075ab414fd602859e5999a138aa5bf (patch) | |
tree | 37e521b9f3cc678d2cc994e2ec5f39da6ef79232 /src/bridge | |
parent | 6a2240f5935a4608e651a33c39219e912c9ea9ba (diff) | |
download | biboumi-c01befb054075ab414fd602859e5999a138aa5bf.tar.gz biboumi-c01befb054075ab414fd602859e5999a138aa5bf.tar.bz2 biboumi-c01befb054075ab414fd602859e5999a138aa5bf.tar.xz biboumi-c01befb054075ab414fd602859e5999a138aa5bf.zip |
Implement room discovery using the LIST irc command
ref #2472
Diffstat (limited to 'src/bridge')
-rw-r--r-- | src/bridge/bridge.cpp | 38 | ||||
-rw-r--r-- | src/bridge/bridge.hpp | 2 | ||||
-rw-r--r-- | src/bridge/list_element.hpp | 19 |
3 files changed, 59 insertions, 0 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index fc00c8c..2e3520d 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1,5 +1,6 @@ #include <bridge/bridge.hpp> #include <bridge/colors.hpp> +#include <bridge/list_element.hpp> #include <xmpp/xmpp_component.hpp> #include <xmpp/xmpp_stanza.hpp> #include <irc/irc_message.hpp> @@ -285,6 +286,43 @@ void Bridge::send_irc_nick_change(const Iid& iid, const std::string& new_nick) irc->send_nick_command(new_nick); } +void Bridge::send_irc_channel_list_request(const Iid& iid, const std::string& iq_id, + const std::string& to_jid) +{ + IrcClient* irc = this->get_irc_client(iid.get_server()); + + if (!irc) + return; + + irc->send_list_command(); + irc_responder_callback_t cb = [this, iid, iq_id, to_jid](const std::string& irc_hostname, + const IrcMessage& message) -> bool + { + static std::vector<ListElement> list; + + if (irc_hostname != iid.get_server()) + return false; + if (message.command == "263" || message.command == "RPL_TRYAGAIN") + { // TODO send an error iq + return true; + } + else if (message.command == "322" || message.command == "RPL_LIST") + { // Add element to list + if (message.arguments.size() == 4) + list.emplace_back(message.arguments[1], message.arguments[2], + message.arguments[3]); + return false; + } + else if (message.command == "323" || message.command == "RPL_LISTEND") + { // Send the iq response with the content of the list + this->xmpp->send_iq_room_list_result(iq_id, to_jid, std::to_string(iid), list); + return true; + } + return false; + }; + this->add_waiting_irc(std::move(cb)); +} + void Bridge::send_irc_kick(const Iid& iid, const std::string& target, const std::string& reason, const std::string& iq_id, const std::string& to_jid) { diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index b1f79d5..8f71846 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -72,6 +72,8 @@ public: void 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); + void send_irc_channel_list_request(const Iid& iid, const std::string& iq_id, + const std::string& to_jid); void forward_affiliation_role_change(const Iid& iid, const std::string& nick, const std::string& affiliation, const std::string& role); /** diff --git a/src/bridge/list_element.hpp b/src/bridge/list_element.hpp new file mode 100644 index 0000000..bd28185 --- /dev/null +++ b/src/bridge/list_element.hpp @@ -0,0 +1,19 @@ +#ifndef LIST_ELEMENT_HPP_INCLUDED +#define LIST_ELEMENT_HPP_INCLUDED + +#include <string> + +struct ListElement +{ + ListElement(const std::string& channel, const std::string& nb_users, + const std::string& topic): + channel(channel), + nb_users(nb_users), + topic(topic){} + + std::string channel; + std::string nb_users; + std::string topic; +}; + +#endif /* LIST_ELEMENT_HPP_INCLUDED */ |