0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-12 13:01:07 +01:00

ircd:Ⓜ️:app: Reorg from old module stubs; start central unit.

This commit is contained in:
Jason Volk 2020-04-07 12:34:43 -07:00
parent fe63f9a3db
commit 4108945a2c
7 changed files with 145 additions and 177 deletions

View file

@ -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

114
matrix/app.cc Normal file
View file

@ -0,0 +1,114 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 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.
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);
}

View file

@ -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

View file

@ -172,7 +172,6 @@ app_moduledir = @moduledir@
app_app_app_la_SOURCES = \
app/app.cc \
app/transactions.cc \
###
app_module_LTLIBRARIES = \

View file

@ -1,164 +1,54 @@
// Matrix Construct
// The Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 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.
#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<vm::eval &> 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);
}

View file

@ -1,27 +0,0 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 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.
namespace ircd::m::app::ns
{
extern std::set<std::string> users;
extern std::set<std::string> aliases;
extern std::set<std::string> 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;
}

View file

@ -1,11 +0,0 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 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.
#include "app.h"