- | HExtlib.Localized(_,e)
- | e ->
- (prerr_endline ("exception: " ^ Printexc.to_string e);
- (try
- NTacStatus.pp_tac_status !status
- with e -> prerr_endline ("inner exception: " ^
- Printexc.to_string e));
- prerr_endline "end status";
- let txt = output_status !status in
- (0,"",txt), Printexc.to_string e, `Code 500)
- in
- (* prerr_endline ("server response:\n" ^ txt); *)
- let body =
- "<response><parsed length=\"" ^ (string_of_int parsed_len) ^ "\" />" ^ txt
- ^ "</response>"
- in (prerr_endline ("sending advance response:\n" ^ body);
- Http_daemon.respond ~code ~body outchan)
- | "/bottom" ->
- let script = req#body in
- prerr_endline ("body length = " ^ (string_of_int (String.length script)));
- let (parsed_len,txt), res, code =
- try gotoBottom script, "OK", `Code 200
- with
- | HExtlib.Localized(_,e)
- | e ->
- (prerr_endline ("exception: " ^ Printexc.to_string e);
- (try
- NTacStatus.pp_tac_status !status
- with e -> prerr_endline ("inner exception: " ^
- Printexc.to_string e));
- prerr_endline "end status";
- let txt = output_status !status in
- (0,txt), Printexc.to_string e, `Code 500)
- in
- (* prerr_endline ("server response:\n" ^ txt); *)
- let body =
- "<parsed length=\"" ^ (string_of_int parsed_len) ^ "\" />" ^ txt
- in Http_daemon.respond ~code ~body outchan
- | "/retract" ->
- (try
- let body = retract () in
- prerr_endline "retract OK";
- Http_daemon.respond ~code:(`Code 200) ~body outchan
- with e ->
- (prerr_endline (Printexc.to_string e);
- Http_daemon.respond ~code:(`Code 500) outchan))
- | url ->
- try
- let url = String.sub url 1 (String.length url - 1) in
- load_doc url outchan
- with _ -> Http_daemon.respond_not_found ~url outchan
+ | HExtlib.Localized (_,e) -> raise e
+ (*| End_of_file -> raise Margin *)
+ in
+ let stringbuf = Ulexing.from_utf8_string new_statements in
+ let interpr = GrafiteDisambiguate.get_interpr st#disambiguate_db in
+ let outstr = ref "" in
+ ignore (SmallLexer.mk_small_printer interpr outstr stringbuf);
+ prerr_endline ("parser output: " ^ !outstr);
+ MatitaAuthentication.set_status sid st;
+ parsed_len,
+ Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false
+ () (html_of_matita !outstr), 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" *)
+ cgi#out_channel#output_string
+ ("<html><head><meta http-equiv=\"refresh\" content=\"2;url=/login.html\">"
+ ^ "</head><body>Redirecting to login page...</body></html>")
+ with
+ | MatitaAuthentication.UsernameCollision _ ->
+ cgi#set_header
+ ~cache:`No_cache
+ ~content_type:"text/html; charset=\"utf-8\""
+ ();
+ cgi#out_channel#output_string
+ "<html><head></head><body>Error: User id collision!</body></html>"
+ | MatitaFilesystem.SvnError msg ->
+ cgi#set_header
+ ~cache:`No_cache
+ ~content_type:"text/html; charset=\"utf-8\""
+ ();
+ cgi#out_channel#output_string
+ ("<html><head></head><body><p>Error: Svn checkout failed!<p><p><textarea>"
+ ^ msg ^ "</textarea></p></body></html>"));
+ 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
+ let env = cgi#environment in
+
+ assert (cgi#arguments <> []);
+ let uid = cgi#argument_value "userid" in
+ let userpw = cgi#argument_value "password" in
+ let pw,_ = MatitaAuthentication.lookup_user uid in
+
+ if pw = userpw then
+ begin
+ let _ = MatitaFilesystem.html_of_library uid in
+ let sid = MatitaAuthentication.create_session uid in
+ (* 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" *)
+ cgi#out_channel#output_string
+ ("<html><head><meta http-equiv=\"refresh\" content=\"2;url=/index.html\">"
+ ^ "</head><body>Redirecting to Matita page...</body></html>")
+ end
+ else
+ begin
+ prerr_endline ("ERROR: received " ^ userpw ^ "but the password is " ^ pw);
+ cgi#set_header
+ ~cache:`No_cache
+ ~content_type:"text/html; charset=\"utf-8\""
+ ();
+ cgi#out_channel#output_string
+ "<html><head></head><body>Authentication error</body></html>"
+ end;
+
+ cgi#out_channel#commit_work()
+
+;;
+
+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/html; charset=\"utf-8\""
+ ());
+ cgi#out_channel#commit_work()
+;;
+
+let save (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
+ let status = MatitaAuthentication.get_status sid in
+ let uid = MatitaAuthentication.user_of_session sid in
+ assert (cgi#arguments <> []);
+ let locked = cgi#argument_value "locked" in
+ let unlocked = cgi#argument_value "unlocked" in
+ let filename = libdir uid ^ "/" ^ (cgi # argument_value "file") in
+ prerr_endline ("Matita will save the file for user " ^ uid);
+ let oc = open_out filename in
+ output_string oc (locked ^ unlocked);
+ close_out oc;
+ if MatitaEngine.eos status unlocked then
+ begin
+ prerr_endline ("serializing proof objects...");
+ GrafiteTypes.Serializer.serialize
+ ~baseuri:(NUri.uri_of_string status#baseuri) status;
+ prerr_endline ("adding to the commit queue...");
+ MatitaFilesystem.add_user uid;
+ prerr_endline ("done.");
+ end;
+ cgi # set_header
+ ~cache:`No_cache
+ ~content_type:"text/xml; charset=\"utf-8\""
+ ();
+ cgi#out_channel#output_string "<response>ok</response>"
+ 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()
+;;
+
+let initiate_commit (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 errors = MatitaFilesystem.do_global_commit () in
+ prerr_endline ("commit errors: " ^ (String.concat " " errors));
+ cgi # set_header
+ ~cache:`No_cache
+ ~content_type:"text/xml; charset=\"utf-8\""
+ ();
+ cgi#out_channel#output_string "<response>ok</response>"
+ 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) =
+ 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
+ (*
+ cgi # set_header
+ ~cache:`No_cache
+ ~content_type:"text/xml; charset=\"utf-8\""
+ ();
+ *)
+ let text = cgi#argument_value "body" in
+ prerr_endline ("body =\n" ^ text);
+ let history = MatitaAuthentication.get_history sid in
+ let parsed_len, new_parsed, new_unparsed, new_status = advance0 sid text in
+ MatitaAuthentication.set_history sid (new_status::history);
+ let txt = output_status new_status in
+ let body =
+ "<response><parsed length=\"" ^ (string_of_int parsed_len) ^ "\">" ^
+ new_parsed ^ "</parsed>" ^ txt
+ ^ "</response>"
+ in
+ prerr_endline ("sending advance response:\n" ^ body);
+ cgi # set_header
+ ~cache:`No_cache
+ ~content_type:"text/xml; charset=\"utf-8\""
+ ();
+ cgi#out_channel#output_string body
+ 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()
+;;
+
+let gotoBottom (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
+ let history = MatitaAuthentication.get_history sid in
+
+ let rec aux parsed_len parsed_txt text =
+ try
+ prerr_endline ("evaluating: " ^ first_line text);
+ let plen,new_parsed,new_unparsed,_new_status = advance0 sid text in
+ aux (parsed_len+plen) (parsed_txt ^ new_parsed) new_unparsed
+ with
+ | End_of_file ->
+ let status = MatitaAuthentication.get_status sid in
+ GrafiteTypes.Serializer.serialize
+ ~baseuri:(NUri.uri_of_string status#baseuri) status;
+ if parsed_len > 0 then
+ MatitaAuthentication.set_history sid (status::history);
+ parsed_len, parsed_txt
+ | _ -> parsed_len, parsed_txt
+ in
+ (*
+ cgi # set_header
+ ~cache:`No_cache
+ ~content_type:"text/xml; charset=\"utf-8\""
+ ();
+ *)
+ let text = cgi#argument_value "body" in
+ prerr_endline ("body =\n" ^ text);
+ let parsed_len, new_parsed = aux 0 "" text in
+ let status = MatitaAuthentication.get_status sid in
+ let txt = output_status status in
+ let body =
+ "<response><parsed length=\"" ^ (string_of_int parsed_len) ^ "\">" ^
+ new_parsed ^ "</parsed>" ^ txt
+ ^ "</response>"
+ in
+ (*let body =
+ "<response><parsed length=\"" ^ (string_of_int parsed_len) ^ "\" />" ^ txt
+ ^ "</response>"
+ in*)
+ prerr_endline ("sending goto bottom response:\n" ^ body);
+ cgi # set_header
+ ~cache:`No_cache
+ ~content_type:"text/xml; charset=\"utf-8\""
+ ();
+ cgi#out_channel#output_string body
+ 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()