16 #include <QTextStream>
17 #include <QHostAddress>
26 #include "libmythbase/mythversion.h"
51 QDomDocument doc (
"upnp" );
52 QFile
file( sFileName );
54 if ( !
file.open( QIODevice::ReadOnly ) )
57 #if QT_VERSION < QT_VERSION_CHECK(6,5,0)
61 bool bSuccess = doc.setContent( &
file,
false,
62 &sErrMsg, &nErrLine, &nErrCol );
68 LOG(VB_GENERAL, LOG_ERR,
69 QString(
"UPnpDeviceDesc::Load - Error parsing: %1 "
70 "at line: %2 column: %3")
71 .arg(sFileName) .arg(nErrLine)
73 LOG(VB_GENERAL, LOG_ERR,
74 QString(
"UPnpDeviceDesc::Load - Error Msg: %1" ) .arg(sErrMsg));
78 auto parseResult = doc.setContent( &
file );
84 LOG(VB_GENERAL, LOG_ERR,
85 QString(
"UPnpDeviceDesc::Load - Error parsing: %1 "
86 "at line: %2 column: %3")
87 .arg(sFileName) .arg(parseResult.errorLine)
88 .arg(parseResult.errorColumn));
89 LOG(VB_GENERAL, LOG_ERR,
90 QString(
"UPnpDeviceDesc::Load - Error Msg: %1" ) .arg(parseResult.errorMessage));
112 QDomNode oNode = xmlDevDesc.documentElement();
125 QString pin =
GetMythDB()->GetSetting(
"SecurityPin",
"");
126 pCurDevice->
m_securityPin = !(pin.isEmpty() || pin ==
"0000");
128 for ( oNode = oNode.firstChild();
130 oNode = oNode.nextSibling() )
132 QDomElement e = oNode.toElement();
138 if ( e.tagName() ==
"deviceType" )
140 else if ( e.tagName() ==
"friendlyName" )
142 else if ( e.tagName() ==
"manufacturer" )
144 else if ( e.tagName() ==
"manufacturerURL" )
146 else if ( e.tagName() ==
"modelDescription" )
148 else if ( e.tagName() ==
"modelName" )
150 else if ( e.tagName() ==
"modelNumber" )
152 else if ( e.tagName() ==
"modelURL" )
154 else if ( e.tagName() ==
"serialNumber" )
156 else if ( e.tagName() ==
"UPC" )
158 else if ( e.tagName() ==
"presentationURL" )
160 else if ( e.tagName() ==
"UDN" )
162 else if ( e.tagName() ==
"iconList" )
164 else if ( e.tagName() ==
"serviceList" )
166 else if ( e.tagName() ==
"deviceList" )
168 else if ( e.tagName() ==
"mythtv:X_secure" )
170 else if ( e.tagName() ==
"mythtv:X_protocol" )
178 QDomNamedNodeMap attributes = e.attributes();
179 for (
int i = 0; i < attributes.size(); i++)
182 attributes.item(i).nodeValue(),
196 for ( QDomNode oNode = oListNode.firstChild();
198 oNode = oNode.nextSibling() )
200 QDomElement e = oNode.toElement();
205 if ( e.tagName() ==
"icon" )
210 SetStrValue( e.namedItem(
"mimetype" ), pIcon->m_sMimeType );
211 SetNumValue( e.namedItem(
"width" ), pIcon->m_nWidth );
212 SetNumValue( e.namedItem(
"height" ), pIcon->m_nHeight );
213 SetNumValue( e.namedItem(
"depth" ), pIcon->m_nDepth );
214 SetStrValue( e.namedItem(
"url" ), pIcon->m_sURL );
225 for ( QDomNode oNode = oListNode.firstChild();
227 oNode = oNode.nextSibling() )
229 QDomElement e = oNode.toElement();
234 if ( e.tagName() ==
"service" )
239 SetStrValue(e.namedItem(
"serviceType" ), pService->m_sServiceType);
240 SetStrValue(e.namedItem(
"serviceId" ), pService->m_sServiceId);
241 SetStrValue(e.namedItem(
"SCPDURL" ), pService->m_sSCPDURL);
242 SetStrValue(e.namedItem(
"controlURL" ), pService->m_sControlURL);
243 SetStrValue(e.namedItem(
"eventSubURL" ), pService->m_sEventSubURL);
245 LOG(VB_UPNP, LOG_INFO,
246 QString(
"ProcessServiceList adding service : %1 : %2 :")
247 .arg(pService->m_sServiceType,
248 pService->m_sServiceId));
260 for ( QDomNode oNode = oListNode.firstChild();
262 oNode = oNode.nextSibling() )
264 QDomElement e = oNode.toElement();
269 if ( e.tagName() ==
"device")
284 QDomText oText = n.firstChild().toText();
287 sValue = oText.nodeValue();
297 QDomText oText = n.firstChild().toText();
300 nValue = oText.nodeValue().toInt();
308 QDomText oText = n.firstChild().toText();
312 QString s = oText.nodeValue();
313 nValue = (s ==
"yes" || s ==
"true" || (s.toInt() != 0));
325 QTextStream os( &sXML, QIODevice::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));