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:
181
core/functionparser.cpp
Executable file
181
core/functionparser.cpp
Executable file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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 "functionparser.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void FunctionParser::SkipEmptyString(const char * msg)
|
||||
{
|
||||
for( ; get_index != get_table_len && request.get_table[get_index].empty() ; ++get_index )
|
||||
log << log3 << msg << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseDirectories()
|
||||
{
|
||||
Item * pdir = data.dirs.GetRootDir();
|
||||
|
||||
if( !pdir )
|
||||
{
|
||||
// there is no the root dir
|
||||
request.status = Error::no_root_dir;
|
||||
return;
|
||||
}
|
||||
|
||||
while( true )
|
||||
{
|
||||
request.dir_table.push_back( pdir );
|
||||
log << log3 << "FP: Directory: ";
|
||||
|
||||
if( pdir->parent_id == -1 )
|
||||
log << "(root)" << logend;
|
||||
else
|
||||
log << pdir->url << logend;
|
||||
|
||||
SkipEmptyString("FP: Directory: skipped empty string");
|
||||
|
||||
if( get_index == get_table_len )
|
||||
break;
|
||||
|
||||
pdir = data.dirs.GetDir(request.get_table[get_index], pdir->id);
|
||||
|
||||
if( !pdir )
|
||||
break;
|
||||
|
||||
++get_index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseItem()
|
||||
{
|
||||
SkipEmptyString("FP: Item: skipped empty string");
|
||||
|
||||
if( get_index == get_table_len )
|
||||
return;
|
||||
|
||||
// request.dir_table has at least one element
|
||||
long parent_id = request.dir_table.back()->id;
|
||||
const std::string & url = request.get_table[get_index];
|
||||
|
||||
request.status = db.GetItem(parent_id, url, request.item);
|
||||
|
||||
if( request.status == Error::ok )
|
||||
{
|
||||
++get_index;
|
||||
request.is_item = true;
|
||||
log << log3 << "FP: Item: id: " << request.item.id << ", url: " << request.item.url << logend;
|
||||
}
|
||||
else
|
||||
log << log3 << "FP: No Item: url: " << url << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseFunction()
|
||||
{
|
||||
SkipEmptyString("FP: Function: skipped empty string");
|
||||
|
||||
if( get_index == get_table_len )
|
||||
return;
|
||||
|
||||
request.pfunction = data.functions.GetFunction(request.get_table[get_index]);
|
||||
|
||||
|
||||
if( request.pfunction )
|
||||
{
|
||||
++get_index;
|
||||
log << log3 << "FP: Function: " << request.pfunction->item.url << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseParams()
|
||||
{
|
||||
while( true )
|
||||
{
|
||||
SkipEmptyString("FP: Params: skipped empty string");
|
||||
|
||||
if( get_index == get_table_len )
|
||||
break;
|
||||
|
||||
request.param_table.push_back( &request.get_table[get_index] );
|
||||
log << log3 << "FP: Params: " << request.get_table[get_index] << logend;
|
||||
|
||||
++get_index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FunctionParser::Parse()
|
||||
{
|
||||
request.status = Error::ok;
|
||||
get_index = 0;
|
||||
get_table_len = request.get_table.size();
|
||||
request.pfunction = 0;
|
||||
request.is_item = false;
|
||||
|
||||
ParseDirectories();
|
||||
|
||||
if( request.status != Error::ok )
|
||||
return;
|
||||
|
||||
ParseFunction();
|
||||
|
||||
if( !request.pfunction )
|
||||
{
|
||||
ParseItem();
|
||||
|
||||
if( request.status != Error::ok )
|
||||
return;
|
||||
|
||||
ParseFunction();
|
||||
|
||||
if( !request.pfunction && get_index != get_table_len )
|
||||
{
|
||||
request.status = Error::no_function;
|
||||
log << log3 << "FP: Parse: unknown function: \"" << request.get_table[get_index] << "\"" << logend;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ParseParams();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user