~ubuntu-branches/ubuntu/maverick/vlc/maverick

« back to all changes in this revision

Viewing changes to modules/access_output/http.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-09-17 21:56:14 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20080917215614-tj0vx8xzd57e52t8
Tags: 0.9.2-1ubuntu1
* New Upstream Release, exception granted by
    - dktrkranz, norsetto, Hobbsee (via irc). LP: #270404

Changes done in ubuntu:

* add libxul-dev to build-depends
* make sure that vlc is build against libxul in configure. This doesn't
  change anything in the package, but makes it more robust if building
  in an 'unclean' chroot or when modifying the package.
* debian/control: make Vcs-* fields point to the motumedia branch
* add libx264-dev and libass-dev to build-depends
  LP: #210354, #199870
* actually enable libass support by passing --enable-libass to configure
* enable libdca: add libdca-dev to build depends and --enable-libdca
* install the x264 plugin.

Changes already in the pkg-multimedia branch in debian:

* don't install usr/share/vlc/mozilla in debian/mozilla-plugin-vlc.install  
* new upstream .desktop file now registers flash video mimetype LP: #261567
* add Xb-Npp-Applications to mozilla-plugin-vlc
* remove duplicate entries in debian/vlc-nox.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * http.c
3
3
 *****************************************************************************
4
4
 * Copyright (C) 2001-2005 the VideoLAN team
5
 
 * $Id: ecd1ea3677d7a101ac6004b6356502223a7b1ffd $
 
5
 * $Id: 8b194fce95801ea6e0b6d19c3bf5cfd21e6dd8e9 $
6
6
 *
7
7
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8
8
 *          Jon Lech Johansen <jon@nanocrew.net>
25
25
/*****************************************************************************
26
26
 * Preamble
27
27
 *****************************************************************************/
28
 
#include <stdlib.h>
29
 
 
30
 
#include <vlc/vlc.h>
31
 
#include <vlc/sout.h>
 
28
 
 
29
#ifdef HAVE_CONFIG_H
 
30
# include "config.h"
 
31
#endif
 
32
 
 
33
#include <vlc_common.h>
 
34
#include <vlc_plugin.h>
 
35
#include <vlc_sout.h>
 
36
#include <vlc_block.h>
 
37
 
 
38
 
 
39
#include <vlc_input.h>
 
40
#include <vlc_playlist.h>
32
41
 
33
42
#ifdef HAVE_AVAHI_CLIENT
34
 
    #include <vlc/intf.h>
35
 
 
36
43
    #include "bonjour.h"
37
44
 
38
45
    #if defined( WIN32 )
44
51
 
45
52
#include "vlc_httpd.h"
46
53
 
47
 
#define FREE( p ) if( p ) { free( p); (p) = NULL; }
48
 
 
49
54
#define DEFAULT_PORT        8080
50
55
#define DEFAULT_SSL_PORT    8443
51
56
 
63
68
#define PASS_TEXT N_("Password")
64
69
#define PASS_LONGTEXT N_("Password that will be " \
65
70
                         "requested to access the stream." )
66
 
 
67
 
/// \bug [String] missing closing parenthesis
68
71
#define MIME_TEXT N_("Mime")
69
72
#define MIME_LONGTEXT N_("MIME returned by the server (autodetected " \
70
 
                        "if not specified." )
71
 
 
 
73
                        "if not specified)." )
72
74
#define CERT_TEXT N_( "Certificate file" )
73
75
#define CERT_LONGTEXT N_( "Path to the x509 PEM certificate file that will "\
74
76
                          "be used for HTTPS." )
90
92
 
91
93
 
92
94
vlc_module_begin();
93
 
    set_description( _("HTTP stream output") );
 
95
    set_description( N_("HTTP stream output") );
94
96
    set_capability( "sout access", 0 );
95
97
    set_shortname( "HTTP" );
96
98
    add_shortcut( "http" );
99
101
    set_category( CAT_SOUT );
100
102
    set_subcategory( SUBCAT_SOUT_ACO );
101
103
    add_string( SOUT_CFG_PREFIX "user", "", NULL,
102
 
                USER_TEXT, USER_LONGTEXT, VLC_TRUE );
 
104
                USER_TEXT, USER_LONGTEXT, true );
103
105
    add_string( SOUT_CFG_PREFIX "pwd", "", NULL,
104
 
                PASS_TEXT, PASS_LONGTEXT, VLC_TRUE );
 
