summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-11-25 19:46:07 +0100
committerMax Kellermann <max@musicpd.org>2017-11-25 19:47:56 +0100
commit2b3c1d640ea7f677c9bae4393247e58f907aace5 (patch)
tree236a9459816f6add345d9a790f15052e2f617f09 /src
parentf70b4e02c41732f8e6d78488bdb1eb6b325efa17 (diff)
parent323231d1ddd12e97b46c43536661a539b7bc3fbe (diff)
Merge tag 'v0.20.12'
release v0.20.12
Diffstat (limited to 'src')
-rw-r--r--src/lib/upnp/Callback.hxx2
-rw-r--r--src/lib/upnp/ClientInit.cxx7
-rw-r--r--src/lib/upnp/Compat.hxx69
-rw-r--r--src/lib/upnp/Discovery.cxx27
-rw-r--r--src/lib/upnp/Discovery.hxx13
5 files changed, 99 insertions, 19 deletions
diff --git a/src/lib/upnp/Callback.hxx b/src/lib/upnp/Callback.hxx
index f232a6cd2..544bd9d41 100644
--- a/src/lib/upnp/Callback.hxx
+++ b/src/lib/upnp/Callback.hxx
@@ -40,7 +40,7 @@ public:
return *(UpnpCallback *)cookie;
}
- virtual int Invoke(Upnp_EventType et, void *evp) noexcept = 0;
+ virtual int Invoke(Upnp_EventType et, const void *evp) noexcept = 0;
};
#endif
diff --git a/src/lib/upnp/ClientInit.cxx b/src/lib/upnp/ClientInit.cxx
index b320beb79..b2f6b3348 100644
--- a/src/lib/upnp/ClientInit.cxx
+++ b/src/lib/upnp/ClientInit.cxx
@@ -33,7 +33,12 @@ static unsigned upnp_client_ref;
static UpnpClient_Handle upnp_client_handle;
static int
-UpnpClientCallback(Upnp_EventType et, void *evp, void *cookie) noexcept
+UpnpClientCallback(Upnp_EventType et,
+#if UPNP_VERSION >= 10800
+ const
+#endif
+ void *evp,
+ void *cookie) noexcept
{
if (cookie == nullptr)
/* this is the cookie passed to UpnpRegisterClient();
diff --git a/src/lib/upnp/Compat.hxx b/src/lib/upnp/Compat.hxx
new file mode 100644
index 000000000..2e2d2f1de
--- /dev/null
+++ b/src/lib/upnp/Compat.hxx
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2003-2017 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_UPNP_COMPAT_HXX
+#define MPD_UPNP_COMPAT_HXX
+
+#include <upnp/upnp.h>
+
+#if UPNP_VERSION < 10800
+#include "Compiler.h"
+
+/* emulate the libupnp 1.8 API with older versions */
+
+using UpnpDiscovery = Upnp_Discovery;
+
+gcc_pure
+static inline int
+UpnpDiscovery_get_Expires(const UpnpDiscovery *disco) noexcept
+{
+ return disco->Expires;
+}
+
+gcc_pure
+static inline const char *
+UpnpDiscovery_get_DeviceID_cstr(const UpnpDiscovery *disco) noexcept
+{
+ return disco->DeviceId;
+}
+
+gcc_pure
+static inline const char *
+UpnpDiscovery_get_DeviceType_cstr(const UpnpDiscovery *disco) noexcept
+{
+ return disco->DeviceType;
+}
+
+gcc_pure
+static inline const char *
+UpnpDiscovery_get_ServiceType_cstr(const UpnpDiscovery *disco) noexcept
+{
+ return disco->ServiceType;
+}
+
+gcc_pure
+static inline const char *
+UpnpDiscovery_get_Location_cstr(const UpnpDiscovery *disco) noexcept
+{
+ return disco->Location;
+}
+
+#endif
+
+#endif
diff --git a/src/lib/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx
index 33218ba79..27dedac62 100644
--- a/src/lib/upnp/Discovery.cxx
+++ b/src/lib/upnp/Discovery.cxx
@@ -33,12 +33,13 @@
#include <string.h>
UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent,
- const Upnp_Discovery &disco)
+ const UpnpDiscovery &disco)
:defer_start_event(_parent.GetEventLoop(),
BIND_THIS_METHOD(OnDeferredStart)),
parent(_parent),
- id(disco.DeviceId), url(disco.Location),
- expires(std::chrono::seconds(disco.Expires)),
+ id(UpnpDiscovery_get_DeviceID_cstr(&disco)),
+ url(UpnpDiscovery_get_Location_cstr(&disco)),
+ expires(std::chrono::seconds(UpnpDiscovery_get_Expires(&disco))),
request(*parent.curl, url.c_str(), *this)
{
parent.downloaders.push_back(*this);
@@ -170,10 +171,10 @@ UPnPDeviceDirectory::LockRemove(const std::string &id)
}
inline int
-UPnPDeviceDirectory::OnAlive(Upnp_Discovery *disco) noexcept
+UPnPDeviceDirectory::OnAlive(const UpnpDiscovery *disco) noexcept
{
- if (isMSDevice(disco->DeviceType) ||
- isCDService(disco->ServiceType)) {
+ if (isMSDevice(UpnpDiscovery_get_DeviceType_cstr(disco)) ||
+ isCDService(UpnpDiscovery_get_ServiceType_cstr(disco))) {
try {
auto *downloader = new Downloader(*this, *disco);
@@ -196,12 +197,12 @@ UPnPDeviceDirectory::OnAlive(Upnp_Discovery *disco) noexcept
}
inline int
-UPnPDeviceDirectory::OnByeBye(Upnp_Discovery *disco) noexcept
+UPnPDeviceDirectory::OnByeBye(const UpnpDiscovery *disco) noexcept
{
- if (isMSDevice(disco->DeviceType) ||
- isCDService(disco->ServiceType)) {
+ if (isMSDevice(UpnpDiscovery_get_DeviceType_cstr(disco)) ||
+ isCDService(UpnpDiscovery_get_ServiceType_cstr(disco))) {
// Device signals it is going off.
- LockRemove(disco->DeviceId);
+ LockRemove(UpnpDiscovery_get_DeviceID_cstr(disco));
}
return UPNP_E_SUCCESS;
@@ -212,19 +213,19 @@ UPnPDeviceDirectory::OnByeBye(Upnp_Discovery *disco) noexcept
// Example: ContentDirectories appearing and disappearing from the network
// We queue a task for our worker thread(s)
int
-UPnPDeviceDirectory::Invoke(Upnp_EventType et, void *evp) noexcept
+UPnPDeviceDirectory::Invoke(Upnp_EventType et, const void *evp) noexcept
{
switch (et) {
case UPNP_DISCOVERY_SEARCH_RESULT:
case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:
{
- Upnp_Discovery *disco = (Upnp_Discovery *)evp;
+ auto *disco = (const UpnpDiscovery *)evp;
return OnAlive(disco);
}
case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE:
{
- Upnp_Discovery *disco = (Upnp_Discovery *)evp;
+ auto *disco = (const UpnpDiscovery *)evp;
return OnByeBye(disco);
}
diff --git a/src/lib/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx
index a0a79157f..eb6297a73 100644
--- a/src/lib/upnp/Discovery.hxx
+++ b/src/lib/upnp/Discovery.hxx
@@ -20,6 +20,7 @@
#ifndef _UPNPPDISC_H_X_INCLUDED_
#define _UPNPPDISC_H_X_INCLUDED_
+#include "Compat.hxx"
#include "Callback.hxx"
#include "Device.hxx"
#include "lib/curl/Init.hxx"
@@ -39,6 +40,10 @@
#include <memory>
#include <chrono>
+#if UPNP_VERSION < 10800
+#define UpnpDiscovery Upnp_Discovery
+#endif
+
class ContentDirectoryService;
class UPnPDiscoveryListener {
@@ -100,7 +105,7 @@ class UPnPDeviceDirectory final : UpnpCallback {
public:
Downloader(UPnPDeviceDirectory &_parent,
- const Upnp_Discovery &disco);
+ const UpnpDiscovery &disco);
void Start() noexcept {
defer_start_event.Schedule();
@@ -184,11 +189,11 @@ private:
void LockAdd(ContentDirectoryDescriptor &&d);
void LockRemove(const std::string &id);
- int OnAlive(Upnp_Discovery *disco) noexcept;
- int OnByeBye(Upnp_Discovery *disco) noexcept;
+ int OnAlive(const UpnpDiscovery *disco) noexcept;
+ int OnByeBye(const UpnpDiscovery *disco) noexcept;
/* virtual methods from class UpnpCallback */
- int Invoke(Upnp_EventType et, void *evp) noexcept override;
+ int Invoke(Upnp_EventType et, const void *evp) noexcept override;
};