*****************************************************************************/
#include <vlc/vlc.h>
+#include "../libvlc.h"
#include "vlc_keys.h"
#include "vlc_charset.h"
#endif
#include "configuration.h"
+#include "modules/modules.h"
static int ConfigStringToKey( const char * );
static char *ConfigKeyToString( int );
-static inline void freenull (const void *p)
-{
- if (p != NULL)
- free ((void *)p);
-}
-
static inline char *strdupnull (const char *src)
{
if (src == NULL)
return strdup (_(src));
}
+/* Item types that use a string value (i.e. serialized in the module cache) */
+int IsConfigStringType (int type)
+{
+ static const unsigned char config_types[] =
+ {
+ CONFIG_ITEM_STRING, CONFIG_ITEM_FILE, CONFIG_ITEM_MODULE,
+ CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_MODULE_CAT, CONFIG_ITEM_PASSWORD,
+ CONFIG_ITEM_MODULE_LIST, CONFIG_ITEM_MODULE_LIST_CAT
+ };
+
+ /* NOTE: this needs to be changed if we ever get more than 255 types */
+ return memchr (config_types, type, sizeof (config_types)) != NULL;
+}
+
+
+static int IsConfigIntegerType (int type)
+{
+ static const unsigned char config_types[] =
+ {
+ CONFIG_ITEM_INTEGER, CONFIG_ITEM_KEY, CONFIG_ITEM_BOOL,
+ CONFIG_CATEGORY, CONFIG_SUBCATEGORY
+ };
+
+ return memchr (config_types, type, sizeof (config_types)) != NULL;
+}
+
+
+static inline int IsConfigFloatType (int type)
+{
+ return type == CONFIG_ITEM_FLOAT;
+}
+
/*****************************************************************************
* config_GetType: get the type of a variable (bool, int, float, string)
i_type = VLC_VAR_STRING;
break;
+ case CONFIG_ITEM_PASSWORD:
+ i_type = VLC_VAR_STRING;
+ break;
+
case CONFIG_ITEM_FILE:
i_type = VLC_VAR_FILE;
break;
*****************************************************************************
* This function is used to get the value of variables which are internally
* represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
- * CONFIG_ITEM_DIRECTORY, and CONFIG_ITEM_MODULE).
+ * CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_PASSWORD, and CONFIG_ITEM_MODULE).
*
* Important note: remember to free() the returned char* because it's a
* duplicate of the actual value. It isn't safe to return a pointer to the
*****************************************************************************
* This function is used to set the value of variables which are internally
* represented by a string (CONFIG_ITEM_STRING, CONFIG_ITEM_FILE,
- * CONFIG_ITEM_DIRECTORY, and CONFIG_ITEM_MODULE).
+ * CONFIG_ITEM_DIRECTORY, CONFIG_ITEM_PASSWORD, and CONFIG_ITEM_MODULE).
*****************************************************************************/
void __config_PutPsz( vlc_object_t *p_this,
const char *psz_name, const char *psz_value )
if (IsConfigStringType (p_item->i_type))
{
- freenull (p_item->value.psz);
- freenull (p_item->orig.psz);
- freenull (p_item->saved.psz);
+ free ((char *)p_item->value.psz);
+ free ((char *)p_item->orig.psz);
+ free ((char *)p_item->saved.psz);
}
if( p_item->i_list )
else
if (IsConfigStringType (p_module->p_config[i].i_type))
{
- freenull (p_module->p_config[i].value.psz);
+ free ((char *)p_module->p_config[i].value.psz);
p_module->p_config[i].value.psz =
strdupnull (p_module->p_config[i].orig.psz);
}
}
+static int strtoi (const char *str)
+{
+ char *end;
+ long l;
+
+ errno = 0;
+ l = strtol (str, &end, 0);
+
+ if (!errno)
+ {
+ if ((l > INT_MAX) || (l < INT_MIN))
+ errno = ERANGE;
+ if (*end)
+ errno = EINVAL;
+ }
+ return (int)l;
+}
+
+
/*****************************************************************************
* config_LoadConfigFile: loads the configuration file.
*****************************************************************************
continue;
/* We found it */
+ errno = 0;
+
switch( p_item->i_type )
{
case CONFIG_ITEM_BOOL:
case CONFIG_ITEM_INTEGER:
- if( !*psz_option_value )
- break; /* ignore empty option */
- p_item->value.i = strtol( psz_option_value, 0, 0 );
- p_item->saved.i = p_item->value.i;
-
- /*msg_Dbg (p_this, "option \"%s\", value %i",
- psz_option_name, p_item->value.i);*/
+ {
+ long l = strtoi (psz_option_value);
+ if (errno)
+ msg_Warn (p_this, "Integer value (%s) for %s: %s",
+ psz_option_value, psz_option_name,
+ strerror (errno));
+ else
+ p_item->saved.i = p_item->value.i = (int)l;
break;
+ }
case CONFIG_ITEM_FLOAT:
if( !*psz_option_value )
break; /* ignore empty option */
p_item->value.f = (float)i18n_atof( psz_option_value);
p_item->saved.f = p_item->value.f;
-
- /*msg_Dbg (p_this, "option \"%s\", value %f",
- psz_option_name, (double)p_item->value.f);*/
break;
case CONFIG_ITEM_KEY:
p_item->saved.psz = strdupnull (p_item->value.psz);
vlc_mutex_unlock( p_item->p_lock );
-
- /*msg_Dbg (p_this, "option \"%s\", value \"%s\"",
- psz_option_name, psz_option_value ?: "");*/
break;
}
}
}
- vlc_list_release( p_list );
+ if (ferror (file))
+ {
+ msg_Err (p_this, "error reading configuration: %s", strerror (errno));
+ clearerr (file);
+ }
+ fclose (file);
- fclose( file );
+ vlc_list_release( p_list );
vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
return 0;
psz_key = ConfigKeyToString( i_value );
fprintf( file, "%s=%s\n", p_item->psz_name,
psz_key ? psz_key : "" );
- freenull (psz_key);
+ free (psz_key);
p_item->saved.i = i_value;
break;
if( b_autosave && !p_item->b_autosave ) break;
- freenull (p_item->saved.psz);
+ free ((char *)p_item->saved.psz);
if( (psz_value && p_item->orig.psz &&
strcmp( psz_value, p_item->orig.psz )) ||
!psz_value || !p_item->orig.psz)
/* Check if the option is deprecated */
if( p_conf->psz_current )
{
- if( !strcmp(p_conf->psz_current,"SUPPRESSED") )
+ if( p_conf->b_strict )
{
- if( !b_ignore_errors )
- {
- fprintf(stderr,
- "Warning: option --%s is no longer used.\n",
- p_conf->psz_name);
- }
+ fprintf(stderr,
+ "Warning: option --%s no longer exists.\n",
+ p_conf->psz_name);
continue;
}
+
+ fprintf( stderr,
+ "%s: option --%s is deprecated. Use --%s instead.\n",
+ b_ignore_errors ? "Warning" : "Error",
+ p_conf->psz_name, p_conf->psz_current);
if( !b_ignore_errors )
{
- if( p_conf->b_strict )
- {
- fprintf( stderr,
- "Error: option --%s is deprecated. "
- "Use --%s instead.\n",
- p_conf->psz_name, p_conf->psz_current);
- /*free */
- for( i_index = 0; p_longopts[i_index].name; i_index++ )
- free( (char *)p_longopts[i_index].name );
-
- free( p_longopts );
- free( psz_shortopts );
- return -1;
- }
- fprintf(stderr,
- "Warning: option --%s is deprecated. "
- "You should use --%s instead.\n",
- p_conf->psz_name, p_conf->psz_current);
+ /*free */
+ for( i_index = 0; p_longopts[i_index].name; i_index++ )
+ free( (char *)p_longopts[i_index].name );
+
+ free( p_longopts );
+ free( psz_shortopts );
+ return -1;
}
+
psz_name = (char *)p_conf->psz_current;
p_conf = config_FindConfig( p_this, psz_name );
}
switch( p_conf->i_type )
{
case CONFIG_ITEM_STRING:
+ case CONFIG_ITEM_PASSWORD:
case CONFIG_ITEM_FILE:
case CONFIG_ITEM_DIRECTORY:
case CONFIG_ITEM_MODULE:
switch( pp_shortopts[i_cmd]->i_type )
{
case CONFIG_ITEM_STRING:
+ case CONFIG_ITEM_PASSWORD:
case CONFIG_ITEM_FILE:
case CONFIG_ITEM_DIRECTORY:
case CONFIG_ITEM_MODULE:
*
* @return a string (always succeeds).
*/
-const char *config_GetDataDir( const vlc_object_t *p_this )
+const char *config_GetDataDir( void )
{
#if defined (WIN32) || defined (UNDER_CE)
- return p_this->p_libvlc_global->psz_vlcpath;
+ return vlc_global()->psz_vlcpath;
#elif defined(__APPLE__) || defined (SYS_BEOS)
static char path[PATH_MAX] = "";
if( *path == '\0' )
{
snprintf( path, sizeof( path ), "%s/share",
- p_this->p_libvlc_global->psz_vlcpath );
+ vlc_global()->psz_vlcpath );
path[sizeof( path ) - 1] = '\0';
}
return path;
#else
- (void)p_this;
return DATA_PATH;
#endif
}