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.cc70
1 files changed, 45 insertions, 25 deletions
diff --git a/server/src/server.cc b/server/src/server.cc
index 6474fb5..1665bbf 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -32,7 +32,10 @@
#include "httpd.h"
#include "configuration.h"
#include "environment.h"
+
#include "connection.h"
+#include "client_connection.h"
+#include "admin_connection.h"
class PracroHttpd : public Httpd {
public:
@@ -51,52 +54,69 @@ public:
void *begin(const std::string &url,
const std::string &method,
const std::string &version,
+ headers_t &getargs,
headers_t &headers)
{
- std::string sessionid;
- std::string patientid;
- std::string templ;
- if(headers.contains("SessionID")) sessionid = headers["SessionID"];
- if(headers.contains("SessionPatientID"))
- patientid = headers["SessionPatientID"];
- if(headers.contains("SessionTemplate")) templ = headers["SessionTemplate"];
-
- bool commit = headers.contains("SessionCommit");
- bool nocommit = headers.contains("SessionNoCommit");
- bool discard = headers.contains("SessionDiscard");
+ Connection *connection = NULL;
+
+ if(headers.find("User-Agent") != headers.end() &&
+ headers["User-Agent"].find("Pracro") == std::string::npos) { // Admin
+ connection = new AdminConnection(env, getargs);
+ } 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 *connection = new Connection(env, sessionid, patientid, templ,
- commit, discard, nocommit);
+ connection = new ClientConnection(env, parms);
+ }
return connection;
}
bool data(void *ptr, const char *data, unsigned int data_size)
{
- Connection *connection = (Connection *)ptr;
- connection->handle(data, data_size);
+ if(ptr) {
+ Connection *connection = (Connection *)ptr;
+ connection->handle(data, data_size);
+ }
return true;
}
bool complete(void *ptr, Httpd::Reply &reply)
{
- Connection *connection = (Connection *)ptr;
+ if(ptr) {
+ Connection *connection = (Connection *)ptr;
- // Flush and do commit/discard
- connection->handle(NULL, 0);
+ // Flush and do commit/discard
+ 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'
+
+ }
- reply.data = connection->getResponse();
- reply.headers["Content-Type"] = "text/plain; charset=UTF-8";
- reply.headers["SessionID"] = connection->getSessionID();
- reply.status = 200; // http 'OK'
-
return true;
}
void cleanup(void *ptr)
{
- Connection *connection = (Connection *)ptr;
- delete connection;
+ if(ptr) {
+ Connection *connection = (Connection *)ptr;
+ delete connection;
+ }
}
private: