diff --git a/apps/aqhome-storage/u_rooms.c b/apps/aqhome-storage/u_rooms.c index 1401d13..ea3f499 100644 --- a/apps/aqhome-storage/u_rooms.c +++ b/apps/aqhome-storage/u_rooms.c @@ -18,15 +18,23 @@ #include "aqhome/http/httpservice_conf.h" #include -#include #include -#include -#include -#include -#include +#include +/* ------------------------------------------------------------------------------------------------ + * defines + * ------------------------------------------------------------------------------------------------ + */ + + + +/* ------------------------------------------------------------------------------------------------ + * forward declarations + * ------------------------------------------------------------------------------------------------ + */ + static int _handleUrl(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq); static int _handleGet(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq); static int _handlePost(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq); @@ -35,10 +43,14 @@ static void _handleGetList(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_B static void _handleGetAdd(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER *pageBuf); static int _handlePostAdd(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq); -static int _writeAddPage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER *pageBuf); +static int _writeAddPage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_DB_NODE *dbValues, GWEN_BUFFER *pageBuf); +/* ------------------------------------------------------------------------------------------------ + * implementations + * ------------------------------------------------------------------------------------------------ + */ AQH_HTTP_URLHANDLER *AQH_RoomsHttpUrlHandler_new(AQH_SERVICE *sv) { @@ -211,9 +223,13 @@ void _handleGetList(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER * if (sto) { const AQH_ROOM_LIST *rl; - GWEN_Buffer_AppendString(pageBuf, "

Rooms

"); - GWEN_Buffer_AppendString(pageBuf, ""); - GWEN_Buffer_AppendString(pageBuf, ""); + GWEN_Buffer_AppendArgs(pageBuf, + "

%s

" + "
IdNameDescription
" + " ", + I18N("Rooms"), + I18N("Name"), + I18N("Description")); rl=AQH_Storage_GetRoomList(sto); if (rl) { const AQH_ROOM *r; @@ -232,15 +248,14 @@ void _handleGetList(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER * r=AQH_Room_List_Next(r); } } - GWEN_Buffer_AppendString(pageBuf, "
Id%s%s
"); - GWEN_Buffer_AppendString(pageBuf, "Add Room
"); + GWEN_Buffer_AppendArgs(pageBuf, "%s
", I18N("Add Room")); } else { GWEN_Buffer_AppendString(pageBuf, "

Internal error.

"); } } else { - GWEN_Buffer_AppendString(pageBuf, "

No permissions to see list of rooms.

"); + GWEN_Buffer_AppendArgs(pageBuf, "

%s

