From 212e4abb553dc66157236a9a25558b755193ada1 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 11 Jul 2019 20:32:32 -0700 Subject: [PATCH] ircd::m::fed: Add /v2/invite request support. --- include/ircd/m/fed/fed.h | 1 + include/ircd/m/fed/invite2.h | 41 ++++++++++++++++++++++++++ ircd/m_fed.cc | 56 ++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 include/ircd/m/fed/invite2.h diff --git a/include/ircd/m/fed/fed.h b/include/ircd/m/fed/fed.h index cca0ef22f..33f147fdf 100644 --- a/include/ircd/m/fed/fed.h +++ b/include/ircd/m/fed/fed.h @@ -25,6 +25,7 @@ namespace ircd::m::v1 #include "make_join.h" #include "send_join.h" #include "invite.h" +#include "invite2.h" #include "event.h" #include "event_auth.h" #include "query_auth.h" diff --git a/include/ircd/m/fed/invite2.h b/include/ircd/m/fed/invite2.h new file mode 100644 index 000000000..27f359450 --- /dev/null +++ b/include/ircd/m/fed/invite2.h @@ -0,0 +1,41 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2019 Jason Volk +// +// 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_FED_INVITE2_H + +namespace ircd::m::v2 +{ + struct invite; +}; + +struct ircd::m::v2::invite +:server::request +{ + struct opts; + + explicit operator json::object() const + { + return json::object{in.content}; + } + + invite(const room::id &, const id::event &, const json::object &, const mutable_buffer &, opts); + invite() = default; +}; + +struct ircd::m::v2::invite::opts +{ + net::hostport remote; + m::request request; + server::out out; + server::in in; + const struct server::request::opts *sopts {nullptr}; + bool dynamic {false}; +}; diff --git a/ircd/m_fed.cc b/ircd/m_fed.cc index c1abbe461..aed7efee1 100644 --- a/ircd/m_fed.cc +++ b/ircd/m_fed.cc @@ -671,6 +671,62 @@ ircd::m::v1::invite::invite(const room::id &room_id, { } +/////////////////////////////////////////////////////////////////////////////// +// +// v2/invite.h +// + +ircd::m::v2::invite::invite(const room::id &room_id, + const id::event &event_id, + const json::object &content, + const mutable_buffer &buf, + opts opts) +:server::request{[&] +{ + assert(!!opts.remote); + + assert(!size(opts.out.content)); + opts.out.content = content; + + assert(!defined(json::get<"content"_>(opts.request))); + json::get<"content"_>(opts.request) = json::object{opts.out.content}; + + 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], ridbuf[768], eidbuf[768]; + json::get<"uri"_>(opts.request) = fmt::sprintf + { + urlbuf, "/_matrix/federation/v2/invite/%s/%s", + url::encode(ridbuf, room_id), + url::encode(eidbuf, event_id) + }; + } + + json::get<"method"_>(opts.request) = "PUT"; + opts.out.head = opts.request(buf); + + if(!size(opts.in)) + { + opts.in.head = buf + size(opts.out.head); + opts.in.content = opts.dynamic? + mutable_buffer{}: // server::request will allocate new mem + opts.in.head; // server::request will auto partition + } + + return server::request + { + opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts + }; +}()} +{ +} + /////////////////////////////////////////////////////////////////////////////// // // v1/send_join.h