Commit 451b436d52605ee1f22916baf870e448f79f1d67

Authored by David RENE
1 parent 1b48e26b

finish the management of state by cookie: #827

CXM_cookies.anubis :
 server_get_cookies. Needs because HTTP header must be start by "Cookie" (server side)
CXM_making_a_web_site.anubis :
 Separated_Web_Args now handle state name by cookie.
 using_state_cookies has been definitively removed
calexium_lib/web/CXM_cookies.anubis
... ... @@ -474,8 +474,8 @@ define List(Cookie)
474 474 ) =
475 475 if read_cookie is
476 476 {
477   - failure then so_far,
478   - success(c) then read_cookies([c . so_far])
  477 + failure then so_far,
  478 + success(c) then read_cookies([c . so_far])
479 479 }.
480 480  
481 481  
... ... @@ -508,8 +508,36 @@ public define List(Cookie)
508 508 [h . t] then
509 509 append(get_cookies(server_name,h),get_cookies(server_name,t))
510 510 }.
  511 +
  512 +define List(Cookie)
  513 + server_get_cookies
  514 + (
  515 + HTTP_header h
  516 + ) =
  517 + if h is http_header(n,v) then
  518 + if to_lower(n) = "cookie"
  519 + then (
  520 + unput_atoms <- [];
  521 + input <- v;
  522 + index <- 0;
  523 + server_name <- "";
  524 + read_cookies([])
  525 + )
  526 + else [].
511 527  
512   -
  528 +public define List(Cookie)
  529 + server_get_cookies
  530 + (
  531 + // String server_name,
  532 + List(HTTP_header) headers
  533 + ) =
  534 + if headers is
  535 + {
  536 + [ ] then [ ],
  537 + [h . t] then
  538 + append(server_get_cookies(h), server_get_cookies(t))
  539 + }.
  540 +
513 541 public define Maybe(Cookie)
514 542 find_cookie
515 543 (
... ...
calexium_lib/web/CXM_html.anubis
... ... @@ -6,7 +6,7 @@
6 6  
7 7 read tools/basis.anubis
8 8 read system/string.anubis
9   -
  9 +read tools/printable_tree.anubis
10 10  
11 11  
12 12 *** Managing Web Arguments.
... ... @@ -837,7 +837,7 @@ define Printable_tree
837 837 ) = [(String)format_without_sharp(c)].
838 838  
839 839  
840   -define Printable_tree
  840 + define Printable_tree
841 841 [Word32 x . Printable_tree t]
842 842 =
843 843 [to_Int(x) . t].
... ...
calexium_lib/web/CXM_making_a_web_site.anubis
... ... @@ -51,7 +51,7 @@ read system/logger.anubis
51 51 read CXM_common.anubis
52 52 read CXM_multihost_http_server.anubis
53 53 read CXM_mime.anubis
54   -
  54 +read CXM_cookies.anubis
55 55  
56 56  
57 57 * (1) Structure of a web site.
... ... @@ -2057,49 +2057,54 @@ type Separated_Web_Args($State):
2057 2057  
2058 2058 The next function constructs the function which separates the web arguments.
2059 2059  
2060   -define (List(Web_arg) lwa) -> Separated_Web_Args($State)
  2060 +define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State)
