2018-10-25 02:24:43 +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 14.1 :Public Rooms"
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource
|
2018-10-25 02:24:43 +02:00
|
|
|
publicrooms_resource
|
|
|
|
{
|
|
|
|
"/_matrix/federation/v1/publicRooms",
|
|
|
|
{
|
|
|
|
"(14.1) Gets all the public rooms for the homeserver. This should not return "
|
|
|
|
"rooms that are listed on another homeserver's directory, just those listed on "
|
|
|
|
"the receiving homeserver's directory. "
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
conf::item<size_t>
|
|
|
|
flush_hiwat
|
|
|
|
{
|
|
|
|
{ "name", "ircd.federation.publicrooms.flush.hiwat" },
|
|
|
|
{ "default", 16384L },
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
static m::resource::response
|
2018-10-25 02:24:43 +02:00
|
|
|
handle_get(client &,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &);
|
2018-10-25 02:24:43 +02:00
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::method
|
2018-10-25 02:24:43 +02:00
|
|
|
get_method
|
|
|
|
{
|
|
|
|
publicrooms_resource, "GET", handle_get,
|
|
|
|
{
|
|
|
|
get_method.VERIFY_ORIGIN
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-29 09:52:02 +02:00
|
|
|
m::resource::method
|
|
|
|
post_method
|
|
|
|
{
|
|
|
|
publicrooms_resource, "POST", handle_get,
|
|
|
|
{
|
|
|
|
post_method.VERIFY_ORIGIN
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2018-10-25 02:24:43 +02:00
|
|
|
handle_get(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request)
|
2018-10-25 02:24:43 +02:00
|
|
|
{
|
2019-08-13 07:59:27 +02:00
|
|
|
char sincebuf[m::room::id::buf::SIZE];
|
2020-05-29 09:52:02 +02:00
|
|
|
const json::string &since
|
2018-10-25 02:24:43 +02:00
|
|
|
{
|
2020-05-29 09:52:02 +02:00
|
|
|
request.query["since"]?
|
|
|
|
url::decode(sincebuf, request.query["since"]):
|
|
|
|
request["since"]
|
2018-10-25 02:24:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if(since && !valid(m::id::ROOM, since))
|
|
|
|
throw m::BAD_REQUEST
|
|
|
|
{
|
|
|
|
"Invalid since token for this server."
|
|
|
|
};
|
|
|
|
|
|
|
|
const uint8_t limit
|
|
|
|
{
|
|
|
|
request.has("limit")?
|
|
|
|
uint8_t(request.at<ushort>("limit")):
|
|
|
|
uint8_t(request.query.get<ushort>("limit", 255U))
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool include_all_networks
|
|
|
|
{
|
|
|
|
request.get<bool>("include_all_networks", false)
|
|
|
|
};
|
|
|
|
|
2020-05-29 09:52:02 +02:00
|
|
|
const json::object &filter
|
|
|
|
{
|
|
|
|
request["filter"]
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::string &search_term
|
|
|
|
{
|
|
|
|
filter["generic_search_term"]
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response::chunked response
|
2018-10-25 02:24:43 +02:00
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack out
|
|
|
|
{
|
|
|
|
response.buf, response.flusher(), size_t(flush_hiwat)
|
|
|
|
};
|
|
|
|
|
2019-08-13 07:59:27 +02:00
|
|
|
m::rooms::opts opts;
|
|
|
|
opts.summary = true;
|
|
|
|
opts.join_rule = "public";
|
|
|
|
opts.server = my_host();
|
|
|
|
opts.lower_bound = true;
|
|
|
|
opts.room_id = since;
|
2020-05-29 09:52:02 +02:00
|
|
|
opts.search_term = search_term;
|
2023-01-25 07:14:26 +01:00
|
|
|
opts.request_node_id = request.node_id;
|
2023-04-22 06:20:53 +02:00
|
|
|
opts.room_type = json::string(filter["room_type"]);
|
2019-08-13 07:59:27 +02:00
|
|
|
|
2018-10-25 02:24:43 +02:00
|
|
|
size_t count{0};
|
|
|
|
m::room::id::buf prev_batch_buf;
|
|
|
|
m::room::id::buf next_batch_buf;
|
|
|
|
json::stack::object top{out};
|
|
|
|
{
|
2019-03-06 08:54:36 +01:00
|
|
|
json::stack::array chunk
|
|
|
|
{
|
|
|
|
top, "chunk"
|
|
|
|
};
|
2018-10-25 02:24:43 +02:00
|
|
|
|
2019-08-13 07:59:27 +02:00
|
|
|
m::rooms::for_each(opts, [&]
|
|
|
|
(const m::room::id &room_id)
|
2018-10-25 02:24:43 +02:00
|
|
|
{
|
2019-08-13 07:59:27 +02:00
|
|
|
json::stack::object obj
|
|
|
|
{
|
|
|
|
chunk
|
|
|
|
};
|
2018-10-25 02:24:43 +02:00
|
|
|
|
2019-09-15 04:51:08 +02:00
|
|
|
m::rooms::summary::get(obj, room_id);
|
2018-10-25 02:24:43 +02:00
|
|
|
next_batch_buf = room_id;
|
|
|
|
return ++count < limit;
|
2019-08-13 07:59:27 +02:00
|
|
|
});
|
2018-10-25 02:24:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "total_room_count_estimate", json::value
|
|
|
|
{
|
2019-08-13 07:59:27 +02:00
|
|
|
ssize_t(m::rooms::count(opts))
|
2018-10-25 02:24:43 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(prev_batch_buf)
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "prev_batch", prev_batch_buf
|
|
|
|
};
|
|
|
|
|
|
|
|
if(count >= limit)
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "next_batch", next_batch_buf
|
|
|
|
};
|
|
|
|
|
2022-06-25 22:47:43 +02:00
|
|
|
return response;
|
2018-10-25 02:24:43 +02:00
|
|
|
}
|