vlc_configuration.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_configuration.h : configuration management module
00003  * This file describes the programming interface for the configuration module.
00004  * It includes functions allowing to declare, get or set configuration options.
00005  *****************************************************************************
00006  * Copyright (C) 1999-2006 VLC authors and VideoLAN
00007  * $Id: fa045938d3cd5e50d8588b2c035faeeb310ebe81 $
00008  *
00009  * Authors: Gildas Bazin <gbazin@videolan.org>
00010  *
00011  * This program is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU Lesser General Public License as published by
00013  * the Free Software Foundation; either version 2.1 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019  * GNU Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00024  *****************************************************************************/
00025 
00026 #ifndef VLC_CONFIGURATION_H
00027 #define VLC_CONFIGURATION_H 1
00028 
00029 /**
00030  * \file
00031  * This file describes the programming interface for the configuration module.
00032  * It includes functions allowing to declare, get or set configuration options.
00033  */
00034 
00035 # ifdef __cplusplus
00036 extern "C" {
00037 # endif
00038 
00039 struct config_category_t
00040 {
00041     int         i_id;
00042     const char *psz_name;
00043     const char *psz_help;
00044 };
00045 
00046 typedef union
00047 {
00048     char       *psz;
00049     int64_t     i;
00050     float       f;
00051 } module_value_t;
00052 
00053 struct module_config_t
00054 {
00055     char        *psz_type;                          /* Configuration subtype */
00056     char        *psz_name;                                    /* Option name */
00057     char        *psz_text;      /* Short comment on the configuration option */
00058     char        *psz_longtext;   /* Long comment on the configuration option */
00059     module_value_t value;                                    /* Option value */
00060     module_value_t orig;
00061     module_value_t min;
00062     module_value_t max;
00063 
00064     /* Values list */
00065     char **      ppsz_list;       /* List of possible values for the option */
00066     int         *pi_list;                              /* Idem for integers */
00067     char       **ppsz_list_text;          /* Friendly names for list values */
00068     int          i_list;                               /* Options list size */
00069     vlc_callback_t pf_update_list; /* Callback to initialize dropdown lists */
00070     uint8_t      i_type;                              /* Configuration type */
00071     char         i_short;                     /* Optional short option name */
00072 
00073     /* Misc */
00074     unsigned    b_advanced:1;        /* Flag to indicate an advanced option */
00075     unsigned    b_internal:1; /* Flag to indicate option is not to be shown */
00076     unsigned    b_unsaveable:1;               /* Config should not be saved */
00077     unsigned    b_safe:1;       /* Safe to use in web plugins and playlists */
00078 
00079     /* Actions list */
00080     int            i_action;                           /* actions list size */
00081     vlc_callback_t *ppf_action;    /* List of possible actions for a config */
00082     char          **ppsz_action_text;         /* Friendly names for actions */
00083 
00084     /* Deprecated */
00085     bool        b_removed;
00086 };
00087 
00088 /*****************************************************************************
00089  * Prototypes - these methods are used to get, set or manipulate configuration
00090  * data.
00091  *****************************************************************************/
00092 VLC_API int config_GetType(vlc_object_t *, const char *) VLC_USED;
00093 VLC_API int64_t config_GetInt(vlc_object_t *, const char *) VLC_USED;
00094 VLC_API void config_PutInt(vlc_object_t *, const char *, int64_t);
00095 VLC_API float config_GetFloat(vlc_object_t *, const char *) VLC_USED;
00096 VLC_API void config_PutFloat(vlc_object_t *, const char *, float);
00097 VLC_API char * config_GetPsz(vlc_object_t *, const char *) VLC_USED VLC_MALLOC;
00098 VLC_API void config_PutPsz(vlc_object_t *, const char *, const char *);
00099 
00100 VLC_API int config_SaveConfigFile( vlc_object_t * );
00101 #define config_SaveConfigFile(a) config_SaveConfigFile(VLC_OBJECT(a))
00102 
00103 VLC_API void config_ResetAll( vlc_object_t * );
00104 #define config_ResetAll(a) config_ResetAll(VLC_OBJECT(a))
00105 
00106 VLC_API module_config_t * config_FindConfig( vlc_object_t *, const char * ) VLC_USED;
00107 VLC_API char * config_GetDataDir(void) VLC_USED VLC_MALLOC;
00108 VLC_API char *config_GetLibDir(void) VLC_USED;
00109 VLC_API const char * config_GetConfDir( void ) VLC_USED;
00110 
00111 typedef enum vlc_userdir
00112 {
00113     VLC_HOME_DIR, /* User's home */
00114     VLC_CONFIG_DIR, /* VLC-specific configuration directory */
00115     VLC_DATA_DIR, /* VLC-specific data directory */
00116     VLC_CACHE_DIR, /* VLC-specific user cached data directory */
00117     /* Generic directories (same as XDG) */
00118     VLC_DESKTOP_DIR=0x80,
00119     VLC_DOWNLOAD_DIR,
00120     VLC_TEMPLATES_DIR,
00121     VLC_PUBLICSHARE_DIR,
00122     VLC_DOCUMENTS_DIR,
00123     VLC_MUSIC_DIR,
00124     VLC_PICTURES_DIR,
00125     VLC_VIDEOS_DIR,
00126 } vlc_userdir_t;
00127 
00128 VLC_API char * config_GetUserDir( vlc_userdir_t ) VLC_USED VLC_MALLOC;
00129 
00130 VLC_API void config_AddIntf( vlc_object_t *, const char * );
00131 VLC_API void config_RemoveIntf( vlc_object_t *, const char * );
00132 VLC_API bool config_ExistIntf( vlc_object_t *, const char * ) VLC_USED;
00133 
00134 #define config_GetType(a,b) config_GetType(VLC_OBJECT(a),b)
00135 #define config_GetInt(a,b) config_GetInt(VLC_OBJECT(a),b)
00136 #define config_PutInt(a,b,c) config_PutInt(VLC_OBJECT(a),b,c)
00137 #define config_GetFloat(a,b) config_GetFloat(VLC_OBJECT(a),b)
00138 #define config_PutFloat(a,b,c) config_PutFloat(VLC_OBJECT(a),b,c)
00139 #define config_GetPsz(a,b) config_GetPsz(VLC_OBJECT(a),b)
00140 #define config_PutPsz(a,b,c) config_PutPsz(VLC_OBJECT(a),b,c)
00141 
00142 #define config_AddIntf(a,b) config_AddIntf(VLC_OBJECT(a),b)
00143 #define config_RemoveIntf(a,b) config_RemoveIntf(VLC_OBJECT(a),b)
00144 #define config_ExistIntf(a,b) config_ExistIntf(VLC_OBJECT(a),b)
00145 
00146 /****************************************************************************
00147  * config_chain_t:
00148  ****************************************************************************/
00149 struct config_chain_t
00150 {
00151     config_chain_t *p_next;     /**< Pointer on the next config_chain_t element */
00152 
00153     char        *psz_name;      /**< Option name */
00154     char        *psz_value;     /**< Option value */
00155 };
00156 
00157 /**
00158  * This function will
00159  * - create all options in the array ppsz_options (var_Create).
00160  * - parse the given linked list of config_chain_t and set the value (var_Set).
00161  *
00162  * The option names will be created by adding the psz_prefix prefix.
00163  */
00164 VLC_API void config_ChainParse( vlc_object_t *, const char *psz_prefix, const char *const *ppsz_options, config_chain_t * );
00165 #define config_ChainParse( a, b, c, d ) config_ChainParse( VLC_OBJECT(a), b, c, d )
00166 
00167 /**
00168  * This function will parse a configuration string (psz_opts) and
00169  * - set all options for this module in a chained list (*pp_cfg)
00170  * - returns a pointer on the next module if any.
00171  *
00172  * The string format is
00173  *   module{option=*,option=*}
00174  *
00175  * The options values are unescaped using config_StringUnescape.
00176  */
00177 VLC_API const char *config_ChainParseOptions( config_chain_t **pp_cfg, const char *ppsz_opts );
00178 
00179 /**
00180  * This function will parse a configuration string (psz_string) and
00181  * - set the module name (*ppsz_name)
00182  * - set all options for this module in a chained list (*pp_cfg)
00183  * - returns a pointer on the next module if any.
00184  *
00185  * The string format is
00186  *   module{option=*,option=*}[:modulenext{option=*,...}]
00187  *
00188  * The options values are unescaped using config_StringUnescape.
00189  */
00190 VLC_API char *config_ChainCreate( char **ppsz_name, config_chain_t **pp_cfg, const char *psz_string ) VLC_USED VLC_MALLOC;
00191 
00192 /**
00193  * This function will release a linked list of config_chain_t
00194  * (Including the head)
00195  */
00196 VLC_API void config_ChainDestroy( config_chain_t * );
00197 
00198 /**
00199  * This function will duplicate a linked list of config_chain_t
00200  */
00201 VLC_API config_chain_t * config_ChainDuplicate( const config_chain_t * ) VLC_USED VLC_MALLOC;
00202 
00203 /**
00204  * This function will unescape a string in place and will return a pointer on
00205  * the given string.
00206  * No memory is allocated by it (unlike config_StringEscape).
00207  * If NULL is given as parameter nothing will be done (NULL will be returned).
00208  *
00209  * The following sequences will be unescaped (only one time):
00210  * \\ \' and \"
00211  */
00212 VLC_API char * config_StringUnescape( char *psz_string );
00213 
00214 /**
00215  * This function will escape a string that can be unescaped by
00216  * config_StringUnescape.
00217  * The returned value is allocated by it. You have to free it once you
00218  * do not need it anymore (unlike config_StringUnescape).
00219  * If NULL is given as parameter nothing will be done (NULL will be returned).
00220  *
00221  * The escaped characters are ' " and \
00222  */
00223 VLC_API char * config_StringEscape( const char *psz_string ) VLC_USED VLC_MALLOC;
00224 
00225 # ifdef __cplusplus
00226 }
00227 # endif
00228 
00229 #endif /* _VLC_CONFIGURATION_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines