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