diff options
author | deva <deva> | 2011-02-04 07:35:10 +0000 |
---|---|---|
committer | deva <deva> | 2011-02-04 07:35:10 +0000 |
commit | 9ec9a98e83076bb339d1d546fa445b2420e5a4fb (patch) | |
tree | d507ac2dff3825719c6557a672ad8eb64c303e18 /server/src/server.cc | |
parent | e137415d0e0325d143b69a9917d8ebba411b3c12 (diff) |
A new connection handling mechanism.
Diffstat (limited to 'server/src/server.cc')
-rw-r--r-- | server/src/server.cc | 70 |
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: |