mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 05:30:06 +08:00
feat: support SIP008 format subscription
This commit is contained in:
parent
34d31d5b6b
commit
9d666595e0
@ -38,6 +38,7 @@ namespace Configs
|
||||
// baseConfig overrides
|
||||
bool ParseFromLink(const QString& link) override;
|
||||
bool ParseFromJson(const QJsonObject& object) override;
|
||||
bool ParseFromSIP008(const QJsonObject& object);
|
||||
QString ExportToLink() override;
|
||||
QJsonObject ExportToJson() override;
|
||||
BuildResult Build() override;
|
||||
|
||||
@ -11,6 +11,8 @@ namespace Subscription {
|
||||
|
||||
void updateWireguardFileConfig(const QString &str);
|
||||
|
||||
void updateSIP008(const QString &str);
|
||||
|
||||
int gid_add_to = -1;
|
||||
|
||||
QList<std::shared_ptr<Configs::ProxyEntity>> updated_order;
|
||||
|
||||
@ -62,6 +62,24 @@ namespace Configs {
|
||||
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()
|
||||
{
|
||||
QUrl url;
|
||||
|
||||
@ -80,6 +80,13 @@ namespace Subscription {
|
||||
return;
|
||||
}
|
||||
|
||||
// SIP008
|
||||
if (str.contains("version") && str.contains("servers"))
|
||||
{
|
||||
updateSIP008(str);
|
||||
return;
|
||||
}
|
||||
|
||||
// Multi line
|
||||
if (str.count("\n") > 0 && needParse) {
|
||||
auto list = Disect(str);
|
||||
@ -327,6 +334,26 @@ namespace Subscription {
|
||||
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 运行
|
||||
void GroupUpdater::AsyncUpdate(const QString &str, int _sub_gid, const std::function<void()> &finish) {
|
||||
auto content = str.trimmed();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user