diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index b997a5a95..a049b9a26 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2516,6 +2516,9 @@ getFileMimeType file_name:string = Text; //@description Returns the extension of a file, guessed by its MIME type. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously @mime_type The MIME type of the file getFileExtension mime_type:string = Text; +//@description Removes potentially dangerous characters from a file name. File name encoding supposed to be UTF-8. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously @file_name The name of the file or path to the file +cleanFileName file_name:string = Text; + //@description Sends an inline query to a bot and returns its results. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires @bot_user_id The identifier of the target bot //@chat_id Identifier of the chat, where the query was sent @user_location Location of the user, only if needed @query Text of the query @offset Offset of the first entry to return diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index f679e8e7b..98fbf5878 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 4e9fdda08..f5f246948 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -71,6 +71,7 @@ #include "td/mtproto/utils.h" // for create_storer, fetch_result, etc, TODO #include "td/utils/buffer.h" +#include "td/utils/filesystem.h" #include "td/utils/format.h" #include "td/utils/MimeType.h" #include "td/utils/misc.h" @@ -7129,6 +7130,11 @@ void Td::on_request(uint64 id, const td_api::getFileExtension &request) { send_closure(actor_id(this), &Td::send_result, id, do_static_request(request)); } +void Td::on_request(uint64 id, const td_api::cleanFileName &request) { + // don't check authorization state + send_closure(actor_id(this), &Td::send_result, id, do_static_request(request)); +} + template td_api::object_ptr Td::do_static_request(const T &request) { return make_error(400, "Function can't be executed synchronously"); @@ -7179,6 +7185,11 @@ td_api::object_ptr Td::do_static_request(const td_api::getFileEx return make_tl_object(MimeType::to_extension(request.mime_type_)); } +td_api::object_ptr Td::do_static_request(const td_api::cleanFileName &request) { + // don't check file name UTF-8 correctness + return make_tl_object(clean_filename(request.file_name_)); +} + // test void Td::on_request(uint64 id, td_api::testNetwork &request) { create_handler(id)->send(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index a1bddbb5e..636024724 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -811,6 +811,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::getFileExtension &request); + void on_request(uint64 id, const td_api::cleanFileName &request); + // test void on_request(uint64 id, td_api::testNetwork &request); void on_request(uint64 id, td_api::testGetDifference &request); @@ -831,6 +833,7 @@ class Td final : public NetQueryCallback { static td_api::object_ptr do_static_request(td_api::parseTextEntities &request); static td_api::object_ptr do_static_request(const td_api::getFileMimeType &request); static td_api::object_ptr do_static_request(const td_api::getFileExtension &request); + static td_api::object_ptr do_static_request(const td_api::cleanFileName &request); Status init(DbKey key) TD_WARN_UNUSED_RESULT; void clear(); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 1b65ac92e..e4b76fb38 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2168,6 +2168,8 @@ class CliClient final : public Actor { send_request(make_tl_object(trim(args))); } else if (op == "gfe") { send_request(make_tl_object(trim(args))); + } else if (op == "cfn") { + send_request(make_tl_object(args)); } else { op_not_found_count++; }