diff options
author | Max Kellermann <max@duempel.org> | 2014-01-26 11:51:56 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-26 13:41:40 +0100 |
commit | f86f5ad2240c49f35c4948bed09027d9f5530d0b (patch) | |
tree | 2b0e8b09285fd817fb9e7fecb8c84fdcf2939f9c /src | |
parent | 8b6b3ff28a3406f8360920db5818ab321981c645 (diff) |
db/upnp: move generic code to lib/upnp/
Diffstat (limited to 'src')
-rw-r--r-- | src/db/plugins/UpnpDatabasePlugin.cxx | 10 | ||||
-rw-r--r-- | src/db/plugins/upnp/ContentDirectoryService.cxx | 77 | ||||
-rw-r--r-- | src/db/plugins/upnp/Directory.cxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/Action.hxx (renamed from src/db/plugins/upnp/Action.hxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/ContentDirectoryService.cxx | 93 | ||||
-rw-r--r-- | src/lib/upnp/ContentDirectoryService.hxx (renamed from src/db/plugins/upnp/ContentDirectoryService.hxx) | 2 | ||||
-rw-r--r-- | src/lib/upnp/Device.cxx (renamed from src/db/plugins/upnp/Device.cxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/Device.hxx (renamed from src/db/plugins/upnp/Device.hxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/Discovery.cxx (renamed from src/db/plugins/upnp/Discovery.cxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/Discovery.hxx (renamed from src/db/plugins/upnp/Discovery.hxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/Domain.cxx (renamed from src/db/plugins/upnp/Domain.cxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/Domain.hxx (renamed from src/db/plugins/upnp/Domain.hxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/Util.cxx (renamed from src/db/plugins/upnp/Util.cxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/Util.hxx (renamed from src/db/plugins/upnp/Util.hxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/WorkQueue.hxx (renamed from src/db/plugins/upnp/WorkQueue.hxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/ixmlwrap.cxx (renamed from src/db/plugins/upnp/ixmlwrap.cxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/ixmlwrap.hxx (renamed from src/db/plugins/upnp/ixmlwrap.hxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/upnpplib.cxx (renamed from src/db/plugins/upnp/upnpplib.cxx) | 0 | ||||
-rw-r--r-- | src/lib/upnp/upnpplib.hxx (renamed from src/db/plugins/upnp/upnpplib.hxx) | 0 |
19 files changed, 105 insertions, 79 deletions
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 <string.h> #include <stdio.h> -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) { @@ -192,50 +167,6 @@ ContentDirectoryService::search(UpnpClient_Handle hdl, } bool -ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl, - std::list<std::string> &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, UPnPDirContent &dirbuf, 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 index 28c88be92..28c88be92 100644 --- a/src/db/plugins/upnp/Action.hxx +++ b/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<std::string> &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 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 <upnp/upnp.h> #include <string> diff --git a/src/db/plugins/upnp/Device.cxx b/src/lib/upnp/Device.cxx index 26bffd0f0..26bffd0f0 100644 --- a/src/db/plugins/upnp/Device.cxx +++ b/src/lib/upnp/Device.cxx diff --git a/src/db/plugins/upnp/Device.hxx b/src/lib/upnp/Device.hxx index dd7ecac2d..dd7ecac2d 100644 --- a/src/db/plugins/upnp/Device.hxx +++ b/src/lib/upnp/Device.hxx diff --git a/src/db/plugins/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx index 5203dba83..5203dba83 100644 --- a/src/db/plugins/upnp/Discovery.cxx +++ b/src/lib/upnp/Discovery.cxx diff --git a/src/db/plugins/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx index 4c64fe420..4c64fe420 100644 --- a/src/db/plugins/upnp/Discovery.hxx +++ b/src/lib/upnp/Discovery.hxx diff --git a/src/db/plugins/upnp/Domain.cxx b/src/lib/upnp/Domain.cxx index 010d4c7c2..010d4c7c2 100644 --- a/src/db/plugins/upnp/Domain.cxx +++ b/src/lib/upnp/Domain.cxx diff --git a/src/db/plugins/upnp/Domain.hxx b/src/lib/upnp/Domain.hxx index ec01ef735..ec01ef735 100644 --- a/src/db/plugins/upnp/Domain.hxx +++ b/src/lib/upnp/Domain.hxx diff --git a/src/db/plugins/upnp/Util.cxx b/src/lib/upnp/Util.cxx index cf34a47d3..cf34a47d3 100644 --- a/src/db/plugins/upnp/Util.cxx +++ b/src/lib/upnp/Util.cxx diff --git a/src/db/plugins/upnp/Util.hxx b/src/lib/upnp/Util.hxx index 58e382faa..58e382faa 100644 --- a/src/db/plugins/upnp/Util.hxx +++ b/src/lib/upnp/Util.hxx diff --git a/src/db/plugins/upnp/WorkQueue.hxx b/src/lib/upnp/WorkQueue.hxx index fe8ce53f9..fe8ce53f9 100644 --- a/src/db/plugins/upnp/WorkQueue.hxx +++ b/src/lib/upnp/WorkQueue.hxx diff --git a/src/db/plugins/upnp/ixmlwrap.cxx b/src/lib/upnp/ixmlwrap.cxx index 6a2829cf9..6a2829cf9 100644 --- a/src/db/plugins/upnp/ixmlwrap.cxx +++ b/src/lib/upnp/ixmlwrap.cxx diff --git a/src/db/plugins/upnp/ixmlwrap.hxx b/src/lib/upnp/ixmlwrap.hxx index 0d519a323..0d519a323 100644 --- a/src/db/plugins/upnp/ixmlwrap.hxx +++ b/src/lib/upnp/ixmlwrap.hxx diff --git a/src/db/plugins/upnp/upnpplib.cxx b/src/lib/upnp/upnpplib.cxx index 27b4e0564..27b4e0564 100644 --- a/src/db/plugins/upnp/upnpplib.cxx +++ b/src/lib/upnp/upnpplib.cxx diff --git a/src/db/plugins/upnp/upnpplib.hxx b/src/lib/upnp/upnpplib.hxx index 6759aa16d..6759aa16d 100644 --- a/src/db/plugins/upnp/upnpplib.hxx +++ b/src/lib/upnp/upnpplib.hxx |