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 
118  UPnpCDSExtensionResults() = default;
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( const QString& sName,
253  QString sExtensionId,
254  QString sClass )
255  {
256  m_sName = QObject::tr(sName.toLatin1().constData());
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
QStringList GetBasePaths() override
Definition: eventing.cpp:129
QPair< QString, QString > IDToken
Definition: upnpcds.h:200
QStringList m_sSearchList
Definition: upnpcds.h:91
QString m_sParentId
Definition: upnpcds.h:85
virtual QString CreateXML()=0
ShortCutType
Allowed values for the Container Shortcut feature.
Definition: upnpcds.h:149
UPnPResultCode
Definition: upnp.h:36
QList< CDSObject * > CDSObjects
QString m_sFilter
Definition: upnpcds.h:78
QList< UPnpCDSExtension * > UPnpCDSExtensionList
Definition: upnpcds.h:273
QMap< ShortCutType, QString > m_shortcuts
Definition: upnpcds.h:192
UPnpCDSExtension(const QString &sName, QString sExtensionId, QString sClass)
Definition: upnpcds.h:252
UPnpCDSBrowseFlag
Definition: upnpcds.h:45
QString sHeaderValue
Definition: upnpcds.h:66
QMap< uint, int > FilterMap
virtual CDSShortCutList GetShortCuts()
Definition: upnpcds.h:270
QString m_sSortCriteria
Definition: upnpcds.h:81
QString GetServiceId() override
Provides the device specific urn.
Definition: upnpcds.h:316
QString m_sExtensionId
Definition: upnpcds.h:206
QString GetServiceControlURL() override
Provices the base URL for control commands.
Definition: upnpcds.h:318
virtual int GetRootContainerCount()
Definition: upnpcds.h:224
virtual QString GetSortCapabilities()
Definition: upnpcds.h:269
QString m_sSearchCriteria
Definition: upnpcds.h:90
QString m_sObjectId
Definition: upnpcds.h:75
QString GetServiceDescURL() override
Provices the URL of the service description XML.
Definition: upnpcds.h:320
QString GetServiceType() override
Provices the schema urn.
Definition: upnpcds.h:314
virtual int GetRootCount()
Definition: upnpcds.h:223
CDSObject m_root
Definition: upnpcds.h:288
UPnpCDSClient nClientType
Definition: upnpcds.h:64
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:141
Standard UPnP Shortcut feature.
Definition: upnpcds.h:138
#define UPNP_PUBLIC
Definition: upnpexp.h:9
QString m_sName
Definition: upnpcds.h:207
QMap< QString, QString > IDTokenMap
Definition: upnpcds.h:199
QString m_sContainerID
Definition: upnpcds.h:77
UPnpCDSExtensionList m_extensions
Definition: upnpcds.h:287
unsigned short uint16_t
Definition: iso6937tables.h:1
QString m_sControlUrl
Definition: upnpcds.h:291
UPnPFeatureList m_features
Definition: upnpcds.h:293
UPnpCDSMethod
Definition: upnpcds.h:32
CDSShortCutList m_shortcuts
Definition: upnpcds.h:210
UPnpCDSClient
Definition: upnpcds.h:52
virtual QString GetSearchCapabilities()
Definition: upnpcds.h:268
QString m_sClass
Definition: upnpcds.h:208
QString m_sSearchClass
Definition: upnpcds.h:92
QString m_sServiceDescFileName
Definition: upnpcds.h:290
QMap< UPnPShortcutFeature::ShortCutType, QString > CDSShortCutList
Definition: upnpcds.h:195