aqhome-cgi: more work
This commit is contained in:
@@ -38,6 +38,9 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
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 _runIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf);
|
||||
@@ -58,6 +61,82 @@ void AQH_ModDevices_Extend(AQH_MODULE *m, AQH_SERVICE *sv, const char *baseFolde
|
||||
|
||||
|
||||
|
||||
int AQH_ModDevices_Create(AQH_SERVICE *sv)
|
||||
{
|
||||
AQH_MODULE *m;
|
||||
int rv;
|
||||
|
||||
m=AQH_Module_new();
|
||||
AQH_Module_SetName(m, "devices");
|
||||
AQH_Module_SetDescr(m, "device 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, "DeviceRead", 0x001, "Read and list devices");
|
||||
AQH_ModService_AddPermDef(permDefList, "DeviceWrite", 0x002, "Modify devices");
|
||||
AQH_ModService_AddPermDef(permDefList, "DeviceAdd", 0x004, "Add devices");
|
||||
AQH_ModService_AddPermDef(permDefList, "DeviceDel", 0x008, "Remove devices");
|
||||
|
||||
AQH_ModService_AddPermDef(permDefList, "ValueRead", 0x010, "Read and list values");
|
||||
AQH_ModService_AddPermDef(permDefList, "ValueWrite", 0x020, "Modify values");
|
||||
AQH_ModService_AddPermDef(permDefList, "ValueAdd", 0x040, "Add values");
|
||||
AQH_ModService_AddPermDef(permDefList, "ValueDel", 0x080, "Remove values");
|
||||
AQH_ModService_AddPermDef(permDefList, "ValueSet", 0x100, "Set values");
|
||||
|
||||
AQH_Module_SetPermDefList(m, permDefList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _createRoleList(AQH_MODULE *m)
|
||||
{
|
||||
AQH_ROLE_LIST *roleList;
|
||||
int id=0;
|
||||
|
||||
roleList=AQH_Role_List_new();
|
||||
AQH_ModService_AddRole(roleList, id++, "Reader",
|
||||
AQH_MODDEVICES_PERMS_DEVICEREAD |
|
||||
AQH_MODDEVICES_PERMS_VALUEREAD,
|
||||
"Read devices and values");
|
||||
AQH_ModService_AddRole(roleList, id++, "Writer",
|
||||
AQH_MODDEVICES_PERMS_DEVICEREAD |
|
||||
AQH_MODDEVICES_PERMS_DEVICEWRITE |
|
||||
AQH_MODDEVICES_PERMS_DEVICEADD |
|
||||
AQH_MODDEVICES_PERMS_DEVICEDEL |
|
||||
AQH_MODDEVICES_PERMS_VALUEREAD |
|
||||
AQH_MODDEVICES_PERMS_VALUEWRITE |
|
||||
AQH_MODDEVICES_PERMS_VALUEADD |
|
||||
AQH_MODDEVICES_PERMS_VALUEDEL |
|
||||
AQH_MODDEVICES_PERMS_VALUESET,
|
||||
"Read and write devices and values");
|
||||
AQH_ModService_AddRole(roleList, id++, "Setter",
|
||||
AQH_MODDEVICES_PERMS_DEVICEREAD |
|
||||
AQH_MODDEVICES_PERMS_VALUEREAD |
|
||||
AQH_MODDEVICES_PERMS_VALUESET,
|
||||
"Set values");
|
||||
AQH_Module_SetRoleList(m, roleList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_MODULE *_loadSubModule(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, const char *sModuleName)
|
||||
{
|
||||
return NULL;
|
||||
@@ -81,146 +160,172 @@ int _handleRequest(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, const
|
||||
|
||||
void _runIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
AQH_DEVICE_LIST *deviceList;
|
||||
AQH_DEVICE *device;
|
||||
uint32_t perms;
|
||||
|
||||
deviceList=AQH_DataClient_GetDevices(dc, NULL);
|
||||
if (deviceList==NULL) {
|
||||
DBG_ERROR(NULL, "No device received");
|
||||
GWEN_Buffer_AppendString(dbuf, "Empty device list.");
|
||||
return;
|
||||
perms=AQH_ModService_GetUserPerms(m);
|
||||
DBG_ERROR(NULL, "Perms=%08x", perms);
|
||||
if (perms & AQH_MODDEVICES_PERMS_DEVICEREAD) {
|
||||
AQH_DEVICE_LIST *deviceList;
|
||||
AQH_DEVICE *device;
|
||||
|
||||
deviceList=AQH_DataClient_GetDevices(dc, NULL);
|
||||
if (deviceList==NULL) {
|
||||
DBG_ERROR(NULL, "No device received");
|
||||
GWEN_Buffer_AppendString(dbuf, "Empty device list.");
|
||||
return;
|
||||
}
|
||||
|
||||
GWEN_Buffer_AppendString(dbuf, "<h1>Devices</h1>\n");
|
||||
GWEN_Buffer_AppendString(dbuf,
|
||||
"<table class=\"datatable\">\n"
|
||||
"<thead>\n"
|
||||
"<tr>"
|
||||
"<th>Name For System</th>"
|
||||
"<th>Room</th>"
|
||||
"<th>Location</th>"
|
||||
"<th>Description</th>"
|
||||
"<th>Type</th>"
|
||||
"<th>Driver</th>"
|
||||
"<th>Name</th>"
|
||||
"<th>GUI Name</th>"
|
||||
"<th>Manufacturer</th>"
|
||||
"</tr>\n"
|
||||
"</thead>\n"
|
||||
"<tbody>\n");
|
||||
|
||||
device=AQH_Device_List_First(deviceList);
|
||||
while(device) {
|
||||
const char *s;
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<tr>");
|
||||
/* name for system */
|
||||
s=AQH_Device_GetNameForSystem(device);
|
||||
GWEN_Buffer_AppendString(dbuf,"<td><a href=\"values.html?device=");
|
||||
GWEN_Text_EscapeToBufferTolerant(s, dbuf);
|
||||
GWEN_Buffer_AppendArgs(dbuf,"\">%s</a></td>", s?s:"");
|
||||
/* room */
|
||||
s=AQH_Device_GetRoomName(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* location */
|
||||
s=AQH_Device_GetLocation(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* description */
|
||||
s=AQH_Device_GetDescription(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* device type */
|
||||
s=AQH_Device_GetDeviceType(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* driver */
|
||||
s=AQH_Device_GetDriver(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* short device name */
|
||||
s=AQH_Device_GetName(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* GUI name for device */
|
||||
s=AQH_Device_GetNameForGui(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* manufacturer */
|
||||
s=AQH_Device_GetManufacturer(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf, "</tr>");
|
||||
device=AQH_Device_List_Next(device);
|
||||
}
|
||||
|
||||
GWEN_Buffer_AppendString(dbuf,
|
||||
"</tbody>\n"
|
||||
"</table>\n");
|
||||
AQH_Device_List_free(deviceList);
|
||||
AQCGI_Request_SetResponseCode(rq, 200);
|
||||
AQCGI_Request_SetResponseText(rq, "Ok");
|
||||
}
|
||||
|
||||
GWEN_Buffer_AppendString(dbuf, "<h1>Devices</h1>\n");
|
||||
GWEN_Buffer_AppendString(dbuf,
|
||||
"<table class=\"datatable\">\n"
|
||||
"<thead>\n"
|
||||
"<tr>"
|
||||
"<th>Name For System</th>"
|
||||
"<th>Room</th>"
|
||||
"<th>Location</th>"
|
||||
"<th>Description</th>"
|
||||
"<th>Type</th>"
|
||||
"<th>Driver</th>"
|
||||
"<th>Name</th>"
|
||||
"<th>GUI Name</th>"
|
||||
"<th>Manufacturer</th>"
|
||||
"</tr>\n"
|
||||
"</thead>\n"
|
||||
"<tbody>\n");
|
||||
|
||||
device=AQH_Device_List_First(deviceList);
|
||||
while(device) {
|
||||
const char *s;
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<tr>");
|
||||
/* name for system */
|
||||
s=AQH_Device_GetNameForSystem(device);
|
||||
GWEN_Buffer_AppendString(dbuf,"<td><a href=\"values.html?device=");
|
||||
GWEN_Text_EscapeToBufferTolerant(s, dbuf);
|
||||
GWEN_Buffer_AppendArgs(dbuf,"\">%s</a></td>", s?s:"");
|
||||
/* room */
|
||||
s=AQH_Device_GetRoomName(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* location */
|
||||
s=AQH_Device_GetLocation(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* description */
|
||||
s=AQH_Device_GetDescription(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* device type */
|
||||
s=AQH_Device_GetDeviceType(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* driver */
|
||||
s=AQH_Device_GetDriver(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* short device name */
|
||||
s=AQH_Device_GetName(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* GUI name for device */
|
||||
s=AQH_Device_GetNameForGui(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* manufacturer */
|
||||
s=AQH_Device_GetManufacturer(device);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf, "</tr>");
|
||||
device=AQH_Device_List_Next(device);
|
||||
else {
|
||||
GWEN_Buffer_AppendString(dbuf, "<p>No permissions to read devices.</p>");
|
||||
AQCGI_Request_SetResponseCode(rq, 200);
|
||||
AQCGI_Request_SetResponseText(rq, "Ok");
|
||||
}
|
||||
|
||||
GWEN_Buffer_AppendString(dbuf,
|
||||
"</tbody>\n"
|
||||
"</table>\n");
|
||||
|
||||
AQH_Device_List_free(deviceList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _runValues(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
GWEN_DB_NODE *dbQuery;
|
||||
const char *sDeviceName;
|
||||
uint32_t perms;
|
||||
|
||||
dbQuery=AQCGI_Request_GetDbQuery(rq);
|
||||
sDeviceName=GWEN_DB_GetCharValue(dbQuery, "device", 0, NULL);
|
||||
if (!(sDeviceName && *sDeviceName))
|
||||
_runIndex(m, rq, session, dc, dbuf);
|
||||
else {
|
||||
AQH_VALUE_LIST *valueList;
|
||||
perms=AQH_ModService_GetUserPerms(m);
|
||||
DBG_ERROR(NULL, "Perms=%08x", perms);
|
||||
if ((perms & AQH_MODDEVICES_PERMS_DEVICEREAD) &&
|
||||
(perms & AQH_MODDEVICES_PERMS_VALUEREAD)) {
|
||||
GWEN_DB_NODE *dbQuery;
|
||||
const char *sDeviceName;
|
||||
|
||||
valueList=AQH_DataClient_GetValues(dc, sDeviceName, 0);
|
||||
if (valueList) {
|
||||
AQH_VALUE *value;
|
||||
dbQuery=AQCGI_Request_GetDbQuery(rq);
|
||||
sDeviceName=GWEN_DB_GetCharValue(dbQuery, "device", 0, NULL);
|
||||
if (!(sDeviceName && *sDeviceName))
|
||||
_runIndex(m, rq, session, dc, dbuf);
|
||||
else {
|
||||
AQH_VALUE_LIST *valueList;
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<h1>Values for Device %s</h1>\n", sDeviceName);
|
||||
GWEN_Buffer_AppendString(dbuf,
|
||||
"<table class=\"datatable\">\n"
|
||||
"<thead>"
|
||||
"<tr>"
|
||||
"<th>Name</th>"
|
||||
"<th>Type</th>"
|
||||
"<th>Modality</th>"
|
||||
"<th>Driver</th>"
|
||||
"<th>Device</th>"
|
||||
"<th>Name for System</th>"
|
||||
"</tr>"
|
||||
"</thead>\n"
|
||||
"<tbody>\n");
|
||||
valueList=AQH_DataClient_GetValues(dc, sDeviceName, 0);
|
||||
if (valueList) {
|
||||
AQH_VALUE *value;
|
||||
|
||||
value=AQH_Value_List_First(valueList);
|
||||
while(value) {
|
||||
const char *s;
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<h1>Values for Device %s</h1>\n", sDeviceName);
|
||||
GWEN_Buffer_AppendString(dbuf,
|
||||
"<table class=\"datatable\">\n"
|
||||
"<thead>"
|
||||
"<tr>"
|
||||
"<th>Name</th>"
|
||||
"<th>Type</th>"
|
||||
"<th>Modality</th>"
|
||||
"<th>Driver</th>"
|
||||
"<th>Device</th>"
|
||||
"<th>Name for System</th>"
|
||||
"</tr>"
|
||||
"</thead>\n"
|
||||
"<tbody>\n");
|
||||
|
||||
GWEN_Buffer_AppendString(dbuf, "<tr>");
|
||||
value=AQH_Value_List_First(valueList);
|
||||
while(value) {
|
||||
const char *s;
|
||||
|
||||
s=AQH_Value_GetName(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
GWEN_Buffer_AppendString(dbuf, "<tr>");
|
||||
|
||||
s=AQH_ValueType_toString(AQH_Value_GetValueType(value));
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
s=AQH_Value_GetName(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
s=AQH_ValueModality_toString(AQH_Value_GetModality(value));
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
s=AQH_ValueType_toString(AQH_Value_GetValueType(value));
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
s=AQH_Value_GetDriver(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
s=AQH_ValueModality_toString(AQH_Value_GetModality(value));
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
s=AQH_Value_GetDeviceNameForSystem(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
s=AQH_Value_GetDriver(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
s=AQH_Value_GetNameForSystem(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
s=AQH_Value_GetDeviceNameForSystem(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
GWEN_Buffer_AppendArgs(dbuf, "</tr>\n");
|
||||
s=AQH_Value_GetNameForSystem(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
value=AQH_Value_List_Next(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "</tr>\n");
|
||||
|
||||
value=AQH_Value_List_Next(value);
|
||||
}
|
||||
GWEN_Buffer_AppendString(dbuf,
|
||||
"</tbody>\n"
|
||||
"</table>\n");
|
||||
AQH_Value_List_free(valueList);
|
||||
}
|
||||
GWEN_Buffer_AppendString(dbuf,
|
||||
"</tbody>\n"
|
||||
"</table>\n");
|
||||
AQH_Value_List_free(valueList);
|
||||
}
|
||||
AQCGI_Request_SetResponseCode(rq, 200);
|
||||
AQCGI_Request_SetResponseText(rq, "Ok");
|
||||
}
|
||||
else {
|
||||
GWEN_Buffer_AppendString(dbuf, "<p>No permissions to read devices/values.</p>");
|
||||
AQCGI_Request_SetResponseCode(rq, 200);
|
||||
AQCGI_Request_SetResponseText(rq, "Ok");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user