diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b1a648..22af45c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include/") IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE Release) ENDIF() -SET(CMAKE_CXX_STANDARD 17) +SET(CMAKE_CXX_STANDARD 20) IF(NOT MSVC) ADD_COMPILE_OPTIONS(-Wall -Wextra -Wno-unused-parameter -Wno-unused-result) diff --git a/src/generator/config/ruleconvert.cpp b/src/generator/config/ruleconvert.cpp index d9d4866..7c5ddc2 100644 --- a/src/generator/config/ruleconvert.cpp +++ b/src/generator/config/ruleconvert.cpp @@ -481,6 +481,22 @@ static rapidjson::Value transformRuleToSingBox(const std::string& rule, const st return rule_obj; } +static void appendSingBoxRule(rapidjson::Value &rules, const std::string& rule, rapidjson::MemoryPoolAllocator<>& allocator) +{ + using namespace rapidjson_ext; + auto args = split(rule, ","); + if (args.size() < 2) return; + auto type = toLower(std::string(args[0])); + auto value = toLower(args[1]); +// std::string_view option; +// if (args.size() >= 3) option = args[2]; + + type = replaceAllDistinct(type, "-", "_"); + type = replaceAllDistinct(type, "ip_cidr6", "ip_cidr"); + + rules | AppendToArray(type.c_str(), rapidjson::Value(value.c_str(), allocator), allocator); +} + void rulesetToSingBox(rapidjson::Document &base_rule, std::vector &ruleset_content_array, bool overwrite_original_rules) { using namespace rapidjson_ext; @@ -504,6 +520,9 @@ void rulesetToSingBox(rapidjson::Document &base_rule, std::vector global.maxAllowedRules) @@ -532,7 +551,10 @@ void rulesetToSingBox(rapidjson::Document &base_rule, std::vector global.maxAllowedRules) @@ -548,8 +570,11 @@ void rulesetToSingBox(rapidjson::Document &base_rule, std::vector &nodes, rapidjson::Document &json, std::v outbounds.PushBack(direct, allocator); auto reject = buildObject(allocator, "type", "block", "tag", "REJECT"); outbounds.PushBack(reject, allocator); + auto dns = buildObject(allocator, "type", "dns", "tag", "dns-out"); + outbounds.PushBack(dns, allocator); for (Proxy &x : nodes) { diff --git a/src/script/script_quickjs.cpp b/src/script/script_quickjs.cpp index a6e6327..1bbe7e8 100644 --- a/src/script/script_quickjs.cpp +++ b/src/script/script_quickjs.cpp @@ -447,7 +447,6 @@ int script_context_init(qjs::Context &context) .fun<&qjs_fetch_Headers::parse_from_string>("parse"); module.class_("Request") .constructor<>() - .constructor("Request") .fun<&qjs_fetch_Request::method>("method") .fun<&qjs_fetch_Request::url>("url") .fun<&qjs_fetch_Request::proxy>("proxy") diff --git a/src/utils/rapidjson_extra.h b/src/utils/rapidjson_extra.h index 5404d82..1b9d6be 100644 --- a/src/utils/rapidjson_extra.h +++ b/src/utils/rapidjson_extra.h @@ -96,20 +96,53 @@ namespace rapidjson_ext { }; struct AddMemberOrReplace : public ExtensionFunction { - rapidjson::Value &member; + rapidjson::Value &value; const rapidjson::Value::Ch *name; rapidjson::MemoryPoolAllocator<> &allocator; AddMemberOrReplace(const rapidjson::Value::Ch *name, rapidjson::Value &value, - rapidjson::MemoryPoolAllocator<> &allocator) : member(value), name(name), allocator(allocator) {} + rapidjson::MemoryPoolAllocator<> &allocator) : value(value), name(name), allocator(allocator) {} AddMemberOrReplace(const rapidjson::Value::Ch *name, rapidjson::Value &&value, - rapidjson::MemoryPoolAllocator<> &allocator) : member(value), name(name), allocator(allocator) {} + rapidjson::MemoryPoolAllocator<> &allocator) : value(value), name(name), allocator(allocator) {} inline rapidjson::Value & operator() (rapidjson::Value &root) const override { if (root.HasMember(name)) - root[name] = member; + root[name] = value; else - root.AddMember(rapidjson::StringRef(name), member, allocator); + root.AddMember(rapidjson::Value(name, allocator), value, allocator); + return root; + } + }; + + struct AppendToArray : public ExtensionFunction + { + rapidjson::Value &value; + const rapidjson::Value::Ch *name; + rapidjson::MemoryPoolAllocator<> &allocator; + + AppendToArray(const rapidjson::Value::Ch *name, rapidjson::Value &value, + rapidjson::MemoryPoolAllocator<> &allocator): value(value), name(name), allocator(allocator) {} + + AppendToArray(const rapidjson::Value::Ch *name, rapidjson::Value &&value, + rapidjson::MemoryPoolAllocator<> &allocator): value(value), name(name), allocator(allocator) {} + + inline rapidjson::Value &operator()(rapidjson::Value &root) const override + { + if (root.HasMember(name)) + { + if (root[name].IsArray()) + { + root[name].PushBack(value, allocator); + } + else + { + root[name] = rapidjson::Value(rapidjson::kArrayType).PushBack(value, allocator); + } + } + else + { + root.AddMember(rapidjson::Value(name, allocator), rapidjson::Value(rapidjson::kArrayType).PushBack(value, allocator), allocator); + } return root; } };