You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#include "serverConf.h"
#include <cstdlib>
namespace mtx {
bool parseDurationMs(const std::string & s, int64_t & ms){ if (s.empty()) { return false; } char * tEnd = nullptr; double tV = strtod(s.c_str(), &tEnd); if (tEnd == s.c_str() || tV < 0) { return false; } std::string tUnit(tEnd); double tMul; if (tUnit.empty() || tUnit == "s") { tMul = 1000.0; } else if (tUnit == "ms") { tMul = 1.0; } else if (tUnit == "m") { tMul = 60000.0; } else if (tUnit == "h") { tMul = 3600000.0; } else { return false; } ms = (int64_t) (tV * tMul + 0.5); return true;}
bool splitHostPort(const std::string & addr, std::string & host, uint16_t & port){ size_t tColon = addr.rfind(':'); if (tColon == std::string::npos) { return false; } host = addr.substr(0, tColon); int tPort = atoi(addr.c_str() + tColon + 1); if (tPort <= 0 || tPort > 65535) { return false; } port = (uint16_t) tPort; if (host.size() >= 2 && host.front() == '[' && host.back() == ']') { host = host.substr(1, host.size() - 2); } return true;}
std::string hideCredentials(const std::string & url){ size_t tScheme = url.find("://"); if (tScheme == std::string::npos) { return url; } size_t tHostStart = tScheme + 3; size_t tSlash = url.find('/', tHostStart); size_t tAt = url.rfind('@', tSlash == std::string::npos ? url.size() : tSlash); if (tAt == std::string::npos || tAt < tHostStart) { return url; } return url.substr(0, tHostStart) + url.substr(tAt + 1);}
} // namespace mtx
|