Coverage Report

Created: 2025-07-11 07:16

/src/vlc/include/vlc_configuration.h
Line
Count
Source (jump to first uncovered line)
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;
57
} module_value_t;
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
231
VLC_API int config_SaveConfigFile( libvlc_int_t * );
232
0
#define config_SaveConfigFile(a) config_SaveConfigFile(vlc_object_instance(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
 */
252
VLC_API module_config_t *config_FindConfig(const char *name) VLC_USED;
253
254
/**
255
 * Gets the config label string for a configuration item, acquired by name.
256
 * A valid configuration item name is required.
257
 *
258
 * \param name Configuration item name
259
 */
260
static inline const char *config_GetLabel(const char *const psz_name)
261
0
{
262
0
    module_config_t *const p_config = config_FindConfig(psz_name);
263
0
264
0
    /* sanity checks */
265
0
    if (p_config == NULL)
266
0
        return NULL;
267
0
    if (p_config->psz_longtext)
268
0
        return p_config->psz_longtext;
269
0
    if (p_config->psz_text)
270
0
        return p_config->psz_text;
271
0
    return NULL;
272
0
}
Unexecuted instantiation: dvbsub.c:config_GetLabel
Unexecuted instantiation: libvlc.c:config_GetLabel
Unexecuted instantiation: core.c:config_GetLabel
Unexecuted instantiation: chain.c:config_GetLabel
Unexecuted instantiation: file.c:config_GetLabel
Unexecuted instantiation: help.c:config_GetLabel
Unexecuted instantiation: cmdline.c:config_GetLabel
Unexecuted instantiation: modules.c:config_GetLabel
Unexecuted instantiation: bank.c:config_GetLabel
Unexecuted instantiation: entry.c:config_GetLabel
Unexecuted instantiation: textdomain.c:config_GetLabel
Unexecuted instantiation: interface.c:config_GetLabel
Unexecuted instantiation: demux.c:config_GetLabel
Unexecuted instantiation: services_discovery.c:config_GetLabel
Unexecuted instantiation: filters.c:config_GetLabel
Unexecuted instantiation: meter.c:config_GetLabel
Unexecuted instantiation: output.c:config_GetLabel
Unexecuted instantiation: video_output.c:config_GetLabel
Unexecuted instantiation: renderer_discovery.c:config_GetLabel
Unexecuted instantiation: variables.c:config_GetLabel
Unexecuted instantiation: filter.c:config_GetLabel
Unexecuted instantiation: filter_chain.c:config_GetLabel
Unexecuted instantiation: stream_output.c:config_GetLabel
Unexecuted instantiation: dirs.c:config_GetLabel
Unexecuted instantiation: art.c:config_GetLabel
Unexecuted instantiation: es_out.c:config_GetLabel
Unexecuted instantiation: interlacing.c:config_GetLabel
Unexecuted instantiation: snapshot.c:config_GetLabel
273
274
/**
275
 * System directory identifiers
276
 */
277
typedef enum vlc_system_dir
278
{
279
    VLC_PKG_DATA_DIR, /**< Package-specific architecture-independent read-only
280
                           data directory (e.g. /usr/local/data/vlc). */
281
    VLC_PKG_LIB_DIR, /**< Package-specific architecture-dependent read-only
282
                          data directory (e.g. /usr/local/lib/vlc). */
283
    VLC_PKG_LIBEXEC_DIR, /**< Package-specific executable read-only directory
284
                              (e.g. /usr/local/libexec/vlc). */
285
    VLC_PKG_INCLUDE_DIR_RESERVED,
286
    VLC_SYSDATA_DIR, /**< Global architecture-independent read-only
287
                          data directory (e.g. /usr/local/data).
288
                          Available only on some platforms. */
289
    VLC_LIB_DIR, /**< Global architecture-dependent read-only directory
290
                      (e.g. /usr/local/lib). */
291
    VLC_LIBEXEC_DIR, /**< Global executable read-only directory
292
                          (e.g. /usr/local/libexec). */
293
    VLC_INCLUDE_DIR_RESERVED,
294
    VLC_LOCALE_DIR, /**< Base directory for package read-only locale data. */
295
} vlc_sysdir_t;
296
297
/**
298
 * Gets an installation directory.
299
 *
300
 * This function determines one of the installation directory.
301
 *
302
 * @param dir identifier of the directory (see \ref vlc_sysdir_t)
303
 * @param filename name of a file or other object within the directory
304
 *                 (or NULL to obtain the plain directory)
305
 *
306
 * @return a heap-allocated string (use free() to release it), or NULL on error
307
 */
