part II of rewriting

git-svn-id: svn://ttmath.org/publicrep/winix/trunk@635 e52654a7-88a9-db11-a3e9-0013d4bc506e
pull/3/head
Tomasz Sowa 13 years ago
parent c3fac2e83f
commit 9a199cd834

@ -1,12 +1,11 @@
# DO NOT DELETE
acceptbaseparser.o: acceptbaseparser.h
app.o: app.h config.h confparser.h system.h dirs.h item.h dircontainer.h db.h
app.o: user.h group.h thread.h error.h log.h ugcontainer.h ticket.h request.h
app.o: requesttypes.h session.h plugindata.h rebus.h compress.h
app.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
app.o: postmultiparser.h mounts.h mount.h users.h lastcontainer.h groups.h
app.o: loadavg.h sessionmanager.h sessioncontainer.h notify.h
app.o: app.h config.h confparser.h htmlfilter.h system.h dirs.h item.h
app.o: dircontainer.h db.h user.h group.h thread.h error.h log.h
app.o: ugcontainer.h ticket.h request.h requesttypes.h session.h plugindata.h
app.o: rebus.h mounts.h mount.h users.h lastcontainer.h groups.h loadavg.h
app.o: sessionmanager.h sessioncontainer.h notify.h
app.o: ../templatesnotify/templatesnotify.h ../../ezc/src/ezc.h
app.o: ../core/mount.h ../core/locale.h ../core/config.h ../templates/misc.h
app.o: ../templates/localefilter.h ../core/locale.h ../functions/functions.h
@ -28,18 +27,18 @@ app.o: ../functions/uptime.h ../functions/who.h ../templates/templates.h
app.o: ../templates/patterncacher.h ../core/item.h misc.h
app.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
app.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
app.o: plugin.h pluginmsg.h
app.o: compress.h getparser.h httpsimpleparser.h postparser.h cookieparser.h
app.o: postmultiparser.h acceptencodingparser.h acceptbaseparser.h plugin.h
app.o: pluginmsg.h
bbcodeparser.o: bbcodeparser.h htmlfilter.h
compress.o: compress.h log.h
config.o: config.h confparser.h log.h plugin.h pluginmsg.h plugindata.h
config.o: request.h requesttypes.h session.h item.h error.h user.h rebus.h
config.o: compress.h acceptencodingparser.h acceptbaseparser.h htmlfilter.h
config.o: postmultiparser.h system.h dirs.h dircontainer.h db.h group.h
config.o: thread.h ugcontainer.h ticket.h mounts.h mount.h users.h
config.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
config.o: sessioncontainer.h ../functions/functions.h
config.o: ../functions/functionbase.h ../core/item.h ../core/db.h
config.o: ../core/request.h ../core/config.h ../core/system.h
config.o: config.h confparser.h htmlfilter.h log.h plugin.h pluginmsg.h
config.o: plugindata.h request.h requesttypes.h session.h item.h error.h
config.o: user.h rebus.h system.h dirs.h dircontainer.h db.h group.h thread.h
config.o: ugcontainer.h ticket.h mounts.h mount.h users.h lastcontainer.h
config.o: groups.h loadavg.h sessionmanager.h sessioncontainer.h
config.o: ../functions/functions.h ../functions/functionbase.h ../core/item.h
config.o: ../core/db.h ../core/request.h ../core/config.h ../core/system.h
config.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
config.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
config.o: ../functions/privchanger.h ../functions/chown.h
@ -67,9 +66,7 @@ db_itemcolumns.o: dircontainer.h ugcontainer.h ticket.h
dircontainer.o: dircontainer.h item.h log.h
dirs.o: dirs.h item.h dircontainer.h db.h user.h group.h thread.h error.h
dirs.o: log.h ugcontainer.h ticket.h request.h requesttypes.h session.h
dirs.o: plugindata.h rebus.h compress.h acceptencodingparser.h
dirs.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
dirs.o: confparser.h
dirs.o: plugindata.h rebus.h config.h confparser.h htmlfilter.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 ticket.h
htmlfilter.o: htmlfilter.h
@ -83,30 +80,25 @@ mount.o: mount.h
mountparser.o: mountparser.h mount.h item.h error.h log.h dirs.h
mountparser.o: dircontainer.h db.h user.h group.h thread.h ugcontainer.h
mountparser.o: ticket.h request.h requesttypes.h session.h plugindata.h
mountparser.o: rebus.h compress.h acceptencodingparser.h acceptbaseparser.h
mountparser.o: htmlfilter.h postmultiparser.h config.h confparser.h misc.h
mountparser.o: rebus.h config.h confparser.h htmlfilter.h misc.h
mounts.o: mounts.h mount.h error.h log.h dirs.h item.h dircontainer.h db.h
mounts.o: user.h group.h thread.h ugcontainer.h ticket.h request.h
mounts.o: requesttypes.h session.h plugindata.h rebus.h compress.h
mounts.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
mounts.o: postmultiparser.h config.h confparser.h mountparser.h
mounts.o: requesttypes.h session.h plugindata.h rebus.h config.h confparser.h
mounts.o: htmlfilter.h mountparser.h
notify.o: log.h notify.h ../templatesnotify/templatesnotify.h
notify.o: ../../ezc/src/ezc.h ../core/mount.h ../core/locale.h confparser.h
notify.o: ../core/config.h ../templates/misc.h ../templates/localefilter.h
notify.o: ../core/locale.h request.h requesttypes.h session.h item.h error.h
notify.o: user.h plugindata.h rebus.h compress.h acceptencodingparser.h
notify.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h system.h
notify.o: dirs.h dircontainer.h db.h group.h thread.h ugcontainer.h ticket.h
notify.o: user.h plugindata.h rebus.h config.h htmlfilter.h system.h dirs.h
notify.o: dircontainer.h db.h group.h thread.h ugcontainer.h ticket.h
notify.o: mounts.h mount.h users.h lastcontainer.h groups.h loadavg.h misc.h
plugin.o: plugin.h pluginmsg.h log.h plugindata.h config.h confparser.h
plugin.o: request.h requesttypes.h session.h item.h error.h user.h rebus.h
plugin.o: compress.h acceptencodingparser.h acceptbaseparser.h htmlfilter.h
plugin.o: postmultiparser.h system.h dirs.h dircontainer.h db.h group.h
plugin.o: thread.h ugcontainer.h ticket.h mounts.h mount.h users.h
plugin.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
plugin.o: sessioncontainer.h ../functions/functions.h
plugin.o: ../functions/functionbase.h ../core/item.h ../core/db.h
plugin.o: ../core/request.h ../core/config.h ../core/system.h
plugin.o: htmlfilter.h request.h requesttypes.h session.h item.h error.h
plugin.o: user.h rebus.h system.h dirs.h dircontainer.h db.h group.h thread.h
plugin.o: ugcontainer.h ticket.h mounts.h mount.h users.h lastcontainer.h
plugin.o: groups.h loadavg.h sessionmanager.h sessioncontainer.h
plugin.o: ../functions/functions.h ../functions/functionbase.h ../core/item.h
plugin.o: ../core/db.h ../core/request.h ../core/config.h ../core/system.h
plugin.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
plugin.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
plugin.o: ../functions/privchanger.h ../functions/chown.h
@ -127,11 +119,10 @@ plugin.o: ../core/log.h ../templates/indexpatterns.h
plugin.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
plugin.o: ../core/sessionmanager.h
plugindata.o: plugindata.h plugin.h pluginmsg.h log.h config.h confparser.h
plugindata.o: request.h requesttypes.h session.h item.h error.h user.h
plugindata.o: rebus.h compress.h acceptencodingparser.h acceptbaseparser.h
plugindata.o: htmlfilter.h postmultiparser.h system.h dirs.h dircontainer.h
plugindata.o: db.h group.h thread.h ugcontainer.h ticket.h mounts.h mount.h
plugindata.o: users.h lastcontainer.h groups.h loadavg.h sessionmanager.h
plugindata.o: htmlfilter.h request.h requesttypes.h session.h item.h error.h
plugindata.o: user.h rebus.h system.h dirs.h dircontainer.h db.h group.h
plugindata.o: thread.h ugcontainer.h ticket.h mounts.h mount.h users.h
plugindata.o: lastcontainer.h groups.h loadavg.h sessionmanager.h
plugindata.o: sessioncontainer.h ../functions/functions.h
plugindata.o: ../functions/functionbase.h ../core/item.h ../core/db.h
plugindata.o: ../core/request.h ../core/config.h ../core/system.h
@ -157,25 +148,20 @@ plugindata.o: ../core/httpsimpleparser.h ../core/log.h
plugindata.o: ../templates/indexpatterns.h ../templates/localefilter.h
plugindata.o: ../core/locale.h ../core/locale.h ../core/sessionmanager.h
postmultiparser.o: postmultiparser.h error.h log.h requesttypes.h config.h
postmultiparser.o: confparser.h
postmultiparser.o: confparser.h htmlfilter.h
rebus.o: log.h rebus.h misc.h item.h request.h requesttypes.h session.h
rebus.o: error.h user.h plugindata.h compress.h acceptencodingparser.h
rebus.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
rebus.o: confparser.h
rebus.o: error.h user.h plugindata.h config.h confparser.h htmlfilter.h
request.o: request.h requesttypes.h session.h item.h error.h log.h user.h
request.o: plugindata.h rebus.h compress.h acceptencodingparser.h
request.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
request.o: confparser.h getparser.h httpsimpleparser.h postparser.h
request.o: cookieparser.h plugin.h pluginmsg.h system.h dirs.h dircontainer.h
request.o: db.h group.h thread.h ugcontainer.h ticket.h mounts.h mount.h
request.o: users.h lastcontainer.h groups.h loadavg.h sessionmanager.h
request.o: sessioncontainer.h ../functions/functions.h
request.o: ../functions/functionbase.h ../core/item.h ../core/db.h
request.o: ../core/request.h ../core/config.h ../core/system.h
request.o: ../core/notify.h ../../ezc/src/ezc.h ../functions/functionparser.h
request.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
request.o: ../functions/privchanger.h ../functions/chown.h
request.o: ../functions/ckeditor.h ../functions/cp.h
request.o: plugindata.h rebus.h config.h confparser.h htmlfilter.h plugin.h
request.o: pluginmsg.h system.h dirs.h dircontainer.h db.h group.h thread.h
request.o: ugcontainer.h ticket.h mounts.h mount.h users.h lastcontainer.h
request.o: groups.h loadavg.h sessionmanager.h sessioncontainer.h
request.o: ../functions/functions.h ../functions/functionbase.h
request.o: ../core/item.h ../core/db.h ../core/request.h ../core/config.h
request.o: ../core/system.h ../core/notify.h ../../ezc/src/ezc.h
request.o: ../functions/functionparser.h ../functions/adduser.h
request.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
request.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
request.o: ../functions/createthread.h ../functions/createticket.h
request.o: ../functions/default.h ../functions/download.h
request.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
@ -190,35 +176,33 @@ request.o: ../templates/patterncacher.h ../core/item.h misc.h
request.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
request.o: ../core/log.h ../templates/indexpatterns.h
request.o: ../templates/localefilter.h ../core/locale.h ../core/locale.h
request.o: ../core/sessionmanager.h ../functions/functionbase.h
request.o: ../core/sessionmanager.h
session.o: session.h item.h error.h log.h user.h plugindata.h rebus.h
sessioncontainer.o: sessioncontainer.h session.h item.h error.h log.h user.h
sessioncontainer.o: plugindata.h rebus.h lastcontainer.h
sessionmanager.o: sessionmanager.h sessioncontainer.h session.h item.h
sessionmanager.o: error.h log.h user.h plugindata.h rebus.h lastcontainer.h
sessionmanager.o: config.h confparser.h request.h requesttypes.h compress.h
sessionmanager.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
sessionmanager.o: postmultiparser.h system.h dirs.h dircontainer.h db.h
sessionmanager.o: group.h thread.h ugcontainer.h ticket.h mounts.h mount.h
sessionmanager.o: users.h groups.h loadavg.h sessionparser.h plugin.h
sessionmanager.o: pluginmsg.h ../functions/functions.h
sessionmanager.o: ../functions/functionbase.h ../core/item.h ../core/db.h
sessionmanager.o: ../core/request.h ../core/config.h ../core/system.h
sessionmanager.o: ../core/notify.h ../../ezc/src/ezc.h
sessionmanager.o: ../functions/functionparser.h ../functions/adduser.h
sessionmanager.o: ../functions/cat.h ../functions/chmod.h
sessionmanager.o: ../functions/privchanger.h ../functions/chown.h
sessionmanager.o: ../functions/ckeditor.h ../functions/cp.h
sessionmanager.o: ../functions/createthread.h ../functions/createticket.h
sessionmanager.o: ../functions/default.h ../functions/download.h
sessionmanager.o: ../functions/editticket.h ../functions/emacs.h
sessionmanager.o: ../functions/last.h ../functions/login.h
sessionmanager.o: ../functions/logout.h ../functions/ls.h
sessionmanager.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
sessionmanager.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
sessionmanager.o: ../functions/run.h ../functions/subject.h
sessionmanager.o: ../functions/funthread.h ../core/thread.h
sessionmanager.o: ../functions/funticket.h ../core/ticket.h
sessionmanager.o: config.h confparser.h htmlfilter.h request.h requesttypes.h
sessionmanager.o: system.h dirs.h dircontainer.h db.h group.h thread.h
sessionmanager.o: ugcontainer.h ticket.h mounts.h mount.h users.h groups.h
sessionmanager.o: loadavg.h sessionparser.h plugin.h pluginmsg.h
sessionmanager.o: ../functions/functions.h ../functions/functionbase.h
sessionmanager.o: ../core/item.h ../core/db.h ../core/request.h
sessionmanager.o: ../core/config.h ../core/system.h ../core/notify.h
sessionmanager.o: ../../ezc/src/ezc.h ../functions/functionparser.h
sessionmanager.o: ../functions/adduser.h ../functions/cat.h
sessionmanager.o: ../functions/chmod.h ../functions/privchanger.h
sessionmanager.o: ../functions/chown.h ../functions/ckeditor.h
sessionmanager.o: ../functions/cp.h ../functions/createthread.h
sessionmanager.o: ../functions/createticket.h ../functions/default.h
sessionmanager.o: ../functions/download.h ../functions/editticket.h
sessionmanager.o: ../functions/emacs.h ../functions/last.h
sessionmanager.o: ../functions/login.h ../functions/logout.h
sessionmanager.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
sessionmanager.o: ../functions/node.h ../functions/priv.h
sessionmanager.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
sessionmanager.o: ../functions/subject.h ../functions/funthread.h
sessionmanager.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
sessionmanager.o: ../functions/tinymce.h ../functions/uname.h
sessionmanager.o: ../functions/upload.h ../functions/uptime.h
sessionmanager.o: ../functions/who.h ../templates/templates.h
@ -229,39 +213,17 @@ sessionmanager.o: ../templates/localefilter.h ../core/locale.h
sessionmanager.o: ../core/locale.h ../core/sessionmanager.h
sessionparser.o: sessionparser.h session.h item.h error.h log.h user.h
sessionparser.o: plugindata.h rebus.h sessioncontainer.h lastcontainer.h
sessionparser.o: users.h ugcontainer.h request.h requesttypes.h compress.h
sessionparser.o: acceptencodingparser.h acceptbaseparser.h htmlfilter.h
sessionparser.o: postmultiparser.h config.h confparser.h db.h group.h
sessionparser.o: thread.h dircontainer.h ticket.h
sessionparser.o: users.h ugcontainer.h request.h requesttypes.h config.h
sessionparser.o: confparser.h htmlfilter.h db.h group.h thread.h
sessionparser.o: dircontainer.h ticket.h
system.o: system.h dirs.h item.h dircontainer.h db.h user.h group.h thread.h
system.o: error.h log.h ugcontainer.h ticket.h request.h requesttypes.h
system.o: session.h plugindata.h rebus.h compress.h acceptencodingparser.h
system.o: acceptbaseparser.h htmlfilter.h postmultiparser.h config.h
system.o: confparser.h mounts.h mount.h users.h lastcontainer.h groups.h
system.o: loadavg.h misc.h notify.h ../templatesnotify/templatesnotify.h
system.o: ../../ezc/src/ezc.h ../core/mount.h ../core/locale.h
system.o: ../core/config.h ../templates/misc.h ../templates/localefilter.h
system.o: ../core/locale.h ../functions/functions.h
system.o: ../functions/functionbase.h ../core/item.h ../core/db.h
system.o: ../core/request.h ../core/system.h ../core/notify.h
system.o: ../functions/functionparser.h ../functions/adduser.h
system.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
system.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
system.o: ../functions/createthread.h ../functions/createticket.h
system.o: ../functions/default.h ../functions/download.h
system.o: ../functions/editticket.h ../functions/emacs.h ../functions/last.h
system.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
system.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
system.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
system.o: ../functions/run.h ../functions/subject.h ../functions/funthread.h
system.o: ../core/thread.h ../functions/funticket.h ../core/ticket.h
system.o: ../functions/tinymce.h ../functions/uname.h ../functions/upload.h
system.o: ../functions/uptime.h ../functions/who.h ../templates/templates.h
system.o: ../templates/patterncacher.h ../core/item.h
system.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
system.o: ../core/log.h ../templates/indexpatterns.h ../core/sessionmanager.h
system.o: session.h plugindata.h rebus.h config.h confparser.h htmlfilter.h
system.o: mounts.h mount.h users.h lastcontainer.h groups.h loadavg.h misc.h
system.o: notify.h ../templatesnotify/templatesnotify.h ../../ezc/src/ezc.h
system.o: ../core/mount.h ../core/locale.h ../core/config.h
system.o: ../templates/misc.h ../templates/localefilter.h ../core/locale.h
users.o: users.h user.h ugcontainer.h log.h lastcontainer.h request.h
users.o: requesttypes.h session.h item.h error.h plugindata.h rebus.h
users.o: compress.h acceptencodingparser.h acceptbaseparser.h htmlfilter.h
users.o: postmultiparser.h config.h confparser.h db.h group.h thread.h
users.o: config.h confparser.h htmlfilter.h db.h group.h thread.h
users.o: dircontainer.h ticket.h

