diff --git a/src/ippdiscovery.cpp b/src/ippdiscovery.cpp index dc8b38c..a950bdf 100644 --- a/src/ippdiscovery.cpp +++ b/src/ippdiscovery.cpp @@ -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; } diff --git a/src/ippdiscovery.h b/src/ippdiscovery.h index 020a01d..427ce9c 100644 --- a/src/ippdiscovery.h +++ b/src/ippdiscovery.h @@ -16,7 +16,7 @@ class IppDiscovery : public QStringListModel Q_INVOKABLE void discover(); Q_INVOKABLE void reset(); - void resolve(QUrl& url); + bool resolve(QUrl& url); signals: void favouritesChanged(); diff --git a/src/ippprinter.cpp b/src/ippprinter.cpp index 199d4ba..8f7fa3a 100644 --- a/src/ippprinter.cpp +++ b/src/ippprinter.cpp @@ -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()); + } + } +} diff --git a/src/ippprinter.h b/src/ippprinter.h index dda7a73..a351996 100644 --- a/src/ippprinter.h +++ b/src/ippprinter.h @@ -101,6 +101,7 @@ public slots: private: QUrl _url; QUrl httpUrl(); + void resolveUrl(QUrl& url); QJsonObject opAttrs();