From 34d1ea4afc85e31f9b81ce6eb89c572fbc0c4246 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 21 Feb 2018 16:53:07 -0800 Subject: [PATCH] modules/client/user: Stub handler for 11.18.2.2 PUT rooms/account_data; fix parv check. --- modules/Makefile.am | 1 + modules/client/user/rooms.cc | 72 ++++++++++++++++++++++++++++++++++++ modules/client/user/user.cc | 11 +++++- modules/client/user/user.h | 10 +++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 modules/client/user/rooms.cc diff --git a/modules/Makefile.am b/modules/Makefile.am index 0c5b52bb1..9673ada37 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -148,6 +148,7 @@ client_client_user_la_SOURCES = \ client/user/openid.cc \ client/user/filter.cc \ client/user/account_data.cc \ + client/user/rooms.cc \ client/user/user.cc \ ### diff --git a/modules/client/user/rooms.cc b/modules/client/user/rooms.cc new file mode 100644 index 000000000..1df088121 --- /dev/null +++ b/modules/client/user/rooms.cc @@ -0,0 +1,72 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2018 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. The +// full license for this software is available in the LICENSE file. + +#include "user.h" + +using namespace ircd; + +static resource::response +put__account_data(client &client, + const resource::request &request, + const m::user::id &user_id, + const m::room::id &room_id) +{ + if(request.parv.size() < 5) + throw m::NEED_MORE_PARAMS + { + "type required" + }; + + const string_view &type + { + request.parv[4] + }; + + return resource::response + { + client, http::OK + }; +} + +resource::response +put__rooms(client &client, + const resource::request &request, + const m::user::id &user_id) +{ + if(request.parv.size() < 3) + throw m::NEED_MORE_PARAMS + { + "room_id required" + }; + + m::room::id::buf room_id + { + url::decode(request.parv[2], room_id) + }; + + if(request.parv.size() < 4) + throw m::NEED_MORE_PARAMS + { + "rooms command required" + }; + + const string_view &cmd + { + request.parv[3] + }; + + if(cmd == "account_data") + return put__account_data(client, request, user_id, room_id); + + throw m::NOT_FOUND + { + "/user/rooms/ command not found" + }; +} diff --git a/modules/client/user/user.cc b/modules/client/user/user.cc index 35119c433..e31211ff0 100644 --- a/modules/client/user/user.cc +++ b/modules/client/user/user.cc @@ -108,7 +108,7 @@ post_method resource::response put_user(client &client, const resource::request &request) { - if(request.parv.size() < 2) + if(request.parv.size() < 1) throw m::NEED_MORE_PARAMS { "user_id required" @@ -119,6 +119,12 @@ put_user(client &client, const resource::request &request) url::decode(request.parv[0], user_id) }; + if(request.parv.size() < 2) + throw m::NEED_MORE_PARAMS + { + "user command required" + }; + const string_view &cmd { request.parv[1] @@ -127,6 +133,9 @@ put_user(client &client, const resource::request &request) if(cmd == "account_data") return put__account_data(client, request, user_id); + if(cmd == "rooms") + return put__rooms(client, request, user_id); + throw m::NOT_FOUND { "/user command not found" diff --git a/modules/client/user/user.h b/modules/client/user/user.h index 655bb169c..c9baeafcb 100644 --- a/modules/client/user/user.h +++ b/modules/client/user/user.h @@ -44,3 +44,13 @@ ircd::resource::response post__openid(ircd::client &client, const ircd::resource::request &request, const ircd::m::user::id &user_id); + +/////////////////////////////////////////////////////////////////////////////// +// +// rooms.cc +// + +ircd::resource::response +put__rooms(ircd::client &client, + const ircd::resource::request &request, + const ircd::m::user::id &user_id);