# HG changeset patch # User David Demelier # Date 1530978154 -7200 # Node ID e0cd4f544b2460c7c069e5d25557d0b510196439 # Parent fc66cc9706a7412ec521da7f0d259c9199296469 Plugin links: create new request in case of redirection While here, fix conversion from boost::string_view to std::string that was using .data() which returns a non-null terminated string. diff -r fc66cc9706a7 -r e0cd4f544b24 plugins/links/links.cpp --- a/plugins/links/links.cpp Sat Jul 07 15:40:46 2018 +0200 +++ b/plugins/links/links.cpp Sat Jul 07 17:42:34 2018 +0200 @@ -22,8 +22,6 @@ #include #include -#include - #include #include @@ -159,7 +157,7 @@ requester(io_context&, shared_ptr, string, string, url); public: - static void run(io_context&, const message_event&); + static void run(io_context&, shared_ptr, string, string, string); }; void requester::notify(const string& title) @@ -198,12 +196,10 @@ return; // Request again in case of relocation. - if (res_.result() == status::moved_permanently) { - const string host(res_[field::location].data()); + if (const auto it = res_.find(field::location); it != res_.end()) { + const string location(it->value().data(), it->value().size()); - // Clean '\r\n' - url_ = url::parse(boost::algorithm::trim_all_copy(host)); - start(); + run(timer_.get_io_service(), server_, origin_, channel_, location); } else parse(); } @@ -380,14 +376,14 @@ { } -void requester::run(io_context& io, const message_event& ev) +void requester::run(io_context& io, shared_ptr server, string origin, string channel, string link) { - auto url = url::parse(ev.message); + auto url = url::parse(link); if (url.protocol.empty() || url.host.empty()) return; - shared_ptr(new requester(io, ev.server, ev.channel, ev.origin, move(url)))->start(); + shared_ptr(new requester(io, server, channel, origin, move(url)))->start(); } // }}} @@ -417,7 +413,7 @@ void links_plugin::handle_message(irccd& irccd, const message_event& ev) { - requester::run(irccd.get_service(), ev); + requester::run(irccd.get_service(), ev.server, ev.origin, ev.channel, ev.message); } // }}}