Commit 1dcf554d93a46837cdab646e7e3e0816dbd35f8f
1 parent
3bada934
start working on web controller version
Showing
6 changed files
with
223 additions
and
25 deletions
Show diff stats
web/CXM_common.anubis
| ... | ... | @@ -61,7 +61,19 @@ public define String |
| 61 | 61 | )= |
| 62 | 62 | join("\n\r",to_List_String(l)). |
| 63 | 63 | |
| 64 | - | |
| 64 | + | |
| 65 | +public type HTTP_Info: | |
| 66 | + http_info | |
| 67 | + ( | |
| 68 | + Word32 ip_address, // IP address of the client | |
| 69 | + String hostname, // hostname requested by the client | |
| 70 | + String uri, // URI requested by the client | |
| 71 | + List(HTTP_header) http_headers, // HTTP headers sent by the client | |
| 72 | + Bool is_https | |
| 73 | + //One -> String generate_trust_ticket // may be used against denial of | |
| 74 | + // service attacks | |
| 75 | + ). | |
| 76 | + | |
| 65 | 77 | *Name* Web_arg |
| 66 | 78 | *Description* |
| 67 | 79 | ... | ... |
web/CXM_form.anubis
| ... | ... | @@ -559,7 +559,7 @@ public define HTML_In_Form |
| 559 | 559 | sequence([ |
| 560 | 560 | literal("<fieldset" + format_attrs(options) + ">"), |
| 561 | 561 | literal(if length(legend) > 0 then "<legend>" + legend + "</legend>" else ""), |
| 562 | - sequence( map((CXM_Form_Field ff) |-> div([class("form_field")], format_CXM_Form_Field(ff, lwa)), fields) ), | |
| 562 | + sequence( map((CXM_Form_Field ffield) |-> div([class("form_field")], format_CXM_Form_Field(ffield, lwa)), fields) ), | |
| 563 | 563 | literal("</fieldset>") |
| 564 | 564 | ]), |
| 565 | 565 | ... | ... |
web/CXM_json.anubis
web/CXM_making_a_web_site.anubis
| ... | ... | @@ -60,6 +60,8 @@ read CXM_multihost_http_server.anubis |
| 60 | 60 | read web/mime.anubis |
| 61 | 61 | read CXM_cookies.anubis |
| 62 | 62 | read CXM_json.anubis |
| 63 | +read CXM_web_dump.anubis | |
| 64 | + | |
| 63 | 65 | //read CXM_html_tooltip.anubis |
| 64 | 66 | |
| 65 | 67 | * (1) Structure of a web site. |
| ... | ... | @@ -352,9 +354,18 @@ public type HTTP_Answer:... |
| 352 | 354 | conversation between the client and the web site, but also containing informations |
| 353 | 355 | taken from the data bases. |
| 354 | 356 | |
| 357 | +transmit CXM_controller.anubis | |
| 355 | 358 | |
| 356 | - | |
| 357 | - | |
| 359 | +public type WEB_Controller($State): | |
| 360 | + web_controller( | |
| 361 | + String name, //controller name | |
| 362 | + (HTTP_Info http_info, | |
| 363 | + List(Web_arg) lwa, | |
| 364 | + Bool is_https, | |
| 365 | + $State session | |
| 366 | + ) -> ($State, HTTP_Answer) view //view renderer | |
| 367 | + ) | |
| 368 | +. | |
| 358 | 369 | |
| 359 | 370 | ** (1.5) States. |
| 360 | 371 | |
| ... | ... | @@ -2706,7 +2717,199 @@ public define Web_Site |
| 2706 | 2717 | ), |
| 2707 | 2718 | delete_out_of_date). |
| 2708 | 2719 | |
| 2720 | + public type WEB_Controller: | |
| 2721 | + web_controller( | |
| 2722 | + String name, //controller name | |
| 2723 | + (HTTP_Info http_info, | |
| 2724 | + List(Web_arg) lwa, | |
| 2725 | + Bool is_https | |
| 2726 | + ) -> HTTP_Answer view //view renderer | |
| 2727 | + ) | |
| 2728 | + | |
| 2729 | +define ($State, HTTP_Answer) | |
| 2730 | + controller_404 | |
| 2731 | + (HTTP_Info http_info, | |
| 2732 | + List(Web_arg) lwa, | |
| 2733 | + Bool is_https, | |
| 2734 | + $State session | |
| 2735 | + ) = | |
| 2736 | + (session, | |
| 2737 | + html_page | |
| 2738 | + ( | |
| 2739 | + "page not found", // title of web site | |
| 2740 | + [], // list of 'META' tags (empty for this site) | |
| 2741 | + body // body of page | |
| 2742 | + ( | |
| 2743 | + // list of body options | |
| 2744 | + [ | |
| 2745 | + background_color(rgb(255,200,200)) | |
| 2746 | + ], | |
| 2747 | + | |
| 2748 | + // content of page | |
| 2749 | + center(text([size(14)],"Error 404, Page not found")) | |
| 2750 | + ) | |
| 2751 | + )) | |
| 2752 | +. | |
| 2753 | + | |
| 2754 | +define (HTTP_Info http_info, | |
| 2755 | + List(Web_arg) lwa, | |
| 2756 | + Bool is_https, | |
| 2757 | + $State session | |
| 2758 | + ) -> ($State, HTTP_Answer) | |
| 2759 | + get_controller | |
| 2760 | + ( | |
| 2761 | + String controller_name, | |
| 2762 | + List(WEB_Controller($State)) controllers | |
| 2763 | + )= | |
| 2764 | + if controllers is | |
| 2765 | + { | |
| 2766 | + [] then controller_404, | |
| 2767 | + [h . t] then | |
| 2768 | + if h.name = controller_name then | |
| 2769 | + h.view | |
| 2770 | + else | |
| 2771 | + get_controller(controller_name, t) | |
| 2772 | + } | |
| 2773 | +. | |
| 2774 | + | |
| 2775 | +public define Web_Site | |
| 2776 | + make_web_site_controller_description | |
| 2777 | + ( | |
| 2778 | + String website_name, // site_UID | |
| 2779 | + List(String) common_names, // for example: ["www.our-business.com"] | |
| 2780 | + String site_directory, | |
| 2781 | + String state_directory, | |
| 2782 | + One -> One init, | |
| 2783 | + (HTTP_Info, | |
| 2784 | + List(Web_arg), | |
| 2785 | + Bool is_https) -> $State initial_state, | |
| 2786 | + ($State expired, | |
| 2787 | + Maybe(String), | |
| 2788 | + HTTP_Info, | |
| 2789 | + List(Web_arg), | |
| 2790 | + Bool is_https) -> $State ticket_expired_state, | |
| 2791 | + (Maybe(String), | |
| 2792 | + HTTP_Info, | |
| 2793 | + List(Web_arg), | |
| 2794 | + Bool is_https) -> $State ticket_lost_state, | |
| 2795 | + //List(Web_Action($State)) actions, | |
| 2796 | + Var(List(WEB_Controller($State))) web_controllers, | |
| 2797 | + //$State -> HTTP_Answer compute_page, | |
| 2798 | + $State -> List(HTTP_header) additional_headers, | |
| 2799 | + Int timeout, | |
| 2800 | + Redirections redirections, | |
| 2801 | + String charset, | |
| 2802 | + List(String) journal_extensions, | |
| 2803 | + List(String) journal_headers, | |
| 2804 | + String secret, | |
| 2805 | + List(MIME) known_mime_types, | |
| 2806 | + (String action_name, | |
| 2807 | + List(Web_arg) args) -> One before_send_file | |
| 2808 | + //Bool using_state_cookies | |
| 2809 | + ) = | |
| 2810 | + init(unique); | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + // | |
| 2814 | + // make required directories (if needed) | |
| 2815 | + // | |
| 2816 | + with //web_sites_directory = (String) make_directory(my_anubis_directory+"/web_sites"), | |
| 2817 | + base_directory = (String) make_directory(site_directory), | |
| 2818 | + // state_directory = make_directory(site_directory+"/states"), | |
| 2819 | + forget((String)make_directory(site_directory+"/public")); | |
| 2820 | + // | |
| 2821 | + // construct tool functions | |
| 2822 | + // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true | |
| 2823 | + with save_state = make_save_state_function(timeout, state_directory), | |
| 2824 | + retrieve_state = make_retrieve_state_function(state_directory), | |
| 2825 | + separate_web_args = make_separate_web_args_function(state_directory, retrieve_state, website_name), | |
| 2826 | + //apply_action = make_apply_action_function(actions), | |
| 2827 | + // | |
| 2828 | + // construct the site handler | |
| 2829 | + // | |
| 2830 | + site_handler = (Word32 http_port, Word32 https_port) |-> | |
| 2831 | + ((String host_name, | |
| 2832 | + HTTP_Info http_info, | |
| 2833 | + List(Web_arg) lwa, | |
| 2834 | + Bool is_https) |-> | |
| 2835 | + //(Printable_tree) | |
| 2836 | + println(dump_http_info(http_info)); | |
| 2837 | + println(dump_web_arg_values(lwa)); | |
| 2838 | + | |
| 2839 | + since separate_web_args(lwa, http_info) is swa(mb_previous_state, mb_action_name, operands), | |
| 2840 | + | |
| 2841 | + with new_state = if mb_previous_state is | |
| 2842 | + { | |
| 2843 | + not_found then | |
| 2844 | + //println("previous state not found"); | |
| 2845 | + if mb_action_name is | |
| 2846 | + { | |
| 2847 | + failure then initial_state(http_info, operands, is_https), | |
| 2848 | + success(_) then | |
| 2849 | + ticket_lost_state(mb_action_name, http_info,operands,is_https) | |
| 2850 | + }, | |
| 2851 | + | |
| 2852 | + out_of_date(state) then | |
| 2853 | + //println("previous out_of_date"); | |
| 2854 | + ticket_expired_state(state, mb_action_name, http_info,operands,is_https), | |
| 2855 | + | |
| 2856 | + still_valid(state) then state | |
| 2709 | 2857 | |
| 2858 | + }, | |
| 2859 | + //if state_and_headers is (session_ticket, mb_new_state, headers) then | |
| 2860 | + with state_name = save_state(new_state), | |
| 2861 | + //println("Cookie new STATE NAME "+state_name); | |
| 2862 | + with cookie_headers = if mb_action_name is | |
| 2863 | + { | |
| 2864 | + failure then | |
| 2865 | + make_state_cookie_headers(website_name, state_name), | |
| 2866 | + success(action_name) then | |
| 2867 | + if action_name = "none" then | |
| 2868 | + [] | |
| 2869 | + else if substr(action_name, 0, 5)="ajax_" then | |
| 2870 | + [] | |
| 2871 | + else | |
| 2872 | + make_state_cookie_headers(website_name, state_name) | |
| 2873 | + }, | |
| 2874 | + with controller = get_controller("root", *web_controllers), | |
| 2875 | + since controller(http_info, lwa, is_https, new_state) is (result_state, http_answer), | |
| 2876 | + format(info(host_name, http_port, https_port, site_directory, secret), | |
| 2877 | + state_name, | |
| 2878 | + additional_headers(new_state) + cookie_headers, | |
| 2879 | + http_answer, | |
| 2880 | + is_https, | |
| 2881 | + charset) | |
| 2882 | + ), | |
| 2883 | + // | |
| 2884 | + // make the delete_out_of_date function | |
| 2885 | + // | |
| 2886 | + delete_out_of_date = | |
| 2887 | + make_delete_out_of_date_states_function((Maybe($State))failure, | |
| 2888 | + site_directory+"/states"), | |
| 2889 | + // | |
| 2890 | + // construct the web site description | |
| 2891 | + // | |
| 2892 | + web_site((Word32 http_port, Word32 https_port) |-> | |
| 2893 | + web_site_description(common_names, | |
| 2894 | + site_directory, | |
| 2895 | + redirections, | |
| 2896 | + charset, | |
| 2897 | + journal_extensions, | |
| 2898 | + journal_headers, | |
| 2899 | + secret, | |
| 2900 | + known_mime_types, | |
| 2901 | + site_handler(http_port,https_port), | |
| 2902 | + (HTTP_Info http_info, List(Web_arg) lwa) |-> if separate_web_args(lwa, http_info ) is | |
| 2903 | + swa(mb_previous_state,mb_action_name,operands) then | |
| 2904 | + if mb_action_name is | |
| 2905 | + { | |
| 2906 | + failure then unique | |
| 2907 | + success(an) then before_send_file(an,operands) | |
| 2908 | + } | |
| 2909 | + //using_state_cookies | |
| 2910 | + ), | |
| 2911 | + delete_out_of_date). | |
| 2912 | + | |
| 2710 | 2913 | |
| 2711 | 2914 | define String |
| 2712 | 2915 | get_site_uid | ... | ... |
web/CXM_multihost_http_server.anubis
| ... | ... | @@ -181,17 +181,7 @@ read web/mime.anubis |
| 181 | 181 | informations are rarely used for composing HTML pages. Nevertheless, they are at your |
| 182 | 182 | disposal. |
| 183 | 183 | |
| 184 | -public type HTTP_Info: | |
| 185 | - http_info | |
| 186 | - ( | |
| 187 | - Word32 ip_address, // IP address of the client | |
| 188 | - String hostname, // hostname requested by the client | |
| 189 | - String uri, // URI requested by the client | |
| 190 | - List(HTTP_header) http_headers, // HTTP headers sent by the client | |
| 191 | - Bool is_https | |
| 192 | - //One -> String generate_trust_ticket // may be used against denial of | |
| 193 | - // service attacks | |
| 194 | - ). | |
| 184 | + | |
| 195 | 185 | |
| 196 | 186 | |
| 197 | 187 | |
| ... | ... | @@ -2350,13 +2340,6 @@ define One |
| 2350 | 2340 | else log_journal_msg(desc,"Cannot find or read authorization file.\n") |
| 2351 | 2341 | }. |
| 2352 | 2342 | |
| 2353 | - | |
| 2354 | - | |
| 2355 | - | |
| 2356 | - | |
| 2357 | - | |
| 2358 | - | |
| 2359 | - | |
| 2360 | 2343 | *** [5.6] Answering a www-url encoded request. |
| 2361 | 2344 | |
| 2362 | 2345 | Standard headers are for answering ".awp" requests. | ... | ... |
web/CXM_web_dump.anubis
| ... | ... | @@ -10,8 +10,8 @@ |
| 10 | 10 | read tools/basis.anubis |
| 11 | 11 | read system/string.anubis |
| 12 | 12 | read system/convert.anubis |
| 13 | -read calexium_lib/web/CXM_common.anubis | |
| 14 | -read calexium_lib/web/CXM_multihost_http_server.anubis | |
| 13 | +read CXM_common.anubis | |
| 14 | +read CXM_multihost_http_server.anubis | |
| 15 | 15 | |
| 16 | 16 | /* Provides a dump of Web_arg List */ |
| 17 | 17 | public define String | ... | ... |