added: created directory 'content' which has Content:: files
added: created directory 'templates' which has Templates:: and TemplatesFunctions:: files changed: content.cpp split into many files (directory 'content') changed: templates.cpp split into many files (directory 'templates') added: full permissions changed: building of the program (GNU make is used now) Makefile and Makefile.dep added into directories added: a parser 'FunctionParser' is used to parse the GET string it recognizes directories, items, functions, functions parameters added: other classes: Function, Functions added: function: ls, privileges changed: function 'id' to 'node' changed: version: to 0.2.0 added/changed: a lot of work have been done git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@469 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
256
content/content.cpp
Executable file
256
content/content.cpp
Executable file
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* 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 "content.h"
|
||||
|
||||
|
||||
|
||||
|
||||
bool Content::Init()
|
||||
{
|
||||
templates.Read();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Content::DirsHaveReadExecPerm()
|
||||
{
|
||||
std::vector<Item*>::iterator i;
|
||||
|
||||
for(i = request.dir_table.begin() ; i!=request.dir_table.end() ; ++i)
|
||||
{
|
||||
if( !request.HasReadExecAccess(**i) )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::SetDefaultFunction()
|
||||
{
|
||||
if( request.is_item )
|
||||
{
|
||||
request.pfunction = data.functions.GetFunction(Function::cat);
|
||||
|
||||
if( request.pfunction )
|
||||
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
long default_item = request.dir_table.back()->default_item;
|
||||
|
||||
if( default_item == -1 )
|
||||
{
|
||||
request.pfunction = data.functions.GetFunction(Function::ls);
|
||||
|
||||
if( request.pfunction )
|
||||
log << log3 << "Content: default function: " << request.pfunction->item.url << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log3 << "Content: Default item: id: " << default_item << logend;
|
||||
RedirectTo(default_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::MakeStandardFunction()
|
||||
{
|
||||
if( !request.pfunction )
|
||||
SetDefaultFunction();
|
||||
|
||||
if( request.result == Request::redirect )
|
||||
return;
|
||||
|
||||
|
||||
if( !request.pfunction )
|
||||
{
|
||||
log << log1 << "Content: no function (neither cat nor ls)" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( request.pfunction->code == Function::logout )
|
||||
FunLogout();
|
||||
else
|
||||
if( request.pfunction->code == Function::cat )
|
||||
FunCat();
|
||||
else
|
||||
if( request.pfunction->code == Function::ls )
|
||||
FunLs();
|
||||
else
|
||||
if( request.pfunction->code == Function::emacs )
|
||||
FunEmacs();
|
||||
else
|
||||
if( request.pfunction->code == Function::privileges )
|
||||
FunPrivileges();
|
||||
else
|
||||
if( request.pfunction->code == Function::rm )
|
||||
FunRm();
|
||||
else
|
||||
if( request.pfunction->code == Function::node )
|
||||
FunNode();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Content::MakePost()
|
||||
{
|
||||
if( !request.pfunction )
|
||||
{
|
||||
log << log1 << "Content: MakePost: no function" << logend;
|
||||
request.status = Error::no_function;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch( request.pfunction->code )
|
||||
{
|
||||
case Function::emacs:
|
||||
PostFunEmacs();
|
||||
break;
|
||||
|
||||
case Function::privileges:
|
||||
PostFunPrivileges();
|
||||
break;
|
||||
|
||||
case Function::login:
|
||||
PostFunLogin();
|
||||
break;
|
||||
|
||||
default:
|
||||
log << log1 << "Content: unknown post function" << logend;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::Make()
|
||||
{
|
||||
if( request.dir_table.empty() )
|
||||
{
|
||||
log << log1 << "Content: there is no a root dir" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
// request.status can be changed by function_parser
|
||||
if( request.status == Error::ok )
|
||||
{
|
||||
if( DirsHaveReadExecPerm() )
|
||||
{
|
||||
if( request.method == Request::post )
|
||||
MakePost();
|
||||
|
||||
if( request.result == Request::redirect )
|
||||
return;
|
||||
|
||||
if( request.status == Error::ok )
|
||||
MakeStandardFunction();
|
||||
}
|
||||
else
|
||||
request.status = Error::permision_denied;
|
||||
}
|
||||
|
||||
if( request.result == Request::redirect )
|
||||
return;
|
||||
|
||||
templates.Generate();
|
||||
|
||||
|
||||
//request.PrintGetTable();
|
||||
//request.PrintEnv();
|
||||
//request.PrintIn();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// !! mozna zrobic jakas obsluge kiedy nie mozemy sie redirectnac, np gdy wystapil blad
|
||||
// !! moze zwracac jakas wartosc?
|
||||
void Content::RedirectTo(const Item & item)
|
||||
{
|
||||
std::string path;
|
||||
|
||||
request.result = Request::redirect;
|
||||
request.str = data.base_url;
|
||||
|
||||
|
||||
if( item.type == Item::dir )
|
||||
{
|
||||
// item_id is pointing to a directory
|
||||
data.dirs.MakePath(item.id, path);
|
||||
request.str += path;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !data.dirs.MakePath(item.parent_id, path) )
|
||||
log << log1 << "Content: Can't redirect: no dirs for item id: " << item.id << logend;
|
||||
|
||||
request.str += path;
|
||||
request.str += item.url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Content::RedirectTo(long item_id)
|
||||
{
|
||||
std::string path;
|
||||
Item * pdir;
|
||||
|
||||
request.result = Request::redirect;
|
||||
request.str = data.base_url;
|
||||
pdir = data.dirs.GetDir(item_id);
|
||||
|
||||
|
||||
if( pdir )
|
||||
{
|
||||
// item_id is pointing to a directory
|
||||
data.dirs.MakePath(pdir->id, path);
|
||||
request.str += path;
|
||||
}
|
||||
else
|
||||
{
|
||||
// !! zrobic nowy interfejs
|
||||
// !! GetItem pozamieniac na GetFile
|
||||
db.GetItem(request.item_table, item_id);
|
||||
|
||||
if( !request.item_table.empty() )
|
||||
{
|
||||
if( !data.dirs.MakePath(request.item_table[0].parent_id, path) )
|
||||
log << log1 << "Content: Can't redirect: no dirs for item id: " << request.item_table[0].id << ", requested directory id: " << request.item_table[0].parent_id << logend;
|
||||
|
||||
request.str += path + request.item_table[0].url;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Content: Can't redirect: no such item: id: " << item_id << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user