diff options
Diffstat (limited to 'src/cli/util/gnunet-config.c')
-rw-r--r-- | src/cli/util/gnunet-config.c | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/src/cli/util/gnunet-config.c b/src/cli/util/gnunet-config.c new file mode 100644 index 000000000..714c683dd --- /dev/null +++ b/src/cli/util/gnunet-config.c | |||
@@ -0,0 +1,206 @@ | |||
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 | |||
21 | /** | ||
22 | * @file util/gnunet-config.c | ||
23 | * @brief tool to access and manipulate GNUnet configuration files | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | |||
30 | |||
31 | /** | ||
32 | * Backend to check if the respective plugin is | ||
33 | * loadable. NULL if no check is to be performed. | ||
34 | * The value is the "basename" of the plugin to load. | ||
35 | */ | ||
36 | static char *backend_check; | ||
37 | |||
38 | |||
39 | /** | ||
40 | * If printing the value of CFLAGS has been requested. | ||
41 | */ | ||
42 | static int cflags; | ||
43 | |||
44 | /** | ||
45 | * Check if this is an experimental build | ||
46 | */ | ||
47 | static int is_experimental; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * If printing the value of LIBS has been requested. | ||
52 | */ | ||
53 | static int libs; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * If printing the value of PREFIX has been requested. | ||
58 | */ | ||
59 | static int prefix; | ||
60 | |||
61 | |||
62 | /** | ||
63 | * Print each option in a given section. | ||
64 | * Main task to run to perform operations typical for | ||
65 | * gnunet-config as per the configuration settings | ||
66 | * given in @a cls. | ||
67 | * | ||
68 | * @param cls closure with the `struct GNUNET_CONFIGURATION_ConfigSettings` | ||
69 | * @param args remaining command-line arguments | ||
70 | * @param cfgfile name of the configuration file used (for saving, | ||
71 | * can be NULL!) | ||
72 | * @param cfg configuration | ||
73 | */ | ||
74 | static void | ||
75 | run (void *cls, | ||
76 | char *const *args, | ||
77 | const char *cfgfile, | ||
78 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
79 | { | ||
80 | struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls; | ||
81 | |||
82 | if (1 == is_experimental) | ||
83 | { | ||
84 | #ifdef GNUNET_EXPERIMENTAL | ||
85 | cs->global_ret = 0; | ||
86 | #else | ||
87 | cs->global_ret = 1; | ||
88 | #endif | ||
89 | return; | ||
90 | } | ||
91 | if (1 == cflags || 1 == libs || 1 == prefix) | ||
92 | { | ||
93 | char *prefixdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_PREFIX); | ||
94 | char *libdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR); | ||
95 | |||
96 | if (1 == cflags) | ||
97 | { | ||
98 | fprintf (stdout, "-I%sinclude\n", prefixdir); | ||
99 | } | ||
100 | if (1 == libs) | ||
101 | { | ||
102 | fprintf (stdout, "-L%s -lgnunetutil\n", libdir); | ||
103 | } | ||
104 | if (1 == prefix) | ||
105 | { | ||
106 | fprintf (stdout, "%s\n", prefixdir); | ||
107 | } | ||
108 | cs->global_ret = 0; | ||
109 | GNUNET_free (prefixdir); | ||
110 | GNUNET_free (libdir); | ||
111 | return; | ||
112 | } | ||
113 | if (NULL != backend_check) | ||
114 | { | ||
115 | char *name; | ||
116 | |||
117 | GNUNET_asprintf (&name, | ||
118 | "libgnunet_plugin_%s", | ||
119 | backend_check); | ||
120 | cs->global_ret = (GNUNET_OK == | ||
121 | GNUNET_PLUGIN_test (name)) ? 0 : 77; | ||
122 | GNUNET_free (name); | ||
123 | return; | ||
124 | } | ||
125 | GNUNET_CONFIGURATION_config_tool_run (cs, | ||
126 | args, | ||
127 | cfgfile, | ||
128 | cfg); | ||
129 | } | ||
130 | |||
131 | |||
132 | /** | ||
133 | * Program to manipulate configuration files. | ||
134 | * | ||
135 | * @param argc number of arguments from the command line | ||
136 | * @param argv command line arguments | ||
137 | * @return 0 ok, 1 on error | ||
138 | */ | ||
139 | int | ||
140 | main (int argc, | ||
141 | char *const *argv) | ||
142 | { | ||
143 | struct GNUNET_CONFIGURATION_ConfigSettings cs = { | ||
144 | .api_version = GNUNET_UTIL_VERSION, | ||
145 | .global_ret = EXIT_SUCCESS | ||
146 | }; | ||
147 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
148 | GNUNET_GETOPT_option_exclusive ( | ||
149 | GNUNET_GETOPT_option_string ( | ||
150 | 'b', | ||
151 | "supported-backend", | ||
152 | "BACKEND", | ||
153 | gettext_noop ( | ||
154 | "test if the current installation supports the specified BACKEND"), | ||
155 | &backend_check)), | ||
156 | GNUNET_GETOPT_option_flag ( | ||
157 | 'C', | ||
158 | "cflags", | ||
159 | gettext_noop ( | ||
160 | "Provide an appropriate value for CFLAGS to applications building on top of GNUnet"), | ||
161 | &cflags), | ||
162 | GNUNET_GETOPT_option_flag ( | ||
163 | 'E', | ||
164 | "is-experimental", | ||
165 | gettext_noop ("Is this an experimental build of GNUnet"), | ||
166 | &is_experimental), | ||
167 | GNUNET_GETOPT_option_flag ( | ||
168 | 'j', | ||
169 | "libs", | ||
170 | gettext_noop ( | ||
171 | "Provide an appropriate value for LIBS to applications building on top of GNUnet"), | ||
172 | &libs), | ||
173 | GNUNET_GETOPT_option_flag ( | ||
174 | 'p', | ||
175 | "prefix", | ||
176 | gettext_noop ( | ||
177 | "Provide the path under which GNUnet was installed"), | ||
178 | &prefix), | ||
179 | GNUNET_CONFIGURATION_CONFIG_OPTIONS (&cs), | ||
180 | GNUNET_GETOPT_OPTION_END | ||
181 | }; | ||
182 | enum GNUNET_GenericReturnValue ret; | ||
183 | |||
184 | if (GNUNET_OK != | ||
185 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
186 | &argc, &argv)) | ||
187 | return EXIT_FAILURE; | ||
188 | ret = | ||
189 | GNUNET_PROGRAM_run (argc, | ||
190 | argv, | ||
191 | "gnunet-config [OPTIONS]", | ||
192 | gettext_noop ("Manipulate GNUnet configuration files"), | ||
193 | options, | ||
194 | &run, | ||
195 | &cs); | ||
196 | GNUNET_free_nz ((void *) argv); | ||
197 | GNUNET_CONFIGURATION_config_settings_free (&cs); | ||
198 | if (GNUNET_NO == ret) | ||
199 | return 0; | ||
200 | if (GNUNET_SYSERR == ret) | ||
201 | return EXIT_INVALIDARGUMENT; | ||
202 | return cs.global_ret; | ||
203 | } | ||
204 | |||
205 | |||
206 | /* end of gnunet-config.c */ | ||