]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/graphs/tools/drawGraph.ml
ocaml 3.09 transition
[helm.git] / helm / graphs / tools / drawGraph.ml
index 0714383190fbc4f75b4db18abf063ee1f25eaf59..c17902fbc551dd85e92f0a4a5315fee500d978f7 100644 (file)
@@ -28,29 +28,17 @@ open Printf;;
 let debug = true;;
 let debug_print s = if debug then prerr_endline s;;
 
+let configuration_file = "/projects/helm/etc/drawGraph.conf.xml";;
+
 let daemon_name = "Draw Graph";;
-let default_port = 48083;;
-let default_dir = "/projects/helm/graphs/tools";;
-let port_env_var = "DRAW_GRAPH_PORT";;
-let dir_env_var = "DRAW_GRAPH_DIR";;
 
 let wget url fname =
   prerr_endline (sprintf "DEBUG: wgetting url '%s'" url);
   let oc = open_out fname in
-  Http_client.http_get_iter (output_string oc) url;
+  Http_user_agent.get_iter (output_string oc) url;
   close_out oc
 ;;
 
-let port =
-  try
-    int_of_string (Sys.getenv port_env_var)
-  with
-  | Not_found -> default_port
-  | Failure "int_of_string" ->
-      prerr_endline "Warning: invalid port, reverting to default";
-      default_port
-in
-let dir = try Sys.getenv dir_env_var with Not_found -> default_dir in
 let errmsg =
   sprintf
 "<html>
@@ -58,7 +46,7 @@ let errmsg =
   <title>Graph: error</title>
  </head>
  <body>
-  <h1>Error occured while drawing graph!<br />Please report the occured problem</h1>
+  <h1>Error occurred while drawing graph!<br />Please report the occured problem</h1>
   <h2>%s</h2>
  </body>
 </html>"
@@ -94,15 +82,17 @@ let callback (req: Http_types.request) outchan =
         ignore (Unix.system (
           sprintf "make PID=%s clean_tmp; rm -f prova0.%s.dot" pid pid))
     | invalid_request ->
-        Http_daemon.respond_error ~status:(`Client_error `Bad_request) outchan)
+        Http_daemon.respond_error ~code:(`Status (`Client_error `Bad_request))
+          outchan)
   with
   | Http_types.Param_not_found attr_name ->
-      Http_daemon.respond_error
-        ~status:(`Client_error `Bad_request)
+      Http_daemon.respond_error ~code:(`Status (`Client_error `Bad_request))
         ~body:(sprintf "Parameter '%s' is missing" attr_name)
         outchan
 in
-Sys.chdir dir;
+Helm_registry.load_from configuration_file;
+let port = Helm_registry.get_int "draw_graph.port" in
+Sys.chdir (Helm_registry.get "draw_graph.dir");
 printf "%s started and listening on port %d\n" daemon_name port;
 printf "current directory is %s\n" (Sys.getcwd ());
 flush stdout;