MythTV  master
upnpdevice.cpp
Go to the documentation of this file.
1 // Program Name: upnpdevice.cpp
3 // Created : Oct. 24, 2005
4 //
5 // Purpose : UPnp Device Description parser/generator
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 #include <unistd.h> // for gethostname
14 
15 #include <QFile>
16 #include <QTextStream>
17 #include <QHostAddress>
18 #include <QHostInfo>
19 
20 // MythDB
23 #include "libmythbase/mythdb.h"
26 #include "libmythbase/mythversion.h" // for MYTH_BINARY_VERSION
27 
28 #include "upnp.h"
29 #include "upnpdevice.h"
30 
31 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
32  #define QT_FLUSH flush
33 #else
34  #define QT_FLUSH Qt::flush
35 #endif
36 
37 int DeviceLocation::g_nAllocated = 0; // Debugging only
38 
41 //
42 // UPnpDeviceDesc Class Implementation
43 //
46 
48 //
50 
51 bool UPnpDeviceDesc::Load( const QString &sFileName )
52 {
53  // ----------------------------------------------------------------------
54  // Open Supplied XML uPnp Description file.
55  // ----------------------------------------------------------------------
56 
57  QDomDocument doc ( "upnp" );
58  QFile file( sFileName );
59 
60  if ( !file.open( QIODevice::ReadOnly ) )
61  return false;
62 
63  QString sErrMsg;
64  int nErrLine = 0;
65  int nErrCol = 0;
66  bool bSuccess = doc.setContent( &file, false,
67  &sErrMsg, &nErrLine, &nErrCol );
68 
69  file.close();
70 
71  if (!bSuccess)
72  {
73  LOG(VB_GENERAL, LOG_ERR,
74  QString("UPnpDeviceDesc::Load - Error parsing: %1 "
75  "at line: %2 column: %3")
76  .arg(sFileName) .arg(nErrLine)
77  .arg(nErrCol));
78  LOG(VB_GENERAL, LOG_ERR,
79  QString("UPnpDeviceDesc::Load - Error Msg: %1" ) .arg(sErrMsg));
80  return false;
81  }
82 
83  // --------------------------------------------------------------
84  // XML Document Loaded... now parse it into the UPnpDevice Hierarchy
85  // --------------------------------------------------------------
86 
87  return Load( doc );
88 }
89 
91 //
93 
94 bool UPnpDeviceDesc::Load( const QDomDocument &xmlDevDesc )
95 {
96  // --------------------------------------------------------------
97  // Parse XML into the UPnpDevice Hierarchy
98  // --------------------------------------------------------------
99 
100  QDomNode oNode = xmlDevDesc.documentElement();
101 
102  InternalLoad( oNode.namedItem( "device" ), &m_rootDevice );
103 
104  return true;
105 }
106 
108 //
110 
111 void UPnpDeviceDesc::InternalLoad( QDomNode oNode, UPnpDevice *pCurDevice )
112 {
113  QString pin = GetMythDB()->GetSetting( "SecurityPin", "");
114  pCurDevice->m_securityPin = !(pin.isEmpty() || pin == "0000");
115 
116  for ( oNode = oNode.firstChild();
117  !oNode.isNull();
118  oNode = oNode.nextSibling() )
119  {
120  QDomElement e = oNode.toElement();
121 
122  if (e.isNull())
123  continue;
124 
125  // TODO: make this table driven (using offset within structure)
126  if ( e.tagName() == "deviceType" )
127  SetStrValue( e, pCurDevice->m_sDeviceType);
128  else if ( e.tagName() == "friendlyName" )
129  SetStrValue( e, pCurDevice->m_sFriendlyName );
130  else if ( e.tagName() == "manufacturer" )
131  SetStrValue( e, pCurDevice->m_sManufacturer );
132  else if ( e.tagName() == "manufacturerURL" )
133  SetStrValue( e, pCurDevice->m_sManufacturerURL );
134  else if ( e.tagName() == "modelDescription" )
135  SetStrValue( e, pCurDevice->m_sModelDescription);
136  else if ( e.tagName() == "modelName" )
137  SetStrValue( e, pCurDevice->m_sModelName );
138  else if ( e.tagName() == "modelNumber" )
139  SetStrValue( e, pCurDevice->m_sModelNumber );
140  else if ( e.tagName() == "modelURL" )
141  SetStrValue( e, pCurDevice->m_sModelURL );
142  else if ( e.tagName() == "serialNumber" )
143  SetStrValue( e, pCurDevice->m_sSerialNumber );
144  else if ( e.tagName() == "UPC" )
145  SetStrValue( e, pCurDevice->m_sUPC );
146  else if ( e.tagName() == "presentationURL" )
147  SetStrValue( e, pCurDevice->m_sPresentationURL );
148  else if ( e.tagName() == "UDN" )
149  SetStrValue( e, pCurDevice->m_sUDN );
150  else if ( e.tagName() == "iconList" )
151  ProcessIconList( oNode, pCurDevice );
152  else if ( e.tagName() == "serviceList" )
153  ProcessServiceList( oNode, pCurDevice );
154  else if ( e.tagName() == "deviceList" )
155  ProcessDeviceList ( oNode, pCurDevice );
156  else if ( e.tagName() == "mythtv:X_secure" )
157  SetBoolValue( e, pCurDevice->m_securityPin );
158  else if ( e.tagName() == "mythtv:X_protocol" )
159  SetStrValue( e, pCurDevice->m_protocolVersion );
160  else
161  {
162  // Not one of the expected element names... add to extra list.
163  QString sValue = "";
164  SetStrValue( e, sValue );
165  NameValue node = NameValue(e.tagName(), sValue);
166  QDomNamedNodeMap attributes = e.attributes();
167  for (int i = 0; i < attributes.size(); i++)
168  {
169  node.AddAttribute(attributes.item(i).nodeName(),
170  attributes.item(i).nodeValue(),
171  true); // TODO Check whether all attributes are in fact requires for the device xml
172  }
173  pCurDevice->m_lstExtra.push_back(node);
174  }
175  }
176 }
177 
179 //
181 
182 void UPnpDeviceDesc::ProcessIconList( const QDomNode& oListNode, UPnpDevice *pDevice )
183 {
184  for ( QDomNode oNode = oListNode.firstChild();
185  !oNode.isNull();
186  oNode = oNode.nextSibling() )
187  {
188  QDomElement e = oNode.toElement();
189 
190  if (e.isNull())
191  continue;
192 
193  if ( e.tagName() == "icon" )
194  {
195  auto *pIcon = new UPnpIcon();
196  pDevice->m_listIcons.append( pIcon );
197 
198  SetStrValue( e.namedItem( "mimetype" ), pIcon->m_sMimeType );
199  SetNumValue( e.namedItem( "width" ), pIcon->m_nWidth );
200  SetNumValue( e.namedItem( "height" ), pIcon->m_nHeight );
201  SetNumValue( e.namedItem( "depth" ), pIcon->m_nDepth );
202  SetStrValue( e.namedItem( "url" ), pIcon->m_sURL );
203  }
204  }
205 }
206 
208 //
210 
211 void UPnpDeviceDesc::ProcessServiceList( const QDomNode& oListNode, UPnpDevice *pDevice )
212 {
213  for ( QDomNode oNode = oListNode.firstChild();
214  !oNode.isNull();
215  oNode = oNode.nextSibling() )
216  {
217  QDomElement e = oNode.toElement();
218 
219  if (e.isNull())
220  continue;
221 
222  if ( e.tagName() == "service" )
223  {
224  auto *pService = new UPnpService();
225  pDevice->m_listServices.append( pService );
226 
227  SetStrValue(e.namedItem( "serviceType" ), pService->m_sServiceType);
228  SetStrValue(e.namedItem( "serviceId" ), pService->m_sServiceId);
229  SetStrValue(e.namedItem( "SCPDURL" ), pService->m_sSCPDURL);
230  SetStrValue(e.namedItem( "controlURL" ), pService->m_sControlURL);
231  SetStrValue(e.namedItem( "eventSubURL" ), pService->m_sEventSubURL);
232 
233  LOG(VB_UPNP, LOG_INFO,
234  QString("ProcessServiceList adding service : %1 : %2 :")
235  .arg(pService->m_sServiceType,
236  pService->m_sServiceId));
237  }
238  }
239 }
240 
242 //
244 
245 void UPnpDeviceDesc::ProcessDeviceList( const QDomNode& oListNode,
246  UPnpDevice *pDevice )
247 {
248  for ( QDomNode oNode = oListNode.firstChild();
249  !oNode.isNull();
250  oNode = oNode.nextSibling() )
251  {
252  QDomElement e = oNode.toElement();
253 
254  if (e.isNull())
255  continue;
256 
257  if ( e.tagName() == "device")
258  {
259  auto *pNewDevice = new UPnpDevice();
260  pDevice->m_listDevices.append( pNewDevice );
261  InternalLoad( e, pNewDevice );
262  }
263  }
264 }
265 
268 void UPnpDeviceDesc::SetStrValue( const QDomNode &n, QString &sValue )
269 {
270  if (!n.isNull())
271  {
272  QDomText oText = n.firstChild().toText();
273 
274  if (!oText.isNull())
275  sValue = oText.nodeValue();
276  }
277 }
278 
281 void UPnpDeviceDesc::SetNumValue( const QDomNode &n, int &nValue )
282 {
283  if (!n.isNull())
284  {
285  QDomText oText = n.firstChild().toText();
286 
287  if (!oText.isNull())
288  nValue = oText.nodeValue().toInt();
289  }
290 }
291 
292 void UPnpDeviceDesc::SetBoolValue( const QDomNode &n, bool &nValue )
293 {
294  if (!n.isNull())
295  {
296  QDomText oText = n.firstChild().toText();
297 
298  if (!oText.isNull())
299  {
300  QString s = oText.nodeValue();
301  nValue = (s == "yes" || s == "true" || (s.toInt() != 0));
302  }
303  }
304 }
305 
307 //
309 
310 QString UPnpDeviceDesc::GetValidXML( const QString &sBaseAddress, int nPort )
311 {
312  QString sXML;
313  QTextStream os( &sXML, QIODevice::WriteOnly );
314 
315  GetValidXML( sBaseAddress, nPort, os );
316  os << QT_FLUSH;
317  return( sXML );
318 }
319 
321 //
323 
325  const QString &/*sBaseAddress*/, int /*nPort*/,
326  QTextStream &os, const QString &sUserAgent )
327 {
328 #if 0
329  os.setEncoding( QTextStream::UnicodeUTF8 );
330 #endif
331  os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
332  "<root xmlns=\"urn:schemas-upnp-org:device-1-0\" "
333  " xmlns:mythtv=\"mythtv.org\">\n"
334  "<specVersion>\n"
335  "<major>1</major>\n"
336  "<minor>0</minor>\n"
337  "</specVersion>\n";
338 
339  OutputDevice( os, &m_rootDevice, sUserAgent );
340 
341  os << "</root>\n";
342  os << QT_FLUSH;
343 }
344 
346 //
348 
349 void UPnpDeviceDesc::OutputDevice( QTextStream &os,
350  UPnpDevice *pDevice,
351  const QString &sUserAgent )
352 {
353  if (pDevice == nullptr)
354  return;
355 
356  QString sFriendlyName = QString( "%1: %2" )
357  .arg( GetHostName(),
358  pDevice->m_sFriendlyName );
359 
360  // ----------------------------------------------------------------------
361  // Only override the root device
362  // ----------------------------------------------------------------------
363 
364  if (pDevice == &m_rootDevice)
365  sFriendlyName = XmlConfiguration().GetValue("UPnP/FriendlyName", sFriendlyName);
366 
367  os << "<device>\n";
368  os << FormatValue( "deviceType" , pDevice->m_sDeviceType );
369  os << FormatValue( "friendlyName" , sFriendlyName );
370 
371  // ----------------------------------------------------------------------
372  // XBox 360 needs specific values in the Device Description.
373  //
374  // -=>TODO: This should be externalized in a more generic/extension
375  // kind of way.
376  // ----------------------------------------------------------------------
377 
378  bool bIsXbox360 =
379  sUserAgent.startsWith(QString("Xbox/2.0"), Qt::CaseInsensitive) ||
380  sUserAgent.startsWith(QString("Mozilla/4.0"), Qt::CaseInsensitive);
381 
382  os << FormatValue( "manufacturer" , pDevice->m_sManufacturer );
383  os << FormatValue( "modelURL" , pDevice->m_sModelURL );
384 
385  // HACK
386 // if ( bIsXbox360 )
387 // {
388 // os << FormatValue( "modelName" ,
389 // "Windows Media Connect Compatible (MythTV)");
390 // }
391 // else
392 // {
393  os << FormatValue( "modelName" , pDevice->m_sModelName );
394 // }
395 
396  os << FormatValue( "manufacturerURL" , pDevice->m_sManufacturerURL );
397  os << FormatValue( "modelDescription" , pDevice->m_sModelDescription);
398  os << FormatValue( "modelNumber" , pDevice->m_sModelNumber );
399  os << FormatValue( "serialNumber" , pDevice->m_sSerialNumber );
400  os << FormatValue( "UPC" , pDevice->m_sUPC );
401  os << FormatValue( "presentationURL" , pDevice->m_sPresentationURL );
402 
403  // MythTV Custom information
404  os << FormatValue( "mythtv:X_secure" ,
405  pDevice->m_securityPin ? "true" : "false");
406  os << FormatValue( "mythtv:X_protocol", pDevice->m_protocolVersion );
407 
408  for (const auto & nit : qAsConst(pDevice->m_lstExtra))
409  {
410  os << FormatValue( nit );
411  }
412 
413  // ----------------------------------------------------------------------
414  // Output Any Icons.
415  // ----------------------------------------------------------------------
416 
417  if (pDevice->m_listIcons.count() > 0)
418  {
419  os << "<iconList>\n";
420 
421  for (auto *icon : qAsConst(pDevice->m_listIcons))
422  {
423  os << "<icon>\n";
424  os << FormatValue( "mimetype", icon->m_sMimeType );
425  os << FormatValue( "width" , icon->m_nWidth );
426  os << FormatValue( "height" , icon->m_nHeight );
427  os << FormatValue( "depth" , icon->m_nDepth );
428  os << FormatValue( "url" , icon->m_sURL );
429  os << "</icon>\n";
430  }
431  os << "</iconList>\n";
432  }
433 
434  os << FormatValue( "UDN" , pDevice->GetUDN() );
435 
436  // ----------------------------------------------------------------------
437  // Output any Services
438  // ----------------------------------------------------------------------
439 
440  if (pDevice->m_listServices.count() > 0)
441  {
442  // ------------------------------------------------------------------
443  // -=>TODO: As a temporary fix don't expose the MSRR service unless we
444  // as an XBox360 or Windows MediaPlayer.
445  //
446  // There is a problem with a DSM-520 with firmware 1.04 and
447  // the Denon AVR-4306 receiver.
448  //
449  // If the MSRR Service is exposed, it won't let us browse
450  // any media content.
451  //
452  // Need to find out real fix and remove this code.
453  // ------------------------------------------------------------------
454 
455 #if 0
456  bool bDSM = sUserAgent.startsWith("INTEL_NMPR/2.1 DLNADOC/1.00", false);
457 #endif
458 
459  os << "<serviceList>\n";
460 
461  for (auto *service : qAsConst(pDevice->m_listServices))
462  {
463  if (!bIsXbox360 && service->m_sServiceType.startsWith(
464  "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar",
465  Qt::CaseInsensitive))
466  {
467  continue;
468  }
469 
470  os << "<service>\n";
471  os << FormatValue( "serviceType", service->m_sServiceType );
472  os << FormatValue( "serviceId" , service->m_sServiceId );
473  os << FormatValue( "SCPDURL" , service->m_sSCPDURL );
474  os << FormatValue( "controlURL" , service->m_sControlURL );
475  os << FormatValue( "eventSubURL", service->m_sEventSubURL );
476  os << "</service>\n";
477  }
478  os << "</serviceList>\n";
479  }
480 
481  // ----------------------------------------------------------------------
482  // Output any Embedded Devices
483  // ----------------------------------------------------------------------
484 
485  if (pDevice->m_listDevices.count() > 0)
486  {
487  os << "<deviceList>";
488 
489  UPnpDeviceList::iterator it;
490  for ( it = pDevice->m_listDevices.begin();
491  it != pDevice->m_listDevices.end();
492  ++it )
493  {
494  UPnpDevice *pEmbeddedDevice = (*it);
495  OutputDevice( os, pEmbeddedDevice );
496  }
497  os << "</deviceList>";
498  }
499  os << "</device>\n";
500  os << QT_FLUSH;
501 }
502 
504 //
506 
508 {
509  QString sStr;
510 
511  QString sAttributes;
512  NameValues::iterator it;
513  for (it = node.m_pAttributes->begin(); it != node.m_pAttributes->end(); ++it)
514  {
515  sAttributes += QString(" %1='%2'").arg((*it).m_sName, (*it).m_sValue);
516  }
517  sStr = QString("<%1%2>%3</%1>\n").arg(node.m_sName, sAttributes, node.m_sValue);
518 
519  return( sStr );
520 }
521 
523 //
525 
526 QString UPnpDeviceDesc::FormatValue( const QString &sName,
527  const QString &sValue )
528 {
529  QString sStr;
530 
531  if (sValue.length() > 0)
532  sStr = QString("<%1>%2</%1>\n") .arg(sName, sValue);
533 
534  return( sStr );
535 }
536 
538 
539 QString UPnpDeviceDesc::FormatValue( const QString &sName, int nValue )
540 {
541  return( QString("<%1>%2</%1>\n") .arg(sName) .arg(nValue) );
542 }
543 
545 //
547 
548 QString UPnpDeviceDesc::FindDeviceUDN( UPnpDevice *pDevice, QString sST )
549 {
550  // Ignore device version, UPnP is backwards compatible
551  if (sST.section(':', 0, -2) == pDevice->m_sDeviceType.section(':', 0, -2))
552  return pDevice->GetUDN();
553 
554  if (sST.section(':', 0, -2) == pDevice->GetUDN().section(':', 0, -2))
555  return sST;
556 
557  // ----------------------------------------------------------------------
558  // Check for matching Service
559  // ----------------------------------------------------------------------
560 
561  for (auto sit = pDevice->m_listServices.cbegin();
562  sit != pDevice->m_listServices.cend(); ++sit)
563  {
564  // Ignore the service version, UPnP is backwards compatible
565  if (sST.section(':', 0, -2) == (*sit)->m_sServiceType.section(':', 0, -2))
566  return pDevice->GetUDN();
567  }
568 
569  // ----------------------------------------------------------------------
570  // Check Embedded Devices for a Match
571  // ----------------------------------------------------------------------
572 
573  for (auto *device : qAsConst(pDevice->m_listDevices))
574  {
575  QString sUDN = FindDeviceUDN( device, sST );
576  if (sUDN.length() > 0)
577  return sUDN;
578  }
579 
580  return "";
581 }
582 
584 //
586 
587 UPnpDevice *UPnpDeviceDesc::FindDevice( const QString &sURI )
588 {
589  return FindDevice( &m_rootDevice, sURI );
590 }
591 
593 //
595 
597  const QString &sURI )
598 {
599  // Ignore device version, UPnP is backwards compatible
600  if ( sURI.section(':', 0, -2) == pDevice->m_sDeviceType.section(':', 0, -2) )
601  return pDevice;
602 
603  // ----------------------------------------------------------------------
604  // Check Embedded Devices for a Match
605  // ----------------------------------------------------------------------
606 
607  for (const auto & dev : qAsConst(pDevice->m_listDevices))
608  {
609  UPnpDevice *pFound = FindDevice(dev, sURI);
610 
611  if (pFound != nullptr)
612  return pFound;
613  }
614 
615  return nullptr;
616 }
617 
619 //
621 
623 {
624  UPnpDeviceDesc *pDevice = nullptr;
625 
626  LOG(VB_UPNP, LOG_DEBUG, QString("UPnpDeviceDesc::Retrieve( %1 )")
627  .arg(sURL));
628 
629  QByteArray buffer;
630 
631  bool ok = GetMythDownloadManager()->download(sURL, &buffer);
632 
633  QString sXml(buffer);
634 
635  if (ok && sXml.startsWith( QString("<?xml") ))
636  {
637  QString sErrorMsg;
638 
639  QDomDocument xml( "upnp" );
640 
641  if ( xml.setContent( sXml, false, &sErrorMsg ))
642  {
643  pDevice = new UPnpDeviceDesc();
644  pDevice->Load( xml );
645  pDevice->m_hostUrl = sURL;
646  pDevice->m_sHostName = pDevice->m_hostUrl.host();
647  }
648  else
649  {
650  LOG(VB_UPNP, LOG_ERR,
651  QString("Error parsing device description xml [%1]")
652  .arg(sErrorMsg));
653  }
654  }
655  else
656  {
657  LOG(VB_UPNP, LOG_ERR, QString("Invalid response '%1'").arg(sXml));
658  }
659 
660  return pDevice;
661 }
662 
664 //
666 
668 {
669  if (m_sHostName.length() == 0)
670  {
671  // Get HostName
672 
673  QString localHostName = QHostInfo::localHostName();
674  if (localHostName.isEmpty())
675  LOG(VB_GENERAL, LOG_ERR,
676  "UPnpDeviceDesc: Error, could not determine host name." + ENO);
677 
678  return XmlConfiguration().GetValue("Settings/HostName", localHostName);
679  }
680 
681  return m_sHostName;
682 }
683 
686 //
687 // UPnpDevice Class Implementation
688 //
691 
693  m_sModelNumber(MYTH_BINARY_VERSION),
694  m_sSerialNumber(GetMythSourceVersion()),
695  m_protocolVersion(MYTH_PROTO_VERSION)
696 {
697 
698 // FIXME: UPnPDevice is created via the static initialisation of UPnPDeviceDesc
699 // in upnp.cpp ln 21. This means it's created before the core context is
700 // even intialised so we can't use settings, or any 'core' methods to
701 // help in populating the Device metadata. That is why the URLs below
702 // are relative, not absolute since at this stage we can't determine
703 // which IP or port to use!
704 
705 // NOTE: The icons are defined here and not in devicemaster.xml because they
706 // are also used for the MediaRenderer device and other possible future
707 // devices too.
708 
709  // Large PNG Icon
710  auto *pngIconLrg = new UPnpIcon();
711  pngIconLrg->m_nDepth = 24;
712  pngIconLrg->m_nHeight = 120;
713  pngIconLrg->m_nWidth = 120;
714  pngIconLrg->m_sMimeType = "image/png";
715  pngIconLrg->m_sURL = "/images/icons/upnp_large_icon.png";
716  m_listIcons.append(pngIconLrg);
717 
718  // Large JPG Icon
719  auto *jpgIconLrg = new UPnpIcon();
720  jpgIconLrg->m_nDepth = 24;
721  jpgIconLrg->m_nHeight = 120;
722  jpgIconLrg->m_nWidth = 120;
723  jpgIconLrg->m_sMimeType = "image/jpeg";
724  jpgIconLrg->m_sURL = "/images/icons/upnp_large_icon.jpg";
725  m_listIcons.append(jpgIconLrg);
726 
727  // Small PNG Icon
728  auto *pngIconSm = new UPnpIcon();
729  pngIconSm->m_nDepth = 24;
730  pngIconSm->m_nHeight = 48;
731  pngIconSm->m_nWidth = 48;
732  pngIconSm->m_sMimeType = "image/png";
733  pngIconSm->m_sURL = "/images/icons/upnp_small_icon.png";
734  m_listIcons.append(pngIconSm);
735 
736  // Small JPG Icon
737  auto *jpgIconSm = new UPnpIcon();
738  jpgIconSm->m_nDepth = 24;
739  jpgIconSm->m_nHeight = 48;
740  jpgIconSm->m_nWidth = 48;
741  jpgIconSm->m_sMimeType = "image/jpeg";
742  jpgIconSm->m_sURL = "/images/icons/upnp_small_icon.jpg";
743  m_listIcons.append(jpgIconSm);
744 }
745 
747 {
748  while (!m_listIcons.empty())
749  {
750  delete m_listIcons.back();
751  m_listIcons.pop_back();
752  }
753  while (!m_listServices.empty())
754  {
755  delete m_listServices.back();
756  m_listServices.pop_back();
757  }
758  while (!m_listDevices.empty())
759  {
760  delete m_listDevices.back();
761  m_listDevices.pop_back();
762  }
763 }
764 
765 QString UPnpDevice::GetUDN(void) const
766 {
767  if (m_sUDN.isEmpty())
768  m_sUDN = "uuid:" + LookupUDN( m_sDeviceType );
769 
770  return m_sUDN;
771 }
772 
773 void UPnpDevice::toMap(InfoMap &map) const
774 {
775  map["name"] = m_sFriendlyName;
776  map["modelname"] = m_sModelName;
777  map["modelnumber"] = m_sModelNumber;
778  map["modelurl"] = m_sModelURL;
779  map["modeldescription"] = m_sModelDescription;
780  map["manufacturer"] = m_sManufacturer;
781  map["manufacturerurl"] = m_sManufacturerURL;
782  map["devicetype"] = m_sDeviceType;
783  map["serialnumber"] = m_sSerialNumber;
784  map["UDN"] = m_sUDN;
785  map["UPC"] = m_sUPC;
786  map["protocolversion"] = m_protocolVersion;
787 }
788 
789 UPnpService UPnpDevice::GetService(const QString &urn, bool *found) const
790 {
791  UPnpService srv;
792 
793  bool done = false;
794 
795  for (auto *service : qAsConst(m_listServices))
796  {
797  // Ignore the service version
798  if (service->m_sServiceType.section(':', 0, -2) == urn.section(':', 0, -2))
799  {
800  srv = *service;
801  done = true;
802  break;
803  }
804  }
805 
806  if (!done)
807  {
808  UPnpDeviceList::const_iterator dit = m_listDevices.begin();
809  for (; dit != m_listDevices.end() && !done; ++dit)
810  srv = (*dit)->GetService(urn, &done);
811  }
812 
813  if (found)
814  *found = done;
815 
816  return srv;
817 }
818 
819 QString UPnpDevice::toString(uint padding) const
820 {
821  QString ret =
822  QString("UPnP Device\n"
823  "===========\n"
824  "deviceType: %1\n"
825  "friendlyName: %2\n"
826  "manufacturer: %3\n"
827  "manufacturerURL: %4\n"
828  "modelDescription: %5\n"
829  "modelName: %6\n"
830  "modelNumber: %7\n"
831  "modelURL: %8\n")
832  .arg(m_sDeviceType,
837  m_sModelName,
839  m_sModelURL) +
840  QString("serialNumber: %1\n"
841  "UPC: %2\n"
842  "presentationURL: %3\n"
843  "UDN: %4\n")
844  .arg(m_sSerialNumber,
845  m_sUPC,
847  m_sUDN);
848 
849  if (!m_lstExtra.empty())
850  {
851  ret += "Extra key value pairs\n";
852  for (const auto & extra : qAsConst(m_lstExtra))
853  {
854  ret += extra.m_sName;
855  ret += ":";
856  int int_padding = 18 - (extra.m_sName.length() + 1);
857  for (int i = 0; i < int_padding; i++)
858  ret += " ";
859  ret += QString("%1\n").arg(extra.m_sValue);
860  }
861  }
862 
863  if (!m_listIcons.empty())
864  {
865  ret += "Icon List:\n";
866  for (auto *icon : qAsConst(m_listIcons))
867  ret += icon->toString(padding+2) + "\n";
868  }
869 
870  if (!m_listServices.empty())
871  {
872  ret += "Service List:\n";
873  for (auto *service : qAsConst(m_listServices))
874  ret += service->toString(padding+2) + "\n";
875  }
876 
877  if (!m_listDevices.empty())
878  {
879  ret += "Device List:\n";
880  for (auto *device : qAsConst(m_listDevices))
881  ret += device->toString(padding+2) + "\n";
882  ret += "\n";
883  }
884 
885  // remove trailing newline
886  if (ret.endsWith("\n"))
887  ret = ret.left(ret.length()-1);
888 
889  // add any padding as necessary
890  if (padding)
891  {
892  QString pad;
893  for (uint i = 0; i < padding; i++)
894  pad += " ";
895  ret = pad + ret.replace("\n", QString("\n%1").arg(pad));
896  }
897 
898  return ret;
899 }
UPnpDevice::m_sModelURL
QString m_sModelURL
Definition: upnpdevice.h:113
NameValue
Definition: upnputil.h:40
UPnpDevice::~UPnpDevice
~UPnpDevice()
Definition: upnpdevice.cpp:746
DeviceLocation::g_nAllocated
static int g_nAllocated
Definition: upnpdevice.h:214
UPnpDevice::m_sManufacturer
QString m_sManufacturer
Definition: upnpdevice.h:108
UPnpDevice::m_listIcons
UPnpIconList m_listIcons
Definition: upnpdevice.h:125
ENO
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:73
upnpdevice.h
UPnpDeviceDesc::UPnpDeviceDesc
UPnpDeviceDesc()=default
UPnpDeviceDesc::GetValidXML
void GetValidXML(const QString &sBaseAddress, int nPort, QTextStream &os, const QString &sUserAgent="")
Definition: upnpdevice.cpp:324
UPnpDeviceDesc::GetHostName
QString GetHostName() const
Definition: upnpdevice.cpp:667
UPnpDeviceDesc::Retrieve
static UPnpDeviceDesc * Retrieve(QString &sURL)
Definition: upnpdevice.cpp:622
UPnpDeviceDesc::InternalLoad
void InternalLoad(QDomNode oNode, UPnpDevice *pCurDevice)
Definition: upnpdevice.cpp:111
mythdb.h
NameValue::m_sName
QString m_sName
Definition: upnputil.h:43
UPnpDevice::m_listServices
UPnpServiceList m_listServices
Definition: upnpdevice.h:126
UPnpDevice::GetService
UPnpService GetService(const QString &urn, bool *found=nullptr) const
Definition: upnpdevice.cpp:789
UPnpDevice::m_sUPC
QString m_sUPC
Definition: upnpdevice.h:115
UPnpDevice::toString
QString toString(uint padding=0) const
Definition: upnpdevice.cpp:819
GetMythSourceVersion
const char * GetMythSourceVersion()
Definition: mythversion.cpp:5
UPnpDeviceDesc
Definition: upnpdevice.h:151
UPnpDevice::m_sDeviceType
QString m_sDeviceType
Definition: upnpdevice.h:106
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
UPnpDeviceDesc::FindDeviceUDN
QString FindDeviceUDN(UPnpDevice *pDevice, QString sST)
Definition: upnpdevice.cpp:548
GetMythDB
MythDB * GetMythDB(void)
Definition: mythdb.cpp:50
build_compdb.file
file
Definition: build_compdb.py:55
UPnpDevice::m_sUDN
QString m_sUDN
Definition: upnpdevice.h:117
XmlConfiguration
Definition: configuration.h:38
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
UPnpDeviceDesc::ProcessServiceList
static void ProcessServiceList(const QDomNode &oListNode, UPnpDevice *pDevice)
Definition: upnpdevice.cpp:211
LookupUDN
QString LookupUDN(const QString &sDeviceType)
Definition: upnputil.cpp:46
NameValue::AddAttribute
void AddAttribute(const QString &name, const QString &value, bool required)
Definition: upnputil.h:117
UPnpDeviceDesc::m_rootDevice
UPnpDevice m_rootDevice
Definition: upnpdevice.h:155
UPnpDeviceDesc::SetBoolValue
static void SetBoolValue(const QDomNode &n, bool &nValue)
Definition: upnpdevice.cpp:292
upnp.h
UPnpDevice::toMap
void toMap(InfoMap &map) const
Definition: upnpdevice.cpp:773
UPnpDevice::m_sModelName
QString m_sModelName
Definition: upnpdevice.h:111
mythlogging.h
UPnpDevice::m_securityPin
bool m_securityPin
MythTV specific information.
Definition: upnpdevice.h:122
UPnpDeviceDesc::m_sHostName
QString m_sHostName
Definition: upnpdevice.h:156
UPnpDevice::m_sModelNumber
QString m_sModelNumber
Definition: upnpdevice.h:112
UPnpDevice::m_lstExtra
NameValues m_lstExtra
Definition: upnpdevice.h:119
UPnpIcon
Definition: upnpdevice.h:49
UPnpDevice::m_sSerialNumber
QString m_sSerialNumber
Definition: upnpdevice.h:114
UPnpDevice::m_listDevices
UPnpDeviceList m_listDevices
Definition: upnpdevice.h:127
UPnpDeviceDesc::FormatValue
static QString FormatValue(const NameValue &node)
Definition: upnpdevice.cpp:507
MythDownloadManager::download
bool download(const QString &url, const QString &dest, bool reload=false)
Downloads a URL to a file in blocking mode.
Definition: mythdownloadmanager.cpp:430
UPnpDevice
Definition: upnpdevice.h:102
UPnpDevice::m_sFriendlyName
QString m_sFriendlyName
Definition: upnpdevice.h:107
UPnpDeviceDesc::m_hostUrl
QUrl m_hostUrl
Definition: upnpdevice.h:157
uint
unsigned int uint
Definition: compat.h:81
UPnpDevice::UPnpDevice
UPnpDevice()
Definition: upnpdevice.cpp:692
UPnpDeviceDesc::ProcessDeviceList
void ProcessDeviceList(const QDomNode &oListNode, UPnpDevice *pDevice)
Definition: upnpdevice.cpp:245
XmlConfiguration::GetValue
QString GetValue(const QString &setting)
Definition: configuration.cpp:191
NameValue::m_pAttributes
NameValues * m_pAttributes
Definition: upnputil.h:47
UPnpService
Definition: upnpdevice.h:73
UPnpDeviceDesc::SetNumValue
static void SetNumValue(const QDomNode &n, int &nValue)
Sets nValue param to n.firstChild().toText().nodeValue(), iff neither n.isNull() nor n....
Definition: upnpdevice.cpp:281
mythcorecontext.h
UPnpDeviceDesc::Load
bool Load(const QString &sFileName)
Definition: upnpdevice.cpp:51
QT_FLUSH
#define QT_FLUSH
Definition: upnpdevice.cpp:34
UPnpDevice::m_sModelDescription
QString m_sModelDescription
Definition: upnpdevice.h:110
configuration.h
UPnpDevice::m_sManufacturerURL
QString m_sManufacturerURL
Definition: upnpdevice.h:109
UPnpDevice::m_protocolVersion
QString m_protocolVersion
Definition: upnpdevice.h:123
UPnpDeviceDesc::SetStrValue
static void SetStrValue(const QDomNode &n, QString &sValue)
Sets sValue param to n.firstChild().toText().nodeValue(), iff neither n.isNull() nor n....
Definition: upnpdevice.cpp:268
UPnpDeviceDesc::FindDevice
UPnpDevice * FindDevice(const QString &sURI)
Definition: upnpdevice.cpp:587
UPnpDevice::GetUDN
QString GetUDN(void) const
Definition: upnpdevice.cpp:765
UPnpDevice::m_sPresentationURL
QString m_sPresentationURL
Definition: upnpdevice.h:116
UPnpDeviceDesc::ProcessIconList
static void ProcessIconList(const QDomNode &oListNode, UPnpDevice *pDevice)
Definition: upnpdevice.cpp:182
mythdownloadmanager.h
NameValue::m_sValue
QString m_sValue
Definition: upnputil.h:44
GetMythDownloadManager
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
Definition: mythdownloadmanager.cpp:145
UPnpDeviceDesc::OutputDevice
void OutputDevice(QTextStream &os, UPnpDevice *pDevice, const QString &sUserAgent="")
Definition: upnpdevice.cpp:349