Commit 5402a256 authored by louiz’'s avatar louiz’

Apply all the clang-tidy modernize-* fixes

parent dd4c54c6
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <string.h> #include <cstring>
using namespace std::string_literals; using namespace std::string_literals;
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include <network/socket_handler.hpp> #include <network/socket_handler.hpp>
#include <cassert>
#include <network/tcp_socket_handler.hpp> #include <network/tcp_socket_handler.hpp>
#include <logger/logger.hpp> #include <logger/logger.hpp>
......
#include <utility>
#include <utils/tolower.hpp> #include <utils/tolower.hpp>
#include <config/config.hpp> #include <config/config.hpp>
#include <bridge/bridge.hpp> #include <bridge/bridge.hpp>
...@@ -7,10 +8,10 @@ ...@@ -7,10 +8,10 @@
constexpr char Iid::separator[]; constexpr char Iid::separator[];
Iid::Iid(const std::string& local, const std::string& server, Iid::Type type): Iid::Iid(std::string local, std::string server, Iid::Type type):
type(type), type(std::move(type)),
local(local), local(std::move(local)),
server(server) server(std::move(server))
{ {
} }
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
Iid(const std::string& iid, const std::set<char>& chantypes); Iid(const std::string& iid, const std::set<char>& chantypes);
Iid(const std::string& iid, const std::initializer_list<char>& chantypes); Iid(const std::string& iid, const std::initializer_list<char>& chantypes);
Iid(const std::string& iid, const Bridge* bridge); Iid(const std::string& iid, const Bridge* bridge);
Iid(const std::string& local, const std::string& server, Type type); Iid(std::string local, std::string server, Type type);
Iid() = default; Iid() = default;
Iid(const Iid&) = default; Iid(const Iid&) = default;
......
#include <utility>
#include <utils/timed_events.hpp> #include <utils/timed_events.hpp>
#include <database/database.hpp> #include <database/database.hpp>
#include <irc/irc_message.hpp> #include <irc/irc_message.hpp>
...@@ -127,16 +128,16 @@ static const std::unordered_map<std::string, ...@@ -127,16 +128,16 @@ static const std::unordered_map<std::string,
{"502", {&IrcClient::on_generic_error, {2, 0}}}, {"502", {&IrcClient::on_generic_error, {2, 0}}},
}; };
IrcClient::IrcClient(std::shared_ptr<Poller>& poller, const std::string& hostname, IrcClient::IrcClient(std::shared_ptr<Poller>& poller, std::string hostname,
const std::string& nickname, const std::string& username, std::string nickname, std::string username,
const std::string& realname, const std::string& user_hostname, std::string realname, std::string user_hostname,
Bridge& bridge): Bridge& bridge):
TCPClientSocketHandler(poller), TCPClientSocketHandler(poller),
hostname(hostname), hostname(std::move(hostname)),
user_hostname(user_hostname), user_hostname(std::move(user_hostname)),
username(username), username(std::move(username)),
realname(realname), realname(std::move(realname)),
current_nick(nickname), current_nick(std::move(nickname)),
bridge(bridge), bridge(bridge),
welcomed(false), welcomed(false),
chanmodes({"", "", "", ""}), chanmodes({"", "", "", ""}),
...@@ -791,10 +792,10 @@ void IrcClient::on_nickname_conflict(const IrcMessage& message) ...@@ -791,10 +792,10 @@ void IrcClient::on_nickname_conflict(const IrcMessage& message)
{ {
const std::string nickname = message.arguments[1]; const std::string nickname = message.arguments[1];
this->on_generic_error(message); this->on_generic_error(message);
for (auto it = this->channels.begin(); it != this->channels.end(); ++it) for (const auto& pair: this->channels)
{ {
Iid iid; Iid iid;
iid.set_local(it->first); iid.set_local(pair.first);
iid.set_server(this->hostname); iid.set_server(this->hostname);
iid.type = Iid::Type::Channel; iid.type = Iid::Type::Channel;
this->bridge.send_nickname_conflict_error(iid, nickname); this->bridge.send_nickname_conflict_error(iid, nickname);
...@@ -808,10 +809,10 @@ void IrcClient::on_nickname_change_too_fast(const IrcMessage& message) ...@@ -808,10 +809,10 @@ void IrcClient::on_nickname_change_too_fast(const IrcMessage& message)
if (message.arguments.size() >= 3) if (message.arguments.size() >= 3)
txt = message.arguments[2]; txt = message.arguments[2];
this->on_generic_error(message); this->on_generic_error(message);
for (auto it = this->channels.begin(); it != this->channels.end(); ++it) for (const auto& pair: this->channels)
{ {
Iid iid; Iid iid;
iid.set_local(it->first); iid.set_local(pair.first);
iid.set_server(this->hostname); iid.set_server(this->hostname);
iid.type = Iid::Type::Channel; iid.type = Iid::Type::Channel;
this->bridge.send_presence_error(iid, nickname, this->bridge.send_presence_error(iid, nickname,
...@@ -896,13 +897,13 @@ void IrcClient::on_error(const IrcMessage& message) ...@@ -896,13 +897,13 @@ void IrcClient::on_error(const IrcMessage& message)
{ {
const std::string leave_message = message.arguments[0]; const std::string leave_message = message.arguments[0];
// The user is out of all the channels // The user is out of all the channels
for (auto it = this->channels.begin(); it != this->channels.end(); ++it) for (const auto& pair: this->channels)
{ {
Iid iid; Iid iid;
iid.set_local(it->first); iid.set_local(pair.first);
iid.set_server(this->hostname); iid.set_server(this->hostname);
iid.type = Iid::Type::Channel; iid.type = Iid::Type::Channel;
IrcChannel* channel = it->second.get(); IrcChannel* channel = pair.second.get();
if (!channel->joined) if (!channel->joined)
continue; continue;
std::string own_nick = channel->get_self()->nick; std::string own_nick = channel->get_self()->nick;
...@@ -917,10 +918,10 @@ void IrcClient::on_quit(const IrcMessage& message) ...@@ -917,10 +918,10 @@ void IrcClient::on_quit(const IrcMessage& message)
std::string txt; std::string txt;
if (message.arguments.size() >= 1) if (message.arguments.size() >= 1)
txt = message.arguments[0]; txt = message.arguments[0];
for (auto it = this->channels.begin(); it != this->channels.end(); ++it) for (const auto& pair: this->channels)
{ {
const std::string chan_name = it->first; const std::string& chan_name = pair.first;
IrcChannel* channel = it->second.get(); IrcChannel* channel = pair.second.get();
const IrcUser* user = channel->find_user(message.prefix); const IrcUser* user = channel->find_user(message.prefix);
if (user) if (user)
{ {
...@@ -966,9 +967,9 @@ void IrcClient::on_nick(const IrcMessage& message) ...@@ -966,9 +967,9 @@ void IrcClient::on_nick(const IrcMessage& message)
{ {
change_nick_func("", &this->get_dummy_channel()); change_nick_func("", &this->get_dummy_channel());
} }
for (auto it = this->channels.begin(); it != this->channels.end(); ++it) for (const auto& pair: this->channels)
{ {
change_nick_func(it->first, it->second.get()); change_nick_func(pair.first, pair.second.get());
} }
} }
......
...@@ -26,9 +26,9 @@ class Bridge; ...@@ -26,9 +26,9 @@ class Bridge;
class IrcClient: public TCPClientSocketHandler class IrcClient: public TCPClientSocketHandler
{ {
public: public:
explicit IrcClient(std::shared_ptr<Poller>& poller, const std::string& hostname, explicit IrcClient(std::shared_ptr<Poller>& poller, std::string hostname,
const std::string& nickname, const std::string& username, std::string nickname, std::string username,
const std::string& realname, const std::string& user_hostname, std::string realname, std::string user_hostname,
Bridge& bridge); Bridge& bridge);
~IrcClient(); ~IrcClient();
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#endif #endif
#include <atomic> #include <atomic>
#include <signal.h> #include <csignal>
#ifdef USE_DATABASE #ifdef USE_DATABASE
# include <litesql.hpp> # include <litesql.hpp>
#endif #endif
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#include <logger/logger.hpp> #include <logger/logger.hpp>
#include <utils/timed_events.hpp> #include <utils/timed_events.hpp>
#include <assert.h> #include <cassert>
#include <errno.h> #include <cerrno>
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
......
...@@ -256,6 +256,6 @@ std::string TCPClientSocketHandler::get_port() const ...@@ -256,6 +256,6 @@ std::string TCPClientSocketHandler::get_port() const
bool TCPClientSocketHandler::match_port_pairt(const uint16_t local, const uint16_t remote) const bool TCPClientSocketHandler::match_port_pairt(const uint16_t local, const uint16_t remote) const
{ {
const uint16_t remote_port = static_cast<uint16_t>(std::stoi(this->port)); const auto remote_port = static_cast<uint16_t>(std::stoi(this->port));
return this->is_connected() && local == this->local_port && remote == remote_port; return this->is_connected() && local == this->local_port && remote == remote_port;
} }
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <netinet/ip.h> #include <netinet/ip.h>
#include <cstring> #include <cstring>
#include <cassert>
template <typename RemoteSocketType> template <typename RemoteSocketType>
class TcpSocketServer: public SocketHandler class TcpSocketServer: public SocketHandler
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdexcept> #include <stdexcept>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <cerrno>
#include <cstring> #include <cstring>
#ifdef BOTAN_FOUND #ifdef BOTAN_FOUND
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <stdexcept> #include <stdexcept>
#include <assert.h> #include <cassert>
#include <string.h> #include <string.h>
#include <iconv.h> #include <iconv.h>
#include <cerrno> #include <cerrno>
......
#include <utility>
#include <utils/timed_events.hpp> #include <utils/timed_events.hpp>
TimedEvent::TimedEvent(std::chrono::steady_clock::time_point&& time_point, TimedEvent::TimedEvent(std::chrono::steady_clock::time_point&& time_point,
std::function<void()> callback, const std::string& name): std::function<void()> callback, std::string name):
time_point(std::move(time_point)), time_point(std::move(time_point)),
callback(callback), callback(std::move(callback)),
repeat(false), repeat(false),
repeat_delay(0), repeat_delay(0),
name(name) name(std::move(name))
{ {
} }
TimedEvent::TimedEvent(std::chrono::milliseconds&& duration, TimedEvent::TimedEvent(std::chrono::milliseconds&& duration,
std::function<void()> callback, const std::string& name): std::function<void()> callback, std::string name):
time_point(std::chrono::steady_clock::now() + duration), time_point(std::chrono::steady_clock::now() + duration),
callback(callback), callback(std::move(callback)),
repeat(true), repeat(true),
repeat_delay(std::move(duration)), repeat_delay(std::move(duration)),
name(name) name(std::move(name))
{ {
} }
......
...@@ -25,9 +25,9 @@ public: ...@@ -25,9 +25,9 @@ public:
* An event the occurs only once, at the given time_point * An event the occurs only once, at the given time_point
*/ */
explicit TimedEvent(std::chrono::steady_clock::time_point&& time_point, explicit TimedEvent(std::chrono::steady_clock::time_point&& time_point,
std::function<void()> callback, const std::string& name=""); std::function<void()> callback, std::string name="");
explicit TimedEvent(std::chrono::milliseconds&& duration, explicit TimedEvent(std::chrono::milliseconds&& duration,
std::function<void()> callback, const std::string& name=""); std::function<void()> callback, std::string name="");
explicit TimedEvent(TimedEvent&&) = default; explicit TimedEvent(TimedEvent&&) = default;
TimedEvent& operator=(TimedEvent&&) = default; TimedEvent& operator=(TimedEvent&&) = default;
......
#include <utility>
#include <xmpp/adhoc_command.hpp> #include <xmpp/adhoc_command.hpp>
#include <xmpp/xmpp_component.hpp> #include <xmpp/xmpp_component.hpp>
#include <utils/reload.hpp> #include <utils/reload.hpp>
using namespace std::string_literals; using namespace std::string_literals;
AdhocCommand::AdhocCommand(std::vector<AdhocStep>&& callbacks, const std::string& name, const bool admin_only): AdhocCommand::AdhocCommand(std::vector<AdhocStep>&& callbacks, std::string name, const bool admin_only):
name(name), name(std::move(name)),
callbacks(std::move(callbacks)), callbacks(std::move(callbacks)),
admin_only(admin_only) admin_only(admin_only)
{ {
......
...@@ -17,7 +17,7 @@ class AdhocCommand ...@@ -17,7 +17,7 @@ class AdhocCommand
{ {
friend class AdhocSession; friend class AdhocSession;
public: public:
AdhocCommand(std::vector<AdhocStep>&& callbacks, const std::string& name, const bool admin_only); AdhocCommand(std::vector<AdhocStep>&& callbacks, std::string name, const bool admin_only);
~AdhocCommand() = default; ~AdhocCommand() = default;
AdhocCommand(const AdhocCommand&) = default; AdhocCommand(const AdhocCommand&) = default;
AdhocCommand(AdhocCommand&&) = default; AdhocCommand(AdhocCommand&&) = default;
......
...@@ -83,10 +83,8 @@ BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller>& poller, const std::s ...@@ -83,10 +83,8 @@ BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller>& poller, const std::s
void BiboumiComponent::shutdown() void BiboumiComponent::shutdown()
{ {
for (auto it = this->bridges.begin(); it != this->bridges.end(); ++it) for (auto& pair: this->bridges)
{ pair.second->shutdown("Gateway shutdown");
it->second->shutdown("Gateway shutdown");
}
} }
void BiboumiComponent::clean() void BiboumiComponent::clean()
...@@ -696,8 +694,8 @@ Bridge* BiboumiComponent::find_user_bridge(const std::string& full_jid) ...@@ -696,8 +694,8 @@ Bridge* BiboumiComponent::find_user_bridge(const std::string& full_jid)
std::vector<Bridge*> BiboumiComponent::get_bridges() const std::vector<Bridge*> BiboumiComponent::get_bridges() const
{ {
std::vector<Bridge*> res; std::vector<Bridge*> res;
for (auto it = this->bridges.begin(); it != this->bridges.end(); ++it) for (const auto& bridge: this->bridges)
res.push_back(it->second.get()); res.push_back(bridge.second.get());
return res; return res;
} }
......
...@@ -53,7 +53,7 @@ std::string jidprep(const std::string& original) ...@@ -53,7 +53,7 @@ std::string jidprep(const std::string& original)
char local[max_jid_part_len] = {}; char local[max_jid_part_len] = {};
memcpy(local, jid.local.data(), std::min(max_jid_part_len, jid.local.size())); memcpy(local, jid.local.data(), std::min(max_jid_part_len, jid.local.size()));
Stringprep_rc rc = static_cast<Stringprep_rc>(::stringprep(local, max_jid_part_len, auto rc = static_cast<Stringprep_rc>(::stringprep(local, max_jid_part_len,
static_cast<Stringprep_profile_flags>(0), stringprep_xmpp_nodeprep)); static_cast<Stringprep_profile_flags>(0), stringprep_xmpp_nodeprep));
if (rc != STRINGPREP_OK) if (rc != STRINGPREP_OK)
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string.h> #include <cstring>
std::string xml_escape(const std::string& data) std::string xml_escape(const std::string& data)
{ {
......
...@@ -43,7 +43,7 @@ TEST_CASE("Test basic XML parsing") ...@@ -43,7 +43,7 @@ TEST_CASE("Test basic XML parsing")
TEST_CASE("XML escape") TEST_CASE("XML escape")
{ {
const std::string unescaped = "'coucou'<cc>/&\"gaga\""; const std::string unescaped = R"('coucou'<cc>/&"gaga")";
CHECK(xml_escape(unescaped) == "&apos;coucou&apos;&lt;cc&gt;/&amp;&quot;gaga&quot;"); CHECK(xml_escape(unescaped) == "&apos;coucou&apos;&lt;cc&gt;/&amp;&quot;gaga&quot;");
} }
......
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