diff --git a/.gitattributes b/.gitattributes index ddda6aef9..c684829d4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14,6 +14,7 @@ *.md text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.in text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.sky text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent +*.html text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.java text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent *.py text whitespace=blank-at-eol,space-before-tab,blank-at-eof,tab-in-indent diff --git a/td/telegram/JsonValue.cpp b/td/telegram/JsonValue.cpp index ad26b4830..7757cd271 100644 --- a/td/telegram/JsonValue.cpp +++ b/td/telegram/JsonValue.cpp @@ -9,9 +9,12 @@ #include "td/telegram/misc.h" #include "td/utils/JsonBuilder.h" +#include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/utf8.h" +#include + namespace td { static td_api::object_ptr get_json_value_object(const JsonValue &json_value); diff --git a/td/telegram/Logging.cpp b/td/telegram/Logging.cpp index c895308b1..32cb0d66a 100644 --- a/td/telegram/Logging.cpp +++ b/td/telegram/Logging.cpp @@ -21,8 +21,8 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" +#include #include -#include namespace td { diff --git a/td/telegram/MessagesDb.cpp b/td/telegram/MessagesDb.cpp index da104be1a..106e31ad9 100644 --- a/td/telegram/MessagesDb.cpp +++ b/td/telegram/MessagesDb.cpp @@ -535,7 +535,7 @@ class MessagesDbImpl : public MessagesDbSyncInterface { } Result> get_messages_from_notification_id(DialogId dialog_id, NotificationId from_notification_id, - int32 limit) { + int32 limit) override { auto &stmt = get_messages_from_notification_id_stmt_; SCOPE_EXIT { stmt.reset(); diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index e9372bef8..b97d86ef1 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -14,11 +14,13 @@ #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" +#include "td/utils/logging.h" #include "td/utils/misc.h" +#include "td/utils/Time.h" #include +#include #include -#include #include #include diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 5958dd7fd..b902f0e5a 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -20,11 +20,14 @@ #include "td/actor/Timeout.h" #include "td/utils/common.h" +#include "td/utils/logging.h" +#include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include #include #include +#include namespace td { diff --git a/td/telegram/NotificationType.cpp b/td/telegram/NotificationType.cpp index 1677b71da..2ad1e7512 100644 --- a/td/telegram/NotificationType.cpp +++ b/td/telegram/NotificationType.cpp @@ -32,7 +32,7 @@ class NotificationTypeMessage : public NotificationType { return string_builder << "NewMessageNotification[" << message_id_ << ']'; } - Type get_type() const { + Type get_type() const override { return Type::Message; } @@ -60,7 +60,7 @@ class NotificationTypeSecretChat : public NotificationType { return string_builder << "NewSecretChatNotification[]"; } - Type get_type() const { + Type get_type() const override { return Type::SecretChat; } @@ -86,7 +86,7 @@ class NotificationTypeCall : public NotificationType { return string_builder << "NewCallNotification[" << call_id_ << ']'; } - Type get_type() const { + Type get_type() const override { return Type::Call; } diff --git a/td/telegram/NotificationType.h b/td/telegram/NotificationType.h index 694759908..b547d3678 100644 --- a/td/telegram/NotificationType.h +++ b/td/telegram/NotificationType.h @@ -7,6 +7,7 @@ #pragma once #include "td/telegram/CallId.h" +#include "td/telegram/DialogId.h" #include "td/telegram/MessageId.h" #include "td/telegram/td_api.h" diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index e94a63150..d3c00533a 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -17,6 +17,7 @@ #include "td/actor/Timeout.h" #include "td/utils/common.h" +#include "td/utils/logging.h" #include #include diff --git a/td/telegram/files/FileGcWorker.h b/td/telegram/files/FileGcWorker.h index 20004b234..eddbe13f0 100644 --- a/td/telegram/files/FileGcWorker.h +++ b/td/telegram/files/FileGcWorker.h @@ -13,6 +13,8 @@ #include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileStats.h" +#include "td/utils/logging.h" + namespace td { extern int VERBOSITY_NAME(file_gc); diff --git a/td/telegram/files/FileGenerateManager.cpp b/td/telegram/files/FileGenerateManager.cpp index a03f3cc1b..4dd7f2a34 100644 --- a/td/telegram/files/FileGenerateManager.cpp +++ b/td/telegram/files/FileGenerateManager.cpp @@ -18,10 +18,12 @@ #include "td/telegram/Td.h" #include "td/utils/common.h" +#include "td/utils/format.h" #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Parser.h" #include "td/utils/port/path.h" +#include "td/utils/port/Stat.h" #include "td/utils/Slice.h" #include diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index cdfec22cd..ad9406032 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -675,7 +675,6 @@ class FullRemoteFileLocation { #define as_input_web_file_location() as_input_web_file_location_impl(__FILE__, __LINE__) tl_object_ptr as_input_web_file_location_impl(const char *file, int line) const { CHECK(is_web()) << file << ' ' << line; - ; return make_tl_object(web().url_, web().access_hash_); } diff --git a/td/telegram/net/DcAuthManager.h b/td/telegram/net/DcAuthManager.h index cb57c823a..cedb3b71e 100644 --- a/td/telegram/net/DcAuthManager.h +++ b/td/telegram/net/DcAuthManager.h @@ -12,6 +12,7 @@ #include "td/telegram/net/NetQuery.h" #include "td/actor/actor.h" +#include "td/actor/PromiseFuture.h" #include "td/utils/buffer.h" #include "td/utils/common.h" diff --git a/tdutils/td/utils/Random.cpp b/tdutils/td/utils/Random.cpp index df700efd7..5d8c7f949 100644 --- a/tdutils/td/utils/Random.cpp +++ b/tdutils/td/utils/Random.cpp @@ -13,7 +13,7 @@ #include #endif -#include +#include #include #include #include @@ -21,18 +21,17 @@ namespace td { #if TD_HAVE_OPENSSL + namespace { -constexpr size_t secure_bytes_buffer_size = 512; -} +std::atomic random_seed_generation{0}; +} // namespace + void Random::secure_bytes(MutableSlice dest) { Random::secure_bytes(dest.ubegin(), dest.size()); } -namespace { -std::atomic random_seed_generation{0}; -} void Random::secure_bytes(unsigned char *ptr, size_t size) { - constexpr size_t buf_size = secure_bytes_buffer_size; + constexpr size_t buf_size = 512; static TD_THREAD_LOCAL unsigned char *buf; // static zero-initialized static TD_THREAD_LOCAL size_t buf_pos; static TD_THREAD_LOCAL int64 generation; diff --git a/tdutils/td/utils/StringBuilder.cpp b/tdutils/td/utils/StringBuilder.cpp index 86dfdf87d..369bd7de9 100644 --- a/tdutils/td/utils/StringBuilder.cpp +++ b/tdutils/td/utils/StringBuilder.cpp @@ -6,17 +6,52 @@ // #include "td/utils/StringBuilder.h" +#include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/port/thread_local.h" +#include "td/utils/Slice.h" #include +#include #include #include +#include #include #include namespace td { +StringBuilder::StringBuilder(MutableSlice slice, bool use_buffer) + : begin_ptr_(slice.begin()), current_ptr_(begin_ptr_), use_buffer_(use_buffer) { + if (slice.size() <= reserved_size) { + auto buffer_size = reserved_size + 100; + buffer_ = std::make_unique(buffer_size); + begin_ptr_ = buffer_.get(); + current_ptr_ = begin_ptr_; + end_ptr_ = begin_ptr_ + buffer_size - reserved_size; + } else { + end_ptr_ = slice.end() - reserved_size; + } +} + +StringBuilder &StringBuilder::operator<<(Slice slice) { + size_t size = slice.size(); + if (unlikely(!reserve(size))) { + if (end_ptr_ < current_ptr_) { + return on_error(); + } + auto available_size = static_cast(end_ptr_ + reserved_size - 1 - current_ptr_); + if (size > available_size) { + error_flag_ = true; + size = available_size; + } + } + + std::memcpy(current_ptr_, slice.begin(), size); + current_ptr_ += size; + return *this; +} + template static char *print_uint(char *current_ptr, T x) { if (x < 100) { diff --git a/tdutils/td/utils/StringBuilder.h b/tdutils/td/utils/StringBuilder.h index 1ee97156a..3042aaa2b 100644 --- a/tdutils/td/utils/StringBuilder.h +++ b/tdutils/td/utils/StringBuilder.h @@ -11,25 +11,14 @@ #include "td/utils/StackAllocator.h" #include -#include +#include #include namespace td { class StringBuilder { public: - explicit StringBuilder(MutableSlice slice, bool use_buffer = false) - : begin_ptr_(slice.begin()), current_ptr_(begin_ptr_), use_buffer_(use_buffer) { - if (slice.size() <= reserved_size) { - auto buffer_size = reserved_size + 100; - buffer_ = std::make_unique(buffer_size); - begin_ptr_ = buffer_.get(); - current_ptr_ = begin_ptr_; - end_ptr_ = begin_ptr_ + buffer_size - reserved_size; - } else { - end_ptr_ = slice.end() - reserved_size; - } - } + explicit StringBuilder(MutableSlice slice, bool use_buffer = false); void clear() { current_ptr_ = begin_ptr_; @@ -54,23 +43,7 @@ class StringBuilder { StringBuilder &operator<<(const wchar_t *str) = delete; - StringBuilder &operator<<(Slice slice) { - size_t size = slice.size(); - if (unlikely(!reserve(size))) { - if (end_ptr_ < current_ptr_) { - return on_error(); - } - auto available_size = static_cast(end_ptr_ + reserved_size - 1 - current_ptr_); - if (size > available_size) { - error_flag_ = true; - size = available_size; - } - } - - std::memcpy(current_ptr_, slice.begin(), size); - current_ptr_ += size; - return *this; - } + StringBuilder &operator<<(Slice slice); StringBuilder &operator<<(bool b) { return *this << (b ? Slice("true") : Slice("false")); diff --git a/tdutils/test/json.cpp b/tdutils/test/json.cpp index 5559e2ceb..269b306df 100644 --- a/tdutils/test/json.cpp +++ b/tdutils/test/json.cpp @@ -8,6 +8,7 @@ #include "td/utils/JsonBuilder.h" #include "td/utils/logging.h" +#include "td/utils/Slice.h" #include "td/utils/StringBuilder.h" #include