From: Luca Padovani Date: Thu, 27 May 2004 09:24:03 +0000 (+0000) Subject: * implemented setparams method for setting multiple parameters at once X-Git-Tag: pre_subst_in_kernel~70 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=a61e244b4cb630f95bed9b1f542df3b5800594b0;p=helm.git * implemented setparams method for setting multiple parameters at once --- diff --git a/helm/uwobo/uwobo.ml b/helm/uwobo/uwobo.ml index 2e4546519..891f08d98 100644 --- a/helm/uwobo/uwobo.ml +++ b/helm/uwobo/uwobo.ml @@ -196,10 +196,11 @@ let short_circuit_grandfather_and_client ~cmd ~cmd_pipe ~res_pipe outchan = let (add_cmd_RE, remove_cmd_RE, reload_cmd_RE, kill_cmd_RE, createprofile_cmd_RE, removeprofile_cmd_RE, setprofileparam_cmd_RE, - setpassword_cmd_RE, setpermission_cmd_RE) = + setparams_cmd_RE, setpassword_cmd_RE, setpermission_cmd_RE) = (Pcre.regexp "^add ", Pcre.regexp "^remove ", Pcre.regexp "^reload ", Pcre.regexp "^kill", Pcre.regexp "^createprofile ", Pcre.regexp "^removeprofile ", - Pcre.regexp "^setprofileparam ", Pcre.regexp "^setpassword ", Pcre.regexp "^setpermission ") + Pcre.regexp "^setprofileparam ", + Pcre.regexp "^setparams ", Pcre.regexp "^setpassword ", Pcre.regexp "^setpermission ") ;; (** raised by child processes when HTTP daemon process have to be restarted *) @@ -418,6 +419,25 @@ let callback ("") outchan + | "/setparams" -> + let is_global_param = Pcre.pmatch ~pat:"^param(\\.[^.]+){1}$" in + let is_local_param = Pcre.pmatch ~pat:"^param(\\.[^.]+){2}$" in + let param_value_list = + List.filter + (fun (param, _) -> (is_global_param param) || (is_local_param param)) + req#params + in + let serialized_param_value_list = + List.map + (fun (param, value) -> (Pcre.replace ~pat:"^param\\." param) ^ "=" ^ value) + param_value_list + in + let cmd = sprintf "setparams %s,%s,%s" + (req#param "id") + (string_of_param_option req "password") + (String.concat "," serialized_param_value_list) + in + short_circuit_grandfather_and_client ~cmd ~cmd_pipe ~res_pipe outchan | "/getparam" -> let pid = req#param "id" in let password = try Some (req#param "password") with _ -> None in @@ -672,6 +692,27 @@ let main () = save_configuration () ; output_string res_pipe "Done" ; raise Restart_HTTP_daemon + | line when Pcre.pmatch ~rex:setparams_cmd_RE line -> (* /setparams *) + stop_http_daemon () ; + let pid, password, pv_list = + match Pcre.split ~pat:"," (Pcre.replace ~rex:setparams_cmd_RE line) with + pid::password::pv_list -> + pid, (string_option_of_string password), + (List.map + (fun pv -> + match Pcre.split ~pat:"=" pv with + [key] -> (key, None) + | [key; value] -> (key, Some value) + | _ -> assert false) + pv_list) + | _ -> assert false + in + List.iter + (fun (key, value) -> Uwobo_profiles.set_param pid ?password ~key ~value ()) + pv_list ; + save_configuration () ; + output_string res_pipe "Done" ; + raise Restart_HTTP_daemon | line when Pcre.pmatch ~rex:setprofileparam_cmd_RE line -> (* /setprofileparam *) stop_http_daemon (); let pid, password, key, value =