Avoid the use of ConvToStr in string concatenation.

This function calls INSP_FORMAT in most cases nowadays so we may
as well just call that manually.
This commit is contained in:
Sadie Powell 2025-03-01 16:06:32 +00:00
parent 22ad04aafa
commit 32a127d2e0
22 changed files with 43 additions and 36 deletions

View File

@ -139,7 +139,7 @@ public:
* @param error The error which occurred whilst compiling the regular expression. * @param error The error which occurred whilst compiling the regular expression.
*/ */
Exception(const Module* mod, const std::string& regex, const std::string& error) Exception(const Module* mod, const std::string& regex, const std::string& error)
: ModuleException(mod, "Error in regex '" + regex + "': " + error) : ModuleException(mod, INSP_FORMAT("Error in regex '{}': {}", regex, error))
{ {
} }
@ -150,7 +150,7 @@ public:
* @param offset The offset at which the errror occurred. * @param offset The offset at which the errror occurred.
*/ */
Exception(const Module* mod, const std::string& regex, const std::string& error, size_t offset) Exception(const Module* mod, const std::string& regex, const std::string& error, size_t offset)
: ModuleException(mod, "Error in regex '" + regex + "' at offset " + ConvToStr(offset) + ": " + error) : ModuleException(mod, INSP_FORMAT("Error in regex '{}' at offset {}: {}", regex, offset, error))
{ {
} }
}; };

View File

@ -29,9 +29,10 @@ namespace Duration
* seconds. If called with this duration 33,019,565 will be returned. * seconds. If called with this duration 33,019,565 will be returned.
* *
* @param str A string containing a duration. * @param str A string containing a duration.
* @param base The base time to use for leap year calculation.
* @return Either the number of seconds in the duration or 0 on error. * @return Either the number of seconds in the duration or 0 on error.
*/ */
CoreExport unsigned long From(const std::string& str); CoreExport unsigned long From(const std::string& str, time_t base = 0);
/** Determines whether a duration string is valid. /** Determines whether a duration string is valid.
* @param str The duration string to check. * @param str The duration string to check.
@ -54,9 +55,10 @@ namespace Duration
* *
* @param str A string containing a duration. * @param str A string containing a duration.
* @param duration The location to store the resulting duration. * @param duration The location to store the resulting duration.
* @param base The base time to use for leap year calculation.
* @return True if the conversion succeeded; otherwise, false. * @return True if the conversion succeeded; otherwise, false.
*/ */
CoreExport bool TryFrom(const std::string& str, unsigned long& duration); CoreExport bool TryFrom(const std::string& str, unsigned long& duration, time_t base = 0);
} }
namespace Time namespace Time

View File

@ -348,7 +348,7 @@ FilePosition::FilePosition(const std::string& Name, unsigned long Line, unsigned
std::string FilePosition::str() const std::string FilePosition::str() const
{ {
return name + ":" + ConvToStr(line) + ":" + ConvToStr(column); return INSP_FORMAT("{}:{}:{}", name, line, column);
} }
void ParseStack::DoInclude(const std::shared_ptr<ConfigTag>& tag, int flags) void ParseStack::DoInclude(const std::shared_ptr<ConfigTag>& tag, int flags)
@ -588,7 +588,7 @@ std::string ConfigTag::getString(const std::string& key, const std::string& def,
if (res.length() < minlen || res.length() > maxlen) if (res.length() < minlen || res.length() > maxlen)
{ {
LogMalformed(key, res, def, "not between " + ConvToStr(minlen) + " and " + ConvToStr(maxlen) + " characters in length"); LogMalformed(key, res, def, INSP_FORMAT("not between {} and {} characters in length", minlen, maxlen));
return def; return def;
} }
return res; return res;
@ -629,7 +629,7 @@ namespace
default: default:
num = def; num = def;
tag->LogMalformed(key, val, ConvToStr(def), "contains an invalid magnitude specifier (" + ConvToStr(*tail) +")"); tag->LogMalformed(key, val, ConvToStr(def), INSP_FORMAT("contains an invalid magnitude specifier ({})", *tail));
return; return;
} }
} }
@ -649,7 +649,7 @@ namespace
if (num >= min && num <= max) if (num >= min && num <= max)
return; return;
tag->LogMalformed(key, ConvToStr(num), ConvToStr(def), "not between " + ConvToStr(min) + " and " + ConvToStr(max)); tag->LogMalformed(key, ConvToStr(num), ConvToStr(def), INSP_FORMAT("not between {} and {}", min, max));
num = def; num = def;
} }
} }

