Commit 1a15cad4748f93f7b134058005292cc0e714a971
1 parent
f715c0d9
add the generation by densaku of calexium lib types
Showing
4 changed files
with
394 additions
and
0 deletions
Show diff stats
| 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 | ... | ... |
| 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 | +. | ... | ... |
| 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 | + | ... | ... |