mirror of
https://github.com/matrix-construct/construct
synced 2024-06-02 18:18:56 +02:00
modules: Add preliminary federation and media directories.
This commit is contained in:
parent
6a024e9e16
commit
f89d6f651c
|
@ -90,6 +90,24 @@ key_module_LTLIBRARIES = \
|
|||
key/key_query.la \
|
||||
###
|
||||
|
||||
# This puts the source in federation/ but the installed
|
||||
# library is federation_X.so in the main modules dir.
|
||||
federation_moduledir = @moduledir@
|
||||
federation_federation_send_la_SOURCES = federation/send.cc
|
||||
federation_federation_event_la_SOURCES = federation/event.cc
|
||||
federation_module_LTLIBRARIES = \
|
||||
federation/federation_send.la \
|
||||
federation/federation_event.la \
|
||||
###
|
||||
|
||||
# This puts the source in media/ but the installed
|
||||
# library is media_X.so in the main modules dir.
|
||||
media_moduledir = @moduledir@
|
||||
media_media_download_la_SOURCES = media/download.cc
|
||||
media_module_LTLIBRARIES = \
|
||||
media/media_download.la \
|
||||
###
|
||||
|
||||
if JS
|
||||
server_moduledir = @moduledir@
|
||||
server_server_console_la_SOURCES = server/console.cc
|
||||
|
|
74
modules/federation/event.cc
Normal file
74
modules/federation/event.cc
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Charybdis Development Team
|
||||
* Copyright (C) 2017 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using namespace ircd;
|
||||
|
||||
mapi::header IRCD_MODULE
|
||||
{
|
||||
"federation event"
|
||||
};
|
||||
|
||||
struct send
|
||||
:resource
|
||||
{
|
||||
using resource::resource;
|
||||
}
|
||||
event_resource
|
||||
{
|
||||
"/_matrix/federation/v1/event/", resource::opts
|
||||
{
|
||||
resource::DIRECTORY,
|
||||
"federation event"
|
||||
}
|
||||
};
|
||||
|
||||
resource::response
|
||||
handle_get(client &client,
|
||||
const resource::request &request)
|
||||
{
|
||||
m::event::id::buf event_id
|
||||
{
|
||||
urldecode(request.parv[0], event_id)
|
||||
};
|
||||
|
||||
const unique_buffer<mutable_buffer> buffer
|
||||
{
|
||||
64_KiB
|
||||
};
|
||||
|
||||
const json::object event
|
||||
{
|
||||
m::get(event_id, buffer)
|
||||
};
|
||||
|
||||
return resource::response
|
||||
{
|
||||
client, event
|
||||
};
|
||||
}
|
||||
|
||||
resource::method method_get
|
||||
{
|
||||
event_resource, "GET", handle_get,
|
||||
{
|
||||
method_get.VERIFY_ORIGIN
|
||||
}
|
||||
};
|
158
modules/federation/send.cc
Normal file
158
modules/federation/send.cc
Normal file
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Charybdis Development Team
|
||||
* Copyright (C) 2017 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using namespace ircd;
|
||||
|
||||
mapi::header IRCD_MODULE
|
||||
{
|
||||
"federation send"
|
||||
};
|
||||
|
||||
struct send
|
||||
:resource
|
||||
{
|
||||
using resource::resource;
|
||||
}
|
||||
send_resource
|
||||
{
|
||||
"/_matrix/federation/v1/send/", resource::opts
|
||||
{
|
||||
resource::DIRECTORY,
|
||||
"federation send"
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
handle_edu(client &client,
|
||||
const resource::request::object<m::txn> &request,
|
||||
const string_view &txn_id,
|
||||
const json::object &edu)
|
||||
{
|
||||
//std::cout << edu << std::endl;
|
||||
log::debug("%s | %s | %s | %s",
|
||||
at<"origin"_>(request),
|
||||
txn_id,
|
||||
edu.at("edu_type"),
|
||||
edu.get("sender", string_view{"*"}));
|
||||
}
|
||||
|
||||
void
|
||||
handle_pdu(client &client,
|
||||
const resource::request::object<m::txn> &request,
|
||||
const string_view &txn_id,
|
||||
const m::event &event)
|
||||
try
|
||||
{
|
||||
//std::cout << event << std::endl;
|
||||
log::debug("%s | %s | %s | %s %s %s",
|
||||
at<"origin"_>(request),
|
||||
txn_id,
|
||||
at<"type"_>(event),
|
||||
at<"sender"_>(event),
|
||||
at<"room_id"_>(event),
|
||||
at<"event_id"_>(event));
|
||||
|
||||
m::vm::eval(event);
|
||||
}
|
||||
catch(const ed25519::bad_sig &e)
|
||||
{
|
||||
throw m::BAD_SIGNATURE
|
||||
{
|
||||
":%s %s %s %s",
|
||||
at<"origin"_>(request),
|
||||
at<"room_id"_>(event),
|
||||
at<"event_id"_>(event),
|
||||
e.what()
|
||||
};
|
||||
}
|
||||
|
||||
void
|
||||
handle_pdu_failure(client &client,
|
||||
const resource::request::object<m::txn> &request,
|
||||
const string_view &txn_id,
|
||||
const json::object &pdu_failure)
|
||||
{
|
||||
log::debug("%s | %s | (pdu_failure) %s",
|
||||
at<"origin"_>(request),
|
||||
txn_id,
|
||||
pdu_failure.get("sender", string_view{"*"}),
|
||||
string_view{pdu_failure});
|
||||
}
|
||||
|
||||
resource::response
|
||||
handle_put(client &client,
|
||||
const resource::request::object<m::txn> &request)
|
||||
{
|
||||
const auto txn_id
|
||||
{
|
||||
request.parv[0]
|
||||
};
|
||||
|
||||
const string_view &origin
|
||||
{
|
||||
json::at<"origin"_>(request)
|
||||
};
|
||||
|
||||
const json::array &edus
|
||||
{
|
||||
json::get<"edus"_>(request)
|
||||
};
|
||||
|
||||
const json::array &pdus
|
||||
{
|
||||
json::get<"pdus"_>(request)
|
||||
};
|
||||
|
||||
const json::array &pdu_failures
|
||||
{
|
||||
json::get<"pdu_failures"_>(request)
|
||||
};
|
||||
|
||||
for(const auto &pdu_failure : pdu_failures)
|
||||
handle_pdu_failure(client, request, txn_id, pdu_failure);
|
||||
|
||||
for(const auto &edu : edus)
|
||||
handle_edu(client, request, txn_id, edu);
|
||||
|
||||
for(const auto &pdu : pdus)
|
||||
handle_pdu(client, request, txn_id, m::event{pdu});
|
||||
|
||||
log::debug("%s | %s | %s --> edus:%zu pdus:%zu errors:%zu",
|
||||
origin,
|
||||
txn_id,
|
||||
string(remote(client)),
|
||||
edus.count(),
|
||||
pdus.count(),
|
||||
pdu_failures.count());
|
||||
|
||||
return resource::response
|
||||
{
|
||||
client, json::members{}
|
||||
};
|
||||
}
|
||||
|
||||
resource::method method_put
|
||||
{
|
||||
send_resource, "PUT", handle_put,
|
||||
{
|
||||
method_put.VERIFY_ORIGIN
|
||||
}
|
||||
};
|
88
modules/media/download.cc
Normal file
88
modules/media/download.cc
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (C) 2017 Charybdis Development Team
|
||||
* Copyright (C) 2017 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using namespace ircd;
|
||||
|
||||
mapi::header IRCD_MODULE
|
||||
{
|
||||
"media download"
|
||||
};
|
||||
|
||||
struct send
|
||||
:resource
|
||||
{
|
||||
using resource::resource;
|
||||
}
|
||||
download_resource
|
||||
{
|
||||
"/_matrix/media/r0/download/", resource::opts
|
||||
{
|
||||
resource::DIRECTORY,
|
||||
"media download"
|
||||
}
|
||||
};
|
||||
|
||||
resource::response
|
||||
handle_get(client &client,
|
||||
const resource::request &request)
|
||||
{
|
||||
if(request.parv.size() < 2)
|
||||
throw http::error
|
||||
{
|
||||
http::MULTIPLE_CHOICES, "/ download / domain / file"
|
||||
};
|
||||
|
||||
const auto &domain
|
||||
{
|
||||
request.parv[0]
|
||||
};
|
||||
|
||||
const auto &file
|
||||
{
|
||||
request.parv[1]
|
||||
};
|
||||
|
||||
const fmt::snstringf path
|
||||
{
|
||||
1024,
|
||||
"/home/jason/.synapse/media_store/local_content/%s/%s/%s",
|
||||
file.substr(0, 2),
|
||||
file.substr(2, 2),
|
||||
file.substr(4, file.size() - 4)
|
||||
};
|
||||
|
||||
const auto data
|
||||
{
|
||||
fs::read(path)
|
||||
};
|
||||
|
||||
return resource::response
|
||||
{
|
||||
client, string_view{data}, "image/jpg"
|
||||
};
|
||||
}
|
||||
|
||||
resource::method method_put
|
||||
{
|
||||
download_resource, "GET", handle_get,
|
||||
{
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue