2018-04-03 23:50:47 +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.
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Federation :Request a prototype for creating a join event."
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view
|
|
|
|
make_join_description
|
|
|
|
{R"(
|
|
|
|
|
|
|
|
Sends a partial event to the remote with enough information for them to
|
|
|
|
create a join event 'in the blind' for one of their users.
|
|
|
|
|
|
|
|
)"};
|
|
|
|
|
|
|
|
resource
|
|
|
|
make_join_resource
|
|
|
|
{
|
|
|
|
"/_matrix/federation/v1/make_join/",
|
|
|
|
{
|
|
|
|
make_join_description,
|
|
|
|
resource::DIRECTORY
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
resource::response
|
|
|
|
get__make_join(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
|
|
|
|
{
|
2018-12-07 01:41:47 +01:00
|
|
|
url::decode(room_id, request.parv[0])
|
2018-04-03 23:50:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if(request.parv.size() < 2)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"user_id path parameter required"
|
|
|
|
};
|
|
|
|
|
|
|
|
m::user::id::buf user_id
|
|
|
|
{
|
2018-12-07 01:41:47 +01:00
|
|
|
url::decode(user_id, request.parv[1])
|
2018-04-03 23:50:47 +02:00
|
|
|
};
|
2019-04-17 14:24:28 +02:00
|
|
|
|
2019-05-06 20:10:53 +02:00
|
|
|
if(user_id.host() != request.origin)
|
2019-04-17 14:24:28 +02:00
|
|
|
throw m::ACCESS_DENIED
|
|
|
|
{
|
|
|
|
"You are not permitted to spoof users on other hosts."
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
if(!exists(room))
|
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"Room %s is not known here.",
|
|
|
|
string_view{room_id}
|
|
|
|
};
|
|
|
|
|
2019-05-27 05:36:26 +02:00
|
|
|
if(m::room::server_acl::enable_read && !m::room::server_acl::check(room_id, request.node_id))
|
|
|
|
throw m::ACCESS_DENIED
|
|
|
|
{
|
|
|
|
"You are not permitted by the room's server access control list."
|
|
|
|
};
|
|
|
|
|
2019-08-14 10:01:46 +02:00
|
|
|
if(!visible(room, user_id))
|
2019-04-17 14:24:28 +02:00
|
|
|
throw m::ACCESS_DENIED
|
|
|
|
{
|
|
|
|
"You are not permitted to view the room at this event."
|
|
|
|
};
|
2018-04-03 23:50:47 +02:00
|
|
|
|
2019-07-25 23:02:25 +02:00
|
|
|
char room_version_buf[m::room::VERSION_MAX_SIZE];
|
2019-07-16 02:30:18 +02:00
|
|
|
const string_view &room_version
|
|
|
|
{
|
|
|
|
m::version(room_version_buf, room, std::nothrow)
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool version_mismatch
|
|
|
|
{
|
|
|
|
request.query.for_each("ver", [&room_version]
|
|
|
|
(const auto &val)
|
|
|
|
{
|
|
|
|
return val.second != room_version;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
if(version_mismatch)
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::NOT_IMPLEMENTED, "M_INCOMPATIBLE_ROOM_VERSION",
|
|
|
|
"Your homeserver does not support the room version %s.",
|
|
|
|
room_version?
|
|
|
|
room_version : "?????",
|
|
|
|
};
|
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
const unique_buffer<mutable_buffer> buf
|
2018-04-03 23:50:47 +02:00
|
|
|
{
|
2019-04-17 15:52:09 +02:00
|
|
|
8_KiB
|
2018-04-03 23:50:47 +02:00
|
|
|
};
|
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
json::stack out{buf};
|
|
|
|
json::stack::object top{out};
|
2019-07-15 23:30:26 +02:00
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "room_version", json::value
|
|
|
|
{
|
2019-07-16 02:30:18 +02:00
|
|
|
room_version, json::STRING
|
2019-07-15 23:30:26 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
json::stack::object event
|
2018-04-03 23:50:47 +02:00
|
|
|
{
|
2019-04-17 15:52:09 +02:00
|
|
|
top, "event"
|
2018-04-03 23:50:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
2019-07-09 04:58:04 +02:00
|
|
|
json::stack::checkpoint cp{out};
|
2019-04-17 15:52:09 +02:00
|
|
|
json::stack::array auth_events
|
|
|
|
{
|
|
|
|
event, "auth_events"
|
|
|
|
};
|
|
|
|
|
2019-07-09 04:58:04 +02:00
|
|
|
const json::members args
|
2019-04-17 15:52:09 +02:00
|
|
|
{
|
2019-07-09 04:58:04 +02:00
|
|
|
{ "type", "m.room.member" },
|
|
|
|
{ "state_key", user_id },
|
|
|
|
{ "sender", user_id },
|
2019-04-17 15:52:09 +02:00
|
|
|
};
|
|
|
|
|
2019-08-18 08:19:05 +02:00
|
|
|
if(!m::room::auth::generate(auth_events, room, m::event{args}))
|
2019-07-09 04:58:04 +02:00
|
|
|
cp.decommit();
|
2019-04-17 15:52:09 +02:00
|
|
|
}
|
2018-04-03 23:50:47 +02:00
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
json::stack::member
|
2018-04-05 02:23:47 +02:00
|
|
|
{
|
2019-04-17 15:52:09 +02:00
|
|
|
event, "content", R"({"membership":"join"})"
|
2018-04-05 02:23:47 +02:00
|
|
|
};
|
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
json::stack::member
|
2018-04-05 02:23:47 +02:00
|
|
|
{
|
2019-04-17 15:52:09 +02:00
|
|
|
event, "depth", json::value(m::depth(room) + 1L)
|
2018-04-05 02:23:47 +02:00
|
|
|
};
|
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
event, "origin", request.origin
|
|
|
|
};
|
2019-02-13 23:27:51 +01:00
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
json::stack::member
|
2019-02-13 23:27:51 +01:00
|
|
|
{
|
2019-04-17 15:52:09 +02:00
|
|
|
event, "origin_server_ts", json::value(time<milliseconds>())
|
2019-02-13 23:27:51 +01:00
|
|
|
};
|
2018-04-05 02:23:47 +02:00
|
|
|
|
|
|
|
{
|
2019-04-17 15:52:09 +02:00
|
|
|
const m::room::head head{room};
|
|
|
|
json::stack::array prev_events
|
|
|
|
{
|
|
|
|
event, "prev_events"
|
|
|
|
};
|
|
|
|
|
2019-08-18 09:02:59 +02:00
|
|
|
head.generate(prev_events, 32, true);
|
2019-04-17 15:52:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
event, "room_id", room.room_id
|
2018-04-05 02:23:47 +02:00
|
|
|
};
|
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
json::stack::member
|
2018-04-05 02:23:47 +02:00
|
|
|
{
|
2019-04-17 15:52:09 +02:00
|
|
|
event, "sender", user_id
|
2018-04-05 02:23:47 +02:00
|
|
|
};
|
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
json::stack::member
|
2018-04-05 02:23:47 +02:00
|
|
|
{
|
2019-04-17 15:52:09 +02:00
|
|
|
event, "state_key", user_id
|
2018-04-05 02:23:47 +02:00
|
|
|
};
|
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
event, "type", "m.room.member"
|
2018-04-03 23:50:47 +02:00
|
|
|
};
|
|
|
|
|
2019-04-17 15:52:09 +02:00
|
|
|
event.~object();
|
|
|
|
top.~object();
|
2018-04-03 23:50:47 +02:00
|
|
|
return resource::response
|
|
|
|
{
|
2019-04-17 15:52:09 +02:00
|
|
|
client, json::object
|
|
|
|
{
|
|
|
|
out.completed()
|
|
|
|
}
|
2018-04-03 23:50:47 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
resource::method
|
|
|
|
method_get
|
|
|
|
{
|
|
|
|
make_join_resource, "GET", get__make_join,
|
|
|
|
{
|
|
|
|
method_get.VERIFY_ORIGIN
|
|
|
|
}
|
|
|
|
};
|