aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_configuration_lib.h
blob: abbfe2eec05c47f8688349e979259ae048e75fa8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
     This file is part of GNUnet.
     (C) 2006, 2008, 2009 Christian Grothoff (and other contributing authors)

     GNUnet is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 2, or (at your
     option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/

/**
 * @file include/gnunet_configuration_lib.h
 * @brief configuration API
 *
 * @author Christian Grothoff
 */

#ifndef GNUNET_CONFIGURATION_LIB_H
#define GNUNET_CONFIGURATION_LIB_H


#ifdef __cplusplus
extern "C"
{
#if 0                           /* keep Emacsens' auto-indent happy */
}
#endif
#endif

#include "gnunet_common.h"
#include "gnunet_time_lib.h"

/**
 * A configuration object.
 */
struct GNUNET_CONFIGURATION_Handle;

/**
 * Create a new configuration object.
 *
 * @param component name of responsible component
 */
struct GNUNET_CONFIGURATION_Handle *GNUNET_CONFIGURATION_create (void);

/**
 * Destroy configuration object.
 */
void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg);

/**
 * Load configuration.  This function will first parse the
 * defaults and then parse the specific configuration file
 * to overwrite the defaults.
 *
 * @param filename name of the configuration file
 * @return GNUNET_OK on success, GNUNET_SYSERR on error
 */
int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
                               const char *filename);

/**
 * Parse a configuration file, add all of the options in the
 * file to the configuration environment.
 * @return GNUNET_OK on success, GNUNET_SYSERR on error
 */
int GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
                                const char *filename);

/**
 * Write configuration file.
 * @return GNUNET_OK on success, GNUNET_SYSERR on error
 */
int GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
                                const char *filename);

/**
 * Test if there are configuration options that were
 * changed since the last save.
 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
 */
int GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg);

/**
 * Get a configuration value that should be a number.
 * @return GNUNET_OK on success, GNUNET_SYSERR on error
 */
int GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
                                           *cfg, const char *section,
                                           const char *option,
                                           unsigned long long *number);

/**
 * Get a configuration value that should be a relative time.
 *
 * @param time set to the time value stored in the configuration
 * @return GNUNET_OK on success, GNUNET_SYSERR on error
 */
int GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
					 *cfg, const char *section,
					 const char *option,
					 struct GNUNET_TIME_Relative *time);

/**
 * Test if we have a value for a particular option
 * @return GNUNET_YES if so, GNUNET_NO if not.
 */
int GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                     const char *section, const char *option);

/**
 * Get a configuration value that should be a string.
 * @param value will be set to a freshly allocated configuration
 *        value, or NULL if option is not specified
 * @return GNUNET_OK on success, GNUNET_SYSERR on error
 */
int GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
                                           *cfg, const char *section,
                                           const char *option, char **value);

/**
 * Get a configuration value that should be the name of a file
 * or directory.
 *
 * @param value will be set to a freshly allocated configuration
 *        value, or NULL if option is not specified
 * @return GNUNET_OK on success, GNUNET_SYSERR on error
 */
int GNUNET_CONFIGURATION_get_value_filename (const struct
                                             GNUNET_CONFIGURATION_Handle *cfg,
                                             const char *section,
                                             const char *option,
                                             char **value);

/**
 * Iterate over the set of filenames stored in a configuration value.
 *
 * @return number of filenames iterated over, -1 on error
 */
int GNUNET_CONFIGURATION_iterate_value_filenames (const struct
                                                  GNUNET_CONFIGURATION_Handle
                                                  *cfg,
                                                  const char *section,
                                                  const char *option,
                                                  GNUNET_FileNameCallback
                                                  cb, void *cls);

/**
 * Get a configuration value that should be in a set of
 * predefined strings
 *
 * @param choices NULL-terminated list of legal values
 * @param value will be set to an entry in the legal list,
 *        or NULL if option is not specified and no default given
 * @return GNUNET_OK on success, GNUNET_SYSERR on error
 */
int GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
                                           *cfg, const char *section,
                                           const char *option,
                                           const char **choices,
                                           const char **value);

/**
 * Get a configuration value that should be in a set of
 * "YES" or "NO".
 *
 * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR
 */
int GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
                                          *cfg, const char *section,
                                          const char *option);

/**
 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
 * where either in the "PATHS" section or the environtment
 * "FOO" is set to "DIRECTORY".

 * @param old string to $-expand (will be freed!)
 * @return $-expanded string
 */
char *GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
                                          *cfg, char *old);

/**
 * Set a configuration value that should be a number.
 */
void
GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
                                       *cfg,
                                       const char *section,
                                       const char *option,
                                       unsigned long long number);


/**
 * Set a configuration value that should be a string.
 * @param value
 */
void
GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
                                       *cfg,
                                       const char *section,
                                       const char *option, const char *value);

/**
 * Remove a filename from a configuration value that
 * represents a list of filenames
 *
 * @param value filename to remove
 * @return GNUNET_OK on success,
 *         GNUNET_SYSERR if the filename is not in the list
 */
int GNUNET_CONFIGURATION_remove_value_filename (struct
                                                GNUNET_CONFIGURATION_Handle
                                                *cfg,
                                                const char *section,
                                                const char *option,
                                                const char *value);

/**
 * Append a filename to a configuration value that
 * represents a list of filenames
 *
 * @param value filename to append
 * @return GNUNET_OK on success,
 *         GNUNET_SYSERR if the filename already in the list
 */
int GNUNET_CONFIGURATION_append_value_filename (struct
                                                GNUNET_CONFIGURATION_Handle
                                                *cfg, const char *section,
                                                const char *option,
                                                const char *value);

#if 0                           /* keep Emacsens' auto-indent happy */
{
#endif
#ifdef __cplusplus
}
#endif

#endif