GNUnet 0.22.2
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

int main (int argc, char *const *argv)
 Program to manipulate configuration files. More...
 

Variables

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

Detailed Description

tool to access and manipulate GNUnet configuration files

Author
Christian Grothoff

Definition in file gnunet-config.c.

Function Documentation

◆ 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 76 of file gnunet-config.c.

78{
79 const struct GNUNET_OS_ProjectData *pd
83 .global_ret = EXIT_SUCCESS
84 };
85 char *cfgfile = NULL;
86 char *loglev = NULL;
87 char *logfile = NULL;
91 "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 ( (NULL != pd->config_file) &&
144 (NULL != pd->user_config_file) )
146 iret = GNUNET_GETOPT_run ("gnunet-config",
147 options,
148 argc,
149 argv);
150 if (GNUNET_SYSERR == iret)
151 {
152 GNUNET_free_nz ((void *) argv);
153 GNUNET_free (cfgfile);
154 GNUNET_free (loglev);
155 GNUNET_free (logfile);
157 }
158 if (GNUNET_OK !=
159 GNUNET_log_setup ("gnunet-config",
160 loglev,
161 logfile))
162 {
163 GNUNET_free_nz ((void *) argv);
164 GNUNET_free (cfgfile);
165 GNUNET_free (loglev);
166 GNUNET_free (logfile);
167 return EXIT_FAILURE;
168 }
169 GNUNET_free (loglev);
170 GNUNET_free (logfile);
171 if (1 == is_experimental)
172 {
173 GNUNET_free_nz ((void *) argv);
174 GNUNET_free (cfgfile);
175#ifdef GNUNET_EXPERIMENTAL
176 return 0;
177#else
178 return 1;
179#endif
180 }
181 if (1 == cflags || 1 == libs || 1 == prefix)
182 {
183 char *prefixdir = GNUNET_OS_installation_get_path (pd,
185 char *libdir = GNUNET_OS_installation_get_path (pd,
187
188 if (1 == cflags)
189 {
190 fprintf (stdout, "-I%sinclude\n", prefixdir);
191 }
192 if (1 == libs)
193 {
194 fprintf (stdout, "-L%s -lgnunetutil\n", libdir);
195 }
196 if (1 == prefix)
197 {
198 fprintf (stdout, "%s\n", prefixdir);
199 }
200 GNUNET_free (prefixdir);
201 GNUNET_free (libdir);
202 GNUNET_free (cfgfile);
203 return 0;
204 }
205 if (NULL != backend_check)
206 {
207 char *name;
208
210 "libgnunet_plugin_%s",
212 iret = (GNUNET_OK ==
214 name)) ? 0 : 77;
216 GNUNET_free (cfgfile);
217 return iret;
218 }
219
220 {
222
224
225 if (NULL != ram_config)
226 {
227 if ( (! no_defaults) &&
228 (GNUNET_SYSERR ==
230 NULL)) )
231 {
233 _ ("Failed to load default configuration, exiting ...\n"));
235 GNUNET_free (cfgfile);
236 return EXIT_FAILURE;
237 }
238 if (GNUNET_OK !=
241 strlen (ram_config),
242 NULL))
243 {
245 _ ("Failed to parse configuration, exiting ...\n"));
247 GNUNET_free (cfgfile);
248 return EXIT_FAILURE;
249 }
250 }
251 else
252 {
253 if (GNUNET_YES !=
254 GNUNET_DISK_file_test (cfgfile))
255 {
257 _ ("Unreadable configuration file `%s', exiting ...\n"),
258 cfgfile);
260 GNUNET_free (cfgfile);
261 return EXIT_FAILURE;
262 }
263 if (GNUNET_SYSERR ==
266 cfgfile)
268 cfgfile)) )
269 {
271 _ ("Malformed configuration file `%s', exiting ...\n"),
272 cfgfile);
274 GNUNET_free (cfgfile);
275 return EXIT_FAILURE;
276 }
277 }
279 &argv[iret],
280 cfgfile,
281 cfg);
284 }
285 GNUNET_free (cfgfile);
286 return cs.global_ret;
287}
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:108
static char * ram_config
Parse configuration from this memory.
Definition: gnunet-config.c:55
static int no_defaults
Do not load default configuration.
Definition: gnunet-config.c:50
static int libs
If printing the value of LIBS has been requested.
Definition: gnunet-config.c:60
static char * backend_check
Backend to check if the respective plugin is loadable.
Definition: gnunet-config.c:35
static int cflags
If printing the value of CFLAGS has been requested.
Definition: gnunet-config.c:40
static int is_experimental
Check if this is an experimental build.
Definition: gnunet-config.c:45
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:65
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_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:506
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 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).
Definition: gnunet_common.h:98
@ 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.
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 _(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.
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, GNUNET_OS_ProjectData::config_file, EXIT_INVALIDARGUMENT, gettext_noop, GNUNET_CONFIGURATION_ConfigSettings::global_ret, GNUNET_asprintf(), 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_load(), GNUNET_CONFIGURATION_parse(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_free_nz, 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, libs, name, no_defaults, options, GNUNET_CONFIGURATION_Handle::pd, prefix, ram_config, GNUNET_OS_ProjectData::user_config_file, 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().

◆ is_experimental

int is_experimental
static

Check if this is an experimental build.

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

Referenced by main().

◆ no_defaults

int no_defaults
static

Do not load default configuration.

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

Referenced by main().

◆ ram_config

char* ram_config
static

Parse configuration from this memory.

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

Referenced by main().

◆ libs

int libs
static

If printing the value of LIBS has been requested.

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

Referenced by main().

◆ prefix