diff --git a/database/db_types.anubis b/database/db_types.anubis index aace0c5..fd24400 100644 --- a/database/db_types.anubis +++ b/database/db_types.anubis @@ -8,26 +8,32 @@ transmit tools/basis.anubis transmit tools/ISO-8601.anubis +transmit calexium_lib/database/types/db_id.anubis +transmit calexium_lib/database/types/db_date.anubis +transmit calexium_lib/database/types/db_time.anubis +transmit calexium_lib/database/types/db_datetime.anubis +transmit calexium_lib/database/types/db_integer.anubis + /* DB_id will is deprecated. Please use next version below all upper case */ -public type DB_id: - none, - db_id(Int value). +//public type DB_id: +// none, +// db_id(Int value). public type DB_ID: none, pk(Int value). -public type DB_datetime: - db_datetime(String datetime). //Date and time in ISO8601 format "YYYY-MM-DD hh:mm:ss" +//public type DB_datetime: +// db_datetime(String datetime). //Date and time in ISO8601 format "YYYY-MM-DD hh:mm:ss" -public type DB_date: - db_date(String date). //Date in ISO8601 format "YYYY-MM-DD" - -public type DB_time: - db_time(String time). //Time in ISO8601 format "hh:mm:ss" - -public type DB_integer: - db_integer(Int value). +//public type DB_date: +// db_date(String date). //Date in ISO8601 format "YYYY-MM-DD" +// +//public type DB_time: +// db_time(String time). //Time in ISO8601 format "hh:mm:ss" +// +//public type DB_integer: +// db_integer(Int value). public define String diff --git a/database/types/db_date.anubis b/database/types/db_date.anubis new file mode 100644 index 0000000..d89e44f --- /dev/null +++ b/database/types/db_date.anubis @@ -0,0 +1,64 @@ +/* + * Created by 伝作 (Densaku). + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) + * Date: 2017-02-15 + * Time: 02:18:49 + * + */ + +transmit system/muscle.anubis +transmit system/convert.anubis +transmit tools/basis.anubis + + +public type DB_date: + db_date( + String date //Date and time in ISO8601 format "YYYY-MM-DD" + ) +. + + DB_date message format + ====================== + + +public define Message + to_Message + ( + DB_date _db_date + )= + with _db_date_message = message((Word32)0), // + forget(add_string(_db_date_message, "__TYPE__", "DB_date")); + if _db_date is + { + //Alternative db_date + db_date(_date) then + forget(add_string(_db_date_message, "__TYPE_ALT__", "db_date")); + // [type = String] db_date.date + forget(add_string(_db_date_message, "date", _date)), + + }; + _db_date_message +. + +public define Maybe(DB_date) + from_Message + ( + Message _db_date_message + )= + if find_string(_db_date_message, "__TYPE__") is {failure then failure, success(__type__) then + if find_string(_db_date_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then + if __type__ = "DB_date" then + //Alternative db_date + if __type_alt__ = "db_date" then //Alternative db_date + // [type = String] db_date.date + if find_string(_db_date_message, "date") is {failure then failure, success(date) then + + success(db_date(date)) + } + else + failure //No valid Alternative found ! + else + failure //Type not found in message ! + }} +. + diff --git a/database/types/db_datetime.anubis b/database/types/db_datetime.anubis new file mode 100644 index 0000000..a129f99 --- /dev/null +++ b/database/types/db_datetime.anubis @@ -0,0 +1,64 @@ +/* + * Created by 伝作 (Densaku). + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) + * Date: 2017-02-15 + * Time: 02:18:48 + * + */ + +transmit system/muscle.anubis +transmit system/convert.anubis +transmit tools/basis.anubis + + +public type DB_datetime: + db_datetime( + String datetime //Date and time in ISO8601 format "YYYY-MM-DD hh:mm:ss" + ) +. + + DB_datetime message format + ========================== + + +public define Message + to_Message + ( + DB_datetime _db_datetime + )= + with _db_datetime_message = message((Word32)0), // + forget(add_string(_db_datetime_message, "__TYPE__", "DB_datetime")); + if _db_datetime is + { + //Alternative db_datetime + db_datetime(_datetime) then + forget(add_string(_db_datetime_message, "__TYPE_ALT__", "db_datetime")); + // [type = String] db_datetime.datetime + forget(add_string(_db_datetime_message, "datetime", _datetime)), + + }; + _db_datetime_message +. + +public define Maybe(DB_datetime) + from_Message + ( + Message _db_datetime_message + )= + if find_string(_db_datetime_message, "__TYPE__") is {failure then failure, success(__type__) then + if find_string(_db_datetime_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then + if __type__ = "DB_datetime" then + //Alternative db_datetime + if __type_alt__ = "db_datetime" then //Alternative db_datetime + // [type = String] db_datetime.datetime + if find_string(_db_datetime_message, "datetime") is {failure then failure, success(datetime) then + + success(db_datetime(datetime)) + } + else + failure //No valid Alternative found ! + else + failure //Type not found in message ! + }} +. + diff --git a/database/types/db_id.anubis b/database/types/db_id.anubis new file mode 100644 index 0000000..9e8145e --- /dev/null +++ b/database/types/db_id.anubis @@ -0,0 +1,73 @@ +/* + * Created by 伝作 (Densaku). + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) + * Date: 2017-02-15 + * Time: 02:18:48 + * + */ + +transmit system/muscle.anubis +transmit system/convert.anubis +transmit tools/basis.anubis + + +public type DB_id: + none, //no database Primary Key ID + db_id( + Int value //Integer value of the Primary Key ID + ) +. + + DB_id message format + ==================== + + +public define Message + to_Message + ( + DB_id _db_id + )= + with _db_id_message = message((Word32)0), // + forget(add_string(_db_id_message, "__TYPE__", "DB_id")); + if _db_id is + { + //Alternative none (NO TYPE) + none then + forget(add_string(_db_id_message, "__TYPE_ALT__", "none")), + + //Alternative db_id + db_id(_value) then + forget(add_string(_db_id_message, "__TYPE_ALT__", "db_id")); + // [type = Int] db_id.value + forget(add_string(_db_id_message, "value", to_String(_value))), + + }; + _db_id_message +. + +public define Maybe(DB_id) + from_Message + ( + Message _db_id_message + )= + if find_string(_db_id_message, "__TYPE__") is {failure then failure, success(__type__) then + if find_string(_db_id_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then + if __type__ = "DB_id" then + //Alternative none (NO TYPE) + if __type_alt__ = "none" then + success(none) + else //Alternative db_id + if __type_alt__ = "db_id" then //Alternative db_id + // [type = Int] db_id.value + if find_string(_db_id_message, "value") is {failure then failure, success(_value) then + if decimal_scan(_value) is { failure then failure, success(value) then + + success(db_id(value)) + }} + else + failure //No valid Alternative found ! + else + failure //Type not found in message ! + }} +. + diff --git a/database/types/db_integer.anubis b/database/types/db_integer.anubis new file mode 100644 index 0000000..efcbe98 --- /dev/null +++ b/database/types/db_integer.anubis @@ -0,0 +1,65 @@ +/* + * Created by 伝作 (Densaku). + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) + * Date: 2017-02-15 + * Time: 02:18:49 + * + */ + +transmit system/muscle.anubis +transmit system/convert.anubis +transmit tools/basis.anubis + + +public type DB_integer: + db_integer( + Int value //Integer from datatase + ) +. + + DB_integer message format + ========================= + + +public define Message + to_Message + ( + DB_integer _db_integer + )= + with _db_integer_message = message((Word32)0), // + forget(add_string(_db_integer_message, "__TYPE__", "DB_integer")); + if _db_integer is + { + //Alternative db_integer + db_integer(_value) then + forget(add_string(_db_integer_message, "__TYPE_ALT__", "db_integer")); + // [type = Int] db_integer.value + forget(add_string(_db_integer_message, "value", to_String(_value))), + + }; + _db_integer_message +. + +public define Maybe(DB_integer) + from_Message + ( + Message _db_integer_message + )= + if find_string(_db_integer_message, "__TYPE__") is {failure then failure, success(__type__) then + if find_string(_db_integer_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then + if __type__ = "DB_integer" then + //Alternative db_integer + if __type_alt__ = "db_integer" then //Alternative db_integer + // [type = Int] db_integer.value + if find_string(_db_integer_message, "value") is {failure then failure, success(_value) then + if decimal_scan(_value) is { failure then failure, success(value) then + + success(db_integer(value)) + }} + else + failure //No valid Alternative found ! + else + failure //Type not found in message ! + }} +. + diff --git a/database/types/db_time.anubis b/database/types/db_time.anubis new file mode 100644 index 0000000..ad63385 --- /dev/null +++ b/database/types/db_time.anubis @@ -0,0 +1,64 @@ +/* + * Created by 伝作 (Densaku). + * Types & Messages generator written by フランスのトトロ aka (David RENÉ) + * Date: 2017-02-15 + * Time: 02:18:49 + * + */ + +transmit system/muscle.anubis +transmit system/convert.anubis +transmit tools/basis.anubis + + +public type DB_time: + db_time( + String time //Date and time in ISO8601 format "hh:mm:ss" + ) +. + + DB_time message format + ====================== + + +public define Message + to_Message + ( + DB_time _db_time + )= + with _db_time_message = message((Word32)0), // + forget(add_string(_db_time_message, "__TYPE__", "DB_time")); + if _db_time is + { + //Alternative db_time + db_time(_time) then + forget(add_string(_db_time_message, "__TYPE_ALT__", "db_time")); + // [type = String] db_time.time + forget(add_string(_db_time_message, "time", _time)), + + }; + _db_time_message +. + +public define Maybe(DB_time) + from_Message + ( + Message _db_time_message + )= + if find_string(_db_time_message, "__TYPE__") is {failure then failure, success(__type__) then + if find_string(_db_time_message, "__TYPE_ALT__") is {failure then failure, success(__type_alt__) then + if __type__ = "DB_time" then + //Alternative db_time + if __type_alt__ = "db_time" then //Alternative db_time + // [type = String] db_time.time + if find_string(_db_time_message, "time") is {failure then failure, success(time) then + + success(db_time(time)) + } + else + failure //No valid Alternative found ! + else + failure //Type not found in message ! + }} +. + diff --git a/web/CXM_form.anubis b/web/CXM_form.anubis index 85b8662..dd1f9fe 100644 --- a/web/CXM_form.anubis +++ b/web/CXM_form.anubis @@ -241,7 +241,7 @@ public type CXM_Form_Field: //--- submit button ------------------------------------------------------------------- submit (List(CoreAttrs) options, HtmlClass class, - String action_name, + WEB_Action_Name action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands), @@ -310,11 +310,11 @@ public define CXM_Form_Field = radio_buttonr([], label, html_Id(n.name), n, value, checked, mand). public define CXM_Form_Field - submit(String action_name, HtmlClass class, Maybe(String) label, String button_text, List((String,String)) extra_operands) + submit(WEB_Action_Name action_name, HtmlClass class, Maybe(String) label, String button_text, List((String,String)) extra_operands) = submit([], class, action_name, label, button_text, extra_operands). public define CXM_Form_Field - submit(String action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands) + submit(WEB_Action_Name action_name, Maybe(String) label, String button_text, List((String,String)) extra_operands) = submit([], htmlClass(""), action_name, label, button_text, extra_operands). public define CXM_Form_Field @@ -619,9 +619,9 @@ public define HTML_In_Form public define HTML_Off_Form cxm_form ( - HTML_Id form_Id, + HTML_Id form_Id, List(CoreAttrs) options, - String action_name, + WEB_Action_Name action, List((String,String)) extra_ops, List(Web_arg) lwa, List(CXM_Form_Field) fields @@ -630,7 +630,7 @@ public define HTML_Off_Form form( form_Id, [class("cxm_form") . options], - action_name, + action, extra_ops, format_CXM_Form_Field(fields, lwa) ). @@ -640,12 +640,12 @@ public define HTML_Off_Form ( String form_name, List(CoreAttrs) options, - String action_name, + WEB_Action_Name action, List((String,String)) extra_ops, List(Web_arg) lwa, List(CXM_Form_Field) form_fields )= - cxm_form(html_Id(form_name), options, action_name, extra_ops, lwa, form_fields). + cxm_form(html_Id(form_name), options, action, extra_ops, lwa, form_fields). public define HTML_In_Form cxm_fieldset @@ -665,7 +665,7 @@ public define HTML_Off_Form List(CoreAttrs) options, List(HTML_In_Form) fields ) = - cxm_form(html_Id(form_id), options, "", [], [], map((HTML_In_Form field) |-> raw_in_form(field), fields) ). + cxm_form(html_Id(form_id), options, action_name(""), [], [], map((HTML_In_Form field) |-> raw_in_form(field), fields) ). public define HTML_Off_Form cxm_form @@ -675,7 +675,7 @@ public define HTML_Off_Form List(Web_arg) lwa, List(CXM_Form_Field) fields ) = - cxm_form(html_Id(form_id), options, "", [], lwa, fields). + cxm_form(html_Id(form_id), options, action_name(""), [], lwa, fields). public define HTML_Off_Form cxm_form @@ -683,7 +683,7 @@ public define HTML_Off_Form String form_id, List(HTML_In_Form) fields ) = - cxm_form(html_Id(form_id), [], "", [], [], map((HTML_In_Form field) |-> raw_in_form(field), fields) ). + cxm_form(html_Id(form_id), [], action_name(""), [], [], map((HTML_In_Form field) |-> raw_in_form(field), fields) ). public define HTML_Off_Form cxm_form @@ -700,4 +700,4 @@ public define HTML_Off_Form String form_id, List(CXM_Form_Field) fields ) = - cxm_form(html_Id(form_id), [], "", [], [], fields). + cxm_form(html_Id(form_id), [], action_name(""), [], [], fields). diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index 8feb263..f304692 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -5,7 +5,7 @@ *Title* Making interactive Web sites. *Copyright* Copyright (c) Alain Prouté 2004-2005. - Copyright (c) Calexium 2007-2016. + Copyright (c) Calexium 2007-2017. *Authors* Alain Prouté @@ -47,7 +47,7 @@ --------------------------------------------------------------------------------------- -read tools/basis.anubis +transmit tools/basis.anubis read tools/printable_tree.anubis read tools/base64.anubis read tools/random.anubis @@ -55,12 +55,13 @@ read tools/dictionaries.anubis read system/lists.anubis read system/string.anubis read system/logger.anubis -read CXM_common.anubis -read CXM_multihost_http_server.anubis +transmit CXM_common.anubis +transmit CXM_multihost_http_server.anubis read web/mime.anubis read CXM_cookies.anubis read CXM_json.anubis -read CXM_web_dump.anubis +transmit CXM_web_dump.anubis +transmit CXM_web_arg_utils.anubis //read CXM_html_tooltip.anubis @@ -276,64 +277,6 @@ public type Web_Action($State): In most cases, HTTP informations are not used. This is the reason why they are gathered for simplicity into a unique datum of type 'HTTP_Info'. -// For your convenience, we introduce the following simpler variants: -// -//public define Web_Action($State) -// http_action -// ( -// String name, -// $State -> Bool allow, -// (List(Web_arg),$State) -> $State do_it -// ) = -// http_action(name, -// (Maybe($State) ms) |-> if ms is -// { -// failure then true, -// success(s) then allow(s) -// }, -// (HTTP_Info h, List(Web_arg) l, Maybe($State) s) |-> if s is -// { -// failure then (failure, []), -// success(s2) then (success(do_it(l,s2)), []) -// }). -// -//public define Web_Action($State) -// https_action -// ( -// String name, -// $State -> Bool allow, -// (List(Web_arg),$State) -> $State do_it -// ) = -// https_action(name, -// (Maybe($State) ms) |-> if ms is -// { -// failure then true, -// success(s) then allow(s) -// }, -// (HTTP_Info h, List(Web_arg) l, Maybe($State) s) |-> if s is -// { -// failure then (failure, []), -// success(s2) then (success(do_it(l,s2)), []) -// }). -// -//public define Web_Action($State) -// http_https_action -// ( -// String name, -// $State -> Bool allow, -// (List(Web_arg),$State) -> $State do_it -// ) = -// http_https_action(name, -// (Maybe($State) ms) |-> if ms is -// { -// failure then true, -// success(s) then allow(s) -// }, -// (HTTP_Info h, List(Web_arg) l, Maybe($State) s) |-> if s is -// { -// failure then (failure, []), -// success(s2) then (success(do_it(l,s2)), []) -// }). @@ -353,19 +296,189 @@ public type HTTP_Answer:... understand the page shown to the client as a representation of the current state of the 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): + +public type WEB_Action_Name: + controller_action( + String controller, + String action_name + ), + action_name( + String name + ) +. + +public type WEB_Session_Entry: + session_entry( + String field, + String value + ). + +public type WEB_Request: + web_request( + HTTP_Info http_info, + List(Web_arg) lwa, + Bool is_https, + ) +. + +public type WEB_Session: + web_session( + String language, + List(WEB_Session_Entry) entries, + WEB_Request web_request, + WEB_Request previous_request + ). + + + +public type WEB_Controller_Result: + http_answer( + WEB_Session session, //modified session + HTTP_Answer http_answer //http answer + ), + http_answer( + HTTP_Answer http_answer //http answer + ), + redirect( //internal redirection, session is modified to call the right controller and action + WEB_Session session + ), + redirect_to_previous, + ajax( + HTTP_Answer http_answer + ) +. + +public type WEB_Action_Allowed_Protocol: + http, + https, + http_https. + +public type WEB_Action: + web_action( + WEB_Action_Name name, // name of action + WEB_Action_Allowed_Protocol allowed_proto, + (WEB_Session) -> Bool allow, // true if action allowed + (WEB_Session) -> WEB_Controller_Result do_it + ) +. + +public type WEB_Controller: 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 + String name, //controller name + Var(List(WEB_Action)) controller_actions, //list of all actions of that controller + (WEB_Session)-> WEB_Controller_Result error //Error renderer ) . + +define List(HTTP_header) + make_session_cookie_headers + ( + String website_name, + String session_name + ) + = + //println("Set-Cookie state_"+website_name+"="+state_name); + [ + http_header("Set-Cookie", "session_"+website_name+"="+session_name) + ] + . + +define WEB_Session -> String // the function constructed returns the name of the state + make_save_session_function + ( + Int timeout, + String state_directory + ) = + (WEB_Session s) |-> + //Set the new timeout + with time_stamp = now+timeout, + to_be_saved = (time_stamp,s), + //generate new session name + session_name = to_ascii(sha1(s)), + //println("make_save_state_function " + state_directory+"/s"+state_name); + if save(to_be_saved,state_directory+"/"+session_name) is ok then + session_name + else + println("Cannot create session file in '"+state_directory+"'.\n"); + "" +. + + + When a request arrives, we need to retrieve the previous state from the server's + disk. We receive the name of that state. If the state is out of date, the state file is + kept 3 days, and then deleted. + +type Previous_Session: + not_found, // cannot retrieve the previous state + out_of_date(WEB_Session p_session), // the previous state is out of date + still_valid(WEB_Session p_session). // the previous state is still valid + +define Previous_Session + retrieve_session + ( + HTTP_Info http_info, + String session_directory, + String website_name + ) = + if find_cookie("session_"+website_name, server_get_cookies(http_headers(http_info))) is + { + failure then not_found + success(cookie) then + //println("find_cookie(\"state_"+website_name+"\" success"); + with session_name = value(cookie), + with file_path = session_directory+"/"+session_name, + //unserialize the stored session and his timeout value + if (RetrieveResult((Int, WEB_Session)))retrieve(file_path) is ok(d) then + ( + since d is (time_stamp, s), + if time_stamp < now then + ( + forget(remove(file_path)); + out_of_date(s) + ) + else + still_valid(s) // state has been successfully retrieved + ) + else + not_found + } +. + +define (List(String) file_names) -> One + make_delete_out_of_date_sessions_function + ( + String state_directory + ) = + (List(String) file_names) |-df-> + if file_names is + { + [ ] then unique, + [h . t] then + with file_path = state_directory+"/"+h, + if (RetrieveResult((Int, WEB_Session)))retrieve(file_path) is ok(d) + then ( + if d is (time_stamp,data) then + if time_stamp < now + then (forget(remove(file_path)); df(t)) + else df(t) + ) + else (forget(remove(file_path)); df(t)) + }. + +define One + delete_out_of_date_sessions // for all web sites + ( + List((String, List(String) -> One)) directories_and_functions + )= + if directories_and_functions is + { + [ ] then unique, + [h . t] then + since h is (state_directory, function), + function(directory_list(state_directory,"*")); + delete_out_of_date_sessions(t) + } +. ** (1.5) States. @@ -1236,7 +1349,7 @@ public type HTML_In_Form: Int content_width, Int content_height, HTML_In_Form content), actioner (Actioner_Connection, Actioner_Target, Actioner_Aspect, - String action_name, List((String,String)) extra_ops, + WEB_Action_Name action_name, List((String,String)) extra_ops, List(Actioner_Local_Action)), foreign_link_new (Actioner_Target, Actioner_Aspect, String url), foreign_link (List(Text_Option), String url), @@ -1293,15 +1406,16 @@ public define HTML_In_Form foreign_link([size(tsize)],url,name). public define HTML_In_Form - actioner - ( + actioner + ( Actioner_Connection conn, Actioner_Target targ, Actioner_Aspect asp, - String action_name, + WEB_Action_Name action, List((String,String)) extra_ops - ) = - actioner(conn,targ,asp,action_name,extra_ops,[]). + )= + actioner(conn,targ,asp,action,extra_ops,[]) +. public define HTML_In_Form actioner @@ -1310,7 +1424,7 @@ public define HTML_In_Form Actioner_Target targ, Actioner_Aspect asp, ) = - actioner(conn, targ, asp, "", [], []). + actioner(conn, targ, asp, action_name(""), [], []). public define HTML_In_Form @@ -1454,10 +1568,10 @@ public type HTML_Off_Form: fixed_size (HTML_Size width, HTML_Size height, HTML_Off_Form content), fixed_size_2 (HTML_Size width, HTML_Size height, String name_of_HTML_file), actioner (Actioner_Connection, Actioner_Target, Actioner_Aspect, - String action_name, List((String,String)) extra_ops, + WEB_Action_Name action_name, List((String,String)) extra_ops, List(Actioner_Local_Action)), actioner (Actioner_Connection, Actioner_Target, Actioner_Aspect, - String action_name, List((String,String)) extra_ops, + WEB_Action_Name action_name, List((String,String)) extra_ops, List(Actioner_Local_Action), String form_name), foreign_link_new (Actioner_Target, Actioner_Aspect, String url), foreign_link (List(Text_Option), String url), @@ -1467,7 +1581,7 @@ public type HTML_Off_Form: label (String name), form (HTML_Id form_id, List(CoreAttrs), HTML_In_Form content), form (HTML_Id form_id, List(CoreAttrs), - String action_name, List((String,String)) extra_ops, + WEB_Action_Name action, List((String,String)) extra_ops, HTML_In_Form content), in_form (HTML_Id form_id, HTML_In_Form content), div (List(CoreAttrs), HTML_Off_Form content), @@ -1507,11 +1621,11 @@ public define HTML_Off_Form ( String form_name, List(CoreAttrs) options, - String action_name, + WEB_Action_Name action, List((String,String)) extra_ops, HTML_In_Form content ) = - form(html_Id(form_name), options, action_name, extra_ops, content). + form(html_Id(form_name), options, action, extra_ops, content). public define HTML_Off_Form literal(Printable_tree t) = literal_pt(t). @@ -1535,10 +1649,10 @@ public define HTML_Off_Form Actioner_Connection conn, Actioner_Target targ, Actioner_Aspect asp, - String action_name, + WEB_Action_Name action, List((String,String)) extra_ops ) = - actioner(conn,targ,asp,action_name,extra_ops,[]). + actioner(conn,targ,asp,action,extra_ops,[]). public define HTML_Off_Form table @@ -1772,8 +1886,8 @@ define Printable_tree public type HTML_Meta: keywords (List(String)), refresh (Actioner_Connection connection, - Actioner_Target target, - String action_name, + Actioner_Target target, + WEB_Action_Name action, Int delay), // in seconds refresh (String url, Int delay), // in seconds meta (String name, String content), @@ -2009,22 +2123,26 @@ public define HTTP_Answer *** [1] States. *** [1.1] Saving and retrieving states. *** [1.2] Deleting out of date states. + + *** [2] Sessions. + *** [2.1] Saving and retrieving sessions. + *** [2.2] Deleting out of date sessions. + + *** [3] Tools. + *** [3.1] Directories. + *** [3.2] Secondary documents. - *** [2] Tools. - *** [2.1] Directories. - *** [2.2] Secondary documents. - - *** [3] Managing web arguments. + *** [4] Managing web arguments. *** [3.1] Prefixing web arguments names. *** [3.2] Separating web arguments. *** [3.3] Applying an action. - *** [4] Web site descriptions and the 'awp handlers'. + *** [5] Web site descriptions and the 'awp handlers'. *** [4.1] The type 'Web_Site'. *** [4.2] Making a web site description. *** [4.3] Starting the servers. - *** [5] HTML Formating. + *** [6] HTML Formating. *** [5.1] The type 'HTML_Any($T)'. *** [5.2] Formating a color. *** [5.3] Creating buttons. @@ -2043,7 +2161,7 @@ define Printable_tree format ( CommonInfo cinfo, - String sn, // state_name + //String sn, // state_name Var(Int) ic_v, // 'idnum' counter variable HTML_Off_Form element, Bool is_https, @@ -2086,7 +2204,8 @@ read CXM_web_arg_encode.anubis The tool below constructs the function which is able to save a state on the server's disk. - + + define ($State s) -> String // the function constructed returns the name of the state make_save_state_function ( @@ -2129,7 +2248,9 @@ define (String state_name) -> PreviousState($State) ) else still_valid(s) // state has been successfully retrieved ) - else not_found. + else + forget(remove(file_path)); + not_found. @@ -2150,7 +2271,7 @@ define (List(String) file_names) -> One { [ ] then unique, [h . t] then - with file_path = state_directory+"/"+h, + with file_path = state_directory+"/s"+h, if (RetrieveResult((Int,$State)))retrieve(file_path) is ok(d) then ( if d is (time_stamp,data) then @@ -2159,7 +2280,7 @@ define (List(String) file_names) -> One else df(t) ) else (forget(remove(file_path)); df(t)) - }. + }. The 'labelled arrow' |-df-> is documented in 'documentation/en/anubis_doc.txt'. @@ -2223,7 +2344,7 @@ define One else if now > next_time then ( - delete_out_of_date_states(directories_and_functions); + delete_out_of_date_states(directories_and_functions); delete_states_loop(directories_and_functions, timeout, now+timeout, @@ -2276,7 +2397,6 @@ define String ( String sd, // site directory String as, // authorization_secret - String sn, // state name $T -> Printable_tree format_element, $T content, HTML_Size width @@ -2428,8 +2548,6 @@ define (List(Web_arg) lwa, HTTP_Info info) -> Separated_Web_Args($State) - - *** [3.3] Applying an action. @@ -2546,7 +2664,7 @@ public define Printable_tree format ( CommonInfo cinfo, - String state_name, + //String state_name, List(HTTP_header) headers, HTTP_Answer page, Bool is_https, @@ -2681,7 +2799,7 @@ public define Web_Site }, format(info(host_name, http_port, https_port, site_directory, secret), - state_name, + //state_name, additional_headers(new_state) + cookie_headers, compute_page(new_state), is_https, @@ -2726,17 +2844,17 @@ public define Web_Site ) -> 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, + + +define HTTP_Answer + error_page + ( + HTTP_Status http_status + ) + = html_page ( - "page not found", // title of web site + http_status, // status [], // list of 'META' tags (empty for this site) body // body of page ( @@ -2746,56 +2864,141 @@ define ($State, HTTP_Answer) ], // content of page - center(text([size(14)],"Error 404, Page not found")) + sequence([ + text([size(16)], "Anubis Web Server 1.14"), + br, + text([size(16)],"Error "+to_String(http_status)) + ]) ) - )) + ) . -define (HTTP_Info http_info, - List(Web_arg) lwa, - Bool is_https, - $State session - ) -> ($State, HTTP_Answer) +define WEB_Controller_Result + apply_action + ( + WEB_Session _session, + String requested_action_name, + List(WEB_Action) actions_list + ) = + if actions_list is + { + [] then http_answer(error_page(http_not_found)), + [h . t] then + with action_name = if h.name is + { + controller_action(_, name) then name, + action_name(name) then name + }, + if requested_action_name = action_name then + if h.allowed_proto is + { + //Action only in HTTP + http then + if _session.web_request.is_https then + http_answer(error_page(http_forbidden)) + else + //ask to the server the authorization to execute that action + if h.allow(_session) then + h.do_it(_session) + else + http_answer(error_page(http_unauthorized)) + + //Action only in HTTPS + https then + if _session.web_request.is_https then + //ask to the server the authorization to execute that action + if h.allow(_session) then + h.do_it(_session) + else + http_answer(error_page(http_unauthorized)) + else + http_answer(error_page(http_forbidden)) + //Action in both HTTP / HTTPS + http_https then + //ask to the server the authorization to execute that action + if h.allow(_session) then + h.do_it(_session) + else + http_answer(error_page(http_unauthorized)) + + } + else + apply_action(_session, requested_action_name, t) + } +. + +define Maybe(WEB_Controller) get_controller ( String controller_name, - List(WEB_Controller($State)) controllers + List(WEB_Controller) controllers, )= if controllers is { - [] then controller_404, + [] then failure, [h . t] then if h.name = controller_name then - h.view + success(h) else get_controller(controller_name, t) } . +define (Maybe(WEB_Session), HTTP_Answer) + apply_controller_action + ( + WEB_Controller controller, + List(WEB_Controller) controllers, + WEB_Session _session + )= + //get the action name + if get_String(_session.web_request.lwa, "aws_action") is + { + failure then (failure, error_page(http_not_found)), + success(action_name) then + + if apply_action(_session, action_name, *controller.controller_actions) is + { + http_answer(session, answer) then (success(session), answer), + http_answer(answer) then (success(_session), answer), + redirect(new_session) then + if get_controller(get_String(new_session.web_request.lwa, "aws_controller", "root"), controllers) is + { + failure then (failure, error_page(http_not_found)), + success(new_controller) then apply_controller_action(new_controller, controllers, new_session), + } + + redirect_to_previous then + if get_controller(get_String(_session.previous_request.lwa, "aws_controller", "root"), controllers) is + { + failure then (failure, error_page(http_not_found)), + success(new_controller) then + since _session is web_session(lang, entries, _, previous), + apply_controller_action(new_controller, controllers, web_session(lang, entries, previous, previous)), + } + + ajax(answer) then (failure, answer), + } + } +. + 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, + 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), + Bool is_https) -> WEB_Session initial_session, + (WEB_Session, 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, + Bool is_https) -> WEB_Session expired_session, + Var(List(WEB_Controller)) web_controllers, + Maybe(WEB_Session) -> List(HTTP_header) additional_headers, Int timeout, Redirections redirections, String charset, @@ -2805,9 +3008,9 @@ public define Web_Site List(MIME) known_mime_types, (String action_name, List(Web_arg) args) -> One before_send_file - //Bool using_state_cookies - ) = - init(unique); + )= + //call the initialization function + init(unique); // @@ -2820,72 +3023,74 @@ public define Web_Site // // 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), + with save_session = make_save_session_function(timeout, state_directory), + // retrieve_session = make_retrieve_session_function(state_directory, website_name), + //separate_web_args = make_separate_web_args_function(state_directory, retrieve_state), //apply_action = make_apply_action_function(actions), + // // construct the site handler // - site_handler = (Word32 http_port, Word32 https_port) |-> + site_handler = (Word32 http_port, Word32 https_port) |-> ((String host_name, HTTP_Info http_info, - List(Web_arg) lwa, + List(Web_arg) _lwa, Bool is_https) |-> //(Printable_tree) + println("host_name "+host_name); println(dump_http_info(http_info)); - println(dump_web_arg_values(lwa)); + 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), + //retrieve the previous session and determine the new one + with current_session = if retrieve_session(http_info, state_directory, website_name) is + { + not_found then + //println("previous state not found"); + initial_session(http_info, _lwa, is_https), - still_valid(state) then state + out_of_date(previous_session) then + //println("previous out_of_date"); + expired_session(previous_session, http_info, _lwa, is_https), - }, - //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) - ), + still_valid(previous_session) then + since previous_session is web_session(lang, entries, previous, _), + web_session(lang, entries, web_request(http_info, _lwa, is_https), previous) + }, + + + //apply the action according to current session + //since apply_controller_action(get_controller(get_String(lwa, "aws_controller", "root"), *web_controllers), *web_controllers, current_session) + since if get_controller(get_String(current_session.web_request.lwa, "aws_controller", "root"), *web_controllers) is + { + failure then (failure, error_page(http_not_found)), + success(new_controller) then apply_controller_action(new_controller, *web_controllers, current_session), + } + is (mb_new_session, http_answer), + + //save the session if need and construct the according cookie + with cookie_headers = + if mb_new_session is + { + failure then [], + success(new_session) then + with session_name = save_session(new_session), + make_session_cookie_headers(website_name, session_name) + }, + + //formatting and send http answer because this is the last function + format(info(host_name, http_port, https_port, site_directory, secret), + //state_name, + additional_headers(mb_new_session) + 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"), + make_delete_out_of_date_sessions_function(site_directory+"/states"), // // construct the web site description // @@ -2899,13 +3104,14 @@ public define Web_Site 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) - } + (HTTP_Info http_info, List(Web_arg) lwa) |-> unique +// 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). @@ -3102,7 +3308,7 @@ type HTML_Any($T): any_actioner (Actioner_Connection, Actioner_Target, Actioner_Aspect, - String action_name, + WEB_Action_Name action, List((String,String)) extra_ops, List(Actioner_Local_Action), Maybe(String) form_name), @@ -3298,25 +3504,39 @@ define Int window. define String - make_actioner_url - ( - CommonInfo cinfo, - Actioner_Connection connection, - Actioner_Target target, - String state_name, - String action_name, - List((String,String)) extra_ops, - Bool is_https - ) = + make_actioner_url + ( + CommonInfo cinfo, + Actioner_Connection connection, + Actioner_Target target, + WEB_Action_Name action, + List((String,String)) extra_ops, + Bool is_https + ) = if cinfo is info(common_name,http_port,https_port,site_directory,secret) then with strict_url = if connection is { same then "/", - http then "http://"+common_name+":"+http_port+"/", - https then "https://"+common_name+":"+https_port+"/", + http then + if http_port = 80 then + "http://"+common_name+"/" + else + "http://"+common_name+":"+http_port+"/", + https then + if https_port = 443 then + "https://"+common_name+"/" + else + "https://"+common_name+":"+https_port+"/", } + - "?a=" + action_name + + //with action_string = + if action is + { + controller_action(controller, action_name) then "?aws_controller="+controller+"&aws_action="+action_name, + action_name(action_name) then "?aws_action="+action_name + } + //"?a=" + action_name + + + format_extra_operands(extra_ops), if target is { @@ -3738,7 +3958,7 @@ define Printable_tree String url, Bool is_https, CommonInfo cinfo, - String state_name, +// String state_name, Var(Int) action_count, Var(Int) ic_v, // 'idnum' counter variable Var(List(HTML_Head_Tag)) head_tags @@ -3781,7 +4001,7 @@ define Printable_tree html(html_off_form) then [ "", - format(cinfo, state_name, ic_v, html_off_form, is_https, action_count, head_tags), + format(cinfo, ic_v, html_off_form, is_https, action_count, head_tags), "" ] }. @@ -3790,11 +4010,10 @@ define Printable_tree format_actioner ( CommonInfo cinfo, - String state_name, Actioner_Connection connection, Actioner_Target target, Actioner_Aspect aspect, - String action_name, + WEB_Action_Name action, List((String,String)) extra_ops, List(Actioner_Local_Action) local_actions, Maybe(String) mb_form_name, @@ -3807,8 +4026,8 @@ define Printable_tree if cinfo is info(common_name,http_port,https_port,site_dir,secret) then with url = make_actioner_url(cinfo,connection,target, - state_name,action_name,extra_ops,is_https), - with action = format_action(url, aspect, extract_id(aspect), mb_form_name, action_count), + action,extra_ops,is_https), + with formatted_action = format_action(url, aspect, extract_id(aspect), mb_form_name, action_count), if aspect is { @@ -3821,6 +4040,10 @@ define Printable_tree ], img_link(options, img, alt_text) then //if action name is empty, format options on image because maybe there onclick action + with action_name = if action is { + controller_action(_, an) then an, + action_name(an) then an + }, if action_name ="" then [ "", text, "" ], javascript(s,h) then + with action_name = + if action is + { + controller_action(_, an) then an, + action_name(an) then an + }, if action_name = "" then [""] else @@ -3846,7 +4075,7 @@ define Printable_tree } ], button(url_off,url_on) then - [ if action is + [ if formatted_action is { url(u) then ["", text, "" ], javascript(s,h) then + with action_name = if action is { + controller_action(_, an) then an, + action_name(an) then an + }, if action_name = "" then // special case where URL (so the action_name) is provided by the form itself // so javascript isn't needed. This is the standard HMTL way. [""] @@ -3900,7 +4133,7 @@ define Printable_tree [ //if custom function name is provided, that name is used instead of autogenerated js function if custom_function_name = "" then - if action is + if formatted_action is { url(u) then [""], @@ -4695,9 +4920,9 @@ define Printable_tree [ "", format_label(label, id)] div(options, e) then - format(cinfo,sn,ic_v,any_div(options, e),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_div(options, e),format_element,is_https, action_count, head_tags), div_empty(options) then - format(cinfo,sn,ic_v,any_div_empty(options),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_div_empty(options),format_element,is_https, action_count, head_tags), hidden(_id, name, value) then since _id is html_Id(id), [""], @@ -4705,17 +4930,17 @@ define Printable_tree if p_content is partial_content(tags, html_elements) then head_tags <- *head_tags + tags; - format(cinfo, sn, ic_v, html_elements, is_https, action_count, head_tags), + format(cinfo, ic_v, html_elements, is_https, action_count, head_tags), br then ["
"], progress(options, value, max) then [""], ol(opts, t) then - format(cinfo,sn,ic_v,any_ol(opts,t),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_ol(opts,t),format_element,is_https, action_count, head_tags), ul(opts, t) then - format(cinfo,sn,ic_v,any_ul(opts,t),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_ul(opts,t),format_element,is_https, action_count, head_tags), li(opts, t) then - format(cinfo,sn,ic_v,any_li(opts,t),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_li(opts,t),format_element,is_https, action_count, head_tags), button(options, e) then - format(cinfo,sn,ic_v,any_button(options, e),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_button(options, e),format_element,is_https, action_count, head_tags), }. @@ -4821,7 +5046,6 @@ define Printable_tree format ( CommonInfo cinfo, - String sn, // state_name Var(Int) ic_v, // 'idnum' counter variable HTML_Off_Form element, Bool is_https, @@ -4829,7 +5053,7 @@ define Printable_tree Var(List(HTML_Head_Tag)) head_tags ) = if cinfo is info(common_name,http_port,https_port,site_directory,secret) then - with format_element = (HTML_Off_Form e) |-> format(cinfo, sn, ic_v, e, is_https, action_count, head_tags), + with format_element = (HTML_Off_Form e) |-> format(cinfo, ic_v, e, is_https, action_count, head_tags), if element is { empty then [], @@ -4837,44 +5061,44 @@ define Printable_tree literal(t) then [t], sequence(l) then flat(map(format_element,l)), text(opts,t) then - format(cinfo,sn,ic_v,any_text(opts,t),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_text(opts,t),format_element,is_https, action_count, head_tags), preformated(o,s) then - format(cinfo,sn,ic_v,any_preformated(o,s),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_preformated(o,s),format_element,is_https, action_count, head_tags), paragraph(opts,t) then - format(cinfo,sn,ic_v,any_paragraph(opts,t),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_paragraph(opts,t),format_element,is_https, action_count, head_tags), image(opts,url,alt) then - format(cinfo,sn,ic_v,any_image(opts,url,alt),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_image(opts,url,alt),format_element,is_https, action_count, head_tags), image(opts,url,alt,w,h) then - format(cinfo,sn,ic_v,any_image(opts,url,alt,w,h),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_image(opts,url,alt,w,h),format_element,is_https, action_count, head_tags), table(opts,header_row, rows, footer_row) then - format(cinfo,sn,ic_v,any_table(opts,header_row, rows, footer_row),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_table(opts,header_row, rows, footer_row),format_element,is_https, action_count, head_tags), center(e) then - format(cinfo,sn,ic_v,any_center(e),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_center(e),format_element,is_https, action_count, head_tags), mail_to(a,e) then - format(cinfo,sn,ic_v,any_mail_to(a,e),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_mail_to(a,e),format_element,is_https, action_count, head_tags), scroller(w,h,cw,ch,c) then - format(cinfo,sn,ic_v,any_scroller(w,h,cw,ch,c),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_scroller(w,h,cw,ch,c),format_element,is_https, action_count, head_tags), fixed_size(w,h,c) then - format(cinfo,sn,ic_v,any_fixed_size(w,h,c),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_fixed_size(w,h,c),format_element,is_https, action_count, head_tags), fixed_size_2(w,h,fn) then - format(cinfo,sn,ic_v,any_fixed_size_2(w,h,fn),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_fixed_size_2(w,h,fn),format_element,is_https, action_count, head_tags), actioner(c,t,a,an,eo,ja) then - format(cinfo,sn,ic_v,any_actioner(c,t,a,an,eo,ja,failure),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_actioner(c,t,a,an,eo,ja,failure),format_element,is_https, action_count, head_tags), actioner(c,t,a,an,eo,ja,fn) then - format(cinfo,sn,ic_v,any_actioner(c,t,a,an,eo,ja,success(fn)),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_actioner(c,t,a,an,eo,ja,success(fn)),format_element,is_https, action_count, head_tags), foreign_link_new(target, aspect, url) then - format(cinfo,sn,ic_v,any_foreign_link_new(target,aspect,url),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_foreign_link_new(target,aspect,url),format_element,is_https, action_count, head_tags), foreign_link(options,url) then - format(cinfo,sn,ic_v,any_foreign_link(options,url),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_foreign_link(options,url),format_element,is_https, action_count, head_tags), foreign_link(options,url,name) then - format(cinfo,sn,ic_v,any_foreign_link(options,url,name),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_foreign_link(options,url,name),format_element,is_https, action_count, head_tags), private_download(url,name,extra,action) then - format(cinfo,sn,ic_v,any_private_download(url,name,extra,action),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_private_download(url,name,extra,action),format_element,is_https, action_count, head_tags), label(n) then [""], form(fn,attributs, c) then [ "
" ] - form(fn,attributs, action_name, extra_ops, c) then + form(fn,attributs, action, extra_ops, c) then with url = make_actioner_url(cinfo, same, same, - sn, action_name, extra_ops, is_https), + action, extra_ops, is_https), [ "", @@ -4901,20 +5125,20 @@ define Printable_tree // action is set dynamically by // the actioner using JavaScript if fn is html_Id(id) then - format(cinfo,id,sn,ic_v,c,is_https, action_count, head_tags), + format(cinfo,id,ic_v,c,is_https, action_count, head_tags), "
" ], in_form(fn, content) then if fn is html_Id(id) then - format(cinfo,id,sn,ic_v, content,is_https, action_count, head_tags), + format(cinfo,id,ic_v, content,is_https, action_count, head_tags), div(options, e) then - format(cinfo, sn, ic_v, any_div(options, e), format_element, is_https, action_count, head_tags), + format(cinfo, ic_v, any_div(options, e), format_element, is_https, action_count, head_tags), div(options, p_content) then if p_content is partial_content(tags, html_elements) then head_tags <- *head_tags +tags; - format(cinfo, sn, ic_v, any_div(options, html_elements), format_element, is_https, action_count, head_tags), + format(cinfo, ic_v, any_div(options, html_elements), format_element, is_https, action_count, head_tags), div_empty(options) then - format(cinfo, sn, ic_v, any_div_empty(options), format_element, is_https, action_count, head_tags), + format(cinfo, ic_v, any_div_empty(options), format_element, is_https, action_count, head_tags), iframe(options, css_styles, css_files, js_files, body) then if body is body(body_options,elem) then [ "\n", @@ -4925,7 +5149,7 @@ define Printable_tree add_js_files(js_files), "\n", "\n", // format body options - format(cinfo,sn,ic_v,elem,is_https, action_count, head_tags), + format(cinfo,ic_v,elem,is_https, action_count, head_tags), "\n", "\n", "\n", @@ -4933,17 +5157,17 @@ define Printable_tree partial(p_content) then if p_content is partial_content(tags, html_elements) then head_tags <- *head_tags + tags; - format(cinfo, sn, ic_v, html_elements, is_https, action_count, head_tags), + format(cinfo, ic_v, html_elements, is_https, action_count, head_tags), br then ["
"], progress(options, value, max) then [""], ol(opts, t) then - format(cinfo,sn,ic_v,any_ol(opts,t),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_ol(opts,t),format_element,is_https, action_count, head_tags), ul(opts, t) then - format(cinfo,sn,ic_v,any_ul(opts,t),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_ul(opts,t),format_element,is_https, action_count, head_tags), li(opts, t) then - format(cinfo,sn,ic_v,any_li(opts,t),format_element,is_https, action_count, head_tags), + format(cinfo,ic_v,any_li(opts,t),format_element,is_https, action_count, head_tags), button(options, e) then - format(cinfo, sn, ic_v, any_button(options, e), format_element, is_https, action_count, head_tags), + format(cinfo, ic_v, any_button(options, e), format_element, is_https, action_count, head_tags), }. @@ -4966,29 +5190,29 @@ define Printable_tree define Printable_tree - format - ( - CommonInfo cinfo, - String state_name, - HTML_Meta m, - Bool is_https - ) = - if m is - { - keywords(l) then ["\n"], - refresh(co,ta,an,delay) then + format + ( + CommonInfo cinfo, + HTML_Meta m, + Bool is_https + ) = + if m is + { + keywords(l) then ["\n"], + refresh(co,ta,an,delay) then ["\n"], - refresh(url,delay) then + make_actioner_url(cinfo,co,ta,an,[],is_https),"\" />\n"], + refresh(url,delay) then ["\n"], - meta(n,c) then ["\n"], - http_equiv(n,c) then ["\n"], - generic_meta(l) then ["\n"], + http_equiv(n,c) then ["\n"], + generic_meta(l) then [" if p is (n,v) then [n,"=\"",v,"\" "], l)), " />\n"], - literal(s) then [s] - }. + literal(s) then [s] + } +. define Printable_tree // c'est le nôtre et c'est meilleur format @@ -5015,18 +5239,17 @@ define Printable_tree // c'est le nôtre et c'est meilleur define Printable_tree format ( - CommonInfo cinfo, - String state_name, + CommonInfo cinfo, List(HTML_Meta) metas, Bool is_https, String charset ) = if metas is { - [] then [format(cinfo,state_name,http_equiv("content-type", + [] then [format(cinfo,http_equiv("content-type", "text/html; charset="+charset),is_https)], - [h . t] then [format(cinfo,state_name,h,is_https) - . format(cinfo,state_name,t,is_https,charset)] + [h . t] then [format(cinfo,h,is_https) + . format(cinfo,t,is_https,charset)] }. define List(HTML_Head_Tag) @@ -5135,33 +5358,26 @@ public define HTML_ajax_content to_html_ajax_content ( HTML_Off_Form content_HTML, - CommonInfo cinfo, - String state_name + CommonInfo cinfo )= with p_content_head_tags = var((List(HTML_Head_Tag))[]), - with content = format(cinfo, state_name, var((Int)0), content_HTML, false, var(0), p_content_head_tags), + with content = format(cinfo, var((Int)0), content_HTML, false, var(0), p_content_head_tags), if sort_head_tag(*p_content_head_tags, "", [], []) is html_ajax_content(_, script, js_file, css_file) then html_ajax_content(to_String(content), script, js_file, css_file). -public define HTML_ajax_content - to_html_ajax_content - ( - HTML_Off_Form content_HTML, - CommonInfo cinfo - )= to_html_ajax_content(content_HTML, cinfo, ""). public define HTML_ajax_content to_html_ajax_content ( HTML_Partial_Content content_HTML, CommonInfo cinfo - )= to_html_ajax_content(partial(content_HTML), cinfo, ""). + )= to_html_ajax_content(partial(content_HTML), cinfo). public define Printable_tree format ( CommonInfo cinfo, - String state_name, + //String state_name, List(HTTP_header) additional_headers, HTTP_Answer page, Bool is_https, @@ -5178,7 +5394,7 @@ public define Printable_tree with answer_body_body = (Printable_tree) [ "", // format body options - format(cinfo,state_name,ic_v,element,is_https, var(0), p_content_head_tags), + format(cinfo,ic_v,element,is_https, var(0), p_content_head_tags), "\n", ""], @@ -5201,7 +5417,14 @@ public define Printable_tree html_page(status, title, metas, css_styles, css_files, js_files, script, body) then if body is body(options,element) then if format(status) is (status_string, status_headers) then - with answer_body = + with + answer_body_body = (Printable_tree) + [ "", // format body options + format(cinfo,ic_v,element,is_https, var(0), p_content_head_tags), + "\n", + "" + ], + answer_body_header = [ doctype_w3c_header, //html_header, "\n", @@ -5222,22 +5445,19 @@ public define Printable_tree " { s[0]=0; d.style.visibility = 'hidden'; }; }", "\n", "",title,"\n", // put title - format(cinfo,state_name,metas,is_https,charset), // format the metas - "\n", - "", // format body options - //"
", - format(cinfo,state_name,ic_v,element,is_https, var(0), p_content_head_tags), - //"
", - "\n", - "" - ], + format(cinfo,metas,is_https,charset), // format the metas + format_html_head(*p_content_head_tags, charset), + "\n" + ], + [ "HTTP/1.1 " + status_string, crlf, format_headers(standard_headers), - format_headers(standard_headers_for("text/html", length(answer_body), success(charset))), + format_headers(standard_headers_for("text/html", length(answer_body_header) + length(answer_body_body), success(charset))), format_headers(status_headers), format_headers(additional_headers), - crlf - . answer_body + crlf, + answer_body_header . + answer_body_body ], plain_text (HTTP_Status status, String text) then @@ -5300,7 +5520,7 @@ public define Printable_tree html_content(HTTP_Status status, HTML_Off_Form content_HTML) then if format(status) is (status_string, status_headers) then - with content = format(cinfo, state_name, ic_v, content_HTML, is_https, var(0), p_content_head_tags), + with content = format(cinfo, ic_v, content_HTML, is_https, var(0), p_content_head_tags), [ "HTTP/1.1 " + status_string, crlf, format_headers(standard_headers), format_headers(standard_headers_for("text/html", length(content), success(charset))), @@ -5317,7 +5537,7 @@ public define Printable_tree with answer_body = (Printable_tree) [ - format(cinfo, state_name, ic_v, html_content, is_https, var(0), p_content_head_tags), + format(cinfo, ic_v, html_content, is_https, var(0), p_content_head_tags), ], answer_header = (Printable_tree) [ diff --git a/web/CXM_multihost_http_server.anubis b/web/CXM_multihost_http_server.anubis index 6de8588..af98276 100644 --- a/web/CXM_multihost_http_server.anubis +++ b/web/CXM_multihost_http_server.anubis @@ -4136,6 +4136,63 @@ global define One + + +public define String + to_String + ( + HTTP_Status status + )= + if status is + { + http_continue then "100 Continue", + http_switching_protocol then "101 Switching Protocols", + + http_ok then "200 OK", + http_created then "201 Created", + http_accepted then "202 Accepted", + http_non_authoritative_info then "203 Non-Authoritative Information", + http_no_content then "204 No Content", + http_reset_content then "205 Reset Content", + http_partial_content then "206 Partial Content", + + http_multiple_choices then "300 Multiple Choices", + http_moved_permanently(loc) then "301 Moved Permanently Location ="+loc, + http_moved_temporarily(loc) then "302 Moved Temporarily Location ="+loc, + http_see_other(loc) then "303 See Other Location ="+loc, + http_not_modified then "304 Not Modified", + http_use_proxy(loc) then "305 Use Proxy Location ="+loc, + http_temporary_redirect(loc) then "307 Temporary Redirect Location ="+loc, + + http_bad_request then "400 Bad Request", + http_unauthorized then "401 Unauthorized", + http_payment_required then "402 Payment Required", + http_forbidden then "403 Forbidden", + http_not_found then "404 Not Found", + http_method_not_allowed then "405 Method Not Allowed", + http_not_acceptable then "406 Not Acceptable", + http_proxy_authentification_required then "407 Proxy Authentication Required", + http_request_timeout then "408 Request Time-out", + http_conflict then "409 Conflict", + http_gone then "410 Gone", + http_length_required then "411 Length Required", + http_precondition_failed then "412 Precondition Failed", + http_request_entity_too_large then "413 Request Entity Too Large", + http_request_uri_too_long then "414 Request-URI Too Long", + http_unsupported_media_type then "415 Unsupported Media Type", + http_request_range_unsatisfiable then "416 Requested range unsatisfiable", + http_expectation_failed then "417 Expectation failed", + + http_internal_server_error then "500 Internal Server Error", + http_not_implemented then "501 Not Implemented", + http_bad_gateway then "502 Bad Gateway", + http_service_unavailable then "503 Service Unavailable", + http_gateway_timeout then "504 Gateway Time-out", + http_version_not_supported then "505 HTTP Version not supported" + + http_error(code, message) then abs_to_decimal(code) + " " + message + }. + public define (String, List(HTTP_header)) format ( diff --git a/web/widgets/button.anubis b/web/widgets/button.anubis index 1486024..9b49c46 100644 --- a/web/widgets/button.anubis +++ b/web/widgets/button.anubis @@ -52,7 +52,7 @@ public define HTML_Partial_Content String url, List((String, String)) extra_ops )= - partial_content(actioner(same, same, img_link(core_attrs+[style("cursor: pointer")], img_path, ""), url, extra_ops)). + partial_content(actioner(same, same, img_link(core_attrs+[style("cursor: pointer")], img_path, ""), action_name(url), extra_ops)). public define HTML_Partial_Content img_button -- libgit2 0.21.4