mirror of
https://github.com/matrix-construct/construct
synced 2024-06-02 18:18:56 +02:00
ircd/modules: Update resource / opts construction arguments.
This commit is contained in:
parent
cc81ed2f33
commit
f931308850
|
@ -31,26 +31,17 @@ struct ircd::resource
|
|||
{
|
||||
IRCD_EXCEPTION(ircd::error, error)
|
||||
|
||||
enum flag :uint;
|
||||
struct opts;
|
||||
struct method;
|
||||
struct request;
|
||||
struct response;
|
||||
|
||||
enum flag
|
||||
{
|
||||
DIRECTORY = 0x01,
|
||||
};
|
||||
|
||||
struct opts
|
||||
{
|
||||
flag flags{flag(0)};
|
||||
string_view description;
|
||||
};
|
||||
|
||||
static std::map<string_view, resource *, iless> resources;
|
||||
|
||||
string_view path;
|
||||
string_view description;
|
||||
flag flags;
|
||||
enum flag flags;
|
||||
std::map<string_view, method *> methods;
|
||||
unique_const_iterator<decltype(resources)> resources_it;
|
||||
|
||||
|
@ -61,14 +52,42 @@ struct ircd::resource
|
|||
method &operator[](const string_view &path);
|
||||
void operator()(client &, parse::capstan &, const http::request::head &);
|
||||
|
||||
resource(const string_view &path, const string_view &description, opts = {{}});
|
||||
resource(const string_view &path, opts = {{}});
|
||||
resource(const string_view &path, const opts &);
|
||||
resource(const string_view &path);
|
||||
resource() = default;
|
||||
virtual ~resource() noexcept;
|
||||
|
||||
static resource &find(string_view path);
|
||||
};
|
||||
|
||||
enum ircd::resource::flag
|
||||
:uint
|
||||
{
|
||||
DIRECTORY = 0x01,
|
||||
};
|
||||
|
||||
struct ircd::resource::opts
|
||||
{
|
||||
/// developer's literal description of the resource
|
||||
string_view description
|
||||
{
|
||||
"no description"
|
||||
};
|
||||
|
||||
/// flags for the resource
|
||||
flag flags
|
||||
{
|
||||
flag(0)
|
||||
};
|
||||
|
||||
/// parameter count limits (DIRECTORY only)
|
||||
std::pair<short, short> parc
|
||||
{
|
||||
0, // minimum params
|
||||
15 // maximum params
|
||||
};
|
||||
};
|
||||
|
||||
struct ircd::resource::request
|
||||
:json::object
|
||||
{
|
||||
|
@ -77,7 +96,7 @@ struct ircd::resource::request
|
|||
const http::request::head &head;
|
||||
http::request::content &content;
|
||||
http::query::string query;
|
||||
m::user::id::buf user_id;
|
||||
string_view user_id; //m::user::id::buf user_id; //TODO: bleeding
|
||||
vector_view<string_view> parv;
|
||||
|
||||
request(const http::request::head &head, http::request::content &content, http::query::string query, const vector_view<string_view> &parv);
|
||||
|
@ -91,6 +110,7 @@ struct ircd::resource::request::object
|
|||
const http::request::head &head;
|
||||
const http::request::content &content;
|
||||
const http::query::string &query;
|
||||
const decltype(r.user_id) &user_id;
|
||||
const vector_view<string_view> &parv;
|
||||
const json::object &body;
|
||||
|
||||
|
@ -100,6 +120,7 @@ struct ircd::resource::request::object
|
|||
,head{r.head}
|
||||
,content{r.content}
|
||||
,query{r.query}
|
||||
,user_id{r.user_id}
|
||||
,parv{r.parv}
|
||||
,body{r}
|
||||
{}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*/
|
||||
|
||||
#include <ircd/m/m.h>
|
||||
#include <ircd/resource.h>
|
||||
|
||||
namespace ircd {
|
||||
|
||||
|
@ -71,20 +70,18 @@ ircd::resource::find(string_view path)
|
|||
return *it->second;
|
||||
}
|
||||
|
||||
ircd::resource::resource(const string_view &path,
|
||||
opts opts)
|
||||
ircd::resource::resource(const string_view &path)
|
||||
:resource
|
||||
{
|
||||
path, opts.description, opts
|
||||
path, opts{}
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::resource::resource(const string_view &path,
|
||||
const string_view &description,
|
||||
opts opts)
|
||||
const opts &opts)
|
||||
:path{path}
|
||||
,description{description}
|
||||
,description{opts.description}
|
||||
,flags{opts.flags}
|
||||
,resources_it{[this, &path]
|
||||
{
|
||||
|
@ -150,7 +147,7 @@ try
|
|||
return false;
|
||||
|
||||
assert(at<"state_key"_>(event) == access_token);
|
||||
request.user_id = at<"sender"_>(event);
|
||||
request.user_id = m::user::id{at<"sender"_>(event)};
|
||||
return true;
|
||||
})
|
||||
};
|
||||
|
|
|
@ -22,18 +22,22 @@
|
|||
using namespace ircd;
|
||||
|
||||
struct account
|
||||
:resource
|
||||
:ircd::resource
|
||||
{
|
||||
resource deactivate
|
||||
{
|
||||
"/_matrix/client/r0/account/deactivate",
|
||||
"Deactivate the user's account, removing all ability for the user to login again. (3.3.3)"
|
||||
{
|
||||
"Deactivate the user's account, removing all ability for the user to login again. (3.3.3)"
|
||||
}
|
||||
};
|
||||
|
||||
resource password
|
||||
{
|
||||
"/_matrix/client/r0/account/password",
|
||||
"Changes the password for an account on this homeserver. (3.3.4)"
|
||||
{
|
||||
"Changes the password for an account on this homeserver. (3.3.4)"
|
||||
}
|
||||
};
|
||||
|
||||
using resource::resource;
|
||||
|
@ -41,7 +45,9 @@ struct account
|
|||
account_resource
|
||||
{
|
||||
"/_matrix/client/r0/account",
|
||||
"Account management (3.3)"
|
||||
{
|
||||
"Account management (3.3)"
|
||||
}
|
||||
};
|
||||
|
||||
resource::response
|
||||
|
|
|
@ -24,7 +24,14 @@ using namespace ircd;
|
|||
resource createroom
|
||||
{
|
||||
"/_matrix/client/r0/createRoom",
|
||||
"Create a new room with various configuration options. (7.1.1)"
|
||||
{
|
||||
"Create a new room with various configuration options. (7.1.1)"
|
||||
}
|
||||
};
|
||||
|
||||
mapi::header IRCD_MODULE
|
||||
{
|
||||
"registers the resource 'client/createRoom' to handle requests"
|
||||
};
|
||||
|
||||
resource::response
|
||||
|
@ -94,8 +101,3 @@ resource::method post_method
|
|||
post_method.REQUIRES_AUTH
|
||||
}
|
||||
};
|
||||
|
||||
mapi::header IRCD_MODULE
|
||||
{
|
||||
"registers the resource 'client/createRoom' to handle requests"
|
||||
};
|
||||
|
|
|
@ -24,7 +24,9 @@ using namespace ircd;
|
|||
resource events_resource
|
||||
{
|
||||
"/_matrix/client/r0/events",
|
||||
"Events (6.2.3) (10.x)"
|
||||
{
|
||||
"Events (6.2.3) (10.x)"
|
||||
}
|
||||
};
|
||||
|
||||
resource::response
|
||||
|
|
|
@ -25,8 +25,8 @@ resource join_resource
|
|||
{
|
||||
"/_matrix/client/r0/join/", resource::opts
|
||||
{
|
||||
"join",
|
||||
resource::DIRECTORY,
|
||||
"join"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -24,8 +24,10 @@ using namespace ircd;
|
|||
resource login_resource
|
||||
{
|
||||
"/_matrix/client/r0/login",
|
||||
"Authenticates the user by password, and issues an access token "
|
||||
"they can use to authorize themself in subsequent requests. (3.2.2)"
|
||||
{
|
||||
"Authenticates the user by password, and issues an access token "
|
||||
"they can use to authorize themself in subsequent requests. (3.2.2)"
|
||||
}
|
||||
};
|
||||
|
||||
namespace { namespace name
|
||||
|
|
|
@ -24,8 +24,10 @@ using namespace ircd;
|
|||
resource logout_resource
|
||||
{
|
||||
"/_matrix/client/r0/logout",
|
||||
"Invalidates an existing access token, so that it can no longer be used for "
|
||||
"authorization. (3.2.3)"
|
||||
{
|
||||
"Invalidates an existing access token, so that it can no longer be used for "
|
||||
"authorization. (3.2.3)"
|
||||
}
|
||||
};
|
||||
|
||||
resource::response
|
||||
|
|
|
@ -24,8 +24,10 @@ using namespace ircd;
|
|||
resource publicrooms_resource
|
||||
{
|
||||
"/_matrix/client/r0/publicRooms",
|
||||
"Lists the public rooms on the server. "
|
||||
"This API returns paginated responses. (7.5)"
|
||||
{
|
||||
"Lists the public rooms on the server. "
|
||||
"This API returns paginated responses. (7.5)"
|
||||
}
|
||||
};
|
||||
|
||||
const ircd::m::room::id::buf
|
||||
|
|
|
@ -21,13 +21,19 @@
|
|||
|
||||
using namespace ircd;
|
||||
|
||||
static const auto description
|
||||
{R"(
|
||||
Retrieve all push rulesets for this user. Clients can "drill-down" on the rulesets by
|
||||
suffixing a scope to this path e.g. /pushrules/global/. This will return a subset of this data
|
||||
under the specified key e.g. the global key. (11.10.1.4.6)
|
||||
)"};
|
||||
|
||||
resource pushrules
|
||||
{
|
||||
"/_matrix/client/r0/pushrules", R"(
|
||||
Retrieve all push rulesets for this user. Clients can "drill-down" on the rulesets by
|
||||
suffixing a scope to this path e.g. /pushrules/global/. This will return a subset of this data
|
||||
under the specified key e.g. the global key. (11.10.1.4.6)
|
||||
)"
|
||||
"/_matrix/client/r0/pushrules",
|
||||
{
|
||||
description
|
||||
}
|
||||
};
|
||||
|
||||
resource::response
|
||||
|
|
|
@ -138,8 +138,7 @@ catch(const m::INVALID_MXID &e)
|
|||
{
|
||||
http::BAD_REQUEST,
|
||||
"M_INVALID_USERNAME",
|
||||
"The desired user ID is not a valid user name: %s",
|
||||
e.content
|
||||
"Not a valid username. Please try again."
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -189,7 +188,9 @@ handle_post(client &client,
|
|||
resource register_resource
|
||||
{
|
||||
"/_matrix/client/r0/register",
|
||||
"Register for an account on this homeserver. (3.3.1)"
|
||||
{
|
||||
"Register for an account on this homeserver. (3.3.1)"
|
||||
}
|
||||
};
|
||||
|
||||
resource::method post
|
||||
|
|
|
@ -30,8 +30,8 @@ rooms_resource
|
|||
{
|
||||
"/_matrix/client/r0/rooms/", resource::opts
|
||||
{
|
||||
"Rooms (7.0)",
|
||||
resource::DIRECTORY,
|
||||
"Rooms (7.0)"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -36,7 +36,9 @@ to the state, and to receive new messages.
|
|||
resource sync_resource
|
||||
{
|
||||
"/_matrix/client/r0/sync",
|
||||
sync_description
|
||||
{
|
||||
sync_description
|
||||
}
|
||||
};
|
||||
|
||||
void longpoll(client &client, const resource::request &request, const steady_point &timeout);
|
||||
|
|
|
@ -24,9 +24,9 @@ using namespace ircd;
|
|||
resource user_resource
|
||||
{
|
||||
"/_matrix/client/r0/user/",
|
||||
"User resource",
|
||||
{
|
||||
resource::DIRECTORY
|
||||
"User resource",
|
||||
resource::DIRECTORY,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,9 @@ using namespace ircd;
|
|||
resource versions_resource
|
||||
{
|
||||
"/_matrix/client/versions",
|
||||
"Gets the versions of the specification supported by the server (2.1)"
|
||||
{
|
||||
"Gets the versions of the specification supported by the server (2.1)"
|
||||
}
|
||||
};
|
||||
|
||||
resource::method getter
|
||||
|
|
|
@ -29,8 +29,10 @@ mapi::header IRCD_MODULE
|
|||
resource turnserver_resource
|
||||
{
|
||||
"/_matrix/client/r0/voip/turnServer",
|
||||
"This API provides credentials for the client to use when initiating calls."
|
||||
"(11.3.3)"
|
||||
{
|
||||
"(11.3.3) "
|
||||
"This API provides credentials for the client to use when initiating calls."
|
||||
}
|
||||
};
|
||||
|
||||
resource::response
|
||||
|
|
|
@ -33,10 +33,10 @@ struct send
|
|||
}
|
||||
event_resource
|
||||
{
|
||||
"/_matrix/federation/v1/event/", resource::opts
|
||||
"/_matrix/federation/v1/event/",
|
||||
{
|
||||
"federation event",
|
||||
resource::DIRECTORY,
|
||||
"federation event"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -50,10 +50,10 @@ struct send
|
|||
}
|
||||
send_resource
|
||||
{
|
||||
"/_matrix/federation/v1/send/", resource::opts
|
||||
"/_matrix/federation/v1/send/",
|
||||
{
|
||||
"federation send",
|
||||
resource::DIRECTORY,
|
||||
"federation send"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ server_resource
|
|||
{
|
||||
"/_matrix/key/v2/server/", resource::opts
|
||||
{
|
||||
"federation 2.2.1.1: Publishing Keys",
|
||||
resource::DIRECTORY,
|
||||
"federation 2.2.1.1: Publishing Keys"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ download_resource
|
|||
{
|
||||
"/_matrix/media/r0/download/", resource::opts
|
||||
{
|
||||
"media download",
|
||||
resource::DIRECTORY,
|
||||
"media download"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -89,8 +89,9 @@ get_root(client &client, const resource::request &request)
|
|||
|
||||
resource root_resource
|
||||
{
|
||||
"/", "Root resource",
|
||||
"/",
|
||||
{
|
||||
"Webroot resource",
|
||||
root_resource.DIRECTORY
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue