]> matita.cs.unibo.it Git - helm.git/commitdiff
* implemented setparams method for setting multiple parameters at once
authorLuca Padovani <luca.padovani@unito.it>
Thu, 27 May 2004 09:24:03 +0000 (09:24 +0000)
committerLuca Padovani <luca.padovani@unito.it>
Thu, 27 May 2004 09:24:03 +0000 (09:24 +0000)
helm/uwobo/uwobo.ml

index 2e454651906de8b5fcc208d8fb2cf6ef506ed986..891f08d9808fbc02039c90fc07cfc4609372e91b 100644 (file)
@@ -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
         ("<html><body><ul>" ^
          String.concat "" (List.map (fun k,v -> "<li><key>" ^ k ^ "</key> = <value>" ^ v  ^ "</value></li>") res) ^
          "</ul></body></html>") 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 =