2 * Copyright (C) 2000, 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/.
27 open Http_getter_types;;
34 | Environment (* read setting from environment variables *)
35 | Conffile (* read setting from configuration file *)
36 | Both (* read setting from both; environment override config file *)
38 let conf_file_tree = ref None
40 let (conf_file, conf_dir) =
43 Pcre.replace ~pat:"/$" (Sys.getenv "HELM_CONFIGURATION_DIR")
45 (conf_dir ^ "/configuration.xml", conf_dir)
46 with Not_found -> failwith "HELM_CONFIGURATION_DIR undefined"
48 let safe_getenv ?(from = Both) var =
49 (let rec read_from_file () =
50 (match !conf_file_tree with
54 (parse_wfcontent_entity
55 default_config (from_file conf_file) default_spec);
59 Some (find_element (String.lowercase var) t)#data
60 with Not_found -> None))
62 let read_from_env () = try Some (Sys.getenv var) with Not_found -> None in
63 let return_value name = function
65 | None -> failwith ("Setting " ^ name ^ " is not defined")
68 | Environment -> return_value var (read_from_env ())
69 | Conffile -> return_value var (read_from_file ())
71 (match read_from_env () with
72 | None -> return_value var (read_from_file ())
73 | v -> return_value var v)))
75 let servers_file = safe_getenv "HTTP_GETTER_SERVERS_FILE"
77 let cons hd tl = hd @ [ tl ] in
78 Http_getter_misc.fold_file cons [] servers_file
80 let xml_dbm = safe_getenv "HTTP_GETTER_XML_DBM"
81 let rdf_dbm = safe_getenv "HTTP_GETTER_RDF_DBM"
82 let xsl_dbm = safe_getenv "HTTP_GETTER_XSL_DBM"
83 let xml_index = safe_getenv "HTTP_GETTER_XML_INDEXNAME"
84 let rdf_index = safe_getenv "HTTP_GETTER_RDF_INDEXNAME"
85 let xsl_index = safe_getenv "HTTP_GETTER_XSL_INDEXNAME"
86 let xml_dir = safe_getenv "HTTP_GETTER_XML_DIR"
87 let rdf_dir = safe_getenv "HTTP_GETTER_RDF_DIR"
88 let xsl_dir = safe_getenv "HTTP_GETTER_XSL_DIR"
89 let dtd_dir = safe_getenv "HTTP_GETTER_DTD_DIR"
92 let port = safe_getenv "HTTP_GETTER_PORT" in
95 with Failure "int_of_string" ->
96 failwith ("Invalid port value: " ^ port)
98 let buf = Buffer.create 20 in
99 Shell.call ~stdout:(Shell.to_buffer buf) [Shell.cmd "hostname" ["-f"]];
100 Pcre.replace ~pat:"\n+$" (Buffer.contents buf)
105 (if port = 80 then "" else (sprintf ":%d" port))
106 let dtd_base_url = safe_getenv "HTTP_GETTER_DTD_BASE_URL"
109 match String.lowercase (safe_getenv "HTTP_GETTER_CACHE_MODE") with
110 | "normal" -> Enc_normal
111 | "gz" -> Enc_gzipped
112 | mode -> failwith ("Invalid cache mode: " ^ mode)
137 xml_dbm rdf_dbm xsl_dbm xml_index rdf_index xsl_index
138 xml_dir rdf_dir xsl_dir dtd_dir servers_file host port
139 my_own_url dtd_base_url
140 (match cache_mode with Enc_normal -> "Normal" | Enc_gzipped -> "GZipped")
141 conf_file conf_dir (String.concat "\n\t" servers);