Add internalLinkTypeUnsupportedProxy.

This commit is contained in:
levlam 2021-10-28 21:46:34 +03:00
parent 00a349656d
commit 81bfbecb18
5 changed files with 45 additions and 22 deletions

View File

@ -3216,6 +3216,9 @@ internalLinkTypeThemeSettings = InternalLinkType;
//@description The link is an unknown tg: link. Call getDeepLinkInfo to process the link @link Link to be passed to getDeepLinkInfo
internalLinkTypeUnknownDeepLink link:string = InternalLinkType;
//@description The link is a link to an unsupported proxy. An alert can be shown to the user
internalLinkTypeUnsupportedProxy = InternalLinkType;
//@description The link is a link to a video chat. Call searchPublicChat with the given chat username, and then joinGoupCall with the given invite hash to process the link
//@chat_username Username of the chat with the video chat @invite_hash If non-empty, invite hash to be used to join the video chat without being muted by administrators
//@is_live_stream True, if the video chat is expected to be a live stream in a channel or a broadcast group

View File

@ -354,6 +354,12 @@ class LinkManager::InternalLinkUnknownDeepLink final : public InternalLink {
}
};
class LinkManager::InternalLinkUnsupportedProxy final : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeUnsupportedProxy>();
}
};
class LinkManager::InternalLinkVoiceChat final : public InternalLink {
string dialog_username_;
string invite_hash_;
@ -863,6 +869,8 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
if (0 < port && port < 65536) {
return td::make_unique<InternalLinkProxy>(
get_arg("server"), port, td_api::make_object<td_api::proxyTypeSocks5>(get_arg("user"), get_arg("pass")));
} else {
return td::make_unique<InternalLinkUnsupportedProxy>();
}
}
} else if (path.size() == 1 && path[0] == "proxy") {
@ -872,6 +880,8 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
if (0 < port && port < 65536 && mtproto::ProxySecret::from_link(get_arg("secret")).is_ok()) {
return td::make_unique<InternalLinkProxy>(get_arg("server"), port,
td_api::make_object<td_api::proxyTypeMtproto>(get_arg("secret")));
} else {
return td::make_unique<InternalLinkUnsupportedProxy>();
}
}
} else if (path.size() == 1 && path[0] == "privatepost") {
@ -982,6 +992,8 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
if (0 < port && port < 65536) {
return td::make_unique<InternalLinkProxy>(
get_arg("server"), port, td_api::make_object<td_api::proxyTypeSocks5>(get_arg("user"), get_arg("pass")));
} else {
return td::make_unique<InternalLinkUnsupportedProxy>();
}
}
} else if (path[0] == "proxy") {
@ -991,6 +1003,8 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
if (0 < port && port < 65536 && mtproto::ProxySecret::from_link(get_arg("secret")).is_ok()) {
return td::make_unique<InternalLinkProxy>(get_arg("server"), port,
td_api::make_object<td_api::proxyTypeMtproto>(get_arg("secret")));
} else {
return td::make_unique<InternalLinkUnsupportedProxy>();
}
}
} else if (path[0] == "bg") {

View File

@ -98,6 +98,7 @@ class LinkManager final : public Actor {
class InternalLinkTheme;
class InternalLinkThemeSettings;
class InternalLinkUnknownDeepLink;
class InternalLinkUnsupportedProxy;
class InternalLinkVoiceChat;
struct LinkInfo {

View File

@ -3364,7 +3364,8 @@ class CliClient final : public Actor {
string bot_id;
string query;
get_args(args, bot_id, query);
send_request(td_api::make_object<td_api::getInlineQueryResults>(as_user_id(bot_id), 0, nullptr, query, ""));
send_request(td_api::make_object<td_api::getInlineQueryResults>(as_user_id(bot_id), as_chat_id(bot_id), nullptr,
query, ""));
} else if (op == "giqro") {
string bot_id;
string offset;

View File

@ -171,6 +171,9 @@ TEST(Link, parse_internal_link) {
auto unknown_deep_link = [](const td::string &link) {
return td::td_api::make_object<td::td_api::internalLinkTypeUnknownDeepLink>(link);
};
auto unsupported_proxy = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeUnsupportedProxy>();
};
auto video_chat = [](const td::string &chat_username, const td::string &invite_hash, bool is_live_stream) {
return td::td_api::make_object<td::td_api::internalLinkTypeVideoChat>(chat_username, invite_hash, is_live_stream);
};
@ -468,17 +471,22 @@ TEST(Link, parse_internal_link) {
proxy_mtproto("1.2.3.4", 80, "1234567890abcdef1234567890ABCDEF"));
parse_internal_link("t.me/proxy?server=1.2.3.4&port=80adasdas&secret=1234567890abcdef1234567890ABCDEF",
proxy_mtproto("1.2.3.4", 80, "1234567890abcdef1234567890ABCDEF"));
parse_internal_link("t.me/proxy?server=1.2.3.4&port=adasdas&secret=1234567890abcdef1234567890ABCDEF", nullptr);
parse_internal_link("t.me/proxy?server=1.2.3.4&port=65536&secret=1234567890abcdef1234567890ABCDEF", nullptr);
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=", nullptr);
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=12", nullptr);
parse_internal_link("t.me/proxy?server=1.2.3.4&port=adasdas&secret=1234567890abcdef1234567890ABCDEF",
unsupported_proxy());
parse_internal_link("t.me/proxy?server=1.2.3.4&port=65536&secret=1234567890abcdef1234567890ABCDEF",
unsupported_proxy());
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=", unsupported_proxy());
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=12", unsupported_proxy());
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=1234567890abcdef1234567890ABCDEF",
proxy_mtproto("google.com", 80, "1234567890abcdef1234567890ABCDEF"));
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=dd1234567890abcdef1234567890ABCDEF",
proxy_mtproto("google.com", 80, "dd1234567890abcdef1234567890ABCDEF"));
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=de1234567890abcdef1234567890ABCDEF", nullptr);
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=ee1234567890abcdef1234567890ABCDEF", nullptr);
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=ee1234567890abcdef1234567890ABCDEF0", nullptr);
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=de1234567890abcdef1234567890ABCDEF",
unsupported_proxy());
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=ee1234567890abcdef1234567890ABCDEF",
unsupported_proxy());
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=ee1234567890abcdef1234567890ABCDEF0",
unsupported_proxy());
parse_internal_link("t.me/proxy?server=google.com&port=8%30&secret=ee1234567890abcdef1234567890ABCDEF%30%30",
proxy_mtproto("google.com", 80, "ee1234567890abcdef1234567890ABCDEF00"));
parse_internal_link(
@ -491,24 +499,21 @@ TEST(Link, parse_internal_link) {
proxy_mtproto("1.2.3.4", 80, "1234567890abcdef1234567890ABCDEF"));
parse_internal_link("tg:proxy?server=1.2.3.4&port=80adasdas&secret=1234567890abcdef1234567890ABCDEF",
proxy_mtproto("1.2.3.4", 80, "1234567890abcdef1234567890ABCDEF"));
parse_internal_link(
"tg:proxy?server=1.2.3.4&port=adasdas&secret=1234567890abcdef1234567890ABCDEF",
unknown_deep_link("tg://proxy?server=1.2.3.4&port=adasdas&secret=1234567890abcdef1234567890ABCDEF"));
parse_internal_link(
"tg:proxy?server=1.2.3.4&port=65536&secret=1234567890abcdef1234567890ABCDEF",
unknown_deep_link("tg://proxy?server=1.2.3.4&port=65536&secret=1234567890abcdef1234567890ABCDEF"));
parse_internal_link("tg:proxy?server=1.2.3.4&port=adasdas&secret=1234567890abcdef1234567890ABCDEF",
unsupported_proxy());
parse_internal_link("tg:proxy?server=1.2.3.4&port=65536&secret=1234567890abcdef1234567890ABCDEF",
unsupported_proxy());
parse_internal_link("tg:proxy?server=google.com&port=8%30&secret=1234567890abcdef1234567890ABCDEF",
proxy_mtproto("google.com", 80, "1234567890abcdef1234567890ABCDEF"));
parse_internal_link("tg:proxy?server=google.com&port=8%30&secret=dd1234567890abcdef1234567890ABCDEF",
proxy_mtproto("google.com", 80, "dd1234567890abcdef1234567890ABCDEF"));
parse_internal_link(
"tg:proxy?server=google.com&port=8%30&secret=de1234567890abcdef1234567890ABCDEF",
unknown_deep_link("tg://proxy?server=google.com&port=8%30&secret=de1234567890abcdef1234567890ABCDEF"));
parse_internal_link("tg:proxy?server=google.com&port=8%30&secret=de1234567890abcdef1234567890ABCDEF",
unsupported_proxy());
parse_internal_link("t.me/socks?server=1.2.3.4&port=80", proxy_socks("1.2.3.4", 80, "", ""));
parse_internal_link("t.me/socks?server=1.2.3.4&port=80adasdas", proxy_socks("1.2.3.4", 80, "", ""));
parse_internal_link("t.me/socks?server=1.2.3.4&port=adasdas", nullptr);
parse_internal_link("t.me/socks?server=1.2.3.4&port=65536", nullptr);
parse_internal_link("t.me/socks?server=1.2.3.4&port=adasdas", unsupported_proxy());
parse_internal_link("t.me/socks?server=1.2.3.4&port=65536", unsupported_proxy());
parse_internal_link("t.me/socks?server=google.com&port=8%30", proxy_socks("google.com", 80, "", ""));
parse_internal_link("t.me/socks?server=google.com&port=8%30&user=1&pass=", proxy_socks("google.com", 80, "1", ""));
parse_internal_link("t.me/socks?server=google.com&port=8%30&user=&pass=2", proxy_socks("google.com", 80, "", "2"));
@ -516,9 +521,8 @@ TEST(Link, parse_internal_link) {
parse_internal_link("tg:socks?server=1.2.3.4&port=80", proxy_socks("1.2.3.4", 80, "", ""));
parse_internal_link("tg:socks?server=1.2.3.4&port=80adasdas", proxy_socks("1.2.3.4", 80, "", ""));
parse_internal_link("tg:socks?server=1.2.3.4&port=adasdas",
unknown_deep_link("tg://socks?server=1.2.3.4&port=adasdas"));
parse_internal_link("tg:socks?server=1.2.3.4&port=65536", unknown_deep_link("tg://socks?server=1.2.3.4&port=65536"));
parse_internal_link("tg:socks?server=1.2.3.4&port=adasdas", unsupported_proxy());
parse_internal_link("tg:socks?server=1.2.3.4&port=65536", unsupported_proxy());
parse_internal_link("tg:socks?server=google.com&port=8%30", proxy_socks("google.com", 80, "", ""));
parse_internal_link("tg:socks?server=google.com&port=8%30&user=1&pass=", proxy_socks("google.com", 80, "1", ""));
parse_internal_link("tg:socks?server=google.com&port=8%30&user=&pass=2", proxy_socks("google.com", 80, "", "2"));