Commit dc3a74bcd8a1ba4b3827cd6f1b30bf94a4366cf8

Authored by totoro
2 parents 56ebceb2 bd61d2eb

Merge branch 'release/ANUBIS_1_14' of ssh://gitlab.calexium.com:33022/calexium/c…

…alexium_lib into release/ANUBIS_1_14
densaku_types.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 07/02/2017
  5 + * Time: 23:01
  6 + * © Calexium
  7 + */
  8 +
  9 +
  10 +read tools/basis.anubis
  11 +read densaku_lib/ds_generator.anubis
  12 +read calexium_lib/ds_files/ds_types.anubis
  13 +read calexium_lib/ds_files/ds_messages.anubis
  14 +
  15 +
  16 +global define One
  17 + calexium_lib_ds
  18 + (
  19 + List(String) args
  20 + ) =
  21 + if load_ds_generator is
  22 + {
  23 + failure then println("Densaku generator can't be load"),
  24 + success(ds_gen) then forget(ds_gen.generate_type_files(calexium_lib_types_description, calexium_lib_messages_list, "ds_files/"))
  25 + }.
  26 +
  27 +execute anbexec calexium_lib_ds // generate the file
... ...
ds_files/ds_messages.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 07/02/2017
  5 + * Time: 23:05
  6 + * © Calexium
  7 + */
  8 +
  9 +
  10 +read densaku_lib/types/densaku.anubis
  11 +
  12 +public define List(DS_Message) calexium_lib_messages_list =
  13 + [
  14 +
  15 + ].
... ...
ds_files/ds_types.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 07/02/2017
  5 + * Time: 23:05
  6 + * © Calexium
  7 + */
  8 +
  9 +read densaku_lib/types/densaku.anubis
  10 +
  11 +public define List(DS_Type) calexium_lib_types_description =
  12 + [
  13 +// public type DB_id:
  14 +// none,
  15 +// db_id(Int value).
  16 + ds_type("DB_id", [
  17 + enum("none", comment("no database Primary Key ID")),
  18 + alternative("db_id", [
  19 + component( int, "value", comment("Integer value of the Primary Key ID"))
  20 + ])
  21 + ]),
  22 +
  23 +// public type DB_datetime:
  24 +// db_datetime(String datetime). //Date and time in ISO8601 format "YYYY-MM-DD hh:mm:ss"
  25 + ds_type("DB_datetime", [
  26 + alternative("db_datetime", [
  27 + component(string, "datetime", comment("Date and time in ISO8601 format \"YYYY-MM-DD hh:mm:ss\""))
  28 + ])
  29 + ]),
  30 +
  31 +// public type DB_date:
  32 +// db_date(String date). //Date in ISO8601 format "YYYY-MM-DD"
  33 + ds_type("DB_date", [
  34 + alternative("db_date", [
  35 + component(string, "date", comment("Date and time in ISO8601 format \"YYYY-MM-DD\""))
  36 + ])
  37 + ]),
  38 +
  39 +// public type DB_time:
  40 +// db_time(String time). //Time in ISO8601 format "hh:mm:ss"
  41 + ds_type("DB_time", [
  42 + alternative("db_time", [
  43 + component(string, "time", comment("Date and time in ISO8601 format \"hh:mm:ss\""))
  44 + ])
  45 + ]),
  46 +
  47 +// public type DB_integer:
  48 +// db_integer(Int value).
  49 +// calexium_lib/database/db_types.anubis
  50 + ds_type("DB_integer", [
  51 + alternative("db_integer", [
  52 + component(int, "value", comment("Integer from datatase"))
  53 + ])
  54 + ]),
  55 +
  56 +// public type MIME:
  57 +// mime(String type,
  58 +// String sybtype,
  59 +// List(String) file_extensions).
  60 +// library/web/mime.anubis
  61 + ds_type("MIME", [
  62 + alternative("mime", [
  63 + component(string, "type"),
  64 + component(string, "subtype"),
  65 + component(list, string, "file_extensions")
  66 + ])
  67 + ]),
  68 +
  69 + ]
  70 +.
