(* 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
| 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 (++) (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
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
in
Http_daemon.respond
~headers:(("Content-Type", "text/plain") :: common_headers)
- ~body outchan
+ ~body outchan
| Fmt_xml ->
let body =
sprintf
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 *)
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 *)
| Some xml_index ->
(log := !log ^ "Updating XML db ...<br />\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 ^ "<br />\n")
- with Http_getter_invalid_URI uri ->
- log := !log ^ "Ignoring invalid XML URI: " ^ uri ^ "<br />\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 ^ "'<br />\n")
+ with Http_getter_invalid_URI uri ->
+ log := !log ^ "Ignoring invalid XML URI: '" ^ uri ^ "'<br />\n")
+ (Pcre.split ~rex:index_sep_RE xml_index)) (* xml_index lines *)
| None -> ());
(match rdf_index with
| Some rdf_index ->
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" ->