2 * Copyright (C) 2003, 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"
76 let parse_servers () =
77 (let cons hd tl = hd @ [ tl ] in
78 Http_getter_misc.fold_file cons [] servers_file)
79 let servers = ref (parse_servers ())
80 let reload_servers () = servers := parse_servers ()
82 let xml_dbm = safe_getenv "HTTP_GETTER_XML_DBM"
83 let rdf_dbm = safe_getenv "HTTP_GETTER_RDF_DBM"
84 let xsl_dbm = safe_getenv "HTTP_GETTER_XSL_DBM"
85 let xml_index = safe_getenv "HTTP_GETTER_XML_INDEXNAME"
86 let rdf_index = safe_getenv "HTTP_GETTER_RDF_INDEXNAME"
87 let xsl_index = safe_getenv "HTTP_GETTER_XSL_INDEXNAME"
88 let xml_dir = safe_getenv "HTTP_GETTER_XML_DIR"
89 let rdf_dir = safe_getenv "HTTP_GETTER_RDF_DIR"
90 let dtd_dir = safe_getenv "HTTP_GETTER_DTD_DIR"
93 let port = safe_getenv "HTTP_GETTER_PORT" in
96 with Failure "int_of_string" ->
97 failwith ("Invalid port value: " ^ port)
99 let buf = Buffer.create 20 in
100 Shell.call ~stdout:(Shell.to_buffer buf) [Shell.cmd "hostname" ["-f"]];
101 Pcre.replace ~pat:"\n+$" (Buffer.contents buf)
104 "http://%s%s" (* without trailing '/' *)
106 (if port = 80 then "" else (sprintf ":%d" port))
107 let dtd_base_url = safe_getenv "HTTP_GETTER_DTD_BASE_URL"
110 match String.lowercase (safe_getenv "HTTP_GETTER_CACHE_MODE") with
111 | "normal" -> Enc_normal
112 | "gz" -> Enc_gzipped
113 | mode -> failwith ("Invalid cache mode: " ^ mode)
140 xml_dbm rdf_dbm xsl_dbm xml_index rdf_index xsl_index
141 xml_dir rdf_dir dtd_dir servers_file host port
142 my_own_url dtd_base_url
143 (match cache_mode with Enc_normal -> "Normal" | Enc_gzipped -> "GZipped")
144 conf_file conf_dir (String.concat "\n\t" !servers);