0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-01 19:22:53 +01:00

ircd:Ⓜ️:v1: Add query_auth request.

This commit is contained in:
Jason Volk 2019-02-16 14:24:56 -08:00
parent 551168c643
commit 547c6ca8e5
3 changed files with 110 additions and 0 deletions

View file

@ -0,0 +1,49 @@
// 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_V1_QUERY_AUTH_H
namespace ircd::m::v1
{
struct query_auth;
};
struct ircd::m::v1::query_auth
:server::request
{
struct opts;
explicit operator json::object() const
{
const auto type(json::type(in.content));
return type == json::ARRAY?
json::array{in.content}.at(1): // non-spec [200, {...}]
json::object{in.content}; // spec {...}
}
query_auth(const m::room::id &,
const m::event::id &,
const json::object &content,
const mutable_buffer &,
opts);
query_auth() = default;
};
struct ircd::m::v1::query_auth::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {true};
};

View file

@ -27,6 +27,7 @@ namespace ircd::m::v1
#include "invite.h" #include "invite.h"
#include "event.h" #include "event.h"
#include "event_auth.h" #include "event_auth.h"
#include "query_auth.h"
#include "state.h" #include "state.h"
#include "backfill.h" #include "backfill.h"
#include "frontfill.h" #include "frontfill.h"

View file

@ -462,6 +462,66 @@ ircd::m::v1::state::state(const room::id &room_id,
{ {
} }
///////////////////////////////////////////////////////////////////////////////
//
// v1/query_auth.h
//
ircd::m::v1::query_auth::query_auth(const m::room::id &room_id,
const m::event::id &event_id,
const json::object &content,
const mutable_buffer &buf,
opts opts)
:server::request{[&]
{
if(!opts.remote)
opts.remote = event_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<"content"_>(opts.request)))
json::get<"content"_>(opts.request) = content;
if(defined(json::get<"content"_>(opts.request)))
opts.out.content = json::get<"content"_>(opts.request);
if(!defined(json::get<"content"_>(opts.request)))
json::get<"content"_>(opts.request) = json::object{opts.out.content};
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/v1/query_auth/%s/%s",
url::encode(ridbuf, room_id),
url::encode(eidbuf, event_id),
};
}
json::get<"method"_>(opts.request) = "POST";
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/event_auth.h // v1/event_auth.h