tdlight/td/telegram/LinkManager.h

195 lines
6.7 KiB
C
Raw Normal View History

2021-05-25 02:24:30 +03:00
//
2023-01-01 00:28:08 +03:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
2021-05-25 02:24:30 +03:00
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
2022-10-03 01:26:32 +03:00
#include "td/telegram/CustomEmojiId.h"
2023-09-15 19:07:18 +03:00
#include "td/telegram/DialogBoostLinkInfo.h"
2023-09-21 19:11:17 +03:00
#include "td/telegram/MessageFullId.h"
#include "td/telegram/MessageLinkInfo.h"
#include "td/telegram/td_api.h"
2021-11-24 12:53:38 +03:00
#include "td/telegram/UserId.h"
2021-05-25 02:24:30 +03:00
#include "td/actor/actor.h"
#include "td/utils/common.h"
2022-06-27 13:30:18 +03:00
#include "td/utils/Promise.h"
2021-05-25 02:53:25 +03:00
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
2021-05-25 02:24:30 +03:00
#include <utility>
2021-05-25 02:24:30 +03:00
namespace td {
2023-03-02 02:41:22 +03:00
class Proxy;
2021-05-25 02:24:30 +03:00
class Td;
class LinkManager final : public Actor {
2021-05-25 02:24:30 +03:00
public:
LinkManager(Td *td, ActorShared<> parent);
LinkManager(const LinkManager &) = delete;
LinkManager &operator=(const LinkManager &) = delete;
LinkManager(LinkManager &&) = delete;
LinkManager &operator=(LinkManager &&) = delete;
2021-07-03 23:51:36 +03:00
~LinkManager() final;
2021-05-25 02:24:30 +03:00
class InternalLink {
public:
InternalLink() = default;
InternalLink(const InternalLink &) = delete;
InternalLink &operator=(const InternalLink &) = delete;
InternalLink(InternalLink &&) = delete;
InternalLink &operator=(InternalLink &&) = delete;
virtual ~InternalLink() = default;
virtual td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const = 0;
};
// checks whether the link is a valid tg, ton or HTTP(S) URL and returns it in a canonical form
static Result<string> check_link(CSlice link, bool http_only = false, bool https_only = false);
// same as check_link, but returns an empty string instead of an error
static string get_checked_link(Slice link, bool http_only = false, bool https_only = false);
2021-05-25 02:53:25 +03:00
// returns whether a link is an internal link, supported or not
static bool is_internal_link(Slice link);
2021-06-01 05:41:32 +03:00
// checks whether the link is a supported tg or t.me link and parses it
static unique_ptr<InternalLink> parse_internal_link(Slice link, bool is_trusted = false);
2023-03-02 16:21:36 +03:00
static Result<string> get_internal_link(const td_api::object_ptr<td_api::InternalLinkType> &type, bool is_internal);
2023-02-07 14:01:45 +03:00
void update_autologin_token(string autologin_token);
void update_autologin_domains(vector<string> autologin_domains, vector<string> url_auth_domains,
vector<string> whitelisted_domains);
void get_deep_link_info(Slice link, Promise<td_api::object_ptr<td_api::deepLinkInfo>> &&promise);
void get_external_link_info(string &&link, Promise<td_api::object_ptr<td_api::LoginUrlInfo>> &&promise);
2023-09-21 19:11:17 +03:00
void get_login_url_info(MessageFullId message_full_id, int64 button_id,
Promise<td_api::object_ptr<td_api::LoginUrlInfo>> &&promise);
2023-09-21 19:11:17 +03:00
void get_login_url(MessageFullId message_full_id, int64 button_id, bool allow_write_access,
Promise<td_api::object_ptr<td_api::httpUrl>> &&promise);
void get_link_login_url(const string &url, bool allow_write_access,
Promise<td_api::object_ptr<td_api::httpUrl>> &&promise);
static Result<string> get_background_url(const string &name,
td_api::object_ptr<td_api::BackgroundType> background_type);
static string get_dialog_filter_invite_link_slug(Slice invite_link);
static string get_dialog_filter_invite_link(Slice slug, bool is_internal);
static string get_dialog_invite_link_hash(Slice invite_link);
static string get_dialog_invite_link(Slice invite_hash, bool is_internal);
static string get_instant_view_link_url(Slice link);
static string get_instant_view_link_rhash(Slice link);
static string get_instant_view_link(Slice url, Slice rhash);
2023-03-02 16:21:36 +03:00
static string get_public_dialog_link(Slice username, bool is_internal);
2022-12-01 15:08:13 +03:00
2023-03-02 02:41:22 +03:00
static Result<string> get_proxy_link(const Proxy &proxy, bool is_internal);
2021-11-24 12:53:38 +03:00
static UserId get_link_user_id(Slice url);
static string get_t_me_url();
2022-10-03 01:26:32 +03:00
static Result<CustomEmojiId> get_link_custom_emoji_id(Slice url);
2022-07-18 23:40:57 +03:00
2023-09-15 19:07:18 +03:00
static Result<DialogBoostLinkInfo> get_dialog_boost_link_info(Slice url);
static Result<MessageLinkInfo> get_message_link_info(Slice url);
2021-05-25 02:24:30 +03:00
private:
void start_up() final;
void tear_down() final;
2021-05-25 02:24:30 +03:00
2021-06-01 03:55:08 +03:00
class InternalLinkActiveSessions;
2022-04-01 14:00:34 +03:00
class InternalLinkAttachMenuBot;
class InternalLinkAuthenticationCode;
class InternalLinkBackground;
2022-04-02 14:51:20 +03:00
class InternalLinkBotAddToChannel;
2021-05-30 03:25:45 +03:00
class InternalLinkBotStart;
class InternalLinkBotStartInGroup;
2021-06-01 03:55:08 +03:00
class InternalLinkChangePhoneNumber;
class InternalLinkConfirmPhone;
class InternalLinkDefaultMessageAutoDeleteTimerSettings;
2023-09-15 16:24:26 +03:00
class InternalLinkDialogBoost;
2023-04-03 17:28:51 +03:00
class InternalLinkDialogFolderInvite;
class InternalLinkDialogFolderSettings;
2021-05-28 17:27:30 +03:00
class InternalLinkDialogInvite;
class InternalLinkEditProfileSettings;
2021-05-30 03:46:06 +03:00
class InternalLinkGame;
2022-09-16 01:30:54 +03:00
class InternalLinkInstantView;
2022-05-03 17:19:22 +03:00
class InternalLinkInvoice;
2021-05-28 19:26:09 +03:00
class InternalLinkLanguage;
2022-03-14 18:13:59 +01:00
class InternalLinkLanguageSettings;
class InternalLinkMessage;
2021-05-25 19:05:17 +03:00
class InternalLinkMessageDraft;
class InternalLinkPassportDataRequest;
2022-05-23 20:37:15 +03:00
class InternalLinkPremiumFeatures;
2022-03-14 18:13:59 +01:00
class InternalLinkPrivacyAndSecuritySettings;
2021-05-29 03:51:31 +03:00
class InternalLinkProxy;
2021-05-31 04:15:33 +03:00
class InternalLinkPublicDialog;
class InternalLinkQrCodeAuthentication;
2022-07-25 12:06:32 +03:00
class InternalLinkRestorePurchases;
2021-06-01 03:55:08 +03:00
class InternalLinkSettings;
2023-09-07 19:23:07 +03:00
class InternalLinkSideMenuBot;
2021-05-28 17:27:30 +03:00
class InternalLinkStickerSet;
2023-06-05 17:56:16 +03:00
class InternalLinkStory;
2021-05-28 19:50:54 +03:00
class InternalLinkTheme;
2021-06-01 03:55:08 +03:00
class InternalLinkThemeSettings;
2021-05-25 19:30:23 +03:00
class InternalLinkUnknownDeepLink;
2021-10-28 21:46:34 +03:00
class InternalLinkUnsupportedProxy;
class InternalLinkUserPhoneNumber;
2022-12-01 17:42:57 +03:00
class InternalLinkUserToken;
2021-05-30 02:05:23 +03:00
class InternalLinkVoiceChat;
2023-02-23 18:07:33 +03:00
class InternalLinkWebApp;
2022-09-16 13:51:52 +03:00
enum class LinkType : int32 { External, TMe, Tg, Telegraph };
2022-09-16 13:20:19 +03:00
2021-05-28 17:27:30 +03:00
struct LinkInfo {
2022-09-16 13:20:19 +03:00
LinkType type_ = LinkType::External;
2021-05-28 17:27:30 +03:00
string query_;
};
// returns information about the link
static LinkInfo get_link_info(Slice link);
static unique_ptr<InternalLink> parse_tg_link_query(Slice query, bool is_trusted);
static unique_ptr<InternalLink> parse_t_me_link_query(Slice query, bool is_trusted);
static unique_ptr<InternalLink> get_internal_link_passport(Slice query, const vector<std::pair<string, string>> &args,
bool allow_unknown);
2021-05-25 19:05:17 +03:00
static unique_ptr<InternalLink> get_internal_link_message_draft(Slice url, Slice text);
2023-03-02 16:21:36 +03:00
static Result<string> get_internal_link_impl(const td_api::InternalLinkType *type_ptr, bool is_internal);
static Result<string> check_link_impl(Slice link, bool http_only, bool https_only);
2021-05-25 02:24:30 +03:00
Td *td_;
ActorShared<> parent_;
string autologin_token_;
vector<string> autologin_domains_;
double autologin_update_time_ = 0.0;
vector<string> url_auth_domains_;
2022-10-27 00:57:28 +03:00
vector<string> whitelisted_domains_;
2021-05-25 02:24:30 +03:00
};
} // namespace td