adding --enable-taler-wallet configure option to build a reduced version of libgnunet...
[oweals/gnunet.git] / src / util / configuration_loader.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2006, 2007, 2008, 2009, 2013 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file src/util/configuration_loader.c
23  * @brief configuration loading
24  * @author Christian Grothoff
25  */
26
27 /**
28  * Load configuration (starts with defaults, then loads
29  * system-specific configuration).
30  *
31  * @param cfg configuration to update
32  * @param filename name of the configuration file, NULL to load defaults
33  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
34  */
35 int
36 GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
37                            const char *filename)
38 {
39   char *baseconfig;
40   char *ipath;
41
42   ipath = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
43   if (NULL == ipath)
44     return GNUNET_SYSERR;
45   baseconfig = NULL;
46   GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
47   GNUNET_free (ipath);
48   if (GNUNET_SYSERR ==
49       GNUNET_DISK_directory_scan (baseconfig, &parse_configuration_file, cfg))
50   {
51     GNUNET_free (baseconfig);
52     return GNUNET_SYSERR;       /* no configuration at all found */
53   }
54   GNUNET_free (baseconfig);
55   if ((NULL != filename) &&
56       (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)))
57   {
58     /* specified configuration not found */
59     return GNUNET_SYSERR;
60   }
61   if (((GNUNET_YES !=
62         GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
63       (filename != NULL))
64     GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
65                                            filename);
66   return GNUNET_OK;
67 }
68
69 /* end of configuration_loader.c */