1 /*****************************************************************************
2 * configuration.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 <stdio.h> /* sprintf() */
30 #include <stdlib.h> /* free(), strtol() */
31 #include <string.h> /* strdup() */
32 #include <errno.h> /* errno */
39 # include <unistd.h> /* getuid() */
42 #ifdef HAVE_GETOPT_LONG
44 # include <getopt.h> /* getopt() */
47 # include "../extras/getopt.h"
50 #if defined(HAVE_GETPWUID)
51 # include <pwd.h> /* getpwuid() */
54 #if defined( HAVE_SYS_STAT_H )
55 # include <sys/stat.h>
57 #if defined( HAVE_SYS_TYPES_H )
58 # include <sys/types.h>
61 # if !defined( UNDER_CE )
67 #include "configuration.h"
68 #include "modules/modules.h"
70 static int ConfigStringToKey( const char * );
71 static char *ConfigKeyToString( int );
73 static inline char *strdupnull (const char *src)
80 static inline char *_strdupnull (const char *src)
84 return strdup (_(src));
87 /* Item types that use a string value (i.e. serialized in the module cache) */
88 int IsConfigStringType (int type)
90 static const unsigned char config_types[] =
92 CONFIG_ITEM_STRING, CONFIG_ITEM_FILE, CONFIG_ITEM_MODULE,
93 CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_MODULE_CAT,
94 CONFIG_ITEM_MODULE_LIST, CONFIG_ITEM_MODULE_LIST_CAT
97 /* NOTE: this needs to be changed if we ever get more than 255 types */
98 return memchr (config_types, type, sizeof (config_types)) != NULL;
102 static int IsConfigIntegerType (int type)
104 static const unsigned char config_types[] =
106 CONFIG_ITEM_INTEGER, CONFIG_ITEM_KEY, CONFIG_ITEM_BOOL,
107 CONFIG_CATEGORY, CONFIG_SUBCATEGORY
110 return memchr (config_types, type, sizeof (config_types)) != NULL;
114 static inline int IsConfigFloatType (int type)
116 return type == CONFIG_ITEM_FLOAT;
120 /*****************************************************************************
121 * config_GetType: get the type of a variable (bool, int, float, string)
122 *****************************************************************************
123 * This function is used to get the type of a variable from its name.
124 * Beware, this is quite slow.
125 *****************************************************************************/
126 int __config_GetType( vlc_object_t *p_this, const char *psz_name )
128 module_config_t *p_config;
131 p_config = config_FindConfig( p_this, psz_name );
139 switch( p_config->i_type )
141 case CONFIG_ITEM_BOOL:
142 i_type = VLC_VAR_BOOL;
145 case CONFIG_ITEM_INTEGER:
146 i_type = VLC_VAR_INTEGER;
149 case CONFIG_ITEM_FLOAT:
150 i_type = VLC_VAR_FLOAT;
153 case CONFIG_ITEM_MODULE:
154 case CONFIG_ITEM_MODULE_CAT:
155 case CONFIG_ITEM_MODULE_LIST:
156 case CONFIG_ITEM_MODULE_LIST_CAT:
157 i_type = VLC_VAR_MODULE;
160 case CONFIG_ITEM_STRING:
161 i_type = VLC_VAR_STRING;
164 case CONFIG_ITEM_FILE:
165 i_type = VLC_VAR_FILE;
168 case CONFIG_ITEM_DIRECTORY:
169 i_type = VLC_VAR_DIRECTORY;
180 /*****************************************************************************
181 * config_GetInt: get the value of an int variable
182 *****************************************************************************
183 * This function is used to get the value of variables which are internally
184 * represented by an integer (CONFIG_ITEM_INTEGER and
186 *****************************************************************************/
187 int __config_GetInt( vlc_object_t *p_this, const char *psz_name )
189 module_config_t *p_config;
191 p_config = config_FindConfig( p_this, psz_name );
196 msg_Err( p_this, "option %s does not exist", psz_name );
200 if (!IsConfigIntegerType (p_config->i_type))
202 msg_Err( p_this, "option %s does not refer to an int", psz_name );
206 return p_config->value.i;
209 /*****************************************************************************
210 * config_GetFloat: get the value of a float variable
211 *****************************************************************************
212 * This function is used to get the value of variables which are internally
213 * represented by a float (CONFIG_ITEM_FLOAT).
214 *****************************************************************************/
215 float __config_GetFloat( vlc_object_t *p_this, const char *psz_name )
217 module_config_t *p_config;
219 p_config = config_FindConfig( p_this, psz_name );
224 msg_Err( p_this, "option %s does not exist", psz_name );
228 if (!IsConfigFloatType (p_config->i_type))
230 msg_Err( p_this, "option %s does not refer to a float", psz_name );
234 return p_config->value.f;
237 /*****************************************************************************
238 * config_GetPsz: get the string value of a string variable
239 *****************************************************************************
240 * This function is used to get the value of variables which are internally
241 * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
242 * CONFIG_ITEM_DIRECTORY, and CONFIG_ITEM_MODULE).
244 * Important note: remember to free() the returned char* because it's a
245 * duplicate of the actual value. It isn't safe to return a pointer to the
246 * actual value as it can be modified at any time.
247 *****************************************************************************/
248 char * __config_GetPsz( vlc_object_t *p_this, const char *psz_name )
250 module_config_t *p_config;
252 p_config = config_FindConfig( p_this, psz_name );
257 msg_Err( p_this, "option %s does not exist", psz_name );
261 if (!IsConfigStringType (p_config->i_type))
263 msg_Err( p_this, "option %s does not refer to a string", psz_name );
267 /* return a copy of the string */
268 vlc_mutex_lock( p_config->p_lock );
269 char *psz_value = strdupnull (p_config->value.psz);
270 vlc_mutex_unlock( p_config->p_lock );
275 /*****************************************************************************
276 * config_PutPsz: set the string value of a string variable
277 *****************************************************************************
278 * This function is used to set the value of variables which are internally
279 * represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
280 * CONFIG_ITEM_DIRECTORY, and CONFIG_ITEM_MODULE).
281 *****************************************************************************/
282 void __config_PutPsz( vlc_object_t *p_this,
283 const char *psz_name, const char *psz_value )
285 module_config_t *p_config;
286 vlc_value_t oldval, val;
288 p_config = config_FindConfig( p_this, psz_name );
294 msg_Warn( p_this, "option %s does not exist", psz_name );
298 if (!IsConfigStringType (p_config->i_type))
300 msg_Err( p_this, "option %s does not refer to a string", psz_name );
304 vlc_mutex_lock( p_config->p_lock );
306 /* backup old value */
307 oldval.psz_string = (char *)p_config->value.psz;
309 if ((psz_value != NULL) && *psz_value)
310 p_config->value.psz = strdup (psz_value);
312 p_config->value.psz = NULL;
314 p_config->b_dirty = VLC_TRUE;
316 val.psz_string = (char *)p_config->value.psz;
318 vlc_mutex_unlock( p_config->p_lock );
320 if( p_config->pf_callback )
322 p_config->pf_callback( p_this, psz_name, oldval, val,
323 p_config->p_callback_data );
326 /* free old string */
327 if( oldval.psz_string ) free( oldval.psz_string );
330 /*****************************************************************************
331 * config_PutInt: set the integer value of an int variable
332 *****************************************************************************
333 * This function is used to set the value of variables which are internally
334 * represented by an integer (CONFIG_ITEM_INTEGER and
336 *****************************************************************************/
337 void __config_PutInt( vlc_object_t *p_this, const char *psz_name, int i_value )
339 module_config_t *p_config;
340 vlc_value_t oldval, val;
342 p_config = config_FindConfig( p_this, psz_name );
347 msg_Warn( p_this, "option %s does not exist", psz_name );
351 if (!IsConfigIntegerType (p_config->i_type))
353 msg_Err( p_this, "option %s does not refer to an int", psz_name );
357 /* backup old value */
358 oldval.i_int = p_config->value.i;
360 /* if i_min == i_max == 0, then do not use them */
361 if ((p_config->min.i == 0) && (p_config->max.i == 0))
363 p_config->value.i = i_value;
365 else if (i_value < p_config->min.i)
367 p_config->value.i = p_config->min.i;
369 else if (i_value > p_config->max.i)
371 p_config->value.i = p_config->max.i;
375 p_config->value.i = i_value;
378 p_config->b_dirty = VLC_TRUE;
380 val.i_int = p_config->value.i;
382 if( p_config->pf_callback )
384 p_config->pf_callback( p_this, psz_name, oldval, val,
385 p_config->p_callback_data );
389 /*****************************************************************************
390 * config_PutFloat: set the value of a float variable
391 *****************************************************************************
392 * This function is used to set the value of variables which are internally
393 * represented by a float (CONFIG_ITEM_FLOAT).
394 *****************************************************************************/
395 void __config_PutFloat( vlc_object_t *p_this,
396 const char *psz_name, float f_value )
398 module_config_t *p_config;
399 vlc_value_t oldval, val;
401 p_config = config_FindConfig( p_this, psz_name );
406 msg_Warn( p_this, "option %s does not exist", psz_name );
410 if (!IsConfigFloatType (p_config->i_type))
412 msg_Err( p_this, "option %s does not refer to a float", psz_name );
416 /* backup old value */
417 oldval.f_float = p_config->value.f;
419 /* if f_min == f_max == 0, then do not use them */
420 if ((p_config->min.f == 0) && (p_config->max.f == 0))
422 p_config->value.f = f_value;
424 else if (f_value < p_config->min.f)
426 p_config->value.f = p_config->min.f;
428 else if (f_value > p_config->max.f)
430 p_config->value.f = p_config->max.f;
434 p_config->value.f = f_value;
437 p_config->b_dirty = VLC_TRUE;
439 val.f_float = p_config->value.f;
441 if( p_config->pf_callback )
443 p_config->pf_callback( p_this, psz_name, oldval, val,
444 p_config->p_callback_data );
448 /*****************************************************************************
449 * config_FindConfig: find the config structure associated with an option.
450 *****************************************************************************
451 * FIXME: This function really needs to be optimized.
452 * FIXME: And now even more.
453 *****************************************************************************/
454 module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name )
459 if( !psz_name ) return NULL;
461 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
463 for( i_index = 0; i_index < p_list->i_count; i_index++ )
465 module_config_t *p_item, *p_end;
466 module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object;
468 if( !p_parser->i_config_items )
471 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
475 if( p_item->i_type & CONFIG_HINT )
478 if( !strcmp( psz_name, p_item->psz_name ) )
480 vlc_list_release( p_list );
486 vlc_list_release( p_list );
491 /*****************************************************************************
492 * config_FindModule: find a specific module structure.
493 *****************************************************************************/
494 module_t *config_FindModule( vlc_object_t *p_this, const char *psz_name )
497 module_t *p_module, *p_result = NULL;
500 if( !psz_name ) return NULL;
502 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
504 for( i_index = 0; i_index < p_list->i_count; i_index++ )
506 p_module = (module_t *)p_list->p_values[i_index].p_object;
507 if( !strcmp( p_module->psz_object_name, psz_name ) )
514 vlc_list_release( p_list );
519 /*****************************************************************************
520 * config_Duplicate: creates a duplicate of a module's configuration data.
521 *****************************************************************************
522 * Unfortunatly we cannot work directly with the module's config data as
523 * this module might be unloaded from memory at any time (remember HideModule).
524 * This is why we need to create an exact copy of the config data.
525 *****************************************************************************/
526 int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
530 const module_config_t *p_item, *p_end = p_orig + n;
532 /* Calculate the structure length */
533 p_module->i_config_items = 0;
534 p_module->i_bool_items = 0;
536 for( p_item = p_orig; p_item < p_end; p_item++ )
538 if( p_item->i_type & CONFIG_ITEM )
540 p_module->i_config_items++;
543 if( p_item->i_type == CONFIG_ITEM_BOOL )
545 p_module->i_bool_items++;
549 /* Allocate memory */
550 p_module->p_config = (module_config_t *)calloc( n, sizeof(*p_orig) );
551 if( p_module->p_config == NULL )
553 msg_Err( p_module, "config error: can't duplicate p_config" );
556 p_module->confsize = n;
558 /* Do the duplication job */
559 for( size_t i = 0; i < n ; i++ )
561 p_module->p_config[i] = p_orig[i];
563 if (IsConfigIntegerType (p_module->p_config[i].i_type))
565 p_module->p_config[i].orig.i = p_orig[i].value.i;
566 p_module->p_config[i].saved.i = p_orig[i].value.i;
569 if (IsConfigFloatType (p_module->p_config[i].i_type))
571 p_module->p_config[i].orig.f = p_orig[i].value.f;
572 p_module->p_config[i].saved.f = p_orig[i].value.f;
575 if (IsConfigStringType (p_module->p_config[i].i_type))
577 p_module->p_config[i].value.psz = strdupnull (p_orig[i].value.psz);
578 p_module->p_config[i].orig.psz = strdupnull (p_orig[i].value.psz);
579 p_module->p_config[i].saved.psz = NULL;
582 p_module->p_config[i].psz_type = strdupnull (p_orig[i].psz_type);
583 p_module->p_config[i].psz_name = strdupnull (p_orig[i].psz_name);
584 p_module->p_config[i].psz_current = strdupnull (p_orig[i].psz_current);
585 p_module->p_config[i].psz_text = _strdupnull (p_orig[i].psz_text);
586 p_module->p_config[i].psz_longtext = _strdupnull (p_orig[i].psz_longtext);
588 p_module->p_config[i].p_lock = &p_module->object_lock;
590 /* duplicate the string list */
591 if( p_orig[i].i_list )
593 if( p_orig[i].ppsz_list )
595 p_module->p_config[i].ppsz_list =
596 malloc( (p_orig[i].i_list + 1) * sizeof(char *) );
597 if( p_module->p_config[i].ppsz_list )
599 for( j = 0; j < p_orig[i].i_list; j++ )
600 p_module->p_config[i].ppsz_list[j] =
601 strdupnull (p_orig[i].ppsz_list[j]);
602 p_module->p_config[i].ppsz_list[j] = NULL;
605 if( p_orig[i].ppsz_list_text )
607 p_module->p_config[i].ppsz_list_text =
608 calloc( (p_orig[i].i_list + 1), sizeof(char *) );
609 if( p_module->p_config[i].ppsz_list_text )
611 for( j = 0; j < p_orig[i].i_list; j++ )
612 p_module->p_config[i].ppsz_list_text[j] =
613 strdupnull (_(p_orig[i].ppsz_list_text[j]));
614 p_module->p_config[i].ppsz_list_text[j] = NULL;
617 if( p_orig[i].pi_list )
619 p_module->p_config[i].pi_list =
620 malloc( (p_orig[i].i_list + 1) * sizeof(int) );
621 if( p_module->p_config[i].pi_list )
623 for( j = 0; j < p_orig[i].i_list; j++ )
624 p_module->p_config[i].pi_list[j] =
625 p_orig[i].pi_list[j];
630 /* duplicate the actions list */
631 if( p_orig[i].i_action )
635 p_module->p_config[i].ppf_action =
636 malloc( p_orig[i].i_action * sizeof(void *) );
637 p_module->p_config[i].ppsz_action_text =
638 malloc( p_orig[i].i_action * sizeof(char *) );
640 for( j = 0; j < p_orig[i].i_action; j++ )
642 p_module->p_config[i].ppf_action[j] =
643 p_orig[i].ppf_action[j];
644 p_module->p_config[i].ppsz_action_text[j] =
645 strdupnull (p_orig[i].ppsz_action_text[j]);
649 p_module->p_config[i].pf_callback = p_orig[i].pf_callback;
655 /*****************************************************************************
656 * config_Free: frees a duplicated module's configuration data.
657 *****************************************************************************
658 * This function frees all the data duplicated by config_Duplicate.
659 *****************************************************************************/
660 void config_Free( module_t *p_module )
664 for (size_t j = 0; j < p_module->confsize; j++)
666 module_config_t *p_item = p_module->p_config + j;
668 free( (char*) p_item->psz_type );
669 free( (char*) p_item->psz_name );
670 free( (char*) p_item->psz_current );
671 free( (char*) p_item->psz_text );
672 free( (char*) p_item->psz_longtext );
674 if (IsConfigStringType (p_item->i_type))
676 free ((char *)p_item->value.psz);
677 free ((char *)p_item->orig.psz);
678 free ((char *)p_item->saved.psz);
683 for( i = 0; i < p_item->i_list; i++ )
685 if( p_item->ppsz_list && p_item->ppsz_list[i] )
686 free( (char*) p_item->ppsz_list[i] );
687 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i] )
688 free( (char*) p_item->ppsz_list_text[i] );
690 if( p_item->ppsz_list ) free( p_item->ppsz_list );
691 if( p_item->ppsz_list_text ) free( p_item->ppsz_list_text );
692 if( p_item->pi_list ) free( p_item->pi_list );
695 if( p_item->i_action )
697 for( i = 0; i < p_item->i_action; i++ )
699 free( (char*) p_item->ppsz_action_text[i] );
701 if( p_item->ppf_action ) free( p_item->ppf_action );
702 if( p_item->ppsz_action_text ) free( p_item->ppsz_action_text );
706 if (p_module->p_config != NULL)
708 free (p_module->p_config);
709 p_module->p_config = NULL;
713 /*****************************************************************************
714 * config_SetCallbacks: sets callback functions in the duplicate p_config.
715 *****************************************************************************
716 * Unfortunatly we cannot work directly with the module's config data as
717 * this module might be unloaded from memory at any time (remember HideModule).
718 * This is why we need to duplicate callbacks each time we reload the module.
719 *****************************************************************************/
720 void config_SetCallbacks( module_config_t *p_new, module_config_t *p_orig,
723 for (size_t i = 0; i < n; i++)
725 p_new->pf_callback = p_orig->pf_callback;
731 /*****************************************************************************
732 * config_UnsetCallbacks: unsets callback functions in the duplicate p_config.
733 *****************************************************************************
734 * We simply undo what we did in config_SetCallbacks.
735 *****************************************************************************/
736 void config_UnsetCallbacks( module_config_t *p_new, size_t n )
738 for (size_t i = 0; i < n; i++)
740 p_new->pf_callback = NULL;
745 /*****************************************************************************
746 * config_ResetAll: reset the configuration data for all the modules.
747 *****************************************************************************/
748 void __config_ResetAll( vlc_object_t *p_this )
754 /* Acquire config file lock */
755 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
757 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
759 for( i_index = 0; i_index < p_list->i_count; i_index++ )
761 p_module = (module_t *)p_list->p_values[i_index].p_object ;
762 if( p_module->b_submodule ) continue;
764 for (size_t i = 0; i < p_module->confsize; i++ )
766 if (IsConfigIntegerType (p_module->p_config[i].i_type))
767 p_module->p_config[i].value.i = p_module->p_config[i].orig.i;
769 if (IsConfigFloatType (p_module->p_config[i].i_type))
770 p_module->p_config[i].value.f = p_module->p_config[i].orig.f;
772 if (IsConfigStringType (p_module->p_config[i].i_type))
774 free ((char *)p_module->p_config[i].value.psz);
775 p_module->p_config[i].value.psz =
776 strdupnull (p_module->p_config[i].orig.psz);
781 vlc_list_release( p_list );
782 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
786 static FILE *config_OpenConfigFile( vlc_object_t *p_obj, const char *mode )
788 static const char psz_subpath[] = DIR_SEP CONFIG_DIR DIR_SEP CONFIG_FILE;
789 const char *psz_filename = p_obj->p_libvlc->psz_configfile;
790 const char *psz_homedir;
794 if( psz_filename == NULL )
796 psz_homedir = p_obj->p_libvlc->psz_homedir;
797 if( psz_homedir == NULL )
799 msg_Err( p_obj, "no home directory defined" );
803 i_buflen = strlen(psz_homedir) + sizeof(psz_subpath) + 1;
807 if( psz_filename == NULL )
809 sprintf( buf, "%s%s", psz_homedir, psz_subpath );
813 msg_Dbg( p_obj, "opening config file (%s)", psz_filename );
814 p_stream = utf8_fopen( psz_filename, mode );
815 if( p_stream == NULL && errno != ENOENT )
816 msg_Err( p_obj, "cannot open config file (%s): %s", psz_filename, strerror(errno) );
822 static int strtoi (const char *str)
828 l = strtol (str, &end, 0);
832 if ((l > INT_MAX) || (l < INT_MIN))
841 /*****************************************************************************
842 * config_LoadConfigFile: loads the configuration file.
843 *****************************************************************************
844 * This function is called to load the config options stored in the config
846 *****************************************************************************/
847 int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
852 file = config_OpenConfigFile (p_this, "rt");
856 /* Acquire config file lock */
857 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
859 /* Look for the selected module, if NULL then save everything */
860 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
862 /* Look for UTF-8 Byte Order Mark */
863 char * (*convert) (const char *) = strdupnull;
866 if ((fread (bom, 1, 3, file) != 3)
867 || memcmp (bom, "\xEF\xBB\xBF", 3))
869 convert = FromLocaleDup;
870 rewind (file); /* no BOM, rewind */
873 module_t *module = NULL;
874 char line[1024], section[1022];
877 while (fgets (line, 1024, file) != NULL)
879 /* Ignore comments and empty lines */
890 char *ptr = strchr (line, ']');
892 continue; /* syntax error; */
895 /* New section ( = a given module) */
896 strcpy (section, line + 1);
899 if ((psz_module_name == NULL)
900 || (strcmp (psz_module_name, section) == 0))
902 for (int i = 0; i < p_list->i_count; i++)
904 module_t *m = (module_t *)p_list->p_values[i].p_object;
906 if ((strcmp (section, m->psz_object_name) == 0)
907 && (m->i_config_items > 0)) /* ignore config-less modules */
910 if (psz_module_name != NULL)
912 "loading config for module \"%s\"",
923 continue; /* no need to parse if there is no matching module */
925 char *ptr = strchr (line, '\n');
929 /* look for option name */
930 const char *psz_option_name = line;
932 ptr = strchr (line, '=');
934 continue; /* syntax error */
937 const char *psz_option_value = ptr + 1;
939 /* try to match this option with one of the module's options */
940 for (size_t i = 0; i < module->confsize; i++)
942 module_config_t *p_item = module->p_config + i;
944 if ((p_item->i_type & CONFIG_HINT)
945 || strcmp (p_item->psz_name, psz_option_name))
951 switch( p_item->i_type )
953 case CONFIG_ITEM_BOOL:
954 case CONFIG_ITEM_INTEGER:
956 long l = strtoi (psz_option_value);
958 msg_Warn (p_this, "Integer value (%s) for %s: %s",
959 psz_option_value, psz_option_name,
962 p_item->saved.i = p_item->value.i = (int)l;
966 case CONFIG_ITEM_FLOAT:
967 if( !*psz_option_value )
968 break; /* ignore empty option */
969 p_item->value.f = (float)i18n_atof( psz_option_value);
970 p_item->saved.f = p_item->value.f;
973 case CONFIG_ITEM_KEY:
974 if( !*psz_option_value )
975 break; /* ignore empty option */
976 p_item->value.i = ConfigStringToKey(psz_option_value);
977 p_item->saved.i = p_item->value.i;
981 vlc_mutex_lock( p_item->p_lock );
983 /* free old string */
984 free( (char*) p_item->value.psz );
985 free( (char*) p_item->saved.psz );
987 p_item->value.psz = convert (psz_option_value);
988 p_item->saved.psz = strdupnull (p_item->value.psz);
990 vlc_mutex_unlock( p_item->p_lock );
1000 msg_Err (p_this, "error reading configuration: %s", strerror (errno));
1005 vlc_list_release( p_list );
1007 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1011 /*****************************************************************************
1012 * config_CreateDir: Create configuration directory if it doesn't exist.
1013 *****************************************************************************/
1014 int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname )
1016 if( !psz_dirname && !*psz_dirname ) return -1;
1018 if( utf8_mkdir( psz_dirname ) && ( errno != EEXIST ) )
1020 msg_Err( p_this, "could not create %s (%s)",
1021 psz_dirname, strerror(errno) );
1028 /*****************************************************************************
1029 * config_SaveConfigFile: Save a module's config options.
1030 *****************************************************************************
1031 * This will save the specified module's config options to the config file.
1032 * If psz_module_name is NULL then we save all the modules config options.
1033 * It's no use to save the config options that kept their default values, so
1034 * we'll try to be a bit clever here.
1036 * When we save we mustn't delete the config options of the modules that
1037 * haven't been loaded. So we cannot just create a new config file with the
1038 * config structures we've got in memory.
1039 * I don't really know how to deal with this nicely, so I will use a completly
1041 * I will load the config file in memory, but skipping all the sections of the
1042 * modules we want to save. Then I will create a brand new file, dump the file
1043 * loaded in memory and then append the sections of the modules we want to
1045 * Really stupid no ?
1046 *****************************************************************************/
1047 static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
1048 vlc_bool_t b_autosave )
1053 char p_line[1024], *p_index2;
1055 char *p_bigbuffer, *p_index;
1056 vlc_bool_t b_backup;
1059 /* Acquire config file lock */
1060 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
1062 if (p_this->p_libvlc->psz_configfile == NULL)
1064 const char *psz_homedir = p_this->p_libvlc->psz_homedir;
1067 msg_Err( p_this, "no home directory defined" );
1068 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1072 char dirname[strlen (psz_homedir) + sizeof (DIR_SEP CONFIG_DIR)];
1073 sprintf (dirname, "%s" DIR_SEP CONFIG_DIR, psz_homedir);
1074 config_CreateDir (p_this, dirname);
1077 file = config_OpenConfigFile (p_this, "rt");
1080 /* look for file size */
1081 fseek( file, 0L, SEEK_END );
1082 i_sizebuf = ftell( file );
1083 fseek( file, 0L, SEEK_SET );
1086 p_bigbuffer = p_index = malloc( i_sizebuf+1 );
1089 msg_Err( p_this, "out of memory" );
1090 if( file ) fclose( file );
1091 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1096 /* List all available modules */
1097 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1099 /* backup file into memory, we only need to backup the sections we won't
1102 while( file && fgets( p_line, 1024, file ) )
1104 if( (p_line[0] == '[') && (p_index2 = strchr(p_line,']')))
1107 /* we found a section, check if we need to do a backup */
1108 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1110 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1112 if( ((p_index2 - &p_line[1])
1113 == (int)strlen(p_parser->psz_object_name) )
1114 && !memcmp( &p_line[1], p_parser->psz_object_name,
1115 strlen(p_parser->psz_object_name) ) )
1117 if( !psz_module_name )
1119 else if( !strcmp( psz_module_name,
1120 p_parser->psz_object_name ) )
1125 if( i_index == p_list->i_count )
1127 /* we don't have this section in our list so we need to back
1131 msg_Dbg( p_this, "backing up config for unknown module \"%s\"",
1144 /* save line if requested and line is valid (doesn't begin with a
1145 * space, tab, or eol) */
1146 if( b_backup && (p_line[0] != '\n') && (p_line[0] != ' ')
1147 && (p_line[0] != '\t') )
1149 strcpy( p_index, p_line );
1150 p_index += strlen( p_line );
1153 if( file ) fclose( file );
1157 * Save module config in file
1160 file = config_OpenConfigFile (p_this, "wt");
1163 vlc_list_release( p_list );
1164 free( p_bigbuffer );
1165 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1169 fprintf( file, "\xEF\xBB\xBF###\n### " COPYRIGHT_MESSAGE "\n###\n\n"
1170 "###\n### lines begining with a '#' character are comments\n###\n\n" );
1172 /* Look for the selected module, if NULL then save everything */
1173 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1175 module_config_t *p_item, *p_end;
1176 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1178 if( psz_module_name && strcmp( psz_module_name,
1179 p_parser->psz_object_name ) )
1182 if( !p_parser->i_config_items )
1185 if( psz_module_name )
1186 msg_Dbg( p_this, "saving config for module \"%s\"",
1187 p_parser->psz_object_name );
1189 fprintf( file, "[%s]", p_parser->psz_object_name );
1190 if( p_parser->psz_longname )
1191 fprintf( file, " # %s\n\n", p_parser->psz_longname );
1193 fprintf( file, "\n\n" );
1195 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
1200 int i_value = p_item->value.i;
1201 float f_value = p_item->value.f;
1202 const char *psz_value = p_item->value.psz;
1204 if( p_item->i_type & CONFIG_HINT )
1207 /* Ignore deprecated options */
1208 if( p_item->psz_current )
1210 if( p_item->b_unsaveable )
1214 if( b_autosave && !p_item->b_autosave )
1216 i_value = p_item->saved.i;
1217 f_value = p_item->saved.f;
1218 psz_value = p_item->saved.psz;
1219 if( !psz_value ) psz_value = p_item->orig.psz;
1223 p_item->b_dirty = VLC_FALSE;
1226 switch( p_item->i_type )
1228 case CONFIG_ITEM_BOOL:
1229 case CONFIG_ITEM_INTEGER:
1230 if( p_item->psz_text )
1231 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1232 (p_item->i_type == CONFIG_ITEM_BOOL) ?
1233 _("boolean") : _("integer") );
1234 if( i_value == p_item->orig.i )
1236 fprintf( file, "%s=%i\n", p_item->psz_name, i_value );
1238 p_item->saved.i = i_value;
1241 case CONFIG_ITEM_KEY:
1242 if( p_item->psz_text )
1243 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1245 if( i_value == p_item->orig.i )
1247 psz_key = ConfigKeyToString( i_value );
1248 fprintf( file, "%s=%s\n", p_item->psz_name,
1249 psz_key ? psz_key : "" );
1252 p_item->saved.i = i_value;
1255 case CONFIG_ITEM_FLOAT:
1256 if( p_item->psz_text )
1257 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1259 if( f_value == p_item->orig.f )
1261 fprintf( file, "%s=%f\n", p_item->psz_name, (double)f_value );
1263 p_item->saved.f = f_value;
1267 if( p_item->psz_text )
1268 fprintf( file, "# %s (%s)\n", p_item->psz_text,
1270 if( (!psz_value && !p_item->orig.psz) ||
1271 (psz_value && p_item->orig.psz &&
1272 !strcmp( psz_value, p_item->orig.psz )) )
1274 fprintf( file, "%s=%s\n", p_item->psz_name,
1277 if( b_autosave && !p_item->b_autosave ) break;
1279 free ((char *)p_item->saved.psz);
1280 if( (psz_value && p_item->orig.psz &&
1281 strcmp( psz_value, p_item->orig.psz )) ||
1282 !psz_value || !p_item->orig.psz)
1283 p_item->saved.psz = strdupnull (psz_value);
1285 p_item->saved.psz = NULL;
1292 vlc_list_release( p_list );
1295 * Restore old settings from the config in file
1297 fputs( p_bigbuffer, file );
1298 free( p_bigbuffer );
1301 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1306 int config_AutoSaveConfigFile( vlc_object_t *p_this )
1309 int i_index, i_count;
1311 if( !p_this ) return -1;
1313 /* Check if there's anything to save */
1314 vlc_mutex_lock( &p_this->p_libvlc->config_lock );
1315 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1316 i_count = p_list->i_count;
1317 for( i_index = 0; i_index < i_count; i_index++ )
1319 module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1320 module_config_t *p_item, *p_end;
1322 if( !p_parser->i_config_items ) continue;
1324 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
1328 if( p_item->b_autosave && p_item->b_dirty ) break;
1332 vlc_list_release( p_list );
1333 vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
1335 if( i_index == i_count ) return VLC_SUCCESS;
1336 return SaveConfigFile( p_this, 0, VLC_TRUE );
1339 int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
1341 return SaveConfigFile( p_this, psz_module_name, VLC_FALSE );
1344 /*****************************************************************************
1345 * config_LoadCmdLine: parse command line
1346 *****************************************************************************
1347 * Parse command line for configuration options.
1348 * Now that the module_bank has been initialized, we can dynamically
1349 * generate the longopts structure used by getops. We have to do it this way
1350 * because we don't know (and don't want to know) in advance the configuration
1351 * options used (ie. exported) by each module.
1352 *****************************************************************************/
1353 int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
1354 vlc_bool_t b_ignore_errors )
1356 int i_cmd, i_index, i_opts, i_shortopts, flag, i_verbose = 0;
1359 struct option *p_longopts;
1360 int i_modules_index;
1363 module_config_t *pp_shortopts[256];
1364 char *psz_shortopts;
1366 /* Set default configuration and copy arguments */
1367 p_this->p_libvlc->i_argc = *pi_argc;
1368 p_this->p_libvlc->ppsz_argv = ppsz_argv;
1371 /* When VLC.app is run by double clicking in Mac OS X, the 2nd arg
1372 * is the PSN - process serial number (a unique PID-ish thingie)
1373 * still ok for real Darwin & when run from command line */
1374 if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
1375 /* for example -psn_0_9306113 */
1377 /* GDMF!... I can't do this or else the MacOSX window server will
1378 * not pick up the PSN and not register the app and we crash...
1379 * hence the following kludge otherwise we'll get confused w/ argv[1]
1380 * being an input file name */
1382 ppsz_argv[ 1 ] = NULL;
1384 *pi_argc = *pi_argc - 1;
1390 /* List all modules */
1391 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1394 * Generate the longopts and shortopts structures used by getopt_long
1398 for( i_modules_index = 0; i_modules_index < p_list->i_count;
1401 p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ;
1403 /* count the number of exported configuration options (to allocate
1404 * longopts). We also need to allocate space for two options when
1405 * dealing with boolean to allow for --foo and --no-foo */
1406 i_opts += p_parser->i_config_items
1407 + 2 * p_parser->i_bool_items;
1410 p_longopts = malloc( sizeof(struct option) * (i_opts + 1) );
1411 if( p_longopts == NULL )
1413 msg_Err( p_this, "out of memory" );
1414 vlc_list_release( p_list );
1418 psz_shortopts = malloc( sizeof( char ) * (2 * i_opts + 1) );
1419 if( psz_shortopts == NULL )
1421 msg_Err( p_this, "out of memory" );
1423 vlc_list_release( p_list );
1427 /* If we are requested to ignore errors, then we must work on a copy
1428 * of the ppsz_argv array, otherwise getopt_long will reorder it for
1429 * us, ignoring the arity of the options */
1430 if( b_ignore_errors )
1432 ppsz_argv = (char**)malloc( *pi_argc * sizeof(char *) );
1433 if( ppsz_argv == NULL )
1435 msg_Err( p_this, "out of memory" );
1436 free( psz_shortopts );
1438 vlc_list_release( p_list );
1441 memcpy( ppsz_argv, p_this->p_libvlc->ppsz_argv,
1442 *pi_argc * sizeof(char *) );
1446 for( i_index = 0; i_index < 256; i_index++ )
1448 pp_shortopts[i_index] = NULL;
1451 /* Fill the p_longopts and psz_shortopts structures */
1453 for( i_modules_index = 0; i_modules_index < p_list->i_count;
1456 module_config_t *p_item, *p_end;
1457 p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ;
1459 if( !p_parser->i_config_items )
1462 for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
1467 if( p_item->i_type & CONFIG_HINT )
1470 /* Add item to long options */
1471 p_longopts[i_index].name = strdup( p_item->psz_name );
1472 if( p_longopts[i_index].name == NULL ) continue;
1473 p_longopts[i_index].has_arg =
1474 (p_item->i_type == CONFIG_ITEM_BOOL)?
1475 no_argument : required_argument;
1476 p_longopts[i_index].flag = &flag;
1477 p_longopts[i_index].val = 0;
1480 /* When dealing with bools we also need to add the --no-foo
1482 if( p_item->i_type == CONFIG_ITEM_BOOL )
1484 char *psz_name = malloc( strlen(p_item->psz_name) + 3 );
1485 if( psz_name == NULL ) continue;
1486 strcpy( psz_name, "no" );
1487 strcat( psz_name, p_item->psz_name );
1489 p_longopts[i_index].name = psz_name;
1490 p_longopts[i_index].has_arg = no_argument;
1491 p_longopts[i_index].flag = &flag;
1492 p_longopts[i_index].val = 1;
1495 psz_name = malloc( strlen(p_item->psz_name) + 4 );
1496 if( psz_name == NULL ) continue;
1497 strcpy( psz_name, "no-" );
1498 strcat( psz_name, p_item->psz_name );
1500 p_longopts[i_index].name = psz_name;
1501 p_longopts[i_index].has_arg = no_argument;
1502 p_longopts[i_index].flag = &flag;
1503 p_longopts[i_index].val = 1;
1507 /* If item also has a short option, add it */
1508 if( p_item->i_short )
1510 pp_shortopts[(int)p_item->i_short] = p_item;
1511 psz_shortopts[i_shortopts] = p_item->i_short;
1513 if( p_item->i_type != CONFIG_ITEM_BOOL )
1515 psz_shortopts[i_shortopts] = ':';
1518 if( p_item->i_short == 'v' )
1520 psz_shortopts[i_shortopts] = ':';
1528 /* We don't need the module list anymore */
1529 vlc_list_release( p_list );
1531 /* Close the longopts and shortopts structures */
1532 memset( &p_longopts[i_index], 0, sizeof(struct option) );
1533 psz_shortopts[i_shortopts] = '\0';
1536 * Parse the command line options
1539 optind = 0; /* set to 0 to tell GNU getopt to reinitialize */
1540 while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv, psz_shortopts,
1541 p_longopts, &i_index ) ) != -1 )
1543 /* A long option has been recognized */
1546 module_config_t *p_conf;
1547 char *psz_name = (char *)p_longopts[i_index].name;
1549 /* Check if we deal with a --nofoo or --no-foo long option */
1550 if( flag ) psz_name += psz_name[2] == '-' ? 3 : 2;
1552 /* Store the configuration option */
1553 p_conf = config_FindConfig( p_this, psz_name );
1556 /* Check if the option is deprecated */
1557 if( p_conf->psz_current )
1559 if( !strcmp(p_conf->psz_current,"SUPPRESSED") )
1561 if( !b_ignore_errors )
1564 "Warning: option --%s is no longer used.\n",
1569 if( !b_ignore_errors )
1571 if( p_conf->b_strict )
1574 "Error: option --%s is deprecated. "
1575 "Use --%s instead.\n",
1576 p_conf->psz_name, p_conf->psz_current);
1578 for( i_index = 0; p_longopts[i_index].name; i_index++ )
1579 free( (char *)p_longopts[i_index].name );
1582 free( psz_shortopts );
1586 "Warning: option --%s is deprecated. "
1587 "You should use --%s instead.\n",
1588 p_conf->psz_name, p_conf->psz_current);
1590 psz_name = (char *)p_conf->psz_current;
1591 p_conf = config_FindConfig( p_this, psz_name );
1594 switch( p_conf->i_type )
1596 case CONFIG_ITEM_STRING:
1597 case CONFIG_ITEM_FILE:
1598 case CONFIG_ITEM_DIRECTORY:
1599 case CONFIG_ITEM_MODULE:
1600 case CONFIG_ITEM_MODULE_LIST:
1601 case CONFIG_ITEM_MODULE_LIST_CAT:
1602 case CONFIG_ITEM_MODULE_CAT:
1603 config_PutPsz( p_this, psz_name, optarg );
1605 case CONFIG_ITEM_INTEGER:
1606 config_PutInt( p_this, psz_name, strtol(optarg, 0, 0));
1608 case CONFIG_ITEM_FLOAT:
1609 config_PutFloat( p_this, psz_name, (float)atof(optarg) );
1611 case CONFIG_ITEM_KEY:
1612 config_PutInt( p_this, psz_name, ConfigStringToKey( optarg ) );
1614 case CONFIG_ITEM_BOOL:
1615 config_PutInt( p_this, psz_name, !flag );
1622 /* A short option has been recognized */
1623 if( pp_shortopts[i_cmd] != NULL )
1625 switch( pp_shortopts[i_cmd]->i_type )
1627 case CONFIG_ITEM_STRING:
1628 case CONFIG_ITEM_FILE:
1629 case CONFIG_ITEM_DIRECTORY:
1630 case CONFIG_ITEM_MODULE:
1631 case CONFIG_ITEM_MODULE_CAT:
1632 case CONFIG_ITEM_MODULE_LIST:
1633 case CONFIG_ITEM_MODULE_LIST_CAT:
1634 config_PutPsz( p_this, pp_shortopts[i_cmd]->psz_name, optarg );
1636 case CONFIG_ITEM_INTEGER:
1641 if( *optarg == 'v' ) /* eg. -vvv */
1644 while( *optarg == 'v' )
1652 i_verbose += atoi( optarg ); /* eg. -v2 */
1657 i_verbose++; /* -v */
1659 config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name,
1664 config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name,
1665 strtol(optarg, 0, 0) );
1668 case CONFIG_ITEM_BOOL:
1669 config_PutInt( p_this, pp_shortopts[i_cmd]->psz_name, 1 );
1676 /* Internal error: unknown option */
1677 if( !b_ignore_errors )
1679 fprintf( stderr, "%s: unknown option"
1680 " or missing mandatory argument ",
1681 p_this->p_libvlc->psz_object_name );
1684 fprintf( stderr, "`-%c'\n", optopt );
1688 fprintf( stderr, "`%s'\n", ppsz_argv[optind-1] );
1690 fprintf( stderr, "Try `%s --help' for more information.\n",
1691 p_this->p_libvlc->psz_object_name );
1693 for( i_index = 0; p_longopts[i_index].name; i_index++ )
1694 free( (char *)p_longopts[i_index].name );
1696 free( psz_shortopts );
1701 /* Free allocated resources */
1702 for( i_index = 0; p_longopts[i_index].name; i_index++ )
1703 free( (char *)p_longopts[i_index].name );
1705 free( psz_shortopts );
1706 if( b_ignore_errors ) free( ppsz_argv );
1712 * config_GetDataDir: find directory where shared data is installed
1714 * @return a string (always succeeds).
1716 const char *config_GetDataDir( const vlc_object_t *p_this )
1718 #if defined (WIN32) || defined (UNDER_CE)
1719 return vlc_global( p_this )->psz_vlcpath;
1720 #elif defined(__APPLE__) || defined (SYS_BEOS)
1721 static char path[PATH_MAX] = "";
1725 snprintf( path, sizeof( path ), "%s/share",
1726 vlc_global( p_this )->psz_vlcpath );
1727 path[sizeof( path ) - 1] = '\0';
1736 /*****************************************************************************
1737 * config_GetHomeDir, config_GetUserDir: find the user's home directory.
1738 *****************************************************************************
1739 * This function will try by different ways to find the user's home path.
1740 * Note that this function is not reentrant, it should be called only once
1741 * at the beginning of main where the result will be stored for later use.
1742 *****************************************************************************/
1743 static char *GetDir( vlc_bool_t b_appdata )
1745 const char *psz_localhome = NULL;
1747 #if defined(WIN32) && !defined(UNDER_CE)
1748 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
1750 #ifndef CSIDL_FLAG_CREATE
1751 # define CSIDL_FLAG_CREATE 0x8000
1753 #ifndef CSIDL_APPDATA
1754 # define CSIDL_APPDATA 0x1A
1756 #ifndef CSIDL_PROFILE
1757 # define CSIDL_PROFILE 0x28
1759 #ifndef SHGFP_TYPE_CURRENT
1760 # define SHGFP_TYPE_CURRENT 0
1763 HINSTANCE shfolder_dll;
1764 SHGETFOLDERPATH SHGetFolderPath ;
1766 /* load the shfolder dll to retrieve SHGetFolderPath */
1767 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
1769 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
1770 _T("SHGetFolderPathW") );
1771 if ( SHGetFolderPath != NULL )
1773 wchar_t whomedir[MAX_PATH];
1775 /* get the "Application Data" folder for the current user */
1776 if( S_OK == SHGetFolderPath( NULL,
1777 (b_appdata ? CSIDL_APPDATA :
1778 CSIDL_PROFILE) | CSIDL_FLAG_CREATE,
1779 NULL, SHGFP_TYPE_CURRENT,
1782 FreeLibrary( shfolder_dll );
1783 return FromWide( whomedir );
1786 FreeLibrary( shfolder_dll );
1789 #elif defined(UNDER_CE)
1791 #ifndef CSIDL_APPDATA
1792 # define CSIDL_APPDATA 0x1A
1795 wchar_t whomedir[MAX_PATH];
1797 /* get the "Application Data" folder for the current user */
1798 if( SHGetSpecialFolderPath( NULL, whomedir, CSIDL_APPDATA, 1 ) )
1799 return FromWide( whomedir );
1802 #if defined(HAVE_GETPWUID)
1803 struct passwd *p_pw;
1806 if( ( p_pw = getpwuid( getuid() ) ) == NULL )
1809 psz_localhome = getenv( "HOME" );
1810 if( psz_localhome == NULL )
1812 psz_localhome = getenv( "TMP" );
1813 if( psz_localhome == NULL )
1814 psz_localhome = "/tmp";
1817 #if defined(HAVE_GETPWUID)
1819 psz_localhome = p_pw->pw_dir;
1822 return FromLocaleDup( psz_localhome );
1825 char *config_GetHomeDir( void )
1827 return GetDir( VLC_TRUE );
1830 char *config_GetUserDir( void )
1832 return GetDir( VLC_FALSE );
1836 static int ConfigStringToKey( const char *psz_key )
1840 const char *psz_parser = strchr( psz_key, '-' );
1841 while( psz_parser && psz_parser != psz_key )
1843 for( i = 0; i < sizeof(vlc_modifiers) / sizeof(key_descriptor_t); i++ )
1845 if( !strncasecmp( vlc_modifiers[i].psz_key_string, psz_key,
1846 strlen( vlc_modifiers[i].psz_key_string ) ) )
1848 i_key |= vlc_modifiers[i].i_key_code;
1851 psz_key = psz_parser + 1;
1852 psz_parser = strchr( psz_key, '-' );
1854 for( i = 0; i < sizeof(vlc_keys) / sizeof( key_descriptor_t ); i++ )
1856 if( !strcasecmp( vlc_keys[i].psz_key_string, psz_key ) )
1858 i_key |= vlc_keys[i].i_key_code;
1865 static char *ConfigKeyToString( int i_key )
1867 char *psz_key = malloc( 100 );
1877 for( index = 0; index < (sizeof(vlc_modifiers) / sizeof(key_descriptor_t));
1880 if( i_key & vlc_modifiers[index].i_key_code )
1882 p += sprintf( p, "%s-", vlc_modifiers[index].psz_key_string );
1885 for( index = 0; index < (sizeof(vlc_keys) / sizeof( key_descriptor_t));
1888 if( (int)( i_key & ~KEY_MODIFIER ) == vlc_keys[index].i_key_code )
1890 p += sprintf( p, "%s", vlc_keys[index].psz_key_string );