Commit 9fa1852c authored by louiz’'s avatar louiz’

Send status code='332' on biboumi or IRC server’s shutdown

parent 3a95076d
...@@ -6,6 +6,8 @@ Version 6.0 ...@@ -6,6 +6,8 @@ Version 6.0
- The RecordHistory option can now also be configured for each IRC channel, - The RecordHistory option can now also be configured for each IRC channel,
individually. individually.
- Add a global option to make all channels persistent. - Add a global option to make all channels persistent.
- Status code='332' is sent with the unavailable presences when biboumi is
being shutdown or the connection to the IRC server is cut unexpectedly.
Version 5.0 - 2017-05-24 Version 5.0 - 2017-05-24
======================== ========================
......
...@@ -455,7 +455,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con ...@@ -455,7 +455,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con
} }
else if (channel->joined) else if (channel->joined)
{ {
this->send_muc_leave(iid, channel->get_self()->nick, "", true, resource); this->send_muc_leave(iid, channel->get_self()->nick, "", true, true, resource);
} }
// Since there are no resources left in that channel, we don't // Since there are no resources left in that channel, we don't
// want to receive private messages using this room's JID // want to receive private messages using this room's JID
...@@ -466,7 +466,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con ...@@ -466,7 +466,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con
if (channel && channel->joined) if (channel && channel->joined)
this->send_muc_leave(iid, channel->get_self()->nick, this->send_muc_leave(iid, channel->get_self()->nick,
"Biboumi note: " + std::to_string(resources - 1) + " resources are still in this channel.", "Biboumi note: " + std::to_string(resources - 1) + " resources are still in this channel.",
true, resource); true, true, resource);
this->remove_resource_from_chan(key, resource); this->remove_resource_from_chan(key, resource);
if (this->number_of_channels_the_resource_is_in(iid.get_server(), resource) == 0) if (this->number_of_channels_the_resource_is_in(iid.get_server(), resource) == 0)
this->remove_resource_from_server(iid.get_server(), resource); this->remove_resource_from_server(iid.get_server(), resource);
...@@ -883,16 +883,17 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick, ...@@ -883,16 +883,17 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick,
void Bridge::send_muc_leave(const Iid& iid, const std::string& nick, void Bridge::send_muc_leave(const Iid& iid, const std::string& nick,
const std::string& message, const bool self, const std::string& message, const bool self,
const bool user_requested,
const std::string& resource) const std::string& resource)
{ {
if (!resource.empty()) if (!resource.empty())
this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message), this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message),
this->user_jid + "/" + resource, self); this->user_jid + "/" + resource, self, user_requested);
else else
{ {
for (const auto &res: this->resources_in_chan[iid.to_tuple()]) for (const auto &res: this->resources_in_chan[iid.to_tuple()])
this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message), this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message),
this->user_jid + "/" + res, self); this->user_jid + "/" + res, self, user_requested);
if (self) if (self)
this->remove_all_resources_from_chan(iid.to_tuple()); this->remove_all_resources_from_chan(iid.to_tuple());
......
...@@ -169,7 +169,10 @@ public: ...@@ -169,7 +169,10 @@ public:
/** /**
* Send an unavailable presence from this participant * Send an unavailable presence from this participant
*/ */
void send_muc_leave(const Iid& iid, const std::string& nick, const std::string& message, const bool self, const std::string& resource = ""); void send_muc_leave(const Iid& iid, const std::string& nick,
const std::string& message, const bool self,
const bool user_requested,
const std::string& resource="");
/** /**
* Send presences to indicate that an user old_nick (ourself if self == * Send presences to indicate that an user old_nick (ourself if self ==
* true) changed his nick to new_nick. The user_mode is needed because * true) changed his nick to new_nick. The user_mode is needed because
......
...@@ -981,7 +981,7 @@ void IrcClient::on_part(const IrcMessage& message) ...@@ -981,7 +981,7 @@ void IrcClient::on_part(const IrcMessage& message)
// channel pointer is now invalid // channel pointer is now invalid
channel = nullptr; channel = nullptr;
} }
this->bridge.send_muc_leave(iid, std::move(nick), txt, self); this->bridge.send_muc_leave(iid, std::move(nick), txt, self, true);
} }
} }
...@@ -999,7 +999,7 @@ void IrcClient::on_error(const IrcMessage& message) ...@@ -999,7 +999,7 @@ void IrcClient::on_error(const IrcMessage& message)
if (!channel->joined) if (!channel->joined)
continue; continue;
std::string own_nick = channel->get_self()->nick; std::string own_nick = channel->get_self()->nick;
this->bridge.send_muc_leave(iid, std::move(own_nick), leave_message, true); this->bridge.send_muc_leave(iid, std::move(own_nick), leave_message, true, false);
} }
this->channels.clear(); this->channels.clear();
this->send_gateway_message("ERROR: " + leave_message); this->send_gateway_message("ERROR: " + leave_message);
...@@ -1026,7 +1026,7 @@ void IrcClient::on_quit(const IrcMessage& message) ...@@ -1026,7 +1026,7 @@ void IrcClient::on_quit(const IrcMessage& message)
iid.set_local(chan_name); iid.set_local(chan_name);
iid.set_server(this->hostname); iid.set_server(this->hostname);
iid.type = Iid::Type::Channel; iid.type = Iid::Type::Channel;
this->bridge.send_muc_leave(iid, std::move(nick), txt, self); this->bridge.send_muc_leave(iid, std::move(nick), txt, self, false);
} }
} }
} }
...@@ -1255,7 +1255,7 @@ void IrcClient::leave_dummy_channel(const std::string& exit_message, const std:: ...@@ -1255,7 +1255,7 @@ void IrcClient::leave_dummy_channel(const std::string& exit_message, const std::
this->dummy_channel.joined = false; this->dummy_channel.joined = false;
this->dummy_channel.joining = false; this->dummy_channel.joining = false;
this->dummy_channel.remove_all_users(); this->dummy_channel.remove_all_users();
this->bridge.send_muc_leave(Iid("%" + this->hostname, this->chantypes), std::string(this->current_nick), exit_message, true, resource); this->bridge.send_muc_leave(Iid("%" + this->hostname, this->chantypes), std::string(this->current_nick), exit_message, true, true, resource);
} }
#ifdef BOTAN_FOUND #ifdef BOTAN_FOUND
......
...@@ -441,7 +441,8 @@ void XmppComponent::send_history_message(const std::string& muc_name, const std: ...@@ -441,7 +441,8 @@ void XmppComponent::send_history_message(const std::string& muc_name, const std:
this->send_stanza(message); this->send_stanza(message);
} }
void XmppComponent::send_muc_leave(const std::string& muc_name, const std::string& nick, Xmpp::body&& message, const std::string& jid_to, const bool self) void XmppComponent::send_muc_leave(const std::string& muc_name, const std::string& nick, Xmpp::body&& message,
const std::string& jid_to, const bool self, const bool user_requested)
{ {
Stanza presence("presence"); Stanza presence("presence");
{ {
...@@ -456,6 +457,11 @@ void XmppComponent::send_muc_leave(const std::string& muc_name, const std::strin ...@@ -456,6 +457,11 @@ void XmppComponent::send_muc_leave(const std::string& muc_name, const std::strin
XmlSubNode status(x, "status"); XmlSubNode status(x, "status");
status["code"] = "110"; status["code"] = "110";
} }
if (!user_requested)
{
XmlSubNode status(x, "status");
status["code"] = "332";
}
if (!message_str.empty()) if (!message_str.empty())
{ {
XmlSubNode status(presence, "status"); XmlSubNode status(presence, "status");
......
...@@ -146,7 +146,12 @@ public: ...@@ -146,7 +146,12 @@ public:
/** /**
* Send an unavailable presence for this nick * Send an unavailable presence for this nick
*/ */
void send_muc_leave(const std::string& muc_name, const std::string& nick, Xmpp::body&& message, const std::string& jid_to, const bool self); void send_muc_leave(const std::string& muc_name,
const std::string& nick,
Xmpp::body&& message,
const std::string& jid_to,
const bool self,
const bool user_requested);
/** /**
* Indicate that a participant changed his nick * Indicate that a participant changed his nick
*/ */
......
...@@ -565,7 +565,7 @@ if __name__ == '__main__': ...@@ -565,7 +565,7 @@ if __name__ == '__main__':
), ),
partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"), partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"),
]), ]),
Scenario("quit_message", Scenario("quit",
[ [
handshake_sequence(), handshake_sequence(),
partial(send_stanza, partial(send_stanza,
...@@ -581,7 +581,8 @@ if __name__ == '__main__': ...@@ -581,7 +581,8 @@ if __name__ == '__main__':
# Send a raw QUIT message # Send a raw QUIT message
partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='{irc_server_one}' type='chat'><body>QUIT bye bye</body></message>"), partial(send_stanza, "<message from='{jid_one}/{resource_one}' to='{irc_server_one}' type='chat'><body>QUIT bye bye</body></message>"),
partial(expect_stanza, "/presence[@from='#foo%{irc_server_one}/{nick_one}'][@type='unavailable']/muc_user:x/muc_user:status[@code='110']"), partial(expect_stanza, ("/presence[@from='#foo%{irc_server_one}/{nick_one}'][@type='unavailable']/muc_user:x/muc_user:status[@code='110']",
"/presence[@from='#foo%{irc_server_one}/{nick_one}'][@type='unavailable']/muc_user:x/muc_user:status[@code='110']",)),
partial(expect_stanza, "/message[@from='{irc_server_one}']/body[text()='ERROR: Closing Link: localhost (Client Quit)']"), partial(expect_stanza, "/message[@from='{irc_server_one}']/body[text()='ERROR: Closing Link: localhost (Client Quit)']"),
partial(expect_stanza, "/message[@from='{irc_server_one}']/body[text()='ERROR: Connection closed.']"), partial(expect_stanza, "/message[@from='{irc_server_one}']/body[text()='ERROR: Connection closed.']"),
]), ]),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment