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 = data.o log.o sessionmanager.o requestcontroller.o dircontainer.o session.o main.o done.o request.o misc.o httpsimpleparser.o db.o error.o db_itemcolumns.o users.o config.o dirs.o groups.o function.o functionparser.o functions.o
o = data.o log.o sessionmanager.o requestcontroller.o dircontainer.o session.o main.o done.o request.o misc.o httpsimpleparser.o db.o error.o db_itemcolumns.o users.o config.o dirs.o groups.o function.o functionparser.o functions.o functioncodeparser.o

View File

@@ -2,9 +2,10 @@
config.o: config.h ../confparser/confparser.h error.h log.h data.h misc.h
config.o: item.h dirs.h db.h dircontainer.h user.h group.h ugcontainer.h
config.o: users.h groups.h functions.h function.h
config.o: users.h groups.h functions.h function.h functioncodeparser.h
data.o: data.h misc.h log.h item.h error.h dirs.h db.h dircontainer.h user.h
data.o: group.h ugcontainer.h users.h groups.h functions.h function.h
data.o: functioncodeparser.h
db.o: db.h log.h item.h misc.h error.h dircontainer.h user.h group.h
db.o: ugcontainer.h
db_itemcolumns.o: db.h log.h item.h misc.h error.h dircontainer.h user.h
@@ -15,47 +16,52 @@ dirs.o: ugcontainer.h
done.o: done.h
error.o: error.h log.h
function.o: function.h log.h item.h
functioncodeparser.o: functioncodeparser.h function.h log.h item.h
functionparser.o: functionparser.h request.h requesttypes.h log.h session.h
functionparser.o: error.h item.h done.h user.h getparser.h httpsimpleparser.h
functionparser.o: postparser.h cookieparser.h function.h data.h misc.h dirs.h
functionparser.o: db.h dircontainer.h group.h ugcontainer.h users.h groups.h
functionparser.o: functions.h
functions.o: functions.h function.h log.h item.h
functionparser.o: functions.h functioncodeparser.h ../app/content.h
functionparser.o: ../core/log.h ../core/data.h ../core/function.h
functions.o: functions.h function.h log.h item.h functioncodeparser.h
groups.o: groups.h group.h db.h log.h item.h misc.h error.h dircontainer.h
groups.o: user.h ugcontainer.h
httpsimpleparser.o: httpsimpleparser.h
log.o: log.h
main.o: requestcontroller.h data.h misc.h log.h item.h error.h dirs.h db.h
main.o: dircontainer.h user.h group.h ugcontainer.h users.h groups.h
main.o: functions.h function.h request.h requesttypes.h session.h done.h
main.o: getparser.h httpsimpleparser.h postparser.h cookieparser.h
main.o: ../content/content.h ../templates/templates.h ../../ezc/src/ezc.h
main.o: ../core/data.h ../core/request.h ../core/item.h ../core/db.h
main.o: ../core/error.h ../core/user.h ../core/group.h ../core/users.h
main.o: ../core/groups.h ../core/log.h ../core/misc.h ../core/function.h
main.o: ../core/functionparser.h sessionmanager.h config.h
main.o: ../confparser/confparser.h
main.o: functions.h function.h functioncodeparser.h request.h requesttypes.h
main.o: session.h done.h getparser.h httpsimpleparser.h postparser.h
main.o: cookieparser.h ../content/content.h ../templates/templates.h
main.o: ../../ezc/src/ezc.h ../core/data.h ../core/request.h ../core/item.h
main.o: ../core/db.h ../core/error.h ../core/user.h ../core/group.h
main.o: ../core/users.h ../core/groups.h ../core/log.h
main.o: ../templates/patterncacher.h ../app/templates.h ../core/misc.h
main.o: ../core/function.h ../core/functionparser.h ../app/content.h
main.o: sessionmanager.h config.h ../confparser/confparser.h
misc.o: misc.h log.h item.h
request.o: request.h requesttypes.h log.h session.h error.h item.h done.h
request.o: user.h getparser.h httpsimpleparser.h postparser.h cookieparser.h
request.o: function.h
requestcontroller.o: requestcontroller.h data.h misc.h log.h item.h error.h
requestcontroller.o: dirs.h db.h dircontainer.h user.h group.h ugcontainer.h
requestcontroller.o: users.h groups.h functions.h function.h request.h
requestcontroller.o: requesttypes.h session.h done.h getparser.h
requestcontroller.o: httpsimpleparser.h postparser.h cookieparser.h
requestcontroller.o: ../content/content.h ../templates/templates.h
requestcontroller.o: ../../ezc/src/ezc.h ../core/data.h ../core/request.h
requestcontroller.o: ../core/item.h ../core/db.h ../core/error.h
requestcontroller.o: ../core/user.h ../core/group.h ../core/users.h
requestcontroller.o: ../core/groups.h ../core/log.h ../core/misc.h
requestcontroller.o: ../core/function.h ../core/functionparser.h
requestcontroller.o: users.h groups.h functions.h function.h
requestcontroller.o: functioncodeparser.h request.h requesttypes.h session.h
requestcontroller.o: done.h getparser.h httpsimpleparser.h postparser.h
requestcontroller.o: cookieparser.h ../content/content.h
requestcontroller.o: ../templates/templates.h ../../ezc/src/ezc.h
requestcontroller.o: ../core/data.h ../core/request.h ../core/item.h
requestcontroller.o: ../core/db.h ../core/error.h ../core/user.h
requestcontroller.o: ../core/group.h ../core/users.h ../core/groups.h
requestcontroller.o: ../core/log.h ../templates/patterncacher.h
requestcontroller.o: ../app/templates.h ../core/misc.h ../core/function.h
requestcontroller.o: ../core/functionparser.h ../app/content.h
requestcontroller.o: sessionmanager.h
session.o: session.h requesttypes.h error.h log.h item.h done.h user.h
sessionmanager.o: sessionmanager.h request.h requesttypes.h log.h session.h
sessionmanager.o: error.h item.h done.h user.h getparser.h httpsimpleparser.h
sessionmanager.o: postparser.h cookieparser.h function.h data.h misc.h dirs.h
sessionmanager.o: db.h dircontainer.h group.h ugcontainer.h users.h groups.h
sessionmanager.o: functions.h
sessionmanager.o: functions.h functioncodeparser.h
users.o: users.h user.h db.h log.h item.h misc.h error.h dircontainer.h
users.o: group.h ugcontainer.h

