From ae10f735ecca5be0d1f48c9428772f0fa2ca257c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 6 Mar 2023 18:58:11 -0800 Subject: [PATCH] modules: Stub federation/timestamp_to_event; stub client/rooms/timestamp_to_event. --- matrix/matrix.cc | 1 + modules/Makefile.am | 3 + modules/client/rooms/rooms.cc | 3 + modules/client/rooms/rooms.h | 10 +++ modules/client/rooms/timestamp_to_event.cc | 64 +++++++++++++++ modules/federation/timestamp_to_event.cc | 96 ++++++++++++++++++++++ 6 files changed, 177 insertions(+) create mode 100644 modules/client/rooms/timestamp_to_event.cc create mode 100644 modules/federation/timestamp_to_event.cc diff --git a/matrix/matrix.cc b/matrix/matrix.cc index 67d259a49..40bff8e92 100644 --- a/matrix/matrix.cc +++ b/matrix/matrix.cc @@ -109,6 +109,7 @@ ircd::m::module_names "federation_send_leave", "federation_send", "federation_state", + "federation_timestamp_to_event", "federation_user_devices", "federation_user_keys_claim", "federation_user_keys_query", diff --git a/modules/Makefile.am b/modules/Makefile.am index bbd8ac92f..e43d33218 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -226,6 +226,7 @@ federation_federation_user_keys_query_la_SOURCES = federation/user_keys_query.cc federation_federation_user_keys_claim_la_SOURCES = federation/user_keys_claim.cc federation_federation_rooms_la_SOURCES = federation/rooms.cc federation_federation_hierarchy_la_SOURCES = federation/hierarchy.cc +federation_federation_timestamp_to_event_la_SOURCES = federation/timestamp_to_event.cc federation_module_LTLIBRARIES = \ federation/federation_send.la \ @@ -250,6 +251,7 @@ federation_module_LTLIBRARIES = \ federation/federation_user_keys_claim.la \ federation/federation_rooms.la \ federation/federation_hierarchy.la \ + federation/federation_timestamp_to_event.la \ ### ############################################################################### @@ -346,6 +348,7 @@ client_client_rooms_la_SOURCES = \ client/rooms/aliases.cc \ client/rooms/hierarchy.cc \ client/rooms/threads.cc \ + client/rooms/timestamp_to_event.cc \ client/rooms/rooms.cc \ ### diff --git a/modules/client/rooms/rooms.cc b/modules/client/rooms/rooms.cc index abd16888a..3a80554d7 100644 --- a/modules/client/rooms/rooms.cc +++ b/modules/client/rooms/rooms.cc @@ -81,6 +81,9 @@ get_rooms(client &client, if(cmd == "threads") return get__threads(client, request, room_id); + if(cmd == "timestamp_to_event") + return get__timestamp_to_event(client, request, room_id); + throw m::NOT_FOUND { "/rooms command not found" diff --git a/modules/client/rooms/rooms.h b/modules/client/rooms/rooms.h index 45f0da87a..09a6626bb 100644 --- a/modules/client/rooms/rooms.h +++ b/modules/client/rooms/rooms.h @@ -264,3 +264,13 @@ ircd::m::resource::response get__threads(ircd::client &, const ircd::m::resource::request &, const ircd::m::room::id &); + +/////////////////////////////////////////////////////////////////////////////// +// +// timestamp_to_event.cc +// + +ircd::m::resource::response +get__timestamp_to_event(ircd::client &, + const ircd::m::resource::request &, + const ircd::m::room::id &); diff --git a/modules/client/rooms/timestamp_to_event.cc b/modules/client/rooms/timestamp_to_event.cc new file mode 100644 index 000000000..fad7df1d4 --- /dev/null +++ b/modules/client/rooms/timestamp_to_event.cc @@ -0,0 +1,64 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2023 Jason Volk +// +// 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. + +#include "rooms.h" + +using namespace ircd; + +m::resource::response +get__timestamp_to_event(client &client, + const m::resource::request &request, + const m::room::id &room_id) +{ + const auto &dir + { + request.query["dir"] + }; + + const milliseconds ts + { + request.query.at("ts") + }; + + const m::event::idx event_idx + { + 0UL + }; + + const m::event::fetch event + { + std::nothrow, event_idx + }; + + const long &event_ts + { + json::get<"origin_server_ts"_>(event) + }; + + const m::room room + { + room_id, event.event_id + }; + + if(!visible(room, request.user_id)) + throw m::ACCESS_DENIED + { + "You are not permitted to view the room at this event" + }; + + return m::resource::response + { + client, http::NOT_IMPLEMENTED, json::members + { + { "event_id", event.event_id }, + { "origin_server_ts", event_ts }, + } + }; +} diff --git a/modules/federation/timestamp_to_event.cc b/modules/federation/timestamp_to_event.cc new file mode 100644 index 000000000..ac5287e6b --- /dev/null +++ b/modules/federation/timestamp_to_event.cc @@ -0,0 +1,96 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2023 Jason Volk +// +// 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 timestamp to event" +}; + +m::resource +timestamp_to_event_resource +{ + "/_matrix/federation/v1/timestamp_to_event/", + { + "federation timestamp to event", + resource::DIRECTORY, + } +}; + +m::resource::response +get__timestamp_to_event(client &client, + const m::resource::request &request); + +m::resource::method +method_get +{ + timestamp_to_event_resource, "GET", get__timestamp_to_event, + { + method_get.VERIFY_ORIGIN + } +}; + +m::resource::response +get__timestamp_to_event(client &client, + const m::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(room_id, request.parv[0]) + }; + + 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." + }; + + const auto dir + { + request.query["dir"] + }; + + const milliseconds ts + { + request.query.at("ts") + }; + + const m::event::idx event_idx + { + 0UL + }; + + const m::event::fetch event + { + std::nothrow, event_idx + }; + + const long &event_ts + { + json::get<"origin_server_ts"_>(event) + }; + + return m::resource::response + { + client, http::NOT_IMPLEMENTED, json::members + { + { "event_id", event.event_id }, + { "origin_server_ts", event_ts }, + } + }; +}