Listing objects and permissions

Previous: Actually using all this XML to figure out a user's permissions ] [ Top: The user module ] [ Next: main.c: using the user module ]

In order to present nice menus and show our neat-o little folder system, we want a listing facility.

user_list()
The first step in listing things is the user_list function, which (given a user or group) produces a <user_list> XML structure. As usual, if any of the strings is NULL, that counts as a wildcard. I'm also including "." as a wildcard, as I don't expect classes, objects, or permissions named "." would be very useful anyway.
 
void _user_add_to_list (XML * ret, XML * user, const char * class, const char * object, const char * permission)
{
   XML * child;
   XML * piece;
   int ok;
   child = xml_firstelem (user);
   while (child) {
      if (!strcmp (child->name, "object")) {
         if ((!strcmp (class, ".") || !strcmp (class, xml_attrval (child, "class"))) &&
             (!strcmp (object, ".") || !strcmp (object, xml_attrval (child, "object"))) &&
             (!strcmp (permission, ".") ||
              _user_perm_cmp (xml_attrval (child, "permission"), permission))) {
               piece = xml_create ("object");
               xml_set (piece, "class", xml_attrval (child, "class"));
               xml_set (piece, "object", xml_attrval (child, "object"));
               xml_set (piece, "permission", xml_attrval (child, "permission"));
               xml_append (ret, piece);
         }
      } else if (!strcmp (child->name, "group-include")) {
         if (!strcmp (permission, ".") ||
             _user_perm_cmp (xml_attrval (child, "permission"), permission)) {
             piece = xml_create ("group-include");
             xml_set (piece, "name", xml_attrval (child, "name"));
             xml_set (piece, "permission", xml_attrval (child, "permission"));
             xml_append (ret, piece);
         }
      } else if (!strcmp (child->name, "group")) {
         piece = group_get (xml_attrval (child, "name"));
         if (piece) {
            _user_add_to_list (ret, piece, class, object, permission);
            xml_free (piece);
         }
      }
      child = xml_nextelem (child);
   }
}

XML * user_list (XML * user, const char * class, const char * object, const char * permission)
{
   XML * ret;

   ret = xml_create ("user_list");
   _user_add_to_list (ret, user, class ? class : ".", object ? object : ".", permission ? permission : ".");
   return (ret);
}
Previous: Actually using all this XML to figure out a user's permissions ] [ Top: The user module ] [ Next: main.c: using the user module ]


This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.