Commit a545b7e1c52a8daf4f578e5b706ea8c446b20a57

Authored by Alain Prouté
1 parent 284bceea

*** empty log message ***

anubis_dev/Makefile
... ... @@ -77,4 +77,4 @@ Anubis_PE_Linux:
77 77 cp $(HOME)/my_anubis/server_certs/georges* Anubis_PE_Linux/my_anubis/server_certs
78 78 cp $(HOME)/my_anubis/trusted_certs/* Anubis_PE_Linux/my_anubis/trusted_certs
79 79 cp $(HOME)/anubis/library/system_fonts/*.sf Anubis_PE_Linux/anubis/library/system_fonts
80   - cd Anubis_PE_Linux && tar -czf Anubis_PE_Linux_1_5_1.tar.gz my_anubis anubis
  80 + cd Anubis_PE_Linux && tar -czf Anubis_PE_Linux_1_5_2.tar.gz my_anubis anubis
... ...
anubis_dev/library/web/making_a_web_site.anubis
... ... @@ -387,7 +387,9 @@ public define Web_Site
387 387 List(String) journal_extensions,
388 388 List(String) journal_headers,
389 389 String authorization_secret,
390   - List(MIME) known_mime_types
  390 + List(MIME) known_mime_types,
  391 + (String action_name,
  392 + List(Web_arg) args)-> One before_send_file
391 393 ).
392 394  
393 395  
... ... @@ -436,6 +438,11 @@ public define Web_Site
436 438 entity not depending on $State. You should have a look to the private part of this file
437 439 if you want more precisions about this programming technique.
438 440  
  441 + 'before_send_file' is a function which is executed just before the HTTP server sends a
  442 + file. It gets an action name and the web arguments received with the request for that
  443 + file. Notice that this action name and these web arguments may be put into a
  444 + 'private_download' element, and will come back to the server at the time of the
  445 + download.
439 446  
440 447  
441 448  
... ... @@ -689,7 +696,8 @@ public type HTML_In_Form:
689 696 local_popup (Actioner_Aspect, HTML_In_Form content,
690 697 Int32 x, Int32 y, String title, RGB color, Int32 width),
691 698 foreign_link (String url, String name),
692   - private_download (String abs_path, String name, String extra_ext),
  699 + private_download (String abs_path, String name, String extra_ext,
  700 + Maybe((String,List((String,String)))) action),
693 701 text_input (String name, String init, Int32 width),
694 702 password_input (String name, Int32 width),
695 703 text_area (List(TextAreaOption), String name, String init, Int32 width, Int32 height),
... ... @@ -720,6 +728,30 @@ public define HTML_In_Form
720 728 table([],rows).
721 729  
722 730  
  731 +public define HTML_In_Form
  732 + private_download
  733 + (
  734 + String abs_path,
  735 + String name,
  736 + String extra_ext
  737 + ) =
  738 + private_download(abs_path,name,extra_ext,failure).
  739 +
  740 +public define HTML_In_Form
  741 + private_download
  742 + (
  743 + String abs_path,
  744 + String name,
  745 + String extra_ext,
  746 + String action_name,
  747 + List((String,String)) args
  748 + ) =
  749 + private_download(abs_path,name,extra_ext,success((action_name,args))).
  750 +
  751 +
  752 +
  753 +
  754 +
723 755 public type HTML_Off_Form:
724 756 literal (Printable_tree),
725 757 sequence (List(HTML_Off_Form) items),
... ... @@ -742,7 +774,8 @@ public type HTML_Off_Form:
742 774 local_popup (Actioner_Aspect, HTML_Off_Form content,
743 775 Int32 x, Int32 y, String title, RGB color, Int32 width),
744 776 foreign_link (String url, String name),
745   - private_download (String abs_path, String name, String extra_ext),
  777 + private_download (String abs_path, String name, String extra_ext,
  778 + Maybe((String,List((String,String)))) action),
746 779 form (String form_name, HTML_In_Form content).
747 780  
748 781 'HTML_Off_Form' defines all the elements you may put outside any form.
... ... @@ -773,6 +806,31 @@ public define HTML_Row(HTML_Off_Form)
773 806 ) =
774 807 row([],[cell([],content)]).
775 808  
  809 +
  810 +public define HTML_Off_Form
  811 + private_download
  812 + (
  813 + String abs_path,
  814 + String name,
  815 + String extra_ext
  816 + ) =
  817 + private_download(abs_path,name,extra_ext,failure).
  818 +
  819 +
  820 +public define HTML_Off_Form
  821 + private_download
  822 + (
  823 + String abs_path,
  824 + String name,
  825 + String extra_ext,
  826 + String action_name,
  827 + List((String,String)) args
  828 + ) =
  829 + private_download(abs_path,name,extra_ext,success((action_name,args))).
  830 +
  831 +
  832 +
  833 +
776 834 Notice that the two types have alternatives in common (same name, same arguments types,
777 835 up to the value of the parameter $T), which correspond to elements which may be put
778 836 anywhere in the page.
... ... @@ -1512,7 +1570,9 @@ public define Web_Site
1512 1570 List(String) journal_extensions,
1513 1571 List(String) journal_headers,
1514 1572 String secret,
1515   - List(MIME) known_mime_types
  1573 + List(MIME) known_mime_types,
  1574 + (String action_name,
  1575 + List(Web_arg) args) -> One before_send_file
1516 1576 ) =
1517 1577 init(hf87jdh23sqPjfYUGF7865GHTjf7);
1518 1578 //
... ... @@ -1596,7 +1656,14 @@ public define Web_Site
1596 1656 journal_headers,
1597 1657 secret,
1598 1658 known_mime_types,
1599   - site_handler(http_port,https_port)),
  1659 + site_handler(http_port,https_port),
  1660 + (List(Web_arg) lwa) |-> if separate_web_args(lwa) is
  1661 + swa(mb_previous_state,mb_action_name,operands) then
  1662 + if mb_action_name is
  1663 + {
  1664 + failure then unique
  1665 + success(an) then before_send_file(an,operands)
  1666 + }),
1600 1667 delete_out_of_date)}.
1601 1668  
1602 1669  
... ... @@ -1718,7 +1785,8 @@ type HTML_Any($T):
1718 1785 any_local_popup (Actioner_Aspect, $T content, Int32 x, Int32 y,
1719 1786 String title, RGB color, Int32 width),
1720 1787 any_foreign_link (String url, String name),
1721   - any_private_download (String abs_path, String name, String extra_ext).
  1788 + any_private_download (String abs_path, String name, String extra_ext,
  1789 + Maybe((String,List((String,String))))).
1722 1790  
1723 1791  
1724 1792  
... ... @@ -2237,17 +2305,26 @@ define Printable_tree
2237 2305 define Printable_tree
2238 2306 format_private_download
2239 2307 (
2240   - CommonInfo cinfo,
2241   - String sn, // state name
2242   - String abs_path, // absolute file path on server
2243   - String name, // name of file as it appears in the browser
2244   - String extra // extra extension
  2308 + CommonInfo cinfo,
  2309 + String sn, // state name
  2310 + String abs_path, // absolute file path on server
  2311 + String name, // name of file as it appears in the browser
  2312 + String extra, // extra extension
  2313 + Maybe((String,List((String,String)))) action
  2314 +
2245 2315 ) =
2246 2316 if cinfo is info(common_name,http_port,https_port,site_directory,secret,font) then
2247 2317 with private_download_directory = site_directory+"/private_download",
2248 2318 with auth = make_authorization(site_directory,secret,abs_path),
2249 2319 [
2250   - "<a href=\"",name,extra,"?zauth=",auth,"\">",
  2320 + "<a href=\"",name,extra,"?zauth=",auth,
  2321 + if action is
  2322 + {
  2323 + failure then [ ]
  2324 + success(a) then if a is (an,args) then
  2325 + ["&a=",an,format_extra_operands(args)]
  2326 + },
  2327 + "\">",
2251 2328 name,
2252 2329 "</a>"
2253 2330 ].
... ... @@ -2635,8 +2712,8 @@ define Printable_tree
2635 2712 ],
2636 2713 any_foreign_link(url,name) then
2637 2714 ["<a href=\"",url,"\">",name,"</a>"],
2638   - any_private_download(url,name,extra_ext) then
2639   - format_private_download(cinfo,sn,url,name,extra_ext)
  2715 + any_private_download(url,name,extra_ext,action) then
  2716 + format_private_download(cinfo,sn,url,name,extra_ext,action)
2640 2717 }.
2641 2718  
2642 2719  
... ... @@ -2686,8 +2763,8 @@ define Printable_tree
2686 2763 format(cinfo,sn,ic_v,any_local_popup(a,c,x,y,t,clr,w),format_element,is_https),
2687 2764 foreign_link(url,name) then
2688 2765 format(cinfo,sn,ic_v,any_foreign_link(url,name),format_element,is_https),
2689   - private_download(url,name,extra) then
2690   - format(cinfo,sn,ic_v,any_private_download(url,name,extra),format_element,is_https),
  2766 + private_download(url,name,extra,action) then
  2767 + format(cinfo,sn,ic_v,any_private_download(url,name,extra,action),format_element,is_https),
2691 2768 text_input(n,i,w) then
2692 2769 ["<input type=text name=o",n," size=",w," value=\"",i,"\">"],
2693 2770 //["&nbsp; <input type=text name=o",n," size=",w," value=\"",i,"\">"],
... ... @@ -2753,7 +2830,7 @@ define Bool
2753 2830 actioner(c,t,a,an,eo) then false,
2754 2831 local_popup(a,c,x,y,t,clr,w) then contains_an_upload(c),
2755 2832 foreign_link(u,n) then false,
2756   - private_download(p,n,e) then false,
  2833 + private_download(p,n,e,a) then false,
2757 2834 text_input(n,i,w) then false,
2758 2835 password_input(n,w) then false,
2759 2836 text_area(o,n,i,w,h) then false,
... ... @@ -2818,8 +2895,8 @@ define Printable_tree
2818 2895 format(cinfo,sn,ic_v,any_local_popup(a,c,x,y,t,clr,w),format_element,is_https),
2819 2896 foreign_link(url,name) then
2820 2897 format(cinfo,sn,ic_v,any_foreign_link(url,name),format_element,is_https),
2821   - private_download(url,name,extra) then
2822   - format(cinfo,sn,ic_v,any_private_download(url,name,extra),format_element,is_https),
  2898 + private_download(url,name,extra,action) then
  2899 + format(cinfo,sn,ic_v,any_private_download(url,name,extra,action),format_element,is_https),
2823 2900 form(fn,c) then
2824 2901 [
2825 2902 "<form name=\"f",fn,"\" method=POST",
... ...
anubis_dev/library/web/multihost_http_server.anubis
... ... @@ -187,7 +187,8 @@ public type Web_Site_Description:
187 187 List(MIME) known_mime_types,
188 188 (HTTP_Info http_info,
189 189 List(Web_arg) lwa,
190   - Bool is_https) -> Printable_tree awp_handler).
  190 + Bool is_https) -> Printable_tree awp_handler,
  191 + (List(Web_arg) lwa) -> One before_send_file).
191 192  
192 193 The component 'common_name' is the name of the site, like for example
193 194 "www.our-business.com". It is important that this name is exactly the same as the
... ... @@ -1767,8 +1768,10 @@ define One
1767 1768 List(HTTP_header) headers,
1768 1769 Int32 size,
1769 1770 Connection file,
1770   - String filename
  1771 + String filename,
  1772 + One -> One action_before_send_file
1771 1773 ) =
  1774 + action_before_send_file(unique);
1772 1775 forget(reliable_write(connection,to_byte_array("HTTP/1.1 200 OK"+crlf)));
1773 1776 forget(reliable_write(connection,format(headers)));
1774 1777 send_file_body(desc,connection,file,size,0,filename).
... ... @@ -1802,7 +1805,8 @@ define One
1802 1805 Web_Site_Description desc,
1803 1806 Connection connection,
1804 1807 String uri,
1805   - Maybe(String) mbauthorization
  1808 + Maybe(String) mbauthorization,
  1809 + One -> One action_before_send_file
1806 1810 ) =
1807 1811 if mbauthorization is
1808 1812 {
... ... @@ -1821,7 +1825,8 @@ define One
1821 1825 headers_for_send_file(mime_type,size),
1822 1826 size,
1823 1827 file(f),
1824   - uri)
  1828 + uri,
  1829 + action_before_send_file)
1825 1830 }
1826 1831 },
1827 1832  
... ... @@ -1849,7 +1854,8 @@ define One
1849 1854 size),
1850 1855 size,
1851 1856 file(f),
1852   - uri)
  1857 + uri,
  1858 + action_before_send_file)
1853 1859 }
1854 1860 )
1855 1861 else log_journal_msg(desc,"Cannot find or read authorization file.\n")
... ... @@ -1869,7 +1875,8 @@ define One
1869 1875 headers_for_send_file(mime_type,size),
1870 1876 size,
1871 1877 file(f),
1872   - uri)
  1878 + uri,
  1879 + action_before_send_file)
1873 1880 }
1874 1881 }
1875 1882 }.
... ... @@ -1969,7 +1976,8 @@ define One
1969 1976 {
1970 1977 not_found then failure,
1971 1978 found(v) then success(v)
1972   - }))).
  1979 + },
  1980 + (One u) |-> before_send_file(desc)(all_web_args)))).
1973 1981  
1974 1982  
1975 1983  
... ... @@ -2591,7 +2599,7 @@ define Maybe(Web_Site_Description)
2591 2599 {
2592 2600 [ ] then print("Requested host '"+requested_host+"' does not exist.\n"); failure,
2593 2601 [site1 . others] then
2594   - if site1 is web_site_description(common_name,_,_,_,_,_,_,_) then
  2602 + if site1 is web_site_description(common_name,_,_,_,_,_,_,_,_) then
2595 2603 if common_name = requested_host
2596 2604 then success(site1)
2597 2605 else get_site(requested_host,others)
... ...