mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-03 10:12:50 +00:00
Fix logic error on generating Clash rule-providers
Optimize codes.
This commit is contained in:
11 files changed
+20
-29
No files matched your search
+1
-1
@@ -128,7 +128,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Parse a file during initialization.
|
* @brief Parse a file during initialization.
|
||||||
*/
|
*/
|
||||||
INIReader(const std::string &filePath)
|
explicit INIReader(const std::string &filePath)
|
||||||
{
|
{
|
||||||
parsed = false;
|
parsed = false;
|
||||||
ParseFile(filePath);
|
ParseFile(filePath);
|
||||||
|
|||||||
+3
-4
@@ -134,18 +134,17 @@ const std::vector<UAProfile> UAMatchList = {
|
|||||||
|
|
||||||
bool verGreaterEqual(const std::string &src_ver, const std::string &target_ver)
|
bool verGreaterEqual(const std::string &src_ver, const std::string &target_ver)
|
||||||
{
|
{
|
||||||
int part_src, part_target;
|
string_size src_pos_beg = 0, src_pos_end, target_pos_beg = 0, target_pos_end;
|
||||||
string_size src_pos_beg = 0, src_pos_end = 0, target_pos_beg = 0, target_pos_end = 0;
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
src_pos_end = src_ver.find('.', src_pos_beg);
|
src_pos_end = src_ver.find('.', src_pos_beg);
|
||||||
if(src_pos_end == src_ver.npos)
|
if(src_pos_end == src_ver.npos)
|
||||||
src_pos_end = src_ver.size();
|
src_pos_end = src_ver.size();
|
||||||
part_src = std::stoi(src_ver.substr(src_pos_beg, src_pos_end - src_pos_beg));
|
int part_src = std::stoi(src_ver.substr(src_pos_beg, src_pos_end - src_pos_beg));
|
||||||
target_pos_end = target_ver.find('.', target_pos_beg);
|
target_pos_end = target_ver.find('.', target_pos_beg);
|
||||||
if(target_pos_end == target_ver.npos)
|
if(target_pos_end == target_ver.npos)
|
||||||
target_pos_end = target_ver.size();
|
target_pos_end = target_ver.size();
|
||||||
part_target = std::stoi(target_ver.substr(target_pos_beg, target_pos_end - target_pos_beg));
|
int part_target = std::stoi(target_ver.substr(target_pos_beg, target_pos_end - target_pos_beg));
|
||||||
if(part_src > part_target)
|
if(part_src > part_target)
|
||||||
break;
|
break;
|
||||||
else if(part_src < part_target)
|
else if(part_src < part_target)
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ std::string getTime(int type)
|
|||||||
return std::string(tmpbuf);
|
return std::string(tmpbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeLog(int type, std::string content, int level)
|
void writeLog(int type, const std::string &content, int level)
|
||||||
{
|
{
|
||||||
if(level > global_log_level)
|
if(level > global_log_level)
|
||||||
return;
|
return;
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ int makeDir(const char *path);
|
|||||||
std::string getTime(int type);
|
std::string getTime(int type);
|
||||||
void logInit(bool rpcmode);
|
void logInit(bool rpcmode);
|
||||||
void resultInit();
|
void resultInit();
|
||||||
void writeLog(int type, std::string content, int level = LOG_LEVEL_VERBOSE);
|
void writeLog(int type, const std::string &content, int level = LOG_LEVEL_VERBOSE);
|
||||||
void logEOF();
|
void logEOF();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+4
-5
@@ -134,7 +134,7 @@ unsigned char ToHex(unsigned char x)
|
|||||||
|
|
||||||
unsigned char FromHex(unsigned char x)
|
unsigned char FromHex(unsigned char x)
|
||||||
{
|
{
|
||||||
unsigned char y = '\0';
|
unsigned char y;
|
||||||
if (x >= 'A' && x <= 'Z')
|
if (x >= 'A' && x <= 'Z')
|
||||||
y = x - 'A' + 10;
|
y = x - 'A' + 10;
|
||||||
else if (x >= 'a' && x <= 'z')
|
else if (x >= 'a' && x <= 'z')
|
||||||
@@ -208,8 +208,7 @@ std::string base64_encode(const std::string &string_to_encode)
|
|||||||
unsigned int in_len = string_to_encode.size();
|
unsigned int in_len = string_to_encode.size();
|
||||||
|
|
||||||
std::string ret;
|
std::string ret;
|
||||||
int i = 0;
|
int i = 0, j;
|
||||||
int j = 0;
|
|
||||||
unsigned char char_array_3[3];
|
unsigned char char_array_3[3];
|
||||||
unsigned char char_array_4[4];
|
unsigned char char_array_4[4];
|
||||||
|
|
||||||
@@ -256,7 +255,7 @@ std::string base64_decode(const std::string &encoded_string, bool accept_urlsafe
|
|||||||
string_size in_len = encoded_string.size();
|
string_size in_len = encoded_string.size();
|
||||||
string_size i = 0;
|
string_size i = 0;
|
||||||
string_size in_ = 0;
|
string_size in_ = 0;
|
||||||
unsigned char char_array_4[4], char_array_3[3], uchar = 0;
|
unsigned char char_array_4[4], char_array_3[3], uchar;
|
||||||
static unsigned char dtable[256], itable[256], table_ready = 0;
|
static unsigned char dtable[256], itable[256], table_ready = 0;
|
||||||
std::string ret;
|
std::string ret;
|
||||||
|
|
||||||
@@ -1157,7 +1156,7 @@ std::string getFormData(const std::string &raw_data)
|
|||||||
std::string UTF8ToCodePoint(const std::string &data)
|
std::string UTF8ToCodePoint(const std::string &data)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
int charcode = 0;
|
int charcode;
|
||||||
for(std::string::size_type i = 0; i < data.size(); i++)
|
for(std::string::size_type i = 0; i < data.size(); i++)
|
||||||
{
|
{
|
||||||
charcode = data[i] & 0xff;
|
charcode = data[i] & 0xff;
|
||||||
|
|||||||
+1
-1
@@ -163,7 +163,7 @@ public:
|
|||||||
|
|
||||||
template <typename T> tribool(const T &value) { set(value); }
|
template <typename T> tribool(const T &value) { set(value); }
|
||||||
|
|
||||||
tribool(const tribool &value) { *this = value; }
|
explicit tribool(const tribool &value) { *this = value; }
|
||||||
|
|
||||||
~tribool() = default;
|
~tribool() = default;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ void copyNodes(std::vector<nodeInfo> &source, std::vector<nodeInfo> &dest)
|
|||||||
std::move(source.begin(), source.end(), std::back_inserter(dest));
|
std::move(source.begin(), source.end(), std::back_inserter(dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
int addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID, std::string proxy, string_array &exclude_remarks, string_array &include_remarks, string_array &stream_rules, string_array &time_rules, std::string &subInfo, bool authorized, string_map &request_headers)
|
int addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID, const std::string &proxy, string_array &exclude_remarks, string_array &include_remarks, string_array &stream_rules, string_array &time_rules, std::string &subInfo, bool authorized, string_map &request_headers)
|
||||||
{
|
{
|
||||||
int linkType = -1;
|
int linkType = -1;
|
||||||
std::vector<nodeInfo> nodes;
|
std::vector<nodeInfo> nodes;
|
||||||
|
|||||||
+1
-1
@@ -6,6 +6,6 @@
|
|||||||
|
|
||||||
#include "nodeinfo.h"
|
#include "nodeinfo.h"
|
||||||
|
|
||||||
int addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID, std::string proxy, string_array &exclude_remarks, string_array &include_remarks, string_array &stream_rules, string_array &time_rules, std::string &subInfo, bool authorized, string_map &request_headers);
|
int addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID, const std::string &proxy, string_array &exclude_remarks, string_array &include_remarks, string_array &stream_rules, string_array &time_rules, std::string &subInfo, bool authorized, string_map &request_headers);
|
||||||
|
|
||||||
#endif // NODEMANIP_H_INCLUDED
|
#endif // NODEMANIP_H_INCLUDED
|
||||||
@@ -2031,7 +2031,6 @@ void filterNodes(std::vector<nodeInfo> &nodes, string_array &exclude_remarks, st
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool excluded, included;
|
|
||||||
std::vector<std::unique_ptr<pcre2_code, decltype(&pcre2_code_free)>> exclude_patterns, include_patterns;
|
std::vector<std::unique_ptr<pcre2_code, decltype(&pcre2_code_free)>> exclude_patterns, include_patterns;
|
||||||
std::vector<std::unique_ptr<pcre2_match_data, decltype(&pcre2_match_data_free)>> exclude_match_data, include_match_data;
|
std::vector<std::unique_ptr<pcre2_match_data, decltype(&pcre2_match_data_free)>> exclude_match_data, include_match_data;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
@@ -2061,8 +2060,7 @@ void filterNodes(std::vector<nodeInfo> &nodes, string_array &exclude_remarks, st
|
|||||||
writeLog(LOG_TYPE_INFO, "Filter started.");
|
writeLog(LOG_TYPE_INFO, "Filter started.");
|
||||||
while(iter != nodes.end())
|
while(iter != nodes.end())
|
||||||
{
|
{
|
||||||
excluded = false;
|
bool excluded = false, included = false;
|
||||||
included = false;
|
|
||||||
for(i = 0; i < exclude_patterns.size(); i++)
|
for(i = 0; i < exclude_patterns.size(); i++)
|
||||||
{
|
{
|
||||||
rc = pcre2_match(exclude_patterns[i].get(), reinterpret_cast<const unsigned char*>(iter->remarks.c_str()), iter->remarks.size(), 0, 0, exclude_match_data[i].get(), NULL);
|
rc = pcre2_match(exclude_patterns[i].get(), reinterpret_cast<const unsigned char*>(iter->remarks.c_str()), iter->remarks.size(), 0, 0, exclude_match_data[i].get(), NULL);
|
||||||
|
|||||||
+1
-2
@@ -1868,7 +1868,6 @@ std::string netchToSSSub(std::string &base_conf, std::vector<nodeInfo> &nodes, c
|
|||||||
std::string plugin, pluginopts;
|
std::string plugin, pluginopts;
|
||||||
std::string protocol, obfs;
|
std::string protocol, obfs;
|
||||||
std::string output_content;
|
std::string output_content;
|
||||||
int port;
|
|
||||||
|
|
||||||
rapidjson::Document::AllocatorType &alloc = json.GetAllocator();
|
rapidjson::Document::AllocatorType &alloc = json.GetAllocator();
|
||||||
json.SetObject();
|
json.SetObject();
|
||||||
@@ -1897,7 +1896,7 @@ std::string netchToSSSub(std::string &base_conf, std::vector<nodeInfo> &nodes, c
|
|||||||
|
|
||||||
remark = x.remarks;
|
remark = x.remarks;
|
||||||
hostname = x.server;
|
hostname = x.server;
|
||||||
port = (unsigned short)stoi(GetMember(json, "Port"));
|
int port = (unsigned short)stoi(GetMember(json, "Port"));
|
||||||
password = GetMember(json, "Password");
|
password = GetMember(json, "Password");
|
||||||
method = GetMember(json, "EncryptMethod");
|
method = GetMember(json, "EncryptMethod");
|
||||||
plugin = GetMember(json, "Plugin");
|
plugin = GetMember(json, "Plugin");
|
||||||
|
|||||||
+5
-9
@@ -308,19 +308,15 @@ int renderClashScript(YAML::Node &base_rule, std::vector<ruleset_content> &rules
|
|||||||
{
|
{
|
||||||
case RULESET_CLASH_IPCIDR:
|
case RULESET_CLASH_IPCIDR:
|
||||||
has_ipcidr[rule_name] = true;
|
has_ipcidr[rule_name] = true;
|
||||||
if(!script)
|
|
||||||
rules.emplace_back("RULE-SET," + rule_name + "_ipcidr," + rule_group);
|
|
||||||
break;
|
break;
|
||||||
case RULESET_CLASH_DOMAIN:
|
case RULESET_CLASH_DOMAIN:
|
||||||
has_domain[rule_name] = true;
|
has_domain[rule_name] = true;
|
||||||
if(!script)
|
|
||||||
rules.emplace_back("RULE-SET," + rule_name + "_domain," + rule_group);
|
|
||||||
break;
|
break;
|
||||||
case RULESET_CLASH_CLASSICAL:
|
case RULESET_CLASH_CLASSICAL:
|
||||||
if(!script)
|
|
||||||
rules.emplace_back("RULE-SET," + rule_name + "," + rule_group);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if(!script)
|
||||||
|
rules.emplace_back("RULE-SET," + rule_name + "," + rule_group);
|
||||||
groups.emplace_back(std::move(rule_name));
|
groups.emplace_back(std::move(rule_name));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -420,7 +416,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector<ruleset_content> &rules
|
|||||||
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
|
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
|
||||||
else
|
else
|
||||||
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=3&url=" + urlsafe_base64_encode(url);
|
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=3&url=" + urlsafe_base64_encode(url);
|
||||||
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + x + "_domain.yaml";
|
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
|
||||||
if(interval)
|
if(interval)
|
||||||
base_rule["rule-providers"][yaml_key]["interval"] = interval;
|
base_rule["rule-providers"][yaml_key]["interval"] = interval;
|
||||||
}
|
}
|
||||||
@@ -435,7 +431,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector<ruleset_content> &rules
|
|||||||
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
|
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
|
||||||
else
|
else
|
||||||
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=4&url=" + urlsafe_base64_encode(url);
|
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=4&url=" + urlsafe_base64_encode(url);
|
||||||
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + x + "_ipcidr.yaml";
|
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
|
||||||
if(interval)
|
if(interval)
|
||||||
base_rule["rule-providers"][yaml_key]["interval"] = interval;
|
base_rule["rule-providers"][yaml_key]["interval"] = interval;
|
||||||
}
|
}
|
||||||
@@ -448,7 +444,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector<ruleset_content> &rules
|
|||||||
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
|
base_rule["rule-providers"][yaml_key]["url"] = url.substr(1);
|
||||||
else
|
else
|
||||||
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=6&url=" + urlsafe_base64_encode(url);
|
base_rule["rule-providers"][yaml_key]["url"] = remote_path_prefix + "/getruleset?type=6&url=" + urlsafe_base64_encode(url);
|
||||||
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + x + "_classical.yaml";
|
base_rule["rule-providers"][yaml_key]["path"] = "./providers/rule-provider_" + yaml_key + ".yaml";
|
||||||
if(interval)
|
if(interval)
|
||||||
base_rule["rule-providers"][yaml_key]["interval"] = interval;
|
base_rule["rule-providers"][yaml_key]["interval"] = interval;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user