fixed: the core didn't test for special folder when system was running

(now mkdir addes correctly special folders)
added: function 'reload'
       param: 'templates' - reloading templates


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@519 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2009-11-16 17:43:23 +00:00
parent 9129f1b82a
commit c62d48160a
13 changed files with 123 additions and 29 deletions

View File

@ -107,6 +107,13 @@ priv.o: ../core/error.h ../core/db.h ../core/group.h ../core/dircontainer.h
priv.o: ../core/ugcontainer.h ../core/data.h ../core/dirs.h ../core/users.h
priv.o: ../core/groups.h ../core/functions.h ../core/lastcontainer.h
priv.o: ../core/mounts.h ../core/mount.h
reload.o: content.h ../core/item.h ../templates/templates.h
reload.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
reload.o: ../core/requesttypes.h ../core/session.h ../core/done.h
reload.o: ../core/item.h ../core/error.h ../core/log.h ../core/user.h
reload.o: ../core/function.h ../core/thread.h ../core/compress.h
reload.o: ../core/acceptencodingparser.h ../core/acceptbaseparser.h
reload.o: ../core/error.h
rm.o: content.h ../core/item.h ../templates/templates.h
rm.o: ../templates/patterncacher.h ../core/thread.h ../core/request.h
rm.o: ../core/requesttypes.h ../core/session.h ../core/done.h ../core/item.h

View File

@ -1 +1 @@
o = cat.o content.o createthread.o default.o emacs.o last.o login.o logout.o ls.o mkdir.o node.o priv.o rm.o run.o thread.o who.o
o = cat.o content.o createthread.o default.o emacs.o last.o login.o logout.o ls.o mkdir.o node.o priv.o reload.o rm.o run.o thread.o who.o

View File

@ -19,8 +19,8 @@
bool Content::Init()
{
templates.Read();
templates.ReadTemplates();
templates.CreateFunctions();
return true;
}
@ -160,6 +160,9 @@ void Content::MakeStandardFunction()
if( request.pfunction->code == FUN_THREAD )
FunThread();
else
if( request.pfunction->code == FUN_RELOAD )
FunReload();
else
if( request.pfunction->code == FUN_CREATETHREAD )
FunCreateThread();
else

View File

@ -56,7 +56,10 @@ class Content
void FunRun();
void FunWho();
void FunLast();
void FunReloadTemplates();
void FunReload();
static bool FunThreadSort(const Thread & t1, const Thread & t2);
void FunThread();
void FunCreateThread();

45
content/reload.cpp Executable file
View File