... ...
examples/minimal_web_site_vc.anubis 0 → 100644
  1 +
  2 +
  3 + *Project* The Anubis Project
  4 +
  5 + *Title* A minimal web site.
  6 +
  7 + *Copyright* Copyright © Calexium www.calexium.com.
  8 +
  9 + *Released*
  10 +
  11 + *Author* David RENÉ
  12 +
  13 + *Overview*
  14 +
  15 + This file is just an example which may help to start making a web site with
  16 + Anubis Calexium Library
  17 + It was based on the example for making a minimal web site made by Alain Prouté and located
  18 + in examples/network folder in standard library example
  19 +
  20 + This example is absolutely minimalist and manage only page.
  21 +
  22 +
  23 +read tools/basis.anubis // required for 'make_directory' and .
  24 +read system/convert.anubis
  25 +read calexium_lib/web/CXM_common.anubis // required for type 'Web_arg'
  26 +read calexium_lib/web/CXM_multihost_http_server.anubis // required for type 'HTTP_Info'
  27 +read calexium_lib/web/CXM_controller.anubis
  28 +read calexium_lib/web/CXM_making_a_web_site.anubis
  29 +read web/mime.anubis // required for list of known MIME types
  30 +read calexium_lib/web/CXM_web_arg_utils.anubis
  31 +read calexium_lib/web/CXM_form.anubis
  32 +read calexium_lib/web/jQuery/CXM_jquery_button.anubis
  33 +
  34 + *** Server directory.
  35 +
  36 + A directory for putting files for all web sites. There will be one subdirectory per web
  37 + site.
  38 +
  39 +define String web_sites_directory = my_anubis_directory+"/web_sites".
  40 +
  41 +
  42 +define HTML_Partial_Content
  43 + create_login_form
  44 + =
  45 +
  46 + partial_content(
  47 + [css(css_file("css/login.css"))],
  48 + div([id("login")],
  49 + sequence([
  50 + //BODY
  51 + div([id("login_body")],
  52 + cxm_form( "login_form", [], "do_login", [], [],
  53 + [
  54 + input (label(("LOGIN_NAME"), no_help), wan("login_name"), init(""), narrow, non_mandatory),
  55 + password_input(label(("PASSWORD"), no_help), wan("password"), init(""), narrow, non_mandatory),
  56 + partial(img_submit_button(("CONNECTION"), "login_form" ))
  57 + ])
  58 + ),
  59 + ])
  60 + )).
  61 +
  62 +define HTTP_Answer
  63 + go_login
  64 + (
  65 + One state
  66 + )=
  67 + html_page
  68 + (
  69 + "Example Site 1", // title of web site
  70 + [], // list of 'META' tags (empty for this site)
  71 + body // body of page
  72 + (
  73 + // list of body options
  74 + [
  75 + background_color(rgb(255,200,200))
  76 + // add more body options here
  77 + ],
  78 +
  79 + // content of page
  80 + partial(create_login_form)
  81 + )
  82 + )
  83 +.
  84 +
  85 +define HTTP_Answer
  86 + compute_page_1
  87 + (
  88 + One state
  89 + )=
  90 + html_page
  91 + (
  92 + "Example Site 1", // title of web site
  93 + [], // list of 'META' tags (empty for this site)
  94 + body // body of page
  95 + (
  96 + // list of body options
  97 + [
  98 + background_color(rgb(255,200,200))
  99 + // add more body options here
  100 + ],
  101 +
  102 + // content of page
  103 + center(text([size(14)],"This is the 'Example 1' web site."))
  104 + )
  105 + )
  106 +.
  107 +
  108 +define (One, HTTP_Answer)
  109 + root_controller
  110 + (
  111 + HTTP_Info http_info,
  112 + List(Web_arg) lwa,
  113 + Bool is_https,
  114 + One toto
  115 + )=
  116 +
  117 + with action = get_String(lwa, "action", "go_login"),
  118 + if action = "go_login" then
  119 + (unique, go_login(unique))
  120 + else
  121 + (unique, compute_page_1(unique)).
  122 +
  123 +
  124 +define WEB_Controller(One)
  125 + make_root_controller
  126 + =
  127 + web_controller("root", root_controller)
  128 +.
  129 +
  130 + Making the description of web site 1. In this description, several elements are the
  131 + bare minimum. There is no action at all, no data base, almost nothing. See
  132 + 'web/making_a_web_site.anubis' for the declaration of the function
  133 + 'make_web_site_description'.
  134 +
  135 +define Web_Site
  136 + example_site_1
  137 + =
  138 + // make the directory for web site 1
  139 + // (subdirectories of it will be created automatically by the HTTP server)
  140 + forget((String)make_directory(web_sites_directory+"/example_site_1"));
  141 +
  142 + // make a list of all possible 'host names' for web site 1:
  143 + with addresses = (List(String))
  144 + [
  145 + "example-site-1",
  146 + "127.0.0.1",
  147 + "192.168.0.1"
  148 + // add more adresses here
  149 + ],
  150 +
  151 + // now make the description of the web site
  152 + make_web_site_controller_description(
  153 +
  154 + //this is the unique ID of the web site. This ID will be use for prepend the cookies
  155 + //names belonging to that web site
  156 + "example",
  157 +
  158 + // the list of addresses defined above
  159 + addresses,
  160 +
  161 + // directory for the files of web site 1
  162 + web_sites_directory+"/example_site_1",
  163 +
  164 + // directory for the states of that web_site
  165 + web_sites_directory+"/example_site_1/states",
  166 +
  167 + // initializing function
  168 + (One u) |-> u, // nothing to initialize for web site 1
  169 +
  170 + // the function producing the initial state
  171 + (HTTP_Info info,
  172 + List(Web_arg) lwa,
  173 + Bool is_https) |-> unique, // there is ony one possible state for web site 1
  174 +
  175 + // the function for handling expired tickets
  176 + // (tickets are kept on the server's disk and represent states. They are used for
  177 + // passing session informations from pages to pages. See
  178 + // 'web/CXM_making_a_web_site.anubis' for detailed explanations.)
  179 + (One expired,
  180 + Maybe(String) mb_action_name,
  181 + HTTP_Info info,
  182 + List(Web_arg) lwa,
  183 + Bool is_https) |-> unique, // keep the same state
  184 +
  185 + // the function for handling lost tickets
  186 + (Maybe(String) mb_action_name,
  187 + HTTP_Info info,
  188 + List(Web_arg) lwa,
  189 + Bool is_https) |-> unique, // restart with default state
  190 +
  191 + var([make_root_controller]),
  192 +
  193 + // the function for producing additional HTTP headers
  194 + (One u) |-> [],
  195 +
  196 + // timeout for tickets (in seconds)
  197 + 3600, // does'nt matter since only one state
  198 +
  199 + // list of redirections (one for each address)
  200 + // (see 'web/CXM_common.anubis' for the type 'Redirection')
  201 + redirection_list(map((String address) |-> redirect("/",address,"/index.awp"), addresses)),
  202 +
  203 + // character encoding for web site 1
  204 + "UTF-8",
  205 +
  206 + // list of URI extensions producing a console/journal message
  207 + [
  208 + ".awp", // pages computed by this program
  209 + ".jpg", // images, etc...
  210 + ".gif",
  211 + ".png"
  212 + // add more extensions here (they must be known; see 'web/mime.anubis')
  213 + ],
  214 +
  215 + // list of HTTP headers which are traced in the console/journal messages
  216 + [
  217 + "host",
  218 + "user-agent"
  219 + // add more HTTP headers here
  220 + ],
  221 +
  222 + // secret string (used by 'private download')
  223 + "HUD76GRD56FD7GFDS4RT", // for a real site, please choose another one
  224 + // it must remain secret
  225 +
  226 + // list of known MIME types (taken from 'web/mime.anubis')
  227 + known_mime_types,
  228 +
  229 + // action to be performed before a file is sent
  230 + // (for example, this may be used for counting downloads)
  231 + (String action_name,
  232 + List(Web_arg) lwa) |-> unique // no action at all
  233 + )
  234 +.
  235 +
  236 +
  237 +
  238 +
  239 + *** Example site 2.
  240 +
  241 + Imagine another web site here...
  242 +
  243 +
  244 +
  245 +
  246 +
  247 + *** Starting all our web sites together.
  248 +
  249 +global define One
  250 + minimal_web_site_vc
  251 + (
  252 + List(String) args
  253 + ) =
  254 + // make the directory for all web sites (if needed)
  255 + forget((String) make_directory(web_sites_directory));
  256 +
  257 + with http_port = (Word32)8000,
  258 + https_port = (Word32)4430,
  259 + // create a variable for handling the shutdown of our web sites
  260 + with shutdown_required = var(false),
  261 + with is_shutdown = (One u) |-> *shutdown_required,
  262 +
  263 + // start all web sites
  264 + if start_web_sites(
  265 + 0, // listen on all IP addresses
  266 + http_port, // port for HTTP
  267 + https_port, // port for HTTPS
  268 + "www.georges.example.com", // common name of SSL certificate
  269 + [
  270 + example_site_1
  271 + // add other web sites here
  272 + ],
  273 + is_shutdown) is
  274 + {
  275 + cannot_bind_to_port(n) then println("Cannot bind to port: "+n),
  276 + cannot_bind_to_port(n,m) then println("Cannot bind to ports: "+n+", "+m),
  277 + ok(s1,s2) then println("Servers started on ports "+http_port+" (HTTP) and "+https_port+" (HTTPS).")
  278 + }
  279 +.
  280 +
  281 +
  282 +
