changed: the way of building the cmslu

main Makefile is in an application directory
         in cmslu/ there are only libraries:
         core.a content.a confparser.a templates.a
added:   macros APPTEMPLATES APPFUNCTIONS
         defined in the application's Makefile
added:   PatternCacher
added:   cmslu function 'run'
         files which have exec permissions
         can be run (run is a default function)
         after read from the database the content is parsed
         into Ezc::Pattern object, this object is then cached
         in PatternCacher
added:   FunctionCodeParser - will be used to parse the code
         from standard functions (ls/cat/...)


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@475 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2009-01-26 20:49:28 +00:00
parent 327f18525c
commit 20f6fbcf84
37 changed files with 866 additions and 298 deletions

View File

@@ -1,4 +1,4 @@
o = templates.o sys.o item.o doc.o user.o dir.o done.o priv.o
o = templates.o sys.o item.o doc.o user.o dir.o done.o priv.o patterncacher.o
all: templates.a

View File

@@ -4,79 +4,90 @@ dir.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
dir.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
dir.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
dir.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
dir.o: ../core/functions.h ../core/function.h ../core/request.h
dir.o: ../core/requesttypes.h ../core/session.h ../core/done.h
dir.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
dir.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
dir.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
dir.o: ../core/log.h
dir.o: ../core/functions.h ../core/function.h ../core/functioncodeparser.h
dir.o: ../core/request.h ../core/requesttypes.h ../core/session.h
dir.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
dir.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
dir.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
dir.o: ../core/users.h ../core/groups.h ../core/log.h patterncacher.h
dir.o: ../app/templates.h
doc.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
doc.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
doc.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
doc.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
doc.o: ../core/functions.h ../core/function.h ../core/request.h
doc.o: ../core/requesttypes.h ../core/session.h ../core/done.h
doc.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
doc.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
doc.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
doc.o: ../core/log.h
doc.o: ../core/functions.h ../core/function.h ../core/functioncodeparser.h
doc.o: ../core/request.h ../core/requesttypes.h ../core/session.h
doc.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
doc.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
doc.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
doc.o: ../core/users.h ../core/groups.h ../core/log.h patterncacher.h
doc.o: ../app/templates.h
done.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
done.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
done.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
done.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
done.o: ../core/functions.h ../core/function.h ../core/request.h
done.o: ../core/requesttypes.h ../core/session.h ../core/done.h
done.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
done.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
done.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
done.o: ../core/log.h
done.o: ../core/functions.h ../core/function.h ../core/functioncodeparser.h
done.o: ../core/request.h ../core/requesttypes.h ../core/session.h
done.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
done.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
done.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
done.o: ../core/users.h ../core/groups.h ../core/log.h patterncacher.h
done.o: ../app/templates.h
item.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
item.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
item.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
item.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
item.o: ../core/functions.h ../core/function.h ../core/request.h
item.o: ../core/requesttypes.h ../core/session.h ../core/done.h
item.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
item.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
item.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
item.o: ../core/log.h
item.o: ../core/functions.h ../core/function.h ../core/functioncodeparser.h
item.o: ../core/request.h ../core/requesttypes.h ../core/session.h
item.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
item.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
item.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
item.o: ../core/users.h ../core/groups.h ../core/log.h patterncacher.h
item.o: ../app/templates.h
patterncacher.o: patterncacher.h ../core/item.h ../../ezc/src/ezc.h
patterncacher.o: ../core/log.h
priv.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
priv.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
priv.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
priv.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
priv.o: ../core/functions.h ../core/function.h ../core/request.h
priv.o: ../core/requesttypes.h ../core/session.h ../core/done.h
priv.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
priv.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
priv.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
priv.o: ../core/log.h
priv.o: ../core/functions.h ../core/function.h ../core/functioncodeparser.h
priv.o: ../core/request.h ../core/requesttypes.h ../core/session.h
priv.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
priv.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
priv.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
priv.o: ../core/users.h ../core/groups.h ../core/log.h patterncacher.h
priv.o: ../app/templates.h
sys.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
sys.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
sys.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
sys.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
sys.o: ../core/functions.h ../core/function.h ../core/request.h
sys.o: ../core/requesttypes.h ../core/session.h ../core/done.h
sys.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
sys.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
sys.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
sys.o: ../core/log.h
sys.o: ../core/functions.h ../core/function.h ../core/functioncodeparser.h
sys.o: ../core/request.h ../core/requesttypes.h ../core/session.h
sys.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
sys.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
sys.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
sys.o: ../core/users.h ../core/groups.h ../core/log.h patterncacher.h
sys.o: ../app/templates.h
templates.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
templates.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
templates.o: ../core/db.h ../core/dircontainer.h ../core/user.h
templates.o: ../core/group.h ../core/ugcontainer.h ../core/users.h
templates.o: ../core/groups.h ../core/functions.h ../core/function.h
templates.o: ../core/request.h ../core/requesttypes.h ../core/session.h
templates.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
templates.o: ../core/functioncodeparser.h ../core/request.h
templates.o: ../core/requesttypes.h ../core/session.h ../core/done.h
templates.o: ../core/getparser.h ../core/httpsimpleparser.h
templates.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
templates.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
templates.o: ../core/users.h ../core/groups.h ../core/log.h
templates.o: ../core/users.h ../core/groups.h ../core/log.h patterncacher.h
templates.o: ../app/templates.h
user.o: templates.h ../../ezc/src/ezc.h ../core/data.h ../core/misc.h
user.o: ../core/log.h ../core/item.h ../core/error.h ../core/dirs.h
user.o: ../core/db.h ../core/dircontainer.h ../core/user.h ../core/group.h
user.o: ../core/ugcontainer.h ../core/users.h ../core/groups.h
user.o: ../core/functions.h ../core/function.h ../core/request.h
user.o: ../core/requesttypes.h ../core/session.h ../core/done.h
user.o: ../core/getparser.h ../core/httpsimpleparser.h ../core/postparser.h
user.o: ../core/cookieparser.h ../core/item.h ../core/db.h ../core/error.h
user.o: ../core/user.h ../core/group.h ../core/users.h ../core/groups.h
user.o: ../core/log.h
user.o: ../core/functions.h ../core/function.h ../core/functioncodeparser.h
user.o: ../core/request.h ../core/requesttypes.h ../core/session.h
user.o: ../core/done.h ../core/getparser.h ../core/httpsimpleparser.h
user.o: ../core/postparser.h ../core/cookieparser.h ../core/item.h
user.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
user.o: ../core/users.h ../core/groups.h ../core/log.h patterncacher.h
user.o: ../app/templates.h

