X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matitaB%2Fmatita%2Fmatitadaemon.ml;h=840442665e9c047806a9d05243587f3e345ad314;hb=0e81e658803822599b5e015aab67bc282afc9c4d;hp=664a7301c1b727ae26816d9d7f7cb8581a87aaa4;hpb=d8ae533d041cb600993ab2957111c105b6ded21d;p=helm.git diff --git a/matitaB/matita/matitadaemon.ml b/matitaB/matita/matitadaemon.ml index 664a7301c..840442665 100644 --- a/matitaB/matita/matitadaemon.ml +++ b/matitaB/matita/matitadaemon.ml @@ -3,6 +3,8 @@ open Http_types;; module Stack = Continuationals.Stack +let rt_path () = Helm_registry.get "matita.rt_base_dir" + let utf8_length = Netconversion.ustring_length `Enc_utf8 let utf8_parsed_text s floc = @@ -216,6 +218,25 @@ let advance0 sid text = MatitaAuthentication.set_history sid (st::history); parsed_len, new_unparsed, st +let register (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = + let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in + let env = cgi#environment in + + assert (cgi#arguments <> []); + let uid = cgi#argument_value "userid" in + let userpw = cgi#argument_value "password" in + (try + MatitaAuthentication.add_user uid userpw; + env#set_output_header_field "Location" "/index.html" + with MatitaAuthentication.UsernameCollision _ -> + cgi#set_header + ~cache:`No_cache + ~content_type:"text/html; charset=\"utf-8\"" + (); + cgi#out_channel#output_string + "Error: User id collision!"); + cgi#out_channel#commit_work() +;; let login (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in @@ -233,8 +254,10 @@ let login (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = begin prerr_endline "4"; let sid = MatitaAuthentication.create_session uid in - let cookie = Netcgi.Cookie.make "session" (Uuidm.to_string sid) in - cgi#set_header ~status:`See_other ~cache:`No_cache ~set_cookies:[cookie] (); + (* let cookie = Netcgi.Cookie.make "session" (Uuidm.to_string sid) in + cgi#set_header ~set_cookies:[cookie] (); *) + env#set_output_header_field + "Set-Cookie" ("session=" ^ (Uuidm.to_string sid)); env#set_output_header_field "Location" "/index.html" end else @@ -251,6 +274,29 @@ let login (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = ;; +let logout (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = + let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in + let env = cgi#environment in + (try + let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in + let sid = HExtlib.unopt sid in + MatitaAuthentication.logout_user sid; + cgi # set_header + ~cache:`No_cache + ~content_type:"text/html; charset=\"utf-8\"" + (); + let text = read_file (rt_path () ^ "/logout.html") in + cgi#out_channel#output_string text + with + | Not_found _ -> + cgi # set_header + ~status:`Internal_server_error + ~cache:`No_cache + ~content_type:"text/xml; charset=\"utf-8\"" + ()); + cgi#out_channel#commit_work() +;; + (* returns the length of the executed text and an html representation of the * current metasenv*) let advance (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = @@ -413,6 +459,13 @@ let start() = dyn_translator = (fun _ -> ""); (* not needed *) dyn_accept_all_conditionals = false; } in + let do_register = + { Nethttpd_services.dyn_handler = (fun _ -> register); + dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered; + dyn_uri = None; (* not needed *) + dyn_translator = (fun _ -> ""); (* not needed *) + dyn_accept_all_conditionals = false; + } in let do_login = { Nethttpd_services.dyn_handler = (fun _ -> login); dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered; @@ -420,6 +473,13 @@ let start() = dyn_translator = (fun _ -> ""); (* not needed *) dyn_accept_all_conditionals = false; } in + let do_logout = + { Nethttpd_services.dyn_handler = (fun _ -> logout); + dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered; + dyn_uri = None; (* not needed *) + dyn_translator = (fun _ -> ""); (* not needed *) + dyn_accept_all_conditionals = false; + } in let nethttpd_factory = Nethttpd_plex.nethttpd_factory @@ -427,13 +487,13 @@ let start() = ; "retract", do_retract ; "bottom", goto_bottom ; "open", retrieve - ; "login", do_login ] + ; "register", do_register + ; "login", do_login + ; "logout", do_logout ] () in MatitaInit.initialize_all (); - (* test begin *) - MatitaAuthentication.add_user "ricciott" "pippo123"; - MatitaAuthentication.add_user "asperti" "pluto456"; - (* test end *) + prerr_endline (MatitaFilesystem.checkout "ricciott"); + MatitaAuthentication.deserialize (); Netplex_main.startup parallelizer Netplex_log.logger_factories (* allow all built-in logging styles *)