From f66faaaf8ddcf3b2e75ada891933fe3fcdc87cd9 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 16 Mar 2020 10:13:12 -0700 Subject: [PATCH] modules/client/pushrules: Additional handler stubs w/ params. --- modules/client/pushrules.cc | 145 ++++++++++++++++++++++++++++++++---- 1 file changed, 129 insertions(+), 16 deletions(-) diff --git a/modules/client/pushrules.cc b/modules/client/pushrules.cc index 25e017b7d..77c90aede 100644 --- a/modules/client/pushrules.cc +++ b/modules/client/pushrules.cc @@ -1,23 +1,32 @@ -// Matrix Construct +// The Construct // -// Copyright (C) Matrix Construct Developers, Authors & Contributors -// Copyright (C) 2016-2018 Jason Volk +// Copyright (C) The Construct Developers, Authors & Contributors +// Copyright (C) 2016-2020 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. -using namespace ircd; +namespace ircd::m::pushrules +{ + static resource::response handle_delete(client &, const resource::request &); + static resource::response handle_put(client &, const resource::request &); + static resource::response handle_get(client &, const resource::request &); + extern resource::method method_get; + extern resource::method method_put; + extern resource::method method_delete; + extern resource resource; +} -mapi::header +ircd::mapi::header IRCD_MODULE { - "Client 11.12.1.5 :Push Rules API" + "Client 0.6.0-13.13.1.6 :Push Rules API" }; -resource -pushrules +decltype(ircd::m::pushrules::resource) +ircd::m::pushrules::resource { "/_matrix/client/r0/pushrules", { @@ -27,10 +36,42 @@ pushrules } }; -resource::response -get_pushrules(client &client, const resource::request &request) -try +decltype(ircd::m::pushrules::method_get) +ircd::m::pushrules::method_get { + resource, "GET", handle_get, + { + method_get.REQUIRES_AUTH + } +}; + +ircd::m::resource::response +ircd::m::pushrules::handle_get(client &client, + const resource::request &request) +{ + char buf[3][64]; + const auto &scope + { + request.parv.size() > 0? + url::decode(buf[0], request.parv[0]): + string_view{}, + }; + + const auto &kind + { + request.parv.size() > 1? + url::decode(buf[1], request.parv[1]): + string_view{}, + }; + + const auto &ruleid + { + request.parv.size() > 2? + url::decode(buf[2], request.parv[2]): + string_view{}, + }; + + return resource::response { client, json::members @@ -46,13 +87,85 @@ try } }; } -catch(...) + +decltype(ircd::m::pushrules::method_put) +ircd::m::pushrules::method_put { - throw; + resource, "PUT", handle_put, + { + method_put.REQUIRES_AUTH + } +}; + +ircd::m::resource::response +ircd::m::pushrules::handle_put(client &client, + const resource::request &request) +{ + char buf[3][64]; + const auto &scope + { + request.parv.size() > 0? + url::decode(buf[0], request.parv[0]): + string_view{}, + }; + + const auto &kind + { + request.parv.size() > 1? + url::decode(buf[1], request.parv[1]): + string_view{}, + }; + + const auto &ruleid + { + request.parv.size() > 2? + url::decode(buf[2], request.parv[2]): + string_view{}, + }; + + return resource::response + { + client, json::object{} + }; } -resource::method -get_method +decltype(ircd::m::pushrules::method_delete) +ircd::m::pushrules::method_delete { - pushrules, "GET", get_pushrules + resource, "DELETE", handle_delete, + { + method_delete.REQUIRES_AUTH + } }; + +ircd::m::resource::response +ircd::m::pushrules::handle_delete(client &client, + const resource::request &request) +{ + char buf[3][64]; + const auto &scope + { + request.parv.size() > 0? + url::decode(buf[0], request.parv[0]): + string_view{}, + }; + + const auto &kind + { + request.parv.size() > 1? + url::decode(buf[1], request.parv[1]): + string_view{}, + }; + + const auto &ruleid + { + request.parv.size() > 2? + url::decode(buf[2], request.parv[2]): + string_view{}, + }; + + return resource::response + { + client, json::object{} + }; +}