Commit c8a2ef78e6cbbfa1faeea06e72c5b0d7d9bb8a25

Authored by David RENE
1 parent daef9747

http_action, https_action and http_https_action now return $State instead of (Ma…

…ybe($SessionTicket, Maybe($Sate), List(HTTP_header))
web/CXM_making_a_web_site.anubis
... ... @@ -230,22 +230,22 @@ read CXM_cookies.anubis
230 230 sub-boxes as there are actions. For this reason, we define the following type for
231 231 representing actions (where '$State' is the type representing session informations):
232 232  
233   -public type Web_Action($SessionTicket, $State):
  233 +public type Web_Action($State):
234 234 http_action (String name, // name of action
235   - (Maybe($State)) -> Bool allow, // true if action allowed
  235 + ($State) -> Bool allow, // true if action allowed
236 236 (HTTP_Info http_info,
237 237 List(Web_arg) web_args, // actually only 'operands' web arguments
238   - Maybe($State) state) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) do_it),
  238 + $State state) -> $State do_it),
239 239 https_action (String name, // name of action
240   - (Maybe($State)) -> Bool allow, // true if action allowed
  240 + ($State) -> Bool allow, // true if action allowed
241 241 (HTTP_Info http_info,
242 242 List(Web_arg) web_args, // actually only 'operands' web arguments
243   - Maybe($State) state) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) do_it),
  243 + $State state) -> $State do_it),
244 244 http_https_action (String name,
245   - (Maybe($State)) -> Bool allow, // true if action allowed
  245 + ($State) -> Bool allow,
246 246 (HTTP_Info http_info,
247 247 List(Web_arg) web_args,
248   - Maybe($State) state) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) do_it).
  248 + $State state) -> $State do_it).
249 249  
250 250 'http_action's are executed only under HTTP, and 'https_action's are executed only
251 251 under HTTPS. 'http_https_action's may be executed under both types of connections.
... ... @@ -431,17 +431,18 @@ public define Web_Site
431 431 String site_directory, // where 'public' and other directories are
432 432 // located (should NOT end with '/')
433 433 One -> One init,
434   - (HTTP_Info) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) initial_state,
  434 + (HTTP_Info) -> $State initial_state,
435 435 ($State expired,
436 436 HTTP_Info,
437 437 List(Web_arg),
438   - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_expired_state,
  438 + Bool is_https) -> $State ticket_expired_state,
439 439 (HTTP_Info,
440 440 List(Web_arg),
441   - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_lost_state,
442   - List(Web_Action($SessionTicket, $State)) actions,
443   - (Maybe($SessionTicket), Maybe($State), String state_name, List(Web_arg) lwa) -> HTTP_Answer compute_page,
444   - Int timeout, // seconds (todo: minutes)
  441 + Bool is_https) -> $State ticket_lost_state,
  442 + List(Web_Action($State)) actions,
  443 + $State -> HTTP_Answer compute_page,
  444 + $State -> List(HTTP_header) additional_headers,
  445 + Int timeout, // seconds (todo: minutes)
445 446 List(Redirection) redirections,
446 447 String charset,
447 448 List(String) journal_extensions,
... ... @@ -512,7 +513,7 @@ public define Web_Site
512 513  
513 514 ** (2.2) Directories on the server's disk.
514 515  
515   - The description of you site contains the name of the directory within which the
  516 + The description of your site contains the name of the directory within which the
516 517 required files are located. This may be for example:
517 518  
518 519 my_anubis/web_sites/www.our-business.com/
... ... @@ -1799,24 +1800,19 @@ read CXM_web_arg_encode.anubis
1799 1800 The tool below constructs the function which is able to save a state on the server's
1800 1801 disk.
1801 1802  
1802   -define (Maybe($State) s) -> String // the function constructed returns the name of the state
  1803 +define ($State s) -> String // the function constructed returns the name of the state
1803 1804 make_save_state_function
1804 1805 (
1805 1806 Int timeout,
1806 1807 String state_directory
1807 1808 ) =
1808   - (Maybe($State) mbs) |->
1809   - if mbs is
1810   - {
1811   - failure then "",
1812   - success(s) then
  1809 + ($State s) |->
1813 1810 with time_stamp = now+timeout,
1814 1811 to_be_saved = (time_stamp,s),
1815 1812 state_name = web_arg_encode(sha1(s)),
1816 1813 if save(to_be_saved,state_directory+"/s"+state_name) is ok
1817 1814 then state_name
1818   - else (print("Cannot create state file in '"+state_directory+"'.\n"); "")
1819   - }.
  1815 + else (print("Cannot create state file in '"+state_directory+"'.\n"); "").
1820 1816  
1821 1817  
1822 1818 When a request arrives, we need to retrieve the previous state from the server's
... ... @@ -2076,9 +2072,9 @@ define Int
2076 2072 The result of the separation of the web arguments is of type:
2077 2073  
2078 2074 type Separated_Web_Args($State):
2079   - swa(Maybe(PreviousState($State)) previous_state,
2080   - Maybe(String) action_name,
2081   - List(Web_arg) operands).
  2075 + swa(PreviousState($State) previous_state,
  2076 + Maybe(String) action_name,
  2077 + List(Web_arg) operands).
