Skip to content

Commit

Permalink
Run the v4 modules through clang-tidy's modernizing checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
SadieCat committed Jun 25, 2023
1 parent 0dd4b8a commit cc4e2db
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 60 deletions.
6 changes: 3 additions & 3 deletions 4/m_antisnoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AntiSnoopMode final
syntax = "<idletime>";
}

bool OnSet(User* source, Channel* channel, std::string& parameter)
bool OnSet(User* source, Channel* channel, std::string& parameter) override
{
unsigned long idletime;
if (!Duration::TryFrom(parameter, idletime) || !idletime)
Expand Down Expand Up @@ -72,7 +72,7 @@ class ModuleAntiSnoop final
{
}

void ReadConfig(ConfigStatus& status)
void ReadConfig(ConfigStatus& status) override
{
const auto& tag = ServerInstance->Config->ConfValue("antisnoop");
exemptrank = tag->getNum<ModeHandler::Rank>("exemptrank", VOICE_VALUE);
Expand All @@ -83,7 +83,7 @@ class ModuleAntiSnoop final
if (target.type != MessageTarget::TYPE_CHANNEL)
return MOD_RES_PASSTHRU; // We only care about channel messages.

Channel* channel = target.Get<Channel>();
auto* channel = target.Get<Channel>();
Membership* memb = channel->GetUser(user);
if (memb)
{
Expand Down
2 changes: 1 addition & 1 deletion 4/m_asn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class ModuleASN final
}
}

ModResult OnPreChangeConnectClass(LocalUser* user, const std::shared_ptr<ConnectClass>& klass, std::optional<Numeric::Numeric>& errnum)
ModResult OnPreChangeConnectClass(LocalUser* user, const std::shared_ptr<ConnectClass>& klass, std::optional<Numeric::Numeric>& errnum) override
{
const std::string asn = klass->config->getString("asn");
if (asn.empty())
Expand Down
2 changes: 1 addition & 1 deletion 4/m_autoaway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ModuleAutoAway final


const std::string awaymsg = user->awaymsg;
autoaway.Set(user, 0);
autoaway.Unset(user);
user->awaytime = 0;
user->awaymsg.clear();
user->WriteNumeric(RPL_UNAWAY, "You are no longer automatically marked as being away");
Expand Down
4 changes: 2 additions & 2 deletions 4/m_autokick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class ModeWatcherBan final
ModeHandler::Rank rank = channel->GetPrefixValue(source);

const Channel::MemberMap& users = channel->GetUsers();
Channel::MemberMap::const_iterator iter = users.begin();
auto iter = users.begin();

while (iter != users.end())
{
// KickUser invalidates the iterator so copy and increment it here.
Channel::MemberMap::const_iterator it = iter++;
auto it = iter++;
if (IS_LOCAL(it->first) && rank > channel->GetPrefixValue(it->first) && channel->CheckBan(it->first, change.param))
{
channel->KickUser(ServerInstance->FakeClient, it->first, reason.c_str());
Expand Down
2 changes: 1 addition & 1 deletion 4/m_blockhighlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ModuleBlockHighlight final
if (details.text.length() < minlen)
return MOD_RES_PASSTHRU;

Channel* const chan = target.Get<Channel>();
auto* const chan = target.Get<Channel>();
if (chan->GetUsers().size() < minusers)
return MOD_RES_PASSTHRU;

Expand Down
2 changes: 1 addition & 1 deletion 4/m_censor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ModuleCensor : public Module

case MessageTarget::TYPE_CHANNEL:
{
Channel* targchan = target.Get<Channel>();
auto* targchan = target.Get<Channel>();
if (!targchan->IsModeSet(cc))
return MOD_RES_PASSTHRU;

Expand Down
2 changes: 1 addition & 1 deletion 4/m_clones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CommandClones : public SplitCommand

CmdResult HandleLocal(LocalUser* user, const Params& parameters) override
{
unsigned int limit = ConvToNum<unsigned int>(parameters[0]);
auto limit = ConvToNum<unsigned int>(parameters[0]);

// Syntax of a CLONES reply:
// :irc.example.com BATCH +<id> inspircd.org/clones :<min-count>
Expand Down
20 changes: 10 additions & 10 deletions 4/m_customtags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CustomTagsExtItem final
if (!user)
return;

CustomTagMap* list = new CustomTagMap();
auto* list = new CustomTagMap();
irc::spacesepstream ts(value);
while (!ts.StreamEnd())
{
Expand Down Expand Up @@ -90,9 +90,9 @@ class CustomTagsExtItem final

std::string ToInternal(const Extensible* container, void* item) const noexcept override
{
CustomTagMap* list = static_cast<CustomTagMap*>(item);
auto* list = static_cast<CustomTagMap*>(item);
std::string buf;
for (CustomTagMap::const_iterator iter = list->begin(); iter != list->end(); ++iter)
for (auto iter = list->begin(); iter != list->end(); ++iter)
{
if (iter != list->begin())
buf.push_back(' ');
Expand All @@ -113,7 +113,7 @@ class CustomTags final

User* UserFromMsg(ClientProtocol::Message& msg)
{
SpecialMessageMap::const_iterator iter = specialmsgs.find(msg.GetCommand());
auto iter = specialmsgs.find(msg.GetCommand());
if (iter == specialmsgs.end())
return nullptr; // Not a special message.

Expand All @@ -137,13 +137,13 @@ class CustomTags final
CustomTagsExtItem ext;
SpecialMessageMap specialmsgs;
std::string vendor;
int whox_index;
int whox_index{-1};

CustomTags(Module* mod)
: ClientProtocol::MessageTagProvider(mod)
, ctctagcap(mod)
, ext(mod, ctctagcap)
, whox_index(-1)
{
}

Expand All @@ -161,8 +161,8 @@ class CustomTags final
if (!tags)
return;

for (CustomTagMap::const_iterator iter = tags->begin(); iter != tags->end(); ++iter)
msg.AddTag(vendor + iter->first, this, iter->second);
for (const auto & tag : *tags)
msg.AddTag(vendor + tag.first, this, tag.second);
}

ModResult OnProcessTag(User* user, const std::string& tagname, std::string& tagvalue) override
Expand Down Expand Up @@ -194,8 +194,8 @@ class ModuleCustomTags final
if (!tagmap)
return MOD_RES_PASSTHRU;

for (CustomTagMap::const_iterator iter = tagmap->begin(); iter != tagmap->end(); ++iter)
tags.insert(std::make_pair(ctags.vendor + iter->first, ClientProtocol::MessageTagData(&ctags, iter->second)));
for (const auto & iter : *tagmap)
tags.insert(std::make_pair(ctags.vendor + iter.first, ClientProtocol::MessageTagData(&ctags, iter.second)));
return MOD_RES_PASSTHRU;
}

Expand Down
2 changes: 1 addition & 1 deletion 4/m_discordnick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ModuleDiscordNick final
ServerInstance->IsNick = &IsDiscordNick;
}

~ModuleDiscordNick()
~ModuleDiscordNick() override
{
ServerInstance->IsNick = origisnick;
}
Expand Down
8 changes: 4 additions & 4 deletions 4/m_messagelength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class MessageLengthMode final
MessageLengthMode(Module* Creator)
: ParamMode<MessageLengthMode, IntExtItem>(Creator, "message-length", 'W')
{
syntax = { "<max-length>" };
syntax = "<max-length>" ;
}

bool OnSet(User* source, Channel* channel, std::string& parameter)
bool OnSet(User* source, Channel* channel, std::string& parameter) override
{
size_t length = ConvToNum<size_t>(parameter);
auto length = ConvToNum<size_t>(parameter);
if (length == 0 || length > ServerInstance->Config->Limits.MaxLine)
{
source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter));
Expand Down Expand Up @@ -72,7 +72,7 @@ class ModuleMessageLength final
if (target.type != MessageTarget::TYPE_CHANNEL)
return MOD_RES_PASSTHRU;

Channel* channel = target.Get<Channel>();
auto* channel = target.Get<Channel>();
if (!channel->IsModeSet(&mode))
return MOD_RES_PASSTHRU;

Expand Down
9 changes: 4 additions & 5 deletions 4/m_noidletyping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ class ModuleNoIdleTyping final

ModResult BuildChannelExempts(User* source, Channel* channel, CTCTags::TagMessageDetails& details)
{
const Channel::MemberMap& members = channel->GetUsers();
for (Channel::MemberMap::const_iterator member = members.begin(); member != members.end(); ++member)
for (const auto& [member, _] : channel->GetUsers())
{
if (IsIdle(source))
details.exemptions.insert(member->first);
details.exemptions.insert(member);
}
return MOD_RES_PASSTHRU;
}
Expand All @@ -70,8 +69,8 @@ class ModuleNoIdleTyping final

ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) override
{
ClientProtocol::TagMap::const_iterator iter = details.tags_out.find("+typing");
ClientProtocol::TagMap::const_iterator draftiter = details.tags_out.find("+draft/typing");
auto iter = details.tags_out.find("+typing");
auto draftiter = details.tags_out.find("+draft/typing");
if (iter == details.tags_out.end() && draftiter == details.tags_out.end())
return MOD_RES_PASSTHRU;

Expand Down
7 changes: 3 additions & 4 deletions 4/m_noprivatemode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ class NoPrivateMode final
if (!IS_LOCAL(source) || !channel)
return MOD_RES_PASSTHRU;

Modes::ChangeList::List& list = modes.getlist();
for (Modes::ChangeList::List::iterator iter = list.begin(); iter != list.end(); ++iter)
for (auto& change : modes.getlist())
{
if (iter->adding && iter->mh == *privatemode)
iter->mh = *secretmode;
if (change.adding && change.mh == *privatemode)
change.mh = *secretmode;
}
return MOD_RES_PASSTHRU;
}
Expand Down
26 changes: 3 additions & 23 deletions 4/m_qrcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,6 @@ class CommandQRCode final
return buffer;
}

std::string URLEncode(const std::string& data)
{
static const char* hextable = "0123456789ABCDEF";

std::string buffer;
for (std::string::const_iterator iter = data.begin(); iter != data.end(); ++iter)
{
if (isalnum(*iter))
{
buffer.push_back(*iter);
continue;
}

buffer.push_back('%');
buffer.push_back(hextable[*iter >> 4]);
buffer.push_back(hextable[*iter & 15]);
}
return buffer;
}

void WriteMessage(LocalUser* user, const std::string& message)
{
ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->FakeClient, user, message);
Expand Down Expand Up @@ -155,7 +135,7 @@ class CommandQRCode final
return CmdResult::FAILURE;
}

url = URLEncode(channel->name);
url = Percent::Encode(channel->name);
if (channel->IsModeSet(keymode))
url.append(",needkey");
}
Expand All @@ -167,7 +147,7 @@ class CommandQRCode final
source->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
return CmdResult::FAILURE;
}
url = URLEncode(user->nick) + ",isnick";
url = Percent::Encode(user->nick) + ",isnick";
}
}

