Go to the documentation of this file.
20 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
22 #define QT_FLUSH flush
24 #define QT_ENDL Qt::endl
25 #define QT_FLUSH Qt::flush
100 map.insert(it.key(), *it);
123 LOG(VB_UPNP, LOG_INFO, QString(
"SSDP Cache adding USN: %1 Location %2")
138 LOG(VB_UPNP, LOG_INFO,
139 QString(
"SSDP Cache removing USN: %1 Location %2")
140 .arg((*it)->m_sUSN, (*it)->m_sLocation));
163 else if ((*it)->m_ttExpires < ttNow)
185 QTextStream &os,
uint *pnEntryCount)
const
191 if (entry ==
nullptr)
196 os <<
"<Service usn='" << entry->m_sUSN
197 <<
"' expiresInSecs='" << entry->ExpiresInSecs().count()
198 <<
"' url='" << entry->m_sLocation <<
"' />" <<
QT_ENDL;
200 if (pnEntryCount !=
nullptr)
214 if (entry ==
nullptr)
219 LOG(VB_UPNP, LOG_DEBUG, QString(
" * \t\t%1\t | %2\t | %3 ")
220 .arg(entry->m_sUSN) .arg(entry->ExpiresInSecs().count())
221 .arg(entry->m_sLocation));
231 int uuid_end_loc = sUSN.indexOf(
":",5);
232 if (uuid_end_loc > 0)
233 return sUSN.left(uuid_end_loc).toLower() + sUSN.mid(uuid_end_loc);
257 LOG(VB_UPNP, LOG_DEBUG,
"SSDPCache - Constructor");
276 LOG(VB_UPNP, LOG_DEBUG,
"SSDPCache - Destructor");
290 for (
auto *
const it : qAsConst(
m_cache))
305 SSDPCacheEntriesMap::iterator it =
m_cache.find(sURI);
306 if (it !=
m_cache.end() && (*it !=
nullptr))
309 return (it !=
m_cache.end()) ? *it :
nullptr;
319 if (pEntries !=
nullptr)
321 pEntry = pEntries->
Find(sUSN);
335 std::chrono::seconds sExpiresInSecs )
341 auto ttExpires = nowAsDuration<std::chrono::microseconds>() + sExpiresInSecs;
350 SSDPCacheEntriesMap::iterator it =
m_cache.find(sURI);
351 if (it ==
m_cache.end() || (*it ==
nullptr))
354 it =
m_cache.insert(sURI, pEntries);
365 if (pEntry ==
nullptr)
368 QString host = url.host();
369 QString hostport = QString(
"%1:%2").arg(host).arg(url.port(80));
376 bool isGoodUrl =
false;
382 if (checker.
checkPort(host, url.port(80), 5s))
394 pEntries->
Insert(sUSN, pEntry);
423 SSDPCacheEntriesMap::Iterator it =
m_cache.find( sURI );
429 if (pEntries !=
nullptr)
435 if (pEntries->
Count() == 0)
462 auto ttNow = nowAsDuration<std::chrono::microseconds>();
474 if (pEntries !=
nullptr)
480 if (pEntries->
Count() == 0)
481 lstKeys.append( it.key() );
487 nCount = lstKeys.count();
494 for (
const auto & key : qAsConst(lstKeys))
496 SSDPCacheEntriesMap::iterator it =
m_cache.find( key );
522 values.append( sURI );
523 values.append( sUSN );
539 values.append( sURI );
540 values.append( sUSN );
549 QTextStream &os,
uint *pnDevCount,
uint *pnEntryCount)
const
553 if (pnDevCount !=
nullptr)
555 if (pnEntryCount !=
nullptr)
562 os <<
"<Device uri='" << it.key() <<
"'>" <<
QT_ENDL;
566 (*it)->OutputXML(os, &
tmp);
568 if (pnEntryCount !=
nullptr)
569 *pnEntryCount +=
tmp;
573 if (pnDevCount !=
nullptr)
590 LOG(VB_UPNP, LOG_DEBUG,
"========================================"
591 "=======================================");
592 LOG(VB_UPNP, LOG_DEBUG, QString(
" URI (type) - Found: %1 Entries - "
593 "%2 have been Allocated. ")
595 LOG(VB_UPNP, LOG_DEBUG,
" \t\tUSN (unique id)\t\t | Expires"
597 LOG(VB_UPNP, LOG_DEBUG,
"----------------------------------------"
598 "---------------------------------------");
605 LOG(VB_UPNP, LOG_DEBUG, it.key());
607 LOG(VB_UPNP, LOG_DEBUG,
" ");
611 LOG(VB_UPNP, LOG_DEBUG,
"----------------------------------------"
612 "---------------------------------------");
613 LOG(VB_UPNP, LOG_DEBUG,
614 QString(
" Found: %1 Entries - %2 have been Allocated. ")
616 LOG(VB_UPNP, LOG_DEBUG,
"========================================"
617 "=======================================" );
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.