From 245d2efe100779fe38308c9da30a31c38190a3d0 Mon Sep 17 00:00:00 2001 From: totoro Date: Wed, 9 Oct 2019 06:13:34 +0900 Subject: [PATCH] continue the make web site with controllers independent. --- web/CXM_making_a_web_site.anubis | 127 +++---------------------------------------------------------------------------------------------------------------------------- web/CXM_page_message.anubis | 1 + web/CXM_web_session.anubis | 83 +---------------------------------------------------------------------------------- web/controllers_web_site.anubis | 586 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- web/plugin/plugin.anubis | 3 ++- web/types/controllers_web_site.anubis | 26 +++++++++++++++++++++++++- web/types/web_session.anubis | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 271 insertions(+), 651 deletions(-) create mode 100644 web/types/web_session.anubis diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index 27325d6..65aa9f7 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -357,7 +357,7 @@ public define String -define List(HTTP_header) +public define List(HTTP_header) make_session_cookie_headers ( String website_name, @@ -370,105 +370,15 @@ define List(HTTP_header) ] . -define WEB_Session -> String // the function constructed returns the name of the state - make_save_session_function - ( - Int timeout, - String state_directory, - (LogLevel, String) -> One logger - ) = - (WEB_Session s_var) |-> - //Set the new timeout - with time_stamp = now+timeout, - s = to_WEB_Session_No_Var(s_var), - to_be_saved = (time_stamp,s), - //generate new session name - //session_name = to_ascii(sha1(s)), - session_name = s_var.session_id, - //println("make_save_state_function " + state_directory+"/s"+state_name); - if save(to_be_saved,state_directory+"/"+session_name) is ok then - //logger(logInfo, "----- session ["+session_name+"] saved"+dump_WEB_Session_Fields(*s_var.fields)); - session_name - else - logger(logError, ("Cannot create session file in '"+state_directory+"'.\n")); - "" -. When a request arrives, we need to retrieve the previous state from the server's disk. We receive the name of that state. If the state is out of date, the state file is kept 3 days, and then deleted. -type Previous_Session: - not_found, // cannot retrieve the previous state - out_of_date(WEB_Session p_session), // the previous state is out of date - still_valid(WEB_Session p_session). // the previous state is still valid - -define Previous_Session - retrieve_session - ( - HTTP_Info http_info, - String session_directory, - String website_name - ) = - if find_cookie("session_"+website_name, server_get_cookies(http_headers(http_info))) is - { - failure then not_found - success(cookie) then - //println("find_cookie(\"state_"+website_name+"\" success"); - with session_name = value(cookie), - with file_path = session_directory+"/"+session_name, - //unserialize the stored session and his timeout value - //println("retrieve session ["+session_name+"]"); - if (RetrieveResult((Int, WEB_Session_No_Var)))retrieve(file_path) is ok(d) then - ( - //println("retrieve session OK ["+session_name+"]"); - since d is (time_stamp, s_no_var), - with s = to_WEB_Session(s_no_var), - if time_stamp < now then - ( - forget(remove(file_path)); - out_of_date(s) - ) - else - still_valid(s) // state has been successfully retrieved - ) - else - not_found - } -. - -define (List(String) file_names) -> One - make_delete_out_of_date_sessions_function - ( - String state_directory, - (LogLevel, String) -> One logger - ) = - (List(String) file_names) |-df-> - if file_names is - { - [ ] then unique, - [h . t] then - if h = "." | h = ".." then - df(t) - else - with file_path = state_directory+"/"+h, - if (RetrieveResult((Int, WEB_Session_No_Var)))retrieve(file_path) is ok(d) then - ( - if d is (time_stamp, data) then - if time_stamp < now then - //println("session "+h+" out date will be deleted timestamp ["+time_stamp+"] now ["+now+"]"); - (forget(remove(file_path)); - df(t)) - else - //println("Session "+h+" still valid ["+time_stamp+"] now ["+now+"]"); - df(t) - ) - else - logger(logError, "Can't retreive session "+h+", hence will be deleted"); - (forget(remove(file_path)); df(t)) - }. + + define One delete_out_of_date_sessions // for all web sites ( @@ -3017,37 +2927,6 @@ public define Web_Site -define HTTP_Answer - error_page - ( - HTTP_Status http_status, - String message, - WEB_Session _session, - ) - = - html_page - ( - http_status, // status - [], // list of 'META' tags (empty for this site) - body // body of page - ( - // list of body options - [ - background_color(rgb(255,200,200)) - ], - - // content of page - sequence([ - preformated([size(14)],"Anubis Web Server - Standard Lib v1.14.0.0 - Anubis language v1.14"), - preformated([size(12)],"Error "+to_String(http_status)), - preformated([size(12)],"Internal message :"+message), - br, - in_form(html_Id(""),text_area(wan(""), init(dump(_session)), 120, 60)) - ]) - ) - ) -. - public define JsonValue to_html_ajax_content(Printable_tree content_HTML, String additional_script). public define JsonValue to_html_ajax_content(HTML_Partial_Content content_HTML, CommonInfo cinfo, String additional_script). diff --git a/web/CXM_page_message.anubis b/web/CXM_page_message.anubis index d934e52..266bbbf 100644 --- a/web/CXM_page_message.anubis +++ b/web/CXM_page_message.anubis @@ -8,6 +8,7 @@ read calexium_lib/web/CXM_making_a_web_site.anubis read calexium_lib/web/widgets/icons_set.anubis +read calexium_lib/web/types/web_session.anubis public type Alignment: left, diff --git a/web/CXM_web_session.anubis b/web/CXM_web_session.anubis index 3d2d230..ca0ad19 100644 --- a/web/CXM_web_session.anubis +++ b/web/CXM_web_session.anubis @@ -9,6 +9,7 @@ read system/convert.anubis read system/muscle.anubis read calexium_lib/database/db_types.anubis +transmit types/web_session.anubis read CXM_common.anubis read CXM_web_dump.anubis @@ -23,89 +24,7 @@ read CXM_web_dump.anubis //"AWS_CURRENT_LEFT_MENU" Left_Menu current left menu on the page //"AWS_CURRENT_MENU" Menu current menu, on the top of the page -public type WEB_Session_Field_Datum: - string(String), //fully implented - bool(Bool), //fully implented - int(Int), //fully implemented - db_id(DB_id), - message(Message), //fully implemented - byte_array(ByteArray), - float(Float), - word128(Word128), - word64(Word64), - word32(Word32), - word16(Word16), - word8(Word8), - word4(Word4) - //WEB_Request -. - -public type WEB_Session_Field_Type: - string_t, - bool_t, - int_t, - db_id_t, - message_t, - byte_array_t, - float_t, - word128_t, - word64_t, - word32_t, - word16_t, - word8_t, - word4_t -. - -public type WEB_Session_Field: - session_field( - String field_name, - WEB_Session_Field_Type field_type, - Var(WEB_Session_Field_Datum) field_datum //Var because it can be replaced - ). - -public type WEB_Session_Field_No_Var: - session_field( - String field_name, - WEB_Session_Field_Type field_type, - WEB_Session_Field_Datum field_datum //Var because it can be replaced - ). - -public type WEB_Request: - web_request( - HTTP_Info http_info, - Var(List(Web_arg)) lwa, - Bool is_https, - ) -. - -public type WEB_Request_No_Var: - web_request( - HTTP_Info http_info, - List(Web_arg) lwa, - Bool is_https, - ) -. -public type WEB_Session: - web_session( - String session_id, - String language, - Var(List(WEB_Session_Field)) fields, - WEB_Request web_request, - WEB_Request previous_web_request, - WEB_Request draw_web_request - ). - -public type WEB_Session_No_Var: - web_session( - String session_id, - String language, - List(WEB_Session_Field_No_Var) fields, - WEB_Request_No_Var web_request, - WEB_Request_No_Var previous_web_request, - WEB_Request_No_Var draw_web_request, - ). - public define Var(List(WEB_Session_Field)) empty_fields_list = var([]). diff --git a/web/controllers_web_site.anubis b/web/controllers_web_site.anubis index 634d6ce..f31d813 100644 --- a/web/controllers_web_site.anubis +++ b/web/controllers_web_site.anubis @@ -8,25 +8,157 @@ website with: - controllers - - web session + - web session in controller - plugin - web page renderer - + +read system/logger.anubis +read tools/printable_tree.anubis + +transmit CXM_cookies.anubis transmit CXM_web_session.anubis transmit types/controllers_web_site.anubis +read plugin/plugin.anubis + +read CXM_making_a_web_site.anubis + read calexium_lib/web/plugin/plugin.anubis read config/logger_config.anubis -public type WEB_Action: - web_action( - WEB_Action_Name name, // name of action - WEB_Action_Allowed_Protocol allowed_proto, - (WEB_Session) -> Bool allow, // true if action allowed - (WEB_Session) -> WEB_Controller_Result do_it - ) +type Previous_Session: + not_found, // cannot retrieve the previous state + out_of_date(WEB_Session p_session), // the previous state is out of date + still_valid(WEB_Session p_session). // the previous state is still valid + +define Previous_Session + retrieve_session + ( + HTTP_Info http_info, + String session_directory, + String website_name + ) = + if find_cookie("session_"+website_name, server_get_cookies(http_headers(http_info))) is + { + failure then not_found + success(cookie) then + //println("find_cookie(\"state_"+website_name+"\" success"); + with session_name = value(cookie), + with file_path = session_directory+"/"+session_name, + //unserialize the stored session and his timeout value + //println("retrieve session ["+session_name+"]"); + if (RetrieveResult((Int, WEB_Session_No_Var)))retrieve(file_path) is ok(d) then + ( + //println("retrieve session OK ["+session_name+"]"); + since d is (time_stamp, s_no_var), + with s = to_WEB_Session(s_no_var), + if time_stamp < now then + ( + forget(remove(file_path)); + out_of_date(s) + ) + else + still_valid(s) // state has been successfully retrieved + ) + else + not_found + } +. + +define (List(String) file_names) -> One + make_delete_out_of_date_sessions_function + ( + String state_directory, + (LogLevel, String) -> One logger + ) = + (List(String) file_names) |-df-> + if file_names is + { + [ ] then unique, + [h . t] then + if h = "." | h = ".." then + df(t) + else + with file_path = state_directory+"/"+h, + if (RetrieveResult((Int, WEB_Session_No_Var)))retrieve(file_path) is ok(d) then + ( + if d is (time_stamp, data) then + if time_stamp < now then + //println("session "+h+" out date will be deleted timestamp ["+time_stamp+"] now ["+now+"]"); + (forget(remove(file_path)); + df(t)) + else + //println("Session "+h+" still valid ["+time_stamp+"] now ["+now+"]"); + df(t) + ) + else + logger(logError, "Can't retreive session "+h+", hence will be deleted"); + (forget(remove(file_path)); df(t)) + }. + +define WEB_Session -> String // the function constructed returns the name of the state + make_save_session_function + ( + Int timeout, + String state_directory, + (LogLevel, String) -> One logger + ) = + (WEB_Session s_var) |-> + //Set the new timeout + with time_stamp = now+timeout, + s = to_WEB_Session_No_Var(s_var), + to_be_saved = (time_stamp,s), + //generate new session name + //session_name = to_ascii(sha1(s)), + session_name = s_var.session_id, + //println("make_save_state_function " + state_directory+"/s"+state_name); + if save(to_be_saved,state_directory+"/"+session_name) is ok then + //logger(logInfo, "----- session ["+session_name+"] saved"+dump_WEB_Session_Fields(*s_var.fields)); + session_name + else + logger(logError, ("Cannot create session file in '"+state_directory+"'.\n")); + "" +. + +public type WEB_Page_Renderer: + web_page_renderer( + String app, //application + String name, //renderer name + (WEB_Session _session, List(WEB_Plugin), HTML_Partial_Content _content) -> HTTP_Answer page_layout //call back for rendering page + ) +. + +define HTTP_Answer + error_page + ( + HTTP_Status http_status, + String message, + WEB_Session _session, + ) + = + html_page + ( + http_status, // status + [], // list of 'META' tags (empty for this site) + body // body of page + ( + // list of body options + [ + background_color(rgb(255,200,200)) + ], + + // content of page + sequence([ + preformated([size(14)],"Anubis Web Server - Standard Lib v1.14.0.0 - Anubis language v1.14"), + preformated([size(12)],"Error "+to_String(http_status)), + preformated([size(12)],"Internal message :"+message), + br, + in_form(html_Id(""),text_area(wan(""), init(dump(_session)), 120, 60)) + ]) + ) + ) . @@ -133,13 +265,7 @@ public define WEB_Controller_Result redraw(failure, content) . -public type WEB_Page_Renderer: - web_page_renderer( - String app, //application - String name, //renderer name - (WEB_Session _session, List(WEB_Plugin), HTML_Partial_Content _content) -> HTTP_Answer page_layout //call back for rendering page - ) -. + define WEB_Page_Renderer default_page_renderer = @@ -556,13 +682,7 @@ public define Web_Site ), delete_out_of_date). -public type WEB_Controller: - web_controller( - String name, //controller name - Var(List(WEB_Action)) controller_actions, //list of all actions of that controller - (WEB_Session)-> WEB_Controller_Result error //Error renderer - ) -. + define (WEB_Session)-> WEB_Controller_Result web_controller_error @@ -584,423 +704,3 @@ public define WEB_Controller web_controller(name, controller_actions, web_controller_error(name)) . -public type WEB_Page_Renderer: - web_page_renderer( - String app, //application - String name, //renderer name - (WEB_Session _session, List(WEB_Plugin), HTML_Partial_Content _content) -> HTTP_Answer page_layout //call back for rendering page - ) -. - -define WEB_Page_Renderer - default_page_renderer = - web_page_renderer("AWS", "AWS_DEFAULT_PAGE", - ( WEB_Session _session, - List(WEB_Plugin) _plugins, - HTML_Partial_Content _content - ) |-> - with _title = get_page_title(_session), - html_page - ( - http_ok, - [ title(_title), ]// title of web site - , - body // body of page - ( - [], //body options empty - (HTML_Off_Form)partial(_content) - ) - ) - ) -. - -define WEB_Controller_Result - apply_action - ( - WEB_Session _session, - String requested_action_name, - List(WEB_Action) actions_list - ) = - //println("apply_action "); - if actions_list is - { - [] then http_answer(error_page(http_not_found, "["+requested_action_name+"] Action not found in all controllers", _session)), - [h . t] then - if h.name = no_action then - http_answer( _session, html_content(http_no_content, empty)) - else - with action_name = if h.name is - { - no_action then "", - controller_action(_, name) then name, - action_name(name) then name, - url(url) then url, - }, - if requested_action_name = action_name then - with step = get_Int(_session.fields, "AWS_SESSION_STEP", 0) + 1, - replace_Int(_session.fields, "AWS_SESSION_STEP", step); - if h.allowed_proto is - { - //Action only in HTTP - http then - if _session.web_request.is_https then - http_answer(error_page(http_forbidden, "Only HTTP authorized", _session)) - else - //ask to the server the authorization to execute that action - if h.allow(_session) then - h.do_it(_session) - else - http_answer(error_page(http_unauthorized, "you are not authorized for this action", _session)) - - //Action only in HTTPS - https then - if _session.web_request.is_https then - //ask to the server the authorization to execute that action - if h.allow(_session) then - h.do_it(_session) - else - http_answer(error_page(http_unauthorized, "you are not authorized for this action", _session)) - else - http_answer(error_page(http_forbidden, "Only HTTPS authorized", _session)) - //Action in both HTTP / HTTPS - http_https then - //ask to the server the authorization to execute that action - if h.allow(_session) then - //println("do_it "+action_name); - h.do_it(_session) - else - http_answer(error_page(http_unauthorized, "you are not authorized for this action", _session)) - - } - else - apply_action(_session, requested_action_name, t) - } -. - -define Maybe(WEB_Controller) - get_controller - ( - String controller_name, - List(WEB_Controller) controllers, - (LogLevel, String) -> One logger //logger - )= - if controllers is - { - [] then - logger(logWarning, "Can't find controller ["+controller_name+"]"); - failure, - [h . t] then - if h.name = controller_name then - //println("Controller ["+controller_name+"] found"); - success(h) - else - get_controller(controller_name, t, logger) - } -. - -define WEB_Page_Renderer - get_page_renderer - ( - String renderer_name, - List(WEB_Page_Renderer) renderers, - (LogLevel, String) -> One logger //logger - )= - if renderers is - { - [] then - logger(logWarning, "Can't find page_renderer ["+renderer_name+"], use the default"); - default_page_renderer, - [h . t] then - if h.name = renderer_name then - //println("renderer_name ["+renderer_name+"] found"); - h - else - //println("renderer_name "+renderer_name+" not matching"); - get_page_renderer(renderer_name, t, logger) - } -. - -define WEB_Page_Renderer - get_page_renderer - ( - WEB_Session _session, - WEB_Page_Renderer _current_page_renderer, - List(WEB_Page_Renderer) renderers, - (LogLevel, String) -> One logger //logger - )= - //get the renderer page name to use from the session "AWS_PAGE_RENDERER" - if get_String(_session.fields, "AWS_CURRENT_PAGE_RENDERER") is - { - failure then logger(logWarning, "No renderer defined, use the default"); default_page_renderer, - success(renderer_name) then - //check if the renderer_page already in cache - if renderer_name = _current_page_renderer.name then - _current_page_renderer - else - //if not in cache, use the selector function - get_page_renderer(renderer_name, renderers, logger) - } -. - -define (Maybe(WEB_Session), HTTP_Answer) - apply_controller_action - ( - WEB_Controller controller, - List(WEB_Plugin) plugins, - List(WEB_Controller) controllers, - WEB_Page_Renderer _current_page_renderer, - List(WEB_Page_Renderer) page_renderers, - CommonInfo cinfo, - WEB_Session _session, - Maybe(String) _mb_action_name, - (HTTP_Info, - Var(List(Web_arg)), - Bool is_https) -> WEB_Session initial_session, - (LogLevel, String) -> One logger //logger - )= - //get the action name - with mb_action_name = - if _mb_action_name is - { - failure then get_String(*_session.web_request.lwa, "aws_action"), - success(_an) then success(_an) - }, - - if mb_action_name is - { - failure then - //(failure, error_page(http_not_found, "Action name failure", _session)), - with new_session = initial_session(_session.web_request.http_info, _session.web_request.lwa, _session.web_request.is_https), - if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers, logger) is - { - failure then (failure, error_page(http_not_found, "Initial Session Controller not found", new_session)), - success(new_controller) then apply_controller_action(new_controller, plugins, controllers, _current_page_renderer, page_renderers, cinfo, new_session, failure, initial_session, logger), - }, - success(action_name) then - //logger(logInfo, "ACTION_NAME ["+action_name+"] from IP "+get_String(_session.fields, "IP", "")); - if apply_action(_session, action_name, *controller.controller_actions) is - { - http_answer(session, answer) then - since session is web_session(id, lang, entries, current, previous, _), - with new_web_session = web_session(id, lang, entries, current, previous, current), -// println("***** http_answer(session, answer) record new draw point to *****"); -// println("web arguments:"+ -// dump_web_arg_values(*current.lwa)); -// println("************************************"); - (success(new_web_session), answer), - - http_answer(answer) then - since _session is web_session(id, lang, entries, current, previous, _), - with new_web_session = web_session(id, lang, entries, current, previous, current), -// println("***** http_answer(answer) record new draw point to *****"); -// println("web arguments:"+ -// dump_web_arg_values(*current.lwa)); -// println("************************************"); - (success(new_web_session), answer), - - redirect(new_session) then - if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers, logger) is - { - failure then (failure, error_page(http_not_found, "Redirect Controller not found", new_session)), - success(new_controller) then apply_controller_action(new_controller, plugins, controllers, _current_page_renderer, page_renderers, cinfo, new_session, failure, initial_session, logger), - }, - - redirect(new_session, r_controller_name, r_action_name) then - if get_controller(r_controller_name, controllers, logger) is - { - failure then (failure, error_page(http_not_found, "Redirect Controller "+r_controller_name+" not found", new_session)), - success(new_controller) then - apply_controller_action(new_controller, plugins, controllers, _current_page_renderer, page_renderers, cinfo, new_session, success(r_action_name), initial_session, logger), - }, - - redirect_to_previous then - if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers, logger) is - { - failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)), - success(new_controller) then - since _session is web_session(id, lang, entries, _, previous, draw), - apply_controller_action(new_controller, plugins, controllers, _current_page_renderer, page_renderers, cinfo, web_session(id, lang, entries, previous, previous, draw), failure, initial_session, logger), - }, - redirect_to_previous(entries) then - if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers, logger) is - { - failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)), - success(new_controller) then - since _session is web_session(id, lang, _, _, previous, draw), - apply_controller_action(new_controller, plugins, controllers, _current_page_renderer, page_renderers, cinfo, web_session(id, lang, entries, previous, previous, draw), failure, initial_session, logger), - }, - //ajax(answer) then (failure, answer), - //ajax with modified session that must be saved - ajax(session, answer) then (session, answer), - - //ajax(content, additional_script) then (failure, json(http_ok, to_html_ajax_content(content, cinfo, additional_script))), - ajax(session, content, additional_script) then (session, json(http_ok, to_html_ajax_content(content, cinfo, additional_script))), - //ajax(content, additional_script) then (failure, json(http_ok, to_html_ajax_content(content, additional_script))), - ajax(session, content, additional_script) then (session, json(http_ok, to_html_ajax_content(content, additional_script))), - send_file(file_path, c_disposition) then (failure, send_file(file_path, c_disposition)), - renderer_content(session, content) then - with the_session = if session is {failure then _session, success(__session) then __session}, - since the_session is web_session(id, lang, entries, current, previous, _), - with new_web_session = web_session(id, lang, entries, current, previous, current), -// println("***** renderer_content(session, content) record new draw point to *****"); -// println("web arguments:"+ -// dump_web_arg_values(*current.lwa)); -// println("************************************"); - with page_renderer = get_page_renderer(new_web_session, _current_page_renderer, page_renderers, logger), - (success(new_web_session), page_renderer.page_layout(new_web_session, plugins, content)) - } - } -. - - - -public define Web_Site - make_web_site_controller_description - ( - String website_name, // site_UID - List(String) common_names, // for example: ["www.our-business.com"] - String site_directory, - String state_directory, - One -> One init, - (HTTP_Info, - Var(List(Web_arg)), - Bool is_https) -> WEB_Session initial_session, - (WEB_Session, - HTTP_Info, - Var(List(Web_arg)), - Bool is_https) -> WEB_Session expired_session, - Var(List(WEB_Controller)) web_controllers, - Var(List(WEB_Page_Renderer)) web_page_renderers, - Var(List(WEB_Plugin)) web_plugins, - Maybe(WEB_Session) -> List(HTTP_header) additional_headers, - List(HTTP_header) constant_additional_headers, - Int timeout, - Redirections redirections, - String charset, - List(String) journal_extensions, - List(String) journal_headers, - (LogLevel, String) -> One logger, //logger - String secret, - List(MIME) known_mime_types, - (String action_name, - List(Web_arg) args) -> One before_send_file - )= - //call the initialization function - init(unique); - - - // - // make required directories (if needed) - // - with //web_sites_directory = (String) make_directory(my_anubis_directory+"/web_sites"), - base_directory = (String) make_directory(site_directory), - // state_directory = make_directory(site_directory+"/states"), - forget((String)make_directory(site_directory+"/public")); - - // - // construct tool functions - // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true - with save_session = make_save_session_function(timeout, state_directory, logger), - with current_page_renderer = var((WEB_Page_Renderer)default_page_renderer), - // with left_menu_list = get_left_menu_from_plugins(*web_plugins), - // retrieve_session = make_retrieve_session_function(state_directory, website_name), - //separate_web_args = make_separate_web_args_function(state_directory, retrieve_state), - //apply_action = make_apply_action_function(actions), - - // - // construct the site handler - // - site_handler = (Word32 http_port, Word32 https_port) |-> - ((String host_name, - HTTP_Info http_info, - List(Web_arg) _lwa, - Bool is_https) |-> - //(Printable_tree) - logger(logTrace,"host_name "+host_name); - logger(logTrace, dump_http_info(http_info)); - logger(logTrace, dump_web_arg_values(_lwa)); - with cinfo = info(host_name, http_port, https_port, site_directory, secret), - - //retrieve the previous session and determine the new one - with current_session = if retrieve_session(http_info, state_directory, website_name) is - { - not_found then - logger(logInfo, "previous state not found"); - initial_session(http_info, var(_lwa), is_https), - - out_of_date(previous_session) then - logger(logInfo, "previous out_of_date"); - //expired_session(previous_session, http_info, var(_lwa), is_https), - since previous_session is web_session(id, lang, entries, previous, _, draw), - replace_String(entries, "IP", http_header_value(http_info.http_headers, "x-forwarded-for", ip_addr_to_string(http_info.ip_address))); - web_session(id, lang, entries, web_request(http_info, var(_lwa), is_https), previous, draw) - - still_valid(previous_session) then - since previous_session is web_session(id, lang, entries, previous, _, draw), - replace_String(entries, "IP", http_header_value(http_info.http_headers, "x-forwarded-for", ip_addr_to_string(http_info.ip_address))); - web_session(id, lang, entries, web_request(http_info, var(_lwa), is_https), previous, draw) - }, - - - //apply the action according to current session - //since apply_controller_action(get_controller(get_String(lwa, "aws_controller", "root"), *web_controllers), *web_controllers, current_session) - since if get_controller(get_String(*current_session.web_request.lwa, "aws_controller", "root"), *web_controllers, logger) is - { - failure then - (failure, error_page(http_not_found, "Controller not found", current_session)), - - success(new_controller) then - apply_controller_action(new_controller, *web_plugins, *web_controllers, *current_page_renderer, *web_page_renderers, cinfo, current_session, failure, initial_session, logger), - } - is (mb_new_session, http_answer), - - //save the session if need and construct the according cookie - with cookie_headers = - if mb_new_session is - { - failure then [], - success(new_session) then - with session_name = save_session(new_session), - make_session_cookie_headers(website_name, session_name) - }, - - //formatting and send http answer because this is the last function - format(cinfo, - //state_name, - additional_headers(mb_new_session) + cookie_headers, - http_answer, - is_https, - charset) - ), - // - // make the delete_out_of_date function - // - delete_out_of_date = - make_delete_out_of_date_sessions_function(site_directory+"/states", logger), - // - // construct the web site description - // - web_site((Word32 http_port, Word32 https_port) |-> - web_site_description(common_names, - site_directory, - redirections, - charset, - journal_extensions, - journal_headers, - logger, - secret, - known_mime_types, - site_handler(http_port,https_port), - constant_additional_headers, - (HTTP_Info http_info, List(Web_arg) lwa) |-> unique -// if separate_web_args(lwa, http_info ) is -// swa(mb_previous_state,mb_action_name,operands) then -// if mb_action_name is -// { -// failure then unique -// success(an) then before_send_file(an,operands) -// } - //using_state_cookies - ), - delete_out_of_date). - diff --git a/web/plugin/plugin.anubis b/web/plugin/plugin.anubis index 8c4a7e1..fb77ed8 100644 --- a/web/plugin/plugin.anubis +++ b/web/plugin/plugin.anubis @@ -7,9 +7,10 @@ */ read system/logger.anubis - read app/app_constants.anubis +read app/app_constants.anubis read calexium_lib/web/widgets/left_menu.anubis transmit calexium_lib/web/types/making_a_web_site.anubis +read calexium_lib/web/types/controllers_web_site.anubis read calexium_lib/web/widgets/menu.anubis read hayamiki_lib/model/database.anubis read hayamiki_lib/view/view_table_manager_types.anubis diff --git a/web/types/controllers_web_site.anubis b/web/types/controllers_web_site.anubis index 3cd8222..c020a48 100644 --- a/web/types/controllers_web_site.anubis +++ b/web/types/controllers_web_site.anubis @@ -6,7 +6,12 @@ * © David RENÉ */ -transmit CXM_web_session.anubis +read tools/printable_tree.anubis +transmit web_session.anubis +transmit calexium_lib/web/CXM_making_a_web_site.anubis + + + public type WEB_Controller_Result: http_answer( @@ -58,3 +63,22 @@ public type WEB_Controller_Result: // HTML_Partial_Content content // ) . + +public type WEB_Action: + web_action( + WEB_Action_Name name, // name of action + WEB_Action_Allowed_Protocol allowed_proto, + (WEB_Session) -> Bool allow, // true if action allowed + (WEB_Session) -> WEB_Controller_Result do_it + ) +. + + + +public type WEB_Controller: + web_controller( + String name, //controller name + Var(List(WEB_Action)) controller_actions, //list of all actions of that controller + (WEB_Session)-> WEB_Controller_Result error //Error renderer + ) +. diff --git a/web/types/web_session.anubis b/web/types/web_session.anubis new file mode 100644 index 0000000..f2a270e --- /dev/null +++ b/web/types/web_session.anubis @@ -0,0 +1,96 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 08/10/2019 + * Time: 18:01 + * © David RENÉ + */ + +read calexium_lib/web/CXM_common.anubis +read calexium_lib/database/db_types.anubis + +public type WEB_Session_Field_Datum: + string(String), //fully implented + bool(Bool), //fully implented + int(Int), //fully implemented + db_id(DB_id), + message(Message), //fully implemented + byte_array(ByteArray), + float(Float), + word128(Word128), + word64(Word64), + word32(Word32), + word16(Word16), + word8(Word8), + word4(Word4) + //WEB_Request +. + +public type WEB_Session_Field_Type: + string_t, + bool_t, + int_t, + db_id_t, + message_t, + byte_array_t, + float_t, + word128_t, + word64_t, + word32_t, + word16_t, + word8_t, + word4_t +. + +public type WEB_Session_Field: + session_field( + String field_name, + WEB_Session_Field_Type field_type, + Var(WEB_Session_Field_Datum) field_datum //Var because it can be replaced + ). + +public type WEB_Session_Field_No_Var: + session_field( + String field_name, + WEB_Session_Field_Type field_type, + WEB_Session_Field_Datum field_datum //Var because it can be replaced + ). + +public type WEB_Request: + web_request( + HTTP_Info http_info, + Var(List(Web_arg)) lwa, + Bool is_https, + ) +. + +public type WEB_Request_No_Var: + web_request( + HTTP_Info http_info, + List(Web_arg) lwa, + Bool is_https, + ) +. + +public type WEB_Session: + web_session( + String session_id, + String language, + Var(List(WEB_Session_Field)) fields, + WEB_Request web_request, + WEB_Request previous_web_request, + WEB_Request draw_web_request + ) +. + +public type WEB_Session_No_Var: + web_session( + String session_id, + String language, + List(WEB_Session_Field_No_Var) fields, + WEB_Request_No_Var web_request, + WEB_Request_No_Var previous_web_request, + WEB_Request_No_Var draw_web_request, + ) +. + -- libgit2 0.21.4