View File

@@ -10,18 +10,25 @@
#include "db.h"
Db::Db()
Db::Db(bool close_at_end_)
{
pg_conn = 0;
pg_conn = 0;
close_at_end = close_at_end_;
}
Db::~Db()
{
Close();
if( close_at_end )
Close();
}
PGconn * Db::GetPGconn()
{
return pg_conn;
}
void Db::Init(const std::string & d, const std::string & u, const std::string & p)
{
@@ -43,10 +50,15 @@ void Db::Connect()
pg_conn = PQconnectdb(buf.str().c_str());
if( !pg_conn )
{
log << log1 << "Db: Fatal error during connecting" << logend;
return;
}
if( PQsetClientEncoding(pg_conn, "LATIN2") == -1 )
log << log1 << "Db: Can't set the proper client encoding" << logend;
log << log3 << "Db: Socket: " << PQsocket(pg_conn) << logend;
}
@@ -92,6 +104,8 @@ void Db::AssertConnection()
if( PQsetClientEncoding(pg_conn, "LATIN2") == -1 )
log << log1 << "Db: Can't set the proper client encoding" << logend;
log << log3 << "Db: Socket: " << PQsocket(pg_conn) << logend;
}
}
}
@@ -138,7 +152,9 @@ PGresult * Db::AssertQuery(const std::string & q)
if( !r )
{
log << log1 << "Db: Problem with query: " << PQerrorMessage(pg_conn) << logend;
log << log1 << "Db: Problem with query: \"" << q << '\"' << logend;
log << log1 << "Db: " << PQerrorMessage(pg_conn) << logend;
throw Error(Error::db_incorrect_query);
}
@@ -1247,6 +1263,42 @@ void Db::GetGroups(UGContainer<Group> & group_table)
tm Db::ConvertTime(const char * str)
{
tm t;
memset(&t, 0, sizeof(t));
if( !str )
return t;
size_t len = strlen(str);
if( len != 19 )
{
// unknown format
// the format must be like this: 2008-12-31 22:30:00
return t;
}
t.tm_year = atoi(str + 0) - 1900; /* year - 1900 */
t.tm_mon = atoi(str + 5) - 1; /* month of year (0 - 11) */
t.tm_mday = atoi(str + 8); /* day of month (1 - 31) */
t.tm_hour = atoi(str + 11); /* hours (0 - 23) */
t.tm_min = atoi(str + 14); /* minutes (0 - 59) */
t.tm_sec = atoi(str + 17); /* seconds (0 - 60) */
// t.tm_wday = 0; /* day of week (Sunday = 0) */
// t.tm_yday = 0; /* day of year (0 - 365) */
// t.tm_isdst = 0; /* is summer time in effect? */
// t.tm_zone = 0; // const_cast<char*>(""); /* abbreviation of timezone name */
//return mktime(&t);
return t;
}

