Add dummy td_api::getCurrentState.
GitOrigin-RevId: 31ea0cfdc0c715fec52ef27340bed7358b13e042
This commit is contained in:
parent
2c5ce9591d
commit
db14b2da4e
@ -2310,6 +2310,10 @@ updateNewCustomEvent event:string = Update;
|
|||||||
updateNewCustomQuery id:int64 data:string timeout:int32 = Update;
|
updateNewCustomQuery id:int64 data:string timeout:int32 = Update;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Contains a list of updated @updates List of updates
|
||||||
|
updates updates:vector<Update> = Updates;
|
||||||
|
|
||||||
|
|
||||||
//@description A simple object containing a number; for testing only @value Number
|
//@description A simple object containing a number; for testing only @value Number
|
||||||
testInt value:int32 = TestInt;
|
testInt value:int32 = TestInt;
|
||||||
//@description A simple object containing a string; for testing only @value String
|
//@description A simple object containing a string; for testing only @value String
|
||||||
@ -2370,6 +2374,10 @@ close = Ok;
|
|||||||
destroy = Ok;
|
destroy = Ok;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Returns all updates needed to restore current TDLib state, i.e. all actual UpdateAuthorizationState/UpdateUser/UpdateNewChat and others. This is especially usefull if TDLib is run in a separate process
|
||||||
|
getCurrentState = Updates;
|
||||||
|
|
||||||
|
|
||||||
//@description Changes the database encryption key. Usually the encryption key is never changed and is stored in some OS keychain @new_encryption_key New encryption key
|
//@description Changes the database encryption key. Usually the encryption key is never changed and is stored in some OS keychain @new_encryption_key New encryption key
|
||||||
setDatabaseEncryptionKey new_encryption_key:bytes = Ok;
|
setDatabaseEncryptionKey new_encryption_key:bytes = Ok;
|
||||||
|
|
||||||
|
Binary file not shown.
@ -485,6 +485,14 @@ tl_object_ptr<td_api::AuthorizationState> AuthManager::get_authorization_state_o
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tl_object_ptr<td_api::AuthorizationState> AuthManager::get_current_authorization_state_object() const {
|
||||||
|
if (state_ == State::None) {
|
||||||
|
return nullptr;
|
||||||
|
} else {
|
||||||
|
return get_authorization_state_object(state_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AuthManager::get_state(uint64 query_id) {
|
void AuthManager::get_state(uint64 query_id) {
|
||||||
if (state_ == State::None) {
|
if (state_ == State::None) {
|
||||||
pending_get_authorization_state_requests_.push_back(query_id);
|
pending_get_authorization_state_requests_.push_back(query_id);
|
||||||
|
@ -168,6 +168,9 @@ class AuthManager : public NetActor {
|
|||||||
|
|
||||||
void on_closing();
|
void on_closing();
|
||||||
|
|
||||||
|
// can return nullptr if state isn't initialized yet
|
||||||
|
tl_object_ptr<td_api::AuthorizationState> get_current_authorization_state_object() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr size_t MAX_NAME_LENGTH = 64; // server side limit
|
static constexpr size_t MAX_NAME_LENGTH = 64; // server side limit
|
||||||
|
|
||||||
|
@ -3243,6 +3243,7 @@ bool Td::is_synchronous_request(int32 id) {
|
|||||||
|
|
||||||
bool Td::is_preinitialization_request(int32 id) {
|
bool Td::is_preinitialization_request(int32 id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
|
case td_api::getCurrentState::ID:
|
||||||
case td_api::setAlarm::ID:
|
case td_api::setAlarm::ID:
|
||||||
case td_api::testUseUpdate::ID:
|
case td_api::testUseUpdate::ID:
|
||||||
case td_api::testUseError::ID:
|
case td_api::testUseError::ID:
|
||||||
@ -3293,6 +3294,27 @@ bool Td::is_preauthentication_request(int32 id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::AuthorizationState> Td::get_fake_authorization_state_object() const {
|
||||||
|
switch (state_) {
|
||||||
|
case State::WaitParameters:
|
||||||
|
return td_api::make_object<td_api::authorizationStateWaitTdlibParameters>();
|
||||||
|
case State::Decrypt:
|
||||||
|
return td_api::make_object<td_api::authorizationStateWaitEncryptionKey>(encryption_info_.is_encrypted);
|
||||||
|
case State::Run:
|
||||||
|
UNREACHABLE();
|
||||||
|
return nullptr;
|
||||||
|
case State::Close:
|
||||||
|
if (close_flag_ == 5) {
|
||||||
|
return td_api::make_object<td_api::authorizationStateClosed>();
|
||||||
|
} else {
|
||||||
|
return td_api::make_object<td_api::authorizationStateClosing>();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
|
void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
LOG(ERROR) << "Ignore request with id == 0: " << to_string(function);
|
LOG(ERROR) << "Ignore request with id == 0: " << to_string(function);
|
||||||
@ -3307,21 +3329,37 @@ void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
|
|||||||
|
|
||||||
VLOG(td_requests) << "Receive request " << id << ": " << to_string(function);
|
VLOG(td_requests) << "Receive request " << id << ": " << to_string(function);
|
||||||
int32 function_id = function->get_id();
|
int32 function_id = function->get_id();
|
||||||
|
if (is_synchronous_request(function_id)) {
|
||||||
|
// send response synchronously
|
||||||
|
return send_result(id, static_request(std::move(function)));
|
||||||
|
}
|
||||||
|
if (state_ != State::Run) {
|
||||||
|
switch (function_id) {
|
||||||
|
case td_api::getAuthorizationState::ID:
|
||||||
|
// send response synchronously to prevent "Request aborted"
|
||||||
|
return send_result(id, get_fake_authorization_state_object());
|
||||||
|
case td_api::getCurrentState::ID: {
|
||||||
|
vector<td_api::object_ptr<td_api::Update>> updates;
|
||||||
|
updates.push_back(td_api::make_object<td_api::updateAuthorizationState>(get_fake_authorization_state_object()));
|
||||||
|
// send response synchronously to prevent "Request aborted"
|
||||||
|
return send_result(id, td_api::make_object<td_api::updates>(std::move(updates)));
|
||||||
|
}
|
||||||
|
case td_api::close::ID:
|
||||||
|
// need to send response synchronously before actual closing
|
||||||
|
send_result(id, td_api::make_object<td_api::ok>());
|
||||||
|
return close();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
switch (state_) {
|
switch (state_) {
|
||||||
case State::WaitParameters: {
|
case State::WaitParameters: {
|
||||||
switch (function_id) {
|
switch (function_id) {
|
||||||
case td_api::getAuthorizationState::ID:
|
|
||||||
return send_closure(actor_id(this), &Td::send_result, id,
|
|
||||||
td_api::make_object<td_api::authorizationStateWaitTdlibParameters>());
|
|
||||||
case td_api::setTdlibParameters::ID:
|
case td_api::setTdlibParameters::ID:
|
||||||
return answer_ok_query(
|
return answer_ok_query(
|
||||||
id, set_parameters(std::move(move_tl_object_as<td_api::setTdlibParameters>(function)->parameters_)));
|
id, set_parameters(std::move(move_tl_object_as<td_api::setTdlibParameters>(function)->parameters_)));
|
||||||
case td_api::close::ID:
|
|
||||||
return close();
|
|
||||||
case td_api::destroy::ID:
|
|
||||||
return destroy();
|
|
||||||
default:
|
default:
|
||||||
if (is_synchronous_request(function_id) || is_preinitialization_request(function_id)) {
|
if (is_preinitialization_request(function_id)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (is_preauthentication_request(function_id)) {
|
if (is_preauthentication_request(function_id)) {
|
||||||
@ -3335,10 +3373,6 @@ void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
|
|||||||
case State::Decrypt: {
|
case State::Decrypt: {
|
||||||
string encryption_key;
|
string encryption_key;
|
||||||
switch (function_id) {
|
switch (function_id) {
|
||||||
case td_api::getAuthorizationState::ID:
|
|
||||||
return send_closure(
|
|
||||||
actor_id(this), &Td::send_result, id,
|
|
||||||
td_api::make_object<td_api::authorizationStateWaitEncryptionKey>(encryption_info_.is_encrypted));
|
|
||||||
case td_api::checkDatabaseEncryptionKey::ID: {
|
case td_api::checkDatabaseEncryptionKey::ID: {
|
||||||
auto check_key = move_tl_object_as<td_api::checkDatabaseEncryptionKey>(function);
|
auto check_key = move_tl_object_as<td_api::checkDatabaseEncryptionKey>(function);
|
||||||
encryption_key = std::move(check_key->encryption_key_);
|
encryption_key = std::move(check_key->encryption_key_);
|
||||||
@ -3349,12 +3383,12 @@ void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
|
|||||||
encryption_key = std::move(set_key->new_encryption_key_);
|
encryption_key = std::move(set_key->new_encryption_key_);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case td_api::close::ID:
|
|
||||||
return close();
|
|
||||||
case td_api::destroy::ID:
|
case td_api::destroy::ID:
|
||||||
|
// need to send response synchronously before actual destroying
|
||||||
|
send_result(id, td_api::make_object<td_api::ok>());
|
||||||
return destroy();
|
return destroy();
|
||||||
default:
|
default:
|
||||||
if (is_synchronous_request(function_id) || is_preinitialization_request(function_id)) {
|
if (is_preinitialization_request(function_id)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (is_preauthentication_request(function_id)) {
|
if (is_preauthentication_request(function_id)) {
|
||||||
@ -3365,28 +3399,14 @@ void Td::request(uint64 id, tl_object_ptr<td_api::Function> function) {
|
|||||||
}
|
}
|
||||||
return answer_ok_query(id, init(as_db_key(encryption_key)));
|
return answer_ok_query(id, init(as_db_key(encryption_key)));
|
||||||
}
|
}
|
||||||
case State::Close: {
|
case State::Close:
|
||||||
if (function_id == td_api::getAuthorizationState::ID) {
|
|
||||||
if (close_flag_ == 5) {
|
|
||||||
return send_closure(actor_id(this), &Td::send_result, id,
|
|
||||||
td_api::make_object<td_api::authorizationStateClosed>());
|
|
||||||
} else {
|
|
||||||
return send_closure(actor_id(this), &Td::send_result, id,
|
|
||||||
td_api::make_object<td_api::authorizationStateClosing>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is_synchronous_request(function_id)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return send_error_raw(id, 401, "Unauthorized");
|
return send_error_raw(id, 401, "Unauthorized");
|
||||||
}
|
|
||||||
case State::Run:
|
case State::Run:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((auth_manager_ == nullptr || !auth_manager_->is_authorized()) && !is_preauthentication_request(function_id) &&
|
if ((auth_manager_ == nullptr || !auth_manager_->is_authorized()) && !is_preauthentication_request(function_id) &&
|
||||||
!is_preinitialization_request(function_id) && !is_synchronous_request(function_id) &&
|
!is_preinitialization_request(function_id) && !is_authentication_request(function_id)) {
|
||||||
!is_authentication_request(function_id)) {
|
|
||||||
return send_error_raw(id, 401, "Unauthorized");
|
return send_error_raw(id, 401, "Unauthorized");
|
||||||
}
|
}
|
||||||
downcast_call(*function, [this, id](auto &request) { this->on_request(id, request); });
|
downcast_call(*function, [this, id](auto &request) { this->on_request(id, request); });
|
||||||
@ -3721,6 +3741,7 @@ void Td::on_closed() {
|
|||||||
void Td::dec_stop_cnt() {
|
void Td::dec_stop_cnt() {
|
||||||
stop_cnt_--;
|
stop_cnt_--;
|
||||||
if (stop_cnt_ == 0) {
|
if (stop_cnt_ == 0) {
|
||||||
|
LOG(WARNING) << "Stop Td";
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3864,6 +3885,7 @@ void Td::close_impl(bool destroy_flag) {
|
|||||||
}
|
}
|
||||||
if (state_ == State::WaitParameters) {
|
if (state_ == State::WaitParameters) {
|
||||||
clear_requests();
|
clear_requests();
|
||||||
|
state_ = State::Close;
|
||||||
return on_closed();
|
return on_closed();
|
||||||
}
|
}
|
||||||
if (state_ == State::Decrypt) {
|
if (state_ == State::Decrypt) {
|
||||||
@ -4545,6 +4567,10 @@ void Td::on_request(uint64 id, td_api::checkAuthenticationBotToken &request) {
|
|||||||
send_closure(auth_manager_actor_, &AuthManager::check_bot_token, id, std::move(request.token_));
|
send_closure(auth_manager_actor_, &AuthManager::check_bot_token, id, std::move(request.token_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, const td_api::getCurrentState &request) {
|
||||||
|
return send_error_raw(id, 500, "Unimplemented");
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::getPasswordState &request) {
|
void Td::on_request(uint64 id, td_api::getPasswordState &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CREATE_REQUEST_PROMISE();
|
CREATE_REQUEST_PROMISE();
|
||||||
@ -6728,27 +6754,27 @@ void Td::on_request(uint64 id, const td_api::pingProxy &request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::getTextEntities &request) {
|
void Td::on_request(uint64 id, const td_api::getTextEntities &request) {
|
||||||
send_closure(actor_id(this), &Td::send_result, id, do_static_request(request));
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::parseTextEntities &request) {
|
void Td::on_request(uint64 id, td_api::parseTextEntities &request) {
|
||||||
send_closure(actor_id(this), &Td::send_result, id, do_static_request(request));
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::getFileMimeType &request) {
|
void Td::on_request(uint64 id, const td_api::getFileMimeType &request) {
|
||||||
send_closure(actor_id(this), &Td::send_result, id, do_static_request(request));
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::getFileExtension &request) {
|
void Td::on_request(uint64 id, const td_api::getFileExtension &request) {
|
||||||
send_closure(actor_id(this), &Td::send_result, id, do_static_request(request));
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::cleanFileName &request) {
|
void Td::on_request(uint64 id, const td_api::cleanFileName &request) {
|
||||||
send_closure(actor_id(this), &Td::send_result, id, do_static_request(request));
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::getLanguagePackString &request) {
|
void Td::on_request(uint64 id, const td_api::getLanguagePackString &request) {
|
||||||
send_closure(actor_id(this), &Td::send_result, id, do_static_request(request));
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
@ -260,6 +260,8 @@ class Td final : public NetQueryCallback {
|
|||||||
template <class T>
|
template <class T>
|
||||||
void complete_pending_preauthentication_requests(const T &func);
|
void complete_pending_preauthentication_requests(const T &func);
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::AuthorizationState> get_fake_authorization_state_object() const;
|
||||||
|
|
||||||
static void on_alarm_timeout_callback(void *td_ptr, int64 alarm_id);
|
static void on_alarm_timeout_callback(void *td_ptr, int64 alarm_id);
|
||||||
void on_alarm_timeout(int64 alarm_id);
|
void on_alarm_timeout(int64 alarm_id);
|
||||||
|
|
||||||
@ -341,6 +343,8 @@ class Td final : public NetQueryCallback {
|
|||||||
|
|
||||||
void on_request(uint64 id, td_api::checkAuthenticationBotToken &request);
|
void on_request(uint64 id, td_api::checkAuthenticationBotToken &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, const td_api::getCurrentState &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::getPasswordState &request);
|
void on_request(uint64 id, td_api::getPasswordState &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::setPassword &request);
|
void on_request(uint64 id, td_api::setPassword &request);
|
||||||
|
@ -417,7 +417,6 @@ class CliClient final : public Actor {
|
|||||||
break;
|
break;
|
||||||
case td_api::authorizationStateClosed::ID:
|
case td_api::authorizationStateClosed::ID:
|
||||||
LOG(WARNING) << "TD closed";
|
LOG(WARNING) << "TD closed";
|
||||||
// TODO only if count of created matches count of closed
|
|
||||||
td_.reset();
|
td_.reset();
|
||||||
if (!close_flag_) {
|
if (!close_flag_) {
|
||||||
create_td("ClientActor3");
|
create_td("ClientActor3");
|
||||||
@ -1193,6 +1192,8 @@ class CliClient final : public Actor {
|
|||||||
send_request(make_tl_object<td_api::checkAuthenticationPassword>(args));
|
send_request(make_tl_object<td_api::checkAuthenticationPassword>(args));
|
||||||
} else if (op == "cab" || op == "cabt") {
|
} else if (op == "cab" || op == "cabt") {
|
||||||
send_request(make_tl_object<td_api::checkAuthenticationBotToken>(args));
|
send_request(make_tl_object<td_api::checkAuthenticationBotToken>(args));
|
||||||
|
} else if (op == "gcs") {
|
||||||
|
send_request(make_tl_object<td_api::getCurrentState>());
|
||||||
} else if (op == "rapr") {
|
} else if (op == "rapr") {
|
||||||
send_request(make_tl_object<td_api::requestAuthenticationPasswordRecovery>());
|
send_request(make_tl_object<td_api::requestAuthenticationPasswordRecovery>());
|
||||||
} else if (op == "rap") {
|
} else if (op == "rap") {
|
||||||
@ -1204,7 +1205,10 @@ class CliClient final : public Actor {
|
|||||||
} else if (op == "reset") {
|
} else if (op == "reset") {
|
||||||
init_td();
|
init_td();
|
||||||
} else if (op == "close_td") {
|
} else if (op == "close_td") {
|
||||||
|
// send_request(make_tl_object<td_api::getCurrentState>());
|
||||||
send_request(make_tl_object<td_api::close>());
|
send_request(make_tl_object<td_api::close>());
|
||||||
|
// send_request(make_tl_object<td_api::getCurrentState>());
|
||||||
|
// send_request(make_tl_object<td_api::close>());
|
||||||
} else if (op == "DeleteAccountYesIReallyWantToDeleteMyAccount") {
|
} else if (op == "DeleteAccountYesIReallyWantToDeleteMyAccount") {
|
||||||
send_request(make_tl_object<td_api::deleteAccount>(args));
|
send_request(make_tl_object<td_api::deleteAccount>(args));
|
||||||
} else if (op == "gps" || op == "GetPasswordState") {
|
} else if (op == "gps" || op == "GetPasswordState") {
|
||||||
|
Loading…
Reference in New Issue
Block a user