open Http_getter_common
open Http_getter_misc
-open Http_getter_debugger
open Http_getter_types
exception Not_implemented of string
| uri -> raise (Unresolvable_URI uri)
let update_from_server logger server_url = (* use global maps *)
- debug_print ("Updating information from " ^ server_url);
+ Http_getter_logger.log ("Updating information from " ^ server_url);
let xml_url_of_uri = function
(* TODO missing sanity checks on server_url, e.g. it can contains $1 *)
| uri when (Pcre.pmatch ~rex:heading_cic_RE uri) ->
http_get (server_url ^ "/" ^ (Lazy.force Http_getter_env.xsl_index)))
in
if (xml_index = None && rdf_index = None && xsl_index = None) then
- debug_print (sprintf "Warning: useless server %s" server_url);
+ Http_getter_logger.log (sprintf "Warning: useless server %s" server_url);
(match xml_index with
| Some xml_index ->
logger (`T "- Updating XML db ...");
logger (`T "All done");
logger `BR
| None -> ());
- debug_print "done with this server"
+ Http_getter_logger.log "done with this server"
let update_from_all_servers logger () = (* use global maps *)
clear_maps ();
(* deliver resolve request to http_getter *)
let doc = ClientHTTP.get (sprintf "%sresolve?uri=%s" (getter_url ()) uri) in
let res = ref Unknown in
- Pxp_yacc.process_entity Pxp_yacc.default_config (`Entry_content [])
- (Pxp_yacc.create_entity_manager ~is_document:true Pxp_yacc.default_config
- (Pxp_yacc.from_string doc))
+ Pxp_ev_parser.process_entity PxpHelmConf.pxp_config (`Entry_content [])
+ (Pxp_ev_parser.create_entity_manager ~is_document:true
+ PxpHelmConf.pxp_config (Pxp_yacc.from_string doc))
(function
- | Pxp_yacc.E_start_tag ("url",["value",url],_) -> res := Resolved url
- | Pxp_yacc.E_start_tag ("unresolved",[],_) ->
+ | Pxp_types.E_start_tag ("url",["value",url],_,_) -> res := Resolved url
+ | Pxp_types.E_start_tag ("unresolvable",[],_,_) ->
res := Exception (Unresolvable_URI uri)
- | Pxp_yacc.E_start_tag _ -> res := Exception UnexpectedGetterOutput
+ | Pxp_types.E_start_tag ("not_found",[],_,_) ->
+ res := Exception (Key_not_found uri)
+ | Pxp_types.E_start_tag (x,_,_,_) ->
+ res := Exception UnexpectedGetterOutput
| _ -> ());
match !res with
| Unknown -> raise UnexpectedGetterOutput
let register_remote ~uri ~url =
ClientHTTP.send (sprintf "%sregister?uri=%s&url=%s" (getter_url ()) uri url)
-let register_remote ~uri ~url =
- ClientHTTP.send (sprintf "%sregister?uri=%s&url=%s" (getter_url ()) uri url)
+let unregister_remote uri =
+ ClientHTTP.send (sprintf "%sunregister?uri=%s" (getter_url ()) uri)
let update_remote logger () =
let answer = ClientHTTP.get (getter_url () ^ "update") in
if remote () then
resolve_remote uri
else
- try
- (map_of_uri uri)#resolve uri
- with Http_getter_map.Key_not_found _ -> raise (Unresolvable_URI uri)
-
- (* Warning: this fail if uri is already registered *)
+ (map_of_uri uri)#resolve uri
+
let register ~uri ~url =
if remote () then
register_remote ~uri ~url
else
(map_of_uri uri)#add uri url
+let unregister uri =
+ if remote () then
+ unregister_remote uri
+ else
+ try
+ (map_of_uri uri)#remove uri
+ with Key_not_found _ -> ()
+
let update ?(logger = fun _ -> ()) () =
if remote () then
update_remote logger ()
if remote () then
getxml_remote ~format ~patch_dtd uri
else begin
+ Http_getter_logger.log ~level:2 ("getxml: " ^ uri);
let url = resolve uri in
+ Http_getter_logger.log ~level:2 ("resolved_uri: " ^ url) ;
let (fname, outchan) = temp_file_of_uri uri in
Http_getter_cache.respond_xml ~via_http:false ~enc:format ~patch:patch_dtd
~uri ~url outchan;
if remote () then
getxslt_remote ~patch_dtd uri
else begin
+
let url = resolve uri in
let (fname, outchan) = temp_file_of_uri uri in
Http_getter_cache.respond_xsl ~via_http:false ~url ~patch:patch_dtd outchan;
getalluris_remote ()
else
let filter uri =
- (Pcre.pmatch ~rex:heading_cic_RE uri) &&
- not (Pcre.pmatch ~rex:trailing_types_RE uri)
+ (Pcre.pmatch ~rex:heading_cic_RE uri)
+(* && not (Pcre.pmatch ~rex:trailing_types_RE uri) *)
in
return_uris (Lazy.force cic_map) filter
"^([^.]*\\.[^.]*)((\\.body)|(\\.proof_tree)|(\\.types))?(\\.ann)?$"
in
let (types_RE, types_ann_RE, body_RE, body_ann_RE,
- proof_tree_RE, proof_tree_ann_RE) =
+ proof_tree_RE, proof_tree_ann_RE, trailing_slash_RE, theory_RE) =
(Pcre.regexp "\\.types$", Pcre.regexp "\\.types\\.ann$",
Pcre.regexp "\\.body$", Pcre.regexp "\\.body\\.ann$",
- Pcre.regexp "\\.proof_tree$", Pcre.regexp "\\.proof_tree\\.ann$")
+ Pcre.regexp "\\.proof_tree$", Pcre.regexp "\\.proof_tree\\.ann$",
+ Pcre.regexp "/$", Pcre.regexp "\\.theory$")
in
let (slash_RE, til_slash_RE, no_slashes_RE) =
(Pcre.regexp "/", Pcre.regexp "^.*/", Pcre.regexp "^[^/]*$")
in
- fun lsuri ->
+ fun regexp ->
if remote () then
- ls_remote lsuri
+ ls_remote regexp
else begin
- let pat =
- "^" ^
- (match lsuri with Cic p -> ("cic:" ^ p) | Theory p -> ("theory:" ^ p))
- in
- let (dir_RE, obj_RE) =
- (Pcre.regexp (pat ^ "/"), Pcre.regexp (pat ^ "(\\.|$)"))
+ let looking_for_dir = Pcre.pmatch ~rex:trailing_slash_RE regexp in
+ let pat = Pcre.replace ~rex:trailing_slash_RE ("^" ^ regexp) in
+ let (dir_RE, dir_RE2, obj_RE, orig_theory_RE) =
+ Pcre.regexp (pat ^ "/"), Pcre.regexp (pat ^ "/[^/]*"),
+ Pcre.regexp (pat ^ "(\\.|$)"), Pcre.regexp (pat ^ ".theory$")
in
let dirs = ref StringSet.empty in
let objs = Hashtbl.create 17 in
in
Hashtbl.replace objs basepart (oldflags ++ newflags)
in
+ (* Variables used in backward compatibility code to map
+ theory:/path/t.theory into theory:/path/t/index.theory
+ when cic:/path/t/ exists *)
+ let the_candidate_for_remapping =
+ (* CSC: Here I am making a strong assumption: the pattern
+ can be only of the form [^:]*:/path where path is
+ NOT a regular expression *)
+ "theory:" ^ Pcre.replace ~rex:(Pcre.regexp "[^:]*:") pat
+ in
+ let index_not_generated_yet = ref true in
+ let valid_candidates = ref [] in
+ let candidates_found = ref [] in
(Lazy.force cic_map) # iter
(* BLEARGH Dbm module lacks support for fold-like functions *)
(fun key _ ->
match key with
- | uri when Pcre.pmatch ~rex:dir_RE uri -> (* directory hit *)
+ | uri when looking_for_dir && Pcre.pmatch ~rex:dir_RE uri ->
+ (* directory hit *)
let localpart = Pcre.replace ~rex:dir_RE uri in
if Pcre.pmatch ~rex:no_slashes_RE localpart then
- store_obj localpart
+ begin
+ (* Backward compatibility code to map
+ theory:/path/t.theory into theory:/path/t/index.theory
+ when cic:/path/t/ exists *)
+ if Pcre.pmatch ~rex:theory_RE localpart then
+ candidates_found := (uri,localpart) :: !candidates_found
+ else
+ store_obj localpart
+
+ end
else
- store_dir localpart
- | uri when Pcre.pmatch ~rex:obj_RE uri -> (* file hit *)
+ begin
+ store_dir localpart ;
+ if String.sub uri 0 3 = "cic" then
+ let dir_found = ref "" in
+ let _ =
+ Pcre.substitute_first ~rex:dir_RE2
+ ~subst:(fun s -> dir_found := s; "") uri in
+ let dir =
+ "theory" ^ String.sub !dir_found 3
+ (String.length !dir_found - 3) ^ ".theory" in
+ if not (List.mem dir !valid_candidates) then
+ valid_candidates := dir::!valid_candidates
+ end
+ | uri when (not looking_for_dir) && Pcre.pmatch ~rex:obj_RE uri ->
+ (* file hit *)
store_obj (Pcre.replace ~rex:til_slash_RE uri)
- | uri -> () (* miss *));
+ | uri -> (* miss *)
+ if !index_not_generated_yet &&
+ Pcre.pmatch ~rex:orig_theory_RE uri
+ then
+ (index_not_generated_yet := false ;
+ store_obj "index.theory"));
+ List.iter
+ (fun (uri,localpart) ->
+ if not (List.mem uri !valid_candidates) then
+ store_obj localpart
+ ) !candidates_found ;
let ls_items = ref [] in
StringSet.iter (fun dir -> ls_items := Ls_section dir :: !ls_items) !dirs;
Http_getter_misc.hashtbl_sorted_iter
let getxml' uri = getxml (UriManager.string_of_uri uri)
let resolve' uri = resolve (UriManager.string_of_uri uri)
let register' uri url = register ~uri:(UriManager.string_of_uri uri) ~url
+let init () =
+ Http_getter_logger.set_log_level
+ (Helm_registry.get_opt_default Helm_registry.get_int 1 "getter.log_level");
+ Http_getter_logger.set_log_file
+ (Helm_registry.get_opt Helm_registry.get_string "getter.log_file");
+ Http_getter_env.reload ()