feat: add anytls link parser

This commit is contained in:
mi0e
2025-08-26 13:15:58 +08:00
parent 57c18b0c69
commit dfa8188739
2 changed files with 59 additions and 0 deletions

View File

@@ -3171,6 +3171,61 @@ void explodeTuic(const std::string &tuic, Proxy &node) {
return; return;
} }
void explodeAnyTLS(std::string anytls, Proxy &node) {
std::string add, port, password, remarks, addition, sni, fp;
std::vector<std::string> alpnList;
tribool udp, tfo, scv;
anytls = anytls.substr(9);
string_size pos;
pos = anytls.rfind("#");
if (pos != anytls.npos) {
remarks = urlDecode(anytls.substr(pos + 1));
anytls.erase(pos);
}
pos = anytls.rfind("?");
if (pos != anytls.npos) {
addition = anytls.substr(pos + 1);
anytls.erase(pos);
}
pos = anytls.find("@");
if (pos != anytls.npos) {
password = anytls.substr(0, pos);
anytls = anytls.substr(pos + 1);
}
pos = anytls.find(":");
if (pos != anytls.npos) {
add = anytls.substr(0, pos);
port = anytls.substr(pos + 1);
}
if (remarks.empty())
remarks = add + ":" + port;
std::string alpn = getUrlArg(addition, "alpn");
if (!alpn.empty()) {
auto alpns = split(alpn, ",");
for (auto &item : alpns) {
if (!item.empty())
alpnList.emplace_back(item);
}
}
fp = getUrlArg(addition, "fp");
if (fp.empty())
fp = getUrlArg(addition, "fingerprint");
sni = getUrlArg(addition, "sni");
udp = getUrlArg(addition, "udp");
tfo = getUrlArg(addition, "tfo");
scv = getUrlArg(addition, "insecure");
anyTlSConstruct(node, ANYTLS_DEFAULT_GROUP, remarks, port, password, add, alpnList, fp, sni, udp, tfo, scv,
tribool(), "", 30, 30, 0);
}
void explode(const std::string &link, Proxy &node) { void explode(const std::string &link, Proxy &node) {
if (startsWith(link, "ssr://")) if (startsWith(link, "ssr://"))
explodeSSR(link, node); explodeSSR(link, node);
@@ -3192,6 +3247,8 @@ void explode(const std::string &link, Proxy &node) {
explodeHysteria(link, node); explodeHysteria(link, node);
else if (strFind(link, "tuic://")) else if (strFind(link, "tuic://"))
explodeTuic(link, node); explodeTuic(link, node);
else if (strFind(link, "anytls://"))
explodeAnyTLS(link, node);
else if (strFind(link, "hysteria2://") || strFind(link, "hy2://")) else if (strFind(link, "hysteria2://") || strFind(link, "hy2://"))
explodeHysteria2(link, node); explodeHysteria2(link, node);
else if (strFind(link, "mierus://") || strFind(link, "mieru://")) else if (strFind(link, "mierus://") || strFind(link, "mieru://"))

View File

@@ -130,6 +130,8 @@ void explodeHysteria(std::string hysteria, Proxy &node);
void explodeHysteria2(std::string hysteria2, Proxy &node); void explodeHysteria2(std::string hysteria2, Proxy &node);
void explodeAnyTLS(std::string anytls, Proxy &node);
/// Parse a link /// Parse a link
void explode(const std::string &link, Proxy &node); void explode(const std::string &link, Proxy &node);