the first part of reimplementing has been done
now we have app object and singletons are only: log logn plugin and app git-svn-id: svn://ttmath.org/publicrep/winix/trunk@628 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
232
functions/functionparser.cpp
Executable file
232
functions/functionparser.cpp
Executable file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "functionparser.h"
|
||||
#include "core/log.h"
|
||||
#include "core/item.h"
|
||||
#include "core/error.h"
|
||||
#include "functions.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 = system->dirs.GetRootDir();
|
||||
|
||||
if( !pdir )
|
||||
{
|
||||
// there is no the root dir
|
||||
request->status = WINIX_ERR_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 = system->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 == WINIX_ERR_OK )
|
||||
{
|
||||
if( request->role == Request::authorizer && request->item.auth == Item::auth_none )
|
||||
{
|
||||
log << log1 << "FP: item.url: " << url << " exists but has not a static content (authorizer role)" << logend;
|
||||
request->status = WINIX_ERR_NO_ITEM;
|
||||
return;
|
||||
}
|
||||
|
||||
++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 = functions->Find(request->get_table[get_index]);
|
||||
|
||||
|
||||
if( request->pfunction )
|
||||
{
|
||||
++get_index;
|
||||
log << log3 << "FP: Function: " << request->pfunction->fun.url << logend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseParams(const std::string & par)
|
||||
{
|
||||
Param param;
|
||||
size_t i;
|
||||
|
||||
if( par.empty() )
|
||||
return;
|
||||
|
||||
// looking for the first colon ':'
|
||||
for(i=0 ; i<par.size() && par[i] != ':' ; ++i);
|
||||
|
||||
if( i == par.size() )
|
||||
{
|
||||
// there is no a colon
|
||||
param.name = par;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( i > 0 )
|
||||
param.name = par.substr(0, i);
|
||||
|
||||
if( i < par.size() - 1 )
|
||||
param.value = par.substr(i+1);
|
||||
}
|
||||
|
||||
request->param_table.push_back(param);
|
||||
|
||||
log << log3 << "FP: Param: name=" << param.name;
|
||||
|
||||
if( !param.value.empty() )
|
||||
log << ", value=" << param.value;
|
||||
|
||||
log << logend;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FunctionParser::ParseParams()
|
||||
{
|
||||
for( ; true ; ++get_index )
|
||||
{
|
||||
SkipEmptyString("FP: Params: skipped empty string");
|
||||
|
||||
if( get_index == get_table_len )
|
||||
break;
|
||||
|
||||
ParseParams(request->get_table[get_index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void FunctionParser::Parse(Request * prequest, Db * pdb, Functions * pfunctions, System * psystem)
|
||||
{
|
||||
request = prequest;
|
||||
db = pdb;
|
||||
functions = pfunctions;
|
||||
system = psystem;
|
||||
|
||||
request->status = WINIX_ERR_OK;
|
||||
get_index = 0;
|
||||
get_table_len = request->get_table.size();
|
||||
request->pfunction = 0;
|
||||
request->is_item = false;
|
||||
|
||||
ParseDirectories();
|
||||
|
||||
if( request->status != WINIX_ERR_OK )
|
||||
return;
|
||||
|
||||
ParseFunction();
|
||||
|
||||
if( !request->pfunction )
|
||||
{
|
||||
ParseItem();
|
||||
|
||||
if( request->status != WINIX_ERR_OK )
|
||||
return;
|
||||
|
||||
ParseFunction();
|
||||
|
||||
if( !request->pfunction && get_index != get_table_len )
|
||||
{
|
||||
request->status = WINIX_ERR_NO_FUNCTION;
|
||||
log << log3 << "FP: Parse: unknown function: \"" << request->get_table[get_index] << "\"" << logend;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ParseParams();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user