GNUnet 0.29.1-dev.1-3-g346358e26
 
Loading...
Searching...
No Matches
gnunet-config.c File Reference

tool to access and manipulate GNUnet configuration files More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for gnunet-config.c:

Go to the source code of this file.

Functions

static void report_cleaned_definition (void *cls, const char *section, const char *option, unsigned int line)
 Report a definition removed by configuration cleanup.
 
int main (int argc, char *const *argv)
 Program to manipulate configuration files.
 

Variables

static char * backend_check
 Backend to check if the respective plugin is loadable.
 
static int cflags
 If printing the value of CFLAGS has been requested.
 
static int clean
 Remove redundant definitions from the main configuration file.
 
static int is_experimental
 Check if this is an experimental build.
 
static int no_defaults
 Do not load default configuration.
 
static char * ram_config
 Parse configuration from this memory.
 
static int libs
 If printing the value of LIBS has been requested.
 
static int prefix
 If printing the value of PREFIX has been requested.
 

Detailed Description

tool to access and manipulate GNUnet configuration files

Author
Christian Grothoff

Definition in file gnunet-config.c.

Function Documentation

◆ report_cleaned_definition()

static void report_cleaned_definition ( void *  cls,
const char *  section,
const char *  option,
unsigned int  line 
)
static

Report a definition removed by configuration cleanup.

Parameters
clstarget filename
sectionconfiguration section
optionconfiguration option
lineremoved line

Definition at line 82 of file gnunet-config.c.

86{
87 const char *filename = cls;
88
89 fprintf (stdout,
90 _ ("Removed [%s]/%s at %s:%u\n"),
91 section,
92 option,
94 line);
95}
static char * line
Desired phone line (string to be converted to a hash).
static char * filename
#define _(String)
GNU gettext support macro.
Definition platform.h:179

References _, filename, and line.

Referenced by main().

Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

Program to manipulate configuration files.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 106 of file gnunet-config.c.

