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 *****************************************************************************/
27 #include <vlc_common.h>
31 /* Adds an extra interface to the configuration */
32 void config_AddIntf( const char *psz_intf
)
36 char *psz_config
, *psz_parser
;
37 size_t i_len
= strlen( psz_intf
);
39 psz_config
= psz_parser
= config_GetPsz( "control" );
42 if( !strncmp( psz_intf
, psz_parser
, i_len
) )
47 psz_parser
= strchr( psz_parser
, ':' );
48 if( psz_parser
) psz_parser
++; /* skip the ':' */
52 psz_config
= psz_parser
= config_GetPsz( "extraintf" );
55 if( !strncmp( psz_intf
, psz_parser
, i_len
) )
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 )
68 if( asprintf( &psz_newconfig
, "%s:%s", psz_config
, psz_intf
) != -1 )
70 config_PutPsz( "extraintf", psz_newconfig
);
71 free( psz_newconfig
);
75 config_PutPsz( "extraintf", psz_intf
);
80 /* Removes an extra interface from the configuration */
81 void config_RemoveIntf( const char *psz_intf
)
85 char *psz_config
, *psz_parser
;
86 size_t i_len
= strlen( psz_intf
);
88 psz_config
= psz_parser
= config_GetPsz( "extraintf" );
91 if( !strncmp( psz_intf
, psz_parser
, i_len
) )
94 char *psz_end
= psz_parser
+ i_len
;
95 if( *psz_end
== ':' ) psz_end
++;
97 if( asprintf( &psz_newconfig
, "%s%s", psz_config
, psz_end
) != -1 )
99 config_PutPsz( "extraintf", psz_newconfig
);
100 free( psz_newconfig
);
104 psz_parser
= strchr( psz_parser
, ':' );
105 if( psz_parser
) psz_parser
++; /* skip the ':' */
109 psz_config
= psz_parser
= config_GetPsz( "control" );
112 if( !strncmp( psz_intf
, psz_parser
, i_len
) )
115 char *psz_end
= psz_parser
+ i_len
;
116 if( *psz_end
== ':' ) psz_end
++;
118 if( asprintf( &psz_newconfig
, "%s%s", psz_config
, psz_end
) != -1 )
120 config_PutPsz( "control", psz_newconfig
);
121 free( psz_newconfig
);
125 psz_parser
= strchr( psz_parser
, ':' );
126 if( psz_parser
) psz_parser
++; /* skip the ':' */
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
)
139 char *psz_config
, *psz_parser
;
140 size_t i_len
= strlen( psz_intf
);
142 psz_config
= psz_parser
= config_GetPsz( "extraintf" );
145 if( !strncmp( psz_parser
, psz_intf
, i_len
) )
150 psz_parser
= strchr( psz_parser
, ':' );
151 if( psz_parser
) psz_parser
++; /* skip the ':' */
155 psz_config
= psz_parser
= config_GetPsz( "control" );
158 if( !strncmp( psz_parser
, psz_intf
, i_len
) )
163 psz_parser
= strchr( psz_parser
, ':' );
164 if( psz_parser
) psz_parser
++; /* skip the ':' */