# HG changeset patch # User David Demelier # Date 1536783034 -7200 # Node ID 80e2d5284b4ade389581a66329ffe1c334721fa8 # Parent 3f5e8ae58a8437db5648611ffd5478a195cbdf1a Plugin links: make maximum count, closes #904 @20m diff -r 3f5e8ae58a84 -r 80e2d5284b4a plugins/links/links.cpp --- a/plugins/links/links.cpp Mon Aug 13 13:29:00 2018 +0200 +++ b/plugins/links/links.cpp Wed Sep 12 22:10:34 2018 +0200 @@ -125,6 +125,8 @@ private: using socket = variant>; + unsigned level_{0U}; + shared_ptr server_; string channel_; string origin_; @@ -154,10 +156,10 @@ void timer(); void start(); - requester(io_context&, shared_ptr, string, string, url); + requester(unsigned, io_context&, shared_ptr, string, string, url); public: - static void run(io_context&, shared_ptr, string, string, string); + static void run(unsigned, io_context&, shared_ptr, string, string, string); }; void requester::notify(const string& title) @@ -199,7 +201,8 @@ if (const auto it = res_.find(field::location); it != res_.end()) { const string location(it->value().data(), it->value().size()); - run(timer_.get_io_service(), server_, origin_, channel_, location); + if (level_ < 32U) + run(++level_, timer_.get_io_service(), server_, origin_, channel_, location); } else parse(); } @@ -362,12 +365,14 @@ resolve(); } -requester::requester(io_context& io, +requester::requester(unsigned level, + io_context& io, shared_ptr server, string channel, string origin, url url) - : server_(move(server)) + : level_(level) + , server_(move(server)) , channel_(move(channel)) , origin_(move(origin)) , url_(move(url)) @@ -376,14 +381,19 @@ { } -void requester::run(io_context& io, shared_ptr server, string origin, string channel, string link) +void requester::run(unsigned level, + io_context& io, + shared_ptr server, + string origin, + string channel, + string link) { auto url = url::parse(link); if (url.protocol.empty() || url.host.empty()) return; - shared_ptr(new requester(io, server, channel, origin, move(url)))->start(); + shared_ptr(new requester(level, io, server, channel, origin, move(url)))->start(); } // }}} @@ -455,7 +465,7 @@ void links_plugin::handle_message(irccd& irccd, const message_event& ev) { - requester::run(irccd.get_service(), ev.server, ev.origin, ev.channel, ev.message); + requester::run(0U, irccd.get_service(), ev.server, ev.origin, ev.channel, ev.message); } auto links_plugin::abi() -> version