2061 2061 make_separate_web_args_function
2062 2062 (
2063 2063 String state_directory,
2064 2064 String -> PreviousState($State) retrieve_state
2065 2065 ) =
2066   - (List(Web_arg) lwa) |-swaf->
2067   - if lwa is
2068   - {
2069   - [ ] then
  2066 + (List(Web_arg) lwa, HTTP_Info info) |-swaf->
  2067 + if lwa is
  2068 + {
  2069 + [ ] then
2070 2070 //
2071 2071 // no web arg found => no previous state and no action
2072 2072 //
2073   - swa(failure,failure,[]),
  2073 + if find_cookie("s", server_get_cookies(http_headers(info))) is
  2074 + {
  2075 + failure then swa(failure,failure,[]),
  2076 + success(cookie) then swa(success(retrieve_state(value(cookie))),failure,[])
  2077 + },
  2078 +
  2079 + //swa(failure,failure,[]),
2074 2080  
2075   - [wa_1 . wa_others] then
  2081 + [wa_1 . wa_others] then
2076 2082 //
2077 2083 // at least one web arg =>
2078 2084 // separate other web args, and insert the first one as needed
2079 2085 //
2080   - if (Separated_Web_Args($State))swaf(wa_others) is
2081   - {
2082   - swa(ps1, // possible previous state
2083   - an1, // maybe an action name
2084   - op1) // operands so far
2085   - then
2086   - if wa_1 is
2087   - {
2088   - web_arg(n, value) then
2089   - with name = if substr(n,0,4) = "amp;" then substr(n, 4, length(n) - 4) else n,
2090   - if name = "s" then
2091   - swa(success(retrieve_state(value)),an1,op1)
2092   - else if name = "a" then
2093   - swa(ps1,success(value),op1)
2094   - else if name = "t" then
2095   - swa(ps1,an1,[web_arg("target",value) . op1])
2096   - else
2097   - swa(ps1,an1,[web_arg(name,value) . op1]),
2098   -
2099   - upload(n,v,t) then
2100   - swa(ps1,an1,[wa_1 . op1])
2101   - }}
2102   - }.
  2086 + if (Separated_Web_Args($State))swaf(wa_others, info) is
  2087 + {
  2088 + swa(ps1, // possible previous state
  2089 + an1, // maybe an action name
  2090 + op1) // operands so far
  2091 + then
  2092 + if wa_1 is
  2093 + {
  2094 + web_arg(n, value) then
  2095 + with name = if substr(n,0,4) = "amp;" then substr(n, 4, length(n) - 4) else n,
  2096 + if name = "a" then
  2097 + swa(ps1,success(value),op1)
  2098 + else if name = "t" then
  2099 + swa(ps1,an1,[web_arg("target",value) . op1])
  2100 + else
  2101 + swa(ps1,an1,[web_arg(name,value) . op1]),
  2102 +
  2103 + upload(n,v,t) then
  2104 + swa(ps1,an1,[wa_1 . op1])
  2105 + }
  2106 + }
  2107 + }.
2103 2108  
2104 2109  
2105 2110  
... ... @@ -2277,8 +2282,8 @@ public define Web_Site
2277 2282 String secret,
2278 2283 List(MIME) known_mime_types,
2279 2284 (String action_name,
2280   - List(Web_arg) args) -> One before_send_file,
2281   - Bool using_state_cookies
  2285 + List(Web_arg) args) -> One before_send_file
  2286 + //Bool using_state_cookies
2282 2287 ) =
2283 2288 init(unique);
2284 2289  
... ... @@ -2306,7 +2311,7 @@ public define Web_Site
2306 2311 List(Web_arg) lwa,
2307 2312 Bool is_https) |->
2308 2313 (Printable_tree)
2309   - if separate_web_args(lwa) is
  2314 + if separate_web_args(lwa, http_info) is
2310 2315 {
2311 2316 swa(mb_previous_state,mb_action_name,operands) then
2312 2317 with state_and_headers = if mb_previous_state is
... ... @@ -2342,7 +2347,7 @@ public define Web_Site
2342 2347 },
2343 2348 if state_and_headers is (session_ticket, mb_new_state, headers) then
2344 2349 with state_name = save_state(mb_new_state),
2345   - with cookie_headers = if using_state_cookies then make_state_cookie_headers(state_name) else [],
  2350 + with cookie_headers = /* if using_state_cookies then */ make_state_cookie_headers(state_name) /*else [] */,
