summaryrefslogtreecommitdiffstats
path: root/bindings/samples
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-09-04 11:37:39 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-09-07 09:43:13 +0200
commit85bca06fe0ee2923421f013da3e9f53abbfff673 (patch)
tree9760887748d9250f90e5ad068413f0d4f913e015 /bindings/samples
parent91c12808e08fb30e58a3d2e008569933f409d6db (diff)
Implement afb_req_has_permission
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 <jose.bollo@iot.bzh>
Diffstat (limited to 'bindings/samples')
-rw-r--r--bindings/samples/HelloWorld.c10
1 files changed, 10 insertions, 0 deletions
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}
};