94 map.insert(it.key(), *it);
117 LOG(VB_UPNP, LOG_INFO, QString(
"SSDP Cache adding USN: %1 Location %2")
132 LOG(VB_UPNP, LOG_INFO,
133 QString(
"SSDP Cache removing USN: %1 Location %2")
134 .arg((*it)->m_sUSN, (*it)->m_sLocation));
157 else if ((*it)->m_ttExpires < ttNow)
179 QTextStream &os,
uint *pnEntryCount)
const
185 if (entry ==
nullptr)
190 os <<
"<Service usn='" << entry->m_sUSN
191 <<
"' expiresInSecs='" << entry->ExpiresInSecs().count()
192 <<
"' url='" << entry->m_sLocation <<
"' />" << Qt::endl;
194 if (pnEntryCount !=
nullptr)
208 if (entry ==
nullptr)
213 LOG(VB_UPNP, LOG_DEBUG, QString(
" * \t\t%1\t | %2\t | %3 ")
214 .arg(entry->m_sUSN) .arg(entry->ExpiresInSecs().count())
215 .arg(entry->m_sLocation));
225 int uuid_end_loc = sUSN.indexOf(
":",5);
226 if (uuid_end_loc > 0)
227 return sUSN.left(uuid_end_loc).toLower() + sUSN.mid(uuid_end_loc);
253 return(
"SSDPCache" );
264 LOG(VB_UPNP, LOG_INFO,
265 QString(
"SSDPCacheTask - Removed %1 stale entries.")
297 LOG(VB_UPNP, LOG_DEBUG,
"SSDPCache - Constructor");
316 LOG(VB_UPNP, LOG_DEBUG,
"SSDPCache - Destructor");
330 for (
auto *
const it : std::as_const(
m_cache))
345 SSDPCacheEntriesMap::iterator it =
m_cache.find(sURI);
346 if (it !=
m_cache.end() && (*it !=
nullptr))
349 return (it !=
m_cache.end()) ? *it :
nullptr;
359 if (pEntries !=
nullptr)
361 pEntry = pEntries->
Find(sUSN);
375 std::chrono::seconds sExpiresInSecs )
381 auto ttExpires = nowAsDuration<std::chrono::microseconds>() + sExpiresInSecs;
390 SSDPCacheEntriesMap::iterator it =
m_cache.find(sURI);
391 if (it ==
m_cache.end() || (*it ==
nullptr))
394 it =
m_cache.insert(sURI, pEntries);
405 if (pEntry ==
nullptr)
408 QString host = url.host();
409 QString hostport = QString(
"%1:%2").arg(host).arg(url.port(80));
416 bool isGoodUrl =
false;
422 if (checker.
checkPort(host, url.port(80), 5s))
436 pEntries->
Insert(sUSN, pEntry);
465 SSDPCacheEntriesMap::Iterator it =
m_cache.find( sURI );
471 if (pEntries !=
nullptr)
477 if (pEntries->
Count() == 0)
504 auto ttNow = nowAsDuration<std::chrono::microseconds>();
516 if (pEntries !=
nullptr)
522 if (pEntries->
Count() == 0)
523 lstKeys.append( it.key() );
529 nCount = lstKeys.count();
536 for (
const auto & key : std::as_const(lstKeys))
538 SSDPCacheEntriesMap::iterator it =
m_cache.find( key );
564 values.append( sURI );
565 values.append( sUSN );
581 values.append( sURI );
582 values.append( sUSN );
591 QTextStream &os,
uint *pnDevCount,
uint *pnEntryCount)
const
595 if (pnDevCount !=
nullptr)
597 if (pnEntryCount !=
nullptr)
604 os <<
"<Device uri='" << it.key() <<
"'>" << Qt::endl;
608 (*it)->OutputXML(os, &
tmp);
610 if (pnEntryCount !=
nullptr)
611 *pnEntryCount +=
tmp;
613 os <<
"</Device>" << Qt::endl;
615 if (pnDevCount !=
nullptr)
632 LOG(VB_UPNP, LOG_DEBUG,
"========================================"
633 "=======================================");
634 LOG(VB_UPNP, LOG_DEBUG, QString(
" URI (type) - Found: %1 Entries - "
635 "%2 have been Allocated. ")
637 LOG(VB_UPNP, LOG_DEBUG,
" \t\tUSN (unique id)\t\t | Expires"
639 LOG(VB_UPNP, LOG_DEBUG,
"----------------------------------------"
640 "---------------------------------------");
647 LOG(VB_UPNP, LOG_DEBUG, it.key());
649 LOG(VB_UPNP, LOG_DEBUG,
" ");
653 LOG(VB_UPNP, LOG_DEBUG,
"----------------------------------------"
654 "---------------------------------------");
655 LOG(VB_UPNP, LOG_DEBUG,
656 QString(
" Found: %1 Entries - %2 have been Allocated. ")
658 LOG(VB_UPNP, LOG_DEBUG,
"========================================"
659 "=======================================" );
std::chrono::microseconds m_ttExpires
This class is used as a container for messages.
void dispatch(const MythEvent &event)
Dispatch an event to all listeners.
Small class to handle TCP port checking and finding link-local context.
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.
General purpose reference counter.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
virtual int IncrRef(void)
Increments reference count.
static QString GetNormalizedUSN(const QString &sUSN)
Returns a normalized USN, so that capitalization of the uuid is not an issue.
void Insert(const QString &sUSN, DeviceLocation *pEntry)
Inserts a device location into the cache.
DeviceLocation * Find(const QString &sUSN)
Finds the Device in the cache, returns nullptr when absent.
uint RemoveStale(std::chrono::microseconds ttNow)
Removes expired cache entries, returning the number removed.
void GetEntryMap(EntryMap &map)
Returns a copy of the EntryMap.
void Dump(uint &nEntryCount) const
Prints this service to the console in human readable form.
void Clear(void)
Clears the cache of all entries.
void Remove(const QString &sUSN)
Removes a specific entry from the cache.
~SSDPCacheEntries() override
Destructor protected to enforce Release method usage.
QTextStream & OutputXML(QTextStream &os, uint *pnEntryCount=nullptr) const
Outputs the XML for this service.
DeviceLocation * GetFirst(void)
Returns random entry in cache, returns nullptr when list is empty.
~SSDPCacheTask() override=default
std::chrono::milliseconds m_nInterval
void Execute(TaskQueue *pQueue) override
SSDPCacheEntriesMap m_cache
void NotifyAdd(const QString &sURI, const QString &sUSN, const QString &sLocation)
QTextStream & OutputXML(QTextStream &os, uint *pnDevCount=nullptr, uint *pnEntryCount=nullptr) const
Outputs the XML for this device.
static SSDPCache * g_pSSDPCache
static SSDPCache * Instance()
void NotifyRemove(const QString &sURI, const QString &sUSN)
void Add(const QString &sURI, const QString &sUSN, const QString &sLocation, std::chrono::seconds sExpiresInSecs)
QStringList m_goodUrlList
SSDPCacheEntries * Find(const QString &sURI)
Finds the SSDPCacheEntries in the cache, returns nullptr when absent.
void Remove(const QString &sURI, const QString &sUSN)
void Dump(void)
Prints this device to the console in a human readable form.
void AddTask(std::chrono::milliseconds msec, Task *pTask)
Add a task to run in the future.
static TaskQueue * Instance()
static const QString sLocation
static bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
QMap< QString, DeviceLocation * > EntryMap
Key == Unique Service Name (USN)