... ...
string/crlf.anubis
... ... @@ -101,13 +101,26 @@ public define ResultCopy
101 101 copy_file_and_convert_to_CRLF
102 102 (
103 103 String file,
104   - ByteArray -> ByteArray converter
  104 + ByteArray -> ByteArray converter,
  105 + Bool keep_org
105 106 )=
106 107 if rename(file, file+".tmp") then
107 108 with result = copy_file_and_convert_to_CRLF(file+".tmp", file, converter),
108   - forget(remove(file+".tmp"));
  109 + (if keep_org then
  110 + unique
  111 + else
  112 + forget(remove(file+".tmp")));
109 113 result
110 114 else
111   - cant_create_file.
  115 + cant_create_file
  116 +.
112 117  
113 118  
  119 +public define ResultCopy
  120 + copy_file_and_convert_to_CRLF
  121 + (
  122 + String file,
  123 + ByteArray -> ByteArray converter
  124 + )=
  125 + copy_file_and_convert_to_CRLF(file, converter, false)
  126 +.
... ...
web/CXM_form.anubis
... ... @@ -317,6 +317,11 @@ public define CXM_Form_Field
317 317 submit(WEB_Action_Name action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands)
318 318 = submit([], htmlClass(""), action_name, label, button_text, extra_operands).
319 319  
  320 +public define CXM_Form_Field //Helper for older project wich use only String as Action name
  321 + submit(String _action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands)
  322 + = submit([], htmlClass(""), action_name(_action_name), label, button_text, extra_operands).
  323 +
  324 +
