mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-04 10:42:04 +00:00
Optimize codes
Fix keeping UDP/TFO/Skip Cert Verify flags from original subscriptions not working. Fix compiler warning.
This commit is contained in:
8 files changed
+46
-64
No files matched your search
+1
-18
@@ -6,6 +6,7 @@
|
|||||||
#include <inja.hpp>
|
#include <inja.hpp>
|
||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
#include "yamlcpp_extra.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "nodeinfo.h"
|
#include "nodeinfo.h"
|
||||||
#include "speedtestutil.h"
|
#include "speedtestutil.h"
|
||||||
@@ -74,24 +75,6 @@ size_t max_allowed_rulesets = 64, max_allowed_rules = 32768;
|
|||||||
|
|
||||||
string_array regex_blacklist = {"(.*)*"};
|
string_array regex_blacklist = {"(.*)*"};
|
||||||
|
|
||||||
template <typename T> void operator >> (const YAML::Node& node, T& i)
|
|
||||||
{
|
|
||||||
if(node.IsDefined() && !node.IsNull()) //fail-safe
|
|
||||||
i = node.as<T>();
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T> T safe_as (const YAML::Node& node)
|
|
||||||
{
|
|
||||||
if(node.IsDefined() && !node.IsNull())
|
|
||||||
return node.as<T>();
|
|
||||||
return T();
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T> void operator >>= (const YAML::Node& node, T& i)
|
|
||||||
{
|
|
||||||
i = safe_as<T>(node);
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string parseProxy(const std::string &source)
|
std::string parseProxy(const std::string &source)
|
||||||
{
|
{
|
||||||
std::string proxy = source;
|
std::string proxy = source;
|
||||||
|
|||||||
@@ -85,6 +85,12 @@ public:
|
|||||||
return _M_VALUE;
|
return _M_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool set(const tribool &value)
|
||||||
|
{
|
||||||
|
_M_VALUE = value._M_VALUE;
|
||||||
|
return _M_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
bool set(const std::string &str)
|
bool set(const std::string &str)
|
||||||
{
|
{
|
||||||
switch(hash_(str))
|
switch(hash_(str))
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ template <typename T> void exception_thrower(T e)
|
|||||||
throw std::runtime_error("assert");
|
throw std::runtime_error("assert");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RAPIDJSON_ASSERT
|
||||||
|
#undef RAPIDJSON_ASSERT
|
||||||
|
#endif // RAPIDJSON_ASSERT
|
||||||
#define RAPIDJSON_ASSERT(x) exception_thrower(x)
|
#define RAPIDJSON_ASSERT(x) exception_thrower(x)
|
||||||
#include <rapidjson/document.h>
|
#include <rapidjson/document.h>
|
||||||
#include <rapidjson/writer.h>
|
#include <rapidjson/writer.h>
|
||||||
|
|||||||
+1
-18
@@ -6,6 +6,7 @@
|
|||||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||||
#include <pcre2.h>
|
#include <pcre2.h>
|
||||||
|
|
||||||
|
#include "yamlcpp_extra.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "printout.h"
|
#include "printout.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
@@ -26,24 +27,6 @@ std::string modSSMD5 = "f7653207090ce3389115e9c88541afe0";
|
|||||||
|
|
||||||
//remake from speedtestutil
|
//remake from speedtestutil
|
||||||
|
|
||||||
template <typename T> void operator >> (const YAML::Node& node, T& i)
|
|
||||||
{
|
|
||||||
if(node.IsDefined() && !node.IsNull()) //fail-safe
|
|
||||||
i = node.as<T>();
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T> T safe_as (const YAML::Node& node)
|
|
||||||
{
|
|
||||||
if(node.IsDefined() && !node.IsNull())
|
|
||||||
return node.as<T>();
|
|
||||||
return T();
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T> void operator >>= (const YAML::Node& node, T& i)
|
|
||||||
{
|
|
||||||
i = safe_as<T>(node);
|
|
||||||
};
|
|
||||||
|
|
||||||
void explodeVmess(std::string vmess, const std::string &custom_port, nodeInfo &node)
|
void explodeVmess(std::string vmess, const std::string &custom_port, nodeInfo &node)
|
||||||
{
|
{
|
||||||
std::string version, ps, add, port, type, id, aid, net, path, host, tls;
|
std::string version, ps, add, port, type, id, aid, net, path, host, tls;
|
||||||
|
|||||||
+11
-17
@@ -1,3 +1,13 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <numeric>
|
||||||
|
#include <cmath>
|
||||||
|
#include <climits>
|
||||||
|
#include <rapidjson/writer.h>
|
||||||
|
#include <rapidjson/document.h>
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
#include <duktape.h>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "speedtestutil.h"
|
#include "speedtestutil.h"
|
||||||
#include "ini_reader.h"
|
#include "ini_reader.h"
|
||||||
@@ -11,16 +21,7 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "script_duktape.h"
|
#include "script_duktape.h"
|
||||||
|
#include "yamlcpp_extra.h"
|
||||||
#include <algorithm>
|
|
||||||
#include <iostream>
|
|
||||||
#include <numeric>
|
|
||||||
#include <cmath>
|
|
||||||
#include <climits>
|
|
||||||
#include <rapidjson/writer.h>
|
|
||||||
#include <rapidjson/document.h>
|
|
||||||
#include <yaml-cpp/yaml.h>
|
|
||||||
#include <duktape.h>
|
|
||||||
|
|
||||||
extern bool api_mode;
|
extern bool api_mode;
|
||||||
extern string_array ss_ciphers, ssr_ciphers;
|
extern string_array ss_ciphers, ssr_ciphers;
|
||||||
@@ -37,13 +38,6 @@ const string_array surge_rule_type = {basic_types, "IP-CIDR6", "USER-AGENT", "UR
|
|||||||
const string_array quanx_rule_type = {basic_types, "USER-AGENT", "HOST", "HOST-SUFFIX", "HOST-KEYWORD"};
|
const string_array quanx_rule_type = {basic_types, "USER-AGENT", "HOST", "HOST-SUFFIX", "HOST-KEYWORD"};
|
||||||
const string_array surfb_rule_type = {basic_types, "IP-CIDR6", "PROCESS-NAME", "IN-PORT", "DEST-PORT", "SRC-IP"};
|
const string_array surfb_rule_type = {basic_types, "IP-CIDR6", "PROCESS-NAME", "IN-PORT", "DEST-PORT", "SRC-IP"};
|
||||||
|
|
||||||
template <typename T> T safe_as (const YAML::Node& node)
|
|
||||||
{
|
|
||||||
if(node.IsDefined() && !node.IsNull())
|
|
||||||
return node.as<T>();
|
|
||||||
return T();
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string hostnameToIPAddr(const std::string &host)
|
std::string hostnameToIPAddr(const std::string &host)
|
||||||
{
|
{
|
||||||
int retVal;
|
int retVal;
|
||||||
|
|||||||
+4
-4
@@ -33,11 +33,11 @@ struct extra_settings
|
|||||||
std::string surge_ssr_path;
|
std::string surge_ssr_path;
|
||||||
std::string managed_config_prefix;
|
std::string managed_config_prefix;
|
||||||
std::string quanx_dev_id;
|
std::string quanx_dev_id;
|
||||||
tribool udp = false;
|
tribool udp = tribool();
|
||||||
tribool tfo = false;
|
tribool tfo = tribool();
|
||||||
tribool skip_cert_verify = false;
|
tribool skip_cert_verify = tribool();
|
||||||
bool clash_classical_ruleset = false;
|
bool clash_classical_ruleset = false;
|
||||||
std::string sort_script;
|
std::string sort_script = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules, bool new_field_name);
|
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules, bool new_field_name);
|
||||||
|
|||||||
+1
-7
@@ -4,6 +4,7 @@
|
|||||||
#include <inja.hpp>
|
#include <inja.hpp>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include "yamlcpp_extra.h"
|
||||||
#include "interfaces.h"
|
#include "interfaces.h"
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
@@ -11,13 +12,6 @@
|
|||||||
|
|
||||||
extern std::string managed_config_prefix;
|
extern std::string managed_config_prefix;
|
||||||
|
|
||||||
template <typename T> T safe_as (const YAML::Node& node)
|
|
||||||
{
|
|
||||||
if(node.IsDefined() && !node.IsNull())
|
|
||||||
return node.as<T>();
|
|
||||||
return T();
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline void parse_json_pointer(nlohmann::json &json, const std::string &path, const std::string &value)
|
static inline void parse_json_pointer(nlohmann::json &json, const std::string &path, const std::string &value)
|
||||||
{
|
{
|
||||||
std::string pointer = "/" + replace_all_distinct(path, ".", "/");
|
std::string pointer = "/" + replace_all_distinct(path, ".", "/");
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
template <typename T> void operator >> (const YAML::Node& node, T& i)
|
||||||
|
{
|
||||||
|
if(node.IsDefined() && !node.IsNull()) //fail-safe
|
||||||
|
i = node.as<T>();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T> T safe_as (const YAML::Node& node)
|
||||||
|
{
|
||||||
|
if(node.IsDefined() && !node.IsNull())
|
||||||
|
return node.as<T>();
|
||||||
|
return T();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T> void operator >>= (const YAML::Node& node, T& i)
|
||||||
|
{
|
||||||
|
i = safe_as<T>(node);
|
||||||
|
};
|
||||||
Reference in new issue
Block a user