]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/searchEngine/searchEngine.ml
* "Invalid UWOBO Server" ==> "Untrusted UWOBO Server"
[helm.git] / helm / searchEngine / searchEngine.ml
index abf9eaa36d1d0b26fbeebe473b7c6ebb8670c011..2da581bf7514799962a6f0c0eb60554a5be8abba 100644 (file)
  * http://cs.unibo.it/helm/.
  *)
 
+open Http_types ;;
+
 let debug = true;;
 let debug_print s = if debug then prerr_endline s;;
 Http_common.debug := true;;
 (* Http_common.debug := true;; *)
 
   (** accepted HTTP servers for ask_uwobo method forwarding *)
-let valid_servers = [ "mowgli.cs.unibo.it:58080" ] ;;
+let valid_servers = [ "mowgli.cs.unibo.it:58080" ; "mowgli.cs.unibo.it" ; "localhost:58080" ] ;;
 
 open Printf;;
 
@@ -98,14 +100,12 @@ let fold_file f init fname =
 let iter_file f = fold_file (fun _ line -> f line) ()
 
 let (title_tag_RE, choices_tag_RE, msg_tag_RE, id_to_uris_RE, id_RE,
-    interpretations_RE, interpretations_labels_RE, results_RE, new_aliases_RE,
-    processorURL_RE)
+    interpretations_RE, interpretations_labels_RE, results_RE, new_aliases_RE)
   =
   (Pcre.regexp "@TITLE@", Pcre.regexp "@CHOICES@", Pcre.regexp "@MSG@",
   Pcre.regexp "@ID_TO_URIS@", Pcre.regexp "@ID@",
   Pcre.regexp "@INTERPRETATIONS@", Pcre.regexp "@INTERPRETATIONS_LABELS@",
-  Pcre.regexp "@RESULTS@", Pcre.regexp "@NEW_ALIASES@",
-  Pcre.regexp "@processorURL@")
+  Pcre.regexp "@RESULTS@", Pcre.regexp "@NEW_ALIASES@")
 let server_and_port_url_RE = Pcre.regexp "^http://([^/]+)/.*$"
 
 let port =
@@ -158,19 +158,31 @@ let callback (req: Http_types.request) outchan =
         in
         (match page with
         | page when is_permitted page ->
-            let fname = sprintf "%s/%s" pages_dir (remove_fragment page) in
+            (let fname = sprintf "%s/%s" pages_dir (remove_fragment page) in
+            Http_daemon.send_basic_headers ~code:200 outchan;
+            Http_daemon.send_header "Content-Type" "text/html" outchan;
+            Http_daemon.send_CRLF outchan;
             if preprocess then begin
-              Http_daemon.send_basic_headers ~code:200 outchan;
-              Http_daemon.send_CRLF outchan;
               iter_file
                 (fun line ->
                   output_string outchan
                     ((apply_substs
-                      [processorURL_RE, req#param "processorURL"] line) ^
+                       (List.map
+                         (function (key,value) ->
+                           let key' =
+                            (Pcre.extract ~pat:"param\\.(.*)" key).(1)
+                           in
+                            Pcre.regexp ("@" ^ key' ^ "@"), value
+                         )
+                         (List.filter
+                           (fun (key,_) as p-> Pcre.pmatch ~pat:"^param\\." key)
+                           req#params)
+                       )
+                       line) ^
                     "\n"))
                 fname
             end else
-              Http_daemon.respond_file ~fname outchan
+              Http_daemon.send_file ~src:(FileSrc fname) outchan)
         | page -> Http_daemon.respond_forbidden ~url:page outchan))
     | "/ask_uwobo" ->
       let url = req#param "url" in
@@ -179,11 +191,12 @@ let callback (req: Http_types.request) outchan =
       in
       if List.mem server_and_port valid_servers then
         Http_daemon.respond
+          ~headers:["Content-Type", "text/html"]
           ~body:(Http_client.Convenience.http_get url)
           outchan
       else
         Http_daemon.respond
-          ~body:(pp_error ("Invalid UWOBO server: " ^ server_and_port))
+          ~body:(pp_error ("Untrusted UWOBO server: " ^ server_and_port))
           outchan
     | "/searchPattern" ->
         let term_string = req#param "term" in