* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <vlc/vlc.h>
#include "../libvlc.h"
#include "vlc_keys.h"
#include "vlc_charset.h"
+#include "vlc_configuration.h"
#include <errno.h> /* errno */
-
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
+#include <assert.h>
+#include <limits.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h> /* getuid() */
#endif
-#ifdef HAVE_GETOPT_LONG
-# ifdef HAVE_GETOPT_H
-# include <getopt.h> /* getopt() */
-# endif
-#else
-# include "../extras/getopt.h"
-#endif
-
#if defined(HAVE_GETPWUID)
# include <pwd.h> /* getpwuid() */
#endif
#include <tchar.h>
#endif
-#include "config.h"
+#include "configuration.h"
#include "modules/modules.h"
static inline char *strdupnull (const char *src)
return src ? strdup (src) : NULL;
}
-static inline char *_strdupnull (const char *src)
-{
- return src ? strdup (_(src)) : NULL;
-}
-
/* Item types that use a string value (i.e. serialized in the module cache) */
int IsConfigStringType (int type)
{
}
/* free old string */
- if( oldval.psz_string ) free( oldval.psz_string );
+ free( oldval.psz_string );
}
/*****************************************************************************
if( p_item->i_type & CONFIG_HINT )
/* ignore hints */
continue;
- if( !strcmp( psz_name, p_item->psz_name ) )
+ if( !strcmp( psz_name, p_item->psz_name )
+ || ( p_item->psz_oldname
+ && !strcmp( psz_name, p_item->psz_oldname ) ) )
{
vlc_list_release( p_list );
return p_item;
return NULL;
}
-/*****************************************************************************
- * config_Duplicate: creates a duplicate of a module's configuration data.
- *****************************************************************************
- * Unfortunatly we cannot work directly with the module's config data as
- * this module might be unloaded from memory at any time (remember HideModule).
- * This is why we need to create an exact copy of the config data.
- *****************************************************************************/
-int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
- size_t n )
-{
- int j;
- const module_config_t *p_item, *p_end = p_orig + n;
-
- /* Calculate the structure length */
- p_module->i_config_items = 0;
- p_module->i_bool_items = 0;
-
- for( p_item = p_orig; p_item < p_end; p_item++ )
- {
- if( p_item->i_type & CONFIG_ITEM )
- {
- p_module->i_config_items++;
- }
-
- if( p_item->i_type == CONFIG_ITEM_BOOL )
- {
- p_module->i_bool_items++;
- }
- }
-
- /* Allocate memory */
- p_module->p_config = (module_config_t *)calloc( n, sizeof(*p_orig) );
- if( p_module->p_config == NULL )
- {
- msg_Err( p_module, "config error: can't duplicate p_config" );
- return VLC_ENOMEM;
- }
- p_module->confsize = n;
-
- /* Do the duplication job */
- for( size_t i = 0; i < n ; i++ )
- {
- p_module->p_config[i] = p_orig[i];
-
- if (IsConfigIntegerType (p_module->p_config[i].i_type))
- {
- p_module->p_config[i].orig.i = p_orig[i].value.i;
- p_module->p_config[i].saved.i = p_orig[i].value.i;
- }
- else
- if (IsConfigFloatType (p_module->p_config[i].i_type))
- {
- p_module->p_config[i].orig.f = p_orig[i].value.f;
- p_module->p_config[i].saved.f = p_orig[i].value.f;
- }
- else
- if (IsConfigStringType (p_module->p_config[i].i_type))
- {
- p_module->p_config[i].value.psz = strdupnull (p_orig[i].value.psz);
- p_module->p_config[i].orig.psz = strdupnull (p_orig[i].value.psz);
- p_module->p_config[i].saved.psz = NULL;
- }
-
- p_module->p_config[i].psz_type = strdupnull (p_orig[i].psz_type);
- p_module->p_config[i].psz_name = p_orig[i].psz_name;
- p_module->p_config[i].psz_current = strdupnull (p_orig[i].psz_current);
- p_module->p_config[i].psz_text = p_orig[i].psz_text;
- p_module->p_config[i].psz_longtext = p_orig[i].psz_longtext;
-
- p_module->p_config[i].p_lock = &p_module->object_lock;
-
- /* duplicate the string list */
- if( p_orig[i].i_list )
- {
- if( p_orig[i].ppsz_list )
- {
- p_module->p_config[i].ppsz_list =
- malloc( (p_orig[i].i_list + 1) * sizeof(char *) );
- if( p_module->p_config[i].ppsz_list )
- {
- for( j = 0; j < p_orig[i].i_list; j++ )
- p_module->p_config[i].ppsz_list[j] =
- strdupnull (p_orig[i].ppsz_list[j]);
- p_module->p_config[i].ppsz_list[j] = NULL;
- }
- }
- if( p_orig[i].ppsz_list_text )
- {
- p_module->p_config[i].ppsz_list_text =
- calloc( (p_orig[i].i_list + 1), sizeof(char *) );
- if( p_module->p_config[i].ppsz_list_text )
- {
- for( j = 0; j < p_orig[i].i_list; j++ )
- p_module->p_config[i].ppsz_list_text[j] =
- strdupnull (_(p_orig[i].ppsz_list_text[j]));
- p_module->p_config[i].ppsz_list_text[j] = NULL;
- }
- }
- if( p_orig[i].pi_list )
- {
- p_module->p_config[i].pi_list =
- malloc( (p_orig[i].i_list + 1) * sizeof(int) );
- if( p_module->p_config[i].pi_list )
- {
- for( j = 0; j < p_orig[i].i_list; j++ )
- p_module->p_config[i].pi_list[j] =
- p_orig[i].pi_list[j];
- }
- }
- }
-
- /* duplicate the actions list */
- if( p_orig[i].i_action )
- {
- int j;
-
- p_module->p_config[i].ppf_action =
- malloc( p_orig[i].i_action * sizeof(void *) );
- p_module->p_config[i].ppsz_action_text =
- malloc( p_orig[i].i_action * sizeof(char *) );
-
- for( j = 0; j < p_orig[i].i_action; j++ )
- {
- p_module->p_config[i].ppf_action[j] =
- p_orig[i].ppf_action[j];
- p_module->p_config[i].ppsz_action_text[j] =
- strdupnull (p_orig[i].ppsz_action_text[j]);
- }
- }
-
- p_module->p_config[i].pf_callback = p_orig[i].pf_callback;
- }
- return VLC_SUCCESS;
-}
-
-
/*****************************************************************************
* config_Free: frees a duplicated module's configuration data.
*****************************************************************************
{
module_config_t *p_item = p_module->p_config + j;
- free( (char*) p_item->psz_type );
- free( (char*) p_item->psz_name );
- free( (char*) p_item->psz_current );
- free( (char*) p_item->psz_text );
- free( (char*) p_item->psz_longtext );
+ free( p_item->psz_type );
+ free( p_item->psz_name );
+ free( p_item->psz_text );
+ free( p_item->psz_longtext );
+ free( p_item->psz_oldname );
if (IsConfigStringType (p_item->i_type))
{
- free ((char *)p_item->value.psz);
- free ((char *)p_item->orig.psz);
- free ((char *)p_item->saved.psz);
+ free (p_item->value.psz);
+ free (p_item->orig.psz);
+ free (p_item->saved.psz);
}
- if( p_item->i_list )
- {
+ if( p_item->ppsz_list )
for( i = 0; i < p_item->i_list; i++ )
- {
- if( p_item->ppsz_list && p_item->ppsz_list[i] )
- free( (char*) p_item->ppsz_list[i] );
- if( p_item->ppsz_list_text && p_item->ppsz_list_text[i] )
- free( (char*) p_item->ppsz_list_text[i] );
- }
- if( p_item->ppsz_list ) free( p_item->ppsz_list );
- if( p_item->ppsz_list_text ) free( p_item->ppsz_list_text );
- if( p_item->pi_list ) free( p_item->pi_list );
- }
+ free( p_item->ppsz_list[i] );
+ if( p_item->ppsz_list_text )
+ for( i = 0; i < p_item->i_list; i++ )
+ free( p_item->ppsz_list_text[i] );
+ free( p_item->ppsz_list );
+ free( p_item->ppsz_list_text );
+ free( p_item->pi_list );
if( p_item->i_action )
{
for( i = 0; i < p_item->i_action; i++ )
{
- free( (char*) p_item->ppsz_action_text[i] );
+ free( p_item->ppsz_action_text[i] );
}
- if( p_item->ppf_action ) free( p_item->ppf_action );
- if( p_item->ppsz_action_text ) free( p_item->ppsz_action_text );
+ free( p_item->ppf_action );
+ free( p_item->ppsz_action_text );
}
}
- if (p_module->p_config != NULL)
- {
- free (p_module->p_config);
- p_module->p_config = NULL;
- }
+ free (p_module->p_config);
+ p_module->p_config = NULL;
}
/*****************************************************************************
* - on windows that's the App Data directory;
* - on other OSes it's the same as the home directory.
*/
-char *config_GetUserDir( void );
+char *config_GetUserDir( void ); /* XXX why does gcc wants a declaration ?
+ * --funman */
char *config_GetUserDir( void )
{
return GetDir( VLC_TRUE );
return psz_dir;
#endif
}
-
-/* Adds an extra interface to the configuration */
-void __config_AddIntf( vlc_object_t *p_this, const char *psz_intf )
-{
- assert( psz_intf );
-
- char *psz_config, *psz_parser;
- size_t i_len = strlen( psz_intf );
-
- psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
- while( psz_parser )
- {
- if( !strncmp( psz_intf, psz_parser, i_len ) )
- {
- free( psz_config );
- return;
- }
- psz_parser = strchr( psz_parser, ':' );
- if( psz_parser ) psz_parser++; /* skip the ':' */
- }
- free( psz_config );
-
- psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
- while( psz_parser )
- {
- if( !strncmp( psz_intf, psz_parser, i_len ) )
- {
- free( psz_config );
- return;
- }
- psz_parser = strchr( psz_parser, ':' );
- if( psz_parser ) psz_parser++; /* skip the ':' */
- }
-
- /* interface not found in the config, let's add it */
- if( psz_config && strlen( psz_config ) > 0 )
- {
- char *psz_newconfig;
- if( asprintf( &psz_newconfig, "%s:%s", psz_config, psz_intf ) != -1 )
- {
- config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
- free( psz_newconfig );
- }
- }
- else
- config_PutPsz( p_this->p_libvlc, "extraintf", psz_intf );
-
- free( psz_config );
-}
-
-/* Removes an extra interface from the configuration */
-void __config_RemoveIntf( vlc_object_t *p_this, const char *psz_intf )
-{
- assert( psz_intf );
-
- char *psz_config, *psz_parser;
- size_t i_len = strlen( psz_intf );
-
- psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
- while( psz_parser )
- {
- if( !strncmp( psz_intf, psz_parser, i_len ) )
- {
- char *psz_newconfig;
- char *psz_end = psz_parser + i_len;
- if( *psz_end == ':' ) psz_end++;
- *psz_parser = '\0';
- if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
- {
- config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
- free( psz_newconfig );
- }
- break;
- }
- psz_parser = strchr( psz_parser, ':' );
- if( psz_parser ) psz_parser++; /* skip the ':' */
- }
- free( psz_config );
-
- psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
- while( psz_parser )
- {
- if( !strncmp( psz_intf, psz_parser, i_len ) )
- {
- char *psz_newconfig;
- char *psz_end = psz_parser + i_len;
- if( *psz_end == ':' ) psz_end++;
- *psz_parser = '\0';
- if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
- {
- config_PutPsz( p_this->p_libvlc, "control", psz_newconfig );
- free( psz_newconfig );
- }
- break;
- }
- psz_parser = strchr( psz_parser, ':' );
- if( psz_parser ) psz_parser++; /* skip the ':' */
- }
- free( psz_config );
-}
-
-/*
- * Returns VLC_TRUE if the specified extra interface is present in the
- * configuration, VLC_FALSE if not
- */
-vlc_bool_t __config_ExistIntf( vlc_object_t *p_this, const char *psz_intf )
-{
- assert( psz_intf );
-
- char *psz_config, *psz_parser;
- size_t i_len = strlen( psz_intf );
-
- psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
- while( psz_parser )
- {
- if( !strncmp( psz_parser, psz_intf, i_len ) )
- {
- free( psz_config );
- return VLC_TRUE;
- }
- psz_parser = strchr( psz_parser, ':' );
- if( psz_parser ) psz_parser++; /* skip the ':' */
- }
- free( psz_config );
-
- psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
- while( psz_parser )
- {
- if( !strncmp( psz_parser, psz_intf, i_len ) )
- {
- free( psz_config );
- return VLC_TRUE;
- }
- psz_parser = strchr( psz_parser, ':' );
- if( psz_parser ) psz_parser++; /* skip the ':' */
- }
- free( psz_config );
-
- return VLC_FALSE;
-}
-