From 7a59ed2a903dbfafdbd878ac998526f56f44f01b Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 29 Aug 2024 15:22:21 +0100 Subject: Refactor InspIRCd::ProcessColors. --- src/helperfuncs.cpp | 76 ++++++++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 44 deletions(-) (limited to 'src/helperfuncs.cpp') diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 5ccb8ed6c..3e50f6439 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -125,60 +125,48 @@ void InspIRCd::ProcessColors(std::vector& input) ProcessColors(line); } -void InspIRCd::ProcessColors(std::string& ret) +void InspIRCd::ProcessColors(std::string& line) { - /* - * Replace all color codes from the special[] array to actual - * color code chars using C++ style escape sequences. You - * can append other chars to replace if you like -- Justasic - */ - static struct special_chars final + static const insp::flat_map formats = { + { '\\', "\\" }, // Escape + { 'b', "\x02" }, // Bold + { 'c', "\x03" }, // Color + { 'h', "\x04" }, // Hex Color + { 'i', "\x1D" }, // Italic + { 'm', "\x11" }, // Monospace + { 'r', "\x16" }, // Reverse + { 's', "\x1E" }, // Strikethrough + { 'u', "\x1F" }, // Underline + { 'x', "\x0F" }, // Reset + }; + + for (size_t idx = 0; idx < line.length(); ) { - std::string character; - std::string replace; - special_chars(const std::string& c, const std::string& r) - : character(c) - , replace(r) + if (line[idx] != '\\') { + // Regular character. + idx++; + continue; } - } special[] = { - special_chars("\\b", "\x02"), // Bold - special_chars("\\c", "\x03"), // Color - special_chars("\\h", "\x04"), // Hex Color - special_chars("\\i", "\x1D"), // Italic - special_chars("\\m", "\x11"), // Monospace - special_chars("\\r", "\x16"), // Reverse - special_chars("\\s", "\x1E"), // Strikethrough - special_chars("\\u", "\x1F"), // Underline - special_chars("\\x", "\x0F"), // Reset - special_chars("", "") - }; - { - for(int i = 0; !special[i].character.empty(); ++i) + auto start = idx; + if (++idx >= line.length()) { - std::string::size_type pos = ret.find(special[i].character); - if(pos == std::string::npos) // Couldn't find the character, skip this line - continue; - - if((pos > 0) && (ret[pos-1] == '\\') && (ret[pos] == '\\')) - continue; // Skip double slashes. - - // Replace all our characters in the array - while(pos != std::string::npos) - { - ret = ret.substr(0, pos) + special[i].replace + ret.substr(pos + special[i].character.size()); - pos = ret.find(special[i].character, pos + special[i].replace.size()); - } + // Stray \ at the end of the string; strip. + line.pop_back(); + continue; } - // Replace double slashes with a single slash before we return - std::string::size_type pos = ret.find("\\\\"); - while(pos != std::string::npos) + const auto it = formats.find(line[idx]); + if (it == formats.end()) { - ret = ret.substr(0, pos) + "\\" + ret.substr(pos + 2); - pos = ret.find("\\\\", pos + 1); + // Unknown escape, strip. + line.erase(start, 2); + continue; } + + line.replace(start, 2, it->second); + idx = start + it->second.length(); } } -- cgit v1.3.1-10-gc9f91 From baad39b85c8516fa44fd55053c630ce3b98c97ba Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 29 Aug 2024 22:25:20 +0100 Subject: Allow using color codes by name in MOTD files. --- docs/conf/inspircd.example.conf | 7 +++++ src/helperfuncs.cpp | 63 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) (limited to 'src/helperfuncs.cpp') diff --git a/docs/conf/inspircd.example.conf b/docs/conf/inspircd.example.conf index d0bdd0f25..5a35931d7 100644 --- a/docs/conf/inspircd.example.conf +++ b/docs/conf/inspircd.example.conf @@ -353,6 +353,7 @@ # used in your MOTD: # Bold: \b # Color: \c[,] + # Color (alt): \c{[,]} # Hex Color: \h[,] # Italic: \i # Monospace: \m (not widely supported) @@ -360,6 +361,12 @@ # Reverse: \r # Strikethrough: \s (not widely supported) # Underline: \u + # + # When using the alternate color syntax the following colors can be used: + # black, blue, brown, cyan, default, green, grey, light blue, + # light cyan, light green, light grey, magenta orange, pink, + # red, white, yellow. + # # See https://defs.ircdocs.horse/info/formatting.html for more information # on client support for formatting characters. motd="secretmotd" diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 3e50f6439..373531b80 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -139,6 +139,27 @@ void InspIRCd::ProcessColors(std::string& line) { 'u', "\x1F" }, // Underline { 'x', "\x0F" }, // Reset }; + static const insp::flat_map colors = { + { "white", 0 }, + { "black", 1 }, + { "blue", 2 }, + { "green", 3 }, + { "red", 4 }, + { "brown", 5 }, + { "magenta", 6 }, + { "orange", 7 }, + { "yellow", 8 }, + { "light green", 9 }, + { "cyan", 10 }, + { "light cyan", 11 }, + { "light blue", 12 }, + { "pink", 13 }, + { "gray", 14 }, + { "grey", 14 }, + { "light gray", 15 }, + { "light grey", 15 }, + { "default", 99 }, + }; for (size_t idx = 0; idx < line.length(); ) { @@ -157,7 +178,8 @@ void InspIRCd::ProcessColors(std::string& line) continue; } - const auto it = formats.find(line[idx]); + const auto chr = line[idx]; + const auto it = formats.find(chr); if (it == formats.end()) { // Unknown escape, strip. @@ -167,6 +189,45 @@ void InspIRCd::ProcessColors(std::string& line) line.replace(start, 2, it->second); idx = start + it->second.length(); + + if (chr != 'c') + continue; // Only colors can have values. + + start = idx; + if (idx >= line.length() || line[idx] != '{') + continue; // No color value. + + const auto fgend = line.find_first_of(",}", idx + 1); + if (fgend == std::string::npos) + { + // Malformed color value, strip. + line.erase(start); + break; + } + + size_t bgend = std::string::npos; + if (line[fgend] == ',') + { + bgend = line.find_first_of("}", fgend + 1); + if (bgend == std::string::npos) + { + // Malformed color value, strip. + line.erase(start); + break; + } + } + + const auto fg = colors.find(line.substr(start + 1, fgend - start - 1)); + auto tmp = ConvToStr(fg == colors.end() ? 99 : fg->second); + if (bgend != std::string::npos) + { + const auto bg = colors.find(line.substr(fgend + 1, bgend - fgend - 1)); + tmp.push_back(','); + tmp.append(ConvToStr(bg == colors.end() ? 99 : bg->second)); + } + + const auto end = bgend == std::string::npos ? fgend : bgend; + line.replace(start, end - start + 1, tmp); } } -- cgit v1.3.1-10-gc9f91 From af6a690f52e24dbf628ff7f65294e5612905696a Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 30 Aug 2024 09:32:44 +0100 Subject: Add MOTD escape sequences for { and }. --- src/helperfuncs.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/helperfuncs.cpp') diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 373531b80..0397b485c 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -129,6 +129,8 @@ void InspIRCd::ProcessColors(std::string& line) { static const insp::flat_map formats = { { '\\', "\\" }, // Escape + { '{', "{" }, // Escape + { '}', "}" }, // Escape { 'b', "\x02" }, // Bold { 'c', "\x03" }, // Color { 'h', "\x04" }, // Hex Color -- cgit v1.3.1-10-gc9f91 From babb39cb171ad975279101d83f3f92da2fe02953 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 30 Aug 2024 16:53:41 +0100 Subject: Refactor InspIRCd::StripColor. - Only strip characters we actually recognise. - Strip the value for hex color codes. --- docs/conf/modules.example.conf | 4 +-- src/helperfuncs.cpp | 62 ++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 23 deletions(-) (limited to 'src/helperfuncs.cpp') diff --git a/docs/conf/modules.example.conf b/docs/conf/modules.example.conf index 88dfc4a51..b59f1291c 100644 --- a/docs/conf/modules.example.conf +++ b/docs/conf/modules.example.conf @@ -2588,8 +2588,8 @@ # #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# -# Strip color module: Adds channel mode +S that strips color codes and -# all control codes except CTCP from all messages sent to the channel. +# Strip color module: Adds channel mode +S that strips IRC formatting +# characters from all messages sent to the channel. # #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 0397b485c..34ef2cee3 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -91,31 +91,51 @@ bool InspIRCd::IsValidMask(const std::string& mask) return true; } -void InspIRCd::StripColor(std::string& sentence) +void InspIRCd::StripColor(std::string& line) { - /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */ - int seq = 0; - - for (std::string::iterator i = sentence.begin(); i != sentence.end();) + for (size_t idx = 0; idx < line.length(); ) { - if (*i == 3) - seq = 1; - else if (seq && (( ((*i >= '0') && (*i <= '9')) || (*i == ',') ) )) + switch (line[idx]) { - seq++; - if ( (seq <= 4) && (*i == ',') ) - seq = 1; - else if (seq > 3) - seq = 0; - } - else - seq = 0; + case '\x02': // Bold + case '\x1D': // Italic + case '\x11': // Monospace + case '\x16': // Reverse + case '\x1E': // Strikethrough + case '\x1F': // Underline + case '\x0F': // Reset + line.erase(idx, 1); + break; - // Strip all control codes too except \001 for CTCP - if (seq || ((*i >= 0) && (*i < 32) && (*i != 1))) - i = sentence.erase(i); - else - ++i; + case '\x03': // Color + { + auto start = idx; + while (++idx < line.length() && idx - start < 6) + { + const auto chr = line[idx]; + if (chr != ',' && (chr < '0' || chr > '9')) + break; + } + line.erase(start, idx - start); + break; + } + case '\x04': // Hex Color + { + auto start = idx; + while (++idx < line.length() && idx - start < 14) + { + const auto chr = line[idx]; + if (chr != ',' && (chr < '0' || chr > '9') && (chr < 'A' || chr > 'F') && (chr < 'a' || chr > 'f')) + break; + } + line.erase(start, idx - start); + break; + } + + default: // Non-formatting character. + idx++; + break; + } } } -- cgit v1.3.1-10-gc9f91 From 0e603bab1d953c947f7c5c39e9d441eaeaaebcfe Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 31 Aug 2024 15:41:35 +0100 Subject: Minor performance improvement to ProcessColors. --- src/helperfuncs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/helperfuncs.cpp') diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 34ef2cee3..8ee71a4df 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -230,7 +230,7 @@ void InspIRCd::ProcessColors(std::string& line) size_t bgend = std::string::npos; if (line[fgend] == ',') { - bgend = line.find_first_of("}", fgend + 1); + bgend = line.find_first_of('}', fgend + 1); if (bgend == std::string::npos) { // Malformed color value, strip. -- cgit v1.3.1-10-gc9f91 From faa96b795628bf2d37fee308c05569e1be79b3ae Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 2 Sep 2024 10:40:47 +0100 Subject: Fix a regression in ProcessColors. We should wait until v5 to be this aggressive with MOTD parsing so we dont break existing users in a minor release. --- src/helperfuncs.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src/helperfuncs.cpp') diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 8ee71a4df..a8fc3e541 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -194,20 +194,12 @@ void InspIRCd::ProcessColors(std::string& line) auto start = idx; if (++idx >= line.length()) - { - // Stray \ at the end of the string; strip. - line.pop_back(); - continue; - } + continue; // Stray \ at the end of the string; skip. const auto chr = line[idx]; const auto it = formats.find(chr); if (it == formats.end()) - { - // Unknown escape, strip. - line.erase(start, 2); - continue; - } + continue; // Unknown escape, skip. line.replace(start, 2, it->second); idx = start + it->second.length(); -- cgit v1.3.1-10-gc9f91 From 8e784862f5f251154a414fa17645caa644c5e4b2 Mon Sep 17 00:00:00 2001 From: InspIRCd Robot Date: Sat, 7 Sep 2024 11:10:36 +0100 Subject: Update copyright headers. --- configure | 1 - include/inspircd.h | 5 ++--- include/logging.h | 2 +- include/membership.h | 2 +- include/mode.h | 2 +- include/modules/ircv3_replies.h | 2 +- include/snomasks.h | 2 +- include/socket.h | 2 +- include/streamsocket.h | 2 +- include/xline.h | 2 +- make/template/inspircd | 2 +- src/channels.cpp | 2 +- src/commands.cpp | 2 +- src/coremods/core_channel/cmd_invite.cpp | 2 +- src/coremods/core_channel/cmd_topic.cpp | 2 +- src/coremods/core_channel/core_channel.cpp | 2 +- src/coremods/core_mode.cpp | 2 +- src/coremods/core_oper/cmd_kill.cpp | 2 +- src/coremods/core_stats.cpp | 2 +- src/coremods/core_user/cmd_nick.cpp | 2 +- src/coremods/core_user/cmd_user.cpp | 2 +- src/coremods/core_user/core_user.cpp | 2 +- src/coremods/core_whowas.cpp | 3 +-- src/coremods/core_xline/core_xline.cpp | 2 +- src/helperfuncs.cpp | 4 ++-- src/listensocket.cpp | 2 +- src/modules/m_bcrypt.cpp | 2 +- src/modules/m_cloak_md5.cpp | 2 +- src/modules/m_override.cpp | 4 ++-- src/modules/m_password_hash.cpp | 2 +- src/modules/m_pbkdf2.cpp | 2 +- src/modules/m_remove.cpp | 2 +- src/modules/m_satopic.cpp | 2 +- src/modules/m_securelist.cpp | 2 +- src/modules/m_showwhois.cpp | 2 +- src/modules/m_spanningtree/rconnect.cpp | 2 +- src/modules/m_spanningtree/rsquit.cpp | 2 +- src/modules/m_sqloper.cpp | 2 +- src/modules/m_tline.cpp | 2 +- src/modules/m_uninvite.cpp | 2 +- src/snomasks.cpp | 2 +- src/streamsocket.cpp | 2 +- src/usermanager.cpp | 2 +- 43 files changed, 45 insertions(+), 48 deletions(-) (limited to 'src/helperfuncs.cpp') diff --git a/configure b/configure index 1036bfb8b..b9cd6dcb8 100755 --- a/configure +++ b/configure @@ -2,7 +2,6 @@ # # InspIRCd -- Internet Relay Chat Daemon # -# Copyright (C) 2020 Daniel Vassdal # Copyright (C) 2019 Matt Schatz # Copyright (C) 2013-2022, 2024 Sadie Powell # Copyright (C) 2012, 2019 Robby diff --git a/include/inspircd.h b/include/inspircd.h index c7364f7a8..9ac5e49d9 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -1,10 +1,9 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2019 Matt Schatz * Copyright (C) 2012-2016, 2018 Attila Molnar - * Copyright (C) 2012-2013, 2017-2023 Sadie Powell - * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2012-2013, 2017-2024 Sadie Powell + * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2007-2009 Dennis Friis diff --git a/include/logging.h b/include/logging.h index 3f2a1015d..7d58a2cd7 100644 --- a/include/logging.h +++ b/include/logging.h @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2022-2023 Sadie Powell + * Copyright (C) 2022-2024 Sadie Powell * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public diff --git a/include/membership.h b/include/membership.h index a7dfe5a21..fc09d3b6b 100644 --- a/include/membership.h +++ b/include/membership.h @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2013-2014, 2016 Attila Molnar - * Copyright (C) 2013, 2017-2018, 2021-2022 Sadie Powell + * Copyright (C) 2013, 2017-2018, 2021-2022, 2024 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2009 Daniel De Graaf * diff --git a/include/mode.h b/include/mode.h index 8c55ba066..90a1eba5e 100644 --- a/include/mode.h +++ b/include/mode.h @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2013-2016 Attila Molnar - * Copyright (C) 2012-2013, 2017-2023 Sadie Powell + * Copyright (C) 2012-2013, 2017-2024 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2009 Daniel De Graaf * Copyright (C) 2008 Thomas Stagner diff --git a/include/modules/ircv3_replies.h b/include/modules/ircv3_replies.h index c92e257e9..d2055fda0 100644 --- a/include/modules/ircv3_replies.h +++ b/include/modules/ircv3_replies.h @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2019-2023 Sadie Powell + * Copyright (C) 2019-2022, 2024 Sadie Powell * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public diff --git a/include/snomasks.h b/include/snomasks.h index 1a6242128..3314529ec 100644 --- a/include/snomasks.h +++ b/include/snomasks.h @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2013, 2017, 2020-2021, 2023 Sadie Powell + * Copyright (C) 2013, 2017, 2020-2021, 2023-2024 Sadie Powell * Copyright (C) 2013 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/include/socket.h b/include/socket.h index 54d0b6e3f..a7a3b6a5c 100644 --- a/include/socket.h +++ b/include/socket.h @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2013, 2015-2016 Attila Molnar - * Copyright (C) 2012-2013, 2017-2023 Sadie Powell + * Copyright (C) 2012-2013, 2017-2024 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/include/streamsocket.h b/include/streamsocket.h index f6594fa36..f246415f6 100644 --- a/include/streamsocket.h +++ b/include/streamsocket.h @@ -5,7 +5,7 @@ * Copyright (C) 2020 Matt Schatz * Copyright (C) 2019 linuxdaemon * Copyright (C) 2013, 2015-2016 Attila Molnar - * Copyright (C) 2012-2013, 2017-2023 Sadie Powell + * Copyright (C) 2012-2013, 2017-2024 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2009 Daniel De Graaf * Copyright (C) 2007-2009 Robin Burchell diff --git a/include/xline.h b/include/xline.h index b9e0027e8..248129e29 100644 --- a/include/xline.h +++ b/include/xline.h @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2019 Matt Schatz - * Copyright (C) 2012-2013, 2018-2023 Sadie Powell + * Copyright (C) 2012-2013, 2018-2024 Sadie Powell * Copyright (C) 2012, 2019 Robby * Copyright (C) 2009 Daniel De Graaf * Copyright (C) 2007-2008 Robin Burchell diff --git a/make/template/inspircd b/make/template/inspircd index e1e452cca..ad8a34a85 100644 --- a/make/template/inspircd +++ b/make/template/inspircd @@ -5,8 +5,8 @@ # # Copyright (C) 2015 Steven Van Acker # Copyright (C) 2015 Attila Molnar +# Copyright (C) 2014, 2016, 2019-2021, 2023-2024 Sadie Powell # Copyright (C) 2014 Dan Parsons -# Copyright (C) 2013-2014, 2016-2017, 2019-2021, 2023-2024 Sadie Powell # Copyright (C) 2012 Robby # Copyright (C) 2011 DjSlash # Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/channels.cpp b/src/channels.cpp index ec88cf244..66cc2150c 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2013-2016, 2018 Attila Molnar - * Copyright (C) 2013, 2016-2023 Sadie Powell + * Copyright (C) 2013, 2016-2024 Sadie Powell * Copyright (C) 2013 Adam * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/commands.cpp b/src/commands.cpp index 85ee41a1a..b2a5b2317 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2021 Herman - * Copyright (C) 2018-2023 Sadie Powell + * Copyright (C) 2018-2024 Sadie Powell * Copyright (C) 2012-2016, 2018 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/coremods/core_channel/cmd_invite.cpp b/src/coremods/core_channel/cmd_invite.cpp index 61f717142..4fbf06052 100644 --- a/src/coremods/core_channel/cmd_invite.cpp +++ b/src/coremods/core_channel/cmd_invite.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018, 2020-2023 Sadie Powell + * Copyright (C) 2018, 2020-2024 Sadie Powell * Copyright (C) 2018 linuxdaemon * Copyright (C) 2017 B00mX0r * Copyright (C) 2013-2016, 2018 Attila Molnar diff --git a/src/coremods/core_channel/cmd_topic.cpp b/src/coremods/core_channel/cmd_topic.cpp index c4f5b3f90..c2a839ea6 100644 --- a/src/coremods/core_channel/cmd_topic.cpp +++ b/src/coremods/core_channel/cmd_topic.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2019 Matt Schatz - * Copyright (C) 2017-2018, 2020-2023 Sadie Powell + * Copyright (C) 2017-2018, 2020-2024 Sadie Powell * Copyright (C) 2017 B00mX0r * Copyright (C) 2013-2016 Attila Molnar * Copyright (C) 2012 Robby diff --git a/src/coremods/core_channel/core_channel.cpp b/src/coremods/core_channel/core_channel.cpp index 0c2e5db3f..69c413e1a 100644 --- a/src/coremods/core_channel/core_channel.cpp +++ b/src/coremods/core_channel/core_channel.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2019 Robby * Copyright (C) 2018 linuxdaemon * Copyright (C) 2018 Dylan Frank - * Copyright (C) 2017-2023 Sadie Powell + * Copyright (C) 2017-2024 Sadie Powell * Copyright (C) 2014-2015, 2018 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can diff --git a/src/coremods/core_mode.cpp b/src/coremods/core_mode.cpp index 7b4c9b62a..44c9c87b6 100644 --- a/src/coremods/core_mode.cpp +++ b/src/coremods/core_mode.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2021 Andrio Celos * Copyright (C) 2021 Andrio Celos * Copyright (C) 2019 linuxdaemon - * Copyright (C) 2018-2023 Sadie Powell + * Copyright (C) 2018-2024 Sadie Powell * Copyright (C) 2017 B00mX0r * Copyright (C) 2014-2016 Attila Molnar * diff --git a/src/coremods/core_oper/cmd_kill.cpp b/src/coremods/core_oper/cmd_kill.cpp index 602490ef0..0ad782245 100644 --- a/src/coremods/core_oper/cmd_kill.cpp +++ b/src/coremods/core_oper/cmd_kill.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2017-2023 Sadie Powell + * Copyright (C) 2017-2024 Sadie Powell * Copyright (C) 2016 Adam * Copyright (C) 2012-2014, 2016, 2018 Attila Molnar * Copyright (C) 2012 Robby diff --git a/src/coremods/core_stats.cpp b/src/coremods/core_stats.cpp index 5cdb28659..7984fc224 100644 --- a/src/coremods/core_stats.cpp +++ b/src/coremods/core_stats.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2018 Puck Meerburg - * Copyright (C) 2016, 2018-2023 Sadie Powell + * Copyright (C) 2016, 2018-2024 Sadie Powell * Copyright (C) 2012-2016 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX diff --git a/src/coremods/core_user/cmd_nick.cpp b/src/coremods/core_user/cmd_nick.cpp index 65712d952..b940ed2f3 100644 --- a/src/coremods/core_user/cmd_nick.cpp +++ b/src/coremods/core_user/cmd_nick.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2014, 2016 Attila Molnar - * Copyright (C) 2013, 2016, 2018, 2020-2023 Sadie Powell + * Copyright (C) 2013, 2016, 2018, 2020-2024 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2007-2008 Robin Burchell diff --git a/src/coremods/core_user/cmd_user.cpp b/src/coremods/core_user/cmd_user.cpp index a74d22ff7..37761e9a0 100644 --- a/src/coremods/core_user/cmd_user.cpp +++ b/src/coremods/core_user/cmd_user.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2017-2018, 2020, 2022-2023 Sadie Powell + * Copyright (C) 2017-2018, 2020, 2022-2024 Sadie Powell * Copyright (C) 2014-2015 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009 Daniel De Graaf diff --git a/src/coremods/core_user/core_user.cpp b/src/coremods/core_user/core_user.cpp index a47946eac..20f679862 100644 --- a/src/coremods/core_user/core_user.cpp +++ b/src/coremods/core_user/core_user.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2017-2023 Sadie Powell + * Copyright (C) 2017-2024 Sadie Powell * Copyright (C) 2014-2015, 2018 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can diff --git a/src/coremods/core_whowas.cpp b/src/coremods/core_whowas.cpp index 9130d4647..e657c28ab 100644 --- a/src/coremods/core_whowas.cpp +++ b/src/coremods/core_whowas.cpp @@ -2,8 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2022 Val Lorentz - * Copyright (C) 2021 Dominic Hamon - * Copyright (C) 2017-2023 Sadie Powell + * Copyright (C) 2017-2024 Sadie Powell * Copyright (C) 2012, 2014-2016 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009 Uli Schlachter diff --git a/src/coremods/core_xline/core_xline.cpp b/src/coremods/core_xline/core_xline.cpp index 7ef4632fe..6f5a2b014 100644 --- a/src/coremods/core_xline/core_xline.cpp +++ b/src/coremods/core_xline/core_xline.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2019-2023 Sadie Powell + * Copyright (C) 2019-2024 Sadie Powell * Copyright (C) 2019 linuxdaemon * Copyright (C) 2019 Robby * Copyright (C) 2019 Matt Schatz diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index a8fc3e541..d3356039d 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -3,9 +3,9 @@ * * Copyright (C) 2019 Matt Schatz * Copyright (C) 2018 linuxdaemon - * Copyright (C) 2012-2013, 2015 Attila Molnar - * Copyright (C) 2012, 2018 Robby + * Copyright (C) 2012-2013 Attila Molnar * Copyright (C) 2012, 2014, 2017-2018, 2020-2024 Sadie Powell + * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2007 Dennis Friis diff --git a/src/listensocket.cpp b/src/listensocket.cpp index 3c9c3418e..64540c58d 100644 --- a/src/listensocket.cpp +++ b/src/listensocket.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2021 Dominic Hamon * Copyright (C) 2019-2020 Matt Schatz * Copyright (C) 2013-2016 Attila Molnar - * Copyright (C) 2013, 2016-2023 Sadie Powell + * Copyright (C) 2013, 2016-2024 Sadie Powell * Copyright (C) 2013 Daniel Vassdal * Copyright (C) 2012 Robby * Copyright (C) 2012 ChrisTX diff --git a/src/modules/m_bcrypt.cpp b/src/modules/m_bcrypt.cpp index 39dd757c3..131a4aaf2 100644 --- a/src/modules/m_bcrypt.cpp +++ b/src/modules/m_bcrypt.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2021 Dominic Hamon - * Copyright (C) 2018-2023 Sadie Powell + * Copyright (C) 2018-2024 Sadie Powell * Copyright (C) 2014 Daniel Vassdal * * This file is part of InspIRCd. InspIRCd is free software: you can diff --git a/src/modules/m_cloak_md5.cpp b/src/modules/m_cloak_md5.cpp index 1c301b613..4cb93ea66 100644 --- a/src/modules/m_cloak_md5.cpp +++ b/src/modules/m_cloak_md5.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2019 B00mX0r * Copyright (C) 2017 Sheogorath * Copyright (C) 2016 Adam - * Copyright (C) 2013, 2017-2019, 2021-2023 Sadie Powell + * Copyright (C) 2013, 2017-2019, 2021-2024 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2008 Robin Burchell diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp index d54a14ebd..1bdb3ba81 100644 --- a/src/modules/m_override.cpp +++ b/src/modules/m_override.cpp @@ -3,9 +3,9 @@ * * Copyright (C) 2020 satmd * Copyright (C) 2017 B00mX0r - * Copyright (C) 2013, 2019-2023 Sadie Powell + * Copyright (C) 2013-2015 Attila Molnar + * Copyright (C) 2013, 2019-2024 Sadie Powell * Copyright (C) 2013 Daniel Vassdal - * Copyright (C) 2012-2015 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009 Daniel De Graaf * Copyright (C) 2008 Robin Burchell diff --git a/src/modules/m_password_hash.cpp b/src/modules/m_password_hash.cpp index 63731834a..80b1e8395 100644 --- a/src/modules/m_password_hash.cpp +++ b/src/modules/m_password_hash.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2014 Daniel Vassdal - * Copyright (C) 2013, 2017, 2019-2023 Sadie Powell + * Copyright (C) 2013, 2017, 2019-2024 Sadie Powell * Copyright (C) 2012, 2014 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/modules/m_pbkdf2.cpp b/src/modules/m_pbkdf2.cpp index 63808804b..d13740128 100644 --- a/src/modules/m_pbkdf2.cpp +++ b/src/modules/m_pbkdf2.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2021 Dominic Hamon - * Copyright (C) 2018-2023 Sadie Powell + * Copyright (C) 2018-2024 Sadie Powell * Copyright (C) 2018 linuxdaemon * Copyright (C) 2014, 2020 Daniel Vassdal * Copyright (C) 2014, 2016 Attila Molnar diff --git a/src/modules/m_remove.cpp b/src/modules/m_remove.cpp index 9646873b5..cfae80e4f 100644 --- a/src/modules/m_remove.cpp +++ b/src/modules/m_remove.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2017 B00mX0r - * Copyright (C) 2013, 2018-2023 Sadie Powell + * Copyright (C) 2013, 2018-2024 Sadie Powell * Copyright (C) 2012-2014 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2012 Justin Crawford diff --git a/src/modules/m_satopic.cpp b/src/modules/m_satopic.cpp index 1046d0157..d43b8cae5 100644 --- a/src/modules/m_satopic.cpp +++ b/src/modules/m_satopic.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2019-2023 Sadie Powell + * Copyright (C) 2019-2024 Sadie Powell * Copyright (C) 2017 B00mX0r * Copyright (C) 2016 Attila Molnar * Copyright (C) 2012 Robby diff --git a/src/modules/m_securelist.cpp b/src/modules/m_securelist.cpp index 2c8c3d6eb..06943ac57 100644 --- a/src/modules/m_securelist.cpp +++ b/src/modules/m_securelist.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2021 Dominic Hamon - * Copyright (C) 2018-2023 Sadie Powell + * Copyright (C) 2018-2024 Sadie Powell * Copyright (C) 2018 linuxdaemon * Copyright (C) 2013, 2016 Attila Molnar * Copyright (C) 2012 Robby diff --git a/src/modules/m_showwhois.cpp b/src/modules/m_showwhois.cpp index 7216c8b13..2099ad25f 100644 --- a/src/modules/m_showwhois.cpp +++ b/src/modules/m_showwhois.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018-2023 Sadie Powell + * Copyright (C) 2018-2024 Sadie Powell * Copyright (C) 2012-2015 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/modules/m_spanningtree/rconnect.cpp b/src/modules/m_spanningtree/rconnect.cpp index f79ed8d17..b22527708 100644 --- a/src/modules/m_spanningtree/rconnect.cpp +++ b/src/modules/m_spanningtree/rconnect.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2013, 2018, 2020, 2023 Sadie Powell + * Copyright (C) 2013, 2018, 2020, 2023-2024 Sadie Powell * Copyright (C) 2012-2013 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/modules/m_spanningtree/rsquit.cpp b/src/modules/m_spanningtree/rsquit.cpp index 97155957c..b279647f4 100644 --- a/src/modules/m_spanningtree/rsquit.cpp +++ b/src/modules/m_spanningtree/rsquit.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018, 2020, 2023 Sadie Powell + * Copyright (C) 2018, 2020, 2023-2024 Sadie Powell * Copyright (C) 2013 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf diff --git a/src/modules/m_sqloper.cpp b/src/modules/m_sqloper.cpp index 0e30d1745..0cd2a4135 100644 --- a/src/modules/m_sqloper.cpp +++ b/src/modules/m_sqloper.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2019 B00mX0r * Copyright (C) 2018 Dylan Frank * Copyright (C) 2014, 2018 Attila Molnar - * Copyright (C) 2013, 2017-2023 Sadie Powell + * Copyright (C) 2013, 2017-2024 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2009 Uli Schlachter diff --git a/src/modules/m_tline.cpp b/src/modules/m_tline.cpp index 8b0fbf675..03732ad2b 100644 --- a/src/modules/m_tline.cpp +++ b/src/modules/m_tline.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2019-2023 Sadie Powell + * Copyright (C) 2019-2024 Sadie Powell * Copyright (C) 2014 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009 Daniel De Graaf diff --git a/src/modules/m_uninvite.cpp b/src/modules/m_uninvite.cpp index c79a0c760..5b353528c 100644 --- a/src/modules/m_uninvite.cpp +++ b/src/modules/m_uninvite.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018-2023 Sadie Powell + * Copyright (C) 2018-2024 Sadie Powell * Copyright (C) 2017 B00mX0r * Copyright (C) 2012, 2014-2016 Attila Molnar * Copyright (C) 2012 Robby diff --git a/src/snomasks.cpp b/src/snomasks.cpp index 4ff6ae1be..1285975c0 100644 --- a/src/snomasks.cpp +++ b/src/snomasks.cpp @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2021-2023 Sadie Powell + * Copyright (C) 2021-2024 Sadie Powell * Copyright (C) 2013-2014 Attila Molnar * Copyright (C) 2013 Adam * Copyright (C) 2012 Robby diff --git a/src/streamsocket.cpp b/src/streamsocket.cpp index d9d1a4026..616e507a2 100644 --- a/src/streamsocket.cpp +++ b/src/streamsocket.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2021 Dominic Hamon * Copyright (C) 2020 Matt Schatz * Copyright (C) 2019 linuxdaemon - * Copyright (C) 2018, 2020-2023 Sadie Powell + * Copyright (C) 2018, 2020-2024 Sadie Powell * Copyright (C) 2018 Dylan Frank * Copyright (C) 2013-2016 Attila Molnar * Copyright (C) 2013 Adam diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 46bf5922b..9e5e55467 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2019 iwalkalone * Copyright (C) 2013-2016, 2018 Attila Molnar - * Copyright (C) 2013, 2018-2023 Sadie Powell + * Copyright (C) 2013, 2018-2024 Sadie Powell * Copyright (C) 2013, 2015 Adam * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf -- cgit v1.3.1-10-gc9f91 From 73a98ce7bedfff951244cb4a15eb487073d64e74 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 7 Sep 2024 19:16:48 +0100 Subject: Use string_view in InspIRCd::Is{FQDN,Host,SID}. --- include/inspircd.h | 6 +++--- src/helperfuncs.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/helperfuncs.cpp') diff --git a/include/inspircd.h b/include/inspircd.h index 9ac5e49d9..d9fee746c 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -340,20 +340,20 @@ public: * @param host The hostname to validate. * @return True if the hostname is valid; otherwise, false. */ - inline static auto IsFQDN(const std::string& host) { return IsHost(host, false); } + inline static auto IsFQDN(const std::string_view& host) { return IsHost(host, false); } /** Determines whether a hostname is valid according to RFC 5891 rules. * @param host The hostname to validate. * @param allowsimple Whether to allow simple hostnames (e.g. localhost). * @return True if the hostname is valid; otherwise, false. */ - static bool IsHost(const std::string& host, bool allowsimple); + static bool IsHost(const std::string_view& host, bool allowsimple); /** Determines whether the specified string is a server identifier. * @param sid The string to check. * @return True if the specified string is a server identifier; otherwise, false. */ - static bool IsSID(const std::string& sid); + static bool IsSID(const std::string_view& sid); /** Determines whether the specified string is a valid nick!user\@host mask. * @param mask The string to check. diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index d3356039d..bbb8ad668 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -292,7 +292,7 @@ bool InspIRCd::DefaultIsUser(const std::string_view& n) return true; } -bool InspIRCd::IsHost(const std::string& host, bool allowsimple) +bool InspIRCd::IsHost(const std::string_view& host, bool allowsimple) { // Hostnames must be non-empty and shorter than the maximum hostname length. if (host.empty() || host.length() > ServerInstance->Config->Limits.MaxHost) @@ -301,10 +301,10 @@ bool InspIRCd::IsHost(const std::string& host, bool allowsimple) unsigned int numdashes = 0; unsigned int numdots = 0; bool seendot = false; - const std::string::const_iterator hostend = host.end() - 1; - for (std::string::const_iterator iter = host.begin(); iter != host.end(); ++iter) + const auto hostend = host.end() - 1; + for (auto iter = host.begin(); iter != host.end(); ++iter) { - unsigned char chr = static_cast(*iter); + const auto chr = static_cast(*iter); // If the current character is a label separator. if (chr == '.') @@ -351,7 +351,7 @@ bool InspIRCd::IsHost(const std::string& host, bool allowsimple) return numdots || allowsimple; } -bool InspIRCd::IsSID(const std::string& str) +bool InspIRCd::IsSID(const std::string_view& str) { /* Returns true if the string given is exactly 3 characters long, * starts with a digit, and the other two characters are A-Z or digits -- cgit v1.3.1-10-gc9f91