* added: class HTMLFilter
files: htmlfilter.h htmlfilter.cpp this is an html filter used to make the html output looking better this is a very lightweight filter (without using any dynamic memory - some memory is allocated only at the beginning - in ctors) this filter has O(n) complexity over the whole html string * added: antyspamming method if the POST request is sent too fast after the GET it is treated as a spam only for no logged users and only in 'emacs' and 'createthread' functions git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@534 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -6,7 +6,8 @@ config.o: config.h ../confparser/confparser.h log.h data.h dirs.h item.h
|
||||
config.o: dircontainer.h users.h user.h ugcontainer.h groups.h group.h
|
||||
config.o: functions.h function.h lastcontainer.h mounts.h mount.h rebus.h
|
||||
config.o: plugin.h request.h requesttypes.h session.h done.h error.h thread.h
|
||||
config.o: compress.h acceptencodingparser.h acceptbaseparser.h pluginmsg.h
|
||||
config.o: compress.h acceptencodingparser.h acceptbaseparser.h htmlfilter.h
|
||||
config.o: pluginmsg.h
|
||||
data.o: data.h dirs.h item.h dircontainer.h users.h user.h ugcontainer.h
|
||||
data.o: log.h groups.h group.h functions.h function.h lastcontainer.h
|
||||
data.o: mounts.h mount.h rebus.h
|
||||
@@ -27,9 +28,11 @@ functionparser.o: dirs.h dircontainer.h users.h user.h ugcontainer.h groups.h
|
||||
functionparser.o: group.h functions.h function.h lastcontainer.h mounts.h
|
||||
functionparser.o: mount.h rebus.h db.h thread.h request.h session.h done.h
|
||||
functionparser.o: compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
functionparser.o: htmlfilter.h
|
||||
functions.o: functions.h function.h item.h
|
||||
groups.o: groups.h group.h ugcontainer.h log.h db.h item.h user.h thread.h
|
||||
groups.o: error.h dircontainer.h
|
||||
htmlfilter.o: htmlfilter.h
|
||||
httpsimpleparser.o: httpsimpleparser.h
|
||||
lastcontainer.o: lastcontainer.h log.h
|
||||
log.o: log.h
|
||||
@@ -42,22 +45,22 @@ mounts.o: mounts.h mount.h data.h dirs.h item.h dircontainer.h users.h user.h
|
||||
mounts.o: ugcontainer.h log.h groups.h group.h functions.h function.h
|
||||
mounts.o: lastcontainer.h rebus.h request.h requesttypes.h session.h done.h
|
||||
mounts.o: error.h thread.h compress.h acceptencodingparser.h
|
||||
mounts.o: acceptbaseparser.h mountparser.h db.h
|
||||
mounts.o: acceptbaseparser.h htmlfilter.h mountparser.h db.h
|
||||
notify.o: log.h notify.h ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||
notify.o: data.h dirs.h item.h dircontainer.h users.h user.h ugcontainer.h
|
||||
notify.o: groups.h group.h functions.h function.h lastcontainer.h mounts.h
|
||||
notify.o: mount.h rebus.h misc.h request.h requesttypes.h session.h done.h
|
||||
notify.o: error.h thread.h compress.h acceptencodingparser.h
|
||||
notify.o: acceptbaseparser.h
|
||||
notify.o: acceptbaseparser.h htmlfilter.h
|
||||
plugin.o: plugin.h request.h requesttypes.h session.h done.h item.h error.h
|
||||
plugin.o: log.h user.h rebus.h function.h thread.h compress.h
|
||||
plugin.o: acceptencodingparser.h acceptbaseparser.h data.h dirs.h
|
||||
plugin.o: dircontainer.h users.h ugcontainer.h groups.h group.h functions.h
|
||||
plugin.o: lastcontainer.h mounts.h mount.h pluginmsg.h
|
||||
plugin.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h data.h
|
||||
plugin.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h group.h
|
||||
plugin.o: functions.h lastcontainer.h mounts.h mount.h pluginmsg.h
|
||||
rebus.o: log.h rebus.h misc.h item.h
|
||||
request.o: request.h requesttypes.h session.h done.h item.h error.h log.h
|
||||
request.o: user.h rebus.h function.h thread.h compress.h
|
||||
request.o: acceptencodingparser.h acceptbaseparser.h getparser.h
|
||||
request.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h getparser.h
|
||||
request.o: httpsimpleparser.h postparser.h cookieparser.h data.h dirs.h
|
||||
request.o: dircontainer.h users.h ugcontainer.h groups.h group.h functions.h
|
||||
request.o: lastcontainer.h mounts.h mount.h plugin.h pluginmsg.h misc.h
|
||||
@@ -69,8 +72,8 @@ requestcontroller.o: functionparser.h requesttypes.h data.h dirs.h
|
||||
requestcontroller.o: dircontainer.h users.h ugcontainer.h groups.h group.h
|
||||
requestcontroller.o: functions.h function.h lastcontainer.h mounts.h mount.h
|
||||
requestcontroller.o: request.h thread.h compress.h acceptencodingparser.h
|
||||
requestcontroller.o: acceptbaseparser.h postparser.h httpsimpleparser.h
|
||||
requestcontroller.o: cookieparser.h notify.h
|
||||
requestcontroller.o: acceptbaseparser.h htmlfilter.h postparser.h
|
||||
requestcontroller.o: httpsimpleparser.h cookieparser.h notify.h
|
||||
requestcontroller.o: ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||
session.o: session.h done.h item.h error.h log.h user.h rebus.h
|
||||
sessioncontainer.o: sessioncontainer.h session.h done.h item.h error.h log.h
|
||||
@@ -80,9 +83,10 @@ sessioncontainer.o: lastcontainer.h mounts.h mount.h
|
||||
sessionmanager.o: sessionmanager.h sessioncontainer.h session.h done.h item.h
|
||||
sessionmanager.o: error.h log.h user.h rebus.h request.h requesttypes.h
|
||||
sessionmanager.o: function.h thread.h compress.h acceptencodingparser.h
|
||||
sessionmanager.o: acceptbaseparser.h data.h dirs.h dircontainer.h users.h
|
||||
sessionmanager.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h
|
||||
sessionmanager.o: mounts.h mount.h sessionparser.h
|
||||
sessionmanager.o: acceptbaseparser.h htmlfilter.h data.h dirs.h
|
||||
sessionmanager.o: dircontainer.h users.h ugcontainer.h groups.h group.h
|
||||
sessionmanager.o: functions.h lastcontainer.h mounts.h mount.h
|
||||
sessionmanager.o: sessionparser.h
|
||||
sessionparser.o: sessionparser.h session.h done.h item.h error.h log.h user.h
|
||||
sessionparser.o: rebus.h sessioncontainer.h data.h dirs.h dircontainer.h
|
||||
sessionparser.o: users.h ugcontainer.h groups.h group.h functions.h
|
||||
|
@@ -1 +1 @@
|
||||
o = acceptbaseparser.o compress.o config.o data.o db.o db_itemcolumns.o dircontainer.o dirs.o done.o error.o function.o functioncodeparser.o functionparser.o functions.o groups.o httpsimpleparser.o lastcontainer.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o rebus.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o sessionparser.o users.o
|
||||
o = acceptbaseparser.o compress.o config.o data.o db.o db_itemcolumns.o dircontainer.o dirs.o done.o error.o function.o functioncodeparser.o functionparser.o functions.o groups.o htmlfilter.o httpsimpleparser.o lastcontainer.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o rebus.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o sessionparser.o users.o
|
||||
|
@@ -126,6 +126,8 @@ void Config::AssignValues()
|
||||
|
||||
std::string p = Text("plugin");
|
||||
data.plugin_file.push_back(p);
|
||||
|
||||
data.html_filter = Bool("html_filter");
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +181,7 @@ bool Config::Bool(const char * name)
|
||||
return default_int;
|
||||
}
|
||||
|
||||
bool res = default_int;
|
||||
bool res = default_bool;
|
||||
|
||||
if( i->second == "true" || i->second == "1" || i->second == "yes" )
|
||||
res = true;
|
||||
|
@@ -98,6 +98,9 @@ public:
|
||||
// plugins
|
||||
std::vector<std::string> plugin_file;
|
||||
|
||||
// the html code is cleaned by our filter
|
||||
bool html_filter;
|
||||
|
||||
// end config members
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
|
@@ -51,7 +51,8 @@ public:
|
||||
|
||||
no_thread,
|
||||
empty,
|
||||
rebus_bad_answer,
|
||||
spam,
|
||||
incorrect_rebus,
|
||||
|
||||
unknown = 1000
|
||||
|
||||
|
799
core/htmlfilter.cpp
Executable file
799
core/htmlfilter.cpp
Executable file
@@ -0,0 +1,799 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2009, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "htmlfilter.h"
|
||||
|
||||
|
||||
|
||||
void HTMLFilter::Item::Clear()
|
||||
{
|
||||
name[0] = 0;
|
||||
name_len = 0;
|
||||
type = none;
|
||||
new_line = false;
|
||||
}
|
||||
|
||||
|
||||
HTMLFilter::Item::Item()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HTMLFilter::Filter(const char * in, std::string & out)
|
||||
{
|
||||
pchar = in;
|
||||
stack_len = 0;
|
||||
out_string = &out;
|
||||
last_new_line = false;
|
||||
out_string->clear();
|
||||
|
||||
Read();
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::Filter(const std::string & in, std::string & out)
|
||||
{
|
||||
out.reserve(in.size() * 2 + 1);
|
||||
Filter(in.c_str(), out);
|
||||
}
|
||||
|
||||
|
||||
HTMLFilter::HTMLFilter()
|
||||
{
|
||||
pstack = new Item[CMSLU_HTMLFILTER_STACK_MAXLEN];
|
||||
buffer = new char[CMSLU_HTMLFILTER_BUFFER_MAXLEN];
|
||||
|
||||
tab_size = 2;
|
||||
trim_white = false;
|
||||
break_long_lines = false;
|
||||
}
|
||||
|
||||
|
||||
HTMLFilter::HTMLFilter(const HTMLFilter & f)
|
||||
{
|
||||
// don't need to copy the stack
|
||||
pstack = new Item[CMSLU_HTMLFILTER_STACK_MAXLEN];
|
||||
buffer = new char[CMSLU_HTMLFILTER_BUFFER_MAXLEN];
|
||||
}
|
||||
|
||||
|
||||
HTMLFilter & HTMLFilter::operator=(const HTMLFilter & f)
|
||||
{
|
||||
// don't need to copy the stack
|
||||
pstack = new Item[CMSLU_HTMLFILTER_STACK_MAXLEN];
|
||||
buffer = new char[CMSLU_HTMLFILTER_BUFFER_MAXLEN];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HTMLFilter::~HTMLFilter()
|
||||
{
|
||||
delete [] pstack;
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::BreakLongLines(bool break_lines)
|
||||
{
|
||||
break_long_lines = break_lines;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::TrimWhite(bool trim)
|
||||
{
|
||||
trim_white = trim;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::InsertTabs(size_t tabsize)
|
||||
{
|
||||
tab_size = tabsize;
|
||||
|
||||
if( tab_size > 1000 )
|
||||
tab_size = 1000;
|
||||
}
|
||||
|
||||
|
||||
HTMLFilter::Item & HTMLFilter::GetItem(size_t i)
|
||||
{
|
||||
if( i >= stack_len )
|
||||
{
|
||||
empty.Clear();
|
||||
return empty;
|
||||
}
|
||||
|
||||
return pstack[i];
|
||||
}
|
||||
|
||||
|
||||
HTMLFilter::Item & HTMLFilter::LastItem()
|
||||
{
|
||||
if( stack_len == 0 )
|
||||
{
|
||||
empty.Clear();
|
||||
return empty;
|
||||
}
|
||||
|
||||
return pstack[stack_len-1];
|
||||
}
|
||||
|
||||
|
||||
bool HTMLFilter::PushStack()
|
||||
{
|
||||
if( stack_len == CMSLU_HTMLFILTER_STACK_MAXLEN )
|
||||
// oops, too many items
|
||||
return false;
|
||||
|
||||
pstack[stack_len].Clear();
|
||||
stack_len += 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HTMLFilter::PopStack()
|
||||
{
|
||||
if( stack_len == 0 )
|
||||
// oops
|
||||
return;
|
||||
|
||||
stack_len -= 1;
|
||||
pstack[stack_len].Clear();
|
||||
}
|
||||
|
||||
|
||||
bool HTMLFilter::IsWhite(int c)
|
||||
{
|
||||
// dont use c==10 here
|
||||
|
||||
if( c==' ' || c=='\t' || c==13 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::SkipWhite()
|
||||
{
|
||||
while( IsWhite(*pchar) )
|
||||
++pchar;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::SkipWhiteLines()
|
||||
{
|
||||
while( *pchar==10 || IsWhite(*pchar) )
|
||||
++pchar;
|
||||
}
|
||||
|
||||
|
||||
bool HTMLFilter::SkipTagCheck()
|
||||
{
|
||||
pchar += 1;
|
||||
SkipWhite();
|
||||
|
||||
if( *pchar == '/' )
|
||||
{
|
||||
pchar += 1;
|
||||
SkipWhite();
|
||||
|
||||
if( IsNameEqual(pchar, LastItem().name, LastItem().name_len) )
|
||||
{
|
||||
pchar += LastItem().name_len;
|
||||
SkipWhite();
|
||||
|
||||
if( *pchar == '>' )
|
||||
{
|
||||
pchar += 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::SkipNormalText()
|
||||
{
|
||||
while( *pchar!=0 && *pchar!='<' )
|
||||
++pchar;
|
||||
}
|
||||
|
||||
void HTMLFilter::CheckNewLine()
|
||||
{
|
||||
const char * start = pchar;
|
||||
|
||||
SkipWhite();
|
||||
last_new_line = (*pchar==10);
|
||||
|
||||
pchar = start;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::PutLastTagWithClosingTag()
|
||||
{
|
||||
const char * start = pchar;
|
||||
|
||||
|
||||
while( *pchar != 0 )
|
||||
{
|
||||
if( *pchar == '<' )
|
||||
{
|
||||
if( SkipTagCheck() )
|
||||
{
|
||||
PopStack();
|
||||
CheckNewLine();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pchar += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Put(start, pchar);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HTMLFilter::SkipItem()
|
||||
{
|
||||
while( *pchar!=0 && *pchar!='>' )
|
||||
++pchar;
|
||||
|
||||
if( *pchar == '>' )
|
||||
++pchar;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::SkipItemCheckXmlSimple()
|
||||
{
|
||||
while( *pchar!=0 )
|
||||
{
|
||||
while( *pchar!=0 && *pchar!='>' && *pchar!='/')
|
||||
++pchar;
|
||||
|
||||
if( *pchar == '/' ) // closing xml tag
|
||||
{
|
||||
++pchar;
|
||||
SkipWhite();
|
||||
|
||||
if( *pchar == '>' )
|
||||
{
|
||||
++pchar;
|
||||
LastItem().type = Item::simple;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
if( *pchar == '>' )
|
||||
{
|
||||
++pchar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool HTMLFilter::IsValidCharForName(int c)
|
||||
{
|
||||
if( (c>='a' && c<='z') ||
|
||||
(c>='A' && c<='Z') ||
|
||||
(c>='0' && c<='9') ||
|
||||
c=='-' || c=='!' )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HTMLFilter::ReadItemName()
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for( i=0 ; IsValidCharForName(*pchar) && i<CMSLU_HTMLFILTER_ITEM_MAXLEN-1 ; ++i )
|
||||
{
|
||||
LastItem().name[i] = *pchar;
|
||||
++pchar;
|
||||
}
|
||||
|
||||
LastItem().name[i] = 0;
|
||||
LastItem().name_len = i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HTMLFilter::Put(const char * str, const char * end)
|
||||
{
|
||||
if( str>=end )
|
||||
return;
|
||||
|
||||
size_t len = end - str;
|
||||
out_string->append(str, len);
|
||||
}
|
||||
|
||||
|
||||
size_t HTMLFilter::PutTrimFillBuffer(const char * & str, const char * & end)
|
||||
{
|
||||
size_t non_whites = 0;
|
||||
size_t i = 0;
|
||||
bool was_white;
|
||||
|
||||
|
||||
for( ; str < end && i<CMSLU_HTMLFILTER_BUFFER_MAXLEN-1 ; ++str )
|
||||
{
|
||||
was_white = false;
|
||||
|
||||
if( *str==10 || IsWhite(*str) )
|
||||
{
|
||||
// skipping the whole white string
|
||||
for( ; (*str==10 || IsWhite(*str)) && str < end ; ++str );
|
||||
|
||||
was_white = true;
|
||||
non_whites = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
non_whites += 1;
|
||||
}
|
||||
|
||||
if( (non_whites>60 && break_long_lines) || was_white )
|
||||
{
|
||||
buffer[i] = ' ';
|
||||
i += 1;
|
||||
non_whites = 0;
|
||||
}
|
||||
|
||||
if( str < end )
|
||||
{
|
||||
buffer[i] = *str;
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
// if there are more than one white characters then they will be changed into one space
|
||||
// and putting a space between 50 characters (if there were not any other white characters between them)
|
||||
void HTMLFilter::PutTrim(const char * str, const char * end)
|
||||
{
|
||||
size_t buf_len;
|
||||
|
||||
// this buffer must have at least 2 bytes (PutTrimFillBuffer needs it)
|
||||
if( !trim_white || CMSLU_HTMLFILTER_BUFFER_MAXLEN < 2 )
|
||||
{
|
||||
Put(str, end);
|
||||
return;
|
||||
}
|
||||
|
||||
while( str < end )
|
||||
{
|
||||
buf_len = PutTrimFillBuffer(str, end);
|
||||
Put(buffer, buffer+buf_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::PutOpeningTag(const char * tag)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if( CMSLU_HTMLFILTER_BUFFER_MAXLEN < CMSLU_HTMLFILTER_ITEM_MAXLEN+2 )
|
||||
return;
|
||||
|
||||
buffer[0] = '<';
|
||||
|
||||
for(i=1 ; *tag ; ++i, ++tag)
|
||||
buffer[i] = *tag;
|
||||
|
||||
buffer[i] = '>';
|
||||
i += 1;
|
||||
|
||||
Put(buffer, buffer+i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HTMLFilter::PutClosingTag(const char * tag)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if( CMSLU_HTMLFILTER_BUFFER_MAXLEN < CMSLU_HTMLFILTER_ITEM_MAXLEN+3 )
|
||||
return;
|
||||
|
||||
buffer[0] = '<';
|
||||
buffer[1] = '/';
|
||||
|
||||
for(i=2 ; *tag ; ++i, ++tag)
|
||||
buffer[i] = *tag;
|
||||
|
||||
buffer[i] = '>';
|
||||
i += 1;
|
||||
|
||||
Put(buffer, buffer+i);
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::PutTabs(size_t len)
|
||||
{
|
||||
if( len == 0 )
|
||||
return;
|
||||
|
||||
if( len > 20 )
|
||||
len = 20;
|
||||
|
||||
// how many spaces do you want
|
||||
size_t spaces = (len-1) * tab_size;
|
||||
size_t i;
|
||||
|
||||
if( spaces < CMSLU_HTMLFILTER_BUFFER_MAXLEN )
|
||||
{
|
||||
for(i=0 ; i<spaces ; ++i)
|
||||
buffer[i] = ' ';
|
||||
|
||||
Put(buffer, buffer+i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::PutNewLine()
|
||||
{
|
||||
if( !trim_white )
|
||||
// new line characters will be directly from the source html
|
||||
return;
|
||||
|
||||
buffer[0] = 10;
|
||||
Put(buffer, buffer+1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool HTMLFilter::IsOpeningCommentaryTag()
|
||||
{
|
||||
static char comm_open[] = "<!--";
|
||||
size_t comm_open_len = sizeof(comm_open) / sizeof(char) - 1;
|
||||
|
||||
return IsNameEqual(pchar, comm_open, comm_open_len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// skipping the commentary tag if exists
|
||||
bool HTMLFilter::SkipCommentaryTagIfExists()
|
||||
{
|
||||
static char comm_close[] = "-->";
|
||||
size_t comm_close_len = sizeof(comm_close) / sizeof(char) - 1;
|
||||
|
||||
if( !IsOpeningCommentaryTag() )
|
||||
return false;
|
||||
|
||||
pchar += 4; // size of commentary opening tag
|
||||
|
||||
// looking for "-->"
|
||||
while( *pchar!=0 && !IsNameEqual(pchar, comm_close, comm_close_len) )
|
||||
++pchar;
|
||||
|
||||
if( *pchar!= 0 )
|
||||
pchar += comm_close_len;
|
||||
|
||||
CheckNewLine();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::ReadNormalText()
|
||||
{
|
||||
const char * start = pchar;
|
||||
|
||||
SkipWhiteLines();
|
||||
|
||||
if( *pchar!=0 && (IsOpeningCommentaryTag() || *pchar!='<') && last_new_line )
|
||||
{
|
||||
if( *pchar == '<' )
|
||||
// skipping some white characters before a opening commentary tag
|
||||
// (but only a tag in a new line)
|
||||
start = pchar;
|
||||
|
||||
PutNewLine();
|
||||
PutTabs(stack_len+1);
|
||||
last_new_line = false; // in normal text we don't allow a new line character
|
||||
}
|
||||
|
||||
|
||||
while( *pchar != 0 )
|
||||
{
|
||||
if( !SkipCommentaryTagIfExists() )
|
||||
{
|
||||
if( *pchar == '<' )
|
||||
break;
|
||||
|
||||
pchar += 1;
|
||||
}
|
||||
}
|
||||
|
||||
PutTrim(start, pchar);
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::PrintItem(const char * start, const char * end)
|
||||
{
|
||||
if( LastItem().type != Item::closing )
|
||||
{
|
||||
if( last_new_line )
|
||||
{
|
||||
if( stack_len > 0 )
|
||||
PutNewLine();
|
||||
|
||||
if( stack_len > 1 )
|
||||
PutTabs(stack_len);
|
||||
}
|
||||
|
||||
// closing tags will be printed later
|
||||
// (when we check the stack)
|
||||
|
||||
Put(start, pchar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool HTMLFilter::ReadItem()
|
||||
{
|
||||
const char * start;
|
||||
|
||||
if( *pchar == 0 )
|
||||
return false;
|
||||
|
||||
// we have '<'
|
||||
start = pchar;
|
||||
pchar += 1;
|
||||
SkipWhite();
|
||||
|
||||
if( PushStack() )
|
||||
{
|
||||
if( *pchar == '/' ) // we have a closing tag
|
||||
{
|
||||
pchar += 1;
|
||||
SkipWhite();
|
||||
LastItem().type = Item::closing;
|
||||
}
|
||||
|
||||
ReadItemName();
|
||||
|
||||
if( LastItem().type != Item::closing )
|
||||
LastItem().type = (LastItem().name[0] == '!') ? Item::special : Item::opening;
|
||||
|
||||
SkipItemCheckXmlSimple();
|
||||
PrintItem(start, pchar);
|
||||
CheckNewLine();
|
||||
LastItem().new_line = last_new_line;
|
||||
return true;
|
||||
}
|
||||
|
||||
pchar = start;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int HTMLFilter::ToLower(int c)
|
||||
{
|
||||
if( c>='A' && c<='Z' )
|
||||
return c - 'A' + 'a';
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
bool HTMLFilter::IsNameEqual(const char * name1, const char * name2)
|
||||
{
|
||||
for( ; *name1!=0 && *name2!=0 ; ++name1, ++name2 )
|
||||
if( ToLower(*name1) != ToLower(*name2) )
|
||||
return false;
|
||||
|
||||
if( *name1==0 && *name2==0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// len characters from both strings must be equal
|
||||
bool HTMLFilter::IsNameEqual(const char * name1, const char * name2, size_t len)
|
||||
{
|
||||
for( ; *name1!=0 && *name2!=0 && len>0 ; ++name1, ++name2, --len )
|
||||
if( ToLower(*name1) != ToLower(*name2) )
|
||||
return false;
|
||||
|
||||
if( len == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HTMLFilter::IsLastTag(const char * name)
|
||||
{
|
||||
const char * tag = LastItem().name;
|
||||
|
||||
return IsNameEqual(name, tag);
|
||||
}
|
||||
|
||||
|
||||
// checking exceptions for opening tags
|
||||
void HTMLFilter::CheckExceptions()
|
||||
{
|
||||
if( IsLastTag("meta") ||
|
||||
IsLastTag("input") ||
|
||||
IsLastTag("br") ||
|
||||
IsLastTag("img") ||
|
||||
IsLastTag("link") )
|
||||
{
|
||||
LastItem().type = Item::simple;
|
||||
PopStack();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( IsLastTag("script") || IsLastTag("pre") || IsLastTag("textarea") )
|
||||
PutLastTagWithClosingTag();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void HTMLFilter::AddForgottenTags()
|
||||
{
|
||||
int i;
|
||||
|
||||
if( stack_len < 3 )
|
||||
return;
|
||||
|
||||
// we have forgotten to close some tags
|
||||
|
||||
// looking whether there is a matching opening tag
|
||||
for(i=int(stack_len)-3 ; i>=0 ; --i)
|
||||
if( IsNameEqual(pstack[i].name, pstack[stack_len-1].name) )
|
||||
break;
|
||||
|
||||
if( i < 0 )
|
||||
{
|
||||
// oops, there is no such a tag
|
||||
// we don't print the closing and the missing opening tag
|
||||
PopStack();
|
||||
return;
|
||||
}
|
||||
|
||||
for(int z=(int)stack_len-2 ; z>=i ; --z)
|
||||
{
|
||||
if( pstack[z].new_line )
|
||||
{
|
||||
PutNewLine();
|
||||
PutTabs(z+1);
|
||||
}
|
||||
|
||||
PutClosingTag(pstack[z].name);
|
||||
pstack[z].Clear();
|
||||
}
|
||||
|
||||
last_new_line = pstack[stack_len-1].new_line;
|
||||
|
||||
// invalidate tags
|
||||
stack_len = i;
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::CheckClosingTags()
|
||||
{
|
||||
if( stack_len == 0 )
|
||||
return;
|
||||
|
||||
// on the stack we have only opening tags
|
||||
// but only the last tag is a closing tag
|
||||
|
||||
if( stack_len == 1 )
|
||||
{
|
||||
// there is only last closing tag
|
||||
// we dont print it
|
||||
PopStack();
|
||||
return;
|
||||
}
|
||||
|
||||
// there are more than one tag
|
||||
if( IsNameEqual(pstack[stack_len-1].name, pstack[stack_len-2].name) )
|
||||
{
|
||||
// last closing tag is from the previous one
|
||||
if( pstack[stack_len-2].new_line )
|
||||
{
|
||||
PutNewLine();
|
||||
PutTabs(stack_len-1);
|
||||
}
|
||||
|
||||
PutClosingTag(pstack[stack_len-1].name);
|
||||
last_new_line = pstack[stack_len-1].new_line;
|
||||
PopStack();
|
||||
PopStack();
|
||||
return;
|
||||
}
|
||||
|
||||
AddForgottenTags();
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::PrintRest()
|
||||
{
|
||||
const char * start = pchar;
|
||||
|
||||
while( *pchar )
|
||||
++pchar;
|
||||
|
||||
if( pchar > start )
|
||||
Put(start, pchar);
|
||||
}
|
||||
|
||||
|
||||
void HTMLFilter::Read()
|
||||
{
|
||||
// white characters at the beginning are skipped
|
||||
SkipWhiteLines();
|
||||
|
||||
// it can be some text before the first html tag (we print it)
|
||||
ReadNormalText();
|
||||
|
||||
while( *pchar && ReadItem() )
|
||||
{
|
||||
if( LastItem().type == Item::opening )
|
||||
{
|
||||
CheckExceptions();
|
||||
}
|
||||
else
|
||||
if( LastItem().type == Item::special || LastItem().type == Item::simple )
|
||||
{
|
||||
if( stack_len > 1 )
|
||||
{
|
||||
pstack[stack_len-2].new_line = LastItem().new_line;
|
||||
}
|
||||
else
|
||||
{
|
||||
// one new line after a simple or special tag
|
||||
// (if the tag has level 0 in the tree - it not means that this is a first tag)
|
||||
// for example can be DOCTYPE
|
||||
PutNewLine();
|
||||
}
|
||||
|
||||
PopStack();
|
||||
}
|
||||
else
|
||||
if( LastItem().type == Item::closing )
|
||||
{
|
||||
CheckClosingTags();
|
||||
}
|
||||
|
||||
ReadNormalText();
|
||||
}
|
||||
|
||||
// sometimes ReadItem() can return a false (when there is no space on the stack)
|
||||
// we print the rest html without filtering
|
||||
PrintRest();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
166
core/htmlfilter.h
Executable file
166
core/htmlfilter.h
Executable file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2009, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfilecmslucorehtmlfilter
|
||||
#define headerfilecmslucorehtmlfilter
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
|
||||
// max length of a name of a html tag (with terminating null)
|
||||
#define CMSLU_HTMLFILTER_ITEM_MAXLEN 30
|
||||
|
||||
// depth of the html tree
|
||||
#define CMSLU_HTMLFILTER_STACK_MAXLEN 100
|
||||
|
||||
// length of a buffer used for printing
|
||||
// it should be at least: CMSLU_HTMLFILTER_ITEM_MAXLEN+3
|
||||
#define CMSLU_HTMLFILTER_BUFFER_MAXLEN 1024
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
very lightweight filter for html
|
||||
(without using any dynamic memory - some memory is allocated only at the beginning - in ctors)
|
||||
this filter has O(n) complexity over the whole html string
|
||||
|
||||
such tags as: <script> <pre> <textarea> are treated in a special way
|
||||
all characters between the opening and closing tag (<script>....</script>) are untouched
|
||||
|
||||
if the filter finds that there are not closed tags it will close them,
|
||||
if the filter finds a closing tag which doesn't have an opening tag - it will skip it
|
||||
|
||||
tags which don't need to be closed: meta, input, br, img, link
|
||||
look at CheckExceptions() method
|
||||
|
||||
the filter recognizes xml simple tags (with / at the end) such as: <br />
|
||||
*/
|
||||
class HTMLFilter
|
||||
{
|
||||
public:
|
||||
|
||||
HTMLFilter();
|
||||
HTMLFilter(const HTMLFilter & f);
|
||||
HTMLFilter & operator=(const HTMLFilter & f);
|
||||
~HTMLFilter();
|
||||
|
||||
// main methods used for filtering
|
||||
void Filter(const char * in, std::string & out);
|
||||
void Filter(const std::string & in, std::string & out);
|
||||
|
||||
// insert a white space into long lines
|
||||
// only between html tags
|
||||
// skipped in such tags: script, pre, textarea
|
||||
// false by default
|
||||
void BreakLongLines(bool break_lines);
|
||||
|
||||
// trimming white characters (with new lines)
|
||||
// at the beginning, at the end and in the middle of a string
|
||||
// only between html tags
|
||||
// at the beginning and at the end only one space is left
|
||||
// skipped in such tags: script, pre, textarea
|
||||
// false by default
|
||||
void TrimWhite(bool trim);
|
||||
|
||||
// first tabs in a tree
|
||||
// default: 2 (spaces)
|
||||
// set 0 to turn off
|
||||
void InsertTabs(size_t tabsize);
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
struct Item
|
||||
{
|
||||
char name[CMSLU_HTMLFILTER_ITEM_MAXLEN];
|
||||
size_t name_len;
|
||||
|
||||
enum Type
|
||||
{
|
||||
opening,
|
||||
closing,
|
||||
simple,
|
||||
special,
|
||||
none
|
||||
} type;
|
||||
|
||||
// is there a new line after this tag
|
||||
bool new_line;
|
||||
|
||||
void Clear();
|
||||
Item();
|
||||
};
|
||||
|
||||
|
||||
// only this method have direct access to the output string
|
||||
// you can easily change the output from a std::string to something else
|
||||
void Put(const char * str, const char * end);
|
||||
|
||||
|
||||
Item & GetItem(size_t i);
|
||||
Item & LastItem();
|
||||
|
||||
int ToLower(int c);
|
||||
bool IsNameEqual(const char * name1, const char * name2);
|
||||
bool IsNameEqual(const char * name1, const char * name2, size_t len);
|
||||
bool IsLastTag(const char * name);
|
||||
|
||||
bool IsWhite(int c);
|
||||
void SkipWhite();
|
||||
void SkipWhiteLines();
|
||||
bool SkipTagCheck();
|
||||
void SkipNormalText();
|
||||
bool IsOpeningCommentaryTag();
|
||||
bool SkipCommentaryTagIfExists();
|
||||
void SkipItem();
|
||||
void SkipItemCheckXmlSimple();
|
||||
|
||||
void PopStack();
|
||||
bool PushStack();
|
||||
bool IsValidCharForName(int c);
|
||||
void CheckNewLine();
|
||||
void CheckExceptions();
|
||||
void AddForgottenTags();
|
||||
void CheckClosingTags();
|
||||
void ReadNormalText();
|
||||
void PrintRest();
|
||||
void PrintItem(const char * start, const char * end);
|
||||
void ReadItemName();
|
||||
bool ReadItem();
|
||||
void Read();
|
||||
|
||||
size_t PutTrimFillBuffer(const char * & str, const char * & end);
|
||||
void PutTrim(const char * str, const char * end);
|
||||
void PutLastTagWithClosingTag();
|
||||
void PutOpeningTag(const char * tag);
|
||||
void PutClosingTag(const char * tag);
|
||||
void PutTabs(size_t len);
|
||||
void PutNewLine();
|
||||
|
||||
const char * pchar;
|
||||
Item empty;
|
||||
Item * pstack; // stack pointer
|
||||
size_t stack_len; // length of the stack
|
||||
char * buffer; // buffer used when printing
|
||||
std::string * out_string;
|
||||
bool last_new_line;
|
||||
bool break_long_lines; // insert a space into long lines
|
||||
bool trim_white; // trimming white characters
|
||||
size_t tab_size;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@@ -42,7 +42,7 @@ void * Notify::ThreadRoutine(void * arg)
|
||||
while( true )
|
||||
{
|
||||
CheckQueue();
|
||||
sleep(30);
|
||||
sleep(1); // !! was 30
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ std::list<NotifyMsg>::iterator i = obj->notify_pool.begin();
|
||||
i = obj->notify_pool.erase(i);
|
||||
obj->Unlock();
|
||||
|
||||
sleep(3);
|
||||
//sleep(3); // !!
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,7 @@ public:
|
||||
bool Init(const std::string & tdir);
|
||||
|
||||
/*
|
||||
this method added an item to our special pool
|
||||
this method addes an item to our special pool
|
||||
the pool is used by a second thread
|
||||
*/
|
||||
void ItemChanged(int notify_code);
|
||||
|
@@ -266,6 +266,18 @@ void Request::CheckMethod()
|
||||
}
|
||||
|
||||
|
||||
bool Request::AllPostVarEmpty()
|
||||
{
|
||||
PostTable::iterator i;
|
||||
|
||||
for(i=post_table.begin() ; i!=post_table.end() ; ++i)
|
||||
if( !i->second.empty() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Request::ReadParameters()
|
||||
{
|
||||
GetParser get_parser(env_request_uri, get_table);
|
||||
@@ -330,11 +342,8 @@ void Request::SendSessionCookie()
|
||||
}
|
||||
|
||||
|
||||
void Request::SendAll()
|
||||
void Request::SendHeaders(bool compressing)
|
||||
{
|
||||
SendSessionCookie();
|
||||
|
||||
|
||||
if( !redirect_to.empty() )
|
||||
{
|
||||
FCGX_PutS("Status: 301 Moved Permanently\r\n", out);
|
||||
@@ -348,43 +357,69 @@ void Request::SendAll()
|
||||
FCGX_PutS("Content-Type: Text/Html\r\n", out);
|
||||
}
|
||||
|
||||
bool compressing = data.compression && !browser_msie && accept_encoding_parser.AcceptDeflate();
|
||||
|
||||
if( compressing )
|
||||
FCGX_PutS("Content-Encoding: deflate\r\n", out);
|
||||
|
||||
FCGX_PutS(headers.str().c_str(), out);
|
||||
FCGX_PutS("\r\n", out);
|
||||
}
|
||||
|
||||
|
||||
if( !redirect_to.empty() )
|
||||
// if there is a redirect we do not send a content
|
||||
return;
|
||||
//
|
||||
|
||||
const std::string & source = page.str();
|
||||
|
||||
if( compressing )
|
||||
{
|
||||
compress.CompressAndPut(source.c_str(), source.length(), out);
|
||||
}
|
||||
else
|
||||
{
|
||||
FCGX_PutS(source.c_str(), out);
|
||||
}
|
||||
|
||||
|
||||
void Request::AddDebugInfo()
|
||||
{
|
||||
const std::string & d = debug.str();
|
||||
|
||||
if( !d.empty() )
|
||||
{
|
||||
FCGX_PutS("\n<!--\n", out);
|
||||
FCGX_PutS(d.c_str(), out);
|
||||
FCGX_PutS("\n-->\n", out);
|
||||
page << "\n<!--\n";
|
||||
page << d;
|
||||
page << "\n-->\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Request::SendPage(bool compressing)
|
||||
{
|
||||
const std::string & source_ref = page.str();
|
||||
const std::string * source = &source_ref;
|
||||
|
||||
if( data.html_filter )
|
||||
{
|
||||
html_filter.TrimWhite(true);
|
||||
html_filter.BreakLongLines(true);
|
||||
html_filter.InsertTabs(2);
|
||||
|
||||
html_filter.Filter(*source, clean_html);
|
||||
source = &clean_html;
|
||||
}
|
||||
|
||||
if( compressing )
|
||||
compress.CompressAndPut(source->c_str(), source->length(), out);
|
||||
else
|
||||
FCGX_PutS(source->c_str(), out);
|
||||
}
|
||||
|
||||
|
||||
void Request::SendAll()
|
||||
{
|
||||
bool compressing = data.compression && !browser_msie && accept_encoding_parser.AcceptDeflate();
|
||||
|
||||
SendSessionCookie();
|
||||
SendHeaders(compressing);
|
||||
|
||||
if( !redirect_to.empty() )
|
||||
// if there is a redirect we do not send a content
|
||||
return;
|
||||
|
||||
// adding debug info if exists
|
||||
AddDebugInfo();
|
||||
|
||||
// sending content
|
||||
SendPage(compressing);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -23,6 +23,8 @@
|
||||
#include "thread.h"
|
||||
#include "compress.h"
|
||||
#include "acceptencodingparser.h"
|
||||
#include "htmlfilter.h"
|
||||
|
||||
|
||||
|
||||
struct Request
|
||||
@@ -118,7 +120,7 @@ struct Request
|
||||
bool IsPostVar(const char * var);
|
||||
std::string * PostVar(const char * var); // it can return null when there is no such a post variable
|
||||
bool PostVar(const char * var, std::string & result);
|
||||
|
||||
bool AllPostVarEmpty(); // returning true if all post vars are empty
|
||||
|
||||
void ReadEnvVariables();
|
||||
void CheckMethod();
|
||||
@@ -150,18 +152,23 @@ private:
|
||||
void SendSessionCookie();
|
||||
void CheckIE();
|
||||
|
||||
void SendHeaders(bool compressing);
|
||||
void AddDebugInfo();
|
||||
void SendPage(bool compressing);
|
||||
|
||||
// used to set some env_* variables into it, when the server didn't set that variable
|
||||
// it contains '\0'
|
||||
const char char_empty;
|
||||
|
||||
|
||||
const char * SetEnvVar(const char * var);
|
||||
|
||||
void StandardLog();
|
||||
|
||||
Compress compress;
|
||||
|
||||
AcceptEncodingParser accept_encoding_parser;
|
||||
HTMLFilter html_filter;
|
||||
|
||||
// html after filtering
|
||||
std::string clean_html;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -20,6 +20,9 @@ Session::Session()
|
||||
|
||||
last_time = time;
|
||||
tm_last_time = tm_time;
|
||||
|
||||
// the first request can be a POST (it doesn't matter)
|
||||
last_time_get = time;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +34,12 @@ void Session::Clear()
|
||||
done = Done::none;
|
||||
done_status = Error::ok;
|
||||
item.Clear();
|
||||
done_timer = 0;
|
||||
rebus_item = 0;
|
||||
done_timer = 0;
|
||||
rebus_item = 0;
|
||||
rebus_checked = false;
|
||||
remember_me = false;
|
||||
new_session = true;
|
||||
spam_score = 0;
|
||||
|
||||
dir_old.clear();
|
||||
}
|
||||
@@ -53,7 +58,7 @@ bool Session::operator<(const Session & s) const
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
bool Session::DecTimer(int & timer)
|
||||
{
|
||||
if( timer == 0 )
|
||||
@@ -77,6 +82,29 @@ void Session::CheckTimers()
|
||||
done_status = Error::ok;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void Session::DecTimer(int & timer)
|
||||
{
|
||||
if( timer == 0 )
|
||||
return;
|
||||
|
||||
--timer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Session::CheckTimers()
|
||||
{
|
||||
DecTimer(done_timer);
|
||||
|
||||
if( done_timer == 0 )
|
||||
{
|
||||
done = Done::none;
|
||||
done_status = Error::ok;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Session::IncrementTimersIfExist()
|
||||
{
|
||||
|
@@ -36,6 +36,9 @@ struct Session
|
||||
time_t last_time;
|
||||
tm tm_last_time;
|
||||
|
||||
// when there was a last get request
|
||||
// (used to calculate spam)
|
||||
time_t last_time_get;
|
||||
|
||||
// 0 - means that nobody is logged
|
||||
User * puser;
|
||||
@@ -55,16 +58,20 @@ struct Session
|
||||
|
||||
// rebus - set by rebus_question(Info & i) from templates
|
||||
Rebus::Item * rebus_item;
|
||||
bool rebus_checked;
|
||||
|
||||
std::string dir_old;
|
||||
|
||||
|
||||
int spam_score;
|
||||
|
||||
// -------------------
|
||||
|
||||
Session();
|
||||
void Clear();
|
||||
bool operator==(const Session & s) const;
|
||||
bool operator<(const Session & s) const;
|
||||
bool DecTimer(int & timer);
|
||||
void DecTimer(int & timer);
|
||||
void CheckTimers();
|
||||
void IncrementTimersIfExist();
|
||||
};
|
||||
|
@@ -110,6 +110,34 @@ int attempts = 100;
|
||||
|
||||
|
||||
|
||||
|
||||
bool SessionManager::SetSessionFromCookie(const std::string & cookie)
|
||||
{
|
||||
long id = atol(cookie.c_str());
|
||||
SessionContainer::Iterator s = session_table.FindById(id);
|
||||
|
||||
if( s == session_table.End() )
|
||||
return false;
|
||||
|
||||
// that session is in the table
|
||||
request.session = &(*s);
|
||||
request.session->new_session = false;
|
||||
session_table.UpdateLastTime(s, std::time(0));
|
||||
|
||||
if( request.method == Request::get )
|
||||
request.session->last_time_get = request.session->last_time;
|
||||
|
||||
log << log2 << "SM: session: " << s->id;
|
||||
|
||||
if( request.session->puser )
|
||||
log << log2 << ", user: " << request.session->puser->name << ", id: " << request.session->puser->id;
|
||||
|
||||
log << log2 << logend;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void SessionManager::SetSession()
|
||||
{
|
||||
CookieTable::iterator i = request.cookie_table.find(data.http_session_id_name);
|
||||
@@ -120,25 +148,7 @@ void SessionManager::SetSession()
|
||||
}
|
||||
else
|
||||
{
|
||||
long id = atol(i->second.c_str());
|
||||
SessionContainer::Iterator s = session_table.FindById(id);
|
||||
|
||||
if( s != session_table.End() )
|
||||
{
|
||||
// that session is in the table
|
||||
request.session = &(*s);
|
||||
request.session->new_session = false;
|
||||
|
||||
session_table.UpdateLastTime(s, std::time(0));
|
||||
|
||||
log << log2 << "SM: session: " << s->id;
|
||||
|
||||
if( request.session->puser )
|
||||
log << log2 << ", user: " << request.session->puser->name << ", id: " << request.session->puser->id;
|
||||
|
||||
log << log2 << logend;
|
||||
}
|
||||
else
|
||||
if( !SetSessionFromCookie(i->second) )
|
||||
{
|
||||
// there is no such a session
|
||||
// deleting the old cookie
|
||||
@@ -149,8 +159,6 @@ void SessionManager::SetSession()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// request.session is set now
|
||||
}
|
||||
|
||||
|
@@ -28,7 +28,7 @@ class SessionManager
|
||||
long CreateSessionId();
|
||||
void CreateTemporarySession();
|
||||
void CreateSession();
|
||||
|
||||
bool SetSessionFromCookie(const std::string & cookie);
|
||||
int session_checker;
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user