From d5e8bbbf4aa1bdeef085cac392f3fd3969df73b2 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 20 Feb 2019 13:26:43 -0800 Subject: [PATCH] modules: Stub m.device_list_update edu handler; json schema. --- include/ircd/m/device.h | 40 +++++++++++++++++++ include/ircd/m/name.h | 4 ++ ircd/m_name.cc | 4 ++ modules/Makefile.am | 2 + modules/m_device_list_update.cc | 71 +++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+) create mode 100644 modules/m_device_list_update.cc diff --git a/include/ircd/m/device.h b/include/ircd/m/device.h index 0ff1743b4..21a7d1eca 100644 --- a/include/ircd/m/device.h +++ b/include/ircd/m/device.h @@ -15,6 +15,7 @@ namespace ircd::m { struct device; struct device_keys; + struct device_list_update; } struct ircd::m::device_keys @@ -55,6 +56,45 @@ struct ircd::m::device_keys using super_type::operator=; }; +struct ircd::m::device_list_update +:json::tuple +< + /// Required. The user ID who owns this device. + json::property, + + /// Required. The ID of the device whose details are changing. + json::property, + + /// The public human-readable name of this device. Will be absent if + /// the device has no name. + json::property, + + /// Required. An ID sent by the server for this update, unique + /// for a given user_id. Used to identify any gaps in the sequence + /// of m.device_list_update EDUs broadcast by a server. + json::property, + + /// The stream_ids of any prior m.device_list_update EDUs sent for this + /// user which have not been referred to already in an EDU's prev_id + /// field. If the receiving server does not recognise any of the prev_ids, + /// it means an EDU has been lost and the server should query a snapshot + /// of the device list via /user/keys/query in order to correctly interpret + /// future m.device_list_update EDUs. May be missing or empty for the + /// first EDU in a sequence. + json::property, + + /// True if the server is announcing that this device has been deleted. + json::property, + + /// The updated identity keys (if any) for this device. May be absent + /// if the device has no E2E keys defined. + json::property +> +{ + using super_type::tuple; + using super_type::operator=; +}; + struct ircd::m::device :json::tuple < diff --git a/include/ircd/m/name.h b/include/ircd/m/name.h index b91626a55..579236d42 100644 --- a/include/ircd/m/name.h +++ b/include/ircd/m/name.h @@ -159,4 +159,8 @@ struct ircd::m::name static constexpr const char *const message_id {"message_id"}; static constexpr const char *const messages {"messages"}; + + static constexpr const char *const stream_id {"stream_id"}; + static constexpr const char *const prev_id {"prev_id"}; + static constexpr const char *const deleted {"deleted"}; }; diff --git a/ircd/m_name.cc b/ircd/m_name.cc index ecc20ba94..5c3609cc7 100644 --- a/ircd/m_name.cc +++ b/ircd/m_name.cc @@ -138,3 +138,7 @@ constexpr const char *const ircd::m::name::algorithms; constexpr const char *const ircd::m::name::message_id; constexpr const char *const ircd::m::name::messages; + +constexpr const char *const ircd::m::name::stream_id; +constexpr const char *const ircd::m::name::prev_id; +constexpr const char *const ircd::m::name::deleted; diff --git a/modules/Makefile.am b/modules/Makefile.am index 7c0ec7556..dc9d779e5 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -107,6 +107,7 @@ m_typing_la_SOURCES = m_typing.cc m_receipt_la_SOURCES = m_receipt.cc m_presence_la_SOURCES = m_presence.cc m_direct_to_device_la_SOURCES = m_direct_to_device.cc +m_device_list_update_la_SOURCES = m_device_list_update.cc m_state_la_SOURCES = m_state.cc m_rooms_la_SOURCES = m_rooms.cc m_room_la_SOURCES = m_room.cc @@ -128,6 +129,7 @@ m_module_LTLIBRARIES = \ m_receipt.la \ m_presence.la \ m_direct_to_device.la \ + m_device_list_update.la \ m_state.la \ m_rooms.la \ m_room.la \ diff --git a/modules/m_device_list_update.cc b/modules/m_device_list_update.cc new file mode 100644 index 000000000..2a0963005 --- /dev/null +++ b/modules/m_device_list_update.cc @@ -0,0 +1,71 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2019 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 +{ + "Matrix Device List Update" +}; + +static void +handle_edu_m_device_list_update(const m::event &, + m::vm::eval &); + +const m::hookfn +_m_device_list_update_eval +{ + handle_edu_m_device_list_update, + { + { "_site", "vm.eval" }, + { "type", "m.device_list_update" }, + } +}; + +void +handle_edu_m_device_list_update(const m::event &event, + m::vm::eval &eval) +try +{ + if(m::my_host(at<"origin"_>(event))) + return; + + const json::object &content + { + at<"content"_>(event) + }; + + const m::device_list_update update + { + content + }; + + log::info + { + m::log, "Device list update from :%s by %s for '%s' sid:%lu %s", + json::get<"origin"_>(event), + json::get<"user_id"_>(update), + json::get<"device_id"_>(update), + json::get<"stream_id"_>(update), + json::get<"deleted"_>(update)? + "[deleted]"_sv: + string_view{} + }; +} +catch(const std::exception &e) +{ + log::derror + { + m::log, "m.device_list_update from %s :%s", + json::get<"origin"_>(event), + e.what(), + }; +}