Optimize codes

Fix keeping UDP/TFO/Skip Cert Verify flags from original subscriptions not working.
Fix compiler warning.
This commit is contained in:
Tindy X committed 2020-06-08 20:41:02 +08:00
1 parent 64b5d3bdaa
commit 11ed400fc7
8 files changed
+46 -64

No files matched your search

+1 -18
View File
@@ -6,6 +6,7 @@
#include <inja.hpp>
#include <yaml-cpp/yaml.h>
#include "yamlcpp_extra.h"
#include "misc.h"
#include "nodeinfo.h"
#include "speedtestutil.h"
@@ -74,24 +75,6 @@ size_t max_allowed_rulesets = 64, max_allowed_rules = 32768;
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 proxy = source;
+6
View File
@@ -85,6 +85,12 @@ public:
return _M_VALUE;
}
bool set(const tribool &value)
{
_M_VALUE = value._M_VALUE;
return _M_VALUE;
}
bool set(const std::string &str)
{
switch(hash_(str))
+3
View File
@@ -9,6 +9,9 @@ template <typename T> void exception_thrower(T e)
throw std::runtime_error("assert");
}
#ifdef RAPIDJSON_ASSERT
#undef RAPIDJSON_ASSERT
#endif // RAPIDJSON_ASSERT
#define RAPIDJSON_ASSERT(x) exception_thrower(x)
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
+1 -18
View File
@@ -6,6 +6,7 @@
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
#include "yamlcpp_extra.h"
#include "misc.h"
#include "printout.h"
#include "logger.h"
@@ -26,24 +27,6 @@ std::string modSSMD5 = "f7653207090ce3389115e9c88541afe0";
//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)
{
std::string version, ps, add, port, type, id, aid, net, path, host, tls;
+11 -17
View File
@@ -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 "speedtestutil.h"
#include "ini_reader.h"
@@ -11,16 +21,7 @@
#include "logger.h"
#include "templates.h"
#include "script_duktape.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>
#include "yamlcpp_extra.h"
extern bool api_mode;
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 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)
{
int retVal;
+4 -4
View File
@@ -33,11 +33,11 @@ struct extra_settings
std::string surge_ssr_path;
std::string managed_config_prefix;
std::string quanx_dev_id;
tribool udp = false;
tribool tfo = false;
tribool skip_cert_verify = false;
tribool udp = tribool();
tribool tfo = tribool();
tribool skip_cert_verify = tribool();
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);
+1 -7
View File
@@ -4,6 +4,7 @@
#include <inja.hpp>
#include <nlohmann/json.hpp>
#include "yamlcpp_extra.h"
#include "interfaces.h"
#include "templates.h"
#include "logger.h"
@@ -11,13 +12,6 @@
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)
{
std::string pointer = "/" + replace_all_distinct(path, ".", "/");
+19
View File
@@ -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);
};