aboutsummaryrefslogtreecommitdiff
path: root/src/util/configuration.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-11-10 17:36:11 +0100
committerChristian Grothoff <christian@grothoff.org>2018-11-10 17:36:11 +0100
commitb237fcbd7e189f755dd8b372398a0ea94255d090 (patch)
treecb5c453ea3b4b966bf30784a4200a1d2b32f622a /src/util/configuration.c
parent54f722729882247a318fbf686f2b2c31137ab72b (diff)
downloadgnunet-b237fcbd7e189f755dd8b372398a0ea94255d090.tar.gz
gnunet-b237fcbd7e189f755dd8b372398a0ea94255d090.zip
new convenience function to do operations on a configuration object to avoid repetitive configuration_create, _load and _destroy logic
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r--src/util/configuration.c35
1 files changed, 35 insertions, 0 deletions
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