View File

@ -281,7 +281,7 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
throw CoreException("Connect class must have allow, deny, or name specified at " + tag->source.str()); throw CoreException("Connect class must have allow, deny, or name specified at " + tag->source.str());
if (name.empty()) if (name.empty())
name = "unnamed-" + ConvToStr(i); name = INSP_FORMAT("unnamed-{}", i);
if (names.find(name) != names.end()) if (names.find(name) != names.end())
throw CoreException("Two connect classes with name \"" + name + "\" defined!"); throw CoreException("Two connect classes with name \"" + name + "\" defined!");

View File

@ -403,7 +403,7 @@ static constexpr unsigned int duration_multi[] =
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
}; };
bool Duration::TryFrom(const std::string& str, unsigned long& duration) bool Duration::TryFrom(const std::string& str, unsigned long& duration, time_t base)
{ {
unsigned long total = 0; unsigned long total = 0;
unsigned long subtotal = 0; unsigned long subtotal = 0;
@ -437,10 +437,10 @@ bool Duration::TryFrom(const std::string& str, unsigned long& duration)
return true; return true;
} }
unsigned long Duration::From(const std::string& str) unsigned long Duration::From(const std::string& str, time_t base)
{ {
unsigned long out = 0; unsigned long out = 0;
Duration::TryFrom(str, out); Duration::TryFrom(str, out, base);
return out; return out;
} }

View File

@ -292,7 +292,8 @@ namespace GnuTLS
if (ret < 0) if (ret < 0)
{ {
// gnutls did not understand the user supplied string // gnutls did not understand the user supplied string
throw Exception("Unable to initialize priorities to \"" + priorities + "\": " + gnutls_strerror(ret) + " Syntax error at position " + ConvToStr((unsigned int) (prioerror - priocstr))); throw Exception(INSP_FORMAT("Unable to initialize priorities to \"{}\": {} Syntax error at position {}.",
priorities, gnutls_strerror(ret), static_cast<size_t>(prioerror - priocstr)));
} }
} }

View File

@ -281,9 +281,9 @@ public:
if ((prefixmsg) && (!batchcap.IsEnabled(localuser))) if ((prefixmsg) && (!batchcap.IsEnabled(localuser)))
{ {
std::string message("Replaying up to " + ConvToStr(list->maxlen) + " lines of pre-join history"); auto message = INSP_FORMAT("Replaying up to {} lines of pre-join history", list->maxlen);
if (list->maxtime > 0) if (list->maxtime > 0)
message.append(" from the last " + Duration::ToString(list->maxtime)); message += INSP_FORMAT(" from the last {}", Duration::ToString(list->maxtime));
memb->WriteNotice(message); memb->WriteNotice(message);
} }

View File

