aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--po/POTFILES.in2
-rw-r--r--src/include/gnunet_configuration_lib.h31
-rw-r--r--src/util/configuration.c35
-rw-r--r--src/util/disk.c51
-rw-r--r--src/util/service.c10
5 files changed, 102 insertions, 27 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in
index caf7353be..54fe7b4e7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -398,9 +398,11 @@ src/testing/list-keys.c
398src/testing/testing.c 398src/testing/testing.c
399src/topology/friends.c 399src/topology/friends.c
400src/topology/gnunet-daemon-topology.c 400src/topology/gnunet-daemon-topology.c
401src/transport/gnunet-communicator-unix.c
401src/transport/gnunet-helper-transport-bluetooth.c 402src/transport/gnunet-helper-transport-bluetooth.c
402src/transport/gnunet-helper-transport-wlan.c 403src/transport/gnunet-helper-transport-wlan.c
403src/transport/gnunet-helper-transport-wlan-dummy.c 404src/transport/gnunet-helper-transport-wlan-dummy.c
405src/transport/gnunet-service-tng.c
404src/transport/gnunet-service-transport_ats.c 406src/transport/gnunet-service-transport_ats.c
405src/transport/gnunet-service-transport.c 407src/transport/gnunet-service-transport.c
406src/transport/gnunet-service-transport_hello.c 408src/transport/gnunet-service-transport_hello.c
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index e3eefa18d..ec3d12738 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2006, 2008, 2009 GNUnet e.V. 3 Copyright (C) 2006, 2008, 2009, 2018 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -191,6 +191,35 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
191 191
192 192
193/** 193/**
194 * Signature of a function to be run with a configuration.
195 *
196 * @param cls closure
197 * @param cfg the configuration
198 * @return status code
199 */
200typedef int
201(*GNUNET_CONFIGURATION_Callback)(void *cls,
202 const struct GNUNET_CONFIGURATION_Handle *cfg);
203
204
205/**
206 * Parse a configuration file @a filename and run the function
207 * @a cb with the resulting configuration object. Then free the
208 * configuration object and return the status value from @a cb.
209 *
210 * @param filename configuration to parse, NULL for "default"
211 * @param cb function to run
212 * @param cb_cls closure for @a cb
213 * @return #GNUNET_SYSERR if parsing the configuration failed,
214 * otherwise return value from @a cb.
215 */
216int
217GNUNET_CONFIGURATION_parse_and_run (const char *filename,
218 GNUNET_CONFIGURATION_Callback cb,
219 void *cb_cls);
220
221
222/**
194 * Function to iterate over options. 223 * Function to iterate over options.
195 * 224 *
196 * @param cls closure 225 * @param cls closure
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 41eb3188d..a8e492a32 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -138,6 +138,41 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
138 138
139 139
140/** 140/**
141 * Parse a configuration file @a filename and run the function
142 * @a cb with the resulting configuration object. Then free the
143 * configuration object and return the status value from @a cb.
144 *
145 * @param filename configuration to parse, NULL for "default"
146 * @param cb function to run
147 * @param cb_cls closure for @a cb
148 * @return #GNUNET_SYSERR if parsing the configuration failed,
149 * otherwise return value from @a cb.
150 */
151int
152GNUNET_CONFIGURATION_parse_and_run (const char *filename,
153 GNUNET_CONFIGURATION_Callback cb,
154 void *cb_cls)
155{
156 struct GNUNET_CONFIGURATION_Handle *cfg;
157 int ret;
158
159 cfg = GNUNET_CONFIGURATION_create ();
160 if (GNUNET_OK !=
161 GNUNET_CONFIGURATION_load (cfg,
162 filename))
163 {
164 GNUNET_break (0);
165 GNUNET_CONFIGURATION_destroy (cfg);
166 return GNUNET_SYSERR;
167 }
168 ret = cb (cb_cls,
169 cfg);
170 GNUNET_CONFIGURATION_destroy (cfg);
171 return ret;
172}
173
174
175/**
141 * De-serializes configuration 176 * De-serializes configuration
142 * 177 *
143 * @param cfg configuration to update 178 * @param cfg configuration to update
diff --git a/src/util/disk.c b/src/util/disk.c
index e0227be70..dc38d1137 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -2668,28 +2668,19 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
2668 2668
2669 2669
2670/** 2670/**
2671 * Remove the directory given under @a option in 2671 * Helper function for #GNUNET_DISK_purge_cfg_dir.
2672 * section [PATHS] in configuration under @a cfg_filename
2673 * 2672 *
2674 * @param cfg_filename configuration file to parse 2673 * @param cls a `const char *` with the option to purge
2675 * @param option option with the dir name to purge 2674 * @param cfg our configuration
2675 * @return #GNUNET_OK on success
2676 */ 2676 */
2677void 2677static int
2678GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, 2678purge_cfg_dir (void *cls,
2679 const char *option) 2679 const struct GNUNET_CONFIGURATION_Handle *cfg)
2680{ 2680{
2681 struct GNUNET_CONFIGURATION_Handle *cfg; 2681 const char *option = cls;
2682 char *tmpname; 2682 char *tmpname;
2683 2683
2684 cfg = GNUNET_CONFIGURATION_create ();
2685 if (GNUNET_OK !=
2686 GNUNET_CONFIGURATION_load (cfg,
2687 cfg_filename))
2688 {
2689 GNUNET_break (0);
2690 GNUNET_CONFIGURATION_destroy (cfg);
2691 return;
2692 }
2693 if (GNUNET_OK != 2684 if (GNUNET_OK !=
2694 GNUNET_CONFIGURATION_get_value_filename (cfg, 2685 GNUNET_CONFIGURATION_get_value_filename (cfg,
2695 "PATHS", 2686 "PATHS",
@@ -2699,10 +2690,8 @@ GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
2699 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 2690 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2700 "PATHS", 2691 "PATHS",
2701 option); 2692 option);
2702 GNUNET_CONFIGURATION_destroy (cfg); 2693 return GNUNET_NO;
2703 return;
2704 } 2694 }
2705 GNUNET_CONFIGURATION_destroy (cfg);
2706 if (GNUNET_SYSERR == 2695 if (GNUNET_SYSERR ==
2707 GNUNET_DISK_directory_remove (tmpname)) 2696 GNUNET_DISK_directory_remove (tmpname))
2708 { 2697 {
@@ -2710,11 +2699,29 @@ GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
2710 "remove", 2699 "remove",
2711 tmpname); 2700 tmpname);
2712 GNUNET_free (tmpname); 2701 GNUNET_free (tmpname);
2713 return; 2702 return GNUNET_OK;
2714 } 2703 }
2715 GNUNET_free (tmpname); 2704 GNUNET_free (tmpname);
2705 return GNUNET_OK;
2716} 2706}
2717 2707
2718 2708
2709/**
2710 * Remove the directory given under @a option in
2711 * section [PATHS] in configuration under @a cfg_filename
2712 *
2713 * @param cfg_filename configuration file to parse
2714 * @param option option with the dir name to purge
2715 */
2716void
2717GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
2718 const char *option)
2719{
2720 GNUNET_break (GNUNET_OK ==
2721 GNUNET_CONFIGURATION_parse_and_run (cfg_filename,
2722 &purge_cfg_dir,
2723 (void *) option));
2724}
2725
2719 2726
2720/* end of disk.c */ 2727/* end of disk.c */
diff --git a/src/util/service.c b/src/util/service.c
index ea34abc6c..b61168570 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1815,8 +1815,9 @@ GNUNET_SERVICE_run_ (int argc,
1815 opt_cfg_filename = GNUNET_strdup (cfg_filename); 1815 opt_cfg_filename = GNUNET_strdup (cfg_filename);
1816 if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_filename)) 1816 if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_filename))
1817 { 1817 {
1818 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, 1818 if (GNUNET_SYSERR ==
1819 opt_cfg_filename)) 1819 GNUNET_CONFIGURATION_load (cfg,
1820 opt_cfg_filename))
1820 { 1821 {
1821 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1822 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1822 _("Malformed configuration file `%s', exit ...\n"), 1823 _("Malformed configuration file `%s', exit ...\n"),
@@ -1826,8 +1827,9 @@ GNUNET_SERVICE_run_ (int argc,
1826 } 1827 }
1827 else 1828 else
1828 { 1829 {
1829 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, 1830 if (GNUNET_SYSERR ==
1830 NULL)) 1831 GNUNET_CONFIGURATION_load (cfg,
1832 NULL))
1831 { 1833 {
1832 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1834 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1833 _("Malformed configuration, exit ...\n")); 1835 _("Malformed configuration, exit ...\n"));