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 *****************************************************************************/
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 )
64 #include "configuration.h"
65 #include "modules/modules.h"
67 /* Adds an extra interface to the configuration */
68 void __config_AddIntf( vlc_object_t *p_this, const char *psz_intf )
72 char *psz_config, *psz_parser;
73 size_t i_len = strlen( psz_intf );
75 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
78 if( !strncmp( psz_intf, psz_parser, i_len ) )
83 psz_parser = strchr( psz_parser, ':' );
84 if( psz_parser ) psz_parser++; /* skip the ':' */
88 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
91 if( !strncmp( psz_intf, psz_parser, i_len ) )
96 psz_parser = strchr( psz_parser, ':' );
97 if( psz_parser ) psz_parser++; /* skip the ':' */
100 /* interface not found in the config, let's add it */
101 if( psz_config && strlen( psz_config ) > 0 )
104 if( asprintf( &psz_newconfig, "%s:%s", psz_config, psz_intf ) != -1 )
106 config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
107 free( psz_newconfig );
111 config_PutPsz( p_this->p_libvlc, "extraintf", psz_intf );
116 /* Removes an extra interface from the configuration */
117 void __config_RemoveIntf( vlc_object_t *p_this, const char *psz_intf )
121 char *psz_config, *psz_parser;
122 size_t i_len = strlen( psz_intf );
124 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
127 if( !strncmp( psz_intf, psz_parser, i_len ) )
130 char *psz_end = psz_parser + i_len;
131 if( *psz_end == ':' ) psz_end++;
133 if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
135 config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
136 free( psz_newconfig );
140 psz_parser = strchr( psz_parser, ':' );
141 if( psz_parser ) psz_parser++; /* skip the ':' */
145 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
148 if( !strncmp( psz_intf, psz_parser, i_len ) )
151 char *psz_end = psz_parser + i_len;
152 if( *psz_end == ':' ) psz_end++;
154 if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
156 config_PutPsz( p_this->p_libvlc, "control", psz_newconfig );
157 free( psz_newconfig );
161 psz_parser = strchr( psz_parser, ':' );
162 if( psz_parser ) psz_parser++; /* skip the ':' */
168 * Returns VLC_TRUE if the specified extra interface is present in the
169 * configuration, VLC_FALSE if not
171 vlc_bool_t __config_ExistIntf( vlc_object_t *p_this, const char *psz_intf )
175 char *psz_config, *psz_parser;
176 size_t i_len = strlen( psz_intf );
178 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
181 if( !strncmp( psz_parser, psz_intf, i_len ) )
186 psz_parser = strchr( psz_parser, ':' );
187 if( psz_parser ) psz_parser++; /* skip the ':' */
191 psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
194 if( !strncmp( psz_parser, psz_intf, i_len ) )
199 psz_parser = strchr( psz_parser, ':' );
200 if( psz_parser ) psz_parser++; /* skip the ':' */