106
                PASS_TEXT, PASS_LONGTEXT, true );
105
107
    add_string( SOUT_CFG_PREFIX "mime", "", NULL,
106
 
                MIME_TEXT, MIME_LONGTEXT, VLC_TRUE );
 
108
                MIME_TEXT, MIME_LONGTEXT, true );
107
109
    add_string( SOUT_CFG_PREFIX "cert", "vlc.pem", NULL,
108
 
                CERT_TEXT, CERT_LONGTEXT, VLC_TRUE );
 
110
                CERT_TEXT, CERT_LONGTEXT, true );
109
111
    add_string( SOUT_CFG_PREFIX "key", NULL, NULL,
110
 
                KEY_TEXT, KEY_LONGTEXT, VLC_TRUE );
 
112
                KEY_TEXT, KEY_LONGTEXT, true );
111
113
    add_string( SOUT_CFG_PREFIX "ca", NULL, NULL,
112
 
                CA_TEXT, CA_LONGTEXT, VLC_TRUE );
 
114
                CA_TEXT, CA_LONGTEXT, true );
113
115
    add_string( SOUT_CFG_PREFIX "crl", NULL, NULL,
114
 
                CRL_TEXT, CRL_LONGTEXT, VLC_TRUE );
115
 
    add_bool( SOUT_CFG_PREFIX "bonjour", VLC_FALSE, NULL,
116
 
              BONJOUR_TEXT, BONJOUR_LONGTEXT, VLC_TRUE);
 
116
                CRL_TEXT, CRL_LONGTEXT, true );
 
117
    add_bool( SOUT_CFG_PREFIX "bonjour", false, NULL,
 
118
              BONJOUR_TEXT, BONJOUR_LONGTEXT, true);
117
119
    set_callbacks( Open, Close );
118
120
vlc_module_end();
119
121
 
121
123
/*****************************************************************************
122
124
 * Exported prototypes
123
125
 *****************************************************************************/
124
 
static const char *ppsz_sout_options[] = {
 
126
static const char *const ppsz_sout_options[] = {
125
127
    "user", "pwd", "mime", "cert", "key", "ca", "crl", NULL
126
128
};
127
129
 
128
 
static int Write( sout_access_out_t *, block_t * );
 
130
static ssize_t Write( sout_access_out_t *, block_t * );
129
131
static int Seek ( sout_access_out_t *, off_t  );
130
132
 
131
133
struct sout_access_out_sys_t
140
142
    int                 i_header_allocated;
141
143
    int                 i_header_size;
142
144
    uint8_t             *p_header;
143
 
    vlc_bool_t          b_header_complete;
 
145
    bool          b_header_complete;
144
146
 
145
147
#ifdef HAVE_AVAHI_CLIENT
146
148
    void                *p_bonjour;
163
165
    char                *psz_user = NULL;
164
166
    char                *psz_pwd = NULL;
165
167
    char                *psz_mime = NULL;
166
 
    const char          *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL,
 
168
    char                *psz_cert = NULL, *psz_key = NULL, *psz_ca = NULL,
167
169
                        *psz_crl = NULL;
168
170
    vlc_value_t         val;
169
171
 
170
172
    if( !( p_sys = p_access->p_sys =
171
173
                malloc( sizeof( sout_access_out_sys_t ) ) ) )
172
 
    {
173
 
        msg_Err( p_access, "Not enough memory" );
174
174
        return VLC_ENOMEM ;
175
 
    }
176
 
 
177
 
    sout_CfgParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
178
 
 
179
 
    /* p_access->psz_name = "hostname:port/filename" */
180
 
    psz_bind_addr = psz_parser = strdup( p_access->psz_name );
 
175
 
 
176
    config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg );
 
177
 
 
178
    /* p_access->psz_path = "hostname:port/filename" */
 
179
    psz_bind_addr = psz_parser = strdup( p_access->psz_path );
181
180
 
182
181
    i_bind_port = 0;
183
 
    psz_file_name = "";
184
 
 
185
 
    while( *psz_parser && *psz_parser != ':' && *psz_parser != '/' )
186
 
    {
187
 
        psz_parser++;
188
 
    }
189
 
    if( *psz_parser == ':' )
