From cf78a2e43ea41c04e22ca4821947afb84ebf07c1 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 5 Nov 2020 14:14:33 +0100 Subject: [PATCH] Don't parse more items than Config::max_guids. --- src/config.hpp | 1 + src/document.cpp | 8 ++++++++ src/mastoapi.cpp | 2 +- src/mastoapi.hpp | 1 - 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/config.hpp b/src/config.hpp index 29a7d57..9cc8e19 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -72,6 +72,7 @@ public: const string profile; ProfileData profiledata; + constexpr static size_t max_guids{100}; void write(); [[nodiscard]] fs::path get_config_dir() const; diff --git a/src/document.cpp b/src/document.cpp index f9f961d..98fe69b 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -165,8 +165,16 @@ void Document::parse() void Document::parse_rss(const pt::ptree &tree) { + size_t counter{0}; for (const auto &child : tree.get_child("rss.channel")) { + if (counter == Config::max_guids) + { + BOOST_LOG_TRIVIAL(debug) + << "Maximum number of items reached. Stopped parsing."; + break; + } + ++counter; if (child.first == "item") { const auto &rssitem = child.second; diff --git a/src/mastoapi.cpp b/src/mastoapi.cpp index 1f71280..62ea6c7 100644 --- a/src/mastoapi.cpp +++ b/src/mastoapi.cpp @@ -128,7 +128,7 @@ void MastoAPI::post_item(const Item &item) BOOST_LOG_TRIVIAL(debug) << "Posted status with GUID: " << item.guid; _profile.guids.push_back(item.guid); - if (_profile.guids.size() > _max_guids) + if (_profile.guids.size() > Config::max_guids) { _profile.guids.pop_front(); } diff --git a/src/mastoapi.hpp b/src/mastoapi.hpp index a6b662e..48b78c3 100644 --- a/src/mastoapi.hpp +++ b/src/mastoapi.hpp @@ -38,7 +38,6 @@ public: private: ProfileData &_profile; mastodonpp::Instance _instance; - constexpr static size_t _max_guids{100}; string replacements_apply(const string &text); };