]> git.sesse.net Git - vlc/blob - src/config/intf.c
Remove security-policy from config_ChainParse()
[vlc] / src / config / intf.c
1 /*****************************************************************************
2  * intf.c: interface configuration handling
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc/vlc.h>
29 #include "../libvlc.h"
30 #include "vlc_keys.h"
31 #include "vlc_charset.h"
32
33 #include <errno.h>                                                  /* errno */
34 #include <assert.h>
35 #include <limits.h>
36
37 #ifdef HAVE_UNISTD_H
38 #    include <unistd.h>                                          /* getuid() */
39 #endif
40
41 #ifdef HAVE_GETOPT_LONG
42 #   ifdef HAVE_GETOPT_H
43 #       include <getopt.h>                                       /* getopt() */
44 #   endif
45 #else
46 #   include "../extras/getopt.h"
47 #endif
48
49 #if defined(HAVE_GETPWUID)
50 #   include <pwd.h>                                            /* getpwuid() */
51 #endif
52
53 #if defined( HAVE_SYS_STAT_H )
54 #   include <sys/stat.h>
55 #endif
56 #if defined( HAVE_SYS_TYPES_H )
57 #   include <sys/types.h>
58 #endif
59 #if defined( WIN32 )
60 #   if !defined( UNDER_CE )
61 #       include <direct.h>
62 #   endif
63 #include <tchar.h>
64 #endif
65
66 #include "configuration.h"
67 #include "modules/modules.h"
68
69 /* Adds an extra interface to the configuration */
70 void __config_AddIntf( vlc_object_t *p_this, const char *psz_intf )
71 {
72     assert( psz_intf );
73
74     char *psz_config, *psz_parser;
75     size_t i_len = strlen( psz_intf );
76
77     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
78     while( psz_parser )
79     {
80         if( !strncmp( psz_intf, psz_parser, i_len ) )
81         {
82             free( psz_config );
83             return;
84         }
85         psz_parser = strchr( psz_parser, ':' );
86         if( psz_parser ) psz_parser++; /* skip the ':' */
87     }
88     free( psz_config );
89
90     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
91     while( psz_parser )
92     {
93         if( !strncmp( psz_intf, psz_parser, i_len ) )
94         {
95             free( psz_config );
96             return;
97         }
98         psz_parser = strchr( psz_parser, ':' );
99         if( psz_parser ) psz_parser++; /* skip the ':' */
100     }
101
102     /* interface not found in the config, let's add it */
103     if( psz_config && strlen( psz_config ) > 0 )
104     {
105         char *psz_newconfig;
106         if( asprintf( &psz_newconfig, "%s:%s", psz_config, psz_intf ) != -1 )
107         {
108             config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
109             free( psz_newconfig );
110         }
111     }
112     else
113         config_PutPsz( p_this->p_libvlc, "extraintf", psz_intf );
114
115     free( psz_config );
116 }
117
118 /* Removes an extra interface from the configuration */
119 void __config_RemoveIntf( vlc_object_t *p_this, const char *psz_intf )
120 {
121     assert( psz_intf );
122
123     char *psz_config, *psz_parser;
124     size_t i_len = strlen( psz_intf );
125
126     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
127     while( psz_parser )
128     {
129         if( !strncmp( psz_intf, psz_parser, i_len ) )
130         {
131             char *psz_newconfig;
132             char *psz_end = psz_parser + i_len;
133             if( *psz_end == ':' ) psz_end++;
134             *psz_parser = '\0';
135             if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
136             {
137                 config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
138                 free( psz_newconfig );
139             }
140             break;
141         }
142         psz_parser = strchr( psz_parser, ':' );
143         if( psz_parser ) psz_parser++; /* skip the ':' */
144     }
145     free( psz_config );
146
147     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
148     while( psz_parser )
149     {
150         if( !strncmp( psz_intf, psz_parser, i_len ) )
151         {
152             char *psz_newconfig;
153             char *psz_end = psz_parser + i_len;
154             if( *psz_end == ':' ) psz_end++;
155             *psz_parser = '\0';
156             if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
157             {
158                 config_PutPsz( p_this->p_libvlc, "control", psz_newconfig );
159                 free( psz_newconfig );
160             }
161             break;
162         }
163         psz_parser = strchr( psz_parser, ':' );
164         if( psz_parser ) psz_parser++; /* skip the ':' */
165     }
166     free( psz_config );
167 }
168
169 /*
170  * Returns VLC_TRUE if the specified extra interface is present in the
171  * configuration, VLC_FALSE if not
172  */
173 vlc_bool_t __config_ExistIntf( vlc_object_t *p_this, const char *psz_intf )
174 {
175     assert( psz_intf );
176
177     char *psz_config, *psz_parser;
178     size_t i_len = strlen( psz_intf );
179
180     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
181     while( psz_parser )
182     {
183         if( !strncmp( psz_parser, psz_intf, i_len ) )
184         {
185             free( psz_config );
186             return VLC_TRUE;
187         }
188         psz_parser = strchr( psz_parser, ':' );
189         if( psz_parser ) psz_parser++; /* skip the ':' */
190     }
191     free( psz_config );
192
193     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
194     while( psz_parser )
195     {
196         if( !strncmp( psz_parser, psz_intf, i_len ) )
197         {
198             free( psz_config );
199             return VLC_TRUE;
200         }
201         psz_parser = strchr( psz_parser, ':' );
202         if( psz_parser ) psz_parser++; /* skip the ':' */
203     }
204     free( psz_config );
205
206     return VLC_FALSE;
207 }
208