File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ (*
2+ * Copyright (C) Citrix Systems Inc.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published
6+ * by the Free Software Foundation; version 2.1 only. with the special
7+ * exception on linking described in file LICENSE.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU Lesser General Public License for more details.
13+ *)
14+
15+
16+ type platformdata = (string * string ) list
17+
18+ let is_valid ~key ~platformdata =
19+ (not (List. mem_assoc key platformdata)) ||
20+ (match List. assoc key platformdata |> String. lowercase with
21+ | "true" | "1" | "false" | "0" -> true
22+ | v -> false
23+ )
24+
25+ let is_true ~key ~platformdata ~default =
26+ try
27+ match List. assoc key platformdata |> String. lowercase with
28+ | "true" | "1" -> true
29+ | "false" | "0" -> false
30+ | _ -> default (* Check for validity using is_valid if required *)
31+ with Not_found ->
32+ default
33+
34+
Original file line number Diff line number Diff line change 1+ (*
2+ * Copyright (C) Citrix Systems Inc.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published
6+ * by the Free Software Foundation; version 2.1 only. with the special
7+ * exception on linking described in file LICENSE.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU Lesser General Public License for more details.
13+ *)
14+
15+ (* This module defines interpretation of boolean platform values. It
16+ * matches the interpretation implemented in XenAPI for these values.
17+ *)
18+
19+ type platformdata = (string * string ) list
20+
21+ (* * [is_valid key platformdata] returns true if:
22+ * 1. The key is _not_ in platformdata (absence of key is valid) or
23+ * 2. The key is in platformdata, associated with a booleanish value *)
24+ val is_valid : key :string -> platformdata :platformdata -> bool
25+
26+ (* * [is_true key platformdata default] returns true, if the platformdata
27+ * contains a value for key that is "true" or "1". It returns false, if
28+ * a value "0" or "false" exists. If the key doesn't exist or contains
29+ * none of the values above, [default] is returned.
30+ *)
31+ val is_true :
32+ key :string ->
33+ platformdata :platformdata ->
34+ default :bool ->
35+ bool
36+
You can’t perform that action at this time.
0 commit comments