2009-04-16 03:59:42 +02:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2009-04-16 03:59:42 +02:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "lastcontainer.h"
|
2009-04-21 22:50:55 +02:00
|
|
|
#include "log.h"
|
2010-10-24 01:12:47 +02:00
|
|
|
#include "misc.h"
|
2009-04-16 03:59:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
LastItem::LastItem()
|
|
|
|
{
|
|
|
|
user_id = 0;
|
|
|
|
ip = 0;
|
|
|
|
session_id = 0;
|
|
|
|
memset((char*)&start, 0, sizeof(start));
|
|
|
|
memset((char*)&end, 0, sizeof(end));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LastItem::IsLoggedOut()
|
|
|
|
{
|
|
|
|
if( end.tm_sec == 0 &&
|
|
|
|
end.tm_min == 0 &&
|
|
|
|
end.tm_hour == 0 &&
|
|
|
|
end.tm_mday == 0 &&
|
|
|
|
end.tm_mon == 0 &&
|
|
|
|
end.tm_year == 0 )
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LastContainer::Iterator LastContainer::Begin()
|
|
|
|
{
|
|
|
|
return last_tab.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LastContainer::Iterator LastContainer::End()
|
|
|
|
{
|
|
|
|
return last_tab.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LastContainer::Iterator LastContainer::FindNotLoggedOut(long user_id, long session_id)
|
|
|
|
{
|
|
|
|
LastTab::iterator i;
|
|
|
|
|
|
|
|
for(i=last_tab.begin() ; i!=last_tab.end() ; ++i)
|
|
|
|
{
|
|
|
|
if( i->user_id == user_id && i->session_id == session_id && !i->IsLoggedOut() )
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return last_tab.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
void LastContainer::UserLogin(long user_id, const std::wstring & name, unsigned int ip, long session_id)
|
2009-04-16 03:59:42 +02:00
|
|
|
{
|
|
|
|
LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
|
|
|
|
|
|
|
|
if( i != last_tab.end() )
|
|
|
|
{
|
|
|
|
log << log1 << "LC: such a user and session_id exist, not added as a new one" << logend;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
added: uptime winix function prints how many sessions there are
changed: functions for text/numbers conversions
int Toi(const std::string & str, int base = 10);
int Toi(const std::wstring & str, int base = 10);
int Toi(const char * str, int base = 10);
int Toi(const wchar_t * str, int base = 10);
long Tol(const std::string & str, int base = 10);
long Tol(const std::wstring & str, int base = 10);
long Tol(const char * str, int base = 10);
long Tol(const wchar_t * str, int base = 10);
template<class CharType>
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10);
template<class CharType>
bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10);
const wchar_t * Toa(unsigned int value, int base = 10);
const wchar_t * Toa(unsigned long value, int base = 10);
const wchar_t * Toa(int value, int base = 10);
const wchar_t * Toa(long value, int base = 10);
void Toa(int value, std::string & res, int base = 10, bool clear = true);
void Toa(long value, std::string & res, int base = 10, bool clear = true);
void Toa(int value, std::wstring & res, int base = 10, bool clear = true);
void Toa(long value, std::wstring & res, int base = 10, bool clear = true);
added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates)
this is a special stream for automatically escaping html tags
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
|
|
|
if( last_tab.size() >= LAST_TABLE_SIZE ) // last_tab has O(n) complexity
|
2009-04-16 03:59:42 +02:00
|
|
|
last_tab.erase(last_tab.begin());
|
|
|
|
|
|
|
|
LastItem li;
|
|
|
|
|
|
|
|
li.user_id = user_id;
|
|
|
|
li.name = name;
|
|
|
|
li.ip = ip;
|
|
|
|
li.session_id = session_id;
|
2010-10-24 01:12:47 +02:00
|
|
|
li.start = Time(std::time(0));
|
2009-04-16 03:59:42 +02:00
|
|
|
|
|
|
|
last_tab.insert(last_tab.end(), li);
|
|
|
|
|
|
|
|
log << log2 << "LC: added user: " << name << " into the last table" << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LastContainer::UserLogout(long user_id, long session_id)
|
|
|
|
{
|
|
|
|
LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
|
|
|
|
|
|
|
|
if( i != last_tab.end() )
|
|
|
|
{
|
2010-10-24 01:12:47 +02:00
|
|
|
i->end = Time(std::time(0));
|
2009-04-16 03:59:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log << log1 << "LC: there is no such a user to log out" << logend;
|
|
|
|
}
|
|
|
|
}
|