aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-29 00:36:57 +0100
committerMax Kellermann <max@duempel.org>2013-12-29 01:25:27 +0100
commit5465647c2e2ac71b932f1268a83a00b36fdada82 (patch)
tree5328b6079df2b185c7570610a3d7e87b7b2b9747
parenta2baeed3290691ced08cf9668b00865fb757698a (diff)
downloadmpd-5465647c2e2ac71b932f1268a83a00b36fdada82.tar.gz
mpd-5465647c2e2ac71b932f1268a83a00b36fdada82.tar.xz
mpd-5465647c2e2ac71b932f1268a83a00b36fdada82.zip
input/smbclient: new input plugin
Diffstat (limited to '')
-rw-r--r--Makefile.am7
-rw-r--r--NEWS1
-rw-r--r--configure.ac14
-rw-r--r--doc/user.xml14
-rw-r--r--src/InputRegistry.cxx7
-rw-r--r--src/input/SmbclientInputPlugin.cxx203
-rw-r--r--src/input/SmbclientInputPlugin.hxx25
-rw-r--r--src/ls.cxx3
8 files changed, 274 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 72a77eb23..0ba0fc11b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -791,6 +791,7 @@ libinput_a_SOURCES = \
libinput_a_CPPFLAGS = $(AM_CPPFLAGS) \
$(CURL_CFLAGS) \
+ $(SMBCLIENT_CFLAGS) \
$(CDIO_PARANOIA_CFLAGS) \
$(FFMPEG_CFLAGS) \
$(DESPOTIFY_CFLAGS) \
@@ -799,6 +800,7 @@ libinput_a_CPPFLAGS = $(AM_CPPFLAGS) \
INPUT_LIBS = \
libinput.a \
$(CURL_LIBS) \
+ $(SMBCLIENT_LIBS) \
$(CDIO_PARANOIA_LIBS) \
$(FFMPEG_LIBS) \
$(DESPOTIFY_LIBS) \
@@ -818,6 +820,11 @@ libinput_a_SOURCES += \
src/IcyMetaDataParser.cxx src/IcyMetaDataParser.hxx
endif
+if ENABLE_SMBCLIENT
+libinput_a_SOURCES += \
+ src/input/SmbclientInputPlugin.cxx src/input/SmbclientInputPlugin.hxx
+endif
+
if ENABLE_CDIO_PARANOIA
libinput_a_SOURCES += \
src/input/CdioParanoiaInputPlugin.cxx \
diff --git a/NEWS b/NEWS
index bd7ed3e91..aadd8a4fe 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ ver 0.19 (not yet released)
- new commands "addtagid", "cleartagid"
* input
- alsa: new input plugin
+ - smbclient: new input plugin
* filter
- volume: improved software volume dithering
* new resampler option using libsoxr
diff --git a/configure.ac b/configure.ac
index a516e3b0c..ac60e72c8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -300,6 +300,11 @@ AC_ARG_ENABLE(curl,
[enable support for libcurl HTTP streaming (default: auto)]),,
[enable_curl=auto])
+AC_ARG_ENABLE(smbclient,
+ AS_HELP_STRING([--enable-smbclient],
+ [enable support for libsmbclient (default: auto)]),,
+ [enable_smbclient=auto])
+
AC_ARG_ENABLE(debug,
AS_HELP_STRING([--enable-debug],
[enable debugging (default: disabled)]),,
@@ -827,6 +832,14 @@ if test x$enable_curl = xyes; then
fi
AM_CONDITIONAL(ENABLE_CURL, test x$enable_curl = xyes)
+dnl ----------------------------------- smbclient -----------------------------
+MPD_AUTO_PKG(smbclient, SMBCLIENT, [smbclient >= 0.2],
+ [smbclient input plugin], [libsmbclient not found])
+if test x$enable_smbclient = xyes; then
+ AC_DEFINE(ENABLE_SMBCLIENT, 1, [Define when libsmbclient is used])
+fi
+AM_CONDITIONAL(ENABLE_SMBCLIENT, test x$enable_smbclient = xyes)
+
dnl --------------------------------- Despotify ---------------------------------
MPD_AUTO_PKG(despotify, DESPOTIFY, [despotify],
[Despotify support], [despotify not found])
@@ -1708,6 +1721,7 @@ fi
printf '\nStreaming support:\n\t'
results(cdio_paranoia, [CDIO_PARANOIA])
results(curl,[CURL])
+results(smbclient,[SMBCLIENT])
results(despotify,[Despotify])
results(soundcloud,[Soundcloud])
printf '\n\t'
diff --git a/doc/user.xml b/doc/user.xml
index f07aba6c2..733b1bd46 100644
--- a/doc/user.xml
+++ b/doc/user.xml
@@ -1059,6 +1059,20 @@ systemctl start mpd.socket</programlisting>
</tgroup>
</informaltable>
</section>
+
+ <section>
+ <title><varname>smbclient</varname></title>
+
+ <para>
+ Allows MPD to access files on SMB/CIFS servers (e.g. Samba
+ or Microsoft Windows). All URIs with the
+ <filename>smb://</filename> scheme are used. Example:
+ </para>
+
+ <para>
+ <filename>mpc add smb://servername/sharename/filename.ogg</filename>
+ </para>
+ </section>
</section>
<section>
diff --git a/src/InputRegistry.cxx b/src/InputRegistry.cxx
index ef4acb237..6e46d3cd7 100644
--- a/src/InputRegistry.cxx
+++ b/src/InputRegistry.cxx
@@ -38,6 +38,10 @@
#include "input/FfmpegInputPlugin.hxx"
#endif
+#ifdef ENABLE_SMBCLIENT
+#include "input/SmbclientInputPlugin.hxx"
+#endif
+
#ifdef ENABLE_MMS
#include "input/MmsInputPlugin.hxx"
#endif
@@ -64,6 +68,9 @@ const InputPlugin *const input_plugins[] = {
#ifdef HAVE_FFMPEG
&input_plugin_ffmpeg,
#endif
+#ifdef ENABLE_SMBCLIENT
+ &input_plugin_smbclient,
+#endif
#ifdef ENABLE_MMS
&input_plugin_mms,
#endif
diff --git a/src/input/SmbclientInputPlugin.cxx b/src/input/SmbclientInputPlugin.cxx
new file mode 100644
index 000000000..f97aff7d5
--- /dev/null
+++ b/src/input/SmbclientInputPlugin.cxx
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program 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.
+ *
+ * This program 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "SmbclientInputPlugin.hxx"
+#include "InputStream.hxx"
+#include "InputPlugin.hxx"
+#include "util/StringUtil.hxx"
+#include "util/Error.hxx"
+
+#include <libsmbclient.h>
+
+#include <string.h>
+
+class SmbclientInputStream {
+ InputStream base;
+
+ SMBCCTX *ctx;
+ int fd;
+
+public:
+ SmbclientInputStream(const char *uri,
+ Mutex &mutex, Cond &cond,
+ SMBCCTX *_ctx, int _fd, const struct stat &st)
+ :base(input_plugin_smbclient, uri, mutex, cond),
+ ctx(_ctx), fd(_fd) {
+ base.ready = true;
+ base.seekable = true;
+ base.size = st.st_size;
+ }
+
+ ~SmbclientInputStream() {
+ smbc_close(fd);
+ smbc_free_context(ctx, 1);
+ }
+
+ InputStream *GetBase() {
+ return &base;
+ }
+
+ bool IsEOF() const {
+ return base.offset >= base.size;
+ }
+
+ size_t Read(void *ptr, size_t size, Error &error) {
+ ssize_t nbytes = smbc_read(fd, ptr, size);
+ if (nbytes < 0) {
+ error.SetErrno("smbc_read() failed");
+ nbytes = 0;
+ }
+
+ return nbytes;
+ }
+
+ bool Seek(InputStream::offset_type offset, int whence, Error &error) {
+ off_t result = smbc_lseek(fd, offset, whence);
+ if (result < 0) {
+ error.SetErrno("smbc_lseek() failed");
+ return false;
+ }
+
+ base.offset = result;
+ return true;
+ }
+};
+
+static void
+mpd_smbc_get_auth_data(gcc_unused const char *srv,
+ gcc_unused const char *shr,
+ char *wg, gcc_unused int wglen,
+ char *un, gcc_unused int unlen,
+ char *pw, gcc_unused int pwlen)
+{
+ // TODO: implement
+ strcpy(wg, "WORKGROUP");
+ strcpy(un, "foo");
+ strcpy(pw, "bar");
+}
+
+/*
+ * InputPlugin methods
+ *
+ */
+
+static bool
+input_smbclient_init(gcc_unused const config_param &param, Error &error)
+{
+ constexpr int debug = 0;
+ if (smbc_init(mpd_smbc_get_auth_data, debug) < 0) {
+ error.SetErrno("smbc_init() failed");
+ return false;
+ }
+
+ // TODO: create one global SMBCCTX here?
+
+ // TODO: evaluate config_param, call smbc_setOption*()
+
+ return true;
+}
+
+static InputStream *
+input_smbclient_open(const char *uri,
+ Mutex &mutex, Cond &cond,
+ Error &error)
+{
+ if (!StringStartsWith(uri, "smb://"))
+ return nullptr;
+
+ SMBCCTX *ctx = smbc_new_context();
+ if (ctx == nullptr) {
+ error.SetErrno("smbc_new_context() failed");
+ return nullptr;
+ }
+
+ SMBCCTX *ctx2 = smbc_init_context(ctx);
+ if (ctx2 == nullptr) {
+ error.SetErrno("smbc_init_context() failed");
+ smbc_free_context(ctx, 1);
+ return nullptr;
+ }
+
+ ctx = ctx2;
+
+ int fd = smbc_open(uri, O_RDONLY, 0);
+ if (fd < 0) {
+ error.SetErrno("smbc_open() failed");
+ smbc_free_context(ctx, 1);
+ return nullptr;
+ }
+
+ struct stat st;
+ if (smbc_fstat(fd, &st) < 0) {
+ error.SetErrno("smbc_fstat() failed");
+ smbc_close(fd);
+ smbc_free_context(ctx, 1);
+ return nullptr;
+ }
+
+ auto s = new SmbclientInputStream(uri, mutex, cond, ctx, fd, st);
+ return s->GetBase();
+}
+
+static size_t
+input_smbclient_read(InputStream *is, void *ptr, size_t size,
+ Error &error)
+{
+ SmbclientInputStream &s = *(SmbclientInputStream *)is;
+ return s.Read(ptr, size, error);
+}
+
+static void
+input_smbclient_close(InputStream *is)
+{
+ SmbclientInputStream *s = (SmbclientInputStream *)is;
+ delete s;
+}
+
+static bool
+input_smbclient_eof(InputStream *is)
+{
+ SmbclientInputStream &s = *(SmbclientInputStream *)is;
+ return s.IsEOF();
+}
+
+static bool
+input_smbclient_seek(InputStream *is,
+ InputPlugin::offset_type offset, int whence,
+ Error &error)
+{
+ SmbclientInputStream &s = *(SmbclientInputStream *)is;
+ return s.Seek(offset, whence, error);
+}
+
+const InputPlugin input_plugin_smbclient = {
+ "smbclient",
+ input_smbclient_init,
+ nullptr,
+ input_smbclient_open,
+ input_smbclient_close,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ input_smbclient_read,
+ input_smbclient_eof,
+ input_smbclient_seek,
+};
diff --git a/src/input/SmbclientInputPlugin.hxx b/src/input/SmbclientInputPlugin.hxx
new file mode 100644
index 000000000..7203a01b8
--- /dev/null
+++ b/src/input/SmbclientInputPlugin.hxx
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program 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.
+ *
+ * This program 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_INPUT_SMBCLIENT_H
+#define MPD_INPUT_SMBCLIENT_H
+
+extern const struct InputPlugin input_plugin_smbclient;
+
+#endif
diff --git a/src/ls.cxx b/src/ls.cxx
index 8039cf1d8..1de515a1f 100644
--- a/src/ls.cxx
+++ b/src/ls.cxx
@@ -49,6 +49,9 @@ static const char *remoteUrlPrefixes[] = {
"rtmpt://",
"rtmps://",
#endif
+#ifdef ENABLE_SMBCLIENT
+ "smb://",
+#endif
#ifdef ENABLE_CDIO_PARANOIA
"cdda://",
#endif