From 2b75f6030faff85a9eabc9028d7d3b47c99bfd0c Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 23 Apr 2018 20:51:59 +0300 Subject: [PATCH] Various improvements. GitOrigin-RevId: e2480ad06ef003e2d0e8db769c837d5b713d96c1 --- td/generate/scheme/td_api.tl | 4 ++-- td/telegram/SecureValue.cpp | 20 +++++++++++++++++--- test/mtproto.cpp | 18 +++++++++++++++--- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 818577ede..b383f8247 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3016,7 +3016,7 @@ getPassportData type:PassportDataType password:string = PassportData; //@description Returns all filled Telegram Passport data @password Password of the current user getAllPassportData password:string = AllPassportData; -//@description Sets Telegram Passport data @data Input Telegram Passport data @password Password of the current user +//@description Sets Telegram Passport data. May return an error with a message "PHONE_VERIFICATION_NEEDED" or "EMAIL_VERIFICATION_NEEDED" if the set phone number or the set email address must be verified first @data Input Telegram Passport data @password Password of the current user setPassportData data:InputPassportData password:string = PassportData; //@description Deletes Telegram Passport data @type Data type @@ -3095,7 +3095,7 @@ getInviteText = Text; //@description Returns the terms of service. Can be called before authorization getTermsOfService = Text; -//@description Returns information about a tg:// deep link. Returns a 404 error for unknown links. Can be called before authorization @link The link +//@description Returns information about a tg:// deep link. Use "tg://need_update_for_some_feature" or "tg:some_unsupported_feature" for testing. Returns a 404 error for unknown links. Can be called before authorization @link The link getDeepLinkInfo link:string = DeepLinkInfo; diff --git a/td/telegram/SecureValue.cpp b/td/telegram/SecureValue.cpp index 73d9ccef3..3ff1f3511 100644 --- a/td/telegram/SecureValue.cpp +++ b/td/telegram/SecureValue.cpp @@ -24,6 +24,8 @@ #include "td/utils/misc.h" #include "td/utils/overloaded.h" +#include + namespace td { StringBuilder &operator<<(StringBuilder &string_builder, const SecureValueType &type) { @@ -541,6 +543,18 @@ static Result get_date(td_api::object_ptr &&date) { << lpad0(to_string(date->year_), 4); } +static Result to_int32(Slice str) { + CHECK(str.size() <= static_cast(std::numeric_limits::digits10)); + int32 integer_value = 0; + for (auto c : str) { + if (!is_digit(c)) { + return Status::Error(PSLICE() << "Can't parse \"" << str << "\" as number"); + } + integer_value = integer_value * 10 + c - '0'; + } + return integer_value; +} + static Result> get_date_object(Slice date) { if (date.empty()) { return nullptr; @@ -552,9 +566,9 @@ static Result> get_date_object(Slice date) { if (parts.size() != 3 || parts[0].size() != 2 || parts[1].size() != 2 || parts[2].size() != 4) { return Status::Error(400, "Date has wrong parts"); } - TRY_RESULT(day, to_integer_safe(parts[0])); - TRY_RESULT(month, to_integer_safe(parts[1])); - TRY_RESULT(year, to_integer_safe(parts[2])); + TRY_RESULT(day, to_int32(parts[0])); + TRY_RESULT(month, to_int32(parts[1])); + TRY_RESULT(year, to_int32(parts[2])); TRY_STATUS(check_date(day, month, year)); return td_api::make_object(day, month, year); diff --git a/test/mtproto.cpp b/test/mtproto.cpp index 7702a1e37..de81cd6c4 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -41,7 +41,11 @@ TEST(Mtproto, config) { { auto guard = sched.get_current_guard(); get_simple_config_azure(PromiseCreator::lambda([&](Result r_simple_config) { - LOG(ERROR) << to_string(r_simple_config.ok()); + if (r_simple_config.is_ok()) { + LOG(ERROR) << to_string(r_simple_config.ok()); + } else { + LOG(ERROR) << r_simple_config.error(); + } if (--cnt == 0) { Scheduler::instance()->finish(); } @@ -49,7 +53,11 @@ TEST(Mtproto, config) { .release(); get_simple_config_google_app(PromiseCreator::lambda([&](Result r_simple_config) { - LOG(ERROR) << to_string(r_simple_config.ok()); + if (r_simple_config.is_ok()) { + LOG(ERROR) << to_string(r_simple_config.ok()); + } else { + LOG(ERROR) << r_simple_config.error(); + } if (--cnt == 0) { Scheduler::instance()->finish(); } @@ -57,7 +65,11 @@ TEST(Mtproto, config) { .release(); get_simple_config_google_dns(PromiseCreator::lambda([&](Result r_simple_config) { - LOG(ERROR) << to_string(r_simple_config.ok()); + if (r_simple_config.is_ok()) { + LOG(ERROR) << to_string(r_simple_config.ok()); + } else { + LOG(ERROR) << r_simple_config.error(); + } if (--cnt == 0) { Scheduler::instance()->finish(); }