View File

@@ -17,7 +17,8 @@
#include <sstream>
#include <libpq-fe.h>
#include <cstdio>
#include <ctime>
#include <cstring>
#include "log.h"
#include "item.h"
@@ -33,7 +34,7 @@ class Db
{
public:
Db();
Db(bool close_at_end_ = true);
~Db();
// !! przerobic tak aby GetItem zwracalo wszystkie pozycja
@@ -65,10 +66,15 @@ public:
long GetFileId(long parent_id, const std::string & url);
long GetDirId(long parent_id, const std::string & url);
tm ConvertTime(const char * str);
PGconn * GetPGconn();
protected:
PGconn * pg_conn;
std::string db_database, db_user, db_pass;
bool close_at_end;
void Connect();
void Close();

View File

@@ -10,10 +10,15 @@
#include "function.h"
Function::Function()
{
code = none;
code = FUN_NONE;
}
void Function::Clear()
{
code = FUN_NONE;
item.Clear();
}

View File

@@ -15,6 +15,18 @@
#include "item.h"
#define FUN_NONE 0
#define FUN_LS 1
#define FUN_CAT 2
#define FUN_NODE 3
#define FUN_EMACS 4
#define FUN_MKDIR 5
#define FUN_DEFAULT 6
#define FUN_PRIV 7
#define FUN_RM 8
#define FUN_LOGIN 9
#define FUN_LOGOUT 10
#define FUN_RUN 11
class Function
@@ -22,6 +34,7 @@ class Function
public:
/*
enum Code
{
none,
@@ -30,22 +43,30 @@ public:
node,
emacs,
mkdir,
default_item,
privileges,
default,
priv,
rm,
login,
logout
logout,
run
};
Code code;
*/
/*
we do not use enum etc. because the code will be used with an application too
(application can set others values)
*/
int code;
Item item;
void Clear();
Function();
Function(const Function & f);
Function & operator=(const Function & f);
};

56
core/functioncodeparser.cpp Executable file
View File

