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 #include <QList>
17 #include <QMap>
18 #include <QString>
19 #include <QObject>
20 
21 #include "upnp.h"
22 #include "upnpcdsobjects.h"
23 #include "eventing.h"
24 #include "mythdbcon.h"
25 
26 class UPnpCDS;
27 
28 typedef enum
29 {
39 
41 
42 typedef enum
43 {
47 
49 
50 typedef enum
51 {
52  CDS_ClientDefault = 0, // (no special attention required)
53  CDS_ClientWMP = 1, // Windows Media Player
54  CDS_ClientXBMC = 2, // XBMC
55  CDS_ClientMP101 = 3, // Netgear MP101
56  CDS_ClientXBox = 4, // XBox 360
57  CDS_ClientSonyDB = 5, // Sony Blu-ray players
59 
60 typedef struct
61 {
63  QString sHeaderKey;
64  QString sHeaderValue;
66 
68 
70 {
71  public:
72 
73  QString m_sObjectId;
74 
75  QString m_sContainerID;
76  QString m_sFilter;
77  uint16_t m_nStartingIndex {0};
78  uint16_t m_nRequestedCount {0};
79  QString m_sSortCriteria;
80 
81  // Browse specific properties
82 
83  QString m_sParentId;
85 
86  // Search specific properties
87 
89  QStringList m_sSearchList;
90  QString m_sSearchClass;
91 
92  // The device performing the request
94  double m_nClientVersion {0.0};
95 
96  public:
97 
98  UPnpCDSRequest() = default;
99 };
100 
102 
104 {
105  public:
106 
109  QString m_sErrorDesc;
110 
111  uint16_t m_nTotalMatches {0};
112  uint16_t m_nUpdateID {0};
113 
114  public:
115 
116  UPnpCDSExtensionResults() = default;
118  {
119  while (!m_List.isEmpty())
120  {
121  m_List.takeLast()->DecrRef();
122  }
123  }
124 
125  void Add ( CDSObject *pObject );
126  void Add ( CDSObjects objects );
127  QString GetResultXML(FilterMap &filter, bool ignoreChildren = false);
128 };
129 
131 
137 {
138  public:
139  UPnPShortcutFeature() : UPnPFeature("CONTAINER_SHORTCUTS", 1) { }
140 
148  {
160 
170 
181 
182  FOLDER_STRUCTURE
183  };
184 
185  bool AddShortCut(ShortCutType type, const QString &objectID);
186  QString CreateXML() override; // UPnPFeature
187 
188  private:
189  static QString TypeToName(ShortCutType type);
190  QMap<ShortCutType, QString> m_shortcuts;
191 };
192 
193 typedef QMap<UPnPShortcutFeature::ShortCutType, QString> CDSShortCutList;
194 
196 
197 typedef QMap<QString, QString> IDTokenMap;
198 typedef QPair<QString, QString> IDToken;
199 
201 {
202  public:
203 
204  QString m_sExtensionId;
205  QString m_sName;
206  QString m_sClass;
207 
209 
210  protected:
211 
212  static QString RemoveToken ( const QString &sToken, const QString &sStr, int num );
213 
214  // ------------------------------------------------------------------
215 
216  virtual bool IsBrowseRequestForUs ( UPnpCDSRequest *pRequest );
217  virtual bool IsSearchRequestForUs ( UPnpCDSRequest *pRequest );
218 
219  // ------------------------------------------------------------------
220 
221  virtual int GetRootCount ( ) { return m_pRoot->GetChildCount(); }
222  virtual int GetRootContainerCount ( )
223  { return m_pRoot->GetChildContainerCount(); }
224 
225  virtual void CreateRoot ( );
226 
227  virtual bool LoadMetadata ( const UPnpCDSRequest *pRequest,
228  UPnpCDSExtensionResults *pResults,
229  const IDTokenMap& tokens,
230  const QString& currentToken );
231  virtual bool LoadChildren ( const UPnpCDSRequest *pRequest,
232  UPnpCDSExtensionResults *pResults,
233  const IDTokenMap& tokens,
234  const QString& currentToken );
235 
236  static IDTokenMap TokenizeIDString ( const QString &Id ) ;
237  static IDToken GetCurrentToken ( const QString &Id ) ;
238 
239  static QString CreateIDString ( const QString &RequestId,
240  const QString &Name,
241  int Value );
242  static QString CreateIDString ( const QString &RequestId,
243  const QString &Name,
244  const QString &Value );
245 
246  CDSObject *m_pRoot {nullptr};
247 
248  public:
249 
250  UPnpCDSExtension( QString sName,
251  QString sExtensionId,
252  QString sClass )
253  {
254  m_sName = QObject::tr(sName.toLatin1().constData());
255  m_sExtensionId = sExtensionId;
256  m_sClass = sClass;
257  }
258 
259  virtual CDSObject *GetRoot ( );
260 
261  virtual ~UPnpCDSExtension();
262 
263  virtual UPnpCDSExtensionResults *Browse( UPnpCDSRequest *pRequest );
264  virtual UPnpCDSExtensionResults *Search( UPnpCDSRequest *pRequest );
265 
266  virtual QString GetSearchCapabilities() { return( "" ); }
267  virtual QString GetSortCapabilities () { return( "" ); }
268  virtual CDSShortCutList GetShortCuts () { return m_shortcuts; }
269 };
270 
271 typedef QList<UPnpCDSExtension*> UPnpCDSExtensionList;
272 
275 //
276 // UPnpCDS Class Definition
277 //
280 
282 {
283  private:
284 
287 
289  QString m_sControlUrl;
290 
292  UPnPShortcutFeature *m_pShortCuts {nullptr};
293 
294  private:
295 
296  static UPnpCDSMethod GetMethod ( const QString &sURI );
297  static UPnpCDSBrowseFlag GetBrowseFlag ( const QString &sFlag );
298 
299  void HandleBrowse ( HTTPRequest *pRequest );
300  void HandleSearch ( HTTPRequest *pRequest );
301  static void HandleGetSearchCapabilities( HTTPRequest *pRequest );
302  static void HandleGetSortCapabilities ( HTTPRequest *pRequest );
303  void HandleGetSystemUpdateID ( HTTPRequest *pRequest );
304  void HandleGetFeatureList ( HTTPRequest *pRequest );
305  void HandleGetServiceResetToken ( HTTPRequest *pRequest );
306  static void DetermineClient ( HTTPRequest *pRequest, UPnpCDSRequest *pCDSRequest );
307 
308  protected:
309 
310  // Implement UPnpServiceImpl methods that we can
311 
312  QString GetServiceType() override // UPnpServiceImpl
313  { return "urn:schemas-upnp-org:service:ContentDirectory:4"; }
314  QString GetServiceId() override // UPnpServiceImpl
315  { return "urn:upnp-org:serviceId:ContentDirectory"; }
316  QString GetServiceControlURL() override // UPnpServiceImpl
317  { return m_sControlUrl.mid( 1 ); }
318  QString GetServiceDescURL() override // UPnpServiceImpl
319  { return m_sControlUrl.mid( 1 ) + "/GetServDesc"; }
320 
321  public:
322  UPnpCDS( UPnpDevice *pDevice,
323  const QString &sSharePath );
324 
325  virtual ~UPnpCDS();
326 
327  void RegisterExtension ( UPnpCDSExtension *pExtension );
328  void UnregisterExtension( UPnpCDSExtension *pExtension );
329 
330  void RegisterShortCut ( UPnPShortcutFeature::ShortCutType type,
331  const QString &objectID );
332  void RegisterFeature ( UPnPFeature *feature );
333 
334  QStringList GetBasePaths() override; // Eventing
335 
336  bool ProcessRequest( HTTPRequest *pRequest ) override; // Eventing
337 };
338 
339 #endif
340 
341 // vim:ts=4:sw=4:ai:et:si:sts=4
QStringList GetBasePaths() override
Definition: eventing.cpp:131
QStringList m_sSearchList
Definition: upnpcds.h:89
QString m_sParentId
Definition: upnpcds.h:83
virtual QString CreateXML()=0
ShortCutType
Allowed values for the Container Shortcut feature.
Definition: upnpcds.h:147
UPnPResultCode
Definition: upnp.h:31
QString m_sFilter
Definition: upnpcds.h:76
QMap< ShortCutType, QString > m_shortcuts
Definition: upnpcds.h:190
UPnpCDSBrowseFlag
Definition: upnpcds.h:42
UPnpCDSExtension(QString sName, QString sExtensionId, QString sClass)
Definition: upnpcds.h:250
QString sHeaderValue
Definition: upnpcds.h:64
QList< CDSObject * > CDSObjects
virtual CDSShortCutList GetShortCuts()
Definition: upnpcds.h:268
QString m_sSortCriteria
Definition: upnpcds.h:79
QString GetServiceId() override
Provides the device specific urn.
Definition: upnpcds.h:314
QList< UPnpCDSExtension * > UPnpCDSExtensionList
Definition: upnpcds.h:271
QString m_sExtensionId
Definition: upnpcds.h:204
QString GetServiceControlURL() override
Provices the base URL for control commands.
Definition: upnpcds.h:316
virtual int GetRootContainerCount()
Definition: upnpcds.h:222
virtual QString GetSortCapabilities()
Definition: upnpcds.h:267
QString m_sSearchCriteria
Definition: upnpcds.h:88
QString m_sObjectId
Definition: upnpcds.h:73
QString GetServiceDescURL() override
Provices the URL of the service description XML.
Definition: upnpcds.h:318
QString GetServiceType() override
Provices the schema urn.
Definition: upnpcds.h:312
virtual int GetRootCount()
Definition: upnpcds.h:221
CDSObject m_root
Definition: upnpcds.h:286
unsigned short uint16_t
Definition: iso6937tables.h:1
UPnpCDSClient nClientType
Definition: upnpcds.h:62
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:143
Standard UPnP Shortcut feature.
Definition: upnpcds.h:136
#define UPNP_PUBLIC
Definition: upnpexp.h:9
QString m_sName
Definition: upnpcds.h:205
QPair< QString, QString > IDToken
Definition: upnpcds.h:198
QString m_sContainerID
Definition: upnpcds.h:75
UPnpCDSExtensionList m_extensions
Definition: upnpcds.h:285
QString m_sControlUrl
Definition: upnpcds.h:289
UPnPFeatureList m_features
Definition: upnpcds.h:291
UPnpCDSMethod
Definition: upnpcds.h:28
QMap< UPnPShortcutFeature::ShortCutType, QString > CDSShortCutList
Definition: upnpcds.h:193
QMap< uint, int > FilterMap
CDSShortCutList m_shortcuts
Definition: upnpcds.h:208
UPnpCDSClient
Definition: upnpcds.h:50
virtual QString GetSearchCapabilities()
Definition: upnpcds.h:266
QString m_sClass
Definition: upnpcds.h:206
QString m_sSearchClass
Definition: upnpcds.h:90
QString m_sServiceDescFileName
Definition: upnpcds.h:288
QMap< QString, QString > IDTokenMap
Definition: upnpcds.h:197