MythTV  master
upnputil.cpp
Go to the documentation of this file.
1 // Program Name: upnputil.cpp
3 // Created : Jan. 15, 2007
4 //
5 // Purpose : Global Helper Methods...
6 //
7 // Copyright (c) 2007 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see COPYING for details
10 //
12 
13 // POSIX headers
14 #include <sys/types.h>
15 #include <sys/time.h>
16 #include <cerrno>
17 
18 // Qt headers
19 #include <QUuid>
20 #include <QStringList>
21 
22 // MythTV headers
23 #include "upnputil.h"
24 #include "upnp.h"
25 #include "upnphelpers.h"
26 #include "compat.h"
27 #include "mythconfig.h" // for HAVE_GETIFADDRS
28 #include "mythlogging.h"
29 #include "httprequest.h"
30 
31 // POSIX headers 2, needs to be after compat.h for OS X
32 #ifndef _WIN32
33 #include <sys/ioctl.h>
34 #endif // _WIN32
35 
36 
37 #include <zlib.h>
38 #undef Z_NULL
39 #define Z_NULL nullptr
40 
42 //
44 
45 QString LookupUDN( const QString &sDeviceType )
46 {
47 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
48  QStringList sList = sDeviceType.split(':', QString::SkipEmptyParts);
49 #else
50  QStringList sList = sDeviceType.split(':', Qt::SkipEmptyParts);
51 #endif
52  QString sLoc = "LookupUDN(" + sDeviceType + ')';
53 
54  if (sList.size() <= 2)
55  {
56  LOG(VB_GENERAL, LOG_ERR, sLoc + "- bad device type '" +
57  sDeviceType + "', not enough tokens");
58  return QString();
59  }
60 
61  sList.removeLast();
62  QString sName = "UPnP/UDN/" + sList.last();
63  QString sUDN = UPnp::GetConfiguration()->GetValue( sName, "" );
64 
65  LOG(VB_UPNP, LOG_INFO, sLoc + " sName=" + sName + ", sUDN=" + sUDN);
66 
67  // Generate new UUID if current is missing or broken
68  if (sUDN.isEmpty() || sUDN.startsWith("{"))
69  {
70  sUDN = QUuid::createUuid().toString();
71  // QUuid returns the uuid enclosed with braces {} which is not
72  // DLNA compliant, we need to remove them
73  sUDN = sUDN.mid(1, 36);
74 
76 
77  pConfig->SetValue( sName, sUDN );
78  pConfig->Save();
79  }
80 
81  return( sUDN );
82 }
83 
91 {
92  QStringList mimeTypes = HTTPRequest::GetSupportedMimeTypes();
93 
94  QString protocolStr("http-get:*:%1:%2");
95  QStringList protocolList;
96  QStringList::Iterator it;
97  for (it = mimeTypes.begin(); it < mimeTypes.end(); ++it)
98  {
99  // HACK
101  if (*it == "video/mpeg")
102  {
103  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_PS_PAL;" + flags);
104  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_PS_NTSC;" + flags);
105  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_PS_SD_DTS;" + flags);
106  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AVC_TS_NA_ISO;" + flags);
107  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_TS_HD_NA_ISO;" + flags);
108  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_TS_SD_NA_ISO;" + flags);
109  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AVC_TS_EU_ISO;" + flags);
110  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_TS_SD_EU_ISO;" + flags);
111  }
112  else if (*it == "audio/mpeg")
113  {
114  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MP3;" + flags); // Technically we don't actually serve these
115  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MP3X;" + flags);
116  }
117  else if (*it == "audio/mp4")
118  {
119  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AAC_ISO_320;" + flags);
120  }
121  else if (*it == "audio/vnd.dolby.dd-raw")
122  {
123  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AC3;" + flags);
124  }
125  else if (*it == "audio/x-ms-wma")
126  {
127  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=WMAFULL;" + flags);
128  }
129  else
130  protocolList << protocolStr.arg(*it, "*");
131  }
132 
133  return protocolList;
134 }
135 
142 QStringList GetSinkProtocolInfos()
143 {
144  QStringList mimeTypes = HTTPRequest::GetSupportedMimeTypes();
145 
146  QStringList protocolList;
147  QStringList::Iterator it;
148  for (it = mimeTypes.begin(); it < mimeTypes.end(); ++it)
149  {
150  protocolList << QString("http-get:*:%1:*").arg(*it);
151  }
152 
153  return protocolList;
154 }
155 
ktm_b
ktm_b
Definition: upnphelpers.h:255
GetSourceProtocolInfos
QStringList GetSourceProtocolInfos()
Return a QStringList containing the supported Source Protocols.
Definition: upnputil.cpp:90
HTTPRequest::GetSupportedMimeTypes
static QStringList GetSupportedMimeTypes()
Definition: httprequest.cpp:1067
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
LookupUDN
QString LookupUDN(const QString &sDeviceType)
Definition: upnputil.cpp:45
Configuration::SetValue
virtual void SetValue(const QString &sSetting, int value)=0
upnp.h
mythlogging.h
compat.h
GetSinkProtocolInfos
QStringList GetSinkProtocolInfos()
Return a QStringList containing the supported Sink Protocols.
Definition: upnputil.cpp:142
kv1_5_flag
kv1_5_flag
Definition: upnphelpers.h:261
upnphelpers.h
Configuration
Definition: configuration.h:21
Configuration::Save
virtual bool Save(void)=0
DLNA::FlagsString
QString FlagsString(uint32_t flags)
Convert an integer composed of DNLA_Flags to a properly formatted string for use in XML.
Definition: upnphelpers.cpp:367
ktm_s
ktm_s
Definition: upnphelpers.h:253
Configuration::GetValue
virtual int GetValue(const QString &sSetting, int Default)=0
UPnp::GetConfiguration
static Configuration * GetConfiguration()
Definition: upnp.cpp:84
upnputil.h
httprequest.h