320 325 public define CXM_Form_Field
321 326 upload(HTML_Label label, HTML_Id id, WebArgName name, Width width)
322 327 = upload([], label, id, name, width, non_mandatory).
... ... @@ -634,6 +639,29 @@ public define HTML_Off_Form
634 639 extra_ops,
635 640 format_CXM_Form_Field(fields, lwa)
636 641 ).
  642 +
  643 +public define HTML_Off_Form
  644 +/* older manner to call CXM_form with action as String.
  645 + * this function only exists for compatibility with older projects. Please consider
  646 + * to use the above function with WEB_Action_Name instead of String
  647 +*/
  648 + cxm_form
  649 + (
  650 + HTML_Id form_Id,
  651 + List(CoreAttrs) options,
  652 + String action, //older manner to call action with String
  653 + List((String,String)) extra_ops,
  654 + List(Web_arg) lwa,
  655 + List(CXM_Form_Field) fields
  656 + ) =
  657 +
  658 + form(
  659 + form_Id,
  660 + [class("cxm_form") . options],
  661 + action_name(action),
  662 + extra_ops,
  663 + format_CXM_Form_Field(fields, lwa)
  664 + ).
637 665  
638 666 public define HTML_Off_Form
639 667 cxm_form
... ... @@ -646,17 +674,19 @@ public define HTML_Off_Form
646 674 List(CXM_Form_Field) form_fields
647 675 )=
648 676 cxm_form(html_Id(form_name), options, action, extra_ops, lwa, form_fields).
649   -
650   - public define HTML_In_Form
651   - cxm_fieldset
  677 +
  678 +public define HTML_Off_Form
  679 + cxm_form
