18#include <QHostAddress>
26#include "libmythbase/mythversion.h"
48 QDomDocument doc (
"upnp" );
49 QFile
file( sFileName );
51 if ( !
file.open( QIODevice::ReadOnly ) )
54#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
58 bool bSuccess = doc.setContent( &
file,
false,
59 &sErrMsg, &nErrLine, &nErrCol );
65 LOG(VB_GENERAL, LOG_ERR,
66 QString(
"UPnpDeviceDesc::Load - Error parsing: %1 "
67 "at line: %2 column: %3")
68 .arg(sFileName) .arg(nErrLine)
70 LOG(VB_GENERAL, LOG_ERR,
71 QString(
"UPnpDeviceDesc::Load - Error Msg: %1" ) .arg(sErrMsg));
75 auto parseResult = doc.setContent( &
file );
81 LOG(VB_GENERAL, LOG_ERR,
82 QString(
"UPnpDeviceDesc::Load - Error parsing: %1 "
83 "at line: %2 column: %3")
84 .arg(sFileName) .arg(parseResult.errorLine)
85 .arg(parseResult.errorColumn));
86 LOG(VB_GENERAL, LOG_ERR,
87 QString(
"UPnpDeviceDesc::Load - Error Msg: %1" ) .arg(parseResult.errorMessage));
109 QDomNode oNode = xmlDevDesc.documentElement();
122 QString pin =
GetMythDB()->GetSetting(
"SecurityPin",
"");
123 pCurDevice->
m_securityPin = !(pin.isEmpty() || pin ==
"0000");
125 for ( oNode = oNode.firstChild();
127 oNode = oNode.nextSibling() )
129 QDomElement e = oNode.toElement();
135 if ( e.tagName() ==
"deviceType" ) {
137 }
else if ( e.tagName() ==
"friendlyName" ) {
139 }
else if ( e.tagName() ==
"manufacturer" ) {
141 }
else if ( e.tagName() ==
"manufacturerURL" ) {
143 }
else if ( e.tagName() ==
"modelDescription" ) {
145 }
else if ( e.tagName() ==
"modelName" ) {
147 }
else if ( e.tagName() ==
"modelNumber" ) {
149 }
else if ( e.tagName() ==
"modelURL" ) {
151 }
else if ( e.tagName() ==
"serialNumber" ) {
153 }
else if ( e.tagName() ==
"UPC" ) {
155 }
else if ( e.tagName() ==
"presentationURL" ) {
157 }
else if ( e.tagName() ==
"UDN" ) {
159 }
else if ( e.tagName() ==
"iconList" ) {
161 }
else if ( e.tagName() ==
"serviceList" ) {
163 }
else if ( e.tagName() ==
"deviceList" ) {
165 }
else if ( e.tagName() ==
"mythtv:X_secure" ) {
167 }
else if ( e.tagName() ==
"mythtv:X_protocol" ) {
174 QDomNamedNodeMap attributes = e.attributes();
175 for (
int i = 0; i < attributes.size(); i++)
178 attributes.item(i).nodeValue(),
192 for ( QDomNode oNode = oListNode.firstChild();
194 oNode = oNode.nextSibling() )
196 QDomElement e = oNode.toElement();
201 if ( e.tagName() ==
"icon" )
206 SetStrValue( e.namedItem(
"mimetype" ), pIcon->m_sMimeType );
207 SetNumValue( e.namedItem(
"width" ), pIcon->m_nWidth );
208 SetNumValue( e.namedItem(
"height" ), pIcon->m_nHeight );
209 SetNumValue( e.namedItem(
"depth" ), pIcon->m_nDepth );
210 SetStrValue( e.namedItem(
"url" ), pIcon->m_sURL );
221 for ( QDomNode oNode = oListNode.firstChild();
223 oNode = oNode.nextSibling() )
225 QDomElement e = oNode.toElement();
230 if ( e.tagName() ==
"service" )
235 SetStrValue(e.namedItem(
"serviceType" ), pService->m_sServiceType);
236 SetStrValue(e.namedItem(
"serviceId" ), pService->m_sServiceId);
237 SetStrValue(e.namedItem(
"SCPDURL" ), pService->m_sSCPDURL);
238 SetStrValue(e.namedItem(
"controlURL" ), pService->m_sControlURL);
239 SetStrValue(e.namedItem(
"eventSubURL" ), pService->m_sEventSubURL);
241 LOG(VB_UPNP, LOG_INFO,
242 QString(
"ProcessServiceList adding service : %1 : %2 :")
243 .arg(pService->m_sServiceType,
244 pService->m_sServiceId));
256 for ( QDomNode oNode = oListNode.firstChild();
258 oNode = oNode.nextSibling() )
260 QDomElement e = oNode.toElement();
265 if ( e.tagName() ==
"device")
280 QDomText oText = n.firstChild().toText();
283 sValue = oText.nodeValue();
293 QDomText oText = n.firstChild().toText();
296 nValue = oText.nodeValue().toInt();
304 QDomText oText = n.firstChild().toText();
308 QString s = oText.nodeValue();
309 nValue = (s ==
"yes" || s ==
"true" || (s.toInt() != 0));
321#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
322 QTextStream os( &sXML, QIODevice::WriteOnly );
324 QTextStream os(&sXML, QIODeviceBase::WriteOnly);
337 const QString &,
int ,
338 QTextStream &os,
const QString &sUserAgent )
341 os.setEncoding( QTextStream::UnicodeUTF8 );
343 os <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
344 "<root xmlns=\"urn:schemas-upnp-org:device-1-0\" "
345 " xmlns:mythtv=\"mythtv.org\">\n"
363 const QString &sUserAgent )
365 if (pDevice ==
nullptr)
368 QString sFriendlyName = QString(
"%1: %2" )
381 os <<
FormatValue(
"friendlyName" , sFriendlyName );
391 sUserAgent.startsWith(QString(
"Xbox/2.0"), Qt::CaseInsensitive) ||
392 sUserAgent.startsWith(QString(
"Mozilla/4.0"), Qt::CaseInsensitive);
420 for (
const auto & nit : std::as_const(pDevice->
m_lstExtra))
431 os <<
"<iconList>\n";
433 for (
auto *icon : std::as_const(pDevice->
m_listIcons))
436 os <<
FormatValue(
"mimetype", icon->m_sMimeType );
443 os <<
"</iconList>\n";
468 bool bDSM = sUserAgent.startsWith(
"INTEL_NMPR/2.1 DLNADOC/1.00",
false);
471 os <<
"<serviceList>\n";
475 if (!bIsXbox360 && service->m_sServiceType.startsWith(
476 "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar",
477 Qt::CaseInsensitive))
483 os <<
FormatValue(
"serviceType", service->m_sServiceType );
484 os <<
FormatValue(
"serviceId" , service->m_sServiceId );
485 os <<
FormatValue(
"SCPDURL" , service->m_sSCPDURL );
486 os <<
FormatValue(
"controlURL" , service->m_sControlURL );
487 os <<
FormatValue(
"eventSubURL", service->m_sEventSubURL );
488 os <<
"</service>\n";
490 os <<
"</serviceList>\n";
499 os <<
"<deviceList>";
501 UPnpDeviceList::iterator it;
509 os <<
"</deviceList>";
524 NameValues::iterator it;
527 sAttributes += QString(
" %1='%2'").arg((*it).m_sName, (*it).m_sValue);
529 sStr = QString(
"<%1%2>%3</%1>\n").arg(node.
m_sName, sAttributes, node.
m_sValue);
539 const QString &sValue )
543 if (sValue.length() > 0)
544 sStr = QString(
"<%1>%2</%1>\n") .arg(sName, sValue);
553 return( QString(
"<%1>%2</%1>\n") .arg(sName) .arg(nValue) );
563 if (sST.section(
':', 0, -2) == pDevice->
m_sDeviceType.section(
':', 0, -2))
566 if (sST.section(
':', 0, -2) == pDevice->
GetUDN().section(
':', 0, -2))
577 if (sST.section(
':', 0, -2) == (*sit)->m_sServiceType.section(
':', 0, -2))
588 if (sUDN.length() > 0)
609 const QString &sURI )
612 if ( sURI.section(
':', 0, -2) == pDevice->
m_sDeviceType.section(
':', 0, -2) )
619 for (
const auto & dev : std::as_const(pDevice->
m_listDevices))
623 if (pFound !=
nullptr)
638 LOG(VB_UPNP, LOG_DEBUG, QString(
"UPnpDeviceDesc::Retrieve( %1 )")
645 QString sXml(buffer);
647 if (ok && sXml.startsWith( QString(
"<?xml") ))
649 QDomDocument xml(
"upnp" );
651#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
653 bool success = xml.setContent( sXml,
false, &sErrorMsg );
655 auto parseResult = xml.setContent( sXml );
656 bool success { parseResult };
657 QString sErrorMsg { parseResult.errorMessage };
662 pDevice->
Load( xml );
668 LOG(VB_UPNP, LOG_ERR,
669 QString(
"Error parsing device description xml [%1]")
675 LOG(VB_UPNP, LOG_ERR, QString(
"Invalid response '%1'").arg(sXml));
691 QString localHostName = QHostInfo::localHostName();
692 if (localHostName.isEmpty())
693 LOG(VB_GENERAL, LOG_ERR,
694 "UPnpDeviceDesc: Error, could not determine host name." +
ENO);
711 m_sModelNumber(MYTH_BINARY_VERSION),
713 m_protocolVersion(MYTH_PROTO_VERSION)
729 pngIconLrg->m_nDepth = 24;
730 pngIconLrg->m_nHeight = 120;
731 pngIconLrg->m_nWidth = 120;
732 pngIconLrg->m_sMimeType =
"image/png";
733 pngIconLrg->m_sURL =
"/images/icons/upnp_large_icon.png";
738 jpgIconLrg->m_nDepth = 24;
739 jpgIconLrg->m_nHeight = 120;
740 jpgIconLrg->m_nWidth = 120;
741 jpgIconLrg->m_sMimeType =
"image/jpeg";
742 jpgIconLrg->m_sURL =
"/images/icons/upnp_large_icon.jpg";
747 pngIconSm->m_nDepth = 24;
748 pngIconSm->m_nHeight = 48;
749 pngIconSm->m_nWidth = 48;
750 pngIconSm->m_sMimeType =
"image/png";
751 pngIconSm->m_sURL =
"/images/icons/upnp_small_icon.png";
756 jpgIconSm->m_nDepth = 24;
757 jpgIconSm->m_nHeight = 48;
758 jpgIconSm->m_nWidth = 48;
759 jpgIconSm->m_sMimeType =
"image/jpeg";
760 jpgIconSm->m_sURL =
"/images/icons/upnp_small_icon.jpg";
816 if (service->m_sServiceType.section(
':', 0, -2) == urn.section(
':', 0, -2))
828 srv = (*dit)->GetService(urn, &done);
840 QString(
"UPnP Device\n"
845 "manufacturerURL: %4\n"
846 "modelDescription: %5\n"
858 QString(
"serialNumber: %1\n"
860 "presentationURL: %3\n"
869 ret +=
"Extra key value pairs\n";
870 for (
const auto & extra : std::as_const(
m_lstExtra))
872 ret += extra.m_sName;
874 int int_padding = 18 - (extra.m_sName.length() + 1);
875 for (
int i = 0; i < int_padding; i++)
877 ret += QString(
"%1\n").arg(extra.m_sValue);
883 ret +=
"Icon List:\n";
885 ret += icon->toString(padding+2) +
"\n";
890 ret +=
"Service List:\n";
892 ret += service->toString(padding+2) +
"\n";
897 ret +=
"Device List:\n";
899 ret += device->toString(padding+2) +
"\n";
904 if (ret.endsWith(
"\n"))
905 ret = ret.left(ret.length()-1);
911 for (
uint i = 0; i < padding; i++)
913 ret = pad + ret.replace(
"\n", QString(
"\n%1").arg(pad));
bool download(const QString &url, const QString &dest, bool reload=false)
Downloads a URL to a file in blocking mode.
NameValues * m_pAttributes
void AddAttribute(const QString &name, const QString &value, bool required)
QString GetHostName() const
void OutputDevice(QTextStream &os, UPnpDevice *pDevice, const QString &sUserAgent="")
void ProcessDeviceList(const QDomNode &oListNode, UPnpDevice *pDevice)
static QString FormatValue(const NameValue &node)
void GetValidXML(const QString &sBaseAddress, int nPort, QTextStream &os, const QString &sUserAgent="")
static void SetNumValue(const QDomNode &n, int &nValue)
Sets nValue param to n.firstChild().toText().nodeValue(), iff neither n.isNull() nor n....
static UPnpDeviceDesc * Retrieve(QString &sURL)
void InternalLoad(QDomNode oNode, UPnpDevice *pCurDevice)
QString FindDeviceUDN(UPnpDevice *pDevice, QString sST)
UPnpDevice * FindDevice(const QString &sURI)
static void ProcessServiceList(const QDomNode &oListNode, UPnpDevice *pDevice)
bool Load(const QString &sFileName)
static void SetStrValue(const QDomNode &n, QString &sValue)
Sets sValue param to n.firstChild().toText().nodeValue(), iff neither n.isNull() nor n....
static void ProcessIconList(const QDomNode &oListNode, UPnpDevice *pDevice)
static void SetBoolValue(const QDomNode &n, bool &nValue)
QString m_sModelDescription
QString GetUDN(void) const
QString m_sPresentationURL
void toMap(InfoMap &map) const
QString m_sManufacturerURL
bool m_securityPin
MythTV specific information.
QString m_protocolVersion
UPnpService GetService(const QString &urn, bool *found=nullptr) const
UPnpServiceList m_listServices
QString toString(uint padding=0) const
UPnpDeviceList m_listDevices
QString GetValue(const QString &setting)
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
#define ENO
This can be appended to the LOG args with "+".
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
QHash< QString, QString > InfoMap
const char * GetMythSourceVersion()
QString LookupUDN(const QString &sDeviceType)