Go to the documentation of this file.
92 map.insert(it.key(), *it);
115 LOG(VB_UPNP, LOG_INFO, QString(
"SSDP Cache adding USN: %1 Location %2")
130 LOG(VB_UPNP, LOG_INFO,
131 QString(
"SSDP Cache removing USN: %1 Location %2")
132 .arg((*it)->m_sUSN, (*it)->m_sLocation));
155 else if ((*it)->m_ttExpires < ttNow)
177 QTextStream &os,
uint *pnEntryCount)
const
183 if (entry ==
nullptr)
188 os <<
"<Service usn='" << entry->m_sUSN
189 <<
"' expiresInSecs='" << entry->ExpiresInSecs().count()
190 <<
"' url='" << entry->m_sLocation <<
"' />" << Qt::endl;
192 if (pnEntryCount !=
nullptr)
206 if (entry ==
nullptr)
211 LOG(VB_UPNP, LOG_DEBUG, QString(
" * \t\t%1\t | %2\t | %3 ")
212 .arg(entry->m_sUSN) .arg(entry->ExpiresInSecs().count())
213 .arg(entry->m_sLocation));
223 int uuid_end_loc = sUSN.indexOf(
":",5);
224 if (uuid_end_loc > 0)
225 return sUSN.left(uuid_end_loc).toLower() + sUSN.mid(uuid_end_loc);
249 LOG(VB_UPNP, LOG_DEBUG,
"SSDPCache - Constructor");
268 LOG(VB_UPNP, LOG_DEBUG,
"SSDPCache - Destructor");
282 for (
auto *
const it : std::as_const(
m_cache))
297 SSDPCacheEntriesMap::iterator it =
m_cache.find(sURI);
298 if (it !=
m_cache.end() && (*it !=
nullptr))
301 return (it !=
m_cache.end()) ? *it :
nullptr;
311 if (pEntries !=
nullptr)
313 pEntry = pEntries->
Find(sUSN);
327 std::chrono::seconds sExpiresInSecs )
333 auto ttExpires = nowAsDuration<std::chrono::microseconds>() + sExpiresInSecs;
342 SSDPCacheEntriesMap::iterator it =
m_cache.find(sURI);
343 if (it ==
m_cache.end() || (*it ==
nullptr))
346 it =
m_cache.insert(sURI, pEntries);
357 if (pEntry ==
nullptr)
360 QString host = url.host();
361 QString hostport = QString(
"%1:%2").arg(host).arg(url.port(80));
368 bool isGoodUrl =
false;
374 if (checker.
checkPort(host, url.port(80), 5s))
386 pEntries->
Insert(sUSN, pEntry);
415 SSDPCacheEntriesMap::Iterator it =
m_cache.find( sURI );
421 if (pEntries !=
nullptr)
427 if (pEntries->
Count() == 0)
454 auto ttNow = nowAsDuration<std::chrono::microseconds>();
466 if (pEntries !=
nullptr)
472 if (pEntries->
Count() == 0)
473 lstKeys.append( it.key() );
479 nCount = lstKeys.count();
486 for (
const auto & key : std::as_const(lstKeys))
488 SSDPCacheEntriesMap::iterator it =
m_cache.find( key );
514 values.append( sURI );
515 values.append( sUSN );
531 values.append( sURI );
532 values.append( sUSN );
541 QTextStream &os,
uint *pnDevCount,
uint *pnEntryCount)
const
545 if (pnDevCount !=
nullptr)
547 if (pnEntryCount !=
nullptr)
554 os <<
"<Device uri='" << it.key() <<
"'>" << Qt::endl;
558 (*it)->OutputXML(os, &
tmp);
560 if (pnEntryCount !=
nullptr)
561 *pnEntryCount +=
tmp;
563 os <<
"</Device>" << Qt::endl;
565 if (pnDevCount !=
nullptr)
582 LOG(VB_UPNP, LOG_DEBUG,
"========================================"
583 "=======================================");
584 LOG(VB_UPNP, LOG_DEBUG, QString(
" URI (type) - Found: %1 Entries - "
585 "%2 have been Allocated. ")
587 LOG(VB_UPNP, LOG_DEBUG,
" \t\tUSN (unique id)\t\t | Expires"
589 LOG(VB_UPNP, LOG_DEBUG,
"----------------------------------------"
590 "---------------------------------------");
597 LOG(VB_UPNP, LOG_DEBUG, it.key());
599 LOG(VB_UPNP, LOG_DEBUG,
" ");
603 LOG(VB_UPNP, LOG_DEBUG,
"----------------------------------------"
604 "---------------------------------------");
605 LOG(VB_UPNP, LOG_DEBUG,
606 QString(
" Found: %1 Entries - %2 have been Allocated. ")
608 LOG(VB_UPNP, LOG_DEBUG,
"========================================"
609 "=======================================" );
Small class to handle TCP port checking and finding link-local context.
void Remove(const QString &sUSN)
Removes a specific entry from the cache.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
std::chrono::microseconds TaskTime
uint RemoveStale(TaskTime ttNow)
Removes expired cache entries, returning the number removed.
This class is used as a container for messages.
static bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void GetEntryMap(EntryMap &map)
Returns a copy of the EntryMap.
void dispatch(const MythEvent &event)
Dispatch an event to all listeners.
static SSDPCache * Instance()
static SSDPCache * g_pSSDPCache
void NotifyRemove(const QString &sURI, const QString &sUSN)
void Add(const QString &sURI, const QString &sUSN, const QString &sLocation, std::chrono::seconds sExpiresInSecs)
QTextStream & OutputXML(QTextStream &os, uint *pnEntryCount=nullptr) const
Outputs the XML for this service.
~SSDPCacheEntries() override
Destructor protected to enforce Release method usage.
SSDPCacheEntriesMap m_cache
static TaskQueue * Instance()
SSDPCacheEntries * Find(const QString &sURI)
Finds the SSDPCacheEntries in the cache, returns nullptr when absent.
QMap< QString, DeviceLocation * > EntryMap
Key == Unique Service Name (USN)
QStringList m_goodUrlList
static const QString sLocation
void Insert(const QString &sUSN, DeviceLocation *pEntry)
Inserts a device location into the cache.
void Dump(void)
Prints this device to the console in a human readable form.
void Remove(const QString &sURI, const QString &sUSN)
bool checkPort(QString &host, int port, std::chrono::milliseconds timeLimit=30s, bool linkLocalOnly=false)
Check if a port is open and sort out the link-local scope.
QTextStream & OutputXML(QTextStream &os, uint *pnDevCount=nullptr, uint *pnEntryCount=nullptr) const
Outputs the XML for this device.
void NotifyAdd(const QString &sURI, const QString &sUSN, const QString &sLocation)
static QString GetNormalizedUSN(const QString &sUSN)
Returns a normalized USN, so that capitalization of the uuid is not an issue.
void Clear(void)
Clears the cache of all entries.
void AddTask(std::chrono::milliseconds msec, Task *pTask)
Add a task to run in the future.
void Dump(uint &nEntryCount) const
Prints this service to the console in human readable form.
virtual int IncrRef(void)
Increments reference count.
DeviceLocation * Find(const QString &sUSN)
Finds the Device in the cache, returns nullptr when absent.
General purpose reference counter.
DeviceLocation * GetFirst(void)
Returns random entry in cache, returns nullptr when list is empty.