0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-19 19:33:45 +02:00

modules: Start an m.room.name module w/ length check conforms hook.

This commit is contained in:
Jason Volk 2019-08-25 14:26:01 -07:00
parent bbaec98d68
commit 4bf39ee1f2
3 changed files with 69 additions and 0 deletions

View file

@ -219,6 +219,7 @@ ircd::m::module_names
"m_room_history_visibility",
"m_room_join_rules",
"m_room_member",
"m_room_name",
"m_room_third_party_invite",
"m_room_message",
"m_room_power_levels",

View file

@ -144,6 +144,7 @@ m_room_server_acl_la_SOURCES = m_room_server_acl.cc
m_room_third_party_invite_la_SOURCES = m_room_third_party_invite.cc
m_room_redaction_la_SOURCES = m_room_redaction.cc
m_room_bootstrap_la_SOURCES = m_room_bootstrap.cc
m_room_name_la_SOURCES = m_room_name.cc
m_init_bootstrap_la_SOURCES = m_init_bootstrap.cc
m_init_backfill_la_SOURCES = m_init_backfill.cc
m_listen_la_SOURCES = m_listen.cc
@ -196,6 +197,7 @@ m_module_LTLIBRARIES = \
m_room_redaction.la \
m_room_server_acl.la \
m_room_bootstrap.la \
m_room_name.la \
m_init_bootstrap.la \
m_init_backfill.la \
m_listen.la \

66
modules/m_room_name.cc Normal file
View file

@ -0,0 +1,66 @@
// 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.
namespace ircd::m
{
static void room_name_length_conform(const event &, vm::eval &);
extern hookfn<vm::eval &> room_name_length_conform_hookfn;
extern const size_t room_name_length_max;
}
ircd::mapi::header
IRCD_MODULE
{
"Matrix m.room.name"
};
/// Spec sez in c2s 13.2.1.3 m.room.name MUST NOT exceed 255 bytes.
decltype(ircd::m::room_name_length_max)
ircd::m::room_name_length_max
{
255
};
decltype(ircd::m::room_name_length_conform_hookfn)
ircd::m::room_name_length_conform_hookfn
{
room_name_length_conform,
{
{ "_site", "vm.conform" },
{ "type", "m.room.name" },
{ "state_key", "" },
}
};
void
ircd::m::room_name_length_conform(const m::event &event,
m::vm::eval &)
{
assert(at<"type"_>(event) == "m.room.name");
const auto &content
{
json::get<"content"_>(event)
};
const json::string &name
{
content.get("name")
};
if(size(name) > room_name_length_max)
throw vm::error
{
vm::fault::INVALID,
"m.room.name content.name is %zu characters longer than the %zu allowed.",
size(name) - room_name_length_max,
room_name_length_max,
};
}