From 56596fe01a41313f91ca8fea870c21bcea0c372c Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Mon, 23 Feb 2004 10:27:44 +0000 Subject: [PATCH] support optional keys in configuration file --- helm/DEVEL/rdfly/rdfly.ml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/helm/DEVEL/rdfly/rdfly.ml b/helm/DEVEL/rdfly/rdfly.ml index 0a268ce7c..bb734a62b 100644 --- a/helm/DEVEL/rdfly/rdfly.ml +++ b/helm/DEVEL/rdfly/rdfly.ml @@ -7,9 +7,9 @@ let _ = Helm_registry.load_from configuration_file ;; -let open_db ~host ~database ~port ~password ~user = +let open_db ?host ?database ?port ?password ?user = try - M.quick_connect ~host ~database ~port ~password ~user + M.quick_connect ?host ?database ?port ?password ?user with M.Error e as exc -> prerr_endline e ; @@ -82,11 +82,21 @@ let return_xml = mk_return_fun "text/xml" let return_400 body ch = Http_daemon.respond_error ~code:400 ~body ch let return_html_error s = return_html ("" ^ s ^ "") -let host = Helm_registry.get "rdfly.mysql_connection.host";; -let database = Helm_registry.get "rdfly.mysql_connection.database";; -let port = Helm_registry.get_int "rdfly.mysql_connection.port";; -let password = Helm_registry.get "rdfly.mysql_connection.password";; -let user = Helm_registry.get "rdfly.mysql_connection.user";; +let get_option key = + try + Some (Helm_registry.get key) + with Helm_registry.Key_not_found _ -> None + +let get_int_option key = + try + Some (Helm_registry.get_int key) + with Helm_registry.Key_not_found _ -> None + +let host = get_option "rdfly.mysql_connection.host";; +let database = get_option "rdfly.mysql_connection.database";; +let port = get_int_option "rdfly.mysql_connection.port";; +let password = get_option "rdfly.mysql_connection.password";; +let user = get_option "rdfly.mysql_connection.user";; let daemonport = Helm_registry.get_int "rdfly.port";; let callback (req: Http_types.request) ch = @@ -99,7 +109,7 @@ let callback (req: Http_types.request) ch = | "/get" -> let obj = req#param "object" and kind = req#param "kind" in - let db = open_db ~host ~database ~port ~password ~user () in + let db = open_db ?host ?database ?port ?password ?user () in begin match kind with "forward" -> return_xml (forward_metadata db obj) ch -- 2.39.2