2082 2078  
2083 2079  
2084 2080  
... ... @@ -2099,8 +2095,8 @@ define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State)
2099 2095 //
2100 2096 if find_cookie("s", server_get_cookies(http_headers(info))) is
2101 2097 {
2102   - failure then swa(failure,failure,[]),
2103   - success(cookie) then swa(success(retrieve_state(value(cookie))),failure,[])
  2098 + failure then swa(not_found,failure,[]),
  2099 + success(cookie) then swa(retrieve_state(value(cookie)),failure,[])
2104 2100 },
2105 2101  
2106 2102 //swa(failure,failure,[]),
... ... @@ -2147,26 +2143,26 @@ define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State)
2147 2143 arrives through the HTTPS channel and conversely.
2148 2144  
2149 2145  
2150   -define (Maybe($State) previous,
2151   - String action_name,
2152   - HTTP_Info http_info,
2153   - List(Web_arg) lwa,
2154   - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header))
  2146 +define ($State previous,
  2147 + String action_name,
  2148 + HTTP_Info http_info,
  2149 + List(Web_arg) lwa,
  2150 + Bool is_https) -> $State
2155 2151 make_apply_action_function
2156 2152 (
2157   - List(Web_Action($SessionTicket, $State)) actions_list
  2153 + List(Web_Action($State)) actions_list
2158 2154 ) =
2159 2155 with f =
2160   - (Maybe($State) previous,
  2156 + ($State previous,
2161 2157 String action_name,
2162 2158 HTTP_Info http_info,
2163 2159 List(Web_arg) lwa,
2164 2160 Bool is_https,
2165   - List(Web_Action($SessionTicket, $State)) actions) |-f->
  2161 + List(Web_Action($State)) actions) |-f->
2166 2162 if actions is
2167 2163 {
2168   - [ ] then (print("action '"+action_name+
2169   - "' not found.\n"); (failure, previous, [])),
  2164 + [ ] then print("action '"+action_name+
  2165 + "' not found.\n"); previous,
2170 2166 [ac1 . others] then if ac1 is
2171 2167 {
2172 2168 http_action(an,allow,do_it) then
... ... @@ -2174,10 +2170,10 @@ define (Maybe($State) previous,
2174 2170 then if is_https
2175 2171 then (print("HTTP action '"+an+
2176 2172 "' called through HTTPS (denied).\n");
2177   - (failure, previous, []))
  2173 + previous)
2178 2174 else if allow(previous)
2179 2175 then do_it(http_info,lwa,previous)
2180   - else (failure, previous, [])
  2176 + else previous
2181 2177 else f(previous,action_name,http_info,lwa,is_https,others),
2182 2178  
2183 2179 https_action(an,allow,do_it) then
... ... @@ -2185,26 +2181,26 @@ define (Maybe($State) previous,
2185 2181 then if is_https
2186 2182 then if allow(previous)
2187 2183 then do_it(http_info,lwa,previous)
2188   - else (failure, previous, [])
  2184 + else previous
2189 2185 else (print("HTTPS action '"+an+
2190 2186 "' called through HTTP (denied).\n");
2191   - (failure, previous, []))
  2187 + previous)
2192 2188 else f(previous,action_name,http_info,lwa,is_https,others),
2193 2189  
2194 2190 http_https_action(an,allow,do_it) then
2195 2191 if an = action_name
2196 2192 then if allow(previous)
2197 2193 then do_it(http_info,lwa,previous)
2198   - else (failure, previous, [])
  2194 + else previous
2199 2195 else f(previous,action_name,http_info,lwa,is_https,others),
2200 2196  
2201 2197 }
2202 2198 },
2203   - (Maybe($State) previous,
2204   - String action_name,
2205   - HTTP_Info http_info,
2206   - List(Web_arg) lwa,
2207   - Bool is_https) |->
  2199 + ($State previous,
  2200 + String action_name,
  2201 + HTTP_Info http_info,
  2202 + List(Web_arg) lwa,
  2203 + Bool is_https) |->
2208 2204 f(previous, action_name, http_info, lwa, is_https, actions_list).
2209 2205  
2210 2206  
... ... @@ -2289,20 +2285,21 @@ public define Web_Site
2289 2285 One -> One init,
2290 2286 (HTTP_Info,
2291 2287 List(Web_arg),
2292   - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) initial_state,
  2288 + Bool is_https) -> $State initial_state,
2293 2289 ($State expired,
2294 2290 Maybe(String),
2295 2291 HTTP_Info,
2296 2292 List(Web_arg),
2297   - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_expired_state,
  2293 + Bool is_https) -> $State ticket_expired_state,
