td_api::getProxyLink.
GitOrigin-RevId: 0d876446bbbb22467c452b088f4df24e7e1624a2
This commit is contained in:
parent
bf43893503
commit
cb6c46071e
@ -2138,7 +2138,7 @@ updateFile file:file = Update;
|
||||
//@generation_id Unique identifier for the generation process
|
||||
//@original_path The path to a file from which a new file is generated; may be empty
|
||||
//@destination_path The path to a file that should be created and where the new file should be generated
|
||||
//@conversion String specifying the conversion applied to the original file. If conversion is "#url#" than original_path contains a HTTP/HTTPS URL of a file, which should be downloaded by the client
|
||||
//@conversion String specifying the conversion applied to the original file. If conversion is "#url#" than original_path contains an HTTP/HTTPS URL of a file, which should be downloaded by the client
|
||||
updateFileGenerationStart generation_id:int64 original_path:string destination_path:string conversion:string = Update;
|
||||
|
||||
//@description File generation is no longer needed @generation_id Unique identifier for the generation process
|
||||
@ -3160,22 +3160,25 @@ getTermsOfService = Text;
|
||||
getDeepLinkInfo link:string = DeepLinkInfo;
|
||||
|
||||
|
||||
//@description Adds a proxy server for network requests. Can be called before authorization @server Proxy server IP address @port Proxy server port @enable True, if the proxy should be enabled @type Type of a proxy
|
||||
//@description Adds a proxy server for network requests. Can be called before authorization @server Proxy server IP address @port Proxy server port @enable True, if the proxy should be enabled @type Type of the proxy
|
||||
addProxy server:string port:int32 enable:Bool type:ProxyType = Proxy;
|
||||
|
||||
//@description Enables a proxy. Only one proxy can be enabled at a time. Can be called before authorization @proxy_id The proxy identifier
|
||||
//@description Enables a proxy. Only one proxy can be enabled at a time. Can be called before authorization @proxy_id Proxy identifier
|
||||
enableProxy proxy_id:int32 = Ok;
|
||||
|
||||
//@description Disables currently enabled proxy. Can be called before authorization
|
||||
disableProxy = Ok;
|
||||
|
||||
//@description Removes a proxy server. Can be called before authorization @proxy_id The proxy identifier
|
||||
//@description Removes a proxy server. Can be called before authorization @proxy_id Proxy identifier
|
||||
removeProxy proxy_id:int32 = Ok;
|
||||
|
||||
//@description Returns list of proxies that are currently set up. Can be called before authorization
|
||||
getProxies = Proxies;
|
||||
|
||||
//@description Computes time needed to receive a response from a Telegram server through the proxy. Can be called before authorization @proxy_id The proxy identifier
|
||||
//@description Returns an HTTPS link, which can be used to add the proxy. Available only for SOCKS5 and MTProto proxies. Can be called before authorization @proxy_id Proxy identifier
|
||||
getProxyLink proxy_id:int32 = Text;
|
||||
|
||||
//@description Computes time needed to receive a response from a Telegram server through the proxy. Can be called before authorization @proxy_id Proxy identifier
|
||||
pingProxy proxy_id:int32 = Seconds;
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -705,7 +705,13 @@ void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
|
||||
(config->flags_ & telegram_api::config::BLOCKED_MODE_MASK) != 0);
|
||||
}
|
||||
if (is_from_main_dc || !shared_config.have_option("t_me_url")) {
|
||||
shared_config.set_option_string("t_me_url", config->me_url_prefix_);
|
||||
auto url = config->me_url_prefix_;
|
||||
if (!url.empty()) {
|
||||
if (url.back() != '/') {
|
||||
url.push_back('/');
|
||||
}
|
||||
shared_config.set_option_string("t_me_url", url);
|
||||
}
|
||||
}
|
||||
if (is_from_main_dc) {
|
||||
if ((config->flags_ & telegram_api::config::TMP_SESSIONS_MASK) != 0) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "td/utils/misc.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
ConfigShared::ConfigShared(BinlogPmcPtr config_pmc, unique_ptr<Callback> callback)
|
||||
: config_pmc_(config_pmc), callback_(std::move(callback)) {
|
||||
for (auto key_value : config_pmc_->get_all()) {
|
||||
@ -85,6 +86,18 @@ int32 ConfigShared::get_option_integer(Slice name, int32 default_value) const {
|
||||
return to_integer<int32>(str_value.substr(1));
|
||||
}
|
||||
|
||||
string ConfigShared::get_option_string(Slice name, string default_value) const {
|
||||
auto str_value = get_option(name);
|
||||
if (str_value.empty()) {
|
||||
return default_value;
|
||||
}
|
||||
if (str_value[0] != 'S') {
|
||||
LOG(ERROR) << "Found \"" << str_value << "\" instead of string option";
|
||||
return default_value;
|
||||
}
|
||||
return str_value.substr(1);
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::OptionValue> ConfigShared::get_option_value(Slice value) const {
|
||||
return get_option_value_object(get_option(value));
|
||||
}
|
||||
@ -123,4 +136,5 @@ tl_object_ptr<td_api::OptionValue> ConfigShared::get_option_value_object(Slice v
|
||||
void ConfigShared::on_option_updated(Slice name) {
|
||||
callback_->on_option_updated(name.str());
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
namespace td {
|
||||
|
||||
class ConfigShared {
|
||||
public:
|
||||
class Callback {
|
||||
@ -41,6 +42,7 @@ class ConfigShared {
|
||||
|
||||
bool get_option_boolean(Slice name, bool default_value = false) const;
|
||||
int32 get_option_integer(Slice name, int32 default_value = 0) const;
|
||||
string get_option_string(Slice name, string default_value = "") const;
|
||||
|
||||
tl_object_ptr<td_api::OptionValue> get_option_value(Slice value) const;
|
||||
|
||||
@ -53,4 +55,5 @@ class ConfigShared {
|
||||
|
||||
void on_option_updated(Slice name);
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -4659,6 +4659,7 @@ Status Td::init(DbKey key) {
|
||||
case td_api::disableProxy::ID:
|
||||
case td_api::removeProxy::ID:
|
||||
case td_api::getProxies::ID:
|
||||
case td_api::getProxyLink::ID:
|
||||
case td_api::pingProxy::ID:
|
||||
return true;
|
||||
default:
|
||||
@ -7027,6 +7028,19 @@ void Td::on_request(uint64 id, const td_api::getProxies &request) {
|
||||
send_closure(G()->connection_creator(), &ConnectionCreator::get_proxies, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getProxyLink &request) {
|
||||
CREATE_REQUEST_PROMISE(promise);
|
||||
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<string> result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
promise.set_value(make_tl_object<td_api::text>(result.move_as_ok()));
|
||||
}
|
||||
});
|
||||
send_closure(G()->connection_creator(), &ConnectionCreator::get_proxy_link, request.proxy_id_,
|
||||
std::move(query_promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::pingProxy &request) {
|
||||
CREATE_REQUEST_PROMISE(promise);
|
||||
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<double> result) mutable {
|
||||
|
@ -825,6 +825,8 @@ class Td final : public NetQueryCallback {
|
||||
|
||||
void on_request(uint64 id, const td_api::getProxies &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getProxyLink &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::pingProxy &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getTextEntities &request);
|
||||
|
@ -3092,6 +3092,8 @@ class CliClient final : public Actor {
|
||||
send_request(make_tl_object<td_api::addProxy>(server, to_integer<int32>(port), op == "aeproxy", std::move(type)));
|
||||
} else if (op == "gproxy" || op == "gproxies") {
|
||||
send_request(make_tl_object<td_api::getProxies>());
|
||||
} else if (op == "gproxyl" || op == "gpl") {
|
||||
send_request(make_tl_object<td_api::getProxyLink>(as_proxy_id(args)));
|
||||
} else if (op == "pproxy") {
|
||||
send_request(make_tl_object<td_api::pingProxy>(as_proxy_id(args)));
|
||||
} else if (op == "touch") {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/telegram/ConfigManager.h"
|
||||
#include "td/telegram/ConfigShared.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/logevent/LogEvent.h"
|
||||
#include "td/telegram/MessagesManager.h"
|
||||
@ -322,6 +323,43 @@ void ConnectionCreator::get_proxies(Promise<td_api::object_ptr<td_api::proxies>>
|
||||
transform(proxies_, [this](const std::pair<int32, Proxy> &proxy) { return get_proxy_object(proxy.first); })));
|
||||
}
|
||||
|
||||
void ConnectionCreator::get_proxy_link(int32 proxy_id, Promise<string> promise) {
|
||||
if (proxies_.count(proxy_id) == 0) {
|
||||
return promise.set_error(Status::Error(400, "Unknown proxy identifier"));
|
||||
}
|
||||
|
||||
auto &proxy = proxies_[proxy_id];
|
||||
string url = G()->shared_config().get_option_string("t_me_url", "https://t.me/");
|
||||
bool is_socks = false;
|
||||
switch (proxy.type()) {
|
||||
case Proxy::Type::Socks5:
|
||||
url += "socks";
|
||||
is_socks = true;
|
||||
break;
|
||||
case Proxy::Type::Mtproto:
|
||||
url += "proxy";
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
url += "?server=";
|
||||
url += url_encode(proxy.server());
|
||||
url += "&port=";
|
||||
url += to_string(proxy.port());
|
||||
if (is_socks) {
|
||||
if (!proxy.user().empty() || !proxy.password().empty()) {
|
||||
url += "&user=";
|
||||
url += url_encode(proxy.user());
|
||||
url += "&pass=";
|
||||
url += url_encode(proxy.password());
|
||||
}
|
||||
} else {
|
||||
url += "&secret=";
|
||||
url += url_encode(proxy.secret());
|
||||
}
|
||||
promise.set_value(std::move(url));
|
||||
}
|
||||
|
||||
void ConnectionCreator::ping_proxy(int32 proxy_id, Promise<double> promise) {
|
||||
if (proxies_.count(proxy_id) == 0) {
|
||||
return promise.set_error(Status::Error(400, "Unknown proxy identifier"));
|
||||
|
@ -143,6 +143,7 @@ class ConnectionCreator : public NetQueryCallback {
|
||||
void disable_proxy(Promise<Unit> promise);
|
||||
void remove_proxy(int32 proxy_id, Promise<Unit> promise);
|
||||
void get_proxies(Promise<td_api::object_ptr<td_api::proxies>> promise);
|
||||
void get_proxy_link(int32 proxy_id, Promise<string> promise);
|
||||
void ping_proxy(int32 proxy_id, Promise<double> promise);
|
||||
|
||||
private:
|
||||
|
@ -91,4 +91,32 @@ Result<string> hex_decode(Slice hex) {
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
static bool is_url_char(char c) {
|
||||
return is_alnum(c) || c == '-' || c == '.' || c == '_' || c == '~';
|
||||
}
|
||||
|
||||
string url_encode(Slice str) {
|
||||
size_t length = 3 * str.size();
|
||||
for (auto c : str) {
|
||||
length -= 2 * is_url_char(c);
|
||||
}
|
||||
if (length == str.size()) {
|
||||
return str.str();
|
||||
}
|
||||
string result;
|
||||
result.reserve(length);
|
||||
for (auto c : str) {
|
||||
if (is_url_char(c)) {
|
||||
result += c;
|
||||
} else {
|
||||
auto ch = static_cast<unsigned char>(c);
|
||||
result += '%';
|
||||
result += "0123456789ABCDEF"[ch / 16];
|
||||
result += "0123456789ABCDEF"[ch % 16];
|
||||
}
|
||||
}
|
||||
CHECK(result.size() == length);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -278,6 +278,8 @@ T clamp(T value, T min_value, T max_value) {
|
||||
|
||||
Result<string> hex_decode(Slice hex);
|
||||
|
||||
string url_encode(Slice str);
|
||||
|
||||
// run-time checked narrowing cast (type conversion):
|
||||
|
||||
namespace detail {
|
||||
|
Reference in New Issue
Block a user