", I18N("No permissions to see list of rooms.")); } } @@ -253,7 +268,7 @@ void _handleGetAdd(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER *p DBG_ERROR(NULL, "ADD"); perms=AQH_HttpRequest_GetModulePerms(rq); if (perms & AQHOME_HTTP_PERMS_ADD_ROOM) { - _writeAddPage(uh, rq, pageBuf); + _writeAddPage(uh, rq, NULL, pageBuf); } else { DBG_INFO(NULL, "No permissions to add a room."); @@ -263,18 +278,36 @@ void _handleGetAdd(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER *p -int _writeAddPage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER *pageBuf) +int _writeAddPage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_DB_NODE *dbValues, GWEN_BUFFER *pageBuf) { - int rv; - int pos; + const char *name=NULL; + const char *descr=NULL; - pos=GWEN_Buffer_GetPos(pageBuf); - rv=AQH_HttpService_AddFile(AQH_HttpUrlHandler_GetHttpService(uh), NULL, "roomadd.html", pageBuf); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error reading file \"roomadd.html\""); - GWEN_Buffer_Crop(pageBuf, 0, pos); - GWEN_Buffer_AppendString(pageBuf, "

Internal error.

"); + if (dbValues) { + name=GWEN_DB_GetCharValue(dbValues, "name", 0, NULL); + descr=GWEN_DB_GetCharValue(dbValues, "description", 0, NULL); } + GWEN_Buffer_AppendArgs(pageBuf, + "

%s


\n" + "
" + " " + " " + " " + " " + " " + " " + " " + " " + " " + "
" + " " + "
", + I18N("Create a Room"), + I18N("Room Name"), + name?name:"", + I18N("Description"), + descr?descr:"", + I18N("Add Room")); return 0; } @@ -298,11 +331,11 @@ int _handlePostAdd(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq) db=AQH_HttpRequest_GetDbPostBody(rq); - roomName=GWEN_DB_GetCharValue(db, "roomname", 0, NULL); - roomDescr=GWEN_DB_GetCharValue(db, "descr", 0, NULL); + roomName=GWEN_DB_GetCharValue(db, "name", 0, NULL); + roomDescr=GWEN_DB_GetCharValue(db, "description", 0, NULL); if (!(roomName && *roomName)) { - msgOut=AQH_HttpUrlHandler_CreatePageMessage(uh, rq, "red", "Missing room name", 1, _writeAddPage); + msgOut=AQH_HttpUrlHandler_CreatePageMessage(uh, rq, "red", I18N("Missing room name"), 1, db, _writeAddPage); AQH_HttpRequest_SetResponseMsg(rq, msgOut); return 0; } @@ -316,7 +349,7 @@ int _handlePostAdd(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq) if (roomDescr && *roomDescr) AQH_Room_SetDescription(r, roomDescr); if (AQH_Storage_GetRoomByName(sto, roomName)!=NULL) { - msgOut=AQH_HttpUrlHandler_CreatePageMessage(uh, rq, "red", "Room already exists", 1, _writeAddPage); + msgOut=AQH_HttpUrlHandler_CreatePageMessage(uh, rq, "red", I18N("Room already exists"), 1, db, _writeAddPage); AQH_HttpRequest_SetResponseMsg(rq, msgOut); return 0; } diff --git a/aqhome/http/urlhandler.c b/aqhome/http/urlhandler.c index 0f78f7d..26d0706 100644 --- a/aqhome/http/urlhandler.c +++ b/aqhome/http/urlhandler.c @@ -143,6 +143,7 @@ GWEN_MSG *AQH_HttpUrlHandler_CreatePageMessage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, const char *statusTextColor, const char *statusMsg, int withHeadersAndFooters, + GWEN_DB_NODE *dbValues, AQH_HTTP_URLHANDLER_WRITEPAGE_CB cb) { GWEN_BUFFER *pageBuf; @@ -164,7 +165,7 @@ GWEN_MSG *AQH_HttpUrlHandler_CreatePageMessage(AQH_HTTP_URLHANDLER *uh, if (statusMsg) GWEN_Buffer_AppendArgs(pageBuf, "

%s

", statusTextColor?statusTextColor:"black", statusMsg); if (cb) { - rv=cb(uh, rq, pageBuf); + rv=cb(uh, rq, dbValues, pageBuf); if (rv<0) { DBG_ERROR(AQH_LOGDOMAIN, "Error adding headers"); GWEN_Buffer_free(pageBuf); diff --git a/aqhome/http/urlhandler.h b/aqhome/http/urlhandler.h index 5cce3ad..1946555 100644 --- a/aqhome/http/urlhandler.h +++ b/aqhome/http/urlhandler.h @@ -51,11 +51,13 @@ AQHOME_API int AQH_HttpUrlHandler_HandleMessage(AQH_HTTP_URLHANDLER *uh, AQH_HTT typedef int (*AQH_HTTP_URLHANDLER_WRITEPAGE_CB)(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, + GWEN_DB_NODE *dbValues, GWEN_BUFFER *pageBuf); AQHOME_API GWEN_MSG *AQH_HttpUrlHandler_CreatePageMessage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, const char *statusTextColor, const char *statusMsg, int withHeadersAndFooters, + GWEN_DB_NODE *dbValues, AQH_HTTP_URLHANDLER_WRITEPAGE_CB cb);