Skip to content

Commit

Permalink
Improve likelyhood of name resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed May 26, 2022
1 parent a7d181a commit 58619bd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/ippdiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ void IppDiscovery::readPendingDatagrams()

}

void IppDiscovery::resolve(QUrl& url)
bool IppDiscovery::resolve(QUrl& url)
{
QString host = url.host();

Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion src/ippdiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 24 additions & 2 deletions src/ippprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -161,9 +161,10 @@ void IppPrinter::MaybeGetIcon(bool retry)
}
}

resolveUrl(url);

if(isAllowedAddress(url))
{
IppDiscovery::instance()->resolve(url);
emit doGetImage(url);
}
}
Expand Down Expand Up @@ -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());
}
}
}
1 change: 1 addition & 0 deletions src/ippprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public slots:
private:
QUrl _url;
QUrl httpUrl();
void resolveUrl(QUrl& url);

QJsonObject opAttrs();

Expand Down

0 comments on commit 58619bd

Please sign in to comment.