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