Enhancements

Fix support for generating Loon configs.
Refactor libraries.
This commit is contained in:
Tindy X 2023-07-03 13:52:52 +08:00
parent 4205dee94a
commit deb73c5669
24 changed files with 605 additions and 618 deletions

View File

@ -1,6 +1,6 @@
find_path(QUICKJS_INCLUDE_DIRS quickjs/quickjs.h)
find_library(QUICKJS_LIBRARY quickjs)
find_library(QUICKJS_LIBRARY quickjs/libquickjs.a)
set(QUICKJS_LIBRARIES "${QUICKJS_LIBRARY}")

View File

@ -12,7 +12,8 @@ RUN apk add --no-cache --virtual .build-tools git g++ build-base linux-headers c
git submodule update --init && \
cmake -DCMAKE_BUILD_TYPE=Release . && \
make quickjs -j $THREADS && \
install -m644 quickjs/libquickjs.a /usr/lib && \
install -d /usr/lib/quickjs/ && \
install -m644 quickjs/libquickjs.a /usr/lib/quickjs/ && \
install -d /usr/include/quickjs/ && \
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/include/quickjs/ && \
install -m644 quickjspp.hpp /usr/include && \

View File

@ -20,7 +20,8 @@ git clone https://github.com/ftk/quickjspp --depth=1
cd quickjspp
cmake -DCMAKE_BUILD_TYPE=Release .
make quickjs -j2
install -m644 quickjs/libquickjs.a /usr/lib/
install -d /usr/lib/quickjs/
install -m644 quickjs/libquickjs.a /usr/lib/quickjs/
install -d /usr/include/quickjs/
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/include/quickjs/
install -m644 quickjspp.hpp /usr/include/

View File

@ -21,7 +21,8 @@ git clone https://github.com/ftk/quickjspp --depth=1
cd quickjspp
cmake -DCMAKE_BUILD_TYPE=Release .
make quickjs -j8
install -m644 quickjs/libquickjs.a /usr/local/lib/
install -d /usr/local/lib/quickjs/
install -m644 quickjs/libquickjs.a /usr/local/lib/quickjs/
install -d /usr/local/include/quickjs/
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/local/include/quickjs/
install -m644 quickjspp.hpp /usr/local/include/

View File

@ -18,7 +18,8 @@ cd quickjspp
patch quickjs/quickjs-libc.c -i ../scripts/patches/0001-quickjs-libc-add-realpath-for-Windows.patch
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .
make quickjs -j4
install -m644 quickjs/libquickjs.a "$MINGW_PREFIX/lib/"
install -d "$MINGW_PREFIX/lib/quickjs/"
install -m644 quickjs/libquickjs.a "$MINGW_PREFIX/lib/quickjs/"
install -d "$MINGW_PREFIX/include/quickjs"
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h "$MINGW_PREFIX/include/quickjs/"
install -m644 quickjspp.hpp "$MINGW_PREFIX/include/"

View File

@ -20,7 +20,8 @@ git clone https://github.com/ftk/quickjspp --depth=1
cd quickjspp
cmake -DCMAKE_BUILD_TYPE=Release .
make quickjs -j3
install -m644 quickjs/libquickjs.a $PREFIX/lib/
install -d $PREFIX/lib/quickjs/
install -m644 quickjs/libquickjs.a $PREFIX/lib/quickjs/
install -d $PREFIX/include/quickjs/
install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h $PREFIX/include/quickjs/
install -m644 quickjspp.hpp $PREFIX/include/

View File

@ -68,7 +68,7 @@ int addNodes(std::string link, std::vector<Proxy> &allNodes, int groupID, parse_
switch(args.size())
{
case 0:
link = parse(std::string(), string_array());
link = parse("", string_array());
break;
case 1:
link = parse(args[0], string_array());

View File

@ -245,28 +245,28 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
switch(surge_ver) //other version: -3 for Surfboard, -4 for Loon
{
case 0:
base_rule.SetCurrentSection("RoutingRule"); //Mellow
base_rule.set_current_section("RoutingRule"); //Mellow
break;
case -1:
base_rule.SetCurrentSection("filter_local"); //Quantumult X
base_rule.set_current_section("filter_local"); //Quantumult X
break;
case -2:
base_rule.SetCurrentSection("TCP"); //Quantumult
base_rule.set_current_section("TCP"); //Quantumult
break;
default:
base_rule.SetCurrentSection("Rule");
base_rule.set_current_section("Rule");
}
if(overwrite_original_rules)
{
base_rule.EraseSection();
base_rule.erase_section();
switch(surge_ver)
{
case -1:
base_rule.EraseSection("filter_remote");
base_rule.erase_section("filter_remote");
break;
case -4:
base_rule.EraseSection("Remote Rule");
base_rule.erase_section("Remote Rule");
break;
}
}
@ -308,7 +308,7 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
if(surge_ver == -1 && x.rule_type == RULESET_QUANX && isLink(rule_path))
{
strLine = rule_path + ", tag=" + rule_group + ", force-policy=" + rule_group + ", enabled=true";
base_rule.Set("filter_remote", "{NONAME}", strLine);
base_rule.set("filter_remote", "{NONAME}", strLine);
continue;
}
if(fileExist(rule_path))
@ -325,13 +325,13 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
{
strLine = remote_path_prefix + "/getruleset?type=2&url=" + urlSafeBase64Encode(rule_path_typed) + "&group=" + urlSafeBase64Encode(rule_group);
strLine += ", tag=" + rule_group + ", enabled=true";
base_rule.Set("filter_remote", "{NONAME}", strLine);
base_rule.set("filter_remote", "{NONAME}", strLine);
continue;
}
else if(surge_ver == -4 && remote_path_prefix.size())
{
strLine = remote_path_prefix + "/getruleset?type=1&url=" + urlSafeBase64Encode(rule_path_typed) + "," + rule_group;
base_rule.Set("Remote Rule", "{NONAME}", strLine);
base_rule.set("Remote Rule", "{NONAME}", strLine);
continue;
}
}
@ -359,13 +359,13 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
{
strLine = remote_path_prefix + "/getruleset?type=2&url=" + urlSafeBase64Encode(rule_path_typed) + "&group=" + urlSafeBase64Encode(rule_group);
strLine += ", tag=" + rule_group + ", enabled=true";
base_rule.Set("filter_remote", "{NONAME}", strLine);
base_rule.set("filter_remote", "{NONAME}", strLine);
continue;
}
else if(surge_ver == -4)
{
strLine = rule_path + "," + rule_group;
base_rule.Set("Remote Rule", "{NONAME}", strLine);
base_rule.set("Remote Rule", "{NONAME}", strLine);
continue;
}
}
@ -450,6 +450,6 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
for(std::string &x : allRules)
{
base_rule.Set("{NONAME}", x);
base_rule.set("{NONAME}", x);
}
}

View File