@ -299,13 +299,13 @@ public:
// Ensure that we have the <cloak:key> parameter. // Ensure that we have the <cloak:key> parameter.
const std::string key = tag->getString("key"); const std::string key = tag->getString("key");
if (key.empty()) if (key.empty())
throw ModuleException(creator, "You have not defined a cloaking key. Define <cloak:key> as a " + ConvToStr(minkeylen) + "+ character network-wide secret, at " + tag->source.str()); throw ModuleException(creator, INSP_FORMAT("You have not defined a cloaking key. Define <cloak:key> as a {}+ character network-wide secret, at {}", minkeylen, tag->source.str()));
// If we are the first cloak method then mandate a strong key. // If we are the first cloak method then mandate a strong key.
if (primary) if (primary)
{ {
if (key.length() < minkeylen) if (key.length() < minkeylen)
throw ModuleException(creator, "Your cloaking key is not secure. It should be at least " + ConvToStr(minkeylen) + " characters long, at " + tag->source.str()); throw ModuleException(creator, INSP_FORMAT("Your cloaking key is not secure. It should be at least {} characters long, at {}", minkeylen, tag->source.str()));
ServerInstance->Logs.Normal(MODNAME, "The {} cloak method is deprecated and will be removed in the next major version of InspIRCd. Consider migrating to cloak_sha256 instead. See " INSPIRCD_DOCS "modules/cloak_md5 for more information.", ServerInstance->Logs.Normal(MODNAME, "The {} cloak method is deprecated and will be removed in the next major version of InspIRCd. Consider migrating to cloak_sha256 instead. See " INSPIRCD_DOCS "modules/cloak_md5 for more information.",
name.c_str() + 6); name.c_str() + 6);

View File

@ -311,7 +311,7 @@ public:
// Ensure that we have the <cloak:key> parameter. // Ensure that we have the <cloak:key> parameter.
const std::string key = tag->getString("key"); const std::string key = tag->getString("key");
if (key.length() < minkeylen) if (key.length() < minkeylen)
throw ModuleException(creator, "Your cloak key should be at least " + ConvToStr(minkeylen) + " characters long, at " + tag->source.str()); throw ModuleException(creator, INSP_FORMAT("Your cloak key should be at least {} characters long, at {}", minkeylen, tag->source.str()));
psl_ctx_t* psl = nullptr; psl_ctx_t* psl = nullptr;
std::string psldb = tag->getString("psl"); std::string psldb = tag->getString("psl");

View File

@ -710,9 +710,9 @@ public:
dnsbl->name, dnsbl->stats_hits, dnsbl->stats_misses, dnsbl->stats_errors)); dnsbl->name, dnsbl->stats_hits, dnsbl->stats_misses, dnsbl->stats_errors));
} }
stats.AddGenericRow("Total DNSBL hits: " + ConvToStr(total_hits)); stats.AddGenericRow(INSP_FORMAT("Total DNSBL hits: {}", total_hits));
stats.AddGenericRow("Total DNSBL misses: " + ConvToStr(total_misses)); stats.AddGenericRow(INSP_FORMAT("Total DNSBL misses: {}", total_misses));
stats.AddGenericRow("Total DNSBL errors: " + ConvToStr(total_errors)); stats.AddGenericRow(INSP_FORMAT("Total DNSBL errors: {}", total_errors));
return MOD_RES_DENY; return MOD_RES_DENY;
} }
}; };

View File

