GNUnet  0.11.x
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 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 
29 
35 static char *backend_check;
36 
37 
41 static int cflags;
42 
43 
47 static int libs;
48 
49 
53 static int prefix;
54 
55 
68 static void
69 run (void *cls,
70  char *const *args,
71  const char *cfgfile,
72  const struct GNUNET_CONFIGURATION_Handle *cfg)
73 {
74  struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls;
75 
76  if (1 == cflags || 1 == libs || 1 == prefix)
77  {
80 
81  if (1 == cflags)
82  {
83  fprintf (stdout, "-I%sinclude\n", prefixdir);
84  }
85  if (1 == libs)
86  {
87  fprintf (stdout, "-L%s -lgnunetutil\n", libdir);
88  }
89  if (1 == prefix)
90  {
91  fprintf (stdout, "%s\n", prefixdir);
92  }
93  cs->global_ret = 0;
94  GNUNET_free (prefixdir);
95  GNUNET_free (libdir);
96  return;
97  }
98  if (NULL != backend_check)
99  {
100  char *name;
101 
103  "libgnunet_plugin_%s",
104  backend_check);
105  cs->global_ret = (GNUNET_OK ==
106  GNUNET_PLUGIN_test (name)) ? 0 : 77;
107  GNUNET_free (name);
108  return;
109  }
111  args,
112  cfgfile,
113  cfg);
114 }
115 
116 
124 int
125 main (int argc,
126  char *const *argv)
127 {
130  .global_ret = EXIT_SUCCESS
131  };
135  'b',
136  "supported-backend",
137  "BACKEND",
138  gettext_noop (
139  "test if the current installation supports the specified BACKEND"),
140  &backend_check)),
142  'C',
143  "cflags",
144  gettext_noop (
145  "Provide an appropriate value for CFLAGS to applications building on top of GNUnet"),
146  &cflags),
148  'j',
149  "libs",
150  gettext_noop (
151  "Provide an appropriate value for LIBS to applications building on top of GNUnet"),
152  &libs),
154  'p',
155  "prefix",
156  gettext_noop (
157  "Provide the path under which GNUnet was installed"),
158  &prefix),
161  };
163 
164  if (GNUNET_OK !=
165  GNUNET_STRINGS_get_utf8_args (argc, argv,
166  &argc, &argv))
167  return EXIT_FAILURE;
168  ret =
169  GNUNET_PROGRAM_run (argc,
170  argv,
171  "gnunet-config [OPTIONS]",
172  gettext_noop ("Manipulate GNUnet configuration files"),
173  options,
174  &run,
175  &cs);
176  GNUNET_free_nz ((void *) argv);
178  if (GNUNET_NO == ret)
179  return 0;
180  if (GNUNET_SYSERR == ret)
181  return EXIT_INVALIDARGUMENT;
182  return cs.global_ret;
183 }
184 
185 
186 /* 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:69
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static int libs
If printing the value of LIBS has been requested.
Definition: gnunet-config.c:47
static char * backend_check
Backend to check if the respective plugin is loadable.
Definition: gnunet-config.c:35
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Print each option in a given section.
Definition: gnunet-config.c:69
static int cflags
If printing the value of CFLAGS has been requested.
Definition: gnunet-config.c:41
int main(int argc, char *const *argv)
Program to manipulate configuration files.
static int prefix
If printing the value of PREFIX has been requested.
Definition: gnunet-config.c:53
#define GNUNET_UTIL_VERSION
Version of the API (for entire gnunetutil.so library).
Definition: gnunet_common.h:82
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
#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_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...
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_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.
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,...
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
int GNUNET_PLUGIN_test(const char *library_name)
Test if a plugin exists.
Definition: plugin.c:175
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:364
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:1209
#define EXIT_INVALIDARGUMENT
Definition: platform.h:252
const char * name
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.