From 42b8d41e5876d57a15db2298b71bfdc96f0e8575 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 11 May 2018 02:02:46 -0700 Subject: [PATCH] ircd::m::v1::key: Add overload for key_id in uri. --- include/ircd/m/v1/key.h | 1 + ircd/m/v1.cc | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/ircd/m/v1/key.h b/include/ircd/m/v1/key.h index 32d3a791f..42c9c488d 100644 --- a/include/ircd/m/v1/key.h +++ b/include/ircd/m/v1/key.h @@ -30,6 +30,7 @@ struct ircd::m::v1::key::keys return object; } + keys(const server_key &, const mutable_buffer &, opts); keys(const string_view &server_name, const mutable_buffer &, opts); keys() = default; }; diff --git a/ircd/m/v1.cc b/ircd/m/v1.cc index 2cb08db47..be970b16b 100644 --- a/ircd/m/v1.cc +++ b/ircd/m/v1.cc @@ -935,8 +935,21 @@ ircd::m::v1::query::query(const string_view &type, ircd::m::v1::key::keys::keys(const string_view &server_name, const mutable_buffer &buf, opts opts) +:keys +{ + server_key{server_name, ""}, buf, std::move(opts) +} +{ +} + +ircd::m::v1::key::keys::keys(const server_key &server_key, + const mutable_buffer &buf, + opts opts) :server::request{[&] { + const auto &server_name{server_key.first}; + const auto &key_id{server_key.second}; + if(!opts.remote) opts.remote = net::hostport{server_name}; @@ -953,7 +966,17 @@ ircd::m::v1::key::keys::keys(const string_view &server_name, json::get<"content"_>(opts.request) = json::object{opts.out.content}; if(!defined(json::get<"uri"_>(opts.request))) - json::get<"uri"_>(opts.request) = "/_matrix/key/v2/server/"; + { + if(!empty(key_id)) + { + thread_local char uribuf[512]; + json::get<"uri"_>(opts.request) = fmt::sprintf + { + uribuf, "/_matrix/key/v2/server/%s/", key_id + }; + } + else json::get<"uri"_>(opts.request) = "/_matrix/key/v2/server/"; + } json::get<"method"_>(opts.request) = "GET";