diff options
Diffstat (limited to 'server/src/sessionserialiser.cc')
-rw-r--r-- | server/src/sessionserialiser.cc | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/server/src/sessionserialiser.cc b/server/src/sessionserialiser.cc index 386a115..d5150ac 100644 --- a/server/src/sessionserialiser.cc +++ b/server/src/sessionserialiser.cc @@ -34,6 +34,7 @@ #include "journal.h" #include "sessionparser.h" +#include "sessionheaderparser.h" #include "database.h" #include "xml_encode_decode.h" @@ -255,25 +256,36 @@ Session *SessionSerialiser::findFromTupple(const std::string &patientid, DEBUG(sessionserialiser, "Is xml file\n"); - // Load session file - FILE *fp = fopen(filename.c_str(), "r"); - std::string xml; - while(!feof(fp)) { - char str[64]; - memset(str, 0, sizeof(str)); - fread(str, sizeof(str) - 1, 1, fp); - xml += str; + std::string pid; + std::string tpl; + + SessionHeaderParser p(filename); + try { + p.parse(); + pid = p.getPatientID(); + tpl = p.getTemplate(); + } catch( ... ) { + continue; } - fclose(fp); - Session *session = loadStr(xml); + if(patientid == pid && templ == tpl) { + // Load session file + FILE *fp = fopen(filename.c_str(), "r"); + std::string xml; + while(!feof(fp)) { + char str[64]; + memset(str, 0, sizeof(str)); + fread(str, sizeof(str) - 1, 1, fp); + xml += str; + } + fclose(fp); + + Session *session = loadStr(xml); - DEBUG(sessionserialiser, "PatientID %s - Template %s\n", - session->patientid.c_str(), - session->templ.c_str()); + DEBUG(sessionserialiser, "PatientID %s - Template %s\n", + session->patientid.c_str(), + session->templ.c_str()); - if(session->patientid == patientid && - session->templ == templ) { closedir(dir); unlink(filename.c_str()); return session; |