added: Export plugin (not finished yet)

added:   ThreadManager
         all threads are connected to the ThreadManager
         they are started/stopped by the manager
changed: FunctionParser
         now we are parsing directly what is in URI
         (we were using GetParser beforehand)
         we are able to recognize ordinary URI scheme (with '?' and '#' characters)
         sample:
         http://domain.com/dir1/dir2/item/function?par1=val2&par2=val2#htmlanchor
         is the same as:
         http://domain.com/dir1/dir2/item/function/par1:val2/par2:val2#htmlanchor
         'htmlanchor' is put in Request::anchor field,
         and the default function can be used like this:
         http://domain.com/dir1/dir2/item?par1=val2&par2=val2#htmlanchor
         but there is not an equivalent in winix form
         e.g. http://domain.com/dir1/dir2/item/par1:val2/par2:val2#htmlanchor
         because 'par1:val2' would be treated as a function name
removed: GetParser
         now we don't have Request::get_tab structure
removed: CKEditorGetParser
         it is not needed now



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@752 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2011-07-28 22:18:10 +00:00
parent c37c1ff812
commit 4d87359aca
51 changed files with 1646 additions and 1203 deletions

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* Copyright (c) 2008-2011, Tomasz Sowa
* All rights reserved.
*
*/
@@ -12,138 +12,231 @@
#include "core/item.h"
#include "core/error.h"
#include "functions.h"
#include "utf8.h"
void FunctionParser::SkipEmptyString(const char * msg)
FunctionParser::FunctionParser()
{
for( ; get_index != get_tab_len && cur->request->get_tab[get_index].empty() ; ++get_index )
log << log3 << msg << logend;
utf8 = false;
}
void FunctionParser::UTF8(bool use_utf8)
{
utf8 = use_utf8;
}
bool FunctionParser::Parse(Cur * pcur, Db * pdb, Functions * pfunctions, System * psystem)
{
db = pdb;
cur = pcur;
system = psystem;
functions = pfunctions;
last_dir = 0;
path = cur->request->env_request_uri;
//!! mozna dodac sprawdzanie dlugosci path
// jesli wieksza niz np 2048 to zglosic incorrect url
// i nie parsowac
ParseDirsItemFunction();
ParseParams();
ParseAnchor();
return cur->request->status == WINIX_ERR_OK;
}
void FunctionParser::ParseDirectories()
void FunctionParser::ParseDirsItemFunction()
{
Item * pdir = system->dirs.GetRootDir();
if( !pdir )
if( !AddRootDir() )
return;
ReadName();
while( IsDir() )
{
// there is no the root dir
cur->request->status = WINIX_ERR_NO_ROOT_DIR;
return;
AddDir();
ReadName();
}
if( name.empty() )
return;
while( true )
{
cur->request->dir_tab.push_back( pdir );
log << log3 << "FP: Directory: ";
if( pdir->parent_id == -1 )
log << "(root)" << logend;
else
log << pdir->url << logend;
if( CheckAddFunction() )
return;
SkipEmptyString("FP: Directory: skipped empty string");
if( get_index == get_tab_len )
break;
if( CheckAddItem() )
{
ReadName();
CheckAddFunction();
SkipSlashes();
pdir = system->dirs.GetDir(cur->request->get_tab[get_index], pdir->id);
if( !cur->request->function && *path && *path!='#' && *path!='?' )
{
log << log3 << "FP: unknown function: " << name << logend;
cur->request->status = WINIX_ERR_NO_ITEM;
}
}
}
bool FunctionParser::AddRootDir()
{
last_dir = system->dirs.GetRootDir();
if( !last_dir )
{
log << log3 << "FP: there is not a root directory" << logend;
cur->request->status = WINIX_ERR_INTERNAL_ERROR;
return false;
}
AddDir();
return true;
}
bool FunctionParser::IsDir()
{
// directory names should not be empty
if( name.empty() || !last_dir )
return false;
last_dir = system->dirs.GetDir(name, last_dir->id);
if( !pdir )
break;
++get_index;
}
return last_dir != 0;
}
bool FunctionParser::CheckAddItem()
{
// cur->request->dir_tab has at least one element
long parent_id = cur->request->dir_tab.back()->id;
Error status = db->GetItem(parent_id, name, cur->request->item);
if( status == WINIX_ERR_OK )
{
log << log3 << "FP: Item: id: " << cur->request->item.id << ", url: " << cur->request->item.url << logend;
cur->request->last_item = &cur->request->item;
cur->request->is_item = true;
return true;
}
if( status == WINIX_ERR_NO_ITEM )
{
log << log3 << "FP: No Item: url: " << name << logend;
cur->request->status = WINIX_ERR_NO_ITEM;
return false;
}
log << log1 << "FP: db error" << logend;
cur->request->status = WINIX_ERR_INTERNAL_ERROR;
return false;
}
bool FunctionParser::CheckAddFunction()
{
cur->request->function = functions->Find(name);
if( cur->request->function )
{
log << log3 << "FP: Function: " << cur->request->function->fun.url << logend;
return true;
}
return false;
}
void FunctionParser::AddDir()
{
cur->request->dir_tab.push_back( last_dir );
log << log3 << "FP: Directory: ";
if( last_dir->parent_id == -1 )
log << "(root)" << logend;
else
log << last_dir->url << logend;
cur->request->last_item = cur->request->dir_tab.back();
}
void FunctionParser::ParseItem()
void FunctionParser::ParseParams()
{
SkipEmptyString("FP: Item: skipped empty string");
if( get_index == get_tab_len )
SkipSlashes();
if( *path == '#' )
{
// there are not any parameters
return;
// cur->request->dir_tab has at least one element
long parent_id = cur->request->dir_tab.back()->id;
const std::wstring & url = cur->request->get_tab[get_index];
cur->request->status = db->GetItem(parent_id, url, cur->request->item);
if( cur->request->status == WINIX_ERR_OK )
{
cur->request->last_item = &cur->request->item;
if( cur->request->role == Request::authorizer && cur->request->item.file_type == WINIX_ITEM_FILETYPE_NONE )
{
log << log1 << "FP: item.url: " << url << " exists but has not a static content (authorizer role)" << logend;
cur->request->status = WINIX_ERR_NO_ITEM;
return;
}
++get_index;
cur->request->is_item = true;
log << log3 << "FP: Item: id: " << cur->request->item.id << ", url: " << cur->request->item.url << logend;
}
if( *path == '?' )
ParseOrdinaryParams();
else
{
log << log3 << "FP: No Item: url: " << url << logend;
}
ParseWinixParams();
}
void FunctionParser::ParseFunction()
void FunctionParser::ParseOrdinaryParams()
{
SkipEmptyString("FP: Function: skipped empty string");
if( get_index == get_tab_len )
return;
cur->request->function = functions->Find(cur->request->get_tab[get_index]);
if( cur->request->function )
if( *path=='?' )
path += 1;
do
{
++get_index;
log << log3 << "FP: Function: " << cur->request->function->fun.url << logend;
ReadOrdinaryParName();
if( name.empty() )
break;
ReadOrdinaryParValue();
if( *path == '&' )
path += 1;
AddParam();
}
while( true );
}
void FunctionParser::ParseParams(const std::wstring & par)
void FunctionParser::ParseWinixParams()
{
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() )
do
{
// there is no a colon
param.name = par;
}
else
{
if( i > 0 )
param.name = par.substr(0, i);
SkipSlashes();
ReadWinixParName();
if( i < par.size() - 1 )
param.value = par.substr(i+1);
}
if( name.empty() )
break;
ReadWinixParValue();
AddParam();
}
while( true );
}
void FunctionParser::AddParam()
{
param.name = name;
param.value = value;
cur->request->param_tab.push_back(param);
log << log3 << "FP: Param: name=" << param.name;
@@ -155,81 +248,153 @@ size_t i;
}
void FunctionParser::ParseParams()
void FunctionParser::ParseAnchor()
{
for( ; true ; ++get_index )
{
SkipEmptyString("FP: Params: skipped empty string");
if( get_index == get_tab_len )
break;
ParseParams(cur->request->get_tab[get_index]);
}
}
void FunctionParser::Parse(Cur * pcur, Db * pdb, Functions * pfunctions, System * psystem)
{
db = pdb;
cur = pcur;
system = psystem;
functions = pfunctions;
cur->request->status = WINIX_ERR_OK;
get_index = 0;
get_tab_len = cur->request->get_tab.size();
cur->request->function = 0;
cur->request->is_item = false;
ParseDirectories();
if( cur->request->status != WINIX_ERR_OK )
if( *path == 0 )
return;
ParseFunction();
if( !cur->request->function )
if( *path != '#' )
{
ParseItem();
if( cur->request->status != WINIX_ERR_OK )
return;
ParseFunction();
if( !cur->request->function && get_index != get_tab_len )
{
cur->request->status = WINIX_ERR_NO_FUNCTION;
log << log3 << "FP: Parse: unknown function: \"" << cur->request->get_tab[get_index] << "\"" << logend;
return;
}
cur->request->status = WINIX_ERR_INCORRECT_URI;
return;
}
ParseParams();
path += 1;
name_ascii.clear();
while( *path )
name_ascii += GetChar();
ToWide(name_ascii, cur->request->anchor);
if( !cur->request->anchor.empty() )
log << log3 << "FP: anchor: " << cur->request->anchor << logend;
}
void FunctionParser::SkipSlashes()
{
while( *path == '/' )
path += 1;
}
int FunctionParser::FromHex(int c)
{
if( c>='0' && c<='9' )
return c - '0';
else
if( c>='a' && c<='f' )
return c - 'a' + 10;
else
if( c>='A' && c<='F' )
return c - 'A' + 10;
else
cur->request->status = WINIX_ERR_INCORRECT_URI;
return 0;
}
int FunctionParser::GetChar()
{
int c;
if( *path == 0 )
return 0;
if( *path == '%' && *(path+1)!=0 && *(path+2)!=0 )
{
c = (FromHex(*(path+1)) << 4) + FromHex(*(path+2));
if( c == 0 )
cur->request->status = WINIX_ERR_INCORRECT_URI;
path += 3;
}
else
{
c = *path;
path += 1;
}
return c;
}
void FunctionParser::ToWide(const std::string & src, std::wstring & dst)
{
dst.clear();
if( utf8 )
Ezc::UTF8ToWide(src, dst, false);
else
AssignString(src, dst, false);
}
void FunctionParser::ReadName()
{
SkipSlashes();
name_ascii.clear();
while( *path && *path!='/' && *path!='?' && *path!='#' )
name_ascii += GetChar();
ToWide(name_ascii, name);
}
void FunctionParser::ReadOrdinaryParName()
{
name_ascii.clear();
while( *path && *path!='=' && *path!='&' && *path!='#' )
name_ascii += GetChar();
ToWide(name_ascii, name);
}
void FunctionParser::ReadOrdinaryParValue()
{
value_ascii.clear();
if( *path=='=' )
path += 1;
while( *path && *path!='&' && *path!='#' )
value_ascii += GetChar();
ToWide(value_ascii, value);
}
void FunctionParser::ReadWinixParName()
{
name_ascii.clear();
while( *path && *path!='/' && *path!=':' && *path!='#' )
name_ascii += GetChar();
ToWide(name_ascii, name);
}
void FunctionParser::ReadWinixParValue()
{
value_ascii.clear();
if( *path==':' )
path += 1;
while( *path && *path!='/' && *path!='#' )
value_ascii += GetChar();
ToWide(value_ascii, value);
}