mirror of
https://github.com/matrix-construct/construct
synced 2024-10-01 21:28:53 +02:00
modules: Split client/user.
This commit is contained in:
parent
c45461d5f6
commit
d4e6e23804
5 changed files with 220 additions and 143 deletions
|
@ -86,7 +86,6 @@ client_client_pushers_la_SOURCES = client/pushers.cc
|
||||||
client_client_publicrooms_la_SOURCES = client/publicrooms.cc
|
client_client_publicrooms_la_SOURCES = client/publicrooms.cc
|
||||||
client_client_createroom_la_SOURCES = client/createroom.cc
|
client_client_createroom_la_SOURCES = client/createroom.cc
|
||||||
client_client_pushrules_la_SOURCES = client/pushrules.cc
|
client_client_pushrules_la_SOURCES = client/pushrules.cc
|
||||||
client_client_user_la_SOURCES = client/user.cc
|
|
||||||
client_client_join_la_SOURCES = client/join.cc
|
client_client_join_la_SOURCES = client/join.cc
|
||||||
client_client_voip_turnserver_la_SOURCES = client/voip/turnserver.cc
|
client_client_voip_turnserver_la_SOURCES = client/voip/turnserver.cc
|
||||||
client_client_directory_room_la_SOURCES = client/directory/room.cc
|
client_client_directory_room_la_SOURCES = client/directory/room.cc
|
||||||
|
@ -105,7 +104,6 @@ client_module_LTLIBRARIES += \
|
||||||
client/client_publicrooms.la \
|
client/client_publicrooms.la \
|
||||||
client/client_createroom.la \
|
client/client_createroom.la \
|
||||||
client/client_pushrules.la \
|
client/client_pushrules.la \
|
||||||
client/client_user.la \
|
|
||||||
client/client_join.la \
|
client/client_join.la \
|
||||||
client/client_voip_turnserver.la \
|
client/client_voip_turnserver.la \
|
||||||
client/client_directory_room.la \
|
client/client_directory_room.la \
|
||||||
|
@ -130,6 +128,18 @@ client_client_rooms_la_SOURCES = \
|
||||||
|
|
||||||
client_module_LTLIBRARIES += client/client_rooms.la
|
client_module_LTLIBRARIES += client/client_rooms.la
|
||||||
|
|
||||||
|
#
|
||||||
|
# client/user/
|
||||||
|
#
|
||||||
|
|
||||||
|
client_client_user_la_SOURCES = \
|
||||||
|
client/user/filter.cc \
|
||||||
|
client/user/account_data.cc \
|
||||||
|
client/user/user.cc \
|
||||||
|
###
|
||||||
|
|
||||||
|
client_module_LTLIBRARIES += client/client_user.la
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# /_matrix/key/
|
# /_matrix/key/
|
||||||
|
|
24
modules/client/user/account_data.cc
Normal file
24
modules/client/user/account_data.cc
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
#include "user.h"
|
||||||
|
|
||||||
|
using namespace ircd;
|
||||||
|
|
||||||
|
resource::response
|
||||||
|
put__account_data(client &client,
|
||||||
|
const resource::request &request,
|
||||||
|
const m::user::id &user_id)
|
||||||
|
{
|
||||||
|
return resource::response
|
||||||
|
{
|
||||||
|
client, http::OK
|
||||||
|
};
|
||||||
|
}
|
|
@ -8,21 +8,14 @@
|
||||||
// copyright notice and this permission notice is present in all copies. The
|
// copyright notice and this permission notice is present in all copies. The
|
||||||
// full license for this software is available in the LICENSE file.
|
// full license for this software is available in the LICENSE file.
|
||||||
|
|
||||||
|
#include "user.h"
|
||||||
|
|
||||||
using namespace ircd;
|
using namespace ircd;
|
||||||
|
|
||||||
resource user_resource
|
|
||||||
{
|
|
||||||
"/_matrix/client/r0/user/",
|
|
||||||
{
|
|
||||||
"User resource",
|
|
||||||
resource::DIRECTORY,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
resource::response
|
resource::response
|
||||||
get_filter(client &client,
|
get__filter(client &client,
|
||||||
const resource::request &request,
|
const resource::request &request,
|
||||||
const m::user::id &user_id)
|
const m::user::id &user_id)
|
||||||
{
|
{
|
||||||
char filter_id_buf[64];
|
char filter_id_buf[64];
|
||||||
const auto filter_id
|
const auto filter_id
|
||||||
|
@ -46,9 +39,9 @@ get_filter(client &client,
|
||||||
// (5.2) Uploads a new filter definition to the homeserver. Returns a filter ID that
|
// (5.2) Uploads a new filter definition to the homeserver. Returns a filter ID that
|
||||||
// may be used in future requests to restrict which events are returned to the client.
|
// may be used in future requests to restrict which events are returned to the client.
|
||||||
resource::response
|
resource::response
|
||||||
post_filter(client &client,
|
post__filter(client &client,
|
||||||
const resource::request::object<const m::filter> &request,
|
const resource::request::object<const m::filter> &request,
|
||||||
const m::user::id &user_id)
|
const m::user::id &user_id)
|
||||||
{
|
{
|
||||||
// (5.2) Required. The id of the user uploading the filter. The access
|
// (5.2) Required. The id of the user uploading the filter. The access
|
||||||
// token must be authorized to make requests for this user id.
|
// token must be authorized to make requests for this user id.
|
||||||
|
@ -115,129 +108,3 @@ post_filter(client &client,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
resource::response
|
|
||||||
put_account_data(client &client,
|
|
||||||
const resource::request &request,
|
|
||||||
const m::user::id &user_id)
|
|
||||||
{
|
|
||||||
std::cout << "put account data: " << user_id << " " << request.content << std::endl;
|
|
||||||
|
|
||||||
return resource::response
|
|
||||||
{
|
|
||||||
client, http::OK
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
resource::response
|
|
||||||
get_user(client &client, const resource::request &request)
|
|
||||||
{
|
|
||||||
if(request.parv.size() < 2)
|
|
||||||
throw m::error
|
|
||||||
{
|
|
||||||
http::MULTIPLE_CHOICES, "M_NOT_FOUND", "user id required"
|
|
||||||
};
|
|
||||||
|
|
||||||
m::user::id::buf user_id
|
|
||||||
{
|
|
||||||
url::decode(request.parv[0], user_id)
|
|
||||||
};
|
|
||||||
|
|
||||||
const string_view &cmd
|
|
||||||
{
|
|
||||||
request.parv[1]
|
|
||||||
};
|
|
||||||
|
|
||||||
if(cmd == "filter")
|
|
||||||
return get_filter(client, request, user_id);
|
|
||||||
|
|
||||||
throw m::NOT_FOUND
|
|
||||||
{
|
|
||||||
"/user command not found"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
resource::method get_method
|
|
||||||
{
|
|
||||||
user_resource, "GET", get_user,
|
|
||||||
{
|
|
||||||
get_method.REQUIRES_AUTH
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
resource::response
|
|
||||||
post_user(client &client, resource::request &request)
|
|
||||||
{
|
|
||||||
if(request.parv.size() < 2)
|
|
||||||
throw m::error
|
|
||||||
{
|
|
||||||
http::MULTIPLE_CHOICES, "M_NOT_FOUND", "user id required"
|
|
||||||
};
|
|
||||||
|
|
||||||
m::user::id::buf user_id
|
|
||||||
{
|
|
||||||
url::decode(request.parv[0], user_id)
|
|
||||||
};
|
|
||||||
|
|
||||||
const string_view &cmd
|
|
||||||
{
|
|
||||||
request.parv[1]
|
|
||||||
};
|
|
||||||
|
|
||||||
if(cmd == "filter")
|
|
||||||
return post_filter(client, request, user_id);
|
|
||||||
|
|
||||||
throw m::NOT_FOUND
|
|
||||||
{
|
|
||||||
"/user command not found"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
resource::method post_method
|
|
||||||
{
|
|
||||||
user_resource, "POST", post_user,
|
|
||||||
{
|
|
||||||
post_method.REQUIRES_AUTH
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
resource::response
|
|
||||||
put_user(client &client, const resource::request &request)
|
|
||||||
{
|
|
||||||
if(request.parv.size() < 2)
|
|
||||||
throw m::error
|
|
||||||
{
|
|
||||||
http::MULTIPLE_CHOICES, "M_NOT_FOUND", "user id required"
|
|
||||||
};
|
|
||||||
|
|
||||||
m::user::id::buf user_id
|
|
||||||
{
|
|
||||||
url::decode(request.parv[0], user_id)
|
|
||||||
};
|
|
||||||
|
|
||||||
const string_view &cmd
|
|
||||||
{
|
|
||||||
request.parv[1]
|
|
||||||
};
|
|
||||||
|
|
||||||
if(cmd == "account_data")
|
|
||||||
return put_account_data(client, request, user_id);
|
|
||||||
|
|
||||||
throw m::NOT_FOUND
|
|
||||||
{
|
|
||||||
"/user command not found"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
resource::method put_method
|
|
||||||
{
|
|
||||||
user_resource, "PUT", put_user,
|
|
||||||
{
|
|
||||||
put_method.REQUIRES_AUTH
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
mapi::header IRCD_MODULE
|
|
||||||
{
|
|
||||||
"registers the resource 'client/user' to handle requests"
|
|
||||||
};
|
|
140
modules/client/user/user.cc
Normal file
140
modules/client/user/user.cc
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
#include "user.h"
|
||||||
|
|
||||||
|
using namespace ircd;
|
||||||
|
|
||||||
|
mapi::header
|
||||||
|
IRCD_MODULE
|
||||||
|
{
|
||||||
|
"registers the resource 'client/user' to handle requests"
|
||||||
|
};
|
||||||
|
|
||||||
|
resource
|
||||||
|
user_resource
|
||||||
|
{
|
||||||
|
"/_matrix/client/r0/user/",
|
||||||
|
{
|
||||||
|
"User resource",
|
||||||
|
resource::DIRECTORY,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
resource::response
|
||||||
|
get_user(client &client, const resource::request &request)
|
||||||
|
{
|
||||||
|
if(request.parv.size() < 2)
|
||||||
|
throw m::error
|
||||||
|
{
|
||||||
|
http::MULTIPLE_CHOICES, "M_NOT_FOUND", "user id required"
|
||||||
|
};
|
||||||
|
|
||||||
|
m::user::id::buf user_id
|
||||||
|
{
|
||||||
|
url::decode(request.parv[0], user_id)
|
||||||
|
};
|
||||||
|
|
||||||
|
const string_view &cmd
|
||||||
|
{
|
||||||
|
request.parv[1]
|
||||||
|
};
|
||||||
|
|
||||||
|
if(cmd == "filter")
|
||||||
|
return get__filter(client, request, user_id);
|
||||||
|
|
||||||
|
throw m::NOT_FOUND
|
||||||
|
{
|
||||||
|
"/user command not found"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
resource::method
|
||||||
|
get_method
|
||||||
|
{
|
||||||
|
user_resource, "GET", get_user,
|
||||||
|
{
|
||||||
|
get_method.REQUIRES_AUTH
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
resource::response
|
||||||
|
post_user(client &client, resource::request &request)
|
||||||
|
{
|
||||||
|
if(request.parv.size() < 2)
|
||||||
|
throw m::error
|
||||||
|
{
|
||||||
|
http::MULTIPLE_CHOICES, "M_NOT_FOUND", "user id required"
|
||||||
|
};
|
||||||
|
|
||||||
|
m::user::id::buf user_id
|
||||||
|
{
|
||||||
|
url::decode(request.parv[0], user_id)
|
||||||
|
};
|
||||||
|
|
||||||
|
const string_view &cmd
|
||||||
|
{
|
||||||
|
request.parv[1]
|
||||||
|
};
|
||||||
|
|
||||||
|
if(cmd == "filter")
|
||||||
|
return post__filter(client, request, user_id);
|
||||||
|
|
||||||
|
throw m::NOT_FOUND
|
||||||
|
{
|
||||||
|
"/user command not found"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
resource::method
|
||||||
|
post_method
|
||||||
|
{
|
||||||
|
user_resource, "POST", post_user,
|
||||||
|
{
|
||||||
|
post_method.REQUIRES_AUTH
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
resource::response
|
||||||
|
put_user(client &client, const resource::request &request)
|
||||||
|
{
|
||||||
|
if(request.parv.size() < 2)
|
||||||
|
throw m::error
|
||||||
|
{
|
||||||
|
http::MULTIPLE_CHOICES, "M_NOT_FOUND", "user id required"
|
||||||
|
};
|
||||||
|
|
||||||
|
m::user::id::buf user_id
|
||||||
|
{
|
||||||
|
url::decode(request.parv[0], user_id)
|
||||||
|
};
|
||||||
|
|
||||||
|
const string_view &cmd
|
||||||
|
{
|
||||||
|
request.parv[1]
|
||||||
|
};
|
||||||
|
|
||||||
|
if(cmd == "account_data")
|
||||||
|
return put__account_data(client, request, user_id);
|
||||||
|
|
||||||
|
throw m::NOT_FOUND
|
||||||
|
{
|
||||||
|
"/user command not found"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
resource::method
|
||||||
|
put_method
|
||||||
|
{
|
||||||
|
user_resource, "PUT", put_user,
|
||||||
|
{
|
||||||
|
put_method.REQUIRES_AUTH
|
||||||
|
}
|
||||||
|
};
|
36
modules/client/user/user.h
Normal file
36
modules/client/user/user.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
extern ircd::resource user_resource;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// filter.cc
|
||||||
|
//
|
||||||
|
|
||||||
|
ircd::resource::response
|
||||||
|
get__filter(ircd::client &,
|
||||||
|
const ircd::resource::request &,
|
||||||
|
const ircd::m::user::id &);
|
||||||
|
|
||||||
|
ircd::resource::response
|
||||||
|
post__filter(ircd::client &,
|
||||||
|
const ircd::resource::request::object<const ircd::m::filter> &,
|
||||||
|
const ircd::m::user::id &);
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// account_data.cc
|
||||||
|
//
|
||||||
|
|
||||||
|
ircd::resource::response
|
||||||
|
put__account_data(ircd::client &client,
|
||||||
|
const ircd::resource::request &request,
|
||||||
|
const ircd::m::user::id &user_id);
|
Loading…
Reference in a new issue