0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-05 01:58:35 +02:00

ircd:Ⓜ️🪝 Add a set to track all hooks for a site.

This commit is contained in:
Jason Volk 2018-04-26 15:17:28 -07:00
parent 63e662606a
commit 523bf19f30
2 changed files with 17 additions and 0 deletions

View file

@ -60,6 +60,7 @@ struct ircd::m::hook::site
std::multimap<string_view, hook *> sender;
std::multimap<string_view, hook *> state_key;
std::multimap<string_view, hook *> type;
std::set<hook *> hooks;
friend class hook;
bool add(hook &);

View file

@ -2540,6 +2540,16 @@ catch(const std::exception &e)
bool
ircd::m::hook::site::add(hook &hook)
{
if(!hooks.emplace(&hook).second)
{
log::warning
{
"Hook %p already registered to site %s", &hook, name()
};
return false;
}
if(json::get<"origin"_>(hook.matching))
origin.emplace(at<"origin"_>(hook.matching), &hook);
@ -2589,6 +2599,12 @@ ircd::m::hook::site::del(hook &hook)
if(json::get<"type"_>(hook.matching))
unmap(type, at<"type"_>(hook.matching));
const auto erased
{
hooks.erase(&hook)
};
assert(erased);
--count;
return true;
}