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

« back to all changes in this revision

Viewing changes to modules/access/smb.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
 * smb.c: SMB input module
3
3
 *****************************************************************************
4
4
 * Copyright (C) 2001-2004 the VideoLAN team
5
 
 * $Id: 1a39e0645f8fa3dfd82a714fff31586268cbcd40 $
 
5
 * $Id$
6
6
 *
7
7
 * Authors: Gildas Bazin <gbazin@videolan.org>
8
8
 *
24
24
/*****************************************************************************
25
25
 * Preamble
26
26
 *****************************************************************************/
27
 
#include <stdlib.h>
28
 
 
29
 
#include <vlc/vlc.h>
30
 
#include <vlc/input.h>
 
27
 
 
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_access.h>
31
36
 
32
37
#ifdef WIN32
33
38
#ifdef HAVE_FCNTL_H
72
77
 
73
78
vlc_module_begin();
74
79
    set_shortname( "SMB" );
75
 
    set_description( _("SMB input") );
76
 
    set_capability( "access2", 0 );
 
80
    set_description( N_("SMB input") );
 
81
    set_capability( "access", 0 );
77
82
    set_category( CAT_INPUT );
78
83
    set_subcategory( SUBCAT_INPUT_ACCESS );
79
84
    add_integer( "smb-caching", 2 * DEFAULT_PTS_DELAY / 1000, NULL,
80
 
                 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
 
85
                 CACHING_TEXT, CACHING_LONGTEXT, true );
81
86
    add_string( "smb-user", NULL, NULL, USER_TEXT, USER_LONGTEXT,
82
 
                VLC_FALSE );
 
87
                false );
83
88
    add_string( "smb-pwd", NULL, NULL, PASS_TEXT,
84
 
                PASS_LONGTEXT, VLC_FALSE );
 
89
                PASS_LONGTEXT, false );
85
90
    add_string( "smb-domain", NULL, NULL, DOMAIN_TEXT,
86
 
                DOMAIN_LONGTEXT, VLC_FALSE );
 
91
                DOMAIN_LONGTEXT, false );
87
92
    add_shortcut( "smb" );
88
93
    set_callbacks( Open, Close );
89
94
vlc_module_end();
91
96
/*****************************************************************************
92
97
 * Local prototypes
93
98
 *****************************************************************************/
94
 
static int Read( access_t *, uint8_t *, int );
 
99
static ssize_t Read( access_t *, uint8_t *, size_t );
95
100
static int Seek( access_t *, int64_t );
96
101
static int Control( access_t *, int, va_list );
97
102
 
107
112
 
108
113
#ifdef WIN32
109
114
static void Win32AddConnection( access_t *, char *, char *, char *, char * );
110
 
#endif
111
 
 
112
 
void smb_auth( const char *srv, const char *shr, char *wg, int wglen,
113
 
               char *un, int unlen, char *pw, int pwlen )
 
115
#else
 
116
static void smb_auth( const char *srv, const char *shr, char *wg, int wglen,
 
117
                      char *un, int unlen, char *pw, int pwlen )
114
118
{
115
119
    //wglen = unlen = pwlen = 0;
116
120
}
 
121
#endif
117
122
 
