(* * Copyright (C) 2003-2004: * Stefano Zacchiroli * for the HELM Team http://helm.cs.unibo.it/ * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://helm.cs.unibo.it/ *) open Printf open Http_getter_types open Http_getter_misc let version = Http_getter_const.version let prefix_RE = Pcre.regexp "^\\s*([^\\s]+)\\s+([^\\s]+)\\s*$" let cache_dir = lazy (normalize_dir (Helm_registry.get "getter.cache_dir")) let dtd_dir = lazy (normalize_dir (Helm_registry.get "getter.dtd_dir")) let dtd_base_urls = lazy ( let rex = Pcre.regexp "/*$" in let raw_urls = match Helm_registry.get_list Helm_registry.string "getter.dtd_base_urls" with | [] -> ["http://helm.cs.unibo.it/dtd"; "http://mowgli.cs.unibo.it/dtd"] | urls -> urls in List.map (Pcre.replace ~rex) raw_urls) let port = lazy ( Helm_registry.get_opt_default Helm_registry.int ~default:58081 "getter.port") let prefixes = lazy ( let prefixes = Helm_registry.get_list Helm_registry.string "getter.prefix" in List.fold_left (fun acc prefix -> let subs = Pcre.extract ~rex:prefix_RE prefix in try (subs.(1), subs.(2)) :: acc with Invalid_argument _ -> Http_getter_logger.log ("skipping invalid prefix: " ^ prefix); acc) [] prefixes) let host = lazy (let buf = Buffer.create 20 in Shell.call ~stdout:(Shell.to_buffer buf) [Shell.cmd "hostname" ["-f"]]; Pcre.replace ~pat:"\n+$" (Buffer.contents buf)) let my_own_url = lazy (let (host, port) = (Lazy.force host, Lazy.force port) in sprintf "http://%s%s" (* without trailing '/' *) host (if port = 80 then "" else (sprintf ":%d" port))) let env_to_string () = let pp_prefix (uri_prefix, url_prefix) = " " ^ uri_prefix ^ " -- " ^ url_prefix in let pp_prefixes prefixes = match prefixes with | [] -> "" | l -> "\n" ^ String.concat "\n" (List.map pp_prefix l) in sprintf "HTTP Getter %s prefixes:%s dtd_dir:\t%s host:\t\t%s port:\t\t%d my_own_url:\t%s dtd_base_urls:\t%s log_file:\t%s log_level:\t%d " version (pp_prefixes (Lazy.force prefixes)) (Lazy.force dtd_dir) (Lazy.force host) (Lazy.force port) (Lazy.force my_own_url) (String.concat " " (Lazy.force dtd_base_urls)) (match Http_getter_logger.get_log_file () with None -> "None" | Some f -> f) (Http_getter_logger.get_log_level ())