mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 09:40:12 +01:00
ircd:Ⓜ️:v1: Support query for client_keys; add console command.
This commit is contained in:
parent
9b6ef1189b
commit
b284f707e5
3 changed files with 110 additions and 2 deletions
|
@ -23,6 +23,7 @@ struct ircd::m::v1::query
|
||||||
struct profile;
|
struct profile;
|
||||||
struct directory;
|
struct directory;
|
||||||
struct user_devices;
|
struct user_devices;
|
||||||
|
struct client_keys;
|
||||||
|
|
||||||
explicit operator json::object() const
|
explicit operator json::object() const
|
||||||
{
|
{
|
||||||
|
@ -71,3 +72,10 @@ struct ircd::m::v1::query::user_devices
|
||||||
user_devices(const id::user &, const mutable_buffer &, opts);
|
user_devices(const id::user &, const mutable_buffer &, opts);
|
||||||
user_devices(const id::user &, const mutable_buffer &);
|
user_devices(const id::user &, const mutable_buffer &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ircd::m::v1::query::client_keys
|
||||||
|
:query
|
||||||
|
{
|
||||||
|
client_keys(const id::user &, const string_view &device_id, const mutable_buffer &, opts);
|
||||||
|
client_keys(const id::user &, const string_view &device_id, const mutable_buffer &);
|
||||||
|
};
|
||||||
|
|
54
ircd/m/v1.cc
54
ircd/m/v1.cc
|
@ -486,6 +486,50 @@ namespace ircd::m::v1
|
||||||
thread_local char query_url_buf[1024];
|
thread_local char query_url_buf[1024];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ircd::m::v1::query::client_keys::client_keys(const id::user &user_id,
|
||||||
|
const string_view &device_id,
|
||||||
|
const mutable_buffer &buf)
|
||||||
|
:client_keys
|
||||||
|
{
|
||||||
|
user_id, device_id, buf, opts{user_id.host()}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ircd::m::v1::query::client_keys::client_keys(const id::user &user_id,
|
||||||
|
const string_view &device_id,
|
||||||
|
const mutable_buffer &buf,
|
||||||
|
opts opts)
|
||||||
|
:query{[&]() -> query
|
||||||
|
{
|
||||||
|
const json::value device_ids[]
|
||||||
|
{
|
||||||
|
{ device_id }
|
||||||
|
};
|
||||||
|
|
||||||
|
const json::members body
|
||||||
|
{
|
||||||
|
{ "device_keys", json::members
|
||||||
|
{
|
||||||
|
{ string_view{user_id}, { device_ids, 1 } }
|
||||||
|
}}
|
||||||
|
};
|
||||||
|
|
||||||
|
mutable_buffer out{buf};
|
||||||
|
const string_view content
|
||||||
|
{
|
||||||
|
stringify(out, body)
|
||||||
|
};
|
||||||
|
|
||||||
|
json::get<"content"_>(opts.request) = content;
|
||||||
|
return
|
||||||
|
{
|
||||||
|
"client_keys", string_view{}, out, std::move(opts)
|
||||||
|
};
|
||||||
|
}()}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ircd::m::v1::query::user_devices::user_devices(const id::user &user_id,
|
ircd::m::v1::query::user_devices::user_devices(const id::user &user_id,
|
||||||
const mutable_buffer &buf)
|
const mutable_buffer &buf)
|
||||||
:user_devices
|
:user_devices
|
||||||
|
@ -610,13 +654,19 @@ ircd::m::v1::query::query(const string_view &type,
|
||||||
thread_local char urlbuf[2048];
|
thread_local char urlbuf[2048];
|
||||||
json::get<"uri"_>(opts.request) = fmt::sprintf
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
||||||
{
|
{
|
||||||
urlbuf, "/_matrix/federation/v1/query/%s?%s",
|
urlbuf, "/_matrix/federation/v1/query/%s%s%s",
|
||||||
type,
|
type,
|
||||||
|
args? "?"_sv : ""_sv,
|
||||||
args
|
args
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
json::get<"method"_>(opts.request) = "GET";
|
if(defined(json::get<"content"_>(opts.request)))
|
||||||
|
opts.out.content = json::get<"content"_>(opts.request);
|
||||||
|
|
||||||
|
if(!defined(json::get<"method"_>(opts.request)))
|
||||||
|
json::get<"method"_>(opts.request) = "GET";
|
||||||
|
|
||||||
opts.out.head = opts.request(buf);
|
opts.out.head = opts.request(buf);
|
||||||
|
|
||||||
if(!size(opts.in))
|
if(!size(opts.in))
|
||||||
|
|
|
@ -1748,6 +1748,7 @@ console_cmd__fed__event(const string_view &line)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool console_cmd__fed__query__client_keys(const string_view &line);
|
||||||
static bool console_cmd__fed__query__user_devices(const string_view &line);
|
static bool console_cmd__fed__query__user_devices(const string_view &line);
|
||||||
static bool console_cmd__fed__query__directory(const string_view &line);
|
static bool console_cmd__fed__query__directory(const string_view &line);
|
||||||
static bool console_cmd__fed__query__profile(const string_view &line);
|
static bool console_cmd__fed__query__profile(const string_view &line);
|
||||||
|
@ -1771,6 +1772,9 @@ console_cmd__fed__query(const string_view &line)
|
||||||
case hash("user_devices"):
|
case hash("user_devices"):
|
||||||
return console_cmd__fed__query__user_devices(args);
|
return console_cmd__fed__query__user_devices(args);
|
||||||
|
|
||||||
|
case hash("client_keys"):
|
||||||
|
return console_cmd__fed__query__client_keys(args);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw bad_command{};
|
throw bad_command{};
|
||||||
}
|
}
|
||||||
|
@ -1893,6 +1897,52 @@ console_cmd__fed__query__user_devices(const string_view &line)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
console_cmd__fed__query__client_keys(const string_view &line)
|
||||||
|
{
|
||||||
|
const m::id::user &user_id
|
||||||
|
{
|
||||||
|
token(line, ' ', 0)
|
||||||
|
};
|
||||||
|
|
||||||
|
const string_view &device_id
|
||||||
|
{
|
||||||
|
token(line, ' ', 1)
|
||||||
|
};
|
||||||
|
|
||||||
|
const net::hostport remote
|
||||||
|
{
|
||||||
|
token(line, ' ', 2, user_id.host())
|
||||||
|
};
|
||||||
|
|
||||||
|
m::v1::query::opts opts;
|
||||||
|
opts.remote = remote;
|
||||||
|
|
||||||
|
const unique_buffer<mutable_buffer> buf
|
||||||
|
{
|
||||||
|
32_KiB
|
||||||
|
};
|
||||||
|
|
||||||
|
m::v1::query::client_keys request
|
||||||
|
{
|
||||||
|
user_id, device_id, buf, std::move(opts)
|
||||||
|
};
|
||||||
|
|
||||||
|
request.wait(seconds(10));
|
||||||
|
const auto code
|
||||||
|
{
|
||||||
|
request.get()
|
||||||
|
};
|
||||||
|
|
||||||
|
const json::object &response
|
||||||
|
{
|
||||||
|
request
|
||||||
|
};
|
||||||
|
|
||||||
|
out << string_view{response} << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
console_cmd__fed__version(const string_view &line)
|
console_cmd__fed__version(const string_view &line)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue