Resolve string uris

This commit is contained in:
Anton Thomasson 2022-01-14 22:44:55 +01:00
parent 0684e677ec
commit 2ab6a7d979
3 changed files with 23 additions and 14 deletions

View file

@ -404,6 +404,22 @@ void IppDiscovery::readPendingDatagrams()
} }
void IppDiscovery::resolve(QUrl& url)
{
QString host = url.host();
if(host.endsWith("."))
{
host.chop(1);
}
// TODO IPv6
if(_AAs.contains(host))
{ // TODO: retry potential other IPs
url.setHost(_AAs.value(host));
}
}
QImage IppDiscovery::requestImage(const QString &id, QSize *size, const QSize &requestedSize) QImage IppDiscovery::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{ //TODO: consider caching images (doesn't appear to be needed currently) { //TODO: consider caching images (doesn't appear to be needed currently)
Q_UNUSED(requestedSize); Q_UNUSED(requestedSize);
@ -413,19 +429,8 @@ QImage IppDiscovery::requestImage(const QString &id, QSize *size, const QSize &r
QNetworkAccessManager* nam = new QNetworkAccessManager(); QNetworkAccessManager* nam = new QNetworkAccessManager();
QUrl url(id); QUrl url(id);
QString host = url.host();
if(host.endsWith(".")) resolve(url);
{
host.chop(1);
}
qDebug() << url.host() << host << _AAs;
// TODO IPv6
if(_AAs.contains(host))
{ // TODO: retry potential other IPs
url.setHost(_AAs.value(host));
}
QNetworkRequest request(url); QNetworkRequest request(url);
request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint " SEAPRINT_VERSION); request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint " SEAPRINT_VERSION);

View file

@ -21,6 +21,8 @@ public:
Q_INVOKABLE void discover(); Q_INVOKABLE void discover();
Q_INVOKABLE void reset(); Q_INVOKABLE void reset();
void resolve(QUrl& url);
signals: signals:
void favouritesChanged(); void favouritesChanged();
void ignoreSslErrorsChanged(); void ignoreSslErrorsChanged();

View file

@ -1,4 +1,5 @@
#include "ippprinter.h" #include "ippprinter.h"
#include "ippdiscovery.h"
#include "mimer.h" #include "mimer.h"
#include "papersizes.h" #include "papersizes.h"
#include "overrider.h" #include "overrider.h"
@ -125,10 +126,11 @@ void IppPrinter::refresh() {
void IppPrinter::MaybeGetStrings() void IppPrinter::MaybeGetStrings()
{ {
// TODO: resolve .local
if(_attrs.contains("printer-strings-uri") && _strings.empty()) if(_attrs.contains("printer-strings-uri") && _strings.empty())
{ {
emit doGetStrings(QUrl(_attrs["printer-strings-uri"].toObject()["value"].toString())); QUrl url(_attrs["printer-strings-uri"].toObject()["value"].toString());
IppDiscovery::instance()->resolve(url);
emit doGetStrings(url);
} }
} }