@ -0,0 +1,45 @@
/*
* 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 "content.h"
#include "../core/request.h"
#include "../core/error.h"
void Content::FunReloadTemplates()
{
log << log1 << "Content: reloading html templates" << logend;
templates.ReadTemplates();
request.session->done = Done::reloaded_templates;
request.session->done_status = Error::ok;
request.session->done_timer = 1;
}
void Content::FunReload()
{
// !! temporarily only an admin has access
if( !request.session->puser || !request.session->puser->super_user )
{
log << log1 << "Content: Only an admin has access to reload function" << logend;
request.status = Error::permision_denied;
return;
}
if( request.IsParam("templates") )
FunReloadTemplates();
}

View File

@ -11,6 +11,9 @@
#include "log.h"
std::string DirContainer::dir_etc = "etc";
DirContainer::DirContainer()
{
is_root = false;
@ -62,10 +65,9 @@ bool DirContainer::Empty()
// looking for '/etc'
// 'root' is found beforehand
// CheckSpecialFolder() may not find everything (when the first is a special folder and then the root)
void DirContainer::FindSpecialFolders()
{
static std::string etc = "etc";
is_etc = false;
if( !is_root )
@ -75,7 +77,7 @@ static std::string etc = "etc";
for( ; i!=ParentEnd() ; i = NextParent(i) )
{
if( i->second->url == etc )
if( i->second->url == dir_etc )
{
is_etc = true;
etc_iter = i->second;
@ -85,6 +87,27 @@ static std::string etc = "etc";
}
// this is used with PushBack() method
void DirContainer::CheckSpecialFolder(const Item & item, Iterator iter)
{
if( item.parent_id == -1 )
{
is_root = true;
root_iter = iter;
}
if( !is_root )
return;
if( item.parent_id==root_iter->id && item.url==dir_etc )
{
is_etc = true;
etc_iter = iter;
log << log1 << "DirCont: added special folder: /etc" << logend;
}
}
DirContainer::Iterator DirContainer::PushBack(const Item & item)
{
if( item.parent_id == -1 && is_root )
@ -94,12 +117,7 @@ DirContainer::Iterator DirContainer::PushBack(const Item & item)
}
Iterator last_iter = table.insert(table.end(), item);
if( item.parent_id == -1 )
{
is_root = true;
root_iter = last_iter;
}
CheckSpecialFolder(item, last_iter);
log << log2 << "DirCont: added dir, url: " << item.url << ", id: " << item.id << ", parent_id: " << item.parent_id << logend;

View File

@ -57,6 +57,8 @@ public:
private:
void CheckSpecialFolder(const Item & item, Iterator iter);
// main table with dirs
Table table;
@ -75,6 +77,9 @@ private:
// indexes
TableId table_id;
TableParent table_parent;
// names of folders
static std::string dir_etc;
};

View File

@ -28,6 +28,7 @@ public:
added_dir,
added_thread,
defaulted_dir,
reloaded_templates,
loggedout
};

View File

@ -30,6 +30,7 @@
#define FUN_LAST 13
#define FUN_CREATETHREAD 14
#define FUN_THREAD 15
#define FUN_RELOAD 16

View File

@ -30,7 +30,7 @@ void Functions::ReadFunctions()
f.item.user_id = -1;
f.item.group_id = -1;
f.item.privileges = 0644;
f.item.privileges = 0755;
f.item.parent_id = -1; // !! temporarily doesn't matter
f.item.id = -1;
f.item.type = Item::file;
@ -96,9 +96,14 @@ void Functions::ReadFunctions()
f.item.url = "thread";
table.insert( std::make_pair(f.item.url, f) );
// -----------
// FunctionCodeParser fc;
// fc.Parse(Item()); // temporary for linking
// functions which need more privileges
f.code = FUN_RELOAD;
f.item.url = "reload";
f.item.privileges = 0700;
table.insert( std::make_pair(f.item.url, f) );
}

View File

@ -95,6 +95,12 @@ void done_defaulted_dir(Info & i)
}
void done_reloaded_templates(Info & i)
{
i.result = request.session->done == Done::reloaded_templates;
}
} // namespace TemplatesFunctions

View File

@ -28,6 +28,7 @@ Ezc::Pattern pat_fun_who;
Ezc::Pattern pat_fun_run;
Ezc::Pattern pat_fun_last;
Ezc::Pattern pat_fun_thread;
Ezc::Pattern pat_fun_reload;
Ezc::Pattern pat_fun_createthread;
Ezc::Pattern pat_err_item_required;
Ezc::Pattern pat_err_404;
@ -110,6 +111,10 @@ Ezc::Pattern * p = 0;
p = &pat_fun_thread;
break;
case FUN_RELOAD:
p = &pat_fun_reload;
break;
case FUN_CREATETHREAD:
p = &pat_fun_createthread;
break;
@ -322,6 +327,7 @@ void Templates::CreateFunctions()
functions.Insert("done_added_dir", done_added_dir);
functions.Insert("done_deleted_dir", done_deleted_dir);
functions.Insert("done_defaulted_dir", done_defaulted_dir);
functions.Insert("done_reloaded_templates", done_reloaded_templates);
/*
@ -384,7 +390,7 @@ void Templates::CreateFunctions()
void Templates::Read()
void Templates::ReadTemplates()
{
using namespace TemplatesFunctions;
@ -448,8 +454,9 @@ void Templates::Read()
pat_dir_last_info.Directory(data.templates);
pat_dir_last_info.ParseFile("dir_last_info.html");
pat_fun_reload.Directory(data.templates);
pat_fun_reload.ParseFile("fun_reload.html");
CreateFunctions();
}

View File

@ -174,7 +174,7 @@ namespace TemplatesFunctions
void done_defaulted_dir(Info & i);
void done_loggedout(Info & i);
void done_reloaded_templates(Info & i);
/*
who
@ -229,18 +229,11 @@ namespace TemplatesFunctions
class Templates
{
public:
void Read();
void Generate();
private:
void ReadTemplates();
void CreateFunctions();
void Generate();
};