From 08ec7fb7c7b9c77ba52ff84d853833d70fd6f59b Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Thu, 8 May 2025 05:10:16 +0800 Subject: [PATCH] build: lint header files with clang-tidy (#7527) * build: clang-tidy headers when building libtransmission * chore: revert `= default` workaround It was introduced in 6909ec0bad to fix build issues with macOS 10.14. We no longer support that version. * fix: clang-tidy warnings for libtransmission * build: clang-tidy headers when building tests * fix: clang-tidy warnings for tests * build: clang-tidy headers when building qt * code review: don't manually edit mime-types.h * code review: unify variable naming for static private members --- .gitattributes | 1 + gtk/main.cc | 6 +- libtransmission/.clang-tidy | 13 ++-- libtransmission/announce-list.h | 2 +- libtransmission/announcer.h | 22 +++---- libtransmission/benc.h | 2 +- libtransmission/block-info.h | 4 +- libtransmission/completion.h | 6 +- libtransmission/crypto-utils.h | 6 +- libtransmission/error.h | 2 +- libtransmission/handshake.h | 31 +++++---- libtransmission/interned-string.h | 5 +- libtransmission/log.cc | 6 +- libtransmission/log.h | 4 +- libtransmission/makemeta.h | 4 +- libtransmission/mime-types.h | 45 ++++++++++++- libtransmission/mime-types.js | 2 +- libtransmission/net.cc | 5 +- libtransmission/net.h | 11 ++-- libtransmission/observable.h | 4 +- libtransmission/peer-common.h | 6 +- libtransmission/peer-io.h | 11 +++- libtransmission/peer-mgr.cc | 4 +- libtransmission/peer-mgr.h | 6 +- libtransmission/peer-mse.h | 4 +- libtransmission/peer-msgs.cc | 2 +- libtransmission/peer-msgs.h | 5 ++ libtransmission/peer-socket.h | 4 +- libtransmission/platform.h | 2 +- libtransmission/port-forwarding-natpmp.h | 7 ++- libtransmission/port-forwarding-upnp.cc | 4 +- libtransmission/port-forwarding-upnp.h | 2 +- libtransmission/port-forwarding.h | 2 +- libtransmission/quark.h | 2 +- libtransmission/rpc-server.h | 8 +-- libtransmission/session-alt-speeds.h | 6 +- libtransmission/session-id.h | 2 +- libtransmission/session-thread.h | 12 +++- libtransmission/session.h | 19 +++--- libtransmission/stats.h | 5 ++ libtransmission/torrent-queue.h | 3 +- libtransmission/torrent.cc | 2 +- libtransmission/torrent.h | 6 +- libtransmission/tr-arc4.h | 2 +- libtransmission/tr-buffer.h | 1 + libtransmission/tr-getopt.h | 4 +- libtransmission/tr-macros.h | 4 +- libtransmission/tr-popcount.h | 37 +++++------ libtransmission/tr-strbuf.h | 9 ++- libtransmission/transmission.h | 63 +++++++++++-------- libtransmission/utils.cc | 10 +-- libtransmission/values.h | 16 ++--- libtransmission/variant.h | 15 +++-- libtransmission/verify.h | 6 ++ libtransmission/version.h.in | 4 ++ libtransmission/watchdir-base.h | 2 + libtransmission/watchdir.h | 4 +- libtransmission/web-utils.cc | 3 +- libtransmission/web-utils.h | 6 +- libtransmission/web.h | 7 ++- libtransmission/webseed.h | 2 +- macosx/Controller.mm | 6 +- macosx/MessageWindowController.mm | 4 +- qt/.clang-tidy | 2 + qt/Application.cc | 6 +- qt/Prefs.cc | 2 +- tests/libtransmission/.clang-tidy | 4 +- tests/libtransmission/announce-list-test.cc | 2 +- tests/libtransmission/makemeta-test.cc | 2 +- tests/libtransmission/move-test.cc | 6 +- tests/libtransmission/remove-test.cc | 2 +- tests/libtransmission/rename-test.cc | 4 +- tests/libtransmission/test-fixtures.h | 54 ++++++++-------- .../libtransmission/torrent-metainfo-test.cc | 2 +- tests/libtransmission/utils-test.cc | 2 +- tests/libtransmission/variant-test.cc | 3 +- tests/libtransmission/watchdir-test.cc | 2 +- utils/remote.cc | 2 +- 78 files changed, 368 insertions(+), 237 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..e1460f387 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +libtransmission/mime-types.h linguist-generated=true diff --git a/gtk/main.cc b/gtk/main.cc index 3f1a06e63..154eb90d3 100644 --- a/gtk/main.cc +++ b/gtk/main.cc @@ -117,9 +117,9 @@ int main(int argc, char** argv) // init the unit formatters using Config = libtransmission::Values::Config; - Config::Speed = { Config::Base::Kilo, _("B/s"), _("kB/s"), _("MB/s"), _("GB/s"), _("TB/s") }; - Config::Memory = { Config::Base::Kibi, _("B"), _("KiB"), _("MiB"), _("GiB"), _("TiB") }; - Config::Storage = { Config::Base::Kilo, _("B"), _("kB"), _("MB"), _("GB"), _("TB") }; + Config::speed = { Config::Base::Kilo, _("B/s"), _("kB/s"), _("MB/s"), _("GB/s"), _("TB/s") }; + Config::memory = { Config::Base::Kibi, _("B"), _("KiB"), _("MiB"), _("GiB"), _("TiB") }; + Config::storage = { Config::Base::Kilo, _("B"), _("kB"), _("MB"), _("GB"), _("TB") }; /* set up the config dir */ if (std::empty(config_dir)) diff --git a/libtransmission/.clang-tidy b/libtransmission/.clang-tidy index 5accfde5b..361a168b9 100644 --- a/libtransmission/.clang-tidy +++ b/libtransmission/.clang-tidy @@ -1,4 +1,6 @@ --- +HeaderFilterRegex: .*/libtransmission/.* + # PRs welcome to fix & re-enable any of these explicitly-disabled checks Checks: > bugprone-*, @@ -39,9 +41,10 @@ Checks: > -readability-qualified-auto, CheckOptions: - - { key: cppcoreguidelines-avoid-do-while.IgnoreMacros, value: true } - - { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase } - - { key: readability-identifier-naming.ParameterCase, value: lower_case } - - { key: readability-identifier-naming.VariableCase, value: lower_case } - - { key: readability-implicit-bool-conversion.UseUpperCaseLiteralSuffix, value: true } + - { key: cppcoreguidelines-avoid-do-while.IgnoreMacros, value: true } + - { key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor, value: true } + - { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase } + - { key: readability-identifier-naming.ParameterCase, value: lower_case } + - { key: readability-identifier-naming.VariableCase, value: lower_case } + - { key: readability-implicit-bool-conversion.UseUpperCaseLiteralSuffix, value: true } diff --git a/libtransmission/announce-list.h b/libtransmission/announce-list.h index b93194994..4ef1a5d69 100644 --- a/libtransmission/announce-list.h +++ b/libtransmission/announce-list.h @@ -115,7 +115,7 @@ public: TR_CONSTEXPR20 void clear() { - return trackers_.clear(); + trackers_.clear(); } /** diff --git a/libtransmission/announcer.h b/libtransmission/announcer.h index 33a6ce18a..836747041 100644 --- a/libtransmission/announcer.h +++ b/libtransmission/announcer.h @@ -40,7 +40,7 @@ struct tr_torrent_announcer; /** @brief Notification object to tell listeners about announce or scrape occurrences */ struct tr_tracker_event { - enum class Type + enum class Type : uint8_t { Error, ErrorClear, @@ -70,7 +70,7 @@ using tr_tracker_callback = std::function create(tr_session* session, tr_announcer_udp&); + [[nodiscard]] static std::unique_ptr create(tr_session* session, tr_announcer_udp& announcer_udp); virtual ~tr_announcer() = default; virtual tr_torrent_announcer* addTorrent(tr_torrent*, tr_tracker_callback callback) = 0; @@ -87,24 +87,24 @@ std::unique_ptr tr_announcerCreate(tr_session* session); // --- For torrent customers -void tr_announcerChangeMyPort(tr_torrent*); +void tr_announcerChangeMyPort(tr_torrent* tor); -bool tr_announcerCanManualAnnounce(tr_torrent const*); +bool tr_announcerCanManualAnnounce(tr_torrent const* tor); -void tr_announcerManualAnnounce(tr_torrent*); +void tr_announcerManualAnnounce(tr_torrent* tor); -void tr_announcerTorrentCompleted(tr_torrent*); +void tr_announcerTorrentCompleted(tr_torrent* tor); -enum +enum : uint8_t { TR_ANN_UP, TR_ANN_DOWN, TR_ANN_CORRUPT }; -void tr_announcerAddBytes(tr_torrent*, int type, uint32_t n_bytes); +void tr_announcerAddBytes(tr_torrent* tor, int type, uint32_t n_bytes); -time_t tr_announcerNextManualAnnounce(tr_torrent const*); +time_t tr_announcerNextManualAnnounce(tr_torrent const* tor); tr_tracker_view tr_announcerTracker(tr_torrent const* torrent, size_t nth); @@ -112,7 +112,7 @@ size_t tr_announcerTrackerCount(tr_torrent const* tor); // --- ANNOUNCE -enum tr_announce_event +enum tr_announce_event : uint8_t { /* Note: the ordering of this enum's values is important to * announcer.c's tr_tier.announce_event_priority. If changing @@ -147,7 +147,7 @@ public: virtual ~tr_announcer_udp() noexcept = default; - [[nodiscard]] static std::unique_ptr create(Mediator&); + [[nodiscard]] static std::unique_ptr create(Mediator& mediator); virtual void announce(tr_announce_request const& request, tr_announce_response_func on_response) = 0; diff --git a/libtransmission/benc.h b/libtransmission/benc.h index 196fcbabe..e652c9ddc 100644 --- a/libtransmission/benc.h +++ b/libtransmission/benc.h @@ -182,7 +182,7 @@ private: template struct ParserStack { - enum class ParentType + enum class ParentType : uint8_t { Array, Dict diff --git a/libtransmission/block-info.h b/libtransmission/block-info.h index 678db0cfe..7223a8d18 100644 --- a/libtransmission/block-info.h +++ b/libtransmission/block-info.h @@ -14,9 +14,7 @@ struct tr_block_info public: static auto constexpr BlockSize = uint32_t{ 1024U * 16U }; - tr_block_info() noexcept - { - } + tr_block_info() noexcept = default; tr_block_info(uint64_t const total_size_in, uint32_t const piece_size_in) noexcept { diff --git a/libtransmission/completion.h b/libtransmission/completion.h index b2dfded19..c1e3bcac9 100644 --- a/libtransmission/completion.h +++ b/libtransmission/completion.h @@ -84,13 +84,13 @@ struct tr_completion [[nodiscard]] constexpr double percent_complete() const { auto const denom = block_info_->total_size(); - return denom ? std::clamp(double(size_now_) / denom, 0.0, 1.0) : 0.0; + return denom != 0U ? std::clamp(double(size_now_) / denom, 0.0, 1.0) : 0.0; } [[nodiscard]] double percent_done() const { auto const denom = size_when_done(); - return denom ? std::clamp(double(size_now_) / denom, 0.0, 1.0) : 0.0; + return denom != 0U ? std::clamp(double(size_now_) / denom, 0.0, 1.0) : 0.0; } [[nodiscard]] uint64_t size_when_done() const; @@ -155,7 +155,7 @@ struct tr_completion size_when_done_.reset(); } - [[nodiscard]] uint64_t count_has_bytes_in_span(tr_byte_span_t) const; + [[nodiscard]] uint64_t count_has_bytes_in_span(tr_byte_span_t span) const; [[nodiscard]] constexpr bool has_metainfo() const noexcept { diff --git a/libtransmission/crypto-utils.h b/libtransmission/crypto-utils.h index af0f64b4a..c2af5aace 100644 --- a/libtransmission/crypto-utils.h +++ b/libtransmission/crypto-utils.h @@ -174,7 +174,7 @@ using tr_sha1_string = tr_strbuf; /** * @brief Generate an ascii hex string for a sha1 digest. */ -[[nodiscard]] tr_sha1_string tr_sha1_to_string(tr_sha1_digest_t const&); +[[nodiscard]] tr_sha1_string tr_sha1_to_string(tr_sha1_digest_t const& digest); /** * @brief Generate a sha1 digest from a hex string. @@ -186,7 +186,7 @@ using tr_sha256_string = tr_strbuf; /** * @brief Generate an ascii hex string for a sha256 digest. */ -[[nodiscard]] tr_sha256_string tr_sha256_to_string(tr_sha256_digest_t const&); +[[nodiscard]] tr_sha256_string tr_sha256_to_string(tr_sha256_digest_t const& digest); /** * @brief Generate a sha256 digest from a hex string. @@ -196,7 +196,7 @@ using tr_sha256_string = tr_strbuf; // Convenience utility to efficiently get many random small values. // Use this instead of making a lot of calls to tr_rand_int(). template -class tr_salt_shaker +class tr_salt_shaker // NOLINT(cppcoreguidelines-pro-type-member-init): buf doesn't need to be initialised { public: [[nodiscard]] auto operator()() noexcept diff --git a/libtransmission/error.h b/libtransmission/error.h index cac7eee87..586a15c07 100644 --- a/libtransmission/error.h +++ b/libtransmission/error.h @@ -37,7 +37,7 @@ public: return code_ != 0; } - [[nodiscard]] constexpr operator bool() const noexcept + [[nodiscard]] explicit constexpr operator bool() const noexcept { return has_value(); } diff --git a/libtransmission/handshake.h b/libtransmission/handshake.h index 7ca55af98..d217e9743 100644 --- a/libtransmission/handshake.h +++ b/libtransmission/handshake.h @@ -90,6 +90,11 @@ public: maybe_recycle_dh(); } + tr_handshake(tr_handshake const&) = delete; + tr_handshake(tr_handshake&&) = delete; + tr_handshake& operator=(tr_handshake const&) = delete; + tr_handshake& operator=(tr_handshake&&) = delete; + // bittorrent handshake constants // https://www.bittorrent.org/beps/bep_0003.html#peer-protocol // https://wiki.theory.org/BitTorrentSpecification#Handshake @@ -173,19 +178,19 @@ private: // --- - ReadState read_crypto_provide(tr_peerIo*); - ReadState read_crypto_select(tr_peerIo*); - ReadState read_handshake(tr_peerIo*); - ReadState read_ia(tr_peerIo*); - ReadState read_pad_a(tr_peerIo*); - ReadState read_pad_c(tr_peerIo*); - ReadState read_pad_d(tr_peerIo*); - ReadState read_peer_id(tr_peerIo*); - ReadState read_vc(tr_peerIo*); - ReadState read_ya(tr_peerIo*); - ReadState read_yb(tr_peerIo*); + ReadState read_crypto_provide(tr_peerIo* peer_io); + ReadState read_crypto_select(tr_peerIo* peer_io); + ReadState read_handshake(tr_peerIo* peer_io); + ReadState read_ia(tr_peerIo* peer_io); + ReadState read_pad_a(tr_peerIo* peer_io); + ReadState read_pad_c(tr_peerIo* peer_io); + ReadState read_pad_d(tr_peerIo* peer_io); + ReadState read_peer_id(tr_peerIo* peer_io); + ReadState read_vc(tr_peerIo* peer_io); + ReadState read_ya(tr_peerIo* peer_io); + ReadState read_yb(tr_peerIo* peer_io); - void send_ya(tr_peerIo*); + void send_ya(tr_peerIo* io); void set_peer_id(tr_peer_id_t const& id) noexcept { @@ -228,7 +233,7 @@ private: static ReadState can_read(tr_peerIo* peer_io, void* vhandshake, size_t* piece); - static void on_error(tr_peerIo* io, tr_error const&, void* vhandshake); + static void on_error(tr_peerIo* io, tr_error const& error, void* vhandshake); bool build_handshake_message(tr_peerIo* io, libtransmission::BufferWriter& buf) const; diff --git a/libtransmission/interned-string.h b/libtransmission/interned-string.h index 991275ae6..91f0f3841 100644 --- a/libtransmission/interned-string.h +++ b/libtransmission/interned-string.h @@ -31,7 +31,7 @@ public: } explicit tr_interned_string(char const* c_str) - : tr_interned_string{ std::string_view{ c_str ? c_str : "" } } + : tr_interned_string{ std::string_view{ c_str != nullptr ? c_str : "" } } { } @@ -157,6 +157,7 @@ public: return *this != std::string_view{ that != nullptr ? that : "" }; } + // NOLINTNEXTLINE(google-explicit-constructor) [[nodiscard]] constexpr operator std::string_view() const noexcept { return sv(); @@ -164,7 +165,7 @@ public: private: tr_quark quark_ = TR_KEY_NONE; - std::string_view sv_ = ""; + std::string_view sv_; }; template<> diff --git a/libtransmission/log.cc b/libtransmission/log.cc index 2a16afda9..ef48899e3 100644 --- a/libtransmission/log.cc +++ b/libtransmission/log.cc @@ -50,7 +50,7 @@ public: tr_log_message** queue_tail_ = &queue_; - int queue_length_ = 0; + size_t queue_length_ = 0; std::recursive_mutex message_mutex_; }; @@ -121,14 +121,14 @@ void logAddImpl( log_state.queue_tail_ = &newmsg->next; ++log_state.queue_length_; - if (log_state.queue_length_ > TR_LOG_MAX_QUEUE_LENGTH) + if (log_state.queue_length_ > TrLogMaxQueueLength) { tr_log_message* old = log_state.queue_; log_state.queue_ = old->next; old->next = nullptr; tr_logFreeQueue(old); --log_state.queue_length_; - TR_ASSERT(log_state.queue_length_ == TR_LOG_MAX_QUEUE_LENGTH); + TR_ASSERT(log_state.queue_length_ == TrLogMaxQueueLength); } } else diff --git a/libtransmission/log.h b/libtransmission/log.h index b49437b7b..d20081776 100644 --- a/libtransmission/log.h +++ b/libtransmission/log.h @@ -68,7 +68,7 @@ struct tr_log_message // --- -#define TR_LOG_MAX_QUEUE_LENGTH 10000 +inline constexpr auto TrLogMaxQueueLength = 10000U; void tr_logSetQueueEnabled(bool is_enabled); @@ -78,7 +78,7 @@ void tr_logFreeQueue(tr_log_message* freeme); // --- -void tr_logSetLevel(tr_log_level); +void tr_logSetLevel(tr_log_level level); [[nodiscard]] tr_log_level tr_logGetLevel(); diff --git a/libtransmission/makemeta.h b/libtransmission/makemeta.h index eb2c513cb..98d3cffd5 100644 --- a/libtransmission/makemeta.h +++ b/libtransmission/makemeta.h @@ -27,6 +27,8 @@ class tr_metainfo_builder public: explicit tr_metainfo_builder(std::string_view single_file_or_parent_directory); + ~tr_metainfo_builder() = default; + tr_metainfo_builder(tr_metainfo_builder&&) = delete; tr_metainfo_builder(tr_metainfo_builder const&) = delete; tr_metainfo_builder& operator=(tr_metainfo_builder&&) = delete; @@ -182,7 +184,7 @@ public: [[nodiscard]] constexpr static bool is_legal_piece_size(uint32_t x) { // It must be a power of two and at least 16KiB - auto const MinSize = uint32_t{ 1024U * 16U }; + auto constexpr MinSize = uint32_t{ 1024U * 16U }; auto const is_power_of_two = (x & (x - 1)) == 0; return x >= MinSize && is_power_of_two; } diff --git a/libtransmission/mime-types.h b/libtransmission/mime-types.h index b46a271a3..1c77ff284 100644 --- a/libtransmission/mime-types.h +++ b/libtransmission/mime-types.h @@ -17,9 +17,10 @@ struct mime_type_suffix std::string_view mime_type; }; -inline auto constexpr mime_type_suffixes = std::array{ +inline auto constexpr MimeTypeSuffixes = std::array{ { { "123", "application/vnd.lotus-1-2-3" }, { "1km", "application/vnd.1000minds.decision-model+xml" }, + { "210", "model/step" }, { "3dml", "text/vnd.in3d.3dml" }, { "3ds", "image/x-3ds" }, { "3g2", "video/3gpp2" }, @@ -90,16 +91,19 @@ inline auto constexpr mime_type_suffixes = std::array{ { "azv", "image/vnd.airzip.accelerator.azv" }, { "azw", "application/vnd.amazon.ebook" }, { "b16", "image/vnd.pco.b16" }, + { "bary", "model/vnd.bary" }, { "bat", "application/x-msdownload" }, { "bcpio", "application/x-bcpio" }, { "bdf", "application/x-font-bdf" }, { "bdm", "application/vnd.syncml.dm+wbxml" }, + { "bdo", "application/vnd.nato.bindingdataobject+xml" }, { "bdoc", "application/bdoc" }, { "bdoc", "application/x-bdoc" }, { "bed", "application/vnd.realvnc.bed" }, { "bh2", "application/vnd.fujitsu.oasysprs" }, { "bin", "application/octet-stream" }, { "blb", "application/x-blorb" }, + { "blend", "application/x-blender" }, { "blorb", "application/x-blorb" }, { "bmi", "application/vnd.bmi" }, { "bmml", "application/vnd.balsamiq.bmml+xml" }, @@ -109,6 +113,8 @@ inline auto constexpr mime_type_suffixes = std::array{ { "box", "application/vnd.previewsystems.box" }, { "boz", "application/x-bzip2" }, { "bpk", "application/octet-stream" }, + { "brush", "application/vnd.procreate.brush" }, + { "brushset", "application/vnd.procrate.brushset" }, { "bsp", "model/vnd.valve.source.compiled-map" }, { "btf", "image/prs.btif" }, { "btif", "image/prs.btif" }, @@ -206,6 +212,8 @@ inline auto constexpr mime_type_suffixes = std::array{ { "davmount", "application/davmount+xml" }, { "dbf", "application/vnd.dbf" }, { "dbk", "application/docbook+xml" }, + { "dcm", "application/dicom" }, + { "dcmp", "application/vnd.dcmp+xml" }, { "dcr", "application/x-director" }, { "dcurl", "text/vnd.curl.dcurl" }, { "dd2", "application/vnd.oma.dd2+xml" }, @@ -235,6 +243,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "dmp", "application/vnd.tcpdump.pcap" }, { "dms", "application/octet-stream" }, { "dna", "application/vnd.dna" }, + { "dng", "image/x-adobe-dng" }, { "doc", "application/msword" }, { "docm", "application/vnd.ms-word.document.macroenabled.12" }, { "docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }, @@ -246,6 +255,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "dpx", "image/dpx" }, { "dra", "audio/vnd.dra" }, { "drle", "image/dicom-rle" }, + { "drm", "application/vnd.procreate.dream" }, { "dsc", "text/prs.lines.tag" }, { "dssc", "application/dssc+der" }, { "dtb", "application/x-dtbook+xml" }, @@ -303,6 +313,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "f77", "text/x-fortran" }, { "f90", "text/x-fortran" }, { "fbs", "image/vnd.fastbidsheet" }, + { "fbx", "application/vnd.autodesk.fbx" }, { "fcdt", "application/vnd.adobe.formscentral.fcdt" }, { "fcs", "application/vnd.isac.fcs" }, { "fdf", "application/fdf" }, @@ -348,17 +359,22 @@ inline auto constexpr mime_type_suffixes = std::array{ { "gca", "application/x-gca-compressed" }, { "gdl", "model/vnd.gdl" }, { "gdoc", "application/vnd.google-apps.document" }, + { "gdraw", "application/vnd.google-apps.drawing" }, { "ged", "text/vnd.familysearch.gedcom" }, { "geo", "application/vnd.dynageo" }, { "geojson", "application/geo+json" }, { "gex", "application/vnd.geometry-explorer" }, + { "gform", "application/vnd.google-apps.form" }, { "ggb", "application/vnd.geogebra.file" }, + { "ggs", "application/vnd.geogebra.slides" }, { "ggt", "application/vnd.geogebra.tool" }, { "ghf", "application/vnd.groove-help" }, { "gif", "image/gif" }, { "gim", "application/vnd.groove-identity-message" }, + { "gjam", "application/vnd.google-apps.jam" }, { "glb", "model/gltf-binary" }, { "gltf", "model/gltf+json" }, + { "gmap", "application/vnd.google-apps.map" }, { "gml", "application/gml+xml" }, { "gmx", "application/vnd.gmx" }, { "gnumeric", "application/x-gnumeric" }, @@ -371,8 +387,10 @@ inline auto constexpr mime_type_suffixes = std::array{ { "gre", "application/vnd.geometry-explorer" }, { "grv", "application/vnd.groove-injector" }, { "grxml", "application/srgs+xml" }, + { "gscript", "application/vnd.google-apps.script" }, { "gsf", "application/x-font-ghostscript" }, { "gsheet", "application/vnd.google-apps.spreadsheet" }, + { "gsite", "application/vnd.google-apps.site" }, { "gslides", "application/vnd.google-apps.presentation" }, { "gtar", "application/x-gtar" }, { "gtm", "application/vnd.groove-tool-message" }, @@ -403,7 +421,6 @@ inline auto constexpr mime_type_suffixes = std::array{ { "hpid", "application/vnd.hp-hpid" }, { "hps", "application/vnd.hp-hps" }, { "hqx", "application/mac-binhex40" }, - { "hsj2", "image/hsj2" }, { "htc", "text/x-component" }, { "htke", "application/vnd.kenameaapp" }, { "htm", "text/html" }, @@ -438,6 +455,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "iota", "application/vnd.astraea-software.iota" }, { "ipfix", "application/ipfix" }, { "ipk", "application/vnd.shana.informed.package" }, + { "ipynb", "application/x-ipynb+json" }, { "irm", "application/vnd.ibm.rights-management" }, { "irp", "application/vnd.irepository.package+xml" }, { "iso", "application/octet-stream" }, @@ -448,10 +466,13 @@ inline auto constexpr mime_type_suffixes = std::array{ { "ivu", "application/vnd.immervision-ivu" }, { "jad", "text/vnd.sun.j2me.app-descriptor" }, { "jade", "text/jade" }, + { "jaii", "image/jaii" }, + { "jais", "image/jais" }, { "jam", "application/vnd.jam" }, { "jar", "application/java-archive" }, { "jardiff", "application/x-java-archive-diff" }, { "java", "text/x-java-source" }, + { "jfif", "image/pjpeg" }, { "jhc", "image/jphc" }, { "jisp", "application/vnd.jisp" }, { "jls", "image/jls" }, @@ -480,6 +501,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "jsonml", "application/jsonml+json" }, { "jsx", "text/jsx" }, { "jt", "model/jt" }, + { "jxl", "image/jxl" }, { "jxr", "image/jxr" }, { "jxra", "image/jxra" }, { "jxrs", "image/jxrs" }, @@ -525,6 +547,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "lnk", "application/x-ms-shortcut" }, { "log", "text/plain" }, { "lostxml", "application/lost+xml" }, + { "lottie", "application/zip+dotlottie" }, { "lrf", "application/octet-stream" }, { "lrm", "application/vnd.ms-lrm" }, { "ltf", "application/vnd.frogans.ltf" }, @@ -538,12 +561,15 @@ inline auto constexpr mime_type_suffixes = std::array{ { "m1v", "video/mpeg" }, { "m21", "application/mp21" }, { "m2a", "audio/mpeg" }, + { "m2t", "video/mp2t" }, + { "m2ts", "video/mp2t" }, { "m2v", "video/mpeg" }, { "m3a", "audio/mpeg" }, { "m3u", "audio/x-mpegurl" }, { "m3u8", "application/vnd.apple.mpegurl" }, { "m4a", "audio/mp4" }, { "m4a", "audio/x-m4a" }, + { "m4b", "audio/mp4" }, { "m4p", "application/mp4" }, { "m4s", "video/iso.segment" }, { "m4u", "video/vnd.mpegurl" }, @@ -578,6 +604,8 @@ inline auto constexpr mime_type_suffixes = std::array{ { "mft", "application/rpki-manifest" }, { "mgp", "application/vnd.osgeo.mapguide.package" }, { "mgz", "application/vnd.proteus.magazine" }, + { "mht", "message/rfc822" }, + { "mhtml", "message/rfc822" }, { "mid", "audio/midi" }, { "midi", "audio/midi" }, { "mie", "application/x-mie" }, @@ -648,6 +676,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "msty", "application/vnd.muvee.style" }, { "mtl", "model/mtl" }, { "mts", "model/vnd.mts" }, + { "mts", "video/mp2t" }, { "mus", "application/vnd.musician" }, { "musd", "application/mmt-usd+xml" }, { "musicxml", "application/vnd.recordare.musicxml+xml" }, @@ -707,6 +736,8 @@ inline auto constexpr mime_type_suffixes = std::array{ { "ogv", "video/ogg" }, { "ogx", "application/ogg" }, { "omdoc", "application/omdoc+xml" }, + { "one", "application/onenote" }, + { "onea", "application/onenote" }, { "onepkg", "application/onenote" }, { "onetmp", "application/onenote" }, { "onetoc", "application/onenote" }, @@ -736,6 +767,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "p", "text/x-pascal" }, { "p10", "application/pkcs10" }, { "p12", "application/x-pkcs12" }, + { "p21", "model/step" }, { "p7b", "application/x-pkcs7-certificates" }, { "p7c", "application/pkcs7-mime" }, { "p7m", "application/pkcs7-mime" }, @@ -836,6 +868,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "raml", "application/raml+yaml" }, { "rapd", "application/route-apd+xml" }, { "rar", "application/vnd.rar" }, + { "rar", "application/x-compressed" }, { "rar", "application/x-rar-compressed" }, { "ras", "image/x-cmu-raster" }, { "rcprofile", "application/vnd.ipunplugged.rcprofile" }, @@ -967,11 +1000,14 @@ inline auto constexpr mime_type_suffixes = std::array{ { "st", "application/vnd.sailingtracker.track" }, { "stc", "application/vnd.sun.xml.calc.template" }, { "std", "application/vnd.sun.xml.draw.template" }, + { "step", "model/step" }, { "stf", "application/vnd.wt.stf" }, { "sti", "application/vnd.sun.xml.impress.template" }, { "stk", "application/hyperstudio" }, { "stl", "application/vnd.ms-pki.stl" }, { "stl", "model/stl" }, + { "stp", "model/step" }, + { "stpnc", "model/step" }, { "stpx", "model/step+xml" }, { "stpxz", "model/step-xml+zip" }, { "stpz", "model/step+zip" }, @@ -1106,6 +1142,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "vcx", "application/vnd.vcx" }, { "vdi", "application/x-virtualbox-vdi" }, { "vds", "model/vnd.sap.vds" }, + { "vdx", "application/vnd.ms-visio.viewer" }, { "vhd", "application/x-virtualbox-vhd" }, { "vis", "application/vnd.visionary" }, { "viv", "video/vnd.vivo" }, @@ -1115,6 +1152,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "vox", "application/x-authorware-bin" }, { "vrml", "model/vrml" }, { "vsd", "application/vnd.visio" }, + { "vsdx", "application/vnd.visio" }, { "vsf", "application/vnd.vsf" }, { "vss", "application/vnd.visio" }, { "vst", "application/vnd.visio" }, @@ -1122,6 +1160,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "vtf", "image/vnd.valve.source.texture" }, { "vtt", "text/vtt" }, { "vtu", "model/vnd.vtu" }, + { "vtx", "application/vnd.visio" }, { "vxml", "application/voicexml+xml" }, { "w3d", "application/x-director" }, { "wad", "application/x-doom" }, @@ -1194,6 +1233,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "xbm", "image/x-xbitmap" }, { "xca", "application/xcap-caps+xml" }, { "xcs", "application/calendar+xml" }, + { "xdcf", "application/vnd.gov.sk.xmldatacontainer+xml" }, { "xdf", "application/xcap-diff+xml" }, { "xdm", "application/vnd.syncml.dm+xml" }, { "xdp", "application/vnd.adobe.xdp+xml" }, @@ -1264,6 +1304,7 @@ inline auto constexpr mime_type_suffixes = std::array{ { "z7", "application/x-zmachine" }, { "z8", "application/x-zmachine" }, { "zaz", "application/vnd.zzazz.deck+xml" }, + { "zip", "application/x-zip-compressed" }, { "zip", "application/zip" }, { "zir", "application/vnd.zul" }, { "zirz", "application/vnd.zul" }, diff --git a/libtransmission/mime-types.js b/libtransmission/mime-types.js index 3dc7dedb9..1ea1afb42 100755 --- a/libtransmission/mime-types.js +++ b/libtransmission/mime-types.js @@ -52,7 +52,7 @@ struct mime_type_suffix std::string_view mime_type; }; -inline auto constexpr mime_type_suffixes = std::array{ +inline auto constexpr MimeTypeSuffixes = std::array{ { ${mime_type_lines.trim()} } }; `); diff --git a/libtransmission/net.cc b/libtransmission/net.cc index 805a8b2da..4c2f559fa 100644 --- a/libtransmission/net.cc +++ b/libtransmission/net.cc @@ -487,7 +487,7 @@ std::pair tr_port::from_compact(std::byte const* comp std::optional tr_address::from_string(std::string_view address_sv) { - auto const address_sz = tr_strbuf{ address_sv }; + auto const address_sz = tr_strbuf{ address_sv }; auto ss = sockaddr_storage{}; auto sslen = int{ sizeof(ss) }; @@ -814,8 +814,7 @@ std::optional tr_socket_address::from_string(std::string_view { auto ss = sockaddr_storage{}; auto sslen = int{ sizeof(ss) }; - if (evutil_parse_sockaddr_port(tr_strbuf{ sockaddr_sv }, reinterpret_cast(&ss), &sslen) != - 0) + if (evutil_parse_sockaddr_port(tr_strbuf{ sockaddr_sv }, reinterpret_cast(&ss), &sslen) != 0) { return {}; } diff --git a/libtransmission/net.h b/libtransmission/net.h index ab62631ea..088541971 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -194,7 +194,7 @@ struct tr_address } template - OutputIt to_compact(OutputIt out) const + OutputIt to_compact(OutputIt out) const // NOLINT(modernize-use-nodiscard) { switch (type) { @@ -255,7 +255,7 @@ struct tr_address { struct in6_addr addr6; struct in_addr addr4; - } addr; + } addr = {}; static auto constexpr CompactAddrBytes = std::array{ 4U, 16U }; static auto constexpr CompactAddrMaxBytes = *std::max_element(std::begin(CompactAddrBytes), std::end(CompactAddrBytes)); @@ -362,7 +362,7 @@ struct tr_socket_address } template - OutputIt to_compact(OutputIt out) const + OutputIt to_compact(OutputIt out) const // NOLINT(modernize-use-nodiscard) { return to_compact(out, address_, port_); } @@ -389,7 +389,7 @@ struct tr_socket_address // --- sockaddr helpers [[nodiscard]] static std::optional from_string(std::string_view sockaddr_sv); - [[nodiscard]] static std::optional from_sockaddr(sockaddr const*); + [[nodiscard]] static std::optional from_sockaddr(sockaddr const* from); [[nodiscard]] static std::pair to_sockaddr(tr_address const& addr, tr_port port) noexcept; [[nodiscard]] std::pair to_sockaddr() const noexcept @@ -488,12 +488,13 @@ public: { } + // NOLINTNEXTLINE(google-explicit-constructor) [[nodiscard]] constexpr operator int() const noexcept { return value_; } - [[nodiscard]] static std::optional from_string(std::string_view); + [[nodiscard]] static std::optional from_string(std::string_view name); [[nodiscard]] std::string toString() const; diff --git a/libtransmission/observable.h b/libtransmission/observable.h index fcff8967e..2b3d22384 100644 --- a/libtransmission/observable.h +++ b/libtransmission/observable.h @@ -67,7 +67,7 @@ private: // remove-during-emit; this is meant to be as lightweight // as possible for very basic use cases. template -class SimpleObservable +class SimpleObservable // NOLINT(cppcoreguidelines-special-member-functions) { using Key = size_t; @@ -104,6 +104,8 @@ private: TR_ASSERT(n_removed == 1U); } + // TODO: Re-enable after setting readability-identifier-naming.PrivateMemberSuffix to _ + // NOLINTNEXTLINE(readability-identifier-naming) static auto inline next_key_ = Key{ 1U }; small::map observers_; }; diff --git a/libtransmission/peer-common.h b/libtransmission/peer-common.h index 937d396fb..0b6e1c678 100644 --- a/libtransmission/peer-common.h +++ b/libtransmission/peer-common.h @@ -45,7 +45,7 @@ class tr_peer_event } public: - enum class Type + enum class Type : uint8_t { // Unless otherwise specified, all events are for BT peers only ClientGotBlock, // applies to webseed too @@ -275,9 +275,9 @@ struct tr_swarm_stats // connected peers uint16_t peer_count; // connected peers by peer source - std::array peer_from_count; + std::array peer_from_count; // known peers by peer source - std::array known_peer_from_count; + std::array known_peer_from_count; }; tr_swarm_stats tr_swarmGetStats(tr_swarm const* swarm); diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index 01900da27..dea6b12f6 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -59,8 +59,8 @@ class tr_peerIo final : public std::enable_shared_from_this using DH = tr_message_stream_encryption::DH; using Filter = tr_message_stream_encryption::Filter; using CanRead = ReadState (*)(tr_peerIo* io, void* user_data, size_t* setme_piece_byte_count); - using DidWrite = void (*)(tr_peerIo* io, size_t bytesWritten, bool wasPieceData, void* userData); - using GotError = void (*)(tr_peerIo* io, tr_error const& error, void* userData); + using DidWrite = void (*)(tr_peerIo* io, size_t bytes_written, bool was_piece_data, void* user_data); + using GotError = void (*)(tr_peerIo* io, tr_error const& error, void* user_data); public: tr_peerIo( @@ -73,6 +73,11 @@ public: ~tr_peerIo(); + tr_peerIo(tr_peerIo const&) = delete; + tr_peerIo(tr_peerIo&&) = delete; + tr_peerIo& operator=(tr_peerIo const&) = delete; + tr_peerIo& operator=(tr_peerIo&&) = delete; + static std::shared_ptr new_outgoing( tr_session* session, tr_bandwidth* parent, @@ -96,7 +101,7 @@ public: set_callbacks(nullptr, nullptr, nullptr, nullptr); } - void set_socket(tr_peer_socket); + void set_socket(tr_peer_socket socket_in); [[nodiscard]] constexpr auto is_utp() const noexcept { diff --git a/libtransmission/peer-mgr.cc b/libtransmission/peer-mgr.cc index 4c1a93628..cc4c7b660 100644 --- a/libtransmission/peer-mgr.cc +++ b/libtransmission/peer-mgr.cc @@ -468,7 +468,7 @@ public: tr_peer_from const from) { TR_ASSERT(socket_address.is_valid()); - TR_ASSERT(from < TR_PEER_FROM__MAX); + TR_ASSERT(from < TR_PEER_FROM_N_TYPES); auto peer_info = get_existing_peer_info(socket_address); if (peer_info) @@ -2585,7 +2585,7 @@ namespace connect_helpers /* Prefer peers that we got from more trusted sources. * lower `fromBest` values indicate more trusted sources */ - score = addValToKey(score, 4U, peer_info.from_best()); // TODO(tearfur): use std::bit_width(TR_PEER_FROM__MAX - 1) + score = addValToKey(score, 4U, peer_info.from_best()); // TODO(tearfur): use std::bit_width(TR_PEER_FROM_N_TYPES - 1) /* salt */ score = addValToKey(score, 8U, salt); diff --git a/libtransmission/peer-mgr.h b/libtransmission/peer-mgr.h index 14c6ce4e4..319d8fa0a 100644 --- a/libtransmission/peer-mgr.h +++ b/libtransmission/peer-mgr.h @@ -39,7 +39,7 @@ struct tr_session; struct tr_torrent; /* added_f's bitwise-or'ed flags */ -enum +enum : uint8_t { /* true if the peer supports encryption */ ADDED_F_ENCRYPTION_FLAG = 1, @@ -561,7 +561,7 @@ struct tr_pex } template - OutputIt to_compact(OutputIt out) const + OutputIt to_compact(OutputIt out) const // NOLINT(modernize-use-nodiscard) { return socket_address.to_compact(out); } @@ -653,7 +653,7 @@ void tr_peerMgrAddIncoming(tr_peerMgr* manager, tr_peer_socket&& socket); size_t tr_peerMgrAddPex(tr_torrent* tor, tr_peer_from from, tr_pex const* pex, size_t n_pex); -enum +enum : uint8_t { TR_PEERS_CONNECTED, TR_PEERS_INTERESTING diff --git a/libtransmission/peer-mse.h b/libtransmission/peer-mse.h index 778460ec8..191ce96b9 100644 --- a/libtransmission/peer-mse.h +++ b/libtransmission/peer-mse.h @@ -76,7 +76,7 @@ private: class Filter { public: - void decrypt_init(bool is_incoming, DH const&, tr_sha1_digest_t const& info_hash); + void decrypt_init(bool is_incoming, DH const& dh, tr_sha1_digest_t const& info_hash); constexpr void decrypt_disable() noexcept { dec_active_ = false; @@ -88,7 +88,7 @@ public: process(buf_in, buf_len, buf_out, dec_active_, dec_key_); } - void encrypt_init(bool is_incoming, DH const&, tr_sha1_digest_t const& info_hash); + void encrypt_init(bool is_incoming, DH const& dh, tr_sha1_digest_t const& info_hash); constexpr void encrypt_disable() noexcept { enc_active_ = false; diff --git a/libtransmission/peer-msgs.cc b/libtransmission/peer-msgs.cc index c2afc5e4e..6df6648c2 100644 --- a/libtransmission/peer-msgs.cc +++ b/libtransmission/peer-msgs.cc @@ -1179,7 +1179,7 @@ void tr_peerMsgsImpl::send_ltep_handshake() // you as. i.e. this is the receiver's external ip address (no port is included). // This may be either an IPv4 (4 bytes) or an IPv6 (16 bytes) address. { - auto buf = std::array{}; + auto buf = std::array{}; auto const begin = std::data(buf); auto const end = io_->address().to_compact(begin); auto const len = end - begin; diff --git a/libtransmission/peer-msgs.h b/libtransmission/peer-msgs.h index 433b7f55d..4a6f13af8 100644 --- a/libtransmission/peer-msgs.h +++ b/libtransmission/peer-msgs.h @@ -45,6 +45,11 @@ public: ~tr_peerMsgs() override; + tr_peerMsgs(tr_peerMsgs const&) = delete; + tr_peerMsgs(tr_peerMsgs&&) = delete; + tr_peerMsgs& operator=(tr_peerMsgs const&) = delete; + tr_peerMsgs& operator=(tr_peerMsgs&&) = delete; + [[nodiscard]] static auto size() noexcept { return n_peers.load(); diff --git a/libtransmission/peer-socket.h b/libtransmission/peer-socket.h index 3d70d4295..57693a898 100644 --- a/libtransmission/peer-socket.h +++ b/libtransmission/peer-socket.h @@ -103,7 +103,7 @@ public: [[nodiscard]] static bool limit_reached(tr_session const* session) noexcept; private: - enum class Type + enum class Type : uint8_t { None, TCP, @@ -114,5 +114,7 @@ private: enum Type type_ = Type::None; + // TODO: Re-enable after setting readability-identifier-naming.PrivateMemberSuffix to _ + // NOLINTNEXTLINE(readability-identifier-naming) static inline std::atomic n_open_sockets_ = {}; }; diff --git a/libtransmission/platform.h b/libtransmission/platform.h index 6d14e680e..bbe59837f 100644 --- a/libtransmission/platform.h +++ b/libtransmission/platform.h @@ -14,7 +14,7 @@ struct tr_session; /** @brief return the directory where the Web Client's web ui files are kept */ -[[nodiscard]] std::string tr_getWebClientDir(tr_session const*); +[[nodiscard]] std::string tr_getWebClientDir(tr_session const* session); /** @brief return the directory where session id lock files are stored */ [[nodiscard]] std::string tr_getSessionIdDir(); diff --git a/libtransmission/port-forwarding-natpmp.h b/libtransmission/port-forwarding-natpmp.h index 7f7949570..5df00bc97 100644 --- a/libtransmission/port-forwarding-natpmp.h +++ b/libtransmission/port-forwarding-natpmp.h @@ -31,6 +31,11 @@ public: closenatpmp(&natpmp_); } + tr_natpmp(tr_natpmp const&) = delete; + tr_natpmp(tr_natpmp&&) = delete; + tr_natpmp& operator=(tr_natpmp const&) = delete; + tr_natpmp& operator=(tr_natpmp&&) = delete; + [[nodiscard]] constexpr auto renewTime() const noexcept { return renew_time_; @@ -47,7 +52,7 @@ public: PulseResult pulse(tr_port local_port, bool is_enabled); private: - enum class State + enum class State : uint8_t { Idle, Err, diff --git a/libtransmission/port-forwarding-upnp.cc b/libtransmission/port-forwarding-upnp.cc index d1d4c3aa5..4b5d23776 100644 --- a/libtransmission/port-forwarding-upnp.cc +++ b/libtransmission/port-forwarding-upnp.cc @@ -26,7 +26,7 @@ #include "libtransmission/net.h" #include "libtransmission/port-forwarding-upnp.h" #include "libtransmission/tr-assert.h" -#include "libtransmission/tr-macros.h" // TR_ADDRSTRLEN +#include "libtransmission/tr-macros.h" // TrAddrStrlen #include "libtransmission/utils.h" // for _(), tr_strerror() #ifndef MINIUPNPC_API_VERSION @@ -260,7 +260,7 @@ tr_port_forwarding_state tr_upnpPulse( handle->discover_future.reset(); FreeUPNPUrls(&handle->urls); - auto lanaddr = std::array{}; + auto lanaddr = std::array{}; if ( #if (MINIUPNPC_API_VERSION >= 18) UPNP_GetValidIGD(devlist, &handle->urls, &handle->data, std::data(lanaddr), std::size(lanaddr) - 1, nullptr, 0) diff --git a/libtransmission/port-forwarding-upnp.h b/libtransmission/port-forwarding-upnp.h index 0d6d96e6a..ced8bc6b3 100644 --- a/libtransmission/port-forwarding-upnp.h +++ b/libtransmission/port-forwarding-upnp.h @@ -26,7 +26,7 @@ tr_upnp* tr_upnpInit(); void tr_upnpClose(tr_upnp* handle); tr_port_forwarding_state tr_upnpPulse( - tr_upnp*, + tr_upnp* handle, tr_port advertised_port, tr_port local_port, bool is_enabled, diff --git a/libtransmission/port-forwarding.h b/libtransmission/port-forwarding.h index a3344ce76..32e797224 100644 --- a/libtransmission/port-forwarding.h +++ b/libtransmission/port-forwarding.h @@ -35,7 +35,7 @@ public: virtual void on_port_forwarded(tr_port advertised_port) = 0; }; - [[nodiscard]] static std::unique_ptr create(Mediator&); + [[nodiscard]] static std::unique_ptr create(Mediator& mediator); virtual ~tr_port_forwarding() = default; [[nodiscard]] virtual bool is_enabled() const = 0; diff --git a/libtransmission/quark.h b/libtransmission/quark.h index 99a35c41d..dac37310c 100644 --- a/libtransmission/quark.h +++ b/libtransmission/quark.h @@ -19,7 +19,7 @@ using tr_quark = size_t; * between RPC and settings. This will be a mess and we shouldn't be * in a hurry to do it. */ -enum +enum // NOLINT(performance-enum-size) { TR_KEY_NONE, /* represented as an empty string */ TR_KEY_activeTorrentCount, /* rpc */ diff --git a/libtransmission/rpc-server.h b/libtransmission/rpc-server.h index 18650a36e..3dc0b304d 100644 --- a/libtransmission/rpc-server.h +++ b/libtransmission/rpc-server.h @@ -54,13 +54,13 @@ public: bool is_whitelist_enabled = true; size_t anti_brute_force_limit = 100U; std::string bind_address_str = "0.0.0.0"; - std::string host_whitelist_str = ""; - std::string salted_password = ""; + std::string host_whitelist_str; + std::string salted_password; std::string url = TR_DEFAULT_RPC_URL_STR; - std::string username = ""; + std::string username; std::string whitelist_str = TR_DEFAULT_RPC_WHITELIST; tr_mode_t socket_mode = 0750; - tr_port port = tr_port::from_host(TR_DEFAULT_RPC_PORT); + tr_port port = tr_port::from_host(TrDefaultRpcPort); private: [[nodiscard]] Fields fields() override diff --git a/libtransmission/session-alt-speeds.h b/libtransmission/session-alt-speeds.h index ee3088cd1..8cf95d77d 100644 --- a/libtransmission/session-alt-speeds.h +++ b/libtransmission/session-alt-speeds.h @@ -180,9 +180,9 @@ private: // whether `time` hits in one of the `minutes_` that is true [[nodiscard]] bool is_active_minute(time_t time) const noexcept; - static auto constexpr MinutesPerHour = int{ 60 }; - static auto constexpr MinutesPerDay = int{ MinutesPerHour * 24 }; - static auto constexpr MinutesPerWeek = int{ MinutesPerDay * 7 }; + static int constexpr MinutesPerHour = 60; + static int constexpr MinutesPerDay = MinutesPerHour * 24; + static int constexpr MinutesPerWeek = MinutesPerDay * 7; // bitfield of all the minutes in a week. // Each bit's value indicates whether the scheduler wants diff --git a/libtransmission/session-id.h b/libtransmission/session-id.h index 61aaf5e00..3309b5c5c 100644 --- a/libtransmission/session-id.h +++ b/libtransmission/session-id.h @@ -36,7 +36,7 @@ public: * relative paths to absolute before passing through RPC, or presenting * different UI for local and remote sessions. */ - [[nodiscard]] static bool is_local(std::string_view) noexcept; + [[nodiscard]] static bool is_local(std::string_view session_id) noexcept; // current session identifier [[nodiscard]] std::string_view sv() const noexcept; diff --git a/libtransmission/session-thread.h b/libtransmission/session-thread.h index c0c6a617b..7185f8d03 100644 --- a/libtransmission/session-thread.h +++ b/libtransmission/session-thread.h @@ -34,12 +34,20 @@ public: template void queue(Func&& func, Args&&... args) { - queue(std::function{ std::bind(std::forward(func), std::forward(args)...) }); + // TODO(tearfur): Use C++20 P0780R2, GCC 9, clang 9 + queue(std::function{ + [func = std::forward(func), args = std::make_tuple(std::forward(args)...)]() + { std::apply(std::move(func), std::move(args)); }, + }); } template void run(Func&& func, Args&&... args) { - run(std::function{ std::bind(std::forward(func), std::forward(args)...) }); + // TODO(tearfur): Use C++20 P0780R2, GCC 9, clang 9 + run(std::function{ + [func = std::forward(func), args = std::make_tuple(std::forward(args)...)]() + { std::apply(std::move(func), std::move(args)); }, + }); } }; diff --git a/libtransmission/session.h b/libtransmission/session.h index 1c12d7f7e..cf20645d9 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -163,7 +163,7 @@ private: class DhtMediator : public tr_dht::Mediator { public: - DhtMediator(tr_session& session) noexcept + explicit DhtMediator(tr_session& session) noexcept : session_{ session } { } @@ -184,7 +184,7 @@ private: return session_.timerMaker(); } - void add_pex(tr_sha1_digest_t const&, tr_pex const* pex, size_t n_pex) override; + void add_pex(tr_sha1_digest_t const& info_hash, tr_pex const* pex, size_t n_pex) override; private: tr_session& session_; @@ -353,6 +353,11 @@ private: tr_udp_core(tr_session& session, tr_port udp_port); ~tr_udp_core(); + tr_udp_core(tr_udp_core const&) = delete; + tr_udp_core(tr_udp_core&&) = delete; + tr_udp_core& operator=(tr_udp_core const&) = delete; + tr_udp_core& operator=(tr_udp_core&&) = delete; + void sendto(void const* buf, size_t buflen, struct sockaddr const* to, socklen_t tolen) const; [[nodiscard]] constexpr auto socket4() const noexcept @@ -416,8 +421,8 @@ public: size_t cache_size_mbytes = 4U; size_t download_queue_size = 5U; size_t idle_seeding_limit_minutes = 30U; - size_t peer_limit_global = TR_DEFAULT_PEER_LIMIT_GLOBAL; - size_t peer_limit_per_torrent = TR_DEFAULT_PEER_LIMIT_TORRENT; + size_t peer_limit_global = TrDefaultPeerLimitGlobal; + size_t peer_limit_per_torrent = TrDefaultPeerLimitTorrent; size_t queue_stalled_minutes = 30U; size_t reqq = 2000U; size_t seed_queue_size = 10U; @@ -444,7 +449,7 @@ public: tr_open_files::Preallocation preallocation_mode = tr_open_files::Preallocation::Sparse; tr_port peer_port_random_high = tr_port::from_host(65535); tr_port peer_port_random_low = tr_port::from_host(49152); - tr_port peer_port = tr_port::from_host(TR_DEFAULT_PEER_PORT); + tr_port peer_port = tr_port::from_host(TrDefaultPeerPort); tr_tos_t peer_socket_tos{ 0x04 }; tr_verify_added_mode torrent_added_verify_mode = TR_VERIFY_ADDED_FAST; @@ -1103,6 +1108,7 @@ public: void addTorrent(tr_torrent* tor); + // NOLINTNEXTLINE(readability-make-member-function-const) void maybe_add_dht_node(tr_address const& addr, tr_port port) { if (dht_) @@ -1149,7 +1155,7 @@ private: void onAdvertisedPeerPortChanged(); struct init_data; - void initImpl(init_data&); + void initImpl(init_data& data); void setSettings(tr_variant const& settings_map, bool force); void setSettings(Settings&& settings, bool force); @@ -1311,7 +1317,6 @@ private: QueueMediator torrent_queue_mediator_{ *this }; tr_torrent_queue torrent_queue_{ torrent_queue_mediator_ }; -private: /// other fields // depends-on: session_thread_, settings_.bind_address_ipv4, local_peer_port_, global_ip_cache (via tr_session::bind_address()) diff --git a/libtransmission/stats.h b/libtransmission/stats.h index e77bd36cf..ff94cdcdb 100644 --- a/libtransmission/stats.h +++ b/libtransmission/stats.h @@ -33,6 +33,11 @@ public: save(); } + tr_stats(tr_stats const&) = delete; + tr_stats(tr_stats&&) = delete; + tr_stats& operator=(tr_stats const&) = delete; + tr_stats& operator=(tr_stats&&) = delete; + void clear(); [[nodiscard]] tr_session_stats current() const; diff --git a/libtransmission/torrent-queue.h b/libtransmission/torrent-queue.h index a9273c8e4..af2e11fe9 100644 --- a/libtransmission/torrent-queue.h +++ b/libtransmission/torrent-queue.h @@ -31,6 +31,7 @@ public: : mediator_{ mediator } { } + ~tr_torrent_queue() = default; tr_torrent_queue(tr_torrent_queue const&) = delete; tr_torrent_queue(tr_torrent_queue&&) = delete; tr_torrent_queue& operator=(tr_torrent_queue const&) = delete; @@ -42,7 +43,7 @@ public: [[nodiscard]] size_t get_pos(tr_torrent_id_t id); void set_pos(tr_torrent_id_t id, size_t new_pos); - bool to_file() const; + bool to_file() const; // NOLINT(modernize-use-nodiscard) [[nodiscard]] std::vector from_file(); static auto constexpr MinQueuePosition = size_t{}; diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 632546767..a23323c13 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -1285,7 +1285,7 @@ tr_stat tr_torrent::stats() const stats.peersGettingFromUs = swarm_stats.active_peer_count[TR_UP]; stats.webseedsSendingToUs = swarm_stats.active_webseed_count; - for (int i = 0; i < TR_PEER_FROM__MAX; i++) + for (int i = 0; i < TR_PEER_FROM_N_TYPES; i++) { stats.peersFrom[i] = swarm_stats.peer_from_count[i]; stats.knownPeersFrom[i] = swarm_stats.known_peer_from_count[i]; diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index d706312c8..abd576004 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -95,7 +95,7 @@ struct tr_torrent friend class libtransmission::test::RenameTest_singleFilenameTorrent_Test; friend struct tr_torrent; - ResumeHelper(tr_torrent& tor) + explicit ResumeHelper(tr_torrent& tor) : tor_{ tor } { } @@ -965,7 +965,7 @@ struct tr_torrent return session->torrent_queue().get_pos(id()); } - void set_queue_position(size_t new_pos) + void set_queue_position(size_t new_pos) // NOLINT(readability-make-member-function-const) { session->torrent_queue().set_pos(id(), new_pos); } @@ -1393,7 +1393,7 @@ private: uint16_t idle_limit_minutes_ = 0; - uint16_t max_connected_peers_ = TR_DEFAULT_PEER_LIMIT_TORRENT; + uint16_t max_connected_peers_ = TrDefaultPeerLimitTorrent; bool is_deleting_ = false; bool is_dirty_ = false; diff --git a/libtransmission/tr-arc4.h b/libtransmission/tr-arc4.h index ff1eee7c7..4f69ca7fa 100644 --- a/libtransmission/tr-arc4.h +++ b/libtransmission/tr-arc4.h @@ -42,7 +42,7 @@ public: for (size_t i = 0, j = 0; i < 256; ++i) { - j = static_cast(j + s_[i] + ((uint8_t const*)key)[i % key_length]); + j = static_cast(j + s_[i] + reinterpret_cast(key)[i % key_length]); arc4_swap(i, j); } } diff --git a/libtransmission/tr-buffer.h b/libtransmission/tr-buffer.h index 10206f607..70da6fefe 100644 --- a/libtransmission/tr-buffer.h +++ b/libtransmission/tr-buffer.h @@ -255,6 +255,7 @@ class StackBuffer final { public: StackBuffer() = default; + ~StackBuffer() override = default; StackBuffer(StackBuffer&&) = delete; StackBuffer(StackBuffer const&) = delete; StackBuffer& operator=(StackBuffer&&) = delete; diff --git a/libtransmission/tr-getopt.h b/libtransmission/tr-getopt.h index 2ea90731a..86af50898 100644 --- a/libtransmission/tr-getopt.h +++ b/libtransmission/tr-getopt.h @@ -5,6 +5,8 @@ #pragma once +#include + /** * @addtogroup utils Utilities * @{ @@ -23,7 +25,7 @@ struct tr_option char const* argName; /* argument's description for tr_getopt_usage() */ }; -enum +enum : int8_t { /* all options have been processed */ TR_OPT_DONE = 0, diff --git a/libtransmission/tr-macros.h b/libtransmission/tr-macros.h index ea841552c..e8b81bb7f 100644 --- a/libtransmission/tr-macros.h +++ b/libtransmission/tr-macros.h @@ -39,9 +39,9 @@ // --- -#define TR_INET6_ADDRSTRLEN 46 +inline auto constexpr TrInet6AddrStrlen = 46U; -#define TR_ADDRSTRLEN 64 +inline auto constexpr TrAddrStrlen = 64U; // https://www.bittorrent.org/beps/bep_0007.html // "The client SHOULD include a key parameter in its announces. The key diff --git a/libtransmission/tr-popcount.h b/libtransmission/tr-popcount.h index cb4049eb2..9d1a65385 100644 --- a/libtransmission/tr-popcount.h +++ b/libtransmission/tr-popcount.h @@ -10,6 +10,7 @@ #ifndef TR_POPCNT_H #define TR_POPCNT_H +#include #include #include @@ -26,31 +27,31 @@ template struct tr_popcnt { - static_assert(std::is_integral::value != 0, "Can only popcnt integral types"); + static_assert(std::is_integral_v != 0, "Can only popcnt integral types"); static_assert(sizeof(T) <= sizeof(uint64_t), "Unsupported size"); /* Needed regularly to avoid sign extension / get unsigned shift behavior. */ - using unsigned_T = typename std::make_unsigned::type; + using unsigned_T = typename std::make_unsigned_t; /* Sanity tests. */ static_assert(sizeof(unsigned_T) == sizeof(T), "Unsigned type somehow smaller than signed type"); - static_assert(std::is_integral::value != 0, "Unsigned type somehow non integral"); + static_assert(std::is_integral_v != 0, "Unsigned type somehow non integral"); #if defined(TR_HAVE_STD_POPCOUNT) /* If we have std::popcount just use that. */ - static constexpr inline unsigned count(T v) + static constexpr unsigned count(T v) { - unsigned_T unsigned_v = static_cast(v); + auto const unsigned_v = static_cast(v); return static_cast(std::popcount(unsigned_v)); } #else /* Generic implementation. */ - static inline unsigned count(T v) + static constexpr unsigned count(T v) { /* To avoid signed shifts. */ - unsigned_T unsigned_v = static_cast(v); + auto unsigned_v = static_cast(v); if constexpr (sizeof(T) <= sizeof(uint16_t)) { @@ -58,7 +59,7 @@ struct tr_popcnt * byte for each value if ever hit a case where perf is * limited by severe bottleneck on L1D this can be * optimized. */ - static constexpr uint8_t popcnt_lut[256] = { + constexpr auto PopcntLut = std::array{ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, @@ -69,11 +70,11 @@ struct tr_popcnt }; if constexpr (sizeof(T) == sizeof(uint8_t)) { - return popcnt_lut[unsigned_v]; + return PopcntLut[unsigned_v]; } else { - return popcnt_lut[unsigned_v & 0xFF] + popcnt_lut[unsigned_v >> 8]; + return PopcntLut[unsigned_v & 0xFF] + PopcntLut[unsigned_v >> 8]; } } else @@ -81,16 +82,16 @@ struct tr_popcnt /* for larger sizes use implementation described here: * http://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation */ - static constexpr unsigned_T m1 = static_cast(0x5555555555555555ll); - static constexpr unsigned_T m2 = static_cast(0x3333333333333333ll); - static constexpr unsigned_T m4 = static_cast(0x0F0F0F0F0F0F0F0Fll); - static constexpr unsigned_T h01 = static_cast(0x0101010101010101ll); + constexpr auto M1 = static_cast(0x5555555555555555LL); + constexpr auto M2 = static_cast(0x3333333333333333LL); + constexpr auto M4 = static_cast(0x0F0F0F0F0F0F0F0FLL); + constexpr auto H01 = static_cast(0x0101010101010101LL); - unsigned_v = unsigned_v - ((unsigned_v >> 1) & m1); - unsigned_v = (unsigned_v & m2) + ((unsigned_v >> 2) & m2); - unsigned_v = (unsigned_v + (unsigned_v >> 4)) & m4; + unsigned_v = unsigned_v - ((unsigned_v >> 1) & M1); + unsigned_v = (unsigned_v & M2) + ((unsigned_v >> 2) & M2); + unsigned_v = (unsigned_v + (unsigned_v >> 4)) & M4; - unsigned_v = unsigned_v * h01; + unsigned_v = unsigned_v * H01; return unsigned_v >> (8 * sizeof(T) - 8); } } diff --git a/libtransmission/tr-strbuf.h b/libtransmission/tr-strbuf.h index 358015859..977fad596 100644 --- a/libtransmission/tr-strbuf.h +++ b/libtransmission/tr-strbuf.h @@ -51,13 +51,15 @@ public: return *this; } - tr_strbuf(tr_strbuf&& other) + tr_strbuf(tr_strbuf&& other) noexcept : buffer_{ std::move(other.buffer_) } { ensure_sz(); } - tr_strbuf& operator=(tr_strbuf&& other) + ~tr_strbuf() = default; + + tr_strbuf& operator=(tr_strbuf&& other) noexcept { buffer_ = std::move(other.buffer_); ensure_sz(); @@ -269,11 +271,13 @@ public: join(std::basic_string_view{ sz_delim }, args...); } + // NOLINTNEXTLINE(google-explicit-constructor) [[nodiscard]] constexpr operator std::basic_string_view() const noexcept { return sv(); } + // NOLINTNEXTLINE(google-explicit-constructor) [[nodiscard]] constexpr operator auto() const noexcept { return c_str(); @@ -281,6 +285,7 @@ public: bool popdir() noexcept { + // NOLINTNEXTLINE(readability-redundant-declaration): P.S. This looks like some dark magic std::string_view tr_sys_path_dirname(std::string_view path); auto const parent = tr_sys_path_dirname(sv()); auto const changed = parent != sv(); diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index ddd3e0e6e..85dc16fee 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -55,7 +55,7 @@ struct tr_variant; #define TR_RPC_SESSION_ID_HEADER "X-Transmission-Session-Id" -enum tr_verify_added_mode +enum tr_verify_added_mode : uint8_t { // See discussion @ https://github.com/transmission/transmission/pull/2626 // Let newly-added torrents skip upfront verify do it on-demand later. @@ -65,7 +65,7 @@ enum tr_verify_added_mode TR_VERIFY_ADDED_FULL = 1 }; -enum tr_encryption_mode +enum tr_encryption_mode : uint8_t { TR_CLEAR_PREFERRED, TR_ENCRYPTION_PREFERRED, @@ -79,8 +79,11 @@ enum tr_priority_t : int8_t TR_PRI_HIGH = 1 }; -#define TR_RATIO_NA (-1) -#define TR_RATIO_INF (-2) +enum : int8_t +{ + TR_RATIO_NA = -1, + TR_RATIO_INF = -2 +}; // --- Startup & Shutdown @@ -129,15 +132,15 @@ size_t tr_getDefaultDownloadDirToBuf(char* buf, size_t buflen); #define TR_DEFAULT_RPC_WHITELIST "127.0.0.1,::1" #define TR_DEFAULT_RPC_PORT_STR "9091" -#define TR_DEFAULT_RPC_PORT 9091 +inline auto constexpr TrDefaultRpcPort = 9091U; #define TR_DEFAULT_RPC_URL_STR "/transmission/" #define TR_DEFAULT_PEER_PORT_STR "51413" -#define TR_DEFAULT_PEER_PORT 51413 +inline auto constexpr TrDefaultPeerPort = 51413U; #define TR_DEFAULT_PEER_SOCKET_TOS_STR "le" #define TR_DEFAULT_PEER_LIMIT_GLOBAL_STR "200" -#define TR_DEFAULT_PEER_LIMIT_GLOBAL 200 +inline auto constexpr TrDefaultPeerLimitGlobal = 200U; #define TR_DEFAULT_PEER_LIMIT_TORRENT_STR "50" -#define TR_DEFAULT_PEER_LIMIT_TORRENT 50 +inline auto constexpr TrDefaultPeerLimitTorrent = 50U; /** * Add libtransmission's default settings to the benc dictionary. @@ -365,7 +368,7 @@ void tr_sessionSetRPCPasswordEnabled(tr_session* session, bool is_enabled); void tr_sessionSetDefaultTrackers(tr_session* session, char const* trackers); -enum tr_rpc_callback_type +enum tr_rpc_callback_type : uint8_t { TR_RPC_TORRENT_ADDED, TR_RPC_TORRENT_STARTED, @@ -379,7 +382,7 @@ enum tr_rpc_callback_type TR_RPC_SESSION_CLOSE }; -enum tr_rpc_callback_status +enum tr_rpc_callback_status : uint8_t { /* no special handling is needed by the caller */ TR_RPC_OK = 0, @@ -465,7 +468,7 @@ uint16_t tr_sessionSetPeerPortRandom(tr_session* session); bool tr_sessionGetPeerPortRandomOnStart(tr_session const* session); void tr_sessionSetPeerPortRandomOnStart(tr_session* session, bool random); -enum tr_port_forwarding_state +enum tr_port_forwarding_state : uint8_t { TR_PORT_ERROR, TR_PORT_UNMAPPED, @@ -476,7 +479,7 @@ enum tr_port_forwarding_state tr_port_forwarding_state tr_sessionGetPortForwarding(tr_session const* session); -enum tr_direction +enum tr_direction : uint8_t { TR_CLIENT_TO_PEER = 0, TR_UP = 0, @@ -509,7 +512,7 @@ void tr_sessionSetAltSpeedBegin(tr_session* session, size_t minutes_since_midnig size_t tr_sessionGetAltSpeedEnd(tr_session const* session); void tr_sessionSetAltSpeedEnd(tr_session* session, size_t minutes_since_midnight); -enum tr_sched_day +enum tr_sched_day : uint8_t { TR_SCHED_SUN = (1 << 0), TR_SCHED_MON = (1 << 1), @@ -664,7 +667,7 @@ size_t tr_sessionGetAllTorrents(tr_session* session, tr_torrent** buf, size_t bu // --- -enum TrScript +enum TrScript : uint8_t { TR_SCRIPT_ON_TORRENT_ADDED, TR_SCRIPT_ON_TORRENT_DONE, @@ -737,7 +740,7 @@ void tr_blocklistSetURL(tr_session* session, char const* url); * When ready, pass the builder object to `tr_torrentNew()`. */ -enum tr_ctorMode +enum tr_ctorMode : uint8_t { TR_FALLBACK, /* indicates the ctor value should be used only in case of missing resume settings */ TR_FORCE /* indicates the ctor value should be used regardless of what's in the resume settings */ @@ -902,7 +905,7 @@ void tr_torrentRenamePath( tr_torrent_rename_done_func callback, void* callback_user_data); -enum +enum : uint8_t { TR_LOC_MOVING, TR_LOC_DONE, @@ -973,7 +976,7 @@ void tr_torrentUseSessionLimits(tr_torrent* tor, bool enabled); // --- Ratio Limits -enum tr_ratiolimit +enum tr_ratiolimit : uint8_t { /* follow the global settings */ TR_RATIOLIMIT_GLOBAL = 0, @@ -993,7 +996,7 @@ bool tr_torrentGetSeedRatio(tr_torrent const* tor, double* ratio); // --- Idle Time Limits -enum tr_idlelimit +enum tr_idlelimit : uint8_t { /* follow the global settings */ TR_IDLELIMIT_GLOBAL = 0, @@ -1086,7 +1089,7 @@ bool tr_torrentSetTrackerList(tr_torrent* tor, char const* text); // --- -enum tr_completeness +enum tr_completeness : uint8_t { TR_LEECH, /* doesn't have all the desired pieces */ TR_SEED, /* has the entire torrent */ @@ -1169,6 +1172,7 @@ bool tr_torrentCanManualUpdate(tr_torrent const* torrent); // --- tr_peer_stat +// NOLINTBEGIN(modernize-avoid-c-arrays) struct tr_peer_stat { bool isUTP; @@ -1187,7 +1191,7 @@ struct tr_peer_stat uint8_t from; uint16_t port; - char addr[TR_INET6_ADDRSTRLEN]; + char addr[TrInet6AddrStrlen]; char flagStr[32]; char const* client; @@ -1212,6 +1216,7 @@ struct tr_peer_stat /* how many requests we've made and are currently awaiting a response for */ size_t activeReqsToPeer; }; +// NOLINTEND(modernize-avoid-c-arrays) tr_peer_stat* tr_torrentPeers(tr_torrent const* torrent, size_t* peer_count); @@ -1219,7 +1224,7 @@ void tr_torrentPeersFree(tr_peer_stat* peer_stats, size_t peer_count); // --- tr_tracker_stat -enum tr_tracker_state +enum tr_tracker_state : uint8_t { /* we won't (announce,scrape) this torrent to this tracker because * the torrent is stopped, or because of an error, or whatever */ @@ -1234,6 +1239,7 @@ enum tr_tracker_state TR_TRACKER_ACTIVE = 3 }; +// NOLINTBEGIN(modernize-avoid-c-arrays) /* * Unlike other _view structs, it is safe to keep a tr_tracker_view copy. * The announce and scrape strings are interned & never go out-of-scope. @@ -1280,6 +1286,7 @@ struct tr_tracker_view bool lastScrapeSucceeded; // if hasScraped, whether or not the latest scrape succeeded bool lastScrapeTimedOut; // true iff the latest scrape request timed out }; +// NOLINTEND(modernize-avoid-c-arrays) struct tr_tracker_view tr_torrentTracker(tr_torrent const* torrent, size_t i); @@ -1385,7 +1392,7 @@ bool tr_torrentHasMetadata(tr_torrent const* tor); * Note: these values will become a straight enum at some point in the future. * Do not rely on their current `bitfield` implementation */ -enum tr_torrent_activity +enum tr_torrent_activity : uint8_t { TR_STATUS_STOPPED = 0, /* Torrent is stopped */ TR_STATUS_CHECK_WAIT = 1, /* Queued to check files */ @@ -1404,15 +1411,15 @@ enum tr_peer_from : uint8_t TR_PEER_FROM_PEX, /* peers found from PEX */ TR_PEER_FROM_RESUME, /* peers found in the .resume file */ TR_PEER_FROM_LTEP, /* peer address provided in an LTEP handshake */ - TR_PEER_FROM__MAX + TR_PEER_FROM_N_TYPES }; -enum tr_eta : time_t +enum tr_eta : time_t // NOLINT(performance-enum-size) { TR_ETA_NOT_AVAIL = -1, TR_ETA_UNKNOWN = -2, }; -enum tr_stat_errtype +enum tr_stat_errtype : uint8_t { /* everything's fine */ TR_STAT_OK = 0, @@ -1424,6 +1431,7 @@ enum tr_stat_errtype TR_STAT_LOCAL_ERROR = 3 }; +// NOLINTBEGIN(modernize-avoid-c-arrays) /** @brief Used by `tr_torrentStat()` to tell clients about a torrent's state and statistics */ struct tr_stat { @@ -1563,11 +1571,11 @@ struct tr_stat /** How many connected peers we found out about from the tracker, or from pex, or from incoming connections, or from our resume file. */ - uint16_t peersFrom[TR_PEER_FROM__MAX]; + uint16_t peersFrom[TR_PEER_FROM_N_TYPES]; /** How many known peers we found out about from the tracker, or from pex, or from incoming connections, or from our resume file. */ - uint16_t knownPeersFrom[TR_PEER_FROM__MAX]; + uint16_t knownPeersFrom[TR_PEER_FROM_N_TYPES]; /** Number of peers that are sending data to us. */ uint16_t peersSendingToUs; @@ -1586,6 +1594,7 @@ struct tr_stat to be considered stalled. @see `tr_sessionGetQueueStalledMinutes()` */ bool isStalled; }; +// NOLINTEND(modernize-avoid-c-arrays) /** Return a pointer to an `tr_stat` structure with updated information on the torrent. This is typically called by the GUI clients every diff --git a/libtransmission/utils.cc b/libtransmission/utils.cc index 363e6863e..fc5db25ca 100644 --- a/libtransmission/utils.cc +++ b/libtransmission/utils.cc @@ -68,9 +68,9 @@ namespace libtransmission::Values { // default values; can be overridden by client apps -Config::Units Config::Memory{ Config::Base::Kibi, "B"sv, "KiB"sv, "MiB"sv, "GiB"sv, "TiB"sv }; -Config::Units Config::Speed{ Config::Base::Kilo, "B/s"sv, "kB/s"sv, "MB/s"sv, "GB/s"sv, "TB/s"sv }; -Config::Units Config::Storage{ Config::Base::Kilo, "B"sv, "kB"sv, "MB"sv, "GB"sv, "TB"sv }; +Config::Units Config::memory{ Config::Base::Kibi, "B"sv, "KiB"sv, "MiB"sv, "GiB"sv, "TiB"sv }; +Config::Units Config::speed{ Config::Base::Kilo, "B/s"sv, "kB/s"sv, "MB/s"sv, "GB/s"sv, "TB/s"sv }; +Config::Units Config::storage{ Config::Base::Kilo, "B"sv, "kB"sv, "MB"sv, "GB"sv, "TB"sv }; } // namespace libtransmission::Values @@ -794,8 +794,8 @@ std::string_view tr_get_mime_type_for_filename(std::string_view filename) if (auto const pos = filename.rfind('.'); pos != std::string_view::npos) { auto const suffix_lc = tr_strlower(filename.substr(pos + 1)); - auto const it = std::lower_bound(std::begin(mime_type_suffixes), std::end(mime_type_suffixes), suffix_lc, Compare); - if (it != std::end(mime_type_suffixes) && suffix_lc == it->suffix) + auto const it = std::lower_bound(std::begin(MimeTypeSuffixes), std::end(MimeTypeSuffixes), suffix_lc, Compare); + if (it != std::end(MimeTypeSuffixes) && suffix_lc == it->suffix) { return it->mime_type; } diff --git a/libtransmission/values.h b/libtransmission/values.h index 1bd1fad4c..4f0b50331 100644 --- a/libtransmission/values.h +++ b/libtransmission/values.h @@ -47,7 +47,7 @@ struct Config template struct Units { - template + template // NOLINTNEXTLINE(google-explicit-constructor, cppcoreguidelines-pro-type-member-init) Units(Base base, Names... names) noexcept { set_base(base); @@ -96,12 +96,12 @@ struct Config std::array, 5> display_names_ = {}; std::array multipliers_; - Base base_; + Base base_ = {}; }; - static Units Memory; - static Units Speed; - static Units Storage; + static Units memory; + static Units speed; + static Units storage; }; template const& units_> @@ -263,8 +263,8 @@ private: } }; -using Memory = Value; -using Storage = Value; -using Speed = Value; +using Memory = Value; +using Storage = Value; +using Speed = Value; } // namespace libtransmission::Values diff --git a/libtransmission/variant.h b/libtransmission/variant.h index 51e600274..5517474ed 100644 --- a/libtransmission/variant.h +++ b/libtransmission/variant.h @@ -49,7 +49,7 @@ public: public: Map() = default; - Map(size_t const n_reserve) + explicit Map(size_t const n_reserve) { vec_.reserve(n_reserve); } @@ -193,13 +193,14 @@ public: }; constexpr tr_variant() noexcept = default; + ~tr_variant() = default; tr_variant(tr_variant const&) = delete; tr_variant(tr_variant&& that) noexcept = default; tr_variant& operator=(tr_variant const&) = delete; tr_variant& operator=(tr_variant&& that) noexcept = default; template - tr_variant(Val&& value) + tr_variant(Val&& value) // NOLINT(bugprone-forwarding-reference-overload, google-explicit-constructor) { *this = std::forward(value); } @@ -382,10 +383,14 @@ private: { public: StringHolder() = default; + ~StringHolder() = default; explicit StringHolder(std::string&& str) noexcept; - explicit StringHolder(StringHolder&& that) noexcept; + StringHolder(StringHolder&& that) noexcept; + StringHolder(StringHolder const&) = delete; void set_unmanaged(std::string_view sv); StringHolder& operator=(StringHolder&& that) noexcept; + StringHolder& operator=(StringHolder const&) = delete; + std::string_view sv_; private: @@ -565,7 +570,7 @@ public: private: friend tr_variant; - enum class Type + enum class Type : uint8_t { Benc, Json @@ -583,7 +588,7 @@ private: void (*container_end_func)(tr_variant const& var, void* user_data); }; - tr_variant_serde(Type type) + explicit tr_variant_serde(Type type) : type_{ type } { } diff --git a/libtransmission/verify.h b/libtransmission/verify.h index b2ae72a9e..3fed1a5cb 100644 --- a/libtransmission/verify.h +++ b/libtransmission/verify.h @@ -41,8 +41,14 @@ public: virtual void on_verify_done(bool aborted) = 0; }; + tr_verify_worker() = default; ~tr_verify_worker(); + tr_verify_worker(tr_verify_worker const&) = delete; + tr_verify_worker(tr_verify_worker&&) = delete; + tr_verify_worker& operator=(tr_verify_worker const&) = delete; + tr_verify_worker& operator=(tr_verify_worker&&) = delete; + void add(std::unique_ptr mediator, tr_priority_t priority); void remove(tr_sha1_digest_t const& info_hash); diff --git a/libtransmission/version.h.in b/libtransmission/version.h.in index 778deb2d1..4a10c19bf 100644 --- a/libtransmission/version.h.in +++ b/libtransmission/version.h.in @@ -1,5 +1,7 @@ #pragma once +// NOLINTBEGIN + #define PEERID_PREFIX "${TR_PEER_ID_PREFIX}" #define USERAGENT_PREFIX "${TR_USER_AGENT_PREFIX}" #define VCS_REVISION "${TR_VCS_REVISION}" @@ -15,3 +17,5 @@ #cmakedefine TR_BETA_RELEASE 1 #cmakedefine TR_NIGHTLY_RELEASE 1 #cmakedefine TR_STABLE_RELEASE 1 + +// NOLINTEND diff --git a/libtransmission/watchdir-base.h b/libtransmission/watchdir-base.h index a714ad2aa..9ce2a9925 100644 --- a/libtransmission/watchdir-base.h +++ b/libtransmission/watchdir-base.h @@ -37,6 +37,8 @@ public: retry_timer_->set_callback([this]() { onRetryTimer(); }); } + ~BaseWatchdir() override = default; + BaseWatchdir(BaseWatchdir&&) = delete; BaseWatchdir(BaseWatchdir const&) = delete; BaseWatchdir& operator=(BaseWatchdir&&) = delete; diff --git a/libtransmission/watchdir.h b/libtransmission/watchdir.h index d9718c6b2..371c86b9a 100644 --- a/libtransmission/watchdir.h +++ b/libtransmission/watchdir.h @@ -20,7 +20,7 @@ class TimerMaker; class Watchdir { public: - enum class Action + enum class Action : uint8_t { Done, Retry @@ -60,6 +60,8 @@ public: std::chrono::milliseconds rescan_interval = generic_rescan_interval_); private: + // TODO: Re-enable after setting readability-identifier-naming.PrivateMemberSuffix to _ + // NOLINTNEXTLINE(readability-identifier-naming) static inline auto generic_rescan_interval_ = std::chrono::milliseconds{ 1000 }; }; diff --git a/libtransmission/web-utils.cc b/libtransmission/web-utils.cc index 626f73d02..60be7d7a0 100644 --- a/libtransmission/web-utils.cc +++ b/libtransmission/web-utils.cc @@ -446,8 +446,7 @@ tr_url_query_view::iterator tr_url_query_view::begin() const { auto it = iterator{}; it.remain = query; - ++it; - return it; + return ++it; } std::string tr_urlPercentDecode(std::string_view in) diff --git a/libtransmission/web-utils.h b/libtransmission/web-utils.h index 1ca601c6b..b56a4e60d 100644 --- a/libtransmission/web-utils.h +++ b/libtransmission/web-utils.h @@ -62,8 +62,8 @@ struct tr_url_query_view struct iterator { - std::pair keyval = std::make_pair(std::string_view{ "" }, std::string_view{ "" }); - std::string_view remain = ""; + std::pair keyval; + std::string_view remain; iterator& operator++(); @@ -90,7 +90,7 @@ struct tr_url_query_view [[nodiscard]] iterator begin() const; - [[nodiscard]] constexpr iterator end() const + [[nodiscard]] static constexpr iterator end() { return iterator{}; } diff --git a/libtransmission/web.h b/libtransmission/web.h index 55d2a7a3c..7492ea943 100644 --- a/libtransmission/web.h +++ b/libtransmission/web.h @@ -38,7 +38,7 @@ public: class FetchOptions { public: - enum class IPProtocol + enum class IPProtocol : uint8_t { ANY, V4, @@ -108,6 +108,11 @@ public: // all of its tasks. ~tr_web(); + tr_web(tr_web const&) = delete; + tr_web(tr_web&&) = delete; + tr_web& operator=(tr_web const&) = delete; + tr_web& operator=(tr_web&&) = delete; + /** * Mediates between `tr_web` and its clients. * diff --git a/libtransmission/webseed.h b/libtransmission/webseed.h index 8fef98ed4..cc801b1e0 100644 --- a/libtransmission/webseed.h +++ b/libtransmission/webseed.h @@ -29,7 +29,7 @@ protected: public: [[nodiscard]] static std::unique_ptr create( tr_torrent& torrent, - std::string_view, + std::string_view url, tr_peer_callback_webseed callback, void* callback_data); diff --git a/macosx/Controller.mm b/macosx/Controller.mm index 6df0bb1da..07c2ef1aa 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -149,9 +149,9 @@ static void initUnits() NSString* g_str = [unitFormatter stringFromByteCount:ArbitraryPluralNumber]; unitFormatter.allowedUnits = NSByteCountFormatterUseTB; NSString* t_str = [unitFormatter stringFromByteCount:ArbitraryPluralNumber]; - Config::Memory = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String, + Config::memory = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String, m_str.UTF8String, g_str.UTF8String, t_str.UTF8String }; - Config::Storage = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String, + Config::storage = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String, m_str.UTF8String, g_str.UTF8String, t_str.UTF8String }; b_str = NSLocalizedString(@"B/s", "Transfer speed (bytes per second)"); @@ -159,7 +159,7 @@ static void initUnits() m_str = NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)"); g_str = NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)"); t_str = NSLocalizedString(@"TB/s", "Transfer speed (terabytes per second)"); - Config::Speed = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String, + Config::speed = { Config::Base::Kilo, b_str.UTF8String, k_str.UTF8String, m_str.UTF8String, g_str.UTF8String, t_str.UTF8String }; } diff --git a/macosx/MessageWindowController.mm b/macosx/MessageWindowController.mm index 68ed42db2..d2ed10cfa 100644 --- a/macosx/MessageWindowController.mm +++ b/macosx/MessageWindowController.mm @@ -268,11 +268,11 @@ static NSTimeInterval const kUpdateSeconds = 0.75; } } - if (self.fMessages.count > TR_LOG_MAX_QUEUE_LENGTH) + if (self.fMessages.count > TrLogMaxQueueLength) { NSUInteger const oldCount = self.fDisplayedMessages.count; - NSIndexSet* removeIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.fMessages.count - TR_LOG_MAX_QUEUE_LENGTH)]; + NSIndexSet* removeIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.fMessages.count - TrLogMaxQueueLength)]; NSArray* itemsToRemove = [self.fMessages objectsAtIndexes:removeIndexes]; [self.fMessages removeObjectsAtIndexes:removeIndexes]; diff --git a/qt/.clang-tidy b/qt/.clang-tidy index a9bee7092..b20b5e4a3 100644 --- a/qt/.clang-tidy +++ b/qt/.clang-tidy @@ -1,4 +1,6 @@ --- +HeaderFilterRegex: .*/qt/.* + # Many of these checks are disabled only because the code hasn't been # cleaned up yet. Pull requests welcomed. Checks: > diff --git a/qt/Application.cc b/qt/Application.cc index c5a9c43c3..99595c26a 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -71,21 +71,21 @@ void initUnits() { using Config = libtransmission::Values::Config; - Config::Speed = { Config::Base::Kilo, + Config::speed = { Config::Base::Kilo, QObject::tr("B/s").toStdString(), QObject::tr("kB/s").toStdString(), QObject::tr("MB/s").toStdString(), QObject::tr("GB/s").toStdString(), QObject::tr("TB/s").toStdString() }; - Config::Memory = { Config::Base::Kibi, + Config::memory = { Config::Base::Kibi, QObject::tr("B").toStdString(), QObject::tr("KiB").toStdString(), QObject::tr("MiB").toStdString(), QObject::tr("GiB").toStdString(), QObject::tr("TiB").toStdString() }; - Config::Storage = { Config::Base::Kilo, + Config::storage = { Config::Base::Kilo, QObject::tr("B").toStdString(), QObject::tr("kB").toStdString(), QObject::tr("MB").toStdString(), diff --git a/qt/Prefs.cc b/qt/Prefs.cc index 8c980a5bf..485733898 100644 --- a/qt/Prefs.cc +++ b/qt/Prefs.cc @@ -464,7 +464,7 @@ tr_variant Prefs::get_default_app_settings() settings.try_emplace(TR_KEY_main_window_width, 300); settings.try_emplace(TR_KEY_main_window_x, 50); settings.try_emplace(TR_KEY_main_window_y, 50); - settings.try_emplace(TR_KEY_remote_session_port, TR_DEFAULT_RPC_PORT); + settings.try_emplace(TR_KEY_remote_session_port, TrDefaultRpcPort); settings.try_emplace(TR_KEY_download_dir, download_dir); settings.try_emplace(TR_KEY_filter_mode, FilterMode); settings.try_emplace(TR_KEY_main_window_layout_order, WindowLayout); diff --git a/tests/libtransmission/.clang-tidy b/tests/libtransmission/.clang-tidy index a4af83657..95cbab806 100644 --- a/tests/libtransmission/.clang-tidy +++ b/tests/libtransmission/.clang-tidy @@ -1,4 +1,6 @@ --- +HeaderFilterRegex: .*/tests/libtransmission/.* + # Many of these checks are disabled only because the code hasn't been # cleaned up yet. Pull requests welcomed. Checks: > @@ -24,6 +26,7 @@ Checks: > -hicpp-signed-bitwise, misc-*, -misc-include-cleaner, + -misc-no-recursion, -misc-non-private-member-variables-in-classes, modernize-*, -modernize-use-trailing-return-type, @@ -39,7 +42,6 @@ CheckOptions: - { key: readability-identifier-naming.ClassCase, value: CamelCase } - { key: readability-identifier-naming.ClassMethodCase, value: camelBack } - { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase } - - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE } - { key: readability-identifier-naming.FunctionCase, value: camelBack } - { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase } - { key: readability-identifier-naming.MemberConstantCase, value: CamelCase } diff --git a/tests/libtransmission/announce-list-test.cc b/tests/libtransmission/announce-list-test.cc index f01669a13..1fc2200be 100644 --- a/tests/libtransmission/announce-list-test.cc +++ b/tests/libtransmission/announce-list-test.cc @@ -363,7 +363,7 @@ TEST_F(AnnounceListTest, save) // first, set up a scratch torrent auto constexpr* const OriginalFile = LIBTRANSMISSION_TEST_ASSETS_DIR "/Android-x86 8.1 r6 iso.torrent"; auto original_content = std::vector{}; - auto const sandbox = libtransmission::test::Sandbox::create_sandbox(::testing::TempDir(), "transmission-test-XXXXXX"); + auto const sandbox = libtransmission::test::Sandbox::createSandbox(::testing::TempDir(), "transmission-test-XXXXXX"); auto const test_file = tr_pathbuf{ sandbox, "transmission-announce-list-test.torrent"sv }; auto error = tr_error{}; EXPECT_TRUE(tr_file_read(OriginalFile, original_content, &error)); diff --git a/tests/libtransmission/makemeta-test.cc b/tests/libtransmission/makemeta-test.cc index 2f7e73bc6..7b1e67476 100644 --- a/tests/libtransmission/makemeta-test.cc +++ b/tests/libtransmission/makemeta-test.cc @@ -37,7 +37,7 @@ protected: static auto constexpr DefaultMaxFileCount = size_t{ 16 }; static auto constexpr DefaultMaxFileSize = size_t{ 1024 }; - auto makeRandomFiles( + static auto makeRandomFiles( std::string_view top, size_t n_files = std::max(size_t{ 1U }, static_cast(tr_rand_int(DefaultMaxFileCount))), size_t max_size = DefaultMaxFileSize) diff --git a/tests/libtransmission/move-test.cc b/tests/libtransmission/move-test.cc index 9ca690a70..619785cc5 100644 --- a/tests/libtransmission/move-test.cc +++ b/tests/libtransmission/move-test.cc @@ -69,9 +69,7 @@ TEST_P(IncompleteDirTest, incompleteDir) EXPECT_EQ(path, tr_torrentFindFile(tor, 1)); EXPECT_EQ(tor->piece_size(), tr_torrentStat(tor)->leftUntilDone); - // auto constexpr completeness_unset = tr_completeness { -1 }; - // auto completeness = completeness_unset; - int completeness = -1; + auto completeness = TR_LEECH; auto const zeroes_completeness_func = [](tr_torrent* /*torrent*/, tr_completeness c, bool /*was_running*/, void* vc) noexcept { @@ -125,7 +123,7 @@ TEST_P(IncompleteDirTest, incompleteDir) auto test = [&completeness]() { - return completeness != -1; + return completeness != TR_LEECH; }; EXPECT_TRUE(waitFor(test, MaxWaitMsec)); EXPECT_EQ(TR_SEED, completeness); diff --git a/tests/libtransmission/remove-test.cc b/tests/libtransmission/remove-test.cc index 68a09d1fb..7aee2f793 100644 --- a/tests/libtransmission/remove-test.cc +++ b/tests/libtransmission/remove-test.cc @@ -172,7 +172,7 @@ protected: return files; } - auto createFiles(tr_torrent_files const& files, char const* parent) + static auto createFiles(tr_torrent_files const& files, char const* parent) { auto paths = std::set{}; diff --git a/tests/libtransmission/rename-test.cc b/tests/libtransmission/rename-test.cc index a3bf73b25..1fe307b2a 100644 --- a/tests/libtransmission/rename-test.cc +++ b/tests/libtransmission/rename-test.cc @@ -46,13 +46,13 @@ protected: EXPECT_TRUE(waitFor(test, MaxWaitMsec)); } - void createSingleFileTorrentContents(std::string_view top) + static void createSingleFileTorrentContents(std::string_view top) { auto const path = tr_pathbuf{ top, "/hello-world.txt" }; createFileWithContents(path, "hello, world!\n"); } - void createMultifileTorrentContents(std::string_view top) + static void createMultifileTorrentContents(std::string_view top) { auto path = tr_pathbuf{ top, "/Felidae/Felinae/Acinonyx/Cheetah/Chester"sv }; createFileWithContents(path, "It ain't easy bein' cheesy.\n"); diff --git a/tests/libtransmission/test-fixtures.h b/tests/libtransmission/test-fixtures.h index 2544305e9..28901d22a 100644 --- a/tests/libtransmission/test-fixtures.h +++ b/tests/libtransmission/test-fixtures.h @@ -37,15 +37,12 @@ inline std::ostream& operator<<(std::ostream& os, tr_error const& err) return os; } -namespace libtransmission -{ - -namespace test +namespace libtransmission::test { using file_func_t = std::function; -static void depthFirstWalk(char const* path, file_func_t func) +static void depthFirstWalk(char const* path, file_func_t const& func) { if (auto const info = tr_sys_path_get_info(path); info && info->isFolder()) { @@ -125,8 +122,8 @@ class Sandbox { public: Sandbox() - : parent_dir_{ get_default_parent_dir() } - , sandbox_dir_{ create_sandbox(parent_dir_, "transmission-test-XXXXXX") } + : parent_dir_{ getDefaultParentDir() } + , sandbox_dir_{ createSandbox(parent_dir_, "transmission-test-XXXXXX") } { } @@ -135,12 +132,17 @@ public: rimraf(sandbox_dir_); } + Sandbox(Sandbox const&) = delete; + Sandbox(Sandbox&&) = delete; + Sandbox& operator=(Sandbox const&) = delete; + Sandbox& operator=(Sandbox&&) = delete; + [[nodiscard]] constexpr std::string const& path() const { return sandbox_dir_; } - static std::string create_sandbox(std::string const& parent_dir, std::string const& tmpl) + static std::string createSandbox(std::string const& parent_dir, std::string const& tmpl) { auto path = fmt::format(FMT_STRING("{:s}/{:s}"sv), tr_sys_path_resolve(parent_dir), tmpl); tr_sys_dir_create_temp(std::data(path)); @@ -149,7 +151,7 @@ public: } protected: - static std::string get_default_parent_dir() + static std::string getDefaultParentDir() { if (auto* const path = getenv("TMPDIR"); path != nullptr) { @@ -166,7 +168,7 @@ protected: { if (verbose) { - std::cerr << "cleanup: removing '" << filename << "'" << std::endl; + std::cerr << "cleanup: removing '" << filename << "'\n"; } tr_sys_path_remove(filename); @@ -188,7 +190,7 @@ protected: return sandbox_.path(); } - [[nodiscard]] auto currentTestName() const + [[nodiscard]] static auto currentTestName() { auto const* i = ::testing::UnitTest::GetInstance()->current_test_info(); auto child = std::string(i->test_suite_name()); @@ -197,7 +199,7 @@ protected: return child; } - void buildParentDir(std::string_view path) const + static void buildParentDir(std::string_view path) { auto const tmperr = errno; @@ -237,7 +239,7 @@ protected: } } - void createTmpfileWithContents(char* tmpl, void const* payload, size_t n) const + static void createTmpfileWithContents(char* tmpl, void const* payload, size_t n) { auto const tmperr = errno; @@ -260,7 +262,7 @@ protected: errno = tmperr; } - void createFileWithContents(std::string_view path, void const* payload, size_t n) const + static void createFileWithContents(std::string_view path, void const* payload, size_t n) { auto const tmperr = errno; @@ -278,19 +280,19 @@ protected: errno = tmperr; } - void createFileWithContents(std::string_view path, std::string_view payload) const + static void createFileWithContents(std::string_view path, std::string_view payload) { createFileWithContents(path, std::data(payload), std::size(payload)); } - void createFileWithContents(std::string_view path, void const* payload) const + static void createFileWithContents(std::string_view path, void const* payload) { createFileWithContents(path, payload, strlen(static_cast(payload))); } - bool verbose = false; + bool verbose_ = false; - void sync() const + static void sync() { #ifndef _WIN32 ::sync(); @@ -330,19 +332,19 @@ private: // fill in any missing settings settings_map->try_emplace(TR_KEY_port_forwarding_enabled, false); settings_map->try_emplace(TR_KEY_dht_enabled, false); - settings_map->try_emplace(TR_KEY_message_level, verbose ? TR_LOG_DEBUG : TR_LOG_ERROR); + settings_map->try_emplace(TR_KEY_message_level, verbose_ ? TR_LOG_DEBUG : TR_LOG_ERROR); - return tr_sessionInit(sandboxDir().data(), !verbose, settings); + return tr_sessionInit(sandboxDir().data(), !verbose_, settings); } - void sessionClose(tr_session* session) + static void sessionClose(tr_session* session) { tr_sessionClose(session); tr_logFreeQueue(tr_logGetQueue()); } protected: - enum class ZeroTorrentState + enum class ZeroTorrentState : uint8_t { NoFiles, Partial, @@ -485,7 +487,7 @@ protected: return settings_.get(); } - virtual void SetUp() override + void SetUp() override { SandboxedTest::SetUp(); @@ -494,7 +496,7 @@ protected: session_ = sessionInit(*settings()); } - virtual void TearDown() override + void TearDown() override { sessionClose(session_); session_ = nullptr; @@ -509,6 +511,4 @@ private: std::vector verified_; }; -} // namespace test - -} // namespace libtransmission +} // namespace libtransmission::test diff --git a/tests/libtransmission/torrent-metainfo-test.cc b/tests/libtransmission/torrent-metainfo-test.cc index cc3547003..a6a53fb17 100644 --- a/tests/libtransmission/torrent-metainfo-test.cc +++ b/tests/libtransmission/torrent-metainfo-test.cc @@ -134,7 +134,7 @@ TEST_F(TorrentMetainfoTest, AndroidTorrent) TEST_F(TorrentMetainfoTest, ctorSaveContents) { - auto const sandbox = libtransmission::test::Sandbox::create_sandbox(::testing::TempDir(), "transmission-test-XXXXXX"); + auto const sandbox = libtransmission::test::Sandbox::createSandbox(::testing::TempDir(), "transmission-test-XXXXXX"); auto const src_filename = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, "/Android-x86 8.1 r6 iso.torrent"sv }; auto const tgt_filename = tr_pathbuf{ sandbox, "save-contents-test.torrent" }; diff --git a/tests/libtransmission/utils-test.cc b/tests/libtransmission/utils-test.cc index 6081a0e31..a8c4e60ac 100644 --- a/tests/libtransmission/utils-test.cc +++ b/tests/libtransmission/utils-test.cc @@ -262,7 +262,7 @@ TEST_F(UtilsTest, saveFile) auto filename = tr_pathbuf{}; // save a file to GoogleTest's temp dir - auto const sandbox = libtransmission::test::Sandbox::create_sandbox(::testing::TempDir(), "transmission-test-XXXXXX"); + auto const sandbox = libtransmission::test::Sandbox::createSandbox(::testing::TempDir(), "transmission-test-XXXXXX"); filename.assign(sandbox, "filename.txt"sv); auto contents = "these are the contents"sv; auto error = tr_error{}; diff --git a/tests/libtransmission/variant-test.cc b/tests/libtransmission/variant-test.cc index ea478e73a..28a7c98d9 100644 --- a/tests/libtransmission/variant-test.cc +++ b/tests/libtransmission/variant-test.cc @@ -4,9 +4,7 @@ // License text can be found in the licenses/ folder. #include -#include #include -#include // lrint() #include // size_t #include // int64_t #include @@ -22,6 +20,7 @@ #include #include "gtest/gtest.h" +#include "test-fixtures.h" using namespace std::literals; diff --git a/tests/libtransmission/watchdir-test.cc b/tests/libtransmission/watchdir-test.cc index 4c80c2569..78c6f79c6 100644 --- a/tests/libtransmission/watchdir-test.cc +++ b/tests/libtransmission/watchdir-test.cc @@ -96,7 +96,7 @@ protected: return watchdir; } - void createFile(std::string_view dirname, std::string_view basename, std::string_view contents = ""sv) + static void createFile(std::string_view dirname, std::string_view basename, std::string_view contents = ""sv) { createFileWithContents(tr_pathbuf{ dirname, '/', basename }, contents); } diff --git a/utils/remote.cc b/utils/remote.cc index 5751acad2..9c19cf747 100644 --- a/utils/remote.cc +++ b/utils/remote.cc @@ -48,7 +48,7 @@ using namespace libtransmission::Values; namespace { -auto constexpr DefaultPort = uint16_t{ TR_DEFAULT_RPC_PORT }; +auto constexpr DefaultPort = uint16_t{ TrDefaultRpcPort }; char constexpr DefaultHost[] = "localhost"; char constexpr DefaultUrl[] = TR_DEFAULT_RPC_URL_STR "rpc/";