From: Otto Moerbeek Date: Wed, 9 Jul 2025 12:39:38 +0000 (+0200) Subject: pubsuffix: tidy and use C++ strings X-Git-Tag: rec-5.4.0-alpha1~317^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16bd01d4c9a2554cfcbb12a20345c56607ba0226;p=thirdparty%2Fpdns.git pubsuffix: tidy and use C++ strings Signed-off-by: Otto Moerbeek --- diff --git a/pdns/recursordist/mkpubsuffixcc b/pdns/recursordist/mkpubsuffixcc index 48de2058ae..e2d8958e1e 100755 --- a/pdns/recursordist/mkpubsuffixcc +++ b/pdns/recursordist/mkpubsuffixcc @@ -9,9 +9,10 @@ temp=$(mktemp pubsuffixXXXXXX) trap "rm -f $temp" 0 1 2 3 15 set -e curl -o $temp -s -S https://publicsuffix.org/list/public_suffix_list.dat -(echo "const char* g_pubsuffix[]={"; +(echo "#include \"pubsuffix.hh\"" + echo "const std::vector g_pubsuffix = {"; for a in $(grep -v "//" "$temp" | grep \\. | egrep "^[.0-9a-z-]*$") do echo \"$a\", done -echo "0};") > "$1" +echo "};") > "$1" diff --git a/pdns/recursordist/pubsuffix.hh b/pdns/recursordist/pubsuffix.hh index cc5f7c4272..1179cec262 100644 --- a/pdns/recursordist/pubsuffix.hh +++ b/pdns/recursordist/pubsuffix.hh @@ -25,6 +25,7 @@ #include extern std::vector> g_pubs; +extern const std::vector g_pubsuffix; /* initialize the g_pubs variable with the public suffix list, using the file passed in parameter if any, or the built-in diff --git a/pdns/recursordist/pubsuffixloader.cc b/pdns/recursordist/pubsuffixloader.cc index 1174a82c56..719151ec9d 100644 --- a/pdns/recursordist/pubsuffixloader.cc +++ b/pdns/recursordist/pubsuffixloader.cc @@ -24,12 +24,10 @@ #include #include "dnsname.hh" -#include "logger.hh" #include "logging.hh" #include "misc.hh" #include "pubsuffix.hh" -extern const char* g_pubsuffix[]; std::vector> g_pubs; void initPublicSuffixList(const std::string& file) @@ -60,36 +58,35 @@ void initPublicSuffixList(const std::string& file) if (name.countLabels() < 2) { continue; } - pbList.push_back(name.labelReverse().getRawLabels()); + pbList.emplace_back(name.labelReverse().getRawLabels()); } catch (...) { /* not a DNS name, ignoring */ + continue; } } - SLOG(g_log << Logger::Info << "Loaded the Public Suffix List from '" << file << "'" << endl, - g_slog->withName("runtime")->info(Logr::Info, "Loaded the Public Suffix List", "file", Logging::Loggable(file))); + g_slog->withName("runtime")->info(Logr::Info, "Loaded the Public Suffix List", "file", Logging::Loggable(file)); loaded = true; } catch (const std::exception& e) { - SLOG(g_log << Logger::Warning << "Error while loading the Public Suffix List from '" << file << "', falling back to the built-in list: " << e.what() << endl, - g_slog->withName("runtime")->error(Logr::Error, e.what(), "Error while loading the Public Suffix List", "file", Logging::Loggable(file))); + g_slog->withName("runtime")->error(Logr::Error, e.what(), "Error while loading the Public Suffix List", "file", Logging::Loggable(file)); } } if (!loaded) { pbList.clear(); - for (const char** p = g_pubsuffix; *p; ++p) { - string low = toLower(*p); - - vector parts; + for (const auto& entry : g_pubsuffix) { + const auto low = toLower(entry); + std::vector parts; stringtok(parts, low, "."); - reverse(parts.begin(), parts.end()); - pbList.push_back(std::move(parts)); + std::reverse(parts.begin(), parts.end()); + parts.shrink_to_fit(); + pbList.emplace_back(std::move(parts)); } } - sort(pbList.begin(), pbList.end()); + std::sort(pbList.begin(), pbList.end()); g_pubs = std::move(pbList); }