summaryrefslogtreecommitdiff
path: root/server/src/server.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/server.cc')
-rw-r--r--server/src/server.cc23
1 files changed, 17 insertions, 6 deletions
diff --git a/server/src/server.cc b/server/src/server.cc
index d9b28a9..67ae74d 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -60,6 +60,11 @@
#include "templatelist.h"
#include "versionstr.h"
+struct conn_t {
+ Database *db;
+
+};
+
static std::string error_box(std::string message)
{
std::string errorbox =
@@ -296,7 +301,7 @@ static std::string handleTransaction(Transaction *transaction,
}
-static std::string handleConnection(char *buf, size_t size)
+static std::string handleConnection(char *buf, size_t size, struct conn_t *conn)
{
if(size == 0)
return error_box(xml_encode("Empty document received."));
@@ -306,8 +311,6 @@ static std::string handleConnection(char *buf, size_t size)
pentominos_socket.connect(Conf::pentominos_addr, Conf::pentominos_port);
#endif/*WITHOUT_PENTOMINOS*/
- Database db(Conf::database_backend, Conf::database_addr, "", Conf::database_user, Conf::database_passwd, "");
-
JournalWriter journalwriter(Conf::journal_commit_addr.c_str(), Conf::journal_commit_port);
MacroList macrolist(Conf::xml_basedir + "/macros");
@@ -322,7 +325,7 @@ static std::string handleConnection(char *buf, size_t size)
PRACRO_DEBUG(server, "Got complete XML document, %d bytes in current buffer.\n", size);
std::string res = handleTransaction(&transaction, pentominos_socket,
- db, journalwriter, macrolist, templatelist);
+ *conn->db, journalwriter, macrolist, templatelist);
journalwriter.commit();
return res;
@@ -341,12 +344,14 @@ static int handle_request(void *cls,
unsigned int *data_size,
void **ptr)
{
+ struct conn_t *conn = (struct conn_t*)cls;
+
PRACRO_DEBUG(httpd,
"handle_request(url=\"%s\", method=\"%s\","
" version=\"%s\", data_size=\"%d\")\n",
url, method, version, *data_size);
- std::string reply = handleConnection((char*)data, *data_size);
+ std::string reply = handleConnection((char*)data, *data_size, conn);
struct MHD_Response *rsp;
rsp = MHD_create_response_from_data(reply.length(), (char*)reply.c_str(), MHD_NO, MHD_YES);
@@ -404,6 +409,10 @@ void server()
PRACRO_DEBUG(server, "Server running on port %d.\n", port);
+ struct conn_t conn;
+ conn.db = new Database(Conf::database_backend, Conf::database_addr,
+ "", Conf::database_user, Conf::database_passwd, "");
+
struct MHD_Daemon *d;
d = MHD_start_daemon(MHD_USE_DEBUG
| MHD_USE_SELECT_INTERNALLY
@@ -412,7 +421,7 @@ void server()
,
port,
NULL, NULL,
- handle_request, NULL,
+ handle_request, &conn,
MHD_OPTION_NOTIFY_COMPLETED, NULL, NULL,
// MHD_OPTION_CONNECTION_LIMIT, 42,
MHD_OPTION_HTTPS_MEM_KEY, KEY,
@@ -428,6 +437,8 @@ void server()
while(pracro_is_running) sleep(1);
+ delete conn.db;
+
MHD_stop_daemon(d);
PRACRO_DEBUG(server, "Server gracefully shut down.\n");