From f86f5ad2240c49f35c4948bed09027d9f5530d0b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 26 Jan 2014 11:51:56 +0100 Subject: [PATCH] db/upnp: move generic code to lib/upnp/ --- Makefile.am | 22 +++-- src/db/plugins/UpnpDatabasePlugin.cxx | 10 +- .../plugins/upnp/ContentDirectoryService.cxx | 77 +-------------- src/db/plugins/upnp/Directory.cxx | 2 +- src/{db/plugins => lib}/upnp/Action.hxx | 0 src/lib/upnp/ContentDirectoryService.cxx | 93 +++++++++++++++++++ .../upnp/ContentDirectoryService.hxx | 2 + src/{db/plugins => lib}/upnp/Device.cxx | 0 src/{db/plugins => lib}/upnp/Device.hxx | 0 src/{db/plugins => lib}/upnp/Discovery.cxx | 0 src/{db/plugins => lib}/upnp/Discovery.hxx | 0 src/{db/plugins => lib}/upnp/Domain.cxx | 0 src/{db/plugins => lib}/upnp/Domain.hxx | 0 src/{db/plugins => lib}/upnp/Util.cxx | 0 src/{db/plugins => lib}/upnp/Util.hxx | 0 src/{db/plugins => lib}/upnp/WorkQueue.hxx | 0 src/{db/plugins => lib}/upnp/ixmlwrap.cxx | 0 src/{db/plugins => lib}/upnp/ixmlwrap.hxx | 0 src/{db/plugins => lib}/upnp/upnpplib.cxx | 0 src/{db/plugins => lib}/upnp/upnpplib.hxx | 0 20 files changed, 118 insertions(+), 88 deletions(-) rename src/{db/plugins => lib}/upnp/Action.hxx (100%) create mode 100644 src/lib/upnp/ContentDirectoryService.cxx rename src/{db/plugins => lib}/upnp/ContentDirectoryService.hxx (99%) rename src/{db/plugins => lib}/upnp/Device.cxx (100%) rename src/{db/plugins => lib}/upnp/Device.hxx (100%) rename src/{db/plugins => lib}/upnp/Discovery.cxx (100%) rename src/{db/plugins => lib}/upnp/Discovery.hxx (100%) rename src/{db/plugins => lib}/upnp/Domain.cxx (100%) rename src/{db/plugins => lib}/upnp/Domain.hxx (100%) rename src/{db/plugins => lib}/upnp/Util.cxx (100%) rename src/{db/plugins => lib}/upnp/Util.hxx (100%) rename src/{db/plugins => lib}/upnp/WorkQueue.hxx (100%) rename src/{db/plugins => lib}/upnp/ixmlwrap.cxx (100%) rename src/{db/plugins => lib}/upnp/ixmlwrap.hxx (100%) rename src/{db/plugins => lib}/upnp/upnpplib.cxx (100%) rename src/{db/plugins => lib}/upnp/upnpplib.hxx (100%) diff --git a/Makefile.am b/Makefile.am index f0b97f429..c9b0e05ba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -216,6 +216,17 @@ src_mpd_SOURCES = \ src/PlaylistFile.cxx src/PlaylistFile.hxx \ src/Timer.cxx +UPNP_SOURCES = \ + src/lib/upnp/Device.cxx src/lib/upnp/Device.hxx \ + src/lib/upnp/ContentDirectoryService.cxx src/lib/upnp/ContentDirectoryService.hxx \ + src/lib/upnp/Discovery.cxx src/lib/upnp/Discovery.hxx \ + src/lib/upnp/Domain.cxx src/lib/upnp/Domain.hxx \ + src/lib/upnp/ixmlwrap.cxx src/lib/upnp/ixmlwrap.hxx \ + src/lib/upnp/upnpplib.cxx src/lib/upnp/upnpplib.hxx \ + src/lib/upnp/Util.cxx src/lib/upnp/Util.hxx \ + src/lib/upnp/WorkQueue.hxx \ + src/lib/upnp/Action.hxx + # # Windows resource file # @@ -444,18 +455,11 @@ DB_LIBS = \ if HAVE_LIBUPNP libdb_plugins_a_SOURCES += \ + $(UPNP_SOURCES) \ src/db/plugins/UpnpDatabasePlugin.cxx src/db/plugins/UpnpDatabasePlugin.hxx \ src/db/plugins/upnp/Tags.cxx src/db/plugins/upnp/Tags.hxx \ - src/db/plugins/upnp/ContentDirectoryService.cxx src/db/plugins/upnp/ContentDirectoryService.hxx \ - src/db/plugins/upnp/Device.cxx src/db/plugins/upnp/Device.hxx \ + src/db/plugins/upnp/ContentDirectoryService.cxx \ src/db/plugins/upnp/Directory.cxx src/db/plugins/upnp/Directory.hxx \ - src/db/plugins/upnp/Discovery.cxx src/db/plugins/upnp/Discovery.hxx \ - src/db/plugins/upnp/Domain.cxx src/db/plugins/upnp/Domain.hxx \ - src/db/plugins/upnp/ixmlwrap.cxx src/db/plugins/upnp/ixmlwrap.hxx \ - src/db/plugins/upnp/upnpplib.cxx src/db/plugins/upnp/upnpplib.hxx \ - src/db/plugins/upnp/Util.cxx src/db/plugins/upnp/Util.hxx \ - src/db/plugins/upnp/Action.hxx \ - src/db/plugins/upnp/WorkQueue.hxx \ src/db/plugins/upnp/Object.cxx src/db/plugins/upnp/Object.hxx DB_LIBS += \ $(EXPAT_LIBS) \ diff --git a/src/db/plugins/UpnpDatabasePlugin.cxx b/src/db/plugins/UpnpDatabasePlugin.cxx index cd36cb2c9..8861359ce 100644 --- a/src/db/plugins/UpnpDatabasePlugin.cxx +++ b/src/db/plugins/UpnpDatabasePlugin.cxx @@ -19,13 +19,13 @@ #include "config.h" #include "UpnpDatabasePlugin.hxx" -#include "upnp/Domain.hxx" -#include "upnp/upnpplib.hxx" -#include "upnp/Discovery.hxx" -#include "upnp/ContentDirectoryService.hxx" +#include "lib/upnp/Domain.hxx" +#include "lib/upnp/upnpplib.hxx" +#include "lib/upnp/Discovery.hxx" +#include "lib/upnp/ContentDirectoryService.hxx" +#include "lib/upnp/Util.hxx" #include "upnp/Directory.hxx" #include "upnp/Tags.hxx" -#include "upnp/Util.hxx" #include "db/DatabasePlugin.hxx" #include "db/Selection.hxx" #include "db/DatabaseError.hxx" diff --git a/src/db/plugins/upnp/ContentDirectoryService.cxx b/src/db/plugins/upnp/ContentDirectoryService.cxx index 35445e09d..c097f7644 100644 --- a/src/db/plugins/upnp/ContentDirectoryService.cxx +++ b/src/db/plugins/upnp/ContentDirectoryService.cxx @@ -18,41 +18,16 @@ */ #include "config.h" -#include "ContentDirectoryService.hxx" -#include "Domain.hxx" -#include "Device.hxx" -#include "ixmlwrap.hxx" +#include "lib/upnp/ContentDirectoryService.hxx" +#include "lib/upnp/Domain.hxx" +#include "lib/upnp/ixmlwrap.hxx" +#include "lib/upnp/Action.hxx" #include "Directory.hxx" -#include "Util.hxx" -#include "Action.hxx" #include "util/NumberParser.hxx" #include "util/Error.hxx" -#include #include -ContentDirectoryService::ContentDirectoryService(const UPnPDevice &device, - const UPnPService &service) - :m_actionURL(caturl(device.URLBase, service.controlURL)), - m_serviceType(service.serviceType), - m_deviceId(device.UDN), - m_friendlyName(device.friendlyName), - m_manufacturer(device.manufacturer), - m_modelName(device.modelName), - m_rdreqcnt(200) -{ - if (!m_modelName.compare("MediaTomb")) { - // Readdir by 200 entries is good for most, but MediaTomb likes - // them really big. Actually 1000 is better but I don't dare - m_rdreqcnt = 500; - } -} - -ContentDirectoryService::~ContentDirectoryService() -{ - /* this destructor exists here just so it won't get inlined */ -} - static bool ReadResultTag(UPnPDirContent &dirbuf, IXML_Document *response, Error &error) { @@ -191,50 +166,6 @@ ContentDirectoryService::search(UpnpClient_Handle hdl, return true; } -bool -ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl, - std::list &result, - Error &error) const -{ - assert(result.empty()); - - IXML_Document *request = - UpnpMakeAction("GetSearchCapabilities", m_serviceType.c_str(), - 0, - nullptr, nullptr); - if (request == 0) { - error.Set(upnp_domain, "UpnpMakeAction() failed"); - return false; - } - - IXML_Document *response; - auto code = UpnpSendAction(hdl, m_actionURL.c_str(), - m_serviceType.c_str(), - 0 /*devUDN*/, request, &response); - ixmlDocument_free(request); - if (code != UPNP_E_SUCCESS) { - error.Format(upnp_domain, code, - "UpnpSendAction() failed: %s", - UpnpGetErrorMessage(code)); - return false; - } - - const char *s = ixmlwrap::getFirstElementValue(response, "SearchCaps"); - if (s == nullptr || *s == 0) { - ixmlDocument_free(response); - return true; - } - - bool success = true; - if (!csvToStrings(s, result)) { - error.Set(upnp_domain, "Bad response"); - success = false; - } - - ixmlDocument_free(response); - return success; -} - bool ContentDirectoryService::getMetadata(UpnpClient_Handle hdl, const char *objectId, diff --git a/src/db/plugins/upnp/Directory.cxx b/src/db/plugins/upnp/Directory.cxx index 9c089cc5e..e43cd48a6 100644 --- a/src/db/plugins/upnp/Directory.cxx +++ b/src/db/plugins/upnp/Directory.cxx @@ -19,7 +19,7 @@ #include "config.h" #include "Directory.hxx" -#include "Util.hxx" +#include "lib/upnp/Util.hxx" #include "lib/expat/ExpatParser.hxx" #include "Tags.hxx" #include "tag/TagBuilder.hxx" diff --git a/src/db/plugins/upnp/Action.hxx b/src/lib/upnp/Action.hxx similarity index 100% rename from src/db/plugins/upnp/Action.hxx rename to src/lib/upnp/Action.hxx diff --git a/src/lib/upnp/ContentDirectoryService.cxx b/src/lib/upnp/ContentDirectoryService.cxx new file mode 100644 index 000000000..ef8757ec5 --- /dev/null +++ b/src/lib/upnp/ContentDirectoryService.cxx @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2003-2014 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 "ContentDirectoryService.hxx" +#include "Domain.hxx" +#include "Device.hxx" +#include "ixmlwrap.hxx" +#include "Util.hxx" +#include "Action.hxx" +#include "util/Error.hxx" + +ContentDirectoryService::ContentDirectoryService(const UPnPDevice &device, + const UPnPService &service) + :m_actionURL(caturl(device.URLBase, service.controlURL)), + m_serviceType(service.serviceType), + m_deviceId(device.UDN), + m_friendlyName(device.friendlyName), + m_manufacturer(device.manufacturer), + m_modelName(device.modelName), + m_rdreqcnt(200) +{ + if (!m_modelName.compare("MediaTomb")) { + // Readdir by 200 entries is good for most, but MediaTomb likes + // them really big. Actually 1000 is better but I don't dare + m_rdreqcnt = 500; + } +} + +ContentDirectoryService::~ContentDirectoryService() +{ + /* this destructor exists here just so it won't get inlined */ +} + +bool +ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl, + std::list &result, + Error &error) const +{ + assert(result.empty()); + + IXML_Document *request = + UpnpMakeAction("GetSearchCapabilities", m_serviceType.c_str(), + 0, + nullptr, nullptr); + if (request == 0) { + error.Set(upnp_domain, "UpnpMakeAction() failed"); + return false; + } + + IXML_Document *response; + auto code = UpnpSendAction(hdl, m_actionURL.c_str(), + m_serviceType.c_str(), + 0 /*devUDN*/, request, &response); + ixmlDocument_free(request); + if (code != UPNP_E_SUCCESS) { + error.Format(upnp_domain, code, + "UpnpSendAction() failed: %s", + UpnpGetErrorMessage(code)); + return false; + } + + const char *s = ixmlwrap::getFirstElementValue(response, "SearchCaps"); + if (s == nullptr || *s == 0) { + ixmlDocument_free(response); + return true; + } + + bool success = true; + if (!csvToStrings(s, result)) { + error.Set(upnp_domain, "Bad response"); + success = false; + } + + ixmlDocument_free(response); + return success; +} diff --git a/src/db/plugins/upnp/ContentDirectoryService.hxx b/src/lib/upnp/ContentDirectoryService.hxx similarity index 99% rename from src/db/plugins/upnp/ContentDirectoryService.hxx rename to src/lib/upnp/ContentDirectoryService.hxx index 24be5dfbf..3c4497be1 100644 --- a/src/db/plugins/upnp/ContentDirectoryService.hxx +++ b/src/lib/upnp/ContentDirectoryService.hxx @@ -20,6 +20,8 @@ #ifndef _UPNPDIR_HXX_INCLUDED_ #define _UPNPDIR_HXX_INCLUDED_ +#include "Compiler.h" + #include #include diff --git a/src/db/plugins/upnp/Device.cxx b/src/lib/upnp/Device.cxx similarity index 100% rename from src/db/plugins/upnp/Device.cxx rename to src/lib/upnp/Device.cxx diff --git a/src/db/plugins/upnp/Device.hxx b/src/lib/upnp/Device.hxx similarity index 100% rename from src/db/plugins/upnp/Device.hxx rename to src/lib/upnp/Device.hxx diff --git a/src/db/plugins/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx similarity index 100% rename from src/db/plugins/upnp/Discovery.cxx rename to src/lib/upnp/Discovery.cxx diff --git a/src/db/plugins/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx similarity index 100% rename from src/db/plugins/upnp/Discovery.hxx rename to src/lib/upnp/Discovery.hxx diff --git a/src/db/plugins/upnp/Domain.cxx b/src/lib/upnp/Domain.cxx similarity index 100% rename from src/db/plugins/upnp/Domain.cxx rename to src/lib/upnp/Domain.cxx diff --git a/src/db/plugins/upnp/Domain.hxx b/src/lib/upnp/Domain.hxx similarity index 100% rename from src/db/plugins/upnp/Domain.hxx rename to src/lib/upnp/Domain.hxx diff --git a/src/db/plugins/upnp/Util.cxx b/src/lib/upnp/Util.cxx similarity index 100% rename from src/db/plugins/upnp/Util.cxx rename to src/lib/upnp/Util.cxx diff --git a/src/db/plugins/upnp/Util.hxx b/src/lib/upnp/Util.hxx similarity index 100% rename from src/db/plugins/upnp/Util.hxx rename to src/lib/upnp/Util.hxx diff --git a/src/db/plugins/upnp/WorkQueue.hxx b/src/lib/upnp/WorkQueue.hxx similarity index 100% rename from src/db/plugins/upnp/WorkQueue.hxx rename to src/lib/upnp/WorkQueue.hxx diff --git a/src/db/plugins/upnp/ixmlwrap.cxx b/src/lib/upnp/ixmlwrap.cxx similarity index 100% rename from src/db/plugins/upnp/ixmlwrap.cxx rename to src/lib/upnp/ixmlwrap.cxx diff --git a/src/db/plugins/upnp/ixmlwrap.hxx b/src/lib/upnp/ixmlwrap.hxx similarity index 100% rename from src/db/plugins/upnp/ixmlwrap.hxx rename to src/lib/upnp/ixmlwrap.hxx diff --git a/src/db/plugins/upnp/upnpplib.cxx b/src/lib/upnp/upnpplib.cxx similarity index 100% rename from src/db/plugins/upnp/upnpplib.cxx rename to src/lib/upnp/upnpplib.cxx diff --git a/src/db/plugins/upnp/upnpplib.hxx b/src/lib/upnp/upnpplib.hxx similarity index 100% rename from src/db/plugins/upnp/upnpplib.hxx rename to src/lib/upnp/upnpplib.hxx