2298 2294 (Maybe(String),
2299 2295 HTTP_Info,
2300 2296 List(Web_arg),
2301   - Bool is_https) -> (Maybe($SessionTicket), Maybe($State), List(HTTP_header)) ticket_lost_state,
2302   - List(Web_Action($SessionTicket, $State)) actions,
2303   - (Maybe($SessionTicket), Maybe($State), String state_name, List(Web_arg) lwa) -> HTTP_Answer compute_page,
2304   - Int timeout,
2305   - Redirections redirections,
  2297 + Bool is_https) -> $State ticket_lost_state,
  2298 + List(Web_Action($State)) actions,
  2299 + $State -> HTTP_Answer compute_page,
  2300 + $State -> List(HTTP_header) additional_headers,
  2301 + Int timeout,
  2302 + Redirections redirections,
2306 2303 String charset,
2307 2304 List(String) journal_extensions,
2308 2305 List(String) journal_headers,
... ... @@ -2337,21 +2334,12 @@ public define Web_Site
2337 2334 HTTP_Info http_info,
2338 2335 List(Web_arg) lwa,
2339 2336 Bool is_https) |->
2340   - (Printable_tree)
  2337 + //(Printable_tree)
2341 2338 if separate_web_args(lwa, http_info) is
2342 2339 {
2343 2340 swa(mb_previous_state,mb_action_name,operands) then
2344   - with state_and_headers = if mb_previous_state is
  2341 + with new_state = if mb_previous_state is
2345 2342 {
2346   - failure then
2347   - if mb_action_name is
2348   - {
2349   - failure then initial_state(http_info, operands, is_https),
2350   - success(action_name) then
2351   - apply_action(failure,action_name,http_info,operands,is_https)
2352   - },
2353   - success(previous_state) then if previous_state is
2354   - {
2355 2343 not_found then
2356 2344 if mb_action_name is
2357 2345 {
... ... @@ -2366,19 +2354,18 @@ public define Web_Site
2366 2354 still_valid(state) then
2367 2355 if mb_action_name is
2368 2356 {
2369   - failure then (failure, success(state), []),
  2357 + failure then state,
2370 2358 success(action_name) then
2371   - apply_action(success(state),action_name,http_info,operands,is_https)
  2359 + apply_action(state,action_name,http_info,operands,is_https)
2372 2360 }
2373   - }
2374   - },
2375   - if state_and_headers is (session_ticket, mb_new_state, headers) then
2376   - with state_name = save_state(mb_new_state),
  2361 + },
  2362 + //if state_and_headers is (session_ticket, mb_new_state, headers) then
  2363 + with state_name = save_state(new_state),
2377 2364 with cookie_headers = /* if using_state_cookies then */ make_state_cookie_headers(state_name) /*else [] */,
2378   - format(info(host_name, http_port, https_port, site_directory, secret),
  2365 + format(info(host_name, http_port, https_port, site_directory, secret),
2379 2366 state_name,
2380   - headers + cookie_headers,
2381   - compute_page(session_ticket, mb_new_state, state_name, operands),
  2367 + additional_headers(new_state) + cookie_headers,
  2368 + compute_page(new_state),
2382 2369 is_https,
2383 2370 charset)
2384 2371 }),
... ... @@ -3525,19 +3512,7 @@ define String
3525 3512  
3526 3513  
3527 3514 Normalizing a list of cell options (horizontal position must be specified; the default
3528   - is 'left').
3529   -
3530   -define List(Cell_Option)
3531   - normalize
3532   - (
3533   - List(Cell_Option) l
3534   - ) =
3535   - if member(l,left) then l else
3536   - if member(l,h_center) then l else
3537   - if member(l,right) then l else
3538   - //[left . l]. CR: why ? there is no default because we can use CSS
3539   - l.
3540   -
  3515 + is 'left').
3541 3516  
3542 3517 Formating cells in a row.
3543 3518  
... ... @@ -3551,7 +3526,7 @@ define Printable_tree
3551 3526 {
3552 3527 [ ] then [ ],
3553 3528 [h . t] then if h is cell(options,element) then
3554   - ["<td",format(reverse(normalize(options))),">",
  3529 + ["<td",format(reverse(options)),">",
3555 3530 format_element(element),
3556 3531 "</td>"
3557 3532 . format(t,format_element)]
... ... @@ -3567,7 +3542,7 @@ define Printable_tree
3567 3542 {
3568 3543 [ ] then [ ],
3569 3544 [h . t] then if h is header_cell(options,element) then
3570   - ["<th ",format(reverse(normalize(options))),">",
  3545 + ["<th ",format(reverse(options)),">",
3571 3546 format_element(element),
3572 3547 "</th>"
3573 3548 . format(t,format_element)]
... ...
web/CXM_multihost_http_server.anubis
... ... @@ -209,7 +209,8 @@ public type Web_Site_Description:
209 209 (String host_name,
210 210 HTTP_Info http_info,
211 211 List(Web_arg) lwa,
212   - Bool is_https) -> (Printable_tree) awp_handler,
  212 + Bool is_https) -> (//List(HTTP_header),
  213 + Printable_tree) awp_handler,
213 214 (HTTP_Info http_info,
214 215 List(Web_arg) lwa) -> One before_send_file
215 216 //Bool using_state_cookies,
... ...