0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

modules/federation: Add send_leave endpoint handler.

This commit is contained in:
Jason Volk 2018-04-03 17:16:15 -07:00
parent 4720431d72
commit d2d6ba0f18
2 changed files with 134 additions and 0 deletions

View file

@ -248,6 +248,7 @@ federation_federation_send_join_la_SOURCES = federation/send_join.cc
federation_federation_state_ids_la_SOURCES = federation/state_ids.cc
federation_federation_state_la_SOURCES = federation/state.cc
federation_federation_make_leave_la_SOURCES = federation/make_leave.cc
federation_federation_send_leave_la_SOURCES = federation/send_leave.cc
federation_module_LTLIBRARIES = \
federation/federation_send.la \
@ -263,6 +264,7 @@ federation_module_LTLIBRARIES = \
federation/federation_state_ids.la \
federation/federation_state.la \
federation/federation_make_leave.la \
federation/federation_send_leave.la \
###
###############################################################################

View file

@ -0,0 +1,132 @@
// 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.
using namespace ircd;
mapi::header
IRCD_MODULE
{
"Federation :Send leave event"
};
const string_view
send_leave_description
{R"(
Inject a leave event into a room originating from a server without any joined
users in that room.
)"};
resource
send_leave_resource
{
"/_matrix/federation/v1/send_leave/",
{
send_leave_description,
resource::DIRECTORY
}
};
resource::response
put__send_leave(client &client,
const resource::request &request)
{
if(request.parv.size() < 1)
throw m::NEED_MORE_PARAMS
{
"room_id path parameter required"
};
m::room::id::buf room_id
{
url::decode(request.parv[0], room_id)
};
if(!my_host(room_id.host()))
throw m::error
{
http::FORBIDDEN, "M_INVALID_ROOM_ID",
"Can only send_leave for rooms on my host '%s'",
my_host()
};
if(request.parv.size() < 2)
throw m::NEED_MORE_PARAMS
{
"event_id path parameter required"
};
m::event::id::buf event_id
{
url::decode(request.parv[1], event_id)
};
const m::event event
{
request
};
if(at<"event_id"_>(event) != event_id)
throw m::error
{
http::NOT_MODIFIED, "M_MISMATCH_EVENT_ID",
"ID of event in request body does not match path parameter."
};
if(at<"room_id"_>(event) != room_id)
throw m::error
{
http::NOT_MODIFIED, "M_MISMATCH_ROOM_ID",
"ID of room in request body does not match path parameter."
};
if(json::get<"type"_>(event) != "m.room.member")
throw m::error
{
http::NOT_MODIFIED, "M_INVALID_TYPE",
"Event type must be m.room.member"
};
if(json::get<"membership"_>(event) != "leave")
throw m::error
{
http::NOT_MODIFIED, "M_INVALID_MEMBERSHIP",
"Event membership state must be 'leave'."
};
if(unquote(json::get<"content"_>(event).get("membership")) != "leave")
throw m::error
{
http::NOT_MODIFIED, "M_INVALID_CONTENT_MEMBERSHIP",
"Event content.membership state must be 'leave'."
};
m::vm::opts vmopts;
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
m::vm::eval eval
{
event, vmopts
};
return resource::response
{
client, http::OK
};
}
resource::method
method_put
{
send_leave_resource, "PUT", put__send_leave,
{
method_put.VERIFY_ORIGIN
}
};