108{
109 const struct GNUNET_OS_ProjectData *pd
113 .global_ret = EXIT_SUCCESS
114 };
115 char *cfgfile = NULL;
116 char *loglev = NULL;
117 char *logfile = NULL;
121 "gnunet-config [OPTIONS]"),
127 'b',
128 "supported-backend",
129 "BACKEND",
131 "test if the current installation supports the specified BACKEND"),
132 &backend_check)),
134 'C',
135 "cflags",
137 "Provide an appropriate value for CFLAGS to applications building on top of GNUnet"),
138 &cflags),
140 'x',
141 "clean",
143 "remove redundant definitions from the main configuration file"),
144 &clean),
146 'E',
147 "is-experimental",
148 gettext_noop ("Is this an experimental build of GNUnet"),
151 'j',
152 "libs",
154 "Provide an appropriate value for LIBS to applications building on top of GNUnet"),
155 &libs),
157 'n',
158 "no-defaults",
159 gettext_noop ("Do not parse default configuration files"),
160 &no_defaults),
162 'p',
163 "prefix",
165 "Provide the path under which GNUnet was installed"),
166 &prefix),
168 'R',
169 "ram-config",
170 "CONFIG_DATA",
172 "Parse main configuration from this command-line argument and not from disk"),
173 &ram_config),
176 };
177 int iret;
178
179 if ( (NULL != pd->config_file) &&
180 (NULL != pd->user_config_file) )
182 iret = GNUNET_GETOPT_run ("gnunet-config",
183 options,
184 argc,
185 argv);
186 if (GNUNET_SYSERR == iret)
187 {
188 GNUNET_free (cfgfile);
189 GNUNET_free (loglev);
190 GNUNET_free (logfile);
192 }
193 if (GNUNET_OK !=
194 GNUNET_log_setup ("gnunet-config",
195 loglev,
196 logfile))
197 {
198 GNUNET_free (cfgfile);
199 GNUNET_free (loglev);
200 GNUNET_free (logfile);
201 return EXIT_FAILURE;
202 }
203 GNUNET_free (loglev);
204 GNUNET_free (logfile);
205 if (clean &&
206 ( (NULL == cfgfile) ||
207 (NULL != ram_config) ||
208 (NULL != backend_check) ||
210 cs.full || cs.is_filename || (NULL != cs.option) ||
211 cs.rewrite || cs.diagnostics || cs.list_sections ||
212 (NULL != cs.section) || (NULL != cs.value) ||
213 (NULL != argv[iret]) ))
214 {
215 fprintf (stderr,
216 _ ("--clean requires a file-backed configuration and cannot be combined with another operation\n"));
218 GNUNET_free (cfgfile);
220 }
221 if (1 == is_experimental)
222 {
223 GNUNET_free (cfgfile);
224#ifdef GNUNET_EXPERIMENTAL
225 return 0;
226#else
227 return 1;
228#endif
229 }
230 if (1 == cflags || 1 == libs || 1 == prefix)
231 {
232 char *prefixdir = GNUNET_OS_installation_get_path (pd,
234 char *libdir = GNUNET_OS_installation_get_path (pd,
236
237 if (1 == cflags)
238 {
239 fprintf (stdout, "-I%sinclude\n", prefixdir);
240 }
241 if (1 == libs)
242 {
243 fprintf (stdout, "-L%s -lgnunetutil\n", libdir);
244 }
245 if (1 == prefix)
246 {
247 fprintf (stdout, "%s\n", prefixdir);
248 }
249 GNUNET_free (prefixdir);
250 GNUNET_free (libdir);
251 GNUNET_free (cfgfile);
252 return 0;
253 }
254 if (NULL != backend_check)
255 {
256 char *name;
257
259 "libgnunet_plugin_%s",
261 iret = (GNUNET_OK ==
263 name)) ? 0 : 77;
265 GNUNET_free (cfgfile);
266 return iret;
267 }
268
269 {
271
273 if ( (0 != cs.diagnostics) || clean)
275
276 if (NULL != ram_config)
277 {
278 if ( (! no_defaults) &&
279 (GNUNET_SYSERR ==
281 NULL)) )
282 {
284 _ ("Failed to load default configuration, exiting ...\n"));
286 GNUNET_free (cfgfile);
287 return EXIT_FAILURE;
288 }
289 if (GNUNET_OK !=
292 strlen (ram_config),
293 NULL))
294 {
296 _ ("Failed to parse configuration, exiting ...\n"));
298 GNUNET_free (cfgfile);
299 return EXIT_FAILURE;
300 }
301 }
302 else if (NULL != cfgfile)
303 {
304 if (GNUNET_YES !=
305 GNUNET_DISK_file_test (cfgfile))
306 {
308 _ ("Unreadable configuration file `%s', exiting ...\n"),
309 cfgfile);
311 GNUNET_free (cfgfile);
312 return EXIT_FAILURE;
313 }
314 if (GNUNET_SYSERR ==
317 cfgfile)
319 cfgfile)) )
320 {
322 _ ("Malformed configuration file `%s', exiting ...\n"),
323 cfgfile);
325 GNUNET_free (cfgfile);
326 return EXIT_FAILURE;
327 }
328 }
329 else if (! no_defaults)
330 {
331 /* cfgfile is NULL, so only load defaults */
332 if (GNUNET_SYSERR ==
334 NULL))
335 {
337 _ ("Malformed configuration file `%s', exiting ...\n"),
338 cfgfile);
340 return EXIT_FAILURE;
341 }
342 }
343 if (clean)
344 {
345 unsigned int removed;
346
347 if (GNUNET_OK !=
349 cfgfile,
351 cfgfile,
352 &removed))
353 {
354 fprintf (stderr,
355 _ ("Failed to clean configuration file `%s'\n"),
356 cfgfile);
357 cs.global_ret = 2;
358 }
359 else
360 fprintf (stdout,
361 ngettext ("Removed %u duplicate definition from %s\n",
362 "Removed %u duplicate definitions from %s\n",
363 removed),
364 removed,
365 cfgfile);
366 }
367 else
369 &argv[iret],
370 cfgfile,
371 cfg);
374 }
375 GNUNET_free (cfgfile);
376 return cs.global_ret;
377}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
#define gettext_noop(String)
Definition gettext.h:74
#define ngettext(Msgid1, Msgid2, N)
Definition gettext.h:53
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static int clean
Remove redundant definitions from the main configuration file.
static char * ram_config
Parse configuration from this memory.
static int no_defaults
Do not load default configuration.
static int libs
If printing the value of LIBS has been requested.
static void report_cleaned_definition(void *cls, const char *section, const char *option, unsigned int line)
Report a definition removed by configuration cleanup.
static char * backend_check
Backend to check if the respective plugin is loadable.
static int cflags
If printing the value of CFLAGS has been requested.
static int is_experimental
Check if this is an experimental build.
static int prefix
If printing the value of PREFIX has been requested.
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...
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
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(const struct GNUNET_OS_ProjectData *pd)
Return the filename of the default configuration filename that is used when no explicit configuration...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_clean_file(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename, GNUNET_CONFIGURATION_CleanCallback cb, void *cb_cls, unsigned int *removed)
Remove redundant option definitions from a parsed configuration file.
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.
void GNUNET_CONFIGURATION_enable_diagnostics(struct GNUNET_CONFIGURATION_Handle *cfg)
Enable extra diagnostics.
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:557
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.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const struct GNUNET_OS_ProjectData *pd, 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).
@ 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.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ 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 struct GNUNET_OS_ProjectData *pd, const char *library_name)
Test if a plugin exists.
Definition plugin.c:172
#define EXIT_INVALIDARGUMENT
Definition platform.h:258
Closure for GNUNET_CONFIGURATION_config_tool_run() with settings for what should be done with the con...
int full
Should the generated configuration file contain the whole configuration?
int global_ret
Return value from the operation, to be returned from 'main'.
int list_sections
Whether to show the sections.
int rewrite
Should we write out the configuration file, even if no value was changed?
int is_filename
Treat option as a filename.
unsigned int diagnostics
Diagnostics verbosity.
unsigned int api_version
Must be set to the API version, i.e.
const struct GNUNET_OS_ProjectData * pd
Project data for this configuration object.
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.

References _, GNUNET_CONFIGURATION_ConfigSettings::api_version, backend_check, cfg, cflags, clean, GNUNET_OS_ProjectData::config_file, GNUNET_CONFIGURATION_ConfigSettings::diagnostics, EXIT_INVALIDARGUMENT, GNUNET_CONFIGURATION_ConfigSettings::full, gettext_noop, GNUNET_CONFIGURATION_ConfigSettings::global_ret, GNUNET_asprintf(), GNUNET_CONFIGURATION_clean_file(), GNUNET_CONFIGURATION_CONFIG_OPTIONS, GNUNET_CONFIGURATION_config_settings_free(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_default_filename(), GNUNET_CONFIGURATION_deserialize(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_enable_diagnostics(), GNUNET_CONFIGURATION_load(), GNUNET_CONFIGURATION_parse(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GETOPT_option_cfgfile(), GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_exclusive(), GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_help(), GNUNET_GETOPT_option_logfile(), GNUNET_GETOPT_option_loglevel(), GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_version(), GNUNET_GETOPT_run(), GNUNET_log, GNUNET_log_setup(), GNUNET_OK, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_LIBDIR, GNUNET_OS_IPK_PREFIX, GNUNET_OS_project_data_gnunet(), GNUNET_PLUGIN_test(), GNUNET_SYSERR, GNUNET_UTIL_VERSION, GNUNET_YES, is_experimental, GNUNET_CONFIGURATION_ConfigSettings::is_filename, libs, GNUNET_CONFIGURATION_ConfigSettings::list_sections, name, ngettext, no_defaults, GNUNET_CONFIGURATION_ConfigSettings::option, options, GNUNET_CONFIGURATION_Handle::pd, prefix, ram_config, report_cleaned_definition(), GNUNET_CONFIGURATION_ConfigSettings::rewrite, GNUNET_CONFIGURATION_ConfigSettings::section, GNUNET_OS_ProjectData::user_config_file, GNUNET_CONFIGURATION_ConfigSettings::value, and GNUNET_OS_ProjectData::version.

Here is the call graph for this function:

Variable Documentation

◆ backend_check

char* backend_check
static

Backend to check if the respective plugin is loadable.

NULL if no check is to be performed. The value is the "basename" of the plugin to load.

Definition at line 35 of file gnunet-config.c.

Referenced by main().

◆ cflags

int cflags
static

If printing the value of CFLAGS has been requested.

Definition at line 40 of file gnunet-config.c.

Referenced by main().

◆ clean

int clean
static

Remove redundant definitions from the main configuration file.

Definition at line 45 of file gnunet-config.c.

Referenced by main().

◆ is_experimental

int is_experimental
static

Check if this is an experimental build.

Definition at line 50 of file gnunet-config.c.

Referenced by main().

◆ no_defaults

int no_defaults
static

Do not load default configuration.

Definition at line 55 of file gnunet-config.c.

Referenced by main().

◆ ram_config

char* ram_config
static

Parse configuration from this memory.

Definition at line 60 of file gnunet-config.c.

Referenced by main().

◆ libs

int libs
static

If printing the value of LIBS has been requested.

Definition at line 65 of file gnunet-config.c.

Referenced by main().

◆ prefix