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

ircd:Ⓜ️ Move spec tuples into headers.

This commit is contained in:
Jason Volk 2018-03-05 03:05:59 -08:00
parent 2dc94d7adc
commit 01ce9a3d6f
9 changed files with 260 additions and 190 deletions

View file

@ -0,0 +1,91 @@
// 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_CREATEROOM_H
namespace ircd::m
{
struct createroom;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsubobject-linkage"
struct ircd::m::createroom
:json::tuple
<
/// A public visibility indicates that the room will be shown in the
/// published room list. A private visibility will hide the room from
/// the published room list. Rooms default to private visibility if this
/// key is not included. NB: This should not be confused with join_rules
/// which also uses the word public. One of: ["public", "private"]
json::property<name::visibility, json::string>,
/// 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.
json::property<name::room_alias_name, json::string>,
/// If this is included, an m.room.name event will be sent into the room
/// to indicate the name of the room. See Room Events for more information
/// on m.room.name.
json::property<name::name, json::string>,
/// 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.
json::property<name::topic, json::string>,
/// A list of user IDs to invite to the room. This will tell the server
/// to invite everyone in the list to the newly created room.
json::property<name::invite, json::array>,
/// A list of objects representing third party IDs to invite into the room.
json::property<name::invite_3pid, invite_3pid>,
/// Extra keys to be added to the content of the m.room.create. The server
/// will clobber the following keys: creator. Future versions of the
/// specification may allow the server to clobber other keys.
json::property<name::creation_content, json::object>,
/// A list of state events to set in the new room. This allows the user
/// to override the default state events set in the new room. The expected
/// format of the state events are an object with type, state_key and content
/// keys set. Takes precedence over events set by presets, but gets overriden
/// by name and topic keys.
json::property<name::initial_state, json::array>,
/// Convenience parameter for setting various default state events based on
/// a preset. Must be either: private_chat => join_rules is set to invite.
/// history_visibility is set to shared. trusted_private_chat => join_rules
/// is set to invite. history_visibility is set to shared. All invitees are
/// given the same power level as the room creator. public_chat: =>
/// join_rules is set to public. history_visibility is set to shared. One
/// of: ["private_chat", "public_chat", "trusted_private_chat"]
json::property<name::preset, json::string>,
/// This flag makes the server set the is_direct flag on the m.room.member
/// events sent to the users in invite and invite_3pid. See Direct
/// Messaging for more information.
json::property<name::is_direct, bool>,
/// Allows guests to join the room. See Guest Access for more information.
///
/// developer note: this is false if undefined, but an m.room.guest_access
/// may be present in the initial vector which allows guest access. This is
/// only meaningful if and only if true.
json::property<name::guest_can_join, bool>
>
{
using super_type::tuple;
};
#pragma GCC diagnostic pop

View file

@ -0,0 +1,38 @@
// 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_INVITE_3PID_H
namespace ircd::m
{
struct invite_3pid;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsubobject-linkage"
struct ircd::m::invite_3pid
:json::tuple
<
/// Required. The hostname+port of the identity server which should be
/// used for third party identifier lookups.
json::property<name::id_server, json::string>,
/// Required. The kind of address being passed in the address field,
/// for example email.
json::property<name::medium, json::string>,
/// Required. The invitee's third party identifier.
json::property<name::address, json::string>
>
{
using super_type::tuple;
};
#pragma GCC diagnostic pop

57
include/ircd/m/login.h Normal file
View file

@ -0,0 +1,57 @@
// 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_LOGIN_H
namespace ircd::m
{
struct login;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsubobject-linkage"
struct ircd::m::login
:json::tuple
<
/// Required. The login type being used. One of: ["m.login.password",
/// "m.login.token"]
json::property<name::type, string_view>,
/// The fully qualified user ID or just local part of the user ID, to
/// log in.
json::property<name::user, string_view>,
/// When logging in using a third party identifier, the medium of the
/// identifier. Must be 'email'.
json::property<name::medium, string_view>,
/// Third party identifier for the user.
json::property<name::address, string_view>,
/// Required when type is m.login.password. The user's password.
json::property<name::password, string_view>,
/// Required when type is m.login.token. The login token.
json::property<name::token, string_view>,
/// ID of the client device. If this does not correspond to a known client
/// device, a new device will be created. The server will auto-generate a
/// device_id if this is not specified.
json::property<name::device_id, string_view>,
/// A display name to assign to the newly-created device. Ignored if
/// device_id corresponds to a known device.
json::property<name::initial_device_display_name, string_view>
>
{
using super_type::tuple;
};
#pragma GCC diagnostic pop

View file

@ -51,6 +51,10 @@ namespace ircd
#include "state.h"
#include "room.h"
#include "user.h"
#include "login.h"
#include "register.h"
#include "invite_3pid.h"
#include "createroom.h"
#include "filter.h"
#include "request.h"
#include "v1/v1.h"

View file

@ -100,4 +100,30 @@ namespace ircd::m::name
constexpr const char *const event_ids {"event_ids"};
constexpr const char *const typing {"typing"};
constexpr const auto user{"user"};
constexpr const auto medium{"medium"};
constexpr const auto address{"address"};
constexpr const auto password{"password"};
constexpr const auto token{"token"};
constexpr const auto device_id{"device_id"};
constexpr const auto initial_device_display_name{"initial_device_display_name"};
constexpr const auto username {"username"};
constexpr const auto bind_email {"bind_email"};
constexpr const auto auth {"auth"};
constexpr const auto visibility {"visibility"};
constexpr const auto room_alias_name {"room_alias_name"};
constexpr const auto name {"name"};
constexpr const auto topic {"topic"};
constexpr const auto invite {"invite"};
constexpr const auto invite_3pid {"invite_3pid"};
constexpr const auto creation_content {"creation_content"};
constexpr const auto initial_state {"initial_state"};
constexpr const auto preset {"preset"};
constexpr const auto is_direct {"is_direct"};
constexpr const auto guest_can_join {"guest_can_join"};
constexpr const auto id_server {"id_server"};
}

33
include/ircd/m/register.h Normal file
View file

@ -0,0 +1,33 @@
// 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_REGISTER_H
namespace ircd::m
{
struct registar;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsubobject-linkage"
struct ircd::m::registar
:json::tuple
<
json::property<name::username, string_view>,
json::property<name::bind_email, bool>,
json::property<name::password, string_view>,
json::property<name::auth, json::object>,
json::property<name::device_id, string_view>
>
{
using super_type::tuple;
};
#pragma GCC diagnostic pop

View file

@ -17,114 +17,6 @@ IRCD_MODULE
"Client 7.1.1 :Create Room"
};
namespace ircd::m::name
{
constexpr const auto visibility {"visibility"};
constexpr const auto room_alias_name {"room_alias_name"};
constexpr const auto name {"name"};
constexpr const auto topic {"topic"};
constexpr const auto invite {"invite"};
constexpr const auto invite_3pid {"invite_3pid"};
constexpr const auto creation_content {"creation_content"};
constexpr const auto initial_state {"initial_state"};
constexpr const auto preset {"preset"};
constexpr const auto is_direct {"is_direct"};
constexpr const auto guest_can_join {"guest_can_join"};
constexpr const auto id_server {"id_server"};
constexpr const auto medium {"medium"};
constexpr const auto address {"address"};
}
struct invite_3pid
:json::tuple
<
/// Required. The hostname+port of the identity server which should be
/// used for third party identifier lookups.
json::property<name::id_server, json::string>,
/// Required. The kind of address being passed in the address field,
/// for example email.
json::property<name::medium, json::string>,
/// Required. The invitee's third party identifier.
json::property<name::address, json::string>
>
{
using super_type::tuple;
};
struct body
:json::tuple
<
/// A public visibility indicates that the room will be shown in the
/// published room list. A private visibility will hide the room from
/// the published room list. Rooms default to private visibility if this
/// key is not included. NB: This should not be confused with join_rules
/// which also uses the word public. One of: ["public", "private"]
json::property<name::visibility, json::string>,
/// 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.
json::property<name::room_alias_name, json::string>,
/// If this is included, an m.room.name event will be sent into the room
/// to indicate the name of the room. See Room Events for more information
/// on m.room.name.
json::property<name::name, json::string>,
/// 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.
json::property<name::topic, json::string>,
/// A list of user IDs to invite to the room. This will tell the server
/// to invite everyone in the list to the newly created room.
json::property<name::invite, json::array>,
/// A list of objects representing third party IDs to invite into the room.
json::property<name::invite_3pid, invite_3pid>,
/// Extra keys to be added to the content of the m.room.create. The server
/// will clobber the following keys: creator. Future versions of the
/// specification may allow the server to clobber other keys.
json::property<name::creation_content, json::object>,
/// A list of state events to set in the new room. This allows the user
/// to override the default state events set in the new room. The expected
/// format of the state events are an object with type, state_key and content
/// keys set. Takes precedence over events set by presets, but gets overriden
/// by name and topic keys.
json::property<name::initial_state, json::array>,
/// Convenience parameter for setting various default state events based on
/// a preset. Must be either: private_chat => join_rules is set to invite.
/// history_visibility is set to shared. trusted_private_chat => join_rules
/// is set to invite. history_visibility is set to shared. All invitees are
/// given the same power level as the room creator. public_chat: =>
/// join_rules is set to public. history_visibility is set to shared. One
/// of: ["private_chat", "public_chat", "trusted_private_chat"]
json::property<name::preset, json::string>,
/// This flag makes the server set the is_direct flag on the m.room.member
/// events sent to the users in invite and invite_3pid. See Direct
/// Messaging for more information.
json::property<name::is_direct, bool>,
/// Allows guests to join the room. See Guest Access for more information.
///
/// developer note: this is false if undefined, but an m.room.guest_access
/// may be present in the initial vector which allows guest access. This is
/// only meaningful if and only if true.
json::property<name::guest_can_join, bool>
>
{
using super_type::tuple;
};
extern "C" room
createroom__parent_type(const id::room &room_id,
const id::user &creator,
@ -137,8 +29,8 @@ createroom__type(const id::room &room_id,
const string_view &type);
extern "C" room
createroom(const id::room &room_id,
const id::user &creator);
createroom_(const id::room &room_id,
const id::user &creator);
const room::id::buf
init_room_id
@ -157,7 +49,7 @@ createroom_resource
resource::response
post__createroom(client &client,
const resource::request::object<body> &request)
const resource::request::object<m::createroom> &request)
try
{
const id::user &sender_id
@ -172,7 +64,7 @@ try
const room room
{
createroom(room_id, sender_id)
createroom_(room_id, sender_id)
};
const event::id::buf join_event_id
@ -211,8 +103,8 @@ post_method
};
room
createroom(const id::room &room_id,
const id::user &creator)
createroom_(const id::room &room_id,
const id::user &creator)
{
return createroom__type(room_id, creator, string_view{});
}

View file

@ -26,58 +26,9 @@ login_resource
}
};
namespace { namespace name
{
constexpr const auto type{"type"};
constexpr const auto user{"user"};
constexpr const auto medium{"medium"};
constexpr const auto address{"address"};
constexpr const auto password{"password"};
constexpr const auto token{"token"};
constexpr const auto device_id{"device_id"};
constexpr const auto initial_device_display_name{"initial_device_display_name"};
}}
struct body
:json::tuple
<
/// Required. The login type being used. One of: ["m.login.password",
/// "m.login.token"]
json::property<name::type, string_view>,
/// The fully qualified user ID or just local part of the user ID, to
/// log in.
json::property<name::user, string_view>,
/// When logging in using a third party identifier, the medium of the
/// identifier. Must be 'email'.
json::property<name::medium, string_view>,
/// Third party identifier for the user.
json::property<name::address, string_view>,
/// Required when type is m.login.password. The user's password.
json::property<name::password, string_view>,
/// Required when type is m.login.token. The login token.
json::property<name::token, string_view>,
/// ID of the client device. If this does not correspond to a known client
/// device, a new device will be created. The server will auto-generate a
/// device_id if this is not specified.
json::property<name::device_id, string_view>,
/// A display name to assign to the newly-created device. Ignored if
/// device_id corresponds to a known device.
json::property<name::initial_device_display_name, string_view>
>
{
using super_type::tuple;
};
resource::response
post__login_password(client &client,
const resource::request::object<body> &request)
const resource::request::object<m::login> &request)
{
// Build a canonical MXID from a the user field
const m::id::user::buf user_id
@ -149,7 +100,7 @@ post__login_password(client &client,
resource::response
post__login(client &client,
const resource::request::object<body> &request)
const resource::request::object<m::login> &request)
{
const auto &type
{

View file

@ -16,35 +16,13 @@ IRCD_MODULE
"Client 3.4.1 :Register"
};
namespace { namespace name
{
constexpr const auto username {"username"};
constexpr const auto bind_email {"bind_email"};
constexpr const auto password {"password"};
constexpr const auto auth {"auth"};
constexpr const auto device_id {"device_id"};
}}
struct body
:json::tuple
<
json::property<name::username, string_view>,
json::property<name::bind_email, bool>,
json::property<name::password, string_view>,
json::property<name::auth, json::object>,
json::property<name::device_id, string_view>
>
{
using super_type::tuple;
};
extern "C" m::event::id::buf register__user(const m::user &user, const json::members &contents);
static void validate_user_id(const m::id::user &user_id);
static void validate_password(const string_view &password);
resource::response
post__register_user(client &client,
const resource::request::object<body> &request)
const resource::request::object<m::registar> &request)
try
{
// 3.3.1 Additional authentication information for the user-interactive authentication API.
@ -173,7 +151,7 @@ catch(const m::INVALID_MXID &e)
resource::response
post__register_guest(client &client,
const resource::request::object<body> &request)
const resource::request::object<m::registar> &request)
{
throw m::error
{
@ -205,7 +183,7 @@ post__register_guest(client &client,
resource::response
post__register(client &client,
const resource::request::object<body> &request)
const resource::request::object<m::registar> &request)
{
const auto kind
{