136
templates/patterncacher.cpp Executable file
View File

@@ -0,0 +1,136 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "patterncacher.h"
PatternCacher::PatternCacher()
{
// !! tymczasowe wartosci dla testow
when_delete_patterns = 3; // 130
how_many_delete = 2; // 30
}
void PatternCacher::CheckTableSize()
{
if( pattern_tab.size() < when_delete_patterns )
return;
PatternTab::iterator i;
PatternErase pe;
size_t erase_index;
erase_tab.resize(pattern_tab.size());
for( i=pattern_tab.begin(), erase_index=0 ; i!=pattern_tab.end() ; ++i, ++erase_index)
{
pe.used = i->second.used;
pe.iter = i;
erase_tab[erase_index] = pe;
}
// sorting through 'used'
std::sort(erase_tab.begin(), erase_tab.end());
for(erase_index = 0 ; erase_index<how_many_delete && erase_index<erase_tab.size() ; ++erase_index)
{
log << log2 << "PC: deleting from cache, id: " << erase_tab[erase_index].iter->second.item_id << logend;
pattern_tab.erase(erase_tab[erase_index].iter);
}
}
void PatternCacher::CreatePattern(const Item & item, Ezc::Pattern & pattern)
{
pattern.allow_include = false;
pattern.ParseString(item.content);
}
Ezc::Pattern * PatternCacher::AddPattern(const Item & item)
{
CheckTableSize();
PatternUsed pu;
CreatePattern(item, pu.pattern);
pu.used = 1;
pu.item_id = item.id;
std::pair<PatternTab::iterator, bool> res = pattern_tab.insert( std::make_pair(item.id, pu) );
log << log2 << "PC: added an item, id: " << item.id << ", url: " << item.url << logend;
return &(res.first->second.pattern);
}
Ezc::Pattern * PatternCacher::GetPattern(const Item & item)
{
PatternTab::iterator i;
i = pattern_tab.find(item.id);
if( i == pattern_tab.end() )
return AddPattern(item);
else
{
log << log2 << "PC: taking a pattern from the cache, id: " << item.id << ", url: " << item.url << logend;
++(i->second.used);
return &(i->second.pattern);
}
}
void PatternCacher::UpdatePattern(const Item & item)
{
PatternTab::iterator i;
i = pattern_tab.find(item.id);
if( i == pattern_tab.end() )
{
log << log2 << "PC: there is no such an item to update, id: " << item.id << ", url: " << item.url << logend;
return;
}
++(i->second.used);
CreatePattern(item, i->second.pattern);
log << log2 << "PC: updated pattern, id: " << item.id << ", url: " << item.url << logend;
}
void PatternCacher::DeletePattern(const Item & item)
{
PatternTab::iterator i;
i = pattern_tab.find(item.id);
if( i == pattern_tab.end() )
{
log << log2 << "PC: there is no such an item to delete, id: " << item.id << ", url: " << item.url << logend;
return;
}
log << log2 << "PC: deleted pattern, id: " << item.id << ", url: " << item.url << logend;
pattern_tab.erase(i);
}

