Remove unsafe non-const NetQuery accessors.

This commit is contained in:
levlam 2023-08-30 18:25:26 +03:00
parent eb06c93532
commit b90bc7be4b
5 changed files with 17 additions and 24 deletions

View File

@ -244,7 +244,7 @@ void PhoneNumberManager::on_result(NetQueryPtr result) {
net_query_type_ = NetQueryType::None;
if (result->is_error()) {
if (query_id_ != 0) {
on_query_error(std::move(result->error()));
on_query_error(result->move_as_error());
}
return;
}

View File

@ -3104,14 +3104,16 @@ void Td::on_result(NetQueryPtr query) {
if (handler != nullptr) {
CHECK(query->is_ready());
if (query->is_ok()) {
handler->on_result(std::move(query->ok()));
handler->on_result(query->move_as_ok());
} else {
handler->on_error(std::move(query->error()));
handler->on_error(query->move_as_error());
}
} else if (!query->is_ok() || query->ok_tl_constructor() != telegram_api::upload_file::ID) {
} else {
if (!query->is_ok() || query->ok_tl_constructor() != telegram_api::upload_file::ID) {
LOG(WARNING) << query << " is ignored: no handlers found";
}
query->clear();
}
}
void Td::on_connection_state_changed(ConnectionState new_state) {

View File

@ -95,25 +95,15 @@ class NetQuery final : public TsListNode<NetQueryDebug> {
resend(dc_id_);
}
BufferSlice &query() {
const BufferSlice &query() const {
return query_;
}
BufferSlice &ok() {
CHECK(state_ == State::OK);
return answer_;
}
const BufferSlice &ok() const {
CHECK(state_ == State::OK);
return answer_;
}
Status &error() {
CHECK(state_ == State::Error);
return status_;
}
const Status &error() const {
CHECK(state_ == State::Error);
return status_;
@ -124,6 +114,7 @@ class NetQuery final : public TsListNode<NetQueryDebug> {
clear();
return ok;
}
Status move_as_error() TD_WARN_UNUSED_RESULT {
auto status = std::move(status_);
clear();

View File

@ -58,7 +58,7 @@ void NetQueryDelayer::delay(NetQueryPtr query) {
query->last_timeout_ = timeout;
LOG(INFO) << "Set total_timeout to " << query->total_timeout_ << " for " << query->id();
auto error = query->error().move_as_error();
auto error = query->error().clone();
query->resend();
// Fix for infinity flood control

View File

@ -391,7 +391,7 @@ void Session::on_bind_result(NetQueryPtr query) {
Status status;
if (query->is_error()) {
status = std::move(query->error());
status = query->move_as_error();
if (status.code() == 400 && status.message() == "ENCRYPTED_MESSAGE_INVALID") {
auto server_time = G()->server_time();
auto auth_key_creation_date = auth_data_.get_main_auth_key().created_at();
@ -424,7 +424,8 @@ void Session::on_bind_result(NetQueryPtr query) {
}
}
} else {
auto r_flag = fetch_result<telegram_api::auth_bindTempAuthKey>(query->ok());
auto answer = query->move_as_ok();
auto r_flag = fetch_result<telegram_api::auth_bindTempAuthKey>(answer);
if (r_flag.is_error()) {
status = r_flag.move_as_error();
} else if (!r_flag.ok()) {
@ -444,7 +445,6 @@ void Session::on_bind_result(NetQueryPtr query) {
connection_close(&long_poll_connection_);
}
query->clear();
yield();
}
@ -455,9 +455,10 @@ void Session::on_check_key_result(NetQueryPtr query) {
Status status;
if (query->is_error()) {
status = std::move(query->error());
status = query->move_as_error();
} else {
auto r_flag = fetch_result<telegram_api::help_getNearestDc>(query->ok());
auto answer = query->move_as_ok();
auto r_flag = fetch_result<telegram_api::help_getNearestDc>(answer);
if (r_flag.is_error()) {
status = r_flag.move_as_error();
}
@ -472,7 +473,6 @@ void Session::on_check_key_result(NetQueryPtr query) {
connection_close(&long_poll_connection_);
}
query->clear();
yield();
}