Browse Source

Fix support for some non-standard Shadowsocks subscriptions

Tindy X 5 years ago
parent
commit
ac11260747
1 changed files with 12 additions and 8 deletions
  1. 12 8
      src/speedtestutil.cpp

+ 12 - 8
src/speedtestutil.cpp

@@ -477,21 +477,25 @@ void explodeSSConf(std::string content, const std::string &custom_port, bool lib
     json.Parse(content.data());
     json.Parse(content.data());
     if(json.HasParseError())
     if(json.HasParseError())
         return;
         return;
+    const char *section = json.HasMember("version") && json.HasMember("remarks") && json.HasMember("servers") ? "servers" : "configs";
+    if(!json.HasMember(section))
+        return;
+    GetMember(json, "remarks", group);
 
 
-    for(unsigned int i = 0; i < json["configs"].Size(); i++)
+    for(unsigned int i = 0; i < json[section].Size(); i++)
     {
     {
-        json["configs"][i]["remarks"] >> ps;
-        port = custom_port.size() ? custom_port : GetMember(json["configs"][i], "server_port");
+        ps = GetMember(json[section][i], "remarks");
+        port = custom_port.size() ? custom_port : GetMember(json[section][i], "server_port");
         if(port == "0")
         if(port == "0")
             continue;
             continue;
         if(ps.empty())
         if(ps.empty())
             ps = server + ":" + port;
             ps = server + ":" + port;
 
 
-        json["configs"][i]["password"] >> password;
-        json["configs"][i]["method"] >> method;
-        json["configs"][i]["server"] >> server;
-        json["configs"][i]["plugin"] >> plugin;
-        json["configs"][i]["plugin_opts"] >> pluginopts;
+        password = GetMember(json[section][i], "password");
+        method = GetMember(json[section][i], "method");
+        server = GetMember(json[section][i], "server");
+        plugin = GetMember(json[section][i], "plugin");
+        pluginopts = GetMember(json[section][i], "plugin_opts");
 
 
         node.linkType = SPEEDTEST_MESSAGE_FOUNDSS;
         node.linkType = SPEEDTEST_MESSAGE_FOUNDSS;
         node.group = group;
         node.group = group;