work in progress
[src/app-framework-main.git] / src / wgtpkg-permissions.c
index 25758e4..ee38988 100644 (file)
@@ -20,6 +20,7 @@
 #include <syslog.h>
 #include <string.h>
 
+#include "verbose.h"
 #include "wgtpkg.h"
 
 struct permission {
@@ -33,6 +34,7 @@ static const char prefix_of_permissions[] = PREFIXPERMISSION;
 
 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 +104,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 +132,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;
+}
+