mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Fix hostname/domain split (#1079)
This commit is contained in:
parent
d5a1e7d19d
commit
56f45a4930
@ -668,7 +668,8 @@ QJsonObject LedDeviceCololight::discover()
|
||||
{
|
||||
QJsonObject obj;
|
||||
|
||||
obj.insert("ip", i.key());
|
||||
QString ipAddress = i.key();
|
||||
obj.insert("ip", ipAddress);
|
||||
obj.insert("model", i.value().value(COLOLIGHT_MODEL));
|
||||
obj.insert("type", i.value().value(COLOLIGHT_MODEL_TYPE));
|
||||
obj.insert("mac", i.value().value(COLOLIGHT_MAC));
|
||||
@ -678,7 +679,6 @@ QJsonObject LedDeviceCololight::discover()
|
||||
if (hostInfo.error() == QHostInfo::NoError)
|
||||
{
|
||||
QString hostname = hostInfo.hostName();
|
||||
//Seems that for Windows no local domain name is resolved
|
||||
if (!QHostInfo::localDomainName().isEmpty())
|
||||
{
|
||||
obj.insert("hostname", hostname.remove("." + QHostInfo::localDomainName()));
|
||||
@ -686,9 +686,23 @@ QJsonObject LedDeviceCololight::discover()
|
||||
}
|
||||
else
|
||||
{
|
||||
int domainPos = hostname.indexOf('.');
|
||||
obj.insert("hostname", hostname.left(domainPos));
|
||||
obj.insert("domain", hostname.mid(domainPos + 1));
|
||||
if (hostname.startsWith(ipAddress))
|
||||
{
|
||||
obj.insert("hostname", ipAddress);
|
||||
|
||||
QString domain = hostname.remove(ipAddress);
|
||||
if (domain.at(0) == '.')
|
||||
{
|
||||
domain.remove(0, 1);
|
||||
}
|
||||
obj.insert("domain", domain);
|
||||
}
|
||||
else
|
||||
{
|
||||
int domainPos = hostname.indexOf('.');
|
||||
obj.insert("hostname", hostname.left(domainPos));
|
||||
obj.insert("domain", hostname.mid(domainPos + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -316,24 +316,40 @@ QJsonArray SSDPDiscover::getServicesDiscoveredJson() const
|
||||
obj.insert("usn", i.value().uniqueServiceName);
|
||||
|
||||
QUrl url (i.value().location);
|
||||
obj.insert("ip", url.host());
|
||||
QString ipAddress = url.host();
|
||||
|
||||
obj.insert("ip", ipAddress);
|
||||
obj.insert("port", url.port());
|
||||
|
||||
QHostInfo hostInfo = QHostInfo::fromName(url.host());
|
||||
if (hostInfo.error() == QHostInfo::NoError )
|
||||
if (hostInfo.error() == QHostInfo::NoError)
|
||||
{
|
||||
QString hostname = hostInfo.hostName();
|
||||
//Seems that for Windows no local domain name is resolved
|
||||
if (!hostInfo.localDomainName().isEmpty() )
|
||||
|
||||
if (!QHostInfo::localDomainName().isEmpty())
|
||||
{
|
||||
obj.insert("hostname", hostname.remove("."+hostInfo.localDomainName()));
|
||||
obj.insert("domain", hostInfo.localDomainName());
|
||||
obj.insert("hostname", hostname.remove("." + QHostInfo::localDomainName()));
|
||||
obj.insert("domain", QHostInfo::localDomainName());
|
||||
}
|
||||
else
|
||||
{
|
||||
int domainPos = hostname.indexOf('.');
|
||||
obj.insert("hostname", hostname.left(domainPos));
|
||||
obj.insert("domain", hostname.mid(domainPos+1));
|
||||
if (hostname.startsWith(ipAddress))
|
||||
{
|
||||
obj.insert("hostname", ipAddress);
|
||||
|
||||
QString domain = hostname.remove(ipAddress);
|
||||
if (domain.at(0) == '.')
|
||||
{
|
||||
domain.remove(0, 1);
|
||||
}
|
||||
obj.insert("domain", domain);
|
||||
}
|
||||
else
|
||||
{
|
||||
int domainPos = hostname.indexOf('.');
|
||||
obj.insert("hostname", hostname.left(domainPos));
|
||||
obj.insert("domain", hostname.mid(domainPos + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user