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,19 +679,32 @@ 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()));
|
||||
obj.insert("domain", QHostInfo::localDomainName());
|
||||
}
|
||||
else
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deviceList << obj;
|
||||
}
|
||||
|
|
|
@ -316,18 +316,33 @@ 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)
|
||||
{
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -336,6 +351,7 @@ QJsonArray SSDPDiscover::getServicesDiscoveredJson() const
|
|||
obj.insert("domain", hostname.mid(domainPos + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QJsonObject objOther;
|
||||
QMap <QString,QString>::const_iterator o;
|
||||
|
|
Loading…
Reference in New Issue