1 /**
2 * SysDB - src/liboconfig/utils.c
3 * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
24 #include "oconfig.h"
26 int
27 oconfig_get_string(oconfig_item_t *ci, char **value)
28 {
29 if (! ci)
30 return -1;
32 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
33 return -1;
35 if (value)
36 *value = ci->values[0].value.string;
37 return 0;
38 } /* oconfig_get_string */
40 int
41 oconfig_get_number(oconfig_item_t *ci, double *value)
42 {
43 if (! ci)
44 return -1;
46 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
47 return -1;
49 if (value)
50 *value = ci->values[0].value.number;
51 return 0;
52 } /* oconfig_get_number */
54 int
55 oconfig_get_boolean(oconfig_item_t *ci, _Bool *value)
56 {
57 if (! ci)
58 return -1;
60 if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN))
61 return -1;
63 if (value)
64 *value = ci->values[0].value.boolean != 0;
65 return 0;
66 } /* oconfig_get_boolean */
68 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */