0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-05 05:18:54 +01:00
construct/modules/m_room_server_acl.cc

76 lines
1.8 KiB
C++

// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
ircd::mapi::header
IRCD_MODULE
{
"Matrix Room Server Access Control List"
};
//
// vm hookfn's
//
namespace ircd::m
{
static void on_changed_room_server_acl(const m::event &, m::vm::eval &);
static void on_check_room_server_acl(const m::event &, m::vm::eval &);
extern m::hookfn<m::vm::eval &> changed_room_server_acl;
extern m::hookfn<m::vm::eval &> check_room_server_acl;
}
decltype(ircd::m::check_room_server_acl)
ircd::m::check_room_server_acl
{
on_check_room_server_acl,
{
{ "_site", "vm.access" },
}
};
void
ircd::m::on_check_room_server_acl(const event &event,
vm::eval &)
{
if(!m::room::server_acl::enable_write)
return;
if(!m::room::server_acl::check(at<"room_id"_>(event), at<"origin"_>(event)))
throw m::ACCESS_DENIED
{
"Server '%s' denied by room %s access control list.",
at<"origin"_>(event),
at<"room_id"_>(event),
};
}
decltype(ircd::m::changed_room_server_acl)
ircd::m::changed_room_server_acl
{
on_changed_room_server_acl,
{
{ "_site", "vm.notify" },
{ "type", "m.room.server_acl" },
}
};
void
ircd::m::on_changed_room_server_acl(const event &event,
vm::eval &)
{
log::info
{
m::log, "%s changed server access control list in %s [%s]",
json::get<"sender"_>(event),
json::get<"room_id"_>(event),
string_view{event.event_id},
};
}