0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-18 07:50:57 +01:00

ircd:Ⓜ️:fed: Add /v2/invite request support.

This commit is contained in:
Jason Volk 2019-07-11 20:32:32 -07:00
parent ce55859fb2
commit 212e4abb55
3 changed files with 98 additions and 0 deletions

View file

@ -25,6 +25,7 @@ namespace ircd::m::v1
#include "make_join.h" #include "make_join.h"
#include "send_join.h" #include "send_join.h"
#include "invite.h" #include "invite.h"
#include "invite2.h"
#include "event.h" #include "event.h"
#include "event_auth.h" #include "event_auth.h"
#include "query_auth.h" #include "query_auth.h"

View file

@ -0,0 +1,41 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 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_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};
};

View file

@ -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 // v1/send_join.h