Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/config/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,21 +285,37 @@ namespace INIBinding
if(pos == String::npos)
continue;
conf.Group = x.substr(0, pos);
if(x.substr(pos + 1, 2) == "[]")
String rest = x.substr(pos + 1);
if(rest.substr(0, 2) == "[]")
{
conf.Url = x.substr(pos + 1);
//conf.Type = RulesetType::SurgeRuleset;
conf.Url = rest;
confs.emplace_back(std::move(conf));
continue;
}
String::size_type epos = x.rfind(",");
if(pos != epos)
String::size_type fpos = rest.rfind(",flags=");
if(fpos != String::npos)
{
conf.Interval = to_int(x.substr(epos + 1), 0);
conf.Url = x.substr(pos + 1, epos - pos - 1);
String flags_part = rest.substr(fpos + 7);
String::size_type ipos = flags_part.find(',');
if(ipos != String::npos)
{
conf.Interval = to_int(flags_part.substr(ipos + 1), 0);
conf.Url = rest.substr(0, fpos) + ",flags=" + flags_part.substr(0, ipos);
}
else
conf.Url = rest;
}
else
conf.Url = x.substr(pos + 1);
{
String::size_type epos = rest.rfind(",");
if(epos != String::npos)
{
conf.Interval = to_int(rest.substr(epos + 1), 0);
conf.Url = rest.substr(0, epos);
}
else
conf.Url = rest;
}
confs.emplace_back(std::move(conf));
}
return confs;
Expand Down
10 changes: 6 additions & 4 deletions src/generator/config/ruleconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,12 @@ void rulesetToSurge(INIReader &base_rule, std::vector<RulesetContent> &ruleset_c
std::string flags_a = extract_flags_from_tail(rule_path);
std::string flags_b = extract_flags_from_tail(rule_path_typed);
std::string merged_flags;
if(!flags_a.empty() && !flags_b.empty())
merged_flags = flags_b + "|" + flags_a;
else
merged_flags = !flags_b.empty() ? flags_b : flags_a;
if(!flags_b.empty())
merged_flags = flags_b;
if(!flags_a.empty())
merged_flags += (merged_flags.empty() ? "" : "|") + flags_a;
if(!x.flags.empty())
merged_flags += (merged_flags.empty() ? "" : "|") + x.flags;

if(rule_path.empty())
{
Expand Down
1 change: 1 addition & 0 deletions src/generator/config/ruleconvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct RulesetContent
std::string rule_group;
std::string rule_path;
std::string rule_path_typed;
std::string flags;
int rule_type = RULESET_SURGE;
std::shared_future<std::string> rule_content;
int update_interval = 0;
Expand Down
15 changes: 11 additions & 4 deletions src/handler/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void readRuleset(YAML::Node node, string_array &dest, bool scope_limit = true)
void refreshRulesets(RulesetConfigs &ruleset_list, std::vector<RulesetContent> &ruleset_content_array)
{
eraseElements(ruleset_content_array);
std::string rule_group, rule_url, rule_url_typed, interval;
std::string rule_group, rule_url, rule_url_typed, flags;
RulesetContent rc;

std::string proxy = parseProxy(global.proxyRuleset);
Expand All @@ -257,11 +257,18 @@ void refreshRulesets(RulesetConfigs &ruleset_list, std::vector<RulesetContent> &
{
rule_group = x.Group;
rule_url = x.Url;
std::string::size_type pos = x.Url.find("[]");
flags.clear();
std::string::size_type fpos = rule_url.rfind(",flags=");
if(fpos != std::string::npos)
{
flags = rule_url.substr(fpos + 7);
rule_url.erase(fpos);
}
std::string::size_type pos = rule_url.find("[]");
if(pos != std::string::npos)
{
writeLog(0, "Adding rule '" + rule_url.substr(pos + 2) + "," + rule_group + "'.", LOG_LEVEL_INFO);
rc = {rule_group, "", "", RULESET_SURGE, std::async(std::launch::async, [=](){return rule_url.substr(pos);}), 0};
rc = {rule_group, "", "", flags, RULESET_SURGE, std::async(std::launch::async, [=](){return rule_url.substr(pos);}), 0};
}
else
{
Expand All @@ -274,7 +281,7 @@ void refreshRulesets(RulesetConfigs &ruleset_list, std::vector<RulesetContent> &
type = iter->second;
}
writeLog(0, "Updating ruleset url '" + rule_url + "' with group '" + rule_group + "'.", LOG_LEVEL_INFO);
rc = {rule_group, rule_url, rule_url_typed, type, fetchFileAsync(rule_url, proxy, global.cacheRuleset, true, global.asyncFetchRuleset), x.Interval};
rc = {rule_group, rule_url, rule_url_typed, flags, type, fetchFileAsync(rule_url, proxy, global.cacheRuleset, true, global.asyncFetchRuleset), x.Interval};
}
ruleset_content_array.emplace_back(std::move(rc));
}
Expand Down
Loading