0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-28 03:38:53 +02:00

ircd:Ⓜ️:v1: Add version request.

This commit is contained in:
Jason Volk 2018-02-19 14:34:34 -08:00
parent af47471830
commit f620bdcb3a
3 changed files with 83 additions and 0 deletions

View file

@ -11,6 +11,7 @@
#pragma once
#define HAVE_IRCD_M_V1_H
#include "version.h"
#include "make_join.h"
#include "send_join.h"
#include "event.h"

View file

@ -0,0 +1,39 @@
// 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_VERSION_H
namespace ircd::m::v1
{
struct version;
};
struct ircd::m::v1::version
:server::request
{
struct opts;
operator json::object() const
{
return json::object{in.content};
}
version(const mutable_buffer &, opts);
};
struct ircd::m::v1::version::opts
{
net::hostport remote;
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
};

View file

@ -494,3 +494,46 @@ ircd::m::v1::make_join::make_join(const room::id &room_id,
}()}
{
}
///////////////////////////////////////////////////////////////////////////////
//
// v1/version.h
//
ircd::m::v1::version::version(const mutable_buffer &buf,
opts opts)
:server::request{[&]
{
assert(!!opts.remote);
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)))
json::get<"uri"_>(opts.request) = "/_matrix/federation/v1/version";
json::get<"method"_>(opts.request) = "GET";
opts.out.head = opts.request(buf);
if(!size(opts.in))
{
const auto in_max
{
std::max(ssize_t(size(buf) - size(opts.out.head)), ssize_t(0))
};
assert(in_max >= ssize_t(size(buf) / 2));
opts.in.head = { data(buf) + size(opts.out.head), size_t(in_max) };
opts.in.content = opts.in.head;
}
return server::request
{
opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts
};
}()}
{
}