X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matitaB%2Fmatita%2FmatitaAuthentication.ml;h=7ae548058abea4efed9272e96645776ec3b03cc4;hb=d6f1365a9f1cb48af8a7b32cf074373466779e7e;hp=a183bc42033d8ed14ef487c86a79e68043ba978b;hpb=5952e8ed7a1deffe8766f4ffb4cd6f97ba803d06;p=helm.git diff --git a/matitaB/matita/matitaAuthentication.ml b/matitaB/matita/matitaAuthentication.ml index a183bc420..7ae548058 100644 --- a/matitaB/matita/matitaAuthentication.ml +++ b/matitaB/matita/matitaAuthentication.ml @@ -25,6 +25,8 @@ type session_id = Uuidm.t +type matita_file = MatitaFilesystem.matita_flag * string + (* user table: user id, (password, optional session id) *) type user = string * (string * session_id option) @@ -41,6 +43,8 @@ let lookup_user uid = List.assoc uid !user_tbl let user_of_session sid = let res,_,_ = List.assoc sid !session_tbl in res +let get_users () = List.map fst !user_tbl + let create_session uid = let status = new MatitaEngine.status (Some uid) "cic:/matita" in let history = [status] in @@ -104,20 +108,57 @@ let serialize () = ;; let deserialize () = - let utbl_ch = open_in (config_path () ^ "/usertable.dump") in - user_tbl := Marshal.from_channel utbl_ch; - close_in utbl_ch; + (try + let utbl_ch = open_in (config_path () ^ "/usertable.dump") in + user_tbl := Marshal.from_channel utbl_ch; + close_in utbl_ch; + with + | Sys_error _ -> + user_tbl := []; serialize()); (* old_sessions are now invalid *) session_tbl := []; ;; +let write_ft uid ft = + let ft_ch = open_out (config_path () ^ "/ft_" ^ uid ^ ".dump") in + Marshal.to_channel ft_ch ft []; + close_out ft_ch; +;; + +let read_ft uid = + try + let ft_ch = open_in (config_path () ^ "/ft_" ^ uid ^ ".dump") in + let ft = Marshal.from_channel ft_ch in + close_in ft_ch; + ft + with + | Sys_error _ -> + (* this is an error, we should rebuild the table by a diff of + the directory listing and svn stat *) + [] +;; + +let set_file_flag uid files_flags = + let ft = read_ft uid in + let files = List.map fst files_flags in + let ft = List.filter (fun (x,_) -> not (List.mem x files)) ft in + let ft' = List.fold_left (fun acc (filename,flag) -> + let filename = MatitaFilesystem.normalize_qfn filename in + try + (filename,HExtlib.unopt flag)::acc + with Failure _ -> acc) [] files_flags + in + write_ft uid (ft'@ft) +;; + let add_user uid pw = try let _ = lookup_user uid in raise (UsernameCollision uid) with Not_found -> - MatitaFilesystem.checkout uid; + let ft = MatitaFilesystem.checkout uid in user_tbl := (uid,(pw,None))::!user_tbl; + write_ft uid ft; serialize () ;;