652 680 (
653   - HTML_Id fieldSetId,
  681 + String form_name,
  682 + List(CoreAttrs) options,
  683 + String action,
  684 + List((String,String)) extra_ops,
654 685 List(Web_arg) lwa,
655   - List(CXM_Form_Field) fields
656   - ) =
657   - cxm_fieldset([id(fieldSetId.id), class("aligned")], "", lwa, fields).
658   -
659   -
  686 + List(CXM_Form_Field) form_fields
  687 + )=
  688 + cxm_form(html_Id(form_name), options, action_name(action), extra_ops, lwa, form_fields).
  689 +
660 690  
661 691 public define HTML_Off_Form
662 692 cxm_form
... ...
web/CXM_making_a_web_site.anubis
... ... @@ -1398,6 +1398,23 @@ public define HTML_In_Form
1398 1398 String name
1399 1399 ) =
1400 1400 foreign_link([size(tsize)],url,name).
  1401 +
  1402 +public define HTML_In_Form
  1403 +/* Older call with String as action instead of WEB_Action_Name.
  1404 + * This function exists only for compatibility with older project.
  1405 + * Please condiser to use above function instead
  1406 + */
  1407 + actioner
  1408 + (
  1409 + Actioner_Connection conn,
  1410 + Actioner_Target targ,
  1411 + Actioner_Aspect asp,
  1412 + String action,
  1413 + List((String,String)) extra_ops,
  1414 + List(Actioner_Local_Action) local_actions
  1415 + )=
  1416 + actioner(conn,targ,asp,action_name(action),extra_ops,local_actions)
  1417 +.
1401 1418  
1402 1419 public define HTML_In_Form
1403 1420 actioner
... ... @@ -1410,6 +1427,22 @@ public define HTML_In_Form
1410 1427 )=
1411 1428 actioner(conn,targ,asp,action,extra_ops,[])
1412 1429 .
  1430 +
  1431 +public define HTML_In_Form
  1432 +/* Older call with String as action instead of WEB_Action_Name.
  1433 + * This function exists only for compatibility with older project.
  1434 + * Please condiser to use above function instead
  1435 + */
  1436 + actioner
  1437 + (
  1438 + Actioner_Connection conn,
  1439 + Actioner_Target targ,
  1440 + Actioner_Aspect asp,
  1441 + String action,
  1442 + List((String,String)) extra_ops
  1443 + )=
  1444 + actioner(conn,targ,asp,action_name(action),extra_ops,[])
  1445 +.
