diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-05-20 10:54:21 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-05-20 10:54:46 +0200 |
commit | 14f47d65b837698fa5245e00352ca804fb8684cb (patch) | |
tree | 0d985232afb3dc1d0b9def7590420a8844883605 | |
parent | 2d68ef96aa4ad8814e5a5b56bba31b2d75815395 (diff) | |
download | gnunet-14f47d65b837698fa5245e00352ca804fb8684cb.tar.gz gnunet-14f47d65b837698fa5245e00352ca804fb8684cb.zip |
CONFIG: add -R and -n options to gnunet-config
-rw-r--r-- | src/cli/util/gnunet-config.c | 66 | ||||
-rw-r--r-- | src/include/gnunet_configuration_lib.h | 77 |
2 files changed, 95 insertions, 48 deletions
diff --git a/src/cli/util/gnunet-config.c b/src/cli/util/gnunet-config.c index 5b0260225..979f0b3f4 100644 --- a/src/cli/util/gnunet-config.c +++ b/src/cli/util/gnunet-config.c | |||
@@ -214,26 +214,58 @@ main (int argc, | |||
214 | 214 | ||
215 | cfg = GNUNET_CONFIGURATION_create (); | 215 | cfg = GNUNET_CONFIGURATION_create (); |
216 | 216 | ||
217 | if (GNUNET_YES != | 217 | if (NULL != ram_config) |
218 | GNUNET_DISK_file_test (cfgfile)) | ||
219 | { | 218 | { |
220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 219 | if ( (! no_defaults) && |
221 | _ ("Unreadable configuration file `%s', exiting ...\n"), | 220 | (GNUNET_SYSERR == |
222 | cfgfile); | 221 | GNUNET_CONFIGURATION_load (cfg, |
223 | GNUNET_free_nz ((void *) argv); | 222 | NULL)) ) |
224 | GNUNET_CONFIGURATION_destroy (cfg); | 223 | { |
225 | return EXIT_FAILURE; | 224 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
225 | _ ("Failed to load default configuration, exiting ...\n")); | ||
226 | GNUNET_free_nz ((void *) argv); | ||
227 | GNUNET_CONFIGURATION_destroy (cfg); | ||
228 | return EXIT_FAILURE; | ||
229 | } | ||
230 | if (GNUNET_OK != | ||
231 | GNUNET_CONFIGURATION_deserialize (cfg, | ||
232 | ram_config, | ||
233 | strlen (ram_config), | ||
234 | NULL)) | ||
235 | { | ||
236 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
237 | _ ("Failed to parse configuration, exiting ...\n")); | ||
238 | GNUNET_free_nz ((void *) argv); | ||
239 | GNUNET_CONFIGURATION_destroy (cfg); | ||
240 | return EXIT_FAILURE; | ||
241 | } | ||
226 | } | 242 | } |
227 | if (GNUNET_SYSERR == | 243 | else |
228 | GNUNET_CONFIGURATION_load (cfg, | ||
229 | cfgfile)) | ||
230 | { | 244 | { |
231 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 245 | if (GNUNET_YES != |
232 | _ ("Malformed configuration file `%s', exiting ...\n"), | 246 | GNUNET_DISK_file_test (cfgfile)) |
233 | cfgfile); | 247 | { |
234 | GNUNET_free_nz ((void *) argv); | 248 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
235 | GNUNET_CONFIGURATION_destroy (cfg); | 249 | _ ("Unreadable configuration file `%s', exiting ...\n"), |
236 | return EXIT_FAILURE; | 250 | cfgfile); |
251 | GNUNET_free_nz ((void *) argv); | ||
252 | GNUNET_CONFIGURATION_destroy (cfg); | ||
253 | return EXIT_FAILURE; | ||
254 | } | ||
255 | if (GNUNET_SYSERR == | ||
256 | (no_defaults | ||
257 | ? GNUNET_CONFIGURATION_parse (cfg, | ||
258 | cfgfile) | ||
259 | : GNUNET_CONFIGURATION_load (cfg, | ||
260 | cfgfile)) ) | ||
261 | { | ||
262 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
263 | _ ("Malformed configuration file `%s', exiting ...\n"), | ||
264 | cfgfile); | ||
265 | GNUNET_free_nz ((void *) argv); | ||
266 | GNUNET_CONFIGURATION_destroy (cfg); | ||
267 | return EXIT_FAILURE; | ||
268 | } | ||
237 | } | 269 | } |
238 | GNUNET_CONFIGURATION_config_tool_run (&cs, | 270 | GNUNET_CONFIGURATION_config_tool_run (&cs, |
239 | &argv[iret], | 271 | &argv[iret], |
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index 88d23e0e9..132172516 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h | |||
@@ -66,7 +66,8 @@ GNUNET_CONFIGURATION_create (void); | |||
66 | * @return duplicate configuration | 66 | * @return duplicate configuration |
67 | */ | 67 | */ |
68 | struct GNUNET_CONFIGURATION_Handle * | 68 | struct GNUNET_CONFIGURATION_Handle * |
69 | GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg); | 69 | GNUNET_CONFIGURATION_dup ( |
70 | const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
70 | 71 | ||
71 | 72 | ||
72 | /** | 73 | /** |
@@ -75,7 +76,8 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg); | |||
75 | * @param cfg configuration to destroy | 76 | * @param cfg configuration to destroy |
76 | */ | 77 | */ |
77 | void | 78 | void |
78 | GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); | 79 | GNUNET_CONFIGURATION_destroy ( |
80 | struct GNUNET_CONFIGURATION_Handle *cfg); | ||
79 | 81 | ||
80 | 82 | ||
81 | /** | 83 | /** |
@@ -88,8 +90,9 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); | |||
88 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 90 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
89 | */ | 91 | */ |
90 | enum GNUNET_GenericReturnValue | 92 | enum GNUNET_GenericReturnValue |
91 | GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | 93 | GNUNET_CONFIGURATION_load ( |
92 | const char *filename); | 94 | struct GNUNET_CONFIGURATION_Handle *cfg, |
95 | const char *filename); | ||
93 | 96 | ||
94 | 97 | ||
95 | /** | 98 | /** |
@@ -101,8 +104,9 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
101 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 104 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
102 | */ | 105 | */ |
103 | enum GNUNET_GenericReturnValue | 106 | enum GNUNET_GenericReturnValue |
104 | GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, | 107 | GNUNET_CONFIGURATION_load_from ( |
105 | const char *defaults_d); | 108 | struct GNUNET_CONFIGURATION_Handle *cfg, |
109 | const char *defaults_d); | ||
106 | 110 | ||
107 | 111 | ||
108 | /** | 112 | /** |
@@ -138,8 +142,9 @@ GNUNET_CONFIGURATION_default_filename (void); | |||
138 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 142 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
139 | */ | 143 | */ |
140 | enum GNUNET_GenericReturnValue | 144 | enum GNUNET_GenericReturnValue |
141 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | 145 | GNUNET_CONFIGURATION_parse ( |
142 | const char *filename); | 146 | struct GNUNET_CONFIGURATION_Handle *cfg, |
147 | const char *filename); | ||
143 | 148 | ||
144 | 149 | ||
145 | /** | 150 | /** |
@@ -151,8 +156,9 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
151 | * present. This memory should be freed by the caller | 156 | * present. This memory should be freed by the caller |
152 | */ | 157 | */ |
153 | char * | 158 | char * |
154 | GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | 159 | GNUNET_CONFIGURATION_serialize ( |
155 | size_t *size); | 160 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
161 | size_t *size); | ||
156 | 162 | ||
157 | 163 | ||
158 | /** | 164 | /** |
@@ -168,6 +174,7 @@ char * | |||
168 | GNUNET_CONFIGURATION_serialize_diagnostics ( | 174 | GNUNET_CONFIGURATION_serialize_diagnostics ( |
169 | const struct GNUNET_CONFIGURATION_Handle *cfg); | 175 | const struct GNUNET_CONFIGURATION_Handle *cfg); |
170 | 176 | ||
177 | |||
171 | /** | 178 | /** |
172 | * De-serializes configuration | 179 | * De-serializes configuration |
173 | * | 180 | * |
@@ -179,10 +186,11 @@ GNUNET_CONFIGURATION_serialize_diagnostics ( | |||
179 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 186 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
180 | */ | 187 | */ |
181 | enum GNUNET_GenericReturnValue | 188 | enum GNUNET_GenericReturnValue |
182 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | 189 | GNUNET_CONFIGURATION_deserialize ( |
183 | const char *mem, | 190 | struct GNUNET_CONFIGURATION_Handle *cfg, |
184 | size_t size, | 191 | const char *mem, |
185 | const char *source_filename); | 192 | size_t size, |
193 | const char *source_filename); | ||
186 | 194 | ||
187 | 195 | ||
188 | /** | 196 | /** |
@@ -193,8 +201,9 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
193 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 201 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
194 | */ | 202 | */ |
195 | enum GNUNET_GenericReturnValue | 203 | enum GNUNET_GenericReturnValue |
196 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | 204 | GNUNET_CONFIGURATION_write ( |
197 | const char *filename); | 205 | struct GNUNET_CONFIGURATION_Handle *cfg, |
206 | const char *filename); | ||
198 | 207 | ||
199 | 208 | ||
200 | /** | 209 | /** |
@@ -233,7 +242,8 @@ GNUNET_CONFIGURATION_get_diff ( | |||
233 | * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) | 242 | * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) |
234 | */ | 243 | */ |
235 | enum GNUNET_GenericReturnValue | 244 | enum GNUNET_GenericReturnValue |
236 | GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); | 245 | GNUNET_CONFIGURATION_is_dirty ( |
246 | const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
237 | 247 | ||
238 | 248 | ||
239 | /** | 249 | /** |
@@ -244,8 +254,9 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); | |||
244 | * @return status code | 254 | * @return status code |
245 | */ | 255 | */ |
246 | typedef enum GNUNET_GenericReturnValue | 256 | typedef enum GNUNET_GenericReturnValue |
247 | (*GNUNET_CONFIGURATION_Callback)(void *cls, | 257 | (*GNUNET_CONFIGURATION_Callback)( |
248 | const struct GNUNET_CONFIGURATION_Handle *cfg); | 258 | void *cls, |
259 | const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
249 | 260 | ||
250 | 261 | ||
251 | /** | 262 | /** |
@@ -260,9 +271,10 @@ typedef enum GNUNET_GenericReturnValue | |||
260 | * otherwise return value from @a cb. | 271 | * otherwise return value from @a cb. |
261 | */ | 272 | */ |
262 | enum GNUNET_GenericReturnValue | 273 | enum GNUNET_GenericReturnValue |
263 | GNUNET_CONFIGURATION_parse_and_run (const char *filename, | 274 | GNUNET_CONFIGURATION_parse_and_run ( |
264 | GNUNET_CONFIGURATION_Callback cb, | 275 | const char *filename, |
265 | void *cb_cls); | 276 | GNUNET_CONFIGURATION_Callback cb, |
277 | void *cb_cls); | ||
266 | 278 | ||
267 | /** | 279 | /** |
268 | * Enable extra diagnostics. Will produce more log output | 280 | * Enable extra diagnostics. Will produce more log output |
@@ -309,9 +321,10 @@ typedef void | |||
309 | * @param iter_cls closure for @a iter | 321 | * @param iter_cls closure for @a iter |
310 | */ | 322 | */ |
311 | void | 323 | void |
312 | GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | 324 | GNUNET_CONFIGURATION_iterate ( |
313 | GNUNET_CONFIGURATION_Iterator iter, | 325 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
314 | void *iter_cls); | 326 | GNUNET_CONFIGURATION_Iterator iter, |
327 | void *iter_cls); | ||
315 | 328 | ||
316 | 329 | ||
317 | /** | 330 | /** |
@@ -335,8 +348,9 @@ GNUNET_CONFIGURATION_iterate_sections ( | |||
335 | * @param section name of the section to remove | 348 | * @param section name of the section to remove |
336 | */ | 349 | */ |
337 | void | 350 | void |
338 | GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, | 351 | GNUNET_CONFIGURATION_remove_section ( |
339 | const char *section); | 352 | struct GNUNET_CONFIGURATION_Handle *cfg, |
353 | const char *section); | ||
340 | 354 | ||
341 | 355 | ||
342 | /** | 356 | /** |
@@ -596,10 +610,11 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
596 | * @param value value to set | 610 | * @param value value to set |
597 | */ | 611 | */ |
598 | void | 612 | void |
599 | GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, | 613 | GNUNET_CONFIGURATION_set_value_string ( |
600 | const char *section, | 614 | struct GNUNET_CONFIGURATION_Handle *cfg, |
601 | const char *option, | 615 | const char *section, |
602 | const char *value); | 616 | const char *option, |
617 | const char *value); | ||
603 | 618 | ||
604 | 619 | ||
605 | /** | 620 | /** |