mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-26 03:11:21 +08:00
refactor: migrate from yaml-cpp to fkYAML (#418)
* refactor: migrate from yaml-cpp to fkYAML * fix
This commit is contained in:
parent
95d12f9556
commit
7a37772761
14724
3rdparty/fkYAML/node.hpp
vendored
Normal file
14724
3rdparty/fkYAML/node.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -56,9 +56,6 @@ endif ()
|
|||||||
include("cmake/myproto.cmake")
|
include("cmake/myproto.cmake")
|
||||||
list(APPEND NKR_EXTERNAL_TARGETS myproto)
|
list(APPEND NKR_EXTERNAL_TARGETS myproto)
|
||||||
|
|
||||||
find_package(yaml-cpp CONFIG REQUIRED) # only Release is built
|
|
||||||
list(APPEND NKR_EXTERNAL_TARGETS yaml-cpp)
|
|
||||||
|
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
set(BUILD_SHARED_LIBS OFF)
|
||||||
list(APPEND NKR_EXTERNAL_TARGETS qhotkey)
|
list(APPEND NKR_EXTERNAL_TARGETS qhotkey)
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,7 @@ Various formats are supported, including share links, JSON array of outbounds an
|
|||||||
- [Qv2ray](https://github.com/Qv2ray/Qv2ray)
|
- [Qv2ray](https://github.com/Qv2ray/Qv2ray)
|
||||||
- [Qt](https://www.qt.io/)
|
- [Qt](https://www.qt.io/)
|
||||||
- [protobuf](https://github.com/protocolbuffers/protobuf)
|
- [protobuf](https://github.com/protocolbuffers/protobuf)
|
||||||
- [yaml-cpp](https://github.com/jbeder/yaml-cpp)
|
- [fkYAML](https://github.com/fktn-k/fkYAML)
|
||||||
- [quirc](https://github.com/dlbeer/quirc)
|
- [quirc](https://github.com/dlbeer/quirc)
|
||||||
- [QHotkey](https://github.com/Skycoder42/QHotkey)
|
- [QHotkey](https://github.com/Skycoder42/QHotkey)
|
||||||
|
|
||||||
|
|||||||
@ -19,22 +19,9 @@ mkdir -p $INSTALL_PREFIX
|
|||||||
|
|
||||||
#### clean ####
|
#### clean ####
|
||||||
clean() {
|
clean() {
|
||||||
rm -rf dl.zip yaml-* zxing-* protobuf
|
rm -rf protobuf
|
||||||
}
|
}
|
||||||
|
|
||||||
#### yaml-cpp ####
|
|
||||||
curl -L -o dl.zip https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.7.0.zip
|
|
||||||
unzip dl.zip
|
|
||||||
|
|
||||||
cd yaml-*
|
|
||||||
mkdir -p build
|
|
||||||
cd build
|
|
||||||
|
|
||||||
$cmake .. -GNinja -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=$1 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX
|
|
||||||
ninja && ninja install
|
|
||||||
|
|
||||||
cd ../..
|
|
||||||
|
|
||||||
#### protobuf ####
|
#### protobuf ####
|
||||||
git clone --recurse-submodules -b v30.2 --depth 1 --shallow-submodules https://github.com/parhelia512/protobuf
|
git clone --recurse-submodules -b v30.2 --depth 1 --shallow-submodules https://github.com/parhelia512/protobuf
|
||||||
|
|
||||||
|
|||||||
@ -6,13 +6,8 @@
|
|||||||
|
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
#include <absl/strings/internal/str_format/extension.h>
|
|
||||||
|
|
||||||
#ifndef NKR_NO_YAML
|
#include "3rdparty/fkYAML/node.hpp"
|
||||||
|
|
||||||
#include <yaml-cpp/yaml.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace NekoGui_sub {
|
namespace NekoGui_sub {
|
||||||
|
|
||||||
@ -78,9 +73,6 @@ namespace NekoGui_sub {
|
|||||||
|
|
||||||
// Clash
|
// Clash
|
||||||
if (str.contains("proxies:")) {
|
if (str.contains("proxies:")) {
|
||||||
runOnUiThread([=] {
|
|
||||||
MessageBoxWarning("Deprecated", "Clash Meta format is deprecated and will no longer be updated.");
|
|
||||||
});
|
|
||||||
updateClash(str);
|
updateClash(str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -341,51 +333,48 @@ namespace NekoGui_sub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Node2QString(const fkyaml::node &n, const QString &def = "") {
|
||||||
#ifndef NKR_NO_YAML
|
|
||||||
|
|
||||||
QString Node2QString(const YAML::Node &n, const QString &def = "") {
|
|
||||||
try {
|
try {
|
||||||
return n.as<std::string>().c_str();
|
return n.as_str().c_str();
|
||||||
} catch (const YAML::Exception &ex) {
|
} catch (const fkyaml::exception &ex) {
|
||||||
qDebug() << ex.what();
|
qDebug() << ex.what();
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Node2QStringList(const YAML::Node &n) {
|
QStringList Node2QStringList(const fkyaml::node &n) {
|
||||||
try {
|
try {
|
||||||
if (n.IsSequence()) {
|
if (n.is_sequence()) {
|
||||||
QStringList list;
|
QStringList list;
|
||||||
for (auto item: n) {
|
for (auto item: n) {
|
||||||
list << item.as<std::string>().c_str();
|
list << item.as_str().c_str();
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
} catch (const YAML::Exception &ex) {
|
} catch (const fkyaml::exception &ex) {
|
||||||
qDebug() << ex.what();
|
qDebug() << ex.what();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Node2Int(const YAML::Node &n, const int &def = 0) {
|
int Node2Int(const fkyaml::node &n, const int &def = 0) {
|
||||||
try {
|
try {
|
||||||
return n.as<int>();
|
return n.as_int();
|
||||||
} catch (const YAML::Exception &ex) {
|
} catch (const fkyaml::exception &ex) {
|
||||||
qDebug() << ex.what();
|
qDebug() << ex.what();
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node2Bool(const YAML::Node &n, const bool &def = false) {
|
bool Node2Bool(const fkyaml::node &n, const bool &def = false) {
|
||||||
try {
|
try {
|
||||||
return n.as<bool>();
|
return n.as_bool();
|
||||||
} catch (const YAML::Exception &ex) {
|
} catch (const fkyaml::exception &ex) {
|
||||||
try {
|
try {
|
||||||
return n.as<int>();
|
return n.as_int();
|
||||||
} catch (const YAML::Exception &ex2) {
|
} catch (const fkyaml::exception &ex2) {
|
||||||
ex2.what();
|
ex2.what();
|
||||||
}
|
}
|
||||||
qDebug() << ex.what();
|
qDebug() << ex.what();
|
||||||
@ -394,21 +383,17 @@ namespace NekoGui_sub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NodeChild returns the first defined children or Null Node
|
// NodeChild returns the first defined children or Null Node
|
||||||
YAML::Node NodeChild(const YAML::Node &n, const std::list<std::string> &keys) {
|
fkyaml::node NodeChild(const fkyaml::node &n, const std::list<std::string> &keys) {
|
||||||
for (const auto &key: keys) {
|
for (const auto &key: keys) {
|
||||||
auto child = n[key];
|
if (n.contains(key)) return n[key];
|
||||||
if (child.IsDefined()) return child;
|
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// https://github.com/Dreamacro/clash/wiki/configuration
|
// https://github.com/Dreamacro/clash/wiki/configuration
|
||||||
void RawUpdater::updateClash(const QString &str) {
|
void RawUpdater::updateClash(const QString &str) {
|
||||||
#ifndef NKR_NO_YAML
|
|
||||||
try {
|
try {
|
||||||
auto proxies = YAML::Load(str.toStdString())["proxies"];
|
auto proxies = fkyaml::node::deserialize(str.toStdString())["proxies"];
|
||||||
for (auto proxy: proxies) {
|
for (auto proxy: proxies) {
|
||||||
auto type = Node2QString(proxy["type"]).toLower();
|
auto type = Node2QString(proxy["type"]).toLower();
|
||||||
auto type_clash = type;
|
auto type_clash = type;
|
||||||
@ -429,8 +414,6 @@ namespace NekoGui_sub {
|
|||||||
auto bean = ent->ShadowSocksBean();
|
auto bean = ent->ShadowSocksBean();
|
||||||
bean->method = Node2QString(proxy["cipher"]).replace("dummy", "none");
|
bean->method = Node2QString(proxy["cipher"]).replace("dummy", "none");
|
||||||
bean->password = Node2QString(proxy["password"]);
|
bean->password = Node2QString(proxy["password"]);
|
||||||
auto plugin_n = proxy["plugin"];
|
|
||||||
auto pluginOpts_n = proxy["plugin-opts"];
|
|
||||||
|
|
||||||
// UDP over TCP
|
// UDP over TCP
|
||||||
if (Node2Bool(proxy["udp-over-tcp"])) {
|
if (Node2Bool(proxy["udp-over-tcp"])) {
|
||||||
@ -438,7 +421,9 @@ namespace NekoGui_sub {
|
|||||||
if (bean->uot == 0) bean->uot = 2;
|
if (bean->uot == 0) bean->uot = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin_n.IsDefined() && pluginOpts_n.IsDefined()) {
|
if (proxy.contains("plugin") && proxy.contains("plugin-opts")) {
|
||||||
|
auto plugin_n = proxy["plugin"];
|
||||||
|
auto pluginOpts_n = proxy["plugin-opts"];
|
||||||
QStringList ssPlugin;
|
QStringList ssPlugin;
|
||||||
auto plugin = Node2QString(plugin_n);
|
auto plugin = Node2QString(plugin_n);
|
||||||
if (plugin == "obfs") {
|
if (plugin == "obfs") {
|
||||||
@ -463,7 +448,7 @@ namespace NekoGui_sub {
|
|||||||
|
|
||||||
// sing-mux
|
// sing-mux
|
||||||
auto smux = NodeChild(proxy, {"smux"});
|
auto smux = NodeChild(proxy, {"smux"});
|
||||||
if (Node2Bool(smux["enabled"])) bean->mux_state = 1;
|
if (!smux.is_null() && Node2Bool(smux["enabled"])) bean->mux_state = 1;
|
||||||
} else if (type == "socks" || type == "http") {
|
} else if (type == "socks" || type == "http") {
|
||||||
auto bean = ent->SocksHTTPBean();
|
auto bean = ent->SocksHTTPBean();
|
||||||
bean->username = Node2QString(proxy["username"]);
|
bean->username = Node2QString(proxy["username"]);
|
||||||
@ -498,15 +483,18 @@ namespace NekoGui_sub {
|
|||||||
|
|
||||||
// sing-mux
|
// sing-mux
|
||||||
auto smux = NodeChild(proxy, {"smux"});
|
auto smux = NodeChild(proxy, {"smux"});
|
||||||
if (Node2Bool(smux["enabled"])) bean->mux_state = 1;
|
if (!smux.is_null() && Node2Bool(smux["enabled"])) bean->mux_state = 1;
|
||||||
|
|
||||||
// opts
|
// opts
|
||||||
auto ws = NodeChild(proxy, {"ws-opts", "ws-opt"});
|
auto ws = NodeChild(proxy, {"ws-opts", "ws-opt"});
|
||||||
if (ws.IsMap()) {
|
if (ws.is_mapping()) {
|
||||||
auto headers = ws["headers"];
|
auto headers = ws["headers"];
|
||||||
for (auto header: headers) {
|
if (headers.is_mapping()) {
|
||||||
if (Node2QString(header.first).toLower() == "host") {
|
for (auto header: headers.as_map()) {
|
||||||
bean->stream->host = Node2QString(header.second);
|
if (Node2QString(header.first).toLower() == "host") {
|
||||||
|
bean->stream->host = Node2QString(header.second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bean->stream->path = Node2QString(ws["path"]);
|
bean->stream->path = Node2QString(ws["path"]);
|
||||||
@ -515,12 +503,12 @@ namespace NekoGui_sub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto grpc = NodeChild(proxy, {"grpc-opts", "grpc-opt"});
|
auto grpc = NodeChild(proxy, {"grpc-opts", "grpc-opt"});
|
||||||
if (grpc.IsMap()) {
|
if (grpc.is_mapping()) {
|
||||||
bean->stream->path = Node2QString(grpc["grpc-service-name"]);
|
bean->stream->path = Node2QString(grpc["grpc-service-name"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto reality = NodeChild(proxy, {"reality-opts"});
|
auto reality = NodeChild(proxy, {"reality-opts"});
|
||||||
if (reality.IsMap()) {
|
if (reality.is_mapping()) {
|
||||||
bean->stream->reality_pbk = Node2QString(reality["public-key"]);
|
bean->stream->reality_pbk = Node2QString(reality["public-key"]);
|
||||||
bean->stream->reality_sid = Node2QString(reality["short-id"]);
|
bean->stream->reality_sid = Node2QString(reality["short-id"]);
|
||||||
}
|
}
|
||||||
@ -543,7 +531,7 @@ namespace NekoGui_sub {
|
|||||||
|
|
||||||
// sing-mux
|
// sing-mux
|
||||||
auto smux = NodeChild(proxy, {"smux"});
|
auto smux = NodeChild(proxy, {"smux"});
|
||||||
if (Node2Bool(smux["enabled"])) bean->mux_state = 1;
|
if (!smux.is_null() && Node2Bool(smux["enabled"])) bean->mux_state = 1;
|
||||||
|
|
||||||
// meta packet encoding
|
// meta packet encoding
|
||||||
if (Node2Bool(proxy["xudp"])) bean->stream->packet_encoding = "xudp";
|
if (Node2Bool(proxy["xudp"])) bean->stream->packet_encoding = "xudp";
|
||||||
@ -551,11 +539,14 @@ namespace NekoGui_sub {
|
|||||||
|
|
||||||
// opts
|
// opts
|
||||||
auto ws = NodeChild(proxy, {"ws-opts", "ws-opt"});
|
auto ws = NodeChild(proxy, {"ws-opts", "ws-opt"});
|
||||||
if (ws.IsMap()) {
|
if (ws.is_mapping()) {
|
||||||
auto headers = ws["headers"];
|
auto headers = ws["headers"];
|
||||||
for (auto header: headers) {
|
if (headers.is_mapping()) {
|
||||||
if (Node2QString(header.first).toLower() == "host") {
|
for (auto header: headers.as_map()) {
|
||||||
bean->stream->host = Node2QString(header.second);
|
if (Node2QString(header.first).toLower() == "host") {
|
||||||
|
bean->stream->host = Node2QString(header.second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bean->stream->path = Node2QString(ws["path"]);
|
bean->stream->path = Node2QString(ws["path"]);
|
||||||
@ -568,12 +559,12 @@ namespace NekoGui_sub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto grpc = NodeChild(proxy, {"grpc-opts", "grpc-opt"});
|
auto grpc = NodeChild(proxy, {"grpc-opts", "grpc-opt"});
|
||||||
if (grpc.IsMap()) {
|
if (grpc.is_mapping()) {
|
||||||
bean->stream->path = Node2QString(grpc["grpc-service-name"]);
|
bean->stream->path = Node2QString(grpc["grpc-service-name"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto h2 = NodeChild(proxy, {"h2-opts", "h2-opt"});
|
auto h2 = NodeChild(proxy, {"h2-opts", "h2-opt"});
|
||||||
if (h2.IsMap()) {
|
if (h2.is_mapping()) {
|
||||||
auto hosts = h2["host"];
|
auto hosts = h2["host"];
|
||||||
for (auto host: hosts) {
|
for (auto host: hosts) {
|
||||||
bean->stream->host = Node2QString(host);
|
bean->stream->host = Node2QString(host);
|
||||||
@ -582,15 +573,17 @@ namespace NekoGui_sub {
|
|||||||
bean->stream->path = Node2QString(h2["path"]);
|
bean->stream->path = Node2QString(h2["path"]);
|
||||||
}
|
}
|
||||||
auto tcp_http = NodeChild(proxy, {"http-opts", "http-opt"});
|
auto tcp_http = NodeChild(proxy, {"http-opts", "http-opt"});
|
||||||
if (tcp_http.IsMap()) {
|
if (tcp_http.is_mapping()) {
|
||||||
bean->stream->network = "tcp";
|
bean->stream->network = "tcp";
|
||||||
bean->stream->header_type = "http";
|
bean->stream->header_type = "http";
|
||||||
auto headers = tcp_http["headers"];
|
auto headers = tcp_http["headers"];
|
||||||
for (auto header: headers) {
|
if (headers.is_mapping()) {
|
||||||
if (Node2QString(header.first).toLower() == "host") {
|
for (auto header: headers.as_map()) {
|
||||||
bean->stream->host = Node2QString(header.second[0]);
|
if (Node2QString(header.first).toLower() == "host") {
|
||||||
|
bean->stream->host = Node2QString(header.second[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
auto paths = tcp_http["path"];
|
auto paths = tcp_http["path"];
|
||||||
for (auto path: paths) {
|
for (auto path: paths) {
|
||||||
@ -673,12 +666,11 @@ namespace NekoGui_sub {
|
|||||||
NekoGui::profileManager->AddProfile(ent, gid_add_to);
|
NekoGui::profileManager->AddProfile(ent, gid_add_to);
|
||||||
updated_order += ent;
|
updated_order += ent;
|
||||||
}
|
}
|
||||||
} catch (const YAML::Exception &ex) {
|
} catch (const fkyaml::exception &ex) {
|
||||||
runOnUiThread([=] {
|
runOnUiThread([=] {
|
||||||
MessageBoxWarning("YAML Exception", ex.what());
|
MessageBoxWarning("YAML Exception", ex.what());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在新的 thread 运行
|
// 在新的 thread 运行
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user