Commit 961016680054c147ea2f748a84a3019e96c920d4

Authored by Cédric RICARD
1 parent 6fbf99a4

Modifying HTML doctype (HTML v4.0 --> XHTML 1.0)

Adding function to read http headers
calexium_lib/web/CXM_common.anubis
1 -  
2 - *Project* The Anubis Project  
3 - *Title* Some common stuff for the web.  
4 -  
5 - *Copyright* Copyright (c) Alain Prouté 2003.  
6 -  
7 -  
8 -  
9 - *Author* Alain Prouté  
10 -  
11 - *Public*  
12 - *Name* HTTP_header  
13 - *Description*  
14 - The type 'HTTP_header' describes HTTP headers, which are just pairs '(name,value)'.  
15 -  
16 -public type HTTP_header:  
17 - http_header(String name,  
18 - String value).  
19 -  
20 - *Name* Web_arg  
21 - *Description*  
22 -  
23 - The type 'Web_arg' describes 'web arguments'. A web argument is either a pair  
24 - '(name,value)' (for example it may be 'web_arg("password","foobar")', if the client  
25 - clicks on the submit button of a form containing a password input field named  
26 - 'password'), or an uploaded file. In this last case, it is a triplet containing the  
27 - name of the file upload input field, the value of this input field (name of the  
28 - uploaded file), and the name of the temporary file as saved by the server in its  
29 - 'upload temporary directory'; see 'web/http_server.anubis' and the 'upload' Web_item in  
30 - 'web/html.anubis').  
31 -  
32 -public type Web_arg:  
33 - web_arg(String name,  
34 - String value),  
35 - upload (String name, // name of corresponding 'upload' Web_item  
36 - String value, // name of uploaded file  
37 - String temp_file_path). // temporary file path (relative to server directory)  
38 -  
39 -  
40 - *Name* Web_arg_value  
41 - *Description*  
42 - Of course, within the body of a 'web page' operation, you may want to recover the value  
43 - of a particular web argument. To that end, use the operation 'web_arg_value', which  
44 - takes 2 argument:  
45 -  
46 - - the list of all web arguments (the operand of the web page operation),  
47 - - the name of the argument whose value is wanted.  
48 -  
49 - This operation has the following return type:  
50 -  
51 -public type Web_arg_value:  
52 - not_found,  
53 - found(String value).  
54 -  
55 - *Name* Web_arg_value  
56 - *Description*  
57 - If the requested argument name is not found in the list, 'not_found' is  
58 - returned. Otherwise, the value returned by 'web_arg_value' has the form 'found(v)',  
59 - where 'v' is the value of the argument.  
60 -  
61 - The operation 'web_arg_value' is defined below.  
62 -  
63 -public define Web_arg_value  
64 - web_arg_value  
65 - (  
66 - List(Web_arg) l,  
67 - String name  
68 - ) =  
69 - if l is  
70 - {  
71 - [ ] then not_found,  
72 - [h . t] then if h is  
73 - {  
74 - web_arg(n,v) then  
75 - if name=n  
76 - then found(v)  
77 - else web_arg_value(t,name),  
78 -  
79 - upload(n,v,tfn) then  
80 - if name=n  
81 - then found(v)  
82 - else web_arg_value(t,name)  
83 - }  
84 - }.  
85 -  
86 - *Ignore*  
87 -  
88 -public define Maybe((String,String))  
89 - file_upload_value  
90 - (  
91 - List(Web_arg) l,  
92 - String name  
93 - ) =  
94 - if l is  
95 - {  
96 - [ ] then failure,  
97 - [h . t] then if h is  
98 - {  
99 - web_arg(_,_) then file_upload_value(t,name),  
100 - upload(n,v,tfn) then  
101 - if n = name  
102 - then success((v,tfn))  
103 - else file_upload_value(t,name)  
104 - }  
105 - }.  
106 -  
107 -public type Redirection:  
108 - redirect(String required_uri, // URI required by the client  
109 - String required_host, // value of 'Host' HTTP header sent by the client  
110 - String corresponding_uri). // URI which will be served to the client  
111 -  
112 -  
113 -  
114 -  
115 - Now, you may also want to recover web argument values which have been encoded (by  
116 - 'web_arg_encode'). In this case, use the following:  
117 -  
118 -read CXM_web_arg_encode.anubis  
119 -  
120 -  
121 -public define Maybe($T)  
122 - decode_web_arg_value  
123 - (  
124 - List(Web_arg) l,  
125 - String name  
126 - ) =  
127 - if web_arg_value(l,name) is  
128 - {  
129 - not_found then failure,  
130 - found(v) then web_arg_decode(v)  
131 - }.  
132 -  
133 -public define List(String)  
134 - web_arg_list_values  
135 - (  
136 - List(Web_arg) l,  
137 - String name  
138 - ) =  
139 - if l is  
140 - {  
141 - [] then [],  
142 - [h . t] then  
143 - if h is web_arg(n, v) then  
144 - if n = name then  
145 - [ v . web_arg_list_values(t, name)]  
146 - else  
147 - web_arg_list_values(t, name)  
148 - else  
149 - web_arg_list_values(t, name)  
150 -  
151 - }  
152 - .  
153 -  
154 -public define String  
155 - dump_web_arg_values  
156 - (  
157 - List(Web_arg) l,  
158 - ) =  
159 - if l is  
160 - {  
161 - [ ] then "\n",  
162 - [h . t] then if h is  
163 - {  
164 - web_arg(n,v) then "\n["+n+"] = '"+v+"'" + dump_web_arg_values(t),  
165 - upload(n,v,tfn) then "\n["+n+"] = '"+v+"'" + dump_web_arg_values(t)  
166 - }  
167 - }. 1 +
  2 + *Project* The Anubis Project
  3 + *Title* Some common stuff for the web.
  4 +
  5 + *Copyright* Copyright (c) Alain Prouté 2003.
  6 +
  7 +
  8 +
  9 + *Author* Alain Prouté
  10 +
  11 + *Public*
  12 + *Name* HTTP_header
  13 + *Description*
  14 +
  15 +read system/String.anubis
  16 +
  17 +/**
  18 + * The type 'HTTP_header' describes HTTP headers, which are just pairs '(name,value)'.
  19 + */
  20 +public type HTTP_header:
  21 + http_header(String name,
  22 + String value).
  23 +
  24 +
  25 +public define Maybe(String)
  26 + http_header_value
  27 + (
  28 + List(HTTP_header) l,
  29 + String name
  30 + ) =
  31 + if l is
  32 + {
  33 + [ ] then failure,
  34 + [h . t] then if h is
  35 + {
  36 + http_header(n, v) then //print("DEBUG: http_header_value --> HEADER = " + n + ":" + v + "\n");
  37 + if insensitive_equal(name, n) then success(v)
  38 + else http_header_value(t, name),
  39 + }
  40 + }.
  41 +
  42 + *Name* Web_arg
  43 + *Description*
  44 +
  45 + The type 'Web_arg' describes 'web arguments'. A web argument is either a pair
  46 + '(name,value)' (for example it may be 'web_arg("password","foobar")', if the client
  47 + clicks on the submit button of a form containing a password input field named
  48 + 'password'), or an uploaded file. In this last case, it is a triplet containing the
  49 + name of the file upload input field, the value of this input field (name of the
  50 + uploaded file), and the name of the temporary file as saved by the server in its
  51 + 'upload temporary directory'; see 'web/http_server.anubis' and the 'upload' Web_item in
  52 + 'web/html.anubis').
  53 +
  54 +public type Web_arg:
  55 + web_arg(String name,
  56 + String value),
  57 + upload (String name, // name of corresponding 'upload' Web_item
  58 + String value, // name of uploaded file
  59 + String temp_file_path). // temporary file path (relative to server directory)
  60 +
  61 +
  62 + *Name* Web_arg_value
  63 + *Description*
  64 + Of course, within the body of a 'web page' operation, you may want to recover the value
  65 + of a particular web argument. To that end, use the operation 'web_arg_value', which
  66 + takes 2 argument:
  67 +
  68 + - the list of all web arguments (the operand of the web page operation),
  69 + - the name of the argument whose value is wanted.
  70 +
  71 + This operation has the following return type:
  72 +
  73 +public type Web_arg_value:
  74 + not_found,
  75 + found(String value).
  76 +
  77 + *Name* Web_arg_value
  78 + *Description*
  79 + If the requested argument name is not found in the list, 'not_found' is
  80 + returned. Otherwise, the value returned by 'web_arg_value' has the form 'found(v)',
  81 + where 'v' is the value of the argument.
  82 +
  83 + The operation 'web_arg_value' is defined below.
  84 +
  85 +public define Web_arg_value
  86 + web_arg_value
  87 + (
  88 + List(Web_arg) l,
  89 + String name
  90 + ) =
  91 + if l is
  92 + {
  93 + [ ] then not_found,
  94 + [h . t] then if h is
  95 + {
  96 + web_arg(n,v) then
  97 + if name=n
  98 + then found(v)
  99 + else web_arg_value(t,name),
  100 +
  101 + upload(n,v,tfn) then
  102 + if name=n
  103 + then found(v)
  104 + else web_arg_value(t,name)
  105 + }
  106 + }.
  107 +
  108 + *Ignore*
  109 +
  110 +public define Maybe((String,String))
  111 + file_upload_value
  112 + (
  113 + List(Web_arg) l,
  114 + String name
  115 + ) =
  116 + if l is
  117 + {
  118 + [ ] then failure,
  119 + [h . t] then if h is
  120 + {
  121 + web_arg(_,_) then file_upload_value(t,name),
  122 + upload(n,v,tfn) then
  123 + if n = name
  124 + then success((v,tfn))
  125 + else file_upload_value(t,name)
  126 + }
  127 + }.
  128 +
  129 +public type Redirection:
  130 + redirect(String required_uri, // URI required by the client
  131 + String required_host, // value of 'Host' HTTP header sent by the client
  132 + String corresponding_uri). // URI which will be served to the client
  133 +
  134 +
  135 +
  136 +
  137 + Now, you may also want to recover web argument values which have been encoded (by
  138 + 'web_arg_encode'). In this case, use the following:
  139 +
  140 +read CXM_web_arg_encode.anubis
  141 +
  142 +
  143 +public define Maybe($T)
  144 + decode_web_arg_value
  145 + (
  146 + List(Web_arg) l,
  147 + String name
  148 + ) =
  149 + if web_arg_value(l,name) is
  150 + {
  151 + not_found then failure,
  152 + found(v) then web_arg_decode(v)
  153 + }.
  154 +
  155 +public define List(String)
  156 + web_arg_list_values
  157 + (
  158 + List(Web_arg) l,
  159 + String name
  160 + ) =
  161 + if l is
  162 + {
  163 + [] then [],
  164 + [h . t] then
  165 + if h is web_arg(n, v) then
  166 + if n = name then
  167 + [ v . web_arg_list_values(t, name)]
  168 + else
  169 + web_arg_list_values(t, name)
  170 + else
  171 + web_arg_list_values(t, name)
  172 +
  173 + }
  174 + .
  175 +
  176 +public define String
  177 + dump_web_arg_values
  178 + (
  179 + List(Web_arg) l,
  180 + ) =
  181 + if l is
  182 + {
  183 + [ ] then "\n",
  184 + [h . t] then if h is
  185 + {
  186 + web_arg(n,v) then "\n["+n+"] = '"+v+"'" + dump_web_arg_values(t),
  187 + upload(n,v,tfn) then "\n["+n+"] = '"+v+"'" + dump_web_arg_values(t)
  188 + }
  189 + }.
