we can create links (hard links, symbolic links) now

added winix functions: ln

winix function 'default' can be used without redirecting now

added new tickets types: TypeProgress, TypeString, TypeMultistring, TypeImages, TypeFiles
now tickets are combined with files
added winix functions: showtickets

fixed mountpoints:
when the default root mount was created its parameter table was empty
and it caused accessing to a non-existing objects

fixed logger:
modifiers (log1, log2, log3) were incorrectly treated
added modifier: log4 (debug info)

now we are moving threads to a new plugin 'thread'
created directory: plugins/thread
(not finished yet)




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@704 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2011-01-05 21:24:11 +00:00
parent bb83aed20d
commit 8154c403d8
113 changed files with 5840 additions and 2972 deletions

View File

@ -23,12 +23,13 @@ app.o: ../functions/functionbase.h ../core/request.h ../core/system.h
app.o: ../core/synchro.h ../functions/functionparser.h ../functions/adduser.h
app.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
app.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
app.o: ../functions/createthread.h ../functions/default.h
app.o: ../functions/download.h ../functions/emacs.h ../functions/last.h
app.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
app.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
app.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
app.o: ../functions/run.h ../functions/specialdefault.h ../functions/stat.h
app.o: ../functions/createthread.h ../functions/functionbase.h
app.o: ../functions/default.h ../functions/download.h ../functions/emacs.h
app.o: ../functions/last.h ../functions/login.h ../functions/logout.h
app.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
app.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
app.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
app.o: ../functions/specialdefault.h ../functions/stat.h
app.o: ../functions/subject.h ../functions/funthread.h
app.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
app.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
@ -65,13 +66,14 @@ config.o: ../core/request.h ../core/system.h ../core/synchro.h
config.o: ../functions/functionparser.h ../functions/adduser.h
config.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
config.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
config.o: ../functions/createthread.h ../functions/default.h
config.o: ../functions/download.h ../functions/emacs.h ../functions/last.h
config.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
config.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
config.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
config.o: ../functions/run.h ../functions/specialdefault.h
config.o: ../functions/stat.h ../functions/subject.h ../functions/funthread.h
config.o: ../functions/createthread.h ../functions/functionbase.h
config.o: ../functions/default.h ../functions/download.h ../functions/emacs.h
config.o: ../functions/last.h ../functions/login.h ../functions/logout.h
config.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
config.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
config.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
config.o: ../functions/specialdefault.h ../functions/stat.h
config.o: ../functions/subject.h ../functions/funthread.h
config.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
config.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
config.o: ../functions/vim.h ../core/htmlfilter.h ../templates/templates.h
@ -164,13 +166,14 @@ mounts.o: ../core/synchro.h ../functions/functionparser.h
mounts.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
mounts.o: ../functions/privchanger.h ../functions/chown.h
mounts.o: ../functions/ckeditor.h ../functions/cp.h
mounts.o: ../functions/createthread.h ../functions/default.h
mounts.o: ../functions/download.h ../functions/emacs.h ../functions/last.h
mounts.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
mounts.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
mounts.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
mounts.o: ../functions/run.h ../functions/specialdefault.h
mounts.o: ../functions/stat.h ../functions/subject.h ../functions/funthread.h
mounts.o: ../functions/createthread.h ../functions/functionbase.h
mounts.o: ../functions/default.h ../functions/download.h ../functions/emacs.h
mounts.o: ../functions/last.h ../functions/login.h ../functions/logout.h
mounts.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
mounts.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
mounts.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
mounts.o: ../functions/specialdefault.h ../functions/stat.h
mounts.o: ../functions/subject.h ../functions/funthread.h
mounts.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
mounts.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
mounts.o: ../functions/vim.h ../core/htmlfilter.h ../templates/templates.h
@ -201,13 +204,14 @@ plugin.o: ../core/request.h ../core/system.h ../core/synchro.h
plugin.o: ../functions/functionparser.h ../functions/adduser.h
plugin.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
plugin.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
plugin.o: ../functions/createthread.h ../functions/default.h
plugin.o: ../functions/download.h ../functions/emacs.h ../functions/last.h
plugin.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
plugin.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
plugin.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
plugin.o: ../functions/run.h ../functions/specialdefault.h
plugin.o: ../functions/stat.h ../functions/subject.h ../functions/funthread.h
plugin.o: ../functions/createthread.h ../functions/functionbase.h
plugin.o: ../functions/default.h ../functions/download.h ../functions/emacs.h
plugin.o: ../functions/last.h ../functions/login.h ../functions/logout.h
plugin.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
plugin.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
plugin.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
plugin.o: ../functions/specialdefault.h ../functions/stat.h
plugin.o: ../functions/subject.h ../functions/funthread.h
plugin.o: ../functions/template.h ../functions/tinymce.h ../functions/uname.h
plugin.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
plugin.o: ../functions/vim.h ../core/htmlfilter.h ../templates/templates.h
@ -239,21 +243,22 @@ plugindata.o: ../core/synchro.h ../functions/functionparser.h
plugindata.o: ../functions/adduser.h ../functions/cat.h ../functions/chmod.h
plugindata.o: ../functions/privchanger.h ../functions/chown.h
plugindata.o: ../functions/ckeditor.h ../functions/cp.h
plugindata.o: ../functions/createthread.h ../functions/default.h
plugindata.o: ../functions/download.h ../functions/emacs.h
plugindata.o: ../functions/last.h ../functions/login.h ../functions/logout.h
plugindata.o: ../functions/ls.h ../functions/mkdir.h ../functions/mv.h
plugindata.o: ../functions/node.h ../functions/priv.h ../functions/reload.h
plugindata.o: ../functions/rm.h ../functions/run.h
plugindata.o: ../functions/specialdefault.h ../functions/stat.h
plugindata.o: ../functions/subject.h ../functions/funthread.h
plugindata.o: ../functions/template.h ../functions/tinymce.h
plugindata.o: ../functions/uname.h ../functions/upload.h
plugindata.o: ../functions/uptime.h ../functions/who.h ../functions/vim.h
plugindata.o: ../core/htmlfilter.h ../templates/templates.h
plugindata.o: ../templates/patterncacher.h ../templates/ckeditorgetparser.h
plugindata.o: ../core/httpsimpleparser.h ../core/log.h
plugindata.o: ../templates/indexpatterns.h ../core/sessionmanager.h
plugindata.o: ../functions/createthread.h ../functions/functionbase.h
plugindata.o: ../functions/default.h ../functions/download.h
plugindata.o: ../functions/emacs.h ../functions/last.h ../functions/login.h
plugindata.o: ../functions/logout.h ../functions/ln.h ../functions/ls.h
plugindata.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
plugindata.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
plugindata.o: ../functions/run.h ../functions/specialdefault.h
plugindata.o: ../functions/stat.h ../functions/subject.h
plugindata.o: ../functions/funthread.h ../functions/template.h
plugindata.o: ../functions/tinymce.h ../functions/uname.h
plugindata.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
plugindata.o: ../functions/vim.h ../core/htmlfilter.h
plugindata.o: ../templates/templates.h ../templates/patterncacher.h
plugindata.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
plugindata.o: ../core/log.h ../templates/indexpatterns.h
plugindata.o: ../core/sessionmanager.h
postmultiparser.o: postmultiparser.h error.h requesttypes.h config.h
postmultiparser.o: confparser.h htmlfilter.h log.h textstream.h
postmultiparser.o: ../../ezc/src/utf8.h misc.h item.h
@ -284,9 +289,10 @@ request.o: ../core/request.h ../core/system.h ../core/synchro.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/default.h
request.o: ../functions/download.h ../functions/emacs.h ../functions/last.h
request.o: ../functions/login.h ../functions/logout.h ../functions/ls.h
request.o: ../functions/createthread.h ../functions/functionbase.h
request.o: ../functions/default.h ../functions/download.h
request.o: ../functions/emacs.h ../functions/last.h ../functions/login.h
request.o: ../functions/logout.h ../functions/ln.h ../functions/ls.h
request.o: ../functions/mkdir.h ../functions/mv.h ../functions/node.h
request.o: ../functions/priv.h ../functions/reload.h ../functions/rm.h
request.o: ../functions/run.h ../functions/specialdefault.h
@ -332,19 +338,20 @@ 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/default.h
sessionmanager.o: ../functions/download.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/specialdefault.h
sessionmanager.o: ../functions/stat.h ../functions/subject.h
sessionmanager.o: ../functions/funthread.h ../functions/template.h
sessionmanager.o: ../functions/tinymce.h ../functions/uname.h
sessionmanager.o: ../functions/upload.h ../functions/uptime.h
sessionmanager.o: ../functions/who.h ../functions/vim.h ../core/htmlfilter.h
sessionmanager.o: ../templates/templates.h ../templates/patterncacher.h
sessionmanager.o: ../functions/createthread.h ../functions/functionbase.h
sessionmanager.o: ../functions/default.h ../functions/download.h
sessionmanager.o: ../functions/emacs.h ../functions/last.h
sessionmanager.o: ../functions/login.h ../functions/logout.h
sessionmanager.o: ../functions/ln.h ../functions/ls.h ../functions/mkdir.h
sessionmanager.o: ../functions/mv.h ../functions/node.h ../functions/priv.h
sessionmanager.o: ../functions/reload.h ../functions/rm.h ../functions/run.h
sessionmanager.o: ../functions/specialdefault.h ../functions/stat.h
sessionmanager.o: ../functions/subject.h ../functions/funthread.h
sessionmanager.o: ../functions/template.h ../functions/tinymce.h
sessionmanager.o: ../functions/uname.h ../functions/upload.h
sessionmanager.o: ../functions/uptime.h ../functions/who.h ../functions/vim.h
sessionmanager.o: ../core/htmlfilter.h ../templates/templates.h
sessionmanager.o: ../templates/patterncacher.h
sessionmanager.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
sessionmanager.o: ../core/log.h ../templates/indexpatterns.h
sessionmanager.o: ../core/sessionmanager.h
@ -376,11 +383,24 @@ system.o: ../templates/templates.h ../templates/patterncacher.h
system.o: ../templates/ckeditorgetparser.h ../core/httpsimpleparser.h
system.o: ../core/log.h ../templates/indexpatterns.h ../core/request.h
system.o: ../core/system.h ../core/sessionmanager.h
system.o: ../functions/functionbase.h
textstream.o: textstream.h misc.h item.h
thumb.o: thumb.h basethread.h textstream.h ../db/db.h ../db/dbbase.h
thumb.o: ../db/dbconn.h ../db/dbtextstream.h ../core/textstream.h misc.h
thumb.o: item.h ../core/error.h log.h ../db/dbitemquery.h ../core/item.h
thumb.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h
thumb.o: ../core/thread.h ../core/dircontainer.h ../core/ugcontainer.h
thumb.o: ../../ezc/src/utf8.h
thumb.o: ../core/config.h ../../ezc/src/utf8.h system.h dirs.h dircontainer.h
thumb.o: request.h requesttypes.h session.h error.h user.h plugindata.h
thumb.o: rebus.h config.h confparser.h htmlfilter.h
thumb.o: ../templates/htmltextstream.h ../notify/notify.h
thumb.o: ../notify/notifypool.h ../templates/locale.h ../core/confparser.h
thumb.o: ../templates/misc.h ../templates/localefilter.h
thumb.o: ../templates/locale.h ../../ezc/src/ezc.h ../../ezc/src/generator.h
thumb.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
thumb.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h
thumb.o: ../templates/htmltextstream.h ../notify/notifythread.h
thumb.o: ../core/basethread.h synchro.h ../notify/templatesnotify.h
thumb.o: ../core/users.h ugcontainer.h lastcontainer.h mounts.h mount.h
thumb.o: mountparser.h users.h groups.h group.h loadavg.h
users.o: users.h