190
 
    {
191
 
        *psz_parser = '\0';
192
 
        psz_parser++;
193
 
        i_bind_port = atoi( psz_parser );
194
 
 
195
 
        while( *psz_parser && *psz_parser != '/' )
196
 
        {
197
 
            psz_parser++;
198
 
        }
199
 
    }
200
 
    if( *psz_parser == '/' )
201
 
    {
202
 
        *psz_parser = '\0';
203
 
        psz_parser++;
204
 
        psz_file_name = psz_parser;
205
 
    }
206
 
 
207
 
    if( !*psz_file_name )
208
 
    {
 
182
 
 
183
    psz_parser = strchr( psz_bind_addr, '/' );
 
184
    if( psz_parser )
 
185
    {
 
186
        psz_file_name = strdup( psz_parser );
 
187
        *psz_parser = '\0';
 
188
    }
 
189
    else
209
190
        psz_file_name = strdup( "/" );
210
 
    }
211
 
    else if( *psz_file_name != '/' )
 
191
 
 
192
    if( psz_bind_addr[0] == '[' )
212
193
    {
213
 
        char *p = psz_file_name;
214
 
 
215
 
        psz_file_name = malloc( strlen( p ) + 2 );
216
 
        strcpy( psz_file_name, "/" );
217
 
        strcat( psz_file_name, p );
 
194
        psz_bind_addr++;
 
195
        psz_parser = strstr( psz_bind_addr, "]:" );
 
196
        if( psz_parser )
 
197
        {
 
198
            *psz_parser = '\0';
 
199
            i_bind_port = atoi( psz_parser + 2 );
 
200
        }
 
201
        psz_parser = psz_bind_addr - 1;
218
202
    }
219
203
    else
220
204
    {
221
 
        psz_file_name = strdup( psz_file_name );
 
205
        psz_parser = strrchr( psz_bind_addr, ':' );
 
206
        if( psz_parser )
 
207
        {
 
208
            *psz_parser = '\0';
 
209
            i_bind_port = atoi( psz_parser + 1 );
 
210
        }
 
211
        psz_parser = psz_bind_addr;
222
212
    }
223
213
 
224
214
    /* SSL support */
242
232
                                            psz_bind_addr, i_bind_port,
243
233
                                            psz_cert, psz_key, psz_ca,
244
234
                                            psz_crl );
 
235
    free( psz_cert );
 
236
    free( psz_key );
 
237
    free( psz_ca );
 
238
    free( psz_crl );
 
239
 
245
240
    if( p_sys->p_httpd_host == NULL )
