X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=inline;f=helm%2Fhttp_getter%2Fmain.ml;h=f65e991b7c263fbd7a714e3efbd755684080a3c4;hb=8c578ae2acfb32b39610aebbd4baab3a31775a9f;hp=90f776df359e2ca9a1e1592b6c53293fd7f29a74;hpb=c10721e8910fc80786cf668d0f843e3da2598a21;p=helm.git diff --git a/helm/http_getter/main.ml b/helm/http_getter/main.ml index 90f776df3..f65e991b7 100644 --- a/helm/http_getter/main.ml +++ b/helm/http_getter/main.ml @@ -29,13 +29,13 @@ open Printf open Http_getter_common +open Http_getter_const open Http_getter_misc open Http_getter_types -open Http_getter_debugger (* constants *) -let configuration_file = "http_getter.conf.xml" +let configuration_file = BuildTimeOpts.conffile let common_headers = [ "Cache-Control", "no-cache"; @@ -45,14 +45,14 @@ let common_headers = [ (* HTTP queries argument parsing *) - (* parse encoding ("format" parameter), default is Enc_normal *) + (* parse encoding ("format" parameter), default is `Normal *) let parse_enc (req: Http_types.request) = try (match req#param "format" with - | "normal" -> Enc_normal - | "gz" -> Enc_gzipped + | "normal" -> `Normal + | "gz" -> `Gzipped | s -> raise (Bad_request ("Invalid format: " ^ s))) - with Http_types.Param_not_found _ -> Enc_normal + with Http_types.Param_not_found _ -> `Normal (* parse "patch_dtd" parameter, default is true *) let parse_patch (req: Http_types.request) = @@ -64,31 +64,11 @@ let parse_patch (req: Http_types.request) = with Http_types.Param_not_found _ -> true (* parse output format ("format" parameter), no default value *) -let parse_output_format (req: Http_types.request) = +let parse_output_format meth (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 (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 (Bad_request ("Invalid /ls baseuri: " ^ uri)) - in - fun (req: Http_types.request) -> - let baseuri = req#param "baseuri" in - 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 + | s when String.lowercase s = "txt" -> `Text + | s when String.lowercase s = "xml" -> `Xml + | s -> raise (Bad_request ("Invalid /" ^ meth ^ " format: " ^ s)) (* parse "position" argument, default is 0 *) let parse_position (req: Http_types.request) = @@ -110,8 +90,41 @@ let parse_rdf_class (req: Http_types.request) = | "backward" -> `Backward | c -> raise (Bad_request ("Invalid RDF class: " ^ c)) +let html_tag ?exn () = + let xml_decl = "\n" in + match exn with + | Some exn -> + sprintf + "%s\n" + xml_decl xhtml_ns helm_ns exn + | None -> + sprintf "%s\n" + xml_decl xhtml_ns helm_ns + +let mk_return_fun pp_fun contype msg outchan = + Http_daemon.respond + ~body:(pp_fun msg) ~headers:["Content-Type", contype] outchan +let pp_msg s = sprintf "%s
%s" (html_tag ()) s +let null_pp s = s +let return_html_error exn = + let pp_error s = + sprintf "%s\nHttp Getter error: %s" + (html_tag ~exn ()) s + in + mk_return_fun pp_error "text/xml" +let return_html_internal_error exn = + let pp_internal_error s = + sprintf "%s\nHttp Getter Internal error: %s