Example #1
0
TStr CookieExpand(TStr &Cookie, const TStr &Name)
{
		TStr c = Cookie.CopyAfter(Name + "=");
		c = c.CopyBefore(";").CopyBefore(",");
		if( c.Length() != 32 ) {
			c = Cookie.CopyAfter(Name + "=").CopyAfter(Name + "=");
			c = c.CopyBefore(";").CopyBefore(",");
		}
		if( c.Length() != 32 ) {
			c = Cookie.CopyAfter(Name + "=").CopyAfter(Name + "=").CopyAfter(Name + "=");
			c = c.CopyBefore(";").CopyBefore(",");
		}
		if( c.Length() != 32 )
			c.Clear();
		return c;
}
Example #2
0
void TDatabaseSession::ClearValue(const TStr &Cookie, const TStr &Name)
{
	if( Cookie.Length() > 0 ) {
		query->execSql("DELETE FROM tbs_session WHERE FCookie='"+Cookie+"' and FName='"+Name+"'");
		query->execSql("DELETE FROM tbs_session_blob WHERE FCookie='"+Cookie+"' and FName='"+Name+"'");
	}
}
Example #3
0
void TDatabaseSession::SaveValue(
	const TStr &Cookie,
	const TStr &Name,
	const char *Value,
	const int Size)
{
/*
NULL ASCII 0.  represent this by `\0'
\    ASCII 92, Represent this by `\\'
'    ASCII 39, Represent this by `\''
"    ASCII 34, Represent this by `\"'
*/
	if( Cookie.Length() > 0 ) {
		query->openSql("SELECT ID FROM tbs_session_blob WHERE FName='"+Name+"' and FCookie='"+Cookie+"' and to_days(fDate) > to_days(now())-"+DaySave);
		char * s = new char[Size+Size];
		mysql_escape_string(s,Value,Size);
		TStr v(s);
		delete[] s;
		if( query->eof() )
			query->execSql("INSERT INTO tbs_session_blob (FName,FCookie,FValue,FDate) VALUES ('"+Name+"','"+Cookie+"','"+v+"',now())");
		else
			query->execSql(TStr("UPDATE tbs_session_blob SET FValue='"+v+"', FDate=now() WHERE ID=")+query->fields(0));
		query->close();
	}
}
Example #4
0
bool TDatabaseSession::LoadValue(
	const TStr &Cookie,
	const TStr &Name,
	TStr  &Value)
{
	if( Cookie.Length() > 0 ) {
		query->openSql("SELECT FValue,Length(FValue) FROM tbs_session_blob WHERE FCookie='"+Cookie+"' and FName='"+Name+"' and to_days(fDate) > to_days(now())-"+DaySave);
		if( !query->eof() ) {
			Value += query->fields(0);
			return true;
		}
	}
	return false;
}
Example #5
0
void TSession::SaveValue(
	const TStr &Cookie,
	const TStr &Name,
	TSessionValue *p)
{
	TStr s;
	m_ssi::TStringList sl;
	p->SaveValues(sl);
	for( int i = 0; i < sl.Count(); i++ )
	{
		TStr l(sl.Names(i) + "=" + sl.Values(i));
		s += TStr(l.Length()) + "-" + l;
	}
	SaveValue(Cookie,Name,s.c_str(),s.Length());
}
Example #6
0
void TSession::LoadValue(
	const TStr &Cookie,
	const TStr &Name,
	TSessionValue *p)
{
	TStr s;
	if( LoadValue(Cookie,Name,s) ) {
		m_ssi::TStringList sl;
		while( s.Length() > 0 )
		{
			int Len = s.GetBefore("-").ToIntDef(0);
			TStr n(s.GetBefore(Len));
			sl.Add(n.CopyBefore("="),n.CopyAfter("="));
		}
		p->LoadValues(sl);
	}
}
Example #7
0
bool TDatabaseSession::LoadValue(
	const TStr &Cookie,
	const TStr &Name,
	char *Value,
	const int Size)
{
	if( Cookie.Length() > 0 ) {
		query->openSql("SELECT FValue,Length(FValue) FROM tbs_session_blob WHERE FCookie='"+Cookie+"' and FName='"+Name+"' and to_days(fDate) > to_days(now())-"+DaySave);
		if( !query->eof() ) {
			if( Size != StrToInt(query->fields(1)) )
				throw TExcept("LoadValue(): Size != BDSize");
			memmove(Value,query->fields(0),Size);
			return true;
		}
	}
	return false;
}
Example #8
0
void TDatabaseSession::SetValue(
	const TStr &Cookie,
	const TStr &Name,
	const TStr &Value)
{
	SetCookie(Cookie);
	if( Cookie.Length() > 0 ) {
		m_ssi::TMapItem<TStr> *p = SessionList.Find(Name);
		if( p == NULL ) {
			query->execSql("INSERT INTO tbs_session (FName,FCookie,FValue,FDate) VALUES ('"+Name+"','"+Cookie+"','"+Value+"',now())");
			SessionList.Add(Name,Value);
		} else {
			query->execSql("UPDATE tbs_session SET FValue='"+Value+"', FDate=now() WHERE FName='"+Name+"' and FCookie='"+Cookie+"'");
			p->SetValue(Value);
		}
	}
}