From 3bada9349f578d1a39a4e634d0d564f175aeef84 Mon Sep 17 00:00:00 2001 From: totoro Date: Sat, 4 Feb 2017 18:30:50 +0100 Subject: [PATCH] add minimal web site as example with calexium_lib --- examples.ide | 18 ++++++++++++++++++ examples/minimal_web_site.anubis | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ minimal_web_site.aproj | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ web/CXM_common.anubis | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------- web/CXM_json.anubis | 2 +- web/CXM_making_a_web_site.anubis | 22 +++++++++++----------- 6 files changed, 425 insertions(+), 73 deletions(-) create mode 100644 examples.ide create mode 100644 examples/minimal_web_site.anubis create mode 100644 minimal_web_site.aproj diff --git a/examples.ide b/examples.ide new file mode 100644 index 0000000..1deee12 --- /dev/null +++ b/examples.ide @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +# SharpDevelop 1.0.12.108 +Project("{B6712916-30DE-4a3e-A54C-2A79AC984AEE}") = "minimal_web_site", "minimal_web_site.aproj", "{F2C65267-0D20-4964-A5D8-602BD42C01A4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F2C65267-0D20-4964-A5D8-602BD42C01A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F2C65267-0D20-4964-A5D8-602BD42C01A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F2C65267-0D20-4964-A5D8-602BD42C01A4}.Release|Any CPU.Build.0 = Release|Any CPU + {F2C65267-0D20-4964-A5D8-602BD42C01A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/examples/minimal_web_site.anubis b/examples/minimal_web_site.anubis new file mode 100644 index 0000000..249cb29 --- /dev/null +++ b/examples/minimal_web_site.anubis @@ -0,0 +1,230 @@ + + + *Project* The Anubis Project + + *Title* A minimal web site. + + *Copyright* Copyright © Calexium www.calexium.com. + + *Released* + + *Author* David RENÉ + + *Overview* + + This file is just an example which may help to start making a web site with + Anubis Calexium Library + It was based on the example for making a minimal web site made by Alain Prouté and located + in examples/network folder in standard library example + + This example is absolutely minimalist and manage only page. + + +read tools/basis.anubis // required for 'make_directory' and . +read system/convert.anubis +read web/CXM_common.anubis // required for type 'Web_arg' +read web/CXM_multihost_http_server.anubis // required for type 'HTTP_Info' +read web/CXM_making_a_web_site.anubis +read web/mime.anubis // required for list of known MIME types + + + + + *** Server directory. + + A directory for putting files for all web sites. There will be one subdirectory per web + site. + +define String web_sites_directory = my_anubis_directory+"/web_sites". + + + *** Example site 1. + + Computing the pages of site 1. There is just one page. The type '$State' (see + 'web/CXM_making_a_web_site.anubis') has been chosen as 'One'. If this type were more + elaborate, the function 'compute_page_1' could compute several different pages (for + example, one per alternative of this type). Anyway, there is only one such function for + each web site. + +define HTTP_Answer + compute_page_1 + ( + One state + )= + html_page + ( + "Example Site 1", // title of web site + [], // list of 'META' tags (empty for this site) + body // body of page + ( + // list of body options + [ + background_color(rgb(255,200,200)) + // add more body options here + ], + + // content of page + center(text([size(14)],"This is the 'Example 1' web site.")) + ) + ) +. + + + + Making the description of web site 1. In this description, several elements are the + bare minimum. There is no action at all, no data base, almost nothing. See + 'web/making_a_web_site.anubis' for the declaration of the function + 'make_web_site_description'. + +define Web_Site + example_site_1 + = + // make the directory for web site 1 + // (subdirectories of it will be created automatically by the HTTP server) + forget((String)make_directory(web_sites_directory+"/example_site_1")); + + // make a list of all possible 'host names' for web site 1: + with addresses = (List(String)) + [ + "example-site-1", + "127.0.0.1", + "192.168.0.1" + // add more adresses here + ], + + // now make the description of the web site + make_web_site_description( + + //this is the unique ID of the web site. This ID will be use for prepend the cookies + //names belonging to that web site + "example", + + // the list of addresses defined above + addresses, + + // directory for the files of web site 1 + web_sites_directory+"/example_site_1", + + // directory for the states of that web_site + web_sites_directory+"/example_site_1/states", + + // initializing function + (One u) |-> u, // nothing to initialize for web site 1 + + // the function producing the initial state + (HTTP_Info info, + List(Web_arg) lwa, + Bool is_https) |-> unique, // there is ony one possible state for web site 1 + + // the function for handling expired tickets + // (tickets are kept on the server's disk and represent states. They are used for + // passing session informations from pages to pages. See + // 'web/CXM_making_a_web_site.anubis' for detailed explanations.) + (One expired, + Maybe(String) mb_action_name, + HTTP_Info info, + List(Web_arg) lwa, + Bool is_https) |-> unique, // keep the same state + + // the function for handling lost tickets + (Maybe(String) mb_action_name, + HTTP_Info info, + List(Web_arg) lwa, + Bool is_https) |-> unique, // restart with default state + + // list of all actions + [ ], // no action for web site 1 + + // the function for computing the pages of web site 1 (it is defined above) + compute_page_1, + + // the function for producing additional HTTP headers + (One u) |-> [], + + // timeout for tickets (in seconds) + 3600, // does'nt matter since only one state + + // list of redirections (one for each address) + // (see 'web/CXM_common.anubis' for the type 'Redirection') + redirection_list(map((String address) |-> redirect("/",address,"/site1.awp"), addresses)), + + // character encoding for web site 1 + "UTF-8", + + // list of URI extensions producing a console/journal message + [ + ".awp", // pages computed by this program + ".jpg", // images, etc... + ".gif", + ".png" + // add more extensions here (they must be known; see 'web/mime.anubis') + ], + + // list of HTTP headers which are traced in the console/journal messages + [ + "host", + "user-agent" + // add more HTTP headers here + ], + + // secret string (used by 'private download') + "HUD76GRD56FD7GFDS4RT", // for a real site, please choose another one + // it must remain secret + + // list of known MIME types (taken from 'web/mime.anubis') + known_mime_types, + + // action to be performed before a file is sent + // (for example, this may be used for counting downloads) + (String action_name, + List(Web_arg) lwa) |-> unique // no action at all + ) +. + + + + + *** Example site 2. + + Imagine another web site here... + + + + + + *** Starting all our web sites together. + +global define One + minimal_web_site + ( + List(String) args + ) = + // make the directory for all web sites (if needed) + forget((String) make_directory(web_sites_directory)); + + with http_port = (Word32)8000, + https_port = (Word32)4430, + // create a variable for handling the shutdown of our web sites + with shutdown_required = var(false), + with is_shutdown = (One u) |-> *shutdown_required, + + // start all web sites + if start_web_sites( + 0, // listen on all IP addresses + http_port, // port for HTTP + https_port, // port for HTTPS + "www.georges.example.com", // common name of SSL certificate + [ + example_site_1 + // add other web sites here + ], + is_shutdown) is + { + cannot_bind_to_port(n) then println("Cannot bind to port: "+n), + cannot_bind_to_port(n,m) then println("Cannot bind to ports: "+n+", "+m), + ok(s1,s2) then println("Servers started on ports "+http_port+" (HTTP) and "+https_port+" (HTTPS).") + } +. + + + diff --git a/minimal_web_site.aproj b/minimal_web_site.aproj new file mode 100644 index 0000000..140a7fe --- /dev/null +++ b/minimal_web_site.aproj @@ -0,0 +1,95 @@ + + + {F2C65267-0D20-4964-A5D8-602BD42C01A4} + Debug + AnyCPU + Exe + minimal_web_site + minimal_web_site + examples\minimal_web_site.anubis + ./ + + + bin\Debug\ + True + Full + False + + + bin\Release\ + False + None + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web/CXM_common.anubis b/web/CXM_common.anubis index b1e8612..dcc006e 100644 --- a/web/CXM_common.anubis +++ b/web/CXM_common.anubis @@ -4,12 +4,12 @@ *Copyright* Copyright (c) Alain Prouté 2003~2007. - © Calexium 2007~2016 + © Calexium 2007~2017 *Authors:* Alain Prouté - David René + David RENÉ *Public* *Name* HTTP_header @@ -21,27 +21,31 @@ transmit system/string.anubis /** * The type 'HTTP_header' describes HTTP headers, which are just pairs '(name,value)'. */ + public type HTTP_header: - http_header(String name, - String value). - + http_header( + String name, + String value + ) +. public define Maybe(String) http_header_value - ( - List(HTTP_header) l, - String name - ) = + ( + List(HTTP_header) l, + String name + )= if l is - { - [ ] then failure, - [h . t] then if h is - { - http_header(n, v) then //print("DEBUG: http_header_value --> HEADER = " + n + ":" + v + "\n"); - if insensitive_equal(name, n) then success(v) - else http_header_value(t, name), - } - }. + { + [ ] then failure, + [h . t] then if h is + { + http_header(n, v) then //print("DEBUG: http_header_value --> HEADER = " + n + ":" + v + "\n"); + if insensitive_equal(name, n) then success(v) + else http_header_value(t, name), + } + } +. public define List(String) to_List_String @@ -49,7 +53,7 @@ public define List(String) List(HTTP_header) l )= map((HTTP_header h) |-> h.name +": "+h.value, l ). - + public define String to_String ( @@ -71,13 +75,16 @@ public define String 'web/html.anubis'). public type Web_arg: - web_arg(String name, - String value), - upload (String name, // name of corresponding 'upload' Web_item - String value, // name of uploaded file - String temp_file_path). // temporary file path (relative to server directory) + web_arg( + String name, + String value + ), + upload ( + String name, // name of corresponding 'upload' Web_item + String value, // name of uploaded file + String temp_file_path) // temporary file path (relative to server directory) +. - *Name* Web_arg_value *Description* Of course, within the body of a 'web page' operation, you may want to recover the value @@ -103,26 +110,27 @@ public type Web_arg_value: public define Web_arg_value web_arg_value - ( - List(Web_arg) l, - String name - ) = + ( + List(Web_arg) l, + String name + )= if l is - { - [ ] then not_found, - [h . t] then if h is - { - web_arg(n,v) then - if name=n - then found(v) - else web_arg_value(t,name), - - upload(n,v,tfn) then - if name=n - then found(v) - else web_arg_value(t,name) - } - }. + { + [ ] then not_found, + [h . t] then if h is + { + web_arg(n,v) then + if name=n + then found(v) + else web_arg_value(t,name), + + upload(n,v,tfn) then + if name=n + then found(v) + else web_arg_value(t,name) + } + } +. public define Web_arg_value web_arg_value_not_null @@ -143,23 +151,24 @@ public define Web_arg_value *Ignore* public define Maybe((String,String)) - file_upload_value - ( - List(Web_arg) l, - String name - ) = - if l is - { - [ ] then failure, - [h . t] then if h is - { - web_arg(_,_) then file_upload_value(t,name), - upload(n,v,tfn) then - if n = name - then success((v,tfn)) - else file_upload_value(t,name) - } - }. + file_upload_value + ( + List(Web_arg) l, + String name + )= + if l is + { + [ ] then failure, + [h . t] then + if h is + { + web_arg(_,_) then file_upload_value(t,name), + upload(n,v,tfn) then + if n = name + then success((v,tfn)) + else file_upload_value(t,name) + } + }. public define List((String,String)) file_upload_value diff --git a/web/CXM_json.anubis b/web/CXM_json.anubis index 06d4a07..b39640a 100644 --- a/web/CXM_json.anubis +++ b/web/CXM_json.anubis @@ -11,7 +11,7 @@ read tools/basis.anubis read tools/printable_tree.anubis transmit web/mime.anubis -transmit calexium_lib/extensions/json.anubis +transmit extensions/json.anubis public type JsonMember:... diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index 264e7a6..c4c2f51 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -2831,17 +2831,17 @@ public define Start_Web_Sites_Result public define One - start_web_sites - ( - Word32 ip_address, // the IP address shared by the web sites - Word32 http_port, // usually: 80 - Word32 https_port, // usually: 443 - String ssl_certificate_common_name, - List(Web_Site) web_sites, // web sites to be started - (One) -> Bool shutdown_required, - Logger log - ) = - if (Start_Web_Sites_Result)start_web_sites(ip_address, + start_web_sites + ( + Word32 ip_address, // the IP address shared by the web sites + Word32 http_port, // usually: 80 + Word32 https_port, // usually: 443 + String ssl_certificate_common_name, + List(Web_Site) web_sites, // web sites to be started + (One) -> Bool shutdown_required, + Logger log //logger where to report the error + )= + if (Start_Web_Sites_Result)start_web_sites(ip_address, http_port, https_port, ssl_certificate_common_name, -- libgit2 0.21.4