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 LICENSE 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 "httprequest.h"
24 #include "libmythbase/compat.h"
27 
28 #include "upnp.h"
29 #include "upnphelpers.h"
30 #include "upnputil.h"
31 
32 // POSIX headers 2, needs to be after compat.h for OS X
33 #ifndef _WIN32
34 #include <sys/ioctl.h>
35 #endif // _WIN32
36 
37 
38 #include <zlib.h>
39 #undef Z_NULL
40 #define Z_NULL nullptr
41 
43 //
45 
46 QString LookupUDN( const QString &sDeviceType )
47 {
48 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
49  QStringList sList = sDeviceType.split(':', QString::SkipEmptyParts);
50 #else
51  QStringList sList = sDeviceType.split(':', Qt::SkipEmptyParts);
52 #endif
53  QString sLoc = "LookupUDN(" + sDeviceType + ')';
54 
55  if (sList.size() <= 2)
56  {
57  LOG(VB_GENERAL, LOG_ERR, sLoc + "- bad device type '" +
58  sDeviceType + "', not enough tokens");
59  return {};
60  }
61 
62  sList.removeLast();
63  auto config = XmlConfiguration(); // read-write
64  QString sName = "UPnP/UDN/" + sList.last();
65  QString sUDN = config.GetValue(sName, "");
66 
67  LOG(VB_UPNP, LOG_INFO, sLoc + " sName=" + sName + ", sUDN=" + sUDN);
68 
69  // Generate new UUID if current is missing or broken
70  if (sUDN.isEmpty() || sUDN.startsWith("{"))
71  {
72  sUDN = QUuid::createUuid().toString();
73  // QUuid returns the uuid enclosed with braces {} which is not
74  // DLNA compliant, we need to remove them
75  sUDN = sUDN.mid(1, 36);
76 
77  config.SetValue(sName, sUDN);
78  config.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 
DLNA::ktm_s
@ ktm_s
Definition: upnphelpers.h:254
GetSourceProtocolInfos
QStringList GetSourceProtocolInfos()
Return a QStringList containing the supported Source Protocols.
Definition: upnputil.cpp:90
HTTPRequest::GetSupportedMimeTypes
static QStringList GetSupportedMimeTypes()
Definition: httprequest.cpp:997
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
XmlConfiguration
Definition: configuration.h:38
LookupUDN
QString LookupUDN(const QString &sDeviceType)
Definition: upnputil.cpp:46
upnp.h
mythlogging.h
compat.h
GetSinkProtocolInfos
QStringList GetSinkProtocolInfos()
Return a QStringList containing the supported Sink Protocols.
Definition: upnputil.cpp:142
DLNA::kv1_5_flag
@ kv1_5_flag
Definition: upnphelpers.h:262
upnphelpers.h
DLNA::ktm_b
@ ktm_b
Definition: upnphelpers.h:256
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
configuration.h
upnputil.h
httprequest.h