diff options
author | deva <deva> | 2011-02-10 10:15:25 +0000 |
---|---|---|
committer | deva <deva> | 2011-02-10 10:15:25 +0000 |
commit | c1f0cdeb919864e0f93fcfecb8c27d889b473acb (patch) | |
tree | 51d11a58f1a24d79af66be46e2332e498d9f53fd /server/src/client_connection.cc | |
parent | 35472208a495541f2e5be866e6f55242d34506ba (diff) |
Some cleaning up. Added activeSessions.
Diffstat (limited to 'server/src/client_connection.cc')
-rw-r--r-- | server/src/client_connection.cc | 110 |
1 files changed, 53 insertions, 57 deletions
diff --git a/server/src/client_connection.cc b/server/src/client_connection.cc index 9689ac4..5aee707 100644 --- a/server/src/client_connection.cc +++ b/server/src/client_connection.cc @@ -40,37 +40,27 @@ static std::string error_box(std::string message) return errorbox; } -#ifdef TEST_CONNECTION +#ifdef TEST_CLIENT_CONNECTION static bool did_commit = false; #endif -ClientConnection::Parameters::Parameters() -{ - sessionid = ""; - patientid = ""; - templ = ""; - commit = false; - discard = false; - nocommit = false; -} - 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"]; + sessionid = headers["SessionID"]; if(headers.contains("SessionPatientID")) - parms.patientid = headers["SessionPatientID"]; + patientid = headers["SessionPatientID"]; if(headers.contains("SessionTemplate")) - parms.templ = headers["SessionTemplate"]; + templ = headers["SessionTemplate"]; - parms.commit = headers.contains("SessionCommit"); - parms.nocommit = headers.contains("SessionNoCommit"); - parms.discard = headers.contains("SessionDiscard"); + docommit = headers.contains("SessionCommit"); + donocommit = headers.contains("SessionNoCommit"); + dodiscard = headers.contains("SessionDiscard"); -#ifdef TEST_CONNECTION +#ifdef TEST_CLIENT_CONNECTION did_commit = false; #endif @@ -84,23 +74,23 @@ ClientConnection::~ClientConnection() void ClientConnection::nocommit(Session *session) { - if(parms.nocommit) { + if(donocommit) { if(session->isreadonly) { // NoCommit of an empty session discards it. - parms.discard = true; + dodiscard = true; return; } DEBUG(connection, "NoCommit (%s)\n", session->id().c_str()); - parms.nocommit = false; + donocommit = false; session->nocommit(); } } void ClientConnection::commit(Session *session) { - if(parms.commit) { + if(docommit) { if(session->isreadonly) { // Commit of an empty session discards it. - parms.discard = true; + dodiscard = true; return; } @@ -108,9 +98,9 @@ void ClientConnection::commit(Session *session) std::string sid = session->id(); session->commit(); env.sessions.deleteSession(sid); - parms.sessionid = ""; - parms.commit = false; -#ifdef TEST_CONNECTION + sessionid = ""; + docommit = false; +#ifdef TEST_CLIENT_CONNECTION did_commit = true; #endif } @@ -118,13 +108,13 @@ void ClientConnection::commit(Session *session) void ClientConnection::discard(Session *session) { - if(parms.discard) { + if(dodiscard) { DEBUG(connection, "Discard (%s)\n", session->id().c_str()); std::string sid = session->id(); session->discard(); env.sessions.deleteSession(sid); - parms.sessionid = ""; - parms.discard = false; + sessionid = ""; + dodiscard = false; } } @@ -132,18 +122,16 @@ bool ClientConnection::handle(const char *data, size_t size) { Session *session = NULL; try { - if(parms.sessionid == "") { + if(sessionid == "") { // Create new session - session = env.sessions.newSession(parms.patientid, - parms.templ); + session = env.sessions.newSession(patientid, templ); } else { // Attach to old session - session = env.sessions.session(parms.sessionid); + session = env.sessions.session(sessionid); // Session didn't exist - create a new one anyway. if(session == NULL) { - session = env.sessions.newSession(parms.patientid, - parms.templ); + session = env.sessions.newSession(patientid, templ); } } } catch(Sessions::SessionAlreadyActive &e) { @@ -159,7 +147,7 @@ bool ClientConnection::handle(const char *data, size_t size) return true; } - parms.sessionid = session->id(); + sessionid = session->id(); try { @@ -199,7 +187,7 @@ void ClientConnection::getReply(Httpd::Reply &reply) headers_t hdrs; hdrs["Content-Type"] = "text/plain; charset=UTF-8"; - hdrs["SessionID"] = parms.sessionid; + hdrs["SessionID"] = sessionid; reply.headers = hdrs; @@ -212,11 +200,11 @@ void ClientConnection::getReply(Httpd::Reply &reply) } #ifdef TEST_CLIENT_CONNECTION -//deps: debug.cc transactionparser.cc session.cc xml_encode_decode.cc saxparser.cc transactionhandler.cc journal.cc mutex.cc templateparser.cc exception.cc configuration.cc macroparser.cc semaphore.cc entitylist.cc luaquerymapper.cc inotify.cc log.cc queryhandlerpentominos.cc widgetgenerator.cc queryhandlerpracro.cc resumeparser.cc journal_commit.cc versionstr.cc luaresume.cc luautil.cc artefact.cc environment.cc database.cc macrolist.cc templatelist.cc pracrodao.cc templateheaderparser.cc macroheaderparser.cc pracrodaotest.cc pracrodaopgsql.cc +//deps: debug.cc transactionparser.cc session.cc xml_encode_decode.cc saxparser.cc transactionhandler.cc journal.cc mutex.cc templateparser.cc exception.cc configuration.cc macroparser.cc semaphore.cc entitylist.cc luaquerymapper.cc inotify.cc log.cc queryhandlerpentominos.cc widgetgenerator.cc queryhandlerpracro.cc resumeparser.cc journal_commit.cc versionstr.cc luaresume.cc luautil.cc artefact.cc environment.cc database.cc macrolist.cc templatelist.cc pracrodao.cc templateheaderparser.cc macroheaderparser.cc pracrodaotest.cc pracrodaopgsql.cc journal_uploadserver.cc sessionserialiser.cc sessionparser.cc widgetvalue.cc //cflags: -DWITHOUT_DATABASE -DWITHOUT_ARTEFACT -I.. $(LUA_CFLAGS) $(EXPAT_CFLAGS) $(PTHREAD_CFLAGS) $(PQXX_CXXFLAGS) //libs: $(LUA_LIBS) $(EXPAT_LIBS) $(PTHREAD_LIBS) $(PQXX_LIBS) #include "test.h" - +/* static char xml_request[] = "<?xml version='1.0' encoding='UTF-8'?>\n" "<pracro version=\"1.0\" user=\"testuser\" cpr=\"1505050505\">\n" @@ -248,48 +236,56 @@ static char xml_commit_p2[] = " </commit>\n" "</pracro>\n" ; - +*/ TEST_BEGIN; Environment env; +Httpd::Reply reply; std::string sid; // Without data { - ClientConnection con(env, "", false); + headers_t hdrs; + ClientConnection con(env, hdrs); TEST_TRUE(con.handle("", 0), "Test handler return value."); - TEST_EQUAL_STR(con.getResponse(), "", "Test response value."); - sid = con.getSessionID(); - TEST_NOTEQUAL_STR(sid, "", "Test new session id."); + con.getReply(reply); + TEST_EQUAL_STR(reply.data, "", "Test response value."); + TEST_NOTEQUAL_STR(reply.headers["SessionID"], "", "Test new session id."); TEST_FALSE(did_commit, "No commit."); } { - ClientConnection con(env, sid, false); + headers_t hdrs; + ClientConnection con(env, hdrs); TEST_TRUE(con.handle("", 0), "Test handler return value."); - TEST_EQUAL_STR(con.getResponse(), "", "Test response value."); - TEST_NOTEQUAL_STR(con.getSessionID(), "", "Test existing session id."); - TEST_EQUAL_STR(con.getSessionID(), sid, "Test existing session id."); + con.getReply(reply); + TEST_EQUAL_STR(reply.data, "", "Test response value."); + TEST_NOTEQUAL_STR(reply.headers["SessionID"], "", "Test existing session id."); + TEST_EQUAL_STR(reply.headers["SessionID"], sid, "Test existing session id."); TEST_FALSE(did_commit, "No commit."); } { - ClientConnection con(env, sid, true); + headers_t hdrs; + ClientConnection con(env, hdrs); TEST_TRUE(con.handle("", 0), "Test handler return value."); - TEST_EQUAL_STR(con.getResponse(), "", "Test response value."); - TEST_EQUAL_STR(con.getSessionID(), "", "Test existing session id."); + con.getReply(reply); + TEST_EQUAL_STR(reply.data, "", "Test response value."); + TEST_EQUAL_STR(reply.headers["SessionID"], "", "Test existing session id."); TEST_TRUE(did_commit, "Commit."); } { - ClientConnection con(env, sid, false); + headers_t hdrs; + ClientConnection con(env, hdrs); TEST_TRUE(con.handle("", 0), "Test handler return value."); - TEST_EQUAL_STR(con.getResponse(), "", "Test response value."); - TEST_NOTEQUAL_STR(con.getSessionID(), "", "Test existing session id."); - TEST_NOTEQUAL_STR(con.getSessionID(), sid, "Test new session id."); + con.getReply(reply); + TEST_EQUAL_STR(reply.data, "", "Test response value."); + TEST_NOTEQUAL_STR(reply.headers["SessionID"], "", "Test existing session id."); + TEST_NOTEQUAL_STR(reply.headers["SessionID"], sid, "Test new session id."); TEST_FALSE(did_commit, "No commit."); } - +/* // With commit partial data { ClientConnection con(env, "", false); @@ -400,7 +396,7 @@ std::string sid; TEST_NOTEQUAL_STR(con.getSessionID(), sid, "Test new session id."); TEST_FALSE(did_commit, "No commit."); } - +*/ TEST_END; #endif/*TEST_CLIENT_CONNECTION*/ |