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"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "core/log.h"
|
|
|
|
#include "core/item.h"
|
|
|
|
#include "core/error.h"
|
|
|
|
#include "functions.h"
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FunctionParser::SkipEmptyString(const char * msg)
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
for( ; get_index != get_tab_len && request->get_tab[get_index].empty() ; ++get_index )
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log3 << msg << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FunctionParser::ParseDirectories()
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
Item * pdir = system->dirs.GetRootDir();
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
if( !pdir )
|
|
|
|
{
|
|
|
|
// there is no the root dir
|
2010-08-10 18:12:50 +02: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 )
|
|
|
|
{
|
2010-08-10 22:43:38 +02:00
|
|
|
request->dir_tab.push_back( pdir );
|
2008-12-30 02:05:03 +01:00
|
|
|
log << log3 << "FP: Directory: ";
|
|
|
|
|
|
|
|
if( pdir->parent_id == -1 )
|
|
|
|
log << "(root)" << logend;
|
|
|
|
else
|
|
|
|
log << pdir->url << logend;
|
|
|
|
|
|
|
|
SkipEmptyString("FP: Directory: skipped empty string");
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( get_index == get_tab_len )
|
2008-12-30 02:05:03 +01:00
|
|
|
break;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
pdir = system->dirs.GetDir(request->get_tab[get_index], pdir->id);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
if( !pdir )
|
|
|
|
break;
|
|
|
|
|
|
|
|
++get_index;
|
|
|
|
}
|
2010-08-14 16:45:25 +02:00
|
|
|
|
|
|
|
request->last_item = request->dir_tab.back();
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FunctionParser::ParseItem()
|
|
|
|
{
|
|
|
|
SkipEmptyString("FP: Item: skipped empty string");
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( get_index == get_tab_len )
|
2008-12-30 02:05:03 +01:00
|
|
|
return;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
// request->dir_tab has at least one element
|
|
|
|
long parent_id = request->dir_tab.back()->id;
|
2010-11-21 01:19:17 +01:00
|
|
|
const std::wstring & url = request->get_tab[get_index];
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
request->status = db->GetItem(parent_id, url, request->item);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
if( request->status == WINIX_ERR_OK )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-08-14 16:45:25 +02:00
|
|
|
request->last_item = &request->item;
|
|
|
|
|
2010-08-10 18:12:50 +02: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-08-10 18:12:50 +02: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;
|
2010-08-10 18:12:50 +02:00
|
|
|
request->is_item = true;
|
|
|
|
log << log3 << "FP: Item: id: " << request->item.id << ", url: " << request->item.url << logend;
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
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");
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( get_index == get_tab_len )
|
2008-12-30 02:05:03 +01:00
|
|
|
return;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
request->function = functions->Find(request->get_tab[get_index]);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( request->function )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
|
|
|
++get_index;
|
2010-08-10 22:43:38 +02:00
|
|
|
log << log3 << "FP: Function: " << request->function->fun.url << logend;
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-04 22:27:14 +02:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
void FunctionParser::ParseParams(const std::wstring & par)
|
2010-07-04 22:27:14 +02:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
request->param_tab.push_back(param);
|
2010-07-04 22:27:14 +02:00
|
|
|
|
2010-07-05 17:21:06 +02:00
|
|
|
log << log3 << "FP: Param: name=" << param.name;
|
|
|
|
|
|
|
|
if( !param.value.empty() )
|
|
|
|
log << ", value=" << param.value;
|
|
|
|
|
|
|
|
log << logend;
|
2010-07-04 22:27:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
void FunctionParser::ParseParams()
|
|
|
|
{
|
2010-07-04 22:27:14 +02:00
|
|
|
for( ; true ; ++get_index )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
|
|
|
SkipEmptyString("FP: Params: skipped empty string");
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( get_index == get_tab_len )
|
2008-12-30 02:05:03 +01:00
|
|
|
break;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
ParseParams(request->get_tab[get_index]);
|
2008-12-30 02:05:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void FunctionParser::Parse(Request * prequest, Db * pdb, Functions * pfunctions, System * psystem)
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
request = prequest;
|
|
|
|
db = pdb;
|
|
|
|
functions = pfunctions;
|
|
|
|
system = psystem;
|
|
|
|
|
|
|
|
request->status = WINIX_ERR_OK;
|
|
|
|
get_index = 0;
|
2010-08-10 22:43:38 +02:00
|
|
|
get_tab_len = request->get_tab.size();
|
|
|
|
request->function = 0;
|
2010-08-10 18:12:50 +02:00
|
|
|
request->is_item = false;
|
2008-12-30 02:05:03 +01:00
|
|
|
|
|
|
|
ParseDirectories();
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
if( request->status != WINIX_ERR_OK )
|
2008-12-30 02:05:03 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
ParseFunction();
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( !request->function )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
|
|
|
ParseItem();
|
|
|
|
|
2010-08-10 18:12:50 +02: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();
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
if( !request->function && get_index != get_tab_len )
|
2008-12-30 02:05:03 +01:00
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
request->status = WINIX_ERR_NO_FUNCTION;
|
2010-08-10 22:43:38 +02:00
|
|
|
log << log3 << "FP: Parse: unknown function: \"" << request->get_tab[get_index] << "\"" << logend;
|
2008-12-30 02:05:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-12-30 21:46:12 +01:00
|
|
|
|
2008-12-30 02:05:03 +01:00
|
|
|
ParseParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|