mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 05:30:06 +08:00
Merge pull request #1004 from throneproj/sip008
feat: support SIP008 format subscription
This commit is contained in:
commit
14c96f93ba
@ -38,6 +38,7 @@ namespace Configs
|
|||||||
// baseConfig overrides
|
// baseConfig overrides
|
||||||
bool ParseFromLink(const QString& link) override;
|
bool ParseFromLink(const QString& link) override;
|
||||||
bool ParseFromJson(const QJsonObject& object) override;
|
bool ParseFromJson(const QJsonObject& object) override;
|
||||||
|
bool ParseFromSIP008(const QJsonObject& object);
|
||||||
QString ExportToLink() override;
|
QString ExportToLink() override;
|
||||||
QJsonObject ExportToJson() override;
|
QJsonObject ExportToJson() override;
|
||||||
BuildResult Build() override;
|
BuildResult Build() override;
|
||||||
|
|||||||
@ -11,6 +11,8 @@ namespace Subscription {
|
|||||||
|
|
||||||
void updateWireguardFileConfig(const QString &str);
|
void updateWireguardFileConfig(const QString &str);
|
||||||
|
|
||||||
|
void updateSIP008(const QString &str);
|
||||||
|
|
||||||
int gid_add_to = -1;
|
int gid_add_to = -1;
|
||||||
|
|
||||||
QList<std::shared_ptr<Configs::ProxyEntity>> updated_order;
|
QList<std::shared_ptr<Configs::ProxyEntity>> updated_order;
|
||||||
|
|||||||
@ -62,6 +62,24 @@ namespace Configs {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shadowsocks::ParseFromSIP008(const QJsonObject& object)
|
||||||
|
{
|
||||||
|
if (object.isEmpty()) return false;
|
||||||
|
outbound::ParseFromJson(object);
|
||||||
|
if (object.contains("remarks")) name = object["remarks"].toString();
|
||||||
|
if (object.contains("method")) method = object["method"].toString();
|
||||||
|
if (object.contains("password")) password = object["password"].toString();
|
||||||
|
if (object.contains("plugin")) plugin = object["plugin"].toString().replace("simple-obfs", "obfs-local");
|
||||||
|
if (object.contains("plugin_opts")) plugin_opts = object["plugin_opts"].toString();
|
||||||
|
if (object.contains("uot"))
|
||||||
|
{
|
||||||
|
if (object["uot"].isBool()) uot = object["uot"].toBool();
|
||||||
|
if (object["uot"].isObject()) uot = object["uot"].toObject()["enabled"].toBool();
|
||||||
|
}
|
||||||
|
if (object.contains("multiplex")) multiplex->ParseFromJson(object["multiplex"].toObject());
|
||||||
|
return !(server.isEmpty() || method.isEmpty() || password.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
QString shadowsocks::ExportToLink()
|
QString shadowsocks::ExportToLink()
|
||||||
{
|
{
|
||||||
QUrl url;
|
QUrl url;
|
||||||
|
|||||||
@ -80,6 +80,13 @@ namespace Subscription {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SIP008
|
||||||
|
if (str.contains("version") && str.contains("servers"))
|
||||||
|
{
|
||||||
|
updateSIP008(str);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Multi line
|
// Multi line
|
||||||
if (str.count("\n") > 0 && needParse) {
|
if (str.count("\n") > 0 && needParse) {
|
||||||
auto list = Disect(str);
|
auto list = Disect(str);
|
||||||
@ -327,6 +334,26 @@ namespace Subscription {
|
|||||||
updated_order += ent;
|
updated_order += ent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RawUpdater::updateSIP008(const QString& str)
|
||||||
|
{
|
||||||
|
auto json = QString2QJsonObject(str);
|
||||||
|
|
||||||
|
for (auto o : json["servers"].toArray())
|
||||||
|
{
|
||||||
|
auto out = o.toObject();
|
||||||
|
if (out.isEmpty())
|
||||||
|
{
|
||||||
|
MW_show_log("invalid server object");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ent = Configs::ProfileManager::NewProxyEntity("shadowsocks");
|
||||||
|
auto ok = ent->ShadowSocks()->ParseFromSIP008(out);
|
||||||
|
if (!ok) continue;
|
||||||
|
updated_order += ent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 在新的 thread 运行
|
// 在新的 thread 运行
|
||||||
void GroupUpdater::AsyncUpdate(const QString &str, int _sub_gid, const std::function<void()> &finish) {
|
void GroupUpdater::AsyncUpdate(const QString &str, int _sub_gid, const std::function<void()> &finish) {
|
||||||
auto content = str.trimmed();
|
auto content = str.trimmed();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user