mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd:Ⓜ️:v1: Fix user devices query and associated console cmd.
This commit is contained in:
parent
e0130466e9
commit
7b38d216b4
4 changed files with 124 additions and 5 deletions
48
include/ircd/m/v1/user.h
Normal file
48
include/ircd/m/v1/user.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
// Matrix Construct
|
||||
//
|
||||
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2018 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.
|
||||
|
||||
#pragma once
|
||||
#define HAVE_IRCD_M_V1_USER_H
|
||||
|
||||
namespace ircd::m::v1::user
|
||||
{
|
||||
struct opts;
|
||||
struct devices;
|
||||
}
|
||||
|
||||
struct ircd::m::v1::user::devices
|
||||
:server::request
|
||||
{
|
||||
using opts = v1::user::opts;
|
||||
|
||||
explicit operator json::object() const
|
||||
{
|
||||
const json::object object{in.content};
|
||||
return object;
|
||||
}
|
||||
|
||||
devices(const id::user &user_id, const mutable_buffer &, opts);
|
||||
devices() = default;
|
||||
};
|
||||
|
||||
struct ircd::m::v1::user::opts
|
||||
{
|
||||
net::hostport remote;
|
||||
m::request request;
|
||||
server::out out;
|
||||
server::in in;
|
||||
const struct server::request::opts *sopts {nullptr};
|
||||
|
||||
opts(const net::hostport &remote)
|
||||
:remote{remote}
|
||||
{}
|
||||
|
||||
opts() = default;
|
||||
};
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "version.h"
|
||||
#include "query.h"
|
||||
#include "user.h"
|
||||
#include "make_join.h"
|
||||
#include "send_join.h"
|
||||
#include "event.h"
|
||||
|
|
57
ircd/m/v1.cc
57
ircd/m/v1.cc
|
@ -537,6 +537,63 @@ ircd::m::v1::make_join::make_join(const room::id &room_id,
|
|||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// v1/user.h
|
||||
//
|
||||
|
||||
ircd::m::v1::user::devices::devices(const id::user &user_id,
|
||||
const mutable_buffer &buf,
|
||||
opts opts)
|
||||
:server::request{[&]
|
||||
{
|
||||
if(!opts.remote)
|
||||
opts.remote = user_id.host();
|
||||
|
||||
if(!defined(json::get<"origin"_>(opts.request)))
|
||||
json::get<"origin"_>(opts.request) = my_host();
|
||||
|
||||
if(!defined(json::get<"destination"_>(opts.request)))
|
||||
json::get<"destination"_>(opts.request) = host(opts.remote);
|
||||
|
||||
if(!defined(json::get<"uri"_>(opts.request)))
|
||||
{
|
||||
thread_local char urlbuf[2048], uidbuf[768];
|
||||
json::get<"uri"_>(opts.request) = fmt::sprintf
|
||||
{
|
||||
urlbuf, "/_matrix/federation/v1/user/devices/%s",
|
||||
url::encode(user_id, uidbuf)
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if(!size(opts.in))
|
||||
{
|
||||
const auto in_max
|
||||
{
|
||||
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
|
||||
};
|
||||
|
||||
assert(in_max >= ssize_t(size(buf) / 2));
|
||||
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
|
||||
opts.in.content = opts.in.head;
|
||||
}
|
||||
|
||||
return server::request
|
||||
{
|
||||
opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts
|
||||
};
|
||||
}()}
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// v1/query.h
|
||||
|
|
|
@ -2275,7 +2275,7 @@ console_cmd__fed__query__directory(opt &out, const string_view &line)
|
|||
}
|
||||
|
||||
bool
|
||||
console_cmd__fed__query__user_devices(opt &out, const string_view &line)
|
||||
console_cmd__fed__user__devices(opt &out, const string_view &line)
|
||||
{
|
||||
const m::id::user &user_id
|
||||
{
|
||||
|
@ -2287,7 +2287,7 @@ console_cmd__fed__query__user_devices(opt &out, const string_view &line)
|
|||
token(line, ' ', 1, user_id.host())
|
||||
};
|
||||
|
||||
m::v1::query::opts opts;
|
||||
m::v1::user::devices::opts opts;
|
||||
opts.remote = remote;
|
||||
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
|
@ -2295,12 +2295,12 @@ console_cmd__fed__query__user_devices(opt &out, const string_view &line)
|
|||
32_KiB
|
||||
};
|
||||
|
||||
m::v1::query::user_devices request
|
||||
m::v1::user::devices request
|
||||
{
|
||||
user_id, buf, std::move(opts)
|
||||
};
|
||||
|
||||
request.wait(seconds(10));
|
||||
request.wait(seconds(15));
|
||||
const auto code
|
||||
{
|
||||
request.get()
|
||||
|
@ -2311,7 +2311,20 @@ console_cmd__fed__query__user_devices(opt &out, const string_view &line)
|
|||
request
|
||||
};
|
||||
|
||||
out << string_view{response} << std::endl;
|
||||
const string_view stream_id
|
||||
{
|
||||
unquote(response["stream_id"])
|
||||
};
|
||||
|
||||
const json::array &devices
|
||||
{
|
||||
response["devices"]
|
||||
};
|
||||
|
||||
for(const json::object &device : devices)
|
||||
out << string_view{device} << std::endl;
|
||||
|
||||
out << "-- " << size(devices) << " devices." << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue