Commit fd42aebc058d35dd941cce90f9898698bfaa1963

Authored by David RENÉ
1 parent 102790d5

add logger in web site description to be able to report error into log

web/CXM_making_a_web_site.anubis
@@ -554,8 +554,9 @@ define List(HTTP_header) @@ -554,8 +554,9 @@ define List(HTTP_header)
554 define WEB_Session -> String // the function constructed returns the name of the state 554 define WEB_Session -> String // the function constructed returns the name of the state
555 make_save_session_function 555 make_save_session_function
556 ( 556 (
557 - Int timeout,  
558 - String state_directory 557 + Int timeout,
  558 + String state_directory,
  559 + (LogLevel, String) -> One logger
559 ) = 560 ) =
560 (WEB_Session s_var) |-> 561 (WEB_Session s_var) |->
561 //Set the new timeout 562 //Set the new timeout
@@ -567,10 +568,10 @@ define WEB_Session -> String // the function constructed returns the name of @@ -567,10 +568,10 @@ define WEB_Session -> String // the function constructed returns the name of
567 session_name = s_var.session_id, 568 session_name = s_var.session_id,
568 //println("make_save_state_function " + state_directory+"/s"+state_name); 569 //println("make_save_state_function " + state_directory+"/s"+state_name);
569 if save(to_be_saved,state_directory+"/"+session_name) is ok then 570 if save(to_be_saved,state_directory+"/"+session_name) is ok then
570 - println("----- session ["+session_name+"] saved"+dump_WEB_Session_Fields(*s_var.fields)); 571 + logger(logInfo, "----- session ["+session_name+"] saved"+dump_WEB_Session_Fields(*s_var.fields));
571 session_name 572 session_name
572 else 573 else
573 - println("Cannot create session file in '"+state_directory+"'.\n"); 574 + logger(logError, ("Cannot create session file in '"+state_directory+"'.\n"));
574 "" 575 ""
575 . 576 .
576 577
@@ -621,7 +622,8 @@ define Previous_Session @@ -621,7 +622,8 @@ define Previous_Session
621 define (List(String) file_names) -> One 622 define (List(String) file_names) -> One
622 make_delete_out_of_date_sessions_function 623 make_delete_out_of_date_sessions_function
623 ( 624 (
624 - String state_directory 625 + String state_directory,
  626 + (LogLevel, String) -> One logger
625 ) = 627 ) =
626 (List(String) file_names) |-df-> 628 (List(String) file_names) |-df->
627 if file_names is 629 if file_names is
@@ -644,7 +646,7 @@ define (List(String) file_names) -> One @@ -644,7 +646,7 @@ define (List(String) file_names) -> One
644 df(t) 646 df(t)
645 ) 647 )
646 else 648 else
647 - println("Can't retreive session "+h+", hence will be deleted"); 649 + logger(logError, "Can't retreive session "+h+", hence will be deleted");
648 (forget(remove(file_path)); df(t)) 650 (forget(remove(file_path)); df(t))
649 }. 651 }.
650 652
@@ -3064,19 +3066,23 @@ read CXM_web_arg_encode.anubis @@ -3064,19 +3066,23 @@ read CXM_web_arg_encode.anubis
3064 3066
3065 3067
3066 define ($State s) -> String // the function constructed returns the name of the state 3068 define ($State s) -> String // the function constructed returns the name of the state
3067 - make_save_state_function  
3068 - (  
3069 - Int timeout,  
3070 - String state_directory  
3071 - ) =  
3072 - ($State s) |-> 3069 + make_save_state_function
  3070 + (
  3071 + Int timeout,
  3072 + String state_directory,
  3073 + (LogLevel, String) -> One logger
  3074 + )=
  3075 + ($State s) |->
3073 with time_stamp = now+timeout, 3076 with time_stamp = now+timeout,
3074 to_be_saved = (time_stamp,s), 3077 to_be_saved = (time_stamp,s),
3075 state_name = to_ascii(sha1(s)), 3078 state_name = to_ascii(sha1(s)),
3076 //println("make_save_state_function " + state_directory+"/s"+state_name); 3079 //println("make_save_state_function " + state_directory+"/s"+state_name);
3077 - if save(to_be_saved,state_directory+"/s"+state_name) is ok  
3078 - then state_name  
3079 - else (print("Cannot create state file in '"+state_directory+"'.\n"); ""). 3080 + if save(to_be_saved,state_directory+"/s"+state_name) is ok then
  3081 + state_name
  3082 + else
  3083 + logger(logError, "Cannot create state file in '"+state_directory+"'.\n");
  3084 + ""
  3085 +.
3080 3086
3081 3087
3082 When a request arrives, we need to retrieve the previous state from the server's 3088 When a request arrives, we need to retrieve the previous state from the server's
@@ -3414,43 +3420,47 @@ define ($State previous, @@ -3414,43 +3420,47 @@ define ($State previous,
3414 HTTP_Info http_info, 3420 HTTP_Info http_info,
3415 List(Web_arg) lwa, 3421 List(Web_arg) lwa,
3416 Bool is_https) -> $State 3422 Bool is_https) -> $State
3417 - make_apply_action_function  
3418 - (  
3419 - List(Web_Action($State)) actions_list  
3420 - ) =  
3421 - with f =  
3422 - ($State previous,  
3423 - String action_name,  
3424 - HTTP_Info http_info,  
3425 - List(Web_arg) lwa,  
3426 - Bool is_https,  
3427 - List(Web_Action($State)) actions) |-f-> 3423 + make_apply_action_function
  3424 + (
  3425 + List(Web_Action($State)) actions_list,
  3426 + (LogLevel, String) -> One logger //logger
  3427 + )=
  3428 + with f =
  3429 + ($State previous,
  3430 + String action_name,
  3431 + HTTP_Info http_info,
  3432 + List(Web_arg) lwa,
  3433 + Bool is_https,
  3434 + List(Web_Action($State)) actions) |-f->
