GNUnet 0.21.2
gnunet-config.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2021 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
36static char *backend_check;
37
41static int cflags;
42
46static int is_experimental;
47
51static int no_defaults;
52
56static char *ram_config;
57
61static int libs;
62
66static int prefix;
67
68
76int
77main (int argc,
78 char *const *argv)
79{
82 .global_ret = EXIT_SUCCESS
83 };
84 const struct GNUNET_OS_ProjectData *pd
86 char *cfgfile = NULL;
87 char *loglev = NULL;
88 char *logfile = NULL;
91 GNUNET_GETOPT_option_help ("gnunet-config [OPTIONS]"),
97 'b',
98 "supported-backend",
99 "BACKEND",
101 "test if the current installation supports the specified BACKEND"),
102 &backend_check)),
104 'C',
105 "cflags",
107 "Provide an appropriate value for CFLAGS to applications building on top of GNUnet"),
108 &cflags),
110 'E',
111 "is-experimental",
112 gettext_noop ("Is this an experimental build of GNUnet"),
115 'j',
116 "libs",
118 "Provide an appropriate value for LIBS to applications building on top of GNUnet"),
119 &libs),
121 'n',
122 "no-defaults",
123 gettext_noop ("Do not parse default configuration files"),
124 &no_defaults),
126 'p',
127 "prefix",
129 "Provide the path under which GNUnet was installed"),
130 &prefix),
132 'R',
133 "ram-config",
134 "CONFIG_DATA",
136 "Parse main configuration from this command-line argument and not from disk"),
137 &ram_config),
140 };
141 int iret;
142
143 if (GNUNET_OK !=
145 &argc, &argv))
146 return EXIT_FAILURE;
147 if ( (NULL != pd->config_file) &&
148 (NULL != pd->user_config_file) )
150 iret = GNUNET_GETOPT_run ("gnunet-config",
151 options,
152 argc,
153 argv);
154 if (GNUNET_SYSERR == iret)
155 {
156 GNUNET_free_nz ((void *) argv);
157 GNUNET_free (cfgfile);
158 GNUNET_free (loglev);
159 GNUNET_free (logfile);
161 }
162 if (GNUNET_OK !=
163 GNUNET_log_setup ("gnunet-config",
164 loglev,
165 logfile))
166 {
167 GNUNET_free_nz ((void *) argv);
168 GNUNET_free (cfgfile);
169 GNUNET_free (loglev);
170 GNUNET_free (logfile);
171 return EXIT_FAILURE;
172 }
173 GNUNET_free (loglev);
174 GNUNET_free (logfile);
175 if (1 == is_experimental)
176 {
177 GNUNET_free_nz ((void *) argv);
178 GNUNET_free (cfgfile);
179#ifdef GNUNET_EXPERIMENTAL
180 return 0;
181#else
182 return 1;
183#endif
184 }
185 if (1 == cflags || 1 == libs || 1 == prefix)
186 {
189
190 if (1 == cflags)
191 {
192 fprintf (stdout, "-I%sinclude\n", prefixdir);
193 }
194 if (1 == libs)
195 {
196 fprintf (stdout, "-L%s -lgnunetutil\n", libdir);
197 }
198 if (1 == prefix)
199 {
200 fprintf (stdout, "%s\n", prefixdir);
201 }
202 GNUNET_free (prefixdir);
203 GNUNET_free (libdir);
204 GNUNET_free (cfgfile);
205 GNUNET_free_nz ((void *) argv);
206 return 0;
207 }
208 if (NULL != backend_check)
209 {
210 char *name;
211
213 "libgnunet_plugin_%s",
215 iret = (GNUNET_OK ==
216 GNUNET_PLUGIN_test (name)) ? 0 : 77;
218 GNUNET_free (cfgfile);
219 GNUNET_free_nz ((void *) argv);
220 return iret;
221 }
222
223 {
225
227
228 if (NULL != ram_config)
229 {
230 if ( (! no_defaults) &&
231 (GNUNET_SYSERR ==
233 NULL)) )
234 {
236 _ ("Failed to load default configuration, exiting ...\n"));
237 GNUNET_free_nz ((void *) argv);
239 GNUNET_free (cfgfile);
240 return EXIT_FAILURE;
241 }
242 if (GNUNET_OK !=
245 strlen (ram_config),
246 NULL))
247 {
249 _ ("Failed to parse configuration, exiting ...\n"));
250 GNUNET_free_nz ((void *) argv);
252 GNUNET_free (cfgfile);
253 return EXIT_FAILURE;
254 }
255 }
256 else
257 {
258 if (GNUNET_YES !=
259 GNUNET_DISK_file_test (cfgfile))
260 {
262 _ ("Unreadable configuration file `%s', exiting ...\n"),
263 cfgfile);
264 GNUNET_free_nz ((void *) argv);
266 GNUNET_free (cfgfile);
267 return EXIT_FAILURE;
268 }
269 if (GNUNET_SYSERR ==
272 cfgfile)
274 cfgfile)) )
275 {
277 _ ("Malformed configuration file `%s', exiting ...\n"),
278 cfgfile);
279 GNUNET_free_nz ((void *) argv);
281 GNUNET_free (cfgfile);
282 return EXIT_FAILURE;
283 }
284 }
286 &argv[iret],
287 cfgfile,
288 cfg);
289 GNUNET_free_nz ((void *) argv);
292 }
293 GNUNET_free (cfgfile);
294 return cs.global_ret;
295}
296
297
298/* end of gnunet-config.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:74
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static char * ram_config
Parse configuration from this memory.
Definition: gnunet-config.c:56
static int no_defaults
Do not load default configuration.
Definition: gnunet-config.c:51
static int libs
If printing the value of LIBS has been requested.
Definition: gnunet-config.c:61
static char * backend_check
Backend to check if the respective plugin is loadable.
Definition: gnunet-config.c:36
static int cflags
If printing the value of CFLAGS has been requested.
Definition: gnunet-config.c:41
static int is_experimental
Check if this is an experimental build.
Definition: gnunet-config.c:46
int main(int argc, char *const *argv)
Program to manipulate configuration files.
Definition: gnunet-config.c:77
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:66
static char * name
Name (label) of the records to list.
#define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs)
Macro that expands to a set of GNUNET-getopt directives to initialize a struct GNUNET_CONFIGURATION_C...
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
void GNUNET_CONFIGURATION_config_settings_free(struct GNUNET_CONFIGURATION_ConfigSettings *cs)
Free resources associated with cs.
void GNUNET_CONFIGURATION_config_tool_run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main task to run to perform operations typical for gnunet-config as per the configuration settings gi...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
char * GNUNET_CONFIGURATION_default_filename(void)
Return the filename of the default configuration filename that is used when no explicit configuration...
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load 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.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile(char **fn)
Allow user to specify configuration file name (-c option)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile(char **logfn)
Allow user to specify log file name (-l option)
int GNUNET_GETOPT_run(const char *binaryOptions, const struct GNUNET_GETOPT_CommandLineOption *allOptions, unsigned int argc, char *const *argv)
Parse the command line.
Definition: getopt.c:884
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_exclusive(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mutually exclusive with other options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const char *about)
Defining the option to print the command line help text (-h option).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel(char **level)
Define the '-L' log level option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version(const char *version)
Define the option to print the version of the application (-v option)
#define GNUNET_log(kind,...)
#define GNUNET_UTIL_VERSION
Version of the API (for entire gnunetutil.so library).
Definition: gnunet_common.h:96
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
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,...
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
enum GNUNET_GenericReturnValue GNUNET_PLUGIN_test(const char *library_name)
Test if a plugin exists.
Definition: plugin.c:168
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define EXIT_INVALIDARGUMENT
Definition: platform.h:253
Closure for GNUNET_CONFIGURATION_config_tool_run() with settings for what should be done with the con...
int global_ret
Return value from the operation, to be returned from 'main'.
unsigned int api_version
Must be set to the API version, i.e.
Definition of a command line option.
Project-specific data used to help the OS subsystem find installation paths.
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
const char * version
String identifying the current project version.