@ -995,7 +995,7 @@ bool ModuleFilter::WriteDatabase()
return true; return true;
} }
const std::string newfilterconf = filterconf + ".new." + ConvToStr(ServerInstance->Time()); const auto newfilterconf = INSP_FORMAT("{}.new.{}", filterconf, ServerInstance->Time());
std::ofstream stream(newfilterconf.c_str()); std::ofstream stream(newfilterconf.c_str());
if (!stream.is_open()) // Filesystem probably not writable. if (!stream.is_open()) // Filesystem probably not writable.
{ {

View File

@ -67,7 +67,8 @@ public:
{ {
if (!IsValid()) if (!IsValid())
return ""; return "";
return ConvToStr(this->iterations) + ":" + Base64::Encode(this->hash) + ":" + Base64::Encode(this->salt);
return INSP_FORMAT("{}:{}:{}", this->iterations, Base64::Encode(this->hash), Base64::Encode(this->salt));
} }
bool IsValid() const bool IsValid() const

View File

@ -74,7 +74,7 @@ static bool WriteDatabase(PermChannel& permchanmode, bool save_listmodes, unsign
if (permchannelsconf.empty()) if (permchannelsconf.empty())
return true; return true;
const std::string permchannelsnewconf = permchannelsconf + ".new." + ConvToStr(ServerInstance->Time()); const auto permchannelsnewconf = INSP_FORMAT("{}.new.{}", permchannelsconf, ServerInstance->Time());
std::ofstream stream(permchannelsnewconf); std::ofstream stream(permchannelsnewconf);
if (!stream.is_open()) if (!stream.is_open())
{ {

View File

@ -61,7 +61,7 @@ public:
if (user->signon > user->idle_lastmsg) if (user->signon > user->idle_lastmsg)
user->signon = user->idle_lastmsg; user->signon = user->idle_lastmsg;
ServerInstance->SNO.WriteToSnoMask('a', user->nick+" used SETIDLE to set their idle time to "+ConvToStr(idle)+" seconds"); ServerInstance->SNO.WriteToSnoMask('a', "{} used SETIDLE to set their idle time to {} seconds", user->nick, idle);
noterpl.SendIfCap(user, stdrplcap, this, "IDLE_TIME_SET", user->idle_lastmsg, "Idle time set."); noterpl.SendIfCap(user, stdrplcap, this, "IDLE_TIME_SET", user->idle_lastmsg, "Idle time set.");
return CmdResult::SUCCESS; return CmdResult::SUCCESS;
} }

View File

@ -330,7 +330,7 @@ void TreeSocket::SendCapabilities(int phase)
return; return;
if (capab->capab_phase < 1 && phase >= 1) if (capab->capab_phase < 1 && phase >= 1)
WriteLine("CAPAB START " + ConvToStr(PROTO_NEWEST)); WriteLine(INSP_FORMAT("CAPAB START {}", (uint16_t)PROTO_NEWEST));
capab->capab_phase = phase; capab->capab_phase = phase;
if (phase < 2) if (phase < 2)

View File

@ -100,7 +100,10 @@ static std::vector<std::string> GetMap(User* user, TreeServer* current, size_t m
if (user->IsOper()) if (user->IsOper())
{ {
time_t secs_up = ServerInstance->Time() - current->age; time_t secs_up = ServerInstance->Time() - current->age;
buffer += " [Up: " + Duration::ToString(secs_up) + (current->rtt == 0 ? "]" : " Lag: " + ConvToStr(current->rtt) + "ms]"); buffer += INSP_FORMAT(" [Up: {}", Duration::ToString(secs_up));
if (current->rtt)
buffer += INSP_FORMAT(" Lag: {}ms", current->rtt);
buffer += "]";
} }
std::vector<std::string> map; std::vector<std::string> map;

View File

@ -161,11 +161,11 @@ void TreeSocket::ProcessLine(std::string& line)
if (!params.empty()) if (!params.empty())
{ {
time_t them = ServerCommand::ExtractTS(params[0]); time_t them = ServerCommand::ExtractTS(params[0]);
time_t delta = them - ServerInstance->Time(); time_t delta = std::abs(them - ServerInstance->Time());
if ((delta < -15) || (delta > 15)) if (delta > 15)
{ {
ServerInstance->SNO.WriteGlobalSno('l', "\002ERROR\002: Your clocks are off by {} seconds (this is more than fifteen seconds). Link aborted, \002PLEASE SYNC YOUR CLOCKS!\002", labs((long)delta)); ServerInstance->SNO.WriteGlobalSno('l', "\002ERROR\002: Your clocks are off by {} seconds (this is more than fifteen seconds). Link aborted, \002PLEASE SYNC YOUR CLOCKS!\002", delta);
SendError("Your clocks are out by "+ConvToStr(labs((long)delta))+" seconds (this is more than fifteen seconds). Link aborted, PLEASE SYNC YOUR CLOCKS!"); SendError(INSP_FORMAT("Your clocks are out by {} seconds (this is more than fifteen seconds). Link aborted, PLEASE SYNC YOUR CLOCKS!", delta));
return; return;
} }
else if ((delta < -5) || (delta > 5)) else if ((delta < -5) || (delta > 5))

View File

@ -301,7 +301,7 @@ void SpanningTreeUtilities::ReadConfiguration()
throw ModuleException((Module*)Creator, "The link name '"+L->Name+"' is invalid as it must contain at least one '.' character"); throw ModuleException((Module*)Creator, "The link name '"+L->Name+"' is invalid as it must contain at least one '.' character");
if (L->Name.length() > ServerInstance->Config->Limits.MaxHost) if (L->Name.length() > ServerInstance->Config->Limits.MaxHost)
throw ModuleException((Module*)Creator, "The link name '"+L->Name+"' is invalid as it is longer than " + ConvToStr(ServerInstance->Config->Limits.MaxHost) + " characters"); throw ModuleException((Module*)Creator, INSP_FORMAT("The link name '{}' is invalid as it is longer than {} characters", L->Name, ServerInstance->Config->Limits.MaxHost));
if (L->RecvPass.empty()) if (L->RecvPass.empty())
throw ModuleException((Module*)Creator, "Invalid configuration for server '"+L->Name+"', recvpass not defined"); throw ModuleException((Module*)Creator, "Invalid configuration for server '"+L->Name+"', recvpass not defined");

View File

@ -124,7 +124,7 @@ public:
* -- w00t * -- w00t
*/ */
ServerInstance->Logs.Debug(MODNAME, "Opening temporary database"); ServerInstance->Logs.Debug(MODNAME, "Opening temporary database");
const std::string xlinenewdbpath = xlinedbpath + ".new." + ConvToStr(ServerInstance->Time()); const auto xlinenewdbpath = INSP_FORMAT("{}.new.{}", xlinedbpath, ServerInstance->Time());
std::ofstream stream(xlinenewdbpath); std::ofstream stream(xlinenewdbpath);
if (!stream.is_open()) if (!stream.is_open())
{ {

View File

@ -100,7 +100,7 @@ void Snomask::Flush()
if (Count > 1) if (Count > 1)
{ {
std::string desc = GetDescription(LastLetter); std::string desc = GetDescription(LastLetter);
std::string msg = "(last message repeated " + ConvToStr(Count) + " times)"; std::string msg = INSP_FORMAT("(last message repeated {} times)", Count);
FOREACH_MOD(OnSendSnotice, (LastLetter, desc, msg)); FOREACH_MOD(OnSendSnotice, (LastLetter, desc, msg));
Snomask::Send(LastLetter, desc, msg); Snomask::Send(LastLetter, desc, msg);

View File

@ -120,7 +120,7 @@ size_t InspIRCd::BindPorts(FailedPortList& failed_ports)
// Check if the port is out of range. // Check if the port is out of range.
if (port <= std::numeric_limits<in_port_t>::min() || port > std::numeric_limits<in_port_t>::max()) if (port <= std::numeric_limits<in_port_t>::min() || port > std::numeric_limits<in_port_t>::max())
{ {
failed_ports.emplace_back("Port is not valid: " + ConvToStr(port), bindspec, tag); failed_ports.emplace_back(INSP_FORMAT("Port is not valid: {}", port), bindspec, tag);
continue; continue;
} }

View File

@ -65,7 +65,7 @@ namespace
if (!user->lastping) if (!user->lastping)
{ {
time_t secs = ServerInstance->Time() - (user->nextping - user->GetClass()->pingtime); time_t secs = ServerInstance->Time() - (user->nextping - user->GetClass()->pingtime);
const std::string message = "Ping timeout: " + ConvToStr(secs) + (secs != 1 ? " seconds" : " second"); const std::string message = INSP_FORMAT("Ping timeout: {} {}", secs, (secs != 1 ? "seconds" : "second"));
ServerInstance->Users.QuitUser(user, message); ServerInstance->Users.QuitUser(user, message);
return; return;
} }