]> git.sesse.net Git - vlc/blob - modules/access/mms/mms.c
75a1a7745622601753fccd74deb208d13f63ab67
[vlc] / modules / access / mms / mms.c
1 /*****************************************************************************
2  * mms.c: MMS over tcp, udp and http access plug-in
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 VideoLAN
5  * $Id: mms.c,v 1.35 2004/01/21 16:56:16 fenrir Exp $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/input.h>
32
33 #include "mms.h"
34
35 /****************************************************************************
36  * NOTES:
37  *  MMSProtocole documentation found at http://get.to/sdp
38  ****************************************************************************/
39
40 /*****************************************************************************
41  * Local prototypes
42  *****************************************************************************/
43
44 struct access_sys_t
45 {
46     int i_proto;
47
48 };
49
50 static int  Open        ( vlc_object_t * );
51 static void Close       ( vlc_object_t * );
52
53
54 /*****************************************************************************
55  * Module descriptor
56  *****************************************************************************/
57 #define CACHING_TEXT N_("Caching value in ms")
58 #define CACHING_LONGTEXT N_( \
59     "Allows you to modify the default caching value for mms streams. This " \
60     "value should be set in miliseconds units." )
61
62 vlc_module_begin();
63     set_description( _("Microsoft Media Server (MMS) input") );
64     set_capability( "access", 0 );
65     add_category_hint( "stream", NULL, VLC_TRUE );
66         add_integer( "mms-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
67                      CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
68
69         add_bool( "mms-all", 0, NULL,
70                   "force selection of all streams",
71                   "force selection of all streams", VLC_TRUE );
72         add_integer( "mms-maxbitrate", 0, NULL,
73                      "max bitrate",
74                      "set max bitrate for auto streams selections", VLC_FALSE );
75     add_shortcut( "mms" );
76     add_shortcut( "mmsu" );
77     add_shortcut( "mmst" );
78     add_shortcut( "mmsh" );
79     set_callbacks( Open, Close );
80 vlc_module_end();
81
82
83 static int Open( vlc_object_t *p_this )
84 {
85     input_thread_t  *p_input = (input_thread_t*)p_this;
86
87     /* First set ipv4/ipv6 */
88     var_Create( p_input, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
89     var_Create( p_input, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
90
91     /* mms-caching */
92     var_Create( p_input, "mms-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
93
94     /* use specified method */
95     if( *p_input->psz_access )
96     {
97         if( !strncmp( p_input->psz_access, "mmsu", 4 ) )
98         {
99             return E_( MMSTUOpen )( p_input );
100         }
101         else if( !strncmp( p_input->psz_access, "mmst", 4 ) )
102         {
103             return E_( MMSTUOpen )( p_input );
104         }
105         else if( !strncmp( p_input->psz_access, "mmsh", 4 ) )
106         {
107             return E_( MMSHOpen )( p_input );
108         }
109     }
110
111     if( E_( MMSTUOpen )( p_input ) )
112     {
113         /* try mmsh if mmstu failed */
114         return E_( MMSHOpen )( p_input );
115     }
116     return VLC_SUCCESS;
117 }
118
119 /*****************************************************************************
120  * Close: free unused data structures
121  *****************************************************************************/
122 static void Close( vlc_object_t *p_this )
123 {
124     input_thread_t *  p_input = (input_thread_t *)p_this;
125     access_sys_t   *  p_sys   = p_input->p_access_data;
126
127     if( p_sys->i_proto == MMS_PROTO_TCP || p_sys->i_proto == MMS_PROTO_UDP )
128     {
129         E_( MMSTUClose )( p_input );
130     }
131     else if( p_sys->i_proto == MMS_PROTO_HTTP )
132     {
133         E_( MMSHClose )( p_input );
134     }
135 }
136
137 /****************************************************************************
138  * parse hostname:port/path@username:password
139  * FIXME ipv6 ip will be baddly parsed (contain ':' )
140  ****************************************************************************/
141 url_t *E_( url_new )  ( char * psz_url )
142 {
143     url_t *p_url = malloc( sizeof( url_t ) );
144
145     char  *psz_dup    = strdup( psz_url );
146     char  *psz_parser = psz_dup;
147
148     char  *psz_tmp;
149
150     /* 1: get hostname:port */
151     while( *psz_parser == '/' )
152     {
153         psz_parser++;
154     }
155
156     psz_tmp = psz_parser;
157
158     while( *psz_parser &&
159            *psz_parser != ':' &&  *psz_parser != '/' && *psz_parser != '@' )
160     {
161         psz_parser++;
162     }
163
164     p_url->psz_host     = strndup( psz_tmp, psz_parser - psz_tmp );
165
166     if( *psz_parser == ':' )
167     {
168         psz_parser++;
169         psz_tmp = psz_parser;
170
171         while( *psz_parser && *psz_parser != '/' && *psz_parser != '@' )
172         {
173             psz_parser++;
174         }
175         p_url->i_port = atoi( psz_tmp );
176     }
177     else
178     {
179         p_url->i_port = 0;
180     }
181
182     /* 2: get path */
183     if( *psz_parser == '/' )
184     {
185         //psz_parser++;
186
187         psz_tmp = psz_parser;
188
189         while( *psz_parser && *psz_parser != '@' )
190         {
191             psz_parser++;
192         }
193
194         p_url->psz_path = strndup( psz_tmp, psz_parser - psz_tmp );
195     }
196     else
197     {
198         p_url->psz_path = strdup( "" );
199     }
200
201     /* 3: usrname and password */
202     if( *psz_parser == '@' )
203     {
204         psz_parser++;
205
206         psz_tmp = psz_parser;
207
208         while( *psz_parser && *psz_parser != ':' )
209         {
210             psz_parser++;
211         }
212
213         p_url->psz_username = strndup( psz_tmp, psz_parser - psz_tmp );
214
215         if( *psz_parser == ':' )
216         {
217             psz_parser++;
218
219             p_url->psz_password = strdup( psz_parser );
220         }
221         else
222         {
223             p_url->psz_password = strdup( "" );
224         }
225     }
226     else
227     {
228         p_url->psz_username = strdup( "" );
229         p_url->psz_password = strdup( "" );
230     }
231 #if 0
232     fprintf( stderr,
233              "host=`%s' port=%d path=`%s' username=`%s' password=`%s'\n",
234              p_url->psz_host,
235              p_url->i_port,
236              p_url->psz_path,
237              p_url->psz_username,
238              p_url->psz_password );
239 #endif
240     free( psz_dup );
241     return p_url;
242 }
243
244 void   E_( url_free ) ( url_t * p_url )
245 {
246     free( p_url->psz_host );
247     free( p_url->psz_path );
248     free( p_url->psz_username );
249     free( p_url->psz_password );
250     free( p_url );
251 }