From: Gonzalo A. <ga...@us...> - 2006-09-12 00:25:50
|
Update of /cvsroot/mod-c/ehtml/src In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv2869/src Modified Files: DiskSessionDriver.cpp Log Message: * Cosmetic change: id.hex() is coded in a single place (eaiser to update in the near future). * Cosmetic change in DiskSessionDriver::Get(). * Bugfix: the session has to be created with the propper ID. * Bugfix: inconsistent session data has to get triggered. * Bugfix: expiration calculation was wrong. * Bugfix: DiskSessionDriver::Release: is rename(old,new), not rename(new,old). Index: DiskSessionDriver.cpp =================================================================== RCS file: /cvsroot/mod-c/ehtml/src/DiskSessionDriver.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DiskSessionDriver.cpp 8 Sep 2006 14:30:59 -0000 1.1 --- DiskSessionDriver.cpp 12 Sep 2006 00:25:19 -0000 1.2 *************** *** 15,20 **** uint32_t collect_prob; time_t old_enough; ! string filename(const string& id); ! string locked_filename(const string& id); public: DiskSessionDriver(): connected(false), collect_prob(1), old_enough(86400) { ; } --- 15,20 ---- uint32_t collect_prob; time_t old_enough; ! string filename(const SessionID& id); ! string locked_filename(const SessionID& id); public: DiskSessionDriver(): connected(false), collect_prob(1), old_enough(86400) { ; } *************** *** 34,43 **** }; ! string DiskSessionDriver::filename(const string& hexid) { ! return spool + "/" + hexid; } ! string DiskSessionDriver::locked_filename(const string& hexid) { ! return filename(hexid) + ",$$"; } --- 34,43 ---- }; ! string DiskSessionDriver::filename(const SessionID& id) { ! return spool + "/" + id.hex(); } ! string DiskSessionDriver::locked_filename(const SessionID& id) { ! return filename(id) + ",$$"; } *************** *** 114,129 **** return NULL; mayBeCollect(); ! string name = filename(id.hex()); ! string lname = locked_filename(id.hex()); ! if (rename(name.c_str(), lname.c_str())) return NULL; ! Session* dev = new Session(); ifstream in(lname.c_str()); ! in >> *dev; if (!in.eof()) { delete dev; return NULL; } ! if (dev->Expires() < time(NULL)) { unlink(lname.c_str()); delete dev; --- 114,142 ---- return NULL; mayBeCollect(); ! string name = filename(id); ! string lname = locked_filename(id); ! printf("name %s / %s\n", name.c_str(), lname.c_str()); ! if (rename(name.c_str(), lname.c_str())) { ! printf("Error: stale session (id=%s, rename error=%s)\n", ! id.hex().c_str(), strerror(errno)); return NULL; ! } ! Session* dev = new Session(id); ifstream in(lname.c_str()); ! try { ! in >> *dev; ! } catch (const char*) { ! printf("Error: corrupt session state (id=%s)\n", id.hex().c_str()); ! delete dev; ! return NULL; ! } if (!in.eof()) { + printf("Error: corrupt session state (%s)\n", id.hex().c_str()); delete dev; return NULL; } ! if (dev->Expired()) { ! printf("Error: expired session (id=%s, expires=%lu, now=%lu)\n", ! id.hex().c_str(), dev->Expires(), time(NULL)); unlink(lname.c_str()); delete dev; *************** *** 137,141 **** if (!connected) return false; ! string lfile = locked_filename(s->ID().hex()); ofstream out(lfile.c_str()); if (!out) --- 150,154 ---- if (!connected) return false; ! string lfile = locked_filename(s->ID()); ofstream out(lfile.c_str()); if (!out) *************** *** 148,153 **** if (!connected) return false; ! unlink(filename(s->ID().hex()).c_str()); ! unlink(locked_filename(s->ID().hex()).c_str()); } --- 161,166 ---- if (!connected) return false; ! unlink(filename(s->ID()).c_str()); ! unlink(locked_filename(s->ID()).c_str()); } *************** *** 155,160 **** if (!connected) return false; ! return rename(locked_filename(s->ID().hex()).c_str(), ! filename(s->ID().hex()).c_str()) == 0 ? true : false; } --- 168,176 ---- if (!connected) return false; ! string name(filename(s->ID())); ! string lname(locked_filename(s->ID())); ! int status = rename(lname.c_str(), name.c_str()); ! printf("rename(%s,%s): %d\n", lname.c_str(), name.c_str(), status); ! return status ? false : true; } |