From 85bca06fe0ee2923421f013da3e9f53abbfff673 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Mon, 4 Sep 2017 11:37:39 +0200 Subject: Implement afb_req_has_permission MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This new verb is available in bindings to check whether the client identified by a request has a given permission or not. Change-Id: I5eaa0892d8260d26bd76f37123251c103c981e10 Signed-off-by: José Bollo --- bindings/samples/HelloWorld.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'bindings/samples') diff --git a/bindings/samples/HelloWorld.c b/bindings/samples/HelloWorld.c index 002c4721..4125e77f 100644 --- a/bindings/samples/HelloWorld.c +++ b/bindings/samples/HelloWorld.c @@ -412,6 +412,15 @@ static void broadcast(afb_req request) json_object_put(object); } +static void hasperm (afb_req request) +{ + const char *perm = afb_req_value(request, "perm"); + if (afb_req_has_permission(request, perm)) + afb_req_success_f(request, NULL, "permission %s granted", perm?:"(null)"); + else + afb_req_fail_f(request, "not-granted", "permission %s NOT granted", perm?:"(null)"); +} + static int preinit() { AFB_NOTICE("hello binding comes to live"); @@ -450,6 +459,7 @@ static const afb_verb_v2 verbs[]= { { .verb="callsync", .callback=callsync }, { .verb="verbose", .callback=verbose }, { .verb="broadcast", .callback=broadcast }, + { .verb="hasperm", .callback=hasperm }, { .verb="exit", .callback=exitnow }, { .verb=NULL} }; -- cgit 1.2.3-korg