2018-03-29 04:26:16 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 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.
|
|
|
|
|
2019-07-18 22:45:15 +02:00
|
|
|
namespace ircd::m
|
|
|
|
{
|
|
|
|
static void auth_room_create(const event &, event::auth::hookdata &);
|
|
|
|
extern hookfn<event::auth::hookdata &> auth_room_create_hookfn;
|
2019-07-21 01:32:22 +02:00
|
|
|
|
|
|
|
static void created_room(const event &, vm::eval &);
|
|
|
|
extern hookfn<vm::eval &> created_room_hookfn;
|
2019-07-18 22:45:15 +02:00
|
|
|
}
|
2018-03-29 04:26:16 +02:00
|
|
|
|
2019-07-18 22:45:15 +02:00
|
|
|
ircd::mapi::header
|
2018-03-29 04:26:16 +02:00
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Matrix m.room.create"
|
|
|
|
};
|
|
|
|
|
2019-07-21 01:32:22 +02:00
|
|
|
//
|
|
|
|
// an effect of room created
|
|
|
|
//
|
|
|
|
|
2019-07-18 22:45:15 +02:00
|
|
|
decltype(ircd::m::created_room_hookfn)
|
|
|
|
ircd::m::created_room_hookfn
|
|
|
|
{
|
|
|
|
created_room,
|
|
|
|
{
|
|
|
|
{ "_site", "vm.effect" },
|
|
|
|
{ "type", "m.room.create" },
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::created_room(const m::event &event,
|
|
|
|
m::vm::eval &)
|
2019-08-06 01:26:52 +02:00
|
|
|
try
|
2018-03-29 04:26:16 +02:00
|
|
|
{
|
2019-08-06 01:32:39 +02:00
|
|
|
const m::user::id &sender
|
2018-05-13 05:19:17 +02:00
|
|
|
{
|
2019-08-06 01:32:39 +02:00
|
|
|
at<"sender"_>(event)
|
2018-05-13 05:19:17 +02:00
|
|
|
};
|
|
|
|
|
2019-08-06 01:32:39 +02:00
|
|
|
const auto &level
|
2018-05-13 05:19:17 +02:00
|
|
|
{
|
2019-08-06 01:32:39 +02:00
|
|
|
my(sender) && sender != m::me?
|
|
|
|
log::INFO:
|
|
|
|
log::DEBUG
|
2018-05-13 05:19:17 +02:00
|
|
|
};
|
2018-03-29 04:26:16 +02:00
|
|
|
|
2019-08-06 01:32:39 +02:00
|
|
|
log::logf
|
2018-10-25 23:48:52 +02:00
|
|
|
{
|
2019-08-06 01:32:39 +02:00
|
|
|
m::log, level, "Created room %s with %s by %s",
|
|
|
|
json::get<"room_id"_>(event),
|
|
|
|
json::get<"sender"_>(event),
|
2019-07-10 09:26:25 +02:00
|
|
|
string_view{event.event_id},
|
2018-10-25 23:48:52 +02:00
|
|
|
};
|
2018-03-29 04:26:16 +02:00
|
|
|
}
|
2019-08-06 01:26:52 +02:00
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
log::error
|
|
|
|
{
|
|
|
|
m::log, "Effect of creating room %s with %s by %s :%s",
|
|
|
|
json::get<"room_id"_>(event),
|
|
|
|
string_view{event.event_id},
|
|
|
|
json::get<"sender"_>(event),
|
|
|
|
e.what()
|
|
|
|
};
|
|
|
|
}
|
2018-03-29 04:26:16 +02:00
|
|
|
|
2019-07-21 01:32:22 +02:00
|
|
|
//
|
|
|
|
// auth handler
|
|
|
|
//
|
|
|
|
|
2019-07-18 22:45:15 +02:00
|
|
|
decltype(ircd::m::auth_room_create_hookfn)
|
|
|
|
ircd::m::auth_room_create_hookfn
|
2018-03-29 04:26:16 +02:00
|
|
|
{
|
2019-07-18 22:45:15 +02:00
|
|
|
auth_room_create,
|
2018-03-29 04:26:16 +02:00
|
|
|
{
|
2019-07-18 22:45:15 +02:00
|
|
|
{ "_site", "event.auth" },
|
|
|
|
{ "type", "m.room.create" },
|
2018-03-29 04:26:16 +02:00
|
|
|
}
|
|
|
|
};
|
2019-07-18 22:45:15 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::auth_room_create(const event &event,
|
|
|
|
event::auth::hookdata &data)
|
|
|
|
{
|
|
|
|
using FAIL = m::event::auth::FAIL;
|
|
|
|
using conforms = m::event::conforms;
|
2019-07-21 01:32:22 +02:00
|
|
|
|
|
|
|
// 1. If type is m.room.create:
|
2019-07-18 22:45:15 +02:00
|
|
|
assert(json::get<"type"_>(event) == "m.room.create");
|
|
|
|
|
|
|
|
// a. If it has any previous events, reject.
|
|
|
|
if(count(data.prev) || !empty(data.auth_events))
|
|
|
|
throw FAIL
|
|
|
|
{
|
|
|
|
"m.room.create has previous events."
|
|
|
|
};
|
|
|
|
|
|
|
|
// b. If the domain of the room_id does not match the domain of the
|
|
|
|
// sender, reject.
|
|
|
|
if(conforms(event).has(conforms::MISMATCH_CREATE_SENDER))
|
|
|
|
throw FAIL
|
|
|
|
{
|
|
|
|
"m.room.create room_id domain does not match sender domain."
|
|
|
|
};
|
|
|
|
|
|
|
|
// c. If content.room_version is present and is not a recognised
|
|
|
|
// version, reject.
|
|
|
|
if(json::get<"content"_>(event).has("room_version"))
|
|
|
|
{
|
|
|
|
const json::string &claim_version
|
|
|
|
{
|
|
|
|
json::get<"content"_>(event).get("room_version", "1")
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &id_version
|
|
|
|
{
|
|
|
|
event.event_id.version()
|
|
|
|
};
|
|
|
|
|
|
|
|
if(claim_version == "3")
|
|
|
|
{
|
|
|
|
if(id_version != "3")
|
|
|
|
throw FAIL
|
|
|
|
{
|
|
|
|
"m.room.create room_version not 3"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else if(claim_version == "4")
|
|
|
|
{
|
|
|
|
if(id_version != "4")
|
|
|
|
throw FAIL
|
|
|
|
{
|
|
|
|
"m.room.create room_version not 4"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else if(claim_version == "1" || claim_version == "2")
|
|
|
|
{
|
|
|
|
//if(id_version != "1")
|
|
|
|
// return "m.room.create room_version not 1";
|
|
|
|
}
|
|
|
|
else if(claim_version != "1" && claim_version != "2")
|
|
|
|
{
|
|
|
|
if(id_version != "4")
|
|
|
|
throw FAIL
|
|
|
|
{
|
|
|
|
"m.room.create room_version not 4"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// d. If content has no creator field, reject.
|
|
|
|
if(empty(json::get<"content"_>(event).get("creator")))
|
|
|
|
throw FAIL
|
|
|
|
{
|
|
|
|
"m.room.create content.creator is missing."
|
|
|
|
};
|
|
|
|
|
|
|
|
// e. Otherwise, allow.
|
|
|
|
data.allow = true;
|
|
|
|
}
|