[MPlayer-cvslog] CVS: main/libmpdemux stream_smb.c, NONE, 1.1 Makefile, 1.89, 1.90 open.c, 1.107, 1.108 stream.c, 1.76, 1.77

Nico Sabbi CVS syncmail at mplayerhq.hu
Thu May 19 22:58:13 CEST 2005


CVS change done by Nico Sabbi CVS

Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var2/tmp/cvs-serv6908

Modified Files:
	Makefile open.c stream.c 
Added Files:
	stream_smb.c 
Log Message:
ported smb:// to the new stream api

--- NEW FILE ---

#include "config.h"

#ifdef LIBSMBCLIENT

#include <libsmbclient.h>
#include <unistd.h>
#include <stdio.h>

#include "mp_msg.h"
#include "stream.h"
#include "help_mp.h"
#include "../m_option.h"
#include "../m_struct.h"

static struct stream_priv_s {
} stream_priv_dflts = {
};

#define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
// URL definition
static m_option_t stream_opts_fields[] = {
  { NULL, NULL, 0, 0, 0, 0,  NULL }
};

static struct m_struct_st stream_opts = {
  "smb",
  sizeof(struct stream_priv_s),
  &stream_priv_dflts,
  stream_opts_fields
};

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);
}

static int seek(stream_t *s,off_t newpos) {
  s->pos = newpos;
  if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) {
    s->eof=1;
    return 0;
  }
  return 1;
}

static int fill_buffer(stream_t *s, char* buffer, int max_len){
  int r = smbc_read(s->fd,buffer,max_len);
  return (r <= 0) ? -1 : r;
}

static int write_buffer(stream_t *s, char* buffer, int len) {
  int r = smbc_write(s->fd,buffer,len);
  return (r <= 0) ? -1 : r;
}

static void close_f(stream_t *s){
  smbc_close(s->fd);
}

static int open_f (stream_t *stream, int mode, void *opts, int* file_format) {
  struct stream_priv_s *p = (struct stream_priv_s*)opts;
  char *filename;
  mode_t m = 0;
  off_t len;
  int fd, err;
  
  filename = stream->url;
  
  if(mode == STREAM_READ)
    m = O_RDONLY;
  else if (mode == STREAM_WRITE) //who's gonna do that ?
    m = O_WRONLY;
  else {
    mp_msg(MSGT_OPEN, MSGL_ERR, "[smb] Unknown open mode %d\n", mode);
    m_struct_free (&stream_opts, opts);
    return STREAM_UNSUPORTED;
  }
  
  if(!filename) {
    mp_msg(MSGT_OPEN,MSGL_ERR, "[smb] Bad url\n");
    m_struct_free(&stream_opts, opts);
    return STREAM_ERROR;
  }
  
  err = smbc_init(smb_auth_fn, 1);
  if (err < 0) {
    mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBInitError,err);
    m_struct_free(&stream_opts, opts);
    return STREAM_ERROR;
  }
  
  fd = smbc_open(filename, m,0644);
  if (fd < 0) {	
    mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBFileNotFound, filename);
    m_struct_free(&stream_opts, opts);
    return STREAM_ERROR;
  }
  
  len = smbc_lseek(fd,0,SEEK_END);
  smbc_lseek (fd, 0, SEEK_SET);
  if (len <= 0)
    stream->flags = 0;
  else {
    stream->flags = STREAM_READ | STREAM_SEEK;
    stream->end_pos = len;
    stream->seek = seek;
  }
  stream->type = STREAMTYPE_SMB;
  stream->fd = fd;
  stream->fill_buffer = fill_buffer;
  stream->write_buffer = write_buffer;
  stream->close = close_f;
  
  m_struct_free(&stream_opts, opts);
  return STREAM_OK;
}

stream_info_t stream_info_smb = {
  "Server Message Block",
  "smb",
  "M. Tourne",
  "based on the code from 'a bulgarian' (one says)",
  open_f,
  {"smb", NULL},
  &stream_opts,
  0 //Url is an option string
};

#endif

Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/Makefile,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -r1.89 -r1.90
--- Makefile	19 May 2005 19:50:39 -0000	1.89
+++ Makefile	19 May 2005 20:58:11 -0000	1.90
@@ -3,7 +3,7 @@
 
 include ../config.mak
 
-SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c muxer.c muxer_avi.c muxer_mpeg.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_ty.c demux_ty_osd.c demux_pva.c demux_viv.c demuxer.c dvdnav_stream.c open.c parse_es.c stream.c stream_file.c stream_netstream.c stream_vcd.c stream_null.c stream_ftp.c stream_vstream.c tv.c tvi_dummy.c tvi_v4l.c tvi_v4l2.c tvi_bsdbt848.c frequencies.c demux_fli.c demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c demux_roq.c mf.c demux_mf.c demux_audio.c demux_demuxers.c demux_ogg.c cdda.c demux_rawaudio.c demux_rawvideo.c cddb.c cdinfo.c demux_rawdv.c ai_alsa.c ai_alsa1x.c ai_oss.c audio_in.c demux_smjpeg.c demux_lmlm4.c cue_read.c extension.c demux_gif.c demux_ts.c demux_realaud.c url.c muxer_rawvideo.c demux_lavf.c demux_nsv.c demux_vqf.c stream_dvd.c
+SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c muxer.c muxer_avi.c muxer_mpeg.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_ty.c demux_ty_osd.c demux_pva.c demux_viv.c demuxer.c dvdnav_stream.c open.c parse_es.c stream.c stream_file.c stream_netstream.c stream_vcd.c stream_null.c stream_ftp.c stream_smb.c stream_vstream.c tv.c tvi_dummy.c tvi_v4l.c tvi_v4l2.c tvi_bsdbt848.c frequencies.c demux_fli.c demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c demux_roq.c mf.c demux_mf.c demux_audio.c demux_demuxers.c demux_ogg.c cdda.c demux_rawaudio.c demux_rawvideo.c cddb.c cdinfo.c demux_rawdv.c ai_alsa.c ai_alsa1x.c ai_oss.c audio_in.c demux_smjpeg.c demux_lmlm4.c cue_read.c extension.c demux_gif.c demux_ts.c demux_realaud.c url.c muxer_rawvideo.c demux_lavf.c demux_nsv.c demux_vqf.c stream_dvd.c
 ifeq ($(XMMS_PLUGINS),yes)
 SRCS += demux_xmms.c
 endif 

Index: open.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/open.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -r1.107 -r1.108
--- open.c	19 May 2005 19:50:39 -0000	1.107
+++ open.c	19 May 2005 20:58:11 -0000	1.108
@@ -34,45 +34,6 @@
 int vcd_track=0;
 char* cdrom_device=NULL;
 
-
-// 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,char** options, int* file_format){
@@ -122,50 +83,12 @@
     strncmp("cdda://", filename, 7) && strncmp("cddb://", filename, 7) &&
     strncmp("mpst://", filename, 7) && strncmp("tivo://", filename, 7) &&
     strncmp("file://", filename, 7) && strncmp("cue://", filename, 6) &&
-    strncmp("ftp://", filename, 6) &&
+    strncmp("ftp://", filename, 6) && strncmp("smb://", filename, 6) && 
     strncmp("dvd://", filename, 6) && strncmp("dvdnav://", filename, 9) &&
     strstr(filename, "://")) {
      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);
-	    url = NULL;
-            stream=new_stream(f,STREAMTYPE_SMB);
-    	    stream->end_pos=len;
-	    return stream;
-#else
-	    mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBNotCompiled);
-	    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);

Index: stream.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- stream.c	19 May 2005 19:50:39 -0000	1.76
+++ stream.c	19 May 2005 20:58:11 -0000	1.77
@@ -37,10 +37,6 @@
 
 //#include "vcd_read_bincue.h"
 
-#ifdef LIBSMBCLIENT
-#include "libsmbclient.h"
-#endif
-
 #ifdef HAVE_VCD
 extern stream_info_t stream_info_vcd;
 #endif
@@ -62,6 +58,9 @@
 #ifdef USE_DVDNAV
 extern stream_info_t stream_info_dvdnav;
 #endif
+#ifdef LIBSMBCLIENT
+extern stream_info_t stream_info_smb;
+#endif
 
 extern stream_info_t stream_info_cue;
 extern stream_info_t stream_info_null;
@@ -87,6 +86,9 @@
 #ifdef HAVE_VSTREAM
   &stream_info_vstream,
 #endif
+#ifdef LIBSMBCLIENT
+  &stream_info_smb,
+#endif
   &stream_info_cue,
   &stream_info_dvd,
 #ifdef USE_DVDNAV
@@ -191,11 +193,6 @@
   int len;
   if (/*s->fd == NULL ||*/ 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_STREAM:
 #ifdef MPLAYER_NETWORK
     if( s->streaming_ctrl!=NULL ) {
@@ -230,7 +227,6 @@
   s->buf_pos=s->buf_len=0;
 
   switch(s->type){
-  case STREAMTYPE_SMB:
   case STREAMTYPE_STREAM:
 #ifdef _LARGEFILE_SOURCE
     newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break;
@@ -264,12 +260,6 @@
 
 if(newpos==0 || newpos!=s->pos){
   switch(s->type){
-#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
   case STREAMTYPE_STREAM:
     //s->pos=newpos; // real seek
     // Some streaming protocol allow to seek backward and forward
@@ -386,15 +376,7 @@
     cache_uninit(s);
   }
 #endif
-  switch(s->type) {
-#ifdef LIBSMBCLIENT
-  case STREAMTYPE_SMB:
-    smbc_close(s->fd);
-    break;    
-#endif
-  default:
-    if(s->close) s->close(s);
-  }
+  if(s->close) s->close(s);
   if(s->fd>0){
     /* on unix we define closesocket to close
        on windows however we have to distinguish between




More information about the MPlayer-cvslog mailing list