X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FsearchEngine%2FsearchEngine.ml;h=abf9eaa36d1d0b26fbeebe473b7c6ebb8670c011;hb=eb621b06f0add650cc5f8bbf111ada840b5287a0;hp=9bc3ef2c95eafc12ac2de858bf0a807040ece0ba;hpb=7cf3cc4096a5c37f2302baefca4388f738da3af3;p=helm.git 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 =