1 /*****************************************************************************
2 * intf.c: interface configuration handling
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 *****************************************************************************/
29 #include "../libvlc.h"
31 #include "vlc_charset.h"
33 #include <errno.h> /* errno */
38 # include <unistd.h> /* getuid() */
41 #ifdef HAVE_GETOPT_LONG
43 # include <getopt.h> /* getopt() */
46 # include "../extras/getopt.h"
49 #if defined(HAVE_GETPWUID)
50 # include <pwd.h> /* getpwuid() */
53 #if defined( HAVE_SYS_STAT_H )
54 # include <sys/stat.h>
56 #if defined( HAVE_SYS_TYPES_H )
57 # include <sys/types.h>
60 # if !defined( UNDER_CE )
66 #include "configuration.h"
67 #include "modules/modules.h"
69 /* Adds an extra interface to the configuration */
70 void __config_AddIntf( vlc_object_t *p_this, const char *psz_intf )
74 char *psz_config, *psz_parser;
75 size_t i_len = strlen( psz_intf );
77 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
80 if( !strncmp( psz_intf, psz_parser, i_len ) )
85 psz_parser = strchr( psz_parser, ':' );
86 if( psz_parser ) psz_parser++; /* skip the ':' */
90 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
93 if( !strncmp( psz_intf, psz_parser, i_len ) )
98 psz_parser = strchr( psz_parser, ':' );
99 if( psz_parser ) psz_parser++; /* skip the ':' */
102 /* interface not found in the config, let's add it */
103 if( psz_config && strlen( psz_config ) > 0 )
106 if( asprintf( &psz_newconfig, "%s:%s", psz_config, psz_intf ) != -1 )
108 config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
109 free( psz_newconfig );
113 config_PutPsz( p_this->p_libvlc, "extraintf", psz_intf );
118 /* Removes an extra interface from the configuration */
119 void __config_RemoveIntf( vlc_object_t *p_this, const char *psz_intf )
123 char *psz_config, *psz_parser;
124 size_t i_len = strlen( psz_intf );
126 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
129 if( !strncmp( psz_intf, psz_parser, i_len ) )
132 char *psz_end = psz_parser + i_len;
133 if( *psz_end == ':' ) psz_end++;
135 if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
137 config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
138 free( psz_newconfig );
142 psz_parser = strchr( psz_parser, ':' );
143 if( psz_parser ) psz_parser++; /* skip the ':' */
147 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
150 if( !strncmp( psz_intf, psz_parser, i_len ) )
153 char *psz_end = psz_parser + i_len;
154 if( *psz_end == ':' ) psz_end++;
156 if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
158 config_PutPsz( p_this->p_libvlc, "control", psz_newconfig );
159 free( psz_newconfig );
163 psz_parser = strchr( psz_parser, ':' );
164 if( psz_parser ) psz_parser++; /* skip the ':' */
170 * Returns VLC_TRUE if the specified extra interface is present in the
171 * configuration, VLC_FALSE if not
173 vlc_bool_t __config_ExistIntf( vlc_object_t *p_this, const char *psz_intf )
177 char *psz_config, *psz_parser;
178 size_t i_len = strlen( psz_intf );
180 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
183 if( !strncmp( psz_parser, psz_intf, i_len ) )
188 psz_parser = strchr( psz_parser, ':' );
189 if( psz_parser ) psz_parser++; /* skip the ':' */
193 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
196 if( !strncmp( psz_parser, psz_intf, i_len ) )
201 psz_parser = strchr( psz_parser, ':' );
202 if( psz_parser ) psz_parser++; /* skip the ':' */