From e4a18332a01ed6d6d93ecae93561d22fae9df3ef Mon Sep 17 00:00:00 2001 From: Jonas Wielicki Date: Sun, 15 Oct 2017 13:57:30 +0200 Subject: [PATCH] http: make HTTP server support configurable This allows to configure the local files streaming option per-connection. It defaults to enabled. --- gui/serversettings.cpp | 12 ++++++++++++ gui/serversettings.ui | 10 ++++++++++ gui/settings.cpp | 5 +++++ http/httpserver.cpp | 6 ++++++ http/httpserver.h | 2 +- mpd-interface/mpdconnection.h | 1 + 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/gui/serversettings.cpp b/gui/serversettings.cpp index 6270bf94f..5a81797f2 100644 --- a/gui/serversettings.cpp +++ b/gui/serversettings.cpp @@ -116,6 +116,9 @@ ServerSettings::ServerSettings(QWidget *p) REMOVE(streamUrl) REMOVE(streamUrlNoteLabel) #endif + #ifndef ENABLE_HTTP_SERVER + REMOVE(allowLocalStreaming); + #endif #ifdef Q_OS_MAC expandingSpacer->changeSize(0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed); @@ -178,6 +181,7 @@ void ServerSettings::save() #ifdef ENABLE_HTTP_STREAM_PLAYBACK || c.details.streamUrl!=e.streamUrl #endif + || c.details.allowLocalStreaming!=e.allowLocalStreaming ) { toAdd.append(c); } @@ -279,6 +283,8 @@ void ServerSettings::add() details.port=6600; details.hostname=QLatin1String("localhost"); details.dir=QLatin1String("/var/lib/mpd/music/"); + // disable local streaming by default + details.allowLocalStreaming=false; combo->addItem(details.name); #ifdef ENABLE_SIMPLE_MPD_SUPPORT } else { @@ -375,6 +381,9 @@ void ServerSettings::setDetails(const MPDConnectionDetails &details) #ifdef ENABLE_HTTP_STREAM_PLAYBACK streamUrl->setText(details.streamUrl); #endif + #ifdef ENABLE_HTTP_SERVER + allowLocalStreaming->setChecked(details.allowLocalStreaming); + #endif stackedWidget->setCurrentIndex(0); #ifdef ENABLE_SIMPLE_MPD_SUPPORT } @@ -399,6 +408,9 @@ MPDConnectionDetails ServerSettings::getDetails() const #ifdef ENABLE_HTTP_STREAM_PLAYBACK details.streamUrl=streamUrl->text().trimmed(); #endif + #ifdef ENABLE_HTTP_SERVER + details.allowLocalStreaming=allowLocalStreaming->checkState() == Qt::Checked; + #endif } #ifdef ENABLE_SIMPLE_MPD_SUPPORT else { diff --git a/gui/serversettings.ui b/gui/serversettings.ui index f756b9bf0..fdb718d4f 100644 --- a/gui/serversettings.ui +++ b/gui/serversettings.ui @@ -163,6 +163,16 @@ + + + + If enabled, you can drag local files into the play queue. For this to work, MPD gets access to those (and only those) local files via HTTP. + + + Allow access to local files + + + diff --git a/gui/settings.cpp b/gui/settings.cpp index 76b65f8ad..154173d61 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -171,6 +171,9 @@ MPDConnectionDetails Settings::connectionDetails(const QString &name) details.streamUrl=grp.get("streamUrl", QString()); #endif details.replayGain=grp.get("replayGain", QString()); + // if the setting hasn't been set before, we set it to true to allow + // for easy migration of existing settings + details.allowLocalStreaming=grp.get("allowLocalStreaming", true); } else { details.hostname=mpdDefaults.host; details.port=mpdDefaults.port; @@ -180,6 +183,7 @@ MPDConnectionDetails Settings::connectionDetails(const QString &name) #ifdef ENABLE_HTTP_STREAM_PLAYBACK details.streamUrl=QString(); #endif + details.allowLocalStreaming=true; } details.setDirReadable(); return details; @@ -695,6 +699,7 @@ void Settings::saveConnectionDetails(const MPDConnectionDetails &v) #ifdef ENABLE_HTTP_STREAM_PLAYBACK grp.set("streamUrl", v.streamUrl); #endif + grp.set("allowLocalStreaming", v.allowLocalStreaming); } void Settings::saveCurrentConnection(const QString &v) diff --git a/http/httpserver.cpp b/http/httpserver.cpp index 5c7d4b2db..b3381d3bc 100644 --- a/http/httpserver.cpp +++ b/http/httpserver.cpp @@ -71,6 +71,12 @@ HttpServer::HttpServer() connect(MPDConnection::self(), SIGNAL(ifaceIp(QString)), this, SLOT(ifaceIp(QString))); } +bool HttpServer::isAlive() const +{ + // started on demand, but only start if allowed + return Settings::self()->connectionDetails().allowLocalStreaming; +} + bool HttpServer::start() { if (closeTimer) { diff --git a/http/httpserver.h b/http/httpserver.h index 60224d266..e4d9ee3ca 100644 --- a/http/httpserver.h +++ b/http/httpserver.h @@ -51,7 +51,7 @@ public: #ifdef ENABLE_HTTP_SERVER HttpServer(); - bool isAlive() const { return true; } // Started on-demamnd! + bool isAlive() const; // Started on-demamnd! void readConfig(); QString address() const; bool isOurs(const QString &url) const; diff --git a/mpd-interface/mpdconnection.h b/mpd-interface/mpdconnection.h index ef66ca952..6998431b7 100644 --- a/mpd-interface/mpdconnection.h +++ b/mpd-interface/mpdconnection.h @@ -162,6 +162,7 @@ struct MPDConnectionDetails { QString streamUrl; #endif QString replayGain; + bool allowLocalStreaming; }; class MPDConnection : public QObject