From 0149610bb248b92501a2cd9264d88b16adf090f5 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 23 Aug 2017 15:51:34 -0600 Subject: [PATCH] ircd: Various matrix library / modules / database development. --- include/ircd/m.h | 2 + include/ircd/m/error.h | 14 +- include/ircd/m/event.h | 52 +++---- include/ircd/m/request.h | 14 +- include/ircd/m/session.h | 2 +- ircd/matrix.cc | 12 +- modules/client/events.cc | 225 +++++++++++++++++++++++++++++ modules/client/events.h | 30 ++++ modules/client/login.cc | 33 ++++- modules/client/publicrooms.cc | 45 +----- modules/client/register.cc | 6 +- modules/client/room.cc | 173 ---------------------- modules/client/rooms.cc | 76 ++++++++++ modules/client/{room.h => rooms.h} | 10 +- modules/matrix.cc | 79 +++++++++- modules/root.cc | 5 +- 16 files changed, 483 insertions(+), 295 deletions(-) create mode 100644 modules/client/events.cc create mode 100644 modules/client/events.h delete mode 100644 modules/client/room.cc create mode 100644 modules/client/rooms.cc rename modules/client/{room.h => rooms.h} (88%) diff --git a/include/ircd/m.h b/include/ircd/m.h index 36aec8d4f..feb50643a 100644 --- a/include/ircd/m.h +++ b/include/ircd/m.h @@ -25,6 +25,8 @@ #pragma once #define HAVE_IRCD_M_H +#include "json/parse.h" + namespace ircd { namespace m { diff --git a/include/ircd/m/error.h b/include/ircd/m/error.h index 45fe0dcd6..4f8761699 100644 --- a/include/ircd/m/error.h +++ b/include/ircd/m/error.h @@ -33,8 +33,8 @@ struct error { template error(const http::code &, const string_view &errcode, const char *const &fmt, args&&...); template error(const string_view &errcode, const char *const &fmt, args&&...); - error(const http::code &, const json::doc &doc = {}); - error(const http::code &, const json::obj &obj); + error(const http::code &, const json::object &object = {}); + error(const http::code &, const json::index &idx); }; } // namespace m @@ -42,14 +42,14 @@ struct error inline ircd::m::error::error(const http::code &c, - const json::obj &obj) -:http::error{c, std::string{obj}} + const json::index &index) +:http::error{c, std::string{index}} {} inline ircd::m::error::error(const http::code &c, - const json::doc &doc) -:http::error{c, std::string{doc}} + const json::object &object) +:http::error{c, std::string{object}} {} template @@ -75,7 +75,7 @@ ircd::m::error::error(const http::code &status, fmt::snprintf{estr, sizeof(estr), fmt, std::forward(a)...} }; - return json::obj + return json::index { { "errcode", errcode }, { "error", string_view(estr, estr_len) } diff --git a/include/ircd/m/event.h b/include/ircd/m/event.h index 3056a63e5..7eb2c5dea 100644 --- a/include/ircd/m/event.h +++ b/include/ircd/m/event.h @@ -22,16 +22,32 @@ * */ -#include - #pragma once #define HAVE_IRCD_M_EVENT_H +/////////////////////////////////////////////////////////////////////////////// +// Protocol notes +// +// 10.4 +// The total size of any event MUST NOT exceed 65 KB. +// +// There are additional restrictions on sizes per key: +// sender MUST NOT exceed 255 bytes (including domain). +// room_id MUST NOT exceed 255 bytes. +// state_key MUST NOT exceed 255 bytes. +// type MUST NOT exceed 255 bytes. +// event_id MUST NOT exceed 255 bytes. +// +// Some event types have additional size restrictions which are specified in +// the description of the event. Additional keys have no limit other than that +// implied by the total 65 KB limit on events. +// + namespace ircd { namespace m { struct event -:json::object +:json::parse < string_view, time_t, @@ -53,35 +69,7 @@ struct event template event(A&&... a) - :object{std::make_tuple(std::forward(a)...)} - {} -}; - -struct sync -:json::object -< - string_view, - string_view, - string_view, - string_view -> -{ - IRCD_MEMBERS - ( - "account_data", - "next_batch", - "rooms", - "presence", - ) - - sync(const json::doc &doc) - { - - } - - template - sync(A&&... a) - :object{std::make_tuple(std::forward(a)...)} + :parse{*this, std::forward(a)...} {} }; diff --git a/include/ircd/m/request.h b/include/ircd/m/request.h index c071c39a8..9caf2148b 100644 --- a/include/ircd/m/request.h +++ b/include/ircd/m/request.h @@ -29,7 +29,7 @@ namespace ircd { namespace m { struct request -:json::obj +:json::index { string_view method; string_view path; @@ -39,12 +39,12 @@ struct request request(const string_view &method, const string_view &path, const string_view &query = {}, - std::initializer_list body = {}); + std::initializer_list body = {}); request(const string_view &method, const string_view &path, const string_view &query, - const json::doc &content); + const json::object &content); }; } // namespace m @@ -54,8 +54,8 @@ inline ircd::m::request::request(const string_view &method, const string_view &path, const string_view &query, - std::initializer_list body) -:json::obj{std::move(body)} + std::initializer_list body) +:json::index{std::move(body)} ,method{method} ,path{path} ,query{query} @@ -66,8 +66,8 @@ inline ircd::m::request::request(const string_view &method, const string_view &path, const string_view &query, - const json::doc &content) -:json::obj{content} + const json::object &content) +:json::index{content} ,method{method} ,path{path} ,query{query} diff --git a/include/ircd/m/session.h b/include/ircd/m/session.h index 5a98a648d..e0c4b0779 100644 --- a/include/ircd/m/session.h +++ b/include/ircd/m/session.h @@ -35,7 +35,7 @@ struct session std::deque tape; std::multimap resource; - json::doc operator()(parse::buffer &pb, request &); + json::object operator()(parse::buffer &pb, request &); session(const host_port &); }; diff --git a/ircd/matrix.cc b/ircd/matrix.cc index 750dedbb4..3f3f7e750 100644 --- a/ircd/matrix.cc +++ b/ircd/matrix.cc @@ -26,7 +26,7 @@ ircd::m::session::session(const host_port &host_port) { } -ircd::json::doc +ircd::json::object ircd::m::session::operator()(parse::buffer &pb, request &r) { @@ -49,20 +49,20 @@ ircd::m::session::operator()(parse::buffer &pb, }; http::code status; - json::doc doc; + json::object object; http::response { pc, nullptr, - [&pc, &status, &doc](const http::response::head &head) + [&pc, &status, &object](const http::response::head &head) { status = http::status(head.status); - doc = http::response::content{pc, head}; + object = http::response::content{pc, head}; } }; if(status < 200 || status >= 300) - throw m::error(status, doc); + throw m::error(status, object); - return doc; + return object; } diff --git a/modules/client/events.cc b/modules/client/events.cc new file mode 100644 index 000000000..5ed61fba0 --- /dev/null +++ b/modules/client/events.cc @@ -0,0 +1,225 @@ +/* + * Copyright (C) 2017 Charybdis Development Team + * Copyright (C) 2017 Jason Volk + * + * 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; + +const database::descriptor events_type_descriptor +{ + // name + "type", + + // explanation + R"(### protocol note: + + 10.1 + The type of event. This SHOULD be namespaced similar to Java package naming conventions + e.g. 'com.example.subdomain.event.type'. + + 10.4 + MUST NOT exceed 255 bytes. + + ### developer note: + key is event_id + )", + + // typing (key, value) + { + typeid(string_view), typeid(string_view) + } +}; + +const database::descriptor events_content_descriptor +{ + // name + "content", + + // explanation + R"(### protocol note: + + 10.1 + The fields in this object will vary depending on the type of event. When interacting + with the REST API, this is the HTTP body. + + ### developer note: + Since events must not exceed 65 KB the maximum size for the content is the remaining + space after all the other fields for the event are rendered. + + key is event_id + )", + + // typing (key, value) + { + typeid(string_view), typeid(string_view) + } +}; + +const database::descriptor events_room_id_descriptor +{ + // name + "room_id", + + // explanation + R"(### protocol note: + + 10.2 (apropos room events) + Required. The ID of the room associated with this event. + + 10.4 + MUST NOT exceed 255 bytes. + + ### developer note: + key is event_id + )", + + // typing (key, value) + { + typeid(string_view), typeid(string_view) + } +}; + +const database::descriptor events_sender_descriptor +{ + // name + "sender", + + // explanation + R"(### protocol note: + + 10.2 (apropos room events) + Required. Contains the fully-qualified ID of the user who sent this event. + + 10.4 + MUST NOT exceed 255 bytes. + + ### developer note: + key is event_id + )", + + // typing (key, value) + { + typeid(string_view), typeid(string_view) + } +}; + +const database::descriptor events_state_key_descriptor +{ + // name + "state_key", + + // explanation + R"(### protocol note: + + 10.3 (apropos room state events) + A unique key which defines the overwriting semantics for this piece of room state. + This value is often a zero-length string. The presence of this key makes this event a + State Event. The key MUST NOT start with '_'. + + 10.4 + MUST NOT exceed 255 bytes. + + ### developer note: + key is event_id + )", + + // typing (key, value) + { + typeid(string_view), typeid(string_view) + } +}; + +const database::descriptor events_origin_descriptor +{ + // name + "origin", + + // explanation + R"(### protocol note: + + FEDERATION 4.1 + DNS name of homeserver that created this PDU + + ### developer note: + key is event_id + )", + + // typing (key, value) + { + typeid(string_view), typeid(string_view) + } +}; + +const database::descriptor events_origin_server_ts_descriptor +{ + // name + "origin_server_ts", + + // explanation + R"(### protocol note: + + FEDERATION 4.1 + Timestamp in milliseconds on origin homeserver when this PDU was created. + + ### developer note: + key is event_id + value is a machine integer (binary) + + TODO: consider unsigned rather than time_t because of millisecond precision + + )", + + // typing (key, value) + { + typeid(string_view), typeid(time_t) + } +}; + +const database::description events_description +{ + { "default" }, + events_type_descriptor, + events_content_descriptor, + events_room_id_descriptor, + events_sender_descriptor, + events_state_key_descriptor, + events_origin_descriptor, + events_origin_server_ts_descriptor, +}; + +std::shared_ptr events_database +{ + std::make_shared("events"s, ""s, events_description) +}; + +extern database *const events +{ + events_database.get() +}; + +resource events_resource +{ + "_matrix/client/r0/events", + "Events (6.2.3) (10.x)" +}; + +mapi::header IRCD_MODULE +{ + "registers the resource 'client/events' and hosts the events database" +}; diff --git a/modules/client/events.h b/modules/client/events.h new file mode 100644 index 000000000..14352f322 --- /dev/null +++ b/modules/client/events.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2017 Charybdis Development Team + * Copyright (C) 2017 Jason Volk + * + * 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. + */ + +ircd::import_shared events_database +{ + "client_events", "events_database" +}; + +extern ircd::database *const events +{ + events_database.get() +}; diff --git a/modules/client/login.cc b/modules/client/login.cc index 40c01c117..d0c274e81 100644 --- a/modules/client/login.cc +++ b/modules/client/login.cc @@ -40,7 +40,7 @@ using object = db::object; template using value = db::value; resource::response -login_password(client &client, const resource::request &request) +post_login_password(client &client, const resource::request &request) { const auto user { @@ -98,7 +98,7 @@ login_password(client &client, const resource::request &request) } resource::response -login_token(client &client, const resource::request &request) +post_login_token(client &client, const resource::request &request) { const auto token { @@ -128,7 +128,7 @@ login_token(client &client, const resource::request &request) } resource::response -login(client &client, const resource::request &request) +post_login(client &client, const resource::request &request) { const auto type { @@ -137,9 +137,9 @@ login(client &client, const resource::request &request) }; if(type == "m.login.password") - return login_password(client, request); + return post_login_password(client, request); else if(type == "m.login.token") - return login_token(client, request); + return post_login_token(client, request); else throw m::error { @@ -147,9 +147,28 @@ login(client &client, const resource::request &request) }; } -resource::method post +resource::method method_post { - login_resource, "POST", login + login_resource, "POST", post_login +}; + +resource::response +get_login(client &client, const resource::request &request) +{ + static const json::object flows + { + R"({"flows":[{"type":"m.login.password"}]})" + }; + + return resource::response + { + client, flows + }; +} + +resource::method method_get +{ + login_resource, "GET", get_login }; mapi::header IRCD_MODULE diff --git a/modules/client/publicrooms.cc b/modules/client/publicrooms.cc index 142b4d540..f6b9bbf68 100644 --- a/modules/client/publicrooms.cc +++ b/modules/client/publicrooms.cc @@ -19,7 +19,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "room.h" +#include "rooms.h" using namespace ircd; @@ -33,49 +33,6 @@ resource publicrooms_resource resource::response get_publicrooms(client &client, const resource::request &request) { - json::doc test - { - R"({"content":"hello","origin_server_ts":12345,"sender":"me"})" - }; - - m::event ev - { - "some content", 0, "some sender", "some type", "some unsigned", "statie" - }; - - json::for_each(ev, [] - (const auto &key, const auto &val) - { - std::cout << key << " => " << val << std::endl; - }); - - std::cout << std::endl; - json::rfor_each(ev, [] - (const string_view &key, const auto &val) - { - std::cout << key << " => " << val << std::endl; - }); - - std::cout << std::endl; - json::until(ev, [] - (const string_view &key, const auto &val) - { - std::cout << key << " => " << val << std::endl; - return true; - }); - - std::cout << std::endl; - json::runtil(ev, [] - (const string_view &key, const auto &val) - { - std::cout << key << " => " << val << std::endl; - return true; - }); - - std::cout << std::endl; - std::cout << index(ev, "origin_server_ts") << std::endl; - std::cout << std::endl; - return resource::response { client, json::index diff --git a/modules/client/register.cc b/modules/client/register.cc index 2e9320341..8e9a8c312 100644 --- a/modules/client/register.cc +++ b/modules/client/register.cc @@ -89,10 +89,10 @@ handle_post(client &client, "M_INVALID_USERNAME", "The desired user ID is not a valid user name." }; - const auto pass + const auto password { // "Required. The desired password for the account." - request.at("pass") + request.at("password") }; const auto bind_email @@ -139,7 +139,7 @@ handle_post(client &client, // Batch transaction to database db::write ({ - { db::SET, password_text, pass }, + { db::SET, password_text, password }, { db::SET, access_token_text, access_token }, }); diff --git a/modules/client/room.cc b/modules/client/room.cc deleted file mode 100644 index 390ef8d5f..000000000 --- a/modules/client/room.cc +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (C) 2017 Charybdis Development Team - * Copyright (C) 2017 Jason Volk - * - * 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; - -const database::descriptor room_created_descriptor -{ - "created", - - R"(### developer note: - A UNIX epoch timestamp sampled when the room was created. - )", - { - // readable key // binary value - typeid(string_view), typeid(time_t) - } -}; - -const database::descriptor room_creator_descriptor -{ - "creator", - - R"(### protocol note: - The user_id of the room creator. This is set by the homeserver. - )" -}; - -const database::descriptor room_topic_descriptor -{ - "topic", - - R"(### protocol note: - If this is included, an m.room.topic event will be sent into the room to indicate the - topic for the room. See Room Events for more information on m.room.topic. - )" -}; - -const database::descriptor room_visibility_descriptor -{ - "visibility", - - R"(### protocol note: - Rooms default to private visibility if this key is not included. - - * "public" visibility indicates that the room will be shown in the published room list. - - * "private" visibility will hide the room from the published room list. - - One of: ["public", "private"] - )" -}; - -const database::descriptor room_join_rules_descriptor -{ - "join_rules", - - R"(### protocol note: - A room may be public meaning anyone can join the room without any prior action. - Alternatively, it can be invite meaning that a user who wishes to join the room must first - receive an invite to the room from someone already inside of the room. Currently, knock and private - are reserved keywords which are not implemented. - - The type of rules used for users wishing to join this room. - One of: ["public", "knock", "invite", "private"] - )" -}; - -const database::descriptor room_history_visibility_descriptor -{ - "history_visibility", - - R"(### protocol note: - - * "world_readable" All events while this is the m.room.history_visibility value may be shared - by any participating homeserver with anyone, regardless of whether they have ever joined the room. - - * "shared" Previous events are always accessible to newly joined members. All events in the room - are accessible, even those sent when the member was not a part of the room. - - * "invited" Events are accessible to newly joined members from the point they were invited onwards. - Events stop being accessible when the member's state changes to something other than invite or join. - - * "joined" Events are accessible to newly joined members from the point they joined the room onwards. - Events stop being accessible when the member's state changes to something other than join. - )" -}; - -const database::descriptor room_alias_descriptor -{ - "alias", - - R"(### protocol note: - The desired room alias local part. If this is included, a room alias will be created and mapped to - the newly created room. The alias will belong on the same homeserver which created the room. - For example, if this was set to "foo" and sent to the homeserver "example.com" the complete - room alias would be #foo:example.com. - - ### developer note: - The alias column on the room's primary row has a comma separated list of aliases. - For each of those aliases this column has a key indexed for it; the value for that key is - the primary room's name. This is a cross-reference that must be kept in sync. - )" -}; - -const database::descriptor room_federate_descriptor -{ - "federate", - - R"(### protocol note: - Whether users on other servers can join this room. Defaults to true if key does not exist. - )", - { - // readable key // binary value - typeid(string_view), typeid(bool) - } -}; - -const database::description room_description -{ - { "default" }, - room_created_descriptor, - room_creator_descriptor, - room_topic_descriptor, - room_visibility_descriptor, - room_join_rules_descriptor, - room_history_visibility_descriptor, - room_alias_descriptor, - room_federate_descriptor, -}; - -std::shared_ptr room_database -{ - std::make_shared("room"s, ""s, room_description) -}; - -extern database *const room -{ - room_database.get() -}; - -struct room -:resource -{ - using resource::resource; -} -room_resource -{ - "_matrix/client/r0/room", - "Rooms (7.0)" -}; - -mapi::header IRCD_MODULE -{ - "registers the resource 'client/room' to manage Matrix rooms" -}; diff --git a/modules/client/rooms.cc b/modules/client/rooms.cc new file mode 100644 index 000000000..eec8870c7 --- /dev/null +++ b/modules/client/rooms.cc @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2017 Charybdis Development Team + * Copyright (C) 2017 Jason Volk + * + * 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; + +const database::descriptor rooms_head_descriptor +{ + // name + "head", + + // notes + R"( + ### developer note: + + The latest event for a room. + + key is room_id + value is event_id + + )", + + // typing for key and value + { + typeid(string_view), typeid(string_view) + } +}; + +const database::description rooms_description +{ + { "default" }, + rooms_head_descriptor, +}; + +std::shared_ptr rooms_database +{ + std::make_shared("room"s, ""s, rooms_description) +}; + +extern database *const room +{ + rooms_database.get() +}; + +struct room +:resource +{ + using resource::resource; +} +rooms_resource +{ + "_matrix/client/r0/rooms/", + "Rooms (7.0)" +}; + +mapi::header IRCD_MODULE +{ + "registers the resource 'client/rooms' and hosts the rooms database" +}; diff --git a/modules/client/room.h b/modules/client/rooms.h similarity index 88% rename from modules/client/room.h rename to modules/client/rooms.h index ec7b8e0b4..84b807bf6 100644 --- a/modules/client/room.h +++ b/modules/client/rooms.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2017 Charybdis Development Team * Copyright (C) 2017 Jason Volk * @@ -19,12 +19,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ -ircd::import_shared room_database +ircd::import_shared rooms_database { - "client_room", "room_database" + "client_rooms", "rooms_database" }; -extern ircd::database *const room +extern ircd::database *const rooms { - room_database.get() + rooms_database.get() }; diff --git a/modules/matrix.cc b/modules/matrix.cc index b7f85a045..3cf5fded2 100644 --- a/modules/matrix.cc +++ b/modules/matrix.cc @@ -19,8 +19,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include - using namespace ircd; mapi::header IRCD_MODULE @@ -30,6 +28,8 @@ mapi::header IRCD_MODULE std::map modules; +void test(); + //TODO: XXX very temporary stuff around here // The path root (serves static assets for web etc); this pointer // exists for now to easily find and reload that specifically. @@ -37,34 +37,97 @@ module *root_module; const auto _init_([] { // These modules host databases and have to be loaded first. + modules.emplace("client_events.so"s, "client_events.so"s); modules.emplace("client_account.so"s, "client_account.so"s); - modules.emplace("client_room.so"s, "client_room.so"s); + modules.emplace("client_rooms.so"s, "client_rooms.so"s); for(const auto &name : mods::available()) if(name != "matrix.so") modules.emplace(name, name); root_module = &modules.at("root.so"s); + + test(); + return true; }()); listener matrices { - std::string { json::obj + std::string { json::index { { "name", "Chat Matrix" }, { "host", "0.0.0.0" }, { - "ssl_certificate_chain_file", "/home/jason/.synapse/zemos.net.crt" + "ssl_certificate_file", "/home/jason/newcert.pem" }, { - "ssl_tmp_dh_file", "/home/jason/.synapse/cdc.z.tls.dh" + "ssl_certificate_chain_file", "/home/jason/newcert.pem" }, { - "ssl_private_key_file_pem", "/home/jason/.synapse/cdc.z.tls.key" + "ssl_tmp_dh_file", "/home/jason/dh1024.pem" }, { - "port", 6667 + "ssl_private_key_file_pem", "/home/jason/privkey.pem" + }, + { + "port", 8448 } }} }; + +void test() +{ + json::object test + { + R"({"content":"hello","origin_server_ts":12345,"sender":"@foo:bar.com"})" + }; +/* + const m::event ev0 + { + "some content", 0, "some sender", "some type", "some unsigned", "statie" + }; +*/ + const m::event ev + { + test + }; + + std::cout << "size: " << sizeof(ev) << std::endl; + + json::for_each(ev, [] + (auto&& key, auto&& val) + { + std::cout << key << " => " << val << std::endl; + }); + + std::cout << "----" << std::endl; + + json::rfor_each(ev, [] + (const string_view &key, auto&& val) + { + std::cout << key << " => " << val << std::endl; + }); + + std::cout << "----" << std::endl; + + json::until(ev, [] + (const string_view &key, auto&& val) + { + std::cout << key << " => " << val << std::endl; + return true; + }); + + std::cout << "----" << std::endl; + + json::runtil(ev, [] + (const string_view &key, auto&& val) + { + std::cout << key << " => " << val << std::endl; + return true; + }); + + std::cout << std::endl; + std::cout << json::indexof(ev, "origin_server_ts") << std::endl; + std::cout << std::endl; +} diff --git a/modules/root.cc b/modules/root.cc index 76d45e1ca..5fde56817 100644 --- a/modules/root.cc +++ b/modules/root.cc @@ -37,9 +37,10 @@ __attribute__((constructor)) void init_0() { - for(const auto &file : fs::ls("/home/jason/charybdis/charybdis/modules/static")) + // TODO: XXX + for(const auto &file : fs::ls_recursive("/home/jason/charybdis/charybdis/modules/static")) { - const auto name(token_last(file, "/")); + const auto name(tokens_after(file, "/", 5)); files.emplace(std::string(name), file); } }