add closing dialogs, redirecting and removing content functionality to the winix framework

add such new methods to FunctionBase:
- bool can_push_url_to_browser_history();
- void add_standard_models();
- void close_modal_dialogs();

- void prepare_doc_url(const wchar_t * local_url, pt::WTextStream & url);
- void prepare_doc_url(const wchar_t * local_url, std::wstring & url);
- std::wstring prepare_doc_url(const wchar_t * local_url = nullptr);
- std::wstring prepare_doc_url(const std::wstring & local_url);

- void redirect_to(const wchar_t * url, bool append_domain = true);
- void redirect_to(const std::wstring & url, bool append_domain = true);
- void redirect_to(const pt::WTextStream & url, bool append_domain = true);

- void redirect_to(const wchar_t * url, const wchar_t * frame_url, const wchar_t * dom_target);
- void redirect_to(const std::wstring & url, const std::wstring & frame_url, const std::wstring & dom_target);
- void redirect_to(pt::WTextStream & url, pt::WTextStream & frame_url, pt::WTextStream & dom_target);
- void redirect_to(pt::WTextStream & url, pt::WTextStream & frame_url, const wchar_t * dom_target);
- void redirect_to(const wchar_t * url, const wchar_t * frame_url, pt::WTextStream & dom_target);

- void retarged(const wchar_t * frame, const wchar_t * dom_target, const wchar_t * push_url = nullptr, const wchar_t * swap_algorithm = nullptr);
- void retarged(const std::wstring & frame, const std::wstring & dom_target, const std::wstring & push_url, const wchar_t * swap_algorithm = nullptr);
- void retarged(const wchar_t * frame, pt::WTextStream & dom_target, const wchar_t * push_url = nullptr, const wchar_t * swap_algorithm = nullptr);

- void remove_content(pt::WTextStream & dom_target, bool close_dialogs = false);
- void remove_content(const wchar_t * dom_target, bool has_postfix, long dom_target_postfix, bool close_dialogs = false);
- void remove_content(const wchar_t * dom_target, long dom_target_postfix, bool close_dialogs = false);
- void remove_content(const wchar_t * dom_target, bool close_dialogs = false);

- void update_content(const wchar_t * frame, pt::WTextStream & dom_target, bool close_dialogs = false);
- void update_content(const wchar_t * frame, const wchar_t * dom_target, bool has_postfix, long dom_target_postfix, bool close_dialogs = false);
- void update_content(const wchar_t * frame, const wchar_t * dom_target, long dom_target_postfix, bool close_dialogs = false);
- void update_content(const wchar_t * frame, const wchar_t * dom_target, bool close_dialogs = false);

while here:
- refactor PascalCase to snake_case in FunctionBase
- add start_request() and finish_request() methods to FunctionBase
- add has_*_access() methods to FunctionBase
- fix: FunctionBase::clear() method was not called if a request was assigned to a job
- add a WinixEzcHelper model
- allow to serialize a header if the header value is neither a string nor an integer
- refactor PascalCase to snake_case in functions: Emacs, Mkdir, Upload
This commit is contained in:
2024-06-27 10:57:08 +02:00
parent 6aa100f12c
commit c30b7db041
129 changed files with 4064 additions and 3199 deletions

View File

@@ -143,13 +143,13 @@ void Account::ActivateAccount()
void Account::MakePost()
void Account::make_post()
{
}
void Account::MakeGet()
void Account::make_get()
{
if( cur->request->IsParam(L"activate") )
ActivateAccount();

View File

@@ -51,8 +51,8 @@ public:
Account();
void MakeGet();
void MakePost();
void make_get();
void make_post();
bool ActivateAccount(const std::wstring & login, long code);

View File

@@ -258,7 +258,7 @@ return false;
}
void AddUser::MakePost()
void AddUser::make_post()
{
const std::wstring & login = cur->request->PostVar(L"login");
const std::wstring & pass = cur->request->PostVar(L"password");
@@ -289,7 +289,7 @@ void AddUser::MakePost()
}
void AddUser::MakeGet()
void AddUser::make_get()
{
}

View File

@@ -51,8 +51,8 @@ class AddUser : public FunctionBase
public:
AddUser();
void MakePost();
void MakeGet();
void make_post();
void make_get();
bool IsLoginCorrect(const std::wstring & login);
bool IsEmailCorrect(const std::wstring & email);

View File

@@ -49,7 +49,7 @@ Cat::Cat()
}
void Cat::MakeGet()
void Cat::make_get()
{
// IMPROVE ME this probably should be set for all winix functions
cur->request->html_template = cur->request->last_item->html_template;

View File

@@ -51,7 +51,7 @@ class Cat : public FunctionBase
public:
Cat();
void MakeGet();
void make_get();

View File

@@ -56,7 +56,7 @@ void Chmod::set_dependency(WinixRequest * winix_request)
priv_changer.set_dependency(winix_request);
}
void Chmod::MakePost()
void Chmod::make_post()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);
@@ -65,7 +65,7 @@ void Chmod::MakePost()
}
void Chmod::MakeGet()
void Chmod::make_get()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);

View File

@@ -51,8 +51,8 @@ class Chmod : public FunctionBase
public:
Chmod();
void MakePost();
void MakeGet();
void make_post();
void make_get();
void set_dependency(WinixRequest * winix_request);

View File

@@ -57,7 +57,7 @@ void Chown::set_dependency(WinixRequest * winix_request)
}
void Chown::MakePost()
void Chown::make_post()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);
@@ -66,7 +66,7 @@ void Chown::MakePost()
}
void Chown::MakeGet()
void Chown::make_get()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);

View File

@@ -51,8 +51,8 @@ class Chown : public FunctionBase
public:
Chown();
void MakePost();
void MakeGet();
void make_post();
void make_get();
void set_dependency(WinixRequest * winix_request);

View File

@@ -49,19 +49,19 @@ Ckeditor::Ckeditor()
fun.url = L"ckeditor";
}
void Ckeditor::Init()
void Ckeditor::init()
{
system->AddCommonFileToVar(L"winix/ckeditor_full.js", L"ckeditor_full.js");
system->AddCommonFileToVar(L"winix/ckeditor_winix.js", L"ckeditor_winix.js");
}
bool Ckeditor::HasAccess()
bool Ckeditor::has_access()
{
return functions->fun_emacs.HasAccess();
return functions->fun_emacs.has_access();
}
void Ckeditor::MakeGet()
void Ckeditor::make_get()
{
cur->session->last_css.clear();
int parcss = system->mounts.MountParCss();
@@ -71,9 +71,9 @@ void Ckeditor::MakeGet()
}
void Ckeditor::MakePost()
void Ckeditor::make_post()
{
functions->fun_emacs.MakePost();
functions->fun_emacs.make_post();
}

View File

@@ -50,10 +50,10 @@ class Ckeditor : public FunctionBase
public:
Ckeditor();
void Init();
bool HasAccess();
void MakeGet();
void MakePost();
void init();
bool has_access();
void make_get();
void make_post();
};

View File

@@ -53,7 +53,7 @@ Cp::Cp()
}
bool Cp::HasAccess()
bool Cp::has_access()
{
return CheckAccessFrom();
}
@@ -406,7 +406,7 @@ void Cp::PostCopyDir(const Item & dir, bool redirect)
}
void Cp::Clear()
void Cp::clear()
{
loop_checker.clear();
dir_tab.clear();
@@ -415,7 +415,7 @@ void Cp::Clear()
}
void Cp::MakePost()
void Cp::make_post()
{
if( ParseDir() && CheckAccessTo() )
{
@@ -437,7 +437,7 @@ void Cp::MakePost()
PostCopyDir(*cur->request->dir_tab.back());
}
Clear();
clear();
}
}

View File

@@ -51,8 +51,8 @@ class Cp : public FunctionBase
public:
Cp();
bool HasAccess();
void MakePost();
bool has_access();
void make_post();
private:
@@ -92,7 +92,7 @@ private:
void CopyDirContentTree(const Item & item, long dst_dir_id);
long CopyDirTree(const Item & item, long dst_dir_id);
bool IsTheSameFile(const Item & item);
void Clear();
void clear();
void PostCopyFile(Item & item, bool redirect = true);
void PostCopyDirContent(const Item & dir, bool redirect = true);
void PostCopyDir(const Item & dir, bool redirect = true);

View File

@@ -49,14 +49,14 @@ Default::Default()
}
bool Default::HasAccess()
bool Default::has_access()
{
return !cur->request->is_item && system->HasWriteAccess(*cur->request->dir_tab.back());
}
void Default::MakePost()
void Default::make_post()
{
Item & dir = *cur->request->dir_tab.back();
dir.propagate_connector();

View File

@@ -50,8 +50,8 @@ class Default : public FunctionBase
public:
Default();
bool HasAccess();
void MakePost();
bool has_access();
void make_post();
};

View File

