/**************************************************************************** * This file is part of the project AqHome. * AqHome (c) by 2025 Martin Preuss, all rights reserved. * * The license for this file can be found in the file COPYING which you * should have received along with this file. ****************************************************************************/ #ifdef HAVE_CONFIG_H # include #endif #include "./mmodules.h" #include "aqhome-cgi/service/module.h" #include #include /* ------------------------------------------------------------------------------------------------ * defs and enums * ------------------------------------------------------------------------------------------------ */ #define GBAS GWEN_Buffer_AppendString #define GBAA GWEN_Buffer_AppendArgs /* ------------------------------------------------------------------------------------------------ * forward declarations * ------------------------------------------------------------------------------------------------ */ static void _createPermDefList(AQH_MODULE *m); static void _createRoleList(AQH_MODULE *m); static AQH_MODULE *_loadSubModule(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, const char *sModuleName); static int _handleRequest(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, const char *sLastPathElem); static void _handleRqIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static void _handleRqEditModGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static void _handleRqEditModPost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static void _handleRqAddRoleGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static void _handleRqAddRolePost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static void _handleRqEditRoleGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static void _handleRqEditRolePost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static int _getHighestUsedRoleId(const AQH_ROLE_LIST *roleList); static void _handleRqDeleteRole(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static void _writeEditModForm(const AQH_MODULE *currentMod, const char *sModName, GWEN_BUFFER *dbuf); static void _writeRoleListToForm(const AQH_ROLE_LIST *roleList, const char *sModName, const AQH_PERMDEF_LIST *permDefList, GWEN_BUFFER *dbuf); static void _setLocationHeaderForMod(AQCGI_REQUEST *rq, const char *page, const char *sModName); static void _writeEnabledPermissions(const AQH_PERMDEF_LIST *permDefList, uint32_t perms, GWEN_BUFFER *dbuf); /* ------------------------------------------------------------------------------------------------ * vars * ------------------------------------------------------------------------------------------------ */ static AQH_MODSERVICE_HANDLER_ENTRY _requestTable[]={ {"index.html", AQCGI_REQUEST_METHOD_GET, AQH_MODADMMODULES_PERMS_MODULESREAD, _handleRqIndex}, {"editmodule.html", AQCGI_REQUEST_METHOD_GET, AQH_MODADMMODULES_PERMS_MODULESWRITE, _handleRqEditModGet}, {"editmodule.html", AQCGI_REQUEST_METHOD_POST, AQH_MODADMMODULES_PERMS_MODULESWRITE, _handleRqEditModPost}, {"addrole.html", AQCGI_REQUEST_METHOD_GET, AQH_MODADMMODULES_PERMS_MODULESWRITE, _handleRqAddRoleGet}, {"addrole.html", AQCGI_REQUEST_METHOD_POST, AQH_MODADMMODULES_PERMS_MODULESWRITE, _handleRqAddRolePost}, {"editrole.html", AQCGI_REQUEST_METHOD_GET, AQH_MODADMMODULES_PERMS_MODULESWRITE, _handleRqEditRoleGet}, {"editrole.html", AQCGI_REQUEST_METHOD_POST, AQH_MODADMMODULES_PERMS_MODULESWRITE, _handleRqEditRolePost}, {"delrole.html", AQCGI_REQUEST_METHOD_GET, AQH_MODADMMODULES_PERMS_MODULESWRITE, _handleRqDeleteRole}, {NULL, 0, 0, NULL} }; /* ------------------------------------------------------------------------------------------------ * code * ------------------------------------------------------------------------------------------------ */ void AQH_ModAdmModules_Extend(AQH_MODULE *m, AQH_SERVICE *sv, const char *baseFolder) { AQH_ModService_Extend(m, sv, baseFolder); AQH_ModService_SetHandleRequestFn(m, _handleRequest); AQH_ModService_SetLoadSubModuleFn(m, _loadSubModule); } int AQH_ModAdmModules_Create(AQH_SERVICE *sv) { AQH_MODULE *m; int rv; m=AQH_Module_new(); AQH_Module_SetName(m, "modules"); AQH_Module_SetDescr(m, "modules administration module"); AQH_Module_SetGuestPerms(m, 0); _createPermDefList(m); _createRoleList(m); rv=AQH_Service_AddModule(sv, m); if (rv<0) { DBG_INFO(NULL, "here (%d)", rv); } AQH_Module_free(m); return rv; } void _createPermDefList(AQH_MODULE *m) { AQH_PERMDEF_LIST *permDefList; permDefList=AQH_PermDef_List_new(); AQH_ModService_AddPermDef(permDefList, "ModuleRead", 0x001, "Read modules"); AQH_ModService_AddPermDef(permDefList, "ModuleWrite", 0x002, "Modify modules"); AQH_ModService_AddPermDef(permDefList, "ModuleAdd", 0x004, "Add modules"); AQH_ModService_AddPermDef(permDefList, "ModuleDel", 0x008, "Remove modules"); AQH_Module_SetPermDefList(m, permDefList); } void _createRoleList(AQH_MODULE *m) { AQH_ROLE_LIST *roleList; int id=1; roleList=AQH_Role_List_new(); AQH_ModService_AddRole(roleList, id++, "admin", AQH_MODADMMODULES_PERMS_MODULESREAD | AQH_MODADMMODULES_PERMS_MODULESWRITE | AQH_MODADMMODULES_PERMS_MODULESADD | AQH_MODADMMODULES_PERMS_MODULESDEL, "Administrator Role"); AQH_Module_SetRoleList(m, roleList); } AQH_MODULE *_loadSubModule(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, const char *sModuleName) { /* no sub-modules */ return NULL; } int _handleRequest(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, const char *sLastPathElem) { AQH_ModService_HandleRequestWithTable(m, rq, session, sLastPathElem, _requestTable); return AQCGI_SendResponse(rq); } void _handleRqIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf) { AQH_SERVICE *sv; GWEN_STRINGLIST *slModules; uint32_t perms; perms=AQH_ModService_GetUserPerms(m); sv=AQH_ModService_GetService(m); slModules=AQH_Service_ListModules(sv); if (slModules) { GWEN_STRINGLISTENTRY *se; GBAS(dbuf, "