@ -159,7 +159,7 @@ void processRemark(std::string &oldremark, std::string &newremark, string_array
{
if(proc_comma)
{
if(oldremark.find(',') != oldremark.npos)
if(oldremark.find(',') != std::string::npos)
{
oldremark.insert(0, "\"");
oldremark.append("\"");
@ -213,9 +213,9 @@ void groupGenerate(const std::string &rule, std::vector<Proxy> &nodelist, string
void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupConfigs &extra_proxy_group, bool clashR, extra_settings &ext)
{
YAML::Node proxies, singleproxy, singlegroup, original_groups;
YAML::Node proxies, original_groups;
std::vector<Proxy> nodelist;
string_array remarks_list, filtered_nodelist;
string_array remarks_list;
/// proxies style
bool block = false, compact = false;
switch(hash_(ext.clash_proxies_style))
@ -233,7 +233,7 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
for(Proxy &x : nodes)
{
singleproxy.reset();
YAML::Node singleproxy;
std::string type = getProxyTypeName(x.Type);
std::string remark, pluginopts = replaceAllDistinct(x.PluginOption, ";", "&");
@ -424,6 +424,8 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
}
break;
case ProxyType::Snell:
if (x.SnellVersion >= 4)
continue;
singleproxy["type"] = "snell";
singleproxy["psk"] = x.Password;
if(x.SnellVersion != 0)
@ -471,8 +473,8 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
for(const ProxyGroupConfig &x : extra_proxy_group)
{
singlegroup.reset();
eraseElements(filtered_nodelist);
YAML::Node singlegroup;
string_array filtered_nodelist;
singlegroup["name"] = x.Name;
singlegroup["type"] = x.TypeStr();
@ -517,11 +519,11 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
//singlegroup.SetStyle(YAML::EmitterStyle::Flow);
bool replace_flag = false;
for(unsigned int i = 0; i < original_groups.size(); i++)
for(auto && original_group : original_groups)
{
if(original_groups[i]["name"].as<std::string>() == x.Name)
if(original_group["name"].as<std::string>() == x.Name)
{
original_groups[i] = singlegroup;
original_group.reset(singlegroup);
replace_flag = true;
break;
}
@ -547,7 +549,7 @@ std::string proxyToClash(std::vector<Proxy> &nodes, const std::string &base_conf
catch (std::exception &e)
{
writeLog(0, std::string("Clash base loader failed with error: ") + e.what(), LOG_LEVEL_ERROR);
return std::string();
return "";
}
proxyToClash(nodes, yamlnode, extra_proxy_group, clashR, ext);
@ -589,33 +591,30 @@ std::string proxyToClash(std::vector<Proxy> &nodes, const std::string &base_conf
std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf, std::vector<RulesetContent> &ruleset_content_array, const ProxyGroupConfigs &extra_proxy_group, int surge_ver, extra_settings &ext)
{
INIReader ini;
std::string proxy;
std::string output_nodelist;
tribool udp, tfo, scv, tls13;
std::vector<Proxy> nodelist;
unsigned short local_port = 1080;
string_array remarks_list, filtered_nodelist, args;
string_array remarks_list;
ini.store_any_line = true;
// filter out sections that requires direct-save
ini.AddDirectSaveSection("General");
ini.AddDirectSaveSection("Replica");
ini.AddDirectSaveSection("Rule");
ini.AddDirectSaveSection("MITM");
ini.AddDirectSaveSection("Script");
ini.AddDirectSaveSection("Host");
ini.AddDirectSaveSection("URL Rewrite");
ini.AddDirectSaveSection("Header Rewrite");
if(ini.Parse(base_conf) != 0 && !ext.nodelist)
ini.add_direct_save_section("General");
ini.add_direct_save_section("Replica");
ini.add_direct_save_section("Rule");
ini.add_direct_save_section("MITM");
ini.add_direct_save_section("Script");
ini.add_direct_save_section("Host");
ini.add_direct_save_section("URL Rewrite");
ini.add_direct_save_section("Header Rewrite");
if(ini.parse(base_conf) != 0 && !ext.nodelist)
{
writeLog(0, "Surge base loader failed with error: " + ini.GetLastError(), LOG_LEVEL_ERROR);
return std::string();
writeLog(0, "Surge base loader failed with error: " + ini.get_last_error(), LOG_LEVEL_ERROR);
return "";
}
ini.SetCurrentSection("Proxy");
ini.EraseSection();
ini.Set("{NONAME}", "DIRECT = direct");
ini.set_current_section("Proxy");
ini.erase_section();
ini.set("{NONAME}", "DIRECT = direct");
for(Proxy &x : nodes)
{
@ -632,16 +631,14 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
std::string port = std::to_string(x.Port);
bool &tlssecure = x.TLSSecure;
udp = ext.udp;
tfo = ext.tfo;
scv = ext.skip_cert_verify;
tls13 = ext.tls13;
tribool udp = ext.udp, tfo = ext.tfo, scv = ext.skip_cert_verify, tls13 = ext.tls13;
udp.define(x.UDP);
tfo.define(x.TCPFastOpen);
scv.define(x.AllowInsecure);
tls13.define(x.TLS13);
proxy.clear();
std::string proxy;
string_array args;
switch(x.Type)
{
@ -772,7 +769,7 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
output_nodelist += remark + " = " + proxy + "\n";
else
{
ini.Set("{NONAME}", remark + " = " + proxy);
ini.set("{NONAME}", remark + " = " + proxy);
nodelist.emplace_back(x);
}
remarks_list.emplace_back(std::move(remark));
@ -781,12 +778,12 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
if(ext.nodelist)
return output_nodelist;
ini.SetCurrentSection("Proxy Group");
ini.EraseSection();
ini.set_current_section("Proxy Group");
ini.erase_section();
for(const ProxyGroupConfig &x : extra_proxy_group)
{
eraseElements(filtered_nodelist);
proxy.clear();
string_array filtered_nodelist;
std::string group;
switch(x.Type)
{
@ -799,9 +796,9 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
continue;
break;
case ProxyGroupType::SSID:
proxy = x.TypeStr() + ",default=" + x.Proxies[0] + ",";
proxy += join(x.Proxies.begin() + 1, x.Proxies.end(), ",");
ini.Set("{NONAME}", x.Name + " = " + proxy); //insert order
group = x.TypeStr() + ",default=" + x.Proxies[0] + ",";
group += join(x.Proxies.begin() + 1, x.Proxies.end(), ",");
ini.set("{NONAME}", x.Name + " = " + group); //insert order
continue;
default:
continue;
@ -815,54 +812,50 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
if(filtered_nodelist.size() == 1)
{
proxy = toLower(filtered_nodelist[0]);
switch(hash_(proxy))
group = toLower(filtered_nodelist[0]);
switch(hash_(group))
{
case "direct"_hash:
case "reject"_hash:
case "reject-tinygif"_hash:
ini.Set("Proxy", "{NONAME}", x.Name + " = " + proxy);
ini.set("Proxy", "{NONAME}", x.Name + " = " + group);
continue;
}
}
proxy = x.TypeStr() + ",";
proxy += join(filtered_nodelist, ",");
group = x.TypeStr() + ",";
group += join(filtered_nodelist, ",");
if(x.Type == ProxyGroupType::URLTest || x.Type == ProxyGroupType::Fallback || x.Type == ProxyGroupType::LoadBalance)
{
proxy += ",url=" + x.Url + ",interval=" + std::to_string(x.Interval);
group += ",url=" + x.Url + ",interval=" + std::to_string(x.Interval);
if(x.Tolerance > 0)
proxy += ",tolerance=" + std::to_string(x.Tolerance);
group += ",tolerance=" + std::to_string(x.Tolerance);
if(x.Timeout > 0)
proxy += ",timeout=" + std::to_string(x.Timeout);
group += ",timeout=" + std::to_string(x.Timeout);
if(!x.Persistent.is_undef())
proxy += ",persistent=" + x.Persistent.get_str();
group += ",persistent=" + x.Persistent.get_str();
if(!x.EvaluateBeforeUse.is_undef())
proxy += ",evaluate-before-use=" + x.EvaluateBeforeUse.get_str();
group += ",evaluate-before-use=" + x.EvaluateBeforeUse.get_str();
}
ini.Set("{NONAME}", x.Name + " = " + proxy); //insert order
ini.set("{NONAME}", x.Name + " = " + group); //insert order
}
if(ext.enable_rule_generator)
rulesetToSurge(ini, ruleset_content_array, surge_ver, ext.overwrite_original_rules, ext.managed_config_prefix);
return ini.ToString();
return ini.to_string();
}
std::string proxyToSingle(std::vector<Proxy> &nodes, int types, extra_settings &ext)
{
/// types: SS=1 SSR=2 VMess=4 Trojan=8
std::string remark, hostname, port, password, method;
std::string plugin, pluginopts;
std::string protocol, protoparam, obfs, obfsparam;
std::string id, aid, transproto, faketype, host, path, quicsecure, quicsecret;
std::string proxyStr, allLinks;
bool ss = GETBIT(types, 1), ssr = GETBIT(types, 2), vmess = GETBIT(types, 3), trojan = GETBIT(types, 4);
for(Proxy &x : nodes)
{
remark = x.Remark;
std::string remark = x.Remark;
std::string &hostname = x.Hostname, &password = x.Password, &method = x.EncryptMethod, &plugin = x.Plugin, &pluginopts = x.PluginOption, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.Host, &path = x.Path, &faketype = x.FakeType;
bool &tlssecure = x.TLSSecure;
std::string port = std::to_string(x.Port);
@ -938,12 +931,9 @@ std::string proxyToSingle(std::vector<Proxy> &nodes, int types, extra_settings &
std::string proxyToSSSub(std::string base_conf, std::vector<Proxy> &nodes, extra_settings &ext)
{
rapidjson::Document json, base;
std::string remark, hostname, password, method;
std::string plugin, pluginopts;
std::string protocol, obfs;
std::string output_content;
rapidjson::Document::AllocatorType &alloc = json.GetAllocator();
auto &alloc = json.GetAllocator();
json.SetObject();
json.AddMember("remarks", "", alloc);
json.AddMember("server", "", alloc);
@ -971,8 +961,8 @@ std::string proxyToSSSub(std::string base_conf, std::vector<Proxy> &nodes, extra
output_content = "[";
for(Proxy &x : nodes)
{
remark = x.Remark;
hostname = x.Hostname;
std::string &remark = x.Remark;
std::string &hostname = x.Hostname;
std::string &password = x.Password;
std::string &method = x.EncryptMethod;
std::string &plugin = x.Plugin;
@ -1012,10 +1002,10 @@ std::string proxyToQuan(std::vector<Proxy> &nodes, const std::string &base_conf,
{
INIReader ini;
ini.store_any_line = true;
if(!ext.nodelist && ini.Parse(base_conf) != 0)
if(!ext.nodelist && ini.parse(base_conf) != 0)
{
writeLog(0, "Quantumult base loader failed with error: " + ini.GetLastError(), LOG_LEVEL_ERROR);
return std::string();
writeLog(0, "Quantumult base loader failed with error: " + ini.get_last_error(), LOG_LEVEL_ERROR);
return "";
}
proxyToQuan(nodes, ini, ruleset_content_array, extra_proxy_group, ext);
@ -1024,23 +1014,22 @@ std::string proxyToQuan(std::vector<Proxy> &nodes, const std::string &base_conf,
{
string_array allnodes;
std::string allLinks;
ini.GetAll("SERVER", "{NONAME}", allnodes);
ini.get_all("SERVER", "{NONAME}", allnodes);
if(!allnodes.empty())
allLinks = join(allnodes, "\n");
return base64Encode(allLinks);
}
return ini.ToString();
return ini.to_string();
}
void proxyToQuan(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetContent> &ruleset_content_array, const ProxyGroupConfigs &extra_proxy_group, extra_settings &ext)
{
std::string type, proxyStr;
tribool scv;
std::string proxyStr;
std::vector<Proxy> nodelist;
string_array remarks_list;
ini.SetCurrentSection("SERVER");
ini.EraseSection();
ini.set_current_section("SERVER");
ini.erase_section();
for(Proxy &x : nodes)
{
std::string remark = x.Remark;
@ -1056,6 +1045,7 @@ void proxyToQuan(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetC
std::string &hostname = x.Hostname, &method = x.EncryptMethod, &password = x.Password, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.Host, &path = x.Path, &edge = x.Edge, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam, &plugin = x.Plugin, &pluginopts = x.PluginOption, &username = x.Username;
std::string port = std::to_string(x.Port);
bool &tlssecure = x.TLSSecure;
tribool scv;
switch(x.Type)
{
@ -1161,7 +1151,7 @@ void proxyToQuan(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetC
continue;
}
ini.Set("{NONAME}", proxyStr);
ini.set("{NONAME}", proxyStr);
remarks_list.emplace_back(std::move(remark));
nodelist.emplace_back(x);
}
@ -1169,15 +1159,15 @@ void proxyToQuan(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetC
if(ext.nodelist)
return;
string_array filtered_nodelist;
ini.SetCurrentSection("POLICY");
ini.EraseSection();
ini.set_current_section("POLICY");
ini.erase_section();
std::string singlegroup;
std::string name, proxies;
for(const ProxyGroupConfig &x : extra_proxy_group)
{
eraseElements(filtered_nodelist);
string_array filtered_nodelist;
std::string type;
std::string singlegroup;
std::string name, proxies;
switch(x.Type)
{
@ -1207,7 +1197,7 @@ void proxyToQuan(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetC
if(!celluar.empty())
singlegroup += ", celluar = " + celluar;
singlegroup += "\n" + replaceAllDistinct(trimOf(content, ','), ",", "\n");
ini.Set("{NONAME}", base64Encode(singlegroup)); //insert order
ini.set("{NONAME}", base64Encode(singlegroup)); //insert order
}
continue;
default:
@ -1229,28 +1219,28 @@ void proxyToQuan(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetC
if(type == "static")
singlegroup += ", " + filtered_nodelist[0];
singlegroup += "\n" + proxies + "\n";
ini.Set("{NONAME}", base64Encode(singlegroup));
ini.set("{NONAME}", base64Encode(singlegroup));
}
if(ext.enable_rule_generator)
rulesetToSurge(ini, ruleset_content_array, -2, ext.overwrite_original_rules, std::string());
rulesetToSurge(ini, ruleset_content_array, -2, ext.overwrite_original_rules, "");
}
std::string proxyToQuanX(std::vector<Proxy> &nodes, const std::string &base_conf, std::vector<RulesetContent> &ruleset_content_array, const ProxyGroupConfigs &extra_proxy_group, extra_settings &ext)
{
INIReader ini;
ini.store_any_line = true;
ini.AddDirectSaveSection("general");
ini.AddDirectSaveSection("dns");
ini.AddDirectSaveSection("rewrite_remote");
ini.AddDirectSaveSection("rewrite_local");
ini.AddDirectSaveSection("task_local");
ini.AddDirectSaveSection("mitm");
ini.AddDirectSaveSection("server_remote");
if(!ext.nodelist && ini.Parse(base_conf) != 0)
ini.add_direct_save_section("general");
ini.add_direct_save_section("dns");
ini.add_direct_save_section("rewrite_remote");
ini.add_direct_save_section("rewrite_local");
ini.add_direct_save_section("task_local");
ini.add_direct_save_section("mitm");
ini.add_direct_save_section("server_remote");
if(!ext.nodelist && ini.parse(base_conf) != 0)
{
writeLog(0, "QuantumultX base loader failed with error: " + ini.GetLastError(), LOG_LEVEL_ERROR);
return std::string();
writeLog(0, "QuantumultX base loader failed with error: " + ini.get_last_error(), LOG_LEVEL_ERROR);
return "";
}
proxyToQuanX(nodes, ini, ruleset_content_array, extra_proxy_group, ext);
@ -1259,28 +1249,25 @@ std::string proxyToQuanX(std::vector<Proxy> &nodes, const std::string &base_conf
{
string_array allnodes;
std::string allLinks;
ini.GetAll("server_local", "{NONAME}", allnodes);
ini.get_all("server_local", "{NONAME}", allnodes);
if(!allnodes.empty())
allLinks = join(allnodes, "\n");
return allLinks;
}
return ini.ToString();
return ini.to_string();
}
void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetContent> &ruleset_content_array, const ProxyGroupConfigs &extra_proxy_group, extra_settings &ext)
{
std::string type;
std::string remark, hostname, port, method;
std::string password, plugin, pluginopts;
std::string id, transproto, host, path;
std::string protocol, protoparam, obfs, obfsparam;
std::string remark;
std::string proxyStr;
tribool udp, tfo, scv, tls13;
std::vector<Proxy> nodelist;
string_array remarks_list;
ini.SetCurrentSection("server_local");
ini.EraseSection();
ini.set_current_section("server_local");
ini.erase_section();
for(Proxy &x : nodes)
{
if(ext.append_proxy_type)
@ -1338,7 +1325,7 @@ void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Ruleset
plugin = getUrlArg(pluginopts, "mode") == "websocket" ? "ws" : "";
host = getUrlArg(pluginopts, "host");
path = getUrlArg(pluginopts, "path");
tlssecure = pluginopts.find("tls") != pluginopts.npos;
tlssecure = pluginopts.find("tls") != std::string::npos;
if(tlssecure && plugin == "ws")
{
plugin += 's';
@ -1419,7 +1406,7 @@ void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Ruleset
proxyStr += ", tls-verification=" + scv.reverse().get_str();
proxyStr += ", tag=" + remark;
ini.Set("{NONAME}", proxyStr);
ini.set("{NONAME}", proxyStr);
remarks_list.emplace_back(std::move(remark));
nodelist.emplace_back(x);
}
@ -1428,9 +1415,9 @@ void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Ruleset
return;
string_multimap original_groups;
ini.SetCurrentSection("policy");
ini.GetItems(original_groups);
ini.EraseSection();
ini.set_current_section("policy");
ini.get_items(original_groups);
ini.erase_section();
for(const ProxyGroupConfig &x : extra_proxy_group)
{
@ -1474,8 +1461,8 @@ void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Ruleset
auto iter = std::find_if(original_groups.begin(), original_groups.end(), [&](const string_multimap::value_type &n)
{
std::string groupdata = n.second;
std::string::size_type cpos = groupdata.find(",");
if(cpos != groupdata.npos)
std::string::size_type cpos = groupdata.find(',');
if(cpos != std::string::npos)
return trim(groupdata.substr(0, cpos)) == x.Name;
else
return false;
@ -1493,7 +1480,7 @@ void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Ruleset
std::string proxies = join(filtered_nodelist, ", ");
std::string singlegroup = type + "=" + x.Name + ", " + proxies;
ini.Set("{NONAME}", singlegroup);
ini.set("{NONAME}", singlegroup);
}
if(ext.enable_rule_generator)
@ -1504,7 +1491,7 @@ std::string proxyToSSD(std::vector<Proxy> &nodes, std::string &group, std::strin
{
rapidjson::StringBuffer sb;
rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
size_t index = 0;
int index = 0;
if(group.empty())
group = "SSD";
@ -1603,29 +1590,29 @@ std::string proxyToMellow(std::vector<Proxy> &nodes, const std::string &base_con
{
INIReader ini;
ini.store_any_line = true;
if(ini.Parse(base_conf) != 0)
if(ini.parse(base_conf) != 0)
{
writeLog(0, "Mellow base loader failed with error: " + ini.GetLastError(), LOG_LEVEL_ERROR);
return std::string();
writeLog(0, "Mellow base loader failed with error: " + ini.get_last_error(), LOG_LEVEL_ERROR);
return "";
}
proxyToMellow(nodes, ini, ruleset_content_array, extra_proxy_group, ext);
return ini.ToString();
return ini.to_string();
}
void proxyToMellow(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetContent> &ruleset_content_array, const ProxyGroupConfigs &extra_proxy_group, extra_settings &ext)
{
std::string proxy;
std::string type, remark, hostname, port, username, password, method;
std::string remark, username, password, method;
std::string plugin, pluginopts;
std::string id, aid, transproto, faketype, host, path, quicsecure, quicsecret, tlssecure;
std::string url;
tribool tfo, scv;
std::vector<Proxy> nodelist;
string_array vArray, remarks_list, filtered_nodelist;
string_array vArray, remarks_list;
ini.SetCurrentSection("Endpoint");
ini.set_current_section("Endpoint");
for(Proxy &x : nodes)
{
@ -1637,8 +1624,7 @@ void proxyToMellow(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Rulese
processRemark(x.Remark, remark, remarks_list);
std::string &hostname = x.Hostname;
port = std::to_string(x.Port);
std::string &hostname = x.Hostname, port = std::to_string(x.Port);
tfo = ext.tfo;
scv = ext.skip_cert_verify;
@ -1671,7 +1657,6 @@ void proxyToMellow(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Rulese
proxy += "&quic.security=" + quicsecure + "&quic.key=" + quicsecret;
break;
case "kcp"_hash:
break;
case "tcp"_hash:
break;
}
@ -1696,16 +1681,16 @@ void proxyToMellow(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Rulese
continue;
}
ini.Set("{NONAME}", proxy);
ini.set("{NONAME}", proxy);
remarks_list.emplace_back(std::move(remark));
nodelist.emplace_back(x);
}
ini.SetCurrentSection("EndpointGroup");
ini.set_current_section("EndpointGroup");
for(const ProxyGroupConfig &x : extra_proxy_group)
{
eraseElements(filtered_nodelist);
string_array filtered_nodelist;
url.clear();
proxy.clear();
@ -1749,34 +1734,31 @@ void proxyToMellow(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Rulese
proxy += join(filtered_nodelist, ":");
proxy += ", latency, interval=300, timeout=6"; //use hard-coded values for now
ini.Set("{NONAME}", proxy); //insert order
ini.set("{NONAME}", proxy); //insert order
}
if(ext.enable_rule_generator)
rulesetToSurge(ini, ruleset_content_array, 0, ext.overwrite_original_rules, std::string());
rulesetToSurge(ini, ruleset_content_array, 0, ext.overwrite_original_rules, "");
}
std::string proxyToLoon(std::vector<Proxy> &nodes, const std::string &base_conf, std::vector<RulesetContent> &ruleset_content_array, const ProxyGroupConfigs &extra_proxy_group, extra_settings &ext)
{
rapidjson::Document json;
INIReader ini;
std::string proxy;
std::string output_nodelist;
tribool scv;
std::vector<Proxy> nodelist;
string_array vArray, remarks_list, filtered_nodelist;
string_array remarks_list;
ini.store_any_line = true;
if(ini.Parse(base_conf) != INIREADER_EXCEPTION_NONE && !ext.nodelist)
if(ini.parse(base_conf) != INIREADER_EXCEPTION_NONE && !ext.nodelist)
{
writeLog(0, "Loon base loader failed with error: " + ini.GetLastError(), LOG_LEVEL_ERROR);
return std::string();
writeLog(0, "Loon base loader failed with error: " + ini.get_last_error(), LOG_LEVEL_ERROR);
return "";
}
ini.SetCurrentSection("Proxy");
ini.EraseSection();
ini.set_current_section("Proxy");
ini.erase_section();
for(Proxy &x : nodes)
{
@ -1795,7 +1777,7 @@ std::string proxyToLoon(std::vector<Proxy> &nodes, const std::string &base_conf,
tribool scv = ext.skip_cert_verify;
scv.define(x.AllowInsecure);
proxy.clear();
std::string proxy;
switch(x.Type)
{
@ -1813,59 +1795,58 @@ std::string proxyToLoon(std::vector<Proxy> &nodes, const std::string &base_conf,
if(method == "auto")
method = "chacha20-ietf-poly1305";
proxy = "vmess," + hostname + "," + port + "," + method + ",\"" + id + "\",over-tls:" + (tlssecure ? "true" : "false");
proxy = "vmess," + hostname + "," + port + "," + method + ",\"" + id + "\",over-tls=" + (tlssecure ? "true" : "false");
if(tlssecure)
proxy += ",tls-name:" + host;
proxy += ",tls-name=" + host;
switch(hash_(transproto))
{
case "tcp"_hash:
proxy += ",transport:tcp";
proxy += ",transport=tcp";
break;
case "ws"_hash:
proxy += ",transport:ws,path:" + path + ",host:" + host;
proxy += ",transport=ws,path=" + path + ",host=" + host;
break;
default:
continue;
}
if(!scv.is_undef())
proxy += ",skip-cert-verify:" + std::string(scv.get() ? "1" : "0");
proxy += ",skip-cert-verify=" + std::string(scv.get() ? "true" : "false");
break;
case ProxyType::ShadowsocksR:
proxy = "ShadowsocksR," + hostname + "," + port + "," + method + ",\"" + password + "\"," + protocol + ",{" + protoparam + "}," + obfs + ",{" + obfsparam + "}";
proxy = "ShadowsocksR," + hostname + "," + port + "," + method + ",\"" + password + "\",protocol=" + protocol + ",protocol-param=" + protoparam + ",obfs=" + obfs + ",obfs-param=" + obfsparam;
break;
/*
case ProxyType::SOCKS5:
proxy = "socks5, " + hostname + ", " + port + ", " + username + ", " + password;
if(ext.skip_cert_verify)
proxy += ", skip-cert-verify:1";
break;
*/
case ProxyType::HTTP:
proxy = "http," + hostname + "," + port + "," + username + "," + password;
proxy = "http," + hostname + "," + port + "," + username + ",\"" + password + "\"";
break;
case ProxyType::HTTPS:
proxy = "https," + hostname + "," + port + "," + username + ",\"" + password + "\"";
if(!host.empty())
proxy += ",tls-name=" + host;
if(!scv.is_undef())
proxy += ",skip-cert-verify=" + std::string(scv.get() ? "true" : "false");
break;
case ProxyType::Trojan:
proxy = "trojan," + hostname + "," + port + "," + password;
proxy = "trojan," + hostname + "," + port + ",\"" + password + "\"";
if(!host.empty())
proxy += ",tls-name:" + host;
proxy += ",tls-name=" + host;
if(!scv.is_undef())
proxy += ",skip-cert-verify:" + std::string(scv.get() ? "1" : "0");
proxy += ",skip-cert-verify=" + std::string(scv.get() ? "true" : "false");
break;
default:
continue;
}
/*
if(ext.tfo)
proxy += ", tfo=true";
proxy += ",fast-open=true";
if(ext.udp)
proxy += ", udp-relay=true";
*/
proxy += ",udp=true";
if(ext.nodelist)
output_nodelist += remark + " = " + proxy + "\n";
else
{
ini.Set("{NONAME}", remark + " = " + proxy);
ini.set("{NONAME}", remark + " = " + proxy);
nodelist.emplace_back(x);
remarks_list.emplace_back(std::move(remark));
}
@ -1874,25 +1855,26 @@ std::string proxyToLoon(std::vector<Proxy> &nodes, const std::string &base_conf,
if(ext.nodelist)
return output_nodelist;
ini.SetCurrentSection("Proxy Group");
ini.EraseSection();
ini.set_current_section("Proxy Group");
ini.erase_section();
for(const ProxyGroupConfig &x : extra_proxy_group)
{
eraseElements(filtered_nodelist);
proxy.clear();
string_array filtered_nodelist;
std::string group, group_extra;
switch(x.Type)
{
case ProxyGroupType::Select:
case ProxyGroupType::LoadBalance:
case ProxyGroupType::URLTest:
case ProxyGroupType::Fallback:
break;
case ProxyGroupType::SSID:
if(x.Proxies.size() < 2)
continue;
proxy = x.TypeStr() + ",default=" + x.Proxies[0] + ",";
proxy += join(x.Proxies.begin() + 1, x.Proxies.end(), ",");
ini.Set("{NONAME}", x.Name + " = " + proxy); //insert order
group = x.TypeStr() + ",default=" + x.Proxies[0] + ",";
group += join(x.Proxies.begin() + 1, x.Proxies.end(), ",");
ini.set("{NONAME}", x.Name + " = " + group); //insert order
continue;
default:
continue;
@ -1904,20 +1886,23 @@ std::string proxyToLoon(std::vector<Proxy> &nodes, const std::string &base_conf,
if(filtered_nodelist.empty())
filtered_nodelist.emplace_back("DIRECT");
proxy = x.TypeStr() + ",";
group = x.TypeStr() + ",";
/*
for(std::string &y : filtered_nodelist)
proxy += "," + y;
group += "," + y;
*/
proxy += join(filtered_nodelist, ",");
if(x.Type == ProxyGroupType::URLTest || x.Type == ProxyGroupType::Fallback)
proxy += ",url=" + x.Url + ",interval=" + std::to_string(x.Interval);
group += join(filtered_nodelist, ",");
if(x.Type != ProxyGroupType::Select) {
group += ",url=" + x.Url + ",interval=" + std::to_string(x.Interval);
if (x.Type == ProxyGroupType::LoadBalance)
group += ",strategy=" + std::string(x.Strategy == BalanceStrategy::RoundRobin ? "round-robin" : "pcc");
}
ini.Set("{NONAME}", x.Name + " = " + proxy); //insert order
ini.set("{NONAME}", x.Name + " = " + group); //insert order
}
if(ext.enable_rule_generator)
rulesetToSurge(ini, ruleset_content_array, -4, ext.overwrite_original_rules, ext.managed_config_prefix);
return ini.ToString();
return ini.to_string();
}

View File

@ -151,7 +151,7 @@ int render_template(const std::string &content, const template_args &vars, std::
{
std::string key = args.at(0)->get<std::string>(), value = args.at(1)->get<std::string>();
parse_json_pointer(data, key, value);
return std::string();
return "";
});
env.add_callback("split", 3, [&data](inja::Arguments &args)
{
@ -159,7 +159,7 @@ int render_template(const std::string &content, const template_args &vars, std::
string_array vArray = split(content, delim);
for(size_t index = 0; index < vArray.size(); index++)
parse_json_pointer(data, dest + "." + std::to_string(index), vArray[index]);
return std::string();
return "";
});
env.add_callback("append", 2, [&data](inja::Arguments &args)
{
@ -175,7 +175,7 @@ int render_template(const std::string &content, const template_args &vars, std::
}
output_content.append(value);
data[nlohmann::json::json_pointer(pointer)] = output_content;
return std::string();
return "";
});
env.add_callback("getLink", 1, [](inja::Arguments &args)
{

View File

@ -958,15 +958,15 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
base_content = fetchFile(url, proxy, global.cacheConfig);
if(ini.Parse(base_content) != INIREADER_EXCEPTION_NONE)
if(ini.parse(base_content) != INIREADER_EXCEPTION_NONE)
{
std::string errmsg = "Parsing Surge config failed! Reason: " + ini.GetLastError();
std::string errmsg = "Parsing Surge config failed! Reason: " + ini.get_last_error();
//std::cerr<<errmsg<<"\n";
writeLog(0, errmsg, LOG_LEVEL_ERROR);
*status_code = 400;
return errmsg;
}
if(!ini.SectionExist("Proxy") || !ini.SectionExist("Proxy Group") || !ini.SectionExist("Rule"))
if(!ini.section_exist("Proxy") || !ini.section_exist("Proxy Group") || !ini.section_exist("Rule"))
{
std::string errmsg = "Incomplete surge config! Missing critical sections!";
//std::cerr<<errmsg<<"\n";
@ -977,7 +977,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
//scan groups first, get potential policy-path
string_multimap section;
ini.GetItems("Proxy Group", section);
ini.get_items("Proxy Group", section);
std::string name, type, content;
string_array links;
links.emplace_back(url);
@ -1058,7 +1058,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
proxyToClash(nodes, clash, dummy_groups, false, ext);
section.clear();
ini.GetItems("Proxy", section);
ini.get_items("Proxy", section);
for(auto &x : section)
{
singlegroup.reset();
@ -1088,7 +1088,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
}
eraseElements(dummy_str_array);
ini.GetAll("Rule", "{NONAME}", dummy_str_array);
ini.get_all("Rule", "{NONAME}", dummy_str_array);
YAML::Node rule;
string_array strArray;
std::string strLine;
@ -1166,17 +1166,17 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS)
//std::cerr<<"Trying to load profile '" + name + "'.\n";
writeLog(0, "Trying to load profile '" + name + "'.", LOG_LEVEL_INFO);
INIReader ini;
if(ini.Parse(profile_content) != INIREADER_EXCEPTION_NONE && !ini.SectionExist("Profile"))
if(ini.parse(profile_content) != INIREADER_EXCEPTION_NONE && !ini.section_exist("Profile"))
{
//std::cerr<<"Load profile failed! Reason: "<<ini.GetLastError()<<"\n";
writeLog(0, "Load profile failed! Reason: " + ini.GetLastError(), LOG_LEVEL_ERROR);
//std::cerr<<"Load profile failed! Reason: "<<ini.get_last_error()<<"\n";
writeLog(0, "Load profile failed! Reason: " + ini.get_last_error(), LOG_LEVEL_ERROR);
*status_code = 500;
return "Broken profile!";
}
//std::cerr<<"Trying to parse profile '" + name + "'.\n";
writeLog(0, "Trying to parse profile '" + name + "'.", LOG_LEVEL_INFO);
string_multimap contents;
ini.GetItems("Profile", contents);
ini.get_items("Profile", contents);
if(!contents.size())
{
//std::cerr<<"Load profile failed! Reason: Empty Profile section\n";
@ -1218,12 +1218,12 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS)
writeLog(0, "Ignoring non-exist profile '" + name + "'...", LOG_LEVEL_WARNING);
continue;
}
if(ini.ParseFile(name) != INIREADER_EXCEPTION_NONE && !ini.SectionExist("Profile"))
if(ini.parse_file(name) != INIREADER_EXCEPTION_NONE && !ini.section_exist("Profile"))
{
writeLog(0, "Ignoring broken profile '" + name + "'...", LOG_LEVEL_WARNING);
continue;
}
url = ini.Get("Profile", "url");
url = ini.get("Profile", "url");
if(url.size())
{
all_urls += "|" + url;
@ -1308,16 +1308,16 @@ int simpleGenerator()
}
INIReader ini;
if(ini.Parse(config) != INIREADER_EXCEPTION_NONE)
if(ini.parse(config) != INIREADER_EXCEPTION_NONE)
{
//std::cerr<<"Generator configuration broken! Reason:"<<ini.GetLastError()<<"\n";
writeLog(0, "Generator configuration broken! Reason:" + ini.GetLastError(), LOG_LEVEL_ERROR);
//std::cerr<<"Generator configuration broken! Reason:"<<ini.get_last_error()<<"\n";
writeLog(0, "Generator configuration broken! Reason:" + ini.get_last_error(), LOG_LEVEL_ERROR);
return -2;
}
//std::cerr<<"Read generator configuration completed.\n\n";
writeLog(0, "Read generator configuration completed.\n", LOG_LEVEL_INFO);
string_array sections = ini.GetSections();
string_array sections = ini.get_section_names();
if(global.generateProfiles.size())
{
//std::cerr<<"Generating with specific artifacts: \""<<gen_profile<<"\"...\n";
@ -1352,26 +1352,26 @@ int simpleGenerator()
response.status_code = 200;
//std::cerr<<"Generating artifact '"<<x<<"'...\n";
writeLog(0, "Generating artifact '" + x + "'...", LOG_LEVEL_INFO);
ini.EnterSection(x);
if(ini.ItemExist("path"))
path = ini.Get("path");
ini.enter_section(x);
if(ini.item_exist("path"))
path = ini.get("path");
else
{
//std::cerr<<"Artifact '"<<x<<"' output path missing! Skipping...\n\n";
writeLog(0, "Artifact '" + x + "' output path missing! Skipping...\n", LOG_LEVEL_ERROR);
continue;
}
if(ini.ItemExist("profile"))
if(ini.item_exist("profile"))
{
profile = ini.Get("profile");
profile = ini.get("profile");
request.argument = "name=" + urlEncode(profile) + "&token=" + global.accessToken + "&expand=true";
content = getProfile(request, response);
}
else
{
if(ini.GetBool("direct") == true)
if(ini.get_bool("direct") == true)
{
std::string url = ini.Get("url");
std::string url = ini.get("url");
content = fetchFile(url, proxy, global.cacheSubscription);
if(content.empty())
{
@ -1384,7 +1384,7 @@ int simpleGenerator()
fileWrite(path, "\xEF\xBB\xBF" + content, true);
continue;
}
ini.GetItems(allItems);
ini.get_items(allItems);
allItems.emplace("expand", "true");
for(auto &y : allItems)
{

View File

@ -804,7 +804,7 @@ void readConf()
try
{
std::string prefdata = fileGet(global.prefPath, false);
if(prefdata.find("common:") != prefdata.npos)
if(prefdata.find("common:") != std::string::npos)
{
YAML::Node yaml = YAML::Load(prefdata);
if(yaml.size() && yaml["common"])
@ -830,69 +830,69 @@ void readConf()
INIReader ini;
ini.allow_dup_section_titles = true;
//ini.do_utf8_to_gbk = true;
int retVal = ini.ParseFile(global.prefPath);
int retVal = ini.parse_file(global.prefPath);
if(retVal != INIREADER_EXCEPTION_NONE)
{
writeLog(0, "Unable to load preference settings as INI. Reason: " + ini.GetLastError(), LOG_LEVEL_FATAL);
writeLog(0, "Unable to load preference settings as INI. Reason: " + ini.get_last_error(), LOG_LEVEL_FATAL);
return;
}
string_array tempArray;
ini.EnterSection("common");
ini.GetBoolIfExist("api_mode", global.APIMode);
ini.GetIfExist("api_access_token", global.accessToken);
ini.GetIfExist("default_url", global.defaultUrls);
global.enableInsert = ini.Get("enable_insert");
ini.GetIfExist("insert_url", global.insertUrls);
ini.GetBoolIfExist("prepend_insert_url", global.prependInsert);
if(ini.ItemPrefixExist("exclude_remarks"))
ini.GetAll("exclude_remarks", global.excludeRemarks);
if(ini.ItemPrefixExist("include_remarks"))
ini.GetAll("include_remarks", global.includeRemarks);
global.filterScript = ini.GetBool("enable_filter") ? ini.Get("filter_script"): "";
ini.GetIfExist("base_path", global.basePath);
ini.GetIfExist("clash_rule_base", global.clashBase);
ini.GetIfExist("surge_rule_base", global.surgeBase);
ini.GetIfExist("surfboard_rule_base", global.surfboardBase);
ini.GetIfExist("mellow_rule_base", global.mellowBase);
ini.GetIfExist("quan_rule_base", global.quanBase);
ini.GetIfExist("quanx_rule_base", global.quanXBase);
ini.GetIfExist("loon_rule_base", global.loonBase);
ini.GetIfExist("default_external_config", global.defaultExtConfig);
ini.GetBoolIfExist("append_proxy_type", global.appendType);
ini.GetIfExist("proxy_config", global.proxyConfig);
ini.GetIfExist("proxy_ruleset", global.proxyRuleset);
ini.GetIfExist("proxy_subscription", global.proxySubscription);
ini.enter_section("common");
ini.get_bool_if_exist("api_mode", global.APIMode);
ini.get_if_exist("api_access_token", global.accessToken);
ini.get_if_exist("default_url", global.defaultUrls);
global.enableInsert = ini.get("enable_insert");
ini.get_if_exist("insert_url", global.insertUrls);
ini.get_bool_if_exist("prepend_insert_url", global.prependInsert);
if(ini.item_prefix_exist("exclude_remarks"))
ini.get_all("exclude_remarks", global.excludeRemarks);
if(ini.item_prefix_exist("include_remarks"))
ini.get_all("include_remarks", global.includeRemarks);
global.filterScript = ini.get_bool("enable_filter") ? ini.get("filter_script") : "";
ini.get_if_exist("base_path", global.basePath);
ini.get_if_exist("clash_rule_base", global.clashBase);
ini.get_if_exist("surge_rule_base", global.surgeBase);
ini.get_if_exist("surfboard_rule_base", global.surfboardBase);
ini.get_if_exist("mellow_rule_base", global.mellowBase);
ini.get_if_exist("quan_rule_base", global.quanBase);
ini.get_if_exist("quanx_rule_base", global.quanXBase);
ini.get_if_exist("loon_rule_base", global.loonBase);
ini.get_if_exist("default_external_config", global.defaultExtConfig);
ini.get_bool_if_exist("append_proxy_type", global.appendType);
ini.get_if_exist("proxy_config", global.proxyConfig);
ini.get_if_exist("proxy_ruleset", global.proxyRuleset);
ini.get_if_exist("proxy_subscription", global.proxySubscription);
if(ini.SectionExist("surge_external_proxy"))
if(ini.section_exist("surge_external_proxy"))
{
ini.EnterSection("surge_external_proxy");
ini.GetIfExist("surge_ssr_path", global.surgeSSRPath);
ini.GetBoolIfExist("resolve_hostname", global.surgeResolveHostname);
ini.enter_section("surge_external_proxy");
ini.get_if_exist("surge_ssr_path", global.surgeSSRPath);
ini.get_bool_if_exist("resolve_hostname", global.surgeResolveHostname);
}
if(ini.SectionExist("node_pref"))
if(ini.section_exist("node_pref"))
{
ini.EnterSection("node_pref");
ini.enter_section("node_pref");
/*
ini.GetBoolIfExist("udp_flag", udp_flag);
ini.GetBoolIfExist("tcp_fast_open_flag", tfo_flag);
ini.GetBoolIfExist("skip_cert_verify_flag", scv_flag);
ini.get_bool_if_exist("tcp_fast_open_flag", tfo_flag);
ini.get_bool_if_exist("skip_cert_verify_flag", scv_flag);
*/
global.UDPFlag.set(ini.Get("udp_flag"));
global.TFOFlag.set(ini.Get("tcp_fast_open_flag"));
global.skipCertVerify.set(ini.Get("skip_cert_verify_flag"));
global.TLS13Flag.set(ini.Get("tls13_flag"));
ini.GetBoolIfExist("sort_flag", global.enableSort);
global.sortScript = ini.Get("sort_script");
ini.GetBoolIfExist("filter_deprecated_nodes", global.filterDeprecated);
ini.GetBoolIfExist("append_sub_userinfo", global.appendUserinfo);
ini.GetBoolIfExist("clash_use_new_field_name", global.clashUseNewField);
ini.GetIfExist("clash_proxies_style", global.clashProxiesStyle);
if(ini.ItemPrefixExist("rename_node"))
global.UDPFlag.set(ini.get("udp_flag"));
global.TFOFlag.set(ini.get("tcp_fast_open_flag"));
global.skipCertVerify.set(ini.get("skip_cert_verify_flag"));
global.TLS13Flag.set(ini.get("tls13_flag"));
ini.get_bool_if_exist("sort_flag", global.enableSort);
global.sortScript = ini.get("sort_script");
ini.get_bool_if_exist("filter_deprecated_nodes", global.filterDeprecated);
ini.get_bool_if_exist("append_sub_userinfo", global.appendUserinfo);
ini.get_bool_if_exist("clash_use_new_field_name", global.clashUseNewField);
ini.get_if_exist("clash_proxies_style", global.clashProxiesStyle);
if(ini.item_prefix_exist("rename_node"))
{
ini.GetAll("rename_node", tempArray);
ini.get_all("rename_node", tempArray);
importItems(tempArray, false);
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, "@");
safe_set_renames(configs);
@ -900,20 +900,20 @@ void readConf()
}
}
if(ini.SectionExist("userinfo"))
if(ini.section_exist("userinfo"))
{
ini.EnterSection("userinfo");
if(ini.ItemPrefixExist("stream_rule"))
ini.enter_section("userinfo");
if(ini.item_prefix_exist("stream_rule"))
{
ini.GetAll("stream_rule", tempArray);
ini.get_all("stream_rule", tempArray);
importItems(tempArray, false);
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, "|");
safe_set_streams(configs);
eraseElements(tempArray);
}
if(ini.ItemPrefixExist("time_rule"))
if(ini.item_prefix_exist("time_rule"))
{
ini.GetAll("time_rule", tempArray);
ini.get_all("time_rule", tempArray);
importItems(tempArray, false);
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, "|");
safe_set_times(configs);
@ -921,45 +921,45 @@ void readConf()
}
}
ini.EnterSection("managed_config");
ini.GetBoolIfExist("write_managed_config", global.writeManagedConfig);
ini.GetIfExist("managed_config_prefix", global.managedConfigPrefix);
ini.GetIntIfExist("config_update_interval", global.updateInterval);
ini.GetBoolIfExist("config_update_strict", global.updateStrict);
ini.GetIfExist("quanx_device_id", global.quanXDevID);
ini.enter_section("managed_config");
ini.get_bool_if_exist("write_managed_config", global.writeManagedConfig);
ini.get_if_exist("managed_config_prefix", global.managedConfigPrefix);
ini.get_int_if_exist("config_update_interval", global.updateInterval);
ini.get_bool_if_exist("config_update_strict", global.updateStrict);
ini.get_if_exist("quanx_device_id", global.quanXDevID);
ini.EnterSection("emojis");
ini.GetBoolIfExist("add_emoji", global.addEmoji);
ini.GetBoolIfExist("remove_old_emoji", global.removeEmoji);
if(ini.ItemPrefixExist("rule"))
ini.enter_section("emojis");
ini.get_bool_if_exist("add_emoji", global.addEmoji);
ini.get_bool_if_exist("remove_old_emoji", global.removeEmoji);
if(ini.item_prefix_exist("rule"))
{
ini.GetAll("rule", tempArray);
ini.get_all("rule", tempArray);
importItems(tempArray, false);
auto configs = INIBinding::from<RegexMatchConfig>::from_ini(tempArray, ",");
safe_set_emojis(configs);
eraseElements(tempArray);
}
if(ini.SectionExist("rulesets"))
ini.EnterSection("rulesets");
if(ini.section_exist("rulesets"))
ini.enter_section("rulesets");
else
ini.EnterSection("ruleset");
global.enableRuleGen = ini.GetBool("enabled");
ini.enter_section("ruleset");
global.enableRuleGen = ini.get_bool("enabled");
if(global.enableRuleGen)
{
ini.GetBoolIfExist("overwrite_original_rules", global.overwriteOriginalRules);
ini.GetBoolIfExist("update_ruleset_on_request", global.updateRulesetOnRequest);
if(ini.ItemPrefixExist("ruleset"))
ini.get_bool_if_exist("overwrite_original_rules", global.overwriteOriginalRules);
ini.get_bool_if_exist("update_ruleset_on_request", global.updateRulesetOnRequest);
if(ini.item_prefix_exist("ruleset"))
{
string_array vArray;
ini.GetAll("ruleset", vArray);
ini.get_all("ruleset", vArray);
importItems(vArray, false);
global.customRulesets = INIBinding::from<RulesetConfig>::from_ini(vArray);
}
else if(ini.ItemPrefixExist("surge_ruleset"))
else if(ini.item_prefix_exist("surge_ruleset"))
{
string_array vArray;
ini.GetAll("surge_ruleset", vArray);
ini.get_all("surge_ruleset", vArray);
importItems(vArray, false);
global.customRulesets = INIBinding::from<RulesetConfig>::from_ini(vArray);
}
@ -970,22 +970,22 @@ void readConf()
global.updateRulesetOnRequest = false;
}
if(ini.SectionExist("proxy_groups"))
ini.EnterSection("proxy_groups");
if(ini.section_exist("proxy_groups"))
ini.enter_section("proxy_groups");
else
ini.EnterSection("clash_proxy_group");
if(ini.ItemPrefixExist("custom_proxy_group"))
ini.enter_section("clash_proxy_group");
if(ini.item_prefix_exist("custom_proxy_group"))
{
string_array vArray;
ini.GetAll("custom_proxy_group", vArray);
ini.get_all("custom_proxy_group", vArray);
importItems(vArray, false);
global.customProxyGroups = INIBinding::from<ProxyGroupConfig>::from_ini(vArray);
}
ini.EnterSection("template");
ini.GetIfExist("template_path", global.templatePath);
ini.enter_section("template");
ini.get_if_exist("template_path", global.templatePath);
string_multimap tempmap;
ini.GetItems(tempmap);
ini.get_items(tempmap);
eraseElements(global.templateVars);
for(auto &x : tempmap)
{
@ -995,36 +995,36 @@ void readConf()
}
global.templateVars["managed_config_prefix"] = global.managedConfigPrefix;
if(ini.SectionExist("aliases"))
if(ini.section_exist("aliases"))
{
ini.EnterSection("aliases");
ini.GetItems(tempmap);
ini.enter_section("aliases");
ini.get_items(tempmap);
webServer.reset_redirect();
for(auto &x : tempmap)
webServer.append_redirect(x.first, x.second);
}
if(ini.SectionExist("tasks"))
if(ini.section_exist("tasks"))
{
string_array vArray;
ini.EnterSection("tasks");
ini.GetAll("task", vArray);
ini.enter_section("tasks");
ini.get_all("task", vArray);
importItems(vArray, false);
global.enableCron = !vArray.empty();
global.cronTasks = INIBinding::from<CronTaskConfig>::from_ini(vArray);
refresh_schedule();
}
ini.EnterSection("server");
ini.GetIfExist("listen", global.listenAddress);
ini.GetIntIfExist("port", global.listenPort);
webServer.serve_file_root = ini.Get("serve_file_root");
ini.enter_section("server");
ini.get_if_exist("listen", global.listenAddress);
ini.get_int_if_exist("port", global.listenPort);
webServer.serve_file_root = ini.get("serve_file_root");
webServer.serve_file = !webServer.serve_file_root.empty();
ini.EnterSection("advanced");
ini.enter_section("advanced");
std::string log_level;
ini.GetIfExist("log_level", log_level);
ini.GetBoolIfExist("print_debug_info", global.printDbgInfo);
ini.get_if_exist("log_level", log_level);
ini.get_bool_if_exist("print_debug_info", global.printDbgInfo);
if(global.printDbgInfo)
global.logLevel = LOG_LEVEL_VERBOSE;
else
@ -1050,19 +1050,19 @@ void readConf()
global.logLevel = LOG_LEVEL_INFO;
}
}
ini.GetIntIfExist("max_pending_connections", global.maxPendingConns);
ini.GetIntIfExist("max_concurrent_threads", global.maxConcurThreads);
ini.GetNumberIfExist("max_allowed_rulesets", global.maxAllowedRulesets);
ini.GetNumberIfExist("max_allowed_rules", global.maxAllowedRules);
ini.GetNumberIfExist("max_allowed_download_size", global.maxAllowedDownloadSize);
if(ini.ItemExist("enable_cache"))
ini.get_int_if_exist("max_pending_connections", global.maxPendingConns);
ini.get_int_if_exist("max_concurrent_threads", global.maxConcurThreads);
ini.get_number_if_exist("max_allowed_rulesets", global.maxAllowedRulesets);
ini.get_number_if_exist("max_allowed_rules", global.maxAllowedRules);
ini.get_number_if_exist("max_allowed_download_size", global.maxAllowedDownloadSize);
if(ini.item_exist("enable_cache"))
{
if(ini.GetBool("enable_cache"))
if(ini.get_bool("enable_cache"))
{
ini.GetIntIfExist("cache_subscription", global.cacheSubscription);
ini.GetIntIfExist("cache_config", global.cacheConfig);
ini.GetIntIfExist("cache_ruleset", global.cacheRuleset);
ini.GetBoolIfExist("serve_cache_on_fetch_fail", global.serveCacheOnFetchFail);
ini.get_int_if_exist("cache_subscription", global.cacheSubscription);
ini.get_int_if_exist("cache_config", global.cacheConfig);
ini.get_int_if_exist("cache_ruleset", global.cacheRuleset);
ini.get_bool_if_exist("serve_cache_on_fetch_fail", global.serveCacheOnFetchFail);
}
else
{
@ -1070,9 +1070,9 @@ void readConf()
global.serveCacheOnFetchFail = false;
}
}
ini.GetBoolIfExist("script_clean_context", global.scriptCleanContext);
ini.GetBoolIfExist("async_fetch_ruleset", global.asyncFetchRuleset);
ini.GetBoolIfExist("skip_failed_links", global.skipFailedLinks);
ini.get_bool_if_exist("script_clean_context", global.scriptCleanContext);
ini.get_bool_if_exist("async_fetch_ruleset", global.asyncFetchRuleset);
ini.get_bool_if_exist("skip_failed_links", global.skipFailedLinks);
writeLog(0, "Load preference settings in INI format completed.", LOG_LEVEL_INFO);
}
@ -1227,27 +1227,27 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
INIReader ini;
ini.store_isolated_line = true;
ini.SetIsolatedItemsSection("custom");
if(ini.Parse(base_content) != INIREADER_EXCEPTION_NONE)
ini.set_isolated_items_section("custom");
if(ini.parse(base_content) != INIREADER_EXCEPTION_NONE)
{
//std::cerr<<"Load external configuration failed. Reason: "<<ini.GetLastError()<<"\n";
writeLog(0, "Load external configuration failed. Reason: " + ini.GetLastError(), LOG_LEVEL_ERROR);
//std::cerr<<"Load external configuration failed. Reason: "<<ini.get_last_error()<<"\n";
writeLog(0, "Load external configuration failed. Reason: " + ini.get_last_error(), LOG_LEVEL_ERROR);
return -1;
}
ini.EnterSection("custom");
if(ini.ItemPrefixExist("custom_proxy_group"))
ini.enter_section("custom");
if(ini.item_prefix_exist("custom_proxy_group"))
{
string_array vArray;
ini.GetAll("custom_proxy_group", vArray);
ini.get_all("custom_proxy_group", vArray);
importItems(vArray, global.APIMode);
ext.custom_proxy_group = INIBinding::from<ProxyGroupConfig>::from_ini(vArray);
}
std::string ruleset_name = ini.ItemPrefixExist("ruleset") ? "ruleset" : "surge_ruleset";
if(ini.ItemPrefixExist(ruleset_name))
std::string ruleset_name = ini.item_prefix_exist("ruleset") ? "ruleset" : "surge_ruleset";
if(ini.item_prefix_exist(ruleset_name))
{
string_array vArray;
ini.GetAll(ruleset_name, vArray);
ini.get_all(ruleset_name, vArray);
importItems(vArray, global.APIMode);
if(global.maxAllowedRulesets && vArray.size() > global.maxAllowedRulesets)
{
@ -1257,44 +1257,44 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
ext.surge_ruleset = INIBinding::from<RulesetConfig>::from_ini(vArray);
}
ini.GetIfExist("clash_rule_base", ext.clash_rule_base);
ini.GetIfExist("surge_rule_base", ext.surge_rule_base);
ini.GetIfExist("surfboard_rule_base", ext.surfboard_rule_base);
ini.GetIfExist("mellow_rule_base", ext.mellow_rule_base);
ini.GetIfExist("quan_rule_base", ext.quan_rule_base);
ini.GetIfExist("quanx_rule_base", ext.quanx_rule_base);
ini.GetIfExist("loon_rule_base", ext.loon_rule_base);
ini.GetIfExist("sssub_rule_base", ext.sssub_rule_base);
ini.get_if_exist("clash_rule_base", ext.clash_rule_base);
ini.get_if_exist("surge_rule_base", ext.surge_rule_base);
ini.get_if_exist("surfboard_rule_base", ext.surfboard_rule_base);
ini.get_if_exist("mellow_rule_base", ext.mellow_rule_base);
ini.get_if_exist("quan_rule_base", ext.quan_rule_base);
ini.get_if_exist("quanx_rule_base", ext.quanx_rule_base);
ini.get_if_exist("loon_rule_base", ext.loon_rule_base);
ini.get_if_exist("sssub_rule_base", ext.sssub_rule_base);
ini.GetBoolIfExist("overwrite_original_rules", ext.overwrite_original_rules);
ini.GetBoolIfExist("enable_rule_generator", ext.enable_rule_generator);
ini.get_bool_if_exist("overwrite_original_rules", ext.overwrite_original_rules);
ini.get_bool_if_exist("enable_rule_generator", ext.enable_rule_generator);
if(ini.ItemPrefixExist("rename"))
if(ini.item_prefix_exist("rename"))
{
string_array vArray;
ini.GetAll("rename", vArray);
ini.get_all("rename", vArray);
importItems(vArray, global.APIMode);
ext.rename = INIBinding::from<RegexMatchConfig>::from_ini(vArray, "@");
}
ext.add_emoji = ini.Get("add_emoji");
ext.remove_old_emoji = ini.Get("remove_old_emoji");
if(ini.ItemPrefixExist("emoji"))
ext.add_emoji = ini.get("add_emoji");
ext.remove_old_emoji = ini.get("remove_old_emoji");
if(ini.item_prefix_exist("emoji"))
{
string_array vArray;
ini.GetAll("emoji", vArray);
ini.get_all("emoji", vArray);
importItems(vArray, global.APIMode);
ext.emoji = INIBinding::from<RegexMatchConfig>::from_ini(vArray, ",");
}
if(ini.ItemPrefixExist("include_remarks"))
ini.GetAll("include_remarks", ext.include);
if(ini.ItemPrefixExist("exclude_remarks"))
ini.GetAll("exclude_remarks", ext.exclude);
if(ini.item_prefix_exist("include_remarks"))
ini.get_all("include_remarks", ext.include);
if(ini.item_prefix_exist("exclude_remarks"))
ini.get_all("exclude_remarks", ext.exclude);
if(ini.SectionExist("template") && ext.tpl_args != nullptr)
if(ini.section_exist("template") && ext.tpl_args != nullptr)
{
ini.EnterSection("template");
ini.enter_section("template");
string_multimap tempmap;
ini.GetItems(tempmap);
ini.get_items(tempmap);
for(auto &x : tempmap)
ext.tpl_args->local_vars[x.first] = x.second;
}

View File

@ -41,15 +41,15 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
return -1;
}
ini.ParseFile("gistconf.ini");
if(ini.EnterSection("common") != 0)
ini.parse_file("gistconf.ini");
if(ini.enter_section("common") != 0)
{
//std::cerr<<"gistconf.ini has incorrect format. Skipping...\n";
writeLog(0, "gistconf.ini has incorrect format. Skipping...", LOG_LEVEL_ERROR);
return -1;
}
token = ini.Get("token");
token = ini.get("token");
if(!token.size())
{
//std::cerr<<"No token is provided. Skipping...\n";
@ -57,12 +57,12 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
return -1;
}
id = ini.Get("id");
username = ini.Get("username");
id = ini.get("id");
username = ini.get("username");
if(!path.size())
{
if(ini.ItemExist("path"))
path = ini.Get(name, "path");
if(ini.item_exist("path"))
path = ini.get(name, "path");
else
path = name;
}
@ -102,16 +102,16 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
//std::cerr<<"Writing to Gist success!\nGenerator: "<<name<<"\nPath: "<<path<<"\nRaw URL: "<<url<<"\nGist owner: "<<username<<"\n";
writeLog(0, "Writing to Gist success!\nGenerator: " + name + "\nPath: " + path + "\nRaw URL: " + url + "\nGist owner: " + username, LOG_LEVEL_INFO);
ini.EraseSection();
ini.Set("token", token);
ini.Set("id", id);
ini.Set("username", username);
ini.erase_section();
ini.set("token", token);
ini.set("id", id);
ini.set("username", username);
ini.SetCurrentSection(path);
ini.EraseSection();
ini.Set("type", name);
ini.Set("url", url);
ini.set_current_section(path);
ini.erase_section();
ini.set("type", name);
ini.set("url", url);
ini.ToFile("gistconf.ini");
ini.to_file("gistconf.ini");
return 0;
}

View File

@ -295,10 +295,10 @@ static int curlGet(const FetchArgument &argument, FetchResult &result)
static std::string dataGet(const std::string &url)
{
if (!startsWith(url, "data:"))
return std::string();
return "";
std::string::size_type comma = url.find(',');
if (comma == std::string::npos || comma == url.size() - 1)
return std::string();
return "";
std::string data = urlDecode(url.substr(comma + 1));
if (endsWith(url.substr(0, comma), ";base64")) {

View File

@ -4,4 +4,4 @@
Settings global;
bool fileExist(const std::string&, bool) { return false; }
std::string fileGet(const std::string&, bool) { return std::string(); }
std::string fileGet(const std::string&, bool) { return ""; }

View File

@ -169,9 +169,9 @@ int main(int argc, char *argv[])
std::string env_api_mode = getEnv("API_MODE"), env_managed_prefix = getEnv("MANAGED_PREFIX"), env_token = getEnv("API_TOKEN");
global.APIMode = tribool().parse(toLower(env_api_mode)).get(global.APIMode);
if(env_managed_prefix.size())
if(!env_managed_prefix.empty())
global.managedConfigPrefix = env_managed_prefix;
if(env_token.size())
if(!env_token.empty())
global.accessToken = env_token;
if(global.generatorMode)
@ -191,7 +191,7 @@ int main(int argc, char *argv[])
webServer.append_response("GET", "/refreshrules", "text/plain", [](RESPONSE_CALLBACK_ARGS) -> std::string
{
if(global.accessToken.size())
if(!global.accessToken.empty())
{
std::string token = getUrlArg(request.argument, "token");
if(token != global.accessToken)
@ -206,7 +206,7 @@ int main(int argc, char *argv[])
webServer.append_response("GET", "/readconf", "text/plain", [](RESPONSE_CALLBACK_ARGS) -> std::string
{
if(global.accessToken.size())
if(!global.accessToken.empty())
{
std::string token = getUrlArg(request.argument, "token");
if(token != global.accessToken)
@ -223,7 +223,7 @@ int main(int argc, char *argv[])
webServer.append_response("POST", "/updateconf", "text/plain", [](RESPONSE_CALLBACK_ARGS) -> std::string
{
if(global.accessToken.size())
if(!global.accessToken.empty())
{
std::string token = getUrlArg(request.argument, "token");
if(token != global.accessToken)

View File

@ -1293,17 +1293,17 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
ini.store_isolated_line = true;
ini.keep_empty_section = false;
ini.allow_dup_section_titles = true;
ini.SetIsolatedItemsSection("Proxy");
ini.IncludeSection("Proxy");
ini.AddDirectSaveSection("Proxy");
ini.set_isolated_items_section("Proxy");
ini.include_section("Proxy");
ini.add_direct_save_section("Proxy");
if(surge.find("[Proxy]") != surge.npos)
surge = regReplace(surge, "^[\\S\\s]*?\\[", "[", false);
ini.Parse(surge);
surge = regReplace(surge, R"(^[\S\s]*?\[)", "[", false);
ini.parse(surge);
if(!ini.SectionExist("Proxy"))
if(!ini.section_exist("Proxy"))
return false;
ini.EnterSection("Proxy");
ini.GetItems(proxies);
ini.enter_section("Proxy");
ini.get_items(proxies);
const std::string proxystr = "(.*?)\\s*=\\s*(.*)";

View File

@ -2,7 +2,7 @@
#include <fstream>
#include <sys/stat.h>
#include "string.h"
#include "utils/string.h"
bool isInScope(const std::string &path)
{
@ -22,7 +22,7 @@ std::string fileGet(const std::string &path, bool scope_limit)
std::string content;
if(scope_limit && !isInScope(path))
return std::string();
return "";
std::FILE *fp = std::fopen(path.c_str(), "rb");
if(fp)

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@ std::string hostnameToIPAddr(const std::string &host)
if(retVal != 0)
{
freeaddrinfo(retAddrInfo);
return std::string();
return "";
}
for(cur = retAddrInfo; cur != NULL; cur = cur->ai_next)

View File

@ -21,7 +21,7 @@ template <typename T> void exception_thrower(T e)
inline void operator >> (const rapidjson::Value& value, std::string& i)
{
if(value.IsNull())
i = std::string();
i = "";
else if(value.IsString())
i = std::string(value.GetString());
else if(value.IsInt64())
@ -31,7 +31,7 @@ inline void operator >> (const rapidjson::Value& value, std::string& i)
else if(value.IsDouble())
i = std::to_string(value.GetDouble());
else
i = std::string();
i = "";
}
inline void operator >> (const rapidjson::Value& value, int& i)

View File

@ -234,13 +234,13 @@ std::string trimWhitespace(const std::string &str, bool before, bool after)
{
epos = str.find_last_not_of(whitespaces);
if(epos == std::string::npos)
return std::string();
return "";
}
if(before)
{
bpos = str.find_first_not_of(whitespaces);
if(bpos == std::string::npos)
return std::string();
return "";
}
return str.substr(bpos, epos - bpos + 1);
}
@ -295,7 +295,7 @@ std::string getUrlArg(const std::string &url, const std::string &request)
break;
pos--;
}
return std::string();
return "";
}
std::string replaceAllDistinct(std::string str, const std::string &old_value, const std::string &new_value)

View File

@ -7,6 +7,7 @@
#include <vector>
#include <map>
using string = std::string;
using string_size = std::string::size_type;
using string_array = std::vector<std::string>;
using string_map = std::map<std::string, std::string>;

View File

@ -50,7 +50,7 @@ std::string getSystemProxy()
if(ret != ERROR_SUCCESS)
{
//std::cout << "open failed: " << ret << std::endl;
return std::string();
return "";
}
DWORD values_count, max_value_name_len, max_value_len;
@ -59,7 +59,7 @@ std::string getSystemProxy()
if(ret != ERROR_SUCCESS)
{
//std::cout << "query failed" << std::endl;
return std::string();
return "";
}
std::vector<std::tuple<std::shared_ptr<char>, DWORD, std::shared_ptr<BYTE>>> values;
@ -103,7 +103,7 @@ std::string getSystemProxy()
}
*/
//return 0;
return std::string();
return "";
#else
string_array proxy_env = {"all_proxy", "ALL_PROXY", "http_proxy", "HTTP_PROXY", "https_proxy", "HTTPS_PROXY"};
for(std::string &x : proxy_env)
@ -112,6 +112,6 @@ std::string getSystemProxy()
if(proxy != NULL)
return std::string(proxy);
}
return std::string();
return "";
#endif // _WIN32
}