0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-30 04:38:52 +02:00

ircd:Ⓜ️ Reorg location of database descriptions.

This commit is contained in:
Jason Volk 2017-08-18 12:19:13 -06:00
parent 88201f4e32
commit fa41c1db5f
17 changed files with 396 additions and 327 deletions

View file

@ -35,10 +35,22 @@ namespace m {
#include "m/error.h" #include "m/error.h"
#include "m/id.h" #include "m/id.h"
#include "m/db.h"
#include "m/event.h" #include "m/event.h"
#include "m/request.h" #include "m/request.h"
#include "m/accounts.h"
#include "m/session.h" #include "m/session.h"
namespace ircd { namespace ircd {
namespace m {
struct init
{
db::init db;
init();
~init() noexcept;
};
} // namespace m
} // namespace ircd } // namespace ircd

View file

@ -1,6 +1,8 @@
/* /*
* Copyright (C) 2017 Charybdis Development Team * charybdis: 21st Century IRC++d
* Copyright (C) 2017 Jason Volk <jason@zemos.net> *
* Copyright (C) 2016 Charybdis Development Team
* Copyright (C) 2016 Jason Volk <jason@zemos.net>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -17,14 +19,14 @@
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*
*/ */
ircd::import_shared<ircd::database> rooms_database #pragma once
{ #define HAVE_IRCD_M_ACCOUNTS_H
"client_rooms", "rooms_database"
};
extern ircd::database *const rooms namespace ircd {
{ namespace m {
rooms_database.get()
}; } // namespace m
} // namespace ircd

View file

@ -1,6 +1,8 @@
/* /*
* Copyright (C) 2017 Charybdis Development Team * charybdis: 21st Century IRC++d
* Copyright (C) 2017 Jason Volk <jason@zemos.net> *
* Copyright (C) 2016 Charybdis Development Team
* Copyright (C) 2016 Jason Volk <jason@zemos.net>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -17,14 +19,26 @@
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*
*/ */
ircd::import_shared<ircd::database> events_database #pragma once
#define HAVE_IRCD_M_DB_H
namespace ircd {
namespace m {
namespace db {
extern database *events;
extern database *accounts;
extern database *rooms;
struct init
{ {
"client_events", "events_database" init();
~init() noexcept;
}; };
extern ircd::database *const events } // namespace db
{ } // namespace m
events_database.get() } // namespace ircd
};

View file

@ -33,6 +33,18 @@ module_LTLIBRARIES = \
root.la \ root.la \
### ###
# This puts the source in db/ but the installed
# library is client_X.so in the main modules dir.
db_moduledir = @moduledir@
db_db_events_la_SOURCES = db/events.cc
db_db_accounts_la_SOURCES = db/accounts.cc
db_db_rooms_la_SOURCES = db/rooms.cc
db_module_LTLIBRARIES = \
db/db_events.la \
db/db_accounts.la \
db/db_rooms.la \
###
# This puts the source in client/ but the installed # This puts the source in client/ but the installed
# library is client_X.so in the main modules dir. # library is client_X.so in the main modules dir.
client_moduledir = @moduledir@ client_moduledir = @moduledir@

View file

@ -21,49 +21,6 @@
using namespace ircd; using namespace ircd;
const database::descriptor token_descriptor
{
"token",
"An index of access_token to user_id",
{
// readable key // readable value
typeid(string_view), typeid(string_view)
}
};
const database::descriptor account_registered_descriptor
{
"registered",
"A UNIX epoch timestamp sampled when the account was created.",
{
// readable key // binary value
typeid(string_view), typeid(time_t)
}
};
const database::description account_description
{
{ "default" },
token_descriptor,
account_registered_descriptor,
{ "access_token" },
{ "access_token.text" },
{ "password" },
{ "password.text" },
{ "password.hash" },
{ "password.hash.sha256" },
};
std::shared_ptr<database> account_database
{
std::make_shared<database>("account"s, ""s, account_description)
};
extern database *const account
{
account_database.get()
};
struct account struct account
:resource :resource
{ {

View file

@ -21,16 +21,6 @@
using namespace ircd; using namespace ircd;
import<database *> room_database
{
"client_room", "room"
};
extern database *const room
{
room_database
};
resource createroom resource createroom
{ {
"_matrix/client/r0/createRoom", "_matrix/client/r0/createRoom",

View file

@ -21,204 +21,26 @@
using namespace ircd; 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<database> events_database
{
std::make_shared<database>("events"s, ""s, events_description)
};
extern database *const events
{
events_database.get()
};
resource events_resource resource events_resource
{ {
"_matrix/client/r0/events", "_matrix/client/r0/events",
"Events (6.2.3) (10.x)" "Events (6.2.3) (10.x)"
}; };
resource::response
get_events(client &client, const resource::request &request)
{
return resource::response
{
client, json::object {}
};
}
resource::method method_get
{
events_resource, "GET", get_events
};
mapi::header IRCD_MODULE mapi::header IRCD_MODULE
{ {
"registers the resource 'client/events' and hosts the events database" "registers the resource 'client/events' and hosts the events database"

View file

@ -19,8 +19,6 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "account.h"
using namespace ircd; using namespace ircd;
resource login_resource resource login_resource
@ -36,8 +34,8 @@ const auto home_server
"cdc.z" "cdc.z"
}; };
using object = db::object<account>; using object = db::object<m::db::accounts>;
template<class T = string_view> using value = db::value<T, account>; template<class T = string_view> using value = db::value<m::db::accounts, T>;
resource::response resource::response
post_login_password(client &client, const resource::request &request) post_login_password(client &client, const resource::request &request)

View file

@ -19,12 +19,10 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "account.h"
using namespace ircd; using namespace ircd;
using object = db::object<account>; using object = db::object<m::db::accounts>;
template<class T = string_view> using value = db::value<T, account>; template<class T = string_view> using value = db::value<m::db::accounts, T>;
resource logout_resource resource logout_resource
{ {

View file

@ -19,8 +19,6 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "rooms.h"
using namespace ircd; using namespace ircd;
resource publicrooms_resource resource publicrooms_resource

View file

@ -19,12 +19,10 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "account.h"
using namespace ircd; using namespace ircd;
using object = db::object<account>; using object = db::object<m::db::accounts>;
template<class T = string_view> using value = db::value<T, account>; template<class T = string_view> using value = db::value<m::db::accounts, T>;
const auto home_server const auto home_server
{ {

View file

@ -21,44 +21,6 @@
using namespace ircd; 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<database> rooms_database
{
std::make_shared<database>("room"s, ""s, rooms_description)
};
extern database *const room
{
rooms_database.get()
};
struct room struct room
:resource :resource
{ {
@ -72,5 +34,5 @@ rooms_resource
mapi::header IRCD_MODULE mapi::header IRCD_MODULE
{ {
"registers the resource 'client/rooms' and hosts the rooms database" "registers the resource 'client/rooms'"
}; };

View file

@ -19,12 +19,10 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "account.h"
using namespace ircd; using namespace ircd;
using object = db::object<account>; //using object = db::object<m::db::accounts>;
template<class T = string_view> using value = db::value<T, account>; //template<class T = string_view> using value = db::value<T, m::db::accounts>;
resource sync_resource resource sync_resource
{ {

View file

@ -19,8 +19,6 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "account.h"
using namespace ircd; using namespace ircd;
resource user_resource resource user_resource

66
modules/db/accounts.cc Normal file
View file

@ -0,0 +1,66 @@
/*
* 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;
const database::descriptor accounts_token_descriptor
{
"token",
"An index of access_token to user_id",
{
// readable key // readable value
typeid(string_view), typeid(string_view)
}
};
const database::descriptor accounts_registered_descriptor
{
"registered",
"A UNIX epoch timestamp sampled when the account was created.",
{
// readable key // binary value
typeid(string_view), typeid(time_t)
}
};
const database::description accounts_description
{
{ "default" },
accounts_token_descriptor,
accounts_registered_descriptor,
{ "access_token" },
{ "access_token.text" },
{ "password" },
{ "password.text" },
{ "password.hash" },
{ "password.hash.sha256" },
};
std::shared_ptr<database> accounts_database
{
std::make_shared<database>("accounts"s, ""s, accounts_description)
};
mapi::header IRCD_MODULE
{
"Hosts the 'accounts' database"
};

214
modules/db/events.cc Normal file
View file

@ -0,0 +1,214 @@
/*
* 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;
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<database> events_database
{
std::make_shared<database>("events"s, ""s, events_description)
};
mapi::header IRCD_MODULE
{
"Hosts the 'events' database"
};

View file

@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2017 Charybdis Development Team * Copyright (C) 2017 Charybdis Development Team
* Copyright (C) 2017 Jason Volk <jason@zemos.net> * Copyright (C) 2017 Jason Volk <jason@zemos.net>
* *
@ -19,12 +19,42 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
ircd::import_shared<ircd::database> account_database using namespace ircd;
const database::descriptor rooms_head_descriptor
{ {
"client_account", "account_database" // 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)
}
}; };
extern ircd::database *const account const database::description rooms_description
{ {
account_database.get() { "default" },
rooms_head_descriptor,
};
std::shared_ptr<database> rooms_database
{
std::make_shared<database>("room"s, ""s, rooms_description)
};
mapi::header IRCD_MODULE
{
"Hosts the 'rooms' database"
}; };