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