@@ -0,0 +1,56 @@
/*
* 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 "functioncodeparser.h"
bool FunctionCodeParser::ContentHasOneRow(const Item & item)
{
for(size_t i=0 ; i<item.content.size() ; ++i)
if( item.content[i] == '\n' )
return false;
return true;
}
int FunctionCodeParser::ParseValue(const char * s)
{
if( strncmp(s, "[fun:", 5) != 0 )
return FUN_NONE;
const char * send;
int result = strtol(s+5, (char**)&send, 10);
if( send==s+5 || strcmp(send, "]") != 0 )
return FUN_NONE;
log << log2 << "FCP: function code: " << result << logend;
return result;
}
int FunctionCodeParser::Parse(const Item & item)
{
// format: [fun:1]
// minimum size: 7 characters
if( item.content.size() < 7 )
return FUN_NONE;
if( !ContentHasOneRow(item) )
return FUN_NONE;
return ParseValue(item.content.c_str());
}

35
core/functioncodeparser.h Executable file
View File

@@ -0,0 +1,35 @@
/*
* 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 headerfilefunctioncodeparser
#define headerfilefunctioncodeparser
#include <cstring>
#include <cstdlib>
#include "function.h"
#include "item.h"
#include "log.h"
class FunctionCodeParser
{
bool ContentHasOneRow(const Item & item);
int ParseValue(const char * s);
public:
int Parse(const Item & item);
};
#endif

View File

@@ -102,7 +102,6 @@ void FunctionParser::ParseFunction()
}
void FunctionParser::ParseParams()
{
while( true )
@@ -143,7 +142,7 @@ void FunctionParser::Parse()
if( request.status != Error::ok )
return;
ParseFunction();
if( !request.pfunction && get_index != get_table_len )

View File

@@ -17,9 +17,9 @@
#include "data.h"
#include "db.h"
#ifdef APPFUNCTIONS
#include "../app/content.h"
#endif
class FunctionParser
{
@@ -30,6 +30,7 @@ class FunctionParser
void ParseDirectories();
void ParseItem();
bool IsAppFunction();
void ParseFunction();
void ParseParams();

View File

@@ -35,45 +35,54 @@ void Functions::ReadFunctions()
f.item.type = Item::file;
// in the future we will read these functions from the database
f.code = Function::ls;
f.code = FUN_LS;
f.item.url = "ls";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::cat;
f.code = FUN_CAT;
f.item.url = "cat";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::node;
f.code = FUN_NODE;
f.item.url = "node";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::emacs;
f.code = FUN_EMACS;
f.item.url = "emacs";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::mkdir;
f.code = FUN_MKDIR;
f.item.url = "mkdir";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::default_item;
f.code = FUN_DEFAULT;
f.item.url = "default";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::privileges;
f.code = FUN_PRIV;
f.item.url = "priv";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::rm;
f.code = FUN_RM;
f.item.url = "rm";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::logout;
f.code = FUN_LOGOUT;
f.item.url = "logout";
table.insert( std::make_pair(f.item.url, f) );
f.code = Function::login;
f.code = FUN_LOGIN;
f.item.url = "login";
table.insert( std::make_pair(f.item.url, f) );
f.code = FUN_RUN;
f.item.url = "run";
table.insert( std::make_pair(f.item.url, f) );
// -----------
FunctionCodeParser fc;
fc.Parse(Item()); // temporary for linking
}
@@ -92,7 +101,7 @@ return &(i->second);
// !! in the future there will be a special container where we can search through the Code object
Function * Functions::GetFunction(Function::Code code)
Function * Functions::GetFunction(int code)
{
Table::iterator i = table.begin();

View File

@@ -13,7 +13,7 @@
#include <map>
#include <string>
#include "function.h"
#include "functioncodeparser.h"
@@ -31,7 +31,7 @@ public:
void ReadFunctions();
Function * GetFunction(const std::string & name);
Function * GetFunction(Function::Code code);
Function * GetFunction(int code);

View File

@@ -101,12 +101,16 @@ void HttpSimpleParser::CheckSpecialChar()
int c2 = GetChar();
if( c1==-1 || c2==-1 )
{
last_c = -1;
}
else
{
c1 = ParseHalfHex(c1);
c2 = ParseHalfHex(c2);
c1 = ParseHalfHex(c1);
c2 = ParseHalfHex(c2);
last_c = (c1 << 4) + c2;
last_c = (c1 << 4) + c2;
}
}
else
if( last_c == '+' )

View File

@@ -34,7 +34,7 @@ Log & Log::operator<<(const char * s)
if( !s )
return *this;
buffer << s;
buffer << s;
return *this;
}
@@ -42,25 +42,25 @@ return *this;
Log & Log::operator<<(const std::string & s)
{
buffer << s;
return *this;
buffer << s;
return *this;
}
Log & Log::operator<<(int s)
{
buffer << s;
buffer << s;
return *this;
return *this;
}
Log & Log::operator<<(long s)
{
buffer << s;
buffer << s;
return *this;
return *this;
}
@@ -68,17 +68,17 @@ Log & Log::operator<<(long s)
Log & Log::operator<<(char s)
{
buffer << s;
buffer << s;
return *this;
return *this;
}
Log & Log::operator<<(size_t s)
{
buffer << s;
buffer << s;
return *this;
return *this;
}
@@ -113,31 +113,31 @@ void Log::SaveLog()
{
int attempt = 2;
if( current_level > log_level )
return;
if( current_level > log_level )
return;
if( log_stdout )
std::cout << buffer.str() << std::endl;
if( log_stdout )
std::cout << buffer.str() << std::endl;
if( log_file.empty() )
return;
if( log_file.empty() )
return;
std::ofstream file;
std::ofstream file;
do
{
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
do
{
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
// if( !file )
// sleep(1);
}
while( --attempt > 0 && !file );
// if( !file )
// sleep(1);
}
while( --attempt > 0 && !file );
if( !file )
return;
if( !file )
return;
file << buffer.str() << std::endl;
file << buffer.str() << std::endl;
}

View File

@@ -19,7 +19,6 @@
#include "config.h"
// singletons
// first 'data' then 'log' then 'request'
Data data;
@@ -63,6 +62,7 @@ int main(int argv, char ** argc)
{
RequestController req_controller;
std::srand(std::time(0));
if( argv != 2 )
@@ -80,7 +80,9 @@ RequestController req_controller;
// closing descriptors only at the beginning
close(2);
// !! temporary we do not close standard output for errors
// client postgresql uses it for reporting warnings (I don't know why)
//close(2);
if( !data.log_stdout )
{
@@ -88,6 +90,7 @@ RequestController req_controller;
data.stdout_is_closed = true;
}
signal(SIGTERM, signal_term);
signal(SIGINT, signal_term);
@@ -102,7 +105,7 @@ RequestController req_controller;
if( !req_controller.Init() )
return 1;
log << log2 << "checking for table consistency:" << logend;
//log << log2 << "checking for table consistency:" << logend;
// !! zrobic wyjatek dla root
//db.CheckAllUrlSubject();

View File

@@ -16,6 +16,8 @@
#include "requesttypes.h"
class PostParser : public HttpSimpleParser
{

View File

@@ -311,6 +311,8 @@ void Request::SendAll()
FCGX_PutS("Content-Type: Text/Html\r\n", out);
}
log << log2 << "headers: " << logend; // !! wywalic
log << headers.str() << logend; // !!
FCGX_PutS(headers.str().c_str(), out);
FCGX_PutS("\r\n", out);
@@ -321,6 +323,9 @@ void Request::SendAll()
return;
FCGX_PutS(page.str().c_str(), out);
log << log2 << "body: " << logend; // !! wywalic
log << page.str() << logend; // !!
const std::string & d = debug.str();
@@ -466,6 +471,7 @@ bool Request::HasWriteAccess(const Item & item)
return HasAccess(item, 2);
}
bool Request::HasReadWriteAccess(const Item & item)
{
return HasAccess(item, 6); // r+w
@@ -474,6 +480,13 @@ bool Request::HasReadWriteAccess(const Item & item)
bool Request::HasReadExecAccess(const Item & item)
{
if( session && session->puser && session->puser->super_user )
{
// there must be at least one 'x' (for the root)
return (item.privileges & 0111) != 0;
}
return HasAccess(item, 5); // r+x
}

View File

@@ -69,6 +69,7 @@ struct Request
Error done_status; // !! wywalic - jest przeciez w session
// what to do
// !! wywalic?
enum Result { err_internal, err404, err_per_denied, show_dir, show_item, show_item_by_id, add_item, edit_item, del_item, del_item_confirm, confirm, redirect, logout } result; // zamienic na to_do
@@ -154,7 +155,8 @@ struct Request
bool HasWriteAccess(const Item & item);
bool HasReadWriteAccess(const Item & item);
bool HasReadExecAccess(const Item & item);
private:
// used to set some env_* variables into it, when the server didn't set that variable
@@ -165,6 +167,8 @@ private:
void StandardLog();
};

View File

@@ -127,7 +127,13 @@ void SessionManager::SetSession()
{
// that session is in the table
request.session = const_cast<Session*>( &(*s) );
log << log1 << "SM: session: " << s->id << logend;
log << log2 << "SM: session: " << s->id;
if( request.session->puser )
log << log2 << ", user: " << request.session->puser->name << ", id: " << request.session->puser->id;
log << log2 << logend;
}
else
{