demux: adaptive: pass latency to stats
[vlc.git] / src / config / intf.c
blob14bb1d894d93862574ed1ada4495fe30bef1d883
1 /*****************************************************************************
2 * intf.c: interface configuration handling
3 *****************************************************************************
4 * Copyright (C) 2001-2007 VLC authors and VideoLAN
6 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <vlc_common.h>
29 #include <assert.h>
31 /* Adds an extra interface to the configuration */
32 void config_AddIntf( const char *psz_intf )
34 assert( psz_intf );
36 char *psz_config, *psz_parser;
37 size_t i_len = strlen( psz_intf );
39 psz_config = psz_parser = config_GetPsz( "control" );
40 while( psz_parser )
42 if( !strncmp( psz_intf, psz_parser, i_len ) )
44 free( psz_config );
45 return;
47 psz_parser = strchr( psz_parser, ':' );
48 if( psz_parser ) psz_parser++; /* skip the ':' */
50 free( psz_config );
52 psz_config = psz_parser = config_GetPsz( "extraintf" );
53 while( psz_parser )
55 if( !strncmp( psz_intf, psz_parser, i_len ) )
57 free( psz_config );
58 return;
60 psz_parser = strchr( psz_parser, ':' );
61 if( psz_parser ) psz_parser++; /* skip the ':' */
64 /* interface not found in the config, let's add it */
65 if( psz_config && strlen( psz_config ) > 0 )
67 char *psz_newconfig;
68 if( asprintf( &psz_newconfig, "%s:%s", psz_config, psz_intf ) != -1 )
70 config_PutPsz( "extraintf", psz_newconfig );
71 free( psz_newconfig );
74 else
75 config_PutPsz( "extraintf", psz_intf );
77 free( psz_config );
80 /* Removes an extra interface from the configuration */
81 void config_RemoveIntf( const char *psz_intf )
83 assert( psz_intf );
85 char *psz_config, *psz_parser;
86 size_t i_len = strlen( psz_intf );
88 psz_config = psz_parser = config_GetPsz( "extraintf" );
89 while( psz_parser )
91 if( !strncmp( psz_intf, psz_parser, i_len ) )
93 char *psz_newconfig;
94 char *psz_end = psz_parser + i_len;
95 if( *psz_end == ':' ) psz_end++;
96 *psz_parser = '\0';
97 if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
99 config_PutPsz( "extraintf", psz_newconfig );
100 free( psz_newconfig );
102 break;
104 psz_parser = strchr( psz_parser, ':' );
105 if( psz_parser ) psz_parser++; /* skip the ':' */
107 free( psz_config );
109 psz_config = psz_parser = config_GetPsz( "control" );
110 while( psz_parser )
112 if( !strncmp( psz_intf, psz_parser, i_len ) )
114 char *psz_newconfig;
115 char *psz_end = psz_parser + i_len;
116 if( *psz_end == ':' ) psz_end++;
117 *psz_parser = '\0';
118 if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 )
120 config_PutPsz( "control", psz_newconfig );
121 free( psz_newconfig );
123 break;
125 psz_parser = strchr( psz_parser, ':' );
126 if( psz_parser ) psz_parser++; /* skip the ':' */
128 free( psz_config );
132 * Returns true if the specified extra interface is present in the
133 * configuration, false if not
135 bool config_ExistIntf( const char *psz_intf )
137 assert( psz_intf );
139 char *psz_config, *psz_parser;
140 size_t i_len = strlen( psz_intf );
142 psz_config = psz_parser = config_GetPsz( "extraintf" );
143 while( psz_parser )
145 if( !strncmp( psz_parser, psz_intf, i_len ) )
147 free( psz_config );
148 return true;
150 psz_parser = strchr( psz_parser, ':' );
151 if( psz_parser ) psz_parser++; /* skip the ':' */
153 free( psz_config );
155 psz_config = psz_parser = config_GetPsz( "control" );
156 while( psz_parser )
158 if( !strncmp( psz_parser, psz_intf, i_len ) )
160 free( psz_config );
161 return true;
163 psz_parser = strchr( psz_parser, ':' );
164 if( psz_parser ) psz_parser++; /* skip the ':' */
166 free( psz_config );
168 return false;