0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd:Ⓜ️:bridge: Add timeout conf item; fix queries; add console cmd.

This commit is contained in:
Jason Volk 2020-04-11 20:12:42 -07:00
parent 926c5914a8
commit 3c8a8d01aa
3 changed files with 94 additions and 31 deletions

View file

@ -25,10 +25,12 @@ namespace ircd::m::bridge
struct ircd::m::bridge::query struct ircd::m::bridge::query
{ {
static conf::item<seconds> timeout;
rfc3986::uri base_url; rfc3986::uri base_url;
unique_mutable_buffer buf; unique_mutable_buffer buf;
window_buffer wb;
string_view uri; string_view uri;
window_buffer wb;
http::request hypertext; http::request hypertext;
server::request request; server::request request;
http::code code; http::code code;

View file

@ -24,6 +24,18 @@ ircd::m::bridge::exists(const string_view &id)
// query // query
// //
namespace ircd::m::bridge
{
thread_local char urlencbuf[512];
}
decltype(ircd::m::bridge::query::timeout)
ircd::m::bridge::query::timeout
{
{ "name", "ircd.m.bridge.query.timeout" },
{ "default", 5L },
};
ircd::m::bridge::query::query(const config &config, ircd::m::bridge::query::query(const config &config,
const m::room::alias &alias) const m::room::alias &alias)
:base_url :base_url
@ -34,23 +46,19 @@ ircd::m::bridge::query::query(const config &config,
{ {
8_KiB 8_KiB
} }
,wb
{
buf
}
,uri ,uri
{ {
wb([this, &config, &alias](const mutable_buffer &buf) fmt::sprintf
{ {
thread_local char urlencbuf[512]; buf, "%s/_matrix/app/v1/rooms/%s?access_token=%s",
return fmt::sprintf base_url.path,
{ url::encode(urlencbuf, alias),
buf, "%s/_matrix/app/v1/rooms/%s?access_token=%s", at<"hs_token"_>(config),
base_url.path, }
url::encode(urlencbuf, alias), }
at<"hs_token"_>(config), ,wb
}; {
}) buf + size(uri)
} }
,hypertext ,hypertext
{ {
@ -67,7 +75,7 @@ ircd::m::bridge::query::query(const config &config,
} }
,code ,code
{ {
request.get(seconds(10)) //TODO: conf request.get(seconds(timeout))
} }
{ {
} }
@ -82,23 +90,19 @@ ircd::m::bridge::query::query(const config &config,
{ {
8_KiB 8_KiB
} }
,wb
{
buf
}
,uri ,uri
{ {
wb([this, &config, &user_id](const mutable_buffer &buf) fmt::sprintf
{ {
thread_local char urlencbuf[512]; buf, "%s/_matrix/app/v1/users/%s?access_token=%s",
return fmt::sprintf base_url.path,
{ url::encode(urlencbuf, user_id),
buf, "%s/_matrix/app/v1/users/%s?access_token=%s", at<"hs_token"_>(config),
base_url.path, }
url::encode(urlencbuf, user_id), }
at<"hs_token"_>(config), ,wb
}; {
}) buf + size(uri)
} }
,hypertext ,hypertext
{ {
@ -115,7 +119,7 @@ ircd::m::bridge::query::query(const config &config,
} }
,code ,code
{ {
request.get(seconds(10)) //TODO: conf request.get(seconds(timeout))
} }
{ {
} }

View file

@ -15110,3 +15110,60 @@ console_cmd__bridge(opt &out, const string_view &line)
return true; return true;
} }
bool
console_cmd__bridge__query(opt &out, const string_view &line)
{
const params param{line, " ",
{
"bridge_id", "mxid"
}};
const string_view &bridge_id
{
param.at("bridge_id")
};
const string_view &mxid
{
param.at("mxid")
};
std::string config;
m::bridge::config::get(bridge_id, [&config]
(const auto &, const auto &object)
{
config = object.source;
});
switch(m::sigil(mxid))
{
case m::id::USER:
{
m::bridge::query
{
m::bridge::config{config}, m::user::id{mxid}
};
break;
}
case m::id::ROOM_ALIAS:
{
m::bridge::query
{
m::bridge::config{config}, m::room::alias{mxid}
};
break;
}
default:
throw error
{
"Invalid MXID argument"
};
}
return true;
}