/**************************************************************************** * 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 "./mroot_p.h" #include "./mdevices.h" #include "aqhome-cgi/service/module.h" #include "aqhome-cgi/modules/mdataclient.h" #include #include #include /* ------------------------------------------------------------------------------------------------ * defs and enums * ------------------------------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------------------------------ * global vars * ------------------------------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------------------------------ * forward declarations * ------------------------------------------------------------------------------------------------ */ 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); static void _runValues(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf); /* ------------------------------------------------------------------------------------------------ * code * ------------------------------------------------------------------------------------------------ */ void AQH_ModDevices_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); } AQH_MODULE *_loadSubModule(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, const char *sModuleName) { return NULL; } 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; } } void _runIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf) { 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, "

Devices

\n"); GWEN_Buffer_AppendString(dbuf, "\n" "\n" "" "" "" "" "" "" "" "" "" "" "\n" "\n" "\n"); device=AQH_Device_List_First(deviceList); while(device) { const char *s; GWEN_Buffer_AppendArgs(dbuf, ""); /* name for system */ s=AQH_Device_GetNameForSystem(device); GWEN_Buffer_AppendString(dbuf,"", s?s:""); /* room */ s=AQH_Device_GetRoomName(device); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); /* location */ s=AQH_Device_GetLocation(device); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); /* description */ s=AQH_Device_GetDescription(device); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); /* device type */ s=AQH_Device_GetDeviceType(device); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); /* driver */ s=AQH_Device_GetDriver(device); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); /* short device name */ s=AQH_Device_GetName(device); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); /* GUI name for device */ s=AQH_Device_GetNameForGui(device); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); /* manufacturer */ s=AQH_Device_GetManufacturer(device); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); GWEN_Buffer_AppendArgs(dbuf, ""); device=AQH_Device_List_Next(device); } GWEN_Buffer_AppendString(dbuf, "\n" "
Name For SystemRoomLocationDescriptionTypeDriverNameGUI NameManufacturer
%s%s%s%s%s%s%s%s%s
\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; 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, "

Values for Device %s

\n", sDeviceName); GWEN_Buffer_AppendString(dbuf, "\n" "" "" "" "" "" "" "" "" "\n" "\n"); value=AQH_Value_List_First(valueList); while(value) { const char *s; GWEN_Buffer_AppendString(dbuf, ""); s=AQH_Value_GetName(value); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); s=AQH_ValueType_toString(AQH_Value_GetValueType(value)); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); s=AQH_Value_GetDriver(value); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); s=AQH_Value_GetDeviceNameForSystem(value); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); s=AQH_Value_GetNameForSystem(value); GWEN_Buffer_AppendArgs(dbuf, "", s?s:""); GWEN_Buffer_AppendArgs(dbuf, "\n"); value=AQH_Value_List_Next(value); } GWEN_Buffer_AppendString(dbuf, "\n" "
NameTypeDriverDeviceName for System
%s%s%s%s%s
\n"); AQH_Value_List_free(valueList); } } }