ContentDirectoryService.cxx 2.6 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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 "ContentDirectoryService.hxx"
21
#include "UniqueIxml.hxx"
22 23 24
#include "Device.hxx"
#include "ixmlwrap.hxx"
#include "Action.hxx"
25
#include "util/UriUtil.hxx"
26
#include "util/RuntimeError.hxx"
27
#include "util/SplitString.hxx"
28 29

ContentDirectoryService::ContentDirectoryService(const UPnPDevice &device,
30
						 const UPnPService &service) noexcept
31
	:m_actionURL(uri_apply_base(service.controlURL, device.URLBase)),
32 33 34 35 36 37 38 39 40 41 42 43 44 45
	 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;
	}
}

46
ContentDirectoryService::~ContentDirectoryService() noexcept
47 48 49 50
{
	/* this destructor exists here just so it won't get inlined */
}

51
std::forward_list<std::string>
52
ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl) const
53
{
54 55 56
	UniqueIxmlDocument request(UpnpMakeAction("GetSearchCapabilities", m_serviceType.c_str(),
						  0,
						  nullptr, nullptr));
57 58
	if (!request)
		throw std::runtime_error("UpnpMakeAction() failed");
59

60
	IXML_Document *_response;
61 62
	auto code = UpnpSendAction(hdl, m_actionURL.c_str(),
				   m_serviceType.c_str(),
63
				   0 /*devUDN*/, request.get(), &_response);
64 65 66
	if (code != UPNP_E_SUCCESS)
		throw FormatRuntimeError("UpnpSendAction() failed: %s",
					 UpnpGetErrorMessage(code));
67

68 69 70 71 72
	UniqueIxmlDocument response(_response);

	const char *s = ixmlwrap::getFirstElementValue(response.get(),
						       "SearchCaps");
	if (s == nullptr || *s == 0)
73 74 75
		/* we could just "return {}" here, but GCC 5 doesn't
		   understand that */
		return std::forward_list<std::string>();
76

77
	return SplitString(s, ',', false);
78
}