diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index 09d8e74..7adc616 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -74,15 +74,14 @@ void explodeVmess(std::string vmess, const std::string &custom_port, nodeInfo &n GetMember(jsondata, "ps", ps); GetMember(jsondata, "add", add); + port = custom_port.size() ? custom_port : GetMember(jsondata, "port"); + if(port == "0") + return; GetMember(jsondata, "type", type); GetMember(jsondata, "id", id); GetMember(jsondata, "aid", aid); GetMember(jsondata, "net", net); GetMember(jsondata, "tls", tls); - if(custom_port.size()) - port = custom_port; - else - GetMember(jsondata, "port", port); GetMember(jsondata, "host", host); switch(to_int(version)) @@ -107,7 +106,7 @@ void explodeVmess(std::string vmess, const std::string &custom_port, nodeInfo &n node.group = V2RAY_DEFAULT_GROUP; node.remarks = ps; node.server = add; - node.port = to_int(port, 0); + node.port = to_int(port, 1); node.proxyStr = vmessConstruct(add, port, type, id, aid, net, "auto", path, host, "", tls); } @@ -137,7 +136,9 @@ void explodeVmessConf(std::string content, const std::string &custom_port, bool { nodejson = json["outbounds"][0]; add = GetMember(nodejson["settings"]["vnext"][0], "address"); - port = GetMember(nodejson["settings"]["vnext"][0], "port"); + port = custom_port.size() ? custom_port : GetMember(nodejson["settings"]["vnext"][0], "port"); + if(port == "0") + return; if(nodejson["settings"]["vnext"][0]["users"].Size()) { id = GetMember(nodejson["settings"]["vnext"][0]["users"][0], "id"); @@ -188,7 +189,7 @@ void explodeVmessConf(std::string content, const std::string &custom_port, bool node.group = V2RAY_DEFAULT_GROUP; node.remarks = add + ":" + port; node.server = add; - node.port = to_int(port); + node.port = to_int(port, 1); nodes.push_back(node); } return; @@ -212,10 +213,9 @@ void explodeVmessConf(std::string content, const std::string &custom_port, bool //common info json["vmess"][i]["remarks"] >> ps; json["vmess"][i]["address"] >> add; - if(custom_port.size()) - port = custom_port; - else - json["vmess"][i]["port"] >> port; + port = custom_port.size() ? custom_port : GetMember(json["vmess"][i], "port"); + if(port == "0") + continue; json["vmess"][i]["subid"] >> subid; if(subid.size()) @@ -264,7 +264,7 @@ void explodeVmessConf(std::string content, const std::string &custom_port, bool node.remarks = ps; node.id = index; node.server = add; - node.port = to_int(port); + node.port = to_int(port, 1); nodes.push_back(node); } return; @@ -328,6 +328,8 @@ void explodeSS(std::string ss, bool libev, const std::string &custom_port, nodeI } if(custom_port.size()) port = custom_port; + if(port == "0") + return; if(ps.empty()) ps = server + ":" + port; @@ -335,7 +337,7 @@ void explodeSS(std::string ss, bool libev, const std::string &custom_port, nodeI node.group = group; node.remarks = ps; node.server = server; - node.port = to_int(port, 0); + node.port = to_int(port, 1); node.proxyStr = ssConstruct(server, port, password, method, plugin, pluginopts, ps, libev); } @@ -405,15 +407,16 @@ void explodeSSD(std::string link, bool libev, const std::string &custom_port, st GetMember(singlenode, "plugin", plugin); GetMember(singlenode, "plugin_options", pluginopts); - if(custom_port.size()) port = custom_port; + if(port == "0") + continue; node.linkType = SPEEDTEST_MESSAGE_FOUNDSS; node.group = group; node.remarks = remarks; node.server = server; - node.port = to_int(port); + node.port = to_int(port, 1); node.proxyStr = ssConstruct(server, port, password, method, plugin, pluginopts, remarks, libev); node.id = index; nodes.push_back(node); @@ -424,6 +427,9 @@ void explodeSSD(std::string link, bool libev, const std::string &custom_port, st void explodeSSAndroid(std::string ss, bool libev, const std::string &custom_port, std::vector &nodes) { + std::string ps, password, method, server, port, group = SS_DEFAULT_GROUP; + std::string plugin, pluginopts; + Document json; nodeInfo node; int index = nodes.size(); @@ -435,17 +441,13 @@ void explodeSSAndroid(std::string ss, bool libev, const std::string &custom_port for(unsigned int i = 0; i < json["nodes"].Size(); i++) { - std::string ps, password, method, server, port, group = SS_DEFAULT_GROUP; - std::string plugin, pluginopts; - server = GetMember(json["nodes"][i], "server"); if(server.empty()) continue; ps = GetMember(json["nodes"][i], "remarks"); - if(custom_port.size()) - port = custom_port; - else - port = GetMember(json["nodes"][i], "server_port"); + port = custom_port.size() ? custom_port : GetMember(json["nodes"][i], "server_port"); + if(port == "0") + continue; if(ps.empty()) ps = server + ":" + port; password = GetMember(json["nodes"][i], "password"); @@ -458,7 +460,7 @@ void explodeSSAndroid(std::string ss, bool libev, const std::string &custom_port node.group = group; node.remarks = ps; node.server = server; - node.port = to_int(port); + node.port = to_int(port, 1); node.proxyStr = ssConstruct(server, port, password, method, plugin, pluginopts, ps, libev); nodes.push_back(node); index++; @@ -479,14 +481,11 @@ void explodeSSConf(std::string content, const std::string &custom_port, bool lib for(unsigned int i = 0; i < json["configs"].Size(); i++) { json["configs"][i]["remarks"] >> ps; - if(custom_port.size()) - port = custom_port; - else - json["configs"][i]["server_port"] >> port; + port = custom_port.size() ? custom_port : GetMember(json["configs"][i], "server_port"); + if(port == "0") + continue; if(ps.empty()) - { ps = server + ":" + port; - } json["configs"][i]["password"] >> password; json["configs"][i]["method"] >> method; @@ -499,7 +498,7 @@ void explodeSSConf(std::string content, const std::string &custom_port, bool lib node.remarks = ps; node.id = index; node.server = server; - node.port = to_int(port); + node.port = to_int(port, 1); node.proxyStr = ssConstruct(server, port, password, method, plugin, pluginopts, ps, libev); nodes.push_back(node); index++; @@ -544,6 +543,8 @@ void explodeSSR(std::string ssr, bool ss_libev, bool ssr_libev, const std::strin password = urlsafe_base64_decode(password); if(custom_port.size()) port = custom_port; + if(port == "0") + return; if(group.empty()) group = SSR_DEFAULT_GROUP; @@ -556,7 +557,7 @@ void explodeSSR(std::string ssr, bool ss_libev, bool ssr_libev, const std::strin node.group = group; node.remarks = remarks; node.server = server; - node.port = to_int(port, 0); + node.port = to_int(port, 1); if(find(ss_ciphers.begin(), ss_ciphers.end(), method) != ss_ciphers.end() && (obfs.empty() || obfs == "plain") && (protocol.empty() || protocol == "origin")) { node.linkType = SPEEDTEST_MESSAGE_FOUNDSS; @@ -586,7 +587,7 @@ void explodeSSRConf(std::string content, const std::string &custom_port, bool ss port = GetMember(json, "server_port"); node.remarks = server + ":" + port; node.server = server; - node.port = to_int(port); + node.port = to_int(port, 1); method = GetMember(json, "method"); obfs = GetMember(json, "obfs"); protocol = GetMember(json, "protocol"); @@ -617,10 +618,9 @@ void explodeSSRConf(std::string content, const std::string &custom_port, bool ss group = SSR_DEFAULT_GROUP; json["configs"][i]["remarks"] >> remarks; json["configs"][i]["server"] >> server; - if(custom_port.size()) - port = custom_port; - else - json["configs"][i]["server_port"] >> port; + port = custom_port.size() ? custom_port : GetMember(json["configs"][i], "server_port"); + if(port == "0") + continue; if(remarks.empty()) remarks = server + ":" + port; @@ -638,7 +638,7 @@ void explodeSSRConf(std::string content, const std::string &custom_port, bool ss node.remarks = remarks; node.id = index; node.server = server; - node.port = to_int(port); + node.port = to_int(port, 1); node.proxyStr = ssrConstruct(group, remarks, remarks_base64, server, port, protocol, method, obfs, password, obfsparam, protoparam, ssr_libev); nodes.push_back(node); index++; @@ -679,12 +679,14 @@ void explodeSocks(std::string link, const std::string &custom_port, nodeInfo &no remarks = server + ":" + port; if(custom_port.size()) port = custom_port; + if(port == "0") + return; node.linkType = SPEEDTEST_MESSAGE_FOUNDSOCKS; node.group = group; node.remarks = remarks; node.server = server; - node.port = to_int(port, 0); + node.port = to_int(port, 1); node.proxyStr = socksConstruct(remarks, server, port, username, password); } @@ -704,12 +706,14 @@ void explodeHTTP(std::string link, const std::string &custom_port, nodeInfo &nod remarks = server + ":" + port; if(custom_port.size()) port = custom_port; + if(port == "0") + return; node.linkType = SPEEDTEST_MESSAGE_FOUNDHTTP; node.group = group; node.remarks = remarks; node.server = server; - node.port = to_int(port, 0); + node.port = to_int(port, 1); node.proxyStr = httpConstruct(remarks, server, port, username, password, strFind(link, "/https")); } @@ -764,12 +768,14 @@ void explodeHTTPSub(std::string link, const std::string &custom_port, nodeInfo & remarks = server + ":" + port; if(custom_port.size()) port = custom_port; + if(port == "0") + return; node.linkType = SPEEDTEST_MESSAGE_FOUNDHTTP; node.group = group; node.remarks = remarks; node.server = server; - node.port = to_int(port, 0); + node.port = to_int(port, 1); node.proxyStr = httpConstruct(remarks, server, port, username, password, tls); } @@ -806,6 +812,8 @@ void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo return; if(custom_port.size()) port = custom_port; + if(port == "0") + return; host = getUrlArg(addition, "peer"); @@ -818,7 +826,7 @@ void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo node.group = TROJAN_DEFAULT_GROUP; node.remarks = remark; node.server = server; - node.port = to_int(port, 0); + node.port = to_int(port, 1); node.proxyStr = trojanConstruct(remark, server, port, psk, host, true); } @@ -837,6 +845,8 @@ void explodeQuan(std::string quan, const std::string &custom_port, nodeInfo &nod ps = trim(configs[0]); add = trim(configs[2]); port = custom_port.size() ? custom_port : trim(configs[3]); + if(port == "0") + return; cipher = trim(configs[4]); id = trim(replace_all_distinct(configs[5], "\"", "")); @@ -878,7 +888,7 @@ void explodeQuan(std::string quan, const std::string &custom_port, nodeInfo &nod node.group = group; node.remarks = ps; node.server = add; - node.port = to_int(port, 0); + node.port = to_int(port, 1); node.proxyStr = vmessConstruct(add, port, type, id, aid, net, cipher, path, host, edge, tls); } } @@ -900,6 +910,8 @@ void explodeNetch(std::string netch, bool ss_libev, bool ssr_libev, const std::s tfo = GetMember(json, "EnableTFO"); scv = GetMember(json, "AllowInsecure"); port = custom_port.size() ? custom_port : GetMember(json, "Port"); + if(port == "0") + return; method = GetMember(json, "EncryptMethod"); password = GetMember(json, "Password"); if(remark.empty()) @@ -978,7 +990,7 @@ void explodeNetch(std::string netch, bool ss_libev, bool ssr_libev, const std::s node.remarks = remark; node.server = address; - node.port = (unsigned short)to_int(port, 0); + node.port = (unsigned short)to_int(port, 1); } void explodeClash(Node yamlnode, const std::string &custom_port, std::vector &nodes, bool ss_libev, bool ssr_libev) @@ -1000,7 +1012,7 @@ void explodeClash(Node yamlnode, const std::string &custom_port, std::vector>= ps; singleproxy["server"] >>= server; port = custom_port.empty() ? safe_as(singleproxy["port"]) : custom_port; - if(port.empty()) + if(port.empty() || port == "0") continue; udp = safe_as(singleproxy["udp"]); scv = safe_as(singleproxy["skip-cert-verify"]); @@ -1056,8 +1068,7 @@ void explodeClash(Node yamlnode, const std::string &custom_port, std::vector>= pluginopts_mode; - if(singleproxy["obfs-host"].IsDefined()) - singleproxy["obfs-host"] >>= pluginopts_host; + singleproxy["obfs-host"] >>= pluginopts_host; } else plugin.clear(); @@ -1148,7 +1159,7 @@ void explodeClash(Node yamlnode, const std::string &custom_port, std::vector= 5) { username = trim(configs[3]); @@ -1438,6 +1459,8 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector case "vmess"_hash: //surge 4 style vmess proxy server = trim(configs[1]); port = custom_port.empty() ? trim(configs[2]) : custom_port; + if(port == "0") + continue; net = "tcp"; method = "auto"; @@ -1486,6 +1509,8 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector node.group = HTTP_DEFAULT_GROUP; server = trim(configs[1]); port = custom_port.empty() ? trim(configs[2]) : custom_port; + if(port == "0") + continue; for(i = 3; i < configs.size(); i++) { vArray = split(configs[i], "="); @@ -1508,6 +1533,8 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector node.group = TROJAN_DEFAULT_GROUP; server = trim(configs[1]); port = custom_port.empty() ? trim(configs[2]) : custom_port; + if(port == "0") + continue; for(i = 3; i < configs.size(); i++) { @@ -1537,6 +1564,8 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector server = trim(configs[1]); port = custom_port.empty() ? trim(configs[2]) : custom_port; + if(port == "0") + continue; for(i = 3; i < configs.size(); i++) { @@ -1567,6 +1596,8 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector case "shadowsocks"_hash: //quantumult x style ss/ssr link server = trim(configs[0].substr(0, configs[0].rfind(":"))); port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port; + if(port == "0") + continue; for(i = 1; i < configs.size(); i++) { @@ -1617,6 +1648,8 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector case "vmess"_hash: //quantumult x style vmess link server = trim(configs[0].substr(0, configs[0].rfind(":"))); port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port; + if(port == "0") + continue; net = "tcp"; for(i = 1; i < configs.size(); i++) @@ -1659,6 +1692,8 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector case "trojan"_hash: //quantumult x style trojan link server = trim(configs[0].substr(0, configs[0].rfind(":"))); port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port; + if(port == "0") + continue; for(i = 1; i < configs.size(); i++) { @@ -1692,6 +1727,8 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector case "http"_hash: //quantumult x style http links server = trim(configs[0].substr(0, configs[0].rfind(":"))); port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port; + if(port == "0") + continue; for(i = 1; i < configs.size(); i++) { @@ -1743,6 +1780,10 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector void explodeSSTap(std::string sstap, const std::string &custom_port, std::vector &nodes, bool ss_libev, bool ssr_libev) { + std::string configType, group, remarks, server, port; + std::string cipher; + std::string user, pass; + std::string protocol, protoparam, obfs, obfsparam; Document json; nodeInfo node; unsigned int index = nodes.size(); @@ -1752,15 +1793,12 @@ void explodeSSTap(std::string sstap, const std::string &custom_port, std::vector for(unsigned int i = 0; i < json["configs"].Size(); i++) { - std::string configType, group, remarks, server, port; - std::string cipher; - std::string user, pass; - std::string protocol, protoparam, obfs, obfsparam; - json["configs"][i]["group"] >> group; json["configs"][i]["remarks"] >> remarks; json["configs"][i]["server"] >> server; port = custom_port.size() ? custom_port : GetMember(json["configs"][i], "server_port"); + if(port == "0") + continue; if(remarks.empty()) remarks = server + ":" + port; @@ -1799,7 +1837,7 @@ void explodeSSTap(std::string sstap, const std::string &custom_port, std::vector node.remarks = remarks; node.id = index; node.server = server; - node.port = to_int(port); + node.port = to_int(port, 1); nodes.push_back(node); } } diff --git a/src/subexport.cpp b/src/subexport.cpp index d1634d3..2575f8e 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -460,10 +460,10 @@ bool matchRange(std::string &range, int target) return match; } -std::string nodeRename(std::string remark, int groupID, const string_array &rename_array) +std::string nodeRename(const std::string &orig_remark, int groupID, const string_array &rename_array) { string_array vArray; - std::string targetRange; + std::string targetRange, remark = orig_remark; string_size pos; for(const std::string &x : rename_array) @@ -490,12 +490,15 @@ std::string nodeRename(std::string remark, int groupID, const string_array &rena if(matchRange(targetRange, groupID)) remark = regReplace(remark, vArray[0], vArray[1]); } + if(remark.empty()) + return orig_remark; return remark; } -std::string removeEmoji(std::string remark) +std::string removeEmoji(const std::string &orig_remark) { char emoji_id[2] = {(char)-16, (char)-97}; + std::string remark = orig_remark; while(true) { if(remark[0] == emoji_id[0] && remark[1] == emoji_id[1]) @@ -503,6 +506,8 @@ std::string removeEmoji(std::string remark) else break; } + if(remark.empty()) + return orig_remark; return remark; }