From eb621b06f0add650cc5f8bbf111ada840b5287a0 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Wed, 16 Apr 2003 16:58:14 +0000 Subject: [PATCH] Added preprocess feature to "getpage" method. Using this feature you can fill "@processorURL@" 'holes' in .html javascript pages. --- helm/searchEngine/searchEngine.ml | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/helm/searchEngine/searchEngine.ml b/helm/searchEngine/searchEngine.ml index 9bc3ef2c9..abf9eaa36 100644 --- a/helm/searchEngine/searchEngine.ml +++ b/helm/searchEngine/searchEngine.ml @@ -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 = -- 2.39.2