-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.ml
93 lines (84 loc) · 2.85 KB
/
config.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
(* Copyright (c) 2007-2008 Janne Hellsten <[email protected]> *)
(*
* This program 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.
*
* This program 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 this program.
* If not, see <http://www.gnu.org/licenses/>.
*)
module P = Printf
open Eliom_sessions
open Simplexmlparser
type db_config =
{
db_name : string;
db_user : string;
db_host : string option;
db_port : string option;
db_pass : string option;
}
type site_config =
{
cfg_allow_ro_guests : bool;
cfg_homepage : string;
}
let get_attr_opt attr attrs =
try Some (List.assoc attr attrs)
with Not_found -> None
let get_attr_with_err e attr attrs =
try (List.assoc attr attrs)
with Not_found ->
raise (Ocsigen_extensions.Error_in_config_file
("Expecting "^e^"."^attr^" attribute in Nurpawiki config"))
let dbcfg =
let rec find_dbcfg = function
(Element ("database", attrs, _)::_) ->
let dbname = get_attr_with_err "database" "name" attrs in
let dbuser = get_attr_with_err "database" "user" attrs in
let dbhost = get_attr_opt "host" attrs in
let dbport = get_attr_opt "port" attrs in
let dbpass = get_attr_opt "password" attrs in
{
db_name = dbname;
db_user = dbuser;
db_host = dbhost;
db_port = dbport;
db_pass = dbpass;
}
| x::xs ->
find_dbcfg xs
| [] ->
raise (Ocsigen_extensions.Error_in_config_file ("Couldn't find database element from config")) in
find_dbcfg (get_config ())
let site =
let rec find_site_cfg = function
(Element ("nurpawiki", attrs, _))::_ ->
let allow_ro_guests =
(match get_attr_opt "allow_read_only_guests" attrs with
Some s -> s = "yes"
| None -> false) in
let homepage =
(match get_attr_opt "homepage" attrs with
Some s -> s
| None -> "WikiStart") in
{
cfg_allow_ro_guests = allow_ro_guests;
cfg_homepage = homepage;
}
| (Element (x,_,_))::xs ->
Ocsigen_messages.errlog x;
find_site_cfg xs
| _ ->
{
cfg_allow_ro_guests = false;
cfg_homepage = "WikiStart";
} in
let cfg = find_site_cfg (get_config ()) in
Ocsigen_messages.warning (P.sprintf "read-only guests allowed %b" cfg.cfg_allow_ro_guests);
cfg