From 912cf238365dbf70aed65c5a0bc65e5f3c1ea92b Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Fri, 4 Feb 2005 09:26:59 +0000 Subject: [PATCH] - simplified environment handling: * added a lot of default values * use maps_dir instead of dbm files file-per-file * use cache_dir instead of cache dirs dir-per-dir * servers could now either be listed in servers.txt or directly in configuration file --- helm/ocaml/getter/http_getter_env.ml | 81 ++++++++++++++++++--------- helm/ocaml/getter/http_getter_env.mli | 2 +- 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/helm/ocaml/getter/http_getter_env.ml b/helm/ocaml/getter/http_getter_env.ml index a7fe6be91..a0da4b676 100644 --- a/helm/ocaml/getter/http_getter_env.ml +++ b/helm/ocaml/getter/http_getter_env.ml @@ -35,23 +35,35 @@ open Http_getter_types let version = Http_getter_const.version -let servers_file = lazy (Helm_registry.get "getter.servers_file") -let cic_dbm = lazy (Helm_registry.get "getter.cic_dbm") -let nuprl_dbm = lazy (Helm_registry.get "getter.nuprl_dbm") -let rdf_dbm = lazy (Helm_registry.get "getter.rdf_dbm") -let xsl_dbm = lazy (Helm_registry.get "getter.xsl_dbm") -let xml_index = lazy (Helm_registry.get "getter.xml_indexname") -let rdf_index = lazy (Helm_registry.get "getter.rdf_indexname") -let xsl_index = lazy (Helm_registry.get "getter.xsl_indexname") -let cic_dir = lazy (Helm_registry.get "getter.cic_dir") -let nuprl_dir = lazy (Helm_registry.get "getter.nuprl_dir") -let rdf_dir = lazy (Helm_registry.get "getter.rdf_dir") +let servers_file = lazy ( + Helm_registry.get_opt Helm_registry.get "getter.servers_file") +let cic_dbm = lazy (Helm_registry.get "getter.maps_dir" ^ "/cic_db") +let nuprl_dbm = lazy (Helm_registry.get "getter.maps_dir" ^ "/nuprl_db") +let rdf_dbm = lazy (Helm_registry.get "getter.maps_dir" ^ "/rdf_db") +let xsl_dbm = lazy (Helm_registry.get "getter.maps_dir" ^ "/xsl_db") +let xml_index = lazy ( + Helm_registry.get_opt_default Helm_registry.get "index.txt" + "getter.xml_indexname") +let rdf_index = lazy ( + Helm_registry.get_opt_default Helm_registry.get "rdf_index.txt" + "getter.rdf_indexname") +let xsl_index = lazy ( + Helm_registry.get_opt_default Helm_registry.get "xslt_index.txt" + "getter.xsl_indexname") +let cic_dir = lazy (Helm_registry.get "getter.cache_dir" ^ "/cic") +let nuprl_dir = lazy (Helm_registry.get "getter.cache_dir" ^ "/nuprl") +let rdf_dir = lazy (Helm_registry.get "getter.cache_dir" ^ "/rdf") let dtd_dir = lazy (Helm_registry.get "getter.dtd_dir") let dtd_base_urls = lazy ( let rex = Pcre.regexp "/*$" in - let raw_urls = Helm_registry.get_string_list "getter.dtd_base_urls" in + let raw_urls = + Helm_registry.get_opt_default Helm_registry.get_string_list + ["http://helm.cs.unibo.it/dtd"; "http://mowgli.cs.unibo.it/dtd"] + "getter.dtd_base_urls" + in List.map (Pcre.replace ~rex) raw_urls) -let port = lazy (Helm_registry.get_int "getter.port") +let port = lazy ( + Helm_registry.get_opt_default Helm_registry.get_int 58081 "getter.port") let _servers = ref None @@ -62,22 +74,30 @@ let servers = | Some servers -> servers) let load_servers () = - let pos = ref (-1) in - List.rev (Http_getter_misc.fold_file - (fun line servers -> - if Http_getter_misc.is_blank_line line then - servers - else - (incr pos; (!pos, line) :: servers)) - [] - (Lazy.force servers_file)) + let pos = ref ~-1 in + match Lazy.force servers_file with + | None -> + List.map (fun s -> incr pos; (!pos, s)) + (Helm_registry.get_string_list "getter.servers") + | Some servers_file -> + List.rev (Http_getter_misc.fold_file + (fun line servers -> + if Http_getter_misc.is_blank_line line then + servers + else + (incr pos; (!pos, line) :: servers)) + [] + servers_file) let reload_servers () = _servers := Some (load_servers ()) let save_servers () = - let oc = open_out (Lazy.force servers_file) in - List.iter (fun (_,server) -> output_string oc (server ^ "\n")) - (servers ()); + match Lazy.force servers_file with + | None -> () + | Some servers_file -> + let oc = open_out servers_file in + List.iter (fun (_,server) -> output_string oc (server ^ "\n")) + (servers ()); close_out oc let host = @@ -94,7 +114,10 @@ let my_own_url = let cache_mode = lazy - (match String.lowercase (Helm_registry.get "getter.cache_mode") with + (let mode_string = + Helm_registry.get_opt_default Helm_registry.get "gz" "getter.cache_mode" + in + match String.lowercase mode_string with | "normal" -> `Normal | "gz" -> `Gzipped | mode -> failwith ("Invalid cache mode: " ^ mode)) @@ -131,7 +154,11 @@ log_level:\t%d (Lazy.force xsl_dbm) (Lazy.force xml_index) (Lazy.force rdf_index) (Lazy.force xsl_index) (Lazy.force cic_dir) (Lazy.force nuprl_dir) (Lazy.force rdf_dir) - (Lazy.force dtd_dir) (Lazy.force servers_file) (Lazy.force host) + (Lazy.force dtd_dir) + (match Lazy.force servers_file with + | None -> "no servers file" + | Some servers_file -> servers_file) + (Lazy.force host) (Lazy.force port) (Lazy.force my_own_url) (String.concat " " (Lazy.force dtd_base_urls)) (match Lazy.force cache_mode with diff --git a/helm/ocaml/getter/http_getter_env.mli b/helm/ocaml/getter/http_getter_env.mli index d3bc7f319..5e5a0496c 100644 --- a/helm/ocaml/getter/http_getter_env.mli +++ b/helm/ocaml/getter/http_getter_env.mli @@ -45,7 +45,7 @@ val cic_dir : string lazy_t (* XMLs' directory for CIC*) val nuprl_dir : string lazy_t (* XMLs' directory for NuPRL*) val rdf_dir : string lazy_t (* RDFs' directory *) val dtd_dir : string lazy_t (* DTDs' root directory *) -val servers_file : string lazy_t (* servers.txt file *) +val servers_file : string option lazy_t (* servers.txt file *) val port : int lazy_t (* port on which getter listens *) val dtd_base_urls : string list lazy_t (* base URLs for document patching *) -- 2.39.2