@ -9,6 +9,10 @@
#include "app.h"
#include "plugin.h"
#include "misc.h"
#include "functions/functions.h"
@ -37,8 +41,6 @@ App::App()
system.SetConfig(&config);
system.SetRequest(&request);
system.SetDb(&db);
system.SetFunctions(&functions); // !! czy model musi cos wiedziec o funkcjach?
system.SetTemplates(&templates);
templates_notify.SetConfig(&config);
@ -59,6 +61,7 @@ App::App()
session_manager.SetRequest(&request);
session_manager.SetSystem(&system);
post_multi_parser.SetConfig(&config);
}
@ -128,13 +131,12 @@ return true;
bool App::Init()
{
request.Init();
if( !CreateFCGISocket() )
return false;
request.Clear();
compress.Init();
system.Init();
functions.Create();
// !! teraz mamy dwa katalogi z templetami
@ -194,10 +196,9 @@ return true;
}
void App::ProcessRequest()
void App::ProcessRequestThrow()
{
request.Clear(); // !! dac na koniec
request.Read();
ReadRequest();
// when BaseUrlRedirect() return true we didn't have to set everything in request.Read()
// in the future request.Read() can be split and at the beginning only environment variables will be read
@ -216,14 +217,30 @@ void App::ProcessRequest()
Make();
}
request.SendAll(); // !! czemu request sam sie chce wyslac? wrzucic to tutaj do app
SendAnswer();
notify.ItemChanged(request.notify_code);
if( request.function )
request.function->Clear();
}
void App::ProcessRequest()
{
try
{
ProcessRequestThrow();
}
catch(const std::exception & e)
{
log << log1 << "App: there was an exception: std::exception: " << e.what() << logend;
}
catch(const Error & e)
{
log << log1 << "App: there was an exception: Error: " << e << logend;
}
catch(...)
{
log << log1 << "App: there was an unknown exception" << logend;
}
}
void App::Start()
@ -231,41 +248,15 @@ void App::Start()
while( FCGX_Accept(&request.in, &request.out, &request.err, &request.env) == 0 )
{
system.load_avg.StartRequest();
log << log2 << "---------------------------------------------------------------------------------" << logend;
log << log2 << config.log_delimiter << logend;
try
{
ProcessRequest();
}
catch(const std::logic_error & e)
{
log << log1 << "std logic exception: " << e.what() << logend;
}
catch(const std::exception & e)
{
log << log1 << "std exception: " << e.what() << logend;
}
catch(const Error & e)
{
log << log1 << "exception: Error: " << e << logend;
}
catch(...)
{
log << log1 << "uncaught unknown exception" << logend;
}
ProcessRequest();
SaveSessionsIfNeeded();
// !! this should be immediately after FCGX_Accept() but signals don't want to break FCGX_Accept
//if( signal_hup )
if( false )
{
log << logsave;
FCGX_Finish();
return;
}
if( request.function )
request.function->Clear();
request.ClearPostFileTmp();
request.Clear();
system.load_avg.StopRequest();
log << logsave;
}
@ -292,6 +283,7 @@ void App::MakePage()
{
bool sent = false;
if( !request.redirect_to.empty() || !request.x_sendfile.empty() )
return;
@ -328,7 +320,7 @@ void App::Make()
return;
}
// request->status can be changed by function_parser
// request.status can be changed by function_parser
if( request.status == WINIX_ERR_OK )
{
if( system.DirsHaveReadExecPerm() )
@ -361,13 +353,354 @@ void App::Make()
plugin.Call(WINIX_CONTENT_MAKE);
MakePage();
// !! dodac parametr do konfiga wlaczajacy te informacje
//request->PrintGetTab();
//request->PrintEnv();
//request->PrintIn();
if( config.debug_info )
{
// !! dodac inne informacje (get, post, itp)
// jesli jest debug_info wlaczone to nie robic przekierowan
request.PrintGetTab();
request.PrintEnv();
}
}
void App::ReadRequest()
{
ReadEnvVariables();
CheckRequestMethod();
CheckFCGIRole();
LogAccess();
ReadGetPostVars();
cookie_parser.Parse(request.env_http_cookie, request.cookie_tab);
accept_encoding_parser.Parse(request.env_http_accept_encoding);
CheckIE();
CheckKonqueror();
if( request.role == Request::authorizer )
log << log3 << "Request: fast cgi role: authorizer" << logend;
}
void App::SetEnv(const char * & env, const char * name)
{
const char * v = FCGX_GetParam(name, request.env);
if( v )
env = v;
// by default env is set to an empty string (in request.Clear() method)
}
void App::ReadEnvVariables()
{
// we store that values because FCGX_GetParam has O(n) complexity
// with this variables (env_*) we have O(1)
SetEnv(request.env_request_method, "REQUEST_METHOD");
SetEnv(request.env_request_uri, "REQUEST_URI");
SetEnv(request.env_http_cookie, "HTTP_COOKIE");
SetEnv(request.env_remote_addr, "REMOTE_ADDR");
SetEnv(request.env_http_host, "HTTP_HOST");
SetEnv(request.env_http_user_agent, "HTTP_USER_AGENT");
SetEnv(request.env_fcgi_role, "FCGI_ROLE");
SetEnv(request.env_content_type, "CONTENT_TYPE");
SetEnv(request.env_http_accept_encoding,"HTTP_ACCEPT_ENCODING");
}
void App::CheckRequestMethod()
{
request.method = Request::none;
if( ToSmall(request.env_request_method[0]) == 'g' )
request.method = Request::get;
else
if( ToSmall(request.env_request_method[0]) == 'p' )
request.method = Request::post;
else
if( ToSmall(request.env_request_method[0]) == 'h' )
request.method = Request::head;
}
void App::CheckFCGIRole()
{
// default we assume 'responder'
request.role = Request::responder;
if( ToSmall(request.env_fcgi_role[0]) == 'a' )
request.role = Request::authorizer;
}
void App::LogAccess()
{
log.PutDate(log1);
log << request.env_remote_addr << ' '
<< request.env_request_method << ' '
<< request.env_http_host
<< request.env_request_uri << ' '
<< request.env_http_user_agent << logend;
}
void App::ReadGetPostVars()
{
// get parameters we have always
get_parser.Parse(request.env_request_uri, request.get_tab);
if( request.method == Request::post )
{
if( IsSubStringNoCase("multipart/form-data", request.env_content_type) )
{
log << log3 << "Request: post content type: multipart/form-data" << logend;
post_multi_parser.Parse(request.in, request.post_tab, request.post_file_tab);
}
else
{
post_parser.Parse(request.in, request.post_tab);
}
}
}
void App::CheckIE()
{
char * msie = strstr(request.env_http_user_agent, "MSIE");
if( msie )
request.browser_msie = true;
else
request.browser_msie = false;
}
void App::CheckKonqueror()
{
char * kon = strstr(request.env_http_user_agent, "Konqueror");
if( kon )
request.browser_konqueror = true;
else
request.browser_konqueror = false;
}
void App::PrepareSessionCookie()
{
if( !request.session || request.session->id==0 )
return;
if( !request.session->puser || !request.session->remember_me )
{
request.SetCookie(config.http_session_id_name.c_str(), request.session->id);
}
else
{
time_t t = time(0) + config.session_remember_max_idle;
tm * expires = localtime(&t);
if( !expires )
{
// oops, something wrong
request.SetCookie(config.http_session_id_name.c_str(), request.session->id);
return;
}
request.SetCookie(config.http_session_id_name.c_str(), request.session->id, expires);
}
}
void App::SendHeaders(bool compressing, Header header)
{
PrepareSessionCookie();
if( request.send_as_attachment )
FCGX_PutS("Content-Disposition: attachment\r\n", request.out);
if( !request.redirect_to.empty() )
{
FCGX_PutS("Status: 301 Moved Permanently\r\n", request.out);
FCGX_FPrintF(request.out, "Location: %s\r\n", request.redirect_to.c_str());
log << log2 << "Redirect to: " << request.redirect_to << logend;
}
else
if( !request.x_sendfile.empty() )
{
FCGX_FPrintF(request.out, "%s: %s\r\n", config.http_header_send_file.c_str(),
request.x_sendfile.c_str());
FCGX_PutS("Status: 200 OK\r\n", request.out);
log << log2 << "Sending file: " << request.x_sendfile << logend;
}
else
{
switch( header )
{
case h_404:
FCGX_PutS("Status: 404 Not Found\r\n", request.out);
FCGX_PutS("Content-Type: text/html\r\n", request.out);
log << log2 << "Request: response: 404 Not Found" << logend;
break;
case h_403:
FCGX_PutS("Status: 403 Forbidden\r\n", request.out);
FCGX_PutS("Content-Type: text/html\r\n", request.out);
log << log2 << "Request: response: 403 Forbidden" << logend;
break;
default:
FCGX_PutS("Status: 200 OK\r\n", request.out);
if( request.role != Request::authorizer )
FCGX_PutS("Content-Type: text/html\r\n", request.out);
}
}
if( compressing )
FCGX_PutS("Content-Encoding: deflate\r\n", request.out);
FCGX_PutS(request.headers.str().c_str(), request.out);
FCGX_PutS("\r\n", request.out);
}
void App::SetHtmlFilterConf()
{
html_filter.TrimWhite(config.html_filter_trim_white);
html_filter.BreakLines(config.html_filter_break_lines);
html_filter.InsertTabs(config.html_filter_tabs);
if( config.html_filter_orphans )
html_filter.CheckOrphans(config.html_filter_orphans_lang, config.html_filter_orphans_mode);
}
// !! kopiowanie tych stringow bedzie zmienione
// gdy bedziemy korzystac w przyszlosci z wlasnego stringstream
void App::FilterCompressSend(bool compressing, const std::string & source_ref)
{
const std::string * source = &source_ref;
bool raw = request.is_item && request.item.content_type == Item::ct_raw && request.status == WINIX_ERR_OK &&
request.function && (request.function->fun.url == "cat" || request.function->fun.url == "run");
if( config.html_filter && !raw )
{
SetHtmlFilterConf();
html_filter.Filter(*source, clean_html);
AddDebugInfo(clean_html);
source = &clean_html;
}
else
{
html_with_debug = *source;
AddDebugInfo(html_with_debug);
source = &html_with_debug;
}
if( compressing )
compress.CompressAndPut(source->c_str(), source->length(), request.out);
else
FCGX_PutS(source->c_str(), request.out);
}
bool App::IsCompressionAllowed(const std::string & source)
{
return( config.compression &&
request.role == Request::responder &&
request.redirect_to.empty() &&
request.x_sendfile.empty() &&
!request.browser_msie &&
!request.browser_konqueror &&
accept_encoding_parser.AcceptDeflate() &&
source.size() >= (size_t)config.compression_page_min_size );
}
bool App::CanSendContent(Header header)
{
if( !request.redirect_to.empty() || !request.x_sendfile.empty() )
// if there is a redirect or a file to send then we do not send a content
return false;
if( header == h_200 && request.role == Request::authorizer && request.is_item && request.item.auth != Item::auth_none )
// if there is an item and the item has 'file' storage we do not send a content
return false;
/*
we don't have to check the HEAD method
the server (lighttpd) doesn't send the body of its own
*/
if( request.method == Request::head )
return false;
return true;
}
void App::AddDebugInfo(std::string & out)
{
if( config.debug_info )
{
const std::string & d = request.debug.str();
if( !d.empty() )
{
out += "\n<!--\n";
out += d;
out += "\n-->\n";
}
}
}
void App::SendAnswer()
{
const std::string & source = request.page.str();
Header header = h_200;
bool compressing = IsCompressionAllowed(source);
Error status = request.status;
if( status == WINIX_ERR_NO_ITEM || status == WINIX_ERR_NO_FUNCTION || status == WINIX_ERR_UNKNOWN_PARAM )
header = h_404;
if( status == WINIX_ERR_PERMISSION_DENIED || status == WINIX_ERR_CANT_CHANGE_USER || status == WINIX_ERR_CANT_CHANGE_GROUP )
header = h_403;
SendHeaders(compressing, header);
if( CanSendContent(header) )
{
// filtering (html), compressing (deflate) and sending back to the web browser
FilterCompressSend(compressing, source);
}
}

