adapt to latest changes, use generic request handlers.
This commit is contained in:
@@ -27,10 +27,10 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* global vars
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
#define GBAS GWEN_Buffer_AppendString
|
||||
#define GBAA GWEN_Buffer_AppendArgs
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
@@ -42,10 +42,28 @@ 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 _handleRqIndexGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf);
|
||||
static void _handleRqValuesGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf);
|
||||
|
||||
static void _runIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf);
|
||||
static void _runValues(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* vars
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static AQH_MODSERVICE_HANDLER_ENTRY _requestTable[]={
|
||||
{"index.html", AQCGI_REQUEST_METHOD_GET, AQH_MODDEVICES_PERMS_DEVICEREAD, _handleRqIndexGet},
|
||||
{"values.html", AQCGI_REQUEST_METHOD_GET, AQH_MODDEVICES_PERMS_DEVICEREAD | AQH_MODDEVICES_PERMS_VALUEREAD, _handleRqValuesGet},
|
||||
{NULL, 0, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* code
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
@@ -145,189 +163,172 @@ AQH_MODULE *_loadSubModule(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *sessio
|
||||
|
||||
int _handleRequest(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, const char *sLastPathElem)
|
||||
{
|
||||
if (strcasecmp(sLastPathElem, "index.html")==0)
|
||||
return AQH_ModDataClient_HandleRequest(m, rq, session, _runIndex);
|
||||
else if (strcasecmp(sLastPathElem, "values.html")==0)
|
||||
return AQH_ModDataClient_HandleRequest(m, rq, session, _runValues);
|
||||
else {
|
||||
AQCGI_SendResponseWithStatus(rq, 404, "Not Found");
|
||||
return GWEN_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
AQH_ModService_HandleRequestWithTable(m, rq, session, sLastPathElem, _requestTable);
|
||||
return AQCGI_SendResponse(rq);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleRqIndexGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
AQH_ModDataClient_HandleRequest(m, rq, session, _runIndex, dbuf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleRqValuesGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
AQH_ModDataClient_HandleRequest(m, rq, session, _runValues, dbuf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _runIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
uint32_t perms;
|
||||
AQH_DEVICE_LIST *deviceList;
|
||||
AQH_DEVICE *device;
|
||||
|
||||
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.");
|
||||
GWEN_Buffer_AppendString(dbuf, "<p>No devices.</p>");
|
||||
AQCGI_Request_SetResponseCode(rq, 200);
|
||||
AQCGI_Request_SetResponseText(rq, "Ok");
|
||||
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);
|
||||
deviceList=AQH_DataClient_GetDevices(dc, NULL);
|
||||
if (deviceList==NULL) {
|
||||
DBG_ERROR(NULL, "No device received");
|
||||
GBAS(dbuf, "Empty device list.");
|
||||
GBAS(dbuf, "<p>No devices.</p>");
|
||||
AQCGI_Request_SetResponseCode(rq, 200);
|
||||
AQCGI_Request_SetResponseText(rq, "Ok");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
GWEN_Buffer_AppendString(dbuf, "<p>No permissions to read devices.</p>");
|
||||
AQCGI_Request_SetResponseCode(rq, 200);
|
||||
AQCGI_Request_SetResponseText(rq, "Ok");
|
||||
|
||||
GBAS(dbuf, "<h1>Devices</h1>\n");
|
||||
GBAS(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;
|
||||
|
||||
GBAA(dbuf, "<tr>");
|
||||
/* name for system */
|
||||
s=AQH_Device_GetNameForSystem(device);
|
||||
GBAS(dbuf,"<td><a href=\"values.html?device=");
|
||||
GWEN_Text_EscapeToBufferTolerant(s, dbuf);
|
||||
GBAA(dbuf,"\">%s</a></td>", s?s:"");
|
||||
/* room */
|
||||
s=AQH_Device_GetRoomName(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* location */
|
||||
s=AQH_Device_GetLocation(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* description */
|
||||
s=AQH_Device_GetDescription(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* device type */
|
||||
s=AQH_Device_GetDeviceType(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* driver */
|
||||
s=AQH_Device_GetDriver(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* short device name */
|
||||
s=AQH_Device_GetName(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* GUI name for device */
|
||||
s=AQH_Device_GetNameForGui(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* manufacturer */
|
||||
s=AQH_Device_GetManufacturer(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
GBAA(dbuf, "</tr>");
|
||||
device=AQH_Device_List_Next(device);
|
||||
}
|
||||
|
||||
GBAS(dbuf,
|
||||
"</tbody>\n"
|
||||
"</table>\n");
|
||||
AQH_Device_List_free(deviceList);
|
||||
AQCGI_Request_SetResponseCode(rq, 200);
|
||||
AQCGI_Request_SetResponseText(rq, "Ok");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _runValues(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
uint32_t perms;
|
||||
GWEN_DB_NODE *dbQuery;
|
||||
const char *sDeviceName;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
valueList=AQH_DataClient_GetValues(dc, sDeviceName, 0);
|
||||
if (valueList) {
|
||||
AQH_VALUE *value;
|
||||
|
||||
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");
|
||||
|
||||
value=AQH_Value_List_First(valueList);
|
||||
while(value) {
|
||||
const char *s;
|
||||
|
||||
GWEN_Buffer_AppendString(dbuf, "<tr>");
|
||||
|
||||
s=AQH_Value_GetName(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_ValueModality_toString(AQH_Value_GetModality(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_GetDeviceNameForSystem(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
s=AQH_Value_GetNameForSystem(value);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
AQCGI_Request_SetResponseCode(rq, 200);
|
||||
AQCGI_Request_SetResponseText(rq, "Ok");
|
||||
}
|
||||
dbQuery=AQCGI_Request_GetDbQuery(rq);
|
||||
sDeviceName=GWEN_DB_GetCharValue(dbQuery, "device", 0, NULL);
|
||||
if (!(sDeviceName && *sDeviceName))
|
||||
_runIndex(m, rq, session, dc, dbuf);
|
||||
else {
|
||||
GWEN_Buffer_AppendString(dbuf, "<p>No permissions to read devices/values.</p>");
|
||||
AQCGI_Request_SetResponseCode(rq, 200);
|
||||
AQCGI_Request_SetResponseText(rq, "Ok");
|
||||
AQH_VALUE_LIST *valueList;
|
||||
|
||||
valueList=AQH_DataClient_GetValues(dc, sDeviceName, 0);
|
||||
if (valueList) {
|
||||
AQH_VALUE *value;
|
||||
|
||||
GBAA(dbuf, "<h1>Values for Device %s</h1>\n", sDeviceName);
|
||||
GBAS(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");
|
||||
|
||||
value=AQH_Value_List_First(valueList);
|
||||
while(value) {
|
||||
const char *s;
|
||||
|
||||
GBAS(dbuf, "<tr>");
|
||||
|
||||
s=AQH_Value_GetName(value);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
s=AQH_ValueType_toString(AQH_Value_GetValueType(value));
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
s=AQH_ValueModality_toString(AQH_Value_GetModality(value));
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
s=AQH_Value_GetDriver(value);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
s=AQH_Value_GetDeviceNameForSystem(value);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
s=AQH_Value_GetNameForSystem(value);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
GBAA(dbuf, "</tr>\n");
|
||||
|
||||
value=AQH_Value_List_Next(value);
|
||||
}
|
||||
GBAS(dbuf,
|
||||
"</tbody>\n"
|
||||
"</table>\n");
|
||||
AQH_Value_List_free(valueList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user