2346 2351 format(info(host_name, http_port, https_port, site_directory, secret),
2347 2352 state_name,
2348 2353 headers + cookie_headers,
... ... @@ -2369,14 +2374,14 @@ public define Web_Site
2369 2374 secret,
2370 2375 known_mime_types,
2371 2376 site_handler(http_port,https_port),
2372   - (List(Web_arg) lwa) |-> if separate_web_args(lwa) is
  2377 + (HTTP_Info http_info, List(Web_arg) lwa) |-> if separate_web_args(lwa, http_info ) is
2373 2378 swa(mb_previous_state,mb_action_name,operands) then
2374 2379 if mb_action_name is
2375 2380 {
2376 2381 failure then unique
2377 2382 success(an) then before_send_file(an,operands)
2378   - },
2379   - using_state_cookies
  2383 + }
  2384 + //using_state_cookies
2380 2385 ),
2381 2386 delete_out_of_date).
2382 2387  
... ... @@ -2886,7 +2891,7 @@ define String
2886 2891 http then "http://"+common_name+":"+http_port+"/",
2887 2892 https then "https://"+common_name+":"+https_port+"/",
2888 2893 } +
2889   - "?s=" + state_name + "&amp;a=" + action_name +
  2894 + "?a=" + action_name +
2890 2895 format_extra_operands(extra_ops),
2891 2896 if target is
2892 2897 {
... ...
calexium_lib/web/CXM_multihost_http_server.anubis
... ... @@ -210,8 +210,9 @@ public type Web_Site_Description:
210 210 HTTP_Info http_info,
211 211 List(Web_arg) lwa,
212 212 Bool is_https) -> (Printable_tree) awp_handler,
213   - (List(Web_arg) lwa) -> One before_send_file,
214   - Bool using_state_cookies,
  213 + (HTTP_Info http_info,
  214 + List(Web_arg) lwa) -> One before_send_file
  215 + //Bool using_state_cookies,
215 216 ).
216 217  
217 218 The component 'common_names' is the list of names of the site, like for example
... ... @@ -2353,6 +2354,7 @@ define One
2353 2354 read_www_url_encoded_web_args(to_string(body),0),
2354 2355 uri = uri(request_line),
2355 2356 ext = get_uri_extension(uri),
  2357 + http_inf = http_info(ip_addr, host_name, uri, headers, is_SSL(connection), generate_tt),
2356 2358 (if member(journal_extensions(desc),ext)
2357 2359 then log_journal_msg(desc,
2358 2360 format_request(desc,connection,request_line,headers,all_web_args))
... ... @@ -2361,7 +2363,7 @@ define One
2361 2363 then log_journal_msg(desc,"Received illegal URI: "+uri+"\n")
2362 2364 else (if (ext = ".awp" | ext = "")
2363 2365 then (with answer_headers_body = awp_handler(desc)(host_name,
2364   - http_info(ip_addr, host_name, uri, headers, is_SSL(connection), generate_tt),
  2366 + http_inf,
2365 2367 all_web_args,
2366 2368 is_SSL(connection)),
2367 2369 //print_delta("After page generation");
... ... @@ -2378,7 +2380,7 @@ define One
2378 2380 not_found then failure,
2379 2381 found(v) then success(v)
2380 2382 },
2381   - (One u) |-> before_send_file(desc)(all_web_args))
  2383 + (One u) |-> before_send_file(desc)(http_inf, all_web_args))
2382 2384 //print_delta("After sending file")
2383 2385 )).
2384 2386  
... ... @@ -3005,7 +3007,7 @@ define Maybe((String,Web_Site_Description))
3005 3007 {
3006 3008 [ ] then print("Requested host '"+requested_host+"' does not exist.\n"); failure,
3007 3009 [site1 . others] then
3008   - if site1 is web_site_description(common_names,_,_,_,_,_,_,_,_,_,_) then
  3010 + if site1 is web_site_description(common_names,_,_,_,_,_,_,_,_,_) then
3009 3011 if member(common_names,requested_host)
3010 3012 then success((requested_host,site1))
3011 3013 else get_site(requested_host,others)
... ...