118
123
/****************************************************************************
119
124
 * Open: connect to smb server and ask for file
187
192
    if( psz_user && !*psz_user ) { free( psz_user ); psz_user = 0; }
188
193
    if( !psz_pwd ) psz_pwd = var_CreateGetString( p_access, "smb-pwd" );
189
194
    if( psz_pwd && !*psz_pwd ) { free( psz_pwd ); psz_pwd = 0; }
190
 
    if(!psz_domain) psz_domain = var_CreateGetString( p_access, "smb-domain" );
 
195
    if( !psz_domain ) psz_domain = var_CreateGetString( p_access, "smb-domain" );
191
196
    if( psz_domain && !*psz_domain ) { free( psz_domain ); psz_domain = 0; }
192
197
 
193
198
#ifdef WIN32
194
199
    if( psz_user )
195
200
        Win32AddConnection( p_access, psz_path, psz_user, psz_pwd, psz_domain);
196
 
    asprintf( &psz_uri, "//%s", psz_path );
 
201
    i_ret = asprintf( &psz_uri, "//%s", psz_path );
197
202
#else
198
203
    if( psz_user )
199
 
        asprintf( &psz_uri, "smb://%s%s%s%s%s@%s",
200
 
                  psz_domain ? psz_domain : "", psz_domain ? ";" : "",
201
 
                  psz_user, psz_pwd ? ":" : "",
202
 
                  psz_pwd ? psz_pwd : "", psz_path );
 
204
        i_ret = asprintf( &psz_uri, "smb://%s%s%s%s%s@%s",
 
205
                          psz_domain ? psz_domain : "", psz_domain ? ";" : "",
 
206
                          psz_user, psz_pwd ? ":" : "",
 
207
                          psz_pwd ? psz_pwd : "", psz_path );
203
208
    else
204
 
        asprintf( &psz_uri, "smb://%s", psz_path );
 
209
        i_ret = asprintf( &psz_uri, "smb://%s", psz_path );
205
210
#endif
206
211
 
207
 
    if( psz_user ) free( psz_user );
208
 
    if( psz_pwd ) free( psz_pwd );
209
 
    if( psz_domain ) free( psz_domain );
 
212
    free( psz_user );
 
213
    free( psz_pwd );
 
214
    free( psz_domain );
 
215
 
 
216
    if( i_ret == -1 )
 
217
        return VLC_ENOMEM;
210
218
 
211
219
#ifdef USE_CTX
212
220
    if( !(p_smb = smbc_new_context()) )
213
221
    {
214
 
        msg_Err( p_access, "out of memory" );
215
222
        free( psz_uri );
216
223
        return VLC_ENOMEM;
217
224
    }
220
227
 
221
228
    if( !smbc_init_context( p_smb ) )
222
229
    {
223
 
        msg_Err( p_access, "cannot initialize context (%s)", strerror(errno) );
 
230
        msg_Err( p_access, "cannot initialize context (%m)" );
224
231
        smbc_free_context( p_smb, 1 );
225
232
        free( psz_uri );
226
233
        return VLC_EGENERIC;
228
235
 
229
236
    if( !(p_file = (p_smb->open)( p_smb, psz_uri, O_RDONLY, 0 )) )
230
237
    {
231
 
        msg_Err( p_access, "open failed for '%s' (%s)",
232
 
                 p_access->psz_path, strerror(errno) );
 
238
        msg_Err( p_access, "open failed for '%s' (%m)",
 
239
                 p_access->psz_path );
233
240
        smbc_free_context( p_smb, 1 );
234
241
        free( psz_uri );
235
242
        return VLC_EGENERIC;
236
243
    }
237
244
 
238
 
    p_access->info.i_size = 0;
 
245
    /* Init p_access */
 
246
    STANDARD_READ_ACCESS_INIT;
 
247
 
239
248
    i_ret = p_smb->fstat( p_smb, p_file, &filestat );
240
 
    if( i_ret ) msg_Err( p_access, "stat failed (%s)", strerror(errno) );
 
249
    if( i_ret ) msg_Err( p_access, "stat failed (%m)" );
241
250
    else p_access->info.i_size = filestat.st_size;
242
 
 
243
251
#else
244
252
 
245
253
#ifndef WIN32
260
268
#endif
261
269
    if( (i_smb = smbc_open( psz_uri, O_RDONLY, 0 )) < 0 )
262
270
    {
263
 
        msg_Err( p_access, "open failed for '%s' (%s)",
264
 
                 p_access->psz_path, strerror(errno) );
 
271
        msg_Err( p_access, "open failed for '%s' (%m)",
 
272
                 p_access->psz_path );
265
273
        free( psz_uri );
266
274
        return VLC_EGENERIC;
267
275
    }
268
276
 
269
 
    p_access->info.i_size = 0;
 
277
    /* Init p_access */
 
278
    STANDARD_READ_ACCESS_INIT;
 
279
 
270
280
    i_ret = smbc_fstat( i_smb, &filestat );
271
 
    if( i_ret ) msg_Err( p_access, "stat failed (%s)", strerror(i_ret) );
 
281
    if( i_ret )
 
282
    {
 
283
        errno = i_ret;
 
284
        msg_Err( p_access, "stat failed (%m)" );
 
285
    }
272
286
    else p_access->info.i_size = filestat.st_size;
273
287
#endif
274
288
 
275
289
    free( psz_uri );
276
290
 
277
 
    /* Init p_access */
278
 
    p_access->pf_read = Read;
279
 
    p_access->pf_block = NULL;
280
 
    p_access->pf_seek = Seek;
281
 
    p_access->pf_control = Control;
282
 
    p_access->info.i_update = 0;
283
 
    p_access->info.i_pos = 0;
284
 
    p_access->info.b_eof = VLC_FALSE;
285
 
    p_access->info.i_title = 0;
286
 
    p_access->info.i_seekpoint = 0;
287
 
    p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
288
 
    memset( p_sys, 0, sizeof( access_sys_t ) );
