VLC  4.0.0-dev
vlc_configuration.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_configuration.h : configuration management module
3  * This file describes the programming interface for the configuration module.
4  * It includes functions allowing to declare, get or set configuration options.
5  *****************************************************************************
6  * Copyright (C) 1999-2006 VLC authors and VideoLAN
7  *
8  * Authors: Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 
25 #ifndef VLC_CONFIGURATION_H
26 #define VLC_CONFIGURATION_H 1
27 
28 /**
29  * \defgroup config User settings
30  * \ingroup interface
31  * VLC provides a simple name-value dictionary for user settings.
32  *
33  * Those settings are per-user per-system - they are shared by all LibVLC
34  * instances in a single process, and potentially other processes as well.
35  *
36  * Each name-value pair is called a configuration item.
37  * @{
38  */
39 
40 /**
41  * \file
42  * This file describes the programming interface for the configuration module.
43  * It includes functions allowing to declare, get or set configuration options.
44  */
45 
46 #include <sys/types.h> /* for ssize_t */
47 
48 # ifdef __cplusplus
49 extern "C" {
50 # endif
51 
52 struct config_category_t
53 {
54  int i_id;
55  const char *psz_name;
56  const char *psz_help;
57 };
58 
59 typedef union
60 {
61  char *psz;
62  int64_t i;
63  float f;
65 
66 typedef int (*vlc_string_list_cb)(const char *, char ***, char ***);
67 typedef int (*vlc_integer_list_cb)(const char *, int64_t **, char ***);
68 
69 /**
70  * Configuration item
71  *
72  * This is the internal reprensation of a configuration item.
73  * See also config_FindConfig().
74  */
75 struct module_config_t
76 {
77  uint8_t i_type; /**< Configuration type */
78  char i_short; /**< Optional short option name */
79  unsigned b_internal:1; /**< Hidden from preferences and help */
80  unsigned b_unsaveable:1; /**< Not stored in configuration */
81  unsigned b_safe:1; /**< Safe for web plugins and playlist files */
82  unsigned b_removed:1; /**< Obsolete */
83 
84  const char *psz_type; /**< Configuration subtype */
85  const char *psz_name; /**< Option name */
86  const char *psz_text; /**< Short comment on the configuration option */
87  const char *psz_longtext; /**< Long comment on the configuration option */
88 
89  module_value_t value; /**< Current value */
90  module_value_t orig; /**< Default value */
91  module_value_t min; /**< Minimum value (for scalars only) */
92  module_value_t max; /**< Maximum value (for scalars only) */
93 
94  /* Values list */
95  uint16_t list_count; /**< Choices count */
96  union
97  {
98  const char **psz; /**< Table of possible string choices */
99  const int *i; /**< Table of possible integer choices */
100  } list; /**< Possible choices */
101  const char **list_text; /**< Human-readable names for list values */
102  void *owner; /**< Origin run-time linker module handle */
103 };
104 
105 /**
106  * Gets a configuration item type
107  *
108  * This function checks the type of configuration item by name.
109  * \param name Configuration item name
110  * \return The configuration item type or 0 if not found.
111  */
112 VLC_API int config_GetType(const char *name) VLC_USED;
113 
114 /**
115  * Gets an integer configuration item.
116  *
117  * This function retrieves the current value of a configuration item of
118  * integral type (\ref CONFIG_ITEM_INTEGER and \ref CONFIG_ITEM_BOOL).
119  *
120  * \warning The behaviour is undefined if the configuration item exists but is
121  * not of integer or boolean type.
122  *
123  * \param name Configuration item name
124  * \return The configuration item value or -1 if not found.
125  * \bug A legitimate integer value of -1 cannot be distinguished from an error.
126  */
127 VLC_API int64_t config_GetInt(const char *name) VLC_USED;
128 
129 /**
130  * Sets an integer configuration item.
131  *
132  * This function changes the current value of a configuration item of
133  * integral type (\ref CONFIG_ITEM_INTEGER and \ref CONFIG_ITEM_BOOL).
134  *
135  * \warning The behaviour is undefined if the configuration item exists but is
136  * not of integer or boolean type.
137  *
138  * \note If no configuration item by the specified exist, the function has no
139  * effects.
140  *
141  * \param name Configuration item name
142  * \param val New value
143  */
144 VLC_API void config_PutInt(const char *name, int64_t val);
145 
146 /**
147  * Gets an floating point configuration item.
148  *
149  * This function retrieves the current value of a configuration item of
150  * floating point type (\ref CONFIG_ITEM_FLOAT).
151  *
152  * \warning The behaviour is undefined if the configuration item exists but is
153  * not of floating point type.
154  *
155  * \param name Configuration item name
156  * \return The configuration item value or -1 if not found.
157  * \bug A legitimate floating point value of -1 cannot be distinguished from an
158  * error.
159  */
160 VLC_API float config_GetFloat(const char *name) VLC_USED;
161 
162 /**
163  * Sets an integer configuration item.
164  *
165  * This function changes the current value of a configuration item of
166  * integral type (\ref CONFIG_ITEM_FLOAT).
167  *
168  * \warning The behaviour is undefined if the configuration item exists but is
169  * not of floating point type.
170  *
171  * \note If no configuration item by the specified exist, the function has no
172  * effects.
173  *
174  * \param name Configuration item name
175  * \param val New value
176  */
177 VLC_API void config_PutFloat(const char *name, float val);
178 
179 /**
180  * Gets an string configuration item.
181  *
182  * This function retrieves the current value of a configuration item of
183  * string type (\ref CONFIG_ITEM_STRING).
184  *
185  * \note The caller must free() the returned pointer (if non-NULL), which is a
186  * duplicate of the current value. It is not safe to return a pointer to the
187  * current value internally as it can be modified at any time by any other
188  * thread.
189  *
190  * \warning The behaviour is undefined if the configuration item exists but is
191  * not of string type.
192  *
193  * \param name Configuration item name
194  * \return Normally, a heap-allocated copy of the configuration item value.
195  * If the value is the empty string, if the configuration does not exist,
196  * or if an error occurs, NULL is returned.
197  * \bug The empty string value cannot be distinguished from an error.
198  */
199 VLC_API char *config_GetPsz(const char *name) VLC_USED VLC_MALLOC;
200 
201 /**
202  * Sets an string configuration item.
203  *
204  * This function changes the current value of a configuration item of
205  * string type (e.g. \ref CONFIG_ITEM_STRING).
206  *
207  * \warning The behaviour is undefined if the configuration item exists but is
208  * not of a string type.
209  *
210  * \note If no configuration item by the specified exist, the function has no
211  * effects.
212  *
213  * \param name Configuration item name
214  * \param val New value (will be copied)
215  * \bug This function allocates memory but errors cannot be detected.
216  */
217 VLC_API void config_PutPsz(const char *name, const char *val);
218 
219 /**
220  * Enumerates integer configuration choices.
221  *
222  * Determines a list of suggested values for an integer configuration item.
223  * \param values pointer to a table of integer values [OUT]
224  * \param texts pointer to a table of descriptions strings [OUT]
225  * \return number of choices, or -1 on error
226  * \note the caller is responsible for calling free() on all descriptions and
227  * on both tables. In case of error, both pointers are set to NULL.
228  */
229 VLC_API ssize_t config_GetIntChoices(const char *, int64_t **values,
230  char ***texts) VLC_USED;
231 
232 /**
233  * Determines a list of suggested values for a string configuration item.
234  * \param values pointer to a table of value strings [OUT]
235  * \param texts pointer to a table of descriptions strings [OUT]
236  * \return number of choices, or -1 on error
237  * \note the caller is responsible for calling free() on all values, on all
238  * descriptions and on both tables.
239  * In case of error, both pointers are set to NULL.
240  */
241 VLC_API ssize_t config_GetPszChoices(const char *,
242  char ***values, char ***texts) VLC_USED;
243 
245 #define config_SaveConfigFile(a) config_SaveConfigFile(VLC_OBJECT(a))
247 /**
248  * Resets the configuration.
249  *
250  * This function resets all configuration items to their respective
251  * compile-time default value.
252  */
253 VLC_API void config_ResetAll(void);
254 
255 /**
256  * Looks up a configuration item.
257  *
258  * This function looks for the internal representation of a configuration item.
259  * Where possible, this should be avoided in favor of more specific function
260  * calls.
261  *
262  * \param name Configuration item name
263  * \return The internal structure, or NULL if not found.
264  */
266 
267 /**
268  * System directory identifiers
269  */
270 typedef enum vlc_system_dir
271 {
272  VLC_PKG_DATA_DIR, /**< Package-specific architecture-independent read-only
273  data directory (e.g. /usr/local/data/vlc). */
274  VLC_PKG_LIB_DIR, /**< Package-specific architecture-dependent read-only
275  data directory (e.g. /usr/local/lib/vlc). */
276  VLC_PKG_LIBEXEC_DIR, /**< Package-specific executable read-only directory
277  (e.g. /usr/local/libexec/vlc). */
279  VLC_SYSDATA_DIR, /**< Global architecture-independent read-only
280  data directory (e.g. /usr/local/data).
281  Available only on some platforms. */
282  VLC_LIB_DIR, /**< Global architecture-dependent read-only directory
283  (e.g. /usr/local/lib). */
284  VLC_LIBEXEC_DIR, /**< Global executable read-only directory
285  (e.g. /usr/local/libexec). */
287  VLC_LOCALE_DIR, /**< Base directory for package read-only locale data. */
289 
290 /**
291  * Gets an installation directory.
292  *
293  * This function determines one of the installation directory.
294  *
295  * @param dir identifier of the directory (see \ref vlc_sysdir_t)
296  * @param filename name of a file or other object within the directory
297  * (or NULL to obtain the plain directory)
298  *
299  * @return a heap-allocated string (use free() to release it), or NULL on error
300  */
301 VLC_API char *config_GetSysPath(vlc_sysdir_t dir, const char *filename)
302 VLC_USED VLC_MALLOC;
303 
304 typedef enum vlc_user_dir
305 {
306  VLC_HOME_DIR, /* User's home */
307  VLC_CONFIG_DIR, /* VLC-specific configuration directory */
308  VLC_USERDATA_DIR, /* VLC-specific data directory */
309  VLC_CACHE_DIR, /* VLC-specific user cached data directory */
310  /* Generic directories (same as XDG) */
311  VLC_DESKTOP_DIR=0x80,
320 
322 
323 VLC_API void config_AddIntf(const char *);
324 VLC_API void config_RemoveIntf(const char *);
325 VLC_API bool config_ExistIntf(const char *) VLC_USED;
326 
327 /****************************************************************************
328  * config_chain_t:
329  ****************************************************************************/
330 struct config_chain_t
331 {
332  config_chain_t *p_next; /**< Pointer on the next config_chain_t element */
334  char *psz_name; /**< Option name */
335  char *psz_value; /**< Option value */
336 };
337 
338 /**
339  * This function will
340  * - create all options in the array ppsz_options (var_Create).
341  * - parse the given linked list of config_chain_t and set the value (var_Set).
342  *
343  * The option names will be created by adding the psz_prefix prefix.
344  */
345 VLC_API void config_ChainParse( vlc_object_t *, const char *psz_prefix, const char *const *ppsz_options, const config_chain_t * );
346 #define config_ChainParse( a, b, c, d ) config_ChainParse( VLC_OBJECT(a), b, c, d )
348 /**
349  * This function will parse a configuration string (psz_opts) and
350  * - set all options for this module in a chained list (*pp_cfg)
351  * - returns a pointer on the next module if any.
352  *
353  * The string format is
354  * module{option=*,option=*}
355  *
356  * The options values are unescaped using config_StringUnescape.
357  */
358 VLC_API const char *config_ChainParseOptions( config_chain_t **pp_cfg, const char *ppsz_opts );
359 
360 /**
361  * This function will parse a configuration string (psz_string) and
362  * - set the module name (*ppsz_name)
363  * - set all options for this module in a chained list (*pp_cfg)
364  * - returns a pointer on the next module if any.
365  *
366  * The string format is
367  * module{option=*,option=*}[:modulenext{option=*,...}]
368  *
369  * The options values are unescaped using config_StringUnescape.
370  */
371 VLC_API char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg, const char *psz_string ) VLC_USED VLC_MALLOC;
372 
373 /**
374  * This function will release a linked list of config_chain_t
375  * (Including the head)
376  */
378 
379 /**
380  * This function will duplicate a linked list of config_chain_t
381  */
383 
384 /**
385  * This function will unescape a string in place and will return a pointer on
386  * the given string.
387  * No memory is allocated by it (unlike config_StringEscape).
388  * If NULL is given as parameter nothing will be done (NULL will be returned).
389  *
390  * The following sequences will be unescaped (only one time):
391  * \\ \' and \"
392  */
393 VLC_API char * config_StringUnescape( char *psz_string );
394 
395 /**
396  * This function will escape a string that can be unescaped by
397  * config_StringUnescape.
398  * The returned value is allocated by it. You have to free it once you
399  * do not need it anymore (unlike config_StringUnescape).
400  * If NULL is given as parameter nothing will be done (NULL will be returned).
401  *
402  * The escaped characters are ' " and \
403  */
404 VLC_API char * config_StringEscape( const char *psz_string ) VLC_USED VLC_MALLOC;
405 
406 # ifdef __cplusplus
407 }
408 # endif
409 
410 /** @} */
411 
412 #endif /* _VLC_CONFIGURATION_H */
int i_id
Definition: vlc_configuration.h:55
void config_ResetAll(void)
Resets the configuration.
Definition: core.c:487
char * config_GetUserDir(vlc_userdir_t)
Definition: specific.c:273
Package-specific executable read-only directory (e.g.
Definition: vlc_configuration.h:277
vlc_user_dir
Definition: vlc_configuration.h:305
#define config_ChainParse(a, b, c, d)
Definition: vlc_configuration.h:347
module_config_t ** list
Definition: core.c:401
Definition: vlc_configuration.h:316
Definition: vlc_configuration.h:315
config_chain_t * config_ChainDuplicate(const config_chain_t *)
This function will duplicate a linked list of config_chain_t.
Definition: chain.c:435
int config_GetType(const char *name)
Gets a configuration item type.
Definition: core.c:48
Definition: vlc_configuration.h:53
Configuration item.
Definition: vlc_configuration.h:76
const char * psz_name
Definition: vlc_configuration.h:56
void config_PutFloat(const char *name, float val)
Sets an integer configuration item.
Definition: core.c:174
Definition: vlc_configuration.h:309
char * config_ChainCreate(char **ppsz_name, config_chain_t **pp_cfg, const char *psz_string)
This function will parse a configuration string (psz_string) and.
Definition: chain.c:225
char * config_GetSysPath(vlc_sysdir_t dir, const char *filename)
Gets an installation directory.
Definition: specific.c:306
bool config_ExistIntf(const char *)
Definition: intf.c:135
#define config_SaveConfigFile(a)
Definition: vlc_configuration.h:246
Definition: vlc_configuration.h:60
Global architecture-independent read-only data directory (e.g.
Definition: vlc_configuration.h:280
void config_PutPsz(const char *name, const char *val)
Sets an string configuration item.
Definition: core.c:131
void config_PutInt(const char *name, int64_t val)
Sets an integer configuration item.
Definition: core.c:155
int(* vlc_integer_list_cb)(const char *, int64_t **, char ***)
Definition: vlc_configuration.h:68
char * config_StringUnescape(char *psz_string)
This function will unescape a string in place and will return a pointer on the given string...
Definition: chain.c:455
vlc_system_dir
System directory identifiers.
Definition: vlc_configuration.h:271
Definition: vlc_configuration.h:307
Definition: vlc_configuration.h:319
ssize_t config_GetPszChoices(const char *, char ***values, char ***texts)
Determines a list of suggested values for a string configuration item.
Definition: vlc_configuration.h:331
Package-specific architecture-independent read-only data directory (e.g.
Definition: vlc_configuration.h:273
#define VLC_MALLOC
Heap allocated result function annotation.
Definition: vlc_common.h:167
const char * config_ChainParseOptions(config_chain_t **pp_cfg, const char *ppsz_opts)
This function will parse a configuration string (psz_opts) and.
Definition: chain.c:180
ssize_t config_GetIntChoices(const char *, int64_t **values, char ***texts)
Enumerates integer configuration choices.
void config_RemoveIntf(const char *)
Definition: intf.c:81
int i_type
Definition: httpd.c:1270
Global executable read-only directory (e.g.
Definition: vlc_configuration.h:285
Base directory for package read-only locale data.
Definition: vlc_configuration.h:288
int64_t config_GetInt(const char *name)
Gets an integer configuration item.
Definition: core.c:79
const char name[16]
Definition: httpd.c:1269
Definition: vlc_configuration.h:287
char psz_value[8]
Definition: vout_intf.c:99
void config_ChainDestroy(config_chain_t *)
This function will release a linked list of config_chain_t (Including the head)
Definition: chain.c:253
module_config_t * config_FindConfig(const char *name)
Looks up a configuration item.
Definition: core.c:453
#define VLC_API
Definition: fourcc_gen.c:31
const char * psz_help
Definition: vlc_configuration.h:57
char * config_GetPsz(const char *name)
Gets an string configuration item.
Definition: core.c:113
int(* vlc_string_list_cb)(const char *, char ***, char ***)
Definition: vlc_configuration.h:67
Definition: vlc_configuration.h:318
Definition: vlc_configuration.h:310
char * config_StringEscape(const char *psz_string)
This function will escape a string that can be unescaped by config_StringUnescape.
Definition: chain.c:473
Definition: vlc_configuration.h:312
Definition: vlc_configuration.h:317
Definition: vlc_configuration.h:308
Package-specific architecture-dependent read-only data directory (e.g.
Definition: vlc_configuration.h:275
Definition: vlc_configuration.h:279
void config_AddIntf(const char *)
Definition: intf.c:32
VLC object common members.
Definition: vlc_objects.h:43
enum vlc_user_dir vlc_userdir_t
Definition: vlc_configuration.h:313
#define VLC_USED
Definition: fourcc_gen.c:32
enum vlc_system_dir vlc_sysdir_t
System directory identifiers.
Global architecture-dependent read-only directory (e.g.
Definition: vlc_configuration.h:283
float config_GetFloat(const char *name)
Gets an floating point configuration item.
Definition: core.c:95
Definition: vlc_configuration.h:314