diff options
author | Miguel Freitas <miguelfreitas@users.sourceforge.net> | 2004-10-18 18:01:44 +0000 |
---|---|---|
committer | Miguel Freitas <miguelfreitas@users.sourceforge.net> | 2004-10-18 18:01:44 +0000 |
commit | ef1550b3d1959dcf1ad46f88b5ce7ff90039fc4f (patch) | |
tree | b4e2b802d1052215c608e270655724659488adea | |
parent | 476d875bd66137ba47af5a3c5eb2fa608ca2757c (diff) | |
download | xine-lib-ef1550b3d1959dcf1ad46f88b5ce7ff90039fc4f.tar.gz xine-lib-ef1550b3d1959dcf1ad46f88b5ce7ff90039fc4f.tar.bz2 |
Simple libsmbclient (samba) input plugin
CVS patchset: 7044
CVS date: 2004/10/18 18:01:44
-rw-r--r-- | AUTHORS | 3 | ||||
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | configure.ac | 17 | ||||
-rw-r--r-- | src/input/Makefile.am | 10 | ||||
-rw-r--r-- | src/input/input_smb.c | 264 |
5 files changed, 295 insertions, 0 deletions
@@ -507,5 +507,8 @@ Casper Boemann <cbr@boemann.dk> Thomas Hellström <unichrome@shipmail.org> XxMC driver with reworked XvMC support, including VIA CLE266 vld extensions. + +Frank van Viegen <frank@vanviegen.net> + libsmbclient input plugin (let us know if we've forgotten anyone) @@ -31,6 +31,7 @@ * Fixed crash when xine_stop is called and the stream is ending * Fixed crash when the video_out loop still references a disposed stream * Make amp work with 8-bit sounds + * Simple libsmbclient (samba) input plugin xine-lib (1-rc6) * Moved win32 frontend into separate module. diff --git a/configure.ac b/configure.ac index b9d850088..7b5974883 100644 --- a/configure.ac +++ b/configure.ac @@ -1124,6 +1124,20 @@ AM_CONDITIONAL(HAVE_GNOME_VFS, test x"$no_gnome_vfs" != "xyes") dnl --------------------------------------------- +dnl libsmbclient support +dnl --------------------------------------------- + +AC_CHECK_LIB(smbclient, smbc_init, + [ AC_CHECK_HEADER(libsmbclient.h, + [ have_libsmbclient=yes + LIBSMBCLIENT_LIBS="-lsmbclient" ], + AC_MSG_RESULT([*** All libsmbclient dependent parts will be disabled ***]))], + AC_MSG_RESULT([*** All libsmbclient dependent parts will be disabled ***])) +AM_CONDITIONAL(HAVE_LIBSMBCLIENT, test x"$have_libsmbclient" = "xyes") +AC_SUBST(LIBSMBCLIENT_LIBS) + + +dnl --------------------------------------------- dnl SUN style audio interface dnl --------------------------------------------- @@ -2279,6 +2293,9 @@ fi if test x"$have_v4l" = "xyes"; then echo " - v4l" fi +if test x"$have_libsmbclient" = "xyes"; then + echo " - smbclient" +fi echo "" dnl Demuxers diff --git a/src/input/Makefile.am b/src/input/Makefile.am index 04c418a15..1f950075d 100644 --- a/src/input/Makefile.am +++ b/src/input/Makefile.am @@ -35,6 +35,10 @@ if HAVE_GNOME_VFS in_gnome_vfs = xineplug_inp_gnome_vfs.la endif +if HAVE_LIBSMBCLIENT +in_smb = xineplug_inp_smb.la +endif + # For DVD if HAVE_DVDNAV DVD_CFLAGS = $(DVDNAV_CFLAGS) @@ -59,6 +63,7 @@ lib_LTLIBRARIES = \ $(in_vcd) \ $(in_v4l) \ $(in_gnome_vfs) \ + $(in_smb) \ xineplug_inp_mms.la \ xineplug_inp_stdin_fifo.la \ xineplug_inp_pnm.la \ @@ -126,9 +131,14 @@ xineplug_inp_gnome_vfs_la_SOURCES = input_gnome_vfs.c xineplug_inp_gnome_vfs_la_LIBADD = $(GNOME_VFS_LIBS) $(XINE_LIB) xineplug_inp_gnome_vfs_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ +xineplug_inp_smb_la_SOURCES = input_smb.c +xineplug_inp_smb_la_LIBADD = $(LIBSMBCLIENT_LIBS) $(XINE_LIB) +xineplug_inp_smb_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ + xineplug_inp_pvr_la_SOURCES = input_pvr.c xineplug_inp_pvr_la_LIBADD = $(XINE_LIB) xineplug_inp_pvr_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ include_HEADERS = input_plugin.h noinst_HEADERS = net_buf_ctrl.h mms.h mmsh.h pnm.h media_helper.h videodev2.h http_helper.h + diff --git a/src/input/input_smb.c b/src/input/input_smb.c new file mode 100644 index 000000000..51e323116 --- /dev/null +++ b/src/input/input_smb.c @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2004 the xine project + * + * This file is part of totem, + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * $Id: input_smb.c,v 1.1 2004/10/18 18:01:46 miguelfreitas Exp $ + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "xine_internal.h" +#include "xineutils.h" +#include "compat.h" +#include "input_plugin.h" + +#include <libsmbclient.h> +#include <sys/types.h> +#include <errno.h> + +typedef struct { + input_class_t input_class; + xine_t *xine; +} smb_input_class_t; + +typedef struct { + input_plugin_t input_plugin; + xine_stream_t *stream; + + /* File */ + char *mrl; + int fd; +} smb_input_t; + + +static uint32_t +smb_plugin_get_capabilities (input_plugin_t *this_gen) +{ + return INPUT_CAP_SEEKABLE; // | INPUT_CAP_SPULANG; +} + + +static off_t +smb_plugin_read (input_plugin_t *this_gen, char *buf, off_t len) +{ + smb_input_t *this = (smb_input_t *) this_gen; + off_t n, num_bytes; + + num_bytes = 0; + + while (num_bytes < len) + { + n = smbc_read( this->fd, buf+num_bytes, len-num_bytes ); + if (n<1) return -1; + if (!n) return num_bytes; + num_bytes += n; + } + + return num_bytes; +} + +static buf_element_t* +smb_plugin_read_block (input_plugin_t *this_gen, fifo_buffer_t *fifo, + off_t todo) +{ + off_t total_bytes; + buf_element_t *buf = fifo->buffer_pool_alloc (fifo); + + buf->content = buf->mem; + buf->type = BUF_DEMUX_BLOCK; + + total_bytes = smb_plugin_read (this_gen, buf->content, todo); + + if (total_bytes == todo) buf->size = todo; + else + { + buf->free_buffer (buf); + buf = NULL; + } + + return buf; +} + +static off_t +smb_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin) +{ + smb_input_t *this = (smb_input_t *) this_gen; + + if (this->fd<0) return 0; + return smbc_lseek(this->fd,offset,origin); +} + +static off_t +smb_plugin_get_current_pos (input_plugin_t *this_gen) +{ + smb_input_t *this = (smb_input_t *) this_gen; + + if (this->fd<0) return 0; + return smbc_lseek(this->fd,0,SEEK_CUR); +} + +static off_t +smb_plugin_get_length (input_plugin_t *this_gen) +{ + smb_input_t *this = (smb_input_t *) this_gen; + + int e; + struct stat st; + + if (this->fd>=0) e = smbc_fstat(this->fd,&st); + else e = smbc_stat(this->mrl,&st); + + if (e) return 0; + + return st.st_size; +} + +static char* +smb_plugin_get_mrl (input_plugin_t *this_gen) +{ + smb_input_t *this = (smb_input_t *) this_gen; + + return this->mrl; +} + +static char +*smb_class_get_description (input_class_t *this_gen) +{ + return _("CIFS/SMB input plugin based on libsmbclient"); +} + +static const char +*smb_class_get_identifier (input_class_t *this_gen) +{ + return "smb"; +} + +static int +smb_plugin_get_optional_data (input_plugin_t *this_gen, + void *data, int data_type) +{ + return INPUT_OPTIONAL_UNSUPPORTED; +} + +static void +smb_plugin_dispose (input_plugin_t *this_gen ) +{ + smb_input_t *this = (smb_input_t *) this_gen; + + if (this->fd>=0) + smbc_close(this->fd); + if (this->mrl) + free (this->mrl); + free (this); +} + +static int +smb_plugin_open (input_plugin_t *this_gen ) +{ + smb_input_t *this = (smb_input_t *) this_gen; + smb_input_class_t *class = (smb_input_class_t *) this_gen->input_class; + + this->fd = smbc_open(this->mrl,O_RDONLY,0); + xprintf(class->xine, XINE_VERBOSITY_DEBUG, + "input_smb: open failed for %s: %s\n", + this->mrl, strerror(errno)); + if (this->fd<0) return 0; + + return 1; +} + +static void +smb_class_dispose (input_class_t *this_gen) +{ + smb_input_class_t *this = (smb_input_class_t *) this_gen; + + free (this); +} + +static input_plugin_t * +smb_class_get_instance (input_class_t *class_gen, xine_stream_t *stream, + const char *mrl) +{ + smb_input_t *this; + + if (mrl == NULL) + return NULL; + if (strncmp (mrl, "smb://",6)) + return NULL; + + this = (smb_input_t *)xine_xmalloc(sizeof(smb_input_t)); + this->stream = stream; + this->mrl = strdup (mrl); + this->fd = -1; + + this->input_plugin.open = smb_plugin_open; + this->input_plugin.get_capabilities = smb_plugin_get_capabilities; + this->input_plugin.read = smb_plugin_read; + this->input_plugin.read_block = smb_plugin_read_block; + this->input_plugin.seek = smb_plugin_seek; + this->input_plugin.get_current_pos = smb_plugin_get_current_pos; + this->input_plugin.get_length = smb_plugin_get_length; + this->input_plugin.get_blocksize = NULL; + this->input_plugin.get_mrl = smb_plugin_get_mrl; + this->input_plugin.get_optional_data = + smb_plugin_get_optional_data; + this->input_plugin.dispose = smb_plugin_dispose; + this->input_plugin.input_class = class_gen; + + return &this->input_plugin; +} + +void smb_auth(const char *srv, const char *shr, char *wg, int wglen, char *un, int unlen, char *pw, int pwlen) +{ + wglen = unlen = pwlen = 0; +} + +static void +*init_input_class (xine_t *xine, void *data) +{ + smb_input_class_t *this; + + if (smbc_init(smb_auth,1)) return NULL; + + this = (smb_input_class_t *) xine_xmalloc(sizeof(smb_input_class_t)); + this->xine = xine; + + this->input_class.get_instance = smb_class_get_instance; + this->input_class.get_identifier = smb_class_get_identifier; + this->input_class.get_description = smb_class_get_description; + this->input_class.get_dir = NULL; + this->input_class.get_autoplay_list = NULL; + this->input_class.dispose = smb_class_dispose; + this->input_class.eject_media = NULL; + + return (input_class_t *) this; +} + +static input_info_t input_info_smb = { + 0 /* priority */ +}; + +plugin_info_t xine_plugin_info[] = { + { PLUGIN_INPUT, 15, "smb", XINE_VERSION_CODE, &input_info_smb, + init_input_class }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; + |