MythTV  master
upnpcds.h
Go to the documentation of this file.
1 // Program Name: UPnpCDS.h
3 // Created : Oct. 24, 2005
4 //
5 // Purpose :
6 //
7 // Copyright (c) 2005 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see LICENSE for details
10 //
12 
13 #ifndef UPnpCDS_H_
14 #define UPnpCDS_H_
15 
16 // C++ headers
17 #include <utility>
18 
19 // QT headers
20 #include <QList>
21 #include <QMap>
22 #include <QObject>
23 #include <QString>
24 
25 #include "libmythbase/mythdbcon.h"
26 
27 #include "libmythupnp/eventing.h"
28 #include "libmythupnp/upnp.h"
30 
31 class UPnpCDS;
32 
33 enum UPnpCDSMethod : std::uint8_t
34 {
44 };
45 
46 enum UPnpCDSBrowseFlag : std::uint8_t
47 {
51 };
52 
53 enum UPnpCDSClient : std::uint8_t
54 {
55  CDS_ClientDefault = 0, // (no special attention required)
56  CDS_ClientWMP = 1, // Windows Media Player
57  CDS_ClientXBMC = 2, // XBMC
58  CDS_ClientMP101 = 3, // Netgear MP101
59  CDS_ClientXBox = 4, // XBox 360
60  CDS_ClientSonyDB = 5, // Sony Blu-ray players
61 };
62 
64 {
66  QString sHeaderKey;
67  QString sHeaderValue;
68 };
69 
71 
73 {
74  public:
75 
76  QString m_sObjectId;
77 
78  QString m_sContainerID;
79  QString m_sFilter;
80  uint16_t m_nStartingIndex {0};
81  uint16_t m_nRequestedCount {0};
82  QString m_sSortCriteria;
83 
84  // Browse specific properties
85 
86  QString m_sParentId;
88 
89  // Search specific properties
90 
92  QStringList m_sSearchList;
93  QString m_sSearchClass;
94 
95  // The device performing the request
97  double m_nClientVersion {0.0};
98 
99  public:
100 
101  UPnpCDSRequest() = default;
102 };
103 
105 
107 {
108  public:
109 
112  QString m_sErrorDesc;
113 
114  uint16_t m_nTotalMatches {0};
115  uint16_t m_nUpdateID {0};
116 
117  public:
118 
119  UPnpCDSExtensionResults() = default;
121  {
122  while (!m_List.isEmpty())
123  {
124  m_List.takeLast()->DecrRef();
125  }
126  }
127 
128  void Add ( CDSObject *pObject );
129  void Add ( const CDSObjects& objects );
130  QString GetResultXML(FilterMap &filter, bool ignoreChildren = false);
131 };
132 
134 
140 {
141  public:
142  UPnPShortcutFeature() : UPnPFeature("CONTAINER_SHORTCUTS", 1) { }
143 
150  enum ShortCutType : std::uint8_t
151  {
163 
173 
184 
185  FOLDER_STRUCTURE
186  };
187 
188  bool AddShortCut(ShortCutType type, const QString &objectID);
189  QString CreateXML() override; // UPnPFeature
190 
191  private:
192  static QString TypeToName(ShortCutType type);
193  QMap<ShortCutType, QString> m_shortcuts;
194 };
195 
196 using CDSShortCutList = QMap<UPnPShortcutFeature::ShortCutType, QString>;
197 
199 
200 using IDTokenMap = QMap<QString, QString>;
201 using IDToken = QPair<QString, QString>;
202 
204 {
205  public:
206 
207  QString m_sExtensionId;
208  QString m_sName;
209  QString m_sClass;
210 
212 
213  protected:
214 
215  static QString RemoveToken ( const QString &sToken, const QString &sStr, int num );
216 
217  // ------------------------------------------------------------------
218 
219  virtual bool IsBrowseRequestForUs ( UPnpCDSRequest *pRequest );
220  virtual bool IsSearchRequestForUs ( UPnpCDSRequest *pRequest );
221 
222  // ------------------------------------------------------------------
223 
224  virtual int GetRootCount ( ) { return m_pRoot->GetChildCount(); }
225  virtual int GetRootContainerCount ( )
226  { return m_pRoot->GetChildContainerCount(); }
227 
228  virtual void CreateRoot ( );
229 
230  virtual bool LoadMetadata ( const UPnpCDSRequest *pRequest,
231  UPnpCDSExtensionResults *pResults,
232  const IDTokenMap& tokens,
233  const QString& currentToken );
234  virtual bool LoadChildren ( const UPnpCDSRequest *pRequest,
235  UPnpCDSExtensionResults *pResults,
236  const IDTokenMap& tokens,
237  const QString& currentToken );
238 
239  static IDTokenMap TokenizeIDString ( const QString &Id ) ;
240  static IDToken GetCurrentToken ( const QString &Id ) ;
241 
242  static QString CreateIDString ( const QString &RequestId,
243  const QString &Name,
244  int Value );
245  static QString CreateIDString ( const QString &RequestId,
246  const QString &Name,
247  const QString &Value );
248 
249  CDSObject *m_pRoot {nullptr};
250 
251  public:
252 
253  UPnpCDSExtension( QString sName,
254  QString sExtensionId,
255  QString sClass ) :
256  m_sExtensionId(std::move(sExtensionId)),
257  m_sName(std::move(sName)),
258  m_sClass(std::move(sClass)) {}
259 
260  virtual CDSObject *GetRoot ( );
261 
262  virtual ~UPnpCDSExtension();
263 
264  virtual UPnpCDSExtensionResults *Browse( UPnpCDSRequest *pRequest );
265  virtual UPnpCDSExtensionResults *Search( UPnpCDSRequest *pRequest );
266 
267  virtual QString GetSearchCapabilities() { return( "" ); }
268  virtual QString GetSortCapabilities () { return( "" ); }
269  virtual CDSShortCutList GetShortCuts () { return m_shortcuts; }
270 };
271 
272 using UPnpCDSExtensionList = QList<UPnpCDSExtension*>;
273 
276 //
277 // UPnpCDS Class Definition
278 //
281 
283 {
284  private:
285 
288 
290  QString m_sControlUrl;
291 
293  UPnPShortcutFeature *m_pShortCuts {nullptr};
294 
295  private:
296 
297  static UPnpCDSMethod GetMethod ( const QString &sURI );
298  static UPnpCDSBrowseFlag GetBrowseFlag ( const QString &sFlag );
299 
300  void HandleBrowse ( HTTPRequest *pRequest );
301  void HandleSearch ( HTTPRequest *pRequest );
302  static void HandleGetSearchCapabilities( HTTPRequest *pRequest );
303  static void HandleGetSortCapabilities ( HTTPRequest *pRequest );
304  void HandleGetSystemUpdateID ( HTTPRequest *pRequest );
305  void HandleGetFeatureList ( HTTPRequest *pRequest );
306  void HandleGetServiceResetToken ( HTTPRequest *pRequest );
307  static void DetermineClient ( HTTPRequest *pRequest, UPnpCDSRequest *pCDSRequest );
308 
309  protected:
310 
311  // Implement UPnpServiceImpl methods that we can
312 
313  QString GetServiceType() override // UPnpServiceImpl
314  { return "urn:schemas-upnp-org:service:ContentDirectory:4"; }
315  QString GetServiceId() override // UPnpServiceImpl
316  { return "urn:upnp-org:serviceId:ContentDirectory"; }
317  QString GetServiceControlURL() override // UPnpServiceImpl
318  { return m_sControlUrl.mid( 1 ); }
319  QString GetServiceDescURL() override // UPnpServiceImpl
320  { return m_sControlUrl.mid( 1 ) + "/GetServDesc"; }
321 
322  public:
323  UPnpCDS( UPnpDevice *pDevice,
324  const QString &sSharePath );
325 
326  ~UPnpCDS() override;
327 
328  void RegisterExtension ( UPnpCDSExtension *pExtension );
329  void UnregisterExtension( UPnpCDSExtension *pExtension );
330 
331  void RegisterShortCut ( UPnPShortcutFeature::ShortCutType type,
332  const QString &objectID );
333  void RegisterFeature ( UPnPFeature *feature );
334 
335  QStringList GetBasePaths() override; // Eventing
336 
337  bool ProcessRequest( HTTPRequest *pRequest ) override; // Eventing
338 };
339 
340 #endif
341 
342 // vim:ts=4:sw=4:ai:et:si:sts=4
UPnPShortcutFeature::IMAGES_ALL
@ IMAGES_ALL
Definition: upnpcds.h:171
UPnpCDSExtensionList
QList< UPnpCDSExtension * > UPnpCDSExtensionList
Definition: upnpcds.h:272
UPnpCDS::GetServiceControlURL
QString GetServiceControlURL() override
Provices the base URL for control commands.
Definition: upnpcds.h:317
UPnpCDSExtensionResults::~UPnpCDSExtensionResults
~UPnpCDSExtensionResults()
Definition: upnpcds.h:120
UPnPShortcutFeature::VIDEOS_RECORDINGS
@ VIDEOS_RECORDINGS
Definition: upnpcds.h:181
UPnpCDS::m_sControlUrl
QString m_sControlUrl
Definition: upnpcds.h:290
UPnpCDS::m_root
CDSObject m_root
Definition: upnpcds.h:287
UPnPShortcutFeature::IMAGES_FOLDER_STRUCTURE
@ IMAGES_FOLDER_STRUCTURE
Definition: upnpcds.h:172
UPnpCDSRequest::m_sFilter
QString m_sFilter
Definition: upnpcds.h:79
CDSM_GetServiceResetToken
@ CDSM_GetServiceResetToken
Definition: upnpcds.h:43
UPnpCDS::m_features
UPnPFeatureList m_features
Definition: upnpcds.h:292
HTTPRequest
Definition: httprequest.h:109
CDSShortCutList
QMap< UPnPShortcutFeature::ShortCutType, QString > CDSShortCutList
Definition: upnpcds.h:196
UPnpCDSExtension
Definition: upnpcds.h:203
Eventing::GetBasePaths
QStringList GetBasePaths() override
Definition: eventing.cpp:134
CDSM_GetServiceDescription
@ CDSM_GetServiceDescription
Definition: upnpcds.h:36
CDSObject
Definition: upnpcdsobjects.h:186
CDS_ClientDefault
@ CDS_ClientDefault
Definition: upnpcds.h:55
UPnPShortcutFeature
Standard UPnP Shortcut feature.
Definition: upnpcds.h:139
UPnPShortcutFeature::VIDEOS_LAST_PLAYED
@ VIDEOS_LAST_PLAYED
Definition: upnpcds.h:180
UPnpCDSRequest::m_sParentId
QString m_sParentId
Definition: upnpcds.h:86
CDSM_GetSearchCapabilities
@ CDSM_GetSearchCapabilities
Definition: upnpcds.h:39
UPnPShortcutFeature::MUSIC_ALL
@ MUSIC_ALL
Definition: upnpcds.h:161
UPnPShortcutFeature::VIDEOS_FOLDER_STRUCTURE
@ VIDEOS_FOLDER_STRUCTURE
Definition: upnpcds.h:183
UPnPShortcutFeature::MUSIC_LAST_PLAYED
@ MUSIC_LAST_PLAYED
Definition: upnpcds.h:158
UPnpCDSClientException::sHeaderKey
QString sHeaderKey
Definition: upnpcds.h:66
CDS_ClientXBMC
@ CDS_ClientXBMC
Definition: upnpcds.h:57
UPnPShortcutFeature::VIDEOS
@ VIDEOS
Definition: upnpcds.h:174
UPnpCDS::GetServiceId
QString GetServiceId() override
Provides the device specific urn.
Definition: upnpcds.h:315
mythdbcon.h
Eventing
Definition: eventing.h:245
UPnpCDSExtension::m_sName
QString m_sName
Definition: upnpcds.h:208
UPnpCDS::m_extensions
UPnpCDSExtensionList m_extensions
Definition: upnpcds.h:286
UPnPShortcutFeature::MUSIC_AUDIOBOOKS
@ MUSIC_AUDIOBOOKS
Definition: upnpcds.h:159
Eventing::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:146
UPnPShortcutFeature::IMAGES_YEARS_MONTH
@ IMAGES_YEARS_MONTH
Definition: upnpcds.h:166
UPnPShortcutFeature::MUSIC_ALBUMS
@ MUSIC_ALBUMS
Definition: upnpcds.h:153
UPnpCDSExtension::GetSearchCapabilities
virtual QString GetSearchCapabilities()
Definition: upnpcds.h:267
UPnpCDS::GetServiceType
QString GetServiceType() override
Provices the schema urn.
Definition: upnpcds.h:313
UPnpCDSMethod
UPnpCDSMethod
Definition: upnpcds.h:33
UPnpCDSExtension::m_shortcuts
CDSShortCutList m_shortcuts
Definition: upnpcds.h:211
UPnPShortcutFeature::MUSIC_RECENTLY_ADDED
@ MUSIC_RECENTLY_ADDED
Definition: upnpcds.h:157
UPnpCDSRequest::m_sContainerID
QString m_sContainerID
Definition: upnpcds.h:78
UPnpCDSClientException::sHeaderValue
QString sHeaderValue
Definition: upnpcds.h:67
eventing.h
UPnPShortcutFeature::MUSIC
@ MUSIC
Definition: upnpcds.h:152
FilterMap
QMap< uint, int > FilterMap
Definition: ExternalSignalMonitor.h:17
UPnPShortcutFeature::VIDEOS_YEARS_MONTH
@ VIDEOS_YEARS_MONTH
Definition: upnpcds.h:177
upnp.h
UPnpCDS
Definition: upnpcds.h:282
UPnpCDSRequest::m_sSearchCriteria
QString m_sSearchCriteria
Definition: upnpcds.h:91
UPnpCDSExtension::m_sClass
QString m_sClass
Definition: upnpcds.h:209
feature
static const std::array< featureStruct, 7 > feature
Definition: audiooutputsettings.cpp:434
CDSM_Search
@ CDSM_Search
Definition: upnpcds.h:38
UPnPShortcutFeature::VIDEOS_GENRES
@ VIDEOS_GENRES
Definition: upnpcds.h:175
UPnPShortcutFeature::UPnPShortcutFeature
UPnPShortcutFeature()
Definition: upnpcds.h:142
UPnpCDS::m_sServiceDescFileName
QString m_sServiceDescFileName
Definition: upnpcds.h:289
UPnPShortcutFeature::VIDEOS_ALL
@ VIDEOS_ALL
Definition: upnpcds.h:182
UPnPShortcutFeature::m_shortcuts
QMap< ShortCutType, QString > m_shortcuts
Definition: upnpcds.h:193
UPnPShortcutFeature::IMAGES_YEARS
@ IMAGES_YEARS
Definition: upnpcds.h:165
UPnpCDSClient
UPnpCDSClient
Definition: upnpcds.h:53
CDS_BrowseUnknown
@ CDS_BrowseUnknown
Definition: upnpcds.h:48
UPnPShortcutFeature::MUSIC_GENRES
@ MUSIC_GENRES
Definition: upnpcds.h:155
CDSObjects
QList< CDSObject * > CDSObjects
Definition: upnpcdsobjects.h:99
UPnpDevice
Definition: upnpdevice.h:102
CDSM_GetFeatureList
@ CDSM_GetFeatureList
Definition: upnpcds.h:42
UPnpCDSExtension::UPnpCDSExtension
UPnpCDSExtension(QString sName, QString sExtensionId, QString sClass)
Definition: upnpcds.h:253
Search
Definition: netgrabbermanager.h:143
CDS_ClientSonyDB
@ CDS_ClientSonyDB
Definition: upnpcds.h:60
CDSM_GetSystemUpdateID
@ CDSM_GetSystemUpdateID
Definition: upnpcds.h:41
UPnpCDSRequest::m_sObjectId
QString m_sObjectId
Definition: upnpcds.h:76
UPnPResult_Success
@ UPnPResult_Success
Definition: upnp.h:37
UPnpCDSRequest::m_sSearchList
QStringList m_sSearchList
Definition: upnpcds.h:92
CDSM_GetSortCapabilities
@ CDSM_GetSortCapabilities
Definition: upnpcds.h:40
UPnPShortcutFeature::IMAGES
@ IMAGES
Definition: upnpcds.h:164
upnpcdsobjects.h
UPnPFeatureList
Definition: upnpserviceimpl.h:65
UPnpCDS::GetServiceDescURL
QString GetServiceDescURL() override
Provices the URL of the service description XML.
Definition: upnpcds.h:319
UPnpCDSClientException::nClientType
UPnpCDSClient nClientType
Definition: upnpcds.h:65
Name
Definition: channelsettings.cpp:71
CDS_BrowseDirectChildren
@ CDS_BrowseDirectChildren
Definition: upnpcds.h:50
IDTokenMap
QMap< QString, QString > IDTokenMap
Definition: upnpcds.h:200
UPnpCDSClientException
Definition: upnpcds.h:63
CDSM_Browse
@ CDSM_Browse
Definition: upnpcds.h:37
UPnpCDSBrowseFlag
UPnpCDSBrowseFlag
Definition: upnpcds.h:46
UPNP_PUBLIC
#define UPNP_PUBLIC
Definition: upnpexp.h:9
UPnPShortcutFeature::IMAGES_LAST_WATCHED
@ IMAGES_LAST_WATCHED
Definition: upnpcds.h:170
UPnpCDSExtension::GetSortCapabilities
virtual QString GetSortCapabilities()
Definition: upnpcds.h:268
UPnpCDSExtension::GetRootCount
virtual int GetRootCount()
Definition: upnpcds.h:224
UPnpCDSExtensionResults::m_List
CDSObjects m_List
Definition: upnpcds.h:110
UPnPShortcutFeature::MUSIC_ARTISTS
@ MUSIC_ARTISTS
Definition: upnpcds.h:154
UPnPFeature
Definition: upnpserviceimpl.h:50
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:3
IDToken
QPair< QString, QString > IDToken
Definition: upnpcds.h:201
UPnPShortcutFeature::ShortCutType
ShortCutType
Allowed values for the Container Shortcut feature.
Definition: upnpcds.h:150
UPnPShortcutFeature::IMAGES_SLIDESHOWS
@ IMAGES_SLIDESHOWS
Definition: upnpcds.h:168
UPnPShortcutFeature::MUSIC_STATIONS
@ MUSIC_STATIONS
Definition: upnpcds.h:160
UPnPResultCode
UPnPResultCode
Definition: upnp.h:35
UPnpCDSExtensionResults
Definition: upnpcds.h:106
UPnPShortcutFeature::IMAGES_RECENTLY_ADDED
@ IMAGES_RECENTLY_ADDED
Definition: upnpcds.h:169
UPnPShortcutFeature::VIDEOS_YEARS
@ VIDEOS_YEARS
Definition: upnpcds.h:176
CDS_ClientMP101
@ CDS_ClientMP101
Definition: upnpcds.h:58
UPnPShortcutFeature::VIDEOS_ALBUM
@ VIDEOS_ALBUM
Definition: upnpcds.h:178
UPnpCDSExtension::GetRootContainerCount
virtual int GetRootContainerCount()
Definition: upnpcds.h:225
UPnpCDSExtension::GetShortCuts
virtual CDSShortCutList GetShortCuts()
Definition: upnpcds.h:269
CDSM_Unknown
@ CDSM_Unknown
Definition: upnpcds.h:35
UPnPFeature::CreateXML
virtual QString CreateXML()=0
UPnpCDSRequest::m_sSortCriteria
QString m_sSortCriteria
Definition: upnpcds.h:82
UPnPShortcutFeature::IMAGES_ALBUM
@ IMAGES_ALBUM
Definition: upnpcds.h:167
UPnpCDSRequest
Definition: upnpcds.h:72
UPnPShortcutFeature::MUSIC_FOLDER_STRUCTURE
@ MUSIC_FOLDER_STRUCTURE
Definition: upnpcds.h:162
UPnPShortcutFeature::VIDEOS_RECENTLY_ADDED
@ VIDEOS_RECENTLY_ADDED
Definition: upnpcds.h:179
UPnpCDSExtensionResults::m_sErrorDesc
QString m_sErrorDesc
Definition: upnpcds.h:112
UPnPShortcutFeature::MUSIC_PLAYLISTS
@ MUSIC_PLAYLISTS
Definition: upnpcds.h:156
CDS_BrowseMetadata
@ CDS_BrowseMetadata
Definition: upnpcds.h:49
CDS_ClientWMP
@ CDS_ClientWMP
Definition: upnpcds.h:56
UPnpCDSExtension::m_sExtensionId
QString m_sExtensionId
Definition: upnpcds.h:207
UPnpCDSRequest::m_sSearchClass
QString m_sSearchClass
Definition: upnpcds.h:93
CDS_ClientXBox
@ CDS_ClientXBox
Definition: upnpcds.h:59