mirror of
https://github.com/matrix-construct/construct
synced 2025-01-13 08:23:56 +01:00
ircd:Ⓜ️:v1: Add event_auth requestor.
This commit is contained in:
parent
65c8ab3ba7
commit
5621da53bc
3 changed files with 109 additions and 0 deletions
42
include/ircd/m/v1/event_auth.h
Normal file
42
include/ircd/m/v1/event_auth.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
// 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.
|
||||
|
||||
#pragma once
|
||||
#define HAVE_IRCD_M_V1_EVENT_AUTH_H
|
||||
|
||||
namespace ircd::m::v1
|
||||
{
|
||||
struct event_auth;
|
||||
};
|
||||
|
||||
struct ircd::m::v1::event_auth
|
||||
:server::request
|
||||
{
|
||||
struct opts;
|
||||
|
||||
explicit operator json::object() const
|
||||
{
|
||||
return json::object{in.content};
|
||||
}
|
||||
|
||||
event_auth(const m::room::id &, const m::event::id &, const mutable_buffer &, opts);
|
||||
event_auth(const m::room::id &, const m::event::id &, const mutable_buffer &);
|
||||
event_auth() = default;
|
||||
};
|
||||
|
||||
struct ircd::m::v1::event_auth::opts
|
||||
{
|
||||
net::hostport remote;
|
||||
m::request request;
|
||||
server::out out;
|
||||
server::in in;
|
||||
const struct server::request::opts *sopts {nullptr};
|
||||
bool dynamic {true};
|
||||
};
|
|
@ -24,6 +24,7 @@ namespace ircd::m::v1
|
|||
#include "send_join.h"
|
||||
#include "invite.h"
|
||||
#include "event.h"
|
||||
#include "event_auth.h"
|
||||
#include "state.h"
|
||||
#include "backfill.h"
|
||||
#include "send.h"
|
||||
|
|
66
ircd/m/v1.cc
66
ircd/m/v1.cc
|
@ -283,6 +283,72 @@ ircd::m::v1::state::state(const room::id &room_id,
|
|||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// v1/event_auth.h
|
||||
//
|
||||
|
||||
ircd::m::v1::event_auth::event_auth(const m::room::id &room_id,
|
||||
const m::event::id &event_id,
|
||||
const mutable_buffer &buf)
|
||||
:event_auth
|
||||
{
|
||||
room_id, event_id, buf, opts{}
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::m::v1::event_auth::event_auth(const m::room::id &room_id,
|
||||
const m::event::id &event_id,
|
||||
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)))
|
||||
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/event_auth/%s/%s",
|
||||
url::encode(room_id, ridbuf),
|
||||
url::encode(event_id, eidbuf),
|
||||
};
|
||||
}
|
||||
|
||||
json::get<"method"_>(opts.request) = "GET";
|
||||
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.h
|
||||
|
|
Loading…
Reference in a new issue