From 7dbee219182c95a8a34cf32e232e5bbeffccd9f5 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 7 May 2021 02:10:37 +0300 Subject: [PATCH 01/43] Fix sending of updateGroupCallParticipant in some rare cases. --- td/telegram/GroupCallManager.cpp | 16 ++++++++++++---- td/telegram/GroupCallParticipantOrder.cpp | 4 ++++ td/telegram/GroupCallParticipantOrder.h | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index 682731182..f62f04c79 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -1863,7 +1863,7 @@ void GroupCallManager::process_group_call_participants( } auto min_order = GroupCallParticipantOrder::max(); - DialogId min_order_dialog_id; + DialogId debug_min_order_dialog_id; bool can_self_unmute = get_group_call_can_self_unmute(input_group_call_id); bool joined_date_asc = get_group_call_joined_date_asc(input_group_call_id); for (auto &group_call_participant : participants) { @@ -1883,11 +1883,11 @@ void GroupCallManager::process_group_call_participants( if (is_load) { auto real_order = participant.get_real_order(can_self_unmute, joined_date_asc, true); if (real_order > min_order) { - LOG(ERROR) << "Receive call participant " << participant.dialog_id << " with order " << real_order - << " after call participant " << min_order_dialog_id << " with order " << min_order; + LOG(ERROR) << "Receive group call participant " << participant.dialog_id << " with order " << real_order + << " after group call participant " << debug_min_order_dialog_id << " with order " << min_order; } else { min_order = real_order; - min_order_dialog_id = participant.dialog_id; + debug_min_order_dialog_id = participant.dialog_id; } } if (is_sync) { @@ -1895,6 +1895,13 @@ void GroupCallManager::process_group_call_participants( } process_group_call_participant(input_group_call_id, std::move(participant)); } + if (is_load && participants.empty() && !joined_date_asc) { + // If loaded 0 participants and new participants are added to the beginning of the list, + // then the end of the list was reached. + // Set min_order to the minimum possible value to send updates about all participants with order less than + // the current min_order. There can be such participants if the last loaded participant had a fake active_date. + min_order = GroupCallParticipantOrder::min(); + } if (is_sync) { auto participants_it = group_call_participants_.find(input_group_call_id); if (participants_it != group_call_participants_.end()) { @@ -1903,6 +1910,7 @@ void GroupCallManager::process_group_call_participants( for (auto participant_it = group_participants.begin(); participant_it != group_participants.end();) { auto &participant = *participant_it; if (old_participant_dialog_ids.count(participant.dialog_id) == 0) { + // successfully synced old user ++participant_it; continue; } diff --git a/td/telegram/GroupCallParticipantOrder.cpp b/td/telegram/GroupCallParticipantOrder.cpp index 6809d16d3..80a956f9a 100644 --- a/td/telegram/GroupCallParticipantOrder.cpp +++ b/td/telegram/GroupCallParticipantOrder.cpp @@ -14,6 +14,10 @@ namespace td { +GroupCallParticipantOrder GroupCallParticipantOrder::min() { + return GroupCallParticipantOrder(0, 0, 1); +} + GroupCallParticipantOrder GroupCallParticipantOrder::max() { return GroupCallParticipantOrder(std::numeric_limits::max(), std::numeric_limits::max(), std::numeric_limits::max()); diff --git a/td/telegram/GroupCallParticipantOrder.h b/td/telegram/GroupCallParticipantOrder.h index 973974465..dc055b326 100644 --- a/td/telegram/GroupCallParticipantOrder.h +++ b/td/telegram/GroupCallParticipantOrder.h @@ -30,6 +30,8 @@ class GroupCallParticipantOrder { : active_date(active_date), joined_date(joined_date), raise_hand_rating(raise_hand_rating) { } + static GroupCallParticipantOrder min(); + static GroupCallParticipantOrder max(); bool is_valid() const; From 9c49e6a62553f60ffae878c06de170237477259a Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 7 May 2021 20:52:54 +0300 Subject: [PATCH 02/43] Log versions on Td instance creation. --- td/telegram/Td.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 876fda2de..1316e1382 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -95,6 +95,7 @@ #include "td/telegram/TopDialogCategory.h" #include "td/telegram/TopDialogManager.h" #include "td/telegram/UpdatesManager.h" +#include "td/telegram/Version.h" #include "td/telegram/VideoNotesManager.h" #include "td/telegram/VideosManager.h" #include "td/telegram/VoiceNotesManager.h" @@ -3001,6 +3002,8 @@ class SetBackgroundRequest : public RequestActor<> { Td::Td(unique_ptr callback, Options options) : callback_(std::move(callback)), td_options_(std::move(options)) { CHECK(callback_ != nullptr); + LOG(INFO) << "Create Td with layer " << MTPROTO_LAYER << ", database version " << current_db_version() + << " and version " << static_cast(Version::Next) - 1; } Td::~Td() = default; From 6baf923f07d2f077e1254267dfc57ec40fc16351 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 9 May 2021 00:31:43 +0300 Subject: [PATCH 03/43] Fix handling of left dialogs, which are still pinned in filters. --- td/telegram/MessagesManager.cpp | 59 ++++++++++++++++++++++++--------- td/telegram/MessagesManager.h | 2 ++ 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 73bc0f6e4..e6928ba2a 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -9279,9 +9279,11 @@ void MessagesManager::after_get_difference() { auto *list = get_dialog_list(dialog_list_id); CHECK(list != nullptr); if (!list->is_dialog_unread_count_inited_) { - get_dialogs(dialog_list_id, MIN_DIALOG_DATE, static_cast(list->pinned_dialogs_.size() + 2), false, - PromiseCreator::lambda([dialog_list_id](Unit) { - if (!G()->close_flag()) { + int32 limit = list->are_pinned_dialogs_inited_ ? static_cast(list->pinned_dialogs_.size()) + : get_pinned_dialogs_limit(dialog_list_id); + get_dialogs(dialog_list_id, MIN_DIALOG_DATE, limit + 2, false, + PromiseCreator::lambda([dialog_list_id](Result result) { + if (!G()->close_flag() && result.is_ok()) { LOG(INFO) << "Inited total chat count in " << dialog_list_id; } })); @@ -14026,12 +14028,29 @@ void MessagesManager::set_dialog_is_empty(Dialog *d, const char *source) { update_dialog_pos(d, source); } +bool MessagesManager::is_dialog_pinned(DialogListId dialog_list_id, DialogId dialog_id) const { + if (get_dialog_pinned_order(dialog_list_id, dialog_id) != DEFAULT_ORDER) { + return true; + } + if (dialog_list_id.is_filter()) { + const auto *filter = get_dialog_filter(dialog_list_id.get_filter_id()); + if (filter != nullptr) { + for (const auto &input_dialog_id : filter->pinned_dialog_ids) { + if (input_dialog_id.get_dialog_id() == dialog_id) { + return true; + } + } + } + } + return false; +} + int64 MessagesManager::get_dialog_pinned_order(DialogListId dialog_list_id, DialogId dialog_id) const { return get_dialog_pinned_order(get_dialog_list(dialog_list_id), dialog_id); } int64 MessagesManager::get_dialog_pinned_order(const DialogList *list, DialogId dialog_id) { - if (list != nullptr && !list->pinned_dialogs_.empty()) { + if (list != nullptr && !list->pinned_dialog_id_orders_.empty()) { auto it = list->pinned_dialog_id_orders_.find(dialog_id); if (it != list->pinned_dialog_id_orders_.end()) { return it->second; @@ -14050,6 +14069,7 @@ bool MessagesManager::set_dialog_is_pinned(DialogId dialog_id, bool is_pinned) { return set_dialog_is_pinned(DialogListId(d->folder_id), d, is_pinned); } +// only removes the Dialog from the dialog list, but changes nothing in the corresponding DialogFilter bool MessagesManager::set_dialog_is_pinned(DialogListId dialog_list_id, Dialog *d, bool is_pinned, bool need_update_dialog_lists) { if (td_->auth_manager_->is_bot()) { @@ -14558,7 +14578,7 @@ void MessagesManager::on_get_dialogs(FolderId folder_id, vectorauth_manager_->is_bot() && !from_pinned_dialog_list) { // set is_pinned only after updating dialog pos to ensure that order is initialized bool is_pinned = (dialog->flags_ & DIALOG_FLAG_IS_PINNED) != 0; - bool was_pinned = get_dialog_pinned_order(DialogListId(d->folder_id), dialog_id) != DEFAULT_ORDER; + bool was_pinned = is_dialog_pinned(DialogListId(d->folder_id), dialog_id); if (is_pinned != was_pinned) { set_dialog_is_pinned(DialogListId(d->folder_id), d, is_pinned); } @@ -15641,7 +15661,7 @@ std::pair> MessagesManager::get_dialogs(DialogListId dia auto *filter = get_dialog_filter(dialog_list_id.get_filter_id()); CHECK(filter != nullptr); vector input_dialog_ids; - for (auto &input_dialog_id : filter->pinned_dialog_ids) { + for (const auto &input_dialog_id : filter->pinned_dialog_ids) { auto dialog_id = input_dialog_id.get_dialog_id(); if (!have_dialog_force(dialog_id, "get_dialogs")) { if (dialog_id.get_type() == DialogType::SecretChat) { @@ -15955,6 +15975,14 @@ void MessagesManager::preload_folder_dialog_list(FolderId folder_id) { vector MessagesManager::get_pinned_dialog_ids(DialogListId dialog_list_id) const { CHECK(!td_->auth_manager_->is_bot()); + if (dialog_list_id.is_filter()) { + const auto *filter = get_dialog_filter(dialog_list_id.get_filter_id()); + if (filter == nullptr) { + return {}; + } + return transform(filter->pinned_dialog_ids, [](auto &input_dialog) { return input_dialog.get_dialog_id(); }); + } + auto *list = get_dialog_list(dialog_list_id); if (list == nullptr || !list->are_pinned_dialogs_inited_) { return {}; @@ -17834,9 +17862,7 @@ void MessagesManager::sort_dialog_filter_input_dialog_ids(DialogFilter *dialog_f {&dialog_filter->pinned_dialog_ids, &dialog_filter->excluded_dialog_ids, &dialog_filter->included_dialog_ids}) { for (auto input_dialog_id : *input_dialog_ids) { LOG_CHECK(all_dialog_ids.insert(input_dialog_id.get_dialog_id()).second) - << source << ' ' << td::contains(dialog_filter->pinned_dialog_ids, input_dialog_id) << ' ' - << td::contains(dialog_filter->excluded_dialog_ids, input_dialog_id) << ' ' - << td::contains(dialog_filter->included_dialog_ids, input_dialog_id); + << source << ' ' << input_dialog_id.get_dialog_id() << ' ' << dialog_filter; } } } @@ -18185,7 +18211,7 @@ void MessagesManager::add_dialog_filter(unique_ptr dialog_filter, } } - for (auto &input_dialog_id : reversed(dialog_filters_.back()->pinned_dialog_ids)) { + for (const auto &input_dialog_id : reversed(dialog_filters_.back()->pinned_dialog_ids)) { auto dialog_id = input_dialog_id.get_dialog_id(); auto order = get_next_pinned_dialog_order(); list.pinned_dialogs_.emplace_back(order, dialog_id); @@ -18229,7 +18255,7 @@ void MessagesManager::edit_dialog_filter(unique_ptr new_dialog_fil new_list.dialog_list_id = dialog_list_id; auto old_it = old_list.pinned_dialogs_.rbegin(); - for (auto &input_dialog_id : reversed(new_dialog_filter->pinned_dialog_ids)) { + for (const auto &input_dialog_id : reversed(new_dialog_filter->pinned_dialog_ids)) { auto dialog_id = input_dialog_id.get_dialog_id(); while (old_it < old_list.pinned_dialogs_.rend()) { if (old_it->get_dialog_id() == dialog_id) { @@ -18689,7 +18715,7 @@ Status MessagesManager::toggle_dialog_is_pinned(DialogListId dialog_list_id, Dia return Status::Error(6, "Pinned chats must be loaded first"); } - bool was_pinned = get_dialog_pinned_order(dialog_list_id, dialog_id) != DEFAULT_ORDER; + bool was_pinned = is_dialog_pinned(dialog_list_id, dialog_id); if (is_pinned == was_pinned) { return Status::OK(); } @@ -18709,7 +18735,8 @@ Status MessagesManager::toggle_dialog_is_pinned(DialogListId dialog_list_id, Dia td::remove_if(new_dialog_filter->included_dialog_ids, is_changed_dialog); td::remove_if(new_dialog_filter->excluded_dialog_ids, is_changed_dialog); } else { - td::remove_if(new_dialog_filter->pinned_dialog_ids, is_changed_dialog); + bool is_removed = td::remove_if(new_dialog_filter->pinned_dialog_ids, is_changed_dialog); + CHECK(is_removed); new_dialog_filter->included_dialog_ids.push_back(get_input_dialog_id(dialog_id)); } @@ -34472,7 +34499,7 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen if (new_order == DEFAULT_ORDER) { // first addition of a new left dialog if (folder.ordered_dialogs_.insert(new_date).second) { - for (auto &dialog_list : dialog_lists_) { + for (const auto &dialog_list : dialog_lists_) { if (get_dialog_pinned_order(&dialog_list.second, d->dialog_id) != DEFAULT_ORDER) { set_dialog_is_pinned(dialog_list.first, d, false); } @@ -35129,7 +35156,7 @@ MessagesManager::get_dialog_positions(const Dialog *d) const { CHECK(d != nullptr); std::unordered_map positions; if (!td_->auth_manager_->is_bot()) { - for (auto &dialog_list : dialog_lists_) { + for (const auto &dialog_list : dialog_lists_) { positions.emplace(dialog_list.first, get_dialog_position_in_list(&dialog_list.second, d)); } } @@ -35752,7 +35779,7 @@ void MessagesManager::on_get_channel_difference( if (!td_->auth_manager_->is_bot()) { // set is_pinned only after updating dialog pos to ensure that order is initialized bool is_pinned = (dialog->flags_ & DIALOG_FLAG_IS_PINNED) != 0; - bool was_pinned = get_dialog_pinned_order(DialogListId(d->folder_id), dialog_id) != DEFAULT_ORDER; + bool was_pinned = is_dialog_pinned(DialogListId(d->folder_id), dialog_id); if (is_pinned != was_pinned) { set_dialog_is_pinned(DialogListId(d->folder_id), d, is_pinned); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 7afe60190..e2ae20c75 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1714,6 +1714,8 @@ class MessagesManager : public Actor { bool is_dialog_mention_notifications_disabled(const Dialog *d) const; + bool is_dialog_pinned(DialogListId dialog_list_id, DialogId dialog_id) const; + int64 get_dialog_pinned_order(DialogListId dialog_list_id, DialogId dialog_id) const; static int64 get_dialog_pinned_order(const DialogList *list, DialogId dialog_id); From ec362f9e2b6f51fb3e5366c7f29b196e07bc0434 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 9 May 2021 01:00:02 +0300 Subject: [PATCH 04/43] Add more logging on failed CHECK. --- td/telegram/GroupCallManager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index f62f04c79..ce4a78ba9 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -1951,7 +1951,11 @@ void GroupCallManager::process_group_call_participants( for (auto &participant : participants_it->second->participants) { auto real_order = get_real_participant_order(can_self_unmute, participant, participants_it->second.get()); if (old_min_order > real_order && real_order >= min_order) { - CHECK(!participant.order.is_valid() || participant.is_self); + LOG_CHECK(!participant.order.is_valid() || participant.is_self) + << participant << ' ' << old_min_order << ' ' << real_order << ' ' << min_order << ' ' + << participant.joined_date << ' ' << participant.active_date << ' ' << participant.raise_hand_rating + << ' ' << participant.local_active_date << ' ' << G()->unix_time() << ' ' << can_self_unmute << ' ' + << participants_it->second->joined_date_asc; participant.order = real_order; send_update_group_call_participant(input_group_call_id, participant, "process_group_call_participants load"); From 25a6cb07bc86b671760d94fb123cbed1d1a312ee Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 9 May 2021 02:53:15 +0300 Subject: [PATCH 05/43] Add more checks. --- td/telegram/ContactsManager.cpp | 9 +++++++-- td/telegram/ContactsManager.h | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index a1299992d..60ec842e7 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -8592,6 +8592,7 @@ void ContactsManager::save_chat_to_database(Chat *c, ChatId chat_id) { void ContactsManager::save_chat_to_database_impl(Chat *c, ChatId chat_id, string value) { CHECK(c != nullptr); CHECK(load_chat_from_database_queries_.count(chat_id) == 0); + CHECK(!c->is_being_saved); c->is_being_saved = true; c->is_saved = true; LOG(INFO) << "Trying to save to database " << chat_id; @@ -8828,6 +8829,7 @@ void ContactsManager::save_channel_to_database(Channel *c, ChannelId channel_id) void ContactsManager::save_channel_to_database_impl(Channel *c, ChannelId channel_id, string value) { CHECK(c != nullptr); CHECK(load_channel_from_database_queries_.count(channel_id) == 0); + CHECK(!c->is_being_saved); c->is_being_saved = true; c->is_saved = true; LOG(INFO) << "Trying to save to database " << channel_id; @@ -8936,10 +8938,12 @@ void ContactsManager::on_load_channel_from_database(ChannelId channel_id, string temp_c.status.update_restrictions(); if (temp_c.status != c->status) { on_channel_status_changed(c, channel_id, temp_c.status, c->status); + CHECK(!c->is_being_saved); } if (temp_c.username != c->username) { on_channel_username_changed(c, channel_id, temp_c.username, c->username); + CHECK(!c->is_being_saved); } } auto new_value = get_channel_database_value(c); @@ -9078,6 +9082,7 @@ void ContactsManager::save_secret_chat_to_database(SecretChat *c, SecretChatId s void ContactsManager::save_secret_chat_to_database_impl(SecretChat *c, SecretChatId secret_chat_id, string value) { CHECK(c != nullptr); CHECK(load_secret_chat_from_database_queries_.count(secret_chat_id) == 0); + CHECK(!c->is_being_saved); c->is_being_saved = true; c->is_saved = true; LOG(INFO) << "Trying to save to database " << secret_chat_id; @@ -13024,7 +13029,7 @@ void ContactsManager::on_update_channel_status(Channel *c, ChannelId channel_id, } } -void ContactsManager::on_channel_status_changed(Channel *c, ChannelId channel_id, +void ContactsManager::on_channel_status_changed(const Channel *c, ChannelId channel_id, const DialogParticipantStatus &old_status, const DialogParticipantStatus &new_status) { CHECK(c->is_update_supergroup_sent); @@ -13104,7 +13109,7 @@ void ContactsManager::on_update_channel_username(Channel *c, ChannelId channel_i } } -void ContactsManager::on_channel_username_changed(Channel *c, ChannelId channel_id, const string &old_username, +void ContactsManager::on_channel_username_changed(const Channel *c, ChannelId channel_id, const string &old_username, const string &new_username) { if (old_username.empty() || new_username.empty()) { // moving channel from private to public can change availability of chat members diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index ba59d8986..29dce536e 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1244,9 +1244,9 @@ class ContactsManager : public Actor { void on_update_channel_full_bot_user_ids(ChannelFull *channel_full, ChannelId channel_id, vector &&bot_user_ids); - void on_channel_status_changed(Channel *c, ChannelId channel_id, const DialogParticipantStatus &old_status, + void on_channel_status_changed(const Channel *c, ChannelId channel_id, const DialogParticipantStatus &old_status, const DialogParticipantStatus &new_status); - void on_channel_username_changed(Channel *c, ChannelId channel_id, const string &old_username, + void on_channel_username_changed(const Channel *c, ChannelId channel_id, const string &old_username, const string &new_username); void remove_linked_channel_id(ChannelId channel_id); From 4a13e791bbddd485fabd9c08bdc8f0e04631342f Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 9 May 2021 03:21:18 +0300 Subject: [PATCH 06/43] Don't load ChannelFull from database in invalidate_channel_full. --- td/telegram/ContactsManager.cpp | 33 ++++++++++++++++++++++++--------- td/telegram/ContactsManager.h | 3 +++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 60ec842e7..62d8649ed 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -9622,6 +9622,10 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s } } + if (invalidated_channels_full_.erase(channel_id) > 0) { + do_invalidate_channel_full(channel_full, !c->is_slow_mode_enabled); + } + td_->group_call_manager_->on_update_dialog_about(DialogId(channel_id), channel_full->description, false); send_closure_later(G()->messages_manager(), &MessagesManager::on_dialog_bots_updated, DialogId(channel_id), @@ -10451,6 +10455,8 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c return promise.set_value(Unit()); } + invalidated_channels_full_.erase(channel_id); + if (!G()->close_flag()) { auto channel_full = get_channel_full(channel_id, "on_get_channel_full"); if (channel_full != nullptr) { @@ -12035,17 +12041,26 @@ void ContactsManager::drop_channel_photos(ChannelId channel_id, bool is_empty, b void ContactsManager::invalidate_channel_full(ChannelId channel_id, bool need_drop_slow_mode_delay) { LOG(INFO) << "Invalidate supergroup full for " << channel_id; - // drop channel full cache - auto channel_full = get_channel_full_force(channel_id, "invalidate_channel_full"); + auto channel_full = get_channel_full(channel_id, "invalidate_channel_full"); // must not load ChannelFull if (channel_full != nullptr) { - channel_full->expires_at = 0.0; - if (need_drop_slow_mode_delay && channel_full->slow_mode_delay != 0) { - channel_full->slow_mode_delay = 0; - channel_full->slow_mode_next_send_date = 0; - channel_full->is_slow_mode_next_send_date_changed = true; - channel_full->is_changed = true; - } + do_invalidate_channel_full(channel_full, need_drop_slow_mode_delay); update_channel_full(channel_full, channel_id); + } else { + invalidated_channels_full_.insert(channel_id); + } +} + +void ContactsManager::do_invalidate_channel_full(ChannelFull *channel_full, bool need_drop_slow_mode_delay) { + CHECK(channel_full != nullptr); + if (channel_full->expires_at >= Time::now()) { + channel_full->expires_at = 0.0; + channel_full->need_save_to_database = true; + } + if (need_drop_slow_mode_delay && channel_full->slow_mode_delay != 0) { + channel_full->slow_mode_delay = 0; + channel_full->slow_mode_next_send_date = 0; + channel_full->is_slow_mode_next_send_date_changed = true; + channel_full->is_changed = true; } } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 29dce536e..1fcf94df7 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1264,6 +1264,8 @@ class ContactsManager : public Actor { void drop_channel_photos(ChannelId channel_id, bool is_empty, bool drop_channel_full_photo, const char *source); + void do_invalidate_channel_full(ChannelFull *channel_full, bool need_drop_slow_mode_delay); + void update_user_online_member_count(User *u); void update_chat_online_member_count(const ChatFull *chat_full, ChatId chat_id, bool is_from_server); void update_channel_online_member_count(ChannelId channel_id, bool is_from_server); @@ -1589,6 +1591,7 @@ class ContactsManager : public Actor { std::unordered_map, ChannelIdHash> channels_; std::unordered_map, ChannelIdHash> channels_full_; mutable std::unordered_set unknown_channels_; + std::unordered_set invalidated_channels_full_; std::unordered_map channel_full_file_source_ids_; std::unordered_map, SecretChatIdHash> secret_chats_; From c0c5e24b9bb32338c1f944774cf4b0adef042703 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 9 May 2021 03:23:45 +0300 Subject: [PATCH 07/43] Drop slow_mode_delay in saved to database ChannelFull if slow mode is disabled in the channel. --- td/telegram/ContactsManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 62d8649ed..1ca5ce5a1 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -9622,7 +9622,8 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s } } - if (invalidated_channels_full_.erase(channel_id) > 0) { + if (invalidated_channels_full_.erase(channel_id) > 0 || + (!c->is_slow_mode_enabled && channel_full->slow_mode_delay != 0)) { do_invalidate_channel_full(channel_full, !c->is_slow_mode_enabled); } @@ -12041,7 +12042,7 @@ void ContactsManager::drop_channel_photos(ChannelId channel_id, bool is_empty, b void ContactsManager::invalidate_channel_full(ChannelId channel_id, bool need_drop_slow_mode_delay) { LOG(INFO) << "Invalidate supergroup full for " << channel_id; - auto channel_full = get_channel_full(channel_id, "invalidate_channel_full"); // must not load ChannelFull + auto channel_full = get_channel_full(channel_id, "invalidate_channel_full"); // must not load ChannelFull if (channel_full != nullptr) { do_invalidate_channel_full(channel_full, need_drop_slow_mode_delay); update_channel_full(channel_full, channel_id); From 0d41ba340f2f6dfd43b5ceb72b51f7eb2ce22093 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 9 May 2021 18:09:14 +0300 Subject: [PATCH 08/43] Ensure that ChannelFull isn't loaded in on_channel_status_changed and on_channel_username_changed. --- td/telegram/ContactsManager.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 1ca5ce5a1..aea172fda 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -13049,13 +13049,14 @@ void ContactsManager::on_channel_status_changed(const Channel *c, ChannelId chan const DialogParticipantStatus &old_status, const DialogParticipantStatus &new_status) { CHECK(c->is_update_supergroup_sent); + bool have_channel_full = get_channel_full(channel_id) != nullptr; bool need_reload_group_call = old_status.can_manage_calls() != new_status.can_manage_calls(); if (old_status.can_manage_invite_links() && !new_status.can_manage_invite_links()) { - auto channel_full = get_channel_full_force(channel_id, "on_channel_status_changed"); - if (channel_full != nullptr) { + auto channel_full = get_channel_full(channel_id, "on_channel_status_changed"); + if (channel_full != nullptr) { // otherwise invite_link will be dropped when the channel is loaded on_update_channel_full_invite_link(channel_full, nullptr); - invalidate_channel_full(channel_id, !c->is_slow_mode_enabled); + do_invalidate_channel_full(channel_full, !c->is_slow_mode_enabled); update_channel_full(channel_full, channel_id); } } else { @@ -13084,6 +13085,9 @@ void ContactsManager::on_channel_status_changed(const Channel *c, ChannelId chan send_closure_later(G()->messages_manager(), &MessagesManager::on_update_dialog_group_call_rights, DialogId(channel_id)); } + + // must not load ChannelFull, because must not change the Channel + CHECK(have_channel_full == (get_channel_full(channel_id) != nullptr)); } void ContactsManager::on_update_channel_default_permissions(Channel *c, ChannelId channel_id, @@ -13127,10 +13131,14 @@ void ContactsManager::on_update_channel_username(Channel *c, ChannelId channel_i void ContactsManager::on_channel_username_changed(const Channel *c, ChannelId channel_id, const string &old_username, const string &new_username) { + bool have_channel_full = get_channel_full(channel_id) != nullptr; if (old_username.empty() || new_username.empty()) { // moving channel from private to public can change availability of chat members invalidate_channel_full(channel_id, !c->is_slow_mode_enabled); } + + // must not load ChannelFull, because must not change the Channel + CHECK(have_channel_full == (get_channel_full(channel_id) != nullptr)); } void ContactsManager::on_update_channel_description(ChannelId channel_id, string &&description) { From 9176381cffea875250077b8721111b892aa3f60f Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 9 May 2021 18:43:11 +0300 Subject: [PATCH 09/43] Add debug for failed CHECK. --- td/telegram/MessagesManager.cpp | 14 ++++++-------- td/telegram/MessagesManager.h | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index e6928ba2a..5c3cdb9ba 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -33606,7 +33606,9 @@ MessagesManager::Dialog *MessagesManager::get_dialog_by_message_id(MessageId mes r_value.ok().second, false, "get_dialog_by_message_id"); if (m != nullptr) { CHECK(m->message_id == message_id); - CHECK(message_id_to_dialog_id_[message_id] == dialog_id); + LOG_CHECK(message_id_to_dialog_id_[message_id] == dialog_id) + << message_id << ' ' << dialog_id << ' ' << message_id_to_dialog_id_[message_id] << ' ' + << m->debug_source; Dialog *d = get_dialog(dialog_id); CHECK(d != nullptr); return d; @@ -34183,13 +34185,9 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr &&last_datab << ", max_notification_message_id = " << d->max_notification_message_id; if (d->messages != nullptr) { - auto get_debug_source = [](const unique_ptr &message) { - return message->debug_source != nullptr ? message->debug_source : "null"; - }; - LOG_CHECK(d->messages->message_id == last_message_id) - << d->messages->message_id << ' ' << last_message_id << ' ' << get_debug_source(d->messages); - LOG_CHECK(d->messages->left == nullptr) << get_debug_source(d->messages->left); - LOG_CHECK(d->messages->right == nullptr) << get_debug_source(d->messages->right); + CHECK(d->messages->message_id == last_message_id); + CHECK(d->messages->left == nullptr); + CHECK(d->messages->right == nullptr); } // must be after update_dialog_pos, because uses d->order diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index e2ae20c75..69c327b62 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1101,7 +1101,7 @@ class MessagesManager : public Actor { int32 last_edit_pts = 0; - const char *debug_source = nullptr; + const char *debug_source = "null"; unique_ptr left; unique_ptr right; From 260eee8bff62ddf05b62455188039b801bb153c0 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 10 May 2021 01:59:35 +0300 Subject: [PATCH 10/43] Avoid upgrade of read transaction to a write transaction. --- td/telegram/MessagesManager.cpp | 14 ++++++++------ td/telegram/StickersManager.cpp | 5 +++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 5c3cdb9ba..750f33ba9 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -27108,8 +27108,9 @@ MessagesManager::MessageNotificationGroup MessagesManager::get_message_notificat d = get_dialog(it->second); CHECK(d != nullptr); } else if (G()->parameters().use_message_db) { - G()->td_db()->get_dialog_db_sync()->begin_transaction().ensure(); - auto r_value = G()->td_db()->get_dialog_db_sync()->get_notification_group(group_id); + auto *dialog_db = G()->td_db()->get_dialog_db_sync(); + dialog_db->begin_transaction().ensure(); // read transaction + auto r_value = dialog_db->get_notification_group(group_id); if (r_value.is_ok()) { VLOG(notifications) << "Loaded " << r_value.ok() << " from database by " << group_id; d = get_dialog_force(r_value.ok().dialog_id, "get_message_notification_group_force"); @@ -27117,7 +27118,7 @@ MessagesManager::MessageNotificationGroup MessagesManager::get_message_notificat CHECK(r_value.error().message() == "Not found"); VLOG(notifications) << "Failed to load " << group_id << " from database"; } - G()->td_db()->get_dialog_db_sync()->commit_transaction().ensure(); + dialog_db->commit_transaction().ensure(); } if (d == nullptr) { @@ -27403,9 +27404,10 @@ vector MessagesManager::get_message_notification_group_key VLOG(notifications) << "Trying to load " << limit << " message notification groups from database from " << from_group_key; - G()->td_db()->get_dialog_db_sync()->begin_transaction().ensure(); + auto *dialog_db = G()->td_db()->get_dialog_db_sync(); + dialog_db->begin_transaction().ensure(); // read transaction Result> r_notification_group_keys = - G()->td_db()->get_dialog_db_sync()->get_notification_groups_by_last_notification_date(from_group_key, limit); + dialog_db->get_notification_groups_by_last_notification_date(from_group_key, limit); r_notification_group_keys.ensure(); auto group_keys = r_notification_group_keys.move_as_ok(); @@ -27424,7 +27426,7 @@ vector MessagesManager::get_message_notification_group_key VLOG(notifications) << "Loaded " << group_key << " from database"; result.push_back(group_key); } - G()->td_db()->get_dialog_db_sync()->commit_transaction().ensure(); + dialog_db->commit_transaction().ensure(); return result; } diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 05151d843..122323af3 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -6415,6 +6415,9 @@ void StickersManager::on_get_emoji_keywords_difference( version = keywords->version_; auto *pmc = G()->td_db()->get_sqlite_sync_pmc(); pmc->begin_transaction().ensure(); + // set must be the first operation to start a write transaction + pmc->set(get_emoji_language_code_version_database_key(language_code), to_string(version)); + pmc->set(get_emoji_language_code_last_difference_time_database_key(language_code), to_string(G()->unix_time())); for (auto &keyword_ptr : keywords->keywords_) { switch (keyword_ptr->get_id()) { case telegram_api::emojiKeyword::ID: { @@ -6467,8 +6470,6 @@ void StickersManager::on_get_emoji_keywords_difference( UNREACHABLE(); } } - pmc->set(get_emoji_language_code_version_database_key(language_code), to_string(version)); - pmc->set(get_emoji_language_code_last_difference_time_database_key(language_code), to_string(G()->unix_time())); pmc->commit_transaction().ensure(); emoji_language_code_versions_[language_code] = version; emoji_language_code_last_difference_times_[language_code] = static_cast(Time::now_cached()); From eecb0476b516840e533b2a65139f9348b118cace Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 10 May 2021 19:36:18 +0300 Subject: [PATCH 11/43] Unify error messages for private and secret chats. --- td/telegram/MessagesManager.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 750f33ba9..d437738d1 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -28938,14 +28938,13 @@ void MessagesManager::on_send_message_fail(int64 random_id, Status error) { if (td_->auth_manager_->is_bot()) { switch (dialog_id.get_type()) { case DialogType::User: + case DialogType::SecretChat: error_message = "Bot was blocked by the user"; break; case DialogType::Chat: case DialogType::Channel: error_message = "Bot was kicked from the chat"; break; - case DialogType::SecretChat: - break; case DialogType::None: default: UNREACHABLE(); @@ -28953,14 +28952,13 @@ void MessagesManager::on_send_message_fail(int64 random_id, Status error) { } else { switch (dialog_id.get_type()) { case DialogType::User: + case DialogType::SecretChat: error_message = "User was blocked by the other user"; break; case DialogType::Chat: case DialogType::Channel: error_message = "User is not in the chat"; break; - case DialogType::SecretChat: - break; case DialogType::None: default: UNREACHABLE(); @@ -28968,7 +28966,8 @@ void MessagesManager::on_send_message_fail(int64 random_id, Status error) { } // TODO add check to send_message } else if (error.message() == "USER_IS_BOT") { - if (td_->auth_manager_->is_bot() && dialog_id.get_type() == DialogType::User) { + if (td_->auth_manager_->is_bot() && + (dialog_id.get_type() == DialogType::User || dialog_id.get_type() == DialogType::SecretChat)) { error_code = 403; if (td_->contacts_manager_->is_user_bot(dialog_id.get_user_id())) { error_message = "Bot can't send messages to bots"; @@ -28979,7 +28978,8 @@ void MessagesManager::on_send_message_fail(int64 random_id, Status error) { } } else if (error.message() == "PEER_ID_INVALID") { error_code = 403; - if (td_->auth_manager_->is_bot()) { + if (td_->auth_manager_->is_bot() && + (dialog_id.get_type() == DialogType::User || dialog_id.get_type() == DialogType::SecretChat)) { error_message = "Bot can't initiate conversation with a user"; } } else if (error.message() == "WC_CONVERT_URL_INVALID" || error.message() == "EXTERNAL_URL_INVALID") { From 32fe6456e6f17e41c1fd630a6e6dfdc53a0dfd11 Mon Sep 17 00:00:00 2001 From: Fela Ameghino Date: Mon, 10 May 2021 22:41:32 +0200 Subject: [PATCH 12/43] Use RelWithDebInfo for UWP package (#1467) * Added -release_only flag for RelWithDebInfo --- example/uwp/build.ps1 | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/example/uwp/build.ps1 b/example/uwp/build.ps1 index 0d84bfc87..683fa8afe 100644 --- a/example/uwp/build.ps1 +++ b/example/uwp/build.ps1 @@ -2,7 +2,8 @@ param ( [string]$vcpkg_root = $(throw "-vcpkg_root= is required"), [string]$arch = "", [string]$mode = "all", - [string]$compress = "7z" + [string]$compress = "7z", + [switch]$release_only = $false ) $ErrorActionPreference = "Stop" @@ -69,13 +70,27 @@ function build { ForEach($arch in $arch_list) { echo "Build Arch = [$arch]" cd $arch - cmake --build . --config Release --target tddotnet - cmake --build . --config Debug --target tddotnet + if ($release_only) { + cmake --build . --config RelWithDebInfo --target tddotnet + } else { + cmake --build . --config Release --target tddotnet + cmake --build . --config Debug --target tddotnet + } cd .. } cd .. } +function export-architecture($arch, $config, $target) { + New-Item -ItemType Directory -Force -Path vsix/DesignTime/${target}/${arch} + New-Item -ItemType Directory -Force -Path vsix/Redist/${target}/${arch} + New-Item -ItemType Directory -Force -Path vsix/References/${target}/${arch} + + cp ${arch}/${config}/* -include "SSLEAY*","LIBEAY*","libcrypto*","libssl*","zlib*" vsix/Redist/${target}/${arch}/ + cp ${arch}/${config}/* -filter "Telegram.Td.*" -include "*.lib" vsix/DesignTime/${target}/${arch}/ + cp ${arch}/${config}/* -filter "Telegram.Td.*" -include "*.pdb","*.dll" vsix/Redist/${target}/${arch}/ +} + function export { cd build-uwp Remove-Item vsix -Force -Recurse -ErrorAction SilentlyContinue @@ -86,22 +101,16 @@ function export { cp ../LICENSE_1_0.txt vsix ForEach($arch in $arch_list) { - New-Item -ItemType Directory -Force -Path vsix/DesignTime/Debug/${arch} - New-Item -ItemType Directory -Force -Path vsix/DesignTime/Retail/${arch} - New-Item -ItemType Directory -Force -Path vsix/Redist/Debug/${arch} - New-Item -ItemType Directory -Force -Path vsix/Redist/Retail/${arch} - New-Item -ItemType Directory -Force -Path vsix/References/CommonConfiguration/${arch} - - cp ${arch}/Debug/* -include "SSLEAY*","LIBEAY*","libcrypto*","libssl*","zlib*" vsix/Redist/Debug/${arch}/ - cp ${arch}/Release/* -include "SSLEAY*","LIBEAY*","libcrypto*","libssl*","zlib*" vsix/Redist/Retail/${arch}/ - - cp ${arch}/Debug/* -filter "Telegram.Td.*" -include "*.lib" vsix/DesignTime/Debug/${arch}/ - cp ${arch}/Release/* -filter "Telegram.Td.*" -include "*.lib" vsix/DesignTime/Retail/${arch}/ - - cp ${arch}/Debug/* -filter "Telegram.Td.*" -include "*.pdb","*.dll" vsix/Redist/Debug/${arch}/ - cp ${arch}/Release/* -filter "Telegram.Td.*" -include "*.pdb","*.dll" vsix/Redist/Retail/${arch}/ - - cp ${arch}/Release/* -filter "Telegram.Td.*" -include "*.pri","*.winmd","*.xml" vsix/References/CommonConfiguration/${arch}/ + if ($release_only) { + New-Item -ItemType Directory -Force -Path vsix/References/CommonConfiguration/${arch} + export-architecture -arch $arch -config "RelWithDebInfo" -target "CommonConfiguration" + cp ${arch}/RelWithDebInfo/* -filter "Telegram.Td.*" -include "*.pri","*.winmd","*.xml" vsix/References/CommonConfiguration/${arch}/ + } else { + New-Item -ItemType Directory -Force -Path vsix/References/CommonConfiguration/${arch} + export-architecture -arch $arch -config "Debug" -target "Debug" + export-architecture -arch $arch -config "Release" -target "Retail" + cp ${arch}/Release/* -filter "Telegram.Td.*" -include "*.pri","*.winmd","*.xml" vsix/References/CommonConfiguration/${arch}/ + } } cd vsix From 445183e52c8d82d8f5b5506d43fdabcb0dcb5356 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 11 May 2021 03:24:47 +0300 Subject: [PATCH 13/43] Simplify UWP build script. --- example/uwp/build.ps1 | 48 +++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/example/uwp/build.ps1 b/example/uwp/build.ps1 index 683fa8afe..a61998d12 100644 --- a/example/uwp/build.ps1 +++ b/example/uwp/build.ps1 @@ -14,6 +14,11 @@ $arch_list = @( "x86", "x64", "ARM" ) if ($arch) { $arch_list = @(, $arch) } +$config_list = @( "Debug", "Release" ) +if ($release_only) { + $config_list = @(, "RelWithDebInfo") +} +$targets = @{ Debug = "Debug"; Release = "Retail"; RelWithDebInfo = "CommonConfiguration"} $td_root = Resolve-Path "../.." @@ -48,7 +53,7 @@ function config { New-Item -ItemType Directory -Force -Path build-uwp cd build-uwp - ForEach($arch in $arch_list) { + ForEach ($arch in $arch_list) { echo "Config Arch = [$arch]" New-Item -ItemType Directory -Force -Path $arch cd $arch @@ -67,30 +72,17 @@ function config { function build { cd build-uwp - ForEach($arch in $arch_list) { + ForEach ($arch in $arch_list) { echo "Build Arch = [$arch]" cd $arch - if ($release_only) { - cmake --build . --config RelWithDebInfo --target tddotnet - } else { - cmake --build . --config Release --target tddotnet - cmake --build . --config Debug --target tddotnet + ForEach ($config in $config_list) { + cmake --build . --config $config --target tddotnet } cd .. } cd .. } -function export-architecture($arch, $config, $target) { - New-Item -ItemType Directory -Force -Path vsix/DesignTime/${target}/${arch} - New-Item -ItemType Directory -Force -Path vsix/Redist/${target}/${arch} - New-Item -ItemType Directory -Force -Path vsix/References/${target}/${arch} - - cp ${arch}/${config}/* -include "SSLEAY*","LIBEAY*","libcrypto*","libssl*","zlib*" vsix/Redist/${target}/${arch}/ - cp ${arch}/${config}/* -filter "Telegram.Td.*" -include "*.lib" vsix/DesignTime/${target}/${arch}/ - cp ${arch}/${config}/* -filter "Telegram.Td.*" -include "*.pdb","*.dll" vsix/Redist/${target}/${arch}/ -} - function export { cd build-uwp Remove-Item vsix -Force -Recurse -ErrorAction SilentlyContinue @@ -100,16 +92,18 @@ function export { cp '../`[Content_Types`].xml' vsix cp ../LICENSE_1_0.txt vsix - ForEach($arch in $arch_list) { - if ($release_only) { - New-Item -ItemType Directory -Force -Path vsix/References/CommonConfiguration/${arch} - export-architecture -arch $arch -config "RelWithDebInfo" -target "CommonConfiguration" - cp ${arch}/RelWithDebInfo/* -filter "Telegram.Td.*" -include "*.pri","*.winmd","*.xml" vsix/References/CommonConfiguration/${arch}/ - } else { - New-Item -ItemType Directory -Force -Path vsix/References/CommonConfiguration/${arch} - export-architecture -arch $arch -config "Debug" -target "Debug" - export-architecture -arch $arch -config "Release" -target "Retail" - cp ${arch}/Release/* -filter "Telegram.Td.*" -include "*.pri","*.winmd","*.xml" vsix/References/CommonConfiguration/${arch}/ + ForEach ($arch in $arch_list) { + New-Item -ItemType Directory -Force -Path vsix/References/CommonConfiguration/${arch} + ForEach ($config in $config_list) { + $target = $targets[$config] + + New-Item -ItemType Directory -Force -Path vsix/DesignTime/${target}/${arch} + cp ${arch}/${config}/Telegram.Td.lib vsix/DesignTime/${target}/${arch}/ + + New-Item -ItemType Directory -Force -Path vsix/Redist/${target}/${arch} + cp ${arch}/${config}/* -include "SSLEAY*","LIBEAY*","libcrypto*","libssl*","zlib*","Telegram.Td.pdb","Telegram.Td.dll" vsix/Redist/${target}/${arch}/ + + cp ${arch}/${config}/* -include "Telegram.Td.pri","Telegram.Td.winmd","Telegram.Td.xml" vsix/References/CommonConfiguration/${arch}/ } } From 083d599c41a8ee5c5392dac784a11ccf67b21f34 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 11 May 2021 19:26:35 +0300 Subject: [PATCH 14/43] Support stacktrace printing on Windows. --- tdutils/td/utils/port/stacktrace.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tdutils/td/utils/port/stacktrace.cpp b/tdutils/td/utils/port/stacktrace.cpp index 400eadb8d..9b841a6b6 100644 --- a/tdutils/td/utils/port/stacktrace.cpp +++ b/tdutils/td/utils/port/stacktrace.cpp @@ -27,13 +27,24 @@ namespace td { namespace { void print_backtrace(void) { -#if __GLIBC__ void *buffer[128]; +#if TD_PORT_WINDOWS + USHORT nptrs = CaptureStackBackTrace(0, 128, buffer, nullptr); +#elif __GLIBC__ int nptrs = backtrace(buffer, 128); - signal_safe_write("------- Stack Backtrace -------\n", false); - backtrace_symbols_fd(buffer, nptrs, 2); - signal_safe_write("-------------------------------\n", false); +#else + return; #endif + + signal_safe_write("------- Stack Backtrace -------\n", false); +#if TD_PORT_WINDOWS + for (USHORT i = 0; i < nptrs; i++) { + signal_safe_write_pointer(buffer[i], false); + } +#elif __GLIBC__ + backtrace_symbols_fd(buffer, nptrs, 2); +#endif + signal_safe_write("-------------------------------\n", false); } void print_backtrace_gdb(void) { From add28462a02bdd02bff3c36d1b7b796941a785c3 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 14 May 2021 13:18:52 +0300 Subject: [PATCH 15/43] Fix Slice underflow. --- td/telegram/MessageEntity.cpp | 2 +- test/message_entities.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 630e75332..9ea1be0d0 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -628,7 +628,7 @@ static vector match_urls(Slice str) { } path_end_ptr = next_ptr; } - while (bad_path_end_chars.find(path_end_ptr[-1]) < bad_path_end_chars.size()) { + while (path_end_ptr > url_end_ptr + 1 && bad_path_end_chars.find(path_end_ptr[-1]) < bad_path_end_chars.size()) { path_end_ptr--; } if (url_end_ptr[0] == '/' || path_end_ptr > url_end_ptr + 1) { diff --git a/test/message_entities.cpp b/test/message_entities.cpp index 18d3a3f4c..e88139513 100644 --- a/test/message_entities.cpp +++ b/test/message_entities.cpp @@ -582,6 +582,7 @@ TEST(MessageEntities, url) { check_url("https://t…", {}); check_url("👉http://ab.com/cdefgh-1IJ", {"http://ab.com/cdefgh-1IJ"}); check_url("...👉http://ab.com/cdefgh-1IJ", {}); // TODO + check_url(".?", {}); } static void check_fix_formatted_text(td::string str, td::vector entities, From 8a7a3f403b04ae870fc2f7f4eb0810379ca5e02d Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 16 May 2021 02:11:37 +0300 Subject: [PATCH 16/43] Try to create secret chat dialog when receive new message in it. --- td/telegram/MessagesManager.cpp | 12 +++++++++++ td/telegram/SecretChatsManager.cpp | 34 +++++++++++++++--------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index d437738d1..9b27da934 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -13068,6 +13068,10 @@ void MessagesManager::on_get_secret_message(SecretChatId secret_chat_id, UserId message_info.ttl = message->ttl_; Dialog *d = get_dialog_force(message_info.dialog_id, "on_get_secret_message"); + if (d == nullptr && have_dialog_info_force(message_info.dialog_id)) { + force_create_dialog(message_info.dialog_id, "on_get_secret_message", true, true); + d = get_dialog(message_info.dialog_id); + } if (d == nullptr) { LOG(ERROR) << "Ignore secret message in unknown " << message_info.dialog_id; pending_secret_message->success_promise.set_error(Status::Error(500, "Chat not found")); @@ -13158,6 +13162,10 @@ void MessagesManager::on_secret_chat_screenshot_taken(SecretChatId secret_chat_i message_info.content = create_screenshot_taken_message_content(); Dialog *d = get_dialog_force(message_info.dialog_id, "on_secret_chat_screenshot_taken"); + if (d == nullptr && have_dialog_info_force(message_info.dialog_id)) { + force_create_dialog(message_info.dialog_id, "on_get_secret_message", true, true); + d = get_dialog(message_info.dialog_id); + } if (d == nullptr) { LOG(ERROR) << "Ignore secret message in unknown " << message_info.dialog_id; pending_secret_message->success_promise.set_error(Status::Error(500, "Chat not found")); @@ -13192,6 +13200,10 @@ void MessagesManager::on_secret_chat_ttl_changed(SecretChatId secret_chat_id, Us message_info.content = create_chat_set_ttl_message_content(ttl); Dialog *d = get_dialog_force(message_info.dialog_id, "on_secret_chat_ttl_changed"); + if (d == nullptr && have_dialog_info_force(message_info.dialog_id)) { + force_create_dialog(message_info.dialog_id, "on_get_secret_message", true, true); + d = get_dialog(message_info.dialog_id); + } if (d == nullptr) { LOG(ERROR) << "Ignore secret message in unknown " << message_info.dialog_id; pending_secret_message->success_promise.set_error(Status::Error(500, "Chat not found")); diff --git a/td/telegram/SecretChatsManager.cpp b/td/telegram/SecretChatsManager.cpp index 00560d89d..70b4000a7 100644 --- a/td/telegram/SecretChatsManager.cpp +++ b/td/telegram/SecretChatsManager.cpp @@ -352,44 +352,44 @@ unique_ptr SecretChatsManager::make_secret_chat_contex void on_inbound_message(UserId user_id, MessageId message_id, int32 date, tl_object_ptr file, tl_object_ptr message, Promise<> promise) override { - send_closure(G()->messages_manager(), &MessagesManager::on_get_secret_message, secret_chat_id_, user_id, - message_id, date, std::move(file), std::move(message), std::move(promise)); + send_closure_later(G()->messages_manager(), &MessagesManager::on_get_secret_message, secret_chat_id_, user_id, + message_id, date, std::move(file), std::move(message), std::move(promise)); } void on_send_message_error(int64 random_id, Status error, Promise<> promise) override { - send_closure(G()->messages_manager(), &MessagesManager::on_send_secret_message_error, random_id, std::move(error), - std::move(promise)); + send_closure_later(G()->messages_manager(), &MessagesManager::on_send_secret_message_error, random_id, + std::move(error), std::move(promise)); } void on_send_message_ack(int64 random_id) override { - send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); + send_closure_later(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); } void on_send_message_ok(int64 random_id, MessageId message_id, int32 date, tl_object_ptr file, Promise<> promise) override { - send_closure(G()->messages_manager(), &MessagesManager::on_send_secret_message_success, random_id, message_id, - date, std::move(file), std::move(promise)); + send_closure_later(G()->messages_manager(), &MessagesManager::on_send_secret_message_success, random_id, + message_id, date, std::move(file), std::move(promise)); } void on_delete_messages(std::vector random_ids, Promise<> promise) override { - send_closure(G()->messages_manager(), &MessagesManager::delete_secret_messages, secret_chat_id_, - std::move(random_ids), std::move(promise)); + send_closure_later(G()->messages_manager(), &MessagesManager::delete_secret_messages, secret_chat_id_, + std::move(random_ids), std::move(promise)); } void on_flush_history(bool remove_from_dialog_list, MessageId message_id, Promise<> promise) override { - send_closure(G()->messages_manager(), &MessagesManager::delete_secret_chat_history, secret_chat_id_, - remove_from_dialog_list, message_id, std::move(promise)); + send_closure_later(G()->messages_manager(), &MessagesManager::delete_secret_chat_history, secret_chat_id_, + remove_from_dialog_list, message_id, std::move(promise)); } void on_read_message(int64 random_id, Promise<> promise) override { - send_closure(G()->messages_manager(), &MessagesManager::open_secret_message, secret_chat_id_, random_id, - std::move(promise)); + send_closure_later(G()->messages_manager(), &MessagesManager::open_secret_message, secret_chat_id_, random_id, + std::move(promise)); } void on_screenshot_taken(UserId user_id, MessageId message_id, int32 date, int64 random_id, Promise<> promise) override { - send_closure(G()->messages_manager(), &MessagesManager::on_secret_chat_screenshot_taken, secret_chat_id_, user_id, - message_id, date, random_id, std::move(promise)); + send_closure_later(G()->messages_manager(), &MessagesManager::on_secret_chat_screenshot_taken, secret_chat_id_, + user_id, message_id, date, random_id, std::move(promise)); } void on_set_ttl(UserId user_id, MessageId message_id, int32 date, int32 ttl, int64 random_id, Promise<> promise) override { - send_closure(G()->messages_manager(), &MessagesManager::on_secret_chat_ttl_changed, secret_chat_id_, user_id, - message_id, date, ttl, random_id, std::move(promise)); + send_closure_later(G()->messages_manager(), &MessagesManager::on_secret_chat_ttl_changed, secret_chat_id_, + user_id, message_id, date, ttl, random_id, std::move(promise)); } private: From 3798ecaef511a9011eb6b33ed94200c27bc646b3 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 00:12:52 +0300 Subject: [PATCH 17/43] Move outgoing query logging to INFO. --- td/telegram/net/NetQueryCreator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/td/telegram/net/NetQueryCreator.cpp b/td/telegram/net/NetQueryCreator.cpp index 03621e7a5..895e952e5 100644 --- a/td/telegram/net/NetQueryCreator.cpp +++ b/td/telegram/net/NetQueryCreator.cpp @@ -25,7 +25,7 @@ NetQueryPtr NetQueryCreator::create(const telegram_api::Function &function, DcId NetQueryPtr NetQueryCreator::create(uint64 id, const telegram_api::Function &function, DcId dc_id, NetQuery::Type type, NetQuery::AuthFlag auth_flag) { - LOG(DEBUG) << "Create query " << to_string(function); + LOG(INFO) << "Create query " << to_string(function); auto storer = DefaultStorer(function); BufferSlice slice(storer.size()); auto real_size = storer.store(slice.as_slice().ubegin()); From 29230948c34779e90079d24af76be651ccf5fe54 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 02:04:50 +0300 Subject: [PATCH 18/43] Remove redundant LogInterface::rotate overrides. --- td/telegram/cli.cpp | 2 -- tdutils/td/utils/MemoryLog.h | 3 --- tdutils/td/utils/logging.cpp | 2 -- tdutils/td/utils/logging.h | 2 -- 4 files changed, 9 deletions(-) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 6b84f74b6..78b0c7166 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -206,8 +206,6 @@ class CliLog : public LogInterface { default_log_interface->append(slice, log_level); } } - void rotate() override { - } }; struct SendMessageInfo { diff --git a/tdutils/td/utils/MemoryLog.h b/tdutils/td/utils/MemoryLog.h index aa36295f8..0e1e34b19 100644 --- a/tdutils/td/utils/MemoryLog.h +++ b/tdutils/td/utils/MemoryLog.h @@ -67,9 +67,6 @@ class MemoryLog : public LogInterface { } } - void rotate() override { - } - Slice get_buffer() const { return Slice(buffer_, sizeof(buffer_)); } diff --git a/tdutils/td/utils/logging.cpp b/tdutils/td/utils/logging.cpp index 7f4b14477..64bbda507 100644 --- a/tdutils/td/utils/logging.cpp +++ b/tdutils/td/utils/logging.cpp @@ -263,8 +263,6 @@ class DefaultLog : public LogInterface { process_fatal_error(slice); } } - void rotate() override { - } }; static DefaultLog default_log; diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 7a97105e2..fa26c95cf 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -187,8 +187,6 @@ class NullLog : public LogInterface { public: void append(CSlice /*slice*/, int /*log_level*/) override { } - void rotate() override { - } NullLog &ref() { return *this; } From 17a1015f6b28295d7019b276f7d09dfc7613911a Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 03:24:54 +0300 Subject: [PATCH 19/43] Remove dependency of PSLICE/PSTRING on Logger, move them to separate header and make them always safe. --- td/telegram/files/FileLoaderUtils.cpp | 18 ++++----- tdutils/CMakeLists.txt | 1 + tdutils/td/utils/SliceBuilder.h | 57 +++++++++++++++++++++++++++ tdutils/td/utils/Status.h | 23 ----------- tdutils/td/utils/logging.h | 26 +----------- 5 files changed, 69 insertions(+), 56 deletions(-) create mode 100644 tdutils/td/utils/SliceBuilder.h diff --git a/td/telegram/files/FileLoaderUtils.cpp b/td/telegram/files/FileLoaderUtils.cpp index f2af704c4..4b96bc981 100644 --- a/td/telegram/files/FileLoaderUtils.cpp +++ b/td/telegram/files/FileLoaderUtils.cpp @@ -66,9 +66,9 @@ Result> open_temp_file(FileType file_type) { pmc->set("tmp_file_id", to_string(file_id + 1)); auto temp_dir = get_files_temp_dir(file_type); - auto res = try_create_new_file(PSLICE_SAFE() << temp_dir << file_id); + auto res = try_create_new_file(PSLICE() << temp_dir << file_id); if (res.is_error()) { - res = try_create_new_file(PSLICE_SAFE() << temp_dir << file_id << "_" << RandSuff{6}); + res = try_create_new_file(PSLICE() << temp_dir << file_id << "_" << RandSuff{6}); } return res; } @@ -88,20 +88,20 @@ bool for_suggested_file_name(CSlice name, bool use_pmc, bool use_random, F &&cal auto ext = path_view.extension(); bool active = true; if (!stem.empty() && !G()->parameters().ignore_file_names) { - active = try_callback(PSLICE_SAFE() << stem << Ext{ext}); + active = try_callback(PSLICE() << stem << Ext{ext}); for (int i = 0; active && i < 10; i++) { - active = try_callback(PSLICE_SAFE() << stem << "_(" << i << ")" << Ext{ext}); + active = try_callback(PSLICE() << stem << "_(" << i << ")" << Ext{ext}); } for (int i = 2; active && i < 12 && use_random; i++) { - active = try_callback(PSLICE_SAFE() << stem << "_(" << RandSuff{i} << ")" << Ext{ext}); + active = try_callback(PSLICE() << stem << "_(" << RandSuff{i} << ")" << Ext{ext}); } } else if (use_pmc) { auto pmc = G()->td_db()->get_binlog_pmc(); int32 file_id = to_integer(pmc->get("perm_file_id")); pmc->set("perm_file_id", to_string(file_id + 1)); - active = try_callback(PSLICE_SAFE() << "file_" << file_id << Ext{ext}); + active = try_callback(PSLICE() << "file_" << file_id << Ext{ext}); if (active) { - active = try_callback(PSLICE_SAFE() << "file_" << file_id << "_" << RandSuff{6} << Ext{ext}); + active = try_callback(PSLICE() << "file_" << file_id << "_" << RandSuff{6} << Ext{ext}); } } return active; @@ -112,7 +112,7 @@ Result create_from_temp(CSlice temp_path, CSlice dir, CSlice name) { << temp_path; Result> res = Status::Error(500, "Can't find suitable file name"); for_suggested_file_name(name, true, true, [&](CSlice suggested_name) { - res = try_create_new_file(PSLICE_SAFE() << dir << suggested_name); + res = try_create_new_file(PSLICE() << dir << suggested_name); return res.is_error(); }); TRY_RESULT(tmp, std::move(res)); @@ -125,7 +125,7 @@ Result create_from_temp(CSlice temp_path, CSlice dir, CSlice name) { Result search_file(CSlice dir, CSlice name, int64 expected_size) { Result res = Status::Error(500, "Can't find suitable file name"); for_suggested_file_name(name, false, false, [&](CSlice suggested_name) { - auto r_pair = try_open_file(PSLICE_SAFE() << dir << suggested_name); + auto r_pair = try_open_file(PSLICE() << dir << suggested_name); if (r_pair.is_error()) { return false; } diff --git a/tdutils/CMakeLists.txt b/tdutils/CMakeLists.txt index 71a760b4e..f288f5d3c 100644 --- a/tdutils/CMakeLists.txt +++ b/tdutils/CMakeLists.txt @@ -235,6 +235,7 @@ set(TDUTILS_SOURCE td/utils/SharedSlice.h td/utils/Slice-decl.h td/utils/Slice.h + td/utils/SliceBuilder.h td/utils/Span.h td/utils/SpinLock.h td/utils/StackAllocator.h diff --git a/tdutils/td/utils/SliceBuilder.h b/tdutils/td/utils/SliceBuilder.h new file mode 100644 index 000000000..33b0fdf04 --- /dev/null +++ b/tdutils/td/utils/SliceBuilder.h @@ -0,0 +1,57 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 +// +// 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 + +#include "td/utils/common.h" +#include "td/utils/Slice.h" +#include "td/utils/StackAllocator.h" +#include "td/utils/StringBuilder.h" + +#define PSLICE() ::td::detail::Slicify() & ::td::SliceBuilder().ref() +#define PSTRING() ::td::detail::Stringify() & ::td::SliceBuilder().ref() + +namespace td { + +class SliceBuilder { + public: + template + SliceBuilder &operator<<(T &&other) { + sb_ << other; + return *this; + } + + MutableCSlice as_cslice() { + return sb_.as_cslice(); + } + + SliceBuilder &ref() { + return *this; + } + + private: + static const size_t DEFAULT_BUFFER_SIZE = 1024; + decltype(StackAllocator::alloc(0)) buffer_ = StackAllocator::alloc(DEFAULT_BUFFER_SIZE); + StringBuilder sb_ = StringBuilder(buffer_.as_slice(), true); +}; + +namespace detail { +class Slicify { + public: + CSlice operator&(SliceBuilder &slice_builder) { + return slice_builder.as_cslice(); + } +}; + +class Stringify { + public: + string operator&(SliceBuilder &slice_builder) { + return slice_builder.as_cslice().str(); + } +}; +} // namespace detail + +} // namespace td diff --git a/tdutils/td/utils/Status.h b/tdutils/td/utils/Status.h index 982a19188..551b9bf88 100644 --- a/tdutils/td/utils/Status.h +++ b/tdutils/td/utils/Status.h @@ -599,27 +599,4 @@ inline StringBuilder &operator<<(StringBuilder &string_builder, const Status &st return status.print(string_builder); } -namespace detail { - -class SlicifySafe { - public: - Result operator&(Logger &logger) { - if (logger.is_error()) { - return Status::Error("Buffer overflow"); - } - return logger.as_cslice(); - } -}; - -class StringifySafe { - public: - Result operator&(Logger &logger) { - if (logger.is_error()) { - return Status::Error("Buffer overflow"); - } - return logger.as_cslice().str(); - } -}; - -} // namespace detail } // namespace td diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index fa26c95cf..d078bf823 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -26,18 +26,13 @@ #include "td/utils/common.h" #include "td/utils/port/thread_local.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StackAllocator.h" #include "td/utils/StringBuilder.h" #include #include -#define PSTR_IMPL() ::td::Logger(::td::NullLog().ref(), ::td::LogOptions::plain(), 0) -#define PSLICE() ::td::detail::Slicify() & PSTR_IMPL() -#define PSTRING() ::td::detail::Stringify() & PSTR_IMPL() -#define PSLICE_SAFE() ::td::detail::SlicifySafe() & PSTR_IMPL() -#define PSTRING_SAFE() ::td::detail::StringifySafe() & PSTR_IMPL() - #define VERBOSITY_NAME(x) verbosity_##x #define GET_VERBOSITY_LEVEL() (::td::get_verbosity_level()) @@ -187,9 +182,6 @@ class NullLog : public LogInterface { public: void append(CSlice /*slice*/, int /*log_level*/) override { } - NullLog &ref() { - return *this; - } }; extern LogInterface *const default_log_interface; @@ -227,7 +219,7 @@ class TsCerr { class Logger { public: - static const int BUFFER_SIZE = 128 * 1024; + static const size_t BUFFER_SIZE = 128 * 1024; Logger(LogInterface &log, const LogOptions &options, int log_level) : buffer_(StackAllocator::alloc(BUFFER_SIZE)) , log_(log) @@ -274,20 +266,6 @@ class Voidify { void operator&(const T &) { } }; - -class Slicify { - public: - CSlice operator&(Logger &logger) { - return logger.as_cslice(); - } -}; - -class Stringify { - public: - string operator&(Logger &logger) { - return logger.as_cslice().str(); - } -}; } // namespace detail class TsLog : public LogInterface { From a6a4eb6616ba1a21e200922290012c50818ca1f9 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 15:21:11 +0300 Subject: [PATCH 20/43] Don't include SliceBuilder.h in logging.h. --- benchmark/bench_actor.cpp | 1 + benchmark/bench_crypto.cpp | 2 +- benchmark/bench_db.cpp | 1 + benchmark/bench_misc.cpp | 1 + benchmark/check_tls.cpp | 1 + td/generate/tl_json_converter.cpp | 2 +- td/generate/tl_writer_cpp.cpp | 1 + td/mtproto/AuthData.cpp | 1 + td/mtproto/Handshake.cpp | 1 + td/mtproto/HandshakeActor.cpp | 2 +- td/mtproto/HttpTransport.cpp | 1 + td/mtproto/Ping.cpp | 2 +- td/mtproto/RawConnection.cpp | 1 + td/mtproto/SessionConnection.cpp | 1 + td/mtproto/TlsInit.cpp | 2 +- td/mtproto/Transport.cpp | 1 + td/telegram/AudiosManager.cpp | 1 + td/telegram/AuthManager.hpp | 2 +- td/telegram/BackgroundManager.cpp | 1 + td/telegram/BackgroundType.cpp | 1 + td/telegram/CallActor.cpp | 1 + td/telegram/CallManager.cpp | 1 + td/telegram/ClientJson.cpp | 2 +- td/telegram/ConfigManager.cpp | 1 + td/telegram/ConfigShared.cpp | 1 + td/telegram/ContactsManager.cpp | 1 + td/telegram/DeviceTokenManager.cpp | 1 + td/telegram/DialogDb.cpp | 1 + td/telegram/DialogSource.cpp | 2 +- td/telegram/FileReferenceManager.cpp | 1 + td/telegram/GroupCallManager.cpp | 1 + td/telegram/GroupCallParticipantOrder.cpp | 2 +- td/telegram/InlineQueriesManager.cpp | 1 + td/telegram/LanguagePackManager.cpp | 1 + td/telegram/MessageContent.cpp | 1 + td/telegram/MessageEntity.cpp | 1 + td/telegram/MessagesDb.cpp | 1 + td/telegram/MessagesManager.cpp | 1 + td/telegram/NotificationManager.cpp | 1 + td/telegram/PasswordManager.cpp | 1 + td/telegram/Photo.cpp | 1 + td/telegram/PhotoSizeSource.hpp | 2 +- td/telegram/PollManager.cpp | 1 + td/telegram/ReplyMarkup.cpp | 1 + td/telegram/SecretChatActor.cpp | 1 + td/telegram/SecretChatDb.h | 2 +- td/telegram/SecretChatsManager.cpp | 1 + td/telegram/SecureManager.cpp | 1 + td/telegram/SecureStorage.cpp | 1 + td/telegram/SecureValue.cpp | 1 + td/telegram/SequenceDispatcher.cpp | 1 + td/telegram/SpecialStickerSetType.cpp | 2 +- td/telegram/StickersManager.cpp | 1 + td/telegram/Td.cpp | 1 + td/telegram/TdDb.cpp | 1 + td/telegram/TopDialogManager.cpp | 1 + td/telegram/UpdatesManager.cpp | 4 +++- td/telegram/WebPageBlock.cpp | 1 + td/telegram/WebPagesManager.cpp | 1 + td/telegram/cli.cpp | 1 + td/telegram/files/FileDb.cpp | 1 + td/telegram/files/FileDownloader.cpp | 1 + td/telegram/files/FileGenerateManager.cpp | 1 + td/telegram/files/FileLoadManager.cpp | 2 +- td/telegram/files/FileLoaderUtils.cpp | 1 + td/telegram/files/FileManager.cpp | 1 + td/telegram/files/FileManager.hpp | 1 + td/telegram/files/FileStatsWorker.cpp | 1 + td/telegram/files/PartsManager.cpp | 1 + td/telegram/logevent/LogEvent.h | 1 + td/telegram/misc.cpp | 2 +- td/telegram/net/AuthDataShared.cpp | 1 + td/telegram/net/ConnectionCreator.cpp | 1 + td/telegram/net/DcOptionsSet.cpp | 1 + td/telegram/net/NetQuery.cpp | 2 +- td/telegram/net/NetQueryDelayer.cpp | 1 + td/telegram/net/NetQueryDispatcher.cpp | 1 + td/telegram/net/NetQueryStats.cpp | 1 + td/telegram/net/NetStatsManager.cpp | 1 + td/telegram/net/PublicRsaKeyShared.cpp | 1 + td/telegram/net/Session.cpp | 1 + td/telegram/net/SessionMultiProxy.cpp | 1 + td/telegram/net/SessionProxy.cpp | 1 + td/tl/tl_jni_object.cpp | 1 + td/tl/tl_json.h | 1 + td/tl/tl_object_parse.h | 2 +- tdactor/test/actors_workers.cpp | 4 +--- tddb/td/db/SqliteDb.cpp | 1 + tddb/td/db/SqliteKeyValue.cpp | 1 + tddb/td/db/SqliteKeyValue.h | 2 +- tddb/td/db/binlog/Binlog.cpp | 1 + tddb/td/db/binlog/BinlogEvent.h | 1 + tddb/td/db/binlog/ConcurrentBinlog.cpp | 1 + tddb/td/db/binlog/binlog_dump.cpp | 1 + tddb/td/db/binlog/detail/BinlogEventsProcessor.cpp | 2 +- tddb/td/db/detail/RawSqliteDb.h | 2 +- tdnet/td/net/GetHostByNameActor.cpp | 1 + tdnet/td/net/HttpChunkedByteFlow.cpp | 2 +- tdnet/td/net/HttpHeaderCreator.h | 1 + tdnet/td/net/HttpProxy.cpp | 1 + tdnet/td/net/HttpReader.cpp | 1 + tdnet/td/net/Socks5.cpp | 1 + tdnet/td/net/SslStream.cpp | 1 + tdnet/td/net/Wget.cpp | 1 + tdutils/td/utils/BigNum.cpp | 1 + tdutils/td/utils/FileLog.cpp | 1 + tdutils/td/utils/Gzip.cpp | 2 +- tdutils/td/utils/JsonBuilder.cpp | 1 + tdutils/td/utils/OptionParser.cpp | 1 + tdutils/td/utils/Parser.h | 2 +- tdutils/td/utils/Status.h | 1 + tdutils/td/utils/TsFileLog.cpp | 1 + tdutils/td/utils/check.cpp | 1 + tdutils/td/utils/filesystem.cpp | 2 +- tdutils/td/utils/logging.h | 1 - tdutils/td/utils/misc.h | 1 + tdutils/td/utils/port/FileFd.cpp | 1 + tdutils/td/utils/port/IPAddress.cpp | 1 + tdutils/td/utils/port/MemoryMapping.cpp | 2 +- tdutils/td/utils/port/ServerSocketFd.cpp | 1 + tdutils/td/utils/port/SocketFd.cpp | 1 + tdutils/td/utils/port/Stat.cpp | 1 + tdutils/td/utils/port/StdStreams.cpp | 1 + tdutils/td/utils/port/UdpSocketFd.cpp | 1 + tdutils/td/utils/port/detail/EventFdLinux.cpp | 1 + tdutils/td/utils/port/detail/NativeFd.cpp | 1 + tdutils/td/utils/port/path.cpp | 1 + tdutils/td/utils/port/uname.cpp | 1 + tdutils/td/utils/port/user.cpp | 2 +- tdutils/td/utils/tests.cpp | 1 + tdutils/td/utils/tl_helpers.h | 2 +- tdutils/td/utils/tl_parsers.h | 1 + tdutils/td/utils/tl_storers.h | 1 + tdutils/test/StealingQueue.cpp | 1 + tdutils/test/crypto.cpp | 2 +- tdutils/test/log.cpp | 1 + tdutils/test/misc.cpp | 1 + tdutils/test/port.cpp | 1 + tdutils/test/pq.cpp | 1 + test/http.cpp | 1 + test/message_entities.cpp | 1 + test/mtproto.cpp | 1 + test/secret.cpp | 1 + test/secure_storage.cpp | 2 +- test/tdclient.cpp | 1 + test/tqueue.cpp | 1 + 146 files changed, 147 insertions(+), 33 deletions(-) diff --git a/benchmark/bench_actor.cpp b/benchmark/bench_actor.cpp index 894cbf1d2..a1bbd0c7b 100644 --- a/benchmark/bench_actor.cpp +++ b/benchmark/bench_actor.cpp @@ -13,6 +13,7 @@ #include "td/utils/common.h" #include "td/utils/crypto.h" #include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #if TD_MSVC #pragma comment(linker, "/STACK:16777216") diff --git a/benchmark/bench_crypto.cpp b/benchmark/bench_crypto.cpp index 79c00d2d4..671beba50 100644 --- a/benchmark/bench_crypto.cpp +++ b/benchmark/bench_crypto.cpp @@ -8,10 +8,10 @@ #include "td/utils/common.h" #include "td/utils/crypto.h" -#include "td/utils/logging.h" #include "td/utils/port/thread.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/UInt.h" #include diff --git a/benchmark/bench_db.cpp b/benchmark/bench_db.cpp index fa054adaf..4b39c540f 100644 --- a/benchmark/bench_db.cpp +++ b/benchmark/bench_db.cpp @@ -21,6 +21,7 @@ #include "td/utils/common.h" #include "td/utils/format.h" #include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" diff --git a/benchmark/bench_misc.cpp b/benchmark/bench_misc.cpp index b2c5b05b3..69df64cd0 100644 --- a/benchmark/bench_misc.cpp +++ b/benchmark/bench_misc.cpp @@ -15,6 +15,7 @@ #include "td/utils/port/Stat.h" #include "td/utils/port/thread.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.hpp" diff --git a/benchmark/check_tls.cpp b/benchmark/check_tls.cpp index 4e89a2b43..afc80b800 100644 --- a/benchmark/check_tls.cpp +++ b/benchmark/check_tls.cpp @@ -16,6 +16,7 @@ #include "td/utils/port/thread.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/Time.h" diff --git a/td/generate/tl_json_converter.cpp b/td/generate/tl_json_converter.cpp index 276c57859..5068dc947 100644 --- a/td/generate/tl_json_converter.cpp +++ b/td/generate/tl_json_converter.cpp @@ -11,8 +11,8 @@ #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/filesystem.h" -#include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StringBuilder.h" #include diff --git a/td/generate/tl_writer_cpp.cpp b/td/generate/tl_writer_cpp.cpp index cabb1420c..ea478ff1a 100644 --- a/td/generate/tl_writer_cpp.cpp +++ b/td/generate/tl_writer_cpp.cpp @@ -23,6 +23,7 @@ std::string TD_TL_writer_cpp::gen_output_begin() const { "#include \"td/utils/common.h\"\n" "#include \"td/utils/format.h\"\n" "#include \"td/utils/logging.h\"\n" + "#include \"td/utils/SliceBuilder.h\"\n" "#include \"td/utils/tl_parsers.h\"\n" "#include \"td/utils/tl_storers.h\"\n\n" "namespace td {\n" diff --git a/td/mtproto/AuthData.cpp b/td/mtproto/AuthData.cpp index ed08097b1..365218ad1 100644 --- a/td/mtproto/AuthData.cpp +++ b/td/mtproto/AuthData.cpp @@ -9,6 +9,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" #include diff --git a/td/mtproto/Handshake.cpp b/td/mtproto/Handshake.cpp index 73bd0f4f8..df41f1128 100644 --- a/td/mtproto/Handshake.cpp +++ b/td/mtproto/Handshake.cpp @@ -18,6 +18,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/Time.h" #include "td/utils/tl_parsers.h" diff --git a/td/mtproto/HandshakeActor.cpp b/td/mtproto/HandshakeActor.cpp index a3cf20745..861b4b787 100644 --- a/td/mtproto/HandshakeActor.cpp +++ b/td/mtproto/HandshakeActor.cpp @@ -9,7 +9,7 @@ #include "td/mtproto/HandshakeConnection.h" #include "td/utils/common.h" -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" namespace td { diff --git a/td/mtproto/HttpTransport.cpp b/td/mtproto/HttpTransport.cpp index b0b0ae90a..49fcf7300 100644 --- a/td/mtproto/HttpTransport.cpp +++ b/td/mtproto/HttpTransport.cpp @@ -13,6 +13,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" // TODO: do I need \r\n as delimiter? diff --git a/td/mtproto/Ping.cpp b/td/mtproto/Ping.cpp index b53181526..dddd7afb4 100644 --- a/td/mtproto/Ping.cpp +++ b/td/mtproto/Ping.cpp @@ -13,7 +13,7 @@ #include "td/actor/actor.h" #include "td/actor/PromiseFuture.h" -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" namespace td { diff --git a/td/mtproto/RawConnection.cpp b/td/mtproto/RawConnection.cpp index 3aa77ef81..abe243335 100644 --- a/td/mtproto/RawConnection.cpp +++ b/td/mtproto/RawConnection.cpp @@ -22,6 +22,7 @@ #include "td/utils/MpscPollableQueue.h" #include "td/utils/port/EventFd.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StorerBase.h" diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index f81c47a00..7e9409b2f 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -22,6 +22,7 @@ #include "td/utils/misc.h" #include "td/utils/Random.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" #include "td/utils/tl_parsers.h" diff --git a/td/mtproto/TlsInit.cpp b/td/mtproto/TlsInit.cpp index 99449dae4..21591de49 100644 --- a/td/mtproto/TlsInit.cpp +++ b/td/mtproto/TlsInit.cpp @@ -12,8 +12,8 @@ #include "td/utils/BigNum.h" #include "td/utils/common.h" #include "td/utils/crypto.h" -#include "td/utils/logging.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Span.h" #include "td/utils/Time.h" diff --git a/td/mtproto/Transport.cpp b/td/mtproto/Transport.cpp index 7aa616622..9d90e18a0 100644 --- a/td/mtproto/Transport.cpp +++ b/td/mtproto/Transport.cpp @@ -15,6 +15,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include diff --git a/td/telegram/AudiosManager.cpp b/td/telegram/AudiosManager.cpp index dd71aee69..5b193cbca 100644 --- a/td/telegram/AudiosManager.cpp +++ b/td/telegram/AudiosManager.cpp @@ -15,6 +15,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/AuthManager.hpp b/td/telegram/AuthManager.hpp index 901889c50..cf0afc8f8 100644 --- a/td/telegram/AuthManager.hpp +++ b/td/telegram/AuthManager.hpp @@ -12,7 +12,7 @@ #include "td/telegram/Version.h" #include "td/utils/format.h" -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tl_helpers.h" namespace td { diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index 6651944c4..09f6398d0 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -34,6 +34,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tl_helpers.h" namespace td { diff --git a/td/telegram/BackgroundType.cpp b/td/telegram/BackgroundType.cpp index 7e33e7741..276df90ac 100644 --- a/td/telegram/BackgroundType.cpp +++ b/td/telegram/BackgroundType.cpp @@ -8,6 +8,7 @@ #include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" namespace td { diff --git a/td/telegram/CallActor.cpp b/td/telegram/CallActor.cpp index 7181834c0..92066137f 100644 --- a/td/telegram/CallActor.cpp +++ b/td/telegram/CallActor.cpp @@ -30,6 +30,7 @@ #include "td/utils/crypto.h" #include "td/utils/logging.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/td/telegram/CallManager.cpp b/td/telegram/CallManager.cpp index 4687cee08..ac0975cf9 100644 --- a/td/telegram/CallManager.cpp +++ b/td/telegram/CallManager.cpp @@ -10,6 +10,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include "td/telegram/telegram_api.hpp" diff --git a/td/telegram/ClientJson.cpp b/td/telegram/ClientJson.cpp index 75451196e..2f218d030 100644 --- a/td/telegram/ClientJson.cpp +++ b/td/telegram/ClientJson.cpp @@ -11,8 +11,8 @@ #include "td/utils/common.h" #include "td/utils/JsonBuilder.h" -#include "td/utils/logging.h" #include "td/utils/port/thread_local.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StackAllocator.h" #include "td/utils/StringBuilder.h" diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index e7ab6ed53..b2d8c8485 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -53,6 +53,7 @@ #include "td/utils/Parser.h" #include "td/utils/port/Clocks.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" #include "td/utils/tl_helpers.h" #include "td/utils/tl_parsers.h" diff --git a/td/telegram/ConfigShared.cpp b/td/telegram/ConfigShared.cpp index de83dc367..da72c7a93 100644 --- a/td/telegram/ConfigShared.cpp +++ b/td/telegram/ConfigShared.cpp @@ -10,6 +10,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" namespace td { diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index aea172fda..8b596df0d 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -61,6 +61,7 @@ #include "td/utils/misc.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/DeviceTokenManager.cpp b/td/telegram/DeviceTokenManager.cpp index 758cda9c0..447b82013 100644 --- a/td/telegram/DeviceTokenManager.cpp +++ b/td/telegram/DeviceTokenManager.cpp @@ -23,6 +23,7 @@ #include "td/utils/JsonBuilder.h" #include "td/utils/logging.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/DialogDb.cpp b/td/telegram/DialogDb.cpp index 72f1dba59..604f056de 100644 --- a/td/telegram/DialogDb.cpp +++ b/td/telegram/DialogDb.cpp @@ -21,6 +21,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" namespace td { diff --git a/td/telegram/DialogSource.cpp b/td/telegram/DialogSource.cpp index 3387042de..9e45ed1af 100644 --- a/td/telegram/DialogSource.cpp +++ b/td/telegram/DialogSource.cpp @@ -6,8 +6,8 @@ // #include "td/telegram/DialogSource.h" -#include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" namespace td { diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index d02d74549..dbec96cae 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -22,6 +22,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/overloaded.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" namespace td { diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index ce4a78ba9..587354d83 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -24,6 +24,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/td/telegram/GroupCallParticipantOrder.cpp b/td/telegram/GroupCallParticipantOrder.cpp index 80a956f9a..1d1d91f34 100644 --- a/td/telegram/GroupCallParticipantOrder.cpp +++ b/td/telegram/GroupCallParticipantOrder.cpp @@ -6,8 +6,8 @@ // #include "td/telegram/GroupCallParticipantOrder.h" -#include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 2573065d8..1863f0148 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -49,6 +49,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" #include "td/utils/tl_helpers.h" #include "td/utils/tl_parsers.h" diff --git a/td/telegram/LanguagePackManager.cpp b/td/telegram/LanguagePackManager.cpp index c9b205787..67538b819 100644 --- a/td/telegram/LanguagePackManager.cpp +++ b/td/telegram/LanguagePackManager.cpp @@ -26,6 +26,7 @@ #include "td/utils/ExitGuard.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index f371806ab..b9fdb0d9e 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -81,6 +81,7 @@ #include "td/utils/misc.h" #include "td/utils/PathView.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tl_helpers.h" #include "td/utils/utf8.h" diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 9ea1be0d0..35f267bd5 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -15,6 +15,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/unicode.h" #include "td/utils/utf8.h" diff --git a/td/telegram/MessagesDb.cpp b/td/telegram/MessagesDb.cpp index ef09c26ad..796e8c929 100644 --- a/td/telegram/MessagesDb.cpp +++ b/td/telegram/MessagesDb.cpp @@ -22,6 +22,7 @@ #include "td/utils/logging.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StackAllocator.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 9b27da934..d937affc2 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -67,6 +67,7 @@ #include "td/utils/PathView.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" #include "td/utils/tl_helpers.h" #include "td/utils/utf8.h" diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 82e5ca570..9261d3baa 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -51,6 +51,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" #include "td/utils/tl_helpers.h" #include "td/utils/tl_parsers.h" diff --git a/td/telegram/PasswordManager.cpp b/td/telegram/PasswordManager.cpp index 4f218a9c6..00d1f3a4b 100644 --- a/td/telegram/PasswordManager.cpp +++ b/td/telegram/PasswordManager.cpp @@ -22,6 +22,7 @@ #include "td/utils/misc.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" namespace td { diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 4c498bae0..01de1e489 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -22,6 +22,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/td/telegram/PhotoSizeSource.hpp b/td/telegram/PhotoSizeSource.hpp index eea960989..84be3dae2 100644 --- a/td/telegram/PhotoSizeSource.hpp +++ b/td/telegram/PhotoSizeSource.hpp @@ -8,7 +8,7 @@ #include "td/telegram/PhotoSizeSource.h" -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tl_helpers.h" namespace td { diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index fd15dfb11..dc745159b 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -38,6 +38,7 @@ #include "td/utils/misc.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/ReplyMarkup.cpp b/td/telegram/ReplyMarkup.cpp index 6674432e6..d3ea8ea0a 100644 --- a/td/telegram/ReplyMarkup.cpp +++ b/td/telegram/ReplyMarkup.cpp @@ -16,6 +16,7 @@ #include "td/utils/buffer.h" #include "td/utils/format.h" #include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/td/telegram/SecretChatActor.cpp b/td/telegram/SecretChatActor.cpp index 048bc1669..d3f7ca3fb 100644 --- a/td/telegram/SecretChatActor.cpp +++ b/td/telegram/SecretChatActor.cpp @@ -33,6 +33,7 @@ #include "td/utils/overloaded.h" #include "td/utils/Random.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StorerBase.h" #include "td/utils/Time.h" #include "td/utils/tl_parsers.h" diff --git a/td/telegram/SecretChatDb.h b/td/telegram/SecretChatDb.h index 88ed49368..76c4c53de 100644 --- a/td/telegram/SecretChatDb.h +++ b/td/telegram/SecretChatDb.h @@ -8,7 +8,7 @@ #include "td/db/KeyValueSyncInterface.h" -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/SecretChatsManager.cpp b/td/telegram/SecretChatsManager.cpp index 70b4000a7..38e28d69c 100644 --- a/td/telegram/SecretChatsManager.cpp +++ b/td/telegram/SecretChatsManager.cpp @@ -34,6 +34,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/Time.h" diff --git a/td/telegram/SecureManager.cpp b/td/telegram/SecureManager.cpp index 79b196fdb..f5478dd06 100644 --- a/td/telegram/SecureManager.cpp +++ b/td/telegram/SecureManager.cpp @@ -23,6 +23,7 @@ #include "td/utils/misc.h" #include "td/utils/optional.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/td/telegram/SecureStorage.cpp b/td/telegram/SecureStorage.cpp index a1204f283..7c7866f05 100644 --- a/td/telegram/SecureStorage.cpp +++ b/td/telegram/SecureStorage.cpp @@ -13,6 +13,7 @@ #include "td/utils/port/FileFd.h" #include "td/utils/Random.h" #include "td/utils/SharedSlice.h" +#include "td/utils/SliceBuilder.h" namespace td { namespace secure_storage { diff --git a/td/telegram/SecureValue.cpp b/td/telegram/SecureValue.cpp index 09376b4fd..18ca1e6f6 100644 --- a/td/telegram/SecureValue.cpp +++ b/td/telegram/SecureValue.cpp @@ -28,6 +28,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/overloaded.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/utf8.h" #include diff --git a/td/telegram/SequenceDispatcher.cpp b/td/telegram/SequenceDispatcher.cpp index e117fd9bf..872805990 100644 --- a/td/telegram/SequenceDispatcher.cpp +++ b/td/telegram/SequenceDispatcher.cpp @@ -14,6 +14,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include diff --git a/td/telegram/SpecialStickerSetType.cpp b/td/telegram/SpecialStickerSetType.cpp index 453db01a3..b43e15501 100644 --- a/td/telegram/SpecialStickerSetType.cpp +++ b/td/telegram/SpecialStickerSetType.cpp @@ -6,9 +6,9 @@ // #include "td/telegram/SpecialStickerSetType.h" -#include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" namespace td { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 122323af3..5faad9c60 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -48,6 +48,7 @@ #include "td/utils/PathView.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StackAllocator.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 1316e1382..fa88924dc 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -131,6 +131,7 @@ #include "td/utils/port/uname.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/Timer.h" #include "td/utils/tl_parsers.h" diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index febb18026..de0ac900c 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -32,6 +32,7 @@ #include "td/utils/misc.h" #include "td/utils/port/path.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StringBuilder.h" #include diff --git a/td/telegram/TopDialogManager.cpp b/td/telegram/TopDialogManager.cpp index ac025b7fb..38d02b76f 100644 --- a/td/telegram/TopDialogManager.cpp +++ b/td/telegram/TopDialogManager.cpp @@ -26,6 +26,7 @@ #include "td/utils/port/Clocks.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index e28158047..e8fdf4e06 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -21,6 +21,7 @@ #include "td/telegram/DialogAction.h" #include "td/telegram/DialogId.h" #include "td/telegram/DialogInviteLink.h" +#include "td/telegram/DialogParticipant.h" #include "td/telegram/FolderId.h" #include "td/telegram/Global.h" #include "td/telegram/GroupCallManager.h" @@ -56,6 +57,7 @@ #include "td/utils/misc.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" @@ -2618,7 +2620,7 @@ void UpdatesManager::on_update(tl_object_ptr diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index bd3fab7ca..560447b08 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -46,6 +46,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StringBuilder.h" #include "td/utils/tl_helpers.h" #include "td/utils/utf8.h" diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 78b0c7166..b6dfed246 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -39,6 +39,7 @@ #include "td/utils/Random.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" diff --git a/td/telegram/files/FileDb.cpp b/td/telegram/files/FileDb.cpp index bfa2a6f9f..869c571e4 100644 --- a/td/telegram/files/FileDb.cpp +++ b/td/telegram/files/FileDb.cpp @@ -25,6 +25,7 @@ #include "td/utils/misc.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StackAllocator.h" #include "td/utils/Status.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/files/FileDownloader.cpp b/td/telegram/files/FileDownloader.cpp index d06b697db..2a6b7633c 100644 --- a/td/telegram/files/FileDownloader.cpp +++ b/td/telegram/files/FileDownloader.cpp @@ -27,6 +27,7 @@ #include "td/utils/port/path.h" #include "td/utils/port/Stat.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/UInt.h" #include diff --git a/td/telegram/files/FileGenerateManager.cpp b/td/telegram/files/FileGenerateManager.cpp index f2e33f86a..d96545e10 100644 --- a/td/telegram/files/FileGenerateManager.cpp +++ b/td/telegram/files/FileGenerateManager.cpp @@ -27,6 +27,7 @@ #include "td/utils/port/path.h" #include "td/utils/port/Stat.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/td/telegram/files/FileLoadManager.cpp b/td/telegram/files/FileLoadManager.cpp index b964aac2f..37851fa05 100644 --- a/td/telegram/files/FileLoadManager.cpp +++ b/td/telegram/files/FileLoadManager.cpp @@ -12,7 +12,7 @@ #include "td/utils/common.h" #include "td/utils/filesystem.h" #include "td/utils/format.h" -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" namespace td { diff --git a/td/telegram/files/FileLoaderUtils.cpp b/td/telegram/files/FileLoaderUtils.cpp index 4b96bc981..32438ab29 100644 --- a/td/telegram/files/FileLoaderUtils.cpp +++ b/td/telegram/files/FileLoaderUtils.cpp @@ -19,6 +19,7 @@ #include "td/utils/port/FileFd.h" #include "td/utils/port/path.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StringBuilder.h" #include diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 28f647d47..9d889f439 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -37,6 +37,7 @@ #include "td/utils/port/path.h" #include "td/utils/port/Stat.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/files/FileManager.hpp b/td/telegram/files/FileManager.hpp index 3ba88b025..23c41ed42 100644 --- a/td/telegram/files/FileManager.hpp +++ b/td/telegram/files/FileManager.hpp @@ -17,6 +17,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tl_helpers.h" namespace td { diff --git a/td/telegram/files/FileStatsWorker.cpp b/td/telegram/files/FileStatsWorker.cpp index dbd15d41e..e50e143d1 100644 --- a/td/telegram/files/FileStatsWorker.cpp +++ b/td/telegram/files/FileStatsWorker.cpp @@ -25,6 +25,7 @@ #include "td/utils/port/path.h" #include "td/utils/port/Stat.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/Time.h" #include "td/utils/tl_parsers.h" diff --git a/td/telegram/files/PartsManager.cpp b/td/telegram/files/PartsManager.cpp index 9f7018d25..69b7d2760 100644 --- a/td/telegram/files/PartsManager.cpp +++ b/td/telegram/files/PartsManager.cpp @@ -11,6 +11,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/td/telegram/logevent/LogEvent.h b/td/telegram/logevent/LogEvent.h index 33aee717b..bfda0f33e 100644 --- a/td/telegram/logevent/LogEvent.h +++ b/td/telegram/logevent/LogEvent.h @@ -15,6 +15,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StorerBase.h" #include "td/utils/StringBuilder.h" diff --git a/td/telegram/misc.cpp b/td/telegram/misc.cpp index d5895c366..a86053e11 100644 --- a/td/telegram/misc.cpp +++ b/td/telegram/misc.cpp @@ -9,9 +9,9 @@ #include "td/utils/algorithm.h" #include "td/utils/common.h" #include "td/utils/HttpUrl.h" -#include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/utf8.h" #include diff --git a/td/telegram/net/AuthDataShared.cpp b/td/telegram/net/AuthDataShared.cpp index aaf628cae..4114cbe81 100644 --- a/td/telegram/net/AuthDataShared.cpp +++ b/td/telegram/net/AuthDataShared.cpp @@ -13,6 +13,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/port/RwMutex.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tl_helpers.h" namespace td { diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 6bf5d47fa..5cee518ee 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -36,6 +36,7 @@ #include "td/utils/port/IPAddress.h" #include "td/utils/Random.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/net/DcOptionsSet.cpp b/td/telegram/net/DcOptionsSet.cpp index edc8180e2..038632f5e 100644 --- a/td/telegram/net/DcOptionsSet.cpp +++ b/td/telegram/net/DcOptionsSet.cpp @@ -14,6 +14,7 @@ #include "td/utils/algorithm.h" #include "td/utils/format.h" #include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/td/telegram/net/NetQuery.cpp b/td/telegram/net/NetQuery.cpp index d47b83f23..127c28ed5 100644 --- a/td/telegram/net/NetQuery.cpp +++ b/td/telegram/net/NetQuery.cpp @@ -11,7 +11,7 @@ #include "td/utils/as.h" #include "td/utils/misc.h" -#include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" namespace td { diff --git a/td/telegram/net/NetQueryDelayer.cpp b/td/telegram/net/NetQueryDelayer.cpp index c6aaf4857..6a5e29317 100644 --- a/td/telegram/net/NetQueryDelayer.cpp +++ b/td/telegram/net/NetQueryDelayer.cpp @@ -14,6 +14,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" namespace td { diff --git a/td/telegram/net/NetQueryDispatcher.cpp b/td/telegram/net/NetQueryDispatcher.cpp index cf4ef4f32..4164e8141 100644 --- a/td/telegram/net/NetQueryDispatcher.cpp +++ b/td/telegram/net/NetQueryDispatcher.cpp @@ -26,6 +26,7 @@ #include "td/utils/misc.h" #include "td/utils/port/thread.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" namespace td { diff --git a/td/telegram/net/NetQueryStats.cpp b/td/telegram/net/NetQueryStats.cpp index 6704f50c7..4eab21464 100644 --- a/td/telegram/net/NetQueryStats.cpp +++ b/td/telegram/net/NetQueryStats.cpp @@ -11,6 +11,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" namespace td { diff --git a/td/telegram/net/NetStatsManager.cpp b/td/telegram/net/NetStatsManager.cpp index c0a7d3627..04f6a869a 100644 --- a/td/telegram/net/NetStatsManager.cpp +++ b/td/telegram/net/NetStatsManager.cpp @@ -20,6 +20,7 @@ #include "td/utils/common.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tl_helpers.h" namespace td { diff --git a/td/telegram/net/PublicRsaKeyShared.cpp b/td/telegram/net/PublicRsaKeyShared.cpp index 89e710eb6..7215b52ac 100644 --- a/td/telegram/net/PublicRsaKeyShared.cpp +++ b/td/telegram/net/PublicRsaKeyShared.cpp @@ -10,6 +10,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include diff --git a/td/telegram/net/Session.cpp b/td/telegram/net/Session.cpp index a53ea238f..43efc3625 100644 --- a/td/telegram/net/Session.cpp +++ b/td/telegram/net/Session.cpp @@ -35,6 +35,7 @@ #include "td/utils/misc.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" #include "td/utils/Timer.h" #include "td/utils/tl_parsers.h" diff --git a/td/telegram/net/SessionMultiProxy.cpp b/td/telegram/net/SessionMultiProxy.cpp index 27c81fce8..26bb6c782 100644 --- a/td/telegram/net/SessionMultiProxy.cpp +++ b/td/telegram/net/SessionMultiProxy.cpp @@ -12,6 +12,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/td/telegram/net/SessionProxy.cpp b/td/telegram/net/SessionProxy.cpp index 44baab333..f387f259f 100644 --- a/td/telegram/net/SessionProxy.cpp +++ b/td/telegram/net/SessionProxy.cpp @@ -18,6 +18,7 @@ #include "td/utils/common.h" #include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/td/tl/tl_jni_object.cpp b/td/tl/tl_jni_object.cpp index 3ada33202..a46ff58c3 100644 --- a/td/tl/tl_jni_object.cpp +++ b/td/tl/tl_jni_object.cpp @@ -11,6 +11,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/td/tl/tl_json.h b/td/tl/tl_json.h index 20d1935e6..47c877c86 100644 --- a/td/tl/tl_json.h +++ b/td/tl/tl_json.h @@ -14,6 +14,7 @@ #include "td/utils/JsonBuilder.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/tl_storers.h" diff --git a/td/tl/tl_object_parse.h b/td/tl/tl_object_parse.h index df915360c..c514242a3 100644 --- a/td/tl/tl_object_parse.h +++ b/td/tl/tl_object_parse.h @@ -8,7 +8,7 @@ #include "td/tl/TlObject.h" -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/UInt.h" #include diff --git a/tdactor/test/actors_workers.cpp b/tdactor/test/actors_workers.cpp index 3d792d55e..b825d9884 100644 --- a/tdactor/test/actors_workers.cpp +++ b/tdactor/test/actors_workers.cpp @@ -9,7 +9,7 @@ #include "td/actor/actor.h" #include "td/actor/ConcurrentScheduler.h" -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" REGISTER_TESTS(actors_workers); @@ -112,8 +112,6 @@ class Manager final : public Actor { }; static void test_workers(int threads_n, int workers_n, int queries_n, int query_size) { - SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR)); - ConcurrentScheduler sched; sched.init(threads_n); diff --git a/tddb/td/db/SqliteDb.cpp b/tddb/td/db/SqliteDb.cpp index bb4de8eeb..2b3203cec 100644 --- a/tddb/td/db/SqliteDb.cpp +++ b/tddb/td/db/SqliteDb.cpp @@ -10,6 +10,7 @@ #include "td/utils/format.h" #include "td/utils/port/path.h" #include "td/utils/port/Stat.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/Timer.h" diff --git a/tddb/td/db/SqliteKeyValue.cpp b/tddb/td/db/SqliteKeyValue.cpp index c51325b2d..7426816d3 100644 --- a/tddb/td/db/SqliteKeyValue.cpp +++ b/tddb/td/db/SqliteKeyValue.cpp @@ -6,6 +6,7 @@ // #include "td/db/SqliteKeyValue.h" +#include "td/utils/logging.h" #include "td/utils/ScopeGuard.h" namespace td { diff --git a/tddb/td/db/SqliteKeyValue.h b/tddb/td/db/SqliteKeyValue.h index 362689b98..cee14a1c4 100644 --- a/tddb/td/db/SqliteKeyValue.h +++ b/tddb/td/db/SqliteKeyValue.h @@ -9,8 +9,8 @@ #include "td/db/SqliteDb.h" #include "td/db/SqliteStatement.h" -#include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include diff --git a/tddb/td/db/binlog/Binlog.cpp b/tddb/td/db/binlog/Binlog.cpp index 5eb1344b8..aea3e444c 100644 --- a/tddb/td/db/binlog/Binlog.cpp +++ b/tddb/td/db/binlog/Binlog.cpp @@ -20,6 +20,7 @@ #include "td/utils/port/Stat.h" #include "td/utils/Random.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/Time.h" #include "td/utils/tl_helpers.h" diff --git a/tddb/td/db/binlog/BinlogEvent.h b/tddb/td/db/binlog/BinlogEvent.h index cb842ec73..96b1c9d46 100644 --- a/tddb/td/db/binlog/BinlogEvent.h +++ b/tddb/td/db/binlog/BinlogEvent.h @@ -11,6 +11,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/Storer.h" #include "td/utils/StorerBase.h" diff --git a/tddb/td/db/binlog/ConcurrentBinlog.cpp b/tddb/td/db/binlog/ConcurrentBinlog.cpp index 6c501434e..40814c4f2 100644 --- a/tddb/td/db/binlog/ConcurrentBinlog.cpp +++ b/tddb/td/db/binlog/ConcurrentBinlog.cpp @@ -8,6 +8,7 @@ #include "td/utils/logging.h" #include "td/utils/OrderedEventsProcessor.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" #include diff --git a/tddb/td/db/binlog/binlog_dump.cpp b/tddb/td/db/binlog/binlog_dump.cpp index 240773ff6..72d1e5734 100644 --- a/tddb/td/db/binlog/binlog_dump.cpp +++ b/tddb/td/db/binlog/binlog_dump.cpp @@ -14,6 +14,7 @@ #include "td/utils/misc.h" #include "td/utils/port/Stat.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StringBuilder.h" #include "td/utils/tl_parsers.h" diff --git a/tddb/td/db/binlog/detail/BinlogEventsProcessor.cpp b/tddb/td/db/binlog/detail/BinlogEventsProcessor.cpp index f45017a45..4416c71e6 100644 --- a/tddb/td/db/binlog/detail/BinlogEventsProcessor.cpp +++ b/tddb/td/db/binlog/detail/BinlogEventsProcessor.cpp @@ -6,7 +6,7 @@ // #include "td/db/binlog/detail/BinlogEventsProcessor.h" -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include diff --git a/tddb/td/db/detail/RawSqliteDb.h b/tddb/td/db/detail/RawSqliteDb.h index d49475bfd..6f38bd869 100644 --- a/tddb/td/db/detail/RawSqliteDb.h +++ b/tddb/td/db/detail/RawSqliteDb.h @@ -6,9 +6,9 @@ // #pragma once -#include "td/utils/logging.h" #include "td/utils/optional.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" struct sqlite3; diff --git a/tdnet/td/net/GetHostByNameActor.cpp b/tdnet/td/net/GetHostByNameActor.cpp index 267382d83..371aaefc5 100644 --- a/tdnet/td/net/GetHostByNameActor.cpp +++ b/tdnet/td/net/GetHostByNameActor.cpp @@ -15,6 +15,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Time.h" namespace td { diff --git a/tdnet/td/net/HttpChunkedByteFlow.cpp b/tdnet/td/net/HttpChunkedByteFlow.cpp index 23b17bb0a..c56fb2d87 100644 --- a/tdnet/td/net/HttpChunkedByteFlow.cpp +++ b/tdnet/td/net/HttpChunkedByteFlow.cpp @@ -8,8 +8,8 @@ #include "td/utils/find_boundary.h" #include "td/utils/format.h" -#include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" namespace td { diff --git a/tdnet/td/net/HttpHeaderCreator.h b/tdnet/td/net/HttpHeaderCreator.h index a63cf6440..b16938c8b 100644 --- a/tdnet/td/net/HttpHeaderCreator.h +++ b/tdnet/td/net/HttpHeaderCreator.h @@ -8,6 +8,7 @@ #include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" diff --git a/tdnet/td/net/HttpProxy.cpp b/tdnet/td/net/HttpProxy.cpp index fc3d34ec9..f31c5cad1 100644 --- a/tdnet/td/net/HttpProxy.cpp +++ b/tdnet/td/net/HttpProxy.cpp @@ -12,6 +12,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" namespace td { diff --git a/tdnet/td/net/HttpReader.cpp b/tdnet/td/net/HttpReader.cpp index 0b7878800..163cd329b 100644 --- a/tdnet/td/net/HttpReader.cpp +++ b/tdnet/td/net/HttpReader.cpp @@ -17,6 +17,7 @@ #include "td/utils/Parser.h" #include "td/utils/PathView.h" #include "td/utils/port/path.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/tdnet/td/net/Socks5.cpp b/tdnet/td/net/Socks5.cpp index ac2037b95..ff7093956 100644 --- a/tdnet/td/net/Socks5.cpp +++ b/tdnet/td/net/Socks5.cpp @@ -10,6 +10,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" namespace td { diff --git a/tdnet/td/net/SslStream.cpp b/tdnet/td/net/SslStream.cpp index e456e0708..94eb90858 100644 --- a/tdnet/td/net/SslStream.cpp +++ b/tdnet/td/net/SslStream.cpp @@ -13,6 +13,7 @@ #include "td/utils/misc.h" #include "td/utils/port/IPAddress.h" #include "td/utils/port/wstring_convert.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/Time.h" diff --git a/tdnet/td/net/Wget.cpp b/tdnet/td/net/Wget.cpp index a54396b74..d67c6ecd2 100644 --- a/tdnet/td/net/Wget.cpp +++ b/tdnet/td/net/Wget.cpp @@ -17,6 +17,7 @@ #include "td/utils/port/IPAddress.h" #include "td/utils/port/SocketFd.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/tdutils/td/utils/BigNum.cpp b/tdutils/td/utils/BigNum.cpp index d29ef7502..4e2e2bf8c 100644 --- a/tdutils/td/utils/BigNum.cpp +++ b/tdutils/td/utils/BigNum.cpp @@ -12,6 +12,7 @@ char disable_linker_warning_about_empty_file_bignum_cpp TD_UNUSED; #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/tdutils/td/utils/FileLog.cpp b/tdutils/td/utils/FileLog.cpp index 95edc7454..14f8211db 100644 --- a/tdutils/td/utils/FileLog.cpp +++ b/tdutils/td/utils/FileLog.cpp @@ -12,6 +12,7 @@ #include "td/utils/port/path.h" #include "td/utils/port/StdStreams.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" namespace td { diff --git a/tdutils/td/utils/Gzip.cpp b/tdutils/td/utils/Gzip.cpp index 852bfe5f7..26466f294 100644 --- a/tdutils/td/utils/Gzip.cpp +++ b/tdutils/td/utils/Gzip.cpp @@ -9,7 +9,7 @@ char disable_linker_warning_about_empty_file_gzip_cpp TD_UNUSED; #if TD_HAVE_ZLIB -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/tdutils/td/utils/JsonBuilder.cpp b/tdutils/td/utils/JsonBuilder.cpp index 44538f155..c3634795e 100644 --- a/tdutils/td/utils/JsonBuilder.cpp +++ b/tdutils/td/utils/JsonBuilder.cpp @@ -8,6 +8,7 @@ #include "td/utils/misc.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/tdutils/td/utils/OptionParser.cpp b/tdutils/td/utils/OptionParser.cpp index 09a761229..5866eed29 100644 --- a/tdutils/td/utils/OptionParser.cpp +++ b/tdutils/td/utils/OptionParser.cpp @@ -8,6 +8,7 @@ #include "td/utils/logging.h" #include "td/utils/PathView.h" +#include "td/utils/SliceBuilder.h" #if TD_PORT_WINDOWS #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) diff --git a/tdutils/td/utils/Parser.h b/tdutils/td/utils/Parser.h index 1288fccf8..a6ce8eece 100644 --- a/tdutils/td/utils/Parser.h +++ b/tdutils/td/utils/Parser.h @@ -8,8 +8,8 @@ #include "td/utils/common.h" #include "td/utils/format.h" -#include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include diff --git a/tdutils/td/utils/Status.h b/tdutils/td/utils/Status.h index 551b9bf88..a777f5395 100644 --- a/tdutils/td/utils/Status.h +++ b/tdutils/td/utils/Status.h @@ -10,6 +10,7 @@ #include "td/utils/logging.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StackAllocator.h" #include "td/utils/StringBuilder.h" diff --git a/tdutils/td/utils/TsFileLog.cpp b/tdutils/td/utils/TsFileLog.cpp index 3a2de2689..ecd72df75 100644 --- a/tdutils/td/utils/TsFileLog.cpp +++ b/tdutils/td/utils/TsFileLog.cpp @@ -11,6 +11,7 @@ #include "td/utils/logging.h" #include "td/utils/port/thread_local.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/tdutils/td/utils/check.cpp b/tdutils/td/utils/check.cpp index 79e92afa4..3d78954f8 100644 --- a/tdutils/td/utils/check.cpp +++ b/tdutils/td/utils/check.cpp @@ -8,6 +8,7 @@ #include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" namespace td { namespace detail { diff --git a/tdutils/td/utils/filesystem.cpp b/tdutils/td/utils/filesystem.cpp index 8922713d8..480bff9fc 100644 --- a/tdutils/td/utils/filesystem.cpp +++ b/tdutils/td/utils/filesystem.cpp @@ -7,12 +7,12 @@ #include "td/utils/filesystem.h" #include "td/utils/buffer.h" -#include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/PathView.h" #include "td/utils/port/FileFd.h" #include "td/utils/port/path.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/unicode.h" #include "td/utils/utf8.h" diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index d078bf823..28c970b2b 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -26,7 +26,6 @@ #include "td/utils/common.h" #include "td/utils/port/thread_local.h" #include "td/utils/Slice.h" -#include "td/utils/SliceBuilder.h" #include "td/utils/StackAllocator.h" #include "td/utils/StringBuilder.h" diff --git a/tdutils/td/utils/misc.h b/tdutils/td/utils/misc.h index a514acc93..d26e689f7 100644 --- a/tdutils/td/utils/misc.h +++ b/tdutils/td/utils/misc.h @@ -9,6 +9,7 @@ #include "td/utils/common.h" #include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" diff --git a/tdutils/td/utils/port/FileFd.cpp b/tdutils/td/utils/port/FileFd.cpp index 8ee8c4a40..6fe322ce1 100644 --- a/tdutils/td/utils/port/FileFd.cpp +++ b/tdutils/td/utils/port/FileFd.cpp @@ -21,6 +21,7 @@ #include "td/utils/port/PollFlags.h" #include "td/utils/port/sleep.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StringBuilder.h" #include diff --git a/tdutils/td/utils/port/IPAddress.cpp b/tdutils/td/utils/port/IPAddress.cpp index 7206190d2..cf4e317b7 100644 --- a/tdutils/td/utils/port/IPAddress.cpp +++ b/tdutils/td/utils/port/IPAddress.cpp @@ -15,6 +15,7 @@ #include "td/utils/port/thread_local.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/utf8.h" #if TD_WINDOWS diff --git a/tdutils/td/utils/port/MemoryMapping.cpp b/tdutils/td/utils/port/MemoryMapping.cpp index bcd3c4c98..8a06aa103 100644 --- a/tdutils/td/utils/port/MemoryMapping.cpp +++ b/tdutils/td/utils/port/MemoryMapping.cpp @@ -6,8 +6,8 @@ // #include "td/utils/port/MemoryMapping.h" -#include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/SliceBuilder.h" // TODO: // windows, diff --git a/tdutils/td/utils/port/ServerSocketFd.cpp b/tdutils/td/utils/port/ServerSocketFd.cpp index cd6f10fb9..dc546a7d4 100644 --- a/tdutils/td/utils/port/ServerSocketFd.cpp +++ b/tdutils/td/utils/port/ServerSocketFd.cpp @@ -13,6 +13,7 @@ #include "td/utils/port/detail/skip_eintr.h" #include "td/utils/port/IPAddress.h" #include "td/utils/port/PollFlags.h" +#include "td/utils/SliceBuilder.h" #if TD_PORT_POSIX #include diff --git a/tdutils/td/utils/port/SocketFd.cpp b/tdutils/td/utils/port/SocketFd.cpp index b74a078f9..261e14fa5 100644 --- a/tdutils/td/utils/port/SocketFd.cpp +++ b/tdutils/td/utils/port/SocketFd.cpp @@ -12,6 +12,7 @@ #include "td/utils/misc.h" #include "td/utils/port/detail/skip_eintr.h" #include "td/utils/port/PollFlags.h" +#include "td/utils/SliceBuilder.h" #if TD_PORT_WINDOWS #include "td/utils/buffer.h" diff --git a/tdutils/td/utils/port/Stat.cpp b/tdutils/td/utils/port/Stat.cpp index e4387cf45..a762a6209 100644 --- a/tdutils/td/utils/port/Stat.cpp +++ b/tdutils/td/utils/port/Stat.cpp @@ -16,6 +16,7 @@ #include "td/utils/port/Clocks.h" #include "td/utils/port/detail/skip_eintr.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/tdutils/td/utils/port/StdStreams.cpp b/tdutils/td/utils/port/StdStreams.cpp index df73a643f..681d4b564 100644 --- a/tdutils/td/utils/port/StdStreams.cpp +++ b/tdutils/td/utils/port/StdStreams.cpp @@ -15,6 +15,7 @@ #include "td/utils/port/thread.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/tdutils/td/utils/port/UdpSocketFd.cpp b/tdutils/td/utils/port/UdpSocketFd.cpp index ae143c8b5..2f782fd1e 100644 --- a/tdutils/td/utils/port/UdpSocketFd.cpp +++ b/tdutils/td/utils/port/UdpSocketFd.cpp @@ -13,6 +13,7 @@ #include "td/utils/port/detail/skip_eintr.h" #include "td/utils/port/PollFlags.h" #include "td/utils/port/SocketFd.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/VectorQueue.h" #if TD_PORT_WINDOWS diff --git a/tdutils/td/utils/port/detail/EventFdLinux.cpp b/tdutils/td/utils/port/detail/EventFdLinux.cpp index 0e6657e40..96bfcb052 100644 --- a/tdutils/td/utils/port/detail/EventFdLinux.cpp +++ b/tdutils/td/utils/port/detail/EventFdLinux.cpp @@ -17,6 +17,7 @@ char disable_linker_warning_about_empty_file_event_fd_linux_cpp TD_UNUSED; #include "td/utils/port/PollFlags.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include diff --git a/tdutils/td/utils/port/detail/NativeFd.cpp b/tdutils/td/utils/port/detail/NativeFd.cpp index 28a03c8e5..c03e0afc1 100644 --- a/tdutils/td/utils/port/detail/NativeFd.cpp +++ b/tdutils/td/utils/port/detail/NativeFd.cpp @@ -8,6 +8,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #if TD_PORT_POSIX #include diff --git a/tdutils/td/utils/port/path.cpp b/tdutils/td/utils/port/path.cpp index 7f9aabbda..29fadd243 100644 --- a/tdutils/td/utils/port/path.cpp +++ b/tdutils/td/utils/port/path.cpp @@ -12,6 +12,7 @@ #include "td/utils/logging.h" #include "td/utils/port/detail/skip_eintr.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #if TD_PORT_WINDOWS #include "td/utils/port/FromApp.h" diff --git a/tdutils/td/utils/port/uname.cpp b/tdutils/td/utils/port/uname.cpp index 628cc5bd2..5f3caf17c 100644 --- a/tdutils/td/utils/port/uname.cpp +++ b/tdutils/td/utils/port/uname.cpp @@ -13,6 +13,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/Stat.h" +#include "td/utils/SliceBuilder.h" #if TD_PORT_POSIX diff --git a/tdutils/td/utils/port/user.cpp b/tdutils/td/utils/port/user.cpp index 0c8ed5950..b31f28437 100644 --- a/tdutils/td/utils/port/user.cpp +++ b/tdutils/td/utils/port/user.cpp @@ -9,7 +9,7 @@ #include "td/utils/port/config.h" #if TD_PORT_POSIX -#include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/tdutils/td/utils/tests.cpp b/tdutils/td/utils/tests.cpp index 248098155..0e79b2629 100644 --- a/tdutils/td/utils/tests.cpp +++ b/tdutils/td/utils/tests.cpp @@ -14,6 +14,7 @@ #include "td/utils/port/Stat.h" #include "td/utils/Random.h" #include "td/utils/ScopeGuard.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" diff --git a/tdutils/td/utils/tl_helpers.h b/tdutils/td/utils/tl_helpers.h index 035fd37ff..f31f2d9c1 100644 --- a/tdutils/td/utils/tl_helpers.h +++ b/tdutils/td/utils/tl_helpers.h @@ -7,10 +7,10 @@ #pragma once #include "td/utils/common.h" -#include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/SharedSlice.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StackAllocator.h" #include "td/utils/Status.h" #include "td/utils/tl_parsers.h" diff --git a/tdutils/td/utils/tl_parsers.h b/tdutils/td/utils/tl_parsers.h index 771f877da..a7141d263 100644 --- a/tdutils/td/utils/tl_parsers.h +++ b/tdutils/td/utils/tl_parsers.h @@ -11,6 +11,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/UInt.h" #include "td/utils/utf8.h" diff --git a/tdutils/td/utils/tl_storers.h b/tdutils/td/utils/tl_storers.h index 8de3fe5be..0865088dd 100644 --- a/tdutils/td/utils/tl_storers.h +++ b/tdutils/td/utils/tl_storers.h @@ -10,6 +10,7 @@ #include "td/utils/logging.h" #include "td/utils/SharedSlice.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StorerBase.h" #include "td/utils/UInt.h" diff --git a/tdutils/test/StealingQueue.cpp b/tdutils/test/StealingQueue.cpp index 9b5e6ebf8..fc878fb58 100644 --- a/tdutils/test/StealingQueue.cpp +++ b/tdutils/test/StealingQueue.cpp @@ -11,6 +11,7 @@ #include "td/utils/MpmcQueue.h" #include "td/utils/port/thread.h" #include "td/utils/Random.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/StealingQueue.h" #include "td/utils/tests.h" diff --git a/tdutils/test/crypto.cpp b/tdutils/test/crypto.cpp index a1f59d1d4..0c8681639 100644 --- a/tdutils/test/crypto.cpp +++ b/tdutils/test/crypto.cpp @@ -8,9 +8,9 @@ #include "td/utils/benchmark.h" #include "td/utils/common.h" #include "td/utils/crypto.h" -#include "td/utils/logging.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tests.h" #include "td/utils/UInt.h" diff --git a/tdutils/test/log.cpp b/tdutils/test/log.cpp index d248b7fdc..9444b6e8b 100644 --- a/tdutils/test/log.cpp +++ b/tdutils/test/log.cpp @@ -12,6 +12,7 @@ #include "td/utils/port/path.h" #include "td/utils/port/thread.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tests.h" #include "td/utils/TsFileLog.h" diff --git a/tdutils/test/misc.cpp b/tdutils/test/misc.cpp index 55d172ac1..545a7cc2b 100644 --- a/tdutils/test/misc.cpp +++ b/tdutils/test/misc.cpp @@ -30,6 +30,7 @@ #include "td/utils/port/wstring_convert.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/tests.h" diff --git a/tdutils/test/port.cpp b/tdutils/test/port.cpp index 5865ed32a..4fcd7f701 100644 --- a/tdutils/test/port.cpp +++ b/tdutils/test/port.cpp @@ -19,6 +19,7 @@ #include "td/utils/Random.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tests.h" #include "td/utils/Time.h" diff --git a/tdutils/test/pq.cpp b/tdutils/test/pq.cpp index a946f19dc..04f524709 100644 --- a/tdutils/test/pq.cpp +++ b/tdutils/test/pq.cpp @@ -12,6 +12,7 @@ #include "td/utils/crypto.h" #include "td/utils/format.h" #include "td/utils/logging.h" +#include "td/utils/SliceBuilder.h" #include #include diff --git a/test/http.cpp b/test/http.cpp index 3dbc9f940..897e56cac 100644 --- a/test/http.cpp +++ b/test/http.cpp @@ -35,6 +35,7 @@ #include "td/utils/port/thread_local.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/tests.h" #include "td/utils/UInt.h" diff --git a/test/message_entities.cpp b/test/message_entities.cpp index e88139513..78e4d3a55 100644 --- a/test/message_entities.cpp +++ b/test/message_entities.cpp @@ -12,6 +12,7 @@ #include "td/utils/misc.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tests.h" #include "td/utils/utf8.h" diff --git a/test/mtproto.cpp b/test/mtproto.cpp index 05b0aa252..f37e518dd 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -38,6 +38,7 @@ #include "td/utils/port/SocketFd.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/tests.h" #include "td/utils/Time.h" diff --git a/test/secret.cpp b/test/secret.cpp index 6f7779e84..3cf21b8ba 100644 --- a/test/secret.cpp +++ b/test/secret.cpp @@ -40,6 +40,7 @@ #include "td/utils/misc.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/tests.h" #include "td/utils/tl_helpers.h" diff --git a/test/secure_storage.cpp b/test/secure_storage.cpp index e49f149ca..fd587ce31 100644 --- a/test/secure_storage.cpp +++ b/test/secure_storage.cpp @@ -8,8 +8,8 @@ #include "td/utils/buffer.h" #include "td/utils/filesystem.h" -#include "td/utils/logging.h" #include "td/utils/port/path.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/tests.h" using namespace td; diff --git a/test/tdclient.cpp b/test/tdclient.cpp index 2da349c4c..97496be38 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -28,6 +28,7 @@ #include "td/utils/port/thread.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" #include "td/utils/tests.h" diff --git a/test/tqueue.cpp b/test/tqueue.cpp index c2f8c5869..37845b592 100644 --- a/test/tqueue.cpp +++ b/test/tqueue.cpp @@ -15,6 +15,7 @@ #include "td/utils/logging.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" +#include "td/utils/SliceBuilder.h" #include "td/utils/Span.h" #include "td/utils/tests.h" From 13a21b4fe2597a48ba6fd593b9080e4d93579ca1 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 16:18:19 +0300 Subject: [PATCH 21/43] Make LogInterface::append non-virtual. --- td/telegram/cli.cpp | 5 ++--- tdutils/td/utils/FileLog.cpp | 6 +----- tdutils/td/utils/FileLog.h | 8 ++++---- tdutils/td/utils/MemoryLog.h | 24 ++++++++++-------------- tdutils/td/utils/TsFileLog.cpp | 26 +++++++++++++------------- tdutils/td/utils/logging.cpp | 17 ++++++++++------- tdutils/td/utils/logging.h | 25 ++++++++++++++----------- tdutils/test/log.cpp | 16 ++++++---------- 8 files changed, 60 insertions(+), 67 deletions(-) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index b6dfed246..519c60c89 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -189,8 +189,7 @@ static char **tg_cli_completion(const char *text, int start, int end) { #endif class CliLog : public LogInterface { - public: - void append(CSlice slice, int log_level) override { + void do_append(int log_level, CSlice slice) final { #ifdef USE_READLINE deactivate_readline(); SCOPE_EXIT { @@ -204,7 +203,7 @@ class CliLog : public LogInterface { TsCerr() << TC_GREEN << slice << TC_EMPTY; #endif } else { - default_log_interface->append(slice, log_level); + default_log_interface->do_append(log_level, slice); } } }; diff --git a/tdutils/td/utils/FileLog.cpp b/tdutils/td/utils/FileLog.cpp index 14f8211db..54e3fe8d4 100644 --- a/tdutils/td/utils/FileLog.cpp +++ b/tdutils/td/utils/FileLog.cpp @@ -70,8 +70,7 @@ bool FileLog::get_redirect_stderr() const { return redirect_stderr_; } -void FileLog::append(CSlice cslice, int log_level) { - Slice slice = cslice; +void FileLog::do_append(int log_level, CSlice slice) { while (!slice.empty()) { auto r_size = fd_.write(slice); if (r_size.is_error()) { @@ -81,9 +80,6 @@ void FileLog::append(CSlice cslice, int log_level) { size_ += static_cast(written); slice.remove_prefix(written); } - if (log_level == VERBOSITY_NAME(FATAL)) { - process_fatal_error(cslice); - } if (size_ > rotate_threshold_ || want_rotate_.load(std::memory_order_relaxed)) { auto status = rename(path_, PSLICE() << path_ << ".old"); diff --git a/tdutils/td/utils/FileLog.h b/tdutils/td/utils/FileLog.h index 728c873c7..a057fc7b3 100644 --- a/tdutils/td/utils/FileLog.h +++ b/tdutils/td/utils/FileLog.h @@ -26,7 +26,7 @@ class FileLog : public LogInterface { Slice get_path() const; - vector get_file_paths() override; + vector get_file_paths() final; void set_rotate_threshold(int64 rotate_threshold); @@ -34,9 +34,7 @@ class FileLog : public LogInterface { bool get_redirect_stderr() const; - void append(CSlice cslice, int log_level) override; - - void rotate() override; + void rotate() final; void lazy_rotate(); @@ -48,6 +46,8 @@ class FileLog : public LogInterface { bool redirect_stderr_ = false; std::atomic want_rotate_{false}; + void do_append(int log_level, CSlice slice) final; + void do_rotate(); }; diff --git a/tdutils/td/utils/MemoryLog.h b/tdutils/td/utils/MemoryLog.h index 0e1e34b19..06bc2508c 100644 --- a/tdutils/td/utils/MemoryLog.h +++ b/tdutils/td/utils/MemoryLog.h @@ -28,7 +28,16 @@ class MemoryLog : public LogInterface { std::memset(buffer_, ' ', sizeof(buffer_)); } - void append(CSlice new_slice, int log_level) override { + Slice get_buffer() const { + return Slice(buffer_, sizeof(buffer_)); + } + + size_t get_pos() const { + return pos_ & (buffer_size - 1); + } + + private: + void do_append(int log_level, CSlice new_slice) final { Slice slice = new_slice; slice.truncate(MAX_OUTPUT_SIZE); while (!slice.empty() && slice.back() == '\n') { @@ -61,21 +70,8 @@ class MemoryLog : public LogInterface { size_t printed = std::snprintf(&buffer_[start_pos + 1], MAGIC_SIZE - 1, "LOG:%08x: ", real_pos); CHECK(printed == MAGIC_SIZE - 2); buffer_[start_pos + MAGIC_SIZE - 1] = ' '; - - if (log_level == VERBOSITY_NAME(FATAL)) { - process_fatal_error(new_slice); - } } - Slice get_buffer() const { - return Slice(buffer_, sizeof(buffer_)); - } - - size_t get_pos() const { - return pos_ & (buffer_size - 1); - } - - private: char buffer_[buffer_size]; std::atomic pos_{0}; }; diff --git a/tdutils/td/utils/TsFileLog.cpp b/tdutils/td/utils/TsFileLog.cpp index ecd72df75..f7be661b1 100644 --- a/tdutils/td/utils/TsFileLog.cpp +++ b/tdutils/td/utils/TsFileLog.cpp @@ -33,18 +33,6 @@ class TsFileLog : public LogInterface { return init_info(&logs_[0]); } - vector get_file_paths() override { - vector res; - for (auto &log : logs_) { - res.push_back(get_path(&log)); - } - return res; - } - - void append(CSlice cslice, int log_level) override { - get_current_logger()->append(cslice, log_level); - } - private: struct Info { FileLog log; @@ -87,13 +75,25 @@ class TsFileLog : public LogInterface { return PSTRING() << path_ << ".thread" << info->id << ".log"; } - void rotate() override { + void do_append(int log_level, CSlice cslice) final { + get_current_logger()->do_append(log_level, cslice); + } + + void rotate() final { for (auto &info : logs_) { if (info.is_inited.load(std::memory_order_acquire)) { info.log.lazy_rotate(); } } } + + vector get_file_paths() final { + vector res; + for (auto &log : logs_) { + res.push_back(get_path(&log)); + } + return res; + } }; } // namespace detail diff --git a/tdutils/td/utils/logging.cpp b/tdutils/td/utils/logging.cpp index 64bbda507..6910ba5e5 100644 --- a/tdutils/td/utils/logging.cpp +++ b/tdutils/td/utils/logging.cpp @@ -32,6 +32,13 @@ namespace td { LogOptions log_options; +void LogInterface::append(int log_level, CSlice slice) { + do_append(log_level, slice); + if (log_level == VERBOSITY_NAME(FATAL)) { + process_fatal_error(slice); + } +} + TD_THREAD_LOCAL const char *Logger::tag_ = nullptr; TD_THREAD_LOCAL const char *Logger::tag2_ = nullptr; @@ -121,9 +128,9 @@ Logger::~Logger() { slice.back() = '\0'; slice = MutableCSlice(slice.begin(), slice.begin() + slice.size() - 1); } - log_.append(slice, log_level_); + log_.append(log_level_, slice); } else { - log_.append(as_cslice(), log_level_); + log_.append(log_level_, as_cslice()); } } @@ -180,8 +187,7 @@ void TsLog::exit_critical() { } class DefaultLog : public LogInterface { - public: - void append(CSlice slice, int log_level) override { + void do_append(int log_level, CSlice slice) final { #if TD_ANDROID switch (log_level) { case VERBOSITY_NAME(FATAL): @@ -259,9 +265,6 @@ class DefaultLog : public LogInterface { // TODO: color TsCerr() << slice; #endif - if (log_level == VERBOSITY_NAME(FATAL)) { - process_fatal_error(slice); - } } }; static DefaultLog default_log; diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 28c970b2b..528186aa8 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -167,7 +167,7 @@ class LogInterface { LogInterface &operator=(LogInterface &&) = delete; virtual ~LogInterface() = default; - virtual void append(CSlice slice, int log_level) = 0; + void append(int log_level, CSlice slice); virtual void rotate() { } @@ -175,11 +175,12 @@ class LogInterface { virtual vector get_file_paths() { return {}; } + + virtual void do_append(int log_level, CSlice slice) = 0; }; class NullLog : public LogInterface { - public: - void append(CSlice /*slice*/, int /*log_level*/) override { + void do_append(int /*log_level*/, CSlice /*slice*/) final { } }; @@ -217,8 +218,9 @@ class TsCerr { }; class Logger { - public: static const size_t BUFFER_SIZE = 128 * 1024; + + public: Logger(LogInterface &log, const LogOptions &options, int log_level) : buffer_(StackAllocator::alloc(BUFFER_SIZE)) , log_(log) @@ -276,17 +278,12 @@ class TsLog : public LogInterface { log_ = log; exit_critical(); } - void append(CSlice slice, int level) override { - enter_critical(); - log_->append(slice, level); - exit_critical(); - } - void rotate() override { + void rotate() final { enter_critical(); log_->rotate(); exit_critical(); } - vector get_file_paths() override { + vector get_file_paths() final { enter_critical(); auto result = log_->get_file_paths(); exit_critical(); @@ -294,6 +291,12 @@ class TsLog : public LogInterface { } private: + void do_append(int log_level, CSlice slice) final { + enter_critical(); + log_->do_append(log_level, slice); + exit_critical(); + } + LogInterface *log_ = nullptr; std::atomic_flag lock_ = ATOMIC_FLAG_INIT; void enter_critical(); diff --git a/tdutils/test/log.cpp b/tdutils/test/log.cpp index 9444b6e8b..0d3b7d6d6 100644 --- a/tdutils/test/log.cpp +++ b/tdutils/test/log.cpp @@ -106,12 +106,10 @@ TEST(Log, Bench) { file_log_.init("tmplog", std::numeric_limits::max(), false).ensure(); ts_log_.init(&file_log_); } - ~FileLog() { + void do_append(int log_level, td::CSlice slice) final { + static_cast(ts_log_).do_append(log_level, slice); } - void append(td::CSlice slice, int log_level) override { - ts_log_.append(slice, log_level); - } - std::vector get_file_paths() override { + std::vector get_file_paths() final { return file_log_.get_file_paths(); } @@ -128,12 +126,10 @@ TEST(Log, Bench) { FileLog() { file_log_.init("tmplog", std::numeric_limits::max(), false).ensure(); } - ~FileLog() { + void do_append(int log_level, td::CSlice slice) final { + static_cast(file_log_).do_append(log_level, slice); } - void append(td::CSlice slice, int log_level) override { - file_log_.append(slice, log_level); - } - std::vector get_file_paths() override { + std::vector get_file_paths() final { return file_log_.get_file_paths(); } From 135f9de4a951d0dd8237793783ff60165339db36 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 16:53:35 +0300 Subject: [PATCH 22/43] Add CombinedLog.h. --- tdutils/CMakeLists.txt | 1 + tdutils/td/utils/CombinedLog.h | 78 ++++++++++++++++++++++++++++++++++ tdutils/td/utils/TsFileLog.cpp | 4 +- tdutils/test/log.cpp | 14 ++++++ 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 tdutils/td/utils/CombinedLog.h diff --git a/tdutils/CMakeLists.txt b/tdutils/CMakeLists.txt index f288f5d3c..4db85ab35 100644 --- a/tdutils/CMakeLists.txt +++ b/tdutils/CMakeLists.txt @@ -182,6 +182,7 @@ set(TDUTILS_SOURCE td/utils/ChangesProcessor.h td/utils/check.h td/utils/Closure.h + td/utils/CombinedLog.h td/utils/common.h td/utils/ConcurrentHashTable.h td/utils/Container.h diff --git a/tdutils/td/utils/CombinedLog.h b/tdutils/td/utils/CombinedLog.h new file mode 100644 index 000000000..76619cf9d --- /dev/null +++ b/tdutils/td/utils/CombinedLog.h @@ -0,0 +1,78 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 +// +// 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 + +#include "td/utils/algorithm.h" +#include "td/utils/common.h" +#include "td/utils/logging.h" +#include "td/utils/Slice.h" + +namespace td { + +class CombinedLog : public LogInterface { + public: + void set_first(LogInterface *first) { + first_ = first; + } + + void set_second(LogInterface *second) { + second_ = second; + } + + void set_first_verbosity_level(int verbosity_level) { + first_verbosity_level_ = verbosity_level; + } + + void set_second_verbosity_level(int verbosity_level) { + second_verbosity_level_ = verbosity_level; + } + + int get_first_verbosity_level() const { + return first_verbosity_level_; + } + + int get_second_verbosity_level() const { + return second_verbosity_level_; + } + + private: + LogInterface *first_ = nullptr; + int first_verbosity_level_ = VERBOSITY_NAME(FATAL); + LogInterface *second_ = nullptr; + int second_verbosity_level_ = VERBOSITY_NAME(FATAL); + + void do_append(int log_level, CSlice slice) final { + if (first_ && log_level <= first_verbosity_level_) { + first_->do_append(log_level, slice); + } + if (second_ && log_level <= second_verbosity_level_) { + second_->do_append(log_level, slice); + } + } + + void rotate() final { + if (first_) { + first_->rotate(); + } + if (second_) { + second_->rotate(); + } + } + + vector get_file_paths() final { + vector result; + if (first_) { + td::append(result, first_->get_file_paths()); + } + if (second_) { + td::append(result, second_->get_file_paths()); + } + return result; + } +}; + +} // namespace td diff --git a/tdutils/td/utils/TsFileLog.cpp b/tdutils/td/utils/TsFileLog.cpp index f7be661b1..c4095af1d 100644 --- a/tdutils/td/utils/TsFileLog.cpp +++ b/tdutils/td/utils/TsFileLog.cpp @@ -75,8 +75,8 @@ class TsFileLog : public LogInterface { return PSTRING() << path_ << ".thread" << info->id << ".log"; } - void do_append(int log_level, CSlice cslice) final { - get_current_logger()->do_append(log_level, cslice); + void do_append(int log_level, CSlice slice) final { + get_current_logger()->do_append(log_level, slice); } void rotate() final { diff --git a/tdutils/test/log.cpp b/tdutils/test/log.cpp index 0d3b7d6d6..b76f6c2bc 100644 --- a/tdutils/test/log.cpp +++ b/tdutils/test/log.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/utils/benchmark.h" +#include "td/utils/CombinedLog.h" #include "td/utils/FileLog.h" #include "td/utils/format.h" #include "td/utils/logging.h" @@ -96,6 +97,19 @@ TEST(Log, Bench) { bench_log("MemoryLog", [] { return td::make_unique>(); }); + bench_log("CombinedLogEmpty", [] { return td::make_unique(); }); + + bench_log("CombinedLogMemory", [] { + auto result = td::make_unique(); + static td::NullLog null_log; + static td::MemoryLog<1 << 20> memory_log; + result->set_first(&null_log); + result->set_second(&memory_log); + result->set_first_verbosity_level(VERBOSITY_NAME(DEBUG)); + result->set_second_verbosity_level(VERBOSITY_NAME(DEBUG)); + return result; + }); + bench_log("TsFileLog", [] { return td::TsFileLog::create("tmplog", std::numeric_limits::max(), false).move_as_ok(); }); From fdeaafa70d1273752785531bd540344696c0fc4d Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 17:33:26 +0300 Subject: [PATCH 23/43] tg_cli: always write log to file. --- td/telegram/cli.cpp | 30 +++++++++++++++++++++--------- tdutils/td/utils/CombinedLog.h | 8 ++++++++ tdutils/td/utils/FileLog.cpp | 15 +++++++-------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 519c60c89..830007291 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -20,6 +20,7 @@ #include "td/utils/algorithm.h" #include "td/utils/base64.h" #include "td/utils/buffer.h" +#include "td/utils/CombinedLog.h" #include "td/utils/common.h" #include "td/utils/crypto.h" #include "td/utils/ExitGuard.h" @@ -208,6 +209,8 @@ class CliLog : public LogInterface { } }; +static CombinedLog combined_log; + struct SendMessageInfo { double start_time = 0; double quick_ack_time = 0; @@ -4160,12 +4163,10 @@ class CliClient final : public Actor { << ", user ticks = " << stats.process_user_ticks_ << ", system ticks = " << stats.process_system_ticks_; } - } else if (op == "SetVerbosity" || op == "SV") { - Log::set_verbosity_level(to_integer(args)); - } else if (op[0] == 'v' && op[1] == 'v') { - Log::set_verbosity_level(static_cast(op.size())); - } else if (op[0] == 'v' && ('0' <= op[1] && op[1] <= '9')) { - Log::set_verbosity_level(to_integer(op.substr(1))); + } else if (op[0] == 'v' && (op[1] == 'v' || is_digit(op[1]))) { + int new_verbosity_level = op[1] == 'v' ? static_cast(op.size()) : to_integer(op.substr(1)); + SET_VERBOSITY_LEVEL(td::max(new_verbosity_level, VERBOSITY_NAME(DEBUG))); + combined_log.set_first_verbosity_level(new_verbosity_level); } else if (op == "slse") { execute(td_api::make_object(td_api::make_object())); } else if (op == "slsd") { @@ -4388,11 +4389,14 @@ void main(int argc, char **argv) { }; CliLog cli_log; - log_interface = &cli_log; FileLog file_log; TsLog ts_log(&file_log); + combined_log.set_first(&cli_log); + + log_interface = &combined_log; + int new_verbosity_level = VERBOSITY_NAME(INFO); bool use_test_dc = false; bool get_chat_list = false; @@ -4427,7 +4431,7 @@ void main(int argc, char **argv) { options.add_option('l', "log", "Log to file", [&](Slice file_name) { if (file_log.init(file_name.str()).is_ok() && file_log.init(file_name.str()).is_ok() && file_log.init(file_name.str(), 1000 << 20).is_ok()) { - log_interface = &ts_log; + combined_log.set_first(&ts_log); } }); options.add_option('W', "", "Preload chat list", [&] { get_chat_list = true; }); @@ -4449,7 +4453,15 @@ void main(int argc, char **argv) { return; } - SET_VERBOSITY_LEVEL(new_verbosity_level); + SET_VERBOSITY_LEVEL(td::max(new_verbosity_level, VERBOSITY_NAME(DEBUG))); + combined_log.set_first_verbosity_level(new_verbosity_level); + + if (combined_log.get_first() == &cli_log) { + file_log.init("tg_cli.log", 1000 << 20).ensure(); + file_log.lazy_rotate(); + combined_log.set_second(&ts_log); + combined_log.set_second_verbosity_level(VERBOSITY_NAME(DEBUG)); + } { ConcurrentScheduler scheduler; diff --git a/tdutils/td/utils/CombinedLog.h b/tdutils/td/utils/CombinedLog.h index 76619cf9d..9f48b886a 100644 --- a/tdutils/td/utils/CombinedLog.h +++ b/tdutils/td/utils/CombinedLog.h @@ -31,6 +31,14 @@ class CombinedLog : public LogInterface { second_verbosity_level_ = verbosity_level; } + const LogInterface *get_first() const { + return first_; + } + + const LogInterface *get_second() const { + return second_; + } + int get_first_verbosity_level() const { return first_verbosity_level_; } diff --git a/tdutils/td/utils/FileLog.cpp b/tdutils/td/utils/FileLog.cpp index 54e3fe8d4..c907f3d6e 100644 --- a/tdutils/td/utils/FileLog.cpp +++ b/tdutils/td/utils/FileLog.cpp @@ -71,6 +71,13 @@ bool FileLog::get_redirect_stderr() const { } void FileLog::do_append(int log_level, CSlice slice) { + if (size_ > rotate_threshold_ || want_rotate_.load(std::memory_order_relaxed)) { + auto status = rename(path_, PSLICE() << path_ << ".old"); + if (status.is_error()) { + process_fatal_error(PSLICE() << status.error() << " in " << __FILE__ << " at " << __LINE__); + } + do_rotate(); + } while (!slice.empty()) { auto r_size = fd_.write(slice); if (r_size.is_error()) { @@ -80,14 +87,6 @@ void FileLog::do_append(int log_level, CSlice slice) { size_ += static_cast(written); slice.remove_prefix(written); } - - if (size_ > rotate_threshold_ || want_rotate_.load(std::memory_order_relaxed)) { - auto status = rename(path_, PSLICE() << path_ << ".old"); - if (status.is_error()) { - process_fatal_error(PSLICE() << status.error() << " in " << __FILE__ << " at " << __LINE__); - } - do_rotate(); - } } void FileLog::rotate() { From 8231c58335e6c1f04c2eb2d77717adf754d88804 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 17:58:33 +0300 Subject: [PATCH 24/43] Rename LogInterface::rotate to after_rotation. --- tdutils/td/utils/CombinedLog.h | 6 +++--- tdutils/td/utils/FileLog.cpp | 8 ++++---- tdutils/td/utils/FileLog.h | 4 ++-- tdutils/td/utils/TsFileLog.cpp | 16 ++++++++-------- tdutils/td/utils/logging.h | 8 +++----- tdutils/test/log.cpp | 2 +- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/tdutils/td/utils/CombinedLog.h b/tdutils/td/utils/CombinedLog.h index 9f48b886a..87a690e77 100644 --- a/tdutils/td/utils/CombinedLog.h +++ b/tdutils/td/utils/CombinedLog.h @@ -62,12 +62,12 @@ class CombinedLog : public LogInterface { } } - void rotate() final { + void after_rotation() final { if (first_) { - first_->rotate(); + first_->after_rotation(); } if (second_) { - second_->rotate(); + second_->after_rotation(); } } diff --git a/tdutils/td/utils/FileLog.cpp b/tdutils/td/utils/FileLog.cpp index c907f3d6e..23f1a257b 100644 --- a/tdutils/td/utils/FileLog.cpp +++ b/tdutils/td/utils/FileLog.cpp @@ -76,7 +76,7 @@ void FileLog::do_append(int log_level, CSlice slice) { if (status.is_error()) { process_fatal_error(PSLICE() << status.error() << " in " << __FILE__ << " at " << __LINE__); } - do_rotate(); + do_after_rotation(); } while (!slice.empty()) { auto r_size = fd_.write(slice); @@ -89,18 +89,18 @@ void FileLog::do_append(int log_level, CSlice slice) { } } -void FileLog::rotate() { +void FileLog::after_rotation() { if (path_.empty()) { return; } - do_rotate(); + do_after_rotation(); } void FileLog::lazy_rotate() { want_rotate_ = true; } -void FileLog::do_rotate() { +void FileLog::do_after_rotation() { want_rotate_ = false; ScopedDisableLog disable_log; // to ensure that nothing will be printed to the closed log CHECK(!path_.empty()); diff --git a/tdutils/td/utils/FileLog.h b/tdutils/td/utils/FileLog.h index a057fc7b3..b57434f0c 100644 --- a/tdutils/td/utils/FileLog.h +++ b/tdutils/td/utils/FileLog.h @@ -34,7 +34,7 @@ class FileLog : public LogInterface { bool get_redirect_stderr() const; - void rotate() final; + void after_rotation() final; void lazy_rotate(); @@ -48,7 +48,7 @@ class FileLog : public LogInterface { void do_append(int log_level, CSlice slice) final; - void do_rotate(); + void do_after_rotation(); }; } // namespace td diff --git a/tdutils/td/utils/TsFileLog.cpp b/tdutils/td/utils/TsFileLog.cpp index c4095af1d..e904b5dd7 100644 --- a/tdutils/td/utils/TsFileLog.cpp +++ b/tdutils/td/utils/TsFileLog.cpp @@ -33,6 +33,14 @@ class TsFileLog : public LogInterface { return init_info(&logs_[0]); } + void rotate() { + for (auto &info : logs_) { + if (info.is_inited.load(std::memory_order_acquire)) { + info.log.lazy_rotate(); + } + } + } + private: struct Info { FileLog log; @@ -79,14 +87,6 @@ class TsFileLog : public LogInterface { get_current_logger()->do_append(log_level, slice); } - void rotate() final { - for (auto &info : logs_) { - if (info.is_inited.load(std::memory_order_acquire)) { - info.log.lazy_rotate(); - } - } - } - vector get_file_paths() final { vector res; for (auto &log : logs_) { diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 528186aa8..68031cfb1 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -59,8 +59,6 @@ #define VLOG(level) LOG_IMPL(DEBUG, level, true, TD_DEFINE_STR(level)) #define VLOG_IF(level, condition) LOG_IMPL(DEBUG, level, condition, TD_DEFINE_STR(level) " " #condition) -#define LOG_ROTATE() ::td::log_interface->rotate() - #define LOG_TAG ::td::Logger::tag_ #define LOG_TAG2 ::td::Logger::tag2_ @@ -169,7 +167,7 @@ class LogInterface { void append(int log_level, CSlice slice); - virtual void rotate() { + virtual void after_rotation() { } virtual vector get_file_paths() { @@ -278,9 +276,9 @@ class TsLog : public LogInterface { log_ = log; exit_critical(); } - void rotate() final { + void after_rotation() final { enter_critical(); - log_->rotate(); + log_->after_rotation(); exit_critical(); } vector get_file_paths() final { diff --git a/tdutils/test/log.cpp b/tdutils/test/log.cpp index b76f6c2bc..078ddf860 100644 --- a/tdutils/test/log.cpp +++ b/tdutils/test/log.cpp @@ -64,7 +64,7 @@ class LogBenchmark : public td::Benchmark { auto str = PSTRING() << "#" << n << " : fsjklfdjsklfjdsklfjdksl\n"; for (int i = 0; i < n; i++) { if (i % 10000 == 0) { - log_->rotate(); + log_->after_rotation(); } if (test_full_logging_) { LOG(ERROR) << str; From 3b0e2f5e855dc2b979d8e7b8d0db497bca2e4a44 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 18:49:09 +0300 Subject: [PATCH 25/43] Added the ability to hook into logging system. --- tdutils/td/utils/logging.cpp | 14 ++++++++++++++ tdutils/td/utils/logging.h | 6 +++++- tdutils/td/utils/port/detail/KQueue.cpp | 8 +++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tdutils/td/utils/logging.cpp b/tdutils/td/utils/logging.cpp index 6910ba5e5..14cfe2ba0 100644 --- a/tdutils/td/utils/logging.cpp +++ b/tdutils/td/utils/logging.cpp @@ -32,8 +32,22 @@ namespace td { LogOptions log_options; +static std::atomic max_callback_verbosity_level = 0; +static std::atomic on_log_message_callback = nullptr; + +void set_log_message_callback(int max_verbosity_level, OnLogMessageCallback callback) { + max_callback_verbosity_level = max_verbosity_level; + on_log_message_callback = callback; +} + void LogInterface::append(int log_level, CSlice slice) { do_append(log_level, slice); + if (log_level <= max_callback_verbosity_level.load(std::memory_order_relaxed)) { + auto callback = on_log_message_callback.load(std::memory_order_relaxed); + if (callback != nullptr) { + callback(log_level, slice); + } + } if (log_level == VERBOSITY_NAME(FATAL)) { process_fatal_error(slice); } diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 68031cfb1..6e5f3cc65 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -185,10 +185,14 @@ class NullLog : public LogInterface { extern LogInterface *const default_log_interface; extern LogInterface *log_interface; +[[noreturn]] void process_fatal_error(CSlice message); + +// deprecated in favor of set_log_message_callback using OnFatalErrorCallback = void (*)(CSlice message); void set_log_fatal_error_callback(OnFatalErrorCallback callback); -[[noreturn]] void process_fatal_error(CSlice message); +using OnLogMessageCallback = void (*)(int verbosity_level, CSlice message); +void set_log_message_callback(int max_verbosity_level, OnLogMessageCallback callback); #define TC_RED "\x1b[1;31m" #define TC_BLUE "\x1b[1;34m" diff --git a/tdutils/td/utils/port/detail/KQueue.cpp b/tdutils/td/utils/port/detail/KQueue.cpp index 9bbcf290e..e266429bc 100644 --- a/tdutils/td/utils/port/detail/KQueue.cpp +++ b/tdutils/td/utils/port/detail/KQueue.cpp @@ -55,12 +55,14 @@ int KQueue::update(int nevents, const timespec *timeout, bool may_fail) { if (err != -1) { return false; } - if (may_fail) { - return kevent_errno != ENOENT; + if (may_fail && kevent_errno == ENOENT) { + return false; } return kevent_errno != EINTR; }(); - LOG_IF(FATAL, is_fatal_error) << Status::PosixError(kevent_errno, "kevent failed"); + if (is_fatal_error) { + LOG(FATAL) << Status::PosixError(kevent_errno, "kevent failed"); + } changes_n_ = 0; if (err < 0) { From d03bad88b441059fb9bdec8790de2285beab00c4 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 19:11:59 +0300 Subject: [PATCH 26/43] Improve log messages. --- td/telegram/GroupCallManager.cpp | 4 ++++ td/telegram/GroupCallParticipant.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index 587354d83..e1b7f9cba 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -1937,6 +1937,8 @@ void GroupCallManager::process_group_call_participants( } if (participants_it->second->min_order < min_order) { // if previously known more users, adjust min_order + LOG(INFO) << "Decrease min_order from " << participants_it->second->min_order << " to " << min_order << " in " + << input_group_call_id; participants_it->second->min_order = min_order; } } @@ -1948,6 +1950,8 @@ void GroupCallManager::process_group_call_participants( auto old_min_order = participants_it->second->min_order; if (old_min_order > min_order) { participants_it->second->min_order = min_order; + LOG(INFO) << "Increase min_order from " << old_min_order << " to " << min_order << " in " + << input_group_call_id; for (auto &participant : participants_it->second->participants) { auto real_order = get_real_participant_order(can_self_unmute, participant, participants_it->second.get()); diff --git a/td/telegram/GroupCallParticipant.cpp b/td/telegram/GroupCallParticipant.cpp index 741e31023..fd4a5ec16 100644 --- a/td/telegram/GroupCallParticipant.cpp +++ b/td/telegram/GroupCallParticipant.cpp @@ -272,7 +272,7 @@ bool operator!=(const GroupCallParticipant &lhs, const GroupCallParticipant &rhs } StringBuilder &operator<<(StringBuilder &string_builder, const GroupCallParticipant &group_call_participant) { - return string_builder << '[' << group_call_participant.dialog_id << " with source " + return string_builder << "GroupCallParticipant[" << group_call_participant.dialog_id << " with source " << group_call_participant.audio_source << " and order " << group_call_participant.order << ']'; } From 41d75d8c99e36bb5cddc57aa57a07f94aa0d11d1 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 17 May 2021 23:41:00 +0300 Subject: [PATCH 27/43] tg_cli: fix response printing. --- td/telegram/cli.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 830007291..de337d418 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -740,7 +740,7 @@ class CliClient final : public Actor { } } - if (id > 0 && GET_VERBOSITY_LEVEL() < VERBOSITY_NAME(td_requests)) { + if (id > 0 && combined_log.get_first_verbosity_level() < VERBOSITY_NAME(td_requests)) { LOG(ERROR) << "Receive result [" << generation << "][id=" << id << "] " << result_str; } @@ -859,7 +859,7 @@ class CliClient final : public Actor { } void on_error(uint64 generation, uint64 id, td_api::object_ptr error) { - if (id > 0 && GET_VERBOSITY_LEVEL() < VERBOSITY_NAME(td_requests)) { + if (id > 0 && combined_log.get_first_verbosity_level() < VERBOSITY_NAME(td_requests)) { LOG(ERROR) << "Receive error [" << generation << "][id=" << id << "] " << to_string(error); } } @@ -1561,11 +1561,11 @@ class CliClient final : public Actor { } static td_api::object_ptr execute(td_api::object_ptr f) { - if (GET_VERBOSITY_LEVEL() < VERBOSITY_NAME(td_requests)) { + if (combined_log.get_first_verbosity_level() < VERBOSITY_NAME(td_requests)) { LOG(ERROR) << "Execute request: " << to_string(f); } auto res = ClientActor::execute(std::move(f)); - if (GET_VERBOSITY_LEVEL() < VERBOSITY_NAME(td_requests)) { + if (combined_log.get_first_verbosity_level() < VERBOSITY_NAME(td_requests)) { LOG(ERROR) << "Execute response: " << to_string(res); } return res; From d34680b83f0d39883d5146bb94a7c0e8a20c4f84 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 May 2021 04:35:36 +0300 Subject: [PATCH 28/43] Remove set_log_fatal_error_callback. Add td_set_log_message_callback, deprecate td_set_log_fatal_error_callback. --- td/telegram/Client.cpp | 19 +++++++++++++++++++ td/telegram/Client.h | 20 ++++++++++++++++++++ td/telegram/ClientJson.h | 1 + td/telegram/Log.cpp | 15 ++++++++++----- td/telegram/Log.h | 1 + td/telegram/cli.cpp | 11 +++++++---- td/telegram/td_json_client.cpp | 5 +++++ td/telegram/td_json_client.h | 20 ++++++++++++++++++++ td/telegram/td_log.h | 1 + tdclientjson_export_list | 1 + tdutils/td/utils/FileLog.cpp | 6 +++--- tdutils/td/utils/check.cpp | 2 +- tdutils/td/utils/logging.cpp | 30 +++++++++++++++--------------- tdutils/td/utils/logging.h | 4 ---- 14 files changed, 104 insertions(+), 32 deletions(-) diff --git a/td/telegram/Client.cpp b/td/telegram/Client.cpp index 74be58155..9b764209b 100644 --- a/td/telegram/Client.cpp +++ b/td/telegram/Client.cpp @@ -659,6 +659,25 @@ td_api::object_ptr ClientManager::execute(td_api::object_ptr log_message_callback; + +static void log_message_callback_wrapper(int verbosity_level, CSlice message) { + auto callback = log_message_callback.load(std::memory_order_relaxed); + if (callback != nullptr) { + callback(verbosity_level, message.c_str()); + } +} + +void ClientManager::set_log_message_callback(int max_verbosity_level, LogMessageCallbackPtr callback) { + if (callback == nullptr) { + ::td::set_log_message_callback(max_verbosity_level, nullptr); + log_message_callback = nullptr; + } else { + log_message_callback = callback; + ::td::set_log_message_callback(max_verbosity_level, log_message_callback_wrapper); + } +} + ClientManager::~ClientManager() = default; ClientManager::ClientManager(ClientManager &&other) = default; ClientManager &ClientManager::operator=(ClientManager &&other) = default; diff --git a/td/telegram/Client.h b/td/telegram/Client.h index 47b8d67a9..5eaf480d2 100644 --- a/td/telegram/Client.h +++ b/td/telegram/Client.h @@ -238,6 +238,26 @@ class ClientManager final { */ static td_api::object_ptr execute(td_api::object_ptr &&request); + /** + * A type of callback function that will be called when a message is added to the internal TDLib log. + * + * \param verbosity_level Log verbosity level with which the message was added. + * \param message Null-terminated string with the logged message. + */ + using LogMessageCallbackPtr = void (*)(int verbosity_level, const char *message); + + /** + * Sets the callback that will be called when a message is added to the internal TDLib log. + * None of the TDLib methods can be called from the callback. + * If message verbosity level is 0, then TDLib will crash as soon as callback returns. + * By default the callback is not set. + * + * \param[in] max_verbosity_level Maximum verbosity level of messages for which the callback will be called. + * \param[in] callback Callback that will be called when a message is added to the internal TDLib log. + * Pass nullptr to remove the callback. + */ + static void set_log_message_callback(int max_verbosity_level, LogMessageCallbackPtr callback); + /** * Destroys the client manager and all TDLib client instances managed by it. */ diff --git a/td/telegram/ClientJson.h b/td/telegram/ClientJson.h index cb23b3fff..9ee879315 100644 --- a/td/telegram/ClientJson.h +++ b/td/telegram/ClientJson.h @@ -18,6 +18,7 @@ namespace td { +// TODO can be made private in TDLib 2.0 class ClientJson final { public: void send(Slice request); diff --git a/td/telegram/Log.cpp b/td/telegram/Log.cpp index add941b2c..365bf6bbf 100644 --- a/td/telegram/Log.cpp +++ b/td/telegram/Log.cpp @@ -6,6 +6,7 @@ // #include "td/telegram/Log.h" +#include "td/telegram/Client.h" #include "td/telegram/Logging.h" #include "td/telegram/td_api.h" @@ -23,9 +24,13 @@ static string log_file_path; static int64 max_log_file_size = 10 << 20; static Log::FatalErrorCallbackPtr fatal_error_callback; -static void fatal_error_callback_wrapper(CSlice message) { - CHECK(fatal_error_callback != nullptr); - fatal_error_callback(message.c_str()); +static void fatal_error_callback_wrapper(int verbosity_level, const char *message) { + if (verbosity_level == 0) { + auto callback = fatal_error_callback; + if (callback != nullptr) { + callback(message); + } + } } bool Log::set_file_path(string file_path) { @@ -59,11 +64,11 @@ void Log::set_verbosity_level(int new_verbosity_level) { void Log::set_fatal_error_callback(FatalErrorCallbackPtr callback) { std::lock_guard lock(log_mutex); if (callback == nullptr) { + ClientManager::set_log_message_callback(0, nullptr); fatal_error_callback = nullptr; - set_log_fatal_error_callback(nullptr); } else { fatal_error_callback = callback; - set_log_fatal_error_callback(fatal_error_callback_wrapper); + ClientManager::set_log_message_callback(0, fatal_error_callback_wrapper); } } diff --git a/td/telegram/Log.h b/td/telegram/Log.h index f204ece7d..7573c5b8f 100644 --- a/td/telegram/Log.h +++ b/td/telegram/Log.h @@ -76,6 +76,7 @@ class Log { * The TDLib will crash as soon as callback returns. * By default the callback is not set. * + * \deprecated Use ClientManager::set_log_message_callback instead. * \param[in] callback Callback that will be called when a fatal error happens. * Pass nullptr to remove the callback. */ diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index de337d418..92395d8cf 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -13,7 +13,7 @@ #include "td/net/HttpReader.h" #include "td/telegram/ClientActor.h" -#include "td/telegram/Log.h" +#include "td/telegram/Client.h" #include "td/telegram/Td.h" // for VERBOSITY_NAME(td_requests) #include "td/telegram/td_api_json.h" @@ -4366,8 +4366,11 @@ static void fail_signal(int sig) { } } -static void on_fatal_error(const char *error) { - std::cerr << "Fatal error: " << error << std::endl; +static void on_log_message(int verbosity_level, const char *message) { + if (verbosity_level == 0) { + std::cerr << "Fatal error: " << message; + } + std::cerr << "Log message: " << message; } void main(int argc, char **argv) { @@ -4376,7 +4379,7 @@ void main(int argc, char **argv) { ignore_signal(SignalType::Pipe).ensure(); set_signal_handler(SignalType::Error, fail_signal).ensure(); set_signal_handler(SignalType::Abort, fail_signal).ensure(); - Log::set_fatal_error_callback(on_fatal_error); + ClientManager::set_log_message_callback(0, on_log_message); init_openssl_threads(); const char *locale_name = (std::setlocale(LC_ALL, "fr-FR") == nullptr ? "C" : "fr-FR"); diff --git a/td/telegram/td_json_client.cpp b/td/telegram/td_json_client.cpp index 1a426e6d0..fa897d638 100644 --- a/td/telegram/td_json_client.cpp +++ b/td/telegram/td_json_client.cpp @@ -6,6 +6,7 @@ // #include "td/telegram/td_json_client.h" +#include "td/telegram/Client.h" #include "td/telegram/ClientJson.h" #include "td/utils/Slice.h" @@ -45,3 +46,7 @@ const char *td_receive(double timeout) { const char *td_execute(const char *request) { return td::json_execute(td::Slice(request == nullptr ? "" : request)); } + +void td_set_log_message_callback(int max_verbosity_level, td_log_message_callback_ptr callback) { + td::ClientManager::set_log_message_callback(max_verbosity_level, callback); +} diff --git a/td/telegram/td_json_client.h b/td/telegram/td_json_client.h index d72ff4c79..f2b8e09e2 100644 --- a/td/telegram/td_json_client.h +++ b/td/telegram/td_json_client.h @@ -156,6 +156,26 @@ TDJSON_EXPORT const char *td_receive(double timeout); */ TDJSON_EXPORT const char *td_execute(const char *request); +/** + * A type of callback function that will be called when a message is added to the internal TDLib log. + * + * \param verbosity_level Log verbosity level with which the message was added. + * \param message Null-terminated string with the logged message. + */ +typedef void (*td_log_message_callback_ptr)(int verbosity_level, const char *message); + +/** + * Sets the callback that will be called when a message is added to the internal TDLib log. + * None of the TDLib methods can be called from the callback. + * If message verbosity level is 0, then TDLib will crash as soon as callback returns. + * By default the callback is not set. + * + * \param[in] max_verbosity_level Maximum verbosity level of messages for which the callback will be called. + * \param[in] callback Callback that will be called when a message is added to the internal TDLib log. + * Pass nullptr to remove the callback. + */ +TDJSON_EXPORT void td_set_log_message_callback(int max_verbosity_level, td_log_message_callback_ptr callback); + #ifdef __cplusplus } // extern "C" #endif diff --git a/td/telegram/td_log.h b/td/telegram/td_log.h index 24db9e9c9..a1a4bde30 100644 --- a/td/telegram/td_log.h +++ b/td/telegram/td_log.h @@ -71,6 +71,7 @@ typedef void (*td_log_fatal_error_callback_ptr)(const char *error_message); * The TDLib will crash as soon as callback returns. * By default the callback is not set. * + * \deprecated Use td_set_log_message_callback instead. * \param[in] callback Callback that will be called when a fatal error happens. * Pass NULL to remove the callback. */ diff --git a/tdclientjson_export_list b/tdclientjson_export_list index d70976f7d..51f370e6f 100644 --- a/tdclientjson_export_list +++ b/tdclientjson_export_list @@ -11,3 +11,4 @@ _td_create_client_id _td_send _td_receive _td_execute +_td_set_log_message_callback diff --git a/tdutils/td/utils/FileLog.cpp b/tdutils/td/utils/FileLog.cpp index 23f1a257b..e5f9a56d8 100644 --- a/tdutils/td/utils/FileLog.cpp +++ b/tdutils/td/utils/FileLog.cpp @@ -74,14 +74,14 @@ void FileLog::do_append(int log_level, CSlice slice) { if (size_ > rotate_threshold_ || want_rotate_.load(std::memory_order_relaxed)) { auto status = rename(path_, PSLICE() << path_ << ".old"); if (status.is_error()) { - process_fatal_error(PSLICE() << status.error() << " in " << __FILE__ << " at " << __LINE__); + process_fatal_error(PSLICE() << status.error() << " in " << __FILE__ << " at " << __LINE__ << '\n'); } do_after_rotation(); } while (!slice.empty()) { auto r_size = fd_.write(slice); if (r_size.is_error()) { - process_fatal_error(PSLICE() << r_size.error() << " in " << __FILE__ << " at " << __LINE__); + process_fatal_error(PSLICE() << r_size.error() << " in " << __FILE__ << " at " << __LINE__ << '\n'); } auto written = r_size.ok(); size_ += static_cast(written); @@ -107,7 +107,7 @@ void FileLog::do_after_rotation() { fd_.close(); auto r_fd = FileFd::open(path_, FileFd::Create | FileFd::Truncate | FileFd::Write); if (r_fd.is_error()) { - process_fatal_error(PSLICE() << r_fd.error() << " in " << __FILE__ << " at " << __LINE__); + process_fatal_error(PSLICE() << r_fd.error() << " in " << __FILE__ << " at " << __LINE__ << '\n'); } fd_ = r_fd.move_as_ok(); if (!Stderr().empty() && redirect_stderr_) { diff --git a/tdutils/td/utils/check.cpp b/tdutils/td/utils/check.cpp index 3d78954f8..f7f60c15b 100644 --- a/tdutils/td/utils/check.cpp +++ b/tdutils/td/utils/check.cpp @@ -16,7 +16,7 @@ namespace detail { void process_check_error(const char *message, const char *file, int line) { ::td::Logger(*log_interface, log_options, VERBOSITY_NAME(FATAL), Slice(file), line, Slice()) << "Check `" << message << "` failed"; - ::td::process_fatal_error(PSLICE() << "Check `" << message << "` failed in " << file << " at " << line); + ::td::process_fatal_error(PSLICE() << "Check `" << message << "` failed in " << file << " at " << line << '\n'); } } // namespace detail diff --git a/tdutils/td/utils/logging.cpp b/tdutils/td/utils/logging.cpp index 14cfe2ba0..6fdba8fe6 100644 --- a/tdutils/td/utils/logging.cpp +++ b/tdutils/td/utils/logging.cpp @@ -32,25 +32,28 @@ namespace td { LogOptions log_options; -static std::atomic max_callback_verbosity_level = 0; -static std::atomic on_log_message_callback = nullptr; +static std::atomic max_callback_verbosity_level{-2}; +static std::atomic on_log_message_callback{nullptr}; void set_log_message_callback(int max_verbosity_level, OnLogMessageCallback callback) { + if (callback == nullptr) { + max_verbosity_level = -2; + } + max_callback_verbosity_level = max_verbosity_level; on_log_message_callback = callback; } void LogInterface::append(int log_level, CSlice slice) { do_append(log_level, slice); - if (log_level <= max_callback_verbosity_level.load(std::memory_order_relaxed)) { + if (log_level == VERBOSITY_NAME(FATAL)) { + process_fatal_error(slice); + } else if (log_level <= max_callback_verbosity_level.load(std::memory_order_relaxed)) { auto callback = on_log_message_callback.load(std::memory_order_relaxed); if (callback != nullptr) { callback(log_level, slice); } } - if (log_level == VERBOSITY_NAME(FATAL)) { - process_fatal_error(slice); - } } TD_THREAD_LOCAL const char *Logger::tag_ = nullptr; @@ -286,17 +289,14 @@ static DefaultLog default_log; LogInterface *const default_log_interface = &default_log; LogInterface *log_interface = default_log_interface; -static OnFatalErrorCallback on_fatal_error_callback = nullptr; - -void set_log_fatal_error_callback(OnFatalErrorCallback callback) { - on_fatal_error_callback = callback; -} - void process_fatal_error(CSlice message) { - auto callback = on_fatal_error_callback; - if (callback) { - callback(message); + if (0 <= max_callback_verbosity_level.load(std::memory_order_relaxed)) { + auto callback = on_log_message_callback.load(std::memory_order_relaxed); + if (callback != nullptr) { + callback(0, message); + } } + std::abort(); } diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 6e5f3cc65..89ed51a2a 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -187,10 +187,6 @@ extern LogInterface *log_interface; [[noreturn]] void process_fatal_error(CSlice message); -// deprecated in favor of set_log_message_callback -using OnFatalErrorCallback = void (*)(CSlice message); -void set_log_fatal_error_callback(OnFatalErrorCallback callback); - using OnLogMessageCallback = void (*)(int verbosity_level, CSlice message); void set_log_message_callback(int max_verbosity_level, OnLogMessageCallback callback); From e31ec28c3049998e36b2de42853006edffede4c5 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 May 2021 15:49:21 +0300 Subject: [PATCH 29/43] Python example: use td_set_log_message_callback instead of td_set_fatal_error_callback. --- example/python/tdjson_example.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/example/python/tdjson_example.py b/example/python/tdjson_example.py index 4701c2f42..62aaed502 100644 --- a/example/python/tdjson_example.py +++ b/example/python/tdjson_example.py @@ -34,16 +34,17 @@ _td_execute = tdjson.td_execute _td_execute.restype = c_char_p _td_execute.argtypes = [c_char_p] -fatal_error_callback_type = CFUNCTYPE(None, c_char_p) +log_message_callback_type = CFUNCTYPE(None, c_int, c_char_p) -_td_set_log_fatal_error_callback = tdjson.td_set_log_fatal_error_callback -_td_set_log_fatal_error_callback.restype = None -_td_set_log_fatal_error_callback.argtypes = [fatal_error_callback_type] +_td_set_log_message_callback = tdjson.td_set_log_message_callback +_td_set_log_message_callback.restype = None +_td_set_log_message_callback.argtypes = [c_int, log_message_callback_type] # initialize TDLib log with desired parameters -def on_fatal_error_callback(error_message): - print('TDLib fatal error: ', error_message) - sys.stdout.flush() +def on_log_message_callback(verbosity_level, message): + if verbosity_level == 0: + print('TDLib fatal error: ', message) + sys.stdout.flush() def td_execute(query): query = json.dumps(query).encode('utf-8') @@ -52,8 +53,8 @@ def td_execute(query): result = json.loads(result.decode('utf-8')) return result -c_on_fatal_error_callback = fatal_error_callback_type(on_fatal_error_callback) -_td_set_log_fatal_error_callback(c_on_fatal_error_callback) +c_on_log_message_callback = log_message_callback_type(on_log_message_callback) +_td_set_log_message_callback(2, c_on_log_message_callback) # setting TDLib log verbosity level to 1 (errors) print(str(td_execute({'@type': 'setLogVerbosityLevel', 'new_verbosity_level': 1, '@extra': 1.01234})).encode('utf-8')) From 9ad1b3b49a5b07d5b23735105815b667f4eed957 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 May 2021 16:36:11 +0300 Subject: [PATCH 30/43] Use set_log_message_callback in Java example. --- example/java/td_jni.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/example/java/td_jni.cpp b/example/java/td_jni.cpp index e5a204250..7e2974feb 100644 --- a/example/java/td_jni.cpp +++ b/example/java/td_jni.cpp @@ -101,7 +101,10 @@ static constexpr jint JAVA_VERSION = JNI_VERSION_1_6; static JavaVM *java_vm; static jclass log_class; -static void on_fatal_error(const char *error_message) { +static void on_log_message(int verbosity_level, const char *error_message) { + if (verbosity_level != 0) { + return; + } auto env = td::jni::get_jni_env(java_vm, JAVA_VERSION); if (env == nullptr) { return; @@ -154,7 +157,7 @@ static jint register_native(JavaVM *vm) { td::jni::init_vars(env, PACKAGE_NAME); td::td_api::Object::init_jni_vars(env, PACKAGE_NAME); td::td_api::Function::init_jni_vars(env, PACKAGE_NAME); - td::Log::set_fatal_error_callback(on_fatal_error); + td::ClientManager::set_log_message_callback(0, on_log_message); return JAVA_VERSION; } From f72195baabae8c29d9531dd22e7b06f4b4acad05 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 May 2021 16:55:35 +0300 Subject: [PATCH 31/43] Remove TC_* defines. --- td/telegram/cli.cpp | 10 +--------- tdutils/td/utils/logging.cpp | 11 ++++++----- tdutils/td/utils/logging.h | 7 ------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 92395d8cf..1aae9875c 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -197,15 +197,7 @@ class CliLog : public LogInterface { reactivate_readline(); }; #endif - if (log_level == VERBOSITY_NAME(PLAIN)) { -#if TD_WINDOWS - TsCerr() << slice; -#else - TsCerr() << TC_GREEN << slice << TC_EMPTY; -#endif - } else { - default_log_interface->do_append(log_level, slice); - } + default_log_interface->do_append(log_level, slice); } }; diff --git a/tdutils/td/utils/logging.cpp b/tdutils/td/utils/logging.cpp index 6fdba8fe6..abe79b2bb 100644 --- a/tdutils/td/utils/logging.cpp +++ b/tdutils/td/utils/logging.cpp @@ -264,19 +264,20 @@ class DefaultLog : public LogInterface { switch (log_level) { case VERBOSITY_NAME(FATAL): case VERBOSITY_NAME(ERROR): - color = Slice(TC_RED); + color = Slice("\x1b[1;31m"); // red break; case VERBOSITY_NAME(WARNING): - color = Slice(TC_YELLOW); + color = Slice("\x1b[1;33m"); // yellow break; case VERBOSITY_NAME(INFO): - color = Slice(TC_CYAN); + color = Slice("\x1b[1;36m"); // cyan break; } + Slice no_color("\x1b[0m"); if (!slice.empty() && slice.back() == '\n') { - TsCerr() << color << slice.substr(0, slice.size() - 1) << TC_EMPTY "\n"; + TsCerr() << color << slice.substr(0, slice.size() - 1) << no_color << "\n"; } else { - TsCerr() << color << slice << TC_EMPTY; + TsCerr() << color << slice << no_color; } #else // TODO: color diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 89ed51a2a..1c59c388f 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -190,13 +190,6 @@ extern LogInterface *log_interface; using OnLogMessageCallback = void (*)(int verbosity_level, CSlice message); void set_log_message_callback(int max_verbosity_level, OnLogMessageCallback callback); -#define TC_RED "\x1b[1;31m" -#define TC_BLUE "\x1b[1;34m" -#define TC_CYAN "\x1b[1;36m" -#define TC_GREEN "\x1b[1;32m" -#define TC_YELLOW "\x1b[1;33m" -#define TC_EMPTY "\x1b[0m" - class TsCerr { public: TsCerr(); From 674a112bfa7d19cd68bccc43b1fcc458a9e5bf8c Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 May 2021 17:06:22 +0300 Subject: [PATCH 32/43] Add NullLog.h. --- td/telegram/Logging.cpp | 1 + td/telegram/cli.cpp | 1 + tdutils/CMakeLists.txt | 1 + tdutils/td/utils/NullLog.h | 19 +++++++++++++++++++ tdutils/td/utils/logging.h | 5 ----- tdutils/test/log.cpp | 1 + 6 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 tdutils/td/utils/NullLog.h diff --git a/td/telegram/Logging.cpp b/td/telegram/Logging.cpp index 3c0d6bbe2..abf7ec71c 100644 --- a/td/telegram/Logging.cpp +++ b/td/telegram/Logging.cpp @@ -32,6 +32,7 @@ #include "td/utils/algorithm.h" #include "td/utils/ExitGuard.h" #include "td/utils/FileLog.h" +#include "td/utils/NullLog.h" #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/detail/NativeFd.h" diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 1aae9875c..65e271762 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -30,6 +30,7 @@ #include "td/utils/JsonBuilder.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/NullLog.h" #include "td/utils/OptionParser.h" #include "td/utils/port/FileFd.h" #include "td/utils/port/PollFlags.h" diff --git a/tdutils/CMakeLists.txt b/tdutils/CMakeLists.txt index 4db85ab35..beb9eb0eb 100644 --- a/tdutils/CMakeLists.txt +++ b/tdutils/CMakeLists.txt @@ -221,6 +221,7 @@ set(TDUTILS_SOURCE td/utils/MpscPollableQueue.h td/utils/MpscLinkQueue.h td/utils/Named.h + td/utils/NullLog.h td/utils/ObjectPool.h td/utils/Observer.h td/utils/optional.h diff --git a/tdutils/td/utils/NullLog.h b/tdutils/td/utils/NullLog.h new file mode 100644 index 000000000..0752eceea --- /dev/null +++ b/tdutils/td/utils/NullLog.h @@ -0,0 +1,19 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 +// +// 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 + +#include "td/utils/logging.h" +#include "td/utils/Slice.h" + +namespace td { + +class NullLog : public LogInterface { + void do_append(int /*log_level*/, CSlice /*slice*/) final { + } +}; + +} // namespace td diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 1c59c388f..55f92aeb4 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -177,11 +177,6 @@ class LogInterface { virtual void do_append(int log_level, CSlice slice) = 0; }; -class NullLog : public LogInterface { - void do_append(int /*log_level*/, CSlice /*slice*/) final { - } -}; - extern LogInterface *const default_log_interface; extern LogInterface *log_interface; diff --git a/tdutils/test/log.cpp b/tdutils/test/log.cpp index 078ddf860..63637ce36 100644 --- a/tdutils/test/log.cpp +++ b/tdutils/test/log.cpp @@ -10,6 +10,7 @@ #include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/MemoryLog.h" +#include "td/utils/NullLog.h" #include "td/utils/port/path.h" #include "td/utils/port/thread.h" #include "td/utils/Slice.h" From df4c4b94714ca8aaecb3afb87e67a55b5203ca47 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 May 2021 17:24:32 +0300 Subject: [PATCH 33/43] Move TsCerr to separate header. --- benchmark/check_proxy.cpp | 1 + tdutils/CMakeLists.txt | 2 ++ tdutils/td/utils/TsCerr.cpp | 64 ++++++++++++++++++++++++++++++++++++ tdutils/td/utils/TsCerr.h | 33 +++++++++++++++++++ tdutils/td/utils/logging.cpp | 51 +--------------------------- tdutils/td/utils/logging.h | 18 ---------- 6 files changed, 101 insertions(+), 68 deletions(-) create mode 100644 tdutils/td/utils/TsCerr.cpp create mode 100644 tdutils/td/utils/TsCerr.h diff --git a/benchmark/check_proxy.cpp b/benchmark/check_proxy.cpp index 3e60610b9..965418cec 100644 --- a/benchmark/check_proxy.cpp +++ b/benchmark/check_proxy.cpp @@ -12,6 +12,7 @@ #include "td/utils/filesystem.h" #include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/TsCerr.h" #include #include diff --git a/tdutils/CMakeLists.txt b/tdutils/CMakeLists.txt index beb9eb0eb..5f311cc8e 100644 --- a/tdutils/CMakeLists.txt +++ b/tdutils/CMakeLists.txt @@ -114,6 +114,7 @@ set(TDUTILS_SOURCE td/utils/TsFileLog.cpp td/utils/tl_parsers.cpp td/utils/translit.cpp + td/utils/TsCerr.cpp td/utils/TsFileLog.cpp td/utils/unicode.cpp td/utils/utf8.cpp @@ -257,6 +258,7 @@ set(TDUTILS_SOURCE td/utils/tl_parsers.h td/utils/tl_storers.h td/utils/translit.h + td/utils/TsCerr.h td/utils/TsFileLog.h td/utils/TsList.h td/utils/type_traits.h diff --git a/tdutils/td/utils/TsCerr.cpp b/tdutils/td/utils/TsCerr.cpp new file mode 100644 index 000000000..3ef759a13 --- /dev/null +++ b/tdutils/td/utils/TsCerr.cpp @@ -0,0 +1,64 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 +// +// 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) +// +#include "td/utils/TsCerr.h" + +#include "td/utils/ExitGuard.h" +#include "td/utils/port/StdStreams.h" +#include "td/utils/Time.h" + +#include + +namespace td { + +std::atomic_flag TsCerr::lock_ = ATOMIC_FLAG_INIT; + +TsCerr::TsCerr() { + enterCritical(); +} + +TsCerr::~TsCerr() { + exitCritical(); +} + +TsCerr &TsCerr::operator<<(Slice slice) { + auto &fd = Stderr(); + if (fd.empty()) { + return *this; + } + double end_time = 0; + while (!slice.empty()) { + auto res = fd.write(slice); + if (res.is_error()) { + if (res.error().code() == EPIPE) { + break; + } + // Resource temporary unavailable + if (end_time == 0) { + end_time = Time::now() + 0.01; + } else if (Time::now() > end_time) { + break; + } + continue; + } + slice.remove_prefix(res.ok()); + } + return *this; +} + +void TsCerr::enterCritical() { + while (lock_.test_and_set(std::memory_order_acquire) && !ExitGuard::is_exited()) { + // spin + } +} + +void TsCerr::exitCritical() { + lock_.clear(std::memory_order_release); +} + +static ExitGuard exit_guard; + +} // namespace td diff --git a/tdutils/td/utils/TsCerr.h b/tdutils/td/utils/TsCerr.h new file mode 100644 index 000000000..8ef4942e3 --- /dev/null +++ b/tdutils/td/utils/TsCerr.h @@ -0,0 +1,33 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 +// +// 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 + +#include "td/utils/Slice.h" + +#include + +namespace td { + +class TsCerr { + public: + TsCerr(); + TsCerr(const TsCerr &) = delete; + TsCerr &operator=(const TsCerr &) = delete; + TsCerr(TsCerr &&) = delete; + TsCerr &operator=(TsCerr &&) = delete; + ~TsCerr(); + + TsCerr &operator<<(Slice slice); + + private: + static std::atomic_flag lock_; + + void enterCritical(); + void exitCritical(); +}; + +} // namespace td diff --git a/tdutils/td/utils/logging.cpp b/tdutils/td/utils/logging.cpp index abe79b2bb..3133349cc 100644 --- a/tdutils/td/utils/logging.cpp +++ b/tdutils/td/utils/logging.cpp @@ -8,10 +8,9 @@ #include "td/utils/ExitGuard.h" #include "td/utils/port/Clocks.h" -#include "td/utils/port/StdStreams.h" #include "td/utils/port/thread_local.h" #include "td/utils/Slice.h" -#include "td/utils/Time.h" +#include "td/utils/TsCerr.h" #include #include @@ -151,54 +150,6 @@ Logger::~Logger() { } } -TsCerr::TsCerr() { - enterCritical(); -} -TsCerr::~TsCerr() { - exitCritical(); -} -TsCerr &TsCerr::operator<<(Slice slice) { - auto &fd = Stderr(); - if (fd.empty()) { - return *this; - } - double end_time = 0; - while (!slice.empty()) { - auto res = fd.write(slice); - if (res.is_error()) { - if (res.error().code() == EPIPE) { - break; - } - // Resource temporary unavailable - if (end_time == 0) { - end_time = Time::now() + 0.01; - } else if (Time::now() > end_time) { - break; - } - continue; - } - slice.remove_prefix(res.ok()); - } - return *this; -} - -void TsCerr::enterCritical() { - while (lock_.test_and_set(std::memory_order_acquire) && !ExitGuard::is_exited()) { - // spin - } -} - -void TsCerr::exitCritical() { - lock_.clear(std::memory_order_release); -} -TsCerr::Lock TsCerr::lock_ = ATOMIC_FLAG_INIT; - -void TsLog::enter_critical() { - while (lock_.test_and_set(std::memory_order_acquire) && !ExitGuard::is_exited()) { - // spin - } -} - void TsLog::exit_critical() { lock_.clear(std::memory_order_release); } diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 55f92aeb4..e7ee57fde 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -185,24 +185,6 @@ extern LogInterface *log_interface; using OnLogMessageCallback = void (*)(int verbosity_level, CSlice message); void set_log_message_callback(int max_verbosity_level, OnLogMessageCallback callback); -class TsCerr { - public: - TsCerr(); - TsCerr(const TsCerr &) = delete; - TsCerr &operator=(const TsCerr &) = delete; - TsCerr(TsCerr &&) = delete; - TsCerr &operator=(TsCerr &&) = delete; - ~TsCerr(); - TsCerr &operator<<(Slice slice); - - private: - using Lock = std::atomic_flag; - static Lock lock_; - - void enterCritical(); - void exitCritical(); -}; - class Logger { static const size_t BUFFER_SIZE = 128 * 1024; From 7edffa1bc72ea52241cdd7a176d40d0bbca13105 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 May 2021 17:40:37 +0300 Subject: [PATCH 34/43] Move TsLog out of logging.h. --- td/telegram/Logging.cpp | 1 + td/telegram/cli.cpp | 1 + tdutils/CMakeLists.txt | 2 ++ tdutils/td/utils/TsLog.cpp | 21 ++++++++++++++ tdutils/td/utils/TsLog.h | 55 ++++++++++++++++++++++++++++++++++++ tdutils/td/utils/logging.cpp | 4 --- tdutils/td/utils/logging.h | 54 +++++++---------------------------- tdutils/test/log.cpp | 1 + 8 files changed, 91 insertions(+), 48 deletions(-) create mode 100644 tdutils/td/utils/TsLog.cpp create mode 100644 tdutils/td/utils/TsLog.h diff --git a/td/telegram/Logging.cpp b/td/telegram/Logging.cpp index abf7ec71c..728dec8ac 100644 --- a/td/telegram/Logging.cpp +++ b/td/telegram/Logging.cpp @@ -36,6 +36,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/detail/NativeFd.h" +#include "td/utils/TsLog.h" #include #include diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 65e271762..fa0f548d6 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -45,6 +45,7 @@ #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/Time.h" +#include "td/utils/TsLog.h" #include "td/utils/utf8.h" #ifndef USE_READLINE diff --git a/tdutils/CMakeLists.txt b/tdutils/CMakeLists.txt index 5f311cc8e..128c98fb7 100644 --- a/tdutils/CMakeLists.txt +++ b/tdutils/CMakeLists.txt @@ -116,6 +116,7 @@ set(TDUTILS_SOURCE td/utils/translit.cpp td/utils/TsCerr.cpp td/utils/TsFileLog.cpp + td/utils/TsLog.cpp td/utils/unicode.cpp td/utils/utf8.cpp @@ -261,6 +262,7 @@ set(TDUTILS_SOURCE td/utils/TsCerr.h td/utils/TsFileLog.h td/utils/TsList.h + td/utils/TsLog.h td/utils/type_traits.h td/utils/UInt.h td/utils/uint128.h diff --git a/tdutils/td/utils/TsLog.cpp b/tdutils/td/utils/TsLog.cpp new file mode 100644 index 000000000..fe63114de --- /dev/null +++ b/tdutils/td/utils/TsLog.cpp @@ -0,0 +1,21 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 +// +// 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) +// +#include "td/utils/TsLog.h" + +#include "td/utils/ExitGuard.h" + +namespace td { + +void TsLog::enter_critical() { + while (lock_.test_and_set(std::memory_order_acquire) && !ExitGuard::is_exited()) { + // spin + } +} + +static ExitGuard exit_guard; + +} // namespace td diff --git a/tdutils/td/utils/TsLog.h b/tdutils/td/utils/TsLog.h new file mode 100644 index 000000000..4dfb3e44d --- /dev/null +++ b/tdutils/td/utils/TsLog.h @@ -0,0 +1,55 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 +// +// 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 + +#include "td/utils/common.h" +#include "td/utils/logging.h" +#include "td/utils/Slice.h" + +#include + +namespace td { + +class TsLog : public LogInterface { + public: + explicit TsLog(LogInterface *log) : log_(log) { + } + void init(LogInterface *log) { + enter_critical(); + log_ = log; + exit_critical(); + } + void after_rotation() final { + enter_critical(); + log_->after_rotation(); + exit_critical(); + } + vector get_file_paths() final { + enter_critical(); + auto result = log_->get_file_paths(); + exit_critical(); + return result; + } + + private: + void do_append(int log_level, CSlice slice) final { + enter_critical(); + log_->do_append(log_level, slice); + exit_critical(); + } + + void enter_critical(); + + void exit_critical() { + lock_.clear(std::memory_order_release); + } + + LogInterface *log_ = nullptr; + std::atomic_flag lock_ = ATOMIC_FLAG_INIT; +}; + +} // namespace td diff --git a/tdutils/td/utils/logging.cpp b/tdutils/td/utils/logging.cpp index 3133349cc..692b6cfb9 100644 --- a/tdutils/td/utils/logging.cpp +++ b/tdutils/td/utils/logging.cpp @@ -150,10 +150,6 @@ Logger::~Logger() { } } -void TsLog::exit_critical() { - lock_.clear(std::memory_order_release); -} - class DefaultLog : public LogInterface { void do_append(int log_level, CSlice slice) final { #if TD_ANDROID diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index e7ee57fde..1bfb8d693 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -146,16 +146,6 @@ inline int get_verbosity_level() { return log_options.get_level(); } -class ScopedDisableLog { - public: - ScopedDisableLog(); - ScopedDisableLog(const ScopedDisableLog &) = delete; - ScopedDisableLog &operator=(const ScopedDisableLog &) = delete; - ScopedDisableLog(ScopedDisableLog &&) = delete; - ScopedDisableLog &operator=(ScopedDisableLog &&) = delete; - ~ScopedDisableLog(); -}; - class LogInterface { public: LogInterface() = default; @@ -228,6 +218,16 @@ class Logger { int log_level_; }; +class ScopedDisableLog { + public: + ScopedDisableLog(); + ScopedDisableLog(const ScopedDisableLog &) = delete; + ScopedDisableLog &operator=(const ScopedDisableLog &) = delete; + ScopedDisableLog(ScopedDisableLog &&) = delete; + ScopedDisableLog &operator=(ScopedDisableLog &&) = delete; + ~ScopedDisableLog(); +}; + namespace detail { class Voidify { public: @@ -237,38 +237,4 @@ class Voidify { }; } // namespace detail -class TsLog : public LogInterface { - public: - explicit TsLog(LogInterface *log) : log_(log) { - } - void init(LogInterface *log) { - enter_critical(); - log_ = log; - exit_critical(); - } - void after_rotation() final { - enter_critical(); - log_->after_rotation(); - exit_critical(); - } - vector get_file_paths() final { - enter_critical(); - auto result = log_->get_file_paths(); - exit_critical(); - return result; - } - - private: - void do_append(int log_level, CSlice slice) final { - enter_critical(); - log_->do_append(log_level, slice); - exit_critical(); - } - - LogInterface *log_ = nullptr; - std::atomic_flag lock_ = ATOMIC_FLAG_INIT; - void enter_critical(); - void exit_critical(); -}; - } // namespace td diff --git a/tdutils/test/log.cpp b/tdutils/test/log.cpp index 63637ce36..de15185f3 100644 --- a/tdutils/test/log.cpp +++ b/tdutils/test/log.cpp @@ -17,6 +17,7 @@ #include "td/utils/SliceBuilder.h" #include "td/utils/tests.h" #include "td/utils/TsFileLog.h" +#include "td/utils/TsLog.h" #include #include From d710058f2a555832d19538ef9a8b88c3efb0b002 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 May 2021 01:57:38 +0300 Subject: [PATCH 35/43] Move value checks in get_background_fill. --- td/telegram/BackgroundType.cpp | 51 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/td/telegram/BackgroundType.cpp b/td/telegram/BackgroundType.cpp index 276df90ac..ea6f0beb6 100644 --- a/td/telegram/BackgroundType.cpp +++ b/td/telegram/BackgroundType.cpp @@ -20,15 +20,33 @@ static string get_color_hex_string(int32 color) { return result; } -static BackgroundFill get_background_fill(const td_api::BackgroundFill *fill) { - CHECK(fill != nullptr); +static bool is_valid_color(int32 color) { + return 0 <= color && color <= 0xFFFFFF; +} + +static Result get_background_fill(const td_api::BackgroundFill *fill) { + if (fill == nullptr) { + return Status::Error(400, "Background fill info must be non-empty"); + } switch (fill->get_id()) { case td_api::backgroundFillSolid::ID: { auto solid = static_cast(fill); + if (!is_valid_color(solid->color_)) { + return Status::Error(400, "Invalid solid fill color value"); + } return BackgroundFill(solid->color_); } case td_api::backgroundFillGradient::ID: { auto gradient = static_cast(fill); + if (!is_valid_color(gradient->top_color_)) { + return Status::Error(400, "Invalid top gradient color value"); + } + if (!is_valid_color(gradient->bottom_color_)) { + return Status::Error(400, "Invalid bottom gradient color value"); + } + if (!BackgroundFill::is_valid_rotation_angle(gradient->rotation_angle_)) { + return Status::Error(400, "Invalid rotation angle value"); + } return BackgroundFill(gradient->top_color_, gradient->bottom_color_, gradient->rotation_angle_); } default: @@ -49,10 +67,6 @@ static string get_background_fill_color_hex_string(const BackgroundFill &fill, b } } -static bool is_valid_color(int32 color) { - return 0 <= color && color <= 0xFFFFFF; -} - static bool is_valid_intensity(int32 intensity) { return 0 <= intensity && intensity <= 100; } @@ -149,35 +163,22 @@ Result get_background_type(const td_api::BackgroundType *type) { } case td_api::backgroundTypePattern::ID: { auto pattern = static_cast(type); - if (pattern->fill_ == nullptr) { - return Status::Error(400, "Fill info must be non-empty"); + TRY_RESULT(background_fill, get_background_fill(pattern->fill_.get())); + if (!is_valid_intensity(pattern->intensity_)) { + return Status::Error(400, "Wrong intensity value"); } - result = BackgroundType(pattern->is_moving_, get_background_fill(pattern->fill_.get()), pattern->intensity_); + result = BackgroundType(pattern->is_moving_, std::move(background_fill), pattern->intensity_); break; } case td_api::backgroundTypeFill::ID: { auto fill = static_cast(type); - if (fill->fill_ == nullptr) { - return Status::Error(400, "Fill info must be non-empty"); - } - result = BackgroundType(get_background_fill(fill->fill_.get())); + TRY_RESULT(background_fill, get_background_fill(fill->fill_.get())); + result = BackgroundType(std::move(background_fill)); break; } default: UNREACHABLE(); } - if (!is_valid_intensity(result.intensity)) { - return Status::Error(400, "Wrong intensity value"); - } - if (!is_valid_color(result.fill.top_color)) { - return Status::Error(400, result.fill.is_solid() ? Slice("Wrong color value") : ("Wrong top color value")); - } - if (!is_valid_color(result.fill.bottom_color)) { - return Status::Error(400, "Wrong bottom color value"); - } - if (!BackgroundFill::is_valid_rotation_angle(result.fill.rotation_angle)) { - return Status::Error(400, "Wrong rotation angle value"); - } return result; } From 5dcd25462379bc14fa6c0e5fd4e79339bb2695de Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 May 2021 02:21:20 +0300 Subject: [PATCH 36/43] Add BackgroundFill::Type, --- td/telegram/BackgroundType.cpp | 73 +++++++++++++++++++++------------- td/telegram/BackgroundType.h | 8 +++- td/telegram/BackgroundType.hpp | 3 +- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/td/telegram/BackgroundType.cpp b/td/telegram/BackgroundType.cpp index ea6f0beb6..e23a4393d 100644 --- a/td/telegram/BackgroundType.cpp +++ b/td/telegram/BackgroundType.cpp @@ -56,14 +56,20 @@ static Result get_background_fill(const td_api::BackgroundFill * } static string get_background_fill_color_hex_string(const BackgroundFill &fill, bool is_first) { - if (fill.is_solid()) { - return get_color_hex_string(fill.top_color); - } else { - string colors = PSTRING() << get_color_hex_string(fill.top_color) << '-' << get_color_hex_string(fill.bottom_color); - if (fill.rotation_angle != 0) { - colors += (PSTRING() << (is_first ? '?' : '&') << "rotation=" << fill.rotation_angle); + switch (fill.get_type()) { + case BackgroundFill::Type::Solid: + return get_color_hex_string(fill.top_color); + case BackgroundFill::Type::Gradient: { + string colors = PSTRING() << get_color_hex_string(fill.top_color) << '-' + << get_color_hex_string(fill.bottom_color); + if (fill.rotation_angle != 0) { + colors += (PSTRING() << (is_first ? '?' : '&') << "rotation=" << fill.rotation_angle); + } + return colors; } - return colors; + default: + UNREACHABLE(); + return string(); } } @@ -75,10 +81,16 @@ int64 BackgroundFill::get_id() const { CHECK(is_valid_color(top_color)); CHECK(is_valid_color(bottom_color)); CHECK(is_valid_rotation_angle(rotation_angle)); - if (is_solid()) { - return static_cast(top_color) + 1; + switch (get_type()) { + case Type::Solid: + return static_cast(top_color) + 1; + case Type::Gradient: + return (rotation_angle / 45) * 0x1000001000001 + (static_cast(top_color) << 24) + bottom_color + + (1 << 24) + 1; + default: + UNREACHABLE(); + return 0; } - return (rotation_angle / 45) * 0x1000001000001 + (static_cast(top_color) << 24) + bottom_color + (1 << 24) + 1; } bool BackgroundFill::is_valid_id(int64 id) { @@ -235,10 +247,16 @@ BackgroundType get_background_type(bool is_pattern, } static td_api::object_ptr get_background_fill_object(const BackgroundFill &fill) { - if (fill.is_solid()) { - return td_api::make_object(fill.top_color); + switch (fill.get_type()) { + case BackgroundFill::Type::Solid: + return td_api::make_object(fill.top_color); + case BackgroundFill::Type::Gradient: + return td_api::make_object(fill.top_color, fill.bottom_color, + fill.rotation_angle); + default: + UNREACHABLE(); + return nullptr; } - return td_api::make_object(fill.top_color, fill.bottom_color, fill.rotation_angle); } td_api::object_ptr get_background_type_object(const BackgroundType &type) { @@ -257,6 +275,8 @@ td_api::object_ptr get_background_type_object(const Back } telegram_api::object_ptr get_input_wallpaper_settings(const BackgroundType &type) { + CHECK(type.is_server()); + int32 flags = 0; if (type.is_blurred) { flags |= telegram_api::wallPaperSettings::BLUR_MASK; @@ -264,23 +284,22 @@ telegram_api::object_ptr get_input_wallpaper_se if (type.is_moving) { flags |= telegram_api::wallPaperSettings::MOTION_MASK; } - if (type.fill.top_color != 0 || type.fill.bottom_color != 0) { - flags |= telegram_api::wallPaperSettings::BACKGROUND_COLOR_MASK; + switch (type.fill.get_type()) { + case BackgroundFill::Type::Gradient: + flags |= telegram_api::wallPaperSettings::SECOND_BACKGROUND_COLOR_MASK; + // fallthrough + case BackgroundFill::Type::Solid: + flags |= telegram_api::wallPaperSettings::BACKGROUND_COLOR_MASK; + break; + default: + UNREACHABLE(); } - if (!type.fill.is_solid()) { - flags |= telegram_api::wallPaperSettings::SECOND_BACKGROUND_COLOR_MASK; - } - if (type.intensity) { + if (type.intensity != 0) { flags |= telegram_api::wallPaperSettings::INTENSITY_MASK; } - if (type.is_server()) { - return telegram_api::make_object(flags, false /*ignored*/, false /*ignored*/, - type.fill.top_color, type.fill.bottom_color, - type.intensity, type.fill.rotation_angle); - } - - UNREACHABLE(); - return nullptr; + return telegram_api::make_object(flags, false /*ignored*/, false /*ignored*/, + type.fill.top_color, type.fill.bottom_color, + type.intensity, type.fill.rotation_angle); } } // namespace td diff --git a/td/telegram/BackgroundType.h b/td/telegram/BackgroundType.h index 56b0fe1c2..a41a01bdb 100644 --- a/td/telegram/BackgroundType.h +++ b/td/telegram/BackgroundType.h @@ -27,8 +27,12 @@ struct BackgroundFill { : top_color(top_color), bottom_color(bottom_color), rotation_angle(rotation_angle) { } - bool is_solid() const { - return top_color == bottom_color; + enum class Type : int32 { Solid, Gradient }; + Type get_type() const { + if (top_color == bottom_color) { + return Type::Solid; + } + return Type::Gradient; } int64 get_id() const; diff --git a/td/telegram/BackgroundType.hpp b/td/telegram/BackgroundType.hpp index b6ef4a91e..c8b008b47 100644 --- a/td/telegram/BackgroundType.hpp +++ b/td/telegram/BackgroundType.hpp @@ -16,7 +16,8 @@ template void store(const BackgroundType &type, StorerT &storer) { bool has_fill = type.fill.top_color != 0 || type.fill.bottom_color != 0; bool has_intensity = type.intensity != 0; - bool is_gradient = !type.fill.is_solid(); + auto fill_type = type.fill.get_type(); + bool is_gradient = fill_type == BackgroundFill::Type::Gradient; BEGIN_STORE_FLAGS(); STORE_FLAG(type.is_blurred); STORE_FLAG(type.is_moving); From a0728a947669c967231667c45bffa660553213ab Mon Sep 17 00:00:00 2001 From: Fela Ameghino Date: Thu, 20 May 2021 01:36:47 +0200 Subject: [PATCH 37/43] Added SetFatalErrorCallback to CX/CLI Client (#1490) --- td/telegram/ClientDotNet.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/td/telegram/ClientDotNet.cpp b/td/telegram/ClientDotNet.cpp index 5eec5ad55..72a4c229a 100644 --- a/td/telegram/ClientDotNet.cpp +++ b/td/telegram/ClientDotNet.cpp @@ -6,6 +6,7 @@ // #pragma managed(push, off) #include "td/telegram/Client.h" +#include "td/telegram/Log.h" #pragma managed(pop) #include "td/telegram/TdDotNetApi.h" @@ -21,6 +22,12 @@ namespace Td { using namespace CxCli; +/// +/// A type of callback function that will be called when a fatal error happens. +/// +/// Null-terminated string with a description of a happened fatal error. +public delegate void FatalErrorCallback(String^ errorMessage); + /// /// Interface for handler for results of queries to TDLib and incoming updates from TDLib. /// @@ -105,6 +112,21 @@ public: return REF_NEW Client(updateHandler); } + /// + /// Sets the callback that will be called when a fatal error happens. + /// + /// Callback that will be called when a fatal error happens. Pass null to remove the callback. + static void SetFatalErrorCallback(FatalErrorCallback^ callback) { + std::lock_guard lock(logMutex); + if (callback == nullptr) { + ::td::Log::set_fatal_error_callback(nullptr); + fatalErrorCallback = nullptr; + } else { + fatalErrorCallback = callback; + ::td::Log::set_fatal_error_callback(FatalErrorCallbackWrapper); + } + } + private: Client(ClientResultHandler^ updateHandler) { client = new td::Client(); @@ -127,7 +149,18 @@ private: handler->OnResult(object); } } + + static std::mutex logMutex; + static FatalErrorCallback^ fatalErrorCallback; + + static void FatalErrorCallbackWrapper(const char* message) { + CHECK(fatalErrorCallback != nullptr); + fatalErrorCallback(string_from_unmanaged(message)); + } }; +std::mutex Client::logMutex; +FatalErrorCallback^ Client::fatalErrorCallback; + } // namespace Td } // namespace Telegram From 58a12aca833b46f09fcf4ab6267b8cd5fdfe6b3b Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 May 2021 02:54:49 +0300 Subject: [PATCH 38/43] Support logMessageCallback in .NET bindings. --- td/telegram/Client.h | 6 +++--- td/telegram/ClientDotNet.cpp | 38 +++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/td/telegram/Client.h b/td/telegram/Client.h index 5eaf480d2..b61dc60d9 100644 --- a/td/telegram/Client.h +++ b/td/telegram/Client.h @@ -241,15 +241,15 @@ class ClientManager final { /** * A type of callback function that will be called when a message is added to the internal TDLib log. * - * \param verbosity_level Log verbosity level with which the message was added. - * \param message Null-terminated string with the logged message. + * \param verbosity_level Log verbosity level with which the message was added. If 0, then TDLib will crash + * as soon as the callback returns. + * \param message Null-terminated string with the message added to the log. */ using LogMessageCallbackPtr = void (*)(int verbosity_level, const char *message); /** * Sets the callback that will be called when a message is added to the internal TDLib log. * None of the TDLib methods can be called from the callback. - * If message verbosity level is 0, then TDLib will crash as soon as callback returns. * By default the callback is not set. * * \param[in] max_verbosity_level Maximum verbosity level of messages for which the callback will be called. diff --git a/td/telegram/ClientDotNet.cpp b/td/telegram/ClientDotNet.cpp index 72a4c229a..56cb0be31 100644 --- a/td/telegram/ClientDotNet.cpp +++ b/td/telegram/ClientDotNet.cpp @@ -6,7 +6,6 @@ // #pragma managed(push, off) #include "td/telegram/Client.h" -#include "td/telegram/Log.h" #pragma managed(pop) #include "td/telegram/TdDotNetApi.h" @@ -23,10 +22,12 @@ namespace Td { using namespace CxCli; /// -/// A type of callback function that will be called when a fatal error happens. +/// A type of callback function that will be called when a message is added to the internal TDLib log. /// -/// Null-terminated string with a description of a happened fatal error. -public delegate void FatalErrorCallback(String^ errorMessage); +/// Log verbosity level with which the message was added. If 0, +/// then TDLib will crash as soon as the callback returns. +/// Null-terminated string with the message added to the log. +public delegate void LogMessageCallback(int verbosityLevel, String^ message); /// /// Interface for handler for results of queries to TDLib and incoming updates from TDLib. @@ -113,17 +114,20 @@ public: } /// - /// Sets the callback that will be called when a fatal error happens. + /// Sets the callback that will be called when a message is added to the internal TDLib log. + /// None of the TDLib methods can be called from the callback. /// - /// Callback that will be called when a fatal error happens. Pass null to remove the callback. - static void SetFatalErrorCallback(FatalErrorCallback^ callback) { + /// Maximum verbosity level of messages for which the callback will be called. + /// Callback that will be called when a message is added to the internal TDLib log. + /// Pass null to remove the callback. + static void SetLogMessageCallback(std::int32_t max_verbosity_level, LogMessageCallback^ callback) { std::lock_guard lock(logMutex); if (callback == nullptr) { - ::td::Log::set_fatal_error_callback(nullptr); - fatalErrorCallback = nullptr; + ::td::ClientManager::set_log_message_callback(max_verbosity_level, nullptr); + logMessageCallback = nullptr; } else { - fatalErrorCallback = callback; - ::td::Log::set_fatal_error_callback(FatalErrorCallbackWrapper); + logMessageCallback = callback; + ::td::ClientManager::set_log_message_callback(max_verbosity_level, LogMessageCallbackWrapper); } } @@ -151,16 +155,18 @@ private: } static std::mutex logMutex; - static FatalErrorCallback^ fatalErrorCallback; + static LogMessageCallback^ logMessageCallback; - static void FatalErrorCallbackWrapper(const char* message) { - CHECK(fatalErrorCallback != nullptr); - fatalErrorCallback(string_from_unmanaged(message)); + static void LogMessageCallbackWrapper(int verbosity_level, const char *message) { + auto callback = logMessageCallback; + if (callback != nullptr) { + callback(verbosity_level, string_from_unmanaged(message)); + } } }; std::mutex Client::logMutex; -FatalErrorCallback^ Client::fatalErrorCallback; +LogMessageCallback^ Client::logMessageCallback; } // namespace Td } // namespace Telegram From 3d28aaca6219726d1bae5c292cfb9f4205ad9866 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 May 2021 03:51:33 +0300 Subject: [PATCH 39/43] Use Td.Client.SetLogMessageCallback in UWP example. --- example/uwp/app/MainPage.xaml.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/example/uwp/app/MainPage.xaml.cs b/example/uwp/app/MainPage.xaml.cs index c3acf8497..2036150a2 100644 --- a/example/uwp/app/MainPage.xaml.cs +++ b/example/uwp/app/MainPage.xaml.cs @@ -29,6 +29,7 @@ namespace TdApp Td.Client.Execute(new TdApi.SetLogVerbosityLevel(0)); Td.Client.Execute(new TdApi.SetLogStream(new TdApi.LogStreamFile(Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "log"), 1 << 27, false))); + Td.Client.SetLogMessageCallback(100, LogMessageCallback); System.Threading.Tasks.Task.Run(() => { @@ -63,6 +64,14 @@ namespace TdApp }); } + private void LogMessageCallback(int verbosity_level, String str) + { + if (verbosity_level < 0) { + return; + } + Print(verbosity_level + ": " + str); + } + private Td.Client _client; private void AcceptCommand(String command) @@ -107,6 +116,12 @@ namespace TdApp AcceptCommand(command); _client.Send(new TdApi.CheckAuthenticationPassword(args[1]), _handler); } + else if (command.StartsWith("alm")) + { + var args = command.Split(" ".ToCharArray(), 3); + AcceptCommand(command); + _client.Send(new TdApi.AddLogMessage(Int32.Parse(args[1]), args[2]), _handler); + } else if (command.StartsWith("gco")) { var args = command.Split(" ".ToCharArray(), 2); From 3f9b3046a67ae9bf2a07d8f6c4f5c254e545f2d8 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 May 2021 10:29:50 +0300 Subject: [PATCH 40/43] Disable logMessageCallback for C++/CLI. --- td/telegram/ClientDotNet.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/td/telegram/ClientDotNet.cpp b/td/telegram/ClientDotNet.cpp index 56cb0be31..37eb34a9b 100644 --- a/td/telegram/ClientDotNet.cpp +++ b/td/telegram/ClientDotNet.cpp @@ -21,6 +21,7 @@ namespace Td { using namespace CxCli; +#if !TD_CLI /// /// A type of callback function that will be called when a message is added to the internal TDLib log. /// @@ -28,6 +29,7 @@ using namespace CxCli; /// then TDLib will crash as soon as the callback returns. /// Null-terminated string with the message added to the log. public delegate void LogMessageCallback(int verbosityLevel, String^ message); +#endif /// /// Interface for handler for results of queries to TDLib and incoming updates from TDLib. @@ -113,6 +115,7 @@ public: return REF_NEW Client(updateHandler); } +#if !TD_CLI /// /// Sets the callback that will be called when a message is added to the internal TDLib log. /// None of the TDLib methods can be called from the callback. @@ -130,6 +133,7 @@ public: ::td::ClientManager::set_log_message_callback(max_verbosity_level, LogMessageCallbackWrapper); } } +#endif private: Client(ClientResultHandler^ updateHandler) { @@ -154,6 +158,7 @@ private: } } +#if !TD_CLI static std::mutex logMutex; static LogMessageCallback^ logMessageCallback; @@ -163,10 +168,13 @@ private: callback(verbosity_level, string_from_unmanaged(message)); } } +#endif }; +#if !TD_CLI std::mutex Client::logMutex; LogMessageCallback^ Client::logMessageCallback; +#endif } // namespace Td } // namespace Telegram From 65c3c89ad6bb9f1aadf27bb2ae5997fee5ab3eae Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 May 2021 18:30:46 +0300 Subject: [PATCH 41/43] Improve LogMessageCallbackPtr documentation. --- format.ps1 | 2 +- td/telegram/Client.h | 5 +++-- td/telegram/ClientDotNet.cpp | 5 +++-- td/telegram/td_json_client.h | 5 +++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/format.ps1 b/format.ps1 index f64296cc3..3f482557c 100644 --- a/format.ps1 +++ b/format.ps1 @@ -1,3 +1,3 @@ -./src.ps1 | Select-String -NotMatch "CxCli.h" | Select-String -NotMatch "dotnet" | ForEach-Object { +./src.ps1 | Select-String -NotMatch "CxCli.h" | Select-String -NotMatch "DotNet" | ForEach-Object { clang-format -verbose -style=file -i $_ } diff --git a/td/telegram/Client.h b/td/telegram/Client.h index b61dc60d9..d54b1e377 100644 --- a/td/telegram/Client.h +++ b/td/telegram/Client.h @@ -241,8 +241,9 @@ class ClientManager final { /** * A type of callback function that will be called when a message is added to the internal TDLib log. * - * \param verbosity_level Log verbosity level with which the message was added. If 0, then TDLib will crash - * as soon as the callback returns. + * \param verbosity_level Log verbosity level with which the message was added (-1 - 1024). + * If 0, then TDLib will crash as soon as the callback returns. + * None of the TDLib methods can be called from the callback. * \param message Null-terminated string with the message added to the log. */ using LogMessageCallbackPtr = void (*)(int verbosity_level, const char *message); diff --git a/td/telegram/ClientDotNet.cpp b/td/telegram/ClientDotNet.cpp index 37eb34a9b..0ea8742e0 100644 --- a/td/telegram/ClientDotNet.cpp +++ b/td/telegram/ClientDotNet.cpp @@ -25,8 +25,9 @@ using namespace CxCli; /// /// A type of callback function that will be called when a message is added to the internal TDLib log. /// -/// Log verbosity level with which the message was added. If 0, -/// then TDLib will crash as soon as the callback returns. +/// Log verbosity level with which the message was added (-1 - 1024). +/// If 0, then TDLib will crash as soon as the callback returns. +/// None of the TDLib methods can be called from the callback. /// Null-terminated string with the message added to the log. public delegate void LogMessageCallback(int verbosityLevel, String^ message); #endif diff --git a/td/telegram/td_json_client.h b/td/telegram/td_json_client.h index f2b8e09e2..57dd0ed4a 100644 --- a/td/telegram/td_json_client.h +++ b/td/telegram/td_json_client.h @@ -159,7 +159,9 @@ TDJSON_EXPORT const char *td_execute(const char *request); /** * A type of callback function that will be called when a message is added to the internal TDLib log. * - * \param verbosity_level Log verbosity level with which the message was added. + * \param verbosity_level Log verbosity level with which the message was added (-1 - 1024). + * If 0, then TDLib will crash as soon as the callback returns. + * None of the TDLib methods can be called from the callback. * \param message Null-terminated string with the logged message. */ typedef void (*td_log_message_callback_ptr)(int verbosity_level, const char *message); @@ -167,7 +169,6 @@ typedef void (*td_log_message_callback_ptr)(int verbosity_level, const char *mes /** * Sets the callback that will be called when a message is added to the internal TDLib log. * None of the TDLib methods can be called from the callback. - * If message verbosity level is 0, then TDLib will crash as soon as callback returns. * By default the callback is not set. * * \param[in] max_verbosity_level Maximum verbosity level of messages for which the callback will be called. From 5e7adcd1cbf58e86ea2ac91dce796aef44d43978 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 May 2021 23:13:02 +0300 Subject: [PATCH 42/43] Don't include SliceBuilder.h in Status.h. --- tdutils/td/utils/Parser.h | 5 ++--- tdutils/td/utils/Status.cpp | 30 ++++++++++++++++++++++++++++++ tdutils/td/utils/Status.h | 30 +++--------------------------- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/tdutils/td/utils/Parser.h b/tdutils/td/utils/Parser.h index a6ce8eece..1a0e65c78 100644 --- a/tdutils/td/utils/Parser.h +++ b/tdutils/td/utils/Parser.h @@ -7,7 +7,6 @@ #pragma once #include "td/utils/common.h" -#include "td/utils/format.h" #include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" @@ -99,7 +98,7 @@ class ParserImpl { } SliceT res = read_till_nofail(c); if (ptr_ == end_ || ptr_[0] != c) { - status_ = Status::Error(PSLICE() << "Read till " << tag("char", c) << " failed"); + status_ = Status::Error(PSLICE() << "Read till '" << c << "' failed"); return SliceT(); } return res; @@ -126,7 +125,7 @@ class ParserImpl { return; } if (ptr_ == end_ || ptr_[0] != c) { - status_ = Status::Error(PSLICE() << "Skip " << tag("char", c) << " failed"); + status_ = Status::Error(PSLICE() << "Skip '" << c << "' failed"); return; } ptr_++; diff --git a/tdutils/td/utils/Status.cpp b/tdutils/td/utils/Status.cpp index 2d9f7f3c8..1e7e873a3 100644 --- a/tdutils/td/utils/Status.cpp +++ b/tdutils/td/utils/Status.cpp @@ -6,6 +6,8 @@ // #include "td/utils/Status.h" +#include "td/utils/SliceBuilder.h" + #if TD_PORT_WINDOWS #include "td/utils/port/wstring_convert.h" #endif @@ -55,4 +57,32 @@ string winerror_to_string(int code) { } #endif +Status Status::move_as_error_prefix(Slice prefix) const { + CHECK(is_error()); + Info info = get_info(); + switch (info.error_type) { + case ErrorType::General: + return Error(code(), PSLICE() << prefix << message()); + case ErrorType::Os: + return Status(false, ErrorType::Os, code(), PSLICE() << prefix << message()); + default: + UNREACHABLE(); + return {}; + } +} + +Status Status::move_as_error_suffix(Slice suffix) const TD_WARN_UNUSED_RESULT { + CHECK(is_error()); + Info info = get_info(); + switch (info.error_type) { + case ErrorType::General: + return Error(code(), PSLICE() << message() << suffix); + case ErrorType::Os: + return Status(false, ErrorType::Os, code(), PSLICE() << message() << suffix); + default: + UNREACHABLE(); + return {}; + } +} + } // namespace td diff --git a/tdutils/td/utils/Status.h b/tdutils/td/utils/Status.h index a777f5395..2ffb1e7e2 100644 --- a/tdutils/td/utils/Status.h +++ b/tdutils/td/utils/Status.h @@ -10,7 +10,6 @@ #include "td/utils/logging.h" #include "td/utils/ScopeGuard.h" #include "td/utils/Slice.h" -#include "td/utils/SliceBuilder.h" #include "td/utils/StackAllocator.h" #include "td/utils/StringBuilder.h" @@ -325,32 +324,9 @@ class Status { return status.move_as_error_suffix(message()); } - Status move_as_error_prefix(Slice prefix) const TD_WARN_UNUSED_RESULT { - CHECK(is_error()); - Info info = get_info(); - switch (info.error_type) { - case ErrorType::General: - return Error(code(), PSLICE() << prefix << message()); - case ErrorType::Os: - return Status(false, ErrorType::Os, code(), PSLICE() << prefix << message()); - default: - UNREACHABLE(); - return {}; - } - } - Status move_as_error_suffix(Slice suffix) const TD_WARN_UNUSED_RESULT { - CHECK(is_error()); - Info info = get_info(); - switch (info.error_type) { - case ErrorType::General: - return Error(code(), PSLICE() << message() << suffix); - case ErrorType::Os: - return Status(false, ErrorType::Os, code(), PSLICE() << message() << suffix); - default: - UNREACHABLE(); - return {}; - } - } + Status move_as_error_prefix(Slice prefix) const TD_WARN_UNUSED_RESULT; + + Status move_as_error_suffix(Slice suffix) const TD_WARN_UNUSED_RESULT; private: struct Info { From e1ebf743988edfcf4400cd5d33a664ff941dc13e Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 21 May 2021 02:05:03 +0300 Subject: [PATCH 43/43] Fix CE. --- tdutils/td/utils/Status.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdutils/td/utils/Status.cpp b/tdutils/td/utils/Status.cpp index 1e7e873a3..c07cc6003 100644 --- a/tdutils/td/utils/Status.cpp +++ b/tdutils/td/utils/Status.cpp @@ -71,7 +71,7 @@ Status Status::move_as_error_prefix(Slice prefix) const { } } -Status Status::move_as_error_suffix(Slice suffix) const TD_WARN_UNUSED_RESULT { +Status Status::move_as_error_suffix(Slice suffix) const { CHECK(is_error()); Info info = get_info(); switch (info.error_type) {