77
templates/patterncacher.h Executable file
View File

@@ -0,0 +1,77 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilepatterncacher
#define headerfilepatterncacher
#include <vector>
#include <map>
#include "../core/item.h"
#include "../../ezc/src/ezc.h"
#include "../core/log.h"
class PatternCacher
{
struct PatternUsed
{
Ezc::Pattern pattern;
int used; // how many times used (incremented by GetPattern and UpdatePattern)
int item_id;
};
typedef std::map<long, PatternUsed> PatternTab;
PatternTab pattern_tab;
// temporarily struct used during deleting some items from pattern_tab
struct PatternErase
{
PatternTab::iterator iter;
int used;
bool operator<(const PatternErase & p) const { return used < p.used; }
};
// temporarily buffer used during deleting some items from pattern_tab
std::vector<PatternErase> erase_tab;
void CreatePattern(const Item & item, Ezc::Pattern & pattern);
void AddIndexes(const Item & item, size_t pattern_index);
Ezc::Pattern * AddPattern(const Item & item);
void CheckTableSize();
// the size of pattern_tab when we are deleting some items
size_t when_delete_patterns;
// how many items to delete
size_t how_many_delete;
public:
PatternCacher();
// returning a pattern corresponding to the 'item'
Ezc::Pattern * GetPattern(const Item & item);
// updating the pattern for the item
// if there is no such a pattern the method does nothing
void UpdatePattern(const Item & item);
// deleting the pattern for the item
// if there is no such a pattern the method does nothing
void DeletePattern(const Item & item);
};
#endif

View File

@@ -19,8 +19,8 @@ Ezc::Pattern pat_fun_cat;
Ezc::Pattern pat_fun_ls;
Ezc::Pattern pat_fun_emacs;
Ezc::Pattern pat_fun_mkdir;
Ezc::Pattern pat_fun_default_item;
Ezc::Pattern pat_fun_privileges;
Ezc::Pattern pat_fun_default;
Ezc::Pattern pat_fun_priv;
Ezc::Pattern pat_fun_rm;
Ezc::Pattern pat_err_item_required;
Ezc::Pattern pat_err_404;
@@ -32,6 +32,8 @@ Ezc::Pattern pat_err_others;
Ezc::Functions functions;
PatternCacher pattern_cacher;
@@ -61,32 +63,37 @@ Ezc::Pattern * p = 0;
switch( request.pfunction->code )
{
case Function::cat:
case FUN_CAT:
p = &pat_fun_cat;
break;
case Function::ls:
case FUN_LS:
p = &pat_fun_ls;
break;
case Function::rm:
case FUN_RM:
p = &pat_fun_rm;
break;
case Function::emacs:
case FUN_EMACS:
p = &pat_fun_emacs;
break;
case Function::mkdir:
case FUN_MKDIR:
p = &pat_fun_mkdir;
break;
case Function::default_item:
p = &pat_fun_default_item;
case FUN_DEFAULT:
p = &pat_fun_default;
break;
case Function::privileges:
p = &pat_fun_privileges;
case FUN_PRIV:
p = &pat_fun_priv;
break;
case FUN_RUN:
if( request.is_item )
p = pattern_cacher.GetPattern(request.item);
break;
default:
@@ -276,9 +283,7 @@ void Templates::CreateFunctions()
#ifdef APPTEMPLATES
AppTemplateFunctions::CreateAppFunctions(functions);
AppTemplateFunctions::CreateAppFunctions(functions);
#endif
}
@@ -317,16 +322,20 @@ void Templates::Read()
pat_fun_mkdir.Directory(data.templates);
pat_fun_mkdir.ParseFile("fun_mkdir.html");
pat_fun_default_item.Directory(data.templates);
pat_fun_default_item.ParseFile("fun_default_item.html");
pat_fun_default.Directory(data.templates);
pat_fun_default.ParseFile("fun_default.html");
pat_fun_privileges.Directory(data.templates);
pat_fun_privileges.ParseFile("fun_priv.html");
pat_fun_priv.Directory(data.templates);
pat_fun_priv.ParseFile("fun_priv.html");
pat_err_others.Directory(data.templates);
pat_err_others.ParseFile("err_others.html");
CreateFunctions();
#ifdef APPTEMPLATES
AppTemplateFunctions::ReadAppPatterns();
#endif
}

View File

@@ -23,6 +23,7 @@
#include "../core/users.h"
#include "../core/groups.h"
#include "../core/log.h"
#include "patterncacher.h"
#ifdef APPTEMPLATES
#include "../app/templates.h"
@@ -35,6 +36,8 @@ namespace TemplatesFunctions
{
using Ezc::Info;
extern PatternCacher pattern_cacher;
/*
sys
*/
@@ -159,7 +162,6 @@ class Templates
{
public: