GNUnet  0.11.x
configuration_loader.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2006, 2007, 2008, 2009, 2013 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your 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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 
30 #define LOG(kind, ...) GNUNET_log_from (kind, "util-configuration", __VA_ARGS__)
31 
32 
41 int
43  const char *filename)
44 {
45  char *baseconfig;
46  const char *base_config_varname;
47 
48  base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname;
49 
50  if (NULL != base_config_varname
51  && NULL != (baseconfig = getenv (base_config_varname)))
52  {
53  baseconfig = GNUNET_strdup (baseconfig);
54  }
55  else
56  {
57  char *ipath;
58 
60  if (NULL == ipath)
61  return GNUNET_SYSERR;
62  GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d");
63  GNUNET_free (ipath);
64  }
65 
66  char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
67  GNUNET_free (baseconfig);
68 
71  {
72  GNUNET_free (dname);
73  return GNUNET_SYSERR; /* no configuration at all found */
74  }
75  GNUNET_free (dname);
76  if ((NULL != filename) &&
77  (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)))
78  {
79  /* specified configuration not found */
80  return GNUNET_SYSERR;
81  }
82  if (((GNUNET_YES !=
83  GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) &&
84  (filename != NULL))
85  GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG",
86  filename);
87  return GNUNET_OK;
88 }
89 
90 
91 /* end of configuration_loader.c */
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
int GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration (starts with defaults, then loads system-specific configuration).
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment...
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation directory.
static char * filename
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition: strings.c:618
char * getenv()
configuration data
Definition: configuration.c:84
const char * base_config_varname
Name of an environment variable that can be used to override the location from which default configur...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
Return the directory where data is installed (share/gnunet/)
#define GNUNET_free(ptr)
Wrapper around free.