summaryrefslogtreecommitdiff
path: root/server/src/sessionserialiser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/sessionserialiser.cc')
-rw-r--r--server/src/sessionserialiser.cc24
1 files changed, 14 insertions, 10 deletions
diff --git a/server/src/sessionserialiser.cc b/server/src/sessionserialiser.cc
index 9489bd7..b816331 100644
--- a/server/src/sessionserialiser.cc
+++ b/server/src/sessionserialiser.cc
@@ -52,9 +52,8 @@ static std::string itostr(int i)
return sid;
}
-SessionSerialiser::SessionSerialiser(std::string path, Session *session)
+SessionSerialiser::SessionSerialiser(std::string path)
{
- this->session = session;
this->path = path;
}
@@ -64,12 +63,14 @@ SessionSerialiser::SessionSerialiser(std::string path, Session *session)
//#define BENC(s) base64encode(s)
//#define BDEC(s) base64decode(s)
-void SessionSerialiser::loadStr(const std::string &xml)
+Session *SessionSerialiser::loadStr(const std::string &xml,
+ const std::string &sessionid)
{
// SessionAutolock lock(*session);
SessionParser parser;
parser.parse(xml.data(), xml.length());
+ Session *session = new Session(sessionid);
Journal *j = session->journal();
j->setUser(XDEC(parser.userid));
j->setPatientID(XDEC(parser.patientid));
@@ -80,9 +81,11 @@ void SessionSerialiser::loadStr(const std::string &xml)
}
session->database()->restore(XDEC(parser.database));
+
+ return session;
}
-std::string SessionSerialiser::saveStr()
+std::string SessionSerialiser::saveStr(Session *session)
{
// SessionAutolock lock(*session);
@@ -121,10 +124,10 @@ std::string SessionSerialiser::saveStr()
return xml;
}
-void SessionSerialiser::load()
+Session *SessionSerialiser::load(const std::string &sessionid)
{
// read xml from file
- std::string filename = getSessionFilename(path, session->id());
+ std::string filename = getSessionFilename(path, sessionid);
FILE *fp = fopen(filename.c_str(), "r");
std::string xml;
@@ -136,18 +139,19 @@ void SessionSerialiser::load()
}
fclose(fp);
- loadStr(xml);
+ Session *session = loadStr(xml, sessionid);
// delete file
unlink(filename.c_str());
-
+
+ return session;
}
-void SessionSerialiser::save()
+void SessionSerialiser::save(Session *session)
{
std::string filename = getSessionFilename(path, session->id());
- std::string xml = saveStr();
+ std::string xml = saveStr(session);
// write xml to file
FILE *fp = fopen(filename.c_str(), "w");