2013-11-01 19:26:01 +01:00
|
|
|
/*
|
2022-07-14 17:58:12 +02:00
|
|
|
* Copyright 2003-2022 The Music Player Daemon Project
|
2013-11-01 19:26:01 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _UPNPDIR_HXX_INCLUDED_
|
|
|
|
#define _UPNPDIR_HXX_INCLUDED_
|
|
|
|
|
2020-05-27 16:48:44 +02:00
|
|
|
#include "Compat.hxx"
|
2014-01-26 11:51:56 +01:00
|
|
|
|
2013-11-01 19:26:01 +01:00
|
|
|
#include <string>
|
2018-01-02 13:11:00 +01:00
|
|
|
#include <forward_list>
|
2013-11-01 19:26:01 +01:00
|
|
|
|
|
|
|
class UPnPDevice;
|
|
|
|
struct UPnPService;
|
|
|
|
class UPnPDirContent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Content Directory Service class.
|
|
|
|
*
|
|
|
|
* This stores identity data from a directory service
|
|
|
|
* and the device it belongs to, and has methods to query
|
|
|
|
* the directory, using libupnp for handling the UPnP protocols.
|
|
|
|
*
|
|
|
|
* Note: m_rdreqcnt: number of entries requested per directory read.
|
|
|
|
* 0 means all entries. The device can still return less entries than
|
|
|
|
* requested, depending on its own limits. In general it's not optimal
|
|
|
|
* becauses it triggers issues, and is sometimes actually slower, e.g. on
|
|
|
|
* a D-Link NAS 327
|
|
|
|
*
|
|
|
|
* The value chosen may affect by the UpnpSetMaxContentLength
|
|
|
|
* (2000*1024) done during initialization, but this should be ample
|
|
|
|
*/
|
|
|
|
class ContentDirectoryService {
|
|
|
|
std::string m_actionURL;
|
|
|
|
std::string m_serviceType;
|
|
|
|
std::string m_deviceId;
|
|
|
|
std::string m_friendlyName;
|
|
|
|
std::string m_manufacturer;
|
|
|
|
std::string m_modelName;
|
|
|
|
|
|
|
|
int m_rdreqcnt; // Slice size to use when reading
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Construct by copying data from device and service objects.
|
|
|
|
*
|
2015-02-02 22:12:19 +01:00
|
|
|
* The discovery service does this: use
|
|
|
|
* UPnPDeviceDirectory::GetDirectories()
|
2013-11-01 19:26:01 +01:00
|
|
|
*/
|
|
|
|
ContentDirectoryService(const UPnPDevice &device,
|
2017-11-12 18:26:32 +01:00
|
|
|
const UPnPService &service) noexcept;
|
2013-11-01 19:26:01 +01:00
|
|
|
|
|
|
|
/** An empty one */
|
|
|
|
ContentDirectoryService() = default;
|
|
|
|
|
2017-11-12 18:26:32 +01:00
|
|
|
~ContentDirectoryService() noexcept;
|
2014-01-23 21:17:40 +01:00
|
|
|
|
2013-11-01 19:26:01 +01:00
|
|
|
/** Read a container's children list into dirbuf.
|
|
|
|
*
|
|
|
|
* @param objectId the UPnP object Id for the container. Root has Id "0"
|
|
|
|
*/
|
2016-02-06 08:45:19 +01:00
|
|
|
UPnPDirContent readDir(UpnpClient_Handle handle,
|
|
|
|
const char *objectId) const;
|
2013-11-01 19:26:01 +01:00
|
|
|
|
2016-02-06 08:45:19 +01:00
|
|
|
void readDirSlice(UpnpClient_Handle handle,
|
2014-01-22 20:44:24 +01:00
|
|
|
const char *objectId, unsigned offset,
|
|
|
|
unsigned count, UPnPDirContent& dirbuf,
|
2016-02-06 08:45:19 +01:00
|
|
|
unsigned &didread, unsigned &total) const;
|
2013-11-01 19:26:01 +01:00
|
|
|
|
|
|
|
/** Search the content directory service.
|
|
|
|
*
|
|
|
|
* @param objectId the UPnP object Id under which the search
|
|
|
|
* should be done. Not all servers actually support this below
|
|
|
|
* root. Root has Id "0"
|
|
|
|
* @param searchstring an UPnP searchcriteria string. Check the
|
|
|
|
* UPnP document: UPnP-av-ContentDirectory-v1-Service-20020625.pdf
|
|
|
|
* section 2.5.5. Maybe we'll provide an easier way some day...
|
|
|
|
*/
|
2016-02-06 08:45:19 +01:00
|
|
|
UPnPDirContent search(UpnpClient_Handle handle,
|
|
|
|
const char *objectId,
|
|
|
|
const char *searchstring) const;
|
2013-11-01 19:26:01 +01:00
|
|
|
|
|
|
|
/** Read metadata for a given node.
|
|
|
|
*
|
|
|
|
* @param objectId the UPnP object Id. Root has Id "0"
|
|
|
|
*/
|
2016-02-06 08:45:19 +01:00
|
|
|
UPnPDirContent getMetadata(UpnpClient_Handle handle,
|
|
|
|
const char *objectId) const;
|
2013-11-01 19:26:01 +01:00
|
|
|
|
|
|
|
/** Retrieve search capabilities
|
2016-02-07 00:29:06 +01:00
|
|
|
*
|
|
|
|
* Throws std::runtime_error on error.
|
2013-11-01 19:26:01 +01:00
|
|
|
*
|
|
|
|
* @param[out] result an empty vector: no search, or a single '*' element:
|
|
|
|
* any tag can be used in a search, or a list of usable tag names.
|
|
|
|
*/
|
2018-01-02 13:11:00 +01:00
|
|
|
std::forward_list<std::string> getSearchCapabilities(UpnpClient_Handle handle) const;
|
2013-11-01 19:26:01 +01:00
|
|
|
|
2021-10-13 11:28:04 +02:00
|
|
|
[[gnu::pure]]
|
2017-06-03 21:33:44 +02:00
|
|
|
std::string GetURI() const noexcept {
|
2014-01-26 11:19:17 +01:00
|
|
|
return "upnp://" + m_deviceId + "/" + m_serviceType;
|
|
|
|
}
|
|
|
|
|
2013-11-01 19:26:01 +01:00
|
|
|
/** Retrieve the "friendly name" for this server, useful for display. */
|
2017-06-03 21:33:44 +02:00
|
|
|
const char *getFriendlyName() const noexcept {
|
2013-11-01 19:26:01 +01:00
|
|
|
return m_friendlyName.c_str();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _UPNPDIR_HXX_INCLUDED_ */
|