Improve likelyhood of name resolution

This commit is contained in:
Anton Thomasson 2022-05-26 14:42:01 +02:00
parent a7d181a867
commit 58619bd63a
4 changed files with 29 additions and 4 deletions

View file

@ -404,7 +404,7 @@ void IppDiscovery::readPendingDatagrams()
}
void IppDiscovery::resolve(QUrl& url)
bool IppDiscovery::resolve(QUrl& url)
{
QString host = url.host();
@ -417,5 +417,7 @@ void IppDiscovery::resolve(QUrl& url)
if(_AAs.contains(host))
{ // TODO: retry potential other IPs
url.setHost(_AAs.value(host));
return true;
}
return false;
}

View file

@ -16,7 +16,7 @@ public:
Q_INVOKABLE void discover();
Q_INVOKABLE void reset();
void resolve(QUrl& url);
bool resolve(QUrl& url);
signals:
void favouritesChanged();

View file

@ -127,9 +127,9 @@ void IppPrinter::MaybeGetStrings()
if(_attrs.contains("printer-strings-uri") && _strings.empty())
{
QUrl url(_attrs["printer-strings-uri"].toObject()["value"].toString());
resolveUrl(url);
if(isAllowedAddress(url))
{
IppDiscovery::instance()->resolve(url);
emit doGetStrings(url);
}
}
@ -161,9 +161,10 @@ void IppPrinter::MaybeGetIcon(bool retry)
}
}
resolveUrl(url);
if(isAllowedAddress(url))
{
IppDiscovery::instance()->resolve(url);
emit doGetImage(url);
}
}
@ -897,3 +898,24 @@ IppMsg IppPrinter::mk_msg(QJsonObject opAttrs, QJsonObject jobAttrs)
}
return IppMsg(opAttrs, jobAttrs);
}
void IppPrinter::resolveUrl(QUrl& url)
{
if(!IppDiscovery::instance()->resolve(url))
{ // If "proper" resolution fails, cheat...
QString host = url.host();
if(host.endsWith("."))
{
host.chop(1);
}
QString dnsSdName = _attrs["printer-dns-sd-name"].toObject()["value"].toString();
dnsSdName = dnsSdName.append(".local");
if(host.compare(dnsSdName, Qt::CaseInsensitive) == 0)
{ // This could be done unconditionally, but some might want their externally hosted stuff to work
url.setHost(_url.host());
}
}
}

View file

@ -101,6 +101,7 @@ public slots:
private:
QUrl _url;
QUrl httpUrl();
void resolveUrl(QUrl& url);
QJsonObject opAttrs();