demux: avi: PTSToByte remove useless casts and change type
[vlc.git] / src / config / intf.c
blob7d7ac5029d3b5be18d526707551d18e9c7481208
1 /*****************************************************************************
2 * intf.c: interface configuration handling
3 *****************************************************************************
4 * Copyright (C) 2001-2007 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <vlc_common.h>
30 #include <assert.h>
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 )
36 vlc_object_t *libvlc = VLC_OBJECT(p_this->obj.libvlc);
38 assert( psz_intf );
40 char *psz_config, *psz_parser;
41 size_t i_len = strlen( psz_intf );
43 psz_config = psz_parser = config_GetPsz( libvlc, "control" );
44 while( psz_parser )
46 if( !strncmp( psz_intf, psz_parser, i_len ) )
48 free( psz_config );
49 return;
51 psz_parser = strchr( psz_parser, ':' );
52 if( psz_parser ) psz_parser++; /* skip the ':' */
54 free( psz_config );
56 psz_config = psz_parser = config_GetPsz( libvlc, "extraintf" );
57 while( psz_parser )
59 if( !strncmp( psz_intf, psz_parser, i_len ) )
61 free( psz_config );
62 return;
64 psz_parser = strchr( psz_parser, ':' );
65 if( psz_parser ) psz_parser++; /* skip the ':' */
68 /* interface not found in the config, let's add it */
69 if( psz_config && strlen( psz_config ) > 0 )
71 char *psz_newconfig;
72 if( asprintf( &psz_newconfig, "%s:%s", psz_config, psz_intf ) != -1 )
74 config_PutPsz( libvlc, "extraintf", psz_newconfig );
75 free( psz_newconfig );
78 else
79 config_PutPsz( libvlc, "extraintf", psz_intf );
81 free( psz_config );
84 #undef config_RemoveIntf
85 /* Removes an extra interface from the configuration */
86 void config_RemoveIntf( vlc_object_t *p_this, const char *psz_intf )
88 vlc_object_t *libvlc = VLC_OBJECT(p_this->obj.libvlc);
90 assert( psz_intf );
92 char *psz_config, *psz_parser;
93 size_t i_len = strlen( psz_intf );
95 psz_config = psz_parser = config_GetPsz( libvlc, "extraintf" );
96 while( psz_parser )
98 if( !strncmp( psz_intf, psz_parser, i_len ) )
100 char *psz_newconfig;
101 char *psz_end = psz_parser + i_len;
102 if( *psz_end == ':' ) psz_end++;
103 *psz_parser = '\0';
104 if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
106 config_PutPsz( libvlc, "extraintf", psz_newconfig );
107 free( psz_newconfig );
109 break;
111 psz_parser = strchr( psz_parser, ':' );
112 if( psz_parser ) psz_parser++; /* skip the ':' */
114 free( psz_config );
116 psz_config = psz_parser = config_GetPsz( libvlc, "control" );
117 while( psz_parser )
119 if( !strncmp( psz_intf, psz_parser, i_len ) )
121 char *psz_newconfig;
122 char *psz_end = psz_parser + i_len;
123 if( *psz_end == ':' ) psz_end++;
124 *psz_parser = '\0';
125 if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
127 config_PutPsz( libvlc, "control", psz_newconfig );
128 free( psz_newconfig );
130 break;
132 psz_parser = strchr( psz_parser, ':' );
133 if( psz_parser ) psz_parser++; /* skip the ':' */
135 free( psz_config );
138 #undef config_ExistIntf
140 * Returns true if the specified extra interface is present in the
141 * configuration, false if not
143 bool config_ExistIntf( vlc_object_t *p_this, const char *psz_intf )
145 vlc_object_t *libvlc = VLC_OBJECT(p_this->obj.libvlc);
147 assert( psz_intf );
149 char *psz_config, *psz_parser;
150 size_t i_len = strlen( psz_intf );
152 psz_config = psz_parser = config_GetPsz( libvlc, "extraintf" );
153 while( psz_parser )
155 if( !strncmp( psz_parser, psz_intf, i_len ) )
157 free( psz_config );
158 return true;
160 psz_parser = strchr( psz_parser, ':' );
161 if( psz_parser ) psz_parser++; /* skip the ':' */
163 free( psz_config );
165 psz_config = psz_parser = config_GetPsz( libvlc, "control" );
166 while( psz_parser )
168 if( !strncmp( psz_parser, psz_intf, i_len ) )
170 free( psz_config );
171 return true;
173 psz_parser = strchr( psz_parser, ':' );
174 if( psz_parser ) psz_parser++; /* skip the ':' */
176 free( psz_config );
178 return false;