2 (* Copyright (C) 2002, HELM Team.
4 * This file is part of HELM, an Hypertextual, Electronic
5 * Library of Mathematics, developed at the Computer Science
6 * Department, University of Bologna, Italy.
8 * HELM is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * HELM is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with HELM; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 * For details, see the HELM World-Wide-Web page,
24 * http://cs.unibo.it/helm/.
29 let daemon_name = "Draw Graph";;
30 let default_port = 48083;;
31 let port_env_var = "DRAW_GRAPH_PORT";;
34 let data = Http_client.Convenience.http_get url in
35 let oc = open_out fname in
36 output_string oc data;
42 int_of_string (Sys.getenv port_env_var)
44 | Not_found -> default_port
45 | Failure "int_of_string" ->
46 prerr_endline "Warning: invalid port, reverting to default";
49 let callback req outchan =
53 let url = req#param "url" in
54 let pid = Unix.getpid () in
55 wget (sprintf "%s¶m.PID=%d" url pid) (sprintf "prova0.%d.dot" pid);
56 (match Unix.system (sprintf "make PID=%d > log.%d" pid pid) with
58 Http_daemon.respond_file (sprintf "") outchan
60 Http_daemon.respond_error
61 ~status:(`Server_error `Internal_server_error) outchan)
63 let pid = req#param "pid" in
64 Http_daemon.respond_file (sprintf "prova.%s.gif" pid) outchan;
66 sprintf "make PID=%s clean; rm -f prova0.%s.dot" pid pid))
68 Http_daemon.respond_error ~status:(`Client_error `Bad_request) outchan)
70 | Http_request.Param_not_found attr_name ->
71 Http_daemon.respond_error
72 ~status:(`Client_error `Bad_request)
73 ~body:(sprintf "Parameter '%s' is missing" attr_name)
76 printf "%s started and listening on port %d\n" daemon_name port;
78 Http_daemon.start' ~port callback;
79 printf "%s is terminating, bye!\n" daemon_name