From 110b3d58326df542e746a93bbd7a08e9f1ccc884 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 19 Nov 2019 19:26:39 +0300 Subject: [PATCH] Add get_simple_config_firebase_firestore. GitOrigin-RevId: 2c89f7667148f601d16aba01068ebb4f74bd12f8 --- td/telegram/ConfigManager.cpp | 30 +++++++++++++++++++++++++++--- td/telegram/ConfigManager.h | 3 +++ test/mtproto.cpp | 1 + 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 0b67b509..d3b0f4c8 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -252,7 +252,7 @@ static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise Result { TRY_RESULT(json, json_decode(http_query.content_)); if (json.type() != JsonValue::Type::Object) { - return Status::Error("JSON error"); + return Status::Error("Expected JSON object"); } auto &answer_object = json.get_object(); TRY_RESULT(answer, get_json_object_field(answer_object, "Answer", JsonValue::Type::Array, false)); @@ -260,7 +260,7 @@ static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise parts; for (auto &v : answer_array) { if (v.type() != JsonValue::Type::Object) { - return Status::Error("JSON error"); + return Status::Error("Expected JSON object"); } auto &data_object = v.get_object(); TRY_RESULT(part, get_json_object_string_field(data_object, "data", false)); @@ -320,7 +320,7 @@ ActorOwn<> get_simple_config_firebase_remote_config(Promise auto get_config = [](HttpQuery &http_query) -> Result { TRY_RESULT(json, json_decode(http_query.get_arg("entries"))); if (json.type() != JsonValue::Type::Object) { - return Status::Error("JSON error"); + return Status::Error("Expected JSON object"); } auto &entries_object = json.get_object(); TRY_RESULT(config, get_json_object_string_field(entries_object, "ipconfigv3", false)); @@ -346,6 +346,28 @@ ActorOwn<> get_simple_config_firebase_realtime(Promise promi prefer_ipv6, std::move(get_config)); } +ActorOwn<> get_simple_config_firebase_firestore(Promise promise, const ConfigShared *shared_config, + bool is_test, int32 scheduler_id) { + if (is_test) { + promise.set_error(Status::Error(400, "Test config is not supported")); + return ActorOwn<>(); + } + + string url = "https://www.google.com/v1/projects/reserve-5a846/databases/(default)/documents/ipconfig/v3"; + const bool prefer_ipv6 = shared_config == nullptr ? false : shared_config->get_option_boolean("prefer_ipv6"); + auto get_config = [](HttpQuery &http_query) -> Result { + TRY_RESULT(json, json_decode(http_query.get_arg("fields"))); + if (json.type() != JsonValue::Type::Object) { + return Status::Error("Expected JSON object"); + } + TRY_RESULT(data, get_json_object_field(json.get_object(), "data", JsonValue::Type::Object, false)); + TRY_RESULT(config, get_json_object_string_field(data.get_object(), "stringValue", false)); + return std::move(config); + }; + return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "firestore.googleapis.com", {}, + prefer_ipv6, std::move(get_config)); +} + ActorOwn<> get_full_config(DcOption option, Promise promise, ActorShared<> parent) { class SessionCallback : public Session::Callback { public: @@ -773,6 +795,8 @@ class ConfigRecoverer : public Actor { return get_simple_config_firebase_remote_config; case 4: return get_simple_config_firebase_realtime; + case 5: + return get_simple_config_firebase_firestore; case 0: return get_simple_config_google_dns; case 1: diff --git a/td/telegram/ConfigManager.h b/td/telegram/ConfigManager.h index b7cdcaad..7c3e659a 100644 --- a/td/telegram/ConfigManager.h +++ b/td/telegram/ConfigManager.h @@ -51,6 +51,9 @@ ActorOwn<> get_simple_config_firebase_remote_config(Promise ActorOwn<> get_simple_config_firebase_realtime(Promise promise, const ConfigShared *shared_config, bool is_test, int32 scheduler_id); +ActorOwn<> get_simple_config_firebase_firestore(Promise promise, const ConfigShared *shared_config, + bool is_test, int32 scheduler_id); + class HttpDate { static bool is_leap(int32 year) { return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); diff --git a/test/mtproto.cpp b/test/mtproto.cpp index d3503406..dfe15cdb 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -172,6 +172,7 @@ TEST(Mtproto, config) { run(get_simple_config_mozilla_dns, true); run(get_simple_config_firebase_remote_config, false); run(get_simple_config_firebase_realtime, false); + run(get_simple_config_firebase_firestore, false); } cnt--; sched.start();