2019-02-08 07:29:14 +01:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Federation 20 :Device Management"
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource
|
2019-02-08 07:29:14 +01:00
|
|
|
user_devices_resource
|
|
|
|
{
|
|
|
|
"/_matrix/federation/v1/user/devices",
|
|
|
|
{
|
|
|
|
"federation user devices",
|
|
|
|
resource::DIRECTORY,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
static m::resource::response
|
2019-02-08 07:29:14 +01:00
|
|
|
get__user_devices(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request);
|
2019-02-08 07:29:14 +01:00
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::method
|
2019-02-08 07:29:14 +01:00
|
|
|
method_get
|
|
|
|
{
|
2019-02-09 02:55:35 +01:00
|
|
|
user_devices_resource, "GET", get__user_devices,
|
2019-02-08 07:29:14 +01:00
|
|
|
{
|
2019-02-09 02:55:35 +01:00
|
|
|
method_get.VERIFY_ORIGIN
|
2019-02-08 07:29:14 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2019-02-08 07:29:14 +01:00
|
|
|
get__user_devices(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request)
|
2019-02-08 07:29:14 +01:00
|
|
|
{
|
|
|
|
if(request.parv.size() < 1)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"user_id path parameter required"
|
|
|
|
};
|
|
|
|
|
|
|
|
m::user::id::buf user_id
|
|
|
|
{
|
2019-02-18 19:33:35 +01:00
|
|
|
url::decode(user_id, request.parv[0])
|
2019-02-08 07:29:14 +01:00
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response::chunked response
|
2019-02-08 07:29:14 +01:00
|
|
|
{
|
2019-02-20 02:48:14 +01:00
|
|
|
client, http::OK
|
2019-02-08 07:29:14 +01:00
|
|
|
};
|
2019-02-20 02:48:14 +01:00
|
|
|
|
|
|
|
json::stack out
|
|
|
|
{
|
|
|
|
response.buf, response.flusher()
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::object top
|
|
|
|
{
|
|
|
|
out
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "user_id", user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
top, "stream_id", json::value(0L)
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::array devices
|
|
|
|
{
|
|
|
|
top, "devices"
|
|
|
|
};
|
|
|
|
|
2019-02-20 22:09:32 +01:00
|
|
|
m::device::for_each(user_id, [&devices, &user_id]
|
|
|
|
(const string_view &device_id)
|
2019-02-20 02:48:14 +01:00
|
|
|
{
|
2019-02-20 22:09:32 +01:00
|
|
|
json::stack::object device
|
|
|
|
{
|
|
|
|
devices
|
|
|
|
};
|
|
|
|
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
device, "device_id", device_id
|
|
|
|
};
|
|
|
|
|
|
|
|
// The property name difference here is on purpose, probably one of
|
|
|
|
// those so-called spec "thinkos"
|
|
|
|
m::device::get(std::nothrow, user_id, device_id, "display_name", [&device]
|
|
|
|
(const string_view &value)
|
|
|
|
{
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
device, "device_display_name", unquote(value)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
m::device::get(std::nothrow, user_id, device_id, "keys", [&device]
|
|
|
|
(const json::object &value)
|
|
|
|
{
|
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
device, "keys", value
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2019-02-20 02:48:14 +01:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
2019-06-24 07:09:41 +02:00
|
|
|
return std::move(response);
|
2019-02-08 07:29:14 +01:00
|
|
|
}
|