addd urlhandler for static content, more reusing of code.

This commit is contained in:
Martin Preuss
2023-08-10 01:45:12 +02:00
parent b9a54b8ffb
commit 9b0122e34c
13 changed files with 624 additions and 31 deletions

View File

@@ -16,6 +16,7 @@
#include "./aqhomehttp.h"
#include "./u_login.h"
#include "./u_rooms.h"
#include "./u_static.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/ipc/endpoint_ipc.h"
@@ -72,6 +73,7 @@ static GWEN_MSG_ENDPOINT *_acceptHttpFn(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKET *sk,
static int _createUrlHandler_login(AQHOME_STORAGE *aqh);
static int _createUrlHandler_rooms(AQHOME_STORAGE *aqh);
static int _createUrlHandler_static(AQHOME_STORAGE *aqh);
@@ -116,6 +118,12 @@ int AqHomeStorage_SetupHttp(AQHOME_STORAGE *aqh, GWEN_DB_NODE *dbArgs)
return rv;
}
rv=_createUrlHandler_static(aqh);
if (rv<0) {
DBG_INFO(NULL, "here (%d)", rv);
return rv;
}
}
return 0;
}
@@ -241,4 +249,24 @@ int _createUrlHandler_rooms(AQHOME_STORAGE *aqh)
int _createUrlHandler_static(AQHOME_STORAGE *aqh)
{
AQH_HTTP_URLHANDLER *uh;
GWEN_BUFFER *nameBuf;
const char *sourceFolder;
sourceFolder=AQH_HttpService_GetSourceFolder(aqh->httpService);
nameBuf=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Buffer_AppendString(nameBuf, sourceFolder);
GWEN_Buffer_AppendString(nameBuf, GWEN_DIR_SEPARATOR_S AQHOME_STORAGE_STATIC_RELFOLDER GWEN_DIR_SEPARATOR_S "pics");
uh=AQH_StaticHttpUrlHandler_new(aqh->httpService, GWEN_Buffer_GetStart(nameBuf));
GWEN_Buffer_free(nameBuf);
AQH_HttpUrlHandler_AddUrlPattern(uh, "/pics/*");
AQH_HttpService_AddUrlHandler(aqh->httpService, uh);
return 0;
}