M src/bridge/bridge.cpp => src/bridge/bridge.cpp +17 -16
@@ 1,4 1,5 @@
#include <bridge/bridge.hpp>
+#include <utility>
#include <xmpp/biboumi_component.hpp>
#include <network/poller.hpp>
#include <utils/empty_if_fixed_server.hpp>
@@ 29,8 30,8 @@ static std::string in_encoding_for(const Bridge& bridge, const Iid& iid)
#endif
}
-Bridge::Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr<Poller>& poller):
- user_jid(user_jid),
+Bridge::Bridge(std::string user_jid, BiboumiComponent& xmpp, std::shared_ptr<Poller>& poller):
+ user_jid(std::move(user_jid)),
xmpp(xmpp),
poller(poller)
{
@@ 59,10 60,10 @@ static std::tuple<std::string, std::string> get_role_affiliation_from_irc_mode(c
void Bridge::shutdown(const std::string& exit_message)
{
- for (auto it = this->irc_clients.begin(); it != this->irc_clients.end(); ++it)
+ for (auto& pair: this->irc_clients)
{
- it->second->send_quit_command(exit_message);
- it->second->leave_dummy_channel(exit_message, {});
+ pair.second->send_quit_command(exit_message);
+ pair.second->leave_dummy_channel(exit_message, {});
}
}
@@ 168,7 169,7 @@ IrcClient* Bridge::find_irc_client(const std::string& hostname) const
bool Bridge::join_irc_channel(const Iid& iid, const std::string& nickname, const std::string& password,
const std::string& resource)
{
- const auto hostname = iid.get_server();
+ const auto& hostname = iid.get_server();
this->cancel_linger_timer(hostname);
IrcClient* irc = this->make_irc_client(hostname, nickname);
this->add_resource_to_server(hostname, resource);
@@ 439,7 440,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con
#endif
if (channel->joined && !channel->parting && !persistent)
{
- const auto chan_name = iid.get_local();
+ const auto& chan_name = iid.get_local();
if (chan_name.empty())
irc->leave_dummy_channel(status_message, resource);
else
@@ 447,7 448,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con
}
else
{
- this->send_muc_leave(std::move(iid), std::move(nick), "", true, resource);
+ this->send_muc_leave(iid, std::move(nick), "", true, resource);
}
// Since there are no resources left in that channel, we don't
// want to receive private messages using this room's JID
@@ 456,7 457,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con
else
{
if (channel)
- this->send_muc_leave(std::move(iid), std::move(nick),
+ this->send_muc_leave(iid, std::move(nick),
"Biboumi note: "s + std::to_string(resources - 1) + " resources are still in this channel.",
true, resource);
this->remove_resource_from_chan(key, resource);
@@ 870,16 871,16 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick,
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(const Iid &iid, std::string&& nick, const std::string& message, const bool self,
const std::string& resource)
{
if (!resource.empty())
- this->xmpp.send_muc_leave(std::to_string(iid), std::move(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);
else
{
for (const auto &res: this->resources_in_chan[iid.to_tuple()])
- this->xmpp.send_muc_leave(std::to_string(iid), std::move(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);
if (self)
this->remove_all_resources_from_chan(iid.to_tuple());
@@ 1157,9 1158,9 @@ bool Bridge::is_resource_in_chan(const Bridge::ChannelKey& channel, const std::s
return false;
}
-void Bridge::remove_all_resources_from_chan(const Bridge::ChannelKey& channel_key)
+void Bridge::remove_all_resources_from_chan(const Bridge::ChannelKey& channel)
{
- this->resources_in_chan.erase(channel_key);
+ this->resources_in_chan.erase(channel);
}
void Bridge::add_resource_to_server(const Bridge::IrcHostname& irc_hostname, const std::string& resource)
@@ 1191,9 1192,9 @@ bool Bridge::is_resource_in_server(const Bridge::IrcHostname& irc_hostname, cons
return false;
}
-std::size_t Bridge::number_of_resources_in_chan(const Bridge::ChannelKey& channel_key) const
+std::size_t Bridge::number_of_resources_in_chan(const Bridge::ChannelKey& channel) const
{
- auto it = this->resources_in_chan.find(channel_key);
+ auto it = this->resources_in_chan.find(channel);
if (it == this->resources_in_chan.end())
return 0;
return it->second.size();
M src/bridge/bridge.hpp => src/bridge/bridge.hpp +7 -7
@@ 38,7 38,7 @@ using irc_responder_callback_t = std::function<bool(const std::string& irc_hostn
class Bridge
{
public:
- explicit Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr<Poller>& poller);
+ explicit Bridge(std::string user_jid, BiboumiComponent& xmpp, std::shared_ptr<Poller>& poller);
~Bridge() = default;
Bridge(const Bridge&) = delete;
@@ 169,7 169,7 @@ public:
/**
* Send an unavailable presence from this participant
*/
- void send_muc_leave(Iid&& iid, std::string&& nick, const std::string& message, const bool self, const std::string& resource="");
+ void send_muc_leave(const Iid& iid, std::string&& nick, const std::string& message, const bool self, const std::string& resource = "");
/**
* 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
@@ 309,11 309,11 @@ private:
/**
* Manage which resource is in which channel
*/
- void add_resource_to_chan(const ChannelKey& channel_key, const std::string& resource);
- void remove_resource_from_chan(const ChannelKey& channel_key, const std::string& resource);
- bool is_resource_in_chan(const ChannelKey& channel_key, const std::string& resource) const;
- void remove_all_resources_from_chan(const ChannelKey& channel_key);
- std::size_t number_of_resources_in_chan(const ChannelKey& channel_key) const;
+ void add_resource_to_chan(const ChannelKey& channel, const std::string& resource);
+ void remove_resource_from_chan(const ChannelKey& channel, const std::string& resource);
+ bool is_resource_in_chan(const ChannelKey& channel, const std::string& resource) const;
+ void remove_all_resources_from_chan(const ChannelKey& channel);
+ std::size_t number_of_resources_in_chan(const ChannelKey& channel) const;
void add_resource_to_server(const IrcHostname& irc_hostname, const std::string& resource);
void remove_resource_from_server(const IrcHostname& irc_hostname, const std::string& resource);
M src/bridge/colors.hpp => src/bridge/colors.hpp +1 -1
@@ 51,6 51,6 @@ static const char irc_format_char[] = {
* Returns the body cleaned from any IRC formatting (but without any xhtml),
* and the body as XHTML-IM
*/
-Xmpp::body irc_format_to_xhtmlim(const std::string& str);
+Xmpp::body irc_format_to_xhtmlim(const std::string& s);
M src/config/config.cpp => src/config/config.cpp +1 -1
@@ 37,7 37,7 @@ void Config::set(const std::string& option, const std::string& value, bool save)
}
}
-void Config::connect(t_config_changed_callback callback)
+void Config::connect(const t_config_changed_callback& callback)
{
Config::callbacks.push_back(callback);
}
M src/config/config.hpp => src/config/config.hpp +1 -1
@@ 54,7 54,7 @@ public:
* configuration change occurs (when set() is called, or when the initial
* conf is read)
*/
- static void connect(t_config_changed_callback);
+ static void connect(const t_config_changed_callback&);
/**
* Destroy the instance, forcing it to be recreated (with potentially
* different parameters) the next time it’s needed.
M src/database/database.cpp => src/database/database.cpp +1 -1
@@ 20,7 20,7 @@ void Database::open(const std::string& filename, const std::string& db_type)
"database="s + filename);
if (new_db->needsUpgrade())
new_db->upgrade();
- Database::db.reset(new_db.release());
+ Database::db = std::move(new_db);
} catch (const litesql::DatabaseError& e) {
log_error("Failed to open database ", filename, ". ", e.what());
throw;
M src/database/database.hpp => src/database/database.hpp +1 -1
@@ 49,7 49,7 @@ public:
const std::string& server,
const std::string& channel);
static std::vector<db::MucLogLine> get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
- int limit=-1, const std::string& before="", const std::string& after="");
+ int limit=-1, const std::string& start="", const std::string& end="");
static void store_muc_message(const std::string& owner, const Iid& iid,
time_point date, const std::string& body, const std::string& nick);
M src/irc/irc_client.cpp => src/irc/irc_client.cpp +3 -3
@@ 888,7 888,7 @@ void IrcClient::on_part(const IrcMessage& message)
// channel pointer is now invalid
channel = nullptr;
}
- this->bridge.send_muc_leave(std::move(iid), std::move(nick), std::move(txt), self);
+ this->bridge.send_muc_leave(iid, std::move(nick), std::move(txt), self);
}
}
@@ 906,7 906,7 @@ void IrcClient::on_error(const IrcMessage& message)
if (!channel->joined)
continue;
std::string own_nick = channel->get_self()->nick;
- this->bridge.send_muc_leave(std::move(iid), std::move(own_nick), leave_message, true);
+ this->bridge.send_muc_leave(iid, std::move(own_nick), leave_message, true);
}
this->channels.clear();
this->send_gateway_message("ERROR: "s + leave_message);
@@ 930,7 930,7 @@ void IrcClient::on_quit(const IrcMessage& message)
iid.set_local(chan_name);
iid.set_server(this->hostname);
iid.type = Iid::Type::Channel;
- this->bridge.send_muc_leave(std::move(iid), std::move(nick), txt, false);
+ this->bridge.send_muc_leave(iid, std::move(nick), txt, false);
}
}
}
M src/irc/irc_client.hpp => src/irc/irc_client.hpp +1 -1
@@ 52,7 52,7 @@ public:
/**
* Close the connection, remove us from the poller
*/
- void on_connection_close(const std::string& error) override final;
+ void on_connection_close(const std::string& error_msg) override final;
/**
* Parse the data we have received so far and try to get one or more
* complete messages from it.
M src/irc/irc_message.cpp => src/irc/irc_message.cpp +3 -3
@@ 8,12 8,12 @@ IrcMessage::IrcMessage(std::string&& line)
// optional prefix
if (line[0] == ':')
{
- pos = line.find(" ");
+ pos = line.find(' ');
this->prefix = line.substr(1, pos - 1);
line = line.substr(pos + 1, std::string::npos);
}
// command
- pos = line.find(" ");
+ pos = line.find(' ');
this->command = line.substr(0, pos);
line = line.substr(pos + 1, std::string::npos);
// arguments
@@ 24,7 24,7 @@ IrcMessage::IrcMessage(std::string&& line)
this->arguments.emplace_back(line.substr(1, std::string::npos));
break ;
}
- pos = line.find(" ");
+ pos = line.find(' ');
this->arguments.emplace_back(line.substr(0, pos));
line = line.substr(pos + 1, std::string::npos);
} while (pos != std::string::npos);
M src/irc/irc_user.cpp => src/irc/irc_user.cpp +1 -1
@@ 21,7 21,7 @@ IrcUser::IrcUser(const std::string& name,
name_begin++;
}
- const std::string::size_type sep = name.find("!", name_begin);
+ const std::string::size_type sep = name.find('!', name_begin);
if (sep == std::string::npos)
this->nick = name.substr(name_begin);
else
M src/irc/irc_user.hpp => src/irc/irc_user.hpp +1 -1
@@ 23,7 23,7 @@ public:
void add_mode(const char mode);
void remove_mode(const char mode);
- char get_most_significant_mode(const std::vector<char>& sorted_user_modes) const;
+ char get_most_significant_mode(const std::vector<char>& modes) const;
std::string nick;
std::string host;
M src/network/resolver.cpp => src/network/resolver.cpp +6 -7
@@ 1,7 1,7 @@
#include <network/dns_handler.hpp>
#include <utils/timed_events.hpp>
#include <network/resolver.hpp>
-#include <string.h>
+#include <cstring>
#include <arpa/inet.h>
#include <netinet/in.h>
#ifdef UDNS_FOUND
@@ 41,8 41,8 @@ Resolver::Resolver():
void Resolver::resolve(const std::string& hostname, const std::string& port,
SuccessCallbackType success_cb, ErrorCallbackType error_cb)
{
- this->error_cb = error_cb;
- this->success_cb = success_cb;
+ this->error_cb = std::move(error_cb);
+ this->success_cb = std::move(success_cb);
#ifdef UDNS_FOUND
this->port = port;
#endif
@@ 52,8 52,7 @@ void Resolver::resolve(const std::string& hostname, const std::string& port,
int Resolver::call_getaddrinfo(const char *name, const char* port, int flags)
{
- struct addrinfo hints;
- memset(&hints, 0, sizeof(struct addrinfo));
+ struct addrinfo hints{};
hints.ai_flags = flags;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
@@ 111,7 110,7 @@ void Resolver::start_resolving(const std::string& hostname, const std::string& p
// And finally, we try a DNS resolution
auto hostname6_resolved = [](dns_ctx*, dns_rr_a6* result, void* data)
{
- Resolver* resolver = static_cast<Resolver*>(data);
+ auto resolver = static_cast<Resolver*>(data);
resolver->on_hostname6_resolved(result);
resolver->after_resolved();
std::free(result);
@@ 119,7 118,7 @@ void Resolver::start_resolving(const std::string& hostname, const std::string& p
auto hostname4_resolved = [](dns_ctx*, dns_rr_a4* result, void* data)
{
- Resolver* resolver = static_cast<Resolver*>(data);
+ auto resolver = static_cast<Resolver*>(data);
resolver->on_hostname4_resolved(result);
resolver->after_resolved();
std::free(result);
M src/utils/encoding.hpp => src/utils/encoding.hpp +1 -1
@@ 28,7 28,7 @@ namespace utils
* Convert the given string (encoded is "encoding") into valid utf-8.
* If some decoding fails, insert an utf-8 placeholder character instead.
*/
- std::string convert_to_utf8(const std::string& str, const char* encoding);
+ std::string convert_to_utf8(const std::string& str, const char* charset);
}
namespace xep0106
M src/utils/time.cpp => src/utils/time.cpp +1 -1
@@ 1,5 1,5 @@
#include <utils/time.hpp>
-#include <time.h>
+#include <ctime>
#include <sstream>
#include <iomanip>
M src/xmpp/adhoc_command.hpp => src/xmpp/adhoc_command.hpp +1 -1
@@ 17,7 17,7 @@ class AdhocCommand
{
friend class AdhocSession;
public:
- AdhocCommand(std::vector<AdhocStep>&& callback, const std::string& name, const bool admin_only);
+ AdhocCommand(std::vector<AdhocStep>&& callbacks, const std::string& name, const bool admin_only);
~AdhocCommand() = default;
AdhocCommand(const AdhocCommand&) = default;
AdhocCommand(AdhocCommand&&) = default;
M src/xmpp/adhoc_session.cpp => src/xmpp/adhoc_session.cpp +1 -1
@@ 1,7 1,7 @@
#include <xmpp/adhoc_session.hpp>
#include <xmpp/adhoc_command.hpp>
-#include <assert.h>
+#include <cassert>
AdhocSession::AdhocSession(const AdhocCommand& command, const std::string& owner_jid,
const std::string& to_jid):
M src/xmpp/biboumi_adhoc_commands.cpp => src/xmpp/biboumi_adhoc_commands.cpp +7 -7
@@ 24,7 24,7 @@ using namespace std::string_literals;
void DisconnectUserStep1(XmppComponent& xmpp_component, AdhocSession&, XmlNode& command_node)
{
- auto& biboumi_component = static_cast<BiboumiComponent&>(xmpp_component);
+ auto& biboumi_component = dynamic_cast<BiboumiComponent&>(xmpp_component);
XmlSubNode x(command_node, "jabber:x:data:x");
x["type"] = "form";
@@ 55,7 55,7 @@ void DisconnectUserStep1(XmppComponent& xmpp_component, AdhocSession&, XmlNode&
void DisconnectUserStep2(XmppComponent& xmpp_component, AdhocSession& session, XmlNode& command_node)
{
- auto& biboumi_component = static_cast<BiboumiComponent&>(xmpp_component);
+ auto& biboumi_component = dynamic_cast<BiboumiComponent&>(xmpp_component);
// Find out if the jids, and the quit message are provided in the form.
std::string quit_message;
@@ 151,7 151,7 @@ void ConfigureGlobalStep1(XmppComponent&, AdhocSession& session, XmlNode& comman
void ConfigureGlobalStep2(XmppComponent& xmpp_component, AdhocSession& session, XmlNode& command_node)
{
- BiboumiComponent& biboumi_component = static_cast<BiboumiComponent&>(xmpp_component);
+ auto& biboumi_component = dynamic_cast<BiboumiComponent&>(xmpp_component);
const XmlNode* x = command_node.get_child("x", "jabber:x:data");
if (x)
@@ 533,7 533,7 @@ void DisconnectUserFromServerStep1(XmppComponent& xmpp_component, AdhocSession&
}
else
{ // Send a form to select the user to disconnect
- auto& biboumi_component = static_cast<BiboumiComponent&>(xmpp_component);
+ auto& biboumi_component = dynamic_cast<BiboumiComponent&>(xmpp_component);
XmlSubNode x(command_node, "jabber:x:data:x");
x["type"] = "form";
@@ 578,7 578,7 @@ void DisconnectUserFromServerStep2(XmppComponent& xmpp_component, AdhocSession&
// Send a data form to let the user choose which server to disconnect the
// user from
command_node.delete_all_children();
- auto& biboumi_component = static_cast<BiboumiComponent&>(xmpp_component);
+ auto& biboumi_component = dynamic_cast<BiboumiComponent&>(xmpp_component);
XmlSubNode x(command_node, "jabber:x:data:x");
x["type"] = "form";
@@ 643,7 643,7 @@ void DisconnectUserFromServerStep3(XmppComponent& xmpp_component, AdhocSession&
}
}
- auto& biboumi_component = static_cast<BiboumiComponent&>(xmpp_component);
+ auto& biboumi_component = dynamic_cast<BiboumiComponent&>(xmpp_component);
Bridge* bridge = biboumi_component.find_user_bridge(jid_to_disconnect);
auto& clients = bridge->get_irc_clients();
@@ 671,7 671,7 @@ void DisconnectUserFromServerStep3(XmppComponent& xmpp_component, AdhocSession&
void GetIrcConnectionInfoStep1(XmppComponent& component, AdhocSession& session, XmlNode& command_node)
{
- BiboumiComponent& biboumi_component = static_cast<BiboumiComponent&>(component);
+ auto& biboumi_component = dynamic_cast<BiboumiComponent&>(component);
const Jid owner(session.get_owner_jid());
const Jid target(session.get_target_jid());
M src/xmpp/biboumi_component.cpp => src/xmpp/biboumi_component.cpp +0 -2
@@ 422,7 422,6 @@ void BiboumiComponent::handle_iq(const Stanza& stanza)
}
else if (iid.type == Iid::Type::Channel)
{
- log_debug("type_channel");
if (node.empty())
{
this->send_irc_channel_disco_info(id, from, to_str);
@@ 763,7 762,6 @@ void BiboumiComponent::send_irc_channel_muc_traffic_info(const std::string& id,
void BiboumiComponent::send_irc_channel_disco_info(const std::string& id, const std::string& jid_to, const std::string& jid_from)
{
- log_debug("jid_from: ", jid_from);
Jid from(jid_from);
Iid iid(from.local, {});
Stanza iq("iq");
M src/xmpp/jid.cpp => src/xmpp/jid.cpp +1 -2
@@ 68,8 68,7 @@ std::string jidprep(const std::string& original)
// Using getaddrinfo, check if the domain part is a valid IPv4 (then use
// it as is), or IPv6 (surround it with []), or a domain name (run
// nameprep)
- struct addrinfo hints;
- memset(&hints, 0, sizeof(hints));
+ struct addrinfo hints{};
hints.ai_flags = AI_NUMERICHOST;
hints.ai_family = AF_UNSPEC;
M src/xmpp/xmpp_component.cpp => src/xmpp/xmpp_component.cpp +4 -4
@@ 39,14 39,14 @@ static std::set<std::string> kickable_errors{
"malformed-error"
};
-XmppComponent::XmppComponent(std::shared_ptr<Poller>& poller, const std::string& hostname, const std::string& secret):
+XmppComponent::XmppComponent(std::shared_ptr<Poller>& poller, std::string hostname, std::string secret):
TCPClientSocketHandler(poller),
ever_auth(false),
first_connection_try(true),
- secret(secret),
+ secret(std::move(secret)),
authenticated(false),
doc_open(false),
- served_hostname(hostname),
+ served_hostname(std::move(hostname)),
stanza_handlers{},
adhoc_commands_handler(*this)
{
@@ 429,7 429,7 @@ void XmppComponent::send_history_message(const std::string& muc_name, const std:
this->send_stanza(message);
}
-void XmppComponent::send_muc_leave(const std::string& muc_name, 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)
{
Stanza presence("presence");
{
M src/xmpp/xmpp_component.hpp => src/xmpp/xmpp_component.hpp +3 -3
@@ 43,7 43,7 @@
class XmppComponent: public TCPClientSocketHandler
{
public:
- explicit XmppComponent(std::shared_ptr<Poller>& poller, const std::string& hostname, const std::string& secret);
+ explicit XmppComponent(std::shared_ptr<Poller>& poller, std::string hostname, std::string secret);
virtual ~XmppComponent() = default;
XmppComponent(const XmppComponent&) = delete;
@@ 91,7 91,7 @@ public:
* stanza, and explanation being a short human-readable sentence
* describing the error.
*/
- void send_stream_error(const std::string& message, const std::string& explanation);
+ void send_stream_error(const std::string& name, const std::string& explanation);
/**
* Send error stanza, described in http://xmpp.org/rfcs/rfc6120.html#stanzas-error
*/
@@ 143,7 143,7 @@ public:
/**
* Send an unavailable presence for this nick
*/
- void send_muc_leave(const std::string& muc_name, 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);
/**
* Indicate that a participant changed his nick
*/