2008-12-30 02:05:03 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2008-12-30 02:05:03 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2010-02-28 22:33:06 +01:00
|
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
2008-12-30 02:05:03 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "functionparser.h"
|
2009-04-21 22:50:55 +02:00
|
|
|
#include "log.h"
|
|
|
|
#include "item.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "data.h"
|
|
|
|
#include "db.h"
|
|
|
|
#include "request.h"
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2010-02-28 01:08:10 +01:00
|
|
|
request.status = WINIX_ERR_NO_ROOT_DIR;
|
2008-12-30 02:05:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-06 14:12:03 +01:00
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
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);
|
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
if( request.status == WINIX_ERR_OK )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-02-22 23:52:09 +01:00
|
|
|
if( request.role == Request::authorizer && request.item.auth == Item::auth_none )
|
2009-12-30 21:46:12 +01:00
|
|
|
{
|
|
|
|
log << log1 << "FP: item.url: " << url << " exists but has not a static content (authorizer role)" << logend;
|
2010-02-28 01:08:10 +01:00
|
|
|
request.status = WINIX_ERR_NO_ITEM;
|
2009-12-30 21:46:12 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
++get_index;
|
|
|
|
request.is_item = true;
|
|
|
|
log << log3 << "FP: Item: id: " << request.item.id << ", url: " << request.item.url << logend;
|
|
|
|
}
|
|
|
|
else
|
2009-12-30 21:46:12 +01:00
|
|
|
{
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log3 << "FP: No Item: url: " << url << logend;
|
2009-12-30 21:46:12 +01:00
|
|
|
}
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2010-02-28 01:08:10 +01:00
|
|
|
request.status = WINIX_ERR_OK;
|
2008-12-30 02:05:03 +01:00
|
|
|
get_index = 0;
|
|
|
|
get_table_len = request.get_table.size();
|
|
|
|
request.pfunction = 0;
|
|
|
|
request.is_item = false;
|
|
|
|
|
|
|
|
ParseDirectories();
|
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
if( request.status != WINIX_ERR_OK )
|
2008-12-30 02:05:03 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
ParseFunction();
|
|
|
|
|
|
|
|
if( !request.pfunction )
|
|
|
|
{
|
|
|
|
ParseItem();
|
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
if( request.status != WINIX_ERR_OK )
|
2008-12-30 02:05:03 +01:00
|
|
|
return;
|
2009-01-26 21:49:28 +01:00
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
ParseFunction();
|
|
|
|
|
|
|
|
if( !request.pfunction && get_index != get_table_len )
|
|
|
|
{
|
2010-02-28 01:08:10 +01:00
|
|
|
request.status = WINIX_ERR_NO_FUNCTION;
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log3 << "FP: Parse: unknown function: \"" << request.get_table[get_index] << "\"" << logend;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-12-30 21:46:12 +01:00
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
ParseParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|