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