Merge pull request #1004 from throneproj/sip008

feat: support SIP008 format subscription
This commit is contained in:
parhelia512 2025-12-03 19:46:36 +08:00 committed by GitHub
commit 14c96f93ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 0 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();