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's value.
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's value.
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 a floating point configuration item's value.
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 a floating point configuration item's value.
164  *
165  * This function changes the current value of a configuration item of
166  * floating point 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 a string configuration item's value.
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 a string configuration item's value.
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))
246 
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)
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 */
333 
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 )
347 
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 */
module_config_t::psz_name
const char * psz_name
Option name.
Definition: vlc_configuration.h:86
VLC_SYSDATA_DIR
@ VLC_SYSDATA_DIR
Global architecture-independent read-only data directory (e.g.
Definition: vlc_configuration.h:280
vlc_system_dir
vlc_system_dir
System directory identifiers.
Definition: vlc_configuration.h:271
config_category_t
Definition: vlc_configuration.h:53
VLC_API
#define VLC_API
Definition: fourcc_gen.c:31
config_chain_t::p_next
config_chain_t * p_next
Pointer on the next config_chain_t element.
Definition: vlc_configuration.h:335
config_FindConfig
VLC_EXPORT module_config_t * config_FindConfig(const char *name)
Looks up a configuration item.
Definition: core.c:452
config_category_t::i_id
int i_id
Definition: vlc_configuration.h:55
VLC_CACHE_DIR
@ VLC_CACHE_DIR
Definition: vlc_configuration.h:310
VLC_VIDEOS_DIR
@ VLC_VIDEOS_DIR
Definition: vlc_configuration.h:319
VLC_PKG_LIB_DIR
@ VLC_PKG_LIB_DIR
Package-specific architecture-dependent read-only data directory (e.g.
Definition: vlc_configuration.h:275
vlc_common.h
VLC_DESKTOP_DIR
@ VLC_DESKTOP_DIR
Definition: vlc_configuration.h:312
module_config_t::psz_text
const char * psz_text
Short comment on the configuration option.
Definition: vlc_configuration.h:87
module_value_t
Definition: vlc_configuration.h:60
module_config_t::list_text
const char ** list_text
Human-readable names for list values.
Definition: vlc_configuration.h:102
config_AddIntf
VLC_EXPORT void config_AddIntf(const char *)
Definition: intf.c:32
config_GetPszChoices
VLC_EXPORT ssize_t config_GetPszChoices(const char *, char ***values, char ***texts)
Determines a list of suggested values for a string configuration item.
module_config_t::i
const int * i
Table of possible integer choices.
Definition: vlc_configuration.h:100
module_config_t::b_internal
unsigned b_internal
Hidden from preferences and help.
Definition: vlc_configuration.h:80
module_config_t::orig
module_value_t orig
Default value.
Definition: vlc_configuration.h:91
config_ExistIntf
VLC_EXPORT bool config_ExistIntf(const char *)
Definition: intf.c:135
config_ChainParse
#define config_ChainParse(a, b, c, d)
Definition: vlc_configuration.h:347
config_chain_t::psz_name
char * psz_name
Option name.
Definition: vlc_configuration.h:337
module_value_t::psz
char * psz
Definition: vlc_configuration.h:62
VLC_MALLOC
#define VLC_MALLOC
Heap allocated result function annotation.
Definition: vlc_common.h:167
VLC_LIB_DIR
@ VLC_LIB_DIR
Global architecture-dependent read-only directory (e.g.
Definition: vlc_configuration.h:283
VLC_HOME_DIR
@ VLC_HOME_DIR
Definition: vlc_configuration.h:307
config_GetType
VLC_EXPORT int config_GetType(const char *name)
Gets a configuration item type.
Definition: core.c:48
config_ChainDuplicate
VLC_EXPORT config_chain_t * config_ChainDuplicate(const config_chain_t *)
This function will duplicate a linked list of config_chain_t.
Definition: chain.c:435
module_config_t::owner
void * owner
Origin run-time linker module handle.
Definition: vlc_configuration.h:103
config_GetUserDir
VLC_EXPORT char * config_GetUserDir(vlc_userdir_t)
Definition: specific.c:273
config_category_t::psz_help
const char * psz_help
Definition: vlc_configuration.h:57
VLC_LOCALE_DIR
@ VLC_LOCALE_DIR
Base directory for package read-only locale data.
Definition: vlc_configuration.h:288
VLC_DOCUMENTS_DIR
@ VLC_DOCUMENTS_DIR
Definition: vlc_configuration.h:316
config_chain_t
Definition: vlc_configuration.h:331
module_config_t::b_unsaveable
unsigned b_unsaveable
Not stored in configuration.
Definition: vlc_configuration.h:81
module_config_t::max
module_value_t max
Maximum value (for scalars only)
Definition: vlc_configuration.h:93
VLC_INCLUDE_DIR_RESERVED
@ VLC_INCLUDE_DIR_RESERVED
Definition: vlc_configuration.h:287
VLC_PICTURES_DIR
@ VLC_PICTURES_DIR
Definition: vlc_configuration.h:318
config_ResetAll
VLC_EXPORT void config_ResetAll(void)
Resets the configuration.
Definition: core.c:486
config_StringEscape
VLC_EXPORT char * config_StringEscape(const char *psz_string)
This function will escape a string that can be unescaped by config_StringUnescape.
Definition: chain.c:473
config_StringUnescape
VLC_EXPORT 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
config_chain_t::psz_value
char * psz_value
Option value.
Definition: vlc_configuration.h:338
VLC_CONFIG_DIR
@ VLC_CONFIG_DIR
Definition: vlc_configuration.h:308
vlc_string_list_cb
int(* vlc_string_list_cb)(const char *, char ***, char ***)
Definition: vlc_configuration.h:67
config_PutPsz
VLC_EXPORT void config_PutPsz(const char *name, const char *val)
Sets a string configuration item's value.
Definition: core.c:139
config_GetFloat
VLC_EXPORT float config_GetFloat(const char *name)
Gets a floating point configuration item's value.
Definition: core.c:105
VLC_LIBEXEC_DIR
@ VLC_LIBEXEC_DIR
Global executable read-only directory (e.g.
Definition: vlc_configuration.h:285
VLC_PKG_DATA_DIR
@ VLC_PKG_DATA_DIR
Package-specific architecture-independent read-only data directory (e.g.
Definition: vlc_configuration.h:273
VLC_PUBLICSHARE_DIR
@ VLC_PUBLICSHARE_DIR
Definition: vlc_configuration.h:315
vlc_object_t
VLC object common members.
Definition: vlc_objects.h:43
config_ChainCreate
VLC_EXPORT 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
config_GetIntChoices
VLC_EXPORT ssize_t config_GetIntChoices(const char *, int64_t **values, char ***texts)
Enumerates integer configuration choices.
config_PutInt
VLC_EXPORT void config_PutInt(const char *name, int64_t val)
Sets an integer configuration item's value.
Definition: core.c:162
module_config_t
Configuration item.
Definition: vlc_configuration.h:76
module_config_t::b_removed
unsigned b_removed
Obsolete.
Definition: vlc_configuration.h:83
config_ChainDestroy
VLC_EXPORT 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::psz_type
const char * psz_type
Configuration subtype.
Definition: vlc_configuration.h:85
config_PutFloat
VLC_EXPORT void config_PutFloat(const char *name, float val)
Sets a floating point configuration item's value.
Definition: core.c:181
module_config_t::min
module_value_t min
Minimum value (for scalars only)
Definition: vlc_configuration.h:92
config_GetSysPath
VLC_EXPORT char * config_GetSysPath(vlc_sysdir_t dir, const char *filename)
Gets an installation directory.
Definition: specific.c:306
VLC_USED
#define VLC_USED
Definition: fourcc_gen.c:32
vlc_sysdir_t
enum vlc_system_dir vlc_sysdir_t
System directory identifiers.
name
const char name[16]
Definition: httpd.c:1268
vlc_integer_list_cb
int(* vlc_integer_list_cb)(const char *, int64_t **, char ***)
Definition: vlc_configuration.h:68
config_category_t::psz_name
const char * psz_name
Definition: vlc_configuration.h:56
module_config_t::list
union module_config_t::@196 list
Possible choices.
module_value_t::i
int64_t i
Definition: vlc_configuration.h:63
VLC_DOWNLOAD_DIR
@ VLC_DOWNLOAD_DIR
Definition: vlc_configuration.h:313
module_config_t::value
module_value_t value
Current value.
Definition: vlc_configuration.h:90
module_value_t::f
float f
Definition: vlc_configuration.h:64
config_GetInt
VLC_EXPORT int64_t config_GetInt(const char *name)
Gets an integer configuration item's value.
Definition: core.c:89
module_config_t::list_count
uint16_t list_count
Choices count.
Definition: vlc_configuration.h:96
vlc_user_dir
vlc_user_dir
Definition: vlc_configuration.h:305
module_config_t::psz_longtext
const char * psz_longtext
Long comment on the configuration option.
Definition: vlc_configuration.h:88
module_config_t::i_type
uint8_t i_type
Configuration type.
Definition: vlc_configuration.h:78
module_config_t::psz
const char ** psz
Table of possible string choices.
Definition: vlc_configuration.h:99
VLC_TEMPLATES_DIR
@ VLC_TEMPLATES_DIR
Definition: vlc_configuration.h:314
VLC_PKG_INCLUDE_DIR_RESERVED
@ VLC_PKG_INCLUDE_DIR_RESERVED
Definition: vlc_configuration.h:279
module_config_t::i_short
char i_short
Optional short option name.
Definition: vlc_configuration.h:79
config_SaveConfigFile
#define config_SaveConfigFile(a)
Definition: vlc_configuration.h:246
VLC_USERDATA_DIR
@ VLC_USERDATA_DIR
Definition: vlc_configuration.h:309
config_ChainParseOptions
const VLC_EXPORT 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
config_RemoveIntf
VLC_EXPORT void config_RemoveIntf(const char *)
Definition: intf.c:81
vlc_userdir_t
enum vlc_user_dir vlc_userdir_t
config_GetPsz
VLC_EXPORT char * config_GetPsz(const char *name)
Gets a string configuration item's value.
Definition: core.c:123
VLC_MUSIC_DIR
@ VLC_MUSIC_DIR
Definition: vlc_configuration.h:317
VLC_PKG_LIBEXEC_DIR
@ VLC_PKG_LIBEXEC_DIR
Package-specific executable read-only directory (e.g.
Definition: vlc_configuration.h:277
module_config_t::b_safe
unsigned b_safe
Safe for web plugins and playlist files.
Definition: vlc_configuration.h:82