3428 //println("Looking for action ["+action_name+"]"); 3435 //println("Looking for action ["+action_name+"]");
3429 if actions is 3436 if actions is
3430 { 3437 {
3431 - [ ] then print("action '"+action_name+  
3432 - "' not found.\n"); previous,  
3433 - [ac1 . others] then if ac1 is 3438 + [ ] then
  3439 + logger(logError, "action '"+action_name+"' not found.\n"); previous,
  3440 + [ac1 . others] then if ac1 is
3434 { 3441 {
3435 - http_action(an,allow,do_it) then  
3436 - if an = action_name  
3437 - then if is_https  
3438 - then (print("HTTP action '"+an+  
3439 - "' called through HTTPS (denied).\n");  
3440 - previous)  
3441 - else if allow(previous)  
3442 - then do_it(http_info,lwa,previous)  
3443 - else previous  
3444 - else f(previous,action_name,http_info,lwa,is_https,others),  
3445 - 3442 + //check for http action
  3443 + http_action(an, allow, do_it) then
  3444 +
  3445 + //Action name found
  3446 + if an = action_name then
  3447 + if is_https then
  3448 + (logger(logError, "HTTP action '"+an+"' called through HTTPS (denied).\n"); previous)
  3449 + else
  3450 + if allow(previous) then
  3451 + do_it(http_info,lwa,previous)
  3452 + else
  3453 + previous
  3454 + else
  3455 + f(previous,action_name,http_info,lwa,is_https,others),
  3456 + //check https action
3446 https_action(an,allow,do_it) then 3457 https_action(an,allow,do_it) then
3447 if an = action_name 3458 if an = action_name
3448 then if is_https 3459 then if is_https
3449 then if allow(previous) 3460 then if allow(previous)
3450 then do_it(http_info,lwa,previous) 3461 then do_it(http_info,lwa,previous)
3451 else previous 3462 else previous
3452 - else (print("HTTPS action '"+an+  
3453 - "' called through HTTP (denied).\n"); 3463 + else (logger(logError, "HTTPS action '"+an+"' called through HTTP (denied).\n");
3454 previous) 3464 previous)
3455 else f(previous,action_name,http_info,lwa,is_https,others), 3465 else f(previous,action_name,http_info,lwa,is_https,others),
3456 3466
@@ -3548,40 +3558,41 @@ define List(HTTP_header) @@ -3548,40 +3558,41 @@ define List(HTTP_header)
3548 3558
3549 3559
3550 public define Web_Site 3560 public define Web_Site
3551 - make_web_site_description  
3552 - (  
3553 - String website_name, // site_UID  
3554 - List(String) common_names, // for example: ["www.our-business.com"]  
3555 - String site_directory,  
3556 - String state_directory,  
3557 - One -> One init,  
3558 - (HTTP_Info,  
3559 - List(Web_arg),  
3560 - Bool is_https) -> $State initial_state,  
3561 - ($State expired,  
3562 - Maybe(String),  
3563 - HTTP_Info,  
3564 - List(Web_arg),  
3565 - Bool is_https) -> $State ticket_expired_state,  
3566 - (Maybe(String),  
3567 - HTTP_Info,  
3568 - List(Web_arg),  
3569 - Bool is_https) -> $State ticket_lost_state,  
3570 - List(Web_Action($State)) actions,  
3571 - $State -> HTTP_Answer compute_page,  
3572 - $State -> List(HTTP_header) additional_headers,  
3573 - List(HTTP_header) constant_additional_headers,  
3574 - Int timeout,  
3575 - Redirections redirections,  
3576 - String charset,  
3577 - List(String) journal_extensions,  
3578 - List(String) journal_headers,  
3579 - String secret,  
3580 - List(MIME) known_mime_types,  
3581 - (String action_name,  
3582 - List(Web_arg) args) -> One before_send_file  
3583 - ) =  
3584 - init(unique); 3561 + make_web_site_description
  3562 + (
  3563 + String website_name, // site_UID
  3564 + List(String) common_names, // for example: ["www.our-business.com"]
  3565 + String site_directory,
  3566 + String state_directory,
  3567 + One -> One init,
  3568 + (HTTP_Info,
  3569 + List(Web_arg),
  3570 + Bool is_https) -> $State initial_state,
  3571 + ($State expired,
  3572 + Maybe(String),
  3573 + HTTP_Info,
  3574 + List(Web_arg),
  3575 + Bool is_https) -> $State ticket_expired_state,
  3576 + (Maybe(String),
  3577 + HTTP_Info,
  3578 + List(Web_arg),
  3579 + Bool is_https) -> $State ticket_lost_state,
  3580 + List(Web_Action($State)) actions,
  3581 + $State -> HTTP_Answer compute_page,
  3582 + $State -> List(HTTP_header) additional_headers,
  3583 + List(HTTP_header) constant_additional_headers,
  3584 + Int timeout,
  3585 + Redirections redirections,
  3586 + String charset,
  3587 + List(String) journal_extensions,
  3588 + List(String) journal_headers,
  3589 + (LogLevel, String) -> One logger, //logger
  3590 + String secret,
  3591 + List(MIME) known_mime_types,
  3592 + (String action_name,
  3593 + List(Web_arg) args) -> One before_send_file
  3594 + )=
  3595 + init(unique);
3585 3596
3586 3597
3587 // 3598 //
@@ -3594,10 +3605,10 @@ public define Web_Site @@ -3594,10 +3605,10 @@ public define Web_Site
3594 // 3605 //
3595 // construct tool functions 3606 // construct tool functions
3596 // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true 3607 // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true
3597 - with save_state = make_save_state_function(timeout, state_directory), 3608 + with save_state = make_save_state_function(timeout, state_directory, logger),
3598 retrieve_state = make_retrieve_state_function(state_directory), 3609 retrieve_state = make_retrieve_state_function(state_directory),
3599 separate_web_args = make_separate_web_args_function(state_directory, retrieve_state, website_name), 3610 separate_web_args = make_separate_web_args_function(state_directory, retrieve_state, website_name),
3600 - apply_action = make_apply_action_function(actions), 3611 + apply_action = make_apply_action_function(actions, logger),
3601 // 3612 //
3602 // construct the site handler 3613 // construct the site handler
3603 // 3614 //
@@ -3670,6 +3681,7 @@ public define Web_Site @@ -3670,6 +3681,7 @@ public define Web_Site
3670 charset, 3681 charset,
3671 journal_extensions, 3682 journal_extensions,
3672 journal_headers, 3683 journal_headers,
  3684 + logger,
3673 secret, 3685 secret,
3674 known_mime_types, 3686 known_mime_types,
3675 site_handler(http_port, https_port), 3687 site_handler(http_port, https_port),
@@ -3717,7 +3729,7 @@ define HTTP_Answer @@ -3717,7 +3729,7 @@ define HTTP_Answer
3717 3729
3718 // content of page 3730 // content of page
3719 sequence([ 3731 sequence([
3720 - preformated([size(14)], "Anubis Web Server - Calexium Lib v1.00 - Anubis language v1.14"), 3732 + preformated([size(14)],"Anubis Web Server - Standard Lib v1.14.0.0 - Anubis language v1.14"),
3721 preformated([size(12)],"Error "+to_String(http_status)), 3733 preformated([size(12)],"Error "+to_String(http_status)),
3722 preformated([size(12)],"Internal message :"+message), 3734 preformated([size(12)],"Internal message :"+message),
3723 br, 3735 br,
@@ -3816,38 +3828,40 @@ define Maybe(WEB_Controller) @@ -3816,38 +3828,40 @@ define Maybe(WEB_Controller)
3816 ( 3828 (
3817 String controller_name, 3829 String controller_name,
3818 List(WEB_Controller) controllers, 3830 List(WEB_Controller) controllers,
  3831 + (LogLevel, String) -> One logger //logger
3819 )= 3832 )=
3820 if controllers is 3833 if controllers is
3821 { 3834 {
3822 [] then 3835 [] then
3823 - println("Can't find controller ["+controller_name+"]"); 3836 + logger(logWarning, "Can't find controller ["+controller_name+"]");
3824 failure, 3837 failure,
3825 [h . t] then 3838 [h . t] then
3826 if h.name = controller_name then 3839 if h.name = controller_name then
3827 //println("Controller ["+controller_name+"] found"); 3840 //println("Controller ["+controller_name+"] found");
3828 success(h) 3841 success(h)
3829 else 3842 else
3830 - get_controller(controller_name, t) 3843 + get_controller(controller_name, t, logger)
3831 } 3844 }
3832 . 3845 .
3833 3846
3834 define WEB_Page_Renderer 3847 define WEB_Page_Renderer
3835 get_page_renderer 3848 get_page_renderer
3836 ( 3849 (
3837 - String renderer_name,  
3838 - List(WEB_Page_Renderer) renderers, 3850 + String renderer_name,
  3851 + List(WEB_Page_Renderer) renderers,
  3852 + (LogLevel, String) -> One logger //logger
3839 )= 3853 )=
3840 if renderers is 3854 if renderers is
3841 { 3855 {
3842 [] then 3856 [] then
3843 - println("Can't find page_renderer ["+renderer_name+"], use the default"); 3857 + logger(logWarning, "Can't find page_renderer ["+renderer_name+"], use the default");
3844 default_page_renderer, 3858 default_page_renderer,
3845 [h . t] then 3859 [h . t] then
3846 if h.name = renderer_name then 3860 if h.name = renderer_name then
3847 //println("Controller ["+controller_name+"] found"); 3861 //println("Controller ["+controller_name+"] found");
3848 h 3862 h
3849 else 3863 else
3850 - get_page_renderer(renderer_name, t) 3864 + get_page_renderer(renderer_name, t, logger)
3851 } 3865 }
3852 . 3866 .
3853 3867
@@ -3857,18 +3871,19 @@ define WEB_Page_Renderer @@ -3857,18 +3871,19 @@ define WEB_Page_Renderer
3857 WEB_Session _session, 3871 WEB_Session _session,
3858 WEB_Page_Renderer _current_page_renderer, 3872 WEB_Page_Renderer _current_page_renderer,
3859 List(WEB_Page_Renderer) renderers, 3873 List(WEB_Page_Renderer) renderers,
  3874 + (LogLevel, String) -> One logger //logger
3860 )= 3875 )=
3861 //get the renderer page name to use from the session "AWS_PAGE_RENDERER" 3876 //get the renderer page name to use from the session "AWS_PAGE_RENDERER"
3862 if get_String(_session.fields, "AWS_PAGE_RENDERER") is 3877 if get_String(_session.fields, "AWS_PAGE_RENDERER") is
3863 { 3878 {
3864 - failure then println("No renderer defined, use the default"); default_page_renderer, 3879 + failure then logger(logWarning, "No renderer defined, use the default"); default_page_renderer,
3865 success(renderer_name) then 3880 success(renderer_name) then
3866 //check if the renderer_page already in cache 3881 //check if the renderer_page already in cache
3867 if renderer_name = _current_page_renderer.name then 3882 if renderer_name = _current_page_renderer.name then
3868 _current_page_renderer 3883 _current_page_renderer
3869 else 3884 else
3870 //if not in cache, use the selector function 3885 //if not in cache, use the selector function
3871 - get_page_renderer(renderer_name, renderers) 3886 + get_page_renderer(renderer_name, renderers, logger)
3872 } 3887 }
3873 . 3888 .
3874 3889
@@ -3887,7 +3902,8 @@ define (Maybe(WEB_Session), HTTP_Answer) @@ -3887,7 +3902,8 @@ define (Maybe(WEB_Session), HTTP_Answer)
3887 Maybe(String) _mb_action_name, 3902 Maybe(String) _mb_action_name,
3888 (HTTP_Info, 3903 (HTTP_Info,
3889 Var(List(Web_arg)), 3904 Var(List(Web_arg)),
3890 - Bool is_https) -> WEB_Session initial_session, 3905 + Bool is_https) -> WEB_Session initial_session,
  3906 + (LogLevel, String) -> One logger //logger
3891 )= 3907 )=
3892 //get the action name 3908 //get the action name
3893 with mb_action_name = 3909 with mb_action_name =
@@ -3902,47 +3918,47 @@ define (Maybe(WEB_Session), HTTP_Answer) @@ -3902,47 +3918,47 @@ define (Maybe(WEB_Session), HTTP_Answer)
3902 failure then 3918 failure then
3903 //(failure, error_page(http_not_found, "Action name failure", _session)), 3919 //(failure, error_page(http_not_found, "Action name failure", _session)),
3904 with new_session = initial_session(_session.web_request.http_info, _session.web_request.lwa, _session.web_request.is_https), 3920 with new_session = initial_session(_session.web_request.http_info, _session.web_request.lwa, _session.web_request.is_https),
3905 - if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers) is 3921 + if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers, logger) is
3906 { 3922 {
3907 failure then (failure, error_page(http_not_found, "Initial Session Controller not found", new_session)), 3923 failure then (failure, error_page(http_not_found, "Initial Session Controller not found", new_session)),
3908 - success(new_controller) then apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, new_session, failure, initial_session), 3924 + success(new_controller) then apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, new_session, failure, initial_session, logger),
3909 }, 3925 },
3910 success(action_name) then 3926 success(action_name) then
3911 - println("ACTION_NAME ["+action_name+"]"); 3927 + logger(logInfo, "ACTION_NAME ["+action_name+"]");
3912 if apply_action(_session, action_name, *controller.controller_actions) is 3928 if apply_action(_session, action_name, *controller.controller_actions) is
3913 { 3929 {
3914 http_answer(session, answer) then (success(session), answer), 3930 http_answer(session, answer) then (success(session), answer),
3915 http_answer(answer) then (success(_session), answer), 3931 http_answer(answer) then (success(_session), answer),
3916 redirect(new_session) then 3932 redirect(new_session) then
3917 - if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers) is 3933 + if get_controller(get_String(*new_session.web_request.lwa, "aws_controller", "root"), controllers, logger) is
3918 { 3934 {
3919 failure then (failure, error_page(http_not_found, "Redirect Controller not found", new_session)), 3935 failure then (failure, error_page(http_not_found, "Redirect Controller not found", new_session)),
3920 - success(new_controller) then apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, new_session, failure, initial_session), 3936 + success(new_controller) then apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, new_session, failure, initial_session, logger),
3921 }, 3937 },
3922 3938
3923 redirect(new_session, r_controller_name, r_action_name) then 3939 redirect(new_session, r_controller_name, r_action_name) then
3924 - if get_controller(r_controller_name, controllers) is 3940 + if get_controller(r_controller_name, controllers, logger) is
3925 { 3941 {
3926 failure then (failure, error_page(http_not_found, "Redirect Controller "+r_controller_name+" not found", new_session)), 3942 failure then (failure, error_page(http_not_found, "Redirect Controller "+r_controller_name+" not found", new_session)),
3927 success(new_controller) then 3943 success(new_controller) then
3928 - apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, new_session, success(r_action_name), initial_session), 3944 + apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, new_session, success(r_action_name), initial_session, logger),
3929 }, 3945 },
3930 3946
3931 redirect_to_previous then 3947 redirect_to_previous then
3932 - if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is 3948 + if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers, logger) is
3933 { 3949 {
3934 failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)), 3950 failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)),
3935 success(new_controller) then 3951 success(new_controller) then
3936 since _session is web_session(id, lang, entries, _, previous), 3952 since _session is web_session(id, lang, entries, _, previous),
3937 - apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, web_session(id, lang, entries, previous, previous), failure, initial_session), 3953 + apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, web_session(id, lang, entries, previous, previous), failure, initial_session, logger),
3938 }, 3954 },
3939 redirect_to_previous(entries) then 3955 redirect_to_previous(entries) then
3940 - if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers) is 3956 + if get_controller(get_String(*_session.previous_web_request.lwa, "aws_controller", "root"), controllers, logger) is
3941 { 3957 {
3942 failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)), 3958 failure then (failure, error_page(http_not_found, "Redirect to previous Controller not found", _session)),
3943 success(new_controller) then 3959 success(new_controller) then
3944 since _session is web_session(id, lang, _, _, previous), 3960 since _session is web_session(id, lang, _, _, previous),
3945 - apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, web_session(id, lang, entries, previous, previous), failure, initial_session), 3961 + apply_controller_action(new_controller, controllers, _current_page_renderer, page_renderers, cinfo, web_session(id, lang, entries, previous, previous), failure, initial_session, logger),
3946 }, 3962 },
3947 //ajax(answer) then (failure, answer), 3963 //ajax(answer) then (failure, answer),
3948 //ajax with modified session that must be saved 3964 //ajax with modified session that must be saved
@@ -3955,7 +3971,7 @@ define (Maybe(WEB_Session), HTTP_Answer) @@ -3955,7 +3971,7 @@ define (Maybe(WEB_Session), HTTP_Answer)
3955 send_file(file_path, c_disposition) then (failure, send_file(file_path, c_disposition)), 3971 send_file(file_path, c_disposition) then (failure, send_file(file_path, c_disposition)),
3956 renderer_content(session, title, content) then 3972 renderer_content(session, title, content) then
3957 with the_session = if session is {failure then _session, success(__session) then __session}, 3973 with the_session = if session is {failure then _session, success(__session) then __session},
3958 - with page_renderer = get_page_renderer(the_session, _current_page_renderer, page_renderers), 3974 + with page_renderer = get_page_renderer(the_session, _current_page_renderer, page_renderers, logger),
3959 (session, page_renderer.page_layout(the_session, title, content)) 3975 (session, page_renderer.page_layout(the_session, title, content))
3960 } 3976 }
3961 } 3977 }
@@ -3986,7 +4002,8 @@ public define Web_Site @@ -3986,7 +4002,8 @@ public define Web_Site
3986 Redirections redirections, 4002 Redirections redirections,
3987 String charset, 4003 String charset,
3988 List(String) journal_extensions, 4004 List(String) journal_extensions,
3989 - List(String) journal_headers, 4005 + List(String) journal_headers,
  4006 + (LogLevel, String) -> One logger, //logger
