diff --git a/web/CXM_common.anubis b/web/CXM_common.anubis index dcc006e..36eba83 100644 --- a/web/CXM_common.anubis +++ b/web/CXM_common.anubis @@ -61,7 +61,19 @@ public define String )= join("\n\r",to_List_String(l)). - + +public type HTTP_Info: + http_info + ( + Word32 ip_address, // IP address of the client + String hostname, // hostname requested by the client + String uri, // URI requested by the client + List(HTTP_header) http_headers, // HTTP headers sent by the client + Bool is_https + //One -> String generate_trust_ticket // may be used against denial of + // service attacks + ). + *Name* Web_arg *Description* diff --git a/web/CXM_form.anubis b/web/CXM_form.anubis index af90746..85b8662 100644 --- a/web/CXM_form.anubis +++ b/web/CXM_form.anubis @@ -559,7 +559,7 @@ public define HTML_In_Form sequence([ literal("
") ]), diff --git a/web/CXM_json.anubis b/web/CXM_json.anubis index b39640a..06d4a07 100644 --- a/web/CXM_json.anubis +++ b/web/CXM_json.anubis @@ -11,7 +11,7 @@ read tools/basis.anubis read tools/printable_tree.anubis transmit web/mime.anubis -transmit extensions/json.anubis +transmit calexium_lib/extensions/json.anubis public type JsonMember:... diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index c4c2f51..8feb263 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -60,6 +60,8 @@ read CXM_multihost_http_server.anubis read web/mime.anubis read CXM_cookies.anubis read CXM_json.anubis +read CXM_web_dump.anubis + //read CXM_html_tooltip.anubis * (1) Structure of a web site. @@ -352,9 +354,18 @@ public type HTTP_Answer:... conversation between the client and the web site, but also containing informations taken from the data bases. +transmit CXM_controller.anubis - - +public type WEB_Controller($State): + web_controller( + String name, //controller name + (HTTP_Info http_info, + List(Web_arg) lwa, + Bool is_https, + $State session + ) -> ($State, HTTP_Answer) view //view renderer + ) +. ** (1.5) States. @@ -2706,7 +2717,199 @@ public define Web_Site ), delete_out_of_date). + public type WEB_Controller: + web_controller( + String name, //controller name + (HTTP_Info http_info, + List(Web_arg) lwa, + Bool is_https + ) -> HTTP_Answer view //view renderer + ) + +define ($State, HTTP_Answer) + controller_404 + (HTTP_Info http_info, + List(Web_arg) lwa, + Bool is_https, + $State session + ) = + (session, + html_page + ( + "page not found", // title of web site + [], // list of 'META' tags (empty for this site) + body // body of page + ( + // list of body options + [ + background_color(rgb(255,200,200)) + ], + + // content of page + center(text([size(14)],"Error 404, Page not found")) + ) + )) +. + +define (HTTP_Info http_info, + List(Web_arg) lwa, + Bool is_https, + $State session + ) -> ($State, HTTP_Answer) + get_controller + ( + String controller_name, + List(WEB_Controller($State)) controllers + )= + if controllers is + { + [] then controller_404, + [h . t] then + if h.name = controller_name then + h.view + else + get_controller(controller_name, t) + } +. + +public define Web_Site + make_web_site_controller_description + ( + String website_name, // site_UID + List(String) common_names, // for example: ["www.our-business.com"] + String site_directory, + String state_directory, + One -> One init, + (HTTP_Info, + List(Web_arg), + Bool is_https) -> $State initial_state, + ($State expired, + Maybe(String), + HTTP_Info, + List(Web_arg), + Bool is_https) -> $State ticket_expired_state, + (Maybe(String), + HTTP_Info, + List(Web_arg), + Bool is_https) -> $State ticket_lost_state, + //List(Web_Action($State)) actions, + Var(List(WEB_Controller($State))) web_controllers, + //$State -> HTTP_Answer compute_page, + $State -> List(HTTP_header) additional_headers, + Int timeout, + Redirections redirections, + String charset, + List(String) journal_extensions, + List(String) journal_headers, + String secret, + List(MIME) known_mime_types, + (String action_name, + List(Web_arg) args) -> One before_send_file + //Bool using_state_cookies + ) = + init(unique); + + + // + // make required directories (if needed) + // + with //web_sites_directory = (String) make_directory(my_anubis_directory+"/web_sites"), + base_directory = (String) make_directory(site_directory), + // state_directory = make_directory(site_directory+"/states"), + forget((String)make_directory(site_directory+"/public")); + // + // construct tool functions + // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true + with save_state = make_save_state_function(timeout, state_directory), + retrieve_state = make_retrieve_state_function(state_directory), + separate_web_args = make_separate_web_args_function(state_directory, retrieve_state, website_name), + //apply_action = make_apply_action_function(actions), + // + // construct the site handler + // + site_handler = (Word32 http_port, Word32 https_port) |-> + ((String host_name, + HTTP_Info http_info, + List(Web_arg) lwa, + Bool is_https) |-> + //(Printable_tree) + println(dump_http_info(http_info)); + println(dump_web_arg_values(lwa)); + + since separate_web_args(lwa, http_info) is swa(mb_previous_state, mb_action_name, operands), + + with new_state = if mb_previous_state is + { + not_found then + //println("previous state not found"); + if mb_action_name is + { + failure then initial_state(http_info, operands, is_https), + success(_) then + ticket_lost_state(mb_action_name, http_info,operands,is_https) + }, + + out_of_date(state) then + //println("previous out_of_date"); + ticket_expired_state(state, mb_action_name, http_info,operands,is_https), + + still_valid(state) then state + }, + //if state_and_headers is (session_ticket, mb_new_state, headers) then + with state_name = save_state(new_state), + //println("Cookie new STATE NAME "+state_name); + with cookie_headers = if mb_action_name is + { + failure then + make_state_cookie_headers(website_name, state_name), + success(action_name) then + if action_name = "none" then + [] + else if substr(action_name, 0, 5)="ajax_" then + [] + else + make_state_cookie_headers(website_name, state_name) + }, + with controller = get_controller("root", *web_controllers), + since controller(http_info, lwa, is_https, new_state) is (result_state, http_answer), + format(info(host_name, http_port, https_port, site_directory, secret), + state_name, + additional_headers(new_state) + cookie_headers, + http_answer, + is_https, + charset) + ), + // + // make the delete_out_of_date function + // + delete_out_of_date = + make_delete_out_of_date_states_function((Maybe($State))failure, + site_directory+"/states"), + // + // construct the web site description + // + web_site((Word32 http_port, Word32 https_port) |-> + web_site_description(common_names, + site_directory, + redirections, + charset, + journal_extensions, + journal_headers, + secret, + known_mime_types, + site_handler(http_port,https_port), + (HTTP_Info http_info, List(Web_arg) lwa) |-> if separate_web_args(lwa, http_info ) is + swa(mb_previous_state,mb_action_name,operands) then + if mb_action_name is + { + failure then unique + success(an) then before_send_file(an,operands) + } + //using_state_cookies + ), + delete_out_of_date). + define String get_site_uid diff --git a/web/CXM_multihost_http_server.anubis b/web/CXM_multihost_http_server.anubis index 91e837e..6de8588 100644 --- a/web/CXM_multihost_http_server.anubis +++ b/web/CXM_multihost_http_server.anubis @@ -181,17 +181,7 @@ read web/mime.anubis informations are rarely used for composing HTML pages. Nevertheless, they are at your disposal. -public type HTTP_Info: - http_info - ( - Word32 ip_address, // IP address of the client - String hostname, // hostname requested by the client - String uri, // URI requested by the client - List(HTTP_header) http_headers, // HTTP headers sent by the client - Bool is_https - //One -> String generate_trust_ticket // may be used against denial of - // service attacks - ). + @@ -2350,13 +2340,6 @@ define One else log_journal_msg(desc,"Cannot find or read authorization file.\n") }. - - - - - - - *** [5.6] Answering a www-url encoded request. Standard headers are for answering ".awp" requests. diff --git a/web/CXM_web_dump.anubis b/web/CXM_web_dump.anubis index 4e17ccb..63f3a1e 100644 --- a/web/CXM_web_dump.anubis +++ b/web/CXM_web_dump.anubis @@ -10,8 +10,8 @@ read tools/basis.anubis read system/string.anubis read system/convert.anubis -read calexium_lib/web/CXM_common.anubis -read calexium_lib/web/CXM_multihost_http_server.anubis +read CXM_common.anubis +read CXM_multihost_http_server.anubis /* Provides a dump of Web_arg List */ public define String -- libgit2 0.21.4