0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 05:58:56 +02:00

ircd:Ⓜ️:app: Add configuration access interface for appservice.

This commit is contained in:
Jason Volk 2019-03-15 15:31:55 -07:00
parent 8a100eeb26
commit aae00eab7f
4 changed files with 256 additions and 6 deletions

View file

@ -15,7 +15,11 @@ namespace ircd::m::app
{
struct namespace_;
struct namespaces;
struct registration;
struct config;
bool exists(const string_view &id);
extern log::log log;
}
struct ircd::m::app::namespace_
@ -49,7 +53,7 @@ struct ircd::m::app::namespaces
using super_type::tuple;
};
struct ircd::m::app::registration
struct ircd::m::app::config
:json::tuple
<
/// Required. A unique, user-defined ID of the application service which
@ -83,5 +87,13 @@ struct ircd::m::app::registration
json::property<name::protocols, json::array>
>
{
static event::idx idx(std::nothrow_t, const string_view &id);
static event::idx idx(const string_view &id);
static bool get(std::nothrow_t, const string_view &id, const event::fetch::view_closure &);
static void get(const string_view &id, const event::fetch::view_closure &);
static std::string get(std::nothrow_t, const string_view &id);
static std::string get(const string_view &id);
using super_type::tuple;
};

107
ircd/m.cc
View file

@ -846,6 +846,113 @@ const
return this->instance_multimap::it->first;
}
///////////////////////////////////////////////////////////////////////////////
//
// m/app.h
//
decltype(ircd::m::app::log)
ircd::m::app::log
{
"m.app"
};
std::string
ircd::m::app::config::get(const string_view &id)
{
using prototype = std::string (const string_view &);
static mods::import<prototype> call
{
"app_app", "ircd::m::app::config::get"
};
return call(id);
}
std::string
ircd::m::app::config::get(std::nothrow_t,
const string_view &id)
{
using prototype = std::string (std::nothrow_t, const string_view &);
static mods::import<prototype> call
{
"app_app", "ircd::m::app::config::get"
};
return call(std::nothrow, id);
}
void
ircd::m::app::config::get(const string_view &id,
const event::fetch::view_closure &closure)
{
using prototype = void (const string_view &, const event::fetch::view_closure &);
static mods::import<prototype> call
{
"app_app", "ircd::m::app::config::get"
};
return call(id, closure);
}
bool
ircd::m::app::config::get(std::nothrow_t,
const string_view &id,
const event::fetch::view_closure &closure)
{
using prototype = bool (std::nothrow_t, const string_view &, const event::fetch::view_closure &);
static mods::import<prototype> call
{
"app_app", "ircd::m::app::config::get"
};
return call(std::nothrow, id, closure);
}
ircd::m::event::idx
ircd::m::app::config::idx(const string_view &id)
{
using prototype = event::idx (const string_view &);
static mods::import<prototype> call
{
"app_app", "ircd::m::app::config::idx"
};
return call(id);
}
ircd::m::event::idx
ircd::m::app::config::idx(std::nothrow_t,
const string_view &id)
{
using prototype = event::idx (std::nothrow_t, const string_view &);
static mods::import<prototype> call
{
"app_app", "ircd::m::app::config::idx"
};
return call(std::nothrow, id);
}
bool
ircd::m::app::exists(const string_view &id)
{
using prototype = bool (const string_view &);
static mods::import<prototype> call
{
"app_app", "exists"
};
return call(id);
}
///////////////////////////////////////////////////////////////////////////////
//
// m/feds.h

View file

@ -18,24 +18,147 @@ IRCD_MODULE
ircd::m::app::fini
};
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
{
"app", my_host()
};
decltype(ircd::m::app::apps)
ircd::m::app::apps;
void
ircd::m::app::fini()
{
}
void
ircd::m::app::init()
{
if(!m::exists(app_room_id))
m::create(app_room_id, m::me, "internal");
init_apps();
}
void
ircd::m::app::fini()
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)
try
{
}
catch(const std::exception &e)
{
log::error
{
m::log, "Failed to init appservice '%s' :%s", id, 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

@ -8,12 +8,20 @@
// 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;
extern std::map<std::string, m::room::id::buf> apps;
}