Fix compilation failure issue caused by lack of regular expression support in gcc 4.8.5 (#3301 #3279)

This commit is contained in:
xiongguangjie 2024-02-19 11:05:30 +08:00 committed by GitHub
parent da5673d1c4
commit 4fb593f4a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1749,8 +1749,12 @@ void installWebApi() {
CHECK(!offer.empty(), "http body(webrtc offer sdp) is empty");
std::string host = allArgs.getParser()["Host"];
std::string localIp = host.substr(0, host.find(':'));
std::regex ipv4Regex("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
if (!std::regex_match(localIp, ipv4Regex)||localIp=="127.0.0.1") {
auto isVaildIP = [](std::string ip)-> bool {
int a,b,c,d;
return sscanf(ip.c_str(),"%d.%d.%d.%d", &a, &b, &c, &d) == 4;
};
if (!isVaildIP(localIp) || localIp=="127.0.0.1") {
localIp = "";
}