added: SessionContainer special container used by SessionManager

sessions are indexed by id and time (last used time)
changed: old sessions are deleted
       parameter: session_max_iddle in the config file
added: function 'who'


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@483 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2009-01-31 06:53:36 +00:00
parent a48766871d
commit 7d73d048c8
29 changed files with 540 additions and 61 deletions

View File

@@ -10,20 +10,10 @@
#include "sessionmanager.h"
bool SessionManager::IsSession(long s)
bool SessionManager::IsSession(long id)
{
SessionTable::iterator i;
Session temp;
temp.id = s;
i = session_table.find(temp);
if( i == session_table.end() )
if( session_table.FindById(id) == session_table.End() )
return false;
return true;
}
@@ -61,19 +51,19 @@ return id;
void SessionManager::CreateTemporarySession()
{
Session s;
SessionContainer::Iterator i = session_table.FindById( 0 );
s.id = 0;
SessionTable::iterator i = session_table.find( s ); // looking for id=0
if( i == session_table.end() )
if( i == session_table.End() )
{
std::pair<SessionTable::iterator,bool> res = session_table.insert(s);
request.session = const_cast<Session*>( &(*res.first) );
Session s;
s.id = 0;
session_table.PushBack(s);
request.session = &session_table.Back();
}
else
{
request.session = const_cast<Session*>( &(*i) );
request.session = &(*i);
}
}
@@ -87,15 +77,13 @@ int attempts = 100;
{
s.id = CreateSessionId();
std::pair<SessionTable::iterator,bool> res = session_table.insert(s);
bool added = session_table.PushBack(s);
if( res.second == true )
if( added )
{
// the insertion took place
request.session = const_cast<Session*>( &(*res.first) );
request.session = &session_table.Back();
request.SetCookie(data.http_session_id_name.c_str(), request.session->id);
log << log2 << "SM: created a new session: " << s.id << logend;
log << log2 << "SM: created a new session: " << request.session->id << logend;
return;
}
@@ -119,15 +107,16 @@ void SessionManager::SetSession()
}
else
{
Session temp;
temp.id = atol(i->second.c_str());
SessionTable::iterator s = session_table.find(temp);
long id = atol(i->second.c_str());
SessionContainer::Iterator s = session_table.FindById(id);
if( s != session_table.end() )
if( s != session_table.End() )
{
// that session is in the table
request.session = const_cast<Session*>( &(*s) );
request.session = &(*s);
session_table.UpdateLastTime(s, std::time(0));
log << log2 << "SM: session: " << s->id;
if( request.session->puser )
@@ -153,10 +142,23 @@ void SessionManager::SetSession()
SessionContainer::Iterator SessionManager::SessionBegin()
{
return session_table.Begin();
}
SessionContainer::Iterator SessionManager::SessionEnd()
{
return session_table.End();
}
void SessionManager::DeleteOldSessions()
{
session_table.DelFirstByTimeInterval(data.session_max_iddle);
}