From f11be914623f936bd18b6419479ea9270a17f6e3 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Wed, 27 Nov 2002 13:47:32 +0000 Subject: [PATCH] snapshot Wed, 27 Nov 2002 14:47:14 +0100 --- helm/uwobo/src/ocaml/uwobo.ml | 50 ++++++++++++++-------------- helm/uwobo/src/ocaml/uwobo_logger.ml | 15 ++++++--- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/helm/uwobo/src/ocaml/uwobo.ml b/helm/uwobo/src/ocaml/uwobo.ml index 142fddd7d..625455469 100644 --- a/helm/uwobo/src/ocaml/uwobo.ml +++ b/helm/uwobo/src/ocaml/uwobo.ml @@ -88,6 +88,29 @@ let callback req outchan = keys); Http_daemon.respond ~body:log#asHtml outchan in + let parse_apply_params = (* parse parameters for '/apply' action *) + let is_global_param x = Pcre.pmatch ~pat:"^param(\\.[^.]+){1}$" x in + let is_local_param x = Pcre.pmatch ~pat:"^param(\\.[^.]+){2}$" x in + let is_property x = Pcre.pmatch ~pat:"^prop\\.[^.]+$" x in + List.fold_left + (fun (old_params, old_properties) (name, value) -> + match name with + | name when is_global_param name -> + let name = Pcre.replace ~pat:"^param\\." name in + ((fun x -> (old_params x) @ [name, value]), old_properties) + | name when is_local_param name -> + let pieces = Pcre.extract ~pat:"^param\\.([^.]+)\\.(.*)" name in + let (key, name) = (pieces.(1), pieces.(2)) in + ((function + | x when x = key -> [name, value] @ (old_params x) + | x -> old_params x), + old_properties) + | name when is_property name -> + let name = Pcre.replace ~pat:"^prop\\." name in + (old_params, ((name, value) :: old_properties)) + | _ -> (old_params, old_properties)) + ((fun _ -> []), []) (* no parameters, no properties *) + in try syslogger#log `Debug (sprintf "Received request: %s" req#path); (match req#path with @@ -124,6 +147,7 @@ let callback req outchan = act_on_keys req styles outchan styles#reload (fun () -> styles#reloadAll) "reloading" + | "/apply" -> (let logger = new Uwobo_logger.processingLogger () in let xmluri = req#param "xmluri" in @@ -131,31 +155,7 @@ let callback req outchan = (* notation: "local" parameters are those defined on a per-stylesheet pasis (i.e. param.key.param=value), "global" parameters are those defined for all stylesheets (i.e. param.param=value) *) - let is_global_param x = Pcre.pmatch ~pat:"^param(\\.[^.]+){1}$" x in - let is_local_param x = Pcre.pmatch ~pat:"^param(\\.[^.]+){2}$" x in - let is_property x = Pcre.pmatch ~pat:"^prop\\.[^.]+$" x in - let (params, props) = - List.fold_left - (fun (old_params, old_properties) (name, value) -> - match name with - | name when is_global_param name -> - let name = Pcre.replace ~pat:"^param\\." name in - ((fun x -> (old_params x) @ [name, value]), - old_properties) - | name when is_local_param name -> - let pieces = Pcre.extract ~pat:"^param\\.([^.]+)\\.(.*)" name in - let (key, name) = (pieces.(1), pieces.(2)) in - ((function - | x when x = key -> [name, value] @ (old_params x) - | x -> old_params x), - old_properties) - | name when is_property name -> - let name = Pcre.replace ~pat:"^prop\\." name in - (old_params, ((name, value) :: old_properties)) - | _ -> (old_params, old_properties)) - ((fun _ -> []), []) (* no parameters, no properties *) - req#params - in + let (params, props) = parse_apply_params req#params in syslogger#log `Debug (sprintf "Parsing input document %s ..." xmluri); let input = styles#domImpl#createDocumentFromURI ~uri:xmluri () in let output = diff --git a/helm/uwobo/src/ocaml/uwobo_logger.ml b/helm/uwobo/src/ocaml/uwobo_logger.ml index 2907b0726..0a27ee264 100644 --- a/helm/uwobo/src/ocaml/uwobo_logger.ml +++ b/helm/uwobo/src/ocaml/uwobo_logger.ml @@ -51,18 +51,23 @@ let string_of_priority = function | `Debug -> "DEBUG" class sysLogger ?(level: priority = `Notice) () = - object + object (self) + inherit Uwobo_common.threadSafe initializer print_endline (sprintf "Logger started with level %s" (string_of_priority level)) val level_no = int_of_priority level val mutable enabled = false - method enable = enabled <- true - method disable = enabled <- false + method enable = self#doCritical (lazy (enabled <- true)) + method disable = self#doCritical (lazy (enabled <- false)) method log (prio: priority) msg = - if enabled && (int_of_priority prio <= level_no) then - prerr_endline (sprintf ("%s: %s") (string_of_priority prio) msg) + self#doCritical (lazy ( + if enabled && (int_of_priority prio <= level_no) then + prerr_endline (sprintf ("%s: %s") (string_of_priority prio) msg) + )) end + (** non thread safe, a processingLogger is usually instantied locally for each + thread *) class processingLogger = let html_escape s = (* TODO too naive, use Nethtml.encode instead *) Pcre.replace ~pat:"<" ~templ:"<" -- 2.39.2