X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwgtpkg-permissions.c;h=9dabdd0322548dfa8821ca94feec3ea0af9fc74d;hb=c0fc18e47e49dd4e3cc2f09452a19297dad63f9c;hp=25758e407a89faeb1f9b741a88d8fbc0f6c08ca8;hpb=9ab266df6642c6e930e03b3024d7c3d53ef88bbc;p=src%2Fapp-framework-main.git diff --git a/src/wgtpkg-permissions.c b/src/wgtpkg-permissions.c index 25758e4..9dabdd0 100644 --- a/src/wgtpkg-permissions.c +++ b/src/wgtpkg-permissions.c @@ -1,6 +1,8 @@ /* Copyright 2015 IoT.bzh + author: José Bollo + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -17,9 +19,9 @@ #define _GNU_SOURCE #include -#include #include +#include "verbose.h" #include "wgtpkg.h" struct permission { @@ -29,10 +31,11 @@ struct permission { unsigned level: 3; }; -static const char prefix_of_permissions[] = PREFIXPERMISSION; +static const char prefix_of_permissions[] = FWK_PREFIX_PERMISSION; static int nrpermissions = 0; static struct permission *permissions = NULL; +static int indexiter = 0; /* check is the name has the correct prefix for permissions */ int is_standard_permission(const char *name) @@ -102,7 +105,7 @@ void grant_permission_list(const char *list) iter[n] = 0; p = add_permission(iter); if (!p) { - syslog(LOG_ERR, "Can't allocate permission"); + ERROR("Can't allocate permission"); exit(1); } p->granted = 1; @@ -130,3 +133,20 @@ int request_permission(const char *name) return 0; } +/* iteration over granted and requested permissions */ +const char *first_usable_permission() +{ + indexiter = 0; + return next_usable_permission(); +} + +const char *next_usable_permission() +{ + while(indexiter < nrpermissions) { + struct permission *p = &permissions[indexiter++]; + if (p->granted && p->requested) + return p->name; + } + return NULL; +} +