Expand Down Expand Up @@ -282,7 +262,7 @@ class ModuleQRCode final

if (name.find_first_not_of("0123456789") == std::string::npos)
{
const unsigned long value = ConvToNum<unsigned long>(name);
const auto value = ConvToNum<unsigned long>(name);
if (value <= 99)
return ConvToStr(value);
}
Expand Down
2 changes: 1 addition & 1 deletion 4/m_solvemsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class ModuleSolveMessage final
if (!chanmsg)
return MOD_RES_PASSTHRU; // Not enabled.

Channel* target = msgtarget.Get<Channel>();
auto* target = msgtarget.Get<Channel>();
if (target->GetPrefixValue(user) >= VOICE_VALUE)
return MOD_RES_PASSTHRU; // Exempt users with a status rank.
break;
Expand Down
4 changes: 2 additions & 2 deletions 4/m_stats_unlinked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class ModuleStatsUnlinked final

static bool IsServerLinked(const ProtocolInterface::ServerList& linkedServers, const std::string& serverName)
{
for (ProtocolInterface::ServerList::const_iterator it = linkedServers.begin(); it != linkedServers.end(); ++it)
for (const auto& linkedServer : linkedServers)
{
if (it->servername == serverName)
if (linkedServer.servername == serverName)
return true;
}
return false;
Expand Down

0 comments on commit cc4e2db

Please sign in to comment.