Răsfoiți Sursa

Add HTTP single link support with Telegram-link-liked format

Optimize codes.
Tindy X 5 ani în urmă
părinte
comite
ccd623e07e
4 a modificat fișierele cu 33 adăugiri și 26 ștergeri
  1. 7 19
      src/nodemanip.cpp
  2. 23 4
      src/speedtestutil.cpp
  3. 1 1
      src/speedtestutil.h
  4. 2 2
      src/subexport.cpp

+ 7 - 19
src/nodemanip.cpp

@@ -31,14 +31,10 @@ int addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID, std
     // TODO: replace with startsWith if appropriate
     link = replace_all_distinct(link, "\"", "");
     writeLog(LOG_TYPE_INFO, "Received Link.");
-    if(strFind(link, "vmess://") || strFind(link, "vmess1://"))
-        linkType = SPEEDTEST_MESSAGE_FOUNDVMESS;
-    else if(strFind(link, "ss://"))
-        linkType = SPEEDTEST_MESSAGE_FOUNDSS;
-    else if(strFind(link, "ssr://"))
-        linkType = SPEEDTEST_MESSAGE_FOUNDSSR;
-    else if(strFind(link, "socks://") || strFind(link, "https://t.me/socks") || strFind(link, "tg://socks"))
+    if(strFind(link, "https://t.me/socks") || strFind(link, "tg://socks"))
         linkType = SPEEDTEST_MESSAGE_FOUNDSOCKS;
+    else if(strFind(link, "https://t.me/http") || strFind(link, "tg://http"))
+        linkType = SPEEDTEST_MESSAGE_FOUNDHTTP;
     else if(startsWith(link, "http://") || startsWith(link, "https://") || startsWith(link, "data:") || strFind(link, "surge:///install-config"))
         linkType = SPEEDTEST_MESSAGE_FOUNDSUB;
     else if(strFind(link, "Netch://"))
@@ -118,22 +114,14 @@ int addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID, std
         copyNodes(nodes, allNodes);
         break;
     default:
-        if(linkType > 0)
-        {
-            explode(link, ss_libev, ssr_libev, override_conf_port, socksport, node);
-            if(node.linkType == -1)
-            {
-                writeLog(LOG_TYPE_ERROR, "No valid link found.");
-                return -1;
-            }
-            node.groupID = groupID;
-            allNodes.push_back(node);
-        }
-        else
+        explode(link, ss_libev, ssr_libev, override_conf_port, socksport, node);
+        if(node.linkType == -1)
         {
             writeLog(LOG_TYPE_ERROR, "No valid link found.");
             return -1;
         }
+        node.groupID = groupID;
+        allNodes.push_back(node);
     }
     return 0;
 }

+ 23 - 4
src/speedtestutil.cpp

@@ -560,13 +560,9 @@ void explodeSocks(std::string link, std::string custom_port, nodeInfo &node)
         password = getUrlArg(link, "pass");
     }
     if(remarks == "")
-    {
         remarks = server + ":" + port;
-    }
     if(custom_port.size())
-    {
         port = custom_port;
-    }
 
     node.linkType = SPEEDTEST_MESSAGE_FOUNDSOCKS;
     node.group = SOCKS_DEFAULT_GROUP;
@@ -576,6 +572,27 @@ void explodeSocks(std::string link, std::string custom_port, nodeInfo &node)
     node.proxyStr = socksConstruct(remarks, server, port, username, password);
 }
 
+void explodeHTTP(std::string link, std::string custom_port, nodeInfo &node)
+{
+    std::string remarks, server, port, username, password;
+    server = getUrlArg(link, "server");
+    port = getUrlArg(link, "port");
+    username = getUrlArg(link, "user");
+    password = getUrlArg(link, "pass");
+
+    if(remarks == "")
+        remarks = server + ":" + port;
+    if(custom_port.size())
+        port = custom_port;
+
+    node.linkType = SPEEDTEST_MESSAGE_FOUNDHTTP;
+    node.group = HTTP_DEFAULT_GROUP;
+    node.remarks = remarks;
+    node.server = server;
+    node.port = to_int(port, 0);
+    node.proxyStr = httpConstruct(remarks, server, port, username, password, strFind(link, "/https"));
+}
+
 void explodeQuan(std::string quan, std::string custom_port, int local_port, nodeInfo &node)
 {
     std::string strTemp, itemName, itemVal;
@@ -1480,6 +1497,8 @@ void explode(std::string link, bool sslibev, bool ssrlibev, std::string custom_p
         explodeSS(link, sslibev, custom_port, local_port, node);
     else if(strFind(link, "socks://") || strFind(link, "https://t.me/socks") || strFind(link, "tg://socks"))
         explodeSocks(link, custom_port, node);
+    else if(strFind(link, "https://t.me/http") || strFind(link, "tg://http")) //telegram style http link
+        explodeHTTP(link, custom_port, node);
     else if(strFind(link, "Netch://"))
         explodeNetch(link, sslibev, ssrlibev, custom_port, local_port, node);
 }

+ 1 - 1
src/speedtestutil.h

@@ -11,7 +11,7 @@ std::string vmessConstruct(std::string add, std::string port, std::string type,
 std::string ssrConstruct(std::string group, std::string remarks, std::string remarks_base64, std::string server, std::string port, std::string protocol, std::string method, std::string obfs, std::string password, std::string obfsparam, std::string protoparam, int local_port, bool libev);
 std::string ssConstruct(std::string server, std::string port, std::string password, std::string method, std::string plugin, std::string pluginopts, std::string remarks, int local_port, bool libev);
 std::string socksConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password);
-std::string httpConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password);
+std::string httpConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password, bool tls = false);
 void explodeVmess(std::string vmess, std::string custom_port, int local_port, nodeInfo &node);
 void explodeSSR(std::string ssr, bool ss_libev, bool libev, std::string custom_port, int local_port, nodeInfo &node);
 void explodeSS(std::string ss, bool libev, std::string custom_port, int local_port, nodeInfo &node);

+ 2 - 2
src/subexport.cpp

@@ -190,13 +190,13 @@ std::string socksConstruct(std::string remarks, std::string server, std::string
     return sb.GetString();
 }
 
-std::string httpConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password)
+std::string httpConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password, bool tls)
 {
     rapidjson::StringBuffer sb;
     rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
     writer.StartObject();
     writer.Key("Type");
-    writer.String("HTTP");
+    writer.String(tls ? "HTTPS" : "HTTP");
     writer.Key("Remark");
     writer.String(remarks.data());
     writer.Key("Hostname");