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