X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fhttp_getter%2Fhttp_getter.ml;h=0792d30b52a8a58ada989efe6570d3f01ab30dcd;hb=f9fb6aea5ebbb04018ce2b9e4a395339b58d8ff9;hp=40f38dc4eec38598258f23e0fbb4a3f817689af0;hpb=a933ca25f485ac27e662444c250b8773c73b2755;p=helm.git
diff --git a/helm/http_getter/http_getter.ml b/helm/http_getter/http_getter.ml
index 40f38dc4e..0792d30b5 100644
--- a/helm/http_getter/http_getter.ml
+++ b/helm/http_getter/http_getter.ml
@@ -42,6 +42,7 @@ let common_headers = [
(* HTTP queries argument parsing *)
+ (* parse encoding ("format" parameter), default is Enc_normal *)
let parse_enc (req: Http_types.request) =
try
(match req#param "format" with
@@ -50,31 +51,41 @@ let parse_enc (req: Http_types.request) =
| s -> raise (Http_getter_bad_request ("Invalid format: " ^ s)))
with Http_types.Param_not_found _ -> Enc_normal
;;
+ (* parse "patch_dtd" parameter, default is true *)
let parse_patch (req: Http_types.request) =
- match req#param "patch_dtd" with
- | s when String.lowercase s = "yes" -> true
- | s when String.lowercase s = "no" -> false
- | s -> raise (Http_getter_bad_request ("Invalid patch_dtd value: " ^ s))
+ try
+ (match req#param "patch_dtd" with
+ | s when String.lowercase s = "yes" -> true
+ | s when String.lowercase s = "no" -> false
+ | s -> raise (Http_getter_bad_request ("Invalid patch_dtd value: " ^ s)))
+ with Http_types.Param_not_found _ -> true
;;
+ (* parse output format ("format" parameter), no default value *)
let parse_output_format (req: Http_types.request) =
match req#param "format" with
| s when String.lowercase s = "txt" -> Fmt_text
| s when String.lowercase s = "xml" -> Fmt_xml
| s -> raise (Http_getter_bad_request ("Invalid /ls format: " ^ s))
;;
+ (* parse "baseuri" format for /ls method, no default value *)
let parse_ls_uri =
let parse_ls_RE = Pcre.regexp "^(\\w+):(.*)$" in
let trailing_slash_RE = Pcre.regexp "/+$" in
+ let wrong_uri uri =
+ raise (Http_getter_bad_request ("Invalid /ls baseuri: " ^ uri))
+ in
fun (req: Http_types.request) ->
let baseuri = req#param "baseuri" in
- let subs =
- Pcre.extract ~rex:parse_ls_RE
- (Pcre.replace ~rex:trailing_slash_RE baseuri)
- in
- match (subs.(1), subs.(2)) with
- | "cic", uri -> Cic uri
- | "theory", uri -> Theory uri
- | _ -> raise (Http_getter_bad_request ("Invalid /ls baseuri: " ^ baseuri))
+ try
+ let subs =
+ Pcre.extract ~rex:parse_ls_RE
+ (Pcre.replace ~rex:trailing_slash_RE baseuri)
+ in
+ (match (subs.(1), subs.(2)) with
+ | "cic", uri -> Cic uri
+ | "theory", uri -> Theory uri
+ | _ -> wrong_uri baseuri)
+ with Not_found -> wrong_uri baseuri
;;
(* global maps, shared by all threads *)
@@ -99,7 +110,10 @@ let resolve uri =
with Http_getter_map.Key_not_found _ ->
raise (Http_getter_unresolvable_URI uri)
in
-let register uri = (map_of_uri uri )#add uri in
+let register uri =
+ (* Warning: this fail if uri is already registered *)
+ (map_of_uri uri)#add uri
+in
let return_all_foo_uris map doctype filter outchan =
(** return all URIs contained in 'map' which satisfy predicate 'filter'; URIs
are written in an XMLish format ('doctype' is the XML doctype) onto 'outchan'
@@ -132,8 +146,8 @@ let return_ls =
let (++) (oldann, oldtypes, oldbody) (newann, newtypes, newbody) =
((if newann > oldann then newann else oldann),
(if newtypes > oldtypes then newtypes else oldtypes),
- (if newbody > oldbody then newbody else oldbody))
- in
+ (if newbody > oldbody then newbody else oldbody))
+ in
let basepart_RE =
Pcre.regexp "^([^.]*\\.[^.]*)((\\.body)|(\\.types))?(\\.ann)?"
in
@@ -162,7 +176,7 @@ let return_ls =
let oldflags =
try
Hashtbl.find objs basepart
- with Not_found -> (false, No, No) (* no ann, no types no body *)
+ with Not_found -> (false, No, No) (* no ann, no types, no body *)
in
let newflags =
match o with
@@ -201,7 +215,7 @@ let return_ls =
in
Http_daemon.respond
~headers:(("Content-Type", "text/plain") :: common_headers)
- ~body outchan
+ ~body outchan
| Fmt_xml ->
let body =
sprintf
@@ -235,13 +249,14 @@ let return_ls =
in
Http_daemon.respond
~headers:(("Content-Type", "text/xml") :: common_headers)
- ~body outchan
+ ~body outchan
in
let (index_line_sep_RE, index_sep_RE, trailing_types_RE,
- heading_cic_RE, heading_theory_RE,
+ heading_cic_RE, heading_theory_RE, heading_nuprl_RE,
heading_rdf_cic_RE, heading_rdf_theory_RE) =
- (Pcre.regexp "[ \t]+", Pcre.regexp "\n+", Pcre.regexp "\\.types$",
- Pcre.regexp "^cic:", Pcre.regexp "^theory:",
+ (Pcre.regexp "[ \t]+", Pcre.regexp "\r\n|\r|\n",
+ Pcre.regexp "\\.types$",
+ Pcre.regexp "^cic:", Pcre.regexp "^theory:", Pcre.regexp "^nuprl:",
Pcre.regexp "^helm:rdf.*//cic:", Pcre.regexp "^helm:rdf.*//theory:")
in
let update_from_server logmsg server_url = (* use global maps *)
@@ -252,6 +267,8 @@ let update_from_server logmsg server_url = (* use global maps *)
Pcre.replace ~rex:heading_cic_RE ~templ:server_url uri
| uri when (Pcre.pmatch ~rex:heading_theory_RE uri) ->
Pcre.replace ~rex:heading_theory_RE ~templ:server_url uri
+ | uri when (Pcre.pmatch ~rex:heading_nuprl_RE uri) ->
+ Pcre.replace ~rex:heading_nuprl_RE ~templ:server_url uri
| uri -> raise (Http_getter_invalid_URI uri)
in
let rdf_url_of_uri = function (* TODO as above *)
@@ -274,19 +291,24 @@ let update_from_server logmsg server_url = (* use global maps *)
| Some xml_index ->
(log := !log ^ "Updating XML db ...
\n";
List.iter
- (fun l ->
- try
- (match Pcre.split ~rex:index_line_sep_RE l with
- | [uri; "gz"] ->
- assert (is_cic_uri uri || is_nuprl_uri uri) ;
- (map_of_uri uri)#add uri ((xml_url_of_uri uri) ^ ".xml.gz")
- | [uri] ->
- assert (is_cic_uri uri || is_nuprl_uri uri) ;
- (map_of_uri uri)#add uri ((xml_url_of_uri uri) ^ ".xml")
- | _ -> log := !log ^ "Ignoring invalid line: " ^ l ^ "
\n")
- with Http_getter_invalid_URI uri ->
- log := !log ^ "Ignoring invalid XML URI: " ^ uri ^ "
\n")
- (Pcre.split ~rex:index_sep_RE xml_index)) (* xml_index lines *)
+ (function
+ | l when is_blank_line l -> () (* skip blank and commented lines *)
+ | l ->
+ try
+ (match Pcre.split ~rex:index_line_sep_RE l with
+ | [uri; "gz"] ->
+ assert (is_cic_uri uri || is_nuprl_uri uri) ;
+ (map_of_uri uri)#replace
+ uri ((xml_url_of_uri uri) ^ ".xml.gz")
+ | [uri] ->
+ assert (is_cic_uri uri || is_nuprl_uri uri) ;
+ (map_of_uri uri)#replace
+ uri ((xml_url_of_uri uri) ^ ".xml")
+ | _ ->
+ log := !log ^ "Ignoring invalid line: '" ^ l ^ "'
\n")
+ with Http_getter_invalid_URI uri ->
+ log := !log ^ "Ignoring invalid XML URI: '" ^ uri ^ "'
\n")
+ (Pcre.split ~rex:index_sep_RE xml_index)) (* xml_index lines *)
| None -> ());
(match rdf_index with
| Some rdf_index ->
@@ -295,8 +317,9 @@ let update_from_server logmsg server_url = (* use global maps *)
(fun l ->
try
(match Pcre.split ~rex:index_line_sep_RE l with
- | [uri; "gz"] -> rdf_map#add uri ((rdf_url_of_uri uri) ^ ".xml.gz")
- | [uri] -> rdf_map#add uri ((rdf_url_of_uri uri) ^ ".xml")
+ | [uri; "gz"] ->
+ rdf_map#replace uri ((rdf_url_of_uri uri) ^ ".xml.gz")
+ | [uri] -> rdf_map#replace uri ((rdf_url_of_uri uri) ^ ".xml")
| _ -> log := !log ^ "Ignoring invalid line: " ^ l ^ "
\n")
with Http_getter_invalid_URI uri ->
log := !log ^ "Ignoring invalid RDF URI: " ^ uri ^ "
\n")
@@ -306,13 +329,25 @@ let update_from_server logmsg server_url = (* use global maps *)
| Some xsl_index ->
(log := !log ^ "Updating XSLT db ...
\n";
List.iter
- (fun l -> xsl_map#add l (server_url ^ "/" ^ l))
+ (fun l -> xsl_map#replace l (server_url ^ "/" ^ l))
(Pcre.split ~rex:index_sep_RE xsl_index);
log := !log ^ "All done!
\n")
| None -> ());
debug_print "done with this server";
!log
in
+let update_from_all_servers () = (* use global maps *)
+ cic_map#clear; nuprl_map#clear; rdf_map#clear; xsl_map#clear;
+ let log =
+ List.fold_left
+ update_from_server
+ "" (* initial logmsg: empty *)
+ (* reverse order: 1st server is the most important one *)
+ (List.rev !Http_getter_env.servers)
+ in
+ cic_map#sync; nuprl_map#sync; rdf_map#sync; xsl_map#sync;
+ log
+in
(* thread action *)
@@ -321,26 +356,23 @@ let callback (req: Http_types.request) outchan =
debug_print ("Connection from " ^ req#clientAddr);
debug_print ("Received request: " ^ req#path);
(match req#path with
- | "/help" -> return_html_raw Http_getter_const.usage_string outchan
+ | "/help" ->
+ return_html_raw
+ (Http_getter_const.usage_string (Http_getter_env.env_to_string ()))
+ outchan
| "/getxml" | "/getxslt" | "/getdtd" | "/resolve" | "/register" ->
(let uri = req#param "uri" in (* common parameter *)
match req#path with
| "/getxml" ->
let enc = parse_enc req in
- let patch =
- try parse_patch req with Http_types.Param_not_found _ -> true
- in
+ let patch = parse_patch req in
Http_getter_cache.respond_xml
~url:(resolve uri) ~uri ~enc ~patch outchan
| "/getxslt" ->
- let patch =
- try parse_patch req with Http_types.Param_not_found _ -> true
- in
+ let patch = parse_patch req in
Http_getter_cache.respond_xsl ~url:(resolve uri) ~patch outchan
| "/getdtd" ->
- let patch =
- try parse_patch req with Http_types.Param_not_found _ -> true
- in
+ let patch = parse_patch req in
Http_getter_cache.respond_dtd
~patch ~url:(Http_getter_env.dtd_dir ^ "/" ^ uri) outchan
| "/resolve" ->
@@ -356,17 +388,74 @@ let callback (req: Http_types.request) outchan =
return_html_msg "Register done" outchan
| _ -> assert false)
| "/update" ->
- (Http_getter_env.reload (); (* reload servers list from servers file *)
- cic_map#clear; nuprl_map#clear; rdf_map#clear; xsl_map#clear;
- let log =
- List.fold_left
- update_from_server
- "" (* initial logmsg: empty *)
- (* reverse order: 1st server is the most important one *)
- (List.rev !Http_getter_env.servers)
+ Http_getter_env.reload (); (* reload servers list from servers file *)
+ let log = update_from_all_servers () in
+ return_html_msg log outchan
+ | "/list_servers" ->
+ return_html_raw
+ (sprintf "