3990 String secret, 4007 String secret,
3991 List(MIME) known_mime_types, 4008 List(MIME) known_mime_types,
3992 (String action_name, 4009 (String action_name,
@@ -4007,7 +4024,7 @@ public define Web_Site @@ -4007,7 +4024,7 @@ public define Web_Site
4007 // 4024 //
4008 // construct tool functions 4025 // construct tool functions
4009 // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true 4026 // TODO 'make_separate_web_args_function' must retrieve state_cookies before parsing web_args if using_state_cookies is true
4010 - with save_session = make_save_session_function(timeout, state_directory), 4027 + with save_session = make_save_session_function(timeout, state_directory, logger),
4011 with current_page_renderer = var((WEB_Page_Renderer)default_page_renderer), 4028 with current_page_renderer = var((WEB_Page_Renderer)default_page_renderer),
4012 // retrieve_session = make_retrieve_session_function(state_directory, website_name), 4029 // retrieve_session = make_retrieve_session_function(state_directory, website_name),
4013 //separate_web_args = make_separate_web_args_function(state_directory, retrieve_state), 4030 //separate_web_args = make_separate_web_args_function(state_directory, retrieve_state),
@@ -4022,20 +4039,20 @@ public define Web_Site @@ -4022,20 +4039,20 @@ public define Web_Site
4022 List(Web_arg) _lwa, 4039 List(Web_arg) _lwa,
4023 Bool is_https) |-> 4040 Bool is_https) |->
4024 //(Printable_tree) 4041 //(Printable_tree)
4025 - //println("host_name "+host_name);  
4026 - //println(dump_http_info(http_info));  
4027 - println(dump_web_arg_values(_lwa)); 4042 + logger(logTrace,"host_name "+host_name);
  4043 + logger(logTrace,dump_http_info(http_info));
  4044 + logger(logTrace, dump_web_arg_values(_lwa));