View File

@ -182,7 +182,7 @@ return true;
void App::ProcessRequestThrow()
{
ReadRequest();
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
@ -214,15 +214,11 @@ void App::ProcessRequest()
log << log2 << config.log_delimiter << logend;
ProcessRequestThrow();
SaveSessionsIfNeeded();
if( request.function )
request.function->Clear();
SaveSessionsIfNeeded(); // !! przerzucic to na watek sesji
request.Clear();
system.load_avg.StopRequest();
log << logsave;
log << logendrequest;
}
catch(const std::exception & e)
{
@ -313,20 +309,13 @@ void App::Make()
// request.status can be changed by function_parser
if( request.status == WINIX_ERR_OK )
{
plugin.Call(WINIX_PREPARE_REQUEST);
if( system.DirsHaveReadExecPerm() )
{
if( request.method == Request::post )
functions.MakePost();
if( request.redirect_to.empty() && request.status == WINIX_ERR_OK )
functions.MakeGet();
}
else
request.status = WINIX_ERR_PERMISSION_DENIED;
}
if( request.status == WINIX_ERR_OK )
functions.CheckFunctionAndSymlink();
if( request.status == WINIX_ERR_OK )
functions.MakeFunction();
if( request.session->spam_score > 0 )
log << log1 << "App: spam score: " << request.session->spam_score << logend;
@ -538,17 +527,17 @@ void App::SendHeaders(bool compressing, Header header)
if( !request.redirect_to.empty() )
{
FCGX_PutS("Status: 301 Moved Permanently\r\n", fcgi_request.out);
AssignString(request.redirect_to, request.aredirect_to);
UrlEncode(request.redirect_to, request.aredirect_to);
FCGX_FPrintF(fcgi_request.out, "Location: %s\r\n", request.aredirect_to.c_str());
log << log2 << "Redirect to: " << request.redirect_to << logend;
log << log2 << "Redirect to: " << request.aredirect_to << logend;
}
else
if( !request.x_sendfile.empty() )
{
static std::string temp, temp2; // !! wrzucic gdzies to
AssignString(config.http_header_send_file, temp);
AssignString(request.x_sendfile, temp2);
Ezc::WideToUTF8(config.http_header_send_file, temp);
Ezc::WideToUTF8(request.x_sendfile, temp2);
FCGX_FPrintF(fcgi_request.out, "%s: %s\r\n", temp.c_str(), temp2.c_str());
FCGX_PutS("Status: 200 OK\r\n", fcgi_request.out);
@ -833,7 +822,7 @@ bool App::DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool ad
{
if( initgroups(user.c_str(), gid) < 0 )
{
log << log1 << "App: I can't init groups for user: " << user << logend << logsave;
log << log1 << "App: I can't init groups for user: " << user << logend;
return false;
}
}
@ -841,7 +830,7 @@ bool App::DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool ad
{
if( setgroups(1, &gid) < 0 )
{
log << log1 << "App: I can't init groups for user: " << user << logend << logsave;
log << log1 << "App: I can't init groups for user: " << user << logend;
return false;
}
}
@ -849,20 +838,20 @@ bool App::DropPrivileges(const std::string & user, uid_t uid, gid_t gid, bool ad
// for setting real and saved gid too
if( setgid(gid) )
{
log << log1 << "App: I can't change real and saved gid" << logend << logsave;
log << log1 << "App: I can't change real and saved gid" << logend;
return false;
}
if( setuid(uid) < 0 )
{
log << log1 << "App: I can't drop privileges to user: " << user
<< " (uid:" << (int)uid << ")" << logend << logsave;
<< " (uid:" << (int)uid << ")" << logend;
return false;
}
if( getuid()==0 || geteuid()==0 )
{
log << log1 << "App: sorry, for security reasons you should not run me as the root" << logend << logsave;
log << log1 << "App: sorry, for security reasons you should not run me as the root" << logend;
return false;
}
@ -880,14 +869,14 @@ bool App::DropPrivileges()
if( config.user.empty() )
{
log << log1 << "App: you should specify user name in the config file "
<< "to which I have to drop privileges" << logend << logsave;
<< "to which I have to drop privileges" << logend;
return false;
}
if( config.group.empty() )
{
log << log1 << "App: you should specify group name in the config file "
<< "to which I have to drop privileges" << logend << logsave;
<< "to which I have to drop privileges" << logend;
return false;
}
@ -896,13 +885,13 @@ bool App::DropPrivileges()
if( !p )
{
log << log1 << "App: there is no such a user as: \"" << config.user << "\"" << logend << logsave;
log << log1 << "App: there is no such a user as: \"" << config.user << "\"" << logend;
return false;
}
if( !g )
{
log << log1 << "App: there is no such a group as: \"" << config.group << "\"" << logend << logsave;
log << log1 << "App: there is no such a group as: \"" << config.group << "\"" << logend;
return false;
}
@ -922,7 +911,7 @@ bool App::Demonize()
if( pid == -1 )
{
log << log1 << "App: I can't demonize myself (fork problem)" << logend << logsave;
log << log1 << "App: I can't demonize myself (fork problem)" << logend;
return false;
}
@ -935,7 +924,7 @@ bool App::Demonize()
// child
if( setsid() == -1 )
{
log << log1 << "App: I can't demonize myself (setsid problem)" << logend << logsave;
log << log1 << "App: I can't demonize myself (setsid problem)" << logend;
return false;
}

View File

@ -105,6 +105,7 @@ void Config::AssignValues(bool stdout_is_closed)
fcgi_socket_group = AText(L"fcgi_socket_group");
log_level = Int(L"log_level", 1);
log_request = Int(L"log_request", 1);
log_save_each_line = Bool(L"log_save_each_line", false);
log_stdout = Bool(L"log_stdout", false);
log_db_query = Bool(L"log_db_query", false);
log_plugin_call = Bool(L"log_plugin_call", false);
@ -184,6 +185,9 @@ void Config::AssignValues(bool stdout_is_closed)
time_zone_offset_guest = Int(L"time_zone_offset_guest", 0);
utf8 = Bool(L"utf8", true);
symlinks_follow_max = Size(L"symlinks_follow_max", 20);
ticket_form_prefix = Text(L"ticket_form_prefix", L"ticketparam");
}

View File

@ -56,10 +56,14 @@ public:
// default: false
bool log_stdout;
// how many requests should be logged in the same time
// how many requests should be saved in the same time
// default: 1
int log_request;
// whether to save each line of the config (use it for debug purposes)
// default: false
bool log_save_each_line;
// logging db queries
// default: false
bool log_db_query;
@ -285,6 +289,14 @@ public:
// if false it means 8-bit ASCII
bool utf8;
// how many maximum symlinks can be followed
// (symlinks on directories as well)
// default: 20
size_t symlinks_follow_max;
// the prefix of a name of html form controls used in the ticket plugin
// default: ticketparam
std::wstring ticket_form_prefix;
/*
*/

View File

@ -91,9 +91,9 @@ void DirContainer::FindSpecialFolders()
if( !is_root )
return;
DirContainer::ParentIterator i = FindFirstParent(root_iter->id);
DirContainer::ParentIterator i = FindFirstChild(root_iter->id);
for( ; i!=ParentEnd() ; i = NextParent(i) )
for( ; i!=ParentEnd() ; i = NextChild(i) )
{
if( i->second->url == dir_etc )
{
@ -126,14 +126,14 @@ void DirContainer::CheckSpecialFolder(const Item & item, Iterator iter)
{
is_etc = true;
etc_iter = iter;
log << log1 << "DirCont: added special folder: /etc" << logend;
log << log2 << "DirCont: added special folder: /etc" << logend;
}
if( item.parent_id==root_iter->id && item.url==dir_var )
{
is_var = true;
var_iter = iter;
log << log1 << "DirCont: added special folder: /var" << logend;
log << log2 << "DirCont: added special folder: /var" << logend;
}
}
@ -172,10 +172,10 @@ bool DirContainer::ChangeParent(long dir_id, long new_parent_id)
if( i->parent_id == new_parent_id )
return true; // nothing to do
ParentIterator p = FindFirstParent(i->parent_id);
ParentIterator p = FindFirstChild(i->parent_id);
bool found = false;
for( ; p != table_parent.end() ; p = NextParent(p) )
for( ; p != table_parent.end() ; p = NextChild(p) )
{
if( p->second->id == dir_id )
{
@ -251,7 +251,7 @@ bool DirContainer::ParentEmpty()
}
DirContainer::ParentIterator DirContainer::FindFirstParent(long parent)
DirContainer::ParentIterator DirContainer::FindFirstChild(long parent)
{
ParentIterator i = table_parent.lower_bound(parent);
@ -262,7 +262,7 @@ return i;
}
DirContainer::ParentIterator DirContainer::NextParent(ParentIterator i)
DirContainer::ParentIterator DirContainer::NextChild(ParentIterator i)
{
if( i == table_parent.end() )
return table_parent.end();

View File

@ -52,8 +52,8 @@ public:
ParentIterator ParentEnd();
ParentSizeType ParentSize();
bool ParentEmpty();
ParentIterator FindFirstParent(long parent);
ParentIterator NextParent(ParentIterator pi);
ParentIterator FindFirstChild(long parent);
ParentIterator NextChild(ParentIterator pi);
bool IsNameOfSpecialFolder(const std::wstring & name);
void FindSpecialFolders();

View File

@ -70,7 +70,6 @@ void Dirs::CheckRootDir()
root.user_id = -1;
root.group_id = -1;
root.privileges = 0755;
root.default_item = -1;
// !! upewnic sie ze baza nie zmieni url (gdyby wczesniej juz byl w bazie pusty url)
// !! zrobic jakis wyjatek do wprowadzania roota?
@ -129,26 +128,26 @@ bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_tab)
if( parent != -1 && !IsDir(parent) )
return false;
DirContainer::ParentIterator i = dir_tab.FindFirstParent(parent);
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent);
for( ; i != dir_tab.ParentEnd() ; i = dir_tab.NextParent(i) )
for( ; i != dir_tab.ParentEnd() ; i = dir_tab.NextChild(i) )
childs_tab.push_back( &(*i->second) );
return true;
}
DirContainer::ParentIterator Dirs::FindFirstParent(long parent_id)
DirContainer::ParentIterator Dirs::FindFirstChild(long parent_id)
{
DirContainer::ParentIterator i = dir_tab.FindFirstParent(parent_id);
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent_id);
return i;
}
DirContainer::ParentIterator Dirs::NextParent(DirContainer::ParentIterator i)
DirContainer::ParentIterator Dirs::NextChild(DirContainer::ParentIterator i)
{
return dir_tab.NextParent(i);
return dir_tab.NextChild(i);
}
@ -162,11 +161,14 @@ DirContainer::ParentIterator Dirs::ParentEnd()
// albo tutaj stringa nie czyscic?
// O(m * log n) (m- how many parts are in 'id')
// path with a slash at the end
bool Dirs::MakePath(long id, std::wstring & path)
bool Dirs::MakePath(long id, std::wstring & path, bool clear_path)
{
DirContainer::Iterator i;
path = '/';
if( clear_path )
path.clear();
temp_path = '/';
while( true )
{
@ -174,16 +176,21 @@ DirContainer::Iterator i;
if( i == dir_tab.End() ||
i->parent_id == id ) // means a loop (something wrong in the db)
{
// we don't change path if there is no such a directory
return false;
}
if( i->parent_id == -1 )
{
path += temp_path;
return true;
}
id = i->parent_id;
path.insert(0, i->url);
path.insert(path.begin(), '/');
temp_path.insert(0, i->url);
temp_path.insert(temp_path.begin(), '/');
}
}
@ -220,6 +227,33 @@ DirContainer::Iterator i;
bool Dirs::CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab)
{
DirContainer::Iterator i;
out_dir_tab.clear();
do
{
i = dir_tab.FindId(dir_id);
if( i == dir_tab.End() )
return false;
if( out_dir_tab.empty() )
out_dir_tab.insert(out_dir_tab.end(), &(*i)); // !! I am not sure whether begin() can be used on an empty container
else
out_dir_tab.insert(out_dir_tab.begin(), &(*i));
dir_id = i->parent_id;
}
while( dir_id != -1 );
return true;
}
Item * Dirs::GetRootDir()
{
DirContainer::Iterator root = dir_tab.GetRoot();
@ -255,9 +289,9 @@ return &(*etc);
Item * Dirs::GetDir(const std::wstring & name, long parent)
{
DirContainer::ParentIterator i = dir_tab.FindFirstParent(parent);
DirContainer::ParentIterator i = dir_tab.FindFirstChild(parent);
for( ; i!=dir_tab.ParentEnd() ; i = dir_tab.NextParent(i) )
for( ; i!=dir_tab.ParentEnd() ; i = dir_tab.NextChild(i) )
if( i->second->url == name )
return &(*i->second);
@ -276,7 +310,7 @@ Item * Dirs::GetDir(const std::wstring & path)
Item * pitem = &(*root);
std::wstring name;
std::wstring name; // !! dodac jako skladowa klasy
const wchar_t * s = path.c_str();
while( ExtractName(s, name) )
@ -287,7 +321,6 @@ Item * Dirs::GetDir(const std::wstring & path)
return 0;
}
return pitem;
}
@ -392,6 +425,135 @@ return 0;
// current_dir_tab can be the same container as out_dir_tab
void Dirs::CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out)
{
if( &in != &out )
{
out.resize(in.size());
for(size_t i=0 ; i<in.size() ; ++i)
out[i] = in[i];
}
}
size_t Dirs::AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to)
{
if( dir_tab.empty() )
return 0;
size_t i = 0;
size_t old_i;
while( true )
{
// skipping slashes
for( ; i<link_to.size() && link_to[i] == '/' ; ++i);
if( i == link_to.size() )
return i; // end of the path
// creating a name
old_i = i;
analyze_temp.clear();
for( ; i<link_to.size() && link_to[i] != '/' ; ++i)
analyze_temp += link_to[i];
Item * pdir = GetDir(analyze_temp, dir_tab.back()->id);
if( !pdir )
return old_i; // analyze_temp is not a directory
dir_tab.push_back(pdir);
}
}
int Dirs::FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item)
{
size_t i = AnalyzeDir(dir_tab, link_to);
if( i < link_to.size() )
{
// checking if at least one slash has left
for(size_t a=i ; a < link_to.size() ; ++a)
if( link_to[a] == '/' )
return 2; // there is not such a directory
// the rest of the path is a file name
out_item = link_to.c_str() + i;
return 1;
}
return 0;
}
/*
return codes:
ok:
0 - the link_to is a path to a directory (out_item skipped, out_dir_tab will not be empty)
1 - the link_to is a path to a file (out_item is used, out_dir_tab will not be empty)
error:
2 - incorrect link_to
3 - there is not a root dir
4 - current_dir_tab was empty
current_dir_tab can be the same container as out_dir_tab
link_to can be a relative path (without the first slash)
*/
int Dirs::FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
std::vector<Item*> & out_dir_tab, std::wstring & out_item)
{
temp_link_to = link_to; // link_to can be from the out_item and would be cleared next
out_item.clear();
if( current_dir_tab.empty() )
return 4;
if( temp_link_to.empty() )
{
CopyDirTab(current_dir_tab, out_dir_tab);
return 0;
}
if( temp_link_to[0] == '/' )
{
// temp_link_to is an absolute path
Item * pdir = GetRootDir();
if( !pdir )
return 3;
out_dir_tab.clear();
out_dir_tab.push_back(pdir);
}
else
{
// temp_link_to is a relative path
CopyDirTab(current_dir_tab, out_dir_tab);
}
return FollowLink(out_dir_tab, temp_link_to, out_item);
}
void Dirs::SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file)
{
@ -483,5 +645,15 @@ return var;
}
// printing first and last slash
void Dirs::LogDir(const std::vector<Item*> & dir_tab)
{
log << '/';
// skipping the first (root) directory
for(size_t i=1 ; i<dir_tab.size() ; ++i)
log << dir_tab[i]->url << '/';
}