246
241
    {
247
 
        msg_Err( p_access, "cannot listen on %s:%d",
 
242
        msg_Err( p_access, "cannot listen on %s port %d",
248
243
                 psz_bind_addr, i_bind_port );
249
244
        free( psz_file_name );
250
 
        free( psz_bind_addr );
 
245
        free( psz_parser );
251
246
        free( p_sys );
252
247
        return VLC_EGENERIC;
253
248
    }
254
 
    free( psz_bind_addr );
 
249
    free( psz_parser );
255
250
 
256
251
    if( p_access->psz_access && !strcmp( p_access->psz_access, "mmsh" ) )
257
252
    {
281
276
    p_sys->p_httpd_stream =
282
277
        httpd_StreamNew( p_sys->p_httpd_host, psz_file_name, psz_mime,
283
278
                         psz_user, psz_pwd, NULL );
284
 
    if( psz_user ) free( psz_user );
285
 
    if( psz_pwd ) free( psz_pwd );
286
 
    if( psz_mime ) free( psz_mime );
 
279
    free( psz_user );
 
280
    free( psz_pwd );
 
281
    free( psz_mime );
287
282
 
288
283
    if( p_sys->p_httpd_stream == NULL )
289
284
    {
298
293
#ifdef HAVE_AVAHI_CLIENT
299
294
    if( config_GetInt(p_this, SOUT_CFG_PREFIX "bonjour") )
300
295
    {
301
 
        playlist_t          *p_playlist;
302
296
        char                *psz_txt, *psz_name;
303
 
 
304
 
        p_playlist = (playlist_t *)vlc_object_find( p_access,
305
 
                                                    VLC_OBJECT_PLAYLIST,
306
 
                                                    FIND_ANYWHERE );
307
 
        if( p_playlist == NULL )
308
 
        {
309
 
            msg_Err( p_access, "unable to find playlist" );
310
 
            httpd_StreamDelete( p_sys->p_httpd_stream );
311
 
            httpd_HostDelete( p_sys->p_httpd_host );
312
 
            free( (void *)p_sys );
313
 
            return VLC_EGENERIC;
314
 
        }
315
 
 
316
 
        psz_name = strrchr( p_playlist->status.p_item->input.psz_uri,
317
 
                            DIRECTORY_SEPARATOR );
 
297
        playlist_t          *p_playlist = pl_Yield( p_access );
 
298
 
 
299
        char *psz_uri = input_item_GetURI( p_playlist->status.p_item->p_input );
 
300
        char *psz_newuri = psz_uri;
 
301
        psz_name = strrchr( psz_newuri, DIRECTORY_SEPARATOR );
318
302
        if( psz_name != NULL ) psz_name++;
319
 
        else psz_name = p_playlist->status.p_item->input.psz_uri;
 
303
        else psz_name = psz_newuri;
320
304
 
321
 
        asprintf( &psz_txt, "path=%s", psz_file_name );
 
305
        if( psz_file_name &&
 
306
            asprintf( &psz_txt, "path=%s", psz_file_name ) == -1 )
 
307
            {
 
308
                pl_Release( p_access );
 
309
                free( psz_uri );
 
310
                return VLC_ENOMEM;
 
311
            }
322
312
 
323
313
        p_sys->p_bonjour = bonjour_start_service( (vlc_object_t *)p_access,
324
314
                                    strcmp( p_access->psz_access, "https" )
325
315
                                       ? "_vlc-http._tcp" : "_vlc-https._tcp",
326
 
                                                  psz_name, i_bind_port, psz_txt );
327
 
        free( (void *)psz_txt );
 
316
                                             psz_name, i_bind_port, psz_txt );
 
317
        free( psz_uri );
 
318
        free( psz_txt );
328
319
 
329
320
        if( p_sys->p_bonjour == NULL )
330
 
        {
331
 
            msg_Err( p_access, "Avahi stream announcing was requested, but no avahi service could be started" );
332
 
        }
333
 
        vlc_object_release( p_playlist );
 
321
            msg_Err( p_access, "unable to start requested Bonjour announce" );
 
322
        pl_Release( p_access );
334
323
    }
335
324
    else
336
325
        p_sys->p_bonjour = NULL;
341
330
    p_sys->i_header_allocated = 1024;
342
331
    p_sys->i_header_size      = 0;
343
332
    p_sys->p_header           = malloc( p_sys->i_header_allocated );
344
 
    p_sys->b_header_complete  = VLC_FALSE;
 
333
    p_sys->b_header_complete  = false;
345
334
 
346
335
    p_access->pf_write       = Write;
347
336
    p_access->pf_seek        = Seek;
372
361
    httpd_StreamDelete( p_sys->p_httpd_stream );
373
362
    httpd_HostDelete( p_sys->p_httpd_host );
374
363
 
375
 
    FREE( p_sys->p_header );
 
364
    free( p_sys->p_header );
376
365
 
377
366
    msg_Dbg( p_access, "Close" );
378
367
 
382
371
/*****************************************************************************
383
372
 * Write:
384
373
 *****************************************************************************/
385
 
static int Write( sout_access_out_t *p_access, block_t *p_buffer )
 
374
static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
386
375
{
387
376
    sout_access_out_sys_t *p_sys = p_access->p_sys;
388
377
    int i_err = 0;
399
388
            {
400
389
                /* free previously gathered header */
401
390
                p_sys->i_header_size = 0;
402
 
                p_sys->b_header_complete = VLC_FALSE;
 
391
                p_sys->b_header_complete = false;
403
392
            }
404
393
            if( (int)(p_buffer->i_buffer + p_sys->i_header_size) >
405
394
                p_sys->i_header_allocated )
416
405
        }
417
406
        else if( !p_sys->b_header_complete )
418
407
        {
419
 
            p_sys->b_header_complete = VLC_TRUE;
 
408
            p_sys->b_header_complete = true;
420
409
 
421
410
            httpd_StreamHeader( p_sys->p_httpd_stream, p_sys->p_header,
422
411
                                p_sys->i_header_size );
450
439
 *****************************************************************************/
451
440
static int Seek( sout_access_out_t *p_access, off_t i_pos )
452
441
{
 
442
    (void)i_pos;
453
443
    msg_Warn( p_access, "HTTP sout access cannot seek" );
454
444
    return VLC_EGENERIC;
455
445
}