From 4108945a2c6d32c7182bb6549374c2f1ddd2fd56 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 7 Apr 2020 12:34:43 -0700 Subject: [PATCH] ircd::m::app: Reorg from old module stubs; start central unit. --- matrix/Makefile.am | 1 + matrix/app.cc | 114 +++++++++++++++++++++++++ matrix/matrix.cc | 2 + modules/Makefile.am | 1 - modules/app/app.cc | 166 ++++++------------------------------ modules/app/app.h | 27 ------ modules/app/transactions.cc | 11 --- 7 files changed, 145 insertions(+), 177 deletions(-) create mode 100644 matrix/app.cc delete mode 100644 modules/app/app.h delete mode 100644 modules/app/transactions.cc diff --git a/matrix/Makefile.am b/matrix/Makefile.am index 641ee71c2..db8e6a311 100644 --- a/matrix/Makefile.am +++ b/matrix/Makefile.am @@ -121,6 +121,7 @@ libircd_matrix_la_SOURCES += user_room_account_data.cc libircd_matrix_la_SOURCES += user_room_tags.cc libircd_matrix_la_SOURCES += user_rooms.cc libircd_matrix_la_SOURCES += user_tokens.cc +libircd_matrix_la_SOURCES += app.cc libircd_matrix_la_SOURCES += breadcrumb_rooms.cc libircd_matrix_la_SOURCES += display_name.cc libircd_matrix_la_SOURCES += event_append.cc diff --git a/matrix/app.cc b/matrix/app.cc new file mode 100644 index 000000000..dd2dd9b05 --- /dev/null +++ b/matrix/app.cc @@ -0,0 +1,114 @@ +// The Construct +// +// Copyright (C) The Construct Developers, Authors & Contributors +// Copyright (C) 2016-2020 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. + +decltype(ircd::m::app::log) +ircd::m::app::log +{ + "m.app" +}; + +bool +ircd::m::app::exists(const string_view &id) +{ + return config::idx(std::nothrow, id); +} + +// +// config +// + +std::string +ircd::m::app::config::get(const string_view &id) +{ + std::string ret; + get(id, [&ret] + (const string_view &str) + { + ret = str; + }); + + return ret; +} + +std::string +ircd::m::app::config::get(std::nothrow_t, + const string_view &id) +{ + std::string ret; + get(std::nothrow, id, [&ret] + (const string_view &str) + { + ret = str; + }); + + return ret; +} + +void +ircd::m::app::config::get(const string_view &id, + const event::fetch::view_closure &closure) +{ + if(!get(std::nothrow, id, closure)) + throw m::NOT_FOUND + { + "Configuration for appservice '%s' not found.", + id + }; +} + +bool +ircd::m::app::config::get(std::nothrow_t, + const string_view &id, + const event::fetch::view_closure &closure) +{ + const auto event_idx + { + idx(std::nothrow, id) + }; + + return m::get(std::nothrow, event_idx, "content", [&closure] + (const json::object &content) + { + closure(content); + }); +} + +ircd::m::event::idx +ircd::m::app::config::idx(const string_view &id) +{ + const m::room::id::buf app_room_id + { + "app", my_host() + }; + + const m::room::state state + { + app_room_id + }; + + return state.get(std::nothrow, "ircd.app", id); +} + +ircd::m::event::idx +ircd::m::app::config::idx(std::nothrow_t, + const string_view &id) +{ + const m::room::id::buf app_room_id + { + "app", my_host() + }; + + const m::room::state state + { + app_room_id + }; + + return state.get("ircd.app", id); +} diff --git a/matrix/matrix.cc b/matrix/matrix.cc index 92bbdce62..0b1cba1c2 100644 --- a/matrix/matrix.cc +++ b/matrix/matrix.cc @@ -166,6 +166,8 @@ ircd::m::matrix::module_names "client_thirdparty_protocols", "client_versions", "client_capabilities", + + "app_app", }; /// This is a list of modules that are considered "optional" and any loading diff --git a/modules/Makefile.am b/modules/Makefile.am index 7d2f5a9b1..719a382c5 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -172,7 +172,6 @@ app_moduledir = @moduledir@ app_app_app_la_SOURCES = \ app/app.cc \ - app/transactions.cc \ ### app_module_LTLIBRARIES = \ diff --git a/modules/app/app.cc b/modules/app/app.cc index abc7e9977..fb548c1d4 100644 --- a/modules/app/app.cc +++ b/modules/app/app.cc @@ -1,164 +1,54 @@ -// Matrix Construct +// The Construct // -// Copyright (C) Matrix Construct Developers, Authors & Contributors -// Copyright (C) 2016-2019 Jason Volk +// Copyright (C) The Construct Developers, Authors & Contributors +// Copyright (C) 2016-2020 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 "app.h" - ircd::mapi::header IRCD_MODULE { - "Application Services", - ircd::m::app::init, - ircd::m::app::fini + "Application Services" }; -decltype(ircd::m::app::ns::users) -ircd::m::app::ns::users; - -decltype(ircd::m::app::ns::aliases) -ircd::m::app::ns::aliases; - -decltype(ircd::m::app::ns::rooms) -ircd::m::app::ns::rooms; - -decltype(ircd::m::app::app_room_id) -ircd::m::app::app_room_id +namespace ircd::m::app { - "app", my_host() + static void handle_event(const m::event &, vm::eval &); + + extern hookfn notify_hook; +} + +decltype(ircd::m::app::notify_hook) +ircd::m::app::notify_hook +{ + handle_event, + { + { "_site", "vm.notify" }, + } }; void -ircd::m::app::fini() -{ - -} - -void -ircd::m::app::init() -{ - if(!m::exists(app_room_id)) - m::create(app_room_id, me(), "internal"); - - init_apps(); -} - -void -ircd::m::app::init_apps() -{ - const m::room::state room - { - app_room_id - }; - - room.for_each("ircd.app", [] - (const string_view &type, const string_view &id, const event::idx &event_idx) - { - m::app::config::get(std::nothrow, id, [&id] - (const json::object &config) - { - init_app(id, config); - }); - - return true; - }); -} - -void -ircd::m::app::init_app(const string_view &id, - const json::object &config) +ircd::m::app::handle_event(const m::event &event, + vm::eval &eval) try { + // Drop internal room traffic + if(eval.room_internal) + return; + + // Drop EDU's ??? + if(!event.event_id) + return; } catch(const std::exception &e) { log::error { - m::log, "Failed to init appservice '%s' :%s", id, e.what() + log, "Failed to handle for application services :%s", + e.what(), }; } - -std::string -IRCD_MODULE_EXPORT -ircd::m::app::config::get(const string_view &id) -{ - std::string ret; - get(id, [&ret] - (const string_view &str) - { - ret = str; - }); - - return ret; -} - -std::string -IRCD_MODULE_EXPORT -ircd::m::app::config::get(std::nothrow_t, - const string_view &id) -{ - std::string ret; - get(std::nothrow, id, [&ret] - (const string_view &str) - { - ret = str; - }); - - return ret; -} - -void -IRCD_MODULE_EXPORT -ircd::m::app::config::get(const string_view &id, - const event::fetch::view_closure &closure) -{ - if(!get(std::nothrow, id, closure)) - throw m::NOT_FOUND - { - "Configuration for appservice '%s' not found.", id - }; -} - -bool -IRCD_MODULE_EXPORT -ircd::m::app::config::get(std::nothrow_t, - const string_view &id, - const event::fetch::view_closure &closure) -{ - return m::get(std::nothrow, idx(std::nothrow, id), "content", [&closure] - (const json::object &content) - { - closure(content); - }); -} - -ircd::m::event::idx -IRCD_MODULE_EXPORT -ircd::m::app::config::idx(const string_view &id) -{ - const m::room::state state{app_room_id}; - return state.get(std::nothrow, "ircd.app", id); -} - -ircd::m::event::idx -IRCD_MODULE_EXPORT -ircd::m::app::config::idx(std::nothrow_t, - const string_view &id) -{ - const m::room::state state{app_room_id}; - return state.get("ircd.app", id); -} - -bool -IRCD_MODULE_EXPORT -ircd::m::app::exists(const string_view &id) -{ - const m::room::state state{app_room_id}; - return state.has("ircd.app", id); -} diff --git a/modules/app/app.h b/modules/app/app.h deleted file mode 100644 index 0d1650ec4..000000000 --- a/modules/app/app.h +++ /dev/null @@ -1,27 +0,0 @@ -// 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. - -namespace ircd::m::app::ns -{ - extern std::set users; - extern std::set aliases; - extern std::set rooms; -} - -// app.cc -namespace ircd::m::app -{ - void init_app(const string_view &id, const json::object &config); - void init_apps(); - void init(); - void fini(); - - extern const m::room::id::buf app_room_id; -} diff --git a/modules/app/transactions.cc b/modules/app/transactions.cc deleted file mode 100644 index 9204e9979..000000000 --- a/modules/app/transactions.cc +++ /dev/null @@ -1,11 +0,0 @@ -// 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. - -#include "app.h"