X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=helm%2Fhttp_getter%2Fhttp_getter.ml;h=b5cfa47d9564561c09783dfb85b702ae280f7605;hb=85ccebb566c36671ca753debe09e6dd5c9dd0df7;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..b5cfa47d9 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,18 +51,23 @@ 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 @@ -132,8 +138,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 +168,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 +207,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 +241,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 +259,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 +283,22 @@ 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)#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 *) | None -> ()); (match rdf_index with | Some rdf_index -> @@ -327,20 +339,14 @@ let callback (req: Http_types.request) outchan = 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" ->