0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 14:08:56 +02:00

ircd:Ⓜ️:v1: Add public_rooms requestor.

This commit is contained in:
Jason Volk 2018-04-08 13:27:18 -07:00
parent 8bf7c05ed8
commit 8625823d23
3 changed files with 123 additions and 0 deletions

View file

@ -0,0 +1,46 @@
// 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_PUBLIC_ROOMS_H
namespace ircd::m::v1
{
struct public_rooms;
};
struct ircd::m::v1::public_rooms
:server::request
{
struct opts;
explicit operator json::object() const
{
return json::object{in.content};
}
public_rooms(const net::hostport &, const mutable_buffer &, opts);
public_rooms(const net::hostport &, const mutable_buffer &);
public_rooms() = default;
};
struct ircd::m::v1::public_rooms::opts
{
net::hostport remote;
size_t limit {128};
string_view since;
string_view third_party_instance_id;
bool include_all_networks {true};
m::request request;
server::out out;
server::in in;
const struct server::request::opts *sopts {nullptr};
bool dynamic {true};
};

View file

@ -27,5 +27,6 @@ namespace ircd::m::v1
#include "event_auth.h"
#include "state.h"
#include "backfill.h"
#include "public_rooms.h"
#include "send.h"
#include "groups.h"

View file

@ -139,6 +139,82 @@ ircd::m::v1::send::send(const string_view &txnid,
{
}
///////////////////////////////////////////////////////////////////////////////
//
// v1/public_rooms.h
//
ircd::m::v1::public_rooms::public_rooms(const net::hostport &remote,
const mutable_buffer &buf)
:public_rooms
{
remote, buf, opts{}
}
{
}
ircd::m::v1::public_rooms::public_rooms(const net::hostport &remote,
const mutable_buffer &buf,
opts opts)
:server::request{[&]
{
if(!opts.remote)
opts.remote = 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<"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[3072], query[2048], since[1024], tpid[1024];
std::stringstream qss;
pubsetbuf(qss, query);
if(opts.since)
qss << "&since="
<< url::encode(opts.since, since);
if(opts.third_party_instance_id)
qss << "&third_party_instance_id="
<< url::encode(opts.third_party_instance_id, tpid);
json::get<"uri"_>(opts.request) = fmt::sprintf
{
urlbuf, "/_matrix/federation/v1/publicRooms?limit=%zu%s%s",
opts.limit,
opts.include_all_networks? "&include_all_networks=true" : "",
view(qss, query)
};
}
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/backfill.h