Skip to content

Commit bdc155a

Browse files
committed
Extend the upnp device description to include some custom information for internal MythTV use.
1 parent 5a71640 commit bdc155a

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

mythtv/libs/libmythupnp/upnpdevice.cpp

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// Created : Oct. 24, 2005
44
//
55
// Purpose : UPnp Device Description parser/generator
6-
//
6+
//
77
// Copyright (c) 2005 David Blain <mythtv@theblains.net>
8-
//
9-
// This library is free software; you can redistribute it and/or
8+
//
9+
// This library is free software; you can redistribute it and/or
1010
// modify it under the terms of the GNU Lesser General Public
1111
// License as published by the Free Software Foundation; either
1212
// version 2.1 of the License, or at your option any later version of the LGPL.
@@ -25,6 +25,9 @@
2525
#include "upnpdevice.h"
2626
#include "httpcomms.h"
2727

28+
// MythDB
29+
#include "mythdb.h"
30+
2831
#include <cerrno>
2932

3033
#include <QFile>
@@ -127,6 +130,10 @@ bool UPnpDeviceDesc::Load( const QDomDocument &xmlDevDesc )
127130

128131
void UPnpDeviceDesc::_InternalLoad( QDomNode oNode, UPnpDevice *pCurDevice )
129132
{
133+
QString pin = GetMythDB()->GetSetting( "SecurityPin", "");
134+
pCurDevice->m_securityPin = (pin.isEmpty() || pin == "0000") ?
135+
false : true;
136+
130137
for ( oNode = oNode.firstChild();
131138
!oNode.isNull();
132139
oNode = oNode.nextSibling() )
@@ -167,6 +174,11 @@ void UPnpDeviceDesc::_InternalLoad( QDomNode oNode, UPnpDevice *pCurDevice )
167174
if ( e.tagName() == "deviceList" )
168175
{ ProcessDeviceList ( oNode, pCurDevice ); continue; }
169176

177+
if ( e.tagName() == "mythtv:X_secure" )
178+
{ SetBoolValue( e, pCurDevice->m_securityPin ); continue; }
179+
if ( e.tagName() == "mythtv:X_protocol" )
180+
{ SetStrValue( e, pCurDevice->m_protocolVersion ); continue; }
181+
170182
// Not one of the expected element names... add to extra list.
171183

172184
QString sValue = "";
@@ -223,7 +235,7 @@ void UPnpDeviceDesc::ProcessServiceList( QDomNode oListNode, UPnpDevice *pDevice
223235
{
224236
if ( e.tagName() == "service" )
225237
{
226-
UPnpService *pService = new UPnpService();
238+
UPnpService *pService = new UPnpService();
227239
pDevice->m_listServices.append( pService );
228240

229241
SetStrValue( e.namedItem( "serviceType" ),
@@ -302,6 +314,20 @@ void UPnpDeviceDesc::SetNumValue( const QDomNode &n, int &nValue )
302314
}
303315
}
304316

317+
void UPnpDeviceDesc::SetBoolValue( const QDomNode &n, bool &nValue )
318+
{
319+
if (!n.isNull())
320+
{
321+
QDomText oText = n.firstChild().toText();
322+
323+
if (!oText.isNull())
324+
{
325+
QString s = oText.nodeValue();
326+
nValue = (s == "yes" || s == "true" || s.toInt());
327+
}
328+
}
329+
}
330+
305331
/////////////////////////////////////////////////////////////////////////////
306332
//
307333
/////////////////////////////////////////////////////////////////////////////
@@ -315,7 +341,7 @@ QString UPnpDeviceDesc::GetValidXML( const QString &sBaseAddress, int nPort )
315341
os << flush;
316342
return( sXML );
317343
}
318-
344+
319345
/////////////////////////////////////////////////////////////////////////////
320346
//
321347
/////////////////////////////////////////////////////////////////////////////
@@ -346,7 +372,7 @@ void UPnpDeviceDesc::GetValidXML(
346372
/////////////////////////////////////////////////////////////////////////////
347373

348374
void UPnpDeviceDesc::OutputDevice( QTextStream &os,
349-
UPnpDevice *pDevice,
375+
UPnpDevice *pDevice,
350376
const QString &sUserAgent )
351377
{
352378
if (pDevice == NULL)
@@ -363,15 +389,15 @@ void UPnpDeviceDesc::OutputDevice( QTextStream &os,
363389
if (pDevice == &m_rootDevice)
364390
sFriendlyName = UPnp::g_pConfig->GetValue( "UPnP/FriendlyName",
365391
sFriendlyName );
366-
392+
367393
os << "<device>\n";
368394
os << FormatValue( "deviceType" , pDevice->m_sDeviceType );
369395
os << FormatValue( "friendlyName" , sFriendlyName );
370396

371397
// ----------------------------------------------------------------------
372398
// XBox 360 needs specific values in the Device Description.
373399
//
374-
// -=>TODO: This should be externalized in a more generic/extension
400+
// -=>TODO: This should be externalized in a more generic/extension
375401
// kind of way.
376402
// ----------------------------------------------------------------------
377403

@@ -380,7 +406,7 @@ void UPnpDeviceDesc::OutputDevice( QTextStream &os,
380406
sUserAgent.startsWith( QString("Mozilla/4.0"), Qt::CaseInsensitive);
381407

382408
os << FormatValue( "manufacturer" , pDevice->m_sManufacturer );
383-
os << FormatValue( "modelURL" , pDevice->m_sModelURL );
409+
os << FormatValue( "modelURL" , pDevice->m_sModelURL );
384410

385411
if ( bIsXbox360 )
386412
{
@@ -399,10 +425,14 @@ void UPnpDeviceDesc::OutputDevice( QTextStream &os,
399425
os << FormatValue( "UPC" , pDevice->m_sUPC );
400426
os << FormatValue( "presentationURL" , pDevice->m_sPresentationURL );
401427

428+
// MythTV Custom information
429+
os << FormatValue( "mythtv:X_secure" , pDevice->m_securityPin ? "true" : "false");
430+
os << FormatValue( "mythtv:X_protocol", pDevice->m_protocolVersion );
431+
402432
NameValues::const_iterator nit = pDevice->m_lstExtra.begin();
403433
for (; nit != pDevice->m_lstExtra.end(); ++nit)
404434
{
405-
// -=>TODO: Hack to handle one element with attributes... need to
435+
// -=>TODO: Hack to handle one element with attributes... need to
406436
// handle attributes in a more generic way.
407437

408438
if ((*nit).sName == "dlna:X_DLNADOC")
@@ -496,7 +526,7 @@ void UPnpDeviceDesc::OutputDevice( QTextStream &os,
496526
{
497527
os << "<deviceList>";
498528

499-
for ( UPnpDevice *pEmbeddedDevice = pDevice->m_listDevices.first();
529+
for ( UPnpDevice *pEmbeddedDevice = pDevice->m_listDevices.first();
500530
pEmbeddedDevice != NULL;
501531
pEmbeddedDevice = pDevice->m_listDevices.next() )
502532
{
@@ -525,7 +555,7 @@ QString UPnpDeviceDesc::FormatValue( const QString &sName, const QString &sValue
525555
}
526556

527557
/////////////////////////////////////////////////////////////////////////////
528-
558+
529559
QString UPnpDeviceDesc::FormatValue( const QString &sName, int nValue )
530560
{
531561
return( QString( "<%1>%2</%1>\n" ).arg( sName ).arg(nValue) );
@@ -542,7 +572,7 @@ QString UPnpDeviceDesc::FindDeviceUDN( UPnpDevice *pDevice, QString sST )
542572

543573
if (sST == pDevice->GetUDN())
544574
return sST;
545-
575+
546576
// ----------------------------------------------------------------------
547577
// Check for matching Service
548578
// ----------------------------------------------------------------------

mythtv/libs/libmythupnp/upnpdevice.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ class UPNP_PUBLIC UPnpDevice
102102

103103
NameValues m_lstExtra;
104104

105+
/// MythTV specific information
106+
bool m_securityPin;
107+
QString m_protocolVersion;
108+
105109
UPnpIconList m_listIcons;
106110
UPnpServiceList m_listServices;
107111
UPnpDeviceList m_listDevices;
@@ -112,6 +116,8 @@ class UPNP_PUBLIC UPnpDevice
112116
{
113117
m_sModelNumber = MYTH_BINARY_VERSION;
114118
m_sSerialNumber = myth_source_version;
119+
m_securityPin = false;
120+
m_protocolVersion = MYTH_PROTO_VERSION;
115121
}
116122
~UPnpDevice()
117123
{
@@ -172,6 +178,7 @@ class UPNP_PUBLIC UPnpDeviceDesc
172178

173179
void SetStrValue ( const QDomNode &n, QString &sValue );
174180
void SetNumValue ( const QDomNode &n, int &nValue );
181+
void SetBoolValue( const QDomNode &n, bool &nValue );
175182

176183
QString FormatValue ( const QString &sName, const QString &sValue );
177184
QString FormatValue ( const QString &sName, int nValue );
@@ -322,9 +329,13 @@ class UPNP_PUBLIC DeviceLocation : public RefCounted
322329
map["UPC"] = pDevice->m_rootDevice.m_sUPC;
323330
}
324331

325-
const QString GetSecurityPin(void) const
332+
bool NeedSecurityPin( bool bInQtThread = true )
326333
{
327-
return m_sSecurityPin;
334+
UPnpDeviceDesc *pDevice = GetDeviceDesc(bInQtThread);
335+
if (!pDevice)
336+
return false;
337+
338+
return pDevice->m_rootDevice.m_securityPin;
328339
}
329340
};
330341

0 commit comments

Comments
 (0)