aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/db/upnp/Device.cxx21
-rw-r--r--src/db/upnp/Device.hxx15
-rw-r--r--src/db/upnp/Discovery.cxx18
-rw-r--r--src/db/upnp/Discovery.hxx16
4 files changed, 39 insertions, 31 deletions
diff --git a/src/db/upnp/Device.cxx b/src/db/upnp/Device.cxx
index b5174236b..413d6ac99 100644
--- a/src/db/upnp/Device.cxx
+++ b/src/db/upnp/Device.cxx
@@ -21,7 +21,6 @@
#include "Device.hxx"
#include "Util.hxx"
#include "Expat.hxx"
-#include "Log.hxx"
#include "util/Error.hxx"
#include <stdlib.h>
@@ -99,16 +98,15 @@ protected:
}
};
-UPnPDevice::UPnPDevice(const std::string &url, const char *description)
- :ok(false)
+bool
+UPnPDevice::Parse(const std::string &url, const char *description,
+ Error &error)
{
- UPnPDeviceParser mparser(*this);
- Error error;
- if (!mparser.Parse(description, strlen(description), true,
- error)) {
- // TODO: pass Error to caller
- LogError(error);
- return;
+ {
+ UPnPDeviceParser mparser(*this);
+ if (!mparser.Parse(description, strlen(description),
+ true, error))
+ return false;
}
if (URLBase.empty()) {
@@ -129,5 +127,6 @@ UPnPDevice::UPnPDevice(const std::string &url, const char *description)
}
}
}
- ok = true;
+
+ return true;
}
diff --git a/src/db/upnp/Device.hxx b/src/db/upnp/Device.hxx
index 78be01bd5..d03ad24f6 100644
--- a/src/db/upnp/Device.hxx
+++ b/src/db/upnp/Device.hxx
@@ -61,7 +61,6 @@ struct UPnPService {
*/
class UPnPDevice {
public:
- bool ok;
// e.g. urn:schemas-upnp-org:device:MediaServer:1
std::string deviceType;
// e.g. MediaTomb
@@ -78,17 +77,17 @@ public:
// Services provided by this device.
std::vector<UPnPService> services;
+ UPnPDevice() = default;
+ UPnPDevice(const UPnPDevice &) = delete;
+ UPnPDevice(UPnPDevice &&) = default;
+ UPnPDevice &operator=(UPnPDevice &&) = default;
+
/** Build device from xml description downloaded from discovery
* @param url where the description came from
* @param description the xml device description
*/
- UPnPDevice(const std::string &url, const char *description);
-
- UPnPDevice() : ok(false) {}
-
- UPnPDevice(const UPnPDevice &) = delete;
- UPnPDevice(UPnPDevice &&) = default;
- UPnPDevice &operator=(UPnPDevice &&) = default;
+ bool Parse(const std::string &url, const char *description,
+ Error &error);
};
#endif /* _UPNPDEV_HXX_INCLUDED_ */
diff --git a/src/db/upnp/Discovery.cxx b/src/db/upnp/Discovery.cxx
index b5c6b5f92..5e6479b3d 100644
--- a/src/db/upnp/Discovery.cxx
+++ b/src/db/upnp/Discovery.cxx
@@ -22,6 +22,7 @@
#include "Domain.hxx"
#include "ContentDirectoryService.hxx"
#include "upnpplib.hxx"
+#include "Log.hxx"
#include <upnp/upnptools.h>
@@ -73,12 +74,17 @@ UPnPDeviceDirectory::discoExplorer()
}
// Update or insert the device
- ContentDirectoryDescriptor d(tsk->url, buf,
- time(0), tsk->expires);
- free(buf);
- if (!d.device.ok) {
- delete tsk;
- continue;
+ ContentDirectoryDescriptor d(time(0), tsk->expires);
+
+ {
+ Error error2;
+ bool success = d.Parse(tsk->url, buf, error2);
+ free(buf);
+ if (!success) {
+ delete tsk;
+ LogError(error2);
+ continue;
+ }
}
const ScopeLock protect(mutex);
diff --git a/src/db/upnp/Discovery.hxx b/src/db/upnp/Discovery.hxx
index 1f24135b2..edda3a8de 100644
--- a/src/db/upnp/Discovery.hxx
+++ b/src/db/upnp/Discovery.hxx
@@ -65,15 +65,19 @@ class UPnPDeviceDirectory {
*/
class ContentDirectoryDescriptor {
public:
- ContentDirectoryDescriptor() = default;
-
- ContentDirectoryDescriptor(const std::string &url,
- const char *description,
- time_t last, int exp)
- :device(url, description), last_seen(last), expires(exp+20) {}
UPnPDevice device;
time_t last_seen;
int expires; // seconds valid
+
+ ContentDirectoryDescriptor() = default;
+
+ ContentDirectoryDescriptor(time_t last, int exp)
+ :last_seen(last), expires(exp+20) {}
+
+ bool Parse(const std::string &url, const char *description,
+ Error &_error) {
+ return device.Parse(url, description, _error);
+ }
};
LibUPnP *const lib;