View File

@ -39,16 +39,24 @@ public:
// these methods return false if there is no such a dir
bool IsDir(long dir_id);
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_tab); // !! zamienic na GetChilds()
bool MakePath(long dir_id, std::wstring & path);
bool MakePath(long dir_id, std::wstring & path, bool clear_path = true);
bool ChangeParent(long dir_id, long new_parent_id);
bool HasParent(long dir_id, long parent_id);
bool DelDir(long dir_id);
bool CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab);
void LogDir(const std::vector<Item*> & dir_tab);
int AnalyzePath(const std::wstring & path, long & dir_id, std::wstring & dir, std::wstring & file);
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
std::vector<Item*> & out_dir_tab, std::wstring & out_item);
static void SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file);
DirContainer::ParentIterator FindFirstParent(long parent_id); // !! zmienic w koncu nazwe na FindFirstChild
DirContainer::ParentIterator NextParent(DirContainer::ParentIterator i);
DirContainer::ParentIterator FindFirstChild(long parent_id); // !! zmienic w koncu nazwe na FindFirstChild
DirContainer::ParentIterator NextChild(DirContainer::ParentIterator i);
DirContainer::ParentIterator ParentEnd();
@ -76,10 +84,16 @@ private:
Notify * notify;
DirContainer dir_tab;
std::wstring temp_path;
std::wstring temp_link_to;
size_t AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir);
size_t AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to);
std::wstring analyze_temp;
void CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out);
int FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item);
bool ExtractName(const wchar_t * & s, std::wstring & name);
bool HasReadExecAccessForRoot(const Item & item);

