mirror of
https://github.com/mpv-player/mpv
synced 2024-12-23 23:32:26 +00:00
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
TODO: add libsmb* detection and #define LIBSMBCLIENT to ./configure ! git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7631 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
a5eea66f78
commit
632b8e8edd
@ -165,6 +165,10 @@ static char help_text[]=
|
||||
#define MSGTR_ConnToServer "Connected to server: %s\n"
|
||||
#define MSGTR_FileNotFound "File not found: '%s'\n"
|
||||
|
||||
#define MSGTR_SMBInitError "Cannot init the libsmbclient library: %d\n"
|
||||
#define MSGTR_SMBFileNotFound "Could not open from lan: '%s'\n"
|
||||
#define MSGTR_SMBNotCompiled "MPlayer was not compiled with SMB reading support\n"
|
||||
|
||||
#define MSGTR_CantOpenDVD "Couldn't open DVD device: %s\n"
|
||||
#define MSGTR_DVDwait "Reading disc structure, please wait...\n"
|
||||
#define MSGTR_DVDnumTitles "There are %d titles on this DVD.\n"
|
||||
|
@ -79,6 +79,44 @@ stream_t* cddb_open(char* dev,char* track);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Define function about auth the libsmbclient library
|
||||
// FIXME: I really do not not is this function is properly working
|
||||
|
||||
#ifdef LIBSMBCLIENT
|
||||
|
||||
#include "libsmbclient.h"
|
||||
|
||||
static char smb_password[15];
|
||||
static char smb_username[15];
|
||||
|
||||
static void smb_auth_fn(const char *server, const char *share,
|
||||
char *workgroup, int wgmaxlen, char *username, int unmaxlen,
|
||||
char *password, int pwmaxlen)
|
||||
{
|
||||
char temp[128];
|
||||
|
||||
strcpy(temp, "LAN");
|
||||
if (temp[strlen(temp) - 1] == 0x0a)
|
||||
temp[strlen(temp) - 1] = 0x00;
|
||||
|
||||
if (temp[0]) strncpy(workgroup, temp, wgmaxlen - 1);
|
||||
|
||||
strcpy(temp, smb_username);
|
||||
if (temp[strlen(temp) - 1] == 0x0a)
|
||||
temp[strlen(temp) - 1] = 0x00;
|
||||
|
||||
if (temp[0]) strncpy(username, temp, unmaxlen - 1);
|
||||
|
||||
strcpy(temp, smb_password);
|
||||
if (temp[strlen(temp) - 1] == 0x0a)
|
||||
temp[strlen(temp) - 1] = 0x00;
|
||||
|
||||
if (temp[0]) strncpy(password, temp, pwmaxlen - 1);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// Open a new stream (stdin/file/vcd/url)
|
||||
|
||||
stream_t* open_stream(char* filename,int vcd_track,int* file_format){
|
||||
@ -409,6 +447,43 @@ if(dvd_title){
|
||||
#ifdef STREAMING
|
||||
url = url_new(filename);
|
||||
if(url) {
|
||||
if (strcmp(url->protocol, "smb")==0){
|
||||
#ifdef LIBSMBCLIENT
|
||||
|
||||
// we need init of libsmbclient
|
||||
int err;
|
||||
|
||||
// FIXME: HACK: make the username/password global varaibles
|
||||
// so the auth_fn function should grab it ...
|
||||
// i cannot thing other way...
|
||||
err = smbc_init(smb_auth_fn, 10); /* Initialize things */
|
||||
// libsmbclient using
|
||||
if (err < 0) {
|
||||
mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBInitError,err);
|
||||
return NULL;
|
||||
}
|
||||
f=smbc_open(filename, O_RDONLY, 0666);
|
||||
|
||||
// cannot open the file, outputs that
|
||||
// MSGTR_FileNotFound -> MSGTR_SMBFileNotFound
|
||||
if(f<0){
|
||||
mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBFileNotFound,filename);
|
||||
return NULL;
|
||||
}
|
||||
len=smbc_lseek(f,0,SEEK_END);
|
||||
smbc_lseek(f,0,SEEK_SET);
|
||||
// FIXME: I really wonder is such situation -> but who cares ;)
|
||||
// if (len == -1)
|
||||
// return new_stream(f,STREAMTYPE_STREAM); // open as stream
|
||||
url_free(url);
|
||||
stream=new_stream(f,STREAMTYPE_SMB);
|
||||
stream->end_pos=len;
|
||||
return stream;
|
||||
#else
|
||||
mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBNotCompiled,filename);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
stream=new_stream(f,STREAMTYPE_STREAM);
|
||||
if( streaming_start( stream, file_format, url )<0){
|
||||
mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_UnableOpenURL, filename);
|
||||
|
@ -44,12 +44,21 @@ void seek_cdda(stream_t* s);
|
||||
void close_cdda(stream_t* s);
|
||||
#endif
|
||||
|
||||
#ifdef LIBSMBCLIENT
|
||||
#include "libsmbclient.h"
|
||||
#endif
|
||||
|
||||
//=================== STREAMER =========================
|
||||
|
||||
int stream_fill_buffer(stream_t *s){
|
||||
int len;
|
||||
if(s->eof){ s->buf_pos=s->buf_len=0; return 0; }
|
||||
switch(s->type){
|
||||
#ifdef LIBSMBCLIENT
|
||||
case STREAMTYPE_SMB:
|
||||
len=smbc_read(s->fd,s->buffer,STREAM_BUFFER_SIZE);
|
||||
break;
|
||||
#endif
|
||||
case STREAMTYPE_FILE:
|
||||
case STREAMTYPE_STREAM:
|
||||
case STREAMTYPE_PLAYLIST:
|
||||
@ -110,6 +119,7 @@ off_t newpos=0;
|
||||
|
||||
switch(s->type){
|
||||
case STREAMTYPE_FILE:
|
||||
case STREAMTYPE_SMB:
|
||||
case STREAMTYPE_STREAM:
|
||||
#ifdef _LARGEFILE_SOURCE
|
||||
newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break;
|
||||
@ -140,6 +150,12 @@ if(newpos==0 || newpos!=s->pos){
|
||||
s->pos=newpos; // real seek
|
||||
if(lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1;
|
||||
break;
|
||||
#ifdef LIBSMBCLIENT
|
||||
case STREAMTYPE_SMB:
|
||||
s->pos=newpos; // real seek
|
||||
if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1;
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_VCD
|
||||
case STREAMTYPE_VCD:
|
||||
s->pos=newpos; // real seek
|
||||
@ -267,6 +283,11 @@ void free_stream(stream_t *s){
|
||||
}
|
||||
if(s->fd>0) close(s->fd);
|
||||
switch(s->type) {
|
||||
#ifdef LIBSMBCLIENT
|
||||
case STREAMTYPE_SMB:
|
||||
smbc_close(s->fd);
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_CDDA
|
||||
case STREAMTYPE_CDDA:
|
||||
close_cdda(s);
|
||||
|
@ -16,6 +16,7 @@
|
||||
#define STREAMTYPE_DS 8 // read from a demuxer stream
|
||||
#define STREAMTYPE_DVDNAV 9 // we cannot safely "seek" in this...
|
||||
#define STREAMTYPE_CDDA 10 // raw audio CD reader
|
||||
#define STREAMTYPE_SMB 11 // smb:// url, using libsmbclient (samba)
|
||||
|
||||
#define STREAM_BUFFER_SIZE 2048
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user