2018-04-04 02:05:56 +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 state_ids"
|
|
|
|
};
|
|
|
|
|
|
|
|
resource
|
|
|
|
state_ids_resource
|
|
|
|
{
|
|
|
|
"/_matrix/federation/v1/state_ids/",
|
|
|
|
{
|
|
|
|
"federation state_ids",
|
|
|
|
resource::DIRECTORY,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
resource::response
|
|
|
|
get__state_ids(client &client,
|
|
|
|
const resource::request &request)
|
|
|
|
{
|
2019-02-18 19:33:35 +01:00
|
|
|
if(request.parv.size() < 1)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"room_id path parameter required"
|
|
|
|
};
|
|
|
|
|
2018-04-04 02:05:56 +02:00
|
|
|
m::room::id::buf room_id
|
|
|
|
{
|
2018-12-07 01:41:47 +01:00
|
|
|
url::decode(room_id, request.parv[0])
|
2018-04-04 02:05:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
m::event::id::buf event_id;
|
2018-04-30 19:45:41 +02:00
|
|
|
if(request.query["event_id"])
|
2018-12-07 01:41:47 +01:00
|
|
|
event_id = url::decode(event_id, request.query.at("event_id"));
|
2018-04-04 02:05:56 +02:00
|
|
|
|
2018-04-30 19:35:04 +02:00
|
|
|
const m::room room
|
2018-04-04 02:05:56 +02:00
|
|
|
{
|
2018-04-30 19:35:04 +02:00
|
|
|
room_id, event_id
|
|
|
|
};
|
2018-04-04 02:05:56 +02:00
|
|
|
|
2018-05-31 14:56:02 +02:00
|
|
|
if(!room.visible(request.node_id))
|
|
|
|
throw m::ACCESS_DENIED
|
|
|
|
{
|
|
|
|
"You are not permitted to view the room at this event"
|
|
|
|
};
|
|
|
|
|
2018-04-30 19:35:04 +02:00
|
|
|
const m::room::state state
|
|
|
|
{
|
|
|
|
room
|
|
|
|
};
|
2018-04-04 02:05:56 +02:00
|
|
|
|
2019-03-23 05:00:59 +01:00
|
|
|
const m::event::auth::chain ac
|
|
|
|
{
|
|
|
|
event_id?
|
|
|
|
m::index(event_id):
|
|
|
|
m::head_idx(room)
|
|
|
|
};
|
|
|
|
|
2018-04-30 19:35:04 +02:00
|
|
|
resource::response::chunked response
|
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
2018-04-04 02:05:56 +02:00
|
|
|
|
2018-09-05 07:48:23 +02:00
|
|
|
json::stack out
|
2018-04-30 19:35:04 +02:00
|
|
|
{
|
2018-09-05 07:48:23 +02:00
|
|
|
response.buf, response.flusher()
|
|
|
|
};
|
2018-04-30 19:35:04 +02:00
|
|
|
|
|
|
|
json::stack::object top{out};
|
2018-04-04 02:05:56 +02:00
|
|
|
|
2019-02-17 00:16:23 +01:00
|
|
|
// auth_chain
|
2019-04-25 02:11:38 +02:00
|
|
|
if(request.query.get<bool>("auth_chain", true))
|
2018-04-30 19:35:04 +02:00
|
|
|
{
|
2019-02-17 00:16:23 +01:00
|
|
|
json::stack::array auth_chain
|
|
|
|
{
|
|
|
|
top, "auth_chain"
|
|
|
|
};
|
|
|
|
|
|
|
|
ac.for_each([&auth_chain]
|
|
|
|
(const m::event::idx &event_idx)
|
|
|
|
{
|
|
|
|
m::event_id(event_idx, std::nothrow, [&auth_chain]
|
|
|
|
(const auto &event_id)
|
|
|
|
{
|
|
|
|
auth_chain.append(event_id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2018-04-30 19:35:04 +02:00
|
|
|
|
2019-04-25 02:10:48 +02:00
|
|
|
// pdu_ids
|
2019-04-25 02:11:38 +02:00
|
|
|
if(request.query.get<bool>("pdu_ids", true))
|
2019-04-25 02:10:48 +02:00
|
|
|
{
|
|
|
|
json::stack::array pdu_ids
|
|
|
|
{
|
|
|
|
top, "pdu_ids"
|
|
|
|
};
|
|
|
|
|
|
|
|
state.for_each(m::event::id::closure{[&pdu_ids]
|
|
|
|
(const m::event::id &event_id)
|
|
|
|
{
|
|
|
|
pdu_ids.append(event_id);
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
2019-04-18 06:34:18 +02:00
|
|
|
return response;
|
2018-04-04 02:05:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource::method
|
|
|
|
method_get
|
|
|
|
{
|
|
|
|
state_ids_resource, "GET", get__state_ids,
|
|
|
|
{
|
|
|
|
method_get.VERIFY_ORIGIN
|
|
|
|
}
|
|
|
|
};
|