4028 with cinfo = info(host_name, http_port, https_port, site_directory, secret), 4045 with cinfo = info(host_name, http_port, https_port, site_directory, secret),
4029 4046
4030 //retrieve the previous session and determine the new one 4047 //retrieve the previous session and determine the new one
4031 with current_session = if retrieve_session(http_info, state_directory, website_name) is 4048 with current_session = if retrieve_session(http_info, state_directory, website_name) is
4032 { 4049 {
4033 not_found then 4050 not_found then
4034 - println("previous state not found"); 4051 + logger(logInfo, "previous state not found");
4035 initial_session(http_info, var(_lwa), is_https), 4052 initial_session(http_info, var(_lwa), is_https),
4036 4053
4037 out_of_date(previous_session) then 4054 out_of_date(previous_session) then
4038 - println("previous out_of_date"); 4055 + logger(logInfo, "previous out_of_date");
4039 //expired_session(previous_session, http_info, var(_lwa), is_https), 4056 //expired_session(previous_session, http_info, var(_lwa), is_https),
4040 since previous_session is web_session(id, lang, entries, previous, _), 4057 since previous_session is web_session(id, lang, entries, previous, _),
4041 web_session(id, lang, entries, web_request(http_info, var(_lwa), is_https), previous) 4058 web_session(id, lang, entries, web_request(http_info, var(_lwa), is_https), previous)
@@ -4048,13 +4065,13 @@ public define Web_Site @@ -4048,13 +4065,13 @@ public define Web_Site
4048 4065
4049 //apply the action according to current session 4066 //apply the action according to current session
4050 //since apply_controller_action(get_controller(get_String(lwa, "aws_controller", "root"), *web_controllers), *web_controllers, current_session) 4067 //since apply_controller_action(get_controller(get_String(lwa, "aws_controller", "root"), *web_controllers), *web_controllers, current_session)
4051 - since if get_controller(get_String(*current_session.web_request.lwa, "aws_controller", "root"), *web_controllers) is 4068 + since if get_controller(get_String(*current_session.web_request.lwa, "aws_controller", "root"), *web_controllers, logger) is
4052 { 4069 {
4053 failure then 4070 failure then
4054 (failure, error_page(http_not_found, "Controller not found", current_session)), 4071 (failure, error_page(http_not_found, "Controller not found", current_session)),
4055 4072
4056 success(new_controller) then 4073 success(new_controller) then
4057 - apply_controller_action(new_controller, *web_controllers, *current_page_renderer, *web_page_renderers, cinfo, current_session, failure, initial_session), 4074 + apply_controller_action(new_controller, *web_controllers, *current_page_renderer, *web_page_renderers, cinfo, current_session, failure, initial_session, logger),
4058 } 4075 }
4059 is (mb_new_session, http_answer), 4076 is (mb_new_session, http_answer),
4060 4077
@@ -4080,7 +4097,7 @@ public define Web_Site @@ -4080,7 +4097,7 @@ public define Web_Site
4080 // make the delete_out_of_date function 4097 // make the delete_out_of_date function
4081 // 4098 //
4082 delete_out_of_date = 4099 delete_out_of_date =
4083 - make_delete_out_of_date_sessions_function(site_directory+"/states"), 4100 + make_delete_out_of_date_sessions_function(site_directory+"/states", logger),
4084 // 4101 //
4085 // construct the web site description 4102 // construct the web site description
4086 // 4103 //
@@ -4091,6 +4108,7 @@ public define Web_Site @@ -4091,6 +4108,7 @@ public define Web_Site
4091 charset, 4108 charset,
4092 journal_extensions, 4109 journal_extensions,
4093 journal_headers, 4110 journal_headers,
  4111 + logger,
4094 secret, 4112 secret,
4095 known_mime_types, 4113 known_mime_types,
4096 site_handler(http_port,https_port), 4114 site_handler(http_port,https_port),
@@ -4111,22 +4129,23 @@ public define Web_Site @@ -4111,22 +4129,23 @@ public define Web_Site
4111 define String 4129 define String
4112 get_site_uid 4130 get_site_uid
4113 ( 4131 (
4114 - String site_path 4132 + String site_path,
  4133 + (LogLevel, String) -> One logger //logger
4115 )= 4134 )=
4116 with file_name = site_path+"/site_UID", 4135 with file_name = site_path+"/site_UID",
4117 if read_from_file(file_name) is 4136 if read_from_file(file_name) is
4118 { 4137 {
4119 cannot_find_file then 4138 cannot_find_file then
4120 - println("site UID doesn't exists. Generating it now"); 4139 + logger(logInfo,"site UID doesn't exists. Generating one now");
4121 with uid = generate_random_string(9), 4140 with uid = generate_random_string(9),
4122 if write_to_file(file_name, to_byte_array(uid)) is 4141 if write_to_file(file_name, to_byte_array(uid)) is
4123 { 4142 {
4124 - cannot_open_file then println("Can't create site UID here "+file_name);"",  
4125 - write_error(_) then println("Can't write site UID here "+file_name);"", 4143 + cannot_open_file then logger(logError, "Can't create site UID here "+file_name);"",
  4144 + write_error(_) then logger(logError, "Can't write site UID here "+file_name);"",
4126 ok then uid 4145 ok then uid
4127 } 4146 }
4128 read_error(_) then 4147 read_error(_) then
4129 - println("cannot read site UID from "+file_name);"" 4148 + logger(logError, "cannot read site UID from "+file_name);""
4130 ok(ba) then to_string(ba) 4149 ok(ba) then to_string(ba)
4131 } 4150 }
4132 . 4151 .
@@ -4159,7 +4178,8 @@ public define Web_Site @@ -4159,7 +4178,8 @@ public define Web_Site
4159 Redirections redirections, 4178 Redirections redirections,
4160 String charset, 4179 String charset,
4161 List(String) journal_extensions, 4180 List(String) journal_extensions,
4162 - List(String) journal_headers, 4181 + List(String) journal_headers,
  4182 + (LogLevel, String) -> One logger, //logger
4163 String secret, 4183 String secret,
4164 List(MIME) known_mime_types, 4184 List(MIME) known_mime_types,
4165 (String action_name, 4185 (String action_name,
@@ -4168,8 +4188,8 @@ public define Web_Site @@ -4168,8 +4188,8 @@ public define Web_Site
4168 ) 4188 )
4169 = 4189 =
4170 //generate an unique ID if doesn't exist in root of site_directory 4190 //generate an unique ID if doesn't exist in root of site_directory
4171 - with site_UID = get_site_uid(site_directory),  
4172 - make_web_site_description(site_UID, common_names, site_directory, state_directory, init, initial_state, ticket_expired_state, ticket_lost_state, actions, compute_page, additional_headers, constant_additional_headers, timeout, redirections, charset, journal_extensions, journal_headers, secret, known_mime_types, before_send_file) 4191 + with site_UID = get_site_uid(site_directory, logger),
  4192 + make_web_site_description(site_UID, common_names, site_directory, state_directory, init, initial_state, ticket_expired_state, ticket_lost_state, actions, compute_page, additional_headers, constant_additional_headers, timeout, redirections, charset, journal_extensions, journal_headers, logger, secret, known_mime_types, before_send_file)
4173 . 4193 .
4174 4194
4175 4195
web/CXM_multihost_http_server.anubis
@@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
4 *Title* A Multi Host HTTP/HTTPS Server 4 *Title* A Multi Host HTTP/HTTPS Server
5 5
6 *Copyright* Copyright (c) Anubis Team 2003-2007. 6 *Copyright* Copyright (c) Anubis Team 2003-2007.
  7 + (c) Calexium 2007-2013
  8 + (c) David René 2014-2019
7 9
8 10
9 *Authors* Alain Prouté 11 *Authors* Alain Prouté
@@ -12,9 +14,9 @@ @@ -12,9 +14,9 @@
12 14
13 15
14 *Revised* 16 *Revised*
15 - June 2015 : Optimization of the file upload  
16 - July 2007 : Initial version in calexium_lib  
17 - 17 + June 2015 : Optimization of the file upload
  18 + July 2007 : Initial version in calexium_lib
  19 + March 2019 : move as standard lib
18 20
19 *Overviews* 21 *Overviews*
20 In this file a HTTP/HTTPS server is defined, which is able to handle multiple hosts 22 In this file a HTTP/HTTPS server is defined, which is able to handle multiple hosts
@@ -171,10 +173,9 @@ read system/string.anubis @@ -171,10 +173,9 @@ read system/string.anubis
171 read system/files.anubis 173 read system/files.anubis
172 read system/lists.anubis 174 read system/lists.anubis
173 read system/data_io.anubis 175 read system/data_io.anubis
  176 +read system/logger.anubis
174 read web/mime.anubis 177 read web/mime.anubis
175 178
176 -  
177 -  
178 *** (4) Site descriptions. 179 *** (4) Site descriptions.
179 180
180 The type HTTP_Info gathers informations comming along with the client's request. These 181 The type HTTP_Info gathers informations comming along with the client's request. These
@@ -227,6 +228,7 @@ public type Web_Site_Description: @@ -227,6 +228,7 @@ public type Web_Site_Description:
227 String charset, 228 String charset,
228 List(String) journal_extensions, 229 List(String) journal_extensions,
229 List(String) journal_headers, 230 List(String) journal_headers,
  231 + (LogLevel, String) -> One logger, //logger
230 String authorization_secret, 232 String authorization_secret,
231 List(MIME) known_mime_types, 233 List(MIME) known_mime_types,
232 (String host_name, 234 (String host_name,
@@ -1282,11 +1284,11 @@ define One @@ -1282,11 +1284,11 @@ define One
1282 ( 1284 (
1283 if file(site_directory(desc)+"/journal/"+make_current_journal_file_name,append) is 1285 if file(site_directory(desc)+"/journal/"+make_current_journal_file_name,append) is
1284 { 1286 {
1285 - failure then unique,  
1286 - success(journal_file) then 1287 + failure then unique,
  1288 + success(journal_file) then
1287 forget(reliable_write(file(journal_file),ba_msg)) 1289 forget(reliable_write(file(journal_file),ba_msg))
1288 - };  
1289 - forget(reliable_write(file(stdout),ba_msg)) 1290 + }
  1291 + //forget(reliable_write(file(stdout),ba_msg))
1290 ). 1292 ).
1291 1293
1292 1294
@@ -3231,20 +3233,21 @@ define Maybe(String) @@ -3231,20 +3233,21 @@ define Maybe(String)
3231 }. 3233 }.
3232 3234
3233 define Maybe((String,Web_Site_Description)) 3235 define Maybe((String,Web_Site_Description))
3234 - get_site  
3235 - (  
3236 - String requested_host,  
3237 - List(Web_Site_Description) sites  
3238 - ) =  
3239 - if sites is  
3240 - {  
3241 - [ ] then print("Requested host '"+requested_host+"' does not exist.\n"); failure,  
3242 - [site1 . others] then  
3243 - if site1 is web_site_description(common_names,_,_,_,_,_,_,_,_,_,_) then  
3244 - if member(common_names,requested_host)  
3245 - then success((requested_host,site1))  
3246 - else get_site(requested_host,others)  
3247 - }. 3236 + get_site
  3237 + (
  3238 + String requested_host,
  3239 + List(Web_Site_Description) sites
  3240 + )=
  3241 + if sites is
  3242 + {
  3243 + [ ] then print("Requested host '"+requested_host+"' does not exist.\n"); failure,
  3244 + [site1 . others] then
  3245 + if site1 is web_site_description(common_names,_,_,_,_,_,_,_,_,_,_,_) then
  3246 + if member(common_names,requested_host)
  3247 + then success((requested_host,site1))
  3248 + else get_site(requested_host,others)
  3249 + }
  3250 +.
3248 3251
3249 3252
3250 define Maybe((String,Web_Site_Description)) 3253 define Maybe((String,Web_Site_Description))