From b051b4cb22f2ae0318f41e3cf85e0089209e3456 Mon Sep 17 00:00:00 2001 From: totoro Date: Thu, 8 Mar 2018 16:36:40 +0100 Subject: [PATCH] add cxm_form(form_id, options, fields) add id in web_session, not yet used --- web/CXM_form.anubis | 10 +++++++++- web/CXM_making_a_web_site.anubis | 26 ++++++++++++++------------ web/CXM_multihost_http_server.anubis | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------- web/CXM_web_action.anubis | 2 +- web/CXM_web_session.anubis | 23 +++++++++++++++++------ web/jQuery/CXM_jquery_dialog.anubis | 6 +++--- 6 files changed, 161 insertions(+), 118 deletions(-) diff --git a/web/CXM_form.anubis b/web/CXM_form.anubis index 1ef0053..900b1ff 100644 --- a/web/CXM_form.anubis +++ b/web/CXM_form.anubis @@ -966,7 +966,15 @@ public define HTML_Off_Form List(CXM_Form_Field) fields, ) = cxm_form(form_id, [], lwa, fields, "form_field aligned", true). - + +public define HTML_Off_Form + cxm_form + ( + String form_id, + List(CoreAttrs) options, + List(CXM_Form_Field) fields, + ) = + cxm_form(form_id, options, [], fields, "form_field aligned", true). public define HTML_Off_Form cxm_form diff --git a/web/CXM_making_a_web_site.anubis b/web/CXM_making_a_web_site.anubis index 3fa4dbc..d4e7dcb 100644 --- a/web/CXM_making_a_web_site.anubis +++ b/web/CXM_making_a_web_site.anubis @@ -2956,9 +2956,9 @@ define (List(String) file_names) -> One (List(String) file_names) |-df-> if file_names is { - [ ] then unique, - [h . t] then - with file_path = state_directory+"/s"+h, + [ ] then unique, + [h . t] then + with file_path = state_directory+"/"+h, if (RetrieveResult((Int,$State)))retrieve(file_path) is ok(d) then ( if d is (time_stamp,data) then @@ -3001,7 +3001,7 @@ define One { [ ] then unique, [h . t] then if h is (state_directory,function) then - function(directory_list(state_directory,"s*")); + function(directory_list(state_directory,"*")); delete_out_of_date_states(t) }. @@ -3763,16 +3763,16 @@ define (Maybe(WEB_Session), HTTP_Answer) { failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)), success(new_controller) then - since _session is web_session(lang, entries, _, previous), - apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, web_session(lang, entries, previous, previous), failure, initial_session), + since _session is web_session(id, lang, entries, _, previous), + apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, web_session(id, lang, entries, previous, previous), failure, initial_session), }, redirect_to_previous(entries) then if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is { failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)), success(new_controller) then - since _session is web_session(lang, _, _, previous), - apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, web_session(lang, entries, previous, previous), failure, initial_session), + since _session is web_session(id, lang, _, _, previous), + apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, web_session(id, lang, entries, previous, previous), failure, initial_session), }, //ajax(answer) then (failure, answer), //ajax with modified session that must be saved @@ -3866,11 +3866,13 @@ public define Web_Site out_of_date(previous_session) then println("previous out_of_date"); - expired_session(previous_session, http_info, var(_lwa), is_https), - + //expired_session(previous_session, http_info, var(_lwa), is_https), + since previous_session is web_session(id, lang, entries, previous, _), + web_session(id, lang, entries, web_request(http_info, var(_lwa), is_https), previous) + still_valid(previous_session) then - since previous_session is web_session(lang, entries, previous, _), - web_session(lang, entries, web_request(http_info, var(_lwa), is_https), previous) + since previous_session is web_session(id, lang, entries, previous, _), + web_session(id, lang, entries, web_request(http_info, var(_lwa), is_https), previous) }, diff --git a/web/CXM_multihost_http_server.anubis b/web/CXM_multihost_http_server.anubis index e55ffa2..1c54ff9 100644 --- a/web/CXM_multihost_http_server.anubis +++ b/web/CXM_multihost_http_server.anubis @@ -703,29 +703,38 @@ type Error: colon_expected, timeout(Int). -type HTTP_RequestType: - get, - post. +type HTTP_Request_Method: + options, + get, + head, + post, + put, + delete, + trace, + connect, + extension(String) + . -type HTTP_RequestLine: - request_line (HTTP_RequestType type, - String uri, - List(Web_arg) query_string). +type HTTP_Request_Line: + request_line( + HTTP_Request_Method method, + String uri, + List(Web_arg) query_string). type EncodingType: www_url, multipart_form_data. -public type HTTP_BufferedConnection: - http_buffered_connection(Connection conn, - Var(ByteArray) buffer, - Var(Int) read_pos, - Var(List(Word8)) unput_chars // for reading requests - ). - +public type HTTP_Buffered_Connection: + http_buffered_connection( + Connection conn, + Var(ByteArray) buffer, + Var(Int) read_pos, + Var(List(Word8)) unput_chars // for reading requests + ). -public define HTTP_BufferedConnection +public define HTTP_Buffered_Connection http_buffered_connection ( Connection conn @@ -741,27 +750,28 @@ public define HTTP_BufferedConnection The next function formats an error message. public define String - format - ( - Error msg - ) = - if msg is - { - cannot_read_from_connection then - "Cannot read from connection.\n", - not_get_or_post_request(s) then - "The request did not begin by 'GET' or 'POST': "+s+".\n", - end_of_line_expected then - "End of line expected.\n", - incorrect_content_length_value then - "Incorrect value for HTTP header 'Content-Length'.\n", - colon_expected then - "':' was expected.\n", - timeout(n) then - //"time out: "+n+"\n" - //"time out.\n" - "" - }. + format + ( + Error msg + )= + if msg is + { + cannot_read_from_connection then + "Cannot read from connection.\n", + not_get_or_post_request(s) then + "The request did not begin by 'GET' or 'POST': "+s+".\n", + end_of_line_expected then + "End of line expected.\n", + incorrect_content_length_value then + "Incorrect value for HTTP header 'Content-Length'.\n", + colon_expected then + "':' was expected.\n", + timeout(n) then + //"time out: "+n+"\n" + //"time out.\n" + "" + } +. @@ -806,12 +816,12 @@ public type SState: define One - unput // unputting a character (add it in front of the list) - ( - Word8 character, - HTTP_BufferedConnection s - ) = - s.unput_chars <- (List(Word8))[character . *(s.unput_chars)]. + unput // unputting a character (add it in front of the list) + ( + Word8 character, + HTTP_Buffered_Connection s + ) = + s.unput_chars <- (List(Word8))[character . *(s.unput_chars)]. @@ -861,7 +871,7 @@ define One define ReadResult read_from_connexion ( - HTTP_BufferedConnection connection, + HTTP_Buffered_Connection connection, Int size, Int time_out, ByteArray result_buffer, @@ -913,7 +923,7 @@ define Result(Error,Word8) next_char // reading a character (check the list first, and read on the connection // only when the list is empty). ( - HTTP_BufferedConnection connection + HTTP_Buffered_Connection connection // Int dead_line, // DenialOfService dos ) = @@ -969,7 +979,7 @@ define Result(Error,Word8) define ByteArray get_and_erase_buffer ( - HTTP_BufferedConnection connection + HTTP_Buffered_Connection connection )= with head = to_byte_array(implode(*connection.unput_chars)), tail = extract(*connection.buffer, *connection.read_pos, length(*connection.buffer)), @@ -1003,7 +1013,7 @@ define ByteArray define Result(Error,One) read_and_ignore ( - HTTP_BufferedConnection connection, // to client + HTTP_Buffered_Connection connection, // to client Int number_of_characters // number of characters to read and ignore ) = if number_of_characters =< 0 then @@ -1031,7 +1041,7 @@ define Result(Error,One) define Result(Error,String) read_string ( - HTTP_BufferedConnection connection, // connection with the client + HTTP_Buffered_Connection connection, // connection with the client List(Word8) so_far // characters read so far (in reverse order) ) = if next_char(connection) is @@ -1237,7 +1247,7 @@ define String ( Web_Site_Description desc, Connection client_connection, - HTTP_RequestLine request_line, + HTTP_Request_Line request_line, List(HTTP_header) headers, List(Web_arg) web_args ) = @@ -1325,7 +1335,7 @@ define Bool define Result(Error,One) skip_http_blanks ( - HTTP_BufferedConnection connection + HTTP_Buffered_Connection connection ) = if next_char(connection) is @@ -1381,7 +1391,7 @@ define Result(Error,One) public define Result(Error,One) read_new_line ( - HTTP_BufferedConnection connection + HTTP_Buffered_Connection connection ) = if skip_http_blanks(connection) is { @@ -1412,7 +1422,7 @@ public define Result(Error,One) public define Result(Error,One) skip_line ( - HTTP_BufferedConnection connection + HTTP_Buffered_Connection connection ) = if next_char(connection) is { @@ -1451,7 +1461,7 @@ public define Result(Error,One) define Result(Error,String) read_word_aux ( - HTTP_BufferedConnection connection, + HTTP_Buffered_Connection connection, List(Word8) so_far ) = if next_char(connection) is @@ -1467,7 +1477,7 @@ define Result(Error,String) define Result(Error,String) read_word ( - HTTP_BufferedConnection connection + HTTP_Buffered_Connection connection ) = if skip_http_blanks(connection) is { @@ -1639,42 +1649,50 @@ public define List(Web_arg) returns a datum of type 'HTTP_RequestLine' if no error arose. -define Result(Error,HTTP_RequestType) - identify_get_or_post - ( - String s - ) = - with ls = to_lower(s), +define Result(Error, HTTP_Request_Method) + identify_get_or_post + ( + String s + )= + with ls = to_lower(s), if ls = "get" then ok(get) else if ls = "post" then ok(post) else error(not_get_or_post_request(ls)). -public define Result(Error, HTTP_RequestLine) +public define Result(Error, HTTP_Request_Line) read_request_line ( - HTTP_BufferedConnection connection + HTTP_Buffered_Connection connection ) = + //Read the Method if read_word(connection) is { - error(msg) then error(msg), - ok(get_or_post) then + error(msg) then error(msg), + ok(method) then + //read the URI if read_word(connection) is { - error(msg) then error(msg), - ok(uri_and_query_string) then if read_word(connection) is - { - error(msg) then error(msg), - ok(http_version) then if read_new_line(connection) is - { - error(msg) then error(msg), - ok(_) then if separate_uri_from_query_string(uri_and_query_string,0) is - (uri,query_string) then if identify_get_or_post(get_or_post) is - { - error(msg) then error(msg), - ok(request_type) then - ok(request_line(request_type, web_to_ascii(uri, 0, []), read_www_url_encoded_web_args(query_string,0))) - } - } + error(msg) then error(msg), + ok(uri_and_query_string) then + //Read the HTTP version + if read_word(connection) is + { + error(msg) then error(msg), + ok(http_version) then + //read the ending CR/LF + if read_new_line(connection) is + { + error(msg) then error(msg), + ok(_) then + + if separate_uri_from_query_string(uri_and_query_string,0) is + (uri,query_string) then + if identify_get_or_post(method) is + { + error(msg) then error(msg), + ok(request_type) then ok(request_line(request_type, web_to_ascii(uri, 0, []), read_www_url_encoded_web_args(query_string,0))) + } + } } } }. @@ -1703,7 +1721,7 @@ define Bool define Result(Error,String) read_header_name ( - HTTP_BufferedConnection connection, + HTTP_Buffered_Connection connection, List(Word8) so_far ) = if next_char(connection) is @@ -1718,7 +1736,7 @@ define Result(Error,String) define Result(Error,One) skip_colon ( - HTTP_BufferedConnection connection + HTTP_Buffered_Connection connection ) = //Skip the blank char until ':' if skip_http_blanks(connection) is @@ -1738,7 +1756,7 @@ define Result(Error,One) define Result(Error,String) read_header_value ( - HTTP_BufferedConnection connection, + HTTP_Buffered_Connection connection, List(Word8) so_far ) = if next_char(connection) is @@ -1770,7 +1788,7 @@ define Result(Error,String) define Result(Error,Maybe(HTTP_header)) read_header ( - HTTP_BufferedConnection connection + HTTP_Buffered_Connection connection ) = //Find the name if read_header_name(connection, []) is @@ -1811,7 +1829,7 @@ define Result(Error,Maybe(HTTP_header)) public define Result(Error,List(HTTP_header)) read_http_headers ( - HTTP_BufferedConnection connection + HTTP_Buffered_Connection connection ) = if read_header(connection) is { @@ -1872,7 +1890,7 @@ public define Result(Error,Int) public define Result(Error, ByteArray) read_http_body ( - HTTP_BufferedConnection connection, + HTTP_Buffered_Connection connection, Int body_size, ByteArray so_far, // when calling this function, 'so_far' is the empty byte array Int retries // this function is called with retries = 10 @@ -2479,8 +2497,8 @@ define One String host_name, Web_Site_Description desc, Connection connection, // with the client - Word32 ip_addr, // of the client - HTTP_RequestLine request_line, + Word32 ip_addr, // of the client + HTTP_Request_Line request_line, List(HTTP_header) headers, ByteArray body, One -> String generate_tt // trust ticket generation @@ -2492,13 +2510,15 @@ define One http_inf = http_info(ip_addr, host_name, uri, headers, is_SSL(connection)), (if member(journal_extensions(desc),ext) then log_journal_msg(desc, - format_request(desc,connection,request_line,headers,all_web_args)) + format_request(desc, connection, request_line, headers, all_web_args)) else unique); - if is_illegal_uri(uri,0) - then log_journal_msg(desc,"Received illegal URI: "+uri+"\n") - else (if (ext = ".awp" | ext = "") + + if is_illegal_uri(uri,0) then + log_journal_msg(desc,"Received illegal URI: "+uri+"\n") + else + (if (ext = ".awp" | ext = "") then - if awp_handler(desc)(host_name, http_inf, all_web_args, is_SSL(connection)) is + if desc.awp_handler(host_name, http_inf, all_web_args, is_SSL(connection)) is { printable_tree(answer_headers_body) then forget(reliable_write(connection, answer_headers_body)), @@ -2982,7 +3002,7 @@ define One Web_Site_Description desc, Connection connection, Word32 ip_addr, - HTTP_RequestLine request_line, + HTTP_Request_Line request_line, List(HTTP_header) headers, String body_temp_file, One -> String generate_tt, @@ -3261,7 +3281,7 @@ define One http_https_handler ( List(Web_Site_Description) sites, - HTTP_BufferedConnection connection, + HTTP_Buffered_Connection connection, Bool is_https, DenialOfService dos, SState s, @@ -3295,8 +3315,8 @@ define One { error(msg) then log_journal_msg(desc,format(msg)), ok(body_size) then - if rqline is request_line(type, uri, qstring) then - with rqline2 = request_line(type, handle_redirection(redirections(desc), uri, headers), qstring), + if rqline is request_line(method, uri, qstring) then + with rqline2 = request_line(method, handle_redirection(redirections(desc), uri, headers), qstring), //Get the type of encoding which decide if we read the content in ByteArray for www_url or in //temporary file for multipart. @@ -3309,10 +3329,12 @@ define One { error(msg) then log_journal_msg(desc,format(msg)), ok(body) then + //HERE produce the answer of the server www_url_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, body, generate_tt); //it's HTTP 1.1 keep-alive is default http_https_handler(sites, connection, is_https, dos, s, shutdown_required) } + //MULTIPART_FORM_DATA multipart_form_data then diff --git a/web/CXM_web_action.anubis b/web/CXM_web_action.anubis index d67df9d..601930d 100644 --- a/web/CXM_web_action.anubis +++ b/web/CXM_web_action.anubis @@ -68,7 +68,7 @@ public define String format_web_action_name ( WEB_Action_Name action, - List((String,String)) extra_ops, + List((String,String)) extra_ops, )= format_web_action_name(action) + diff --git a/web/CXM_web_session.anubis b/web/CXM_web_session.anubis index 0ff92b6..7b3ad8d 100644 --- a/web/CXM_web_session.anubis +++ b/web/CXM_web_session.anubis @@ -78,6 +78,7 @@ public type WEB_Request_No_Var: public type WEB_Session: web_session( + String session_id, String language, Var(List(WEB_Session_Field)) fields, WEB_Request web_request, @@ -86,6 +87,7 @@ public type WEB_Session: public type WEB_Session_No_Var: web_session( + String session_id, String language, List(WEB_Session_Field_No_Var) fields, WEB_Request_No_Var web_request, @@ -107,6 +109,14 @@ public define WEB_Session_Field *----------------------------------------------------------------* +public define String + get_new_session_id + = + with session_id = (now, (Word32)virtual_machine_id), + to_ascii(sha1(session_id)) +. + + define Var(List(WEB_Session_Field)) to_WEB_Session_Field ( @@ -128,8 +138,8 @@ public define WEB_Session ( WEB_Session_No_Var _session )= - since _session is web_session(language, fields, c_web_request, p_web_request), - web_session(language, to_WEB_Session_Field(fields), + since _session is web_session(id, language, fields, c_web_request, p_web_request), + web_session(id, language, to_WEB_Session_Field(fields), web_request(c_web_request.http_info, var(c_web_request.lwa), c_web_request.is_https), web_request(p_web_request.http_info, var(p_web_request.lwa), p_web_request.is_https) ) @@ -140,8 +150,8 @@ public define WEB_Session_No_Var ( WEB_Session _session )= - since _session is web_session(language, fields, c_web_request, p_web_request), - web_session(language, to_WEB_Session_Field_No_Var(*fields), + since _session is web_session(id, language, fields, c_web_request, p_web_request), + web_session(id, language, to_WEB_Session_Field_No_Var(*fields), web_request(c_web_request.http_info, *c_web_request.lwa, c_web_request.is_https), web_request(p_web_request.http_info, *p_web_request.lwa, p_web_request.is_https) ) @@ -1129,10 +1139,11 @@ public define String ( WEB_Session _session )= - since _session is web_session(language, fields, web_request, previous_web_request), + since _session is web_session(id, language, fields, web_request, previous_web_request), "WEB Session Dump: \n"+ "----------------- \n"+ - "Language : ["+language+"]\n\n"+ + "Session ID : ["+id+"]\n"+ + "Language : ["+language+"]\n\n"+ dump_WEB_Session_Fields(*fields)+ "-----------------------------------------------------------------------------\n"+ "Current WEB REQUEST:\n"+ diff --git a/web/jQuery/CXM_jquery_dialog.anubis b/web/jQuery/CXM_jquery_dialog.anubis index b7f47d5..8c7cee9 100644 --- a/web/jQuery/CXM_jquery_dialog.anubis +++ b/web/jQuery/CXM_jquery_dialog.anubis @@ -8,7 +8,7 @@ read system/convert.anubis read calexium_lib/web/CXM_making_a_web_site.anubis -read calexium_lib/web/CXM_jquery.anubis +transmit calexium_lib/web/CXM_jquery.anubis public type JQuery_dialog_id: dialog_id(String id). @@ -66,9 +66,9 @@ $( \"#"+dlg_id+"\" ).dialog({ { p_content(pc) then if pc is partial_content(tags, html) then - partial_content( [js . tags ], html), //html code of the dialog + partial_content( [js . tags ], div([id(dlg_id)], html)), //html code of the dialog off_form(html) then - partial_content( [js], html), //html code of the dialog + partial_content( [js], div([id(dlg_id)], html)), //html code of the dialog ajax(_url) then with url = format_web_action_name(_url), //println("jq_dialog_create : \njs_str ->"+js_str+"\nurl ->"+url); -- libgit2 0.21.4