]> matita.cs.unibo.it Git - helm.git/blob - matitaB/matita/matitadaemon.ml
Matitaweb:
[helm.git] / matitaB / matita / matitadaemon.ml
1 open Printf;;
2 open Http_types;;
3
4 exception Emphasized_error of string
5 exception Disamb_error of string
6
7 module Stack = Continuationals.Stack
8
9 let rt_path () = Helm_registry.get "matita.rt_base_dir" 
10
11 let libdir uid = (rt_path ()) ^ "/users/" ^ uid 
12
13 let utf8_length = Netconversion.ustring_length `Enc_utf8
14
15 let mutex = Mutex.create ();;
16
17 let to_be_committed = ref [];;
18
19 let html_of_matita s =
20   let patt1 = Str.regexp "\005" in
21   let patt2 = Str.regexp "\006" in
22   let patt3 = Str.regexp "<" in
23   let patt4 = Str.regexp ">" in
24   let res = Str.global_replace patt4 "&gt;" s in
25   let res = Str.global_replace patt3 "&lt;" res in
26   let res = Str.global_replace patt2 ">" res in
27   let res = Str.global_replace patt1 "<" res in
28   res
29 ;;
30
31 (* adds a user to the commit queue; concurrent instances possible, so we
32  * enclose the update in a CS
33  *)
34 let add_user_for_commit uid =
35   Mutex.lock mutex;
36   to_be_committed := uid::List.filter (fun x -> x <> uid) !to_be_committed;
37   Mutex.unlock mutex;
38 ;;
39
40 let do_global_commit () =
41   prerr_endline ("to be committed: " ^ String.concat " " !to_be_committed);
42   List.fold_left
43     (fun out u ->
44        let ft = MatitaAuthentication.read_ft u in
45
46        (* first we add new files/dirs to the repository *)
47        (* must take the reverse because svn requires the add to be performed in
48           the correct order
49           (otherwise run with --parents option) *)
50        let to_be_added = List.rev (List.map fst  
51          (List.filter (fun (_,flag) -> flag = MatitaFilesystem.MAdd) ft))
52        in
53        prerr_endline ("@@@ ADDING files: " ^ String.concat ", " to_be_added);
54        let out = 
55          try
56            let newout = MatitaFilesystem.add_files u to_be_added in
57            out ^ "\n" ^ newout
58          with
59          | MatitaFilesystem.SvnError outstr -> 
60              prerr_endline ("ADD OF " ^ u ^ "FAILED:" ^ outstr);
61              out
62        in
63
64        (* now we update the local copy (to merge updates from other users) *)
65        let out = try
66          let files,anomalies,(added,conflict,del,upd,merged) = 
67            MatitaFilesystem.update_user u 
68          in
69          let anomalies = String.concat "\n" anomalies in
70          let details = Printf.sprintf 
71            ("%d new files\n"^^
72             "%d deleted files\n"^^
73             "%d updated files\n"^^
74             "%d merged files\n"^^
75             "%d conflicting files\n\n" ^^
76             "Anomalies:\n%s") added del upd merged conflict anomalies
77          in
78          prerr_endline ("update details:\n" ^ details);
79          MatitaAuthentication.set_file_flag u files;
80          out ^ "\n" ^ details 
81          with
82          | MatitaFilesystem.SvnError outstr -> 
83              prerr_endline ("UPDATE OF " ^ u ^ "FAILED:" ^ outstr);
84              out
85        in
86
87        (* we re-read the file table after updating *)
88        let ft = MatitaAuthentication.read_ft u in
89
90        (* finally we perform the real commit *)
91        let modified = (List.map fst
92          (List.filter (fun (_,flag) -> flag = MatitaFilesystem.MModified) ft))
93        in
94        let to_be_committed = to_be_added @ modified
95        in
96        let out = try
97          let newout = MatitaFilesystem.commit u to_be_committed in
98          out ^ "\n" ^ newout
99          with
100          | MatitaFilesystem.SvnError outstr -> 
101              prerr_endline ("COMMIT OF " ^ u ^ "FAILED:" ^ outstr);
102              out
103        in
104
105        (* call stat to get the final status *)
106        let files, anomalies = MatitaFilesystem.stat_user u in
107        let added,not_added = List.fold_left 
108          (fun (a_acc, na_acc) fname ->
109             if List.mem fname (List.map fst files) then
110                a_acc, fname::na_acc
111             else
112                fname::a_acc, na_acc)
113          ([],[]) to_be_added
114        in
115        let committed,not_committed = List.fold_left 
116          (fun (c_acc, nc_acc) fname ->
117             if List.mem fname (List.map fst files) then
118                c_acc, fname::nc_acc
119             else
120                fname::c_acc, nc_acc)
121          ([],[]) modified
122        in
123        let conflicts = List.map fst (List.filter 
124          (fun (_,f) -> f = Some MatitaFilesystem.MConflict) files)
125        in
126        MatitaAuthentication.set_file_flag u
127          (List.map (fun x -> x, Some MatitaFilesystem.MSynchronized) (added@committed));
128        MatitaAuthentication.set_file_flag u files;
129        out ^ "\n\n" ^ (Printf.sprintf
130         ("COMMIT RESULTS for %s\n" ^^
131          "==============\n" ^^
132          "added and committed (%d of %d): %s\n" ^^
133          "modified and committed (%d of %d): %s\n" ^^
134          "not added: %s\n" ^^
135          "not committed: %s\n" ^^
136          "conflicts: %s\n")
137          u (List.length added) (List.length to_be_added) (String.concat ", " added)
138          (List.length committed) (List.length modified) (String.concat ", " committed)
139          (String.concat ", " not_added)
140          (String.concat ", " not_committed) (String.concat ", " conflicts)))
141
142   (* XXX: at the moment, we don't keep track of the order in which users have 
143      scheduled their commits, but we should, otherwise we will get a 
144      "first come, random served" policy *)
145   "" (* (List.rev !to_be_committed) *) (MatitaAuthentication.get_users ())
146 ;;
147
148 (*** from matitaScript.ml ***)
149 (* let only_dust_RE = Pcre.regexp "^(\\s|\n|%%[^\n]*\n)*$" *)
150
151 let eval_statement include_paths (* (buffer : GText.buffer) *) status (* script *)
152  statement
153 =
154   let ast,unparsed_text =
155     match statement with
156     | `Raw text ->
157         (* if Pcre.pmatch ~rex:only_dust_RE text then raise Margin; *)
158         prerr_endline ("raw text = " ^ text);
159         let strm =
160          GrafiteParser.parsable_statement status
161           (Ulexing.from_utf8_string text) in
162         prerr_endline "before get_ast";
163         let ast = MatitaEngine.get_ast status include_paths strm in
164         prerr_endline "after get_ast";
165          ast, text
166     | `Ast (st, text) -> st, text
167   in
168
169   (* do we want to generate a trace? *)
170   let is_auto (l,a) = 
171     not (List.mem_assoc "demod" a || List.mem_assoc "paramod" a ||
172       List.mem_assoc "fast_paramod" a || List.assoc "depth" a = "1" ||
173       l <> None)
174   in
175
176   let get_param a param = 
177      try 
178        Some (param ^ "=" ^ List.assoc param a)
179      with Not_found -> None
180   in
181
182   let floc = match ast with
183   | GrafiteAst.Executable (loc, _)
184   | GrafiteAst.Comment (loc, _) -> loc in
185   
186   let lstart,lend = HExtlib.loc_of_floc floc in 
187   let parsed_text, _parsed_text_len = 
188     HExtlib.utf8_parsed_text unparsed_text (HExtlib.floc_of_loc (0,lend)) in
189   let parsed_text_len = utf8_length parsed_text in
190   let byte_parsed_text_len = String.length parsed_text in
191   let unparsed_txt' = 
192     String.sub unparsed_text byte_parsed_text_len 
193       (String.length unparsed_text - byte_parsed_text_len)
194   in
195   prerr_endline (Printf.sprintf "ustring_sub caso 1: lstart=%d, parsed=%s" lstart parsed_text);
196   let pre = Netconversion.ustring_sub `Enc_utf8  0 lstart parsed_text in
197
198   let mk_univ trace = 
199     let href r = 
200       Printf.sprintf "\005A href=\"%s\"\006%s\005/A\006"
201         (NReference.string_of_reference r) (NCicPp.r2s status true r)
202     in
203     if trace = [] then "{}"
204     else String.concat ", " 
205       (HExtlib.filter_map (function 
206         | NotationPt.NRef r -> Some (href r) 
207         | _ -> None)
208       trace)
209   in
210   
211   match ast with
212   | GrafiteAst.Executable (_,
213       GrafiteAst.NTactic (_,
214         [GrafiteAst.NAuto (_, (l,a as auto_params))])) when is_auto auto_params
215           ->
216           let l = match l with
217           | None -> None
218           | Some (_,l') -> Some (List.map (fun x -> "",0,x) l')
219           in
220           let trace_ref = ref [] in
221           let status = NnAuto.auto_tac ~params:(l,a) ~trace_ref status in
222           let new_parsed_text = pre ^ (Printf.sprintf 
223             "/\005span class='autotactic'\006%s\005span class='autotrace'\006 trace %s\005/span\006\005/span\006/"
224              (String.concat " " 
225                (List.assoc "depth" a::
226                 HExtlib.filter_map (get_param a) ["width";"size"]))
227              (mk_univ !trace_ref))
228           in
229           (status,new_parsed_text, unparsed_txt'),parsed_text_len
230   | _ ->
231       let status = 
232         MatitaEngine.eval_ast ~include_paths ~do_heavy_checks:false status ("",0,ast)
233       in
234       let new_parsed_text = Ulexing.from_utf8_string parsed_text in
235       let interpr = GrafiteDisambiguate.get_interpr status#disambiguate_db in
236       let outstr = ref "" in
237       ignore (SmallLexer.mk_small_printer interpr outstr new_parsed_text);
238       prerr_endline ("baseuri after advance = " ^ status#baseuri);
239       (* prerr_endline ("parser output: " ^ !outstr); *)
240       (status,!outstr, unparsed_txt'),parsed_text_len
241
242 (*let save_moo status = 
243   let script = MatitaScript.current () in
244   let baseuri = status#baseuri in
245   match script#bos, script#eos with
246   | true, _ -> ()
247   | _, true ->
248      GrafiteTypes.Serializer.serialize ~baseuri:(NUri.uri_of_string baseuri)
249       status
250   | _ -> clean_current_baseuri status 
251 ;;*)
252     
253 let sequent_size = ref 40;;
254
255 let include_paths = ref [];;
256
257 (* <metasenv>
258  *   <meta number="...">
259  *     <metaname>...</metaname>
260  *     <goal>...</goal>
261  *   </meta>
262  *
263  *   ...
264  * </metasenv> *)
265 let output_status s =
266   let _,_,metasenv,subst,_ = s#obj in
267   let render_switch = function 
268   | Stack.Open i -> "?" ^ (string_of_int i) 
269   | Stack.Closed i -> "<S>?" ^ (string_of_int i) ^ "</S>"
270   in
271   let int_of_switch = function
272   | Stack.Open i | Stack.Closed i -> i
273   in
274   let sequent = function
275   | Stack.Open i ->
276       let meta = List.assoc i metasenv in
277       snd (ApplyTransformation.ntxt_of_cic_sequent 
278         ~metasenv ~subst ~map_unicode_to_tex:false !sequent_size s (i,meta))
279   | Stack.Closed _ -> "This goal has already been closed."
280   in
281   let render_sequent is_loc acc depth tag (pos,sw) =
282     let metano = int_of_switch sw in
283     let markup = 
284       if is_loc then
285         (match depth, pos with
286          | 0, 0 -> "<span class=\"activegoal\">" ^ (render_switch sw) ^ "</span>"
287          | 0, _ -> 
288             Printf.sprintf "<span class=\"activegoal\">|<SUB>%d</SUB>: %s</span>" pos (render_switch sw)
289          | 1, pos when Stack.head_tag s#stack = `BranchTag ->
290              Printf.sprintf "<span class=\"passivegoal\">|<SUB>%d</SUB> : %s</span>" pos (render_switch sw)
291          | _ -> render_switch sw)
292       else render_switch sw
293     in
294     let markup = 
295       Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () markup in
296     let markup = "<metaname>" ^ markup ^ "</metaname>" in
297     let sequent =
298       Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () (sequent sw)
299     in      
300     let txt0 = "<goal>" ^ sequent ^ "</goal>" in
301     "<meta number=\"" ^ (string_of_int metano) ^ "\">" ^ markup ^
302     txt0 ^ "</meta>" ^ acc
303   in
304   "<metasenv>" ^
305     (Stack.fold 
306       ~env:(render_sequent true) ~cont:(render_sequent false) 
307       ~todo:(render_sequent false) "" s#stack) ^
308     "</metasenv>"
309   (* prerr_endline ("sending metasenv:\n" ^ res); res *)
310 ;;
311
312 let heading_nl_RE = Pcre.regexp "^\\s*\n\\s*";;
313
314 let first_line s =
315   let s = Pcre.replace ~rex:heading_nl_RE s in
316   try
317     let nl_pos = String.index s '\n' in
318     String.sub s 0 nl_pos
319   with Not_found -> s
320 ;;
321
322 let read_file fname =
323   let chan = open_in fname in
324   let lines = ref [] in
325   (try
326      while true do
327        lines := input_line chan :: !lines
328      done;
329    with End_of_file -> close_in chan);
330   String.concat "\n" (List.rev !lines)
331 ;;
332
333 let load_index outchan =
334   let s = read_file "index.html" in
335   Http_daemon.respond ~headers:["Content-Type", "text/html"] ~code:(`Code 200) ~body:s outchan
336 ;;
337
338 let load_doc filename outchan =
339   let s = read_file filename in
340   let is_png = 
341     try String.sub filename (String.length filename - 4) 4 = ".png"
342     with Invalid_argument _ -> false
343   in
344   let contenttype = if is_png then "image/png" else "text/html" in
345   Http_daemon.respond ~headers:["Content-Type", contenttype] ~code:(`Code 200) ~body:s outchan
346 ;;
347
348 let retrieve (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
349   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
350   let env = cgi#environment in
351   (try 
352     let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in
353     let sid = HExtlib.unopt sid in
354     let uid = MatitaAuthentication.user_of_session sid in
355     (*
356     cgi # set_header 
357       ~cache:`No_cache 
358       ~content_type:"text/xml; charset=\"utf-8\""
359       ();
360     *)
361     let filename = libdir uid ^ "/" ^ (cgi # argument_value "file") in
362     (* prerr_endline ("reading file " ^ filename); *)
363     let body = 
364      Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false ()
365         (html_of_matita (read_file filename)) in
366      
367      (*   html_of_matita (read_file filename) in *)
368     (* prerr_endline ("sending:\nBEGIN\n" ^ body ^ "\nEND"); *)
369     let body = "<response><file>" ^ body ^ "</file></response>" in
370     let baseuri, incpaths = 
371       try 
372         let root, baseuri, _fname, _tgt = 
373           Librarian.baseuri_of_script ~include_paths:[] filename in 
374         let includes =
375          try
376           Str.split (Str.regexp " ") 
377            (List.assoc "include_paths" (Librarian.load_root_file (root^"/root")))
378          with Not_found -> []
379         in
380         let rc = root :: includes in
381          List.iter (HLog.debug) rc; baseuri, rc
382        with 
383          Librarian.NoRootFor _ | Librarian.FileNotFound _ -> "",[] in
384     include_paths := incpaths;
385     let status = (MatitaAuthentication.get_status sid)#set_baseuri baseuri in
386     let history = [status] in
387     MatitaAuthentication.set_status sid status;
388     MatitaAuthentication.set_history sid history;
389     cgi # set_header 
390       ~cache:`No_cache 
391       ~content_type:"text/xml; charset=\"utf-8\""
392       ();
393     cgi#out_channel#output_string body;
394   with
395   | Not_found _ -> 
396     cgi # set_header
397       ~status:`Internal_server_error
398       ~cache:`No_cache 
399       ~content_type:"text/html; charset=\"utf-8\""
400       ());
401   cgi#out_channel#commit_work()
402 ;;
403
404 let xml_of_disamb_error l =
405   let mk_alias = function
406   | GrafiteAst.Ident_alias (_,uri) -> "href=\"" ^ uri ^ "\""
407   | GrafiteAst.Symbol_alias (_,uri,desc) 
408   | GrafiteAst.Number_alias (uri,desc) -> 
409       let uri = try HExtlib.unopt uri with _ -> "cic:/fakeuri.def(1)" in
410         "href=\"" ^ uri ^ "\" title=\"" ^ 
411         (Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () desc)
412         ^ "\""
413   in
414
415   let mk_interpr (loc,a) =
416     let x,y = HExtlib.loc_of_floc loc in
417     Printf.sprintf "<interpretation start=\"%d\" stop=\"%d\" %s />"
418       x y (mk_alias a)
419   in
420
421   let mk_failure (il,loc,msg) =
422     let x,y = HExtlib.loc_of_floc loc in
423     Printf.sprintf "<failure start=\"%d\" stop=\"%d\" title=\"%s\">%s</failure>"
424       x y (Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () msg)
425       (String.concat "" (List.map mk_interpr il))
426   in
427
428   let mk_choice (a,fl) = 
429     let fl' = String.concat "" (List.map mk_failure fl) in
430     match a with
431     | None -> "<choice>" ^ fl' ^ "</choice>"
432     | Some a -> Printf.sprintf "<choice %s>%s</choice>" (mk_alias a) fl'
433   in
434
435   let mk_located (loc,cl) =
436     let x,y = HExtlib.loc_of_floc loc in
437     Printf.sprintf "<choicepoint start=\"%d\" stop=\"%d\">%s</choicepoint>"
438       x y (String.concat "" (List.map mk_choice cl))
439   in
440   "<disamberror>" ^ (String.concat "" (List.map mk_located l)) ^ "</disamberror>"
441 ;;
442
443 let advance0 sid text =
444   let status = MatitaAuthentication.get_status sid in
445   let history = MatitaAuthentication.get_history sid in
446   let status = status#reset_disambiguate_db () in
447   let (st,new_statements,new_unparsed),parsed_len =
448     try
449       eval_statement !include_paths (*buffer*) status (`Raw text)
450     with
451     | HExtlib.Localized (floc,e) as exn ->
452       let x, y = HExtlib.loc_of_floc floc in
453   prerr_endline (Printf.sprintf "ustring_sub caso 2: (%d,%d) parsed=%s" 0 x text);
454       let pre = Netconversion.ustring_sub `Enc_utf8  0 x text in
455   prerr_endline (Printf.sprintf "ustring_sub caso 3: (%d,%d) parsed=%s" x (y-x) text);
456       let err = Netconversion.ustring_sub `Enc_utf8  x (y-x) text in
457   prerr_endline (Printf.sprintf "ustring_sub caso 4: (%d,%d) parsed=%s" y (Netconversion.ustring_length `Enc_utf8 text - y) text);
458       let post = Netconversion.ustring_sub `Enc_utf8 y 
459          (Netconversion.ustring_length `Enc_utf8 text - y) text in
460       let _,title = MatitaExcPp.to_string exn in
461       (* let title = "" in *)
462       let marked = 
463         pre ^ "\005span class=\"error\" title=\"" ^ title ^ "\"\006" ^ err ^ "\005/span\006" ^ post in
464       let marked = Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false 
465       () (html_of_matita marked) in
466       raise (Emphasized_error marked) 
467     | NTacStatus.Error (s,None) as e ->
468         prerr_endline 
469           ("NTacStatus.Error " ^ (Lazy.force s));
470         raise e
471     | NTacStatus.Error (s,Some exc) as e ->
472         prerr_endline 
473           ("NTacStatus.Error " ^ Lazy.force s ^ " -- " ^ (Printexc.to_string exc));
474         raise e
475     | GrafiteDisambiguate.Ambiguous_input (loc,choices) ->
476       let x,y = HExtlib.loc_of_floc loc in
477       let choice_of_alias = function
478        | GrafiteAst.Ident_alias (_,uri) -> uri, None, uri
479        | GrafiteAst.Number_alias (None,desc)
480        | GrafiteAst.Symbol_alias (_,None,desc) -> "cic:/fakeuri.def(1)", Some desc, desc
481        | GrafiteAst.Number_alias (Some uri,desc)
482        | GrafiteAst.Symbol_alias (_,Some uri,desc) -> uri, Some desc, desc
483       in
484       let tag_of_choice (uri,title,desc) =
485         match title with
486         | None -> Printf.sprintf "<choice href=\"%s\">%s</choice>"
487             uri 
488             (Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () desc)
489         | Some t -> Printf.sprintf "<choice href=\"%s\" title=\"%s\">%s</choice>"
490             uri 
491             (Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () t)
492             (Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () desc)
493       in
494       let strchoices = 
495         String.concat "\n" 
496           (List.map (fun x -> tag_of_choice (choice_of_alias x)) choices)
497       in
498       prerr_endline (Printf.sprintf
499         "@@@ Ambiguous input at (%d,%d). Possible choices:\n\n%s\n\n@@@ End."
500           x y strchoices);
501       (*
502       let pre = Netconversion.ustring_sub `Enc_utf8  0 x text in
503       let err = Netconversion.ustring_sub `Enc_utf8  x (y-x) text in
504       let post = Netconversion.ustring_sub `Enc_utf8 y 
505          (Netconversion.ustring_length `Enc_utf8 text - y) text in
506       let title = "Disambiguation Error" in
507       (* let title = "" in *)
508       let marked = 
509         pre ^ "\005span class=\"error\" title=\"" ^ title ^ "\"\006" ^ err ^ "\005/span\006" ^ post in
510       let marked = Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false 
511       () (html_of_matita marked) in
512       *)
513       let strchoices = Printf.sprintf
514         "<ambiguity start=\"%d\" stop=\"%d\">%s</ambiguity>" x y strchoices
515       in raise (Disamb_error strchoices)
516    | GrafiteDisambiguate.Error l -> raise (Disamb_error (xml_of_disamb_error l))
517    (* | End_of_file -> ...          *)
518   in
519   MatitaAuthentication.set_status sid st;
520   MatitaAuthentication.set_history sid (st::history);
521   parsed_len, 
522     Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false 
523       () (html_of_matita new_statements), new_unparsed, st
524
525 let register (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
526   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
527   let _env = cgi#environment in
528   
529   assert (cgi#arguments <> []);
530   let uid = cgi#argument_value "userid" in
531   let userpw = cgi#argument_value "password" in
532   (try 
533     MatitaAuthentication.add_user uid userpw;
534 (*    env#set_output_header_field "Location" "/index.html" *)
535     cgi#out_channel#output_string
536      ("<html><head><meta http-equiv=\"refresh\" content=\"2;url=/login.html\">"
537      ^ "</head><body>Redirecting to login page...</body></html>")
538    with
539    | MatitaAuthentication.UsernameCollision _ ->
540       cgi#set_header
541        ~cache:`No_cache 
542        ~content_type:"text/html; charset=\"utf-8\""
543        ();
544      cgi#out_channel#output_string
545       "<html><head></head><body>Error: User id collision!</body></html>"
546    | MatitaFilesystem.SvnError msg ->
547       cgi#set_header
548        ~cache:`No_cache 
549        ~content_type:"text/html; charset=\"utf-8\""
550        ();
551      cgi#out_channel#output_string
552       ("<html><head></head><body><p>Error: Svn checkout failed!<p><p><textarea>"
553        ^ msg ^ "</textarea></p></body></html>"));
554   cgi#out_channel#commit_work()
555 ;;
556
557 let login (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
558   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
559   let env = cgi#environment in
560   
561   assert (cgi#arguments <> []);
562   let uid = cgi#argument_value "userid" in
563   let userpw = cgi#argument_value "password" in
564   let pw,_ = MatitaAuthentication.lookup_user uid in
565
566   if pw = userpw then
567    begin
568    let ft = MatitaAuthentication.read_ft uid in
569    let _ = MatitaFilesystem.html_of_library uid ft in
570     let sid = MatitaAuthentication.create_session uid in
571     (* let cookie = Netcgi.Cookie.make "session" (Uuidm.to_string sid) in
572        cgi#set_header ~set_cookies:[cookie] (); *)
573     env#set_output_header_field 
574       "Set-Cookie" ("session=" ^ (Uuidm.to_string sid));
575 (*    env#set_output_header_field "Location" "/index.html" *)
576     cgi#out_channel#output_string
577      ("<html><head><meta http-equiv=\"refresh\" content=\"2;url=/index.html\">"
578      ^ "</head><body>Redirecting to Matita page...</body></html>")
579    end
580   else
581    begin
582     cgi#set_header
583       ~cache:`No_cache 
584       ~content_type:"text/html; charset=\"utf-8\""
585       ();
586     cgi#out_channel#output_string
587       "<html><head></head><body>Authentication error</body></html>"
588    end;
589     
590   cgi#out_channel#commit_work()
591   
592 ;;
593
594 let logout (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
595   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
596   let env = cgi#environment in
597   (try 
598     let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in
599     let sid = HExtlib.unopt sid in
600     MatitaAuthentication.logout_user sid;
601     cgi # set_header 
602       ~cache:`No_cache 
603       ~content_type:"text/html; charset=\"utf-8\""
604       ();
605     let text = read_file (rt_path () ^ "/logout.html") in
606     cgi#out_channel#output_string text
607   with
608   | Not_found _ -> 
609     cgi # set_header
610       ~status:`Internal_server_error
611       ~cache:`No_cache 
612       ~content_type:"text/html; charset=\"utf-8\""
613       ());
614   cgi#out_channel#commit_work()
615 ;;
616
617 exception File_already_exists;;
618
619 let save (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
620   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
621   let env = cgi#environment in
622   (try 
623     let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in
624     let sid = HExtlib.unopt sid in
625     let status = MatitaAuthentication.get_status sid in
626     let uid = MatitaAuthentication.user_of_session sid in
627     assert (cgi#arguments <> []);
628     let locked = cgi#argument_value "locked" in
629     let unlocked = cgi#argument_value "unlocked" in
630     let dir = cgi#argument_value "dir" in
631     let rel_filename = cgi # argument_value "file" in
632     let filename = libdir uid ^ "/" ^ rel_filename in
633     let force = bool_of_string (cgi#argument_value "force") in
634     let already_exists = Sys.file_exists filename in
635
636     if ((not force) && already_exists) then 
637       raise File_already_exists;
638
639     if dir = "true" then
640        Unix.mkdir filename 0o744
641     else 
642      begin
643       let oc = open_out filename in
644       output_string oc (locked ^ unlocked);
645       close_out oc;
646       if MatitaEngine.eos status unlocked then
647        begin
648         (* prerr_endline ("serializing proof objects..."); *)
649         GrafiteTypes.Serializer.serialize 
650           ~baseuri:(NUri.uri_of_string status#baseuri) status;
651         (* prerr_endline ("done."); *)
652        end;
653      end;
654     let old_flag =
655       try 
656         List.assoc rel_filename (MatitaAuthentication.read_ft uid)
657       with Not_found -> MatitaFilesystem.MUnversioned
658     in
659     (if old_flag <> MatitaFilesystem.MConflict &&
660        old_flag <> MatitaFilesystem.MAdd then
661       let newflag = 
662         if already_exists then MatitaFilesystem.MModified
663         else MatitaFilesystem.MAdd
664       in
665       MatitaAuthentication.set_file_flag uid [rel_filename, Some newflag]);
666     cgi # set_header 
667      ~cache:`No_cache 
668      ~content_type:"text/xml; charset=\"utf-8\""
669      ();
670     cgi#out_channel#output_string "<response>ok</response>"
671   with
672   | File_already_exists ->
673       cgi#out_channel#output_string "<response>cancelled</response>"
674   | Sys_error _ -> 
675     cgi # set_header
676       ~status:`Internal_server_error
677       ~cache:`No_cache 
678       ~content_type:"text/xml; charset=\"utf-8\""
679       ()
680   | e ->
681       let estr = Printexc.to_string e in
682       cgi#out_channel#output_string ("<response>" ^ estr ^ "</response>"));
683   cgi#out_channel#commit_work()
684 ;;
685
686 let initiate_commit (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
687   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
688   let _env = cgi#environment in
689   (try
690     let out = do_global_commit () in
691     cgi # set_header 
692       ~cache:`No_cache 
693       ~content_type:"text/xml; charset=\"utf-8\""
694       ();
695     cgi#out_channel#output_string "<commit>";
696     cgi#out_channel#output_string "<response>ok</response>";
697     cgi#out_channel#output_string ("<details>" ^ out ^ "</details>");
698     cgi#out_channel#output_string "</commit>"
699   with
700   | Not_found _ -> 
701     cgi # set_header
702       ~status:`Internal_server_error
703       ~cache:`No_cache 
704       ~content_type:"text/xml; charset=\"utf-8\""
705       ());
706   cgi#out_channel#commit_work()
707 ;;
708
709 let svn_update (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
710   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
711   let env = cgi#environment in
712   let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in
713   let sid = HExtlib.unopt sid in
714   let uid = MatitaAuthentication.user_of_session sid in
715   (try
716     let files,anomalies,(added,conflict,del,upd,merged) = 
717       MatitaFilesystem.update_user uid 
718     in
719     let anomalies = String.concat "\n" anomalies in
720     let details = Printf.sprintf 
721       ("%d new files\n"^^
722        "%d deleted files\n"^^
723        "%d updated files\n"^^
724        "%d merged files\n"^^
725        "%d conflicting files\n\n" ^^
726        "Anomalies:\n%s") added del upd merged conflict anomalies
727     in
728     prerr_endline ("update details:\n" ^ details);
729     let details = 
730       Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () details
731     in
732     MatitaAuthentication.set_file_flag uid files;
733     cgi # set_header 
734       ~cache:`No_cache 
735       ~content_type:"text/xml; charset=\"utf-8\""
736       ();
737     cgi#out_channel#output_string "<update>";
738     cgi#out_channel#output_string "<response>ok</response>";
739     cgi#out_channel#output_string ("<details>" ^ details ^ "</details>");
740     cgi#out_channel#output_string "</update>";
741   with
742   | Not_found _ -> 
743     cgi # set_header
744       ~status:`Internal_server_error
745       ~cache:`No_cache 
746       ~content_type:"text/xml; charset=\"utf-8\""
747       ());
748   cgi#out_channel#commit_work()
749 ;;
750
751 (* returns the length of the executed text and an html representation of the
752  * current metasenv*)
753 let advance (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
754   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
755   let env = cgi#environment in
756   (try 
757     let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in
758     let sid = HExtlib.unopt sid in
759     (*
760     cgi # set_header 
761       ~cache:`No_cache 
762       ~content_type:"text/xml; charset=\"utf-8\""
763       ();
764     *)
765     let text = cgi#argument_value "body" in
766     (* prerr_endline ("body =\n" ^ text); *)
767     let parsed_len, new_parsed, new_unparsed, new_status = advance0 sid text in
768     let txt = output_status new_status in
769     let body = 
770        "<response><parsed length=\"" ^ (string_of_int parsed_len) ^ "\">" ^
771        new_parsed ^ "</parsed>" ^ txt 
772        ^ "</response>"
773     in 
774     (* prerr_endline ("sending advance response:\n" ^ body); *)
775     cgi # set_header 
776       ~cache:`No_cache 
777       ~content_type:"text/xml; charset=\"utf-8\""
778       ();
779     cgi#out_channel#output_string body
780    with
781   | Emphasized_error text ->
782 (* | MultiPassDisambiguator.DisambiguationError (offset,errorll) -> *)
783     let body = "<response><error>" ^ text ^ "</error></response>" in 
784     cgi # set_header 
785       ~cache:`No_cache 
786       ~content_type:"text/xml; charset=\"utf-8\""
787       ();
788     cgi#out_channel#output_string body
789   | Disamb_error text -> 
790     let body = "<response>" ^ text ^ "</response>" in 
791     cgi # set_header 
792       ~cache:`No_cache 
793       ~content_type:"text/xml; charset=\"utf-8\""
794       ();
795     cgi#out_channel#output_string body
796   | Not_found _ -> 
797     cgi # set_header
798       ~status:`Internal_server_error
799       ~cache:`No_cache 
800       ~content_type:"text/xml; charset=\"utf-8\""
801       ()
802   );
803   cgi#out_channel#commit_work()
804 ;;
805
806 let gotoBottom (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
807   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
808   let env = cgi#environment in
809 (*  (try  *)
810     let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in
811     let sid = HExtlib.unopt sid in
812     let history = MatitaAuthentication.get_history sid in
813
814     let error_msg = function
815       | Emphasized_error text -> "<localized>" ^ text ^ "</localized>" 
816       | Disamb_error text -> text
817       | End_of_file _ -> (* not an error *) ""
818       | e -> (* unmanaged error *)
819           "<error>" ^ 
820           (Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () 
821             (Printexc.to_string e)) ^ "</error>"
822     in
823
824     let rec aux acc text =
825       try
826         prerr_endline ("evaluating: " ^ first_line text);
827         let plen,new_parsed,new_unparsed,_new_status = advance0 sid text in
828         aux ((plen,new_parsed)::acc) new_unparsed
829       with e -> 
830           let status = MatitaAuthentication.get_status sid in
831           GrafiteTypes.Serializer.serialize 
832             ~baseuri:(NUri.uri_of_string status#baseuri) status;
833           acc, error_msg e
834     in
835     (* 
836     cgi # set_header 
837       ~cache:`No_cache 
838       ~content_type:"text/xml; charset=\"utf-8\""
839       ();
840     *)
841     let text = cgi#argument_value "body" in
842     (* prerr_endline ("body =\n" ^ text); *)
843     let len_parsedlist, err_msg = aux [] text in
844     let status = MatitaAuthentication.get_status sid in
845     let txt = output_status status in
846     let parsed_tag (len,txt) = 
847        "<parsed length=\"" ^ (string_of_int len) ^ "\">" ^ txt ^ "</parsed>"
848     in
849     (* List.rev: the list begins with the older parsed txt *)
850     let body = 
851        "<response>" ^
852        String.concat "" (List.rev (List.map parsed_tag len_parsedlist)) ^
853        txt ^ err_msg ^ "</response>"
854     in
855     (* prerr_endline ("sending goto bottom response:\n" ^ body); *)
856     cgi # set_header 
857       ~cache:`No_cache 
858       ~content_type:"text/xml; charset=\"utf-8\""
859       ();
860     cgi#out_channel#output_string body;
861 (*   with Not_found -> cgi#set_header ~status:`Internal_server_error 
862       ~cache:`No_cache 
863       ~content_type:"text/xml; charset=\"utf-8\"" ()); *)
864   cgi#out_channel#commit_work() 
865 ;;
866
867 let gotoTop (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
868   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
869   let env = cgi#environment in
870   prerr_endline "executing goto Top";
871   (try 
872     let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in
873     let sid = HExtlib.unopt sid in
874     (*
875     cgi # set_header 
876       ~cache:`No_cache 
877       ~content_type:"text/xml; charset=\"utf-8\""
878       ();
879     *)
880     let status = MatitaAuthentication.get_status sid in
881     let uid = MatitaAuthentication.user_of_session sid in
882     let baseuri = status#baseuri in
883     let new_status = new MatitaEngine.status (Some uid) baseuri in
884     prerr_endline "gototop prima della time travel";
885     (* NCicLibrary.time_travel new_status; *)
886     prerr_endline "gototop dopo della time travel";
887     let new_history = [new_status] in 
888     MatitaAuthentication.set_history sid new_history;
889     MatitaAuthentication.set_status sid new_status;
890     (* NCicLibrary.time_travel new_status; *)
891     cgi # set_header 
892       ~cache:`No_cache 
893       ~content_type:"text/xml; charset=\"utf-8\""
894       ();
895     cgi#out_channel#output_string "<response>ok</response>"
896    with _ -> 
897      (cgi#set_header ~status:`Internal_server_error 
898       ~cache:`No_cache 
899       ~content_type:"text/xml; charset=\"utf-8\"" ();
900       cgi#out_channel#output_string "<response>ok</response>"));
901   cgi#out_channel#commit_work() 
902 ;;
903
904 let retract (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
905   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
906   let env = cgi#environment in
907   (try  
908     let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in
909     let sid = HExtlib.unopt sid in
910     (*
911     cgi # set_header 
912       ~cache:`No_cache 
913       ~content_type:"text/xml; charset=\"utf-8\""
914       ();
915     *)
916     let history = MatitaAuthentication.get_history sid in
917     let new_history,new_status =
918        match history with
919          _::(status::_ as history) ->
920           history, status
921       | [_] -> (prerr_endline "singleton";failwith "retract")
922       | _ -> (prerr_endline "nil"; assert false) in
923     prerr_endline ("prima della time travel");
924     NCicLibrary.time_travel new_status;
925     prerr_endline ("dopo della time travel");
926     MatitaAuthentication.set_history sid new_history;
927     MatitaAuthentication.set_status sid new_status;
928     prerr_endline ("baseuri after retract = " ^ new_status#baseuri);
929     let body = output_status new_status in
930     cgi # set_header 
931       ~cache:`No_cache 
932       ~content_type:"text/xml; charset=\"utf-8\""
933       ();
934     cgi#out_channel#output_string body
935    with e -> 
936     prerr_endline ("error in retract: " ^ Printexc.to_string e);
937     cgi#set_header ~status:`Internal_server_error 
938       ~cache:`No_cache 
939       ~content_type:"text/xml; charset=\"utf-8\"" ());
940   cgi#out_channel#commit_work() 
941 ;;
942
943
944 let viewLib (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
945   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
946   let env = cgi#environment in
947   
948     let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in
949     let sid = HExtlib.unopt sid in
950     (*
951     cgi # set_header 
952       ~cache:`No_cache 
953       ~content_type:"text/html; charset=\"utf-8\""
954       ();
955     *)
956     let uid = MatitaAuthentication.user_of_session sid in
957     
958     let ft = MatitaAuthentication.read_ft uid in
959     let html = MatitaFilesystem.html_of_library uid ft in
960     cgi # set_header 
961       ~cache:`No_cache 
962       ~content_type:"text/html; charset=\"utf-8\""
963       ();
964     cgi#out_channel#output_string
965       ((*
966        "<html><head>\n" ^
967        "<title>XML Tree Control</title>\n" ^
968        "<link href=\"treeview/xmlTree.css\" type=\"text/css\" rel=\"stylesheet\">\n" ^
969        "<script src=\"treeview/xmlTree.js\" type=\"text/javascript\"></script>\n" ^
970        "<body>\n" ^ *)
971        html (* ^ "\n</body></html>" *) );
972     
973     let files,anomalies = MatitaFilesystem.stat_user uid in
974     let changed = HExtlib.filter_map 
975       (fun (n,f) -> if (f = Some MatitaFilesystem.MModified) then Some n else None) files
976     in
977     let changed = String.concat "\n" changed in
978     let anomalies = String.concat "\n" anomalies in
979     prerr_endline ("Changed:\n" ^ changed ^ "\n\nAnomalies:\n" ^ anomalies);
980   cgi#out_channel#commit_work()
981   
982 ;;
983
984 let resetLib (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
985   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
986   MatitaAuthentication.reset ();
987     cgi # set_header 
988       ~cache:`No_cache 
989       ~content_type:"text/html; charset=\"utf-8\""
990       ();
991     
992     cgi#out_channel#output_string
993       ("<html><head>\n" ^
994        "<title>Matitaweb Reset</title>\n" ^
995        "<body><H1>Reset completed</H1></body></html>");
996     cgi#out_channel#commit_work()
997
998 open Netcgi1_compat.Netcgi_types;;
999
1000 (**********************************************************************)
1001 (* Create the webserver                                               *)
1002 (**********************************************************************)
1003
1004
1005 let start() =
1006   let (opt_list, cmdline_cfg) = Netplex_main.args() in
1007
1008   let use_mt = ref true in
1009
1010   let opt_list' =
1011     [ "-mt", Arg.Set use_mt,
1012       "  Use multi-threading instead of multi-processing"
1013     ] @ opt_list in
1014
1015   Arg.parse 
1016     opt_list'
1017     (fun s -> raise (Arg.Bad ("Don't know what to do with: " ^ s)))
1018     "usage: netplex [options]";
1019   let parallelizer = 
1020     if !use_mt then
1021       Netplex_mt.mt()     (* multi-threading *)
1022     else
1023       Netplex_mp.mp() in  (* multi-processing *)
1024 (*
1025   let adder =
1026     { Nethttpd_services.dyn_handler = (fun _ -> process1);
1027       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1028       dyn_uri = None;                 (* not needed *)
1029       dyn_translator = (fun _ -> ""); (* not needed *)
1030       dyn_accept_all_conditionals = false;
1031     } in
1032 *)
1033   let do_advance =
1034     { Nethttpd_services.dyn_handler = (fun _ -> advance);
1035       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1036       dyn_uri = None;                 (* not needed *)
1037       dyn_translator = (fun _ -> ""); (* not needed *)
1038       dyn_accept_all_conditionals = false;
1039     } in
1040   let do_retract =
1041     { Nethttpd_services.dyn_handler = (fun _ -> retract);
1042       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1043       dyn_uri = None;                 (* not needed *)
1044       dyn_translator = (fun _ -> ""); (* not needed *)
1045       dyn_accept_all_conditionals = false;
1046     } in
1047   let goto_bottom =
1048     { Nethttpd_services.dyn_handler = (fun _ -> gotoBottom);
1049       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1050       dyn_uri = None;                 (* not needed *)
1051       dyn_translator = (fun _ -> ""); (* not needed *)
1052       dyn_accept_all_conditionals = false;
1053     } in
1054   let goto_top =
1055     { Nethttpd_services.dyn_handler = (fun _ -> gotoTop);
1056       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1057       dyn_uri = None;                 (* not needed *)
1058       dyn_translator = (fun _ -> ""); (* not needed *)
1059       dyn_accept_all_conditionals = false;
1060     } in
1061   let retrieve =
1062     { Nethttpd_services.dyn_handler = (fun _ -> retrieve);
1063       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1064       dyn_uri = None;                 (* not needed *)
1065       dyn_translator = (fun _ -> ""); (* not needed *)
1066       dyn_accept_all_conditionals = false;
1067     } in
1068   let do_register =
1069     { Nethttpd_services.dyn_handler = (fun _ -> register);
1070       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1071       dyn_uri = None;                 (* not needed *)
1072       dyn_translator = (fun _ -> ""); (* not needed *)
1073       dyn_accept_all_conditionals = false;
1074     } in
1075   let do_login =
1076     { Nethttpd_services.dyn_handler = (fun _ -> login);
1077       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1078       dyn_uri = None;                 (* not needed *)
1079       dyn_translator = (fun _ -> ""); (* not needed *)
1080       dyn_accept_all_conditionals = false;
1081     } in
1082   let do_logout =
1083     { Nethttpd_services.dyn_handler = (fun _ -> logout);
1084       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1085       dyn_uri = None;                 (* not needed *)
1086       dyn_translator = (fun _ -> ""); (* not needed *)
1087       dyn_accept_all_conditionals = false;
1088     } in 
1089   let do_viewlib =
1090     { Nethttpd_services.dyn_handler = (fun _ -> viewLib);
1091       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1092       dyn_uri = None;                 (* not needed *)
1093       dyn_translator = (fun _ -> ""); (* not needed *)
1094       dyn_accept_all_conditionals = false;
1095     } in 
1096   let do_resetlib =
1097     { Nethttpd_services.dyn_handler = (fun _ -> resetLib);
1098       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1099       dyn_uri = None;                 (* not needed *)
1100       dyn_translator = (fun _ -> ""); (* not needed *)
1101       dyn_accept_all_conditionals = false;
1102     } in 
1103   let do_save =
1104     { Nethttpd_services.dyn_handler = (fun _ -> save);
1105       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1106       dyn_uri = None;                 (* not needed *)
1107       dyn_translator = (fun _ -> ""); (* not needed *)
1108       dyn_accept_all_conditionals = false;
1109     } in 
1110   let do_commit =
1111     { Nethttpd_services.dyn_handler = (fun _ -> initiate_commit);
1112       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1113       dyn_uri = None;                 (* not needed *)
1114       dyn_translator = (fun _ -> ""); (* not needed *)
1115       dyn_accept_all_conditionals = false;
1116     } in 
1117   let do_update =
1118     { Nethttpd_services.dyn_handler = (fun _ -> svn_update);
1119       dyn_activation = Nethttpd_services.std_activation `Std_activation_buffered;
1120       dyn_uri = None;                 (* not needed *)
1121       dyn_translator = (fun _ -> ""); (* not needed *)
1122       dyn_accept_all_conditionals = false;
1123     } in 
1124   
1125   
1126   let nethttpd_factory = 
1127     Nethttpd_plex.nethttpd_factory
1128       ~handlers:[ "advance", do_advance
1129                 ; "retract", do_retract
1130                 ; "bottom", goto_bottom
1131                 ; "top", goto_top
1132                 ; "open", retrieve 
1133                 ; "register", do_register
1134                 ; "login", do_login 
1135                 ; "logout", do_logout 
1136                 ; "reset", do_resetlib
1137                 ; "viewlib", do_viewlib
1138                 ; "save", do_save
1139                 ; "commit", do_commit
1140                 ; "update", do_update]
1141       () in
1142   MatitaInit.initialize_all ();
1143   MatitaAuthentication.deserialize ();
1144   Netplex_main.startup
1145     parallelizer
1146     Netplex_log.logger_factories   (* allow all built-in logging styles *)
1147     Netplex_workload.workload_manager_factories (* ... all ways of workload management *)
1148     [ nethttpd_factory ]           (* make this nethttpd available *)
1149     cmdline_cfg
1150 ;;
1151
1152 Sys.set_signal Sys.sigpipe Sys.Signal_ignore;
1153 start();;