@ -29,6 +29,14 @@
#include "functions/functions.h"
#include "templates/templates.h"
#include "templatesnotify/templatesnotify.h"
#include "compress.h"
#include "htmlfilter.h"
#include "getparser.h"
#include "postparser.h"
#include "cookieparser.h"
#include "postmultiparser.h"
#include "acceptencodingparser.h"
@ -71,13 +79,15 @@ public:
System system;
// false at the beginning
// !! moze to do loggera dac?
bool stdout_is_closed;
/*
controller
controllers
(note that the whole app object is actually a controller too)
*/
// functions (ls, cat, emacs, ...)
@ -93,13 +103,53 @@ public:
private:
enum Header
{
h_200,
h_404,
h_403
};
GetParser get_parser;
PostParser post_parser;
PostMultiParser post_multi_parser;
CookieParser cookie_parser;
AcceptEncodingParser accept_encoding_parser;
Compress compress;
HTMLFilter html_filter;
std::string clean_html, html_with_debug;
bool CreateFCGISocket();
void ProcessRequestThrow();
void ProcessRequest();
bool BaseUrlRedirect();
void DeleteAllPluginsData();
void MakePage();
void Make();
void SaveSessionsIfNeeded(); // !! wywalic do managara sesji??
void LogAccess();
void ReadRequest();
void SendAnswer();
void SetEnv(const char * & env, const char * name);
void ReadEnvVariables();
void ReadGetPostVars();
void CheckIE();
void CheckKonqueror();
void CheckRequestMethod();
void CheckFCGIRole();
void SetHtmlFilterConf();
void PrepareSessionCookie();
void AddDebugInfo(std::string & out);
void FilterCompressSend(bool compressing, const std::string & source_ref);
void SendHeaders(bool compressing, Header header);
bool IsCompressionAllowed(const std::string & source);
bool CanSendContent(Header header);
// !! dodac do session managera?
time_t last_sessions_save;

