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

@@ -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;
};