1 /*****************************************************************************
2 * core.c management of the modules configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2007 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include "../libvlc.h"
27 #include "vlc_charset.h"
29 #include <errno.h> /* errno */
36 # include <unistd.h> /* getuid() */
39 #ifdef HAVE_GETOPT_LONG
41 # include <getopt.h> /* getopt() */
44 # include "../extras/getopt.h"
47 #if defined(HAVE_GETPWUID)
48 # include <pwd.h> /* getpwuid() */
51 #if defined( HAVE_SYS_STAT_H )
52 # include <sys/stat.h>
54 #if defined( HAVE_SYS_TYPES_H )
55 # include <sys/types.h>
58 # if !defined( UNDER_CE )
65 #include "modules/modules.h"
67 static inline char *strdupnull (const char *src)
69 return src ? strdup (src) : NULL;
72 static inline char *_strdupnull (const char *src)
74 return src ? strdup (_(src)) : NULL;
77 /* Item types that use a string value (i.e. serialized in the module cache) */
78 int IsConfigStringType (int type)
80 static const unsigned char config_types[] =
82 CONFIG_ITEM_STRING, CONFIG_ITEM_FILE, CONFIG_ITEM_MODULE,
83 CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_MODULE_CAT, CONFIG_ITEM_PASSWORD,
84 CONFIG_ITEM_MODULE_LIST, CONFIG_ITEM_MODULE_LIST_CAT
87 /* NOTE: this needs to be changed if we ever get more than 255 types */
88 return memchr (config_types, type, sizeof (config_types)) != NULL;
92 int IsConfigIntegerType (int type)
94 static const unsigned char config_types[] =
96 CONFIG_ITEM_INTEGER, CONFIG_ITEM_KEY, CONFIG_ITEM_BOOL,
97 CONFIG_CATEGORY, CONFIG_SUBCATEGORY
100 return memchr (config_types, type, sizeof (config_types)) != NULL;
104 /*****************************************************************************
105 * config_GetType: get the type of a variable (bool, int, float, string)
106 *****************************************************************************
107 * This function is used to get the type of a variable from its name.
108 * Beware, this is quite slow.
109 *****************************************************************************/
110 int __config_GetType( vlc_object_t *p_this, const char *psz_name )
112 module_config_t *p_config;
115 p_config = config_FindConfig( p_this, psz_name );
123 switch( p_config->i_type )
125 case CONFIG_ITEM_BOOL:
126 i_type = VLC_VAR_BOOL;
129 case CONFIG_ITEM_INTEGER:
130 case CONFIG_ITEM_KEY:
131 i_type = VLC_VAR_INTEGER;
134 case CONFIG_ITEM_FLOAT:
135 i_type = VLC_VAR_FLOAT;
138 case CONFIG_ITEM_MODULE:
139 case CONFIG_ITEM_MODULE_CAT:
140 case CONFIG_ITEM_MODULE_LIST:
141 case CONFIG_ITEM_MODULE_LIST_CAT:
142 i_type = VLC_VAR_MODULE;
145 case CONFIG_ITEM_STRING:
146 i_type = VLC_VAR_STRING;
149 case CONFIG_ITEM_PASSWORD:
150 i_type = VLC_VAR_STRING;
153 case CONFIG_ITEM_FILE:
154 i_type = VLC_VAR_FILE;
157 case CONFIG_ITEM_DIRECTORY:
158 i_type = VLC_VAR_DIRECTORY;
169 /*****************************************************************************
170 * config_GetInt: get the value of an int variable
171 *****************************************************************************
172 * This function is used to get the value of variables which are internally
173 * represented by an integer (CONFIG_ITEM_INTEGER and
175 *****************************************************************************/
176 int __config_GetInt( vlc_object_t *p_this, const char *psz_name )
178 module_config_t *p_config;
180 p_config = config_FindConfig( p_this, psz_name );
185 msg_Err( p_this, "option %s does not exist", psz_name );
189 if (!IsConfigIntegerType (p_config->i_type))
191 msg_Err( p_this, "option %s does not refer to an int", psz_name );
195 return p_config->value.i;
198 /*****************************************************************************
199 * config_GetFloat: get the value of a float variable
200 *****************************************************************************
201 * This function is used to get the value of variables which are internally
202 * represented by a float (CONFIG_ITEM_FLOAT).
203 *****************************************************************************/
204 float __config_GetFloat( vlc_object_t *p_this, const char *psz_name )
206 module_config_t *p_config;
208 p_config = config_FindConfig( p_this, psz_name );
213 msg_Err( p_this, "option %s does not exist", psz_name );
217 if (!IsConfigFloatType (p_config->i_type))
219 msg_Err( p_this, "option %s does not refer to a float", psz_name );
223 return p_config->value.f;
226 /*****************************************************************************
227 * config_GetPsz: get the string value of a string variable
228 *****************************************************************************
229 * This function is used to get the value of variables which are internally
230 * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
231 * CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_PASSWORD, and CONFIG_ITEM_MODULE).
233 * Important note: remember to free() the returned char* because it's a
234 * duplicate of the actual value. It isn't safe to return a pointer to the
235 * actual value as it can be modified at any time.
236 *****************************************************************************/
237 char * __config_GetPsz( vlc_object_t *p_this, const char *psz_name )
239 module_config_t *p_config;
241 p_config = config_FindConfig( p_this, psz_name );
246 msg_Err( p_this, "option %s does not exist", psz_name );
250 if (!IsConfigStringType (p_config->i_type))
252 msg_Err( p_this, "option %s does not refer to a string", psz_name );
256 /* return a copy of the string */
257 vlc_mutex_lock( p_config->p_lock );
258 char *psz_value = strdupnull (p_config->value.psz);
259 vlc_mutex_unlock( p_config->p_lock );
264 /*****************************************************************************
265 * config_PutPsz: set the string value of a string variable
266 *****************************************************************************
267 * This function is used to set the value of variables which are internally
268 * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
269 * CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_PASSWORD, and CONFIG_ITEM_MODULE).
270 *****************************************************************************/
271 void __config_PutPsz( vlc_object_t *p_this,
272 const char *psz_name, const char *psz_value )
274 module_config_t *p_config;
275 vlc_value_t oldval, val;
277 p_config = config_FindConfig( p_this, psz_name );
283 msg_Warn( p_this, "option %s does not exist", psz_name );
287 if (!IsConfigStringType (p_config->i_type))
289 msg_Err( p_this, "option %s does not refer to a string", psz_name );
293 vlc_mutex_lock( p_config->p_lock );
295 /* backup old value */
296 oldval.psz_string = (char *)p_config->value.psz;
298 if ((psz_value != NULL) && *psz_value)
299 p_config->value.psz = strdup (psz_value);
301 p_config->value.psz = NULL;
303 p_config->b_dirty = VLC_TRUE;
305 val.psz_string = (char *)p_config->value.psz;
307 vlc_mutex_unlock( p_config->p_lock );
309 if( p_config->pf_callback )
311 p_config->pf_callback( p_this, psz_name, oldval, val,
312 p_config->p_callback_data );
315 /* free old string */
316 if( oldval.psz_string ) free( oldval.psz_string );
319 /*****************************************************************************
320 * config_PutInt: set the integer value of an int variable
321 *****************************************************************************
322 * This function is used to set the value of variables which are internally
323 * represented by an integer (CONFIG_ITEM_INTEGER and
325 *****************************************************************************/
326 void __config_PutInt( vlc_object_t *p_this, const char *psz_name, int i_value )
328 module_config_t *p_config;
329 vlc_value_t oldval, val;
331 p_config = config_FindConfig( p_this, psz_name );
336 msg_Warn( p_this, "option %s does not exist", psz_name );
340 if (!IsConfigIntegerType (p_config->i_type))
342 msg_Err( p_this, "option %s does not refer to an int", psz_name );
346 /* backup old value */
347 oldval.i_int = p_config->value.i;
349 /* if i_min == i_max == 0, then do not use them */
350 if ((p_config->min.i == 0) && (p_config->max.i == 0))
352 p_config->value.i = i_value;
354 else if (i_value < p_config->min.i)
356 p_config->value.i = p_config->min.i;
358 else if (i_value > p_config->max.i)
360 p_config->value.i = p_config->max.i;
364 p_config->value.i = i_value;
367 p_config->b_dirty = VLC_TRUE;
369 val.i_int = p_config->value.i;
371 if( p_config->pf_callback )
373 p_config->pf_callback( p_this, psz_name, oldval, val,
374 p_config->p_callback_data );
378 /*****************************************************************************
379 * config_PutFloat: set the value of a float variable
380 *****************************************************************************
381 * This function is used to set the value of variables which are internally
382 * represented by a float (CONFIG_ITEM_FLOAT).
383 *****************************************************************************/
384 void __config_PutFloat( vlc_object_t *p_this,
385 const char *psz_name, float f_value )
387 module_config_t *p_config;
388 vlc_value_t oldval, val;
390 p_config = config_FindConfig( p_this, psz_name );
395 msg_Warn( p_this, "option %s does not exist", psz_name );
399 if (!IsConfigFloatType (p_config->i_type))
401 msg_Err( p_this, "option %s does not refer to a float", psz_name );
405 /* backup old value */
406 oldval.f_float = p_config->value.f;
408 /* if f_min == f_max == 0, then do not use them */
409 if ((p_config->min.f == 0) && (p_config->max.f == 0))
411 p_config->value.f = f_value;
413 else if (f_value < p_config->min.f)
415 p_config->value.f = p_config->min.f;
417 else if (f_value > p_config->max.f)
419 p_config->value.f = p_config->max.f;
423 p_config->value.f = f_value;
426 p_config->b_dirty = VLC_TRUE;
428 val.f_float = p_config->value.f;
430 if( p_config->pf_callback )
432 p_config->pf_callback( p_this, psz_name, oldval, val,
433 p_config->p_callback_data );
437 /*****************************************************************************
438 * config_FindConfig: find the config structure associated with an option.
439 *****************************************************************************
440 * FIXME: This function really needs to be optimized.
441 * FIXME: And now even more.
442 *****************************************************************************/
443 module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name )
448 if( !psz_name ) return NULL;
450 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
452 for( i_index = 0; i_index < p_list->i_count; i_index++ )
454 module_config_t *p_item, *p_end;
455 module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object;
457 if( !p_parser->i_config_items )
460 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
464 if( p_item->i_type & CONFIG_HINT )
467 if( !strcmp( psz_name, p_item->psz_name ) )
469 vlc_list_release( p_list );
475 vlc_list_release( p_list );
480 /*****************************************************************************
481 * config_Duplicate: creates a duplicate of a module's configuration data.
482 *****************************************************************************
483 * Unfortunatly we cannot work directly with the module's config data as
484 * this module might be unloaded from memory at any time (remember HideModule).
485 * This is why we need to create an exact copy of the config data.
486 *****************************************************************************/
487 int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
491 const module_config_t *p_item, *p_end = p_orig + n;
493 /* Calculate the structure length */
494 p_module->i_config_items = 0;
495 p_module->i_bool_items = 0;
497 for( p_item = p_orig; p_item < p_end; p_item++ )
499 if( p_item->i_type & CONFIG_ITEM )
501 p_module->i_config_items++;
504 if( p_item->i_type == CONFIG_ITEM_BOOL )
506 p_module->i_bool_items++;
510 /* Allocate memory */
511 p_module->p_config = (module_config_t *)calloc( n, sizeof(*p_orig) );
512 if( p_module->p_config == NULL )
514 msg_Err( p_module, "config error: can't duplicate p_config" );
517 p_module->confsize = n;
519 /* Do the duplication job */
520 for( size_t i = 0; i < n ; i++ )
522 p_module->p_config[i] = p_orig[i];
523 p_module->p_config[i].p_lock = &p_module->object_lock;
525 /* duplicate the string list */
526 if( p_orig[i].i_list )
528 if( p_orig[i].ppsz_list )
530 p_module->p_config[i].ppsz_list =
531 malloc( (p_orig[i].i_list + 1) * sizeof(char *) );
532 if( p_module->p_config[i].ppsz_list )
534 for( j = 0; j < p_orig[i].i_list; j++ )
535 p_module->p_config[i].ppsz_list[j] =
536 strdupnull (p_orig[i].ppsz_list[j]);
537 p_module->p_config[i].ppsz_list[j] = NULL;
540 if( p_orig[i].ppsz_list_text )
542 p_module->p_config[i].ppsz_list_text =
543 calloc( (p_orig[i].i_list + 1), sizeof(char *) );
544 if( p_module->p_config[i].ppsz_list_text )
546 for( j = 0; j < p_orig[i].i_list; j++ )
547 p_module->p_config[i].ppsz_list_text[j] =
548 strdupnull (_(p_orig[i].ppsz_list_text[j]));
549 p_module->p_config[i].ppsz_list_text[j] = NULL;
552 if( p_orig[i].pi_list )
554 p_module->p_config[i].pi_list =
555 malloc( (p_orig[i].i_list + 1) * sizeof(int) );
556 if( p_module->p_config[i].pi_list )
558 for( j = 0; j < p_orig[i].i_list; j++ )
559 p_module->p_config[i].pi_list[j] =
560 p_orig[i].pi_list[j];
565 /* duplicate the actions list */
566 if( p_orig[i].i_action )
570 p_module->p_config[i].ppf_action =
571 malloc( p_orig[i].i_action * sizeof(void *) );
572 p_module->p_config[i].ppsz_action_text =
573 malloc( p_orig[i].i_action * sizeof(char *) );
575 for( j = 0; j < p_orig[i].i_action; j++ )
577 p_module->p_config[i].ppf_action[j] =
578 p_orig[i].ppf_action[j];
579 p_module->p_config[i].ppsz_action_text[j] =
580 strdupnull (p_orig[i].ppsz_action_text[j]);
584 p_module->p_config[i].pf_callback = p_orig[i].pf_callback;
590 /*****************************************************************************
591 * config_Free: frees a duplicated module's configuration data.
592 *****************************************************************************
593 * This function frees all the data duplicated by config_Duplicate.
594 *****************************************************************************/
595 void config_Free( module_t *p_module )
599 for (size_t j = 0; j < p_module->confsize; j++)
601 module_config_t *p_item = p_module->p_config + j;
603 free( (char*) p_item->psz_type );
604 free( (char*) p_item->psz_name );
605 free( (char*) p_item->psz_text );
606 free( (char*) p_item->psz_longtext );
608 if (IsConfigStringType (p_item->i_type))
610 free ((char *)p_item->value.psz);
611 free ((char *)p_item->orig.psz);
612 free ((char *)p_item->saved.psz);
617 for( i = 0; i < p_item->i_list; i++ )
619 if( p_item->ppsz_list && p_item->ppsz_list[i] )
620 free( (char*) p_item->ppsz_list[i] );
621 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i] )
622 free( (char*) p_item->ppsz_list_text[i] );
624 if( p_item->ppsz_list ) free( p_item->ppsz_list );
625 if( p_item->ppsz_list_text ) free( p_item->ppsz_list_text );
626 if( p_item->pi_list ) free( p_item->pi_list );
629 if( p_item->i_action )
631 for( i = 0; i < p_item->i_action; i++ )
633 free( (char*) p_item->ppsz_action_text[i] );
635 if( p_item->ppf_action ) free( p_item->ppf_action );
636 if( p_item->ppsz_action_text ) free( p_item->ppsz_action_text );
640 if (p_module->p_config != NULL)
642 free (p_module->p_config);
643 p_module->p_config = NULL;
647 /*****************************************************************************
648 * config_SetCallbacks: sets callback functions in the duplicate p_config.
649 *****************************************************************************
650 * Unfortunatly we cannot work directly with the module's config data as
651 * this module might be unloaded from memory at any time (remember HideModule).
652 * This is why we need to duplicate callbacks each time we reload the module.
653 *****************************************************************************/
654 void config_SetCallbacks( module_config_t *p_new, module_config_t *p_orig,
657 for (size_t i = 0; i < n; i++)
659 p_new->pf_callback = p_orig->pf_callback;
665 /*****************************************************************************
666 * config_UnsetCallbacks: unsets callback functions in the duplicate p_config.
667 *****************************************************************************
668 * We simply undo what we did in config_SetCallbacks.
669 *****************************************************************************/
670 void config_UnsetCallbacks( module_config_t *p_new, size_t n )
672 for (size_t i = 0; i < n; i++)
674 p_new->pf_callback = NULL;
679 /*****************************************************************************
680 * config_ResetAll: reset the configuration data for all the modules.
681 *****************************************************************************/
682 void __config_ResetAll( vlc_object_t *p_this )
688 /* Acquire config file lock */
689 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
691 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
693 for( i_index = 0; i_index < p_list->i_count; i_index++ )
695 p_module = (module_t *)p_list->p_values[i_index].p_object ;
696 if( p_module->b_submodule ) continue;
698 for (size_t i = 0; i < p_module->confsize; i++ )
700 if (IsConfigIntegerType (p_module->p_config[i].i_type))
701 p_module->p_config[i].value.i = p_module->p_config[i].orig.i;
703 if (IsConfigFloatType (p_module->p_config[i].i_type))
704 p_module->p_config[i].value.f = p_module->p_config[i].orig.f;
706 if (IsConfigStringType (p_module->p_config[i].i_type))
708 free ((char *)p_module->p_config[i].value.psz);
709 p_module->p_config[i].value.psz =
710 strdupnull (p_module->p_config[i].orig.psz);
715 vlc_list_release( p_list );
716 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
720 * config_GetDataDir: find directory where shared data is installed
722 * @return a string (always succeeds).
724 const char *config_GetDataDir( void )
726 #if defined (WIN32) || defined (UNDER_CE)
727 return vlc_global()->psz_vlcpath;
728 #elif defined(__APPLE__) || defined (SYS_BEOS)
729 static char path[PATH_MAX] = "";
733 snprintf( path, sizeof( path ), "%s/share",
734 vlc_global()->psz_vlcpath );
735 path[sizeof( path ) - 1] = '\0';
743 /*****************************************************************************
744 * config_GetHomeDir, config_GetUserDir: find the user's home directory.
745 *****************************************************************************
746 * This function will try by different ways to find the user's home path.
747 * Note that this function is not reentrant, it should be called only once
748 * at the beginning of main where the result will be stored for later use.
749 *****************************************************************************/
750 static char *GetDir( vlc_bool_t b_appdata )
752 const char *psz_localhome = NULL;
754 #if defined(WIN32) && !defined(UNDER_CE)
755 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
757 #ifndef CSIDL_FLAG_CREATE
758 # define CSIDL_FLAG_CREATE 0x8000
760 #ifndef CSIDL_APPDATA
761 # define CSIDL_APPDATA 0x1A
763 #ifndef CSIDL_PROFILE
764 # define CSIDL_PROFILE 0x28
766 #ifndef SHGFP_TYPE_CURRENT
767 # define SHGFP_TYPE_CURRENT 0
770 HINSTANCE shfolder_dll;
771 SHGETFOLDERPATH SHGetFolderPath ;
773 /* load the shfolder dll to retrieve SHGetFolderPath */
774 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
776 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
777 _T("SHGetFolderPathW") );
778 if ( SHGetFolderPath != NULL )
780 wchar_t whomedir[MAX_PATH];
782 /* get the "Application Data" folder for the current user */
783 if( S_OK == SHGetFolderPath( NULL,
784 (b_appdata ? CSIDL_APPDATA :
785 CSIDL_PROFILE) | CSIDL_FLAG_CREATE,
786 NULL, SHGFP_TYPE_CURRENT,
789 FreeLibrary( shfolder_dll );
790 return FromWide( whomedir );
793 FreeLibrary( shfolder_dll );
796 #elif defined(UNDER_CE)
798 #ifndef CSIDL_APPDATA
799 # define CSIDL_APPDATA 0x1A
802 wchar_t whomedir[MAX_PATH];
804 /* get the "Application Data" folder for the current user */
805 if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) )
806 return FromWide( whomedir );
809 psz_localhome = getenv( "HOME" );
810 if( psz_localhome == NULL )
812 #if defined(HAVE_GETPWUID)
816 if( ( p_pw = getpwuid( getuid() ) ) != NULL )
817 psz_localhome = p_pw->pw_dir;
821 psz_localhome = getenv( "TMP" );
822 if( psz_localhome == NULL )
823 psz_localhome = "/tmp";
827 return FromLocaleDup( psz_localhome );
831 * Get the user's home directory
833 char *config_GetHomeDir( void )
835 return GetDir( VLC_FALSE );
839 * Get the user's main data and config directory:
840 * - on windows that's the App Data directory;
841 * - on other OSes it's the same as the home directory.
843 char *config_GetUserDir( void );
844 char *config_GetUserDir( void )
846 return GetDir( VLC_TRUE );
850 * Get the user's VLC configuration directory
852 char *config_GetConfigDir( libvlc_int_t *p_libvlc )
855 #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS)
856 char *psz_parent = config_GetUserDir();
857 if( !psz_parent ) psz_parent = p_libvlc->psz_homedir;
858 if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 )
862 /* XDG Base Directory Specification - Version 0.6 */
863 char *psz_env = getenv( "XDG_CONFIG_HOME" );
866 if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 )
870 psz_env = getenv( "HOME" );
871 if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */
872 if( asprintf( &psz_dir, "%s/.config/vlc", psz_env ) == -1 )
879 * Get the user's VLC data directory
880 * (used for stuff like the skins, custom lua modules, ...)
882 char *config_GetUserDataDir( libvlc_int_t *p_libvlc )
885 #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS)
886 char *psz_parent = config_GetUserDir();
887 if( !psz_parent ) psz_parent = p_libvlc->psz_homedir;
888 if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 )
892 /* XDG Base Directory Specification - Version 0.6 */
893 char *psz_env = getenv( "XDG_DATA_HOME" );
896 if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 )
900 psz_env = getenv( "HOME" );
901 if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */
902 if( asprintf( &psz_dir, "%s/.local/share/vlc", psz_env ) == -1 )
909 * Get the user's VLC cache directory
910 * (used for stuff like the modules cache, the album art cache, ...)
912 char *config_GetCacheDir( libvlc_int_t *p_libvlc )
915 #if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS)
916 char *psz_parent = config_GetUserDir();
917 if( !psz_parent ) psz_parent = p_libvlc->psz_homedir;
918 if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 )
922 /* XDG Base Directory Specification - Version 0.6 */
923 char *psz_env = getenv( "XDG_CACHE_HOME" );
926 if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 )
930 psz_env = getenv( "HOME" );
931 if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */
932 if( asprintf( &psz_dir, "%s/.cache/vlc", psz_env ) == -1 )
938 /* Adds an extra interface to the configuration */
939 void __config_AddIntf( vlc_object_t *p_this, const char *psz_intf )
943 char *psz_config, *psz_parser;
944 size_t i_len = strlen( psz_intf );
946 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
949 if( !strncmp( psz_intf, psz_parser, i_len ) )
954 psz_parser = strchr( psz_parser, ':' );
955 if( psz_parser ) psz_parser++; /* skip the ':' */
959 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
962 if( !strncmp( psz_intf, psz_parser, i_len ) )
967 psz_parser = strchr( psz_parser, ':' );
968 if( psz_parser ) psz_parser++; /* skip the ':' */
971 /* interface not found in the config, let's add it */
972 if( psz_config && strlen( psz_config ) > 0 )
975 if( asprintf( &psz_newconfig, "%s:%s", psz_config, psz_intf ) != -1 )
977 config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
978 free( psz_newconfig );
982 config_PutPsz( p_this->p_libvlc, "extraintf", psz_intf );
987 /* Removes an extra interface from the configuration */
988 void __config_RemoveIntf( vlc_object_t *p_this, const char *psz_intf )
992 char *psz_config, *psz_parser;
993 size_t i_len = strlen( psz_intf );
995 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
998 if( !strncmp( psz_intf, psz_parser, i_len ) )
1000 char *psz_newconfig;
1001 char *psz_end = psz_parser + i_len;
1002 if( *psz_end == ':' ) psz_end++;
1004 if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
1006 config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
1007 free( psz_newconfig );
1011 psz_parser = strchr( psz_parser, ':' );
1012 if( psz_parser ) psz_parser++; /* skip the ':' */
1016 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
1019 if( !strncmp( psz_intf, psz_parser, i_len ) )
1021 char *psz_newconfig;
1022 char *psz_end = psz_parser + i_len;
1023 if( *psz_end == ':' ) psz_end++;
1025 if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
1027 config_PutPsz( p_this->p_libvlc, "control", psz_newconfig );
1028 free( psz_newconfig );
1032 psz_parser = strchr( psz_parser, ':' );
1033 if( psz_parser ) psz_parser++; /* skip the ':' */
1039 * Returns VLC_TRUE if the specified extra interface is present in the
1040 * configuration, VLC_FALSE if not
1042 vlc_bool_t __config_ExistIntf( vlc_object_t *p_this, const char *psz_intf )
1046 char *psz_config, *psz_parser;
1047 size_t i_len = strlen( psz_intf );
1049 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
1052 if( !strncmp( psz_parser, psz_intf, i_len ) )
1057 psz_parser = strchr( psz_parser, ':' );
1058 if( psz_parser ) psz_parser++; /* skip the ':' */
1062 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
1065 if( !strncmp( psz_parser, psz_intf, i_len ) )
1070 psz_parser = strchr( psz_parser, ':' );
1071 if( psz_parser ) psz_parser++; /* skip the ':' */