16 #include <QTextStream>
17 #include <QHostAddress>
26 #include "libmythbase/mythversion.h"
31 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
32 #define QT_FLUSH flush
34 #define QT_FLUSH Qt::flush
57 QDomDocument doc (
"upnp" );
58 QFile
file( sFileName );
60 if ( !
file.open( QIODevice::ReadOnly ) )
66 bool bSuccess = doc.setContent( &
file,
false,
67 &sErrMsg, &nErrLine, &nErrCol );
73 LOG(VB_GENERAL, LOG_ERR,
74 QString(
"UPnpDeviceDesc::Load - Error parsing: %1 "
75 "at line: %2 column: %3")
76 .arg(sFileName) .arg(nErrLine)
78 LOG(VB_GENERAL, LOG_ERR,
79 QString(
"UPnpDeviceDesc::Load - Error Msg: %1" ) .arg(sErrMsg));
100 QDomNode oNode = xmlDevDesc.documentElement();
113 QString pin =
GetMythDB()->GetSetting(
"SecurityPin",
"");
114 pCurDevice->
m_securityPin = !(pin.isEmpty() || pin ==
"0000");
116 for ( oNode = oNode.firstChild();
118 oNode = oNode.nextSibling() )
120 QDomElement e = oNode.toElement();
126 if ( e.tagName() ==
"deviceType" )
128 else if ( e.tagName() ==
"friendlyName" )
130 else if ( e.tagName() ==
"manufacturer" )
132 else if ( e.tagName() ==
"manufacturerURL" )
134 else if ( e.tagName() ==
"modelDescription" )
136 else if ( e.tagName() ==
"modelName" )
138 else if ( e.tagName() ==
"modelNumber" )
140 else if ( e.tagName() ==
"modelURL" )
142 else if ( e.tagName() ==
"serialNumber" )
144 else if ( e.tagName() ==
"UPC" )
146 else if ( e.tagName() ==
"presentationURL" )
148 else if ( e.tagName() ==
"UDN" )
150 else if ( e.tagName() ==
"iconList" )
152 else if ( e.tagName() ==
"serviceList" )
154 else if ( e.tagName() ==
"deviceList" )
156 else if ( e.tagName() ==
"mythtv:X_secure" )
158 else if ( e.tagName() ==
"mythtv:X_protocol" )
166 QDomNamedNodeMap attributes = e.attributes();
167 for (
int i = 0; i < attributes.size(); i++)
170 attributes.item(i).nodeValue(),
184 for ( QDomNode oNode = oListNode.firstChild();
186 oNode = oNode.nextSibling() )
188 QDomElement e = oNode.toElement();
193 if ( e.tagName() ==
"icon" )
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 );
213 for ( QDomNode oNode = oListNode.firstChild();
215 oNode = oNode.nextSibling() )
217 QDomElement e = oNode.toElement();
222 if ( e.tagName() ==
"service" )
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);
233 LOG(VB_UPNP, LOG_INFO,
234 QString(
"ProcessServiceList adding service : %1 : %2 :")
235 .arg(pService->m_sServiceType,
236 pService->m_sServiceId));
248 for ( QDomNode oNode = oListNode.firstChild();
250 oNode = oNode.nextSibling() )
252 QDomElement e = oNode.toElement();
257 if ( e.tagName() ==
"device")
272 QDomText oText = n.firstChild().toText();
275 sValue = oText.nodeValue();
285 QDomText oText = n.firstChild().toText();
288 nValue = oText.nodeValue().toInt();
296 QDomText oText = n.firstChild().toText();
300 QString s = oText.nodeValue();
301 nValue = (s ==
"yes" || s ==
"true" || (s.toInt() != 0));
313 QTextStream os( &sXML, QIODevice::WriteOnly );
325 const QString &,
int ,
326 QTextStream &os,
const QString &sUserAgent )
329 os.setEncoding( QTextStream::UnicodeUTF8 );
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"
351 const QString &sUserAgent )
353 if (pDevice ==
nullptr)
356 QString sFriendlyName = QString(
"%1: %2" )
369 os <<
FormatValue(
"friendlyName" , sFriendlyName );
379 sUserAgent.startsWith(QString(
"Xbox/2.0"), Qt::CaseInsensitive) ||
380 sUserAgent.startsWith(QString(
"Mozilla/4.0"), Qt::CaseInsensitive);
408 for (
const auto & nit : qAsConst(pDevice->
m_lstExtra))
419 os <<
"<iconList>\n";
424 os <<
FormatValue(
"mimetype", icon->m_sMimeType );
431 os <<
"</iconList>\n";
456 bool bDSM = sUserAgent.startsWith(
"INTEL_NMPR/2.1 DLNADOC/1.00",
false);
459 os <<
"<serviceList>\n";
463 if (!bIsXbox360 && service->m_sServiceType.startsWith(
464 "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar",
465 Qt::CaseInsensitive))
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";
478 os <<
"</serviceList>\n";
487 os <<
"<deviceList>";
489 UPnpDeviceList::iterator it;
497 os <<
"</deviceList>";
512 NameValues::iterator it;
515 sAttributes += QString(
" %1='%2'").arg((*it).m_sName, (*it).m_sValue);
517 sStr = QString(
"<%1%2>%3</%1>\n").arg(node.
m_sName, sAttributes, node.
m_sValue);
527 const QString &sValue )
531 if (sValue.length() > 0)
532 sStr = QString(
"<%1>%2</%1>\n") .arg(sName, sValue);
541 return( QString(
"<%1>%2</%1>\n") .arg(sName) .arg(nValue) );
551 if (sST.section(
':', 0, -2) == pDevice->
m_sDeviceType.section(
':', 0, -2))
554 if (sST.section(
':', 0, -2) == pDevice->
GetUDN().section(
':', 0, -2))
565 if (sST.section(
':', 0, -2) == (*sit)->m_sServiceType.section(
':', 0, -2))
576 if (sUDN.length() > 0)
597 const QString &sURI )
600 if ( sURI.section(
':', 0, -2) == pDevice->
m_sDeviceType.section(
':', 0, -2) )
611 if (pFound !=
nullptr)
626 LOG(VB_UPNP, LOG_DEBUG, QString(
"UPnpDeviceDesc::Retrieve( %1 )")
633 QString sXml(buffer);
635 if (ok && sXml.startsWith( QString(
"<?xml") ))
639 QDomDocument xml(
"upnp" );
641 if ( xml.setContent( sXml,
false, &sErrorMsg ))
644 pDevice->
Load( xml );
650 LOG(VB_UPNP, LOG_ERR,
651 QString(
"Error parsing device description xml [%1]")
657 LOG(VB_UPNP, LOG_ERR, QString(
"Invalid response '%1'").arg(sXml));
673 QString localHostName = QHostInfo::localHostName();
674 if (localHostName.isEmpty())
675 LOG(VB_GENERAL, LOG_ERR,
676 "UPnpDeviceDesc: Error, could not determine host name." +
ENO);
693 m_sModelNumber(MYTH_BINARY_VERSION),
695 m_protocolVersion(MYTH_PROTO_VERSION)
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";
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";
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";
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";
798 if (service->m_sServiceType.section(
':', 0, -2) == urn.section(
':', 0, -2))
810 srv = (*dit)->GetService(urn, &done);
822 QString(
"UPnP Device\n"
827 "manufacturerURL: %4\n"
828 "modelDescription: %5\n"
840 QString(
"serialNumber: %1\n"
842 "presentationURL: %3\n"
851 ret +=
"Extra key value pairs\n";
852 for (
const auto & extra : qAsConst(
m_lstExtra))
854 ret += extra.m_sName;
856 int int_padding = 18 - (extra.m_sName.length() + 1);
857 for (
int i = 0; i < int_padding; i++)
859 ret += QString(
"%1\n").arg(extra.m_sValue);
865 ret +=
"Icon List:\n";
867 ret += icon->toString(padding+2) +
"\n";
872 ret +=
"Service List:\n";
874 ret += service->toString(padding+2) +
"\n";
879 ret +=
"Device List:\n";
881 ret += device->toString(padding+2) +
"\n";
886 if (ret.endsWith(
"\n"))
887 ret = ret.left(ret.length()-1);
893 for (
uint i = 0; i < padding; i++)
895 ret = pad + ret.replace(
"\n", QString(
"\n%1").arg(pad));