From 74008ebce45637cab5cba0f53398846c384f7058 Mon Sep 17 00:00:00 2001 From: David Guillen Fandos Date: Fri, 9 Jul 2021 23:43:30 +0200 Subject: [PATCH] Fix proxy_id validation and add HTTP proxy support --- tdlight-api-openapi.yaml | 32 ++++++++++++++++++++++---------- telegram-bot-api/Client.cpp | 30 ++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/tdlight-api-openapi.yaml b/tdlight-api-openapi.yaml index 97cd2ed..61cb5ac 100644 --- a/tdlight-api-openapi.yaml +++ b/tdlight-api-openapi.yaml @@ -2129,17 +2129,20 @@ paths: description: TCP port where the server is listening for incomming connections. type: integer type: - description: Type of proxy to be added. Must be either `mtproto` or `socks5`. MTProto proxies must provide a `secret` and Socks5 proxies can a `username` and `password`. + description: Type of proxy to be added. Must be either `mtproto`, `socks5` or `http`. MTProto proxies must provide a `secret` and Socks5/Http proxies can a `username` and `password`. type: string username: - description: Username used to authenticate against a Socks5 proxy. + description: Username used to authenticate against a Socks5/Http proxy. type: string password: - description: Password used to authenticate against a Socks5 proxy. + description: Password used to authenticate against a Socks5/Http proxy. type: string secret: description: Secret used to authenticate against an MTProto proxy. type: string + http_only: + description: Set to true if the proxy only supports HTTP requests (as opposed to transparent TCP connections via HTTP CONNECT). + type: boolean required: - server - port @@ -2155,17 +2158,20 @@ paths: description: TCP port where the server is listening for incomming connections. type: integer type: - description: Type of proxy to be added. Must be either `mtproto` or `socks5`. MTProto proxies must provide a `secret` and Socks5 proxies can a `username` and `password`. + description: Type of proxy to be added. Must be either `mtproto`, `socks5` or `http`. MTProto proxies must provide a `secret` and Socks5/Http proxies can a `username` and `password`. type: string username: - description: Username used to authenticate against a Socks5 proxy. + description: Username used to authenticate against a Socks5/Http proxy. type: string password: - description: Password used to authenticate against a Socks5 proxy. + description: Password used to authenticate against a Socks5/Http proxy. type: string secret: description: Secret used to authenticate against an MTProto proxy. type: string + http_only: + description: Set to true if the proxy only supports HTTP requests (as opposed to transparent TCP connections via HTTP CONNECT). + type: boolean required: - server - port @@ -2181,17 +2187,20 @@ paths: description: TCP port where the server is listening for incomming connections. type: integer type: - description: Type of proxy to be added. Must be either `mtproto` or `socks5`. MTProto proxies must provide a `secret` and Socks5 proxies can a `username` and `password`. + description: Type of proxy to be added. Must be either `mtproto`, `socks5` or `http`. MTProto proxies must provide a `secret` and Socks5/Http proxies can a `username` and `password`. type: string username: - description: Username used to authenticate against a Socks5 proxy. + description: Username used to authenticate against a Socks5/Http proxy. type: string password: - description: Password used to authenticate against a Socks5 proxy. + description: Password used to authenticate against a Socks5/Http proxy. type: string secret: description: Secret used to authenticate against an MTProto proxy. type: string + http_only: + description: Set to true if the proxy only supports HTTP requests (as opposed to transparent TCP connections via HTTP CONNECT). + type: boolean required: - server - port @@ -12438,7 +12447,7 @@ components: description: 'TCP port where the proxy server listens.' type: integer type: - description: 'Type of proxy server, either socks5 or mtproto.' + description: 'Type of proxy server, either socks5, mtproto or http.' type: string username: description: 'Username to authenticate to the proxy server.' @@ -12449,6 +12458,9 @@ components: secret: description: 'Secret to authenticate to the proxy server.' type: string + http_only: + description: 'Whether an Http proxy can only use Http requests (and does not support HTTP CONNECT method).' + type: boolean required: - id - last_used_date diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index e7cf1a6..8e6128f 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -2719,6 +2719,15 @@ class Client::JsonProxy : public Jsonable { object("secret", ptype->secret_); } break; + case td_api::proxyTypeHttp::ID: + { + auto ptype = static_cast(proxy_->type_.get()); + object("type", "http"); + object("username", ptype->username_); + object("password", ptype->password_); + object("http_only", td::JsonBool(ptype->http_only_)); + } + break; }; } @@ -8757,6 +8766,11 @@ td::Status Client::process_add_proxy_query(PromisedQueryPtr &query) { auto proxy_user = query->arg("username"); auto proxy_pass = query->arg("password"); type = td_api::make_object(proxy_user.str(), proxy_pass.str()); + } else if (proxy_type == "http") { + auto proxy_user = query->arg("username"); + auto proxy_pass = query->arg("password"); + auto proxy_http = query->arg("http_only"); + type = td_api::make_object(proxy_user.str(), proxy_pass.str(), to_bool(proxy_http)); } else { return Status::Error(400, "Unsupported proxy type"); } @@ -8767,23 +8781,23 @@ td::Status Client::process_add_proxy_query(PromisedQueryPtr &query) { } td::Status Client::process_delete_proxy_query(PromisedQueryPtr &query) { - int32 pid = get_integer_arg(query.get(), "proxy_id", 0, 0); - if (pid == 0) { - return Status::Error(400, PSLICE() << "Invalid proxy_id specified"); + auto arg_pid = query->arg("proxy_id"); + if (arg_pid.empty()) { + return Status::Error(400, PSLICE() << "No proxy_id specified"); } - send_request(make_object(pid), + send_request(make_object(td::to_integer(arg_pid)), std::make_unique(std::move(query))); return Status::OK(); } td::Status Client::process_enable_proxy_query(PromisedQueryPtr &query) { - int32 pid = get_integer_arg(query.get(), "proxy_id", 0, 0); - if (pid == 0) { - return Status::Error(400, PSLICE() << "Invalid proxy_id specified"); + auto arg_pid = query->arg("proxy_id"); + if (arg_pid.empty()) { + return Status::Error(400, PSLICE() << "No proxy_id specified"); } - send_request(make_object(pid), + send_request(make_object(td::to_integer(arg_pid)), std::make_unique(std::move(query))); return Status::OK(); }