Modules

\n"); GBAS(dbuf, "\n" "" "\n" "\n" "\n"); se=GWEN_StringList_FirstEntry(slModules); while(se) { const char *sModName; sModName=GWEN_StringListEntry_Data(se); if (sModName && *sModName) { AQH_MODULE *currentMod; currentMod=AQH_Service_LoadModule(sv, sModName); if (currentMod) { const char *s; const char *sName; sName=AQH_Module_GetName(currentMod); GBAS(dbuf, ""); GBAA(dbuf, "", (unsigned long int) AQH_Module_GetId(currentMod)); GBAA(dbuf, "", sName?sName:""); s=AQH_Module_GetDescr(currentMod); GBAA(dbuf, "", s?s:""); GBAS(dbuf, "\n"); GBAA(dbuf, "\n"); AQH_Module_free(currentMod); } } se=GWEN_StringListEntry_Next(se); } GBAS(dbuf, "\n" "
IdNameDescriptionActions
%lu%s%s"); if (perms & AQH_MODADMMODULES_PERMS_MODULESWRITE) GBAA(dbuf, "", sName?sName:""); GBAA(dbuf, "
\n"); GWEN_StringList_free(slModules); } if (perms & AQH_MODADMMODULES_PERMS_MODULESADD) GBAS(dbuf, "
Add Module"); } void _handleRqEditModGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf) { AQH_SERVICE *sv; GWEN_DB_NODE *dbQuery; const char *sModName; AQH_MODULE *currentMod; sv=AQH_ModService_GetService(m); dbQuery=AQCGI_Request_GetDbQuery(rq); sModName=dbQuery?GWEN_DB_GetCharValue(dbQuery, "name", 0, NULL):NULL; currentMod=(sModName && *sModName)?AQH_Service_LoadModule(sv, sModName):NULL; if (currentMod) { _writeEditModForm(currentMod, sModName, dbuf); AQH_Module_free(currentMod); } else { AQCGI_Request_AddResponseHeaderData(rq, "Location: index.html"); AQCGI_Request_SetResponseCode(rq, 303); AQCGI_Request_SetResponseText(rq, "See other"); } } void _handleRqEditModPost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf) { AQH_SERVICE *sv; GWEN_DB_NODE *dbPost; const char *sModName; AQH_MODULE *currentMod; sv=AQH_ModService_GetService(m); dbPost=AQCGI_Request_GetDbPostBody(rq); sModName=dbPost?GWEN_DB_GetCharValue(dbPost, "module", 0, NULL):NULL; currentMod=(sModName && *sModName)?AQH_Service_LoadModule(sv, sModName):NULL; if (currentMod) { const char *sNewModName; const char *sDescr; int rv; uint32_t perms; const AQH_PERMDEF_LIST *permDefList; permDefList=AQH_Module_GetPermDefList(currentMod); sNewModName=GWEN_DB_GetCharValue(dbPost, "name", 0, NULL); sDescr=GWEN_DB_GetCharValue(dbPost, "descr", 0, NULL); perms=AQH_ModService_ReadPermsFromForm(dbPost, permDefList, NULL); if (sNewModName && *sNewModName) AQH_Module_SetName(currentMod, sNewModName); AQH_Module_SetDescr(currentMod, sDescr); AQH_Module_SetGuestPerms(currentMod, perms); rv=AQH_Service_SaveModule(sv, currentMod); if (rv<0) { GBAS(dbuf, "

