Skip to content

Commit

Permalink
CHG: Allow to (really) disable upnp altogether
Browse files Browse the repository at this point in the history
  • Loading branch information
koying committed Jan 20, 2017
1 parent 4fc0d84 commit e575792
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 16 deletions.
7 changes: 6 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -12130,7 +12130,12 @@ msgctxt "#21342"
msgid "There are currently no updates available for this add-on."
msgstr ""

#empty strings from id 21343 to 21358
#empty strings from id 21343 to 21357

#: system/settings/settings.xml
msgctxt "#21358"
msgid "Enable UPnP support"
msgstr ""

#: xbmc/dialogs/GUIDialogFileBrowser.cpp
msgctxt "#21359"
Expand Down
34 changes: 30 additions & 4 deletions system/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2127,38 +2127,64 @@
<category id="upnp" label="20187" help="36322">
<requirement>HAS_UPNP</requirement>
<group id="1">
<setting id="services.upnpserver" type="boolean" label="21360" help="36323">
<setting id="services.upnp" type="boolean" label="1270">
<level>0</level>
<default>false</default>
<control type="toggle" />
</setting>
<setting id="services.upnpserver" type="boolean" label="21358" help="36323">
<level>1</level>
<default>false</default>
<dependencies>
<dependency type="enable" setting="services.upnp">true</dependency>
</dependencies>
<control type="toggle" />
</setting>
<setting id="services.upnpannounce" type="boolean" parent="services.upnpserver" label="20188" help="36324">
<level>2</level>
<default>true</default>
<dependencies>
<dependency type="enable" setting="services.upnpserver">true</dependency>
<dependency type="enable">
<and>
<condition setting="services.upnp" operator="is">true</condition>
<condition setting="services.upnpserver" operator="is">true</condition>
</and>
</dependency>
</dependencies>
<control type="toggle" />
</setting>
<setting id="services.upnplookforexternalsubtitles" type="boolean" parent="services.upnpserver" label="20222" help="36420">
<level>2</level>
<default>false</default>
<dependencies>
<dependency type="enable" setting="services.upnpserver">true</dependency>
<dependency type="enable">
<and>
<condition setting="services.upnp" operator="is">true</condition>
<condition setting="services.upnpserver" operator="is">true</condition>
</and>
</dependency>
</dependencies>
<control type="toggle" />
</setting>
<setting id="services.upnpcontroller" type="boolean" parent="services.upnpserver" label="21361" help="36326">
<level>1</level>
<default>false</default>
<dependencies>
<dependency type="enable" setting="services.upnpserver">true</dependency>
<dependency type="enable">
<and>
<condition setting="services.upnp" operator="is">true</condition>
<condition setting="services.upnpserver" operator="is">true</condition>
</and>
</dependency>
</dependencies>
<control type="toggle" />
</setting>
<setting id="services.upnprenderer" type="boolean" label="21881" help="36325">
<level>1</level>
<default>false</default>
<dependencies>
<dependency type="enable" setting="services.upnp">true</dependency>
</dependencies>
<control type="toggle" />
</setting>
</group>
Expand Down
2 changes: 1 addition & 1 deletion xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4625,7 +4625,7 @@ void CApplication::ProcessSlow()

// update upnp server/renderer states
#ifdef HAS_UPNP
if(UPNP::CUPnP::IsInstantiated())
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNP) && UPNP::CUPnP::IsInstantiated())
UPNP::CUPnP::GetInstance()->UpdateState();
#endif

Expand Down
7 changes: 7 additions & 0 deletions xbmc/filesystem/UPnPDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "utils/log.h"
#include "utils/URIUtils.h"
#include "utils/StringUtils.h"
#include "settings/Settings.h"

using namespace MUSIC_INFO;
using namespace XFILE;
Expand Down Expand Up @@ -142,6 +143,9 @@ CUPnPDirectory::GetFriendlyName(const CURL& url)
+---------------------------------------------------------------------*/
bool CUPnPDirectory::GetResource(const CURL& path, CFileItem &item)
{
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNP))
return false;

if(!path.IsProtocol("upnp"))
return false;

Expand Down Expand Up @@ -185,6 +189,9 @@ bool CUPnPDirectory::GetResource(const CURL& path, CFileItem &item)
bool
CUPnPDirectory::GetDirectory(const CURL& url, CFileItemList &items)
{
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNP))
return false;

CUPnP* upnp = CUPnP::GetInstance();

/* upnp should never be cached, it has internal cache */
Expand Down
34 changes: 29 additions & 5 deletions xbmc/network/NetworkServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,24 @@ bool CNetworkServices::OnSettingChanging(const CSetting *setting)
#endif //HAS_AIRPLAY

