tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / util / configuration.c
index 312e0acd36f0e114c317afe1b3b96be5ba28a614..a38438ba833c6ebd58cd4f6534683a5dc99ac3f8 100644 (file)
@@ -14,6 +14,8 @@
 
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
@@ -137,6 +139,41 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
 }
 
 
+/**
+ * Parse a configuration file @a filename and run the function
+ * @a cb with the resulting configuration object. Then free the
+ * configuration object and return the status value from @a cb.
+ *
+ * @param filename configuration to parse, NULL for "default"
+ * @param cb function to run
+ * @param cb_cls closure for @a cb
+ * @return #GNUNET_SYSERR if parsing the configuration failed,
+ *   otherwise return value from @a cb.
+ */
+int
+GNUNET_CONFIGURATION_parse_and_run (const char *filename,
+                                   GNUNET_CONFIGURATION_Callback cb,
+                                   void *cb_cls)
+{
+  struct GNUNET_CONFIGURATION_Handle *cfg;
+  int ret;
+
+  cfg = GNUNET_CONFIGURATION_create ();
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_load (cfg,
+                                 filename))
+  {
+    GNUNET_break (0);
+    GNUNET_CONFIGURATION_destroy (cfg);
+    return GNUNET_SYSERR;
+  }
+  ret = cb (cb_cls,
+           cfg);
+  GNUNET_CONFIGURATION_destroy (cfg);
+  return ret;
+}
+
+
 /**
  * De-serializes configuration
  *
@@ -910,7 +947,7 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
                   number,
                   dummy))
     return GNUNET_SYSERR;
-  return GNUNET_OK;  
+  return GNUNET_OK;
 }
 
 
@@ -931,7 +968,7 @@ GNUNET_CONFIGURATION_get_value_float  (const struct GNUNET_CONFIGURATION_Handle
 {
   struct ConfigEntry *e;
   char dummy[2];
-  
+
   if (NULL == (e = find_entry (cfg, section, option)))
     return GNUNET_SYSERR;
   if (NULL == e->val)
@@ -1713,7 +1750,9 @@ GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
                                const char *defaults_d)
 {
   if (GNUNET_SYSERR ==
-      GNUNET_DISK_directory_scan (defaults_d, &parse_configuration_file, cfg))
+      GNUNET_DISK_directory_scan (defaults_d,
+                                  &parse_configuration_file,
+                                  cfg))
     return GNUNET_SYSERR;       /* no configuration at all found */
   return GNUNET_OK;
 }