gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: Add function to return GNUnet's default


From: gnunet
Subject: [gnunet] branch master updated: Add function to return GNUnet's default configuration
Date: Tue, 14 Jul 2020 16:01:52 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 0f2ac01f3 Add function to return GNUnet's default configuration
0f2ac01f3 is described below

commit 0f2ac01f3d935435f9fa0e3d1fb7e038fb0c19fa
Author: Alessio Vanni <vannilla@firemail.cc>
AuthorDate: Fri Jul 3 22:37:42 2020 +0200

    Add function to return GNUnet's default configuration
    
    It's for convenience when applications call `GNUNET_OS_init', after which 
it's
    impossible to obtain GNUnet's configuration without manually checking the
    filesystem.
    
    With this function it's possible to get the configuration regardless of the
    state of the application.
---
 src/include/gnunet_configuration_lib.h | 12 ++++++++++
 src/util/configuration.c               | 40 ++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/src/include/gnunet_configuration_lib.h 
b/src/include/gnunet_configuration_lib.h
index 302429430..b5ceb5b94 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -100,6 +100,18 @@ GNUNET_CONFIGURATION_load_from (struct 
GNUNET_CONFIGURATION_Handle *cfg,
                                 const char *defaults_d);
 
 
+/**
+ * Return GNUnet's default configuration.  A new configuration is allocated
+ * each time and it's up to the caller to destroy it when done.  This function
+ * returns GNUnet's configuration even when #GNUNET_OS_init has been called
+ * with a value different from #GNUNET_OS_project_data_default.
+ *
+ * @return a freshly allocated configuration
+ */
+struct GNUNET_CONFIGURATION_Handle *
+GNUNET_CONFIGURATION_default(void);
+
+
 /**
  * Parse a configuration file, add all of the options in the
  * file to the configuration environment.
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 34ecc9e73..faee9e3bf 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -1810,4 +1810,44 @@ GNUNET_CONFIGURATION_load_from (struct 
GNUNET_CONFIGURATION_Handle *cfg,
 }
 
 
+/**
+ * Return GNUnet's default configuration.  A new configuration is allocated
+ * each time and it's up to the caller to destroy it when done.  This function
+ * returns GNUnet's configuration even when #GNUNET_OS_init has been called
+ * with a value different from #GNUNET_OS_project_data_default.
+ *
+ * @return a freshly allocated configuration
+ */
+struct GNUNET_CONFIGURATION_Handle *
+GNUNET_CONFIGURATION_default(void)
+{
+  const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
+  const struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default ();
+
+  GNUNET_OS_init(dpd);
+
+  struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
+  const char *xdg = getenv ("XDG_CONFIG_HOME");
+  char *cfgname = NULL;
+
+  if (NULL != xdg)
+    GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
+  else
+    cfgname = GNUNET_strdup (pd->user_config_file);
+
+  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgname)) {
+    GNUNET_OS_init (pd);
+    GNUNET_CONFIGURATION_destroy (cfg);
+    GNUNET_free (cfgname);
+    return NULL;
+  }
+
+  GNUNET_free (cfgname);
+
+  GNUNET_OS_init (pd);
+
+  return cfg;
+}
+
+
 /* end of configuration.c */

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]