2018-01-22 12:32:15 +01:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include <ircd/m/m.h>
|
|
|
|
|
2018-03-28 10:00:08 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// v1/groups.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::v1::groups::publicised::publicised(const id::node &node,
|
2018-04-03 03:12:59 +02:00
|
|
|
const vector_view<const id::user> &user_ids,
|
2018-03-28 10:00:08 +02:00
|
|
|
const mutable_buffer &buf_,
|
|
|
|
opts opts)
|
|
|
|
:server::request{[&]
|
|
|
|
{
|
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = node.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) = node.host();
|
|
|
|
|
|
|
|
if(!defined(json::get<"uri"_>(opts.request)))
|
|
|
|
json::get<"uri"_>(opts.request) = "/_matrix/federation/v1/get_groups_publicised";
|
|
|
|
|
|
|
|
json::get<"method"_>(opts.request) = "POST";
|
|
|
|
|
|
|
|
mutable_buffer buf{buf_};
|
|
|
|
const string_view user_ids_
|
|
|
|
{
|
|
|
|
json::stringify(buf, user_ids.data(), user_ids.data() + user_ids.size())
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(!defined(json::get<"content"_>(opts.request)));
|
|
|
|
json::get<"content"_>(opts.request) = stringify(buf, json::members
|
|
|
|
{
|
|
|
|
{ "user_ids", user_ids_ }
|
|
|
|
});
|
|
|
|
|
|
|
|
// (front of buf was advanced by stringify)
|
|
|
|
opts.out.head = opts.request(buf);
|
|
|
|
opts.out.content = json::get<"content"_>(opts.request);
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-22 19:05:45 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// v1/send.h
|
|
|
|
//
|
|
|
|
|
2018-01-23 20:43:04 +01:00
|
|
|
void
|
|
|
|
ircd::m::v1::send::response::for_each_pdu(const pdus_closure &closure)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
const json::object &pdus
|
|
|
|
{
|
|
|
|
this->get("pdus")
|
|
|
|
};
|
|
|
|
|
|
|
|
for(const auto &member : pdus)
|
|
|
|
{
|
|
|
|
const id::event &event_id{member.first};
|
|
|
|
const json::object &error{member.second};
|
|
|
|
closure(event_id, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-22 19:05:45 +01:00
|
|
|
ircd::m::v1::send::send(const string_view &txnid,
|
|
|
|
const const_buffer &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[1024], txnidbuf[512];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
2018-01-26 21:20:02 +01:00
|
|
|
urlbuf, "/_matrix/federation/v1/send/%s/",
|
|
|
|
url::encode(txnid, txnidbuf),
|
2018-01-22 19:05:45 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
json::get<"method"_>(opts.request) = "PUT";
|
|
|
|
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
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-22 12:32:15 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// v1/backfill.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::v1::backfill::backfill(const room::id &room_id,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
:backfill
|
|
|
|
{
|
2018-02-27 06:43:02 +01:00
|
|
|
room_id, buf, opts{}
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::v1::backfill::backfill(const room::id &room_id,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
|
|
|
:server::request{[&]
|
|
|
|
{
|
|
|
|
if(!opts.event_id)
|
|
|
|
{
|
|
|
|
thread_local m::event::id::buf event_id;
|
|
|
|
v1::make_join request
|
|
|
|
{
|
|
|
|
room_id, m::me.user_id, buf
|
|
|
|
};
|
|
|
|
|
2018-01-22 19:05:45 +01:00
|
|
|
request.get();
|
2018-01-22 12:32:15 +01:00
|
|
|
const json::object proto
|
|
|
|
{
|
|
|
|
request.in.content
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::array prev_events
|
|
|
|
{
|
|
|
|
proto.at({"event", "prev_events"})
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::array prev_event
|
|
|
|
{
|
|
|
|
prev_events.at(0)
|
|
|
|
};
|
|
|
|
|
|
|
|
event_id = unquote(prev_event.at(0));
|
|
|
|
opts.event_id = event_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = room_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)))
|
|
|
|
{
|
2018-01-22 19:05:45 +01:00
|
|
|
thread_local char urlbuf[2048], ridbuf[768], eidbuf[768];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2018-01-26 21:20:02 +01:00
|
|
|
urlbuf, "/_matrix/federation/v1/backfill/%s/?limit=%zu&v=%s",
|
|
|
|
url::encode(room_id, ridbuf),
|
|
|
|
opts.limit,
|
|
|
|
url::encode(opts.event_id, eidbuf),
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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) };
|
2018-02-27 07:02:47 +01:00
|
|
|
opts.in.content = mutable_buffer{};
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return server::request
|
|
|
|
{
|
|
|
|
opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// v1/state.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::v1::state::state(const room::id &room_id,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
:state
|
|
|
|
{
|
2018-02-27 06:43:02 +01:00
|
|
|
room_id, buf, opts{}
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::v1::state::state(const room::id &room_id,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
|
|
|
:server::request{[&]
|
|
|
|
{
|
|
|
|
if(!opts.event_id)
|
|
|
|
{
|
|
|
|
thread_local m::event::id::buf event_id;
|
|
|
|
v1::make_join request
|
|
|
|
{
|
|
|
|
room_id, m::me.user_id, buf
|
|
|
|
};
|
|
|
|
|
2018-01-22 19:05:45 +01:00
|
|
|
request.get();
|
2018-01-22 12:32:15 +01:00
|
|
|
const json::object proto
|
|
|
|
{
|
|
|
|
request.in.content
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::array prev_events
|
|
|
|
{
|
|
|
|
proto.at({"event", "prev_events"})
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::array prev_event
|
|
|
|
{
|
|
|
|
prev_events.at(0)
|
|
|
|
};
|
|
|
|
|
|
|
|
event_id = unquote(prev_event.at(0));
|
|
|
|
opts.event_id = event_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = room_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)))
|
|
|
|
{
|
2018-01-22 19:05:45 +01:00
|
|
|
thread_local char urlbuf[2048], ridbuf[768], eidbuf[768];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2018-04-03 02:38:35 +02:00
|
|
|
urlbuf, "/_matrix/federation/v1/%s/%s/?event_id=%s",
|
|
|
|
opts.ids_only? "state_ids" : "state",
|
2018-01-26 21:20:02 +01:00
|
|
|
url::encode(room_id, ridbuf),
|
|
|
|
url::encode(opts.event_id, eidbuf),
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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) };
|
2018-02-27 07:02:47 +01:00
|
|
|
opts.in.content = mutable_buffer{};
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return server::request
|
|
|
|
{
|
|
|
|
opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// v1/event.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::v1::event::event(const m::event::id &event_id,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
:event
|
|
|
|
{
|
2018-02-27 06:43:02 +01:00
|
|
|
event_id, buf, opts{}
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::v1::event::event(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[1024], eidbuf[768];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2018-01-26 21:20:02 +01:00
|
|
|
urlbuf, "/_matrix/federation/v1/event/%s/",
|
|
|
|
url::encode(event_id, eidbuf),
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
|
|
|
opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-03 21:58:18 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// v1/invite.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::v1::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/v1/invite/%s/%s",
|
|
|
|
url::encode(room_id, ridbuf),
|
|
|
|
url::encode(event_id, eidbuf)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
json::get<"method"_>(opts.request) = "PUT";
|
|
|
|
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 = mutable_buffer{};
|
|
|
|
}
|
|
|
|
|
|
|
|
return server::request
|
|
|
|
{
|
|
|
|
opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-22 19:05:45 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// v1/send_join.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::v1::send_join::send_join(const room::id &room_id,
|
2018-03-09 00:55:02 +01:00
|
|
|
const id::event &event_id,
|
2018-01-22 19:05:45 +01:00
|
|
|
const const_buffer &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], uidbuf[768];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 19:05:45 +01:00
|
|
|
{
|
2018-01-26 21:20:02 +01:00
|
|
|
urlbuf, "/_matrix/federation/v1/send_join/%s/%s",
|
|
|
|
url::encode(room_id, ridbuf),
|
2018-03-09 00:55:02 +01:00
|
|
|
url::encode(event_id, uidbuf)
|
2018-01-22 19:05:45 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
json::get<"method"_>(opts.request) = "PUT";
|
|
|
|
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) };
|
2018-02-27 07:02:47 +01:00
|
|
|
opts.in.content = mutable_buffer{};
|
2018-01-22 19:05:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return server::request
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
|
|
|
opts.remote, std::move(opts.out), std::move(opts.in), opts.sopts
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// v1/make_join.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::v1::make_join::make_join(const room::id &room_id,
|
2018-04-03 03:12:59 +02:00
|
|
|
const id::user &user_id,
|
2018-01-22 12:32:15 +01:00
|
|
|
const mutable_buffer &buf)
|
|
|
|
:make_join
|
|
|
|
{
|
2018-02-27 06:43:02 +01:00
|
|
|
room_id, user_id, buf, opts{}
|
2018-01-22 12:32:15 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::v1::make_join::make_join(const room::id &room_id,
|
2018-04-03 03:12:59 +02:00
|
|
|
const id::user &user_id,
|
2018-01-22 12:32:15 +01:00
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
|
|
|
:server::request{[&]
|
|
|
|
{
|
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = room_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], uidbuf[768];
|
2018-01-26 21:20:02 +01:00
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
2018-01-22 12:32:15 +01:00
|
|
|
{
|
2018-01-26 21:20:02 +01:00
|
|
|
urlbuf, "/_matrix/federation/v1/make_join/%s/%s",
|
|
|
|
url::encode(room_id, ridbuf),
|
|
|
|
url::encode(user_id, uidbuf)
|
2018-01-22 12:32:15 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
|
|
|
opts.out.head = opts.request(buf);
|
|
|
|
|
2018-04-03 03:24:57 +02:00
|
|
|
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
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// v1/user.h
|
|
|
|
//
|
|
|
|
|
|
|
|
ircd::m::v1::user::devices::devices(const id::user &user_id,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
|
|
|
:server::request{[&]
|
|
|
|
{
|
|
|
|
if(!opts.remote)
|
|
|
|
opts.remote = user_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<"uri"_>(opts.request)))
|
|
|
|
{
|
|
|
|
thread_local char urlbuf[2048], uidbuf[768];
|
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
|
|
|
urlbuf, "/_matrix/federation/v1/user/devices/%s",
|
|
|
|
url::encode(user_id, uidbuf)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if(defined(json::get<"content"_>(opts.request)))
|
|
|
|
opts.out.content = json::get<"content"_>(opts.request);
|
|
|
|
|
|
|
|
if(!defined(json::get<"method"_>(opts.request)))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
|
|
|
|
|
|
|
opts.out.head = opts.request(buf);
|
|
|
|
|
2018-01-22 12:32:15 +01:00
|
|
|
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
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
2018-02-19 23:34:34 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2018-02-25 08:53:32 +01:00
|
|
|
//
|
|
|
|
// v1/query.h
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace ircd::m::v1
|
|
|
|
{
|
|
|
|
thread_local char query_arg_buf[1024];
|
2018-03-09 18:39:56 +01:00
|
|
|
thread_local char query_url_buf[1024];
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:40:47 +01:00
|
|
|
ircd::m::v1::query::client_keys::client_keys(const id::user &user_id,
|
|
|
|
const string_view &device_id,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
:client_keys
|
|
|
|
{
|
|
|
|
user_id, device_id, buf, opts{user_id.host()}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::v1::query::client_keys::client_keys(const id::user &user_id,
|
|
|
|
const string_view &device_id,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
|
|
|
:query{[&]() -> query
|
|
|
|
{
|
|
|
|
const json::value device_ids[]
|
|
|
|
{
|
|
|
|
{ device_id }
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::members body
|
|
|
|
{
|
|
|
|
{ "device_keys", json::members
|
|
|
|
{
|
|
|
|
{ string_view{user_id}, { device_ids, 1 } }
|
|
|
|
}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mutable_buffer out{buf};
|
|
|
|
const string_view content
|
|
|
|
{
|
|
|
|
stringify(out, body)
|
|
|
|
};
|
|
|
|
|
|
|
|
json::get<"content"_>(opts.request) = content;
|
|
|
|
return
|
|
|
|
{
|
|
|
|
"client_keys", string_view{}, out, std::move(opts)
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:39:56 +01:00
|
|
|
ircd::m::v1::query::user_devices::user_devices(const id::user &user_id,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
:user_devices
|
|
|
|
{
|
|
|
|
user_id, buf, opts{user_id.host()}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::m::v1::query::user_devices::user_devices(const id::user &user_id,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
|
|
|
:query
|
|
|
|
{
|
|
|
|
"user_devices",
|
|
|
|
fmt::sprintf
|
|
|
|
{
|
|
|
|
query_arg_buf, "user_id=%s", url::encode(user_id, query_url_buf)
|
|
|
|
},
|
|
|
|
buf,
|
|
|
|
std::move(opts)
|
|
|
|
}
|
|
|
|
{
|
2018-02-25 08:53:32 +01:00
|
|
|
}
|
|
|
|
|
2018-02-25 11:05:43 +01:00
|
|
|
ircd::m::v1::query::directory::directory(const id::room_alias &room_alias,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
:directory
|
|
|
|
{
|
|
|
|
room_alias, buf, opts{room_alias.host()}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-25 08:53:32 +01:00
|
|
|
ircd::m::v1::query::directory::directory(const id::room_alias &room_alias,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
|
|
|
:query
|
|
|
|
{
|
|
|
|
"directory",
|
|
|
|
fmt::sprintf
|
|
|
|
{
|
2018-03-09 19:11:48 +01:00
|
|
|
query_arg_buf, "room_alias=%s", url::encode(room_alias, query_url_buf)
|
2018-02-25 08:53:32 +01:00
|
|
|
},
|
|
|
|
buf,
|
2018-02-27 06:43:02 +01:00
|
|
|
std::move(opts)
|
2018-02-25 08:53:32 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-25 11:05:43 +01:00
|
|
|
ircd::m::v1::query::profile::profile(const id::user &user_id,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
:profile
|
|
|
|
{
|
|
|
|
user_id, buf, opts{user_id.host()}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-25 08:53:32 +01:00
|
|
|
ircd::m::v1::query::profile::profile(const id::user &user_id,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
|
|
|
:query
|
|
|
|
{
|
|
|
|
"profile",
|
|
|
|
fmt::sprintf
|
|
|
|
{
|
2018-03-09 19:11:48 +01:00
|
|
|
query_arg_buf, "user_id=%s", url::encode(user_id, query_url_buf)
|
2018-02-25 08:53:32 +01:00
|
|
|
},
|
|
|
|
buf,
|
2018-02-27 06:43:02 +01:00
|
|
|
std::move(opts)
|
2018-02-25 08:53:32 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-25 11:05:43 +01:00
|
|
|
ircd::m::v1::query::profile::profile(const id::user &user_id,
|
|
|
|
const string_view &field,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
:profile
|
|
|
|
{
|
|
|
|
user_id, field, buf, opts{user_id.host()}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-25 09:28:55 +01:00
|
|
|
ircd::m::v1::query::profile::profile(const id::user &user_id,
|
|
|
|
const string_view &field,
|
|
|
|
const mutable_buffer &buf,
|
|
|
|
opts opts)
|
|
|
|
:query
|
|
|
|
{
|
|
|
|
"profile",
|
|
|
|
fmt::sprintf
|
|
|
|
{
|
|
|
|
query_arg_buf, "user_id=%s%s%s",
|
2018-03-09 19:11:48 +01:00
|
|
|
url::encode(string_view{user_id}, query_url_buf),
|
2018-02-25 09:28:55 +01:00
|
|
|
!empty(field)? "&field=" : "",
|
|
|
|
field
|
|
|
|
},
|
|
|
|
buf,
|
2018-02-27 06:43:02 +01:00
|
|
|
std::move(opts)
|
2018-02-25 09:28:55 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-25 08:53:32 +01:00
|
|
|
ircd::m::v1::query::query(const string_view &type,
|
|
|
|
const string_view &args,
|
|
|
|
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)))
|
|
|
|
{
|
|
|
|
thread_local char urlbuf[2048];
|
|
|
|
json::get<"uri"_>(opts.request) = fmt::sprintf
|
|
|
|
{
|
2018-03-09 18:40:47 +01:00
|
|
|
urlbuf, "/_matrix/federation/v1/query/%s%s%s",
|
2018-02-25 08:53:32 +01:00
|
|
|
type,
|
2018-03-09 18:40:47 +01:00
|
|
|
args? "?"_sv : ""_sv,
|
2018-02-25 08:53:32 +01:00
|
|
|
args
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:40:47 +01:00
|
|
|
if(defined(json::get<"content"_>(opts.request)))
|
|
|
|
opts.out.content = json::get<"content"_>(opts.request);
|
|
|
|
|
|
|
|
if(!defined(json::get<"method"_>(opts.request)))
|
|
|
|
json::get<"method"_>(opts.request) = "GET";
|
|
|
|
|
2018-02-25 08:53:32 +01:00
|
|
|
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
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2018-02-19 23:34:34 +01:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
};
|
|
|
|
}()}
|
|
|
|
{
|
|
|
|
}
|