0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-28 23:08:20 +02:00

ircd:Ⓜ️:event::auth::chain: No closing over full event; overload void closure.

This commit is contained in:
Jason Volk 2019-02-16 15:03:49 -08:00
parent ed87eb31e0
commit f275cf8c83
5 changed files with 42 additions and 22 deletions

View file

@ -51,7 +51,8 @@ struct ircd::m::event::auth::refs
struct ircd::m::event::auth::chain struct ircd::m::event::auth::chain
{ {
using closure_bool = std::function<bool (const event::idx &, const event &)>; using closure_bool = event::closure_idx_bool;
using closure = event::closure_idx;
event::idx idx; event::idx idx;
@ -59,6 +60,8 @@ struct ircd::m::event::auth::chain
public: public:
bool for_each(const closure_bool &) const; bool for_each(const closure_bool &) const;
bool for_each(const closure &) const;
bool has(const string_view &type) const noexcept; bool has(const string_view &type) const noexcept;
size_t depth() const noexcept; size_t depth() const noexcept;

View file

@ -1433,10 +1433,9 @@ ircd::m::event::auth::chain::depth()
const noexcept const noexcept
{ {
size_t ret(0); size_t ret(0);
for_each([&ret](const auto &, const auto &) for_each([&ret](const auto &)
{ {
++ret; ++ret;
return true;
}); });
return ret; return ret;
@ -1447,16 +1446,33 @@ ircd::m::event::auth::chain::has(const string_view &type)
const noexcept const noexcept
{ {
bool ret(false); bool ret(false);
for_each([&type, &ret] for_each(closure_bool{[&type, &ret]
(const auto &, const auto &event) (const auto &idx)
{ {
ret = type == json::get<"type"_>(event); m::get(std::nothrow, idx, "type", [&type, &ret]
(const auto &value)
{
ret = value == type;
});
return !ret; return !ret;
}); }});
return ret; return ret;
} }
bool
ircd::m::event::auth::chain::for_each(const closure &closure)
const
{
return for_each(closure_bool{[&closure]
(const auto &idx)
{
closure(idx);
return true;
}});
}
bool bool
ircd::m::event::auth::chain::for_each(const closure_bool &closure) ircd::m::event::auth::chain::for_each(const closure_bool &closure)
const const

View file

@ -5939,13 +5939,18 @@ console_cmd__event__auth(opt &out, const string_view &line)
m::index(event_id) m::index(event_id)
}; };
ac.for_each([&out](const auto &idx, const auto &event) ac.for_each([&out](const auto &idx)
{ {
out << idx const m::event::fetch event
<< " " << pretty_oneline(event) {
<< std::endl; idx, std::nothrow
};
return true; out << idx;
if(event.valid)
out << " " << pretty_oneline(event);
out << std::endl;
}); });
return true; return true;

View file

@ -96,11 +96,12 @@ get__event_auth(client &client,
m::index(event_id) m::index(event_id)
}; };
chain.for_each([&auth_chain] m::event::fetch event;
(const m::event::idx &event_idx, const m::event &event) chain.for_each([&auth_chain, &event]
(const m::event::idx &event_idx)
{ {
auth_chain.append(event); if(seek(event, event_idx, std::nothrow))
return true; auth_chain.append(event);
}); });
return {}; return {};

View file

@ -598,13 +598,8 @@ ircd::m::event::auth::chain::for_each(const auth::chain &c,
while(!aq.empty()); while(!aq.empty());
for(const auto &idx : ae) for(const auto &idx : ae)
{ if(!closure(idx))
if(!seek(e, idx, std::nothrow))
continue;
if(!closure(idx, e))
return false; return false;
}
return true; return true;
} }