tdlight/td/telegram/LinkManager.h

196 lines
6.7 KiB
C
Raw Normal View History

2021-05-25 01:24:30 +02:00
//
2022-12-31 22:28:08 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
2021-05-25 01:24:30 +02: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 00:26:32 +02:00
#include "td/telegram/CustomEmojiId.h"
2023-09-15 18:07:18 +02:00
#include "td/telegram/DialogBoostLinkInfo.h"
2023-09-21 18:11:17 +02:00
#include "td/telegram/MessageFullId.h"
#include "td/telegram/MessageLinkInfo.h"
#include "td/telegram/td_api.h"
2021-11-24 10:53:38 +01:00
#include "td/telegram/UserId.h"
2021-05-25 01:24:30 +02:00
#include "td/actor/actor.h"
#include "td/utils/common.h"
2022-06-27 12:30:18 +02:00
#include "td/utils/Promise.h"
2021-05-25 01:53:25 +02:00
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
2021-05-25 01:24:30 +02:00
#include <utility>
2021-05-25 01:24:30 +02:00
namespace td {
2023-03-02 00:41:22 +01:00
class Proxy;
2021-05-25 01:24:30 +02:00
class Td;
class LinkManager final : public Actor {
2021-05-25 01:24:30 +02: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 22:51:36 +02:00
~LinkManager() final;
2021-05-25 01:24:30 +02: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 01:53:25 +02:00
// returns whether a link is an internal link, supported or not
static bool is_internal_link(Slice link);
2021-06-01 04:41:32 +02: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 14:21:36 +01:00
static Result<string> get_internal_link(const td_api::object_ptr<td_api::InternalLinkType> &type, bool is_internal);
2023-02-07 12:01:45 +01: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 18:11:17 +02: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 18:11:17 +02: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 14:21:36 +01:00
static string get_public_dialog_link(Slice username, bool is_internal);
2022-12-01 13:08:13 +01:00
2023-03-02 00:41:22 +01:00
static Result<string> get_proxy_link(const Proxy &proxy, bool is_internal);
2021-11-24 10:53:38 +01:00
static UserId get_link_user_id(Slice url);
static string get_t_me_url();
2022-10-03 00:26:32 +02:00
static Result<CustomEmojiId> get_link_custom_emoji_id(Slice url);
2022-07-18 22:40:57 +02:00
2023-09-15 18:07:18 +02:00
static Result<DialogBoostLinkInfo> get_dialog_boost_link_info(Slice url);
static Result<MessageLinkInfo> get_message_link_info(Slice url);
2021-05-25 01:24:30 +02:00
private:
void start_up() final;
void tear_down() final;
2021-05-25 01:24:30 +02:00
2021-06-01 02:55:08 +02:00
class InternalLinkActiveSessions;
2022-04-01 13:00:34 +02:00
class InternalLinkAttachMenuBot;
class InternalLinkAuthenticationCode;
class InternalLinkBackground;
2022-04-02 13:51:20 +02:00
class InternalLinkBotAddToChannel;
2021-05-30 02:25:45 +02:00
class InternalLinkBotStart;
class InternalLinkBotStartInGroup;
2021-06-01 02:55:08 +02:00
class InternalLinkChangePhoneNumber;
class InternalLinkConfirmPhone;
class InternalLinkDefaultMessageAutoDeleteTimerSettings;
2023-09-15 15:24:26 +02:00
class InternalLinkDialogBoost;
2023-04-03 16:28:51 +02:00
class InternalLinkDialogFolderInvite;
class InternalLinkDialogFolderSettings;
2021-05-28 16:27:30 +02:00
class InternalLinkDialogInvite;
class InternalLinkEditProfileSettings;
2021-05-30 02:46:06 +02:00
class InternalLinkGame;
2022-09-16 00:30:54 +02:00
class InternalLinkInstantView;
2022-05-03 16:19:22 +02:00
class InternalLinkInvoice;
2021-05-28 18:26:09 +02:00
class InternalLinkLanguage;
2022-03-14 18:13:59 +01:00
class InternalLinkLanguageSettings;
class InternalLinkMessage;
2021-05-25 18:05:17 +02:00
class InternalLinkMessageDraft;
class InternalLinkPassportDataRequest;
2022-05-23 19:37:15 +02:00
class InternalLinkPremiumFeatures;
class InternalLinkPremiumGiftCode;
2022-03-14 18:13:59 +01:00
class InternalLinkPrivacyAndSecuritySettings;
2021-05-29 02:51:31 +02:00
class InternalLinkProxy;
2021-05-31 03:15:33 +02:00
class InternalLinkPublicDialog;
class InternalLinkQrCodeAuthentication;
2022-07-25 11:06:32 +02:00
class InternalLinkRestorePurchases;
2021-06-01 02:55:08 +02:00
class InternalLinkSettings;
2023-09-07 18:23:07 +02:00
class InternalLinkSideMenuBot;
2021-05-28 16:27:30 +02:00
class InternalLinkStickerSet;
2023-06-05 16:56:16 +02:00
class InternalLinkStory;
2021-05-28 18:50:54 +02:00
class InternalLinkTheme;
2021-06-01 02:55:08 +02:00
class InternalLinkThemeSettings;
2021-05-25 18:30:23 +02:00
class InternalLinkUnknownDeepLink;
2021-10-28 20:46:34 +02:00
class InternalLinkUnsupportedProxy;
class InternalLinkUserPhoneNumber;
2022-12-01 15:42:57 +01:00
class InternalLinkUserToken;
2021-05-30 01:05:23 +02:00
class InternalLinkVoiceChat;
2023-02-23 16:07:33 +01:00
class InternalLinkWebApp;
2022-09-16 12:51:52 +02:00
enum class LinkType : int32 { External, TMe, Tg, Telegraph };
2022-09-16 12:20:19 +02:00
2021-05-28 16:27:30 +02:00
struct LinkInfo {
2022-09-16 12:20:19 +02:00
LinkType type_ = LinkType::External;
2021-05-28 16:27:30 +02: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 18:05:17 +02:00
static unique_ptr<InternalLink> get_internal_link_message_draft(Slice url, Slice text);
2023-03-02 14:21:36 +01: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 01:24:30 +02: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-26 23:57:28 +02:00
vector<string> whitelisted_domains_;
2021-05-25 01:24:30 +02:00
};
} // namespace td