rewritten: sessions management
(Session, SessionContainer, SessionManager) now a Session object don't copy all fields in its copy constructor (only id) the rest fields are set after the object is inserted in SessionContainer added: after successfully login a session id is changed added: plugin.Call() methods with a first argument a pointer to a Session object git-svn-id: svn://ttmath.org/publicrep/winix/trunk@823 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -44,43 +44,52 @@ Table::iterator i = table.begin();
|
||||
|
||||
log << log3 << "SC: deleting all sessions" << logend;
|
||||
|
||||
cur->session = tmp_session;
|
||||
|
||||
// don't use table.clear();
|
||||
// because plugins session data would not be erased
|
||||
// we must set cur->session for each session and then delete it
|
||||
while( i != table.end() )
|
||||
{
|
||||
cur->session = &(*i);
|
||||
cur->session->plugin_data.DeleteAll(); // it's better to call it here instead of the destructor
|
||||
i->plugin_data.DeleteAll(); // it's better to call it here instead in the destructor
|
||||
table.erase(i++);
|
||||
}
|
||||
|
||||
// erasing indexes
|
||||
index_id.clear();
|
||||
table_size = 0;
|
||||
cur->session = tmp_session;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionContainer::EraseById(IdIterator i)
|
||||
void SessionContainer::EraseById(long id)
|
||||
{
|
||||
Session * old_session = tmp_session;
|
||||
IndexId::iterator i = index_id.find(id);
|
||||
|
||||
if( cur->session != &(*i->second) )
|
||||
old_session = cur->session;
|
||||
if( i != index_id.end() )
|
||||
{
|
||||
Session * old_session = tmp_session;
|
||||
|
||||
cur->session = &(*i->second);
|
||||
if( cur->session != &(*i->second) )
|
||||
old_session = cur->session;
|
||||
|
||||
log << log4 << "SC: deleting session, id: " << i->second->id << logend;
|
||||
cur->session = &(*i->second);
|
||||
|
||||
// call first DeleteAll() because if not then it would be called from the desctructor
|
||||
// and there'll be a problem if it throws an exception there
|
||||
i->second->plugin_data.DeleteAll();
|
||||
table.erase(i->second);
|
||||
index_id.erase(i);
|
||||
table_size -= 1;
|
||||
log << log4 << "SC: deleting session, id: " << i->second->id << logend;
|
||||
|
||||
cur->session = old_session;
|
||||
// call first DeleteAll() because if not then it would be called from the destructor
|
||||
// and there'll be a problem if it throws an exception there
|
||||
i->second->plugin_data.DeleteAll();
|
||||
table.erase(i->second);
|
||||
index_id.erase(i);
|
||||
table_size -= 1;
|
||||
|
||||
cur->session = old_session;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "SC: I cannot delete a session with id: " << id
|
||||
<< " (there is no such a session)" << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,23 +132,24 @@ SessionContainer::IdIterator SessionContainer::IdEnd()
|
||||
|
||||
|
||||
|
||||
bool SessionContainer::PushBack(const Session & session)
|
||||
SessionContainer::Iterator SessionContainer::AddSession(long id)
|
||||
{
|
||||
std::pair<IndexId::iterator, bool> index_id_res = index_id.insert( std::make_pair(session.id, table.end()) );
|
||||
std::pair<IndexId::iterator, bool> index_id_res = index_id.insert( std::make_pair(id, table.end()) );
|
||||
|
||||
if( !index_id_res.second )
|
||||
{
|
||||
// that element already exists (was not inserted now)
|
||||
return false;
|
||||
return End();
|
||||
}
|
||||
|
||||
Iterator last = table.insert(table.end(), session);
|
||||
Iterator last = table.insert(table.end(), empty_session);
|
||||
last->id = id;
|
||||
index_id_res.first->second = last;
|
||||
table_size += 1;
|
||||
|
||||
log << log3 << "SC: added session, id: " << session.id << logend;
|
||||
log << log3 << "SC: added session, id: " << id << logend;
|
||||
|
||||
return true;
|
||||
return last;
|
||||
}
|
||||
|
||||
|
||||
@@ -158,6 +168,41 @@ return i->second;
|
||||
}
|
||||
|
||||
|
||||
bool SessionContainer::ChangeSessionId(SessionContainer::Iterator ses, long new_id)
|
||||
{
|
||||
std::pair<IndexId::iterator, bool> index_id_res = index_id.insert( std::make_pair(new_id, ses) );
|
||||
|
||||
if( !index_id_res.second )
|
||||
{
|
||||
log << log1 << "SC: session with id: " << new_id << " already exists" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
long old_id = ses->id;
|
||||
index_id.erase(old_id); // remove the old index
|
||||
ses->id = new_id;
|
||||
log << log3 << "SC: changed session id from: " << old_id << " to " << new_id << logend;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SessionContainer::ChangeSessionId(long old_id, long new_id)
|
||||
{
|
||||
IndexId::iterator i = index_id.find(old_id);
|
||||
|
||||
if( i != index_id.end() )
|
||||
{
|
||||
return ChangeSessionId(i->second, new_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log2 << "SC: there is no a session with id: " << old_id << logend;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user