]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/http_getter/main.ml
- interpreter: the queries are printed before execution
[helm.git] / helm / http_getter / main.ml
index 90f776df359e2ca9a1e1592b6c53293fd7f29a74..eafbc06e6e571c44c75650668dc7d58c9c0fcd04 100644 (file)
@@ -35,7 +35,7 @@ open Http_getter_debugger
 
   (* constants *)
 
-let configuration_file = "http_getter.conf.xml"
+let configuration_file = "/projects/helm/etc/http_getter.conf.xml"
 
 let common_headers = [
   "Cache-Control", "no-cache";
@@ -64,11 +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))
+  | s -> raise (Bad_request ("Invalid /" ^ meth ^ " format: " ^ s))
 
   (* parse "baseuri" format for /ls method, no default value *)
 let parse_ls_uri =
@@ -132,8 +132,19 @@ let return_all_foo_uris doctype uris outchan =
     uris;
   output_string outchan (sprintf "</%s>\n" doctype)
 
-let return_all_xml_uris outchan =
-  return_all_foo_uris "alluris" (Http_getter.getalluris ()) outchan
+let return_all_xml_uris fmt outchan =
+ let uris = Http_getter.getalluris () in
+  match fmt with
+   | Fmt_text ->
+      let buf = Buffer.create 10240 in
+       List.iter (bprintf buf "%s\n") uris ;
+       let body = Buffer.contents buf in
+       Http_daemon.respond
+         ~headers:(("Content-Type", "text/plain") :: common_headers)
+         ~body outchan
+   | Fmt_xml ->
+      return_all_foo_uris "alluris" uris outchan
+  
 let return_all_rdf_uris classs outchan =
   return_all_foo_uris "allrdfuris" (Http_getter.getallrdfuris classs) outchan
 
@@ -253,9 +264,11 @@ let callback (req: Http_types.request) outchan =
           (sprintf "Removed server at position %d<br />\n%s"
             position (HelmLogger.html_of_html_msg log))
           outchan
-    | "/getalluris" -> return_all_xml_uris outchan
+    | "/getalluris" ->
+       return_all_xml_uris (parse_output_format "getalluris" req) outchan
     | "/getallrdfuris" -> return_all_rdf_uris (parse_rdf_class req) outchan
-    | "/ls" -> return_ls (parse_ls_uri req) (parse_output_format req) outchan
+    | "/ls" ->
+       return_ls (parse_ls_uri req) (parse_output_format "ls" req) outchan
     | "/getempty" ->
         Http_daemon.respond ~body:Http_getter_const.empty_xml outchan
     | invalid_request ->