From c8a2ef78e6cbbfa1faeea06e72c5b0d7d9bb8a25 Mon Sep 17 00:00:00 2001 From: David RENE Date: Sun, 26 Aug 2012 14:26:48 +0000 Subject: [PATCH] http_action, https_action and http_https_action now return $State instead of (Maybe($SessionTicket, Maybe($Sate), List(HTTP_header)) --- web/CXM_making_a_web_site.anubis | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------- web/CXM_multihost_http_server.anubis | 3 ++- 2 files changed, 66 insertions(+), 90 deletions(-) diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index 3df0cd8..c98ac12 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -230,22 +230,22 @@ read CXM_cookies.anubis sub-boxes as there are actions. For this reason, we define the following type for representing actions (where '$State' is the type representing session informations): -public type Web_Action($SessionTicket, $State): +public type Web_Action($State): http_action (String name, // name of action - (Maybe($State)) -> Bool allow, // true if action allowed + ($State) -> Bool allow, // true if action allowed (HTTP_Info http_info, List(Web_arg) web_args, // actually only 'operands' web arguments - Maybe($State) state) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) do_it), + $State state) -> $State do_it), https_action (String name, // name of action - (Maybe($State)) -> Bool allow, // true if action allowed + ($State) -> Bool allow, // true if action allowed (HTTP_Info http_info, List(Web_arg) web_args, // actually only 'operands' web arguments - Maybe($State) state) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) do_it), + $State state) -> $State do_it), http_https_action (String name, - (Maybe($State)) -> Bool allow, // true if action allowed + ($State) -> Bool allow, (HTTP_Info http_info, List(Web_arg) web_args, - Maybe($State) state) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) do_it). + $State state) -> $State do_it). 'http_action's are executed only under HTTP, and 'https_action's are executed only under HTTPS. 'http_https_action's may be executed under both types of connections. @@ -431,17 +431,18 @@ public define Web_Site String site_directory, // where 'public' and other directories are // located (should NOT end with '/') One -> One init, - (HTTP_Info) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) initial_state, + (HTTP_Info) -> $State initial_state, ($State expired, HTTP_Info, List(Web_arg), - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_expired_state, + Bool is_https) -> $State ticket_expired_state, (HTTP_Info, List(Web_arg), - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_lost_state, - List(Web_Action($SessionTicket, $State)) actions, - (Maybe($SessionTicket), Maybe($State), String state_name, List(Web_arg) lwa) -> HTTP_Answer compute_page, - Int timeout, // seconds (todo: minutes) + Bool is_https) -> $State ticket_lost_state, + List(Web_Action($State)) actions, + $State -> HTTP_Answer compute_page, + $State -> List(HTTP_header) additional_headers, + Int timeout, // seconds (todo: minutes) List(Redirection) redirections, String charset, List(String) journal_extensions, @@ -512,7 +513,7 @@ public define Web_Site ** (2.2) Directories on the server's disk. - The description of you site contains the name of the directory within which the + The description of your site contains the name of the directory within which the required files are located. This may be for example: my_anubis/web_sites/www.our-business.com/ @@ -1799,24 +1800,19 @@ read CXM_web_arg_encode.anubis The tool below constructs the function which is able to save a state on the server's disk. -define (Maybe($State) s) -> String // the function constructed returns the name of the state +define ($State s) -> String // the function constructed returns the name of the state make_save_state_function ( Int timeout, String state_directory ) = - (Maybe($State) mbs) |-> - if mbs is - { - failure then "", - success(s) then + ($State s) |-> with time_stamp = now+timeout, to_be_saved = (time_stamp,s), state_name = web_arg_encode(sha1(s)), if save(to_be_saved,state_directory+"/s"+state_name) is ok then state_name - else (print("Cannot create state file in '"+state_directory+"'.\n"); "") - }. + else (print("Cannot create state file in '"+state_directory+"'.\n"); ""). When a request arrives, we need to retrieve the previous state from the server's @@ -2076,9 +2072,9 @@ define Int The result of the separation of the web arguments is of type: type Separated_Web_Args($State): - swa(Maybe(PreviousState($State)) previous_state, - Maybe(String) action_name, - List(Web_arg) operands). + swa(PreviousState($State) previous_state, + Maybe(String) action_name, + List(Web_arg) operands). @@ -2099,8 +2095,8 @@ define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State) // if find_cookie("s", server_get_cookies(http_headers(info))) is { - failure then swa(failure,failure,[]), - success(cookie) then swa(success(retrieve_state(value(cookie))),failure,[]) + failure then swa(not_found,failure,[]), + success(cookie) then swa(retrieve_state(value(cookie)),failure,[]) }, //swa(failure,failure,[]), @@ -2147,26 +2143,26 @@ define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State) arrives through the HTTPS channel and conversely. -define (Maybe($State) previous, - String action_name, - HTTP_Info http_info, - List(Web_arg) lwa, - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) +define ($State previous, + String action_name, + HTTP_Info http_info, + List(Web_arg) lwa, + Bool is_https) -> $State make_apply_action_function ( - List(Web_Action($SessionTicket, $State)) actions_list + List(Web_Action($State)) actions_list ) = with f = - (Maybe($State) previous, + ($State previous, String action_name, HTTP_Info http_info, List(Web_arg) lwa, Bool is_https, - List(Web_Action($SessionTicket, $State)) actions) |-f-> + List(Web_Action($State)) actions) |-f-> if actions is { - [ ] then (print("action '"+action_name+ - "' not found.\n"); (failure, previous, [])), + [ ] then print("action '"+action_name+ + "' not found.\n"); previous, [ac1 . others] then if ac1 is { http_action(an,allow,do_it) then @@ -2174,10 +2170,10 @@ define (Maybe($State) previous, then if is_https then (print("HTTP action '"+an+ "' called through HTTPS (denied).\n"); - (failure, previous, [])) + previous) else if allow(previous) then do_it(http_info,lwa,previous) - else (failure, previous, []) + else previous else f(previous,action_name,http_info,lwa,is_https,others), https_action(an,allow,do_it) then @@ -2185,26 +2181,26 @@ define (Maybe($State) previous, then if is_https then if allow(previous) then do_it(http_info,lwa,previous) - else (failure, previous, []) + else previous else (print("HTTPS action '"+an+ "' called through HTTP (denied).\n"); - (failure, previous, [])) + previous) else f(previous,action_name,http_info,lwa,is_https,others), http_https_action(an,allow,do_it) then if an = action_name then if allow(previous) then do_it(http_info,lwa,previous) - else (failure, previous, []) + else previous else f(previous,action_name,http_info,lwa,is_https,others), } }, - (Maybe($State) previous, - String action_name, - HTTP_Info http_info, - List(Web_arg) lwa, - Bool is_https) |-> + ($State previous, + String action_name, + HTTP_Info http_info, + List(Web_arg) lwa, + Bool is_https) |-> f(previous, action_name, http_info, lwa, is_https, actions_list). @@ -2289,20 +2285,21 @@ public define Web_Site One -> One init, (HTTP_Info, List(Web_arg), - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) initial_state, + Bool is_https) -> $State initial_state, ($State expired, Maybe(String), HTTP_Info, List(Web_arg), - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_expired_state, + Bool is_https) -> $State ticket_expired_state, (Maybe(String), HTTP_Info, List(Web_arg), - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_lost_state, - List(Web_Action($SessionTicket, $State)) actions, - (Maybe($SessionTicket), Maybe($State), String state_name, List(Web_arg) lwa) -> HTTP_Answer compute_page, - Int timeout, - Redirections redirections, + Bool is_https) -> $State ticket_lost_state, + List(Web_Action($State)) actions, + $State -> HTTP_Answer compute_page, + $State -> List(HTTP_header) additional_headers, + Int timeout, + Redirections redirections, String charset, List(String) journal_extensions, List(String) journal_headers, @@ -2337,21 +2334,12 @@ public define Web_Site HTTP_Info http_info, List(Web_arg) lwa, Bool is_https) |-> - (Printable_tree) + //(Printable_tree) if separate_web_args(lwa, http_info) is { swa(mb_previous_state,mb_action_name,operands) then - with state_and_headers = if mb_previous_state is + with new_state = if mb_previous_state is { - failure then - if mb_action_name is - { - failure then initial_state(http_info, operands, is_https), - success(action_name) then - apply_action(failure,action_name,http_info,operands,is_https) - }, - success(previous_state) then if previous_state is - { not_found then if mb_action_name is { @@ -2366,19 +2354,18 @@ public define Web_Site still_valid(state) then if mb_action_name is { - failure then (failure, success(state), []), + failure then state, success(action_name) then - apply_action(success(state),action_name,http_info,operands,is_https) + apply_action(state,action_name,http_info,operands,is_https) } - } - }, - if state_and_headers is (session_ticket, mb_new_state, headers) then - with state_name = save_state(mb_new_state), + }, + //if state_and_headers is (session_ticket, mb_new_state, headers) then + with state_name = save_state(new_state), with cookie_headers = /* if using_state_cookies then */ make_state_cookie_headers(state_name) /*else [] */, - format(info(host_name, http_port, https_port, site_directory, secret), + format(info(host_name, http_port, https_port, site_directory, secret), state_name, - headers + cookie_headers, - compute_page(session_ticket, mb_new_state, state_name, operands), + additional_headers(new_state) + cookie_headers, + compute_page(new_state), is_https, charset) }), @@ -3525,19 +3512,7 @@ define String Normalizing a list of cell options (horizontal position must be specified; the default - is 'left'). - -define List(Cell_Option) - normalize - ( - List(Cell_Option) l - ) = - if member(l,left) then l else - if member(l,h_center) then l else - if member(l,right) then l else - //[left . l]. CR: why ? there is no default because we can use CSS - l. - + is 'left'). Formating cells in a row. @@ -3551,7 +3526,7 @@ define Printable_tree { [ ] then [ ], [h . t] then if h is cell(options,element) then - ["", + ["", format_element(element), "" . format(t,format_element)] @@ -3567,7 +3542,7 @@ define Printable_tree { [ ] then [ ], [h . t] then if h is header_cell(options,element) then - ["", + ["", format_element(element), "" . format(t,format_element)] diff --git a/web/CXM_multihost_http_server.anubis b/web/CXM_multihost_http_server.anubis index 9ec144c..b0bc12c 100644 --- a/web/CXM_multihost_http_server.anubis +++ b/web/CXM_multihost_http_server.anubis @@ -209,7 +209,8 @@ public type Web_Site_Description: (String host_name, HTTP_Info http_info, List(Web_arg) lwa, - Bool is_https) -> (Printable_tree) awp_handler, + Bool is_https) -> (//List(HTTP_header), + Printable_tree) awp_handler, (HTTP_Info http_info, List(Web_arg) lwa) -> One before_send_file //Bool using_state_cookies, -- libgit2 0.21.4