Commit 245d2efe100779fe38308c9da30a31c38190a3d0
1 parent
246a5bad
continue the make web site with controllers independent.
Showing
7 changed files
with
271 additions
and
651 deletions
Show diff stats
web/CXM_making_a_web_site.anubis
| @@ -357,7 +357,7 @@ public define String | @@ -357,7 +357,7 @@ public define String | ||
| 357 | 357 | ||
| 358 | 358 | ||
| 359 | 359 | ||
| 360 | -define List(HTTP_header) | 360 | +public define List(HTTP_header) |
| 361 | make_session_cookie_headers | 361 | make_session_cookie_headers |
| 362 | ( | 362 | ( |
| 363 | String website_name, | 363 | String website_name, |
| @@ -370,105 +370,15 @@ define List(HTTP_header) | @@ -370,105 +370,15 @@ define List(HTTP_header) | ||
| 370 | ] | 370 | ] |
| 371 | . | 371 | . |
| 372 | 372 | ||
| 373 | -define WEB_Session -> String // the function constructed returns the name of the state | ||
| 374 | - make_save_session_function | ||
| 375 | - ( | ||
| 376 | - Int timeout, | ||
| 377 | - String state_directory, | ||
| 378 | - (LogLevel, String) -> One logger | ||
| 379 | - ) = | ||
| 380 | - (WEB_Session s_var) |-> | ||
| 381 | - //Set the new timeout | ||
| 382 | - with time_stamp = now+timeout, | ||
| 383 | - s = to_WEB_Session_No_Var(s_var), | ||
| 384 | - to_be_saved = (time_stamp,s), | ||
| 385 | - //generate new session name | ||
| 386 | - //session_name = to_ascii(sha1(s)), | ||
| 387 | - session_name = s_var.session_id, | ||
| 388 | - //println("make_save_state_function " + state_directory+"/s"+state_name); | ||
| 389 | - if save(to_be_saved,state_directory+"/"+session_name) is ok then | ||
| 390 | - //logger(logInfo, "----- session ["+session_name+"] saved"+dump_WEB_Session_Fields(*s_var.fields)); | ||
| 391 | - session_name | ||
| 392 | - else | ||
| 393 | - logger(logError, ("Cannot create session file in '"+state_directory+"'.\n")); | ||
| 394 | - "" | ||
| 395 | -. | ||
| 396 | 373 | ||
| 397 | 374 | ||
| 398 | When a request arrives, we need to retrieve the previous state from the server's | 375 | When a request arrives, we need to retrieve the previous state from the server's |
| 399 | disk. We receive the name of that state. If the state is out of date, the state file is | 376 | disk. We receive the name of that state. If the state is out of date, the state file is |
| 400 | kept 3 days, and then deleted. | 377 | kept 3 days, and then deleted. |
| 401 | 378 | ||
| 402 | -type Previous_Session: | ||
| 403 | - not_found, // cannot retrieve the previous state | ||
| 404 | - out_of_date(WEB_Session p_session), // the previous state is out of date | ||
| 405 | - still_valid(WEB_Session p_session). // the previous state is still valid | ||
| 406 | - | ||
| 407 | -define Previous_Session | ||
| 408 | - retrieve_session | ||
| 409 | - ( | ||
| 410 | - HTTP_Info http_info, | ||
| 411 | - String session_directory, | ||
| 412 | - String website_name | ||
| 413 | - ) = | ||
| 414 | - if find_cookie("session_"+website_name, server_get_cookies(http_headers(http_info))) is | ||
| 415 | - { | ||
| 416 | - failure then not_found | ||
| 417 | - success(cookie) then | ||
| 418 | - //println("find_cookie(\"state_"+website_name+"\" success"); | ||
| 419 | - with session_name = value(cookie), | ||
| 420 | - with file_path = session_directory+"/"+session_name, | ||
| 421 | - //unserialize the stored session and his timeout value | ||
| 422 | - //println("retrieve session ["+session_name+"]"); | ||
| 423 | - if (RetrieveResult((Int, WEB_Session_No_Var)))retrieve(file_path) is ok(d) then | ||
| 424 | - ( | ||
| 425 | - //println("retrieve session OK ["+session_name+"]"); | ||
| 426 | - since d is (time_stamp, s_no_var), | ||
| 427 | - with s = to_WEB_Session(s_no_var), | ||
| 428 | - if time_stamp < now then | ||
| 429 | - ( | ||
| 430 | - forget(remove(file_path)); | ||
| 431 | - out_of_date(s) | ||
| 432 | - ) | ||
| 433 | - else | ||
| 434 | - still_valid(s) // state has been successfully retrieved | ||
| 435 | - ) | ||
| 436 | - else | ||
| 437 | - not_found | ||
| 438 | - } | ||
| 439 | -. | ||
| 440 | - | ||
| 441 | -define (List(String) file_names) -> One | ||
| 442 | - make_delete_out_of_date_sessions_function | ||
| 443 | - ( | ||
| 444 | - String state_directory, | ||
| 445 | - (LogLevel, String) -> One logger | ||
| 446 | - ) = | ||
| 447 | - (List(String) file_names) |-df-> | ||
| 448 | - if file_names is | ||
| 449 | - { | ||
| 450 | - [ ] then unique, | ||
| 451 | - [h . t] then | ||
| 452 | - if h = "." | h = ".." then | ||
| 453 | - df(t) | ||
| 454 | - else | ||
| 455 | - with file_path = state_directory+"/"+h, | ||
| 456 | - if (RetrieveResult((Int, WEB_Session_No_Var)))retrieve(file_path) is ok(d) then | ||
| 457 | - ( | ||
| 458 | - if d is (time_stamp, data) then | ||
| 459 | - if time_stamp < now then | ||
| 460 | - //println("session "+h+" out date will be deleted timestamp ["+time_stamp+"] now ["+now+"]"); | ||
| 461 | - (forget(remove(file_path)); | ||
| 462 | - df(t)) | ||
| 463 | - else | ||
| 464 | - //println("Session "+h+" still valid ["+time_stamp+"] now ["+now+"]"); | ||
| 465 | - df(t) | ||
| 466 | - ) | ||
| 467 | - else | ||
| 468 | - logger(logError, "Can't retreive session "+h+", hence will be deleted"); | ||
| 469 | - (forget(remove(file_path)); df(t)) | ||
| 470 | - }. | 379 | + |
| 471 | 380 | ||
| 381 | + | ||
| 472 | define One | 382 | define One |
| 473 | delete_out_of_date_sessions // for all web sites | 383 | delete_out_of_date_sessions // for all web sites |
| 474 | ( | 384 | ( |
| @@ -3017,37 +2927,6 @@ public define Web_Site | @@ -3017,37 +2927,6 @@ public define Web_Site | ||
| 3017 | 2927 | ||
| 3018 | 2928 | ||
| 3019 | 2929 | ||
| 3020 | -define HTTP_Answer | ||
| 3021 | - error_page | ||
| 3022 | - ( | ||
| 3023 | - HTTP_Status http_status, | ||
| 3024 | - String message, | ||
| 3025 | - WEB_Session _session, | ||
| 3026 | - ) | ||
| 3027 | - = | ||
| 3028 | - html_page | ||
| 3029 | - ( | ||
| 3030 | - http_status, // status | ||
| 3031 | - [], // list of 'META' tags (empty for this site) | ||
| 3032 | - body // body of page | ||
| 3033 | - ( | ||
| 3034 | - // list of body options | ||
| 3035 | - [ | ||
| 3036 | - background_color(rgb(255,200,200)) | ||
| 3037 | - ], | ||
| 3038 | - | ||
| 3039 | - // content of page | ||
| 3040 | - sequence([ | ||
| 3041 | - preformated([size(14)],"Anubis Web Server - Standard Lib v1.14.0.0 - Anubis language v1.14"), | ||
| 3042 | - preformated([size(12)],"Error "+to_String(http_status)), | ||
| 3043 | - preformated([size(12)],"Internal message :"+message), | ||
| 3044 | - br, | ||
| 3045 | - in_form(html_Id(""),text_area(wan(""), init(dump(_session)), 120, 60)) | ||
| 3046 | - ]) | ||
| 3047 | - ) | ||
| 3048 | - ) | ||
| 3049 | -. | ||
| 3050 | - | ||
| 3051 | 2930 | ||
| 3052 | public define JsonValue to_html_ajax_content(Printable_tree content_HTML, String additional_script). | 2931 | public define JsonValue to_html_ajax_content(Printable_tree content_HTML, String additional_script). |
| 3053 | public define JsonValue to_html_ajax_content(HTML_Partial_Content content_HTML, CommonInfo cinfo, String additional_script). | 2932 | public define JsonValue to_html_ajax_content(HTML_Partial_Content content_HTML, CommonInfo cinfo, String additional_script). |
web/CXM_page_message.anubis
| @@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
| 8 | 8 | ||
| 9 | read calexium_lib/web/CXM_making_a_web_site.anubis | 9 | read calexium_lib/web/CXM_making_a_web_site.anubis |
| 10 | read calexium_lib/web/widgets/icons_set.anubis | 10 | read calexium_lib/web/widgets/icons_set.anubis |
| 11 | +read calexium_lib/web/types/web_session.anubis | ||
| 11 | 12 | ||
| 12 | public type Alignment: | 13 | public type Alignment: |
| 13 | left, | 14 | left, |
web/CXM_web_session.anubis
| @@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
| 9 | read system/convert.anubis | 9 | read system/convert.anubis |
| 10 | read system/muscle.anubis | 10 | read system/muscle.anubis |
| 11 | read calexium_lib/database/db_types.anubis | 11 | read calexium_lib/database/db_types.anubis |
| 12 | +transmit types/web_session.anubis | ||
| 12 | read CXM_common.anubis | 13 | read CXM_common.anubis |
| 13 | read CXM_web_dump.anubis | 14 | read CXM_web_dump.anubis |
| 14 | 15 | ||
| @@ -23,89 +24,7 @@ read CXM_web_dump.anubis | @@ -23,89 +24,7 @@ read CXM_web_dump.anubis | ||
| 23 | //"AWS_CURRENT_LEFT_MENU" Left_Menu current left menu on the page | 24 | //"AWS_CURRENT_LEFT_MENU" Left_Menu current left menu on the page |
| 24 | //"AWS_CURRENT_MENU" Menu current menu, on the top of the page | 25 | //"AWS_CURRENT_MENU" Menu current menu, on the top of the page |
| 25 | 26 | ||
| 26 | -public type WEB_Session_Field_Datum: | ||
| 27 | - string(String), //fully implented | ||
| 28 | - bool(Bool), //fully implented | ||
| 29 | - int(Int), //fully implemented | ||
| 30 | - db_id(DB_id), | ||
| 31 | - message(Message), //fully implemented | ||
| 32 | - byte_array(ByteArray), | ||
| 33 | - float(Float), | ||
| 34 | - word128(Word128), | ||
| 35 | - word64(Word64), | ||
| 36 | - word32(Word32), | ||
| 37 | - word16(Word16), | ||
| 38 | - word8(Word8), | ||
| 39 | - word4(Word4) | ||
| 40 | - //WEB_Request | ||
| 41 | -. | ||
| 42 | - | ||
| 43 | -public type WEB_Session_Field_Type: | ||
| 44 | - string_t, | ||
| 45 | - bool_t, | ||
| 46 | - int_t, | ||
| 47 | - db_id_t, | ||
| 48 | - message_t, | ||
| 49 | - byte_array_t, | ||
| 50 | - float_t, | ||
| 51 | - word128_t, | ||
| 52 | - word64_t, | ||
| 53 | - word32_t, | ||
| 54 | - word16_t, | ||
| 55 | - word8_t, | ||
| 56 | - word4_t | ||
| 57 | -. | ||
| 58 | - | ||
| 59 | -public type WEB_Session_Field: | ||
| 60 | - session_field( | ||
| 61 | - String field_name, | ||
| 62 | - WEB_Session_Field_Type field_type, | ||
| 63 | - Var(WEB_Session_Field_Datum) field_datum //Var because it can be replaced | ||
| 64 | - ). | ||
| 65 | - | ||
| 66 | -public type WEB_Session_Field_No_Var: | ||
| 67 | - session_field( | ||
| 68 | - String field_name, | ||
| 69 | - WEB_Session_Field_Type field_type, | ||
| 70 | - WEB_Session_Field_Datum field_datum //Var because it can be replaced | ||
| 71 | - ). | ||
| 72 | - | ||
| 73 | -public type WEB_Request: | ||
| 74 | - web_request( | ||
| 75 | - HTTP_Info http_info, | ||
| 76 | - Var(List(Web_arg)) lwa, | ||
| 77 | - Bool is_https, | ||
| 78 | - ) | ||
| 79 | -. | ||
| 80 | - | ||
| 81 | -public type WEB_Request_No_Var: | ||
| 82 | - web_request( | ||
| 83 | - HTTP_Info http_info, | ||
| 84 | - List(Web_arg) lwa, | ||
| 85 | - Bool is_https, | ||
| 86 | - ) | ||
| 87 | -. | ||
| 88 | 27 | ||
| 89 | -public type WEB_Session: | ||
| 90 | - web_session( | ||
| 91 | - String session_id, | ||
| 92 | - String language, | ||
| 93 | - Var(List(WEB_Session_Field)) fields, | ||
| 94 | - WEB_Request web_request, | ||
| 95 | - WEB_Request previous_web_request, | ||
| 96 | - WEB_Request draw_web_request | ||
| 97 | - ). | ||
| 98 | - | ||
| 99 | -public type WEB_Session_No_Var: | ||
| 100 | - web_session( | ||
| 101 | - String session_id, | ||
| 102 | - String language, | ||
| 103 | - List(WEB_Session_Field_No_Var) fields, | ||
| 104 | - WEB_Request_No_Var web_request, | ||
| 105 | - WEB_Request_No_Var previous_web_request, | ||
| 106 | - WEB_Request_No_Var draw_web_request, | ||
| 107 | - ). | ||
| 108 | - | ||
| 109 | public define Var(List(WEB_Session_Field)) | 28 | public define Var(List(WEB_Session_Field)) |
| 110 | empty_fields_list = | 29 | empty_fields_list = |
| 111 | var([]). | 30 | var([]). |
web/controllers_web_site.anubis
| @@ -8,25 +8,157 @@ | @@ -8,25 +8,157 @@ | ||
| 8 | 8 | ||
| 9 | website with: | 9 | website with: |
| 10 | - controllers | 10 | - controllers |
| 11 | - - web session | 11 | + - web session in controller |
| 12 | - plugin | 12 | - plugin |
| 13 | - web page renderer | 13 | - web page renderer |
| 14 | 14 | ||
| 15 | - | 15 | + |
| 16 | +read system/logger.anubis | ||
| 17 | +read tools/printable_tree.anubis | ||
| 18 | + | ||
| 19 | +transmit CXM_cookies.anubis | ||
| 16 | transmit CXM_web_session.anubis | 20 | transmit CXM_web_session.anubis |
| 17 | transmit types/controllers_web_site.anubis | 21 | transmit types/controllers_web_site.anubis |
| 22 | +read plugin/plugin.anubis | ||
| 23 | + | ||
| 24 | +read CXM_making_a_web_site.anubis | ||
| 25 | + | ||
| 18 | read calexium_lib/web/plugin/plugin.anubis | 26 | read calexium_lib/web/plugin/plugin.anubis |
| 19 | read config/logger_config.anubis | 27 | read config/logger_config.anubis |
| 20 | 28 | ||
| 21 | 29 | ||
| 22 | 30 | ||
| 23 | -public type WEB_Action: | ||
| 24 | - web_action( | ||
| 25 | - WEB_Action_Name name, // name of action | ||
| 26 | - WEB_Action_Allowed_Protocol allowed_proto, | ||
| 27 | - (WEB_Session) -> Bool allow, // true if action allowed | ||
| 28 | - (WEB_Session) -> WEB_Controller_Result do_it | ||
| 29 | - ) | 31 | +type Previous_Session: |
| 32 | + not_found, // cannot retrieve the previous state | ||
| 33 | + out_of_date(WEB_Session p_session), // the previous state is out of date | ||
| 34 | + still_valid(WEB_Session p_session). // the previous state is still valid | ||
| 35 | + | ||
| 36 | +define Previous_Session | ||
| 37 | + retrieve_session | ||
| 38 | + ( | ||
| 39 | + HTTP_Info http_info, | ||
| 40 | + String session_directory, | ||
| 41 | + String website_name | ||
| 42 | + ) = | ||
| 43 | + if find_cookie("session_"+website_name, server_get_cookies(http_headers(http_info))) is | ||
| 44 | + { | ||
| 45 | + failure then not_found | ||
| 46 | + success(cookie) then | ||
| 47 | + //println("find_cookie(\"state_"+website_name+"\" success"); | ||
| 48 | + with session_name = value(cookie), | ||
| 49 | + with file_path = session_directory+"/"+session_name, | ||
| 50 | + //unserialize the stored session and his timeout value | ||
| 51 | + //println("retrieve session ["+session_name+"]"); | ||
| 52 | + if (RetrieveResult((Int, WEB_Session_No_Var)))retrieve(file_path) is ok(d) then | ||
| 53 | + ( | ||
| 54 | + //println("retrieve session OK ["+session_name+"]"); | ||
| 55 | + since d is (time_stamp, s_no_var), | ||
| 56 | + with s = to_WEB_Session(s_no_var), | ||
| 57 | + if time_stamp < now then | ||
| 58 | + ( | ||
| 59 | + forget(remove(file_path)); | ||
| 60 | + out_of_date(s) | ||
| 61 | + ) | ||
| 62 | + else | ||
| 63 | + still_valid(s) // state has been successfully retrieved | ||
| 64 | + ) | ||
| 65 | + else | ||
| 66 | + not_found | ||
| 67 | + } | ||
| 68 | +. | ||
| 69 | + | ||
| 70 | +define (List(String) file_names) -> One | ||
| 71 | + make_delete_out_of_date_sessions_function | ||
| 72 | + ( | ||
| 73 | + String state_directory, | ||
| 74 | + (LogLevel, String) -> One logger | ||
| 75 | + ) = | ||
| 76 | + (List(String) file_names) |-df-> | ||
| 77 | + if file_names is | ||
| 78 | + { | ||
| 79 | + [ ] then unique, | ||
| 80 | + [h . t] then | ||
| 81 | + if h = "." | h = ".." then | ||
| 82 | + df(t) | ||
| 83 | + else | ||
| 84 | + with file_path = state_directory+"/"+h, | ||
| 85 | + if (RetrieveResult((Int, WEB_Session_No_Var)))retrieve(file_path) is ok(d) then | ||
| 86 | + ( | ||
| 87 | + if d is (time_stamp, data) then | ||
| 88 | + if time_stamp < now then | ||
| 89 | + //println("session "+h+" out date will be deleted timestamp ["+time_stamp+"] now ["+now+"]"); | ||
| 90 | + (forget(remove(file_path)); | ||
| 91 | + df(t)) | ||
| 92 | + else | ||
| 93 | + //println("Session "+h+" still valid ["+time_stamp+"] now ["+now+"]"); | ||
| 94 | + df(t) | ||
| 95 | + ) | ||
| 96 | + else | ||
| 97 | + logger(logError, "Can't retreive session "+h+", hence will be deleted"); | ||
| 98 | + (forget(remove(file_path)); df(t)) | ||
| 99 | + }. | ||
| 100 | + | ||
| 101 | +define WEB_Session -> String // the function constructed returns the name of the state | ||
| 102 | + make_save_session_function | ||
| 103 | + ( | ||
| 104 | + Int timeout, | ||
| 105 | + String state_directory, | ||
| 106 | + (LogLevel, String) -> One logger | ||
| 107 | + ) = | ||
| 108 | + (WEB_Session s_var) |-> | ||
| 109 | + //Set the new timeout | ||
| 110 | + with time_stamp = now+timeout, | ||
| 111 | + s = to_WEB_Session_No_Var(s_var), | ||
| 112 | + to_be_saved = (time_stamp,s), | ||
| 113 | + //generate new session name | ||
| 114 | + //session_name = to_ascii(sha1(s)), | ||
| 115 | + session_name = s_var.session_id, | ||
| 116 | + //println("make_save_state_function " + state_directory+"/s"+state_name); | ||
| 117 | + if save(to_be_saved,state_directory+"/"+session_name) is ok then | ||
| 118 | + //logger(logInfo, "----- session ["+session_name+"] saved"+dump_WEB_Session_Fields(*s_var.fields)); | ||
| 119 | + session_name | ||
| 120 | + else | ||
| 121 | + logger(logError, ("Cannot create session file in '"+state_directory+"'.\n")); | ||
| 122 | + "" | ||
| 123 | +. | ||
| 124 | + | ||
| 125 | +public type WEB_Page_Renderer: | ||
| 126 | + web_page_renderer( | ||
| 127 | + String app, //application | ||
| 128 | + String name, //renderer name | ||
| 129 | + (WEB_Session _session, List(WEB_Plugin), HTML_Partial_Content _content) -> HTTP_Answer page_layout //call back for rendering page | ||
| 130 | + ) | ||
| 131 | +. | ||
| 132 | + | ||
| 133 | +define HTTP_Answer | ||
| 134 | + error_page | ||
| 135 | + ( | ||
| 136 | + HTTP_Status http_status, | ||
| 137 | + String message, | ||
| 138 | + WEB_Session _session, | ||
| 139 | + ) | ||
| 140 | + = | ||
| 141 | + html_page | ||
| 142 | + ( | ||
| 143 | + http_status, // status | ||
| 144 | + [], // list of 'META' tags (empty for this site) | ||
| 145 | + body // body of page | ||
| 146 | + ( | ||
| 147 | + // list of body options | ||
| 148 | + [ | ||
| 149 | + background_color(rgb(255,200,200)) | ||
| 150 | + ], | ||
| 151 | + | ||
| 152 | + // content of page | ||
| 153 | + sequence([ | ||
| 154 | + preformated([size(14)],"Anubis Web Server - Standard Lib v1.14.0.0 - Anubis language v1.14"), | ||
| 155 | + preformated([size(12)],"Error "+to_String(http_status)), | ||
| 156 | + preformated([size(12)],"Internal message :"+message), | ||
| 157 | + br, | ||
| 158 | + in_form(html_Id(""),text_area(wan(""), init(dump(_session)), 120, 60)) | ||
| 159 | + ]) | ||
| 160 | + ) | ||
| 161 | + ) | ||
| 30 | . | 162 | . |
| 31 | 163 | ||
| 32 | 164 | ||
| @@ -133,13 +265,7 @@ public define WEB_Controller_Result | @@ -133,13 +265,7 @@ public define WEB_Controller_Result | ||
| 133 | redraw(failure, content) | 265 | redraw(failure, content) |
| 134 | . | 266 | . |
| 135 | 267 | ||
| 136 | -public type WEB_Page_Renderer: | ||
| 137 | - web_page_renderer( | ||
| 138 | - String app, //application | ||
| 139 | - String name, //renderer name | ||
| 140 | - (WEB_Session _session, List(WEB_Plugin), HTML_Partial_Content _content) -> HTTP_Answer page_layout //call back for rendering page | ||
| 141 | - ) | ||
| 142 | -. | 268 | + |
| 143 | 269 | ||
| 144 | define WEB_Page_Renderer | 270 | define WEB_Page_Renderer |
| 145 | default_page_renderer = | 271 | default_page_renderer = |
| @@ -556,13 +682,7 @@ public define Web_Site | @@ -556,13 +682,7 @@ public define Web_Site | ||
| 556 | ), | 682 | ), |
| 557 | delete_out_of_date). | 683 | delete_out_of_date). |
| 558 | 684 | ||
| 559 | -public type WEB_Controller: | ||
| 560 | - web_controller( | ||
| 561 | - String name, //controller name | ||
| 562 | - Var(List(WEB_Action)) controller_actions, //list of all actions of that controller | ||
| 563 | - (WEB_Session)-> WEB_Controller_Result error //Error renderer | ||
| 564 | - ) | ||
| 565 | -. | 685 | + |
| 566 | 686 | ||
| 567 | define (WEB_Session)-> WEB_Controller_Result | 687 | define (WEB_Session)-> WEB_Controller_Result |
| 568 | web_controller_error | 688 | web_controller_error |
| @@ -584,423 +704,3 @@ public define WEB_Controller | @@ -584,423 +704,3 @@ public define WEB_Controller | ||
| 584 | web_controller(name, controller_actions, web_controller_error(name)) | 704 | web_controller(name, controller_actions, web_controller_error(name)) |
| 585 | . | 705 | . |
| 586 | 706 | ||
| 587 | -public type WEB_Page_Renderer: | ||
| 588 | - web_page_renderer( | ||
| 589 | - String app, //application | ||
| 590 | - String name, //renderer name | ||
| 591 | - (WEB_Session _session, List(WEB_Plugin), HTML_Partial_Content _content) -> HTTP_Answer page_layout //call back for rendering page | ||
| 592 | - ) | ||
| 593 | -. | ||
| 594 | - | ||
| 595 | -define WEB_Page_Renderer | ||
| 596 | - default_page_renderer = | ||
| 597 | - web_page_renderer("AWS", "AWS_DEFAULT_PAGE", | ||
| 598 | - ( WEB_Session _session, | ||
| 599 | - List(WEB_Plugin) _plugins, | ||
| 600 | - HTML_Partial_Content _content | ||
| 601 | - ) |-> | ||
| 602 | - with _title = get_page_title(_session), | ||
| 603 | - html_page | ||
| 604 | - ( | ||
| 605 | - http_ok, | ||
| 606 | - [ title(_title), ]// title of web site | ||
| 607 | - , | ||
| 608 | - body // body of page | ||
| 609 | - ( | ||
| 610 | - [], //body options empty | ||
| 611 | - (HTML_Off_Form)partial(_content) | ||
| 612 | - ) | ||
| 613 | - ) | ||
| 614 | - ) | ||
| 615 | -. | ||
| 616 | - | ||
| 617 | -define WEB_Controller_Result | ||
| 618 | - apply_action | ||
| 619 | - ( | ||
| 620 | - WEB_Session _session, | ||
| 621 | - String requested_action_name, | ||
| 622 | - List(WEB_Action) actions_list | ||
| 623 | - ) = | ||
| 624 | - //println("apply_action "); | ||
| 625 | - if actions_list is | ||
| 626 | - { | ||
| 627 | - [] then http_answer(error_page(http_not_found, "["+requested_action_name+"] Action not found in all controllers", _session)), | ||
| 628 | - [h . t] then | ||
| 629 | - if h.name = no_action then | ||
| 630 | - http_answer( _session, html_content(http_no_content, empty)) | ||
| 631 | - else | ||
| 632 | - with action_name = if h.name is | ||
| 633 | - { | ||
| 634 | - no_action then "", | ||
| 635 | - controller_action(_, name) then name, | ||
| 636 | - action_name(name) then name, | ||
| 637 | - url(url) then url, | ||
| 638 | - }, | ||
| 639 | - if requested_action_name = action_name then | ||
| 640 | - with step = get_Int(_session.fields, "AWS_SESSION_STEP", 0) + 1, | ||
| 641 | - replace_Int(_session.fields, "AWS_SESSION_STEP", step); | ||
| 642 | - if h.allowed_proto is | ||
| 643 | - { | ||
| 644 | - //Action only in HTTP | ||
| 645 | - http then | ||
| 646 | - if _session.web_request.is_https then | ||
| 647 | - http_answer(error_page(http_forbidden, "Only HTTP authorized", _session)) | ||
| 648 | - else | ||
| 649 | - //ask to the server the authorization to execute that action | ||
| 650 | - if h.allow(_session) then | ||
| 651 | - h.do_it(_session) | ||
| 652 | - else | ||
| 653 | - http_answer(error_page(http_unauthorized, "you are not authorized for this action", _session)) | ||
| 654 | - | ||
| 655 | - //Action only in HTTPS | ||
| 656 | - https then | ||
| 657 | - if _session.web_request.is_https then | ||
| 658 | - //ask to the server the authorization to execute that action | ||
| 659 | - if h.allow(_session) then | ||
| 660 | - h.do_it(_session) | ||
| 661 | - else | ||
| 662 | - http_answer(error_page(http_unauthorized, "you are not authorized for this action", _session)) | ||
| 663 | - else | ||
| 664 | - http_answer(error_page(http_forbidden, "Only HTTPS authorized", _session)) | ||
| 665 | - //Action in both HTTP / HTTPS | ||
| 666 | - http_https then | ||
| 667 | - //ask to the server the authorization to execute that action | ||
| 668 | - if h.allow(_session) then | ||
| 669 | - //println("do_it "+action_name); | ||
| 670 | - h.do_it(_session) | ||
| 671 | - else | ||
| 672 | - http_answer(error_page(http_unauthorized, "you are not authorized for this action", _session)) | ||
| 673 | - | ||
| 674 | - } | ||
| 675 | - else | ||
| 676 | - apply_action(_session, requested_action_name, t) | ||
| 677 | - } | ||
| 678 | -. | ||
| 679 | - | ||
| 680 | -define Maybe(WEB_Controller) | ||
| 681 | - get_controller | ||
| 682 | - ( | ||
| 683 | - String controller_name, | ||
| 684 | - List(WEB_Controller) controllers, | ||
| 685 | - (LogLevel, String) -> One logger //logger | ||
| 686 | - )= | ||
| 687 | - if controllers is | ||
| 688 | - { | ||
| 689 | - [] then | ||
| 690 | - logger(logWarning, "Can't find controller ["+controller_name+"]"); | ||
| 691 | - failure, | ||
| 692 | - [h . t] then | ||
| 693 | - if h.name = controller_name then | ||
| 694 | - //println("Controller ["+controller_name+"] found"); | ||
| 695 | - success(h) | ||
| 696 | - else | ||
| 697 | - get_controller(controller_name, t, logger) | ||
| 698 | - } | ||
| 699 | -. | ||
| 700 | - | ||
| 701 | -define WEB_Page_Renderer | ||
| 702 | - get_page_renderer | ||
| 703 | - ( | ||
| 704 | - String renderer_name, | ||
| 705 | - List(WEB_Page_Renderer) renderers, | ||
| 706 | - (LogLevel, String) -> One logger //logger | ||
| 707 | - )= | ||
| 708 | - if renderers is | ||
| 709 | - { | ||
| 710 | - [] then | ||
| 711 | - logger(logWarning, "Can't find page_renderer ["+renderer_name+"], use the default"); | ||
| 712 | - default_page_renderer, | ||
| 713 | - [h . t] then | ||
| 714 | - if h.name = renderer_name then | ||
| 715 | - //println("renderer_name ["+renderer_name+"] found"); | ||
| 716 | - h | ||
| 717 | - else | ||
| 718 | - //println("renderer_name "+renderer_name+" not matching"); | ||
| 719 | - get_page_renderer(renderer_name, t, logger) | ||
| 720 | - } | ||
| 721 | -. | ||
| 722 | - | ||
| 723 | -define WEB_Page_Renderer | ||
| 724 | - get_page_renderer | ||
| 725 | - ( | ||
| 726 | - WEB_Session _session, | ||
| 727 | - WEB_Page_Renderer _current_page_renderer, | ||
| 728 | - List(WEB_Page_Renderer) renderers, | ||
| 729 | - (LogLevel, String) -> One logger //logger | ||
| 730 | - )= | ||
| 731 | - //get the renderer page name to use from the session "AWS_PAGE_RENDERER" | ||
| 732 | - if get_String(_session.fields, "AWS_CURRENT_PAGE_RENDERER") is | ||
| 733 | - { | ||
| 734 | - failure then logger(logWarning, "No renderer defined, use the default"); default_page_renderer, | ||
| 735 | - success(renderer_name) then | ||
| 736 | - //check if the renderer_page already in cache | ||
| 737 | - if renderer_name = _current_page_renderer.name then | ||
| 738 | - _current_page_renderer | ||
| 739 | - else | ||
| 740 | - //if not in cache, use the selector function | ||
| 741 | - get_page_renderer(renderer_name, renderers, logger) | ||
| 742 | - } | ||
| 743 | -. | ||
| 744 | - | ||
| 745 | -define (Maybe(WEB_Session), HTTP_Answer) | ||
| 746 | - apply_controller_action | ||
| 747 | - ( | ||
| 748 | - WEB_Controller controller, | ||
| 749 | - List(WEB_Plugin) plugins, | ||
| 750 | - List(WEB_Controller) controllers, | ||
| 751 | - WEB_Page_Renderer _current_page_renderer, | ||
| 752 | - List(WEB_Page_Renderer) page_renderers, | ||
| 753 | - CommonInfo cinfo, | ||
| 754 | - WEB_Session _session, | ||
| 755 | - Maybe(String) _mb_action_name, | ||
| 756 | - (HTTP_Info, | ||
| 757 | - Var(List(Web_arg)), | ||
| 758 | - Bool is_https) -> WEB_Session initial_session, | ||
| 759 | - (LogLevel, String) -> One logger //logger | ||
| 760 | - )= | ||
| 761 | - //get the action name | ||
| 762 | - with mb_action_name = | ||
| 763 | - if _mb_action_name is | ||
| 764 | - { | ||
| 765 | - failure then get_String(*_session.web_request.lwa, "aws_action"), | ||
| 766 | - success(_an) then success(_an) | ||
| 767 | - }, | ||
| 768 | - | ||
| 769 | - if mb_action_name is | ||
| 770 | - { | ||
| 771 | - failure then | ||
| 772 | - //(failure, error_page(http_not_found, "Action name failure", _session)), | ||
| 773 | - with new_session = initial_session(_session.web_request.http_info, _session.web_request.lwa, _session.web_request.is_https), | ||
| 774 | - if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers, logger) is | ||
| 775 | - { | ||
| 776 | - failure then (failure, error_page(http_not_found, "Initial Session Controller not found", new_session)), | ||
| 777 | - success(new_controller) then apply_controller_action(new_controller, plugins, controllers, _current_page_renderer, page_renderers, cinfo, new_session, failure, initial_session, logger), | ||
| 778 | - }, | ||
| 779 | - success(action_name) then | ||
| 780 | - //logger(logInfo, "ACTION_NAME ["+action_name+"] from IP "+get_String(_session.fields, "IP", "")); | ||
| 781 | - if apply_action(_session, action_name, *controller.controller_actions) is | ||
| 782 | - { | ||
| 783 | - http_answer(session, answer) then | ||
| 784 | - since session is web_session(id, lang, entries, current, previous, _), | ||
| 785 | - with new_web_session = web_session(id, lang, entries, current, previous, current), | ||
| 786 | -// println("***** http_answer(session, answer) record new draw point to *****"); | ||
| 787 | -// println("web arguments:"+ | ||
| 788 | -// dump_web_arg_values(*current.lwa)); | ||
| 789 | -// println("************************************"); | ||
| 790 | - (success(new_web_session), answer), | ||
| 791 | - | ||
| 792 | - http_answer(answer) then | ||
| 793 | - since _session is web_session(id, lang, entries, current, previous, _), | ||
| 794 | - with new_web_session = web_session(id, lang, entries, current, previous, current), | ||
| 795 | -// println("***** http_answer(answer) record new draw point to *****"); | ||
| 796 | -// println("web arguments:"+ | ||
| 797 | -// dump_web_arg_values(*current.lwa)); | ||
| 798 | -// println("************************************"); | ||
| 799 | - (success(new_web_session), answer), | ||
| 800 | - | ||
| 801 | - redirect(new_session) then | ||
| 802 | - if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers, logger) is | ||
| 803 | - { | ||
| 804 | - failure then (failure, error_page(http_not_found, "Redirect Controller not found", new_session)), | ||
| 805 | - success(new_controller) then apply_controller_action(new_controller, plugins, controllers, _current_page_renderer, page_renderers, cinfo, new_session, failure, initial_session, logger), | ||
| 806 | - }, | ||
| 807 | - | ||
| 808 | - redirect(new_session, r_controller_name, r_action_name) then | ||
| 809 | - if get_controller(r_controller_name, controllers, logger) is | ||
| 810 | - { | ||
| 811 | - failure then (failure, error_page(http_not_found, "Redirect Controller "+r_controller_name+" not found", new_session)), | ||
| 812 | - success(new_controller) then | ||
| 813 | - apply_controller_action(new_controller, plugins, controllers, _current_page_renderer, page_renderers, cinfo, new_session, success(r_action_name), initial_session, logger), | ||
| 814 | - }, | ||
| 815 | - | ||
| 816 | - redirect_to_previous then | ||
| 817 | - if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers, logger) is | ||
| 818 | - { | ||
| 819 | - failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)), | ||
| 820 | - success(new_controller) then | ||
| 821 | - since _session is web_session(id, lang, entries, _, previous, draw), | ||
| 822 | - apply_controller_action(new_controller, plugins, controllers, _current_page_renderer, page_renderers, cinfo, web_session(id, lang, entries, previous, previous, draw), failure, initial_session, logger), | ||
| 823 | - }, | ||
| 824 | - redirect_to_previous(entries) then | ||
| 825 | - if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers, logger) is | ||
| 826 | - { | ||
| 827 | - failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)), | ||
| 828 | - success(new_controller) then | ||
| 829 | - since _session is web_session(id, lang, _, _, previous, draw), | ||
| 830 | - apply_controller_action(new_controller, plugins, controllers, _current_page_renderer, page_renderers, cinfo, web_session(id, lang, entries, previous, previous, draw), failure, initial_session, logger), | ||
| 831 | - }, | ||
| 832 | - //ajax(answer) then (failure, answer), | ||
| 833 | - //ajax with modified session that must be saved | ||
| 834 | - ajax(session, answer) then (session, answer), | ||
| 835 | - | ||
| 836 | - //ajax(content, additional_script) then (failure, json(http_ok, to_html_ajax_content(content, cinfo, additional_script))), | ||
| 837 | - ajax(session, content, additional_script) then (session, json(http_ok, to_html_ajax_content(content, cinfo, additional_script))), | ||
| 838 | - //ajax(content, additional_script) then (failure, json(http_ok, to_html_ajax_content(content, additional_script))), | ||
| 839 | - ajax(session, content, additional_script) then (session, json(http_ok, to_html_ajax_content(content, additional_script))), | ||
| 840 | - send_file(file_path, c_disposition) then (failure, send_file(file_path, c_disposition)), | ||
| 841 | - renderer_content(session, content) then | ||
| 842 | - with the_session = if session is {failure then _session, success(__session) then __session}, | ||
| 843 | - since the_session is web_session(id, lang, entries, current, previous, _), | ||
| 844 | - with new_web_session = web_session(id, lang, entries, current, previous, current), | ||
| 845 | -// println("***** renderer_content(session, content) record new draw point to *****"); | ||
| 846 | -// println("web arguments:"+ | ||
| 847 | -// dump_web_arg_values(*current.lwa)); | ||
| 848 | -// println("************************************"); | ||
| 849 | - with page_renderer = get_page_renderer(new_web_session, _current_page_renderer, page_renderers, logger), | ||
| 850 | - (success(new_web_session), page_renderer.page_layout(new_web_session, plugins, content)) | ||
| 851 | - } | ||
| 852 | - } | ||
| 853 | -. | ||
| 854 | - | ||
| 855 | - | ||
| 856 | - | ||
| 857 | -public define Web_Site | ||
| 858 | - make_web_site_controller_description | ||
| 859 | - ( | ||
| 860 | - String website_name, // site_UID | ||
| 861 | - List(String) common_names, // for example: ["www.our-business.com"] | ||
| 862 | - String site_directory, | ||
| 863 | - String state_directory, | ||
| 864 | - One -> One init, | ||
| 865 | - (HTTP_Info, | ||
| 866 | - Var(List(Web_arg)), | ||
| 867 | - Bool is_https) -> WEB_Session initial_session, | ||
| 868 | - (WEB_Session, | ||
| 869 | - HTTP_Info, | ||
| 870 | - Var(List(Web_arg)), | ||
| 871 | - Bool is_https) -> WEB_Session expired_session, | ||
| 872 | - Var(List(WEB_Controller)) web_controllers, | ||
| 873 | - Var(List(WEB_Page_Renderer)) web_page_renderers, | ||
| 874 | - Var(List(WEB_Plugin)) web_plugins, | ||
| 875 | - Maybe(WEB_Session) -> List(HTTP_header) additional_headers, | ||
| 876 | - List(HTTP_header) constant_additional_headers, | ||
| 877 | - Int timeout, | ||
| 878 | - Redirections redirections, | ||
| 879 | - String charset, | ||
| 880 | - List(String) journal_extensions, | ||
| 881 | - List(String) journal_headers, | ||
| 882 | - (LogLevel, String) -> One logger, //logger | ||
| 883 | - String secret, | ||
| 884 | - List(MIME) known_mime_types, | ||
| 885 | - (String action_name, | ||
| 886 | - List(Web_arg) args) -> One before_send_file | ||
| 887 | - )= | ||
| 888 | - //call the initialization function | ||
| 889 | - init(unique); | ||
| 890 | - | ||
| 891 | - | ||
| 892 | - // | ||
| 893 | - // make required directories (if needed) | ||
| 894 | - // | ||
| 895 | - with //web_sites_directory = (String) make_directory(my_anubis_directory+"/web_sites"), | ||
| 896 | - base_directory = (String) make_directory(site_directory), | ||
| 897 | - // state_directory = make_directory(site_directory+"/states"), | ||
| 898 | - forget((String)make_directory(site_directory+"/public")); | ||
| 899 | - | ||
| 900 | - // | ||
| 901 | - // construct tool functions | ||
| 902 | - // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true | ||
| 903 | - with save_session = make_save_session_function(timeout, state_directory, logger), | ||
| 904 | - with current_page_renderer = var((WEB_Page_Renderer)default_page_renderer), | ||
| 905 | - // with left_menu_list = get_left_menu_from_plugins(*web_plugins), | ||
| 906 | - // retrieve_session = make_retrieve_session_function(state_directory, website_name), | ||
| 907 | - //separate_web_args = make_separate_web_args_function(state_directory, retrieve_state), | ||
| 908 | - //apply_action = make_apply_action_function(actions), | ||
| 909 | - | ||
| 910 | - // | ||
| 911 | - // construct the site handler | ||
| 912 | - // | ||
| 913 | - site_handler = (Word32 http_port, Word32 https_port) |-> | ||
| 914 | - ((String host_name, | ||
| 915 | - HTTP_Info http_info, | ||
| 916 | - List(Web_arg) _lwa, | ||
| 917 | - Bool is_https) |-> | ||
| 918 | - //(Printable_tree) | ||
| 919 | - logger(logTrace,"host_name "+host_name); | ||
| 920 | - logger(logTrace, dump_http_info(http_info)); | ||
| 921 | - logger(logTrace, dump_web_arg_values(_lwa)); | ||
| 922 | - with cinfo = info(host_name, http_port, https_port, site_directory, secret), | ||
| 923 | - | ||
| 924 | - //retrieve the previous session and determine the new one | ||
| 925 | - with current_session = if retrieve_session(http_info, state_directory, website_name) is | ||
| 926 | - { | ||
| 927 | - not_found then | ||
| 928 | - logger(logInfo, "previous state not found"); | ||
| 929 | - initial_session(http_info, var(_lwa), is_https), | ||
| 930 | - | ||
| 931 | - out_of_date(previous_session) then | ||
| 932 | - logger(logInfo, "previous out_of_date"); | ||
| 933 | - //expired_session(previous_session, http_info, var(_lwa), is_https), | ||
| 934 | - since previous_session is web_session(id, lang, entries, previous, _, draw), | ||
| 935 | - replace_String(entries, "IP", http_header_value(http_info.http_headers, "x-forwarded-for", ip_addr_to_string(http_info.ip_address))); | ||
| 936 | - web_session(id, lang, entries, web_request(http_info, var(_lwa), is_https), previous, draw) | ||
| 937 | - | ||
| 938 | - still_valid(previous_session) then | ||
| 939 | - since previous_session is web_session(id, lang, entries, previous, _, draw), | ||
| 940 | - replace_String(entries, "IP", http_header_value(http_info.http_headers, "x-forwarded-for", ip_addr_to_string(http_info.ip_address))); | ||
| 941 | - web_session(id, lang, entries, web_request(http_info, var(_lwa), is_https), previous, draw) | ||
| 942 | - }, | ||
| 943 | - | ||
| 944 | - | ||
| 945 | - //apply the action according to current session | ||
| 946 | - //since apply_controller_action(get_controller(get_String(lwa, "aws_controller", "root"), *web_controllers), *web_controllers, current_session) | ||
| 947 | - since if get_controller(get_String(*current_session.web_request.lwa, "aws_controller", "root"), *web_controllers, logger) is | ||
| 948 | - { | ||
| 949 | - failure then | ||
| 950 | - (failure, error_page(http_not_found, "Controller not found", current_session)), | ||
| 951 | - | ||
| 952 | - success(new_controller) then | ||
| 953 | - apply_controller_action(new_controller, *web_plugins, *web_controllers, *current_page_renderer, *web_page_renderers, cinfo, current_session, failure, initial_session, logger), | ||
| 954 | - } | ||
| 955 | - is (mb_new_session, http_answer), | ||
| 956 | - | ||
| 957 | - //save the session if need and construct the according cookie | ||
| 958 | - with cookie_headers = | ||
| 959 | - if mb_new_session is | ||
| 960 | - { | ||
| 961 | - failure then [], | ||
| 962 | - success(new_session) then | ||
| 963 | - with session_name = save_session(new_session), | ||
| 964 | - make_session_cookie_headers(website_name, session_name) | ||
| 965 | - }, | ||
| 966 | - | ||
| 967 | - //formatting and send http answer because this is the last function | ||
| 968 | - format(cinfo, | ||
| 969 | - //state_name, | ||
| 970 | - additional_headers(mb_new_session) + cookie_headers, | ||
| 971 | - http_answer, | ||
| 972 | - is_https, | ||
| 973 | - charset) | ||
| 974 | - ), | ||
| 975 | - // | ||
| 976 | - // make the delete_out_of_date function | ||
| 977 | - // | ||
| 978 | - delete_out_of_date = | ||
| 979 | - make_delete_out_of_date_sessions_function(site_directory+"/states", logger), | ||
| 980 | - // | ||
| 981 | - // construct the web site description | ||
| 982 | - // | ||
| 983 | - web_site((Word32 http_port, Word32 https_port) |-> | ||
| 984 | - web_site_description(common_names, | ||
| 985 | - site_directory, | ||
| 986 | - redirections, | ||
| 987 | - charset, | ||
| 988 | - journal_extensions, | ||
| 989 | - journal_headers, | ||
| 990 | - logger, | ||
| 991 | - secret, | ||
| 992 | - known_mime_types, | ||
| 993 | - site_handler(http_port,https_port), | ||
| 994 | - constant_additional_headers, | ||
| 995 | - (HTTP_Info http_info, List(Web_arg) lwa) |-> unique | ||
| 996 | -// if separate_web_args(lwa, http_info ) is | ||
| 997 | -// swa(mb_previous_state,mb_action_name,operands) then | ||
| 998 | -// if mb_action_name is | ||
| 999 | -// { | ||
| 1000 | -// failure then unique | ||
| 1001 | -// success(an) then before_send_file(an,operands) | ||
| 1002 | -// } | ||
| 1003 | - //using_state_cookies | ||
| 1004 | - ), | ||
| 1005 | - delete_out_of_date). | ||
| 1006 | - |
web/plugin/plugin.anubis
| @@ -7,9 +7,10 @@ | @@ -7,9 +7,10 @@ | ||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | read system/logger.anubis | 9 | read system/logger.anubis |
| 10 | - read app/app_constants.anubis | 10 | +read app/app_constants.anubis |
| 11 | read calexium_lib/web/widgets/left_menu.anubis | 11 | read calexium_lib/web/widgets/left_menu.anubis |
| 12 | transmit calexium_lib/web/types/making_a_web_site.anubis | 12 | transmit calexium_lib/web/types/making_a_web_site.anubis |
| 13 | +read calexium_lib/web/types/controllers_web_site.anubis | ||
| 13 | read calexium_lib/web/widgets/menu.anubis | 14 | read calexium_lib/web/widgets/menu.anubis |
| 14 | read hayamiki_lib/model/database.anubis | 15 | read hayamiki_lib/model/database.anubis |
| 15 | read hayamiki_lib/view/view_table_manager_types.anubis | 16 | read hayamiki_lib/view/view_table_manager_types.anubis |
web/types/controllers_web_site.anubis
| @@ -6,7 +6,12 @@ | @@ -6,7 +6,12 @@ | ||
| 6 | * © David RENÉ | 6 | * © David RENÉ |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | -transmit CXM_web_session.anubis | 9 | +read tools/printable_tree.anubis |
| 10 | +transmit web_session.anubis | ||
| 11 | +transmit calexium_lib/web/CXM_making_a_web_site.anubis | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 10 | 15 | ||
| 11 | public type WEB_Controller_Result: | 16 | public type WEB_Controller_Result: |
| 12 | http_answer( | 17 | http_answer( |
| @@ -58,3 +63,22 @@ public type WEB_Controller_Result: | @@ -58,3 +63,22 @@ public type WEB_Controller_Result: | ||
| 58 | // HTML_Partial_Content content | 63 | // HTML_Partial_Content content |
| 59 | // ) | 64 | // ) |
| 60 | . | 65 | . |
| 66 | + | ||
| 67 | +public type WEB_Action: | ||
| 68 | + web_action( | ||
| 69 | + WEB_Action_Name name, // name of action | ||
| 70 | + WEB_Action_Allowed_Protocol allowed_proto, | ||
| 71 | + (WEB_Session) -> Bool allow, // true if action allowed | ||
| 72 | + (WEB_Session) -> WEB_Controller_Result do_it | ||
| 73 | + ) | ||
| 74 | +. | ||
| 75 | + | ||
| 76 | + | ||
| 77 | + | ||
| 78 | +public type WEB_Controller: | ||
| 79 | + web_controller( | ||
| 80 | + String name, //controller name | ||
| 81 | + Var(List(WEB_Action)) controller_actions, //list of all actions of that controller | ||
| 82 | + (WEB_Session)-> WEB_Controller_Result error //Error renderer | ||
| 83 | + ) | ||
| 84 | +. |
| 1 | +/* | ||
| 2 | + * Created by PyramIDE. | ||
| 3 | + * User: フランスのトトロ aka (David RENÉ) | ||
| 4 | + * Date: 08/10/2019 | ||
| 5 | + * Time: 18:01 | ||
| 6 | + * © David RENÉ | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +read calexium_lib/web/CXM_common.anubis | ||
| 10 | +read calexium_lib/database/db_types.anubis | ||
| 11 | + | ||
| 12 | +public type WEB_Session_Field_Datum: | ||
| 13 | + string(String), //fully implented | ||
| 14 | + bool(Bool), //fully implented | ||
| 15 | + int(Int), //fully implemented | ||
| 16 | + db_id(DB_id), | ||
| 17 | + message(Message), //fully implemented | ||
| 18 | + byte_array(ByteArray), | ||
| 19 | + float(Float), | ||
| 20 | + word128(Word128), | ||
| 21 | + word64(Word64), | ||
| 22 | + word32(Word32), | ||
| 23 | + word16(Word16), | ||
| 24 | + word8(Word8), | ||
| 25 | + word4(Word4) | ||
| 26 | + //WEB_Request | ||
| 27 | +. | ||
| 28 | + | ||
| 29 | +public type WEB_Session_Field_Type: | ||
| 30 | + string_t, | ||
| 31 | + bool_t, | ||
| 32 | + int_t, | ||
| 33 | + db_id_t, | ||
| 34 | + message_t, | ||
| 35 | + byte_array_t, | ||
| 36 | + float_t, | ||
| 37 | + word128_t, | ||
| 38 | + word64_t, | ||
| 39 | + word32_t, | ||
| 40 | + word16_t, | ||
| 41 | + word8_t, | ||
| 42 | + word4_t | ||
| 43 | +. | ||
| 44 | + | ||
| 45 | +public type WEB_Session_Field: | ||
| 46 | + session_field( | ||
| 47 | + String field_name, | ||
| 48 | + WEB_Session_Field_Type field_type, | ||
| 49 | + Var(WEB_Session_Field_Datum) field_datum //Var because it can be replaced | ||
| 50 | + ). | ||
| 51 | + | ||
| 52 | +public type WEB_Session_Field_No_Var: | ||
| 53 | + session_field( | ||
| 54 | + String field_name, | ||
| 55 | + WEB_Session_Field_Type field_type, | ||
| 56 | + WEB_Session_Field_Datum field_datum //Var because it can be replaced | ||
| 57 | + ). | ||
| 58 | + | ||
| 59 | +public type WEB_Request: | ||
| 60 | + web_request( | ||
| 61 | + HTTP_Info http_info, | ||
| 62 | + Var(List(Web_arg)) lwa, | ||
| 63 | + Bool is_https, | ||
| 64 | + ) | ||
| 65 | +. | ||
| 66 | + | ||
| 67 | +public type WEB_Request_No_Var: | ||
| 68 | + web_request( | ||
| 69 | + HTTP_Info http_info, | ||
| 70 | + List(Web_arg) lwa, | ||
| 71 | + Bool is_https, | ||
| 72 | + ) | ||
| 73 | +. | ||
| 74 | + | ||
| 75 | +public type WEB_Session: | ||
| 76 | + web_session( | ||
| 77 | + String session_id, | ||
| 78 | + String language, | ||
| 79 | + Var(List(WEB_Session_Field)) fields, | ||
| 80 | + WEB_Request web_request, | ||
| 81 | + WEB_Request previous_web_request, | ||
| 82 | + WEB_Request draw_web_request | ||
| 83 | + ) | ||
| 84 | +. | ||
| 85 | + | ||
| 86 | +public type WEB_Session_No_Var: | ||
| 87 | + web_session( | ||
| 88 | + String session_id, | ||
| 89 | + String language, | ||
| 90 | + List(WEB_Session_Field_No_Var) fields, | ||
| 91 | + WEB_Request_No_Var web_request, | ||
| 92 | + WEB_Request_No_Var previous_web_request, | ||
| 93 | + WEB_Request_No_Var draw_web_request, | ||
| 94 | + ) | ||
| 95 | +. | ||
| 96 | + |