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:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user