aqhome-cgi: added code to init aqhome-cgi environment.
This commit is contained in:
@@ -21,6 +21,8 @@
|
|||||||
--include=$(srcdir)
|
--include=$(srcdir)
|
||||||
</includes>
|
</includes>
|
||||||
|
|
||||||
|
<define name="AQHOME_CGI_WWWDIR" value="$(httpdatadir)/aqhome-cgi" quoted="TRUE" />
|
||||||
|
|
||||||
<setVar name="local/cflags">$(visibility_cflags)</setVar>
|
<setVar name="local/cflags">$(visibility_cflags)</setVar>
|
||||||
|
|
||||||
<setVar name="tm2flags" >
|
<setVar name="tm2flags" >
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
#include "./service_file.h"
|
#include "./service_file.h"
|
||||||
#include "aqhome-cgi/modules/mroot.h"
|
#include "aqhome-cgi/modules/mroot.h"
|
||||||
|
#include "aqhome-cgi/modules/common/madmin.h"
|
||||||
|
#include "aqhome-cgi/modules/common/mmodules.h"
|
||||||
|
#include "aqhome-cgi/modules/common/musers.h"
|
||||||
|
#include "aqhome-cgi/modules/mdevices.h"
|
||||||
#include "aqhome/aqhome.h"
|
#include "aqhome/aqhome.h"
|
||||||
|
|
||||||
#include <aqcgi/cgi.h>
|
#include <aqcgi/cgi.h>
|
||||||
@@ -20,22 +24,31 @@
|
|||||||
|
|
||||||
#define AQHOME_CGI_LOGFILE "/var/www/aqhome-cgi/log/aqhome-cgi.log"
|
#define AQHOME_CGI_LOGFILE "/var/www/aqhome-cgi/log/aqhome-cgi.log"
|
||||||
|
|
||||||
#define AQHOME_CGI_DEFAULT_STATIC_FILES "0-build/services/static"
|
#define AQHOME_CGI_DEFAULT_STATIC_FILES AQHOME_CGI_WWWDIR"/static"
|
||||||
#define AQHOME_CGI_DEFAULT_RUNTIME_FILES "0-build/services/runtime"
|
#define AQHOME_CGI_DEFAULT_RUNTIME_FILES AQHOME_CGI_WWWDIR"/data"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _handleRequest(AQCGI_REQUEST *rq, const char *sPathStaticFiles, const char *sPathRuntimeFiles);
|
static void _handleRequest(AQCGI_REQUEST *rq, const char *sPathStaticFiles, const char *sPathRuntimeFiles);
|
||||||
int _handlePath(AQH_SERVICE *sv, AQCGI_REQUEST *rq, const char *sPathStaticFiles);
|
static int _handlePath(AQH_SERVICE *sv, AQCGI_REQUEST *rq, const char *sPathStaticFiles);
|
||||||
AQH_MODULE *_loadModule(AQH_SERVICE *sv, AQCGI_REQUEST *rq, AQH_MODULE *mParent, const char *sModuleName);
|
|
||||||
static void logStart(void);
|
static void logStart(void);
|
||||||
|
static int _init(const char *sPathRuntimeFiles);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
GWEN_GUI *gui;
|
GWEN_GUI *gui;
|
||||||
AQCGI_REQUEST *rq;
|
const char *sPathStaticFiles;
|
||||||
|
const char *sPathRuntimeFiles;
|
||||||
|
|
||||||
|
sPathStaticFiles=getenv("AQHOME_STATIC_FILES");
|
||||||
|
if (!(sPathStaticFiles && *sPathStaticFiles))
|
||||||
|
sPathStaticFiles=AQHOME_CGI_DEFAULT_STATIC_FILES;
|
||||||
|
|
||||||
|
sPathRuntimeFiles=getenv("AQHOME_RUNTIME_FILES");
|
||||||
|
if (!(sPathRuntimeFiles && *sPathRuntimeFiles))
|
||||||
|
sPathRuntimeFiles=AQHOME_CGI_DEFAULT_RUNTIME_FILES;
|
||||||
|
|
||||||
GWEN_Init();
|
GWEN_Init();
|
||||||
gui=GWEN_NoGui_new();
|
gui=GWEN_NoGui_new();
|
||||||
@@ -51,9 +64,6 @@ int main(int argc, char **argv)
|
|||||||
GWEN_Logger_SetLevel(AQCGI_LOGDOMAIN, GWEN_LoggerLevel_Debug);
|
GWEN_Logger_SetLevel(AQCGI_LOGDOMAIN, GWEN_LoggerLevel_Debug);
|
||||||
GWEN_Logger_SetLevel(NULL, GWEN_LoggerLevel_Debug);
|
GWEN_Logger_SetLevel(NULL, GWEN_LoggerLevel_Debug);
|
||||||
|
|
||||||
DBG_ERROR(NULL, "Init CGI");
|
|
||||||
AQCGI_Init();
|
|
||||||
|
|
||||||
GWEN_Logger_Close(GWEN_LOGDOMAIN);
|
GWEN_Logger_Close(GWEN_LOGDOMAIN);
|
||||||
GWEN_Logger_Open(GWEN_LOGDOMAIN, "gwenhywfar", AQHOME_CGI_LOGFILE, GWEN_LoggerType_File, GWEN_LoggerFacility_Daemon);
|
GWEN_Logger_Open(GWEN_LOGDOMAIN, "gwenhywfar", AQHOME_CGI_LOGFILE, GWEN_LoggerType_File, GWEN_LoggerFacility_Daemon);
|
||||||
|
|
||||||
@@ -61,28 +71,33 @@ int main(int argc, char **argv)
|
|||||||
GWEN_Logger_SetLevel(AQCGI_LOGDOMAIN, GWEN_LoggerLevel_Debug);
|
GWEN_Logger_SetLevel(AQCGI_LOGDOMAIN, GWEN_LoggerLevel_Debug);
|
||||||
GWEN_Logger_SetLevel(NULL, GWEN_LoggerLevel_Debug);
|
GWEN_Logger_SetLevel(NULL, GWEN_LoggerLevel_Debug);
|
||||||
|
|
||||||
rq=AQCGI_ReadRequest();
|
if (argc>1 && argv[1]) {
|
||||||
if (rq) {
|
if (0==strcasecmp(argv[1], "init")) {
|
||||||
const char *sPathStaticFiles;
|
int rv;
|
||||||
const char *sPathRuntimeFiles;
|
|
||||||
|
|
||||||
sPathStaticFiles=getenv("AQHOME_STATIC_FILES");
|
rv=_init(sPathRuntimeFiles);
|
||||||
if (!(sPathStaticFiles && *sPathStaticFiles))
|
if (rv<0) {
|
||||||
sPathStaticFiles=AQHOME_CGI_DEFAULT_STATIC_FILES;
|
fprintf(stderr, "Error on init (%d)\n", rv);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
sPathRuntimeFiles=getenv("AQHOME_RUNTIME_FILES");
|
}
|
||||||
if (!(sPathRuntimeFiles && *sPathRuntimeFiles))
|
|
||||||
sPathRuntimeFiles=AQHOME_CGI_DEFAULT_RUNTIME_FILES;
|
|
||||||
|
|
||||||
_handleRequest(rq, sPathStaticFiles, sPathRuntimeFiles);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(stdout, "Content-type: text/plain\n\n");
|
AQCGI_REQUEST *rq;
|
||||||
fprintf(stdout, "Error: No Request!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
AQCGI_Fini();
|
DBG_ERROR(NULL, "Init CGI");
|
||||||
|
AQCGI_Init();
|
||||||
|
rq=AQCGI_ReadRequest();
|
||||||
|
if (rq) {
|
||||||
|
_handleRequest(rq, sPathStaticFiles, sPathRuntimeFiles);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fprintf(stdout, "Content-type: text/plain\n\n");
|
||||||
|
fprintf(stdout, "Error: No Request!\n");
|
||||||
|
}
|
||||||
|
AQCGI_Fini();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -184,5 +199,45 @@ void logStart()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _init(const char *sPathRuntimeFiles)
|
||||||
|
{
|
||||||
|
AQH_SERVICE *sv;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
fprintf(stdout, "Creating aqhome-cgi environment in \"%s\"\n", sPathRuntimeFiles);
|
||||||
|
sv=AQH_ServiceFiles_new(sPathRuntimeFiles);
|
||||||
|
rv=AQH_ModAdmin_Create(sv);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_ERROR(NULL, "Error creating module \"admin\"");
|
||||||
|
AQH_Service_free(sv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv=AQH_ModAdmModules_Create(sv);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_ERROR(NULL, "Error creating module \"modules\"");
|
||||||
|
AQH_Service_free(sv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv=AQH_ModAdmUsers_Create(sv);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_ERROR(NULL, "Error creating module \"users\"");
|
||||||
|
AQH_Service_free(sv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv=AQH_ModDevices_Create(sv);
|
||||||
|
if (rv<0) {
|
||||||
|
DBG_ERROR(NULL, "Error creating module \"devices\"");
|
||||||
|
AQH_Service_free(sv);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
AQH_Service_free(sv);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user