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  QStringList sList = sDeviceType.split(':', Qt::SkipEmptyParts);
49  QString sLoc = "LookupUDN(" + sDeviceType + ')';
50 
51  if (sList.size() <= 2)
52  {
53  LOG(VB_GENERAL, LOG_ERR, sLoc + "- bad device type '" +
54  sDeviceType + "', not enough tokens");
55  return {};
56  }
57 
58  sList.removeLast();
59  auto config = XmlConfiguration(); // read-write
60  QString sName = "UPnP/UDN/" + sList.last();
61  QString sUDN = config.GetValue(sName, "");
62 
63  LOG(VB_UPNP, LOG_INFO, sLoc + " sName=" + sName + ", sUDN=" + sUDN);
64 
65  // Generate new UUID if current is missing or broken
66  if (sUDN.isEmpty() || sUDN.startsWith("{"))
67  {
68  sUDN = QUuid::createUuid().toString();
69  // QUuid returns the uuid enclosed with braces {} which is not
70  // DLNA compliant, we need to remove them
71  sUDN = sUDN.mid(1, 36);
72 
73  config.SetValue(sName, sUDN);
74  config.Save();
75  }
76 
77  return( sUDN );
78 }
79 
87 {
88  QStringList mimeTypes = HTTPRequest::GetSupportedMimeTypes();
89 
90  QString protocolStr("http-get:*:%1:%2");
91  QStringList protocolList;
92  QStringList::Iterator it;
93  for (it = mimeTypes.begin(); it < mimeTypes.end(); ++it)
94  {
95  // HACK
97  if (*it == "video/mpeg")
98  {
99  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_PS_PAL;" + flags);
100  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_PS_NTSC;" + flags);
101  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_PS_SD_DTS;" + flags);
102  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AVC_TS_NA_ISO;" + flags);
103  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_TS_HD_NA_ISO;" + flags);
104  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_TS_SD_NA_ISO;" + flags);
105  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AVC_TS_EU_ISO;" + flags);
106  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MPEG_TS_SD_EU_ISO;" + flags);
107  }
108  else if (*it == "audio/mpeg")
109  {
110  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MP3;" + flags); // Technically we don't actually serve these
111  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=MP3X;" + flags);
112  }
113  else if (*it == "audio/mp4")
114  {
115  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AAC_ISO_320;" + flags);
116  }
117  else if (*it == "audio/vnd.dolby.dd-raw")
118  {
119  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=AC3;" + flags);
120  }
121  else if (*it == "audio/x-ms-wma")
122  {
123  protocolList << protocolStr.arg(*it, "DLNA.ORG_PN=WMAFULL;" + flags);
124  }
125  else
126  {
127  protocolList << protocolStr.arg(*it, "*");
128  }
129  }
130 
131  return protocolList;
132 }
133 
140 QStringList GetSinkProtocolInfos()
141 {
142  QStringList mimeTypes = HTTPRequest::GetSupportedMimeTypes();
143 
144  QStringList protocolList;
145  QStringList::Iterator it;
146  for (it = mimeTypes.begin(); it < mimeTypes.end(); ++it)
147  {
148  protocolList << QString("http-get:*:%1:*").arg(*it);
149  }
150 
151  return protocolList;
152 }
153 
DLNA::ktm_s
@ ktm_s
Definition: upnphelpers.h:254
GetSourceProtocolInfos
QStringList GetSourceProtocolInfos()
Return a QStringList containing the supported Source Protocols.
Definition: upnputil.cpp:86
HTTPRequest::GetSupportedMimeTypes
static QStringList GetSupportedMimeTypes()
Definition: httprequest.cpp:1001
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:140
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:369
configuration.h
upnputil.h
httprequest.h