db/upnp: move generic code to lib/upnp/
This commit is contained in:
parent
8b6b3ff28a
commit
f86f5ad224
22
Makefile.am
22
Makefile.am
@ -216,6 +216,17 @@ src_mpd_SOURCES = \
|
|||||||
src/PlaylistFile.cxx src/PlaylistFile.hxx \
|
src/PlaylistFile.cxx src/PlaylistFile.hxx \
|
||||||
src/Timer.cxx
|
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
|
# Windows resource file
|
||||||
#
|
#
|
||||||
@ -444,18 +455,11 @@ DB_LIBS = \
|
|||||||
|
|
||||||
if HAVE_LIBUPNP
|
if HAVE_LIBUPNP
|
||||||
libdb_plugins_a_SOURCES += \
|
libdb_plugins_a_SOURCES += \
|
||||||
|
$(UPNP_SOURCES) \
|
||||||
src/db/plugins/UpnpDatabasePlugin.cxx src/db/plugins/UpnpDatabasePlugin.hxx \
|
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/Tags.cxx src/db/plugins/upnp/Tags.hxx \
|
||||||
src/db/plugins/upnp/ContentDirectoryService.cxx src/db/plugins/upnp/ContentDirectoryService.hxx \
|
src/db/plugins/upnp/ContentDirectoryService.cxx \
|
||||||
src/db/plugins/upnp/Device.cxx src/db/plugins/upnp/Device.hxx \
|
|
||||||
src/db/plugins/upnp/Directory.cxx src/db/plugins/upnp/Directory.hxx \
|
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
|
src/db/plugins/upnp/Object.cxx src/db/plugins/upnp/Object.hxx
|
||||||
DB_LIBS += \
|
DB_LIBS += \
|
||||||
$(EXPAT_LIBS) \
|
$(EXPAT_LIBS) \
|
||||||
|
@ -19,13 +19,13 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "UpnpDatabasePlugin.hxx"
|
#include "UpnpDatabasePlugin.hxx"
|
||||||
#include "upnp/Domain.hxx"
|
#include "lib/upnp/Domain.hxx"
|
||||||
#include "upnp/upnpplib.hxx"
|
#include "lib/upnp/upnpplib.hxx"
|
||||||
#include "upnp/Discovery.hxx"
|
#include "lib/upnp/Discovery.hxx"
|
||||||
#include "upnp/ContentDirectoryService.hxx"
|
#include "lib/upnp/ContentDirectoryService.hxx"
|
||||||
|
#include "lib/upnp/Util.hxx"
|
||||||
#include "upnp/Directory.hxx"
|
#include "upnp/Directory.hxx"
|
||||||
#include "upnp/Tags.hxx"
|
#include "upnp/Tags.hxx"
|
||||||
#include "upnp/Util.hxx"
|
|
||||||
#include "db/DatabasePlugin.hxx"
|
#include "db/DatabasePlugin.hxx"
|
||||||
#include "db/Selection.hxx"
|
#include "db/Selection.hxx"
|
||||||
#include "db/DatabaseError.hxx"
|
#include "db/DatabaseError.hxx"
|
||||||
|
@ -18,41 +18,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ContentDirectoryService.hxx"
|
#include "lib/upnp/ContentDirectoryService.hxx"
|
||||||
#include "Domain.hxx"
|
#include "lib/upnp/Domain.hxx"
|
||||||
#include "Device.hxx"
|
#include "lib/upnp/ixmlwrap.hxx"
|
||||||
#include "ixmlwrap.hxx"
|
#include "lib/upnp/Action.hxx"
|
||||||
#include "Directory.hxx"
|
#include "Directory.hxx"
|
||||||
#include "Util.hxx"
|
|
||||||
#include "Action.hxx"
|
|
||||||
#include "util/NumberParser.hxx"
|
#include "util/NumberParser.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.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
|
static bool
|
||||||
ReadResultTag(UPnPDirContent &dirbuf, IXML_Document *response, Error &error)
|
ReadResultTag(UPnPDirContent &dirbuf, IXML_Document *response, Error &error)
|
||||||
{
|
{
|
||||||
@ -191,50 +166,6 @@ ContentDirectoryService::search(UpnpClient_Handle hdl,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
bool
|
||||||
ContentDirectoryService::getMetadata(UpnpClient_Handle hdl,
|
ContentDirectoryService::getMetadata(UpnpClient_Handle hdl,
|
||||||
const char *objectId,
|
const char *objectId,
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Directory.hxx"
|
#include "Directory.hxx"
|
||||||
#include "Util.hxx"
|
#include "lib/upnp/Util.hxx"
|
||||||
#include "lib/expat/ExpatParser.hxx"
|
#include "lib/expat/ExpatParser.hxx"
|
||||||
#include "Tags.hxx"
|
#include "Tags.hxx"
|
||||||
#include "tag/TagBuilder.hxx"
|
#include "tag/TagBuilder.hxx"
|
||||||
|
93
src/lib/upnp/ContentDirectoryService.cxx
Normal file
93
src/lib/upnp/ContentDirectoryService.cxx
Normal file
@ -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;
|
||||||
|
}
|
@ -20,6 +20,8 @@
|
|||||||
#ifndef _UPNPDIR_HXX_INCLUDED_
|
#ifndef _UPNPDIR_HXX_INCLUDED_
|
||||||
#define _UPNPDIR_HXX_INCLUDED_
|
#define _UPNPDIR_HXX_INCLUDED_
|
||||||
|
|
||||||
|
#include "Compiler.h"
|
||||||
|
|
||||||
#include <upnp/upnp.h>
|
#include <upnp/upnp.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
Loading…
Reference in New Issue
Block a user