From 0fb07d3376ce6769e363011861e1ceeb61b66ecc Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 30 Apr 2018 15:50:54 +0300 Subject: [PATCH] td_api::cleanFileName. GitOrigin-RevId: e03cf634eb6a1e8f7191ea2e6a62f8b8990b21d0 --- td/generate/scheme/td_api.tl | 3 +++ td/generate/scheme/td_api.tlo | Bin 124632 -> 124724 bytes td/telegram/Td.cpp | 11 +++++++++++ td/telegram/Td.h | 3 +++ td/telegram/cli.cpp | 2 ++ 5 files changed, 19 insertions(+) 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 f679e8e7bc6dbbfcc55c2fca0b2e9132dbb34790..98fbf587803a94ebbe9ec0e1d349062abcbf8042 100644 GIT binary patch delta 51 zcmca{mVL`P_J%EtDe;UV+f(Bir3FQPf8S`yo1BxHnCF(6lj@h4o65j2{mn#1kL?Ww Hj1gr35qT58 delta 25 hcmdmTj{U}2_J%EtDe;WL+f(Bir3JU&DPW8!0|1H=3A_LR 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++; }