diff --git a/src/bridge/colors.cpp b/src/bridge/colors.cpp index 66f51eef529f8a6bc81ee565a0c1842f1b2cd2bc..7662425374118f5f02a12050a4c0c47bc5f130a5 100644 --- a/src/bridge/colors.cpp +++ b/src/bridge/colors.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include using namespace std::string_literals; diff --git a/src/identd/identd_socket.hpp b/src/identd/identd_socket.hpp index 10cb797dc824397580e98b2ab522c91d62ce624a..a386d80aa8f79e94517918edbb93b3fb0b3d1b49 100644 --- a/src/identd/identd_socket.hpp +++ b/src/identd/identd_socket.hpp @@ -2,7 +2,6 @@ #include -#include #include #include diff --git a/src/irc/iid.cpp b/src/irc/iid.cpp index 6b07793259701f30f694acac1ab6ac265089d2c3..63c7039706dc28032fa28ee46e75cf85b2f59ba7 100644 --- a/src/irc/iid.cpp +++ b/src/irc/iid.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -7,10 +8,10 @@ constexpr char Iid::separator[]; -Iid::Iid(const std::string& local, const std::string& server, Iid::Type type): - type(type), - local(local), - server(server) +Iid::Iid(std::string local, std::string server, Iid::Type type): + type(std::move(type)), + local(std::move(local)), + server(std::move(server)) { } diff --git a/src/irc/iid.hpp b/src/irc/iid.hpp index 81cf3ca935d4e9121d13cc12329f09d719511ed8..89f47974d53cae1f8c710bffc43765af87f06c38 100644 --- a/src/irc/iid.hpp +++ b/src/irc/iid.hpp @@ -59,7 +59,7 @@ public: Iid(const std::string& iid, const std::set& chantypes); Iid(const std::string& iid, const std::initializer_list& chantypes); 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(const Iid&) = default; diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index 48b105d8b65d5bc21ee068d50fbda12a553b6948..710ba15896cecdc35fea23b277c4ca7326526142 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -127,16 +128,16 @@ static const std::unordered_map& poller, const std::string& hostname, - const std::string& nickname, const std::string& username, - const std::string& realname, const std::string& user_hostname, +IrcClient::IrcClient(std::shared_ptr& poller, std::string hostname, + std::string nickname, std::string username, + std::string realname, std::string user_hostname, Bridge& bridge): TCPClientSocketHandler(poller), - hostname(hostname), - user_hostname(user_hostname), - username(username), - realname(realname), - current_nick(nickname), + hostname(std::move(hostname)), + user_hostname(std::move(user_hostname)), + username(std::move(username)), + realname(std::move(realname)), + current_nick(std::move(nickname)), bridge(bridge), welcomed(false), chanmodes({"", "", "", ""}), @@ -791,10 +792,10 @@ void IrcClient::on_nickname_conflict(const IrcMessage& message) { const std::string nickname = message.arguments[1]; 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.set_local(it->first); + iid.set_local(pair.first); iid.set_server(this->hostname); iid.type = Iid::Type::Channel; this->bridge.send_nickname_conflict_error(iid, nickname); @@ -808,10 +809,10 @@ void IrcClient::on_nickname_change_too_fast(const IrcMessage& message) if (message.arguments.size() >= 3) txt = message.arguments[2]; 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.set_local(it->first); + iid.set_local(pair.first); iid.set_server(this->hostname); iid.type = Iid::Type::Channel; this->bridge.send_presence_error(iid, nickname, @@ -896,13 +897,13 @@ void IrcClient::on_error(const IrcMessage& message) { const std::string leave_message = message.arguments[0]; // 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.set_local(it->first); + iid.set_local(pair.first); iid.set_server(this->hostname); iid.type = Iid::Type::Channel; - IrcChannel* channel = it->second.get(); + IrcChannel* channel = pair.second.get(); if (!channel->joined) continue; std::string own_nick = channel->get_self()->nick; @@ -917,10 +918,10 @@ void IrcClient::on_quit(const IrcMessage& message) std::string txt; if (message.arguments.size() >= 1) 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; - IrcChannel* channel = it->second.get(); + const std::string& chan_name = pair.first; + IrcChannel* channel = pair.second.get(); const IrcUser* user = channel->find_user(message.prefix); if (user) { @@ -966,9 +967,9 @@ void IrcClient::on_nick(const IrcMessage& message) { 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()); } } diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp index 8119201db6f6a6cfacc72f8e31ed2fbd6bbc0992..75930294b7865d883ef4c0ea49436453f00a90eb 100644 --- a/src/irc/irc_client.hpp +++ b/src/irc/irc_client.hpp @@ -26,9 +26,9 @@ class Bridge; class IrcClient: public TCPClientSocketHandler { public: - explicit IrcClient(std::shared_ptr& poller, const std::string& hostname, - const std::string& nickname, const std::string& username, - const std::string& realname, const std::string& user_hostname, + explicit IrcClient(std::shared_ptr& poller, std::string hostname, + std::string nickname, std::string username, + std::string realname, std::string user_hostname, Bridge& bridge); ~IrcClient(); diff --git a/src/main.cpp b/src/main.cpp index 76ab5d9eafc418740e76d08cf4eb30ee4930b10f..2fa72d5251b87a4f58b4c67df8c40c4cc451fb6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,7 @@ #endif #include -#include +#include #ifdef USE_DATABASE # include #endif diff --git a/src/network/poller.cpp b/src/network/poller.cpp index 9f5bcfbbda9efbf71d82ba370d5accfcb2cf1b6e..9f62e36ce178f387149c70f4b214ce0ac8fc7cef 100644 --- a/src/network/poller.cpp +++ b/src/network/poller.cpp @@ -2,8 +2,8 @@ #include #include -#include -#include +#include +#include #include #include #include diff --git a/src/network/tcp_client_socket_handler.cpp b/src/network/tcp_client_socket_handler.cpp index 462870365ce0eaba940daf36b1656fc663c588ce..7181c9ddfbe9f3d5830b11e2138bdbbb46f8ea2b 100644 --- a/src/network/tcp_client_socket_handler.cpp +++ b/src/network/tcp_client_socket_handler.cpp @@ -256,6 +256,6 @@ std::string TCPClientSocketHandler::get_port() const bool TCPClientSocketHandler::match_port_pairt(const uint16_t local, const uint16_t remote) const { - const uint16_t remote_port = static_cast(std::stoi(this->port)); + const auto remote_port = static_cast(std::stoi(this->port)); return this->is_connected() && local == this->local_port && remote == remote_port; } diff --git a/src/network/tcp_server_socket.hpp b/src/network/tcp_server_socket.hpp index c511962887791d062d28af08911177bd19105a7d..652b773c52f4592c84590e42e6d6ca9a0ecc8d97 100644 --- a/src/network/tcp_server_socket.hpp +++ b/src/network/tcp_server_socket.hpp @@ -12,7 +12,6 @@ #include #include -#include template class TcpSocketServer: public SocketHandler diff --git a/src/network/tcp_socket_handler.cpp b/src/network/tcp_socket_handler.cpp index 7eebae070e6242ea188552d06011e00be1757aca..b5e5db19e0bcec653d9a51ee8381dc86c820091c 100644 --- a/src/network/tcp_socket_handler.cpp +++ b/src/network/tcp_socket_handler.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #ifdef BOTAN_FOUND diff --git a/src/utils/encoding.cpp b/src/utils/encoding.cpp index aa91dacc23eb73e51c8e979c0204fd11a1475607..cff003913a34b58c0c26efebaa4a45dffe1d4574 100644 --- a/src/utils/encoding.cpp +++ b/src/utils/encoding.cpp @@ -4,7 +4,7 @@ #include -#include +#include #include #include #include diff --git a/src/utils/timed_events.cpp b/src/utils/timed_events.cpp index 5077199ac0ba726beea6efec7e3e113fdad3e1c0..e35a659f28f4495e0da7872fcd75984f6575a17f 100644 --- a/src/utils/timed_events.cpp +++ b/src/utils/timed_events.cpp @@ -1,22 +1,23 @@ +#include #include TimedEvent::TimedEvent(std::chrono::steady_clock::time_point&& time_point, - std::function callback, const std::string& name): + std::function callback, std::string name): time_point(std::move(time_point)), - callback(callback), + callback(std::move(callback)), repeat(false), repeat_delay(0), - name(name) + name(std::move(name)) { } TimedEvent::TimedEvent(std::chrono::milliseconds&& duration, - std::function callback, const std::string& name): + std::function callback, std::string name): time_point(std::chrono::steady_clock::now() + duration), - callback(callback), + callback(std::move(callback)), repeat(true), repeat_delay(std::move(duration)), - name(name) + name(std::move(name)) { } diff --git a/src/utils/timed_events.hpp b/src/utils/timed_events.hpp index 6e2820634941e97c620d2ce272f95b836a615e80..393b38dc4a2585f6bb63c91c09647221d657df37 100644 --- a/src/utils/timed_events.hpp +++ b/src/utils/timed_events.hpp @@ -25,9 +25,9 @@ public: * An event the occurs only once, at the given time_point */ explicit TimedEvent(std::chrono::steady_clock::time_point&& time_point, - std::function callback, const std::string& name=""); + std::function callback, std::string name=""); explicit TimedEvent(std::chrono::milliseconds&& duration, - std::function callback, const std::string& name=""); + std::function callback, std::string name=""); explicit TimedEvent(TimedEvent&&) = default; TimedEvent& operator=(TimedEvent&&) = default; diff --git a/src/xmpp/adhoc_command.cpp b/src/xmpp/adhoc_command.cpp index 825cc920fbd449b3bac0c6ea0d12def69caa9855..e02bf35aadf2d48101f2b1a8a65c9a37d9f9fbbd 100644 --- a/src/xmpp/adhoc_command.cpp +++ b/src/xmpp/adhoc_command.cpp @@ -1,11 +1,12 @@ +#include #include #include #include using namespace std::string_literals; -AdhocCommand::AdhocCommand(std::vector&& callbacks, const std::string& name, const bool admin_only): - name(name), +AdhocCommand::AdhocCommand(std::vector&& callbacks, std::string name, const bool admin_only): + name(std::move(name)), callbacks(std::move(callbacks)), admin_only(admin_only) { diff --git a/src/xmpp/adhoc_command.hpp b/src/xmpp/adhoc_command.hpp index ced45492a288e35df04699788cfbfb77f0f9555a..c00d9e6bda22011122bfc3e602a840385c4a7a47 100644 --- a/src/xmpp/adhoc_command.hpp +++ b/src/xmpp/adhoc_command.hpp @@ -17,7 +17,7 @@ class AdhocCommand { friend class AdhocSession; public: - AdhocCommand(std::vector&& callbacks, const std::string& name, const bool admin_only); + AdhocCommand(std::vector&& callbacks, std::string name, const bool admin_only); ~AdhocCommand() = default; AdhocCommand(const AdhocCommand&) = default; AdhocCommand(AdhocCommand&&) = default; diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index dc57eebe9f32b238962a2cad7b2e7045771d04b6..b4b6a454cd358a8f074f42021c7003936002d130 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -83,10 +83,8 @@ BiboumiComponent::BiboumiComponent(std::shared_ptr& poller, const std::s void BiboumiComponent::shutdown() { - for (auto it = this->bridges.begin(); it != this->bridges.end(); ++it) - { - it->second->shutdown("Gateway shutdown"); - } + for (auto& pair: this->bridges) + pair.second->shutdown("Gateway shutdown"); } void BiboumiComponent::clean() @@ -696,8 +694,8 @@ Bridge* BiboumiComponent::find_user_bridge(const std::string& full_jid) std::vector BiboumiComponent::get_bridges() const { std::vector res; - for (auto it = this->bridges.begin(); it != this->bridges.end(); ++it) - res.push_back(it->second.get()); + for (const auto& bridge: this->bridges) + res.push_back(bridge.second.get()); return res; } diff --git a/src/xmpp/jid.cpp b/src/xmpp/jid.cpp index ba8d70b308b29494f2b2334ee5dccfc48646fba6..19d1b55541e9fbbd638c9555268837da8325581d 100644 --- a/src/xmpp/jid.cpp +++ b/src/xmpp/jid.cpp @@ -53,7 +53,7 @@ std::string jidprep(const std::string& original) char local[max_jid_part_len] = {}; memcpy(local, jid.local.data(), std::min(max_jid_part_len, jid.local.size())); - Stringprep_rc rc = static_cast(::stringprep(local, max_jid_part_len, + auto rc = static_cast(::stringprep(local, max_jid_part_len, static_cast(0), stringprep_xmpp_nodeprep)); if (rc != STRINGPREP_OK) { diff --git a/src/xmpp/xmpp_stanza.cpp b/src/xmpp/xmpp_stanza.cpp index ac6ce9bf41a542f67afd98cfbb71a4f51c3ce0db..499985106db122ee1060fd6bea9b7b9ac8ccb7dd 100644 --- a/src/xmpp/xmpp_stanza.cpp +++ b/src/xmpp/xmpp_stanza.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include std::string xml_escape(const std::string& data) { diff --git a/tests/xmpp.cpp b/tests/xmpp.cpp index 42b7c08592b45ab39c388edd6a1e724b2d51fa16..7ea03a97fafe75d9a8fd09df54ad0b4973ffc0a2 100644 --- a/tests/xmpp.cpp +++ b/tests/xmpp.cpp @@ -43,7 +43,7 @@ TEST_CASE("Test basic XML parsing") TEST_CASE("XML escape") { - const std::string unescaped = "'coucou'/&\"gaga\""; + const std::string unescaped = R"('coucou'/&"gaga")"; CHECK(xml_escape(unescaped) == "'coucou'<cc>/&"gaga""); }