@@ -52,7 +52,7 @@ Download::Download()
}
void Download::MakeGet()
void Download::make_get()
{
if( !cur->request->is_item )
{

View File

@@ -50,7 +50,7 @@ class Download : public FunctionBase
public:
Download();
void MakeGet();
void make_get();
private:

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2021, Tomasz Sowa
* Copyright (c) 2008-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -52,7 +52,7 @@ Emacs::Emacs()
bool Emacs::HasAccess(const Item & item)
bool Emacs::has_emacs_access(const Item & item)
{
if( cur->session->puser && cur->session->puser->is_super_user )
// super user can use emacs everywhere
@@ -72,9 +72,9 @@ return false;
bool Emacs::HasAccess()
bool Emacs::has_access()
{
return HasAccess(*cur->request->last_item);
return has_emacs_access(*cur->request->last_item);
}
@@ -106,9 +106,9 @@ return true;
*/
int Emacs::NotifyCodeEdit()
int Emacs::notify_code_edit()
{
// !! nie potrzebne
// !! not needed
// if( system->mounts.pmount->type == system->mounts.MountTypeThread() )
// return WINIX_NOTIFY_CODE_THREAD_POST_CHANGED;
@@ -118,9 +118,9 @@ return WINIX_NOTIFY_CODE_EDIT;
int Emacs::NotifyCodeAdd()
int Emacs::notify_code_add()
{
// !! nie potrzebne
// !! not needed
// if( system->mounts.pmount->type == system->mounts.MountTypeThread() )
// return WINIX_NOTIFY_CODE_THREAD_REPLAYED;
@@ -131,7 +131,7 @@ return WINIX_NOTIFY_CODE_ADD;
// IMPROVEME
// make some kind of utils and put this method there
// because this method is used from ckeditor and other editors too
void Emacs::MakePost()
void Emacs::make_post()
{
bool status = false;
bool adding = !cur->request->is_item;
@@ -150,7 +150,7 @@ void Emacs::MakePost()
if( adding )
{
cur->request->item.item_content.privileges = system->NewFilePrivileges();
status = system->AddFile(cur->request->item, NotifyCodeAdd());
status = system->AddFile(cur->request->item, notify_code_edit());
if( status )
{
@@ -159,7 +159,7 @@ void Emacs::MakePost()
}
else
{
status = system->EditFile(cur->request->item, cur->request->item.url != old_url, NotifyCodeEdit());
status = system->EditFile(cur->request->item, cur->request->item.url != old_url, notify_code_edit());
}
cur->request->status = status ? WINIX_ERR_OK : WINIX_ERR_PERMISSION_DENIED;
@@ -185,7 +185,7 @@ void Emacs::MakePost()
}
void Emacs::Clear()
void Emacs::clear()
{
answer.clear();
}

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2018, Tomasz Sowa
* Copyright (c) 2010-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -50,16 +50,16 @@ class Emacs : public FunctionBase
public:
Emacs();
bool HasAccess();
void MakePost();
bool has_access();
void make_post();
private:
bool HasAccess(const Item & item); // !! takie funkcje to nie powinny byc skladowe modelu?
void Clear();
bool has_emacs_access(const Item & item);
void clear();
int NotifyCodeEdit();
int NotifyCodeAdd();
int notify_code_edit();
int notify_code_add();
std::wstring old_url;
pt::Space answer;

View File

@@ -50,7 +50,7 @@ Env::Env()
}
bool Env::HasAccess()
bool Env::has_access()
{
if( !cur->session->puser )
return false;
@@ -168,7 +168,7 @@ void Env::RegisterModels()
void Env::MakePost()
void Env::make_post()
{
user_wrapper.user = nullptr;
user_wrapper.set_connector(model_connector);
@@ -205,7 +205,7 @@ void Env::MakePost()
}
void Env::MakeGet()
void Env::make_get()
{
user_wrapper.user = cur->session->puser;
user_wrapper.set_connector(model_connector);
@@ -214,7 +214,7 @@ void Env::MakeGet()
}
void Env::Clear()
void Env::clear()
{
user_wrapper.user = nullptr;
}

View File

@@ -54,10 +54,10 @@ public:
Env();
bool HasAccess();
void MakePost();
void MakeGet();
void Clear();
bool has_access();
void make_post();
void make_get();
void clear();
private:

View File

@@ -91,13 +91,13 @@ FunctionBase::~FunctionBase()
//}
void FunctionBase::SetFunctions(Functions * pfunctions)
void FunctionBase::set_functions(Functions * pfunctions)
{
functions = pfunctions;
}
void FunctionBase::SetTemplates(Templates * ptemplates)
void FunctionBase::set_templates(Templates * ptemplates)
{
templates = ptemplates;
}
@@ -115,44 +115,40 @@ void FunctionBase::SetTemplates(Templates * ptemplates)
//}
void FunctionBase::Init()
void FunctionBase::init()
{
// this method is called only once at the beginning
// when winix starts
Init();
}
void FunctionBase::Finish()
void FunctionBase::finish()
{
// this method is called only once at the end
// when winix finishes
Finish();
}
bool FunctionBase::HasAccess()
{
// true by default
return true;
}
/*
* this is in a response to the normal OPTIONS method (not cors request)
*/
void FunctionBase::AddAllowMethodsHeader()
void FunctionBase::add_allow_methods_header()
{
cur->request->out_headers.add(Header::allow, L"GET, HEAD, POST, PUT, DELETE, OPTIONS, PATCH");
}
bool FunctionBase::IsCorsMethodAvailable(Request::Method method)
bool FunctionBase::is_cors_method_available(Request::Method method)
{
return method == Request::get || method == Request::head || method == Request::post || method == Request::put ||
method == Request::delete_ ||method == Request::patch;
}
bool FunctionBase::IsOriginAvailable(const std::wstring & origin_url)
bool FunctionBase::is_origin_available(const std::wstring & origin_url)
{
if( config )
{
@@ -176,13 +172,13 @@ bool FunctionBase::IsOriginAvailable(const std::wstring & origin_url)
}
bool FunctionBase::AreCorsCredentialsAvailable()
bool FunctionBase::are_cors_credentials_available()
{
return config && config->access_control_allow_credentials;
}
bool FunctionBase::AreCorsHeadersAvailable(const std::wstring & headers)
bool FunctionBase::are_cors_headers_available(const std::wstring & headers)
{
// true by default for all headers
// headers are comma separated
@@ -193,7 +189,7 @@ bool FunctionBase::AreCorsHeadersAvailable(const std::wstring & headers)
/*
* method is the value of Access-Control-Request-Method header sent by the client
*/
void FunctionBase::AddAccessControlAllowMethodsHeader(Request::Method method)
void FunctionBase::add_access_control_allow_methods_header(Request::Method method)
{
cur->request->AddHeader(Header::access_control_allow_methods, L"GET, HEAD, POST, PUT, DELETE, OPTIONS, PATCH");
}
@@ -205,7 +201,7 @@ void FunctionBase::AddAccessControlAllowMethodsHeader(Request::Method method)
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin
*
*/
void FunctionBase::AddAccessControlAllowOriginHeader(const std::wstring & origin_url)
void FunctionBase::add_access_control_allow_origin_header(const std::wstring & origin_url)
{
if( config )
{
@@ -229,7 +225,7 @@ void FunctionBase::AddAccessControlAllowOriginHeader(const std::wstring & origin
/*
* headers is the value of Access-Control-Request-Headers header sent by the client
*/
void FunctionBase::AddAccessControlAllowHeadersHeader(const std::wstring & headers)
void FunctionBase::add_access_control_allow_headers_header(const std::wstring & headers)
{
if( Header::is_header_value_correct(headers) )
{
@@ -238,20 +234,20 @@ void FunctionBase::AddAccessControlAllowHeadersHeader(const std::wstring & heade
}
void FunctionBase::AddAccessControlMaxAgeHeader()
void FunctionBase::add_access_control_max_age_header()
{
// default 24 hours
cur->request->AddHeader(Header::access_control_max_age, 86400);
}
void FunctionBase::AddAccessControlAllowCredentialsHeader()
void FunctionBase::add_access_control_allow_credentials_header()
{
cur->request->AddHeader(Header::access_control_allow_credentials, L"true");
}
void FunctionBase::AddAccessControlExposeHeadersHeader()
void FunctionBase::add_access_control_expose_headers_header()
{
if( config )
{
@@ -275,45 +271,45 @@ void FunctionBase::AddAccessControlExposeHeadersHeader()
}
void FunctionBase::AddCorsPreflightRequestHeaders(const std::wstring & origin, Request::Method method, const std::wstring * request_headers)
void FunctionBase::add_cors_preflight_request_headers(const std::wstring & origin, Request::Method method, const std::wstring * request_headers)
{
AddAccessControlAllowMethodsHeader(method);
AddAccessControlAllowOriginHeader(origin);
AddAccessControlMaxAgeHeader();
AddAccessControlExposeHeadersHeader();
add_access_control_allow_methods_header(method);
add_access_control_allow_origin_header(origin);
add_access_control_max_age_header();
add_access_control_expose_headers_header();
if( AreCorsCredentialsAvailable() )
if( are_cors_credentials_available() )
{
AddAccessControlAllowCredentialsHeader();
add_access_control_allow_credentials_header();
}
if( request_headers )
{
AddAccessControlAllowHeadersHeader(*request_headers);
add_access_control_allow_headers_header(*request_headers);
}
log << log3 << "FunctionBase: this cors request is permitted" << logend;
}
void FunctionBase::AddCorsNormalRequestHeaders(const std::wstring & origin)
void FunctionBase::add_cors_normal_request_headers(const std::wstring & origin)
{
AddAccessControlAllowOriginHeader(origin);
AddAccessControlExposeHeadersHeader();
add_access_control_allow_origin_header(origin);
add_access_control_expose_headers_header();
if( AreCorsCredentialsAvailable() )
if( are_cors_credentials_available() )
{
AddAccessControlAllowCredentialsHeader();
add_access_control_allow_credentials_header();
}
}
void FunctionBase::CheckCorsPreflightRequest(const std::wstring & origin, const std::wstring & method_string)
void FunctionBase::check_cors_preflight_request(const std::wstring & origin, const std::wstring & method_string)
{
pt::Space * cors_headers = cur->request->headers_in.get_space_nc(L"Access_Control_Request_Headers");
Request::Method method = Request::CheckRequestMethod(method_string.c_str());
if( IsCorsMethodAvailable(method) )
if( is_cors_method_available(method) )
{
bool cors_headers_available = true;
std::wstring * headers = nullptr;
@@ -321,12 +317,12 @@ void FunctionBase::CheckCorsPreflightRequest(const std::wstring & origin, const
if( cors_headers && cors_headers->is_wstr() )
{
headers = cors_headers->get_wstr();
cors_headers_available = AreCorsHeadersAvailable(*headers);
cors_headers_available = are_cors_headers_available(*headers);
}
if( cors_headers_available )
{
AddCorsPreflightRequestHeaders(origin, method, headers);
add_cors_preflight_request_headers(origin, method, headers);
}
else
{
@@ -343,7 +339,7 @@ void FunctionBase::CheckCorsPreflightRequest(const std::wstring & origin, const
}
void FunctionBase::AddResponseHeadersForOrigin(const std::wstring & origin)
void FunctionBase::add_response_headers_for_origin(const std::wstring & origin)
{
if( cur->request->method == Request::Method::options )
{
@@ -360,7 +356,7 @@ void FunctionBase::AddResponseHeadersForOrigin(const std::wstring & origin)
if( config->are_cors_preflight_requests_available )
{
CheckCorsPreflightRequest(origin, *cors_method->get_wstr());
check_cors_preflight_request(origin, *cors_method->get_wstr());
}
else
{
@@ -372,26 +368,26 @@ void FunctionBase::AddResponseHeadersForOrigin(const std::wstring & origin)
/*
* this is not a preflight cors request
*/
AddAllowMethodsHeader();
AddCorsNormalRequestHeaders(origin);
add_allow_methods_header();
add_cors_normal_request_headers(origin);
}
}
else
{
AddCorsNormalRequestHeaders(origin);
add_cors_normal_request_headers(origin);
}
}
void FunctionBase::CheckOriginHeader()
void FunctionBase::check_origin_header()
{
pt::Space * origin = cur->request->headers_in.get_space_nc(L"Origin");
if( origin && origin->is_wstr() )
{
if( IsOriginAvailable(*origin->get_wstr()) )
if( is_origin_available(*origin->get_wstr()) )
{
AddResponseHeadersForOrigin(*origin->get_wstr());
add_response_headers_for_origin(*origin->get_wstr());
}
else
{
@@ -412,118 +408,598 @@ void FunctionBase::CheckOriginHeader()
{
if( cur->request->method == Request::Method::options )
{
AddAllowMethodsHeader();
add_allow_methods_header();
}
}
}
void FunctionBase::MakeGet()
bool FunctionBase::has_access()
{
// true by default
//return true;
return HasAccess(); /* for backward compatibility, will be removed */
}
bool FunctionBase::has_get_access()
{
return has_access();
}
bool FunctionBase::has_head_access()
{
return has_access();
}
bool FunctionBase::has_post_access()
{
return has_access();
}
bool FunctionBase::has_put_access()
{
return has_access();
}
bool FunctionBase::has_delete_access()
{
return has_access();
}
bool FunctionBase::has_connect_access()
{
return has_access();
}
bool FunctionBase::has_options_access()
{
return has_access();
}
bool FunctionBase::has_trace_access()
{
return has_access();
}
bool FunctionBase::has_patch_access()
{
return has_access();
}
void FunctionBase::start_request()
{
// do nothing by default
}
void FunctionBase::MakeHead()
void FunctionBase::make_get()
{
// by default call MakeGet() but we do not return any content at the end of the request
// do nothing by default
MakeGet();
}
void FunctionBase::MakePost()
void FunctionBase::make_head()
{
// by default call MakeGet() but we do not return any content at the end of the request
MakeHead();
}
void FunctionBase::make_post()
{
// do nothing by default
MakePost();
}
void FunctionBase::make_put()
{
// do nothing by default
MakePut();
}
void FunctionBase::make_delete()
{
// do nothing by default
MakeDelete();
}
void FunctionBase::make_connect()
{
// do nothing by default
MakeConnect();
}
void FunctionBase::make_options()
{
// do nothing by default
MakeOptions();
}
void FunctionBase::make_trace()
{
// do nothing by default
MakeTrace();
}
void FunctionBase::make_patch()
{
// do nothing by default
MakePatch();
}
void FunctionBase::finish_request()
{
// do nothing by default
}
void FunctionBase::MakePut()
void FunctionBase::clear()
{
// do nothing by default
}
winix_ezc_helper.set_connector(model_connector);
winix_ezc_helper.clear();
void FunctionBase::MakeDelete()
{
// do nothing by default
}
void FunctionBase::MakeConnect()
{
// do nothing by default
}
void FunctionBase::MakeOptions()
{
// do nothing by default
}
void FunctionBase::MakeTrace()
{
// do nothing by default
}
void FunctionBase::MakePatch()
{
// do nothing by default
}
void FunctionBase::Clear()
{
// do nothing by default
// for backward compatibility - will be removed
Clear();
}
void FunctionBase::ContinueMakeGet()
void FunctionBase::continue_make_get()
{
// do nothing by default
ContinueMakeGet();
}
void FunctionBase::ContinueMakeHead()
void FunctionBase::continue_make_head()
{
// do nothing by default
ContinueMakeHead();
}
void FunctionBase::ContinueMakePost()
void FunctionBase::continue_make_post()
{
// do nothing by default
ContinueMakePost();
}
void FunctionBase::ContinueMakePut()
void FunctionBase::continue_make_put()
{
// do nothing by default
ContinueMakePut();
}
void FunctionBase::ContinueMakeDelete()
void FunctionBase::continue_make_delete()
{
// do nothing by default
ContinueMakeDelete();
}
void FunctionBase::ContinueMakeConnect()
void FunctionBase::continue_make_connect()
{
// do nothing by default
ContinueMakeConnect();
}
void FunctionBase::ContinueMakeOptions()
void FunctionBase::continue_make_options()
{
// do nothing by default
ContinueMakeOptions();
}
void FunctionBase::ContinueMakeTrace()
void FunctionBase::continue_make_trace()
{
// do nothing by default
ContinueMakeTrace();
}
void FunctionBase::ContinueMakePatch()
void FunctionBase::continue_make_patch()
{
// do nothing by default
ContinueMakePatch();
}
bool FunctionBase::NeedToCopyRawPost()
bool FunctionBase::need_to_copy_raw_post()
{
return false;
}
bool FunctionBase::can_push_url_to_browser_history()
{
return true;
}
void FunctionBase::add_standard_models()
{
if( cur->request->use_ezc_engine )
{
cur->request->models.Add(L"winix_ezc_helper", winix_ezc_helper);
}
}
void FunctionBase::prepare_doc_url(const wchar_t * local_url, pt::WTextStream & url)
{
system->PutUrlProto(config->use_ssl, url, false);
if( !cur->request->subdomain.empty() )
{
url << cur->request->subdomain << '.';
}
url << config->base_url;
if( local_url )
{
url << local_url;
}
}
void FunctionBase::prepare_doc_url(const wchar_t * local_url, std::wstring & url)
{
pt::WTextStream stream;
prepare_doc_url(local_url, stream);
stream.to_str(url);
}
std::wstring FunctionBase::prepare_doc_url(const wchar_t * local_url)
{
std::wstring url;
prepare_doc_url(local_url, url);
return url;
}
std::wstring FunctionBase::prepare_doc_url(const std::wstring & local_url)
{
return prepare_doc_url(local_url.c_str());
}
void FunctionBase::redirect_to(const wchar_t * url, bool append_domain)
{
if( cur->request->is_htmx_request )
{
if( append_domain )
{
cur->request->out_headers.add(L"HX-Redirect", prepare_doc_url(url));
}
else
{
cur->request->out_headers.add(L"HX-Redirect", url);
}
}
else
{
if( append_domain )
{
prepare_doc_url(url, cur->request->redirect_to);
}
else
{
cur->request->redirect_to = url;
}
cur->request->redirect_type = Header::status_303_see_other;
}
}
void FunctionBase::redirect_to(const std::wstring & url, bool append_domain)
{
redirect_to(url.c_str(), append_domain);
}
void FunctionBase::redirect_to(const pt::WTextStream & url, bool append_domain)
{
std::wstring url_str;
url.to_str(url_str);
redirect_to(url_str, append_domain);
}
void FunctionBase::redirect_to(const wchar_t * url, const wchar_t * frame_url, const wchar_t * dom_target)
{
if( cur->request->is_htmx_request )
{
/*
* we do not use HX-Location because it will put the frame_url to the browser history
* and there is no an option to disable it or change the url
*/
pt::WTextStream full_url, full_frame_url, hx_trigger_value;
prepare_doc_url(url, full_url);
prepare_doc_url(frame_url, full_frame_url);
pt::Space & trigger = cur->request->out_headers.get_add_space(L"HX-Trigger");
pt::Space & redirect = trigger.get_add_space(L"winix:redirect");
redirect.add(L"path", full_frame_url);
redirect.add(L"target", dom_target);
log << log3 << "FunctionBase: redirecting to: " << frame_url << ", dom_target: " << dom_target << logend;
if( can_push_url_to_browser_history() )
{
cur->request->out_headers.add(L"HX-Push-Url", full_url);
log << log3 << "FunctionBase: pushing a new url to the browser history: " << full_url << logend;
}
}
else
{
prepare_doc_url(url, cur->request->redirect_to);
cur->request->redirect_type = Header::status_303_see_other;
}
}
void FunctionBase::redirect_to(const std::wstring & url, const std::wstring & frame_url, const std::wstring & dom_target)
{
redirect_to(url.c_str(), frame_url.c_str(), dom_target.c_str());
}
void FunctionBase::redirect_to(pt::WTextStream & url, pt::WTextStream & frame_url, pt::WTextStream & dom_target)
{
std::wstring url_str, frame_url_str, dom_target_str;
url.to_str(url_str);
frame_url.to_str(frame_url_str);
dom_target.to_str(dom_target_str);
redirect_to(url_str, frame_url_str, dom_target_str);
}
void FunctionBase::redirect_to(pt::WTextStream & url, pt::WTextStream & frame_url, const wchar_t * dom_target)
{
std::wstring url_str, frame_url_str;
url.to_str(url_str);
frame_url.to_str(frame_url_str);
redirect_to(url_str.c_str(), frame_url_str.c_str(), dom_target);
}
void FunctionBase::redirect_to(const wchar_t * url, const wchar_t * frame_url, pt::WTextStream & dom_target)
{
std::wstring dom_target_str;
dom_target.to_str(dom_target_str);
redirect_to(url, frame_url, dom_target_str.c_str());
}
void FunctionBase::retarged(const wchar_t * frame, const wchar_t * dom_target, const wchar_t * push_url, const wchar_t * swap_algorithm)
{
pt::WTextStream log_msg;
if( frame && (*frame) )
{
cur->request->send_frames.clear();
cur->request->send_frames.push_back(frame);
log_msg << ", frame: " << frame;
}
if( dom_target && (*dom_target) )
{
cur->request->out_headers.add(L"HX-Retarget", dom_target);
log_msg << ", container: " << dom_target;
}
if( push_url && can_push_url_to_browser_history() )
{
std::wstring url = prepare_doc_url(push_url);
cur->request->out_headers.add(L"HX-Push-Url", url);
log << log3 << "FunctionBase: pushing a new url to the browser history: " << url << logend;
}
if( swap_algorithm && (*swap_algorithm) )
{
cur->request->out_headers.add(L"HX-Reswap", swap_algorithm);
}
log << log3 << "FunctionBase: changing the targed" << log_msg << logend;
}
void FunctionBase::retarged(const std::wstring & frame, const std::wstring & dom_target, const std::wstring & push_url, const wchar_t * swap_algorithm)
{
retarged(frame.c_str(), dom_target.c_str(), push_url.c_str(), swap_algorithm);
}
void FunctionBase::retarged(const wchar_t * frame, pt::WTextStream & dom_target, const wchar_t * push_url, const wchar_t * swap_algorithm)
{
std::wstring dom_target_str;
dom_target.to_str(dom_target_str);
retarged(frame, dom_target_str.c_str(), push_url, swap_algorithm);
}
void FunctionBase::remove_content(pt::WTextStream & dom_target, bool close_dialogs)
{
pt::Space & trigger = cur->request->out_headers.get_add_space(L"HX-Trigger");
pt::Space & remove_content = trigger.get_add_space(L"winix:removecontent");
pt::Space & rm = remove_content.get_add_space(L"rm");
rm.add(dom_target);
if( close_dialogs )
{
close_modal_dialogs();
}
/*
* CHECKME may we do not need to use the ezc engine at all?
*/
cur->request->send_frames.clear();
}
void FunctionBase::remove_content(const wchar_t * dom_target, bool has_postfix, long dom_target_postfix, bool close_dialogs)
{
pt::WTextStream target;
target << dom_target;
if( has_postfix )
target << dom_target_postfix;
remove_content(target, close_dialogs);
}
void FunctionBase::remove_content(const wchar_t * dom_target, long dom_target_postfix, bool close_dialogs)
{
remove_content(dom_target, true, dom_target_postfix, close_dialogs);
}
void FunctionBase::remove_content(const wchar_t * dom_target, bool close_dialogs)
{
remove_content(dom_target, false, 0, close_dialogs);
}
void FunctionBase::update_content(const wchar_t * frame, pt::WTextStream & dom_target, bool close_dialogs)
{
if( close_dialogs )
{
close_modal_dialogs();
}
retarged(frame, dom_target);
}
void FunctionBase::update_content(const wchar_t * frame, const wchar_t * dom_target, bool has_postfix, long dom_target_postfix, bool close_dialogs)
{
pt::WTextStream target;
target << dom_target;
if( has_postfix )
target << dom_target_postfix;
update_content(frame, target, close_dialogs);
}
void FunctionBase::update_content(const wchar_t * frame, const wchar_t * dom_target, long dom_target_postfix, bool close_dialogs)
{
update_content(frame, dom_target, true, dom_target_postfix, close_dialogs);
}
void FunctionBase::update_content(const wchar_t * frame, const wchar_t * dom_target, bool close_dialogs)
{
update_content(frame, dom_target, false, 0, close_dialogs);
}
void FunctionBase::close_modal_dialogs()
{
pt::Space & trigger = cur->request->out_headers.get_add_space(L"HX-Trigger");
trigger.add(L"winix:closedialogs", true);
}
/*
* DEPRACATED
* for backward compatibility
*/
void FunctionBase::Init()
{
}
void FunctionBase::Finish()
{
}
bool FunctionBase::HasAccess()
{
return true;
}
void FunctionBase::Clear()
{
}
void FunctionBase::MakeGet()
{
}
void FunctionBase::MakeHead()
{
make_get();
}
void FunctionBase::MakePost()
{
}
void FunctionBase::MakePut()
{
}
void FunctionBase::MakeDelete()
{
}
void FunctionBase::MakeConnect()
{
}
void FunctionBase::MakeOptions()
{
}
void FunctionBase::MakeTrace()
{
}
void FunctionBase::MakePatch()
{
}
void FunctionBase::ContinueMakeGet()
{
}
void FunctionBase::ContinueMakeHead()
{
}
void FunctionBase::ContinueMakePost()
{
}
void FunctionBase::ContinueMakePut()
{
}
void FunctionBase::ContinueMakeDelete()
{
}
void FunctionBase::ContinueMakeConnect()
{
}
void FunctionBase::ContinueMakeOptions()
{
}
void FunctionBase::ContinueMakeTrace()
{
}
void FunctionBase::ContinueMakePatch()
{
}
} // namespace Winix

View File

@@ -36,20 +36,15 @@
#define headerfile_winix_functions_functionbase
#include <string>
#include <vector>
#include "core/request.h"
#include "core/config.h"
#include "core/synchro.h"
#include "notify/notify.h"
#include "core/winixrequest.h"
#include "models/helpers/winixezchelper.h"
#include "models/item.h"
#include "notify/notify.h"
namespace Winix
{
class Functions;
class Templates;
@@ -105,30 +100,126 @@ public:
size_t post_max_nested_objects;
void set_functions(Functions * pfunctions);
void set_templates(Templates * ptemplates);
virtual void init();
virtual void finish();
virtual void add_allow_methods_header();
virtual bool is_cors_method_available(Request::Method method);
virtual bool is_origin_available(const std::wstring & origin_url);
virtual bool are_cors_credentials_available();
virtual bool are_cors_headers_available(const std::wstring & headers);
virtual void add_access_control_allow_methods_header(Request::Method method);
virtual void add_access_control_allow_origin_header(const std::wstring & origin_url);
virtual void add_access_control_allow_headers_header(const std::wstring & headers);
virtual void add_access_control_max_age_header();
virtual void add_access_control_allow_credentials_header();
virtual void add_access_control_expose_headers_header();
virtual void add_cors_preflight_request_headers(const std::wstring & origin, Request::Method method, const std::wstring * request_headers);
virtual void add_cors_normal_request_headers(const std::wstring & origin);
virtual void check_cors_preflight_request(const std::wstring & origin, const std::wstring & method_string);
virtual void add_response_headers_for_origin(const std::wstring & origin);
virtual void check_origin_header();
/*
* - at the beginning call one of has_*_access() depending on the http method
* by default all of them call has_access()
* - next call start_request()
* - call one of make_*() methods
* - if the request is assigned to a job then call clear() and one of continue_make_*() methods
* this call is made from a job thread (with locking mechanism)
* - if the request is still assigned to a job then call clear() and continue_make_*() again
* (this can create a loop of clear() and continue_make_*() calls)
* - if the request is not assigned to a job_request then call finish_request() and clear()
*
*/
virtual bool has_access();
virtual bool has_get_access();
virtual bool has_head_access();
virtual bool has_post_access();
virtual bool has_put_access();
virtual bool has_delete_access();
virtual bool has_connect_access();
virtual bool has_options_access();
virtual bool has_trace_access();
virtual bool has_patch_access();
virtual void start_request();
virtual void make_get();
virtual void make_head();
virtual void make_post();
virtual void make_put();
virtual void make_delete();
virtual void make_connect();
virtual void make_options();
virtual void make_trace();
virtual void make_patch();
virtual void finish_request();
virtual void clear();
/*
* continue_make_* methods are called from the jobs thread
* objects are locked
*/
virtual void continue_make_get();
virtual void continue_make_head();
virtual void continue_make_post();
virtual void continue_make_put();
virtual void continue_make_delete();
virtual void continue_make_connect();
virtual void continue_make_options();
virtual void continue_make_trace();
virtual void continue_make_patch();
virtual bool need_to_copy_raw_post();
virtual bool can_push_url_to_browser_history();
virtual void add_standard_models();
virtual void prepare_doc_url(const wchar_t * local_url, pt::WTextStream & url);
virtual void prepare_doc_url(const wchar_t * local_url, std::wstring & url);
virtual std::wstring prepare_doc_url(const wchar_t * local_url = nullptr);
virtual std::wstring prepare_doc_url(const std::wstring & local_url);
virtual void redirect_to(const wchar_t * url, bool append_domain = true);
virtual void redirect_to(const std::wstring & url, bool append_domain = true);
virtual void redirect_to(const pt::WTextStream & url, bool append_domain = true);
virtual void redirect_to(const wchar_t * url, const wchar_t * frame_url, const wchar_t * dom_target);
virtual void redirect_to(const std::wstring & url, const std::wstring & frame_url, const std::wstring & dom_target);
virtual void redirect_to(pt::WTextStream & url, pt::WTextStream & frame_url, pt::WTextStream & dom_target);
virtual void redirect_to(pt::WTextStream & url, pt::WTextStream & frame_url, const wchar_t * dom_target);
virtual void redirect_to(const wchar_t * url, const wchar_t * frame_url, pt::WTextStream & dom_target);
virtual void retarged(const wchar_t * frame, const wchar_t * dom_target, const wchar_t * push_url = nullptr, const wchar_t * swap_algorithm = nullptr);
virtual void retarged(const std::wstring & frame, const std::wstring & dom_target, const std::wstring & push_url, const wchar_t * swap_algorithm = nullptr);
virtual void retarged(const wchar_t * frame, pt::WTextStream & dom_target, const wchar_t * push_url = nullptr, const wchar_t * swap_algorithm = nullptr);
virtual void remove_content(pt::WTextStream & dom_target, bool close_dialogs = false);
virtual void remove_content(const wchar_t * dom_target, bool has_postfix, long dom_target_postfix, bool close_dialogs = false);
virtual void remove_content(const wchar_t * dom_target, long dom_target_postfix, bool close_dialogs = false);
virtual void remove_content(const wchar_t * dom_target, bool close_dialogs = false);
virtual void update_content(const wchar_t * frame, pt::WTextStream & dom_target, bool close_dialogs = false);
virtual void update_content(const wchar_t * frame, const wchar_t * dom_target, bool has_postfix, long dom_target_postfix, bool close_dialogs = false);
virtual void update_content(const wchar_t * frame, const wchar_t * dom_target, long dom_target_postfix, bool close_dialogs = false);
virtual void update_content(const wchar_t * frame, const wchar_t * dom_target, bool close_dialogs = false);
virtual void close_modal_dialogs();
/*
* DEPRECATED
* for backward compatibility
*/
virtual void Init();
virtual void Finish();
virtual bool HasAccess();
virtual void AddAllowMethodsHeader();
virtual bool IsCorsMethodAvailable(Request::Method method);
virtual bool IsOriginAvailable(const std::wstring & origin_url);
virtual bool AreCorsCredentialsAvailable();
virtual bool AreCorsHeadersAvailable(const std::wstring & headers);
virtual void AddAccessControlAllowMethodsHeader(Request::Method method);
virtual void AddAccessControlAllowOriginHeader(const std::wstring & origin_url);
virtual void AddAccessControlAllowHeadersHeader(const std::wstring & headers);
virtual void AddAccessControlMaxAgeHeader();
virtual void AddAccessControlAllowCredentialsHeader();
virtual void AddAccessControlExposeHeadersHeader();
virtual void AddCorsPreflightRequestHeaders(const std::wstring & origin, Request::Method method, const std::wstring * request_headers);
virtual void AddCorsNormalRequestHeaders(const std::wstring & origin);
virtual void CheckCorsPreflightRequest(const std::wstring & origin, const std::wstring & method_string);
virtual void AddResponseHeadersForOrigin(const std::wstring & origin);
virtual void CheckOriginHeader();
virtual void Clear();
virtual void MakeGet();
virtual void MakeHead();
@@ -140,12 +231,6 @@ public:
virtual void MakeTrace();
virtual void MakePatch();
virtual void Clear();
/*
* called from the jobs thread
* objects are locked
*/
virtual void ContinueMakeGet();
virtual void ContinueMakeHead();
virtual void ContinueMakePost();
@@ -157,24 +242,13 @@ public:
virtual void ContinueMakePatch();
//void SetConfig(Config * pconfig);
//void SetCur(Cur * pcur);
//void SetSystem(System * psystem);
void SetFunctions(Functions * pfunctions);
void SetTemplates(Templates * ptemplates);
//void SetSynchro(Synchro * psynchro);
//void SetSessionManager(SessionManager * pmanager);
virtual bool NeedToCopyRawPost();
protected:
//Config * config;
//System * system;
Functions * functions;
Templates * templates;
//Synchro * synchro;
//SessionManager * session_manager;
WinixEzcHelper winix_ezc_helper;
};

View File

@@ -184,8 +184,8 @@ void Functions::SetObjects(FunctionBase * fun)
//fun->SetConfig(config);
//fun->SetCur(cur);
//fun->SetSystem(system);
fun->SetFunctions(this);
fun->SetTemplates(templates);
fun->set_functions(this);
fun->set_templates(templates);
//fun->SetSynchro(synchro);
//fun->SetSessionManager(session_manager);
}
@@ -288,7 +288,7 @@ void Functions::InitFunctions()
Table::iterator i = table.begin();
for( ; i!=table.end() ; ++i)
i->second->Init();
i->second->init();
}
@@ -297,7 +297,7 @@ void Functions::FinishFunctions()
Table::iterator i = table.begin();
for( ; i!=table.end() ; ++i)
i->second->Finish();
i->second->finish();
}
@@ -449,19 +449,181 @@ bool was_default_function = false;
}
bool Functions::HasAccessToCallMake()
{
bool has_access = false;
if( cur->request->method == Request::get )
{
has_access = cur->request->function->has_get_access();
}
else
if( cur->request->method == Request::head )
{
has_access = cur->request->function->has_head_access();
}
else
if( cur->request->method == Request::post )
{
has_access = cur->request->function->has_post_access();
}
else
if( cur->request->method == Request::put )
{
has_access = cur->request->function->has_put_access();
}
else
if( cur->request->method == Request::delete_ )
{
has_access = cur->request->function->has_delete_access();
}
else
if( cur->request->method == Request::connect )
{
has_access = cur->request->function->has_connect_access();
}
else
if( cur->request->method == Request::options )
{
has_access = cur->request->function->has_options_access();
}
else
if( cur->request->method == Request::trace )
{
has_access = cur->request->function->has_trace_access();
}
else
if( cur->request->method == Request::patch )
{
has_access = cur->request->function->has_patch_access();
}
else
{
log << log2 << "Functions: I cannot call a function, an unknown request method (skipping)" << logend;
}
return has_access;
}
void Functions::CallFunctionMake()
{
if( cur->request->method == Request::get )
{
cur->request->function->make_get();
}
else
if( cur->request->method == Request::head )
{
cur->request->function->make_head();
}
else
if( cur->request->method == Request::post )
{
cur->request->function->make_post();
}
else
if( cur->request->method == Request::put )
{
cur->request->function->make_put();
}
else
if( cur->request->method == Request::delete_ )
{
cur->request->function->make_delete();
}
else
if( cur->request->method == Request::connect )
{
cur->request->function->make_connect();
}
else
if( cur->request->method == Request::options )
{
cur->request->function->make_options();
}
else
if( cur->request->method == Request::trace )
{
cur->request->function->make_trace();
}
else
if( cur->request->method == Request::patch )
{
cur->request->function->make_patch();
}
else
{
log << log2 << "Functions: I cannot call a function, an unknown request method (skipping)" << logend;
}
}
void Functions::CallFunctionContinueMake()
{
if( cur->request->method == Request::get )
{
cur->request->function->continue_make_get();
}
else
if( cur->request->method == Request::head )
{
cur->request->function->continue_make_head();
}
else
if( cur->request->method == Request::post )
{
cur->request->function->continue_make_post();
}
else
if( cur->request->method == Request::put )
{
cur->request->function->continue_make_put();
}
else
if( cur->request->method == Request::delete_ )
{
cur->request->function->continue_make_delete();
}
else
if( cur->request->method == Request::connect )
{
cur->request->function->continue_make_connect();
}
else
if( cur->request->method == Request::options )
{
cur->request->function->continue_make_options();
}
else
if( cur->request->method == Request::trace )
{
cur->request->function->continue_make_trace();
}
else
if( cur->request->method == Request::patch )
{
cur->request->function->continue_make_patch();
}
else
{
log << log2 << "Functions: I cannot continue a request, an unknown request method (skipping)" << logend;
}
}
void Functions::MakeFunction()
{
if( !cur->request->function )
{
cur->request->http_status = Header::status_500_internal_server_error; // or 404? (404 was originally)
log << log1 << "Functions: no function to call" << logend;
log << log2 << "Functions: no function to call" << logend;
return;
}
if( !system->DirsHaveReadExecPerm() ||
!system->HasReadExecAccess(cur->request->function->fun) ||
!cur->request->function->HasAccess() )
!HasAccessToCallMake() )
{
cur->request->http_status = Header::status_403_forbidden;
return;
@@ -473,54 +635,11 @@ void Functions::MakeFunction()
return;
}
if( cur->request->method == Request::get )
{
cur->request->function->MakeGet();
}
else
if( cur->request->method == Request::head )
{
cur->request->function->MakeHead();
}
else
if( cur->request->method == Request::post )
{
cur->request->function->MakePost();
}
else
if( cur->request->method == Request::put )
{
cur->request->function->MakePut();
}
else
if( cur->request->method == Request::delete_ )
{
cur->request->function->MakeDelete();
}
else
if( cur->request->method == Request::connect )
{
cur->request->function->MakeConnect();
}
else
if( cur->request->method == Request::options )
{
cur->request->function->MakeOptions();
}
else
if( cur->request->method == Request::trace )
{
cur->request->function->MakeTrace();
}
else
if( cur->request->method == Request::patch )
{
cur->request->function->MakePatch();
}
else
{
log << log1 << "Functions: I cannot call a function, an unknown request method (skipping)" << logend;
}
cur->request->function->start_request();
CallFunctionMake();
if( cur->request->run_state != Request::RunState::assigned_to_job )
cur->request->function->finish_request();
}
@@ -535,7 +654,7 @@ void Functions::ContinueMakeFunction()
if( !system->DirsHaveReadExecPerm() ||
!system->HasReadExecAccess(cur->request->function->fun) ||
!cur->request->function->HasAccess() )
!HasAccessToCallMake() )
{
cur->request->http_status = Header::status_403_forbidden;
return;
@@ -545,54 +664,10 @@ void Functions::ContinueMakeFunction()
cur->request->PutMethodName(log);
log << " for request " << cur->request << " for function " << cur->request->function->fun.url << logend;
if( cur->request->method == Request::get )
{
cur->request->function->ContinueMakeGet();
}
else
if( cur->request->method == Request::head )
{
cur->request->function->ContinueMakeHead();
}
else
if( cur->request->method == Request::post )
{
cur->request->function->ContinueMakePost();
}
else
if( cur->request->method == Request::put )
{
cur->request->function->ContinueMakePut();
}
else
if( cur->request->method == Request::delete_ )
{
cur->request->function->ContinueMakeDelete();
}
else
if( cur->request->method == Request::connect )
{
cur->request->function->ContinueMakeConnect();
}
else
if( cur->request->method == Request::options )
{
cur->request->function->ContinueMakeOptions();
}
else
if( cur->request->method == Request::trace )
{
cur->request->function->ContinueMakeTrace();
}
else
if( cur->request->method == Request::patch )
{
cur->request->function->ContinueMakePatch();
}
else
{
log << log1 << "Functions: I cannot continue a request, an unknown request method (skipping)" << logend;
}
CallFunctionContinueMake();
if( cur->request->run_state != Request::RunState::assigned_to_job )
cur->request->function->finish_request();
}

View File

@@ -231,6 +231,11 @@ private:
void CheckFunctionFollowSymlink(bool was_default_function);
bool CheckAntispamCounter();
bool HasAccessToCallMake();
void CallFunctionMake();
void CallFunctionContinueMake();
};

View File

@@ -53,7 +53,7 @@ ImgCrop::ImgCrop()
bool ImgCrop::HasAccess()
bool ImgCrop::has_access()
{
if( cur->request->is_item )
return system->HasWriteAccess(cur->request->item);
@@ -88,7 +88,7 @@ void ImgCrop::GetDirContent()
void ImgCrop::MakePost()
void ImgCrop::make_post()
{
int xoffset = int(Tod(cur->request->PostVar(L"cropxtop")) + 0.5);
int yoffset = int(Tod(cur->request->PostVar(L"cropytop")) + 0.5);
@@ -136,7 +136,7 @@ void ImgCrop::MakePost()
}
void ImgCrop::MakeGet()
void ImgCrop::make_get()
{
if( !cur->request->is_item )
{

View File

@@ -51,9 +51,9 @@ public:
ImgCrop();
bool HasAccess();
void MakeGet();
void MakePost();
bool has_access();
void make_get();
void make_post();
// IMPROVEME add method Clear() or ClearAfterRequest()? and clear item_tab

View File

@@ -56,21 +56,21 @@ IPBanFun::IPBanFun()
bool IPBanFun::HasAccess()
bool IPBanFun::has_access()
{
return cur->session->puser && cur->session->puser->is_super_user;
}
void IPBanFun::MakePost()
void IPBanFun::make_post()
{
}
void IPBanFun::MakeGet()
void IPBanFun::make_get()
{
char tmp_ip_str[100];
size_t tmp_ip_len = sizeof(tmp_ip_str) / sizeof(char);

View File

@@ -51,9 +51,9 @@ public:
IPBanFun();
bool HasAccess();
void MakePost();
void MakeGet();
bool has_access();
void make_post();
void make_get();
private:

View File

@@ -49,7 +49,7 @@ Last::Last()
}
bool Last::HasAccess()
bool Last::has_access()
{
return cur->session->puser != 0;
}

View File

@@ -50,7 +50,7 @@ class Last : public FunctionBase
public:
Last();
bool HasAccess();
bool has_access();
private:

View File

@@ -53,7 +53,7 @@ Ln::Ln()
bool Ln::HasAccess()
bool Ln::has_access()
{
return system->HasWriteAccess(*cur->request->dir_tab.back());
}
@@ -153,7 +153,7 @@ void Ln::CreateHardLink(const std::wstring & link_to)
// we do not use notifications for links
void Ln::MakePost()
void Ln::make_post()
{
link_to = cur->request->PostVar(L"linkto");
TrimWhite(link_to);

View File

@@ -50,8 +50,8 @@ class Ln : public FunctionBase
public:
Ln();
bool HasAccess();
void MakePost();
bool has_access();
void make_post();
bool CreateSymbolicLink(long parent_id, const wchar_t * link_to, const wchar_t * url, bool link_redirect = true);
bool CreateSymbolicLink(long parent_id, const std::wstring & link_to, const std::wstring & url, bool link_redirect = true);

View File

@@ -51,14 +51,14 @@ Locale::Locale()
bool Locale::HasAccess()
bool Locale::has_access()
{
return cur->session->puser != 0;
}
void Locale::MakePost()
void Locale::make_post()
{
if( cur->session->puser )
{
@@ -79,7 +79,7 @@ void Locale::MakePost()
void Locale::MakeGet()
void Locale::make_get()
{
}

View File

@@ -50,9 +50,9 @@ class Locale : public FunctionBase
public:
Locale();
bool HasAccess();
void MakePost();
void MakeGet();
bool has_access();
void make_post();
void make_get();
private:

View File

@@ -321,7 +321,7 @@ return false;
}
void Login::MakePost()
void Login::make_post()
{
const std::wstring & login = cur->request->PostVar(L"login");
const std::wstring & pass = cur->request->PostVar(L"password");
@@ -332,7 +332,7 @@ void Login::MakePost()
}
void Login::MakeGet()
void Login::make_get()
{
}

View File

@@ -59,8 +59,8 @@ public:
Login();
void MakePost();
void MakeGet();
void make_post();
void make_get();
bool ShouldUseCaptchaForCurrentIP();
bool ShouldUseCaptchaFor(const IPBan & ipban);

View File

@@ -52,7 +52,7 @@ Logout::Logout()
void Logout::MakeGet()
void Logout::make_get()
{
if( cur->session->puser )
{

View File

@@ -50,7 +50,7 @@ class Logout : public FunctionBase
public:
Logout();
void MakeGet();
void make_get();
private:

View File

@@ -86,7 +86,7 @@ void Ls::prepare_dirs()
}
void Ls::MakeGet()
void Ls::make_get()
{
// !! IMPROVE ME
// this should be moved to ckeditor function (similarly the html content from fun_ls.html)
@@ -107,7 +107,7 @@ void Ls::MakeGet()
void Ls::Clear()
void Ls::clear()
{
item_tab.clear();
dir_tab.clear();

View File

@@ -50,8 +50,8 @@ class Ls : public FunctionBase
public:
Ls();
void MakeGet();
void Clear();
void make_get();
void clear();
private:

View File

@@ -50,7 +50,7 @@ Meta::Meta()
}
bool Meta::HasAccess()
bool Meta::has_access()
{
if( cur->request->IsParam(L"a") )
return cur->session->puser && cur->session->puser->is_super_user;
@@ -161,7 +161,7 @@ void Meta::ChangeMeta()
void Meta::MakePost()
void Meta::make_post()
{
if( cur->request->IsParam(L"a") )
ChangeAdminMeta();

View File

@@ -52,8 +52,8 @@ public:
Meta();
bool HasAccess();
void MakePost();
bool has_access();
void make_post();
bool EditAdminMeta(Item & item, const std::wstring & meta_str);
bool EditMeta(Item & item, const std::wstring & meta_str);

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2021, Tomasz Sowa
* Copyright (c) 2008-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,12 +36,10 @@
#include "functions.h"
namespace Winix
{
namespace Fun
{
@@ -51,10 +49,7 @@ Mkdir::Mkdir()
}
bool Mkdir::HasAccess(const Item & item)
bool Mkdir::has_mkdir_access(const Item & item)
{
// you can create a directory only in a directory
if( item.type != Item::dir )
@@ -73,22 +68,20 @@ bool Mkdir::HasAccess(const Item & item)
if( system->mounts.pmount->IsArg(system->mounts.MountParMkdirOn(), cur->request->dir_tab.size()) )
return true;
return false;
return false;
}
bool Mkdir::HasAccess()
bool Mkdir::has_access()
{
if( cur->request->is_item || !HasAccess(*cur->request->dir_tab.back()) )
if( cur->request->is_item || !has_mkdir_access(*cur->request->dir_tab.back()) )
return false;
return true;
return true;
}
void Mkdir::PostFunMkdir(bool add_to_dir_tab, int privileges)
void Mkdir::post_fun_mkdir(bool add_to_dir_tab, int privileges)
{
cur->request->item.set_connector(model_connector);
functions->ReadItem(cur->request->item, Item::dir);
@@ -110,18 +103,13 @@ void Mkdir::PostFunMkdir(bool add_to_dir_tab, int privileges)
}
void Mkdir::MakePost()
void Mkdir::make_post()
{
PostFunMkdir(false, system->NewDirPrivileges());
post_fun_mkdir(false, system->NewDirPrivileges());
}
} // namespace
} // namespace Winix

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2014, Tomasz Sowa
* Copyright (c) 2010-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -39,8 +39,6 @@
namespace Winix
{
namespace Fun
{
@@ -50,19 +48,17 @@ class Mkdir : public FunctionBase
public:
Mkdir();
bool HasAccess();
void MakePost();
bool has_access();
void make_post();
private:
bool HasAccess(const Item & item); // !! moze to powinien byc skladnik modelu?
bool FunMkdirCheckAccess();
void PostFunMkdir(bool add_to_dir_tab, int privileges);
bool has_mkdir_access(const Item & item);
void post_fun_mkdir(bool add_to_dir_tab, int privileges);
};
} // namespace
} // namespace Winix
#endif

View File

@@ -51,7 +51,7 @@ Mount::Mount()
}
bool Mount::HasAccess()
bool Mount::has_access()
{
if( cur->session->puser && cur->session->puser->is_super_user )
return true;
@@ -60,7 +60,7 @@ return false;
}
void Mount::MakeGet()
void Mount::make_get()
{
}

View File

@@ -50,8 +50,8 @@ class Mount : public FunctionBase
public:
Mount();
bool HasAccess();
void MakeGet();
bool has_access();
void make_get();
};

View File

@@ -59,7 +59,7 @@ Mv::Mv()
// check if everywhere correct messages are sent (prepare_to, modified item/dir)
bool Mv::HasAccess()
bool Mv::has_access()
{
if( cur->request->is_item )
{
@@ -140,7 +140,7 @@ void Mv::Prepare()
void Mv::Clear()
void Mv::clear()
{
out_dir_tab.clear();
out_item.Clear();
@@ -422,7 +422,7 @@ return false;
bool Mv::MoveDir(Item & src_dir, long dst_dir_id, const std::wstring & new_url, bool check_access)
{
bool res = MoveDir2(src_dir, dst_dir_id, new_url, check_access);
Clear();
clear();
return res;
}
@@ -469,7 +469,7 @@ bool Mv::MoveDir2(Item & src_dir, long dst_dir_id, const std::wstring & new_url,
bool Mv::MoveDir(Item & src_dir, const std::wstring & dst_path, bool check_access)
{
bool res = MoveDir2(src_dir, dst_path, check_access);
Clear();
clear();
return res;
}
@@ -560,7 +560,7 @@ return false;
bool Mv::MoveFileOrSymlink(Item & src_file, long dst_dir_id, const std::wstring & new_url, bool check_access)
{
bool res = MoveFileOrSymlink2(src_file, dst_dir_id, new_url, check_access);
Clear();
clear();
return res;
}
@@ -595,7 +595,7 @@ bool Mv::MoveFileOrSymlink2(Item & src_file, long dst_dir_id, const std::wstring
bool Mv::MoveFileOrSymlink(Item & src_file, const std::wstring & dst_path, bool check_access)
{
bool res = MoveFileOrSymlink2(src_file, dst_path, check_access);
Clear();
clear();
return res;
}
@@ -672,7 +672,7 @@ void Mv::MoveAllFilesFromDir(Item & src_dir, std::vector<Item*> & dst_dir_tab, b
void Mv::MoveDirContent(Item & src_dir, long dst_dir_id, bool check_access)
{
MoveDirContent2(src_dir, dst_dir_id, check_access);
Clear();
clear();
}
@@ -709,7 +709,7 @@ void Mv::MoveDirContent2(Item & src_dir, long dst_dir_id, bool check_access)
void Mv::MoveDirContent(Item & src_dir, const std::wstring & dst_dir, bool check_access)
{
MoveDirContent2(src_dir, dst_dir, check_access);
Clear();
clear();
}
@@ -732,7 +732,7 @@ void Mv::MoveDirContent2(Item & src_dir, const std::wstring & dst_dir, bool chec
void Mv::MakePost()
void Mv::make_post()
{
const std::wstring & dst_path = cur->request->PostVar(L"dst_path");
bool ok = true;

View File

@@ -52,8 +52,8 @@ class Mv : public FunctionBase
public:
Mv();
bool HasAccess();
void MakePost();
bool has_access();
void make_post();
// moving a directory
// new_url can be empty (in such a case the old one is preserved)
@@ -114,7 +114,7 @@ private:
void MoveFilesTree(const Item & dir);
bool MoveDir(Item & src_dir, std::vector<Item*> & dst_dir_tab, const std::wstring & dst_name);
bool MoveFileOrSymlink(Item & src_file, std::vector<Item*> & dst_dir_tab, const std::wstring & new_url);
void Clear();
void clear();
bool MoveDir2(Item & src_dir, long dst_dir_id, const std::wstring & new_url, bool check_access);
bool MoveDir2(Item & src_dir, const std::wstring & dst_path, bool check_access);
bool MoveFileOrSymlink2(Item & src_file, long dst_dir_id, const std::wstring & new_url, bool check_access);

View File

@@ -50,15 +50,15 @@ Nicedit::Nicedit()
}
bool Nicedit::HasAccess()
bool Nicedit::has_access()
{
return functions->fun_emacs.HasAccess();
return functions->fun_emacs.has_access();
}
void Nicedit::MakePost()
void Nicedit::make_post()
{
functions->fun_emacs.MakePost();
functions->fun_emacs.make_post();
}

View File

@@ -50,8 +50,8 @@ class Nicedit : public FunctionBase
public:
Nicedit();
bool HasAccess();
void MakePost();
bool has_access();
void make_post();
};

View File

@@ -50,7 +50,7 @@ Node::Node()
}
void Node::MakeGet()
void Node::make_get()
{
if( cur->request->param_tab.empty() )
{

View File

@@ -50,7 +50,7 @@ class Node : public FunctionBase
public:
Node();
void MakeGet();
void make_get();
private:

View File

@@ -54,7 +54,7 @@ Passwd::Passwd()
bool Passwd::HasAccess()
bool Passwd::has_access()
{
// a not logged user can use this function to reset his password
return true;
@@ -286,7 +286,7 @@ void Passwd::ShowResetPasswordForm()
but if you are not a root you can change only your password
and you should provide your current password as well
*/
void Passwd::MakePost()
void Passwd::make_post()
{
const std::wstring * plogin;
@@ -317,7 +317,7 @@ const std::wstring * plogin;
}
void Passwd::MakeGet()
void Passwd::make_get()
{
if( cur->request->IsParam(L"resetpassword") )
ShowResetPasswordForm();

View File

@@ -51,9 +51,9 @@ class Passwd : public FunctionBase
public:
Passwd();
bool HasAccess();
void MakeGet();
void MakePost();
bool has_access();
void make_get();
void make_post();
bool IsPasswordCorrect(const std::wstring & pass, const std::wstring & conf_pass);
bool ChangePassword(long user_id, const std::wstring & new_password);

View File

@@ -58,7 +58,7 @@ void Priv::set_dependency(WinixRequest * winix_request)
}
void Priv::MakePost()
void Priv::make_post()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);
@@ -67,7 +67,7 @@ void Priv::MakePost()
}
void Priv::MakeGet()
void Priv::make_get()
{
priv_changer.SetCur(cur);
priv_changer.SetSystem(system);

View File

@@ -51,8 +51,8 @@ class Priv : public FunctionBase
public:
Priv();
void MakePost();
void MakeGet();
void make_post();
void make_get();
void set_dependency(WinixRequest * winix_request);

View File

@@ -52,7 +52,7 @@ Pw::Pw()
}
bool Pw::HasAccess()
bool Pw::has_access()
{
return true;
}
@@ -62,12 +62,12 @@ bool Pw::HasAccess()
/* this function will be used for: adding a new user, adding a new group, deleting an existing user etc. */
void Pw::MakePost()
void Pw::make_post()
{
}
void Pw::MakeGet()
void Pw::make_get()
{
}

View File

@@ -51,9 +51,9 @@ public:
Pw();
bool HasAccess();
void MakePost();
void MakeGet();
bool has_access();
void make_post();
void make_get();
private:

View File

@@ -51,7 +51,7 @@ Reload::Reload()
}
bool Reload::HasAccess()
bool Reload::has_access()
{
return cur->session->puser && cur->session->puser->is_super_user;
}
@@ -70,7 +70,7 @@ void Reload::FunReloadTemplates()
void Reload::MakeGet()
void Reload::make_get()
{
// !! temporarily only an admin has access

View File

@@ -50,8 +50,8 @@ class Reload : public FunctionBase
public:
Reload();
bool HasAccess();
void MakeGet();
bool has_access();
void make_get();
private:

View File

@@ -98,7 +98,7 @@ return true;
parameter 'c' to rm function means removing only the content of a directory
this parameter can be sent either by a get or a post variable
*/
bool Rm::HasAccess()
bool Rm::has_access()
{
bool res = false;
@@ -511,7 +511,7 @@ void Rm::RemoveDir()
void Rm::Clear()
void Rm::clear()
{
content_item_tab.clear();
files.clear();
@@ -532,7 +532,7 @@ void Rm::CreateJSON(bool status)
void Rm::MakePost()
void Rm::make_post()
{
Prepare();
@@ -548,7 +548,7 @@ void Rm::MakePost()
RemoveDir();
}
Clear();
clear();
if( cur->request->IsParam(L"jquery_upload") )
CreateJSON(true);

View File

@@ -50,8 +50,8 @@ class Rm : public FunctionBase
public:
Rm();
bool HasAccess();
void MakePost();
bool has_access();
void make_post();
// removing the whole directory structure
// if remove_this_dir is false then only content of dir is removed
@@ -92,7 +92,7 @@ private:
bool HasAccessToDir(const Item & dir, bool only_content);
void Prepare();
void Clear();
void clear();
bool RemoveFile(Item & item);
bool RemoveDirFiles(long dir_id, bool check_access);

View File

@@ -53,7 +53,7 @@ RmUser::RmUser()
}
bool RmUser::HasAccess()
bool RmUser::has_access()
{
return cur->session->puser && cur->session->puser->is_super_user;
}
@@ -82,7 +82,7 @@ return result;
}
void RmUser::MakePost()
void RmUser::make_post()
{
if( cur->session->puser )
{
@@ -100,7 +100,7 @@ void RmUser::MakePost()
}
void RmUser::MakeGet()
void RmUser::make_get()
{
}

View File

@@ -50,9 +50,9 @@ public:
RmUser();
bool HasAccess();
void MakeGet();
void MakePost();
bool has_access();
void make_get();
void make_post();
bool RemoveUser(long user_id);

View File

@@ -51,13 +51,13 @@ Run::Run()
void Run::MakePost()
void Run::make_post()
{
MakeGet();
make_get();
}
void Run::MakeGet()
void Run::make_get()
{
// IMPROVE ME this probably should be set for all winix functions
cur->request->html_template = cur->request->last_item->html_template;

View File

@@ -53,8 +53,8 @@ public:
private:
void MakePost();
void MakeGet();
void make_post();
void make_get();
};

View File

@@ -52,7 +52,7 @@ Sort::Sort()
}
bool Sort::HasAccess()
bool Sort::has_access()
{
if( cur->request->is_item )
return system->HasWriteAccess(cur->request->item);
@@ -139,7 +139,7 @@ void Sort::UpdateItems()
void Sort::MakePost()
void Sort::make_post()
{
if( cur->request->is_item )
{
@@ -157,7 +157,7 @@ void Sort::MakePost()
}
void Sort::MakeGet()
void Sort::make_get()
{
if( !cur->request->is_item )
GetDirContent();

View File

@@ -50,9 +50,9 @@ class Sort : public FunctionBase
public:
Sort();
bool HasAccess();
void MakeGet();
void MakePost();
bool has_access();
void make_get();
void make_post();
private:

View File

@@ -110,7 +110,7 @@ void Subject::EditFileSubject()
void Subject::MakePost()
void Subject::make_post()
{
if( !SubjectCheckAccess() )
return;
@@ -123,7 +123,7 @@ void Subject::MakePost()
void Subject::MakeGet()
void Subject::make_get()
{
SubjectCheckAccess();
}

View File

@@ -50,8 +50,8 @@ class Subject : public FunctionBase
public:
Subject();
void MakePost();
void MakeGet();
void make_post();
void make_get();
private:

View File

@@ -53,7 +53,7 @@ Template::Template()
bool Template::HasAccess()
bool Template::has_access()
{
if( config->template_only_root_use_template_fun )
{
@@ -136,7 +136,7 @@ void Template::ChangeTemplate(Item & item)
}
void Template::MakePost()
void Template::make_post()
{
CreateTemplateFileName(cur->request->PostVar(L"template"));
ChangeTemplate(*cur->request->last_item);

View File

@@ -50,8 +50,8 @@ class Template : public FunctionBase
public:
Template();
bool HasAccess();
void MakePost();
bool has_access();
void make_post();
private:

View File

@@ -49,14 +49,14 @@ TimeZone::TimeZone()
}
bool TimeZone::HasAccess()
bool TimeZone::has_access()
{
return cur->session->puser != 0;
}
void TimeZone::MakePost()
void TimeZone::make_post()
{
if( cur->session->puser )
{
@@ -76,7 +76,7 @@ void TimeZone::MakePost()
void TimeZone::MakeGet()
void TimeZone::make_get()
{
}

View File

@@ -51,9 +51,9 @@ public:
TimeZone();
bool HasAccess();
void MakePost();
void MakeGet();
bool has_access();
void make_post();
void make_get();
private:

View File

@@ -49,19 +49,19 @@ Tinymce::Tinymce()
}
void Tinymce::Init()
void Tinymce::init()
{
system->AddCommonFileToVar(L"winix/tinymce.js", L"tinymce.js", Header::text_javascript_utf8);
}
bool Tinymce::HasAccess()
bool Tinymce::has_access()
{
return functions->fun_emacs.HasAccess();
return functions->fun_emacs.has_access();
}
void Tinymce::MakeGet()
void Tinymce::make_get()
{
cur->session->last_css.clear();
int parcss = system->mounts.MountParCss();
@@ -72,9 +72,9 @@ void Tinymce::MakeGet()
void Tinymce::MakePost()
void Tinymce::make_post()
{
functions->fun_emacs.MakePost();
functions->fun_emacs.make_post();
}

View File

@@ -50,10 +50,10 @@ class Tinymce : public FunctionBase
public:
Tinymce();
void Init();
bool HasAccess();
void MakeGet();
void MakePost();
void init();
bool has_access();
void make_get();
void make_post();
};

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2023, Tomasz Sowa
* Copyright (c) 2008-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,18 +57,18 @@ Upload::Upload()
}
void Upload::Init()
void Upload::init()
{
}
void Upload::Finish()
void Upload::finish()
{
CloseMagicLib();
close_magic_lib();
}
bool Upload::HasAccess(const Item & item)
bool Upload::has_upload_access(const Item & item)
{
// you can use 'upload' only in a directory
if( item.type != Item::dir )
@@ -91,9 +91,9 @@ return true;
}
bool Upload::HasAccess()
bool Upload::has_access()
{
if( cur->request->is_item || !HasAccess(*cur->request->dir_tab.back()) )
if( cur->request->is_item || !has_upload_access(*cur->request->dir_tab.back()) )
return false;
return true;
@@ -102,7 +102,7 @@ return true;
bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_filename)
bool Upload::upload_save_static_file(const Item & item, const std::wstring & tmp_filename)
{
if( !system->MakeFilePath(item, path, false, true, config->upload_dirs_chmod, config->upload_group_int) )
{
@@ -131,7 +131,7 @@ bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_fi
void Upload::ResizeImage(Item & item)
void Upload::resize_image(Item & item)
{
Image::Scale scale = system->image.GetImageScale(item.parent_id);
system->image.Resize(item.id, scale.cx, scale.cy, scale.aspect_mode, scale.quality);
@@ -139,7 +139,7 @@ void Upload::ResizeImage(Item & item)
void Upload::CreateThumb(Item & item)
void Upload::create_thumb(Item & item)
{
Image::Scale scale = system->image.GetThumbScale(item.parent_id);
system->image.CreateThumb(item.id, scale.cx, scale.cy, scale.aspect_mode, scale.quality);
@@ -147,7 +147,7 @@ void Upload::CreateThumb(Item & item)
void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
void Upload::upload_file(Item & item, const std::wstring & tmp_filename)
{
// we should add the file beforehand to get the proper item.id
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
@@ -157,7 +157,7 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
{
if( system->CreateNewFile(item) )
{
if( UploadSaveStaticFile(item, tmp_filename) )
if( upload_save_static_file(item, tmp_filename) )
{
ItemModelData item_model_data;
item_model_data.prepare_unique_url = false;
@@ -171,10 +171,10 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
if( item.item_content.file_type == WINIX_ITEM_FILETYPE_IMAGE )
{
if( config->image_resize )
ResizeImage(item);
resize_image(item);
if( config->create_thumb )
CreateThumb(item);
create_thumb(item);
}
if( is_jquery_upload )
@@ -191,7 +191,7 @@ void Upload::UploadFile(Item & item, const std::wstring & tmp_filename)
}
bool Upload::FunUploadCheckAbuse()
bool Upload::fun_upload_check_abuse()
{
if( config->use_antispam_mechanism_for_not_logged_users )
{
@@ -218,7 +218,7 @@ return true;
void Upload::UploadMulti()
void Upload::upload_multi()
{
cur->request->item.Clear(); // clearing and setting date
cur->request->item.parent_id = cur->request->dir_tab.back()->id;
@@ -238,19 +238,19 @@ void Upload::UploadMulti()
cur->request->item.item_content.file_size = i->second.file_size;
functions->PrepareUrl(cur->request->item);
AnalizeFileType(i->second.tmp_filename, cur->request->item.item_content.file_mime_type);
UploadFile(cur->request->item, i->second.tmp_filename);
analize_file_type(i->second.tmp_filename, cur->request->item.item_content.file_mime_type);
upload_file(cur->request->item, i->second.tmp_filename);
i->second.tmp_filename.clear();
}
if( is_jquery_upload )
CreateJqueryUploadAnswer();
create_jquery_upload_answer();
else
system->RedirectToLastDir();
}
void Upload::UploadSingle()
void Upload::upload_single()
{
cur->request->item.Clear(); // clearing and setting date
@@ -278,22 +278,22 @@ void Upload::UploadSingle()
functions->PrepareUrl(cur->request->item);
}
AnalizeFileType(post_file.tmp_filename, cur->request->item.item_content.file_mime_type);
UploadFile(cur->request->item, post_file.tmp_filename);
analize_file_type(post_file.tmp_filename, cur->request->item.item_content.file_mime_type);
upload_file(cur->request->item, post_file.tmp_filename);
post_file.tmp_filename.clear();
if( is_jquery_upload )
CreateJqueryUploadAnswer();
create_jquery_upload_answer();
else
if( is_ckeditor_upload )
CreateCkeditorUploadAnswer();
create_ckeditor_upload_answer();
else
if( cur->request->status == WINIX_ERR_OK )
system->RedirectTo(cur->request->item, L"/cat");
}
void Upload::InitMagicLibIfNeeded()
void Upload::init_magic_lib_if_needed()
{
if( !magic_cookie )
{
@@ -313,7 +313,7 @@ void Upload::InitMagicLibIfNeeded()
}
log << logend;
CloseMagicLib();
close_magic_lib();
}
}
else
@@ -324,7 +324,7 @@ void Upload::InitMagicLibIfNeeded()
}
void Upload::CloseMagicLib()
void Upload::close_magic_lib()
{
if( magic_cookie )
{
@@ -335,7 +335,7 @@ void Upload::CloseMagicLib()
}
void Upload::AnalizeFileType(const std::wstring & file_path, std::wstring & file_type)
void Upload::analize_file_type(const std::wstring & file_path, std::wstring & file_type)
{
file_type.clear();
@@ -375,7 +375,7 @@ void Upload::AnalizeFileType(const std::wstring & file_path, std::wstring & file
/*
* an answer for the 'upload' function
*/
void Upload::CreateJqueryUploadAnswer()
void Upload::create_jquery_upload_answer()
{
Request & req = *cur->request;
@@ -420,7 +420,7 @@ void Upload::CreateJqueryUploadAnswer()
* an answer for the ckeditor function
* https://ckeditor.com/docs/ckeditor4/latest/guide/dev_file_upload.html
*/
void Upload::CreateCkeditorUploadAnswer()
void Upload::create_ckeditor_upload_answer()
{
Request & req = *cur->request;
@@ -453,9 +453,9 @@ void Upload::CreateCkeditorUploadAnswer()
}
void Upload::MakePost()
void Upload::make_post()
{
InitMagicLibIfNeeded();
init_magic_lib_if_needed();
cur->request->item_tab.clear();
is_jquery_upload = cur->request->IsParam(L"jquery_upload");
is_ckeditor_upload = cur->request->IsParam(L"ckeditor_upload");
@@ -466,18 +466,18 @@ void Upload::MakePost()
return;
}
if( !FunUploadCheckAbuse() )
if( !fun_upload_check_abuse() )
return;
if( cur->request->post_file_tab.size() > 1 )
UploadMulti();
upload_multi();
else
UploadSingle();
upload_single();
}
void Upload::MakeGet()
void Upload::make_get()
{
if( cur->request->IsParam(L"jquery_upload") )
{
@@ -492,19 +492,17 @@ void Upload::MakeGet()
raw("order by item.sort_index asc, item.url asc, item.id asc").
get_vector(cur->request->item_tab);
CreateJqueryUploadAnswer();
create_jquery_upload_answer();
}
}
void Upload::Clear()
void Upload::clear()
{
files.clear();
}
} // namespace
} // namespace Winix

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2023, Tomasz Sowa
* Copyright (c) 2010-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -52,10 +52,10 @@ class Upload : public FunctionBase
public:
Upload();
bool HasAccess();
void MakePost();
void MakeGet();
void UploadFile(Item & item, const std::wstring & tmp_filename);
bool has_access();
void make_post();
void make_get();
void upload_file(Item & item, const std::wstring & tmp_filename);
private:
@@ -65,30 +65,29 @@ private:
magic_t magic_cookie;
pt::Space files;
void Init();
void Finish();
void Clear();
void init();
void finish();
void clear();
bool HasAccess(const Item & item);
bool UploadSaveStaticFile(const Item & item, const std::wstring & tmp_filename);
bool FunUploadCheckAbuse();
void UploadMulti();
void UploadSingle();
void ResizeImage(Item & item);
void CreateThumb(Item & item);
void CreateJqueryUploadAnswer();
void CreateCkeditorUploadAnswer();
bool has_upload_access(const Item & item);
bool upload_save_static_file(const Item & item, const std::wstring & tmp_filename);
bool fun_upload_check_abuse();
void upload_multi();
void upload_single();
void resize_image(Item & item);
void create_thumb(Item & item);
void create_jquery_upload_answer();
void create_ckeditor_upload_answer();
void InitMagicLibIfNeeded();
void CloseMagicLib();
void AnalizeFileType(const std::wstring & file_path, std::wstring & file_type);
void init_magic_lib_if_needed();
void close_magic_lib();
void analize_file_type(const std::wstring & file_path, std::wstring & file_type);
};
} // namespace
} // namespace Winix
#endif

View File

@@ -51,7 +51,7 @@ Vim::Vim()
}
void Vim::Init()
void Vim::init()
{
// WYMeditor doesn't work on different domains by default,
// solution: http://forum.wymeditor.org/forum/viewtopic.php?f=2&t=731&p=2507#p2504
@@ -61,15 +61,15 @@ void Vim::Init()
}
bool Vim::HasAccess()
bool Vim::has_access()
{
return functions->fun_emacs.HasAccess();
return functions->fun_emacs.has_access();
}
void Vim::MakePost()
void Vim::make_post()
{
functions->fun_emacs.MakePost();
functions->fun_emacs.make_post();
}

View File

@@ -50,9 +50,9 @@ class Vim : public FunctionBase
public:
Vim();
void Init();
bool HasAccess();
void MakePost();
void init();
bool has_access();
void make_post();
};

View File

@@ -50,7 +50,7 @@ Who::Who()
}
bool Who::HasAccess()
bool Who::has_access()
{
return cur->session->puser != 0;
}

View File

@@ -50,7 +50,7 @@ class Who : public FunctionBase
public:
Who();
bool HasAccess();
bool has_access();
private: