summaryrefslogtreecommitdiff
path: root/server/src/session.cc
diff options
context:
space:
mode:
authordeva <deva>2011-01-25 12:17:47 +0000
committerdeva <deva>2011-01-25 12:17:47 +0000
commit13f286925b1e9e34fe71413edcba23686c005f8a (patch)
treed1ea04756f6eb198fb18a367423670734e6e062a /server/src/session.cc
parent1680325095c79bd66c13e6e0bd9fb6340c83a1e0 (diff)
New database layout.
Diffstat (limited to 'server/src/session.cc')
-rw-r--r--server/src/session.cc42
1 files changed, 17 insertions, 25 deletions
diff --git a/server/src/session.cc b/server/src/session.cc
index 5fe9230..612f264 100644
--- a/server/src/session.cc
+++ b/server/src/session.cc
@@ -46,9 +46,9 @@
Session::Session(std::string sessionid)
{
- _id = sessionid;
_journal = NULL;
_database = NULL;
+ database()->setSessionId(sessionid);
}
Session::~Session()
@@ -59,7 +59,7 @@ Session::~Session()
std::string Session::id()
{
- return _id;
+ return database()->sessionId();
}
void Session::lock()
@@ -86,6 +86,13 @@ void Session::commit()
}
}
+void Session::nocommit()
+{
+ if(_database != NULL) {
+ _database->nocommit();
+ }
+}
+
void Session::discard()
{
if(_journal) {
@@ -127,13 +134,6 @@ static bool fexists(const std::string &f)
{
bool ret;
-/*
- struct stat sbuf;
- int n = stat(f.c_str(), &sbuf);
- if(n != -1) ret = true;
- ret = errno != ENOENT;
-*/
-
FILE *fp = fopen(f.c_str(), "r");
ret = fp != NULL;
if(fp) fclose(fp);
@@ -143,14 +143,7 @@ static bool fexists(const std::string &f)
Session *Sessions::newSession()
{
- char sessionid[32];
- std::string filename;
- do {
- snprintf(sessionid, sizeof(sessionid)-1, "%d", rand());
- filename = getSessionFilename(Conf::session_path, sessionid);
- } while(sessions.find(sessionid) != sessions.end() || fexists(filename));
-
- Session *session = new Session(sessionid);
+ Session *session = new Session();
sessions[session->id()] = session;
return session;
}
@@ -162,13 +155,9 @@ Session *Sessions::session(std::string sessionid)
std::string filename = getSessionFilename(Conf::session_path, sessionid);
if(fexists(filename)) {
- Session *s = new Session(sessionid);
- SessionSerialiser ser(Conf::session_path, s);
- ser.load();
+ SessionSerialiser ser(Conf::session_path);
+ Session *s = ser.load(sessionid);
sessions[s->id()] = s;
-
- fprintf(stderr, "s: %p\n",s);
-
return s;
}
@@ -177,6 +166,8 @@ Session *Sessions::session(std::string sessionid)
Session *Sessions::takeSession(std::string sessionid)
{
+ DEBUG(session,"%s\n", sessionid.c_str());
+
Session *s = NULL;
if(sessions.find(sessionid) != sessions.end()) {
s = sessions[sessionid];
@@ -185,6 +176,7 @@ Session *Sessions::takeSession(std::string sessionid)
if(s) {
sessions.erase(sessionid);
}
+ else DEBUG(session, "No such session!\n");
return s;
}
@@ -204,8 +196,8 @@ void Sessions::store()
{
std::map<std::string, Session*>::iterator i = sessions.begin();
while(i != sessions.end()) {
- SessionSerialiser ser(Conf::session_path, i->second);
- ser.save();
+ SessionSerialiser ser(Conf::session_path);
+ ser.save(i->second);
delete i->second;
sessions.erase(i);
i++;