]> matita.cs.unibo.it Git - helm.git/commitdiff
Added preprocess feature to "getpage" method. Using this feature you can
authorStefano Zacchiroli <zack@upsilon.cc>
Wed, 16 Apr 2003 16:58:14 +0000 (16:58 +0000)
committerStefano Zacchiroli <zack@upsilon.cc>
Wed, 16 Apr 2003 16:58:14 +0000 (16:58 +0000)
fill "@processorURL@" 'holes' in .html javascript pages.

helm/searchEngine/searchEngine.ml

index 9bc3ef2c95eafc12ac2de858bf0a807040ece0ba..abf9eaa36d1d0b26fbeebe473b7c6ebb8670c011 100644 (file)
@@ -98,11 +98,14 @@ 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) =
+    interpretations_RE, interpretations_labels_RE, results_RE, new_aliases_RE,
+    processorURL_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 "@RESULTS@", Pcre.regexp "@NEW_ALIASES@",
+  Pcre.regexp "@processorURL@")
 let server_and_port_url_RE = Pcre.regexp "^http://([^/]+)/.*$"
 
 let port =
@@ -148,11 +151,27 @@ let callback (req: Http_types.request) outchan =
         (let is_permitted _ = true in
         let remove_fragment uri = Pcre.replace ~pat:"#.*" uri in
         let page = remove_fragment (req#param "url") in
-        match page with
+        let preprocess =
+          (try
+            bool_of_string (req#param "preprocess")
+          with Invalid_argument _ | Http_types.Param_not_found _ -> false)
+        in
+        (match page with
         | page when is_permitted page ->
-            Http_daemon.respond_file
-              ~fname:(sprintf "%s/%s" pages_dir (remove_fragment page)) outchan
-        | page -> Http_daemon.respond_forbidden ~url:page outchan)
+            let fname = sprintf "%s/%s" pages_dir (remove_fragment page) in
+            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) ^
+                    "\n"))
+                fname
+            end else
+              Http_daemon.respond_file ~fname outchan
+        | page -> Http_daemon.respond_forbidden ~url:page outchan))
     | "/ask_uwobo" ->
       let url = req#param "url" in
       let server_and_port =