3 * Stefano Zacchiroli <zack@cs.unibo.it>
4 * for the HELM Team http://helm.cs.unibo.it/
6 * This file is part of HELM, an Hypertextual, Electronic
7 * Library of Mathematics, developed at the Computer Science
8 * Department, University of Bologna, Italy.
10 * HELM is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * HELM is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with HELM; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * For details, see the HELM World-Wide-Web page,
26 * http://helm.cs.unibo.it/
29 open Http_getter_types;;
36 | Environment (* read setting from environment variables *)
37 | Conffile (* read setting from configuration file *)
38 | Both (* read setting from both; environment override config file *)
40 let conf_file_tree = ref None
42 let (conf_file, conf_dir) =
45 Pcre.replace ~pat:"/$" (Sys.getenv "HELM_CONFIGURATION_DIR")
47 (conf_dir ^ "/configuration.xml", conf_dir)
48 with Not_found -> failwith "HELM_CONFIGURATION_DIR undefined"
50 let safe_getenv ?(from = Both) var =
51 (let rec read_from_file () =
52 (match !conf_file_tree with
56 (parse_wfcontent_entity
57 default_config (from_file conf_file) default_spec);
61 Some (find_element (String.lowercase var) t)#data
62 with Not_found -> None))
64 let read_from_env () = try Some (Sys.getenv var) with Not_found -> None in
65 let return_value name = function
67 | None -> failwith ("Setting " ^ name ^ " is not defined")
70 | Environment -> return_value var (read_from_env ())
71 | Conffile -> return_value var (read_from_file ())
73 (match read_from_env () with
74 | None -> return_value var (read_from_file ())
75 | v -> return_value var v)))
77 let servers_file = safe_getenv "HTTP_GETTER_SERVERS_FILE"
78 let parse_servers () =
79 (let cons hd tl = hd @ [ tl ] in
80 Http_getter_misc.fold_file cons [] servers_file)
81 let servers = ref (parse_servers ())
82 let reload_servers () = servers := parse_servers ()
84 let xml_dbm = safe_getenv "HTTP_GETTER_XML_DBM"
85 let rdf_dbm = safe_getenv "HTTP_GETTER_RDF_DBM"
86 let xsl_dbm = safe_getenv "HTTP_GETTER_XSL_DBM"
87 let xml_index = safe_getenv "HTTP_GETTER_XML_INDEXNAME"
88 let rdf_index = safe_getenv "HTTP_GETTER_RDF_INDEXNAME"
89 let xsl_index = safe_getenv "HTTP_GETTER_XSL_INDEXNAME"
90 let xml_dir = safe_getenv "HTTP_GETTER_XML_DIR"
91 let rdf_dir = safe_getenv "HTTP_GETTER_RDF_DIR"
92 let dtd_dir = safe_getenv "HTTP_GETTER_DTD_DIR"
95 let port = safe_getenv "HTTP_GETTER_PORT" in
98 with Failure "int_of_string" ->
99 failwith ("Invalid port value: " ^ port)
101 let buf = Buffer.create 20 in
102 Shell.call ~stdout:(Shell.to_buffer buf) [Shell.cmd "hostname" ["-f"]];
103 Pcre.replace ~pat:"\n+$" (Buffer.contents buf)
106 "http://%s%s" (* without trailing '/' *)
108 (if port = 80 then "" else (sprintf ":%d" port))
109 let dtd_base_url = safe_getenv "HTTP_GETTER_DTD_BASE_URL"
112 match String.lowercase (safe_getenv "HTTP_GETTER_CACHE_MODE") with
113 | "normal" -> Enc_normal
114 | "gz" -> Enc_gzipped
115 | mode -> failwith ("Invalid cache mode: " ^ mode)
142 xml_dbm rdf_dbm xsl_dbm xml_index rdf_index xsl_index
143 xml_dir rdf_dir dtd_dir servers_file host port
144 my_own_url dtd_base_url
145 (match cache_mode with Enc_normal -> "Normal" | Enc_gzipped -> "GZipped")
146 conf_file conf_dir (String.concat "\n\t" !servers);