289
 
 
290
291
#ifdef USE_CTX
291
292
    p_sys->p_smb = p_smb;
292
293
    p_sys->p_file = p_file;
332
333
 
333
334
    if( i_pos < 0 ) return VLC_EGENERIC;
334
335
 
335
 
    msg_Dbg( p_access, "seeking to "I64Fd, i_pos );
 
336
    msg_Dbg( p_access, "seeking to %"PRId64, i_pos );
336
337
 
337
338
#ifdef USE_CTX
338
339
    i_ret = p_sys->p_smb->lseek(p_sys->p_smb, p_sys->p_file, i_pos, SEEK_SET);
341
342
#endif
342
343
    if( i_ret == -1 )
343
344
    {
344
 
        msg_Err( p_access, "seek failed (%s)", strerror(errno) );
 
345
        msg_Err( p_access, "seek failed (%m)" );
345
346
        return VLC_EGENERIC;
346
347
    }
347
348
 
348
 
    p_access->info.b_eof = VLC_FALSE;
 
349
    p_access->info.b_eof = false;
349
350
    p_access->info.i_pos = i_ret;
350
351
 
351
352
    return VLC_SUCCESS;
354
355
/*****************************************************************************
355
356
 * Read:
356
357
 *****************************************************************************/
357
 
static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
 
358
static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
358
359
{
359
360
    access_sys_t *p_sys = p_access->p_sys;
360
361
    int i_read;
368
369
#endif
369
370
    if( i_read < 0 )
370
371
    {
371
 
        msg_Err( p_access, "read failed (%s)", strerror(errno) );
 
372
        msg_Err( p_access, "read failed (%m)" );
372
373
        return -1;
373
374
    }
374
375
 
375
 
    if( i_read == 0 ) p_access->info.b_eof = VLC_TRUE;
 
376
    if( i_read == 0 ) p_access->info.b_eof = true;
376
377
    else if( i_read > 0 ) p_access->info.i_pos += i_read;
377
378
 
378
379
    return i_read;
383
384
 *****************************************************************************/
384
385
static int Control( access_t *p_access, int i_query, va_list args )
385
386
{
386
 
    vlc_bool_t   *pb_bool;
 
387
    bool   *pb_bool;
387
388
    int          *pi_int;
388
389
    int64_t      *pi_64;
389
390
 
390
391
    switch( i_query )
391
392
    {
392
393
    case ACCESS_CAN_SEEK:
393
 
        pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
394
 
        *pb_bool = VLC_TRUE;
 
394
        pb_bool = (bool*)va_arg( args, bool* );
 
395
        *pb_bool = true;
395
396
        break;
396
397
    case ACCESS_CAN_FASTSEEK:
397
 
        pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
398
 
        *pb_bool = VLC_TRUE;
 
398
        pb_bool = (bool*)va_arg( args, bool* );
 
399
        *pb_bool = true;
399
400
        break;
400
401
    case ACCESS_CAN_PAUSE:
401
 
        pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
402
 
        *pb_bool = VLC_TRUE;
 
402
        pb_bool = (bool*)va_arg( args, bool* );
 
403
        *pb_bool = true;
403
404
        break;
404
405
    case ACCESS_CAN_CONTROL_PACE:
405
 
        pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
406
 
        *pb_bool = VLC_TRUE;
 
406
        pb_bool = (bool*)va_arg( args, bool* );
 
407
        *pb_bool = true;
407
408
        break;
408
409
 
409
410
    case ACCESS_GET_MTU:
424
425
    case ACCESS_SET_TITLE:
425
426
    case ACCESS_SET_SEEKPOINT:
426
427
    case ACCESS_SET_PRIVATE_ID_STATE:
 
428
    case ACCESS_GET_CONTENT_TYPE:
427
429
        return VLC_EGENERIC;
428
430
 
429
431
    default:
445
447
    NETRESOURCE net_resource;
446
448
    DWORD i_result;
447
449
    char *psz_parser;
 
450
    VLC_UNUSED( psz_domain );
448
451
 
449
452
    HINSTANCE hdll = LoadLibrary(_T("MPR.DLL"));
450
453
    if( !hdll )
484
487
    {
485
488
        msg_Dbg( p_access, "connected to %s", psz_remote );
486
489
    }
487
 
    else if( i_result != ERROR_ALREADY_ASSIGNED && 
 
490
    else if( i_result != ERROR_ALREADY_ASSIGNED &&
488
491
             i_result != ERROR_DEVICE_ALREADY_REMEMBERED )
489
492
    {
490
493
        msg_Dbg( p_access, "already connected to %s", psz_remote );