]> git.sesse.net Git - vlc/blob - src/config/intf.c
update module LIST 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 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc/vlc.h>
29
30 /* Adds an extra interface to the configuration */
31 void __config_AddIntf( vlc_object_t *p_this, const char *psz_intf )
32 {
33     assert( psz_intf );
34
35     char *psz_config, *psz_parser;
36     size_t i_len = strlen( psz_intf );
37
38     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
39     while( psz_parser )
40     {
41         if( !strncmp( psz_intf, psz_parser, i_len ) )
42         {
43             free( psz_config );
44             return;
45         }
46         psz_parser = strchr( psz_parser, ':' );
47         if( psz_parser ) psz_parser++; /* skip the ':' */
48     }
49     free( psz_config );
50
51     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
52     while( psz_parser )
53     {
54         if( !strncmp( psz_intf, psz_parser, i_len ) )
55         {
56             free( psz_config );
57             return;
58         }
59         psz_parser = strchr( psz_parser, ':' );
60         if( psz_parser ) psz_parser++; /* skip the ':' */
61     }
62
63     /* interface not found in the config, let's add it */
64     if( psz_config && strlen( psz_config ) > 0 )
65     {
66         char *psz_newconfig;
67         if( asprintf( &psz_newconfig, "%s:%s", psz_config, psz_intf ) != -1 )
68         {
69             config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
70             free( psz_newconfig );
71         }
72     }
73     else
74         config_PutPsz( p_this->p_libvlc, "extraintf", psz_intf );
75
76     free( psz_config );
77 }
78
79 /* Removes an extra interface from the configuration */
80 void __config_RemoveIntf( vlc_object_t *p_this, const char *psz_intf )
81 {
82     assert( psz_intf );
83
84     char *psz_config, *psz_parser;
85     size_t i_len = strlen( psz_intf );
86
87     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
88     while( psz_parser )
89     {
90         if( !strncmp( psz_intf, psz_parser, i_len ) )
91         {
92             char *psz_newconfig;
93             char *psz_end = psz_parser + i_len;
94             if( *psz_end == ':' ) psz_end++;
95             *psz_parser = '\0';
96             if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
97             {
98                 config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig );
99                 free( psz_newconfig );
100             }
101             break;
102         }
103         psz_parser = strchr( psz_parser, ':' );
104         if( psz_parser ) psz_parser++; /* skip the ':' */
105     }
106     free( psz_config );
107
108     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
109     while( psz_parser )
110     {
111         if( !strncmp( psz_intf, psz_parser, i_len ) )
112         {
113             char *psz_newconfig;
114             char *psz_end = psz_parser + i_len;
115             if( *psz_end == ':' ) psz_end++;
116             *psz_parser = '\0';
117             if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
118             {
119                 config_PutPsz( p_this->p_libvlc, "control", psz_newconfig );
120                 free( psz_newconfig );
121             }
122             break;
123         }
124         psz_parser = strchr( psz_parser, ':' );
125         if( psz_parser ) psz_parser++; /* skip the ':' */
126     }
127     free( psz_config );
128 }
129
130 /*
131  * Returns VLC_TRUE if the specified extra interface is present in the
132  * configuration, VLC_FALSE if not
133  */
134 vlc_bool_t __config_ExistIntf( vlc_object_t *p_this, const char *psz_intf )
135 {
136     assert( psz_intf );
137
138     char *psz_config, *psz_parser;
139     size_t i_len = strlen( psz_intf );
140
141     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" );
142     while( psz_parser )
143     {
144         if( !strncmp( psz_parser, psz_intf, i_len ) )
145         {
146             free( psz_config );
147             return VLC_TRUE;
148         }
149         psz_parser = strchr( psz_parser, ':' );
150         if( psz_parser ) psz_parser++; /* skip the ':' */
151     }
152     free( psz_config );
153
154     psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" );
155     while( psz_parser )
156     {
157         if( !strncmp( psz_parser, psz_intf, i_len ) )
158         {
159             free( psz_config );
160             return VLC_TRUE;
161         }
162         psz_parser = strchr( psz_parser, ':' );
163         if( psz_parser ) psz_parser++; /* skip the ':' */
164     }
165     free( psz_config );
166
167     return VLC_FALSE;
168 }
169