MythTV  master
ssdp.cpp
Go to the documentation of this file.
1 // Program Name: ssdp.cpp
3 // Created : Oct. 1, 2005
4 //
5 // Purpose : SSDP Discovery Service Implmenetation
6 //
7 // Copyright (c) 2005 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see COPYING for details
10 //
12 
13 #include <algorithm>
14 #include <cerrno>
15 #include <chrono> // for milliseconds
16 #include <cstdlib>
17 #include <thread> // for sleep_for
18 
19 #include "upnp.h"
20 #include "mythmiscutil.h"
21 #include "mythlogging.h"
22 
23 #include "upnptasksearch.h"
24 #include "upnptaskcache.h"
25 
26 #include "mmulticastsocketdevice.h"
27 #include "mbroadcastsocketdevice.h"
28 
29 #include <QRegExp>
30 #include <QStringList>
31 
32 #ifdef Q_OS_ANDROID
33 #include <sys/select.h>
34 #endif
35 
38 //
39 // SSDP Class Implementation
40 //
43 
44 // We're creating this class immediately so it will always be available.
45 
46 static QMutex g_pSSDPCreationLock;
47 SSDP* SSDP::g_pSSDP = nullptr;
48 
50 //
52 
54 {
55  QMutexLocker locker(&g_pSSDPCreationLock);
56  return g_pSSDP ? g_pSSDP : (g_pSSDP = new SSDP());
57 }
58 
60 //
62 
64 {
65  QMutexLocker locker(&g_pSSDPCreationLock);
66  delete g_pSSDP;
67  g_pSSDP = nullptr;
68 }
69 
71 //
73 
75  MThread("SSDP")
76 {
77  LOG(VB_UPNP, LOG_NOTICE, "Starting up SSDP Thread..." );
78 
80 
81  m_nPort = pConfig->GetValue("UPnP/SSDP/Port" , SSDP_PORT );
82  m_nSearchPort = pConfig->GetValue("UPnP/SSDP/SearchPort", SSDP_SEARCHPORT);
83 
89  new MBroadcastSocketDevice("255.255.255.255", m_nPort);
90 
91  m_sockets[ SocketIdx_Search ]->setBlocking( false );
92  m_sockets[ SocketIdx_Multicast ]->setBlocking( false );
93  m_sockets[ SocketIdx_Broadcast ]->setBlocking( false );
94 
95  // Setup SearchSocket
96  QHostAddress ip4addr( QHostAddress::Any );
97 
98  m_sockets[ SocketIdx_Search ]->bind( ip4addr , m_nSearchPort );
99  m_sockets[ SocketIdx_Search ]->bind( QHostAddress::Any, m_nSearchPort );
100 
101  // ----------------------------------------------------------------------
102  // Create the SSDP (Upnp Discovery) Thread.
103  // ----------------------------------------------------------------------
104 
105  start();
106 
107  LOG(VB_UPNP, LOG_INFO, "SSDP Thread Starting soon" );
108 }
109 
111 //
113 
115 {
116  LOG(VB_UPNP, LOG_NOTICE, "Shutting Down SSDP Thread..." );
117 
119 
121  wait();
122 
123  if (m_pNotifyTask != nullptr)
124  {
126  m_pNotifyTask = nullptr;
127  }
128 
129  for (auto & socket : m_sockets)
130  delete socket;
131 
132  LOG(VB_UPNP, LOG_INFO, "SSDP Thread Terminated." );
133 }
134 
136 {
137  m_bTermRequested = true;
138 }
139 
141 //
143 
144 void SSDP::EnableNotifications( int nServicePort )
145 {
146  if ( m_pNotifyTask == nullptr )
147  {
148  m_nServicePort = nServicePort;
149 
150  LOG(VB_UPNP, LOG_INFO,
151  "SSDP::EnableNotifications() - creating new task");
153 
154  // ------------------------------------------------------------------
155  // First Send out Notification that we are leaving the network.
156  // ------------------------------------------------------------------
157 
158  LOG(VB_UPNP, LOG_INFO,
159  "SSDP::EnableNotifications() - sending NTS_byebye");
161  m_pNotifyTask->Execute( nullptr );
162 
164  }
165 
166  // ------------------------------------------------------------------
167  // Add Announcement Task to the Queue
168  // ------------------------------------------------------------------
169 
170  LOG(VB_UPNP, LOG_INFO, "SSDP::EnableNotifications() - sending NTS_alive");
171 
173 
175 
176  LOG(VB_UPNP, LOG_INFO,
177  "SSDP::EnableNotifications() - Task added to UPnP queue");
178 }
179 
181 //
183 
185 {
186  m_bAnnouncementsEnabled = false;
187 
188  if (m_pNotifyTask != nullptr)
189  {
190  // Send Announcement that we are leaving.
191 
193  m_pNotifyTask->Execute( nullptr );
194  }
195 }
196 
198 //
200 void SSDP::PerformSearch(const QString &sST, uint timeout_secs)
201 {
202  timeout_secs = std::max(std::min(timeout_secs, 5U), 1U);
203  QString rRequest = QString("M-SEARCH * HTTP/1.1\r\n"
204  "HOST: 239.255.255.250:1900\r\n"
205  "MAN: \"ssdp:discover\"\r\n"
206  "MX: %1\r\n"
207  "ST: %2\r\n"
208  "\r\n")
209  .arg(timeout_secs).arg(sST);
210 
211  LOG(VB_UPNP, LOG_DEBUG, QString("\n\n%1\n").arg(rRequest));
212 
213  QByteArray sRequest = rRequest.toUtf8();
214 
215  MSocketDevice *pSocket = m_sockets[ SocketIdx_Search ];
216  if ( !pSocket->isValid() )
217  {
218  pSocket->setProtocol(MSocketDevice::IPv4);
219  pSocket->setSocket(pSocket->createNewSocket(), MSocketDevice::Datagram);
220  }
221 
222  QHostAddress address;
223  address.setAddress( SSDP_GROUP );
224 
225  int nSize = sRequest.size();
226 
227  if ( pSocket->writeBlock( sRequest.data(),
228  sRequest.size(), address, SSDP_PORT ) != nSize)
229  LOG(VB_GENERAL, LOG_INFO,
230  "SSDP::PerformSearch - did not write entire buffer.");
231 
232  std::this_thread::sleep_for(std::chrono::milliseconds(MythRandom() % 250));
233 
234  if ( pSocket->writeBlock( sRequest.data(),
235  sRequest.size(), address, SSDP_PORT ) != nSize)
236  LOG(VB_GENERAL, LOG_INFO,
237  "SSDP::PerformSearch - did not write entire buffer.");
238 }
239 
241 //
243 
244 void SSDP::run()
245 {
246  RunProlog();
247 
248  fd_set read_set;
249  struct timeval timeout {};
250 
251  LOG(VB_UPNP, LOG_INFO, "SSDP::Run - SSDP Thread Started." );
252 
253  // ----------------------------------------------------------------------
254  // Listen for new Requests
255  // ----------------------------------------------------------------------
256 
257  while ( ! m_bTermRequested )
258  {
259  int nMaxSocket = 0;
260 
261  FD_ZERO( &read_set ); // NOLINT(readability-isolate-declaration)
262 
263  for (auto & socket : m_sockets)
264  {
265  if (socket != nullptr && socket->socket() >= 0)
266  {
267  FD_SET( socket->socket(), &read_set );
268  nMaxSocket = std::max( socket->socket(), nMaxSocket );
269 
270 #if 0
271  if (socket->bytesAvailable() > 0)
272  {
273  LOG(VB_GENERAL, LOG_DEBUG,
274  QString("Found Extra data before select: %1")
275  .arg(nIdx));
276  ProcessData( socket );
277  }
278 #endif
279  }
280  }
281 
282  timeout.tv_sec = 1;
283  timeout.tv_usec = 0;
284 
285  int count = select(nMaxSocket + 1, &read_set, nullptr, nullptr, &timeout);
286 
287  for (int nIdx = 0; count && nIdx < kNumberOfSockets; nIdx++ )
288  {
289  bool cond1 = m_sockets[nIdx] != nullptr;
290  bool cond2 = cond1 && m_sockets[nIdx]->socket() >= 0;
291  bool cond3 = cond2 && FD_ISSET(m_sockets[nIdx]->socket(), &read_set);
292 
293  if (cond3)
294  {
295 #if 0
296  LOG(VB_GENERAL, LOG_DEBUG, QString("FD_ISSET( %1 )").arg(nIdx));
297 #endif
298 
299  ProcessData(m_sockets[nIdx]);
300  count--;
301  }
302  }
303  }
304 
305  RunEpilog();
306 }
307 
309 //
311 
312 void SSDP::ProcessData( MSocketDevice *pSocket )
313 {
314  QByteArray buffer;
315  long nBytes = pSocket->bytesAvailable();
316  int retries = 0;
317  // Note: this function MUST do a read even if someone sends a zero byte UDP message
318  // Otherwise the select() will continue to signal data ready, so to prevent using 100%
319  // CPU, we need to call a recv function to make select() block again
320  bool didDoRead = false;
321 
322  // UDP message of zero length? OK, "recv" it and move on
323  if (nBytes == 0)
324  {
325  LOG(VB_UPNP, LOG_WARNING, QString("SSDP: Received 0 byte UDP message"));
326  }
327 
328  while (((nBytes = pSocket->bytesAvailable()) > 0 || (nBytes == 0 && !didDoRead)) && !m_bTermRequested)
329  {
330  buffer.resize(nBytes);
331 
332  long nRead = 0;
333  do
334  {
335  long ret = pSocket->readBlock( buffer.data() + nRead, nBytes - nRead );
336  didDoRead = true;
337  if (ret < 0)
338  {
339  if (errno == EAGAIN
340 #if EAGAIN != EWOULDBLOCK
341  || errno == EWOULDBLOCK
342 #endif
343  )
344  {
345  if (retries == 3)
346  {
347  nBytes = nRead;
348  buffer.resize(nBytes);
349  break;
350  }
351  retries++;
352  std::this_thread::sleep_for(std::chrono::milliseconds(10));
353  continue;
354  }
355  LOG(VB_GENERAL, LOG_ERR, QString("Socket readBlock error %1")
356  .arg(pSocket->error()));
357  buffer.clear();
358  break;
359  }
360  retries = 0;
361 
362  nRead += ret;
363 
364  if (0 == ret && nBytes != 0)
365  {
366  LOG(VB_SOCKET, LOG_WARNING,
367  QString("%1 bytes reported available, "
368  "but only %2 bytes read.")
369  .arg(nBytes).arg(nRead));
370  nBytes = nRead;
371  buffer.resize(nBytes);
372  break;
373  }
374  }
375  while (nRead < nBytes);
376 
377  if (buffer.isEmpty())
378  continue;
379 
380  QHostAddress peerAddress = pSocket->peerAddress();
381  quint16 peerPort = pSocket->peerPort ();
382 
383  // ------------------------------------------------------------------
384  QString str = QString(buffer.constData());
385 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
386  QStringList lines = str.split("\r\n", QString::SkipEmptyParts);
387 #else
388  QStringList lines = str.split("\r\n", Qt::SkipEmptyParts);
389 #endif
390  QString sRequestLine = !lines.empty() ? lines[0] : "";
391 
392  if (!lines.isEmpty())
393  lines.pop_front();
394 
395  // ------------------------------------------------------------------
396  // Parse request Type
397  // ------------------------------------------------------------------
398 
399  LOG(VB_UPNP, LOG_DEBUG, QString("SSDP::ProcessData - requestLine: %1")
400  .arg(sRequestLine));
401 
402  SSDPRequestType eType = ProcessRequestLine( sRequestLine );
403 
404  // ------------------------------------------------------------------
405  // Read Headers into map
406  // ------------------------------------------------------------------
407 
408  QStringMap headers;
409 
410  for (const auto& sLine : qAsConst(lines))
411  {
412  QString sName = sLine.section( ':', 0, 0 ).trimmed();
413  QString sValue = sLine.section( ':', 1 );
414 
415  sValue.truncate( sValue.length() ); //-2
416 
417  if ((sName.length() != 0) && (sValue.length() !=0))
418  headers.insert( sName.toLower(), sValue.trimmed() );
419  }
420 
421 #if 0
422  pSocket->SetDestAddress( peerAddress, peerPort );
423 #endif
424 
425  // --------------------------------------------------------------
426  // See if this is a valid request
427  // --------------------------------------------------------------
428 
429  switch( eType )
430  {
431  case SSDP_MSearch:
432  {
433  // ----------------------------------------------------------
434  // If we haven't enabled notifications yet, then we don't
435  // want to answer search requests.
436  // ----------------------------------------------------------
437 
438  if (m_pNotifyTask != nullptr)
439  ProcessSearchRequest( headers, peerAddress, peerPort );
440 
441  break;
442  }
443 
444  case SSDP_MSearchResp:
445  ProcessSearchResponse( headers);
446  break;
447 
448  case SSDP_Notify:
449  ProcessNotify( headers );
450  break;
451 
452  case SSDP_Unknown:
453  default:
454  LOG(VB_UPNP, LOG_ERR,
455  "SSPD::ProcessData - Unknown request Type.");
456  break;
457  }
458  }
459 }
460 
462 //
464 
466 {
467 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
468  QStringList tokens = sLine.split(m_procReqLineExp, QString::SkipEmptyParts);
469 #else
470  QStringList tokens = sLine.split(m_procReqLineExp, Qt::SkipEmptyParts);
471 #endif
472 
473  // ----------------------------------------------------------------------
474  // if this is actually a response, then sLine's format will be:
475  // HTTP/m.n <response code> <response text>
476  // otherwise:
477  // <method> <Resource URI> HTTP/m.n
478  // ----------------------------------------------------------------------
479 
480  if ( sLine.startsWith( QString("HTTP/") ))
481  return SSDP_MSearchResp;
482 
483  if (tokens.count() > 0)
484  {
485  if (tokens[0] == "M-SEARCH" ) return SSDP_MSearch;
486  if (tokens[0] == "NOTIFY" ) return SSDP_Notify;
487  }
488 
489  return SSDP_Unknown;
490 }
491 
493 //
495 
496 QString SSDP::GetHeaderValue( const QStringMap &headers,
497  const QString &sKey, const QString &sDefault )
498 {
499  QStringMap::const_iterator it = headers.find( sKey.toLower() );
500 
501  if ( it == headers.end())
502  return( sDefault );
503 
504  return *it;
505 }
506 
508 //
510 
511 bool SSDP::ProcessSearchRequest( const QStringMap &sHeaders,
512  const QHostAddress& peerAddress,
513  quint16 peerPort ) const
514 {
515  QString sMAN = GetHeaderValue( sHeaders, "MAN", "" );
516  QString sST = GetHeaderValue( sHeaders, "ST" , "" );
517  QString sMX = GetHeaderValue( sHeaders, "MX" , "" );
518  int nMX = 0;
519 
520  LOG(VB_UPNP, LOG_DEBUG, QString("SSDP::ProcessSearchrequest : [%1] MX=%2")
521  .arg(sST).arg(sMX));
522 
523  // ----------------------------------------------------------------------
524  // Validate Header Values...
525  // ----------------------------------------------------------------------
526 
527 #if 0
528  if ( pRequest->m_sMethod != "*" ) return false;
529  if ( pRequest->m_sProtocol != "HTTP" ) return false;
530  if ( pRequest->m_nMajor != 1 ) return false;
531 #endif
532  if ( sMAN != "\"ssdp:discover\"" ) return false;
533  if ( sST.length() == 0 ) return false;
534  if ( sMX.length() == 0 ) return false;
535  if ((nMX = sMX.toInt()) == 0 ) return false;
536  if ( nMX < 0 ) return false;
537 
538  // ----------------------------------------------------------------------
539  // Adjust timeout to be a random interval between 0 and MX (max of 120)
540  // ----------------------------------------------------------------------
541 
542  nMX = (nMX > 120) ? 120 : nMX;
543 
544  int nNewMX = (0 + static_cast<int>(MythRandom() % nMX)) * 1000;
545 
546  // ----------------------------------------------------------------------
547  // See what they are looking for...
548  // ----------------------------------------------------------------------
549 
550  if ((sST == "ssdp:all") || (sST == "upnp:rootdevice"))
551  {
552  auto *pTask = new UPnpSearchTask( m_nServicePort,
553  peerAddress, peerPort, sST,
554  UPnp::g_UPnpDeviceDesc.m_rootDevice.GetUDN());
555 
556 #if 0
557  // Excute task now for fastest response, queue for time-delayed response
558  // -=>TODO: To be trully uPnp compliant, this Execute should be removed.
559  pTask->Execute( nullptr );
560 #endif
561 
562  TaskQueue::Instance()->AddTask( nNewMX, pTask );
563 
564  pTask->DecrRef();
565 
566  return true;
567  }
568 
569  // ----------------------------------------------------------------------
570  // Look for a specific device/service
571  // ----------------------------------------------------------------------
572 
573  QString sUDN = UPnp::g_UPnpDeviceDesc.FindDeviceUDN(
574  &(UPnp::g_UPnpDeviceDesc.m_rootDevice), sST );
575 
576  if (sUDN.length() > 0)
577  {
578  auto *pTask = new UPnpSearchTask( m_nServicePort, peerAddress,
579  peerPort, sST, sUDN );
580 
581  // Excute task now for fastest response, queue for time-delayed response
582  // -=>TODO: To be trully uPnp compliant, this Execute should be removed.
583  pTask->Execute( nullptr );
584 
585  TaskQueue::Instance()->AddTask( nNewMX, pTask );
586 
587  pTask->DecrRef();
588 
589  return true;
590  }
591 
592  return false;
593 }
594 
596 //
598 
600 {
601  QString sDescURL = GetHeaderValue( headers, "LOCATION" , "" );
602  QString sST = GetHeaderValue( headers, "ST" , "" );
603  QString sUSN = GetHeaderValue( headers, "USN" , "" );
604  QString sCache = GetHeaderValue( headers, "CACHE-CONTROL" , "" );
605 
606  LOG(VB_UPNP, LOG_DEBUG,
607  QString( "SSDP::ProcessSearchResponse ...\n"
608  "DescURL=%1\n"
609  "ST =%2\n"
610  "USN =%3\n"
611  "Cache =%4")
612  .arg(sDescURL).arg(sST).arg(sUSN).arg(sCache));
613 
614  int nPos = sCache.indexOf("max-age", 0, Qt::CaseInsensitive);
615 
616  if (nPos < 0)
617  return false;
618 
619  if ((nPos = sCache.indexOf("=", nPos)) < 0)
620  return false;
621 
622  int nSecs = sCache.midRef( nPos+1 ).toInt();
623 
624  SSDPCache::Instance()->Add( sST, sUSN, sDescURL, nSecs );
625 
626  return true;
627 }
628 
630 //
632 
633 bool SSDP::ProcessNotify( const QStringMap &headers )
634 {
635  QString sDescURL = GetHeaderValue( headers, "LOCATION" , "" );
636  QString sNTS = GetHeaderValue( headers, "NTS" , "" );
637  QString sNT = GetHeaderValue( headers, "NT" , "" );
638  QString sUSN = GetHeaderValue( headers, "USN" , "" );
639  QString sCache = GetHeaderValue( headers, "CACHE-CONTROL" , "" );
640 
641  LOG(VB_UPNP, LOG_DEBUG,
642  QString( "SSDP::ProcessNotify ...\n"
643  "DescURL=%1\n"
644  "NTS =%2\n"
645  "NT =%3\n"
646  "USN =%4\n"
647  "Cache =%5" )
648  .arg(sDescURL).arg(sNTS).arg(sNT).arg(sUSN).arg(sCache));
649 
650  if (sNTS.contains( "ssdp:alive"))
651  {
652  int nPos = sCache.indexOf("max-age", 0, Qt::CaseInsensitive);
653 
654  if (nPos < 0)
655  return false;
656 
657  if ((nPos = sCache.indexOf("=", nPos)) < 0)
658  return false;
659 
660  int nSecs = sCache.midRef( nPos+1 ).toInt();
661 
662  SSDPCache::Instance()->Add( sNT, sUSN, sDescURL, nSecs );
663 
664  return true;
665  }
666 
667 
668  if ( sNTS.contains( "ssdp:byebye" ) )
669  {
670  SSDPCache::Instance()->Remove( sNT, sUSN );
671 
672  return true;
673  }
674 
675  return false;
676 }
677 
680 //
681 // SSDPExtension Implementation
682 //
685 
687 //
689 
690 SSDPExtension::SSDPExtension( int nServicePort , const QString &sSharePath)
691  : HttpServerExtension( "SSDP" , sSharePath),
692  m_nServicePort(nServicePort)
693 {
695  m_sUPnpDescPath = UPnp::GetConfiguration()->GetValue( "UPnP/DescXmlPath",
696  m_sSharePath );
697 }
698 
700 //
702 
703 SSDPMethod SSDPExtension::GetMethod( const QString &sURI )
704 {
705  if (sURI == "getDeviceDesc" ) return( SSDPM_GetDeviceDesc );
706  if (sURI == "getDeviceList" ) return( SSDPM_GetDeviceList );
707 
708  return( SSDPM_Unknown );
709 }
710 
712 //
714 
716 {
717  // -=>TODO: This is very inefficient... should look into making
718  // it a unique path.
719 
720  return QStringList( "/" );
721 }
722 
724 //
726 
728 {
729  if (pRequest)
730  {
731  if ( pRequest->m_sBaseUrl != "/")
732  return( false );
733 
734  switch( GetMethod( pRequest->m_sMethod ))
735  {
736  case SSDPM_GetDeviceDesc: GetDeviceDesc( pRequest ); return( true );
737  case SSDPM_GetDeviceList: GetDeviceList( pRequest ); return( true );
738 
739  default: break;
740  }
741  }
742 
743  return( false );
744 }
745 
747 //
749 
751 {
752  pRequest->m_eResponseType = ResponseTypeXML;
753 
754  QString sUserAgent = pRequest->GetRequestHeader( "User-Agent", "" );
755 
756  LOG(VB_UPNP, LOG_DEBUG, "SSDPExtension::GetDeviceDesc - " +
757  QString( "Host=%1 Port=%2 UserAgent=%3" )
758  .arg(pRequest->GetHostAddress()) .arg(m_nServicePort)
759  .arg(sUserAgent));
760 
761  QTextStream stream( &(pRequest->m_response) );
762 
765  stream,
766  sUserAgent );
767 }
768 
770 //
772 
773 void SSDPExtension::GetFile( HTTPRequest *pRequest, const QString& sFileName )
774 {
775  pRequest->m_eResponseType = ResponseTypeHTML;
776 
777  pRequest->m_sFileName = m_sUPnpDescPath + sFileName;
778 
779  if (QFile::exists( pRequest->m_sFileName ))
780  {
781  LOG(VB_UPNP, LOG_DEBUG,
782  QString("SSDPExtension::GetFile( %1 ) - Exists")
783  .arg(pRequest->m_sFileName));
784 
785  pRequest->m_eResponseType = ResponseTypeFile;
786  pRequest->m_nResponseStatus = 200;
787  pRequest->m_mapRespHeaders[ "Cache-Control" ]
788  = "no-cache=\"Ext\", max-age = 7200"; // 2 hours
789  }
790  else
791  {
792  pRequest->m_nResponseStatus = 404;
793  pRequest->m_response.write( pRequest->GetResponsePage() );
794  LOG(VB_UPNP, LOG_ERR,
795  QString("SSDPExtension::GetFile( %1 ) - Not Found")
796  .arg(pRequest->m_sFileName));
797  }
798 
799 }
800 
802 //
804 
806 {
807  LOG(VB_UPNP, LOG_DEBUG, "SSDPExtension::GetDeviceList");
808 
809  QString sXML;
810  QTextStream os(&sXML, QIODevice::WriteOnly);
811 
812  uint nDevCount = 0;
813  uint nEntryCount = 0;
814  SSDPCache::Instance()->OutputXML(os, &nDevCount, &nEntryCount);
815 
816  NameValues list;
817  list.push_back(
818  NameValue("DeviceCount", (int)nDevCount));
819  list.push_back(
820  NameValue("DevicesAllocated", SSDPCacheEntries::g_nAllocated));
821  list.push_back(
822  NameValue("CacheEntriesFound", (int)nEntryCount));
823  list.push_back(
824  NameValue("CacheEntriesAllocated", DeviceLocation::g_nAllocated));
825  list.push_back(
826  NameValue("DeviceList", sXML));
827 
828  pRequest->FormatActionResponse(list);
829 
830  pRequest->m_eResponseType = ResponseTypeXML;
831  pRequest->m_nResponseStatus = 200;
832 }
HTTPRequest::GetRequestHeader
QString GetRequestHeader(const QString &sKey, const QString &sDefault)
Definition: httprequest.cpp:1176
NameValue
Definition: upnputil.h:52
HTTPRequest::m_sBaseUrl
QString m_sBaseUrl
Definition: httprequest.h:125
DeviceLocation::g_nAllocated
static int g_nAllocated
Definition: upnpdevice.h:211
HttpServerExtension::m_nSupportedMethods
uint m_nSupportedMethods
Definition: httpserver.h:81
SSDPExtension::m_nServicePort
int m_nServicePort
Definition: ssdp.h:146
HTTPRequest
Definition: httprequest.h:107
MThread::start
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:288
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
SSDP::run
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: ssdp.cpp:244
SSDPExtension::GetBasePaths
QStringList GetBasePaths() override
Definition: ssdp.cpp:715
UPnpDeviceDesc::GetValidXML
void GetValidXML(const QString &sBaseAddress, int nPort, QTextStream &os, const QString &sUserAgent="")
Definition: upnpdevice.cpp:323
ReferenceCounter::DecrRef
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
Definition: referencecounter.cpp:125
UPnpSearchTask
Definition: upnptasksearch.h:40
UPnpNotifyTask
Definition: upnptasknotify.h:52
SSDP_PORT
#define SSDP_PORT
Definition: ssdp.h:27
HTTPRequest::m_sMethod
QString m_sMethod
Definition: httprequest.h:127
SSDP::g_pSSDP
static SSDP * g_pSSDP
Definition: ssdp.h:61
MMulticastSocketDevice
Definition: mmulticastsocketdevice.h:47
g_pSSDPCreationLock
static QMutex g_pSSDPCreationLock
Definition: ssdp.cpp:46
SSDP::m_pNotifyTask
UPnpNotifyTask * m_pNotifyTask
Definition: ssdp.h:71
upnptasksearch.h
arg
arg(title).arg(filename).arg(doDelete))
SSDPM_GetDeviceList
@ SSDPM_GetDeviceList
Definition: ssdp.h:34
NTS_alive
@ NTS_alive
Definition: upnptasknotify.h:40
SSDP_MSearch
@ SSDP_MSearch
Definition: ssdp.h:40
SocketIdx_Multicast
#define SocketIdx_Multicast
Definition: ssdp.h:54
NTS_byebye
@ NTS_byebye
Definition: upnptasknotify.h:41
TaskQueue::AddTask
void AddTask(long msec, Task *pTask)
Definition: taskqueue.cpp:170
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MThread::RunProlog
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
Definition: mthread.cpp:198
UPnpDeviceDesc::FindDeviceUDN
QString FindDeviceUDN(UPnpDevice *pDevice, QString sST)
Definition: upnpdevice.cpp:548
SSDP::ProcessSearchResponse
static bool ProcessSearchResponse(const QStringMap &sHeaders)
Definition: ssdp.cpp:599
SSDP::m_nSearchPort
int m_nSearchPort
Definition: ssdp.h:68
SSDP::m_nPort
int m_nPort
Definition: ssdp.h:67
SSDPCache::Instance
static SSDPCache * Instance()
Definition: ssdpcache.cpp:244
SSDP::Shutdown
static void Shutdown()
Definition: ssdp.cpp:63
ResponseTypeFile
@ ResponseTypeFile
Definition: httprequest.h:82
HTTPRequest::m_mapRespHeaders
QStringMap m_mapRespHeaders
Definition: httprequest.h:151
SSDP::m_nServicePort
int m_nServicePort
Definition: ssdp.h:69
SSDP::Instance
static SSDP * Instance()
Definition: ssdp.cpp:53
NameValues
Definition: upnputil.h:89
HTTPRequest::FormatActionResponse
void FormatActionResponse(Serializer *ser)
Definition: httprequest.cpp:771
SSDP_MSearchResp
@ SSDP_MSearchResp
Definition: ssdp.h:41
SSDP::ProcessNotify
static bool ProcessNotify(const QStringMap &sHeaders)
Definition: ssdp.cpp:633
upnp.h
HTTPRequest::m_nResponseStatus
long m_nResponseStatus
Definition: httprequest.h:150
SSDP::m_bTermRequested
bool m_bTermRequested
Definition: ssdp.h:74
mythlogging.h
RequestTypeMSearch
@ RequestTypeMSearch
Definition: httprequest.h:56
HTTPRequest::GetResponsePage
QByteArray GetResponsePage(void)
Definition: httprequest.cpp:1016
SSDPCache::Add
void Add(const QString &sURI, const QString &sUSN, const QString &sLocation, long sExpiresInSecs)
Definition: ssdpcache.cpp:331
TaskQueue::Instance
static TaskQueue * Instance()
Definition: taskqueue.cpp:58
SSDPExtension::GetMethod
static SSDPMethod GetMethod(const QString &sURI)
Definition: ssdp.cpp:703
QStringMap
QMap< QString, QString > QStringMap
Definition: upnputil.h:44
SSDPExtension::m_sUPnpDescPath
QString m_sUPnpDescPath
Definition: ssdp.h:145
MThread::RunEpilog
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
Definition: mthread.cpp:211
SSDP::~SSDP
~SSDP() override
Definition: ssdp.cpp:114
SSDP_Notify
@ SSDP_Notify
Definition: ssdp.h:42
SocketIdx_Search
#define SocketIdx_Search
Definition: ssdp.h:53
ResponseTypeXML
@ ResponseTypeXML
Definition: httprequest.h:76
uint
unsigned int uint
Definition: compat.h:141
SSDP::ProcessRequestLine
SSDPRequestType ProcessRequestLine(const QString &sLine)
Definition: ssdp.cpp:465
SSDPExtension::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: ssdp.cpp:727
SSDPCache::Remove
void Remove(const QString &sURI, const QString &sUSN)
Definition: ssdpcache.cpp:416
SSDP::kNumberOfSockets
constexpr static int kNumberOfSockets
Definition: ssdp.h:64
SSDP::SSDP
SSDP()
Definition: ssdp.cpp:74
SSDP::m_bAnnouncementsEnabled
bool m_bAnnouncementsEnabled
Definition: ssdp.h:72
HTTPRequest::m_sFileName
QString m_sFileName
Definition: httprequest.h:153
SSDP_Unknown
@ SSDP_Unknown
Definition: ssdp.h:39
ResponseTypeHTML
@ ResponseTypeHTML
Definition: httprequest.h:77
SSDP::DisableNotifications
void DisableNotifications()
Definition: ssdp.cpp:184
SSDPM_Unknown
@ SSDPM_Unknown
Definition: ssdp.h:32
MythRandom
MBASE_PUBLIC uint32_t MythRandom()
Definition: mythmiscutil.h:24
SSDPMethod
SSDPMethod
Definition: ssdp.h:30
SocketIdx_Broadcast
#define SocketIdx_Broadcast
Definition: ssdp.h:55
SSDPCacheEntries::g_nAllocated
static int g_nAllocated
Definition: ssdpcache.h:62
SSDPCache::OutputXML
QTextStream & OutputXML(QTextStream &os, uint *pnDevCount=nullptr, uint *pnEntryCount=nullptr) const
Outputs the XML for this device.
Definition: ssdpcache.cpp:550
RequestTypeNotify
@ RequestTypeNotify
Definition: httprequest.h:59
mythmiscutil.h
upnptaskcache.h
Configuration
Definition: configuration.h:21
SSDPRequestType
SSDPRequestType
Definition: ssdp.h:37
SSDP_SEARCHPORT
#define SSDP_SEARCHPORT
Definition: ssdp.h:28
UPnpNotifyTask::SetNTS
void SetNTS(UPnpNotifyNTS nts)
Definition: upnptasknotify.h:109
SSDPExtension::GetDeviceList
static void GetDeviceList(HTTPRequest *pRequest)
Definition: ssdp.cpp:805
HTTPRequest::m_eResponseType
HttpResponseType m_eResponseType
Definition: httprequest.h:147
SSDP::PerformSearch
void PerformSearch(const QString &sST, uint timeout_secs=2)
Definition: ssdp.cpp:200
mbroadcastsocketdevice.h
SSDPExtension::GetDeviceDesc
void GetDeviceDesc(HTTPRequest *pRequest) const
Definition: ssdp.cpp:750
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
SSDP::ProcessSearchRequest
bool ProcessSearchRequest(const QStringMap &sHeaders, const QHostAddress &peerAddress, quint16 peerPort) const
Definition: ssdp.cpp:511
SSDP::m_sockets
std::array< MSocketDevice *, kNumberOfSockets > m_sockets
Definition: ssdp.h:65
Configuration::GetValue
virtual int GetValue(const QString &sSetting, int Default)=0
mmulticastsocketdevice.h
SSDPM_GetDeviceDesc
@ SSDPM_GetDeviceDesc
Definition: ssdp.h:33
UPnp::GetConfiguration
static Configuration * GetConfiguration()
Definition: upnp.cpp:84
SSDP
Definition: ssdp.h:57
SSDP::EnableNotifications
void EnableNotifications(int nServicePort)
Definition: ssdp.cpp:144
SSDP_GROUP
#define SSDP_GROUP
Definition: ssdp.h:26
MThread::wait
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:305
HTTPRequest::GetHostAddress
virtual QString GetHostAddress()=0
UPnpNotifyTask::Execute
void Execute(TaskQueue *pQueue) override
Definition: upnptasknotify.cpp:137
HttpServerExtension
Definition: httpserver.h:71
UPnp::g_UPnpDeviceDesc
static UPnpDeviceDesc g_UPnpDeviceDesc
Definition: upnp.h:112
SSDPExtension::SSDPExtension
SSDPExtension(int nServicePort, const QString &sSharePath)
Definition: ssdp.cpp:690
SSDP::ProcessData
void ProcessData(MSocketDevice *pSocket)
Definition: ssdp.cpp:312
SSDP::GetHeaderValue
static QString GetHeaderValue(const QStringMap &headers, const QString &sKey, const QString &sDefault)
Definition: ssdp.cpp:496
HTTPRequest::m_response
QBuffer m_response
Definition: httprequest.h:155
SSDPExtension::GetFile
void GetFile(HTTPRequest *pRequest, const QString &sFileName)
Definition: ssdp.cpp:773
MBroadcastSocketDevice
Definition: mbroadcastsocketdevice.h:25
SSDP::RequestTerminate
void RequestTerminate(void)
Definition: ssdp.cpp:135
SSDP::m_procReqLineExp
QRegularExpression m_procReqLineExp
Definition: ssdp.h:63
HttpServerExtension::m_sSharePath
QString m_sSharePath
Definition: httpserver.h:78