2 This file is part of GNUnet.
3 (C) 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_configuration_lib.h
23 * @brief configuration API
25 * @author Christian Grothoff
28 #ifndef GNUNET_CONFIGURATION_LIB_H
29 #define GNUNET_CONFIGURATION_LIB_H
35 #if 0 /* keep Emacsens' auto-indent happy */
40 #include "gnunet_common.h"
41 #include "gnunet_time_lib.h"
44 * A configuration object.
46 struct GNUNET_CONFIGURATION_Handle;
49 * Create a new configuration object.
51 * @param component name of responsible component
53 struct GNUNET_CONFIGURATION_Handle *GNUNET_CONFIGURATION_create (void);
56 * Destroy configuration object.
58 void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);
61 * Load configuration. This function will first parse the
62 * defaults and then parse the specific configuration file
63 * to overwrite the defaults.
65 * @param filename name of the configuration file
66 * @return GNUNET_OK on success, GNUNET_SYSERR on error
68 int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
69 const char *filename);
72 * Parse a configuration file, add all of the options in the
73 * file to the configuration environment.
74 * @return GNUNET_OK on success, GNUNET_SYSERR on error
76 int GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
77 const char *filename);
80 * Write configuration file.
81 * @return GNUNET_OK on success, GNUNET_SYSERR on error
83 int GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
84 const char *filename);
87 * Test if there are configuration options that were
88 * changed since the last save.
89 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
91 int GNUNET_CONFIGURATION_is_dirty (struct GNUNET_CONFIGURATION_Handle *cfg);
94 * Get a configuration value that should be a number.
95 * @return GNUNET_OK on success, GNUNET_SYSERR on error
97 int GNUNET_CONFIGURATION_get_value_number (struct GNUNET_CONFIGURATION_Handle
98 *cfg, const char *section,
100 unsigned long long *number);
103 * Get a configuration value that should be a relative time.
105 * @param time set to the time value stored in the configuration
106 * @return GNUNET_OK on success, GNUNET_SYSERR on error
108 int GNUNET_CONFIGURATION_get_value_time (struct GNUNET_CONFIGURATION_Handle
109 *cfg, const char *section,
111 struct GNUNET_TIME_Relative *time);
114 * Test if we have a value for a particular option
115 * @return GNUNET_YES if so, GNUNET_NO if not.
117 int GNUNET_CONFIGURATION_have_value (struct GNUNET_CONFIGURATION_Handle *cfg,
118 const char *section, const char *option);
121 * Get a configuration value that should be a string.
122 * @param value will be set to a freshly allocated configuration
123 * value, or NULL if option is not specified
124 * @return GNUNET_OK on success, GNUNET_SYSERR on error
126 int GNUNET_CONFIGURATION_get_value_string (struct GNUNET_CONFIGURATION_Handle
127 *cfg, const char *section,
128 const char *option, char **value);
131 * Get a configuration value that should be the name of a file
134 * @param value will be set to a freshly allocated configuration
135 * value, or NULL if option is not specified
136 * @return GNUNET_OK on success, GNUNET_SYSERR on error
138 int GNUNET_CONFIGURATION_get_value_filename (struct
139 GNUNET_CONFIGURATION_Handle *cfg,
145 * Iterate over the set of filenames stored in a configuration value.
147 * @return number of filenames iterated over, -1 on error
149 int GNUNET_CONFIGURATION_iterate_value_filenames (struct
150 GNUNET_CONFIGURATION_Handle
154 GNUNET_FileNameCallback
158 * Get a configuration value that should be in a set of
161 * @param choices NULL-terminated list of legal values
162 * @param value will be set to an entry in the legal list,
163 * or NULL if option is not specified and no default given
164 * @return GNUNET_OK on success, GNUNET_SYSERR on error
166 int GNUNET_CONFIGURATION_get_value_choice (struct GNUNET_CONFIGURATION_Handle
167 *cfg, const char *section,
169 const char **choices,
173 * Get a configuration value that should be in a set of
176 * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR
178 int GNUNET_CONFIGURATION_get_value_yesno (struct GNUNET_CONFIGURATION_Handle
179 *cfg, const char *section,
183 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
184 * where either in the "PATHS" section or the environtment
185 * "FOO" is set to "DIRECTORY".
187 * @param old string to $-expand (will be freed!)
188 * @return $-expanded string
190 char *GNUNET_CONFIGURATION_expand_dollar (struct GNUNET_CONFIGURATION_Handle
194 * Set a configuration value that should be a number.
197 GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
201 unsigned long long number);
205 * Set a configuration value that should be a string.
209 GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
212 const char *option, const char *value);
215 * Remove a filename from a configuration value that
216 * represents a list of filenames
218 * @param value filename to remove
219 * @return GNUNET_OK on success,
220 * GNUNET_SYSERR if the filename is not in the list
222 int GNUNET_CONFIGURATION_remove_value_filename (struct
223 GNUNET_CONFIGURATION_Handle
230 * Append a filename to a configuration value that
231 * represents a list of filenames
233 * @param value filename to append
234 * @return GNUNET_OK on success,
235 * GNUNET_SYSERR if the filename already in the list
237 int GNUNET_CONFIGURATION_append_value_filename (struct
238 GNUNET_CONFIGURATION_Handle
239 *cfg, const char *section,
243 #if 0 /* keep Emacsens' auto-indent happy */