Commit 7e242714 authored by louiz’'s avatar louiz’

Use references instead of raw pointer, to store the “parent” object

In Bridge and IrcClient
parent 8ddbe8d3
...@@ -14,7 +14,7 @@ using namespace std::string_literals; ...@@ -14,7 +14,7 @@ using namespace std::string_literals;
static const char* action_prefix = "\01ACTION "; static const char* action_prefix = "\01ACTION ";
Bridge::Bridge(const std::string& user_jid, BiboumiComponent* xmpp, std::shared_ptr<Poller> poller): Bridge::Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr<Poller> poller):
user_jid(user_jid), user_jid(user_jid),
xmpp(xmpp), xmpp(xmpp),
poller(poller) poller(poller)
...@@ -105,7 +105,7 @@ IrcClient* Bridge::make_irc_client(const std::string& hostname, const std::strin ...@@ -105,7 +105,7 @@ IrcClient* Bridge::make_irc_client(const std::string& hostname, const std::strin
std::make_shared<IrcClient>(this->poller, hostname, std::make_shared<IrcClient>(this->poller, hostname,
nickname, username, nickname, username,
realname, jid.domain, realname, jid.domain,
this)); *this));
std::shared_ptr<IrcClient> irc = this->irc_clients.at(hostname); std::shared_ptr<IrcClient> irc = this->irc_clients.at(hostname);
return irc.get(); return irc.get();
} }
...@@ -172,7 +172,7 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body) ...@@ -172,7 +172,7 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
{ {
if (iid.get_server().empty()) if (iid.get_server().empty())
{ {
this->xmpp->send_stanza_error("message", this->user_jid, std::to_string(iid), "", this->xmpp.send_stanza_error("message", this->user_jid, std::to_string(iid), "",
"cancel", "remote-server-not-found", "cancel", "remote-server-not-found",
std::to_string(iid) + " is not a valid channel name. " std::to_string(iid) + " is not a valid channel name. "
"A correct room jid is of the form: #<chan>%<server>", "A correct room jid is of the form: #<chan>%<server>",
...@@ -205,7 +205,7 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body) ...@@ -205,7 +205,7 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
irc->send_channel_message(iid.get_local(), action_prefix + line.substr(4) + "\01"); irc->send_channel_message(iid.get_local(), action_prefix + line.substr(4) + "\01");
else else
irc->send_channel_message(iid.get_local(), line); irc->send_channel_message(iid.get_local(), line);
this->xmpp->send_muc_message(std::to_string(iid), irc->get_own_nick(), this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(),
this->make_xmpp_body(line), this->user_jid); this->make_xmpp_body(line), this->user_jid);
} }
} }
...@@ -278,7 +278,7 @@ void Bridge::send_private_message(const Iid& iid, const std::string& body, const ...@@ -278,7 +278,7 @@ void Bridge::send_private_message(const Iid& iid, const std::string& body, const
{ {
if (iid.get_local().empty() || iid.get_server().empty()) if (iid.get_local().empty() || iid.get_server().empty())
{ {
this->xmpp->send_stanza_error("message", this->user_jid, std::to_string(iid), "", this->xmpp.send_stanza_error("message", this->user_jid, std::to_string(iid), "",
"cancel", "remote-server-not-found", "cancel", "remote-server-not-found",
std::to_string(iid) + " is not a valid channel name. " std::to_string(iid) + " is not a valid channel name. "
"A correct room jid is of the form: #<chan>%<server>", "A correct room jid is of the form: #<chan>%<server>",
...@@ -336,7 +336,7 @@ void Bridge::send_irc_channel_list_request(const Iid& iid, const std::string& iq ...@@ -336,7 +336,7 @@ void Bridge::send_irc_channel_list_request(const Iid& iid, const std::string& iq
std::string text; std::string text;
if (message.arguments.size() >= 2) if (message.arguments.size() >= 2)
text = message.arguments[1]; text = message.arguments[1];
this->xmpp->send_stanza_error("iq", to_jid, std::to_string(iid), iq_id, this->xmpp.send_stanza_error("iq", to_jid, std::to_string(iid), iq_id,
"wait", "service-unavailable", text, false); "wait", "service-unavailable", text, false);
return true; return true;
} }
...@@ -349,7 +349,7 @@ void Bridge::send_irc_channel_list_request(const Iid& iid, const std::string& iq ...@@ -349,7 +349,7 @@ void Bridge::send_irc_channel_list_request(const Iid& iid, const std::string& iq
} }
else if (message.command == "323" || message.command == "RPL_LISTEND") else if (message.command == "323" || message.command == "RPL_LISTEND")
{ // Send the iq response with the content of the list { // 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); this->xmpp.send_iq_room_list_result(iq_id, to_jid, std::to_string(iid), list);
return true; return true;
} }
return false; return false;
...@@ -374,7 +374,7 @@ void Bridge::send_irc_kick(const Iid& iid, const std::string& target, const std: ...@@ -374,7 +374,7 @@ void Bridge::send_irc_kick(const Iid& iid, const std::string& target, const std:
const std::string chan_name_later = utils::tolower(message.arguments[0]); const std::string chan_name_later = utils::tolower(message.arguments[0]);
if (target_later != target || chan_name_later != iid.get_local()) if (target_later != target || chan_name_later != iid.get_local())
return false; return false;
this->xmpp->send_iq_result(iq_id, to_jid, std::to_string(iid)); this->xmpp.send_iq_result(iq_id, to_jid, std::to_string(iid));
} }
else if (message.command == "401" && message.arguments.size() >= 2) else if (message.command == "401" && message.arguments.size() >= 2)
{ {
...@@ -384,7 +384,7 @@ void Bridge::send_irc_kick(const Iid& iid, const std::string& target, const std: ...@@ -384,7 +384,7 @@ void Bridge::send_irc_kick(const Iid& iid, const std::string& target, const std:
std::string error_message = "No such nick"; std::string error_message = "No such nick";
if (message.arguments.size() >= 3) if (message.arguments.size() >= 3)
error_message = message.arguments[2]; error_message = message.arguments[2];
this->xmpp->send_stanza_error("iq", to_jid, std::to_string(iid), iq_id, "cancel", "item-not-found", this->xmpp.send_stanza_error("iq", to_jid, std::to_string(iid), iq_id, "cancel", "item-not-found",
error_message, false); error_message, false);
} }
else if (message.command == "482" && message.arguments.size() >= 2) else if (message.command == "482" && message.arguments.size() >= 2)
...@@ -395,7 +395,7 @@ void Bridge::send_irc_kick(const Iid& iid, const std::string& target, const std: ...@@ -395,7 +395,7 @@ void Bridge::send_irc_kick(const Iid& iid, const std::string& target, const std:
std::string error_message = "You're not channel operator"; std::string error_message = "You're not channel operator";
if (message.arguments.size() >= 3) if (message.arguments.size() >= 3)
error_message = message.arguments[2]; error_message = message.arguments[2];
this->xmpp->send_stanza_error("iq", to_jid, std::to_string(iid), iq_id, "cancel", "not-allowed", this->xmpp.send_stanza_error("iq", to_jid, std::to_string(iid), iq_id, "cancel", "not-allowed",
error_message, false); error_message, false);
} }
return true; return true;
...@@ -441,7 +441,7 @@ void Bridge::send_irc_user_ping_request(const std::string& irc_hostname, const s ...@@ -441,7 +441,7 @@ void Bridge::send_irc_user_ping_request(const std::string& irc_hostname, const s
if (id != iq_id) if (id != iq_id)
return false; return false;
Jid jid(from_jid); Jid jid(from_jid);
this->xmpp->send_iq_result(iq_id, to_jid, jid.local); this->xmpp.send_iq_result(iq_id, to_jid, jid.local);
return true; return true;
} }
if (message.command == "401" && message.arguments[1] == nick) if (message.command == "401" && message.arguments[1] == nick)
...@@ -449,7 +449,7 @@ void Bridge::send_irc_user_ping_request(const std::string& irc_hostname, const s ...@@ -449,7 +449,7 @@ void Bridge::send_irc_user_ping_request(const std::string& irc_hostname, const s
std::string error_message = "No such nick"; std::string error_message = "No such nick";
if (message.arguments.size() >= 3) if (message.arguments.size() >= 3)
error_message = message.arguments[2]; error_message = message.arguments[2];
this->xmpp->send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "service-unavailable", this->xmpp.send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "service-unavailable",
error_message, true); error_message, true);
return true; return true;
} }
...@@ -467,13 +467,13 @@ void Bridge::send_irc_participant_ping_request(const Iid& iid, const std::string ...@@ -467,13 +467,13 @@ void Bridge::send_irc_participant_ping_request(const Iid& iid, const std::string
IrcChannel* chan = irc->get_channel(iid.get_local()); IrcChannel* chan = irc->get_channel(iid.get_local());
if (!chan->joined) if (!chan->joined)
{ {
this->xmpp->send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "not-allowed", this->xmpp.send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "not-allowed",
"", true); "", true);
return; return;
} }
if (chan->get_self()->nick != nick && !chan->find_user(nick)) if (chan->get_self()->nick != nick && !chan->find_user(nick))
{ {
this->xmpp->send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "item-not-found", this->xmpp.send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "item-not-found",
"Recipient not in room", true); "Recipient not in room", true);
return; return;
} }
...@@ -487,9 +487,9 @@ void Bridge::on_gateway_ping(const std::string& irc_hostname, const std::string& ...@@ -487,9 +487,9 @@ void Bridge::on_gateway_ping(const std::string& irc_hostname, const std::string&
{ {
Jid jid(from_jid); Jid jid(from_jid);
if (irc_hostname.empty() || this->find_irc_client(irc_hostname)) if (irc_hostname.empty() || this->find_irc_client(irc_hostname))
this->xmpp->send_iq_result(iq_id, to_jid, jid.local); this->xmpp.send_iq_result(iq_id, to_jid, jid.local);
else else
this->xmpp->send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "service-unavailable", this->xmpp.send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "service-unavailable",
"", true); "", true);
} }
...@@ -511,7 +511,7 @@ void Bridge::send_irc_version_request(const std::string& irc_hostname, const std ...@@ -511,7 +511,7 @@ void Bridge::send_irc_version_request(const std::string& irc_hostname, const std
{ {
// remove the "\01VERSION " and the "\01" parts from the string // remove the "\01VERSION " and the "\01" parts from the string
const std::string version = message.arguments[1].substr(9, message.arguments[1].size() - 10); const std::string version = message.arguments[1].substr(9, message.arguments[1].size() - 10);
this->xmpp->send_version(iq_id, to_jid, from_jid, version); this->xmpp.send_version(iq_id, to_jid, from_jid, version);
return true; return true;
} }
if (message.command == "401" && message.arguments.size() >= 2 if (message.command == "401" && message.arguments.size() >= 2
...@@ -520,7 +520,7 @@ void Bridge::send_irc_version_request(const std::string& irc_hostname, const std ...@@ -520,7 +520,7 @@ void Bridge::send_irc_version_request(const std::string& irc_hostname, const std
std::string error_message = "No such nick"; std::string error_message = "No such nick";
if (message.arguments.size() >= 3) if (message.arguments.size() >= 3)
error_message = message.arguments[2]; error_message = message.arguments[2];
this->xmpp->send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "item-not-found", this->xmpp.send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "item-not-found",
error_message, true); error_message, true);
return true; return true;
} }
...@@ -532,7 +532,7 @@ void Bridge::send_irc_version_request(const std::string& irc_hostname, const std ...@@ -532,7 +532,7 @@ void Bridge::send_irc_version_request(const std::string& irc_hostname, const std
void Bridge::send_message(const Iid& iid, const std::string& nick, const std::string& body, const bool muc) void Bridge::send_message(const Iid& iid, const std::string& nick, const std::string& body, const bool muc)
{ {
if (muc) if (muc)
this->xmpp->send_muc_message(std::to_string(iid), nick, this->xmpp.send_muc_message(std::to_string(iid), nick,
this->make_xmpp_body(body), this->user_jid); this->make_xmpp_body(body), this->user_jid);
else else
{ {
...@@ -544,7 +544,7 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st ...@@ -544,7 +544,7 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st
target = it->second; target = it->second;
fulljid = true; fulljid = true;
} }
this->xmpp->send_message(target, this->make_xmpp_body(body), this->xmpp.send_message(target, this->make_xmpp_body(body),
this->user_jid, "chat", fulljid); this->user_jid, "chat", fulljid);
} }
} }
...@@ -553,12 +553,12 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick, ...@@ -553,12 +553,12 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick,
const std::string& type, const std::string& condition, const std::string& type, const std::string& condition,
const std::string& error_code, const std::string& text) const std::string& error_code, const std::string& text)
{ {
this->xmpp->send_presence_error(std::to_string(iid), nick, this->user_jid, type, condition, error_code, text); this->xmpp.send_presence_error(std::to_string(iid), nick, this->user_jid, type, condition, error_code, text);
} }
void Bridge::send_muc_leave(Iid&& iid, std::string&& nick, const std::string& message, const bool self) void Bridge::send_muc_leave(Iid&& iid, std::string&& nick, const std::string& message, const bool self)
{ {
this->xmpp->send_muc_leave(std::to_string(iid), std::move(nick), this->make_xmpp_body(message), this->user_jid, self); this->xmpp.send_muc_leave(std::to_string(iid), std::move(nick), this->make_xmpp_body(message), this->user_jid, self);
IrcClient* irc = this->find_irc_client(iid.get_server()); IrcClient* irc = this->find_irc_client(iid.get_server());
if (irc && irc->number_of_joined_channels() == 0) if (irc && irc->number_of_joined_channels() == 0)
irc->send_quit_command(""); irc->send_quit_command("");
...@@ -574,7 +574,7 @@ void Bridge::send_nick_change(Iid&& iid, ...@@ -574,7 +574,7 @@ void Bridge::send_nick_change(Iid&& iid,
std::string role; std::string role;
std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(user_mode); std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(user_mode);
this->xmpp->send_nick_change(std::to_string(iid), this->xmpp.send_nick_change(std::to_string(iid),
old_nick, new_nick, affiliation, role, this->user_jid, self); old_nick, new_nick, affiliation, role, this->user_jid, self);
} }
...@@ -590,7 +590,7 @@ void Bridge::send_xmpp_message(const std::string& from, const std::string& autho ...@@ -590,7 +590,7 @@ void Bridge::send_xmpp_message(const std::string& from, const std::string& autho
} }
else else
body = msg; body = msg;
this->xmpp->send_message(from, this->make_xmpp_body(body), this->user_jid, "chat"); this->xmpp.send_message(from, this->make_xmpp_body(body), this->user_jid, "chat");
} }
void Bridge::send_user_join(const std::string& hostname, void Bridge::send_user_join(const std::string& hostname,
...@@ -603,13 +603,13 @@ void Bridge::send_user_join(const std::string& hostname, ...@@ -603,13 +603,13 @@ void Bridge::send_user_join(const std::string& hostname,
std::string role; std::string role;
std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(user_mode); std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(user_mode);
this->xmpp->send_user_join(chan_name + utils::empty_if_fixed_server("%" + hostname), user->nick, user->host, this->xmpp.send_user_join(chan_name + utils::empty_if_fixed_server("%" + hostname), user->nick, user->host,
affiliation, role, this->user_jid, self); affiliation, role, this->user_jid, self);
} }
void Bridge::send_topic(const std::string& hostname, const std::string& chan_name, const std::string& topic) void Bridge::send_topic(const std::string& hostname, const std::string& chan_name, const std::string& topic)
{ {
this->xmpp->send_topic(chan_name + utils::empty_if_fixed_server("%" + hostname), this->make_xmpp_body(topic), this->user_jid); this->xmpp.send_topic(chan_name + utils::empty_if_fixed_server("%" + hostname), this->make_xmpp_body(topic), this->user_jid);
} }
std::string Bridge::get_own_nick(const Iid& iid) std::string Bridge::get_own_nick(const Iid& iid)
...@@ -627,12 +627,12 @@ size_t Bridge::active_clients() const ...@@ -627,12 +627,12 @@ size_t Bridge::active_clients() const
void Bridge::kick_muc_user(Iid&& iid, const std::string& target, const std::string& reason, const std::string& author) void Bridge::kick_muc_user(Iid&& iid, const std::string& target, const std::string& reason, const std::string& author)
{ {
this->xmpp->kick_user(std::to_string(iid), target, reason, author, this->user_jid); this->xmpp.kick_user(std::to_string(iid), target, reason, author, this->user_jid);
} }
void Bridge::send_nickname_conflict_error(const Iid& iid, const std::string& nickname) void Bridge::send_nickname_conflict_error(const Iid& iid, const std::string& nickname)
{ {
this->xmpp->send_presence_error(std::to_string(iid), nickname, this->user_jid, "cancel", "conflict", "409", ""); this->xmpp.send_presence_error(std::to_string(iid), nickname, this->user_jid, "cancel", "conflict", "409", "");
} }
void Bridge::send_affiliation_role_change(const Iid& iid, const std::string& target, const char mode) void Bridge::send_affiliation_role_change(const Iid& iid, const std::string& target, const char mode)
...@@ -641,12 +641,12 @@ void Bridge::send_affiliation_role_change(const Iid& iid, const std::string& tar ...@@ -641,12 +641,12 @@ void Bridge::send_affiliation_role_change(const Iid& iid, const std::string& tar
std::string affiliation; std::string affiliation;
std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(mode); std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(mode);
this->xmpp->send_affiliation_role_change(std::to_string(iid), target, affiliation, role, this->user_jid); this->xmpp.send_affiliation_role_change(std::to_string(iid), target, affiliation, role, this->user_jid);
} }
void Bridge::send_iq_version_request(const std::string& nick, const std::string& hostname) void Bridge::send_iq_version_request(const std::string& nick, const std::string& hostname)
{ {
this->xmpp->send_iq_version_request(nick + "!" + utils::empty_if_fixed_server(hostname), this->user_jid); this->xmpp.send_iq_version_request(nick + "!" + utils::empty_if_fixed_server(hostname), this->user_jid);
} }
void Bridge::send_xmpp_ping_request(const std::string& nick, const std::string& hostname, void Bridge::send_xmpp_ping_request(const std::string& nick, const std::string& hostname,
...@@ -655,7 +655,7 @@ void Bridge::send_xmpp_ping_request(const std::string& nick, const std::string& ...@@ -655,7 +655,7 @@ void Bridge::send_xmpp_ping_request(const std::string& nick, const std::string&
// Use revstr because the forwarded ping to target XMPP user must not be // Use revstr because the forwarded ping to target XMPP user must not be
// the same that the request iq, but we also need to get it back easily // the same that the request iq, but we also need to get it back easily
// (revstr again) // (revstr again)
this->xmpp->send_ping_request(nick + "!" + utils::empty_if_fixed_server(hostname), this->user_jid, utils::revstr(id)); this->xmpp.send_ping_request(nick + "!" + utils::empty_if_fixed_server(hostname), this->user_jid, utils::revstr(id));
} }
void Bridge::set_preferred_from_jid(const std::string& nick, const std::string& full_jid) void Bridge::set_preferred_from_jid(const std::string& nick, const std::string& full_jid)
......
...@@ -33,7 +33,7 @@ using irc_responder_callback_t = std::function<bool(const std::string& irc_hostn ...@@ -33,7 +33,7 @@ using irc_responder_callback_t = std::function<bool(const std::string& irc_hostn
class Bridge class Bridge
{ {
public: public:
explicit Bridge(const std::string& user_jid, BiboumiComponent* xmpp, std::shared_ptr<Poller> poller); explicit Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr<Poller> poller);
~Bridge(); ~Bridge();
/** /**
* QUIT all connected IRC servers. * QUIT all connected IRC servers.
...@@ -216,11 +216,9 @@ private: ...@@ -216,11 +216,9 @@ private:
*/ */
std::unordered_map<std::string, std::shared_ptr<IrcClient>> irc_clients; std::unordered_map<std::string, std::shared_ptr<IrcClient>> irc_clients;
/** /**
* A raw pointer, because we do not own it, the XMPP component owns us, * To communicate back with the XMPP component
* but we still need to communicate with it, when sending messages from
* IRC to XMPP.
*/ */
BiboumiComponent* xmpp; BiboumiComponent& xmpp;
/** /**
* Poller, to give it the IrcClients that we spawn, to make it manage * Poller, to give it the IrcClients that we spawn, to make it manage
* their sockets. * their sockets.
......
...@@ -27,7 +27,7 @@ using namespace std::chrono_literals; ...@@ -27,7 +27,7 @@ using namespace std::chrono_literals;
IrcClient::IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname, IrcClient::IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname,
const std::string& nickname, const std::string& username, const std::string& nickname, const std::string& username,
const std::string& realname, const std::string& user_hostname, const std::string& realname, const std::string& user_hostname,
Bridge* bridge): Bridge& bridge):
TCPSocketHandler(poller), TCPSocketHandler(poller),
hostname(hostname), hostname(hostname),
user_hostname(user_hostname), user_hostname(user_hostname),
...@@ -48,7 +48,7 @@ IrcClient::IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname ...@@ -48,7 +48,7 @@ IrcClient::IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname
"To disconnect from the IRC server, leave this room and all " "To disconnect from the IRC server, leave this room and all "
"other IRC channels of that server."; "other IRC channels of that server.";
#ifdef USE_DATABASE #ifdef USE_DATABASE
auto options = Database::get_irc_server_options(this->bridge->get_bare_jid(), auto options = Database::get_irc_server_options(this->bridge.get_bare_jid(),
this->get_hostname()); this->get_hostname());
std::vector<std::string> ports = utils::split(options.ports, ';', false); std::vector<std::string> ports = utils::split(options.ports, ';', false);
for (auto it = ports.rbegin(); it != ports.rend(); ++it) for (auto it = ports.rbegin(); it != ports.rend(); ++it)
...@@ -72,7 +72,7 @@ IrcClient::~IrcClient() ...@@ -72,7 +72,7 @@ IrcClient::~IrcClient()
{ {
// This event may or may not exist (if we never got connected, it // This event may or may not exist (if we never got connected, it
// doesn't), but it's ok // doesn't), but it's ok
TimedEventsManager::instance().cancel("PING"s + this->hostname + this->bridge->get_jid()); TimedEventsManager::instance().cancel("PING"s + this->hostname + this->bridge.get_jid());
} }
void IrcClient::start() void IrcClient::start()
...@@ -83,7 +83,7 @@ void IrcClient::start() ...@@ -83,7 +83,7 @@ void IrcClient::start()
bool tls; bool tls;
std::tie(port, tls) = this->ports_to_try.top(); std::tie(port, tls) = this->ports_to_try.top();
this->ports_to_try.pop(); this->ports_to_try.pop();
this->bridge->send_xmpp_message(this->hostname, "", "Connecting to "s + this->bridge.send_xmpp_message(this->hostname, "", "Connecting to "s +
this->hostname + ":" + port + " (" + this->hostname + ":" + port + " (" +
(tls ? "encrypted" : "not encrypted") + ")"); (tls ? "encrypted" : "not encrypted") + ")");
...@@ -94,7 +94,7 @@ void IrcClient::start() ...@@ -94,7 +94,7 @@ void IrcClient::start()
void IrcClient::on_connection_failed(const std::string& reason) void IrcClient::on_connection_failed(const std::string& reason)
{ {
this->bridge->send_xmpp_message(this->hostname, "", this->bridge.send_xmpp_message(this->hostname, "",
"Connection failed: "s + reason); "Connection failed: "s + reason);
if (this->hostname_resolution_failed) if (this->hostname_resolution_failed)
...@@ -107,7 +107,7 @@ void IrcClient::on_connection_failed(const std::string& reason) ...@@ -107,7 +107,7 @@ void IrcClient::on_connection_failed(const std::string& reason)
for (const auto& tuple: this->channels_to_join) for (const auto& tuple: this->channels_to_join)
{ {
Iid iid(std::get<0>(tuple) + "%" + this->hostname); Iid iid(std::get<0>(tuple) + "%" + this->hostname);
this->bridge->send_presence_error(iid, this->current_nick, this->bridge.send_presence_error(iid, this->current_nick,
"cancel", "item-not-found", "cancel", "item-not-found",
"", reason); "", reason);
} }
...@@ -152,7 +152,7 @@ void IrcClient::on_connected() ...@@ -152,7 +152,7 @@ void IrcClient::on_connected()
} }
#ifdef USE_DATABASE #ifdef USE_DATABASE
auto options = Database::get_irc_server_options(this->bridge->get_bare_jid(), auto options = Database::get_irc_server_options(this->bridge.get_bare_jid(),
this->get_hostname()); this->get_hostname());
if (!options.pass.value().empty()) if (!options.pass.value().empty())
this->send_pass_command(options.pass.value()); this->send_pass_command(options.pass.value());
...@@ -258,7 +258,7 @@ void IrcClient::parse_in_buffer(const size_t) ...@@ -258,7 +258,7 @@ void IrcClient::parse_in_buffer(const size_t)
this->on_unknown_message(message); this->on_unknown_message(message);
} }
// Try to find a waiting_iq, which response will be triggered by this IrcMessage // Try to find a waiting_iq, which response will be triggered by this IrcMessage
this->bridge->trigger_on_irc_message(this->hostname, message); this->bridge.trigger_on_irc_message(this->hostname, message);
} }
} }
...@@ -413,7 +413,7 @@ void IrcClient::forward_server_message(const IrcMessage& message) ...@@ -413,7 +413,7 @@ void IrcClient::forward_server_message(const IrcMessage& message)
const std::string from = message.prefix; const std::string from = message.prefix;
const std::string body = message.arguments[1]; const std::string body = message.arguments[1];
this->bridge->send_xmpp_message(this->hostname, from, body); this->bridge.send_xmpp_message(this->hostname, from, body);
} }
void IrcClient::on_notice(const IrcMessage& message) void IrcClient::on_notice(const IrcMessage& message)
...@@ -438,11 +438,11 @@ void IrcClient::on_notice(const IrcMessage& message) ...@@ -438,11 +438,11 @@ void IrcClient::on_notice(const IrcMessage& message)
if (this->nicks_to_treat_as_private.find(nick) != if (this->nicks_to_treat_as_private.find(nick) !=
this->nicks_to_treat_as_private.end()) this->nicks_to_treat_as_private.end())
{ // We previously sent a message to that nick) { // We previously sent a message to that nick)
this->bridge->send_message({nick + "!" + this->hostname}, nick, body, this->bridge.send_message({nick + "!" + this->hostname}, nick, body,
false); false);
} }
else else
this->bridge->send_xmpp_message(this->hostname, from, body); this->bridge.send_xmpp_message(this->hostname, from, body);
} }
else else
{ {
...@@ -494,7 +494,7 @@ void IrcClient::on_isupport_message(const IrcMessage& message) ...@@ -494,7 +494,7 @@ void IrcClient::on_isupport_message(const IrcMessage& message)
void IrcClient::send_gateway_message(const std::string& message, const std::string& from) void IrcClient::send_gateway_message(const std::string& message, const std::string& from)
{ {
this->bridge->send_xmpp_message(this->hostname, from, message); this->bridge.send_xmpp_message(this->hostname, from, message);
} }
void IrcClient::set_and_forward_user_list(const IrcMessage& message) void IrcClient::set_and_forward_user_list(const IrcMessage& message)
...@@ -507,7 +507,7 @@ void IrcClient::set_and_forward_user_list(const IrcMessage& message) ...@@ -507,7 +507,7 @@ void IrcClient::set_and_forward_user_list(const IrcMessage& message)
const IrcUser* user = channel->add_user(nick, this->prefix_to_mode); const IrcUser* user = channel->add_user(nick, this->prefix_to_mode);
if (user->nick != channel->get_self()->nick) if (user->nick != channel->get_self()->nick)
{ {
this->bridge->send_user_join(this->hostname, chan_name, user, this->bridge.send_user_join(this->hostname, chan_name, user,
user->get_most_significant_mode(this->sorted_user_modes), user->get_most_significant_mode(this->sorted_user_modes),
false); false);
} }
...@@ -533,7 +533,7 @@ void IrcClient::on_channel_join(const IrcMessage& message) ...@@ -533,7 +533,7 @@ void IrcClient::on_channel_join(const IrcMessage& message)
else else
{ {
const IrcUser* user = channel->add_user(nick, this->prefix_to_mode); const IrcUser* user = channel->add_user(nick, this->prefix_to_mode);
this->bridge->send_user_join(this->hostname, chan_name, user, this->bridge.send_user_join(this->hostname, chan_name, user,
user->get_most_significant_mode(this->sorted_user_modes), user->get_most_significant_mode(this->sorted_user_modes),
false); false);
} }
...@@ -559,16 +559,16 @@ void IrcClient::on_channel_message(const IrcMessage& message) ...@@ -559,16 +559,16 @@ void IrcClient::on_channel_message(const IrcMessage& message)
if (!body.empty() && body[0] == '\01') if (!body.empty() && body[0] == '\01')
{ {
if (body.substr(1, 6) == "ACTION") if (body.substr(1, 6) == "ACTION")
this->bridge->send_message(iid, nick, this->bridge.send_message(iid, nick,
"/me"s + body.substr(7, body.size() - 8), muc); "/me"s + body.substr(7, body.size() - 8), muc);
else if (body.substr(1, 8) == "VERSION\01") else if (body.substr(1, 8) == "VERSION\01")
this->bridge->send_iq_version_request(nick, this->hostname); this->bridge.send_iq_version_request(nick, this->hostname);
else if (body.substr(1, 5) == "PING ") else if (body.substr(1, 5) == "PING ")
this->bridge->send_xmpp_ping_request(utils::tolower(nick), this->hostname,