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" )
175 QDomNamedNodeMap attributes = e.attributes();
176 for (
int i = 0; i < attributes.size(); i++)
179 attributes.item(i).nodeValue(),
193 for ( QDomNode oNode = oListNode.firstChild();
195 oNode = oNode.nextSibling() )
197 QDomElement e = oNode.toElement();
202 if ( e.tagName() ==
"icon" )
207 SetStrValue( e.namedItem(
"mimetype" ), pIcon->m_sMimeType );
208 SetNumValue( e.namedItem(
"width" ), pIcon->m_nWidth );
209 SetNumValue( e.namedItem(
"height" ), pIcon->m_nHeight );
210 SetNumValue( e.namedItem(
"depth" ), pIcon->m_nDepth );
211 SetStrValue( e.namedItem(
"url" ), pIcon->m_sURL );
222 for ( QDomNode oNode = oListNode.firstChild();
224 oNode = oNode.nextSibling() )
226 QDomElement e = oNode.toElement();
231 if ( e.tagName() ==
"service" )
236 SetStrValue(e.namedItem(
"serviceType" ), pService->m_sServiceType);
237 SetStrValue(e.namedItem(
"serviceId" ), pService->m_sServiceId);
238 SetStrValue(e.namedItem(
"SCPDURL" ), pService->m_sSCPDURL);
239 SetStrValue(e.namedItem(
"controlURL" ), pService->m_sControlURL);
240 SetStrValue(e.namedItem(
"eventSubURL" ), pService->m_sEventSubURL);
242 LOG(VB_UPNP, LOG_INFO,
243 QString(
"ProcessServiceList adding service : %1 : %2 :")
244 .arg(pService->m_sServiceType,
245 pService->m_sServiceId));
257 for ( QDomNode oNode = oListNode.firstChild();
259 oNode = oNode.nextSibling() )
261 QDomElement e = oNode.toElement();
266 if ( e.tagName() ==
"device")
281 QDomText oText = n.firstChild().toText();
284 sValue = oText.nodeValue();
294 QDomText oText = n.firstChild().toText();
297 nValue = oText.nodeValue().toInt();
305 QDomText oText = n.firstChild().toText();
309 QString s = oText.nodeValue();
310 nValue = (s ==
"yes" || s ==
"true" || (s.toInt() != 0));
322 QTextStream os( &sXML, QIODevice::WriteOnly );
334 const QString &,
int ,
335 QTextStream &os,
const QString &sUserAgent )
338 os.setEncoding( QTextStream::UnicodeUTF8 );
340 os <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
341 "<root xmlns=\"urn:schemas-upnp-org:device-1-0\" "
342 " xmlns:mythtv=\"mythtv.org\">\n"
360 const QString &sUserAgent )
362 if (pDevice ==
nullptr)
365 QString sFriendlyName = QString(
"%1: %2" )
378 os <<
FormatValue(
"friendlyName" , sFriendlyName );
388 sUserAgent.startsWith(QString(
"Xbox/2.0"), Qt::CaseInsensitive) ||
389 sUserAgent.startsWith(QString(
"Mozilla/4.0"), Qt::CaseInsensitive);
417 for (
const auto & nit : std::as_const(pDevice->
m_lstExtra))
428 os <<
"<iconList>\n";
430 for (
auto *icon : std::as_const(pDevice->
m_listIcons))
433 os <<
FormatValue(
"mimetype", icon->m_sMimeType );
440 os <<
"</iconList>\n";
465 bool bDSM = sUserAgent.startsWith(
"INTEL_NMPR/2.1 DLNADOC/1.00",
false);
468 os <<
"<serviceList>\n";
472 if (!bIsXbox360 && service->m_sServiceType.startsWith(
473 "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar",
474 Qt::CaseInsensitive))
480 os <<
FormatValue(
"serviceType", service->m_sServiceType );
481 os <<
FormatValue(
"serviceId" , service->m_sServiceId );
482 os <<
FormatValue(
"SCPDURL" , service->m_sSCPDURL );
483 os <<
FormatValue(
"controlURL" , service->m_sControlURL );
484 os <<
FormatValue(
"eventSubURL", service->m_sEventSubURL );
485 os <<
"</service>\n";
487 os <<
"</serviceList>\n";
496 os <<
"<deviceList>";
498 UPnpDeviceList::iterator it;
506 os <<
"</deviceList>";
521 NameValues::iterator it;
524 sAttributes += QString(
" %1='%2'").arg((*it).m_sName, (*it).m_sValue);
526 sStr = QString(
"<%1%2>%3</%1>\n").arg(node.
m_sName, sAttributes, node.
m_sValue);
536 const QString &sValue )
540 if (sValue.length() > 0)
541 sStr = QString(
"<%1>%2</%1>\n") .arg(sName, sValue);
550 return( QString(
"<%1>%2</%1>\n") .arg(sName) .arg(nValue) );
560 if (sST.section(
':', 0, -2) == pDevice->
m_sDeviceType.section(
':', 0, -2))
563 if (sST.section(
':', 0, -2) == pDevice->
GetUDN().section(
':', 0, -2))
574 if (sST.section(
':', 0, -2) == (*sit)->m_sServiceType.section(
':', 0, -2))
585 if (sUDN.length() > 0)
606 const QString &sURI )
609 if ( sURI.section(
':', 0, -2) == pDevice->
m_sDeviceType.section(
':', 0, -2) )
616 for (
const auto & dev : std::as_const(pDevice->
m_listDevices))
620 if (pFound !=
nullptr)
635 LOG(VB_UPNP, LOG_DEBUG, QString(
"UPnpDeviceDesc::Retrieve( %1 )")
642 QString sXml(buffer);
644 if (ok && sXml.startsWith( QString(
"<?xml") ))
646 QDomDocument xml(
"upnp" );
648#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
650 bool success = xml.setContent( sXml,
false, &sErrorMsg );
652 auto parseResult = xml.setContent( sXml );
653 bool success { parseResult };
654 QString sErrorMsg { parseResult.errorMessage };
659 pDevice->
Load( xml );
665 LOG(VB_UPNP, LOG_ERR,
666 QString(
"Error parsing device description xml [%1]")
672 LOG(VB_UPNP, LOG_ERR, QString(
"Invalid response '%1'").arg(sXml));
688 QString localHostName = QHostInfo::localHostName();
689 if (localHostName.isEmpty())
690 LOG(VB_GENERAL, LOG_ERR,
691 "UPnpDeviceDesc: Error, could not determine host name." +
ENO);
708 m_sModelNumber(MYTH_BINARY_VERSION),
710 m_protocolVersion(MYTH_PROTO_VERSION)
726 pngIconLrg->m_nDepth = 24;
727 pngIconLrg->m_nHeight = 120;
728 pngIconLrg->m_nWidth = 120;
729 pngIconLrg->m_sMimeType =
"image/png";
730 pngIconLrg->m_sURL =
"/images/icons/upnp_large_icon.png";
735 jpgIconLrg->m_nDepth = 24;
736 jpgIconLrg->m_nHeight = 120;
737 jpgIconLrg->m_nWidth = 120;
738 jpgIconLrg->m_sMimeType =
"image/jpeg";
739 jpgIconLrg->m_sURL =
"/images/icons/upnp_large_icon.jpg";
744 pngIconSm->m_nDepth = 24;
745 pngIconSm->m_nHeight = 48;
746 pngIconSm->m_nWidth = 48;
747 pngIconSm->m_sMimeType =
"image/png";
748 pngIconSm->m_sURL =
"/images/icons/upnp_small_icon.png";
753 jpgIconSm->m_nDepth = 24;
754 jpgIconSm->m_nHeight = 48;
755 jpgIconSm->m_nWidth = 48;
756 jpgIconSm->m_sMimeType =
"image/jpeg";
757 jpgIconSm->m_sURL =
"/images/icons/upnp_small_icon.jpg";
813 if (service->m_sServiceType.section(
':', 0, -2) == urn.section(
':', 0, -2))
825 srv = (*dit)->GetService(urn, &done);
837 QString(
"UPnP Device\n"
842 "manufacturerURL: %4\n"
843 "modelDescription: %5\n"
855 QString(
"serialNumber: %1\n"
857 "presentationURL: %3\n"
866 ret +=
"Extra key value pairs\n";
867 for (
const auto & extra : std::as_const(
m_lstExtra))
869 ret += extra.m_sName;
871 int int_padding = 18 - (extra.m_sName.length() + 1);
872 for (
int i = 0; i < int_padding; i++)
874 ret += QString(
"%1\n").arg(extra.m_sValue);
880 ret +=
"Icon List:\n";
882 ret += icon->toString(padding+2) +
"\n";
887 ret +=
"Service List:\n";
889 ret += service->toString(padding+2) +
"\n";
894 ret +=
"Device List:\n";
896 ret += device->toString(padding+2) +
"\n";
901 if (ret.endsWith(
"\n"))
902 ret = ret.left(ret.length()-1);
908 for (
uint i = 0; i < padding; i++)
910 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)