View File

@ -55,7 +55,6 @@
#define WINIX_DIFFERENT_MOUNT_POINTS 29
#define WINIX_ERR_DB_FATAL_ERROR_DURING_CONNECTING 100
#define WINIX_ERR_DB_INCORRECT_QUERY 101
#define WINIX_ERR_DB_INCORRENT_RESULT_STATUS 102
@ -70,6 +69,8 @@
//#define WINIX_ERR_UNKNOWN 1000
#define WINIX_NOTHING_TO_DO 109
typedef int Error;

View File

@ -44,15 +44,19 @@ void Item::Clear()
subject.clear();
content.clear();
modify_index = 0;
url.clear();
content_type = ct_formatted_text;
type = none;
parent_id = -1;
default_item = -1;
link_to.clear();
link_redirect = false;
content_id = -1;
ref = 1;
file_path.clear();
file_fs = -1;

View File

@ -19,6 +19,8 @@
#define WINIX_ITEM_FILETYPE_UNKNOWN 3
struct Item
{
long id;
@ -38,8 +40,9 @@ tm date_modification;
std::wstring subject;
std::wstring content;
long content_id; // used by the database
std::wstring url;
int modify_index;
enum ContentType
{
@ -58,22 +61,24 @@ enum Type
{
dir = 0,
file = 1,
symlink = 2,
none = 1000 // !! pozbyc sie tego
none = 1000
};
Type type;
long default_item;
// used when type is symlink or to a directory too (function 'default')
std::wstring link_to;
int link_redirect;
// static file (if exists)
std::wstring file_path; // relative file path
int file_fs; // file system type where the file was saved
int file_type; // file type (none, image, doc, etc)
bool has_thumb;
@ -86,6 +91,14 @@ std::wstring html_template;
void SetDateModifyToNow();
void Clear();
private:
// used by the database
long content_id; // content id in 'content' table
int ref; // content references
friend class Db;
friend class DbItemColumns;
};

View File

@ -15,21 +15,29 @@
Log::Log()
{
log_level = 3;
current_level = 4; // nothing to log (call Init() first)
item = 0;
item_save = 1;
log_level = 1;
current_level = 100; // nothing to log (call Init() first)
request = 0;
max_requests = 1;
lines = 0;
max_lines = 5000;
log_file_open = false;
}
void Log::Init(int log_l, const std::string & log_f, bool log_std, int log_request)
Log::~Log()
{
log_level = log_l;
log_file = log_f;
log_stdout = log_std;
item_save = log_request;
SaveLogAndClear();
}
void Log::Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests)
{
log_level = log_level_;
log_file = log_file_;
log_stdout = log_std;
max_requests = log_max_requests;
save_each_line = save_each_line_;
// don't open the file here
// because it would be created with the root as an owner
@ -67,6 +75,9 @@ void Log::PutDate(Manipulators m)
Log & Log::operator<<(const void * s)
{
if( current_level > log_level )
return *this;
buffer << s;
return *this;
}
@ -75,6 +86,9 @@ Log & Log::operator<<(const void * s)
Log & Log::operator<<(const char * s)
{
if( current_level > log_level )
return *this;
if( !s )
return *this;
@ -87,7 +101,10 @@ return *this;
Log & Log::operator<<(const std::string & s)
{
buffer << s;
if( current_level > log_level )
return *this;
buffer << s;
return *this;
}
@ -95,7 +112,10 @@ Log & Log::operator<<(const std::string & s)
Log & Log::operator<<(const std::string * s)
{
buffer << *s;
if( current_level > log_level )
return *this;
buffer << *s;
return *this;
}
@ -106,10 +126,11 @@ Log & Log::operator<<(const std::string * s)
Log & Log::operator<<(const wchar_t * s)
{
if( !s )
return *this;
buffer << s;
if( current_level <= log_level )
{
if( s )
buffer << s;
}
return *this;
}
@ -118,7 +139,11 @@ return *this;
Log & Log::operator<<(const std::wstring & s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@ -126,7 +151,11 @@ Log & Log::operator<<(const std::wstring & s)
Log & Log::operator<<(const std::wstring * s)
{
buffer << *s;
if( current_level <= log_level )
{
buffer << *s;
}
return *this;
}
@ -136,7 +165,11 @@ Log & Log::operator<<(const std::wstring * s)
Log & Log::operator<<(int s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@ -144,7 +177,11 @@ Log & Log::operator<<(int s)
Log & Log::operator<<(long s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@ -153,7 +190,11 @@ Log & Log::operator<<(long s)
Log & Log::operator<<(char s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@ -161,7 +202,11 @@ Log & Log::operator<<(char s)
Log & Log::operator<<(size_t s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@ -169,7 +214,11 @@ Log & Log::operator<<(size_t s)
Log & Log::operator<<(double s)
{
buffer << s;
if( current_level <= log_level )
{
buffer << s;
}
return *this;
}
@ -180,36 +229,23 @@ Log & Log::operator<<(Manipulators m)
switch(m)
{
case logend:
buffer << '\n';
lines += 1;
//if( lines > 3000 )
if( current_level <= log_level )
{
SaveLog();
buffer.Clear();
item = 0;
lines = 0;
buffer << '\n';
lines += 1;
if( save_each_line )
SaveLogAndClear();
}
break;
case logsavenow:
SaveLog();
buffer.Clear();
item = 0;
lines = 0;
break;
case logsave:
item += 1;
SaveLogAndClear();
break;
if( item >= item_save || lines > 3000 )
{
SaveLog();
buffer.Clear();
item = 0;
lines = 0;
}
case logendrequest:
if( ++request >= max_requests || lines > max_lines )
SaveLogAndClear();
break;
case log1:
@ -223,6 +259,10 @@ Log & Log::operator<<(Manipulators m)
case log3:
current_level = 3;
break;
case log4:
current_level = 4;
break;
}
return *this;
@ -240,12 +280,18 @@ void Log::SystemErr(int err)
}
void Log::SaveLogAndClear()
{
SaveLog();
buffer.Clear();
request = 0;
lines = 0;
}
void Log::SaveLog()
{
if( current_level > log_level )
return;
if( buffer.Str().empty() )
return;

View File

@ -18,19 +18,24 @@
#include "textstream.h"
// !! dodac manipulator logsave, logi zostana zapisane pod koniec wykonywania jednego requesta (albo po kilku w zaleznosci od jakiejs opcji w konfigu)
// logsave zostanie wywolane w requestcontroller.cpp przy konczeniu wykonywania requesta
enum Manipulators { logsave, logsavenow, logend, log1, log2, log3 };
// log1 - the first level
// log2
// log3
// log4 - the last level (debug level)
// logend - the end of a line
// logendrequest - end of a current request
// logsave - current log buffer is saved and cleared
enum Manipulators { log1, log2, log3, log4, logend, logendrequest, logsave };
class Log
{
public:
Log();
void Init(int log_l, const std::string & log_f, bool log_std, int log_request);
~Log();
void Init(int log_level_, bool save_each_line_, const std::string & log_file_, bool log_std, int log_max_requests);
void PutDate(Manipulators m);
Log & operator<<(const void * s);
@ -49,17 +54,46 @@ public:
void SystemErr(int err);
void SaveLog();
void SaveLogAndClear();
private:
// buffer for the log
TextStream<std::wstring> buffer;
int log_level, current_level;
int item, item_save;
// log lovel from the config file
int log_level;
// current level set by a modifier (e.g. log << log3)
int current_level;
// current request for logging
// starts from zero and incremented after logendrequest modifier
int request;
// how many request to save at once
int max_requests;
// file log
std::string log_file;
bool log_stdout;
std::ofstream file;
// logging to stdout
bool log_stdout;
// how many lines there are in the buffer
int lines;
// is the config file already open
bool log_file_open;
// how many lines can be in the config buffer
// default: 5000
int max_lines;
// whether to save each line (for debug)
bool save_each_line;
void OpenFile();
};