diff --git a/scripts/build.alpine.release.sh b/scripts/build.alpine.release.sh index 2dba424fe..304492d01 100644 --- a/scripts/build.alpine.release.sh +++ b/scripts/build.alpine.release.sh @@ -34,7 +34,7 @@ cmake -DCMAKE_BUILD_TYPE=Release . make libcron install -j3 cd .. -git clone https://github.com/ToruNiina/toml11 --branch="v3.7.1" --depth=1 +git clone https://github.com/ToruNiina/toml11 --branch="v4.3.0" --depth=1 cd toml11 cmake -DCMAKE_CXX_STANDARD=11 . make install -j4 diff --git a/scripts/build.macos.release.sh b/scripts/build.macos.release.sh index e554c9964..96ef52203 100644 --- a/scripts/build.macos.release.sh +++ b/scripts/build.macos.release.sh @@ -41,7 +41,7 @@ sudo install -d /usr/local/include/date/ sudo install -m644 libcron/externals/date/include/date/* /usr/local/include/date/ cd .. -git clone https://github.com/ToruNiina/toml11 --branch="v3.7.1" --depth=1 +git clone https://github.com/ToruNiina/toml11 --branch="v4.3.0" --depth=1 cd toml11 cmake -DCMAKE_CXX_STANDARD=11 . sudo make install -j6 > /dev/null diff --git a/scripts/build.windows.release.sh b/scripts/build.windows.release.sh index 2b3e49bb6..c085989ad 100644 --- a/scripts/build.windows.release.sh +++ b/scripts/build.windows.release.sh @@ -38,7 +38,7 @@ cmake -DRAPIDJSON_BUILD_DOC=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD make install -j4 cd .. -git clone https://github.com/ToruNiina/toml11 --branch v3.8.1 --depth=1 +git clone https://github.com/ToruNiina/toml11 --branch "v4.3.0" --depth=1 cd toml11 cmake -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=11 . make install -j4 diff --git a/src/config/binding.h b/src/config/binding.h index c6e3c07a8..e069869d5 100644 --- a/src/config/binding.h +++ b/src/config/binding.h @@ -17,9 +17,9 @@ namespace toml static ProxyGroupConfig from_toml(const value& v) { ProxyGroupConfig conf; - conf.Name = toml::find(v, "name"); - String type = toml::find(v, "type"); - String strategy = toml::find_or(v, "strategy", ""); + conf.Name = find(v, "name"); + String type = find(v, "type"); + String strategy = find_or(v, "strategy", ""); switch(hash_(type)) { case "select"_hash: @@ -27,18 +27,18 @@ namespace toml break; case "url-test"_hash: conf.Type = ProxyGroupType::URLTest; - conf.Url = toml::find(v, "url"); - conf.Interval = toml::find(v, "interval"); - conf.Tolerance = toml::find_or(v, "tolerance", 0); + conf.Url = find(v, "url"); + conf.Interval = find(v, "interval"); + conf.Tolerance = find_or(v, "tolerance", 0); if(v.contains("lazy")) - conf.Lazy = toml::find_or(v, "lazy", false); + conf.Lazy = find_or(v, "lazy", false); if(v.contains("evaluate-before-use")) - conf.EvaluateBeforeUse = toml::find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get()); + conf.EvaluateBeforeUse = find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get()); break; case "load-balance"_hash: conf.Type = ProxyGroupType::LoadBalance; - conf.Url = toml::find(v, "url"); - conf.Interval = toml::find(v, "interval"); + conf.Url = find(v, "url"); + conf.Interval = find(v, "interval"); switch(hash_(strategy)) { case "consistent-hashing"_hash: @@ -49,14 +49,14 @@ namespace toml break; } if(v.contains("persistent")) - conf.Persistent = toml::find_or(v, "persistent", conf.Persistent.get()); + conf.Persistent = find_or(v, "persistent", conf.Persistent.get()); break; case "fallback"_hash: conf.Type = ProxyGroupType::Fallback; - conf.Url = toml::find(v, "url"); - conf.Interval = toml::find(v, "interval"); + conf.Url = find(v, "url"); + conf.Interval = find(v, "interval"); if(v.contains("evaluate-before-use")) - conf.EvaluateBeforeUse = toml::find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get()); + conf.EvaluateBeforeUse = find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get()); break; case "relay"_hash: conf.Type = ProxyGroupType::Relay; @@ -66,24 +66,24 @@ namespace toml break; case "smart"_hash: conf.Type = ProxyGroupType::Smart; - conf.Url = toml::find(v, "url"); - conf.Interval = toml::find(v, "interval"); - conf.Tolerance = toml::find_or(v, "tolerance", 0); + conf.Url = find(v, "url"); + conf.Interval = find(v, "interval"); + conf.Tolerance = find_or(v, "tolerance", 0); if(v.contains("lazy")) - conf.Lazy = toml::find_or(v, "lazy", false); + conf.Lazy = find_or(v, "lazy", false); if(v.contains("evaluate-before-use")) - conf.EvaluateBeforeUse = toml::find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get()); + conf.EvaluateBeforeUse = find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get()); break; default: - throw toml::syntax_error("Proxy Group has incorrect type, should be one of following:\n select, url-test, load-balance, fallback, relay, ssid", v.at("type").location()); + throw serialization_error(format_error("Proxy Group has unsupported type!", v.at("type").location(), "should be one of following: select, url-test, load-balance, fallback, relay, ssid"), v.at("type").location()); } - conf.Timeout = toml::find_or(v, "timeout", 5); - conf.Proxies = toml::find_or(v, "rule", {}); - conf.UsingProvider = toml::find_or(v, "use", {}); + conf.Timeout = find_or(v, "timeout", 5); + conf.Proxies = find_or(v, "rule", {}); + conf.UsingProvider = find_or(v, "use", {}); if(conf.Proxies.empty() && conf.UsingProvider.empty()) - throw toml::syntax_error("Proxy Group must contains at least one of proxy match rule or provider", v.location()); + throw serialization_error(format_error("Proxy Group must contains at least one of proxy match rule or provider!", v.location(), "here"), v.location()); if(v.contains("disable-udp")) - conf.DisableUdp = toml::find_or(v, "disable-udp", conf.DisableUdp.get()); + conf.DisableUdp = find_or(v, "disable-udp", conf.DisableUdp.get()); return conf; } }; @@ -94,8 +94,8 @@ namespace toml static RulesetConfig from_toml(const value& v) { RulesetConfig conf; - conf.Group = toml::find(v, "group"); - String type = toml::find_or(v, "type", "surge-ruleset"); + conf.Group = find(v, "group"); + String type = find_or(v, "type", "surge-ruleset"); switch(hash_(type)) { /* @@ -132,10 +132,10 @@ namespace toml conf.Url = type + ":"; break; default: - throw toml::syntax_error("Ruleset has incorrect type, should be one of following:\n surge-ruleset, quantumultx, clash-domain, clash-ipcidr, clash-classic", v.at("type").location()); + throw serialization_error(format_error("Ruleset has unsupported type!", v.at("type").location(), "should be one of following: surge-ruleset, quantumultx, clash-domain, clash-ipcidr, clash-classic"), v.at("type").location()); } - conf.Url += toml::find(v, "ruleset"); - conf.Interval = toml::find_or(v, "interval", 86400); + conf.Url += find(v, "ruleset"); + conf.Interval = find_or(v, "interval", 86400); return conf; } }; @@ -148,14 +148,14 @@ namespace toml RegexMatchConfig conf; if(v.contains("script")) { - conf.Script = toml::find(v, "script"); + conf.Script = find(v, "script"); return conf; } - conf.Match = toml::find(v, "match"); + conf.Match = find(v, "match"); if(v.contains("emoji")) - conf.Replace = toml::find(v, "emoji"); + conf.Replace = find(v, "emoji"); else - conf.Replace = toml::find(v, "replace"); + conf.Replace = find(v, "replace"); return conf; } }; @@ -166,10 +166,10 @@ namespace toml static CronTaskConfig from_toml(const value& v) { CronTaskConfig conf; - conf.Name = toml::find(v, "name"); - conf.CronExp = toml::find(v, "cronexp"); - conf.Path = toml::find(v, "path"); - conf.Timeout = toml::find_or(v, "timeout", 0); + conf.Name = find(v, "name"); + conf.CronExp = find(v, "cronexp"); + conf.Path = find(v, "path"); + conf.Timeout = find_or(v, "timeout", 0); return conf; } }; diff --git a/src/handler/settings.cpp b/src/handler/settings.cpp index 86e399e87..a90bec7a8 100644 --- a/src/handler/settings.cpp +++ b/src/handler/settings.cpp @@ -567,13 +567,13 @@ void readYAMLConf(YAML::Node &node) } template -void find_if_exist(const toml::value &v, const toml::key &k, T& target, U&&... args) +void find_if_exist(const toml::value &v, const toml::value::key_type &k, T& target, U&&... args) { if(v.contains(k)) target = toml::find(v, k); if constexpr (sizeof...(args) > 0) find_if_exist(v, std::forward(args)...); } -void operate_toml_kv_table(const std::vector &arr, const toml::key &key_name, const toml::key &value_name, std::function binary_op) +void operate_toml_kv_table(const std::vector &arr, const toml::value::key_type &key_name, const toml::value::key_type &value_name, std::function binary_op) { for(const toml::table &table : arr) { @@ -803,7 +803,7 @@ void readConf() return readYAMLConf(yaml); } toml::value conf = parseToml(prefdata, global.prefPath); - if(!conf.is_uninitialized() && toml::find_or(conf, "version", 0)) + if(!conf.is_empty() && toml::find_or(conf, "version", 0)) return readTOMLConf(conf); } catch (YAML::Exception &e) @@ -1213,7 +1213,7 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext) if(yaml.size() && yaml["custom"].IsDefined()) return loadExternalYAML(yaml, ext); toml::value conf = parseToml(base_content, path); - if(!conf.is_uninitialized() && toml::find_or(conf, "version", 0)) + if(!conf.is_empty() && toml::find_or(conf, "version", 0)) return loadExternalTOML(conf, ext); } catch (YAML::Exception &e)