308
VLC_API char *config_GetSysPath(vlc_sysdir_t dir, const char *filename)
309
VLC_USED VLC_MALLOC;
310
311
typedef enum vlc_user_dir
312
{
313
    VLC_HOME_DIR, /* User's home */
314
    VLC_CONFIG_DIR, /* VLC-specific configuration directory */
315
    VLC_USERDATA_DIR, /* VLC-specific data directory */
316
    VLC_CACHE_DIR, /* VLC-specific user cached data directory */
317
    /* Generic directories (same as XDG) */
318
    VLC_DESKTOP_DIR=0x80,
319
    VLC_DOWNLOAD_DIR,
320
    VLC_TEMPLATES_DIR,
321
    VLC_PUBLICSHARE_DIR,
322
    VLC_DOCUMENTS_DIR,
323
    VLC_MUSIC_DIR,
324
    VLC_PICTURES_DIR,
325
    VLC_VIDEOS_DIR,
326
    VLC_SNAPSHOTS_DIR,
327
} vlc_userdir_t;
328
329
VLC_API char * config_GetUserDir( vlc_userdir_t ) VLC_USED VLC_MALLOC;
330
331
VLC_API void config_AddIntf(const char *);
332
VLC_API void config_RemoveIntf(const char *);
333
VLC_API bool config_ExistIntf(const char *) VLC_USED;
334
335
/****************************************************************************
336
 * config_chain_t:
337
 ****************************************************************************/
338
struct config_chain_t
339
{
340
    config_chain_t *p_next;     /**< Pointer on the next config_chain_t element */
341
342
    char        *psz_name;      /**< Option name */
343
    char        *psz_value;     /**< Option value */
344
};
345
346
/**
347
 * This function will
348
 * - create all options in the array ppsz_options (var_Create).
349
 * - parse the given linked list of config_chain_t and set the value (var_Set).
350
 *
351
 * The option names will be created by adding the psz_prefix prefix.
352
 */
353
VLC_API void config_ChainParse( vlc_object_t *, const char *psz_prefix, const char *const *ppsz_options, const config_chain_t * );
354
0
#define config_ChainParse( a, b, c, d ) config_ChainParse( VLC_OBJECT(a), b, c, d )
355
356
/**
357
 * This function will parse a configuration string (psz_opts) and
358
 * - set all options for this module in a chained list (*pp_cfg)
359
 * - returns a pointer on the next module if any.
360
 *
361
 * The string format is
362
 *   module{option=*,option=*}
363
 *
364
 * The options values are unescaped using config_StringUnescape.
365
 */
366
VLC_API const char *config_ChainParseOptions( config_chain_t **pp_cfg, const char *ppsz_opts );
367
368
/**
369
 * This function will parse a configuration string (psz_string) and
370
 * - set the module name (*ppsz_name)
371
 * - set all options for this module in a chained list (*pp_cfg)
372
 * - returns a pointer on the next module if any.
373
 *
374
 * The string format is
375
 *   module{option=*,option=*}[:modulenext{option=*,...}]
376
 *
377
 * The options values are unescaped using config_StringUnescape.
378
 */
379
VLC_API char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg, const char *psz_string ) VLC_USED VLC_MALLOC;
380
381
/**
382
 * This function will release a linked list of config_chain_t
383
 * (Including the head)
384
 */
385
VLC_API void config_ChainDestroy( config_chain_t * );
386
387
/**
388
 * This function will duplicate a linked list of config_chain_t
389
 */
390
VLC_API config_chain_t * config_ChainDuplicate( const config_chain_t * ) VLC_USED VLC_MALLOC;
391
392
/**
393
 * This function will unescape a string in place and will return a pointer on
394
 * the given string.
395
 * No memory is allocated by it (unlike config_StringEscape).
396
 * If NULL is given as parameter nothing will be done (NULL will be returned).
397
 *
398
 * The following sequences will be unescaped (only one time):
399
 * \\ \' and \"
400
 */
401
VLC_API char * config_StringUnescape( char *psz_string );
402
403
/**
404
 * This function will escape a string that can be unescaped by
405
 * config_StringUnescape.
406
 * The returned value is allocated by it. You have to free it once you
407
 * do not need it anymore (unlike config_StringUnescape).
408
 * If NULL is given as parameter nothing will be done (NULL will be returned).
409
 *
410
 * The escaped characters are ' " and \
411
 */
412
VLC_API char * config_StringEscape( const char *psz_string ) VLC_USED VLC_MALLOC;
413
414
# ifdef __cplusplus
415
}
416
# endif
417
418
/** @} */
419
420
#endif /* _VLC_CONFIGURATION_H */