calexium_lib/web/CXM_making_a_web_site.anubis
@@ -1463,8 +1463,8 @@ public define HTML_Page @@ -1463,8 +1463,8 @@ public define HTML_Page
1463 public define String 1463 public define String
1464 doctype_w3c_header 1464 doctype_w3c_header
1465 = 1465 =
1466 - "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" "+  
1467 - "\"http://www.w3c.org/TR/html4/loose.dtd\">\n". 1466 + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "+
  1467 + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".
1468 1468
1469 1469
1470 1470
@@ -2823,7 +2823,7 @@ define Printable_tree @@ -2823,7 +2823,7 @@ define Printable_tree
2823 ( 2823 (
2824 List(DIV_Option) options 2824 List(DIV_Option) options
2825 )= 2825 )=
2826 - ["<DIV" + _format(options) + ">"] . 2826 + ["<div" + _format(options) + ">"] .
2827 2827
2828 2828
2829 define Printable_tree 2829 define Printable_tree
@@ -3407,7 +3407,7 @@ define Printable_tree @@ -3407,7 +3407,7 @@ define Printable_tree
3407 ["<span ", format_text_options(opts), "><pre>",s,"</pre></span>"], 3407 ["<span ", format_text_options(opts), "><pre>",s,"</pre></span>"],
3408 //["<pre>",s,"</pre>"], 3408 //["<pre>",s,"</pre>"],
3409 any_paragraph(opts,t) then 3409 any_paragraph(opts,t) then
3410 - ["<p ", format_text_options(opts), ">",t,"</p>"], 3410 + ["<p ", format_text_options(opts), ">",t,"</p>\n"],
3411 any_image(url) then 3411 any_image(url) then
3412 ["<img alt=\"",url,"\" src=\"",url,"\">"], 3412 ["<img alt=\"",url,"\" src=\"",url,"\">"],
3413 any_image(url,w,h) then 3413 any_image(url,w,h) then
@@ -3415,7 +3415,7 @@ define Printable_tree @@ -3415,7 +3415,7 @@ define Printable_tree
3415 any_table(opts,h_row, rows) then 3415 any_table(opts,h_row, rows) then
3416 ["<table ",format(reverse(opts),false),">", 3416 ["<table ",format(reverse(opts),false),">",
3417 format(h_row,format_element), 3417 format(h_row,format_element),
3418 - format(rows,format_element),"</table>"], 3418 + format(rows,format_element),"</table>\n"],
3419 any_center(e) then 3419 any_center(e) then
3420 ["<center>",format_element(e),"</center>"], 3420 ["<center>",format_element(e),"</center>"],
3421 any_mail_to(email,elem) then 3421 any_mail_to(email,elem) then
@@ -3442,9 +3442,9 @@ define Printable_tree @@ -3442,9 +3442,9 @@ define Printable_tree
3442 any_private_download(url,name,extra_ext,action) then 3442 any_private_download(url,name,extra_ext,action) then
3443 format_private_download(cinfo,sn,url,name,extra_ext,action), 3443 format_private_download(cinfo,sn,url,name,extra_ext,action),
3444 any_div(options, e) then 3444 any_div(options, e) then
3445 - [format_div_option(options), format_element(e),"</DIV>"], 3445 + [format_div_option(options), format_element(e),"</div>\n"],
3446 any_div_empty(options) then 3446 any_div_empty(options) then
3447 - [format_div_option(options), "</DIV>"], 3447 + [format_div_option(options), "</div>\n"],
3448 any_coreattrs(attributs) then 3448 any_coreattrs(attributs) then
3449 [format_coreattrs(attributs)] 3449 [format_coreattrs(attributs)]
3450 }. 3450 }.
@@ -3723,16 +3723,16 @@ define Printable_tree @@ -3723,16 +3723,16 @@ define Printable_tree
3723 ) = 3723 ) =
3724 if m is 3724 if m is
3725 { 3725 {
3726 - keywords(l) then ["<meta name=\"keywords\" content=\"",format_keywords(l),"\">"], 3726 + keywords(l) then ["<meta name=\"keywords\" content=\"",format_keywords(l),"\">\n"],
3727 refresh(co,ta,an,delay) then 3727 refresh(co,ta,an,delay) then
3728 ["<meta http-equiv=\"Refresh\" content=\"",delay,"; URL=", 3728 ["<meta http-equiv=\"Refresh\" content=\"",delay,"; URL=",
3729 - make_actioner_url(cinfo,co,ta,state_name,an,[],is_https),"\">"],  
3730 - meta(n,c) then ["<meta name=\"",n,"\" content=\"",c,"\">"],  
3731 - http_equiv(n,c) then ["<meta http-equiv=\"",n,"\" content=\"",c,"\">"], 3729 + make_actioner_url(cinfo,co,ta,state_name,an,[],is_https),"\">\n"],
  3730 + meta(n,c) then ["<meta name=\"",n,"\" content=\"",c,"\">\n"],
  3731 + http_equiv(n,c) then ["<meta http-equiv=\"",n,"\" content=\"",c,"\">\n"],
3732 generic_meta(l) then ["<meta ", 3732 generic_meta(l) then ["<meta ",
3733 flat(map(((String,String) p) |-> if p is (n,v) then [n,"=\"",v,"\" "], 3733 flat(map(((String,String) p) |-> if p is (n,v) then [n,"=\"",v,"\" "],
3734 l)), 3734 l)),
3735 - ">"], 3735 + ">\n"],
3736 literal(s) then [s] 3736 literal(s) then [s]
3737 }. 3737 }.
3738 3738
@@ -3790,7 +3790,7 @@ define Printable_tree @@ -3790,7 +3790,7 @@ define Printable_tree
3790 { 3790 {
3791 [ ] then [ ], 3791 [ ] then [ ],
3792 [h . t] then 3792 [h . t] then
3793 - [ ["<LINK rel=\"stylesheet\" type=\"text/css\" href=" + file_name(h) + ">\n" ] 3793 + [ ["<link rel=\"stylesheet\" type=\"text/css\" href=\"" + file_name(h) + "\">\n" ]
3794 . add_css_files(t)] 3794 . add_css_files(t)]
3795 }. 3795 }.
3796 3796
@@ -3818,7 +3818,7 @@ define Printable_tree @@ -3818,7 +3818,7 @@ define Printable_tree
3818 [] then [], 3818 [] then [],
3819 [_._] then [ "<style type=\"text/css\"><!--\n", 3819 [_._] then [ "<style type=\"text/css\"><!--\n",
3820 format_css_styles(css_styles), 3820 format_css_styles(css_styles),
3821 - " --></style>" 3821 + " --></style>\n"
3822 ] 3822 ]
3823 }. 3823 }.
3824 3824
@@ -3838,12 +3838,12 @@ define Printable_tree @@ -3838,12 +3838,12 @@ define Printable_tree
3838 html_page(title,metas,css_styles, css_files, js_files, body) then 3838 html_page(title,metas,css_styles, css_files, js_files, body) then
3839 if body is body(options,element) then 3839 if body is body(options,element) then
3840 [ doctype_w3c_header, 3840 [ doctype_w3c_header,
3841 - "<html>",  
3842 - "<head>", 3841 + "<html>\n",
  3842 + "<head>\n",
3843 add_css_styles(css_styles), 3843 add_css_styles(css_styles),
3844 add_css_files(css_files), 3844 add_css_files(css_files),
3845 add_js_files(js_files), 3845 add_js_files(js_files),
3846 - "<link rel=\"shortcut icon\" href=\"favicon.ico\">", 3846 + "<link rel=\"shortcut icon\" href=\"favicon.ico\">\n",
3847 "<script type = \"text/javascript\" language=\"JavaScript\">", 3847 "<script type = \"text/javascript\" language=\"JavaScript\">",
3848 " function show_local_popup(divname,stvname) {", 3848 " function show_local_popup(divname,stvname) {",
3849 " if (document.layers) { var d = eval(document.divname); } else\n", 3849 " if (document.layers) { var d = eval(document.divname); } else\n",
@@ -3854,15 +3854,15 @@ define Printable_tree @@ -3854,15 +3854,15 @@ define Printable_tree
3854 " if (s[0]==0) ", 3854 " if (s[0]==0) ",
3855 " { s[0]=1; d.style.visibility = 'visible'; d.zIndex = 100; } else\n", 3855 " { s[0]=1; d.style.visibility = 'visible'; d.zIndex = 100; } else\n",
3856 " { s[0]=0; d.style.visibility = 'hidden'; }; }", 3856 " { s[0]=0; d.style.visibility = 'hidden'; }; }",
3857 - "</script>",  
3858 - "<title>",title,"</title>", // put title 3857 + "</script>\n",
  3858 + "<title>",title,"</title>\n", // put title
3859 format(cinfo,state_name,metas,is_https,charset), // format the metas 3859 format(cinfo,state_name,metas,is_https,charset), // format the metas
3860 - "</head>", 3860 + "</head>\n",
3861 "<body ", format(options), ">", // format body options 3861 "<body ", format(options), ">", // format body options
3862 //"<center>", 3862 //"<center>",
3863 format(cinfo,state_name,ic_v,element,is_https), 3863 format(cinfo,state_name,ic_v,element,is_https),
3864 //"</center>", 3864 //"</center>",
3865 - "</body>", 3865 + "</body>\n",
3866 "</html>" 3866 "</html>"
3867 ] 3867 ]
3868 }. 3868 }.