Error

Error saving module

"); DBG_ERROR(NULL, "Could not save module \"%s\"", sModName); AQH_Module_free(currentMod); return; } DBG_ERROR(NULL, "Module \"%s\" saved", sModName); AQH_Module_free(currentMod); AQCGI_Request_AddResponseHeaderData(rq, "Location: index.html"); AQCGI_Request_SetResponseCode(rq, 303); AQCGI_Request_SetResponseText(rq, "See other"); } else { DBG_ERROR(NULL, "Could not load module \"%s\"", sModName?sModName:""); GBAS(dbuf, "

Error loading module.

\n"); } } void _handleRqAddRoleGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf) { AQH_SERVICE *sv; GWEN_DB_NODE *dbQuery; const char *sModName; AQH_MODULE *currentMod; const AQH_PERMDEF_LIST *permDefList; uint32_t guestPerms; sv=AQH_ModService_GetService(m); dbQuery=AQCGI_Request_GetDbQuery(rq); sModName=dbQuery?GWEN_DB_GetCharValue(dbQuery, "mod", 0, NULL):NULL; currentMod=(sModName && *sModName)?AQH_Service_LoadModule(sv, sModName):NULL; guestPerms=currentMod?AQH_Module_GetGuestPerms(currentMod):0; permDefList=currentMod?AQH_Module_GetPermDefList(currentMod):NULL; if (currentMod) { if (permDefList) { GBAA(dbuf, "

Add Role for Module %s

\n", sModName?sModName:""); GBAS(dbuf, "
\n" "\n" "" "\n"); GBAS(dbuf, "\n"); GBAS(dbuf, "
"); AQH_ModService_WritePermsToForm(guestPerms, permDefList, NULL, dbuf); GBAS(dbuf, "
\n"); GBAA(dbuf, "\n", sModName?sModName:""); GBAS(dbuf, "\n"); GBAS(dbuf, "
\n\n"); } else { GBAS(dbuf, "

Please add permission definitions first.

\n"); GBAA(dbuf, "

back to module

\n", sModName?sModName:""); } AQH_Module_free(currentMod); } else { GBAS(dbuf, "

Error loading module.

\n"); GBAS(dbuf, "

back to module list

\n"); } } void _handleRqAddRolePost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf) { AQH_SERVICE *sv; GWEN_DB_NODE *dbPost; const char *sModName; AQH_MODULE *currentMod; int newId; const char *sName; const char *sDescr; uint32_t perms; AQH_PERMDEF_LIST *permDefList; AQH_ROLE_LIST *roleList; int rv; /* sample data */ DBG_ERROR(NULL, "Handling POST request"); sv=AQH_ModService_GetService(m); dbPost=AQCGI_Request_GetDbPostBody(rq); sModName=dbPost?GWEN_DB_GetCharValue(dbPost, "mod", 0, NULL):NULL; currentMod=(sModName && *sModName)?AQH_Service_LoadModule(sv, sModName):NULL; permDefList=currentMod?AQH_Module_GetPermDefList(currentMod):NULL; roleList=currentMod?AQH_Module_GetRoleList(currentMod):NULL; /* read role values */ newId=(roleList?_getHighestUsedRoleId(roleList):0)+1; sName=dbPost?GWEN_DB_GetCharValue(dbPost, "name", 0, NULL):NULL; sDescr=dbPost?GWEN_DB_GetCharValue(dbPost, "descr", 0, NULL):NULL; perms=(dbPost && permDefList)?AQH_ModService_ReadPermsFromForm(dbPost, permDefList, NULL):0; /* validate */ if (!(sName && *sName)) { DBG_ERROR(NULL, "Missing value for \"name\""); GBAS(dbuf, "

Missing name.

\n"); GBAA(dbuf, "

back to module

\n", sModName?sModName:""); return; } if (currentMod) { AQH_ROLE *role; /* set new values */ role=AQH_Role_new(); AQH_Role_SetId(role, newId); AQH_Role_SetName(role, sName); AQH_Role_SetDescr(role, sDescr); AQH_Role_SetPerms(role, perms); /* add role */ if (roleList==NULL) { roleList=AQH_Role_List_new(); AQH_Module_SetRoleList(currentMod, roleList); } AQH_Role_List_Add(role, roleList); /* save module */ rv=AQH_Service_SaveModule(sv, currentMod); if (rv<0) { GBAS(dbuf, "

Error saving module.

\n"); GBAA(dbuf, "

back to module

\n", sModName?sModName:""); AQH_Module_free(currentMod); return; } _setLocationHeaderForMod(rq, "editmodule.html", sModName); AQCGI_Request_SetResponseCode(rq, 303); AQCGI_Request_SetResponseText(rq, "See Other"); AQH_Module_free(currentMod); } else { GBAS(dbuf, "

Error loading module.

\n"); GBAS(dbuf, "

back to module list

\n"); } } void _handleRqEditRoleGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf) { AQH_SERVICE *sv; GWEN_DB_NODE *dbQuery; const char *sModName; int id; const char *sName; const char *sDescr; uint32_t perms; AQH_MODULE *currentMod; const AQH_PERMDEF_LIST *permDefList; const AQH_ROLE_LIST *roleList; const AQH_ROLE *role; sv=AQH_ModService_GetService(m); dbQuery=AQCGI_Request_GetDbQuery(rq); sModName=dbQuery?GWEN_DB_GetCharValue(dbQuery, "mod", 0, NULL):NULL; id=dbQuery?GWEN_DB_GetIntValue(dbQuery, "id", 0, 0):0; currentMod=(sModName && *sModName)?AQH_Service_LoadModule(sv, sModName):NULL; permDefList=currentMod?AQH_Module_GetPermDefList(currentMod):NULL; roleList=currentMod?AQH_Module_GetRoleList(currentMod):NULL; role=roleList?AQH_Role_List_GetById(roleList, id):NULL; sName=role?AQH_Role_GetName(role):NULL; sDescr=role?AQH_Role_GetDescr(role):NULL; perms=role?AQH_Role_GetPerms(role):0; if (role) { GBAA(dbuf, "

Edit Role for Module %s

\n", sModName?sModName:""); GBAA(dbuf, "
\n" "\n" "\n" "\n", sName, sDescr?sDescr:""); GBAS(dbuf, "\n"); GBAS(dbuf, "
"); AQH_ModService_WritePermsToForm(perms, permDefList, NULL, dbuf); GBAS(dbuf, "
\n"); GBAA(dbuf, "\n", sModName?sModName:""); GBAA(dbuf, "\n", id); GBAS(dbuf, "\n"); GBAS(dbuf, "
\n\n"); } else { GBAS(dbuf, "

Role not found.

\n"); GBAA(dbuf, "

back to module

\n", sModName?sModName:""); } } void _handleRqEditRolePost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf) { AQH_SERVICE *sv; GWEN_DB_NODE *dbPost; const char *sModName; AQH_MODULE *currentMod; int oldId; const char *sName; const char *sDescr; uint32_t perms; AQH_PERMDEF_LIST *permDefList; AQH_ROLE_LIST *roleList; AQH_ROLE *role; int rv; /* sample data */ sv=AQH_ModService_GetService(m); dbPost=AQCGI_Request_GetDbPostBody(rq); sModName=dbPost?GWEN_DB_GetCharValue(dbPost, "mod", 0, NULL):NULL; currentMod=(sModName && *sModName)?AQH_Service_LoadModule(sv, sModName):NULL; permDefList=currentMod?AQH_Module_GetPermDefList(currentMod):NULL; roleList=currentMod?AQH_Module_GetRoleList(currentMod):NULL; /* read role data */ oldId=dbPost?GWEN_DB_GetIntValue(dbPost, "oldId", 0, -1):-1; sName=dbPost?GWEN_DB_GetCharValue(dbPost, "name", 0, NULL):NULL; sDescr=dbPost?GWEN_DB_GetCharValue(dbPost, "descr", 0, NULL):NULL; role=roleList?AQH_Role_List_GetById(roleList, oldId):NULL; perms=(dbPost && permDefList)?AQH_ModService_ReadPermsFromForm(dbPost, permDefList, NULL):0; /* validate */ if (!(sName && *sName)) { DBG_ERROR(NULL, "Missing value for \"name\""); GBAS(dbuf, "

Missing name.

\n"); GBAA(dbuf, "

back to module

\n", sModName?sModName:""); return; } if (role==NULL) { DBG_ERROR(NULL, "Role %d not found", oldId); GBAS(dbuf, "

Role not found.

\n"); GBAA(dbuf, "

back to module

\n", sModName?sModName:""); return; } if (currentMod) { /* set new values */ AQH_Role_SetName(role, sName); AQH_Role_SetDescr(role, sDescr); AQH_Role_SetPerms(role, perms); /* save module */ rv=AQH_Service_SaveModule(sv, currentMod); if (rv<0) { GBAS(dbuf, "

Error saving module.

\n"); GBAA(dbuf, "

back to module

\n", sModName?sModName:""); AQH_Module_free(currentMod); return; } _setLocationHeaderForMod(rq, "editmodule.html", sModName); AQCGI_Request_SetResponseCode(rq, 303); AQCGI_Request_SetResponseText(rq, "See Other"); AQH_Module_free(currentMod); } else { GBAS(dbuf, "

Error loading module.

\n"); GBAS(dbuf, "

back to module list

\n"); } } void _handleRqDeleteRole(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf) { AQH_SERVICE *sv; GWEN_DB_NODE *dbQuery; const char *sModName; int id; AQH_MODULE *currentMod; const AQH_ROLE_LIST *roleList; AQH_ROLE *role; sv=AQH_ModService_GetService(m); dbQuery=AQCGI_Request_GetDbQuery(rq); sModName=dbQuery?GWEN_DB_GetCharValue(dbQuery, "mod", 0, NULL):NULL; id=dbQuery?GWEN_DB_GetIntValue(dbQuery, "id", 0, 0):0; currentMod=(sModName && *sModName)?AQH_Service_LoadModule(sv, sModName):NULL; if (currentMod) { roleList=currentMod?AQH_Module_GetRoleList(currentMod):NULL; role=roleList?AQH_Role_List_GetById(roleList, id):NULL; if (role) { int rv; AQH_Role_List_Del(role); AQH_Role_free(role); /* save module */ rv=AQH_Service_SaveModule(sv, currentMod); if (rv<0) { GBAS(dbuf, "

Error saving module.

\n"); GBAA(dbuf, "

back to module

\n", sModName?sModName:""); AQH_Module_free(currentMod); return; } _setLocationHeaderForMod(rq, "editmodule.html", sModName); AQCGI_Request_SetResponseCode(rq, 303); AQCGI_Request_SetResponseText(rq, "See Other"); } else { GBAS(dbuf, "

Role not found.

\n"); GBAA(dbuf, "

back to module

\n", sModName?sModName:""); } AQH_Module_free(currentMod); } else { GBAS(dbuf, "

Error loading module.

\n"); GBAS(dbuf, "

back to module list

\n"); } } void _setLocationHeaderForMod(AQCGI_REQUEST *rq, const char *page, const char *sModName) { GWEN_BUFFER *tbuf; tbuf=GWEN_Buffer_new(0, 256, 0, 1); GBAA(tbuf, "Location: %s?name=%s", page?page:"", sModName?sModName:""); AQCGI_Request_AddResponseHeaderData(rq, GWEN_Buffer_GetStart(tbuf)); GWEN_Buffer_free(tbuf); } int _getHighestUsedRoleId(const AQH_ROLE_LIST *roleList) { int id=0; if (roleList) { const AQH_ROLE *role; role=AQH_Role_List_First(roleList); while(role) { int rid; rid=AQH_Role_GetId(role); id=(rid>id)?rid:id; role=AQH_Role_List_Next(role); } } return id; } void _writeEditModForm(const AQH_MODULE *currentMod, const char *sModName, GWEN_BUFFER *dbuf) { const char *sName; const char *sDescr; const AQH_PERMDEF_LIST *permDefList; const AQH_ROLE_LIST *roleList; permDefList=AQH_Module_GetPermDefList(currentMod); roleList=AQH_Module_GetRoleList(currentMod); sName=AQH_Module_GetName(currentMod); sDescr=AQH_Module_GetDescr(currentMod); /* write module info */ GBAS(dbuf, "

Module Info

\n"); GBAA(dbuf, "
\n" "\n" "\n" "\n", sName?sName:"", sDescr?sDescr:""); if (permDefList) { GBAA(dbuf, "\n"); } GBAS(dbuf, "
"); AQH_ModService_WritePermsToForm(AQH_Module_GetGuestPerms(currentMod), permDefList, NULL, dbuf); GBAA(dbuf, "
\n"); GBAA(dbuf, "\n", sModName?sModName:""); GBAS(dbuf, "\n
\n\n"); /* write role list */ GBAS(dbuf, "

User Roles

\n"); if (roleList) _writeRoleListToForm(roleList, sModName, permDefList, dbuf); else GBAS(dbuf, "

none

"); GBAA(dbuf, "
Add Role\n", sModName?sModName:""); } void _writeRoleListToForm(const AQH_ROLE_LIST *roleList, const char *sModName, const AQH_PERMDEF_LIST *permDefList, GWEN_BUFFER *dbuf) { const AQH_ROLE *role; GBAS(dbuf, "\n" "\n\n" "\n"); role=AQH_Role_List_First(roleList); while(role) { uint8_t id; const char *s; GBAS(dbuf, ""); /* id */ id=AQH_Role_GetId(role); GBAA(dbuf, "", id); /* name */ s=AQH_Role_GetName(role); GBAA(dbuf, "", s?s:""); /* permissions */ GBAS(dbuf, ""); /* description */ s=AQH_Role_GetDescr(role); GBAA(dbuf, "", s?s:""); /* actions */ GBAA(dbuf, ""); GBAS(dbuf, "\n"); role=AQH_Role_List_Next(role); } GBAS(dbuf, "\n
IdNamePermissionsDescriptionActions
%d%s"); if (permDefList) _writeEnabledPermissions(permDefList, AQH_Role_GetPerms(role), dbuf); GBAS(dbuf, "%s"); GBAA(dbuf, "", sModName?sModName:"", id); GBAA(dbuf, "", sModName?sModName:"", id); GBAA(dbuf, "
\n"); } void _writeEnabledPermissions(const AQH_PERMDEF_LIST *permDefList, uint32_t perms, GWEN_BUFFER *dbuf) { if (permDefList) { const AQH_PERMDEF *permDef; permDef=AQH_PermDef_List_First(permDefList); while(permDef) { const char *s; uint32_t mask; s=AQH_PermDef_GetId(permDef); mask=AQH_PermDef_GetMask(permDef); if (perms & mask) GBAA(dbuf, "%s ", s?s:""); permDef=AQH_PermDef_List_Next(permDef); } } }