aboutsummaryrefslogtreecommitdiff
path: root/src/util/configuration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r--src/util/configuration.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 7ed87cc1e..26beacaff 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -286,7 +286,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
286 line_orig = NULL; 286 line_orig = NULL;
287 while (r_bytes < size) 287 while (r_bytes < size)
288 { 288 {
289 GNUNET_free_non_null (line_orig); 289 GNUNET_free (line_orig);
290 /* fgets-like behaviour on buffer */ 290 /* fgets-like behaviour on buffer */
291 to_read = size - r_bytes; 291 to_read = size - r_bytes;
292 pos = memchr (&mem[r_bytes], '\n', to_read); 292 pos = memchr (&mem[r_bytes], '\n', to_read);
@@ -404,7 +404,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
404 ret = GNUNET_SYSERR; 404 ret = GNUNET_SYSERR;
405 break; 405 break;
406 } 406 }
407 GNUNET_free_non_null (line_orig); 407 GNUNET_free (line_orig);
408 GNUNET_free (section); 408 GNUNET_free (section);
409 GNUNET_assert ((GNUNET_OK != ret) || (r_bytes == size)); 409 GNUNET_assert ((GNUNET_OK != ret) || (r_bytes == size));
410 return ret; 410 return ret;
@@ -734,7 +734,7 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
734 { 734 {
735 spos->entries = ent->next; 735 spos->entries = ent->next;
736 GNUNET_free (ent->key); 736 GNUNET_free (ent->key);
737 GNUNET_free_non_null (ent->val); 737 GNUNET_free (ent->val);
738 GNUNET_free (ent); 738 GNUNET_free (ent);
739 cfg->dirty = GNUNET_YES; 739 cfg->dirty = GNUNET_YES;
740 } 740 }
@@ -926,13 +926,13 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
926 { 926 {
927 if (NULL == value) 927 if (NULL == value)
928 { 928 {
929 GNUNET_free_non_null (e->val); 929 GNUNET_free (e->val);
930 e->val = NULL; 930 e->val = NULL;
931 } 931 }
932 else 932 else
933 { 933 {
934 nv = GNUNET_strdup (value); 934 nv = GNUNET_strdup (value);
935 GNUNET_free_non_null (e->val); 935 GNUNET_free (e->val);
936 e->val = nv; 936 e->val = nv;
937 } 937 }
938 return; 938 return;
@@ -1383,7 +1383,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1383 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1); 1383 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
1384 strcpy (result, prefix); 1384 strcpy (result, prefix);
1385 strcat (result, post); 1385 strcat (result, post);
1386 GNUNET_free_non_null (def); 1386 GNUNET_free (def);
1387 GNUNET_free (prefix); 1387 GNUNET_free (prefix);
1388 GNUNET_free (orig); 1388 GNUNET_free (orig);
1389 return result; 1389 return result;
@@ -1810,4 +1810,45 @@ GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
1810} 1810}
1811 1811
1812 1812
1813/**
1814 * Return GNUnet's default configuration. A new configuration is allocated
1815 * each time and it's up to the caller to destroy it when done. This function
1816 * returns GNUnet's configuration even when #GNUNET_OS_init has been called
1817 * with a value different from #GNUNET_OS_project_data_default.
1818 *
1819 * @return a freshly allocated configuration
1820 */
1821struct GNUNET_CONFIGURATION_Handle *
1822GNUNET_CONFIGURATION_default (void)
1823{
1824 const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
1825 const struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default ();
1826
1827 GNUNET_OS_init (dpd);
1828
1829 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
1830 const char *xdg = getenv ("XDG_CONFIG_HOME");
1831 char *cfgname = NULL;
1832
1833 if (NULL != xdg)
1834 GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
1835 else
1836 cfgname = GNUNET_strdup (pd->user_config_file);
1837
1838 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgname))
1839 {
1840 GNUNET_OS_init (pd);
1841 GNUNET_CONFIGURATION_destroy (cfg);
1842 GNUNET_free (cfgname);
1843 return NULL;
1844 }
1845
1846 GNUNET_free (cfgname);
1847
1848 GNUNET_OS_init (pd);
1849
1850 return cfg;
1851}
1852
1853
1813/* end of configuration.c */ 1854/* end of configuration.c */