Add connection_parameters options.

GitOrigin-RevId: 68ad956881c53ea9ee7ca529947737b2d55b585a
This commit is contained in:
levlam 2019-07-15 21:37:45 +03:00
parent 58dd51916d
commit 5de81015ad
5 changed files with 47 additions and 0 deletions

View File

@ -51,6 +51,11 @@ Result<td_api::object_ptr<td_api::JsonValue>> get_json_value(MutableSlice json)
return get_json_value_object(json_value);
}
Result<telegram_api::object_ptr<telegram_api::JSONValue>> get_input_json_value(MutableSlice json) {
TRY_RESULT(json_value, get_json_value(json));
return convert_json_value(std::move(json_value));
}
static td_api::object_ptr<td_api::jsonObjectMember> convert_json_value_member_object(
const telegram_api::object_ptr<telegram_api::jsonObjectValue> &json_object_value) {
CHECK(json_object_value != nullptr);

View File

@ -17,6 +17,8 @@ namespace td {
Result<td_api::object_ptr<td_api::JsonValue>> get_json_value(MutableSlice json);
Result<telegram_api::object_ptr<telegram_api::JSONValue>> get_input_json_value(MutableSlice json);
td_api::object_ptr<td_api::JsonValue> convert_json_value_object(
const tl_object_ptr<telegram_api::JSONValue> &json_value);

View File

@ -3666,6 +3666,10 @@ void Td::on_config_option_updated(const string &name) {
} else if (name == "disable_top_chats") {
send_closure(top_dialog_manager_, &TopDialogManager::update_is_enabled,
!G()->shared_config().get_option_boolean(name));
} else if (name == "connection_parameters") {
if (G()->mtproto_header().set_parameters(G()->shared_config().get_option_string(name))) {
G()->net_query_dispatcher().update_mtproto_header();
}
} else if (name == "is_emulator") {
if (G()->mtproto_header().set_is_emulator(G()->shared_config().get_option_boolean(name))) {
G()->net_query_dispatcher().update_mtproto_header();
@ -4126,6 +4130,7 @@ Status Td::init(DbKey key) {
options_.language_pack = G()->shared_config().get_option_string("localization_target");
options_.language_code = G()->shared_config().get_option_string("language_pack_id");
options_.parameters = G()->shared_config().get_option_string("connection_parameters");
options_.is_emulator = G()->shared_config().get_option_boolean("is_emulator");
// options_.proxy = Proxy();
G()->set_mtproto_header(make_unique<MtprotoHeader>(options_));
@ -4694,6 +4699,7 @@ Status Td::set_parameters(td_api::object_ptr<td_api::tdlibParameters> parameters
}
options_.language_pack = "";
options_.language_code = "";
options_.parameters = "";
options_.is_emulator = false;
options_.proxy = Proxy();
@ -6679,6 +6685,17 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
bool is_bot = auth_manager_ != nullptr && auth_manager_->is_authorized() && auth_manager_->is_bot();
switch (request.name_[0]) {
case 'c':
if (!is_bot && set_string_option("connection_parameters", [](Slice value) {
string value_copy = value.str();
auto r_json_value = get_json_value(value_copy);
if (r_json_value.is_error()) {
return false;
}
return r_json_value.ok()->get_id() == td_api::jsonValueObject::ID;
})) {
return;
}
case 'd':
if (!is_bot && set_boolean_option("disable_contact_registered_notifications")) {
return;

View File

@ -7,6 +7,9 @@
#include "td/telegram/net/MtprotoHeader.h"
#include "td/telegram/LanguagePackManager.h"
#include "td/telegram/JsonValue.h"
#include "td/tl/tl_object_store.h"
#include "td/utils/tl_helpers.h"
@ -35,6 +38,9 @@ class HeaderStorer {
if (have_proxy) {
flags |= 1 << 0;
}
if (!options.parameters.empty()) {
flags |= 1 << 1;
}
if (options.is_emulator) {
flags |= 1 << 10;
}
@ -67,6 +73,12 @@ class HeaderStorer {
store(Slice(options.proxy.server()), storer);
store(options.proxy.port(), storer);
}
if (!options.parameters.empty()) {
auto parameters_copy = options.parameters;
auto json_value = get_input_json_value(parameters_copy).move_as_ok();
CHECK(json_value != nullptr);
TlStoreBoxedUnknown<TlStoreObject>::store(json_value, storer);
}
}
private:

View File

@ -23,6 +23,7 @@ class MtprotoHeader {
string application_version;
string language_pack;
string language_code;
string parameters;
bool is_emulator = false;
Proxy proxy;
};
@ -36,6 +37,16 @@ class MtprotoHeader {
default_header_ = gen_header(options_, false);
}
bool set_parameters(string parameters) {
if (options_.parameters == parameters) {
return false;
}
options_.parameters = parameters;
default_header_ = gen_header(options_, false);
return true;
}
bool set_is_emulator(bool is_emulator) {
if (options_.is_emulator == is_emulator) {
return false;