@ -91,6 +91,7 @@ void Config::AssignValues(bool stdout_is_closed)
{
log_file = Text("log_file");
log_notify_file = Text("log_notify_file");
log_delimiter = Text("log_delimiter", "---------------------------------------------------------------------------------");
fcgi_socket = Text("fcgi_socket");
fcgi_socket_chmod = Int("fcgi_socket_chmod", 0770);
fcgi_socket_user = Text("fcgi_socket_user");
@ -132,7 +133,15 @@ void Config::AssignValues(bool stdout_is_closed)
session_file = Text("session_file");
compression = Bool("compression", true);
html_filter = Bool("html_filter", true);
compression_page_min_size = Int("compression_page_min_size", 512);
html_filter = Bool("html_filter", true);
html_filter_trim_white = Bool("html_filter_trim_white", true);
html_filter_break_lines = Int("html_filter_break_lines", 60);
html_filter_tabs = Size("html_filter_tabs", 2);
html_filter_orphans = Bool("html_filter_orphans", false);
html_filter_orphans_lang_str = Text("html_filter_orphans_lang", "pl");
html_filter_orphans_mode_str = Text("html_filter_orphans_mode_str", "nbsp");
locale_str = Text("locale", "en");
locale_dir = Text("locale_dir");
@ -140,6 +149,10 @@ void Config::AssignValues(bool stdout_is_closed)
title_separator = Text("title_separator", " / ");
http_header_send_file = Text("http_header_send_file", "X-LIGHTTPD-send-file");
password_min_size = Size("password_min_size", 5);
debug_info = Bool("debug_info", false);
parser.ListText("plugins", plugin_file);
}
@ -148,6 +161,22 @@ void Config::SetAdditionalVariables()
{
SetHttpHost(base_url, base_url_http_host);
SetHttpHost(base_url_auth, base_url_auth_http_host);
if( html_filter_orphans_lang_str == "pl" )
html_filter_orphans_lang = HTMLFilter::lang_pl;
else
if( html_filter_orphans_lang_str == "cz" )
html_filter_orphans_lang = HTMLFilter::lang_cz;
else
if( html_filter_orphans_lang_str == "sk" )
html_filter_orphans_lang = HTMLFilter::lang_sk;
else
html_filter_orphans_lang = HTMLFilter::lang_none;
if( html_filter_orphans_mode_str == "160" )
html_filter_orphans_mode = HTMLFilter::orphan_160space;
else
html_filter_orphans_mode = HTMLFilter::orphan_nbsp;
}
@ -201,6 +230,24 @@ int Config::Int(const std::string & name, int def)
}
size_t Config::Size(const char * name)
{
return parser.Size(name);
}
size_t Config::Size(const char * name, size_t def)
{
return parser.Size(name, def);
}
size_t Config::Size(const std::string & name, size_t def)
{
return parser.Size(name, def);
}
bool Config::Bool(const char * name)
{
return parser.Bool(name);

@ -12,6 +12,7 @@
#include <string>
#include "confparser.h"
#include "htmlfilter.h"
@ -38,6 +39,9 @@ public:
// default: 1
int log_request;
// request delimiter in the log file, default "---------"
std::string log_delimiter;
// fast cgi: socket (unix domain)
std::string fcgi_socket;
@ -80,13 +84,45 @@ public:
// allow the html ouput to be compressed
bool compression;
// if the output is shorter than this value then it will not be compressed
int compression_page_min_size;
// plugins
std::vector<std::string> plugin_file;
// the html code is cleaned by our filter
// should the html code be cleaned by the html filter
bool html_filter;
// should white characters be trimmed
bool html_filter_trim_white;
// when long lines (lines without a white character) should be break (inserted a space)
// default: after 60 non white characters will be put a space
// set zero to turn off
int html_filter_break_lines;
// how many spaces will be put at one tree level
// default: 2
size_t html_filter_tabs;
// use checking for 'orphans' for a specicic language
// default: false
bool html_filter_orphans;
// language for html orphans
// default: pl
// can be either: "pl" or "cz" or "sk"
std::string html_filter_orphans_lang_str;
HTMLFilter::Lang html_filter_orphans_lang;
// orphans mode
// either: "nbsp" or "160"
// default: "nbsp"
std::string html_filter_orphans_mode_str;
HTMLFilter::OrphanMode html_filter_orphans_mode;
// the url of a new empty item (if there is not the subject too)
std::string item_url_empty;
@ -129,6 +165,21 @@ public:
// separator used in <title> html tag
std::string title_separator;
// http header recognized by www server as a file to send back
// default: X-LIGHTTPD-send-file
std::string http_header_send_file;
// the minimum size of a password for new users (function: adduser)
// default: 5
size_t password_min_size;
// prints additional information (in the end of the html page as a commentary)
//
bool debug_info;
/*
*/
// based on base_url
// set by SetAdditionalVariables()
@ -146,6 +197,9 @@ public:
int Int(const char *);
int Int(const char * name, int def);
int Int(const std::string & name, int def);
size_t Size(const char *);
size_t Size(const char * name, size_t def);
size_t Size(const std::string & name, size_t def);
bool Bool(const char *);
bool Bool(const char * name, bool def);
bool Bool(const std::string & name, bool def);

@ -7,6 +7,7 @@
*
*/
#include <cstdlib>
#include "confparser.h"
#include "misc.h"
@ -27,6 +28,7 @@ ConfParser::ConfParser()
default_str = "";
default_int = 0;
default_size = 0;
default_bool = false;
}
@ -454,6 +456,48 @@ return ToInt(i->second);
}
size_t ConfParser::Size(const char * name)
{
return Size(std::string(name), default_size);
}
size_t ConfParser::Size(const char * name, size_t def)
{
return Size(std::string(name), def);
}
size_t ConfParser::ToSize(const std::string & value)
{
long res = (value[0] == '0')? strtoul(value.c_str() + 1, 0, 8) : strtoul(value.c_str(), 0, 10);
return (size_t)res;
}
size_t ConfParser::Size(const std::string & name, size_t def)
{
TableSingle::iterator i = table_single.find(name);
if( i == table_single.end() )
{
Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() )
return def;
return ToSize(t->second[0]);
}
return ToSize(i->second);
}
bool ConfParser::Bool(const char * name)
{
return Bool(std::string(name), default_bool);
@ -503,6 +547,11 @@ void ConfParser::SetDefaultInt(int def)
default_int = def;
}
void ConfParser::SetDefaultSize(size_t def)
{
default_size = def;
}
void ConfParser::SetDefaultBool(bool def)
{
default_bool = def;

@ -215,6 +215,9 @@ public:
int Int(const char *);
int Int(const char * name, int def);
int Int(const std::string & name, int def);
size_t Size(const char *);
size_t Size(const char * name, size_t def);
size_t Size(const std::string & name, size_t def);
bool Bool(const char *);
bool Bool(const char * name, bool def);
bool Bool(const std::string & name, bool def);
@ -226,11 +229,12 @@ public:
if you don't set it directly then:
default text is: "" (empty)
default int is: 0
default int or size is: 0
default bool is: false
*/
void SetDefaultText(const std::string & def);
void SetDefaultInt(int def);
void SetDefaultSize(size_t def);
void SetDefaultBool(bool def);
@ -324,9 +328,11 @@ private:
std::string default_str;
int default_int;
size_t default_size;
bool default_bool;
int ToInt(const std::string & value);
size_t ToSize(const std::string & value);
bool ToBool(const std::string & value);
Status ParseFile();

@ -21,7 +21,7 @@ class CookieParser : public HttpSimpleParser
{
const char * cookie_string;
CookieTab & cookie_tab;
CookieTab * cookie_tab;
protected:
@ -41,7 +41,7 @@ protected:
// Cookie names are case insensitive according to section 3.1 of RFC 2965
ToLower(name);
std::pair<CookieTab::iterator, bool> res = cookie_tab.insert( std::make_pair(name, value) );
std::pair<CookieTab::iterator, bool> res = cookie_tab->insert( std::make_pair(name, value) );
log << log2 << "Cookie, name: \"" << name << "\", value: \"" << value << "\"";
@ -58,7 +58,7 @@ protected:
public:
CookieParser(const char * cookie_string_, CookieTab & cookie_tab_) : cookie_string(cookie_string_), cookie_tab(cookie_tab_)
CookieParser()
{
HttpSimpleParser::separator = ';';
HttpSimpleParser::value_can_be_quoted = true;
@ -66,6 +66,16 @@ public:
HttpSimpleParser::recognize_special_chars = false;
}
// cookie_string can be null
void Parse(const char * cookie_string_, CookieTab & cookie_tab_)
{
cookie_string = cookie_string_;
cookie_tab = &cookie_tab_;
HttpSimpleParser::Parse();
}
};

@ -215,7 +215,7 @@ void Db::ClearResult(PGresult * r)
}
bool Db::CheckUser(std::string & login, std::string & password, long & user_id)
bool Db::CheckUser(const std::string & login, const std::string & password, long & user_id)
{
PGresult * r = 0;
bool user_ok = false;

@ -43,7 +43,7 @@ public:
// !! GetFile i GetDir beda uzywac GetItem
void Init(const std::string & database, const std::string & user, const std::string & pass);
bool CheckUser(std::string & login, std::string & password, long & user_id);
bool CheckUser(const std::string & login, const std::string & password, long & user_id);
Error AddUser(User & user, const std::string & password);
Error AddItem(Item & item);

@ -18,7 +18,7 @@ class GetParser : public HttpSimpleParser
{
const char * get_string;
GetTab & get_tab;
GetTab * get_tab;
protected:
@ -33,8 +33,7 @@ protected:
virtual void Parameter(std::string &, std::string & value)
{
get_tab.push_back(value);
get_tab->push_back(value);
log << log2 << "Get, value: \"" << value << "\"" << logend;
}
@ -42,13 +41,27 @@ protected:
public:
GetParser(const char * get_string_, GetTab & get_tab_) : get_string(get_string_), get_tab(get_tab_)
GetParser()
{
HttpSimpleParser::separator = '/';
HttpSimpleParser::read_name = false;
if( get_string && *get_string == separator ) // one '/' at the beginning
}
// get_string_ can be null
void Parse(const char * get_string_, GetTab & get_tab_)
{
get_string = get_string_;
get_tab = &get_tab_;
if( get_string && *get_string == separator )
{
// skipping one '/' at the beginning
++get_string;
}
HttpSimpleParser::Parse();
}
};

@ -46,7 +46,7 @@ protected:
void TrimWhiteChars(std::string & s);
void CheckSpecialChar();
void Parse();
public:
@ -60,12 +60,6 @@ public:
skip_white_chars = false;
recognize_special_chars = true;
}
void Parse();
};

@ -15,7 +15,6 @@
// PluginInfo.p1 is a pointer to Ezc::Functions object
#define WINIX_TEMPLATES_CREATEFUNCTIONS 999
#define WINIX_REQUEST_CLEAR 1000
#define WINIX_CONTENT_MAKE 2000

@ -22,7 +22,7 @@ class PostParser : public HttpSimpleParser
{
FCGX_Stream * in;
PostTab & post_tab;
PostTab * post_tab;
protected:
@ -35,7 +35,7 @@ protected:
virtual void Parameter(std::string & name, std::string & value)
{
std::pair<PostTab::iterator, bool> res = post_tab.insert( std::make_pair(name, value) );
std::pair<PostTab::iterator, bool> res = post_tab->insert( std::make_pair(name