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 typedef union
53 {
54  char *psz;
55  int64_t i;
56  float f;
58 
59 typedef int (*vlc_string_list_cb)(const char *, char ***, char ***);
60 typedef int (*vlc_integer_list_cb)(const char *, int64_t **, char ***);
61 
62 /**
63  * Configuration item
64  *
65  * This is the internal reprensation of a configuration item.
66  * See also config_FindConfig().
67  */
68 struct module_config_t
69 {
70  uint8_t i_type; /**< Configuration type */
71 
72  const char *psz_type; /**< Configuration subtype */
73  const char *psz_name; /**< Option name */
74  const char *psz_text; /**< Short comment on the configuration option */
75  const char *psz_longtext; /**< Long comment on the configuration option */
76 
77  module_value_t value; /**< Current value */
78  module_value_t orig; /**< Default value */
79  module_value_t min; /**< Minimum value (for scalars only) */
80  module_value_t max; /**< Maximum value (for scalars only) */
81 
82  /* Values list */
83  uint16_t list_count; /**< Choices count */
84  union
85  {
86  const char **psz; /**< Table of possible string choices */
87  const int *i; /**< Table of possible integer choices */
88  } list; /**< Possible choices */
89  const char **list_text; /**< Human-readable names for list values */
90 };
91 
92 /**
93  * Gets a configuration item type
94  *
95  * This function checks the type of configuration item by name.
96  * \param name Configuration item name
97  * \return The configuration item type or 0 if not found.
98  */
99 VLC_API int config_GetType(const char *name) VLC_USED;
100 
101 /**
102  * Gets an integer configuration item's value.
103  *
104  * This function retrieves the current value of a configuration item of
105  * integral type (\ref CONFIG_ITEM_INTEGER and \ref CONFIG_ITEM_BOOL).
106  *
107  * \warning The behaviour is undefined if the configuration item exists but is
108  * not of integer or boolean type.
109  *
110  * \param name Configuration item name
111  * \return The configuration item value or -1 if not found.
112  * \bug A legitimate integer value of -1 cannot be distinguished from an error.
113  */
114 VLC_API int64_t config_GetInt(const char *name) VLC_USED;
115 
116 /**
117  * Sets an integer configuration item's value.
118  *
119  * This function changes the current value of a configuration item of
120  * integral type (\ref CONFIG_ITEM_INTEGER and \ref CONFIG_ITEM_BOOL).
121  *
122  * \warning The behaviour is undefined if the configuration item exists but is
123  * not of integer or boolean type.
124  *
125  * \note If no configuration item by the specified exist, the function has no
126  * effects.
127  *
128  * \param name Configuration item name
129  * \param val New value
130  */
131 VLC_API void config_PutInt(const char *name, int64_t val);
132 
133 /**
134  * Gets a floating point configuration item's value.
135  *
136  * This function retrieves the current value of a configuration item of
137  * floating point type (\ref CONFIG_ITEM_FLOAT).
138  *
139  * \warning The behaviour is undefined if the configuration item exists but is
140  * not of floating point type.
141  *
142  * \param name Configuration item name
143  * \return The configuration item value or -1 if not found.
144  * \bug A legitimate floating point value of -1 cannot be distinguished from an
145  * error.
146  */
147 VLC_API float config_GetFloat(const char *name) VLC_USED;
148 
149 /**
150  * Sets a floating point configuration item's value.
151  *
152  * This function changes the current value of a configuration item of
153  * floating point type (\ref CONFIG_ITEM_FLOAT).
154  *
155  * \warning The behaviour is undefined if the configuration item exists but is
156  * not of floating point type.
157  *
158  * \note If no configuration item by the specified exist, the function has no
159  * effects.
160  *
161  * \param name Configuration item name
162  * \param val New value
163  */
164 VLC_API void config_PutFloat(const char *name, float val);
165 
166 /**
167  * Gets a string configuration item's value.
168  *
169  * This function retrieves the current value of a configuration item of
170  * string type (\ref CONFIG_ITEM_STRING).
171  *
172  * \note The caller must free() the returned pointer (if non-NULL), which is a
173  * duplicate of the current value. It is not safe to return a pointer to the
174  * current value internally as it can be modified at any time by any other
175  * thread.
176  *
177  * \warning The behaviour is undefined if the configuration item exists but is
178  * not of string type.
179  *
180  * \param name Configuration item name
181  * \return Normally, a heap-allocated copy of the configuration item value.
182  * If the value is the empty string, if the configuration does not exist,
183  * or if an error occurs, NULL is returned.
184  * \bug The empty string value cannot be distinguished from an error.
185  */
186 VLC_API char *config_GetPsz(const char *name) VLC_USED VLC_MALLOC;
187 
188 /**
189  * Sets a string configuration item's value.
190  *
191  * This function changes the current value of a configuration item of
192  * string type (e.g. \ref CONFIG_ITEM_STRING).
193  *
194  * \warning The behaviour is undefined if the configuration item exists but is
195  * not of a string type.
196  *
197  * \note If no configuration item by the specified exist, the function has no
198  * effects.
199  *
200  * \param name Configuration item name
201  * \param val New value (will be copied)
202  * \bug This function allocates memory but errors cannot be detected.
203  */
204 VLC_API void config_PutPsz(const char *name, const char *val);
205 
206 /**
207  * Enumerates integer configuration choices.
208  *
209  * Determines a list of suggested values for an integer configuration item.
210  * \param values pointer to a table of integer values [OUT]
211  * \param texts pointer to a table of descriptions strings [OUT]
212  * \return number of choices, or -1 on error
213  * \note the caller is responsible for calling free() on all descriptions and
214  * on both tables. In case of error, both pointers are set to NULL.
215  */
216 VLC_API ssize_t config_GetIntChoices(const char *, int64_t **values,
217  char ***texts) VLC_USED;
218 
219 /**
220  * Determines a list of suggested values for a string configuration item.
221  * \param values pointer to a table of value strings [OUT]
222  * \param texts pointer to a table of descriptions strings [OUT]
223  * \return number of choices, or -1 on error
224  * \note the caller is responsible for calling free() on all values, on all
225  * descriptions and on both tables.
226  * In case of error, both pointers are set to NULL.
227  */
228 VLC_API ssize_t config_GetPszChoices(const char *,
229  char ***values, char ***texts) VLC_USED;
230 
232 #define config_SaveConfigFile(a) config_SaveConfigFile(VLC_OBJECT(a))
233 
234 /**
235  * Resets the configuration.
236  *
237  * This function resets all configuration items to their respective
238  * compile-time default value.
239  */
240 VLC_API void config_ResetAll(void);
241 
242 /**
243  * Looks up a configuration item.
244  *
245  * This function looks for the internal representation of a configuration item.
246  * Where possible, this should be avoided in favor of more specific function
247  * calls.
248  *
249  * \param name Configuration item name
250  * \return The internal structure, or NULL if not found.
251  */
253 
254 /**
255  * System directory identifiers
256  */
257 typedef enum vlc_system_dir
258 {
259  VLC_PKG_DATA_DIR, /**< Package-specific architecture-independent read-only
260  data directory (e.g. /usr/local/data/vlc). */
261  VLC_PKG_LIB_DIR, /**< Package-specific architecture-dependent read-only
262  data directory (e.g. /usr/local/lib/vlc). */
263  VLC_PKG_LIBEXEC_DIR, /**< Package-specific executable read-only directory
264  (e.g. /usr/local/libexec/vlc). */
266  VLC_SYSDATA_DIR, /**< Global architecture-independent read-only
267  data directory (e.g. /usr/local/data).
268  Available only on some platforms. */
269  VLC_LIB_DIR, /**< Global architecture-dependent read-only directory
270  (e.g. /usr/local/lib). */
271  VLC_LIBEXEC_DIR, /**< Global executable read-only directory
272  (e.g. /usr/local/libexec). */
274  VLC_LOCALE_DIR, /**< Base directory for package read-only locale data. */
276 
277 /**
278  * Gets an installation directory.
279  *
280  * This function determines one of the installation directory.
281  *
282  * @param dir identifier of the directory (see \ref vlc_sysdir_t)
283  * @param filename name of a file or other object within the directory
284  * (or NULL to obtain the plain directory)
285  *
286  * @return a heap-allocated string (use free() to release it), or NULL on error
287  */
288 VLC_API char *config_GetSysPath(vlc_sysdir_t dir, const char *filename)
290 
291 typedef enum vlc_user_dir
292 {
293  VLC_HOME_DIR, /* User's home */
294  VLC_CONFIG_DIR, /* VLC-specific configuration directory */
295  VLC_USERDATA_DIR, /* VLC-specific data directory */
296  VLC_CACHE_DIR, /* VLC-specific user cached data directory */
297  /* Generic directories (same as XDG) */
298  VLC_DESKTOP_DIR=0x80,
307 
309 
310 VLC_API void config_AddIntf(const char *);
311 VLC_API void config_RemoveIntf(const char *);
312 VLC_API bool config_ExistIntf(const char *) VLC_USED;
313 
314 /****************************************************************************
315  * config_chain_t:
316  ****************************************************************************/
317 struct config_chain_t
318 {
319  config_chain_t *p_next; /**< Pointer on the next config_chain_t element */
320 
321  char *psz_name; /**< Option name */
322  char *psz_value; /**< Option value */
323 };
324 
325 /**
326  * This function will
327  * - create all options in the array ppsz_options (var_Create).
328  * - parse the given linked list of config_chain_t and set the value (var_Set).
329  *
330  * The option names will be created by adding the psz_prefix prefix.
331  */
332 VLC_API void config_ChainParse( vlc_object_t *, const char *psz_prefix, const char *const *ppsz_options, const config_chain_t * );
333 #define config_ChainParse( a, b, c, d ) config_ChainParse( VLC_OBJECT(a), b, c, d )
334 
335 /**
336  * This function will parse a configuration string (psz_opts) and
337  * - set all options for this module in a chained list (*pp_cfg)
338  * - returns a pointer on the next module if any.
339  *
340  * The string format is
341  * module{option=*,option=*}
342  *
343  * The options values are unescaped using config_StringUnescape.
344  */
345 VLC_API const char *config_ChainParseOptions( config_chain_t **pp_cfg, const char *ppsz_opts );
346 
347 /**
348  * This function will parse a configuration string (psz_string) and
349  * - set the module name (*ppsz_name)
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=*}[:modulenext{option=*,...}]
355  *
356  * The options values are unescaped using config_StringUnescape.
357  */
358 VLC_API char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg, const char *psz_string ) VLC_USED VLC_MALLOC;
359 
360 /**
361  * This function will release a linked list of config_chain_t
362  * (Including the head)
363  */
365 
366 /**
367  * This function will duplicate a linked list of config_chain_t
368  */
370 
371 /**
372  * This function will unescape a string in place and will return a pointer on
373  * the given string.
374  * No memory is allocated by it (unlike config_StringEscape).
375  * If NULL is given as parameter nothing will be done (NULL will be returned).
376  *
377  * The following sequences will be unescaped (only one time):
378  * \\ \' and \"
379  */
380 VLC_API char * config_StringUnescape( char *psz_string );
381 
382 /**
383  * This function will escape a string that can be unescaped by
384  * config_StringUnescape.
385  * The returned value is allocated by it. You have to free it once you
386  * do not need it anymore (unlike config_StringUnescape).
387  * If NULL is given as parameter nothing will be done (NULL will be returned).
388  *
389  * The escaped characters are ' " and \
390  */
391 VLC_API char * config_StringEscape( const char *psz_string ) VLC_USED VLC_MALLOC;
392 
393 # ifdef __cplusplus
394 }
395 # endif
396 
397 /** @} */
398 
399 #endif /* _VLC_CONFIGURATION_H */
#define VLC_USED
Definition: fourcc_gen.c:32
#define VLC_API
Definition: fourcc_gen.c:31
#define VLC_MALLOC
Heap allocated result function annotation.
Definition: vlc_common.h:168
int config_GetType(const char *name)
Gets a configuration item type.
Definition: core.c:50
enum vlc_user_dir vlc_userdir_t
bool config_ExistIntf(const char *)
Definition: intf.c:135
vlc_system_dir
System directory identifiers.
Definition: vlc_configuration.h:259
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:448
float config_GetFloat(const char *name)
Gets a floating point configuration item's value.
Definition: core.c:90
int64_t config_GetInt(const char *name)
Gets an integer configuration item's value.
Definition: core.c:79
void config_RemoveIntf(const char *)
Definition: intf.c:81
void config_PutInt(const char *name, int64_t val)
Sets an integer configuration item's value.
Definition: core.c:148
int(* vlc_string_list_cb)(const char *, char ***, char ***)
Definition: vlc_configuration.h:60
int(* vlc_integer_list_cb)(const char *, int64_t **, char ***)
Definition: vlc_configuration.h:61
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
void config_AddIntf(const char *)
Definition: intf.c:32
char * config_GetPsz(const char *name)
Gets a string configuration item's value.
Definition: core.c:101
ssize_t config_GetPszChoices(const char *, char ***values, char ***texts)
Determines a list of suggested values for a string configuration item.
char * config_GetUserDir(vlc_userdir_t)
Definition: specific.c:273
config_chain_t * config_ChainDuplicate(const config_chain_t *)
This function will duplicate a linked list of config_chain_t.
Definition: chain.c:428
char * config_StringEscape(const char *psz_string)
This function will escape a string that can be unescaped by config_StringUnescape.
Definition: chain.c:466
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:457
vlc_user_dir
Definition: vlc_configuration.h:293
void config_PutFloat(const char *name, float val)
Sets a floating point configuration item's value.
Definition: core.c:169
ssize_t config_GetIntChoices(const char *, int64_t **values, char ***texts)
Enumerates integer configuration choices.
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
enum vlc_system_dir vlc_sysdir_t
System directory identifiers.
#define config_ChainParse(a, b, c, d)
Definition: vlc_configuration.h:334
void config_ResetAll(void)
Resets the configuration.
Definition: core.c:493
#define config_SaveConfigFile(a)
Definition: vlc_configuration.h:233
void config_PutPsz(const char *name, const char *val)
Sets a string configuration item's value.
Definition: core.c:140
char * config_GetSysPath(vlc_sysdir_t dir, const char *filename)
Gets an installation directory.
Definition: specific.c:306
@ VLC_LIBEXEC_DIR
Global executable read-only directory (e.g.
Definition: vlc_configuration.h:272
@ VLC_SYSDATA_DIR
Global architecture-independent read-only data directory (e.g.
Definition: vlc_configuration.h:267
@ VLC_LOCALE_DIR
Base directory for package read-only locale data.
Definition: vlc_configuration.h:275
@ VLC_PKG_INCLUDE_DIR_RESERVED
Definition: vlc_configuration.h:266
@ VLC_PKG_LIBEXEC_DIR
Package-specific executable read-only directory (e.g.
Definition: vlc_configuration.h:264
@ VLC_PKG_LIB_DIR
Package-specific architecture-dependent read-only data directory (e.g.
Definition: vlc_configuration.h:262
@ VLC_PKG_DATA_DIR
Package-specific architecture-independent read-only data directory (e.g.
Definition: vlc_configuration.h:260
@ VLC_LIB_DIR
Global architecture-dependent read-only directory (e.g.
Definition: vlc_configuration.h:270
@ VLC_INCLUDE_DIR_RESERVED
Definition: vlc_configuration.h:274
@ VLC_TEMPLATES_DIR
Definition: vlc_configuration.h:301
@ VLC_PICTURES_DIR
Definition: vlc_configuration.h:305
@ VLC_USERDATA_DIR
Definition: vlc_configuration.h:296
@ VLC_HOME_DIR
Definition: vlc_configuration.h:294
@ VLC_CACHE_DIR
Definition: vlc_configuration.h:297
@ VLC_DESKTOP_DIR
Definition: vlc_configuration.h:299
@ VLC_DOWNLOAD_DIR
Definition: vlc_configuration.h:300
@ VLC_VIDEOS_DIR
Definition: vlc_configuration.h:306
@ VLC_PUBLICSHARE_DIR
Definition: vlc_configuration.h:302
@ VLC_DOCUMENTS_DIR
Definition: vlc_configuration.h:303
@ VLC_MUSIC_DIR
Definition: vlc_configuration.h:304
@ VLC_CONFIG_DIR
Definition: vlc_configuration.h:295
const char name[16]
Definition: httpd.c:1268
Definition: vlc_configuration.h:319
char * psz_value
Option value.
Definition: vlc_configuration.h:323
char * psz_name
Option name.
Definition: vlc_configuration.h:322
config_chain_t * p_next
Pointer on the next config_chain_t element.
Definition: vlc_configuration.h:320
Configuration item.
Definition: vlc_configuration.h:70
union module_config_t::@197 list
Possible choices.
const char ** list_text
Human-readable names for list values.
Definition: vlc_configuration.h:90
module_value_t value
Current value.
Definition: vlc_configuration.h:78
uint16_t list_count
Choices count.
Definition: vlc_configuration.h:84
const char * psz_type
Configuration subtype.
Definition: vlc_configuration.h:73
module_value_t min
Minimum value (for scalars only)
Definition: vlc_configuration.h:80
const char ** psz
Table of possible string choices.
Definition: vlc_configuration.h:87
const char * psz_text
Short comment on the configuration option.
Definition: vlc_configuration.h:75
const char * psz_longtext
Long comment on the configuration option.
Definition: vlc_configuration.h:76
module_value_t max
Maximum value (for scalars only)
Definition: vlc_configuration.h:81
module_value_t orig
Default value.
Definition: vlc_configuration.h:79
const int * i
Table of possible integer choices.
Definition: vlc_configuration.h:88
uint8_t i_type
Configuration type.
Definition: vlc_configuration.h:71
const char * psz_name
Option name.
Definition: vlc_configuration.h:74
VLC object common members.
Definition: vlc_objects.h:45
Definition: vlc_configuration.h:54