src/testing/testing.c
src/topology/friends.c
src/topology/gnunet-daemon-topology.c
+src/transport/gnunet-communicator-unix.c
src/transport/gnunet-helper-transport-bluetooth.c
src/transport/gnunet-helper-transport-wlan.c
src/transport/gnunet-helper-transport-wlan-dummy.c
+src/transport/gnunet-service-tng.c
src/transport/gnunet-service-transport_ats.c
src/transport/gnunet-service-transport.c
src/transport/gnunet-service-transport_hello.c
/*
This file is part of GNUnet.
- Copyright (C) 2006, 2008, 2009 GNUnet e.V.
+ Copyright (C) 2006, 2008, 2009, 2018 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);
+/**
+ * Signature of a function to be run with a configuration.
+ *
+ * @param cls closure
+ * @param cfg the configuration
+ * @return status code
+ */
+typedef int
+(*GNUNET_CONFIGURATION_Callback)(void *cls,
+ const 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);
+
+
/**
* Function to iterate over options.
*
}
+/**
+ * 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
*
/**
- * Remove the directory given under @a option in
- * section [PATHS] in configuration under @a cfg_filename
+ * Helper function for #GNUNET_DISK_purge_cfg_dir.
*
- * @param cfg_filename configuration file to parse
- * @param option option with the dir name to purge
+ * @param cls a `const char *` with the option to purge
+ * @param cfg our configuration
+ * @return #GNUNET_OK on success
*/
-void
-GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
- const char *option)
+static int
+purge_cfg_dir (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- struct GNUNET_CONFIGURATION_Handle *cfg;
+ const char *option = cls;
char *tmpname;
-
- cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_load (cfg,
- cfg_filename))
- {
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- return;
- }
+
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
"PATHS",
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"PATHS",
option);
- GNUNET_CONFIGURATION_destroy (cfg);
- return;
+ return GNUNET_NO;
}
- GNUNET_CONFIGURATION_destroy (cfg);
if (GNUNET_SYSERR ==
GNUNET_DISK_directory_remove (tmpname))
{
"remove",
tmpname);
GNUNET_free (tmpname);
- return;
+ return GNUNET_OK;
}
GNUNET_free (tmpname);
+ return GNUNET_OK;
}
+/**
+ * Remove the directory given under @a option in
+ * section [PATHS] in configuration under @a cfg_filename
+ *
+ * @param cfg_filename configuration file to parse
+ * @param option option with the dir name to purge
+ */
+void
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
+ const char *option)
+{
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONFIGURATION_parse_and_run (cfg_filename,
+ &purge_cfg_dir,
+ (void *) option));
+}
+
/* end of disk.c */
opt_cfg_filename = GNUNET_strdup (cfg_filename);
if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_filename))
{
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg,
- opt_cfg_filename))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_load (cfg,
+ opt_cfg_filename))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Malformed configuration file `%s', exit ...\n"),
}
else
{
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg,
- NULL))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_load (cfg,
+ NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Malformed configuration, exit ...\n"));