summaryrefslogtreecommitdiff
path: root/src/xmpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-09-18 21:55:21 +0200
committerFlorent Le Coz <louiz@louiz.org>2015-09-18 22:09:26 +0200
commit45e8fe56a688ec03201cdfc3dfea6ae186af682d (patch)
tree7b390546b414f077bec00219d60755d8a7a47c46 /src/xmpp
parent19666d2ffd3ce36b7edd4044143fe535ef85dbd9 (diff)
downloadbiboumi-45e8fe56a688ec03201cdfc3dfea6ae186af682d.tar.gz
biboumi-45e8fe56a688ec03201cdfc3dfea6ae186af682d.tar.bz2
biboumi-45e8fe56a688ec03201cdfc3dfea6ae186af682d.tar.xz
biboumi-45e8fe56a688ec03201cdfc3dfea6ae186af682d.zip
Add an AdhocCommandsHandler to store commands specific to IRC servers
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/biboumi_component.cpp39
-rw-r--r--src/xmpp/biboumi_component.hpp2
2 files changed, 34 insertions, 7 deletions
diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp
index 51775ab..974676b 100644
--- a/src/xmpp/biboumi_component.cpp
+++ b/src/xmpp/biboumi_component.cpp
@@ -41,7 +41,8 @@ static std::set<std::string> kickable_errors{
BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& secret):
- XmppComponent(poller, hostname, secret)
+ XmppComponent(poller, hostname, secret),
+ irc_server_adhoc_commands_handler(this)
{
this->stanza_handlers.emplace("presence",
std::bind(&BiboumiComponent::handle_presence, this,std::placeholders::_1));
@@ -313,9 +314,21 @@ void BiboumiComponent::handle_iq(const Stanza& stanza)
{
Stanza response("iq");
response["to"] = from;
- response["from"] = this->served_hostname;
+ response["from"] = to_str;
response["id"] = id;
- XmlNode inner_node = this->adhoc_commands_handler.handle_request(from, *query);
+
+ // Depending on the 'to' jid in the request, we use one adhoc
+ // command handler or an other
+ Iid iid(to.local);
+ AdhocCommandsHandler* adhoc_handler;
+ if (!to.local.empty() && !iid.is_user && !iid.is_channel)
+ adhoc_handler = &this->irc_server_adhoc_commands_handler;
+ else
+ adhoc_handler = &this->adhoc_commands_handler;
+
+ // Execute the command, if any, and get a result XmlNode that we
+ // insert in our response
+ XmlNode inner_node = adhoc_handler->handle_request(from, to_str, *query);
if (inner_node.get_child("error", ADHOC_NS))
response["type"] = "error";
else
@@ -370,10 +383,22 @@ void BiboumiComponent::handle_iq(const Stanza& stanza)
if (node == ADHOC_NS)
{
Jid from_jid(from);
- this->send_adhoc_commands_list(id, from,
- (Config::get("admin", "") ==
- from_jid.local + "@" + from_jid.domain));
- stanza_error.disable();
+ if (to.local.empty())
+ { // Get biboumi's adhoc commands
+ this->send_adhoc_commands_list(id, from, this->served_hostname,
+ (Config::get("admin", "") ==
+ from_jid.local + "@" + from_jid.domain),
+ this->adhoc_commands_handler);
+ stanza_error.disable();
+ }
+ else if (!iid.is_user && !iid.is_channel)
+ { // Get the server's adhoc commands
+ this->send_adhoc_commands_list(id, from, to_str,
+ (Config::get("admin", "") ==
+ from_jid.local + "@" + from_jid.domain),
+ this->irc_server_adhoc_commands_handler);
+ stanza_error.disable();
+ }
}
else if (node.empty() && !iid.is_user && !iid.is_channel)
{ // Disco on an IRC server: get the list of channels
diff --git a/src/xmpp/biboumi_component.hpp b/src/xmpp/biboumi_component.hpp
index 8b0b3da..fe99f2d 100644
--- a/src/xmpp/biboumi_component.hpp
+++ b/src/xmpp/biboumi_component.hpp
@@ -97,6 +97,8 @@ private:
*/
std::unordered_map<std::string, std::unique_ptr<Bridge>> bridges;
+ AdhocCommandsHandler irc_server_adhoc_commands_handler;
+
BiboumiComponent(const BiboumiComponent&) = delete;
BiboumiComponent(BiboumiComponent&&) = delete;
BiboumiComponent& operator=(const BiboumiComponent&) = delete;