From 32f8435d8a643921caadf22d6eaac3af41665bb3 Mon Sep 17 00:00:00 2001 From: totoro Date: Tue, 20 Jun 2017 19:45:25 +0200 Subject: [PATCH] in web_session change lwa as Var in web_request add helper functions in for adding, removing and replacing web_arg in var list web_arg --- web/CXM_making_a_web_site.anubis | 32 ++++++++++++++++---------------- web/CXM_web_arg_utils.anubis | 40 ++++++++++++++++++++++++++++++++++++++++ web/CXM_web_session.anubis | 32 +++++++++++++++++++++++--------- 3 files changed, 79 insertions(+), 25 deletions(-) diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index cd6dfb6..54c6b7a 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -3445,14 +3445,14 @@ define (Maybe(WEB_Session), HTTP_Answer) WEB_Session _session, Maybe(String) _mb_action_name, (HTTP_Info, - List(Web_arg), + Var(List(Web_arg)), Bool is_https) -> WEB_Session initial_session, )= //get the action name with mb_action_name = if _mb_action_name is { - failure then get_String(_session.web_request.lwa, "aws_action"), + failure then get_String(*_session.web_request.lwa, "aws_action"), success(_an) then success(_an) }, @@ -3461,7 +3461,7 @@ define (Maybe(WEB_Session), HTTP_Answer) 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) is + if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers) 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, controllers, cinfo, new_session, failure, initial_session), @@ -3473,7 +3473,7 @@ define (Maybe(WEB_Session), HTTP_Answer) http_answer(session, answer) then (success(session), answer), http_answer(answer) then (success(_session), answer), redirect(new_session) then - if get_controller(get_String(new_session.web_request.lwa, "aws_controller", "root"), controllers) is + if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers) is { failure then (failure, error_page(http_not_found, "Redirect Controller not found", new_session)), success(new_controller) then apply_controller_action(new_controller, controllers, cinfo, new_session, failure, initial_session), @@ -3488,7 +3488,7 @@ define (Maybe(WEB_Session), HTTP_Answer) }, redirect_to_previous then - if get_controller(get_String(_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is + if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is { failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)), success(new_controller) then @@ -3496,7 +3496,7 @@ define (Maybe(WEB_Session), HTTP_Answer) apply_controller_action(new_controller, controllers, cinfo, web_session(lang, entries, previous, previous), failure, initial_session), }, redirect_to_previous(entries) then - if get_controller(get_String(_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is + if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is { failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)), success(new_controller) then @@ -3525,11 +3525,11 @@ public define Web_Site String state_directory, One -> One init, (HTTP_Info, - List(Web_arg), + Var(List(Web_arg)), Bool is_https) -> WEB_Session initial_session, (WEB_Session, HTTP_Info, - List(Web_arg), + Var(List(Web_arg)), Bool is_https) -> WEB_Session expired_session, Var(List(WEB_Controller)) web_controllers, Maybe(WEB_Session) -> List(HTTP_header) additional_headers, @@ -3567,10 +3567,10 @@ public define Web_Site // 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) |-> + ((String host_name, + HTTP_Info http_info, + List(Web_arg) _lwa, + Bool is_https) |-> //(Printable_tree) //println("host_name "+host_name); //println(dump_http_info(http_info)); @@ -3582,21 +3582,21 @@ public define Web_Site { not_found then //println("previous state not found"); - initial_session(http_info, _lwa, is_https), + initial_session(http_info, var(_lwa), is_https), out_of_date(previous_session) then //println("previous out_of_date"); - expired_session(previous_session, http_info, _lwa, is_https), + expired_session(previous_session, http_info, var(_lwa), is_https), still_valid(previous_session) then since previous_session is web_session(lang, entries, previous, _), - web_session(lang, entries, web_request(http_info, _lwa, is_https), previous) + web_session(lang, entries, web_request(http_info, var(_lwa), is_https), previous) }, //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) is + since if get_controller(get_String(*current_session.web_request.lwa, "aws_controller", "root"), *web_controllers) is { failure then (failure, error_page(http_not_found, "Controller not found", current_session)), diff --git a/web/CXM_web_arg_utils.anubis b/web/CXM_web_arg_utils.anubis index af3dd34..bac6ee9 100644 --- a/web/CXM_web_arg_utils.anubis +++ b/web/CXM_web_arg_utils.anubis @@ -9,6 +9,46 @@ transmit tools/basis.anubis transmit calexium_lib/web/CXM_common.anubis transmit calexium_lib/database/db_types.anubis + +public define One + add_web_arg + ( + Var(List(Web_arg)) lwa, + String arg_name, + String value + )= + lwa <- [ web_arg(arg_name, value) . *lwa] +. + +public define One + add_web_arg + ( + Var(List(Web_arg)) lwa, + Web_arg w_arg + )= + lwa <- [ w_arg . *lwa] +. + +public define One + remove_web_arg + ( + Var(List(Web_arg)) lwa, + String arg_name + )= + lwa <- map_select((Web_arg w_arg) |-> if w_arg is web_arg(name, value) then if name = arg_name then failure else success(w_arg) else success(w_arg), *lwa) +. + +public define One + replace_web_arg + ( + Var(List(Web_arg)) lwa, + String arg_name, + String value + )= + lwa <- map_select((Web_arg w_arg) |-> if w_arg is web_arg(name, value) then if name = arg_name then success(web_arg(name, value)) else success(w_arg) else success(w_arg), *lwa) +. + + public define Maybe(DB_id) get_mb_DB_id ( diff --git a/web/CXM_web_session.anubis b/web/CXM_web_session.anubis index ea035c6..01cd2ff 100644 --- a/web/CXM_web_session.anubis +++ b/web/CXM_web_session.anubis @@ -61,12 +61,20 @@ public type WEB_Session_Field_No_Var: 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 language, @@ -79,8 +87,8 @@ public type WEB_Session_No_Var: web_session( String language, List(WEB_Session_Field_No_Var) fields, - WEB_Request web_request, - WEB_Request previous_web_request + WEB_Request_No_Var web_request, + WEB_Request_No_Var previous_web_request ). public define Var(List(WEB_Session_Field)) @@ -119,8 +127,11 @@ public define WEB_Session ( WEB_Session_No_Var _session )= - since _session is web_session(language, fields, web_request, previous_web_request), - web_session(language, to_WEB_Session_Field(fields), web_request, previous_web_request) + since _session is web_session(language, fields, c_web_request, p_web_request), + web_session(language, to_WEB_Session_Field(fields), + web_request(c_web_request.http_info, var(c_web_request.lwa), c_web_request.is_https), + web_request(p_web_request.http_info, var(p_web_request.lwa), p_web_request.is_https) + ) . public define WEB_Session_No_Var @@ -128,8 +139,11 @@ public define WEB_Session_No_Var ( WEB_Session _session )= - since _session is web_session(language, fields, web_request, previous_web_request), - web_session(language, to_WEB_Session_Field_No_Var(*fields), web_request, previous_web_request) + since _session is web_session(language, fields, c_web_request, p_web_request), + web_session(language, to_WEB_Session_Field_No_Var(*fields), + web_request(c_web_request.http_info, *c_web_request.lwa, c_web_request.is_https), + web_request(p_web_request.http_info, *p_web_request.lwa, p_web_request.is_https) + ) . public define Maybe(WEB_Session_Field_Datum) @@ -1125,7 +1139,7 @@ public define String "http_info:\n"+ dump_http_info(web_request.http_info)+"\n"+ "web arguments:"+ - dump_web_arg_values(web_request.lwa)+"\n\n"+ + dump_web_arg_values(*web_request.lwa)+"\n\n"+ "-----------------------------------------------------------------------------\n"+ "Previous WEB REQUEST:\n"+ "-----------------------------------------------------------------------------\n"+ @@ -1133,6 +1147,6 @@ public define String "http_info:\n"+ dump_http_info(previous_web_request.http_info)+"\n"+ "web arguments:"+ - dump_web_arg_values(previous_web_request.lwa)+"\n" + dump_web_arg_values(*previous_web_request.lwa)+"\n" . -- libgit2 0.21.4