changed: added Cur structure
we have there two pointers: Request * request; Session * session; these are the current request and the current session the session GC was moved to SessionManager (was in SessionContainer) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@708 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -21,12 +21,13 @@ void Functions::SetConfig(Config * pconfig)
|
||||
}
|
||||
|
||||
|
||||
void Functions::SetRequest(Request * prequest)
|
||||
void Functions::SetCur(Cur * pcur)
|
||||
{
|
||||
request = prequest;
|
||||
cur = pcur;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Functions::SetDb(Db * pdb)
|
||||
{
|
||||
db = pdb;
|
||||
@@ -135,7 +136,7 @@ return WINIX_NOTHING_TO_DO;
|
||||
void Functions::SetObjects(FunctionBase * fun)
|
||||
{
|
||||
fun->SetConfig(config);
|
||||
fun->SetRequest(request);
|
||||
fun->SetCur(cur);
|
||||
fun->SetDb(db);
|
||||
fun->SetSystem(system);
|
||||
fun->SetFunctions(this);
|
||||
@@ -224,22 +225,22 @@ void Functions::Init()
|
||||
|
||||
void Functions::Parse()
|
||||
{
|
||||
function_parser.Parse(request, db, this, system);
|
||||
function_parser.Parse(cur, db, this, system);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Functions::SetDefaultFunctionForFile()
|
||||
{
|
||||
if( request->item.file_type != WINIX_ITEM_FILETYPE_NONE )
|
||||
request->function = &fun_download;
|
||||
if( cur->request->item.file_type != WINIX_ITEM_FILETYPE_NONE )
|
||||
cur->request->function = &fun_download;
|
||||
else
|
||||
if( system->HasReadExecAccess(request->item) )
|
||||
request->function = &fun_run;
|
||||
if( system->HasReadExecAccess(cur->request->item) )
|
||||
cur->request->function = &fun_run;
|
||||
else
|
||||
request->function = &fun_cat;
|
||||
cur->request->function = &fun_cat;
|
||||
|
||||
log << log3 << "Functions: default function: " << request->function->fun.url << logend;
|
||||
log << log3 << "Functions: default function: " << cur->request->function->fun.url << logend;
|
||||
}
|
||||
|
||||
|
||||
@@ -249,30 +250,30 @@ void Functions::SetDefaultFunctionForDir()
|
||||
{
|
||||
// !! nie potrzebne
|
||||
// if( system->mounts.pmount->type == system->mounts.MountTypeThread() )
|
||||
// request->function = &fun_thread;
|
||||
// cur->request->function = &fun_thread;
|
||||
// else
|
||||
|
||||
request->function = &fun_ls;
|
||||
cur->request->function = &fun_ls;
|
||||
|
||||
log << log3 << "Functions: default function: " << request->function->fun.url << logend;
|
||||
log << log3 << "Functions: default function: " << cur->request->function->fun.url << logend;
|
||||
}
|
||||
|
||||
|
||||
void Functions::SetDefaultFunction()
|
||||
{
|
||||
request->function = 0;
|
||||
cur->request->function = 0;
|
||||
|
||||
plugin.Call(WINIX_SELECT_DEFAULT_FUNCTION);
|
||||
|
||||
if( request->function )
|
||||
if( cur->request->function )
|
||||
{
|
||||
log << log3 << "Functions: default function: " << request->function->fun.url
|
||||
log << log3 << "Functions: default function: " << cur->request->function->fun.url
|
||||
<< " (set by a plugin)" << logend;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if( request->is_item )
|
||||
if( cur->request->is_item )
|
||||
SetDefaultFunctionForFile();
|
||||
else
|
||||
SetDefaultFunctionForDir();
|
||||
@@ -288,13 +289,13 @@ void Functions::CheckFunctionFollowDir(bool was_default_function)
|
||||
|
||||
if( was_default_function )
|
||||
{
|
||||
if( request->dir_tab.back()->link_redirect == 1 )
|
||||
if( cur->request->dir_tab.back()->link_redirect == 1 )
|
||||
{
|
||||
system->RedirectTo(request->dir_tab.back()->link_to);
|
||||
system->RedirectTo(cur->request->dir_tab.back()->link_to);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( system->FollowAllLinks(request->dir_tab.back()->link_to, true, true) )
|
||||
if( system->FollowAllLinks(cur->request->dir_tab.back()->link_to, true, true) )
|
||||
SetDefaultFunction();
|
||||
}
|
||||
}
|
||||
@@ -304,25 +305,25 @@ void Functions::CheckFunctionFollowDir(bool was_default_function)
|
||||
|
||||
void Functions::CheckFunctionFollowSymlink(bool was_default_function)
|
||||
{
|
||||
if( request->item.link_redirect == 1 )
|
||||
if( cur->request->item.link_redirect == 1 )
|
||||
{
|
||||
if( was_default_function )
|
||||
system->RedirectTo(request->item.link_to);
|
||||
system->RedirectTo(cur->request->item.link_to);
|
||||
else
|
||||
system->RedirectWithFunctionAndParamsTo(request->item.link_to);
|
||||
system->RedirectWithFunctionAndParamsTo(cur->request->item.link_to);
|
||||
}
|
||||
else
|
||||
if( system->FollowAllLinks(request->item.link_to, true, true) )
|
||||
if( system->FollowAllLinks(cur->request->item.link_to, true, true) )
|
||||
{
|
||||
if( was_default_function )
|
||||
SetDefaultFunction();
|
||||
|
||||
if( request->status == WINIX_ERR_OK && !request->redirect_to.empty() && !was_default_function && request->function )
|
||||
if( cur->request->status == WINIX_ERR_OK && !cur->request->redirect_to.empty() && !was_default_function && cur->request->function )
|
||||
{
|
||||
// !! nie jestem pewny dodania tej nowej funkcji do redirecta... (sprawdzic to)
|
||||
request->redirect_to += '/';
|
||||
request->redirect_to += request->function->fun.url;
|
||||
system->AddParams(request->param_tab, request->redirect_to, false);
|
||||
cur->request->redirect_to += '/';
|
||||
cur->request->redirect_to += cur->request->function->fun.url;
|
||||
system->AddParams(cur->request->param_tab, cur->request->redirect_to, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,19 +335,19 @@ void Functions::CheckFunctionAndSymlink()
|
||||
{
|
||||
bool was_default_function = false;
|
||||
|
||||
if( !request->function || request->function == &fun_special_default )
|
||||
if( !cur->request->function || cur->request->function == &fun_special_default )
|
||||
{
|
||||
was_default_function = true;
|
||||
SetDefaultFunction();
|
||||
}
|
||||
|
||||
if( request->status != WINIX_ERR_OK || !request->redirect_to.empty() )
|
||||
if( cur->request->status != WINIX_ERR_OK || !cur->request->redirect_to.empty() )
|
||||
return;
|
||||
|
||||
if( !request->is_item && !request->dir_tab.back()->link_to.empty() )
|
||||
if( !cur->request->is_item && !cur->request->dir_tab.back()->link_to.empty() )
|
||||
CheckFunctionFollowDir(was_default_function);
|
||||
else
|
||||
if( request->is_item && request->item.type == Item::symlink && request->function && request->function->follow_symlinks )
|
||||
if( cur->request->is_item && cur->request->item.type == Item::symlink && cur->request->function && cur->request->function->follow_symlinks )
|
||||
CheckFunctionFollowSymlink(was_default_function);
|
||||
}
|
||||
|
||||
@@ -354,38 +355,38 @@ bool was_default_function = false;
|
||||
|
||||
void Functions::MakeFunction()
|
||||
{
|
||||
if( !request->function )
|
||||
if( !cur->request->function )
|
||||
{
|
||||
request->status = WINIX_ERR_NO_FUNCTION;
|
||||
cur->request->status = WINIX_ERR_NO_FUNCTION;
|
||||
log << log1 << "Functions: no function (neither cat nor ls)" << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
if( !system->DirsHaveReadExecPerm() ||
|
||||
!system->HasReadExecAccess(request->function->fun) ||
|
||||
!request->function->HasAccess() )
|
||||
!system->HasReadExecAccess(cur->request->function->fun) ||
|
||||
!cur->request->function->HasAccess() )
|
||||
{
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
return;
|
||||
}
|
||||
|
||||
if( request->method == Request::get )
|
||||
if( cur->request->method == Request::get )
|
||||
{
|
||||
if( request->redirect_to.empty() )
|
||||
request->function->MakeGet();
|
||||
if( cur->request->redirect_to.empty() )
|
||||
cur->request->function->MakeGet();
|
||||
}
|
||||
else
|
||||
if( request->method == Request::post )
|
||||
if( cur->request->method == Request::post )
|
||||
{
|
||||
// we don't use post with redirecting (the post variables would be lost)
|
||||
|
||||
if( request->redirect_to.empty() )
|
||||
request->function->MakePost();
|
||||
if( cur->request->redirect_to.empty() )
|
||||
cur->request->function->MakePost();
|
||||
else
|
||||
request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||
}
|
||||
else
|
||||
if( request->method == Request::head )
|
||||
if( cur->request->method == Request::head )
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
@@ -401,19 +402,19 @@ void Functions::CheckGetPostTimes(time_t difference)
|
||||
{
|
||||
time_t now = std::time(0);
|
||||
|
||||
if( request->session->puser )
|
||||
if( cur->session->puser )
|
||||
return;
|
||||
|
||||
if( request->method != Request::post )
|
||||
if( cur->request->method != Request::post )
|
||||
return;
|
||||
|
||||
if( now - request->session->last_time_get >= (time_t)difference )
|
||||
if( now - cur->session->last_time_get >= (time_t)difference )
|
||||
return;
|
||||
|
||||
if( request->AllPostVarEmpty() )
|
||||
if( cur->request->AllPostVarEmpty() )
|
||||
return;
|
||||
|
||||
request->session->spam_score += 1;
|
||||
cur->session->spam_score += 1;
|
||||
log << log1 << "Functions: spam +1: POST after GET sent too fast" << logend;
|
||||
}
|
||||
|
||||
@@ -424,15 +425,15 @@ bool Functions::CheckAbuse()
|
||||
{
|
||||
if( !system->rebus.CheckRebus() )
|
||||
{
|
||||
request->status = WINIX_ERR_INCORRECT_REBUS;
|
||||
cur->request->status = WINIX_ERR_INCORRECT_REBUS;
|
||||
return true;
|
||||
}
|
||||
|
||||
CheckGetPostTimes();
|
||||
|
||||
if( request->session->spam_score > 0 )
|
||||
if( cur->session->spam_score > 0 )
|
||||
{
|
||||
request->status = WINIX_ERR_SPAM;
|
||||
cur->request->status = WINIX_ERR_SPAM;
|
||||
log << log1 << "Functions: ignoring due to suspected spamming" << logend;
|
||||
return true;
|
||||
}
|
||||
@@ -446,17 +447,17 @@ return false;
|
||||
// returning true if the 'url' has to be changed
|
||||
void Functions::ReadItemUrlSubject(Item & item, Item::Type item_type)
|
||||
{
|
||||
std::wstring * new_subject = request->PostVarp(L"subject");
|
||||
std::wstring * new_url = request->PostVarp(L"url");
|
||||
std::wstring * new_subject = cur->request->PostVarp(L"subject");
|
||||
std::wstring * new_url = cur->request->PostVarp(L"url");
|
||||
|
||||
if( new_subject )
|
||||
item.subject = *new_subject;
|
||||
|
||||
if( item.subject.empty() )
|
||||
{
|
||||
item.subject = request->dir_tab.back()->subject;
|
||||
item.subject = cur->request->dir_tab.back()->subject;
|
||||
item.subject += L"_msg_";
|
||||
Toa(db->Size(request->dir_tab.back()->id, Item::file), item.subject, 10, false);
|
||||
Toa(db->Size(cur->request->dir_tab.back()->id, Item::file), item.subject, 10, false);
|
||||
}
|
||||
|
||||
if( new_url )
|
||||
@@ -475,13 +476,13 @@ void Functions::ReadItemFilterHtml(Item & item)
|
||||
html_filter.CheckOrphans(HTMLFilter::lang_none);
|
||||
html_filter.SafeMode(true);
|
||||
|
||||
html_filter.Filter(request->PostVar(L"itemcontent"), item.content);
|
||||
html_filter.Filter(cur->request->PostVar(L"itemcontent"), item.content);
|
||||
}
|
||||
|
||||
|
||||
void Functions::ReadItemContent(Item & item, const std::wstring & content_type)
|
||||
{
|
||||
bool is_root = request->session->puser && request->session->puser->super_user;
|
||||
bool is_root = cur->session->puser && cur->session->puser->super_user;
|
||||
bool filter_html = (content_type == L"2") && config->editors_html_safe_mode;
|
||||
|
||||
if( filter_html && is_root && config->editors_html_safe_mode_skip_root )
|
||||
@@ -490,14 +491,14 @@ void Functions::ReadItemContent(Item & item, const std::wstring & content_type)
|
||||
if( filter_html )
|
||||
ReadItemFilterHtml(item);
|
||||
else
|
||||
request->PostVar(L"itemcontent", item.content);
|
||||
cur->request->PostVar(L"itemcontent", item.content);
|
||||
}
|
||||
|
||||
|
||||
void Functions::ReadItemContentWithType(Item & item)
|
||||
{
|
||||
item.content_type = Item::ct_formatted_text; // default is formatted text
|
||||
request->PostVar(L"contenttype", temp);
|
||||
cur->request->PostVar(L"contenttype", temp);
|
||||
|
||||
ReadItemContent(item, temp);
|
||||
|
||||
@@ -513,10 +514,10 @@ void Functions::ReadItemContentWithType(Item & item)
|
||||
|
||||
// those below need special privileges
|
||||
|
||||
if( !request->session->puser )
|
||||
if( !cur->session->puser )
|
||||
return;
|
||||
|
||||
long user_id = request->session->puser->id;
|
||||
long user_id = cur->session->puser->id;
|
||||
|
||||
|
||||
if( temp == L"2" )
|
||||
@@ -551,7 +552,7 @@ void Functions::ReadItem(Item & item, Item::Type item_type)
|
||||
return;
|
||||
|
||||
item.type = item_type;
|
||||
item.parent_id = request->dir_tab.back()->id; // !! moze to dac jako parametr?
|
||||
item.parent_id = cur->request->dir_tab.back()->id; // !! moze to dac jako parametr?
|
||||
|
||||
ReadItemUrlSubject(item, item_type);
|
||||
|
||||
@@ -562,16 +563,16 @@ void Functions::ReadItem(Item & item, Item::Type item_type)
|
||||
|
||||
void Functions::SetUser(Item & item)
|
||||
{
|
||||
if( request->session && request->session->puser )
|
||||
if( cur->session && cur->session->puser )
|
||||
{
|
||||
item.user_id = request->session->puser->id;
|
||||
item.user_id = cur->session->puser->id;
|
||||
item.guest_name.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
item.user_id = -1;
|
||||
request->PostVar(L"guestname", item.guest_name);
|
||||
cur->request->PostVar(L"guestname", item.guest_name);
|
||||
}
|
||||
|
||||
item.group_id = request->dir_tab.back()->group_id;
|
||||
item.group_id = cur->request->dir_tab.back()->group_id;
|
||||
}
|
||||
|
Reference in New Issue
Block a user