From 477fc256879aea7c2ceef921e5b0e3d631c69041 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 15 Jul 2019 16:47:08 -0700 Subject: [PATCH] modules/m_room_power_levels: Remove stale hooks. modules/m_room_create: Remove stale hooks. --- modules/m_room_create.cc | 73 ---------------------------- modules/m_room_power_levels.cc | 88 ---------------------------------- 2 files changed, 161 deletions(-) diff --git a/modules/m_room_create.cc b/modules/m_room_create.cc index 11b8073e5..bfcc41493 100644 --- a/modules/m_room_create.cc +++ b/modules/m_room_create.cc @@ -16,79 +16,6 @@ IRCD_MODULE "Matrix m.room.create" }; -static void -_can_create_room(const m::event &event, - m::vm::eval &eval) -{ - const m::event::id &event_id - { - event.event_id - }; - - const m::room::id &room_id - { - at<"room_id"_>(event) - }; - - const m::user::id &sender - { - at<"sender"_>(event) - }; - - if(room_id.host() != sender.host()) - throw m::ACCESS_DENIED - { - "Room on '%s' cannot be created by sender on '%s'", - room_id.host(), - sender.host() - }; - - if(room_id.host() != sender.host()) - throw m::ACCESS_DENIED - { - "Room on '%s' cannot be created by event from '%s'", - room_id.host(), - sender.host() - }; - - if(room_id.host() != at<"origin"_>(event)) - throw m::ACCESS_DENIED - { - "Room on '%s' cannot be created by event originating from '%s'", - room_id.host(), - at<"origin"_>(event) - }; - - const json::object &content - { - at<"content"_>(event) - }; - - // note: this is a purposely weak check of the content.creator field. - // This server accepts a missing content.creator field entirely because - // it considers the sender of the create event as the room creator. - // Nevertheless if the content.creator field was specified it must match - // the sender or we reject. - if(content.has("creator")) - if(unquote(content.at("creator")) != sender) - throw m::ACCESS_DENIED - { - "Room %s creator must be the sender %s", - string_view{room_id}, - string_view{sender} - }; -} - -const m::hookfn -_can_create_room_hookfn -{ - _can_create_room, - { - { "_site", "vm.eval" }, - { "type", "m.room.create" }, - } -}; - static void _created_room(const m::event &event, m::vm::eval &) diff --git a/modules/m_room_power_levels.cc b/modules/m_room_power_levels.cc index d3b14e0b8..a95398ccf 100644 --- a/modules/m_room_power_levels.cc +++ b/modules/m_room_power_levels.cc @@ -16,94 +16,6 @@ IRCD_MODULE "Matrix m.room.power_levels" }; -static void -_has_power(const m::event &event, - m::vm::eval &) -{ - const auto &room_id - { - json::get<"room_id"_>(event) - }; - - const auto &event_id - { - event.event_id - }; - - if(!room_id || !event_id) // Not evaluated here - return; - - const auto &type - { - at<"type"_>(event) - }; - - if(type == "m.room.create") // Checked by _can_create_room - return; - - const m::room room - { - room_id //TODO: at event - }; - - const m::user::id &sender - { - at<"sender"_>(event) - }; - - //TODO: ircd.presence - if(my(event) && my(room) && !my(sender)) - return; - - const m::room::power power - { - room - }; - - const auto &state_key - { - json::get<"state_key"_>(event) - }; - - if(!power(sender, "events", type, state_key)) - log::warning //TODO: throw - { - m::log, "Power violation %s in %s for %s %s,%s", - string_view{sender}, - string_view{room_id}, - string_view{event_id}, - type, - state_key - }; -} - -const m::hookfn -_has_power_hookfn -{ - _has_power, - { - { "_site", "vm.eval" }, - } -}; - -static void -_can_change_levels(const m::event &event, - m::vm::eval &) -{ - //TODO: abstract event check against existing power levels should - //TODO: cover this? -} - -const m::hookfn -_can_change_levels_hookfn -{ - _can_change_levels, - { - { "_site", "vm.eval" }, - { "type", "m.room.power_levels" }, - } -}; - static void _changed_levels(const m::event &event, m::vm::eval &)