#ifdef HAS_UPNP
if (settingId == CSettings::SETTING_SERVICES_UPNPSERVER)
if (settingId == CSettings::SETTING_SERVICES_UPNP)
{
if (((CSettingBool*)setting)->GetValue())
{
StartUPnPClient();
StartUPnPController();
StartUPnPServer();
StartUPnPRenderer();
}
else
{
StopUPnPRenderer();
StopUPnPServer();
StopUPnPController();
StopUPnPClient();
}
}
else if (settingId == CSettings::SETTING_SERVICES_UPNPSERVER)
{
if (((CSettingBool*)setting)->GetValue())
{
Expand Down Expand Up @@ -473,7 +490,8 @@ void CNetworkServices::Start()
if (CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_WEBSERVER) && !StartWebserver())
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, g_localizeStrings.Get(33101), g_localizeStrings.Get(33100));
#endif // HAS_WEB_SERVER
StartUPnP();
if (CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNP))
StartUPnP();
if (CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_ESENABLED) && !StartEventServer())
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, g_localizeStrings.Get(33102), g_localizeStrings.Get(33100));
if (CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_ESENABLED) && !StartJSONRPCServer())
Expand Down Expand Up @@ -843,6 +861,9 @@ bool CNetworkServices::StopUPnP(bool bWait)
bool CNetworkServices::StartUPnPClient()
{
#ifdef HAS_UPNP
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNP))
return false;

CLog::Log(LOGNOTICE, "starting upnp client");
CUPnP::GetInstance()->StartClient();
return IsUPnPClientRunning();
Expand Down Expand Up @@ -876,7 +897,8 @@ bool CNetworkServices::StartUPnPController()
{
#ifdef HAS_UPNP
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNPCONTROLLER) ||
!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNPSERVER))
!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNPSERVER) ||
!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNP))
return false;

CLog::Log(LOGNOTICE, "starting upnp controller");
Expand Down Expand Up @@ -911,7 +933,8 @@ bool CNetworkServices::StopUPnPController()
bool CNetworkServices::StartUPnPRenderer()
{
#ifdef HAS_UPNP
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNPRENDERER))
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNPRENDERER) ||
!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNP))
return false;

CLog::Log(LOGNOTICE, "starting upnp renderer");
Expand Down Expand Up @@ -945,7 +968,8 @@ bool CNetworkServices::StopUPnPRenderer()
bool CNetworkServices::StartUPnPServer()
{
#ifdef HAS_UPNP
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNPSERVER))
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNPSERVER) ||
!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNP))
return false;

CLog::Log(LOGNOTICE, "starting upnp server");
Expand Down
2 changes: 2 additions & 0 deletions xbmc/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ const std::string CSettings::SETTING_WEATHER_CURRENTLOCATION = "weather.currentl
const std::string CSettings::SETTING_WEATHER_ADDON = "weather.addon";
const std::string CSettings::SETTING_WEATHER_ADDONSETTINGS = "weather.addonsettings";
const std::string CSettings::SETTING_SERVICES_DEVICENAME = "services.devicename";
const std::string CSettings::SETTING_SERVICES_UPNP = "services.upnp";
const std::string CSettings::SETTING_SERVICES_UPNPSERVER = "services.upnpserver";
const std::string CSettings::SETTING_SERVICES_UPNPANNOUNCE = "services.upnpannounce";
const std::string CSettings::SETTING_SERVICES_UPNPLOOKFOREXTERNALSUBTITLES = "services.upnplookforexternalsubtitles";
Expand Down Expand Up @@ -1209,6 +1210,7 @@ void CSettings::InitializeISettingCallbacks()
settingSet.insert(CSettings::SETTING_SERVICES_AIRPLAYVIDEOSUPPORT);
settingSet.insert(CSettings::SETTING_SERVICES_USEAIRPLAYPASSWORD);
settingSet.insert(CSettings::SETTING_SERVICES_AIRPLAYPASSWORD);
settingSet.insert(CSettings::SETTING_SERVICES_UPNP);
settingSet.insert(CSettings::SETTING_SERVICES_UPNPSERVER);
settingSet.insert(CSettings::SETTING_SERVICES_UPNPRENDERER);
settingSet.insert(CSettings::SETTING_SERVICES_UPNPCONTROLLER);
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class CSettings : public CSettingCreator, public CSettingControlCreator
static const std::string SETTING_WEATHER_ADDON;
static const std::string SETTING_WEATHER_ADDONSETTINGS;
static const std::string SETTING_SERVICES_DEVICENAME;
static const std::string SETTING_SERVICES_UPNP;
static const std::string SETTING_SERVICES_UPNPSERVER;
static const std::string SETTING_SERVICES_UPNPANNOUNCE;
static const std::string SETTING_SERVICES_UPNPLOOKFOREXTERNALSUBTITLES;
Expand Down
13 changes: 8 additions & 5 deletions xbmc/storage/MediaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,15 @@ void CMediaManager::GetNetworkLocations(VECSOURCES &locations, bool autolocation
#endif// HAS_FILESYSTEM_NFS

#ifdef HAS_UPNP
std::string strDevices = g_localizeStrings.Get(33040); //"% Devices"
share.strPath = "upnp://";
share.strName = StringUtils::Format(strDevices.c_str(), "UPnP"); //"UPnP Devices"
locations.push_back(share);
if (!CSettings::GetInstance().GetBool(CSettings::SETTING_SERVICES_UPNP))
{
std::string strDevices = g_localizeStrings.Get(33040); //"% Devices"
share.strPath = "upnp://";
share.strName = StringUtils::Format(strDevices.c_str(), "UPnP"); //"UPnP Devices"
locations.push_back(share);
}
#endif

#ifdef HAS_ZEROCONF
share.strPath = "zeroconf://";
share.strName = g_localizeStrings.Get(20262);
Expand Down

0 comments on commit e575792

Please sign in to comment.