mirror of
https://github.com/matrix-construct/construct
synced 2024-06-25 05:18:23 +02:00
ircd:Ⓜ️:app: Rename everything to bridge:: add basic query; simplify config interface.
This commit is contained in:
parent
d340ed1fdd
commit
433a3b3007
|
@ -9,20 +9,36 @@
|
|||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
#define HAVE_IRCD_M_APP_H
|
||||
#define HAVE_IRCD_M_BRIDGE_H
|
||||
|
||||
namespace ircd::m::app
|
||||
namespace ircd::m::bridge
|
||||
{
|
||||
struct namespace_;
|
||||
struct namespaces;
|
||||
struct config;
|
||||
struct query;
|
||||
|
||||
bool exists(const string_view &id);
|
||||
|
||||
extern log::log log;
|
||||
}
|
||||
|
||||
struct ircd::m::app::namespace_
|
||||
struct ircd::m::bridge::query
|
||||
{
|
||||
rfc3986::uri base_url;
|
||||
unique_mutable_buffer buf;
|
||||
window_buffer wb;
|
||||
string_view uri;
|
||||
http::request hypertext;
|
||||
server::request request;
|
||||
http::code code;
|
||||
|
||||
public:
|
||||
query(const config &, const m::user::id &);
|
||||
query(const config &, const m::room::alias &);
|
||||
};
|
||||
|
||||
struct ircd::m::bridge::namespace_
|
||||
:json::tuple
|
||||
<
|
||||
/// Required. A true or false value stating whether this application
|
||||
|
@ -37,7 +53,7 @@ struct ircd::m::app::namespace_
|
|||
using super_type::tuple;
|
||||
};
|
||||
|
||||
struct ircd::m::app::namespaces
|
||||
struct ircd::m::bridge::namespaces
|
||||
:json::tuple
|
||||
<
|
||||
/// Events which are sent from certain users.
|
||||
|
@ -53,7 +69,7 @@ struct ircd::m::app::namespaces
|
|||
using super_type::tuple;
|
||||
};
|
||||
|
||||
struct ircd::m::app::config
|
||||
struct ircd::m::bridge::config
|
||||
:json::tuple
|
||||
<
|
||||
/// Required. A unique, user-defined ID of the application service which
|
||||
|
@ -87,13 +103,16 @@ struct ircd::m::app::config
|
|||
json::property<name::protocols, json::array>
|
||||
>
|
||||
{
|
||||
using closure_bool = std::function<bool (const event::idx &, const config &)>;
|
||||
using closure = std::function<void (const event::idx &, const config &)>;
|
||||
|
||||
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);
|
||||
static bool get(std::nothrow_t, const string_view &id, const closure &);
|
||||
static void get(const string_view &id, const closure &);
|
||||
|
||||
static bool for_each(const closure_bool &);
|
||||
|
||||
using super_type::tuple;
|
||||
};
|
|
@ -88,7 +88,7 @@ namespace ircd
|
|||
#include "visible.h"
|
||||
#include "redacted.h"
|
||||
#include "feds.h"
|
||||
#include "app.h"
|
||||
#include "bridge.h"
|
||||
#include "sync.h"
|
||||
#include "fetch.h"
|
||||
#include "breadcrumb_rooms.h"
|
||||
|
|
|
@ -121,7 +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 += bridge.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
114
matrix/app.cc
|
@ -1,114 +0,0 @@
|
|||
// 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);
|
||||
}
|
196
matrix/bridge.cc
Normal file
196
matrix/bridge.cc
Normal file
|
@ -0,0 +1,196 @@
|
|||
// 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::bridge::log)
|
||||
ircd::m::bridge::log
|
||||
{
|
||||
"m.bridge"
|
||||
};
|
||||
|
||||
bool
|
||||
ircd::m::bridge::exists(const string_view &id)
|
||||
{
|
||||
return config::idx(std::nothrow, id);
|
||||
}
|
||||
|
||||
//
|
||||
// query
|
||||
//
|
||||
|
||||
ircd::m::bridge::query::query(const config &config,
|
||||
const m::room::alias &alias)
|
||||
:base_url
|
||||
{
|
||||
at<"url"_>(config)
|
||||
}
|
||||
,buf
|
||||
{
|
||||
8_KiB
|
||||
}
|
||||
,wb
|
||||
{
|
||||
buf
|
||||
}
|
||||
,uri
|
||||
{
|
||||
wb([this, &config, &alias](const mutable_buffer &buf)
|
||||
{
|
||||
thread_local char urlencbuf[512];
|
||||
return fmt::sprintf
|
||||
{
|
||||
buf, "%s/_matrix/app/v1/rooms/%s?access_token=%s",
|
||||
base_url.path,
|
||||
url::encode(urlencbuf, alias),
|
||||
at<"hs_token"_>(config),
|
||||
};
|
||||
})
|
||||
}
|
||||
,hypertext
|
||||
{
|
||||
wb,
|
||||
base_url.remote,
|
||||
"GET",
|
||||
uri,
|
||||
}
|
||||
,request
|
||||
{
|
||||
net::hostport { base_url.remote },
|
||||
server::out { wb.completed(), {} },
|
||||
server::in { wb.remains(), wb.remains() },
|
||||
}
|
||||
,code
|
||||
{
|
||||
request.get(seconds(10)) //TODO: conf
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::m::bridge::query::query(const config &config,
|
||||
const m::user::id &user_id)
|
||||
:base_url
|
||||
{
|
||||
at<"url"_>(config)
|
||||
}
|
||||
,buf
|
||||
{
|
||||
8_KiB
|
||||
}
|
||||
,wb
|
||||
{
|
||||
buf
|
||||
}
|
||||
,uri
|
||||
{
|
||||
wb([this, &config, &user_id](const mutable_buffer &buf)
|
||||
{
|
||||
thread_local char urlencbuf[512];
|
||||
return fmt::sprintf
|
||||
{
|
||||
buf, "%s/_matrix/app/v1/users/%s?access_token=%s",
|
||||
base_url.path,
|
||||
url::encode(urlencbuf, user_id),
|
||||
at<"hs_token"_>(config),
|
||||
};
|
||||
})
|
||||
}
|
||||
,hypertext
|
||||
{
|
||||
wb,
|
||||
base_url.remote,
|
||||
"GET",
|
||||
uri,
|
||||
}
|
||||
,request
|
||||
{
|
||||
net::hostport { base_url.remote },
|
||||
server::out { wb.completed(), {} },
|
||||
server::in { wb.remains(), wb.remains() },
|
||||
}
|
||||
,code
|
||||
{
|
||||
request.get(seconds(10)) //TODO: conf
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// config
|
||||
//
|
||||
|
||||
bool
|
||||
ircd::m::bridge::config::for_each(const closure_bool &closure)
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::bridge::config::get(const string_view &id,
|
||||
const closure &closure)
|
||||
{
|
||||
if(!get(std::nothrow, id, closure))
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"Configuration for appservice '%s' not found.",
|
||||
id
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::bridge::config::get(std::nothrow_t,
|
||||
const string_view &id,
|
||||
const closure &closure)
|
||||
{
|
||||
const auto event_idx
|
||||
{
|
||||
idx(std::nothrow, id)
|
||||
};
|
||||
|
||||
return m::get(std::nothrow, event_idx, "content", [&event_idx, &closure]
|
||||
(const json::object &content)
|
||||
{
|
||||
closure(event_idx, content);
|
||||
});
|
||||
}
|
||||
|
||||
ircd::m::event::idx
|
||||
ircd::m::bridge::config::idx(const string_view &id)
|
||||
{
|
||||
const auto ret
|
||||
{
|
||||
idx(std::nothrow, id)
|
||||
};
|
||||
|
||||
if(!ret)
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"Configuration for appservice '%s' not found.",
|
||||
id
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::m::event::idx
|
||||
ircd::m::bridge::config::idx(std::nothrow_t,
|
||||
const string_view &id)
|
||||
{
|
||||
const m::room::id::buf bridge_room_id
|
||||
{
|
||||
"bridge", my_host()
|
||||
};
|
||||
|
||||
const m::room::state state
|
||||
{
|
||||
bridge_room_id
|
||||
};
|
||||
|
||||
return state.get("ircd.bridge", id);
|
||||
}
|
|
@ -60,6 +60,7 @@ ircd::m::matrix::module_names
|
|||
|
||||
"m_noop",
|
||||
"m_breadcrumb_rooms",
|
||||
"m_bridge",
|
||||
"m_command",
|
||||
"m_control",
|
||||
"m_device",
|
||||
|
@ -166,8 +167,6 @@ 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
|
||||
|
|
|
@ -89,6 +89,7 @@ endif IMAGEMAGICK
|
|||
m_moduledir = @moduledir@
|
||||
|
||||
m_breadcrumb_rooms_la_SOURCES = m_breadcrumb_rooms.cc
|
||||
m_bridge_la_SOURCES = m_bridge.cc
|
||||
m_command_la_SOURCES = m_command.cc
|
||||
m_control_la_SOURCES = m_control.cc
|
||||
m_device_la_SOURCES = m_device.cc
|
||||
|
@ -119,6 +120,7 @@ m_vm_fetch_la_SOURCES = m_vm_fetch.cc
|
|||
|
||||
m_module_LTLIBRARIES = \
|
||||
m_breadcrumb_rooms.la \
|
||||
m_bridge.la \
|
||||
m_command.la \
|
||||
m_control.la \
|
||||
m_device.la \
|
||||
|
@ -163,21 +165,6 @@ key_module_LTLIBRARIES = \
|
|||
key/key_query.la \
|
||||
###
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# /_matrix/app/
|
||||
#
|
||||
|
||||
app_moduledir = @moduledir@
|
||||
|
||||
app_app_app_la_SOURCES = \
|
||||
app/app.cc \
|
||||
###
|
||||
|
||||
app_module_LTLIBRARIES = \
|
||||
app/app_app.la \
|
||||
###
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# /_matrix/identity/
|
||||
|
|
|
@ -15065,3 +15065,23 @@ console_cmd__well_known__matrix__server(opt &out, const string_view &line)
|
|||
out << result << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// bridge
|
||||
//
|
||||
|
||||
bool
|
||||
console_cmd__bridge(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"id"
|
||||
}};
|
||||
|
||||
const string_view &id
|
||||
{
|
||||
param.at("id")
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -11,18 +11,18 @@
|
|||
ircd::mapi::header
|
||||
IRCD_MODULE
|
||||
{
|
||||
"Application Services"
|
||||
"Bridges (Application Services)"
|
||||
};
|
||||
|
||||
namespace ircd::m::app
|
||||
namespace ircd::m::bridge
|
||||
{
|
||||
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
|
||||
decltype(ircd::m::bridge::notify_hook)
|
||||
ircd::m::bridge::notify_hook
|
||||
{
|
||||
handle_event,
|
||||
{
|
||||
|
@ -31,8 +31,8 @@ ircd::m::app::notify_hook
|
|||
};
|
||||
|
||||
void
|
||||
ircd::m::app::handle_event(const m::event &event,
|
||||
vm::eval &eval)
|
||||
ircd::m::bridge::handle_event(const m::event &event,
|
||||
vm::eval &eval)
|
||||
try
|
||||
{
|
||||
// Drop internal room traffic
|
||||
|
@ -43,12 +43,13 @@ try
|
|||
if(!event.event_id)
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::error
|
||||
{
|
||||
log, "Failed to handle for application services :%s",
|
||||
log, "Failed to handle for bridgelication services :%s",
|
||||
e.what(),
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue