int user_join (XML * user, XML * group)
{
XML * child;
child = xml_firstelem (group);
while (child) {
if (!strcmp (child->name, "user"))
if (!strcmp (xml_attrval (child, "name"), xml_attrval (user, "name")))
goto ensure_group;
child = xml_nextelem (child);
}
child = xml_create ("user");
xml_set (child, "name", xml_attrval (user, "name"));
xml_append (group, child);
ensure_group:
child = xml_firstelem (user);
while (child) {
if (!strcmp (child->name, "group"))
if (!strcmp (xml_attrval (child, "name"), xml_attrval (group, "name")))
return 0;
child = xml_nextelem (child);
}
child = xml_create ("group");
xml_set (child, "name", xml_attrval (group, "name"));
xml_append (user, child);
return 0;
}
|
int user_leave (XML * user, XML * group)
{
XML * child;
child = xml_firstelem (group);
while (child) {
if (!strcmp (child->name, "user")) {
if (!strcmp (xml_attrval (child, "name"), xml_attrval (user, "name"))) {
xml_delete (child);
child = xml_firstelem (group);
}
}
child = xml_nextelem (child);
}
child = xml_firstelem (user);
while (child) {
if (!strcmp (child->name, "group")) {
if (!strcmp (xml_attrval (child, "name"), xml_attrval (group, "name"))) {
xml_delete (child);
child = xml_firstelem (user);
}
}
child = xml_nextelem (child);
}
}
|
int object_grant (XML * user_or_group, const char * class, const char * object, const char * permission)
{
XML * child;
child = xml_firstelem (user_or_group);
while (child) {
if (!strcmp (child->name, "object"))
if (!strcmp (xml_attrval (child, "class"), class) &&
!strcmp (xml_attrval (child, "object"), object) &&
!strcmp (xml_attrval (child, "permission"), permission))
return 0;
child = xml_nextelem (child);
}
child = xml_create ("object");
xml_set (child, "class", class);
xml_set (child, "object", object);
xml_set (child, "permission", permission);
xml_append (user_or_group, child);
return 0;
}
|
int object_revoke (XML * user_or_group, const char * class, const char * object, const char * permission)
{
XML * child;
int ok;
child = xml_firstelem (user_or_group);
while (child) {
if (!strcmp (child->name, "object") &&
!strcmp (xml_attrval (child, "class"), class)) {
ok = 0;
if (!object) ok = 1;
if (!ok) if (!strcmp (xml_attrval (child, "object"), object)) ok = 1;
if (ok) {
ok = 0;
if (!permission) ok = 1;
if (!ok) if (!strcmp (xml_attrval (child, "permission"), permission)) ok = 1;
if (ok) {
xml_delete (child);
child = xml_firstelem (user_or_group);
}
}
}
child = xml_nextelem (child);
}
}
|
int group_include (XML * outgroup, XML * ingroup, const char * permission)
{
XML * child;
child = xml_firstelem (outgroup);
while (child) {
if (!strcmp (child->name, "group-include"))
if (!strcmp (xml_attrval (child, "name"), xml_attrval (ingroup, "name")) &&
!strcmp (xml_attrval (child, "permission"), permission))
goto ensure_ingroup;
child = xml_nextelem (child);
}
child = xml_create ("group-include");
xml_set (child, "name", xml_attrval (ingroup, "name"));
xml_set (child, "permission", permission);
xml_append (outgroup, child);
ensure_ingroup:
child = xml_firstelem (ingroup);
while (child) {
if (!strcmp (child->name, "group-included-by"))
if (!strcmp (xml_attrval (child, "name"), xml_attrval (outgroup, "name")) &&
!strcmp (xml_attrval (child, "permission"), permission))
return 0;
child = xml_nextelem (child);
}
child = xml_create ("group-included-by");
xml_set (child, "name", xml_attrval (outgroup, "name"));
xml_set (child, "permission", permission);
xml_append (ingroup, child);
return 0;
}
|
object_revoke above,
int group_unlink (XML * outgroup, XML * ingroup, const char * permission)
{
XML * child;
int ok;
child = xml_firstelem (outgroup);
while (child) {
if (!strcmp (child->name, "group-include") &&
!strcmp (xml_attrval (child, "name"), xml_attrval (ingroup, "name"))) {
ok = 0;
if (!permission) ok = 1;
if (!ok) if (!strcmp (xml_attrval (child, "permission"), permission)) ok = 1;
if (ok) {
xml_delete (child);
child = xml_firstelem (outgroup);
}
}
child = xml_nextelem (child);
}
child = xml_firstelem (ingroup);
while (child) {
if (!strcmp (child->name, "group-included-by") &&
!strcmp (xml_attrval (child, "name"), xml_attrval (outgroup, "name"))) {
ok = 0;
if (!permission) ok = 1;
if (!ok) if (!strcmp (xml_attrval (child, "permission"), permission)) ok = 1;
if (ok) {
xml_delete (child);
child = xml_firstelem (ingroup);
}
}
child = xml_nextelem (child);
}
}
|
| 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. |