@@ -31,7 +31,7 @@ CConfig::CConfig() {
|
||||
NFsUtils::readFileAsString(NFsUtils::isAbsolute(g_pGlobalState->configPath) ? g_pGlobalState->configPath : g_pGlobalState->cwd + "/" + g_pGlobalState->configPath).value());
|
||||
|
||||
if (!json.has_value())
|
||||
throw std::runtime_error("No config / bad config format");
|
||||
Debug::die("No config or config has bad format");
|
||||
|
||||
m_config = json.value();
|
||||
|
||||
@@ -46,7 +46,7 @@ CConfig::CConfig() {
|
||||
parsed.exclude_regex = std::make_unique<re2::RE2>(ic.exclude_regex);
|
||||
if (parsed.exclude_regex->error_code() != RE2::NoError) {
|
||||
Debug::log(CRIT, "Regex \"{}\" failed to parse", ic.exclude_regex);
|
||||
throw std::runtime_error("Failed to parse regex");
|
||||
Debug::die("Failed to parse regex");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "../debug/log.hpp"
|
||||
|
||||
CIP::CIP(const std::string& ip) {
|
||||
if (std::count(ip.begin(), ip.end(), '.') == 3)
|
||||
parseV4(ip);
|
||||
else if (std::count(ip.begin(), ip.end(), ':') >= 2)
|
||||
parseV6(ip);
|
||||
else
|
||||
throw std::runtime_error("IP not valid");
|
||||
Debug::die("Invalid IP: {}", ip);
|
||||
}
|
||||
|
||||
void CIP::parseV4(const std::string& ip) {
|
||||
@@ -32,7 +34,7 @@ void CIP::parseV4(const std::string& ip) {
|
||||
m_blocks.push_back(std::stoul(std::string{curr}));
|
||||
|
||||
if (m_blocks.back() > 0xFF)
|
||||
throw std::runtime_error("Invalid IPv4 byte");
|
||||
Debug::die("Invalid ipv4 byte: {}", curr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,13 +76,13 @@ void CIP::parseV6(const std::string& ip) {
|
||||
m_blocks.push_back(std::stoul(std::string{curr}, nullptr, 16));
|
||||
|
||||
if (m_blocks.back() > 0xFFFF)
|
||||
throw std::runtime_error("Invalid IPv6 byte");
|
||||
Debug::die("Invalid ipv6 byte: {}", curr);
|
||||
}
|
||||
}
|
||||
|
||||
CIPRange::CIPRange(const std::string& range) {
|
||||
if (!range.contains('/'))
|
||||
throw std::runtime_error("Range has no subnet");
|
||||
Debug::die("IP range {} has no subnet", range);
|
||||
|
||||
m_subnet = std::stoul(range.substr(range.find('/') + 1));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user