534 lines
17 KiB
C
534 lines
17 KiB
C
/****************************************************************************
|
|
* This file is part of the project AqHome.
|
|
* AqHome (c) by 2023 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 <config.h>
|
|
#endif
|
|
|
|
|
|
#include "./u_rooms.h"
|
|
#include "./aqhomehttp.h"
|
|
#include "aqhome/http/httpservice.h"
|
|
#include "aqhome/http/httpservice_http.h"
|
|
#include "aqhome/http/httpservice_conf.h"
|
|
|
|
#include <gwenhywfar/gwenhywfar.h>
|
|
#include <gwenhywfar/debug.h>
|
|
#include <gwenhywfar/i18n.h>
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* defines
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* forward declarations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
static int _handleUrl(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq);
|
|
static GWEN_MSG *_handleGet(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq);
|
|
static GWEN_MSG *_handlePost(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq);
|
|
|
|
static void _handleGetList(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER *pageBuf);
|
|
|
|
static void _handleGetAdd(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER *pageBuf);
|
|
static void _handleGetEdit(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, int id, GWEN_BUFFER *pageBuf);
|
|
static GWEN_MSG *_handlePostAdd(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq);
|
|
static GWEN_MSG *_handlePostEdit(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, int id);
|
|
static int _writeAddPage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_DB_NODE *dbValues, GWEN_BUFFER *pageBuf);
|
|
static int _writeEditPage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_DB_NODE *dbValues, GWEN_BUFFER *pageBuf);
|
|
static GWEN_MSG *_addOrEditAndCreateResponse(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, int id);
|
|
static int _addOrEditRoom(AQH_HTTP_URLHANDLER *uh, const AQH_ROOM *newRoom, int id);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* implementations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
AQH_HTTP_URLHANDLER *AQH_RoomsHttpUrlHandler_new(AQH_SERVICE *sv)
|
|
{
|
|
AQH_HTTP_URLHANDLER *uh;
|
|
|
|
uh=AQH_HttpUrlHandler_new(sv);
|
|
AQH_HttpUrlHandler_SetHandleFn(uh, _handleUrl);
|
|
|
|
return uh;
|
|
}
|
|
|
|
|
|
|
|
int _handleUrl(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq)
|
|
{
|
|
const char *protocol;
|
|
const char *cmd;
|
|
GWEN_MSG *msgOut;
|
|
|
|
AQH_HttpService_SetupModuleAndPerms(AQH_HttpUrlHandler_GetHttpService(uh), rq, "aqhome");
|
|
AQH_HttpRequest_SetupUrlPathMembers(rq);
|
|
|
|
protocol=AQH_HttpRequest_GetProtocol(rq);
|
|
cmd=AQH_HttpRequest_GetCommand(rq);
|
|
if (cmd && *cmd) {
|
|
if (strcasecmp(cmd, "GET")==0)
|
|
msgOut=_handleGet(uh, rq);
|
|
else if (strcasecmp(cmd, "POST")==0)
|
|
msgOut=_handlePost(uh, rq);
|
|
else {
|
|
msgOut=AQH_HttpService_CreateResponseMsg(AQH_HttpUrlHandler_GetHttpService(uh), 405, "Method not allowed", protocol, NULL);
|
|
}
|
|
AQH_HttpRequest_SetResponseMsg(rq, msgOut);
|
|
return 0;
|
|
}
|
|
else {
|
|
DBG_ERROR(AQH_LOGDOMAIN, "No command in request");
|
|
return GWEN_ERROR_INVALID;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG *_handleGet(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq)
|
|
{
|
|
GWEN_BUFFER *pageBuf;
|
|
int rv;
|
|
GWEN_MSG *msgOut=NULL;
|
|
const char *protocol;
|
|
const GWEN_STRINGLIST *sl;
|
|
|
|
protocol=AQH_HttpRequest_GetProtocol(rq);
|
|
pageBuf=GWEN_Buffer_new(0, 256, 0, 1);
|
|
rv=AQH_HttpUrlHandler_AddContentHeaders(uh, AQH_HTTP_CONTENT_MODE_DESKTOP, pageBuf);
|
|
if (rv<0) {
|
|
DBG_ERROR(AQH_LOGDOMAIN, "Error adding headers");
|
|
GWEN_Buffer_free(pageBuf);
|
|
return AQH_HttpService_CreateResponseMsg(AQH_HttpUrlHandler_GetHttpService(uh), 500, "Internal Error", protocol, NULL);
|
|
}
|
|
|
|
/* handle middle part (header - middle - footer) */
|
|
sl=AQH_HttpRequest_GetUrlPathMembers(rq);
|
|
if (sl) {
|
|
const char *s;
|
|
|
|
s=GWEN_StringList_StringAt(sl, 1);
|
|
if (!(s && *s))
|
|
s="list";
|
|
|
|
if (strcasecmp(s, "list")==0)
|
|
_handleGetList(uh, rq, pageBuf);
|
|
else if (strcasecmp(s, "add")==0)
|
|
_handleGetAdd(uh, rq, pageBuf);
|
|
else if (strcasecmp(s, "edit")==0)
|
|
_handleGetEdit(uh, rq, GWEN_StringList_StringAsIntAt(sl, 2, 0), pageBuf);
|
|
else {
|
|
DBG_ERROR(NULL, "Invalid url (2nd member is [%s])", s);
|
|
GWEN_Buffer_free(pageBuf);
|
|
return AQH_HttpService_CreateResponseMsg(AQH_HttpUrlHandler_GetHttpService(uh), 404, "Not found", protocol, NULL);
|
|
}
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "No list of url members");
|
|
GWEN_Buffer_free(pageBuf);
|
|
return AQH_HttpService_CreateResponseMsg(AQH_HttpUrlHandler_GetHttpService(uh), 500, "Internal Error", protocol, NULL);
|
|
}
|
|
|
|
rv=AQH_HttpUrlHandler_AddContentFooters(uh, AQH_HTTP_CONTENT_MODE_DESKTOP, pageBuf);
|
|
if (rv<0) {
|
|
DBG_ERROR(AQH_LOGDOMAIN, "Error adding footers");
|
|
GWEN_Buffer_free(pageBuf);
|
|
return AQH_HttpService_CreateResponseMsg(AQH_HttpUrlHandler_GetHttpService(uh), 500, "Internal Error", protocol, NULL);
|
|
}
|
|
|
|
msgOut=AQH_HttpService_CreateResponseMsg(AQH_HttpUrlHandler_GetHttpService(uh), 200, "OK", protocol, GWEN_Buffer_GetStart(pageBuf));
|
|
GWEN_Buffer_free(pageBuf);
|
|
return msgOut;
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG *_handlePost(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq)
|
|
{
|
|
GWEN_DB_NODE *db;
|
|
const GWEN_STRINGLIST *sl;
|
|
const char *protocol;
|
|
|
|
DBG_ERROR(NULL, "POST:");
|
|
db=AQH_HttpRequest_GetDbPostBody(rq);
|
|
GWEN_DB_Dump(db, 2);
|
|
|
|
protocol=AQH_HttpRequest_GetProtocol(rq);
|
|
sl=AQH_HttpRequest_GetUrlPathMembers(rq);
|
|
if (sl) {
|
|
const char *s;
|
|
|
|
s=GWEN_StringList_StringAt(sl, 1);
|
|
if (s && *s) {
|
|
if (strcasecmp(s, "add")==0)
|
|
return _handlePostAdd(uh, rq);
|
|
else if (strcasecmp(s, "edit")==0)
|
|
return _handlePostEdit(uh, rq, GWEN_StringList_StringAsIntAt(sl, 2, 0));
|
|
else {
|
|
DBG_ERROR(NULL, "Invalid url (2nd member is [%s])", s);
|
|
return AQH_HttpService_CreateResponseMsg(AQH_HttpUrlHandler_GetHttpService(uh), 404, "Not found", protocol, NULL);
|
|
}
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "Invalid url (2nd member missing)");
|
|
return AQH_HttpService_CreateResponseMsg(AQH_HttpUrlHandler_GetHttpService(uh), 404, "Not found", protocol, NULL);
|
|
}
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "No list of url members");
|
|
return AQH_HttpService_CreateResponseMsg(AQH_HttpUrlHandler_GetHttpService(uh), 404, "Not found", protocol, NULL);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _handleGetList(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER *pageBuf)
|
|
{
|
|
AQH_SERVICE *sv;
|
|
uint32_t perms;
|
|
|
|
DBG_ERROR(NULL, "LIST");
|
|
perms=AQH_HttpRequest_GetModulePerms(rq);
|
|
if (perms & AQHOME_HTTP_PERMS_LIST_ROOMS) {
|
|
AQH_STORAGE *sto;
|
|
|
|
sv=AQH_HttpUrlHandler_GetHttpService(uh);
|
|
sto=AqHomeHttpService_GetStorage(sv);
|
|
if (sto) {
|
|
const AQH_ROOM_LIST *rl;
|
|
|
|
GWEN_Buffer_AppendArgs(pageBuf,
|
|
"<h2>%s</h2>"
|
|
"<table class=\"dataTable\">"
|
|
"<thead>"
|
|
" <tr><th>Id</th><th>%s</th><th>%s</th><th></th></tr>"
|
|
"</thead>",
|
|
I18N("Rooms"),
|
|
I18N("Name"),
|
|
I18N("Description"));
|
|
GWEN_Buffer_AppendString(pageBuf, "<tbody>");
|
|
rl=AQH_Storage_GetRoomList(sto);
|
|
if (rl) {
|
|
const AQH_ROOM *r;
|
|
|
|
r=AQH_Room_List_First(rl);
|
|
while(r) {
|
|
long unsigned int id;
|
|
const char *name;
|
|
const char *descr;
|
|
|
|
id=(long unsigned int) AQH_Room_GetId(r);
|
|
name=AQH_Room_GetName(r);
|
|
descr=AQH_Room_GetDescription(r);
|
|
GWEN_Buffer_AppendArgs(pageBuf,
|
|
"<tr><td>%lu</td><td>%s</td><td>%s</td>"
|
|
"<td><a href=\"/rooms/edit/%lu\">"
|
|
"<IMG src=\"/pics/edit.png\" width=32 height=32 align=left border=0></a></td>"
|
|
"</tr>",
|
|
id, name?name:"", descr?descr:"", id);
|
|
|
|
r=AQH_Room_List_Next(r);
|
|
}
|
|
}
|
|
GWEN_Buffer_AppendString(pageBuf, "</tbody>");
|
|
GWEN_Buffer_AppendArgs(pageBuf, "</table><a href=\"/rooms/add\">%s</a><br>", I18N("Add Room"));
|
|
}
|
|
else {
|
|
GWEN_Buffer_AppendString(pageBuf, "<p>Internal error.</p>");
|
|
}
|
|
}
|
|
else {
|
|
GWEN_Buffer_AppendArgs(pageBuf, "<p>%s</p>", I18N("No permissions to see list of rooms."));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _handleGetAdd(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_BUFFER *pageBuf)
|
|
{
|
|
uint32_t perms;
|
|
|
|
DBG_ERROR(NULL, "ADD");
|
|
perms=AQH_HttpRequest_GetModulePerms(rq);
|
|
if (perms & AQHOME_HTTP_PERMS_ADD_ROOM) {
|
|
_writeAddPage(uh, rq, NULL, pageBuf);
|
|
}
|
|
else {
|
|
DBG_INFO(NULL, "No permissions to add a room.");
|
|
GWEN_Buffer_AppendArgs(pageBuf, "<p><font color=\"red\">%s</font></p>", I18N("No permissions to add a room."));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _handleGetEdit(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, int id, GWEN_BUFFER *pageBuf)
|
|
{
|
|
uint32_t perms;
|
|
|
|
DBG_ERROR(NULL, "EDIT");
|
|
perms=AQH_HttpRequest_GetModulePerms(rq);
|
|
if (perms & AQHOME_HTTP_PERMS_EDIT_ROOM) {
|
|
AQH_SERVICE *sv;
|
|
AQH_STORAGE *sto;
|
|
|
|
sv=AQH_HttpUrlHandler_GetHttpService(uh);
|
|
sto=AqHomeHttpService_GetStorage(sv);
|
|
if (id>0) {
|
|
const AQH_ROOM *r;
|
|
|
|
r=AQH_Storage_GetRoomById(sto, id);
|
|
if (r) {
|
|
GWEN_DB_NODE *db;
|
|
|
|
db=GWEN_DB_Group_new("room");
|
|
AQH_Room_toDb(r, db);
|
|
_writeEditPage(uh, rq, db, pageBuf);
|
|
GWEN_DB_Group_free(db);
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "Room %d not found", id);
|
|
GWEN_Buffer_AppendArgs(pageBuf, "<p><font color=\"red\">%s</font></p>", I18N("Room not found."));
|
|
}
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "Missing room id");
|
|
GWEN_Buffer_AppendArgs(pageBuf, "<p><font color=\"red\">%s</font></p>", I18N("Missing or invalid room id."));
|
|
}
|
|
}
|
|
else {
|
|
DBG_INFO(NULL, "No permissions to edit a room.");
|
|
GWEN_Buffer_AppendArgs(pageBuf, "<p>%s</p>", I18N("No permissions to edit a room."));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int _writeAddPage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_DB_NODE *dbValues, GWEN_BUFFER *pageBuf)
|
|
{
|
|
const char *name=NULL;
|
|
const char *descr=NULL;
|
|
|
|
if (dbValues) {
|
|
name=GWEN_DB_GetCharValue(dbValues, "name", 0, NULL);
|
|
descr=GWEN_DB_GetCharValue(dbValues, "description", 0, NULL);
|
|
}
|
|
GWEN_Buffer_AppendArgs(pageBuf,
|
|
"<h2>%s</h2><br>\n"
|
|
"<form action=\"/rooms/add\" method=\"post\" enctype=\"application/x-www-form-urlencoded\">"
|
|
" <table>"
|
|
" <tr>"
|
|
" <td><label for=\"name\">%s: </label></td>"
|
|
" <td><input type=\"text\" name=\"name\" value=\"%s\" required></td>"
|
|
" </tr>"
|
|
" <tr>"
|
|
" <td><label for=\"description\">%s: </label></td>"
|
|
" <td><input type=\"text\" name=\"description\" value=\"%s\" ></td>"
|
|
" </tr>"
|
|
" </table>"
|
|
" <input type=\"submit\" value=\"%s\">"
|
|
"</form>",
|
|
I18N("Create a Room"),
|
|
I18N("Room Name"),
|
|
name?name:"",
|
|
I18N("Description"),
|
|
descr?descr:"",
|
|
I18N("Add Room"));
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int _writeEditPage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, GWEN_DB_NODE *dbValues, GWEN_BUFFER *pageBuf)
|
|
{
|
|
unsigned long int id=0;
|
|
const char *name=NULL;
|
|
const char *descr=NULL;
|
|
|
|
if (dbValues) {
|
|
id=GWEN_DB_GetIntValue(dbValues, "id", 0, 0);
|
|
name=GWEN_DB_GetCharValue(dbValues, "name", 0, NULL);
|
|
descr=GWEN_DB_GetCharValue(dbValues, "description", 0, NULL);
|
|
}
|
|
GWEN_Buffer_AppendArgs(pageBuf,
|
|
"<h2>%s</h2><br>\n"
|
|
"<form action=\"/rooms/edit/%lu\" method=\"post\" enctype=\"application/x-www-form-urlencoded\">"
|
|
" <table>"
|
|
" <tr>"
|
|
" <td><label for=\"name\">%s: </label></td>"
|
|
" <td><input type=\"text\" name=\"name\" value=\"%s\" required></td>"
|
|
" </tr>"
|
|
" <tr>"
|
|
" <td><label for=\"description\">%s: </label></td>"
|
|
" <td><input type=\"text\" name=\"description\" value=\"%s\" ></td>"
|
|
" </tr>"
|
|
" </table>"
|
|
" <input type=\"submit\" value=\"%s\">"
|
|
"</form>",
|
|
I18N("Edit a Room"),
|
|
id,
|
|
I18N("Room Name"),
|
|
name?name:"",
|
|
I18N("Description"),
|
|
descr?descr:"",
|
|
I18N("Submit"));
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG *_handlePostAdd(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq)
|
|
{
|
|
const char *protocol;
|
|
AQH_SERVICE *sv;
|
|
uint32_t perms;
|
|
|
|
protocol=AQH_HttpRequest_GetProtocol(rq);
|
|
sv=AQH_HttpUrlHandler_GetHttpService(uh);
|
|
perms=AQH_HttpRequest_GetModulePerms(rq);
|
|
if (perms & AQHOME_HTTP_PERMS_ADD_ROOM)
|
|
return _addOrEditAndCreateResponse(uh, rq, 0);
|
|
else {
|
|
return AQH_HttpService_CreateResponseMsg(sv, 403, "Forbidden", protocol, NULL);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG *_handlePostEdit(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, int id)
|
|
{
|
|
const char *protocol;
|
|
AQH_SERVICE *sv;
|
|
uint32_t perms;
|
|
|
|
protocol=AQH_HttpRequest_GetProtocol(rq);
|
|
sv=AQH_HttpUrlHandler_GetHttpService(uh);
|
|
perms=AQH_HttpRequest_GetModulePerms(rq);
|
|
if (perms & AQHOME_HTTP_PERMS_EDIT_ROOM) {
|
|
return _addOrEditAndCreateResponse(uh, rq, id);
|
|
}
|
|
else {
|
|
return AQH_HttpService_CreateResponseMsg(sv, 403, "Forbidden", protocol, NULL);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
GWEN_MSG *_addOrEditAndCreateResponse(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq, int id)
|
|
{
|
|
AQH_SERVICE *sv;
|
|
const char *protocol;
|
|
GWEN_DB_NODE *db;
|
|
AQH_ROOM *r;
|
|
int rv;
|
|
|
|
sv=AQH_HttpUrlHandler_GetHttpService(uh);
|
|
protocol=AQH_HttpRequest_GetProtocol(rq);
|
|
db=AQH_HttpRequest_GetDbPostBody(rq);
|
|
|
|
r=AQH_Room_fromDb(db);
|
|
rv=_addOrEditRoom(uh, r, id);
|
|
AQH_Room_free(r);
|
|
if (rv<0) {
|
|
switch(rv) {
|
|
case GWEN_ERROR_INVALID:
|
|
return AQH_HttpUrlHandler_CreatePageMessage(uh, rq, "red", I18N("Missing fields"), 1, db, _writeAddPage);
|
|
case GWEN_ERROR_FOUND:
|
|
return AQH_HttpUrlHandler_CreatePageMessage(uh, rq, "red", I18N("Room already exists"), 1, db, _writeEditPage);
|
|
case GWEN_ERROR_NOT_FOUND:
|
|
return AQH_HttpUrlHandler_CreatePageMessage(uh, rq, "red", I18N("Room not found"), 1, db, _writeEditPage);
|
|
case GWEN_ERROR_IO:
|
|
case GWEN_ERROR_INTERNAL:
|
|
default:
|
|
return AQH_HttpService_CreateResponseMsg(sv, 500, "Internal error", protocol, NULL);
|
|
}
|
|
}
|
|
return AQH_HttpService_CreateRedirectingResponseMsg(sv, protocol, "/rooms/list");
|
|
}
|
|
|
|
|
|
|
|
int _addOrEditRoom(AQH_HTTP_URLHANDLER *uh, const AQH_ROOM *newRoom, int id)
|
|
{
|
|
AQH_SERVICE *sv;
|
|
AQH_STORAGE *sto;
|
|
const char *roomName;
|
|
int rv;
|
|
|
|
sv=AQH_HttpUrlHandler_GetHttpService(uh);
|
|
sto=AqHomeHttpService_GetStorage(sv);
|
|
|
|
roomName=AQH_Room_GetName(newRoom);
|
|
if (!(roomName && *roomName)) {
|
|
DBG_INFO(NULL, "Missing room name");
|
|
return GWEN_ERROR_INVALID;
|
|
}
|
|
|
|
rv=AqHomeHttpService_LockStorage(sv);
|
|
if (rv<0) {
|
|
DBG_ERROR(NULL, "Error locking storage");
|
|
return GWEN_ERROR_IO;
|
|
}
|
|
|
|
if (id>0) {
|
|
AQH_ROOM *r;
|
|
|
|
r=AQH_Storage_GetRoomById(sto, id);
|
|
if (r==NULL) {
|
|
AqHomeHttpService_UnlockStorage(sv);
|
|
DBG_ERROR(NULL, "Room %d not found", id);
|
|
return GWEN_ERROR_NOT_FOUND;
|
|
}
|
|
AQH_Room_SetId(r, id);
|
|
AQH_Room_SetName(r, roomName);
|
|
AQH_Room_SetDescription(r, AQH_Room_GetDescription(newRoom));
|
|
AQH_Storage_AddRuntimeFlags(sto, AQH_STORAGE_RTFLAGS_MODIFIED);
|
|
}
|
|
else {
|
|
AQH_ROOM *r;
|
|
|
|
r=AQH_Storage_GetRoomByName(sto, roomName);
|
|
if (r) {
|
|
DBG_ERROR(NULL, "Room %s exists", roomName);
|
|
return GWEN_ERROR_FOUND;
|
|
}
|
|
AQH_Storage_AddRoom(sto, r);
|
|
AQH_Storage_AddRuntimeFlags(sto, AQH_STORAGE_RTFLAGS_MODIFIED);
|
|
}
|
|
|
|
rv=AqHomeHttpService_UnlockStorage(sv);
|
|
if (rv<0) {
|
|
DBG_ERROR(NULL, "Error unlocking storage");
|
|
return GWEN_ERROR_IO;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO: applyRoom(uh, rq, r, id)
|
|
* share code!
|
|
*
|
|
* check values
|
|
*
|
|
* if id==0:
|
|
* - lookup room
|
|
* - add room if not already found
|
|
* else
|
|
* set room data
|
|
*/
|