1413 1446  
1414 1447 public define HTML_In_Form
1415 1448 actioner
... ... @@ -1621,6 +1654,16 @@ public define HTML_Off_Form
1621 1654 ) =
1622 1655 form(html_Id(form_name), options, action, extra_ops, content).
1623 1656  
  1657 +public define HTML_Off_Form
  1658 + form
  1659 + (
  1660 + String form_name,
  1661 + List(CoreAttrs) options,
  1662 + String action,
  1663 + List((String,String)) extra_ops,
  1664 + HTML_In_Form content
  1665 + ) =
  1666 + form(html_Id(form_name), options, action_name(action), extra_ops, content).
1624 1667  
1625 1668 public define HTML_Off_Form literal(Printable_tree t) = literal_pt(t).
1626 1669 public define HTML_Off_Form fixed_size(HTML_Size width, HTML_Size height, String name_of_HTML_file)
... ... @@ -1647,6 +1690,39 @@ public define HTML_Off_Form
1647 1690 List((String,String)) extra_ops
1648 1691 ) =
1649 1692 actioner(conn,targ,asp,action,extra_ops,[]).
  1693 +
  1694 +public define HTML_Off_Form
  1695 +/* Older call with String as action instead of WEB_Action_Name.
  1696 + * This function exists only for compatibility with older project.
  1697 + * Please condiser to use above function instead
  1698 + */
  1699 + actioner
  1700 + (
  1701 + Actioner_Connection conn,
  1702 + Actioner_Target targ,
  1703 + Actioner_Aspect asp,
  1704 + String action,
  1705 + List((String,String)) extra_ops,
  1706 + List(Actioner_Local_Action) local_actions
  1707 + )=
  1708 + actioner(conn,targ,asp,action_name(action),extra_ops,local_actions)
  1709 +.
  1710 +
  1711 +public define HTML_Off_Form
  1712 +/* Older call with String as action instead of WEB_Action_Name.
  1713 + * This function exists only for compatibility with older project.
  1714 + * Please condiser to use above function instead
  1715 + */
  1716 + actioner
  1717 + (
  1718 + Actioner_Connection conn,
  1719 + Actioner_Target targ,
  1720 + Actioner_Aspect asp,
  1721 + String action,
  1722 + List((String,String)) extra_ops
  1723 + )=
  1724 + actioner(conn,targ,asp,action_name(action),extra_ops,[])
  1725 +.
1650 1726  
1651 1727 public define HTML_Off_Form
1652 1728 table
... ... @@ -1890,7 +1966,19 @@ public type HTML_Meta:
1890 1966 literal (String).
1891 1967  
1892 1968 Meta tags are put in the 'head' of the HTML page.
1893   -
  1969 +
  1970 +public define HTML_Meta
  1971 + refresh
  1972 + (
  1973 + Actioner_Connection connection,
  1974 + Actioner_Target target,
  1975 + String action,
  1976 + Int delay
  1977 + )=
  1978 + refresh(connection, target, action_name(action), delay)
  1979 +.
  1980 +
  1981 +
1894 1982  
1895 1983 public type Body_Option:
1896 1984 core_attrs(List(CoreAttrs)),
... ...
web/CXM_multihost_http_server.anubis
... ... @@ -684,7 +684,8 @@ type EncodingType:
684 684 www_url,
685 685 multipart_form_data.
686 686  
687   -public type BufferedConnection:
  687 +
  688 +type BufferedConnection:
688 689 buffered_connection(Connection conn,
689 690 Var(ByteArray) buffer,
690 691 Var(Int) read_pos,
... ... @@ -692,13 +693,14 @@ public type BufferedConnection:
692 693 ).
693 694  
694 695  
695   -public define BufferedConnection
  696 +define BufferedConnection
696 697 buffered_connection
697 698 (
698 699 Connection conn
699 700 )=
700 701 buffered_connection(conn, var(constant_byte_array(0, 0)), var(0), var([]))
701 702 .
  703 +
702 704  
703 705 *** [2] Tools.
704 706  
... ...