summaryrefslogtreecommitdiff
path: root/src/bridge
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-12-18 17:21:15 +0100
committerlouiz’ <louiz@louiz.org>2016-12-18 17:21:15 +0100
commite397fc837e00cff58081810c8b54cb741299d993 (patch)
treef9972ef543437187d35bc872e3e076b3782f717b /src/bridge
parent36a9eb0e000612e159b1550828bbcd446cd8b11b (diff)
downloadbiboumi-e397fc837e00cff58081810c8b54cb741299d993.tar.gz
biboumi-e397fc837e00cff58081810c8b54cb741299d993.tar.bz2
biboumi-e397fc837e00cff58081810c8b54cb741299d993.tar.xz
biboumi-e397fc837e00cff58081810c8b54cb741299d993.zip
Send iq error/result when the user changed a MODE command with an iq
And add tests for all the mode changes
Diffstat (limited to 'src/bridge')
-rw-r--r--src/bridge/bridge.cpp62
-rw-r--r--src/bridge/bridge.hpp4
2 files changed, 61 insertions, 5 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp
index 1841b95..16b1c68 100644
--- a/src/bridge/bridge.cpp
+++ b/src/bridge/bridge.cpp
@@ -263,9 +263,11 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
}
}
-void Bridge::forward_affiliation_role_change(const Iid& iid, const std::string& nick,
+void Bridge::forward_affiliation_role_change(const Iid& iid, const std::string& from,
+ const std::string& nick,
const std::string& affiliation,
- const std::string& role)
+ const std::string& role,
+ const std::string& id)
{
IrcClient* irc = this->get_irc_client(iid.get_server());
IrcChannel* chan = irc->get_channel(iid.get_local());
@@ -273,7 +275,11 @@ void Bridge::forward_affiliation_role_change(const Iid& iid, const std::string&
return;
IrcUser* user = chan->find_user(nick);
if (!user)
- return;
+ {
+ this->xmpp.send_stanza_error("iq", from, std::to_string(iid), id, "cancel",
+ "item-not-found", "no such nick", false);
+ return;
+ }
// For each affiliation or role, we have a “maximal” mode that we want to
// set. We must remove any superior mode at the same time. For example if
// the user already has +o mode, and we set its affiliation to member, we
@@ -325,6 +331,56 @@ void Bridge::forward_affiliation_role_change(const Iid& iid, const std::string&
std::vector<std::string> args(nb, nick);
args.insert(args.begin(), modes);
irc->send_mode_command(iid.get_local(), args);
+
+ irc_responder_callback_t cb = [this, iid, irc, id, from, nick](const std::string& irc_hostname, const IrcMessage& message) -> bool
+ {
+ if (irc_hostname != iid.get_server())
+ return false;
+
+ if (message.command == "MODE" && message.arguments.size() >= 2)
+ {
+ const std::string& chan_name = message.arguments[0];
+ if (chan_name != iid.get_local())
+ return false;
+ const std::string actor_nick = IrcUser{message.prefix}.nick;
+ if (!irc || irc->get_own_nick() != actor_nick)
+ return false;
+
+ this->xmpp.send_iq_result(id, from, std::to_string(iid));
+ }
+ else if (message.command == "401" && message.arguments.size() >= 2)
+ {
+ const std::string target_later = message.arguments[1];
+ if (target_later != nick)
+ return false;
+ std::string error_message = "No such nick";
+ if (message.arguments.size() >= 3)
+ error_message = message.arguments[2];
+ this->xmpp.send_stanza_error("iq", from, std::to_string(iid), id, "cancel", "item-not-found",
+ error_message, false);
+ }
+ else if (message.command == "482" && message.arguments.size() >= 2)
+ {
+ const std::string chan_name_later = utils::tolower(message.arguments[1]);
+ if (chan_name_later != iid.get_local())
+ return false;
+ std::string error_message = "You're not channel operator";
+ if (message.arguments.size() >= 3)
+ error_message = message.arguments[2];
+ this->xmpp.send_stanza_error("iq", from, std::to_string(iid), id, "cancel", "not-allowed",
+ error_message, false);
+ }
+ else if (message.command == "472" && message.arguments.size() >= 2)
+ {
+ std::string error_message = "Unknown mode: "s + message.arguments[1];
+ if (message.arguments.size() >= 3)
+ error_message = message.arguments[2];
+ this->xmpp.send_stanza_error("iq", from, std::to_string(iid), id, "cancel", "not-allowed",
+ error_message, false);
+ }
+ return true;
+ };
+ this->add_waiting_irc(std::move(cb));
}
void Bridge::send_private_message(const Iid& iid, const std::string& body, const std::string& type)
diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp
index e92747d..fc839b4 100644
--- a/src/bridge/bridge.hpp
+++ b/src/bridge/bridge.hpp
@@ -103,8 +103,8 @@ public:
bool send_matching_channel_list(const ChannelList& channel_list,
const ResultSetInfo& rs_info, const std::string& id, const std::string& to_jid,
const std::string& from);
- void forward_affiliation_role_change(const Iid& iid, const std::string& nick,
- const std::string& affiliation, const std::string& role);
+ void forward_affiliation_role_change(const Iid& iid, const std::string& from, const std::string& nick,
+ const std::string& affiliation, const std::string& role, const std::string& id);
/**
* Directly send a CTCP PING request to the IRC user
*/