From c35bc1c0fca2080a536d5541001cd8ca09ac9f88 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 7 Mar 2018 02:37:39 +0300 Subject: [PATCH] Remove now unsafe FileId constructors. GitOrigin-RevId: eb3e37f4056ff6b967e4fd3d9b310fdc0e7602a1 --- td/telegram/InlineQueriesManager.cpp | 2 +- td/telegram/StickersManager.cpp | 2 +- td/telegram/Td.cpp | 14 +++++++------- td/telegram/files/FileId.h | 9 ++++----- td/telegram/files/FileManager.cpp | 4 ++-- td/telegram/files/FileManager.h | 2 +- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 0dc38094..0b822e5c 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -974,7 +974,7 @@ td_api::object_ptr copy(const td_api::remoteFile &obj) { template <> td_api::object_ptr copy(const td_api::file &obj) { - FileId file_id(obj.id_); + FileId file_id(obj.id_, 0); // wrong, but there should be no difference for get_file_object if (file_id.is_valid()) { return G()->td().get_actor_unsafe()->file_manager_.get()->get_file_object(file_id); } else { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 85ce8e15..0a8da56d 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -3242,7 +3242,7 @@ vector StickersManager::get_attached_sticker_file_ids(const vector { public: GetAttachedStickerSetsRequest(ActorShared td, uint64 request_id, int32 file_id) - : RequestActor(std::move(td), request_id), file_id_(file_id) { + : RequestActor(std::move(td), request_id), file_id_(file_id, 0) { } }; @@ -5127,7 +5127,7 @@ void Td::on_request(uint64 id, const td_api::getPublicMessageLink &request) { void Td::on_request(uint64 id, const td_api::getFile &request) { CHECK_AUTH(); - send_closure(actor_id(this), &Td::send_result, id, file_manager_->get_file_object(FileId(request.file_id_))); + send_closure(actor_id(this), &Td::send_result, id, file_manager_->get_file_object(FileId(request.file_id_, 0))); } void Td::on_request(uint64 id, td_api::getRemoteFile &request) { @@ -5954,9 +5954,9 @@ void Td::on_request(uint64 id, const td_api::downloadFile &request) { if (!(1 <= priority && priority <= 32)) { return send_error_raw(id, 5, "Download priority must be in [1;32] range"); } - file_manager_->download(FileId(request.file_id_), download_file_callback_, priority); + file_manager_->download(FileId(request.file_id_, 0), download_file_callback_, priority); - auto file = file_manager_->get_file_object(FileId(request.file_id_), false); + auto file = file_manager_->get_file_object(FileId(request.file_id_, 0), false); if (file->id_ == 0) { return send_error_raw(id, 400, "Invalid file id"); } @@ -5967,7 +5967,7 @@ void Td::on_request(uint64 id, const td_api::downloadFile &request) { void Td::on_request(uint64 id, const td_api::cancelDownloadFile &request) { CHECK_AUTH(); - file_manager_->download(FileId(request.file_id_), nullptr, request.only_if_pending_ ? -1 : 0); + file_manager_->download(FileId(request.file_id_, 0), nullptr, request.only_if_pending_ ? -1 : 0); send_closure(actor_id(this), &Td::send_result, id, make_tl_object()); } @@ -5997,7 +5997,7 @@ void Td::on_request(uint64 id, td_api::uploadFile &request) { void Td::on_request(uint64 id, const td_api::cancelUploadFile &request) { CHECK_AUTH(); - file_manager_->upload(FileId(request.file_id_), nullptr, 0, 0); + file_manager_->upload(FileId(request.file_id_, 0), nullptr, 0, 0); send_closure(actor_id(this), &Td::send_result, id, make_tl_object()); } @@ -6046,7 +6046,7 @@ void Td::on_request(uint64 id, const td_api::deleteFile &request) { } }); - send_closure(file_manager_actor_, &FileManager::delete_file, FileId(request.file_id_), std::move(query_promise), + send_closure(file_manager_actor_, &FileManager::delete_file, FileId(request.file_id_, 0), std::move(query_promise), "td_api::deleteFile"); } diff --git a/td/telegram/files/FileId.h b/td/telegram/files/FileId.h index cf09e146..ef68681b 100644 --- a/td/telegram/files/FileId.h +++ b/td/telegram/files/FileId.h @@ -21,12 +21,11 @@ class FileId { public: FileId() = default; - explicit FileId(int32 file_id, int32 remote_id) : id(file_id), remote_id(remote_id) { + FileId(int32 file_id, int32 remote_id) : id(file_id), remote_id(remote_id) { } - explicit FileId(int32 file_id) : FileId(file_id, 0) { - } - template ::value>> - FileId(T file_id) = delete; + template ::value>, + typename = std::enable_if_t::value>> + FileId(T1 file_id, T2 remote_id) = delete; bool empty() const { return id <= 0; diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 0b763e38..771d89b0 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -621,7 +621,7 @@ void FileManager::try_forget_file_id(FileId file_id) { CHECK(it != file_node->file_ids_.end()); file_node->file_ids_.erase(it); *info = FileIdInfo(); - empty_file_ids_.push_back(FileId(file_id.get())); + empty_file_ids_.push_back(file_id.get()); } FileId FileManager::register_empty(FileType type) { @@ -1997,7 +1997,7 @@ FileId FileManager::next_file_id() { if (!empty_file_ids_.empty()) { auto res = empty_file_ids_.back(); empty_file_ids_.pop_back(); - return res; + return FileId{res, 0}; } FileId res(static_cast(file_id_info_.size()), 0); // LOG(ERROR) << "NEXT file_id " << res; diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index c9bd2d3f..4329eeb8 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -393,7 +393,7 @@ class FileManager : public FileLoadManager::Callback { std::map pmc_id_to_file_node_id_; vector file_id_info_; - vector empty_file_ids_; + vector empty_file_ids_; vector> file_nodes_; ActorOwn file_load_manager_; ActorOwn file_generate_manager_;