summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/admin_connection.cc34
-rw-r--r--server/src/admin_connection.h3
-rw-r--r--server/src/admin_rc.cc18
-rw-r--r--server/src/client_connection.cc33
-rw-r--r--server/src/client_connection.h5
-rw-r--r--server/src/server.cc25
6 files changed, 64 insertions, 54 deletions
diff --git a/server/src/admin_connection.cc b/server/src/admin_connection.cc
index 21fe331..ae427a3 100644
--- a/server/src/admin_connection.cc
+++ b/server/src/admin_connection.cc
@@ -46,11 +46,6 @@ static std::string admin_sessionunlock(Environment &env, std::string id)
return "Session " + id + " does not exist or has been committed.";
}
-static std::string admin_favicon()
-{
- return admin_rc("favicon");
-}
-
AdminConnection::AdminConnection(Environment &e, headers_t a, std::string u)
: env(e), args(a), uri(u) {}
@@ -61,13 +56,22 @@ bool AdminConnection::handle(const char *data, size_t size)
if(data == NULL && size == 0) {
DEBUG(admin, "URI: %s\n", uri.c_str());
+ if(uri == "/") {
+ reply = admin_rc("header") +
+ "Command list:\n"
+ "/sessionunlock?id=[ID] unlock session with [ID] as its session id.\n"
+ + admin_rc("footer");
+ return true;
+ }
+
if(uri == "/sessionunlock" && args.find("id") != args.end()) {
- reply = admin_sessionunlock(env, args["id"]);
+ reply = admin_rc("header") + admin_sessionunlock(env, args["id"])
+ + admin_rc("footer");
return true;
}
if(uri == "/favicon.ico") {
- reply = admin_favicon();
+ reply = admin_rc("favicon");
return true;
}
@@ -78,18 +82,16 @@ bool AdminConnection::handle(const char *data, size_t size)
return true;
}
-std::string AdminConnection::getResponse()
-{
- return reply;
-}
-
-headers_t AdminConnection::getHeaders()
+void AdminConnection::getReply(Httpd::Reply &r)
{
headers_t hdrs;
- hdrs["Content-Type"] = "text/plain; charset=UTF-8";
- return hdrs;
-}
+ if(uri == "/favicon.ico") hdrs["Content-Type"] = "image/ico";
+ else hdrs["Content-Type"] = "text/html; charset=UTF-8";
+ r.data = reply;
+ r.headers = hdrs;
+ r.status = 200; // http 'OK'
+}
#ifdef TEST_ADMIN_CONNECTION
//deps:
diff --git a/server/src/admin_connection.h b/server/src/admin_connection.h
index c3f70b7..1533d79 100644
--- a/server/src/admin_connection.h
+++ b/server/src/admin_connection.h
@@ -40,8 +40,7 @@ public:
bool handle(const char *data, size_t size);
- std::string getResponse();
- headers_t getHeaders();
+ void getReply(Httpd::Reply &reply);
private:
Environment &env;
diff --git a/server/src/admin_rc.cc b/server/src/admin_rc.cc
index 495647b..ebf733e 100644
--- a/server/src/admin_rc.cc
+++ b/server/src/admin_rc.cc
@@ -389,9 +389,27 @@ static const char favicon[] = {
0x07, 0xff, 0xff
};
+static const char header[] =
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\""
+ " \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+ "<head>\n"
+ " <title>Pracro admin</title>\n"
+ " <link rel=\"shortcut icon\" href=\"/favicon.ico\"/>\n"
+ " </head>\n"
+ " <body>\n"
+ " <pre>";
+
+static const char footer[] =
+ "</pre>\n"
+ " </body>\n"
+ "</html>\n";
+
std::string admin_rc(std::string key)
{
std::string val;
if(key == "favicon") val.append(favicon, faviconsize);
+ if(key == "header") val = header;
+ if(key == "footer") val = footer;
return val;
}
diff --git a/server/src/client_connection.cc b/server/src/client_connection.cc
index af70916..9689ac4 100644
--- a/server/src/client_connection.cc
+++ b/server/src/client_connection.cc
@@ -54,11 +54,22 @@ ClientConnection::Parameters::Parameters()
nocommit = false;
}
-ClientConnection::ClientConnection(Environment &e, Parameters p)
- : parms(p), env(e), parser(&transaction)
+ClientConnection::ClientConnection(Environment &e, headers_t &headers)
+ : env(e), parser(&transaction)
{
DEBUG(connection, "[%p] CREATE\n", this);
+ if(headers.contains("SessionID"))
+ parms.sessionid = headers["SessionID"];
+ if(headers.contains("SessionPatientID"))
+ parms.patientid = headers["SessionPatientID"];
+ if(headers.contains("SessionTemplate"))
+ parms.templ = headers["SessionTemplate"];
+
+ parms.commit = headers.contains("SessionCommit");
+ parms.nocommit = headers.contains("SessionNoCommit");
+ parms.discard = headers.contains("SessionDiscard");
+
#ifdef TEST_CONNECTION
did_commit = false;
#endif
@@ -183,21 +194,21 @@ bool ClientConnection::handle(const char *data, size_t size)
return false;
}
-std::string ClientConnection::getResponse()
-{
- if(parser_complete == false)
- return error_box(xml_encode("XML Parser need more data."));
- return response;
-}
-
-headers_t ClientConnection::getHeaders()
+void ClientConnection::getReply(Httpd::Reply &reply)
{
headers_t hdrs;
hdrs["Content-Type"] = "text/plain; charset=UTF-8";
hdrs["SessionID"] = parms.sessionid;
- return hdrs;
+ reply.headers = hdrs;
+
+ if(parser_complete == false)
+ reply.data = error_box(xml_encode("XML Parser need more data."));
+ else
+ reply.data = response;
+
+ reply.status = 200; // http 'OK'
}
#ifdef TEST_CLIENT_CONNECTION
diff --git a/server/src/client_connection.h b/server/src/client_connection.h
index 69e6fe7..6427217 100644
--- a/server/src/client_connection.h
+++ b/server/src/client_connection.h
@@ -51,13 +51,12 @@ public:
bool nocommit;
};
- ClientConnection(Environment &e, Parameters cp);
+ ClientConnection(Environment &e, headers_t &headers);
~ClientConnection();
bool handle(const char *data, size_t size);
- std::string getResponse();
- headers_t getHeaders();
+ void getReply(Httpd::Reply &reply);
private:
void commit(Session *session);
diff --git a/server/src/server.cc b/server/src/server.cc
index 745b77b..d9daf3a 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -63,19 +63,7 @@ public:
headers["User-Agent"].find("Pracro") == std::string::npos) { // Admin
connection = new AdminConnection(env, getargs, url);
} else { // Pracro client
- ClientConnection::Parameters parms;
- if(headers.contains("SessionID"))
- parms.sessionid = headers["SessionID"];
- if(headers.contains("SessionPatientID"))
- parms.patientid = headers["SessionPatientID"];
- if(headers.contains("SessionTemplate"))
- parms.templ = headers["SessionTemplate"];
-
- parms.commit = headers.contains("SessionCommit");
- parms.nocommit = headers.contains("SessionNoCommit");
- parms.discard = headers.contains("SessionDiscard");
-
- connection = new ClientConnection(env, parms);
+ connection = new ClientConnection(env, headers);
}
return connection;
@@ -95,17 +83,10 @@ public:
if(ptr) {
Connection *connection = (Connection *)ptr;
- // Flush and do commit/discard
+ // Flush and do commit/discards
connection->handle(NULL, 0);
- reply.data = connection->getResponse();
- reply.headers = connection->getHeaders();
- reply.status = 200; // http 'OK'
- } else {
-
- reply.data = "Admin";
- reply.status = 200; // http 'OK'
-
+ connection->getReply(reply);
}
return true;