summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-05-22 12:54:18 +0200
committerlouiz’ <louiz@louiz.org>2016-06-08 01:42:43 +0200
commit711861d40e365564e3828a251066c16e924d30f3 (patch)
treef9501b71283afbdab0c06b4e9b4cc6cc8ec8ae03 /src
parent367de4826c3c7298a88e80c92e325081a3c3d794 (diff)
downloadbiboumi-711861d40e365564e3828a251066c16e924d30f3.tar.gz
biboumi-711861d40e365564e3828a251066c16e924d30f3.tar.bz2
biboumi-711861d40e365564e3828a251066c16e924d30f3.tar.xz
biboumi-711861d40e365564e3828a251066c16e924d30f3.zip
Add methods to know which resource is on which server or channel
Diffstat (limited to 'src')
-rw-r--r--src/bridge/bridge.cpp36
-rw-r--r--src/bridge/bridge.hpp11
-rw-r--r--src/xmpp/biboumi_component.cpp4
-rw-r--r--src/xmpp/biboumi_component.hpp4
4 files changed, 48 insertions, 7 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp
index 6008dfc..484c860 100644
--- a/src/bridge/bridge.cpp
+++ b/src/bridge/bridge.cpp
@@ -46,11 +46,12 @@ Bridge::Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_
}
/**
- * Return the role and affiliation, corresponding to the given irc mode */
+ * Return the role and affiliation, corresponding to the given irc mode
+ */
static std::tuple<std::string, std::string> get_role_affiliation_from_irc_mode(const char mode)
{
- if (mode == 'a' || mode == 'q')
- return std::make_tuple("moderator", "owner");
+ if (mode == 'a' || mode == 'q'){
+ return std::make_tuple("moderator", "owner");}
else if (mode == 'o')
return std::make_tuple("moderator", "admin");
else if (mode == 'h')
@@ -720,3 +721,32 @@ std::unordered_map<std::string, std::shared_ptr<IrcClient>>& Bridge::get_irc_cli
{
return this->irc_clients;
}
+
+void Bridge::add_resource_to_chan(const std::string& channel, const std::string& resource)
+{
+ auto it = this->resources_in_chan.find(channel);
+ if (it == this->resources_in_chan.end())
+ this->resources_in_chan[channel] = {resource};
+ else
+ it->second.insert(resource);
+}
+
+void Bridge::remove_resource_from_chan(const std::string& channel, const std::string& resource)
+{
+ auto it = this->resources_in_chan.find(channel);
+ if (it != this->resources_in_chan.end())
+ {
+ it->second.erase(resource);
+ if (it->second.empty())
+ this->resources_in_chan.erase(it);
+ }
+}
+
+bool Bridge::is_resource_in_chan(const std::string& channel, const std::string& resource) const
+{
+ auto it = this->resources_in_chan.find(channel);
+ if (it != this->resources_in_chan.end())
+ if (it->second.count(resource) == 1)
+ return true;
+ return false;
+}
diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp
index 2676d1d..b852a30 100644
--- a/src/bridge/bridge.hpp
+++ b/src/bridge/bridge.hpp
@@ -194,6 +194,13 @@ public:
void trigger_on_irc_message(const std::string& irc_hostname, const IrcMessage& message);
std::unordered_map<std::string, std::shared_ptr<IrcClient>>& get_irc_clients();
+ /**
+ * Manage which resource is in which channel
+ */
+ void add_resource_to_chan(const std::string& channel, const std::string& resource);
+ void remove_resource_from_chan(const std::string& channel, const std::string& resource);
+ bool is_resource_in_chan(const std::string& channel, const std::string& resource) const;
+
private:
/**
* Returns the client for the given hostname, create one (and use the
@@ -244,6 +251,10 @@ private:
* response iq.
*/
std::list<irc_responder_callback_t> waiting_irc;
+ /**
+ * Keep track of which resource is in which channel.
+ */
+ std::map<std::string, std::set<std::string>> resources_in_chan;
};
struct IRCNotConnected: public std::exception
diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp
index 94d85c6..6dae92c 100644
--- a/src/xmpp/biboumi_component.cpp
+++ b/src/xmpp/biboumi_component.cpp
@@ -519,9 +519,9 @@ Bridge* BiboumiComponent::get_user_bridge(const std::string& user_jid)
}
}
-Bridge* BiboumiComponent::find_user_bridge(const std::string& user_jid)
+Bridge* BiboumiComponent::find_user_bridge(const std::string& full_jid)
{
- auto bare_jid = Jid{user_jid}.bare();
+ auto bare_jid = Jid{full_jid}.bare();
try
{
return this->bridges.at(bare_jid).get();
diff --git a/src/xmpp/biboumi_component.hpp b/src/xmpp/biboumi_component.hpp
index 4d5995e..25982f2 100644
--- a/src/xmpp/biboumi_component.hpp
+++ b/src/xmpp/biboumi_component.hpp
@@ -35,7 +35,7 @@ public:
* Returns the bridge for the given user. If it does not exist, return
* nullptr.
*/
- Bridge* find_user_bridge(const std::string& user_jid);
+ Bridge* find_user_bridge(const std::string& full_jid);
/**
* Return a list of all the managed bridges.
*/
@@ -97,7 +97,7 @@ private:
std::map<std::string, iq_responder_callback_t> waiting_iq;
/**
- * One bridge for each user of the component. Indexed by the user's full
+ * One bridge for each user of the component. Indexed by the user's bare
* jid
*/
std::unordered_map<std::string, std::unique_ptr<Bridge>> bridges;