From fb46694ab8bb87d55aa13abf840e4029eab70586 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Thu, 2 Jan 2020 21:05:04 +0100 Subject: [PATCH 1/4] Re-send mdns queries for unresolved PTRs --- src/ippdiscovery.cpp | 92 ++++++++++++++++++++++++++------------------ src/ippdiscovery.h | 13 ++++++- 2 files changed, 67 insertions(+), 38 deletions(-) diff --git a/src/ippdiscovery.cpp b/src/ippdiscovery.cpp index 30b81c0..9bffa97 100644 --- a/src/ippdiscovery.cpp +++ b/src/ippdiscovery.cpp @@ -5,6 +5,8 @@ #define AAAA 28 #define SRV 33 +#define ALL 255 //for querying + void put_addr(Bytestream& bts, QStringList addr) { for(int i = 0; i < addr.length(); i++) @@ -57,6 +59,11 @@ IppDiscovery::~IppDiscovery() { void IppDiscovery::discover() { + sendQuery(PTR, {"_ipp","_tcp","local"}); +} + +void IppDiscovery::sendQuery(quint16 qtype, QStringList addr) { + qDebug() << "discovering" << qtype << addr; Bytestream query; quint16 transactionid = 0; @@ -64,18 +71,38 @@ void IppDiscovery::discover() { quint16 questions = 1; query << transactionid << flags << questions << (quint16)0 << (quint16)0 << (quint16)0; - put_addr(query, {"_ipp","_tcp","local"}); - query << (quint16)0x000C << (quint16)0x0001; + put_addr(query, addr); + query << qtype << (quint16)0x0001; QByteArray bytes((char*)(query.raw()), query.size()); socket->writeDatagram(bytes, QHostAddress("224.0.0.251"), 5353); - qDebug() << "discovering"; - } + void IppDiscovery::update() { + for(QStringList::Iterator it = _ipp.begin(); it != _ipp.end(); it++) + { + quint16 port = _ports[*it]; + QString target = _targets[*it]; + QString rp = _rps[*it]; + + for(QMultiMap::Iterator ait = _AAs.begin(); ait != _AAs.end(); ait++) + { + if(ait.key() == target) + { + QString ip = ait.value(); + QString addr = ip+":"+QString::number(port)+"/"+rp; + if(!_found.contains(addr)) + { + _found.append(addr); + _found.sort(Qt::CaseInsensitive); + } + } + } + } + qDebug() << _favourites << _found; this->setStringList(_favourites+_found); } @@ -89,12 +116,7 @@ void IppDiscovery::readPendingDatagrams() QHostAddress sender; quint16 senderPort; - QMap ptrs; - QMap rps; - QMap ports; - QMap targets; - QMultiMap AAs; - QMultiMap AAAAs; + QStringList ipp_ptrs; socket->readDatagram((char*)(resp.raw()), size, &sender, &senderPort); sender = QHostAddress(sender.toIPv4Address()); @@ -121,7 +143,10 @@ void IppDiscovery::readPendingDatagrams() if (atype == PTR) { QString tmpname = get_addr(resp).join("."); - ptrs[aaddr] = tmpname; + if(aaddr.endsWith("_ipp._tcp.local")) + { + ipp_ptrs.append(tmpname); + } } else if(atype == TXT) { @@ -133,7 +158,7 @@ void IppDiscovery::readPendingDatagrams() { std::string tmprp; tmp/tmp.remaining() >> tmprp; - rps[aaddr] = tmprp.c_str(); + _rps[aaddr] = tmprp.c_str(); } } } @@ -142,15 +167,15 @@ void IppDiscovery::readPendingDatagrams() quint16 prio, w, port; resp >> prio >> w >> port; QString target = get_addr(resp).join("."); - ports[aaddr] = port; - targets[aaddr] = target; + _ports[aaddr] = port; + _targets[aaddr] = target; } else if(atype == A) { quint32 addr; resp >> addr; QHostAddress haddr(addr); - AAs.insert(aaddr, haddr.toString()); + _AAs.insert(aaddr, haddr.toString()); } else { @@ -160,33 +185,26 @@ void IppDiscovery::readPendingDatagrams() } - qDebug() << "ptrs" << ptrs; - qDebug() << "rps" << rps; - qDebug() << "ports" << ports; - qDebug() << "targets" << targets; - qDebug() << "AAs" << AAs; - qDebug() << "AAAAs" << AAAAs; + qDebug() << "new ipp ptrs" << ipp_ptrs; + qDebug() << "ipp ptrs" << _ipp; + qDebug() << "rps" << _rps; + qDebug() << "ports" << _ports; + qDebug() << "targets" << _targets; + qDebug() << "AAs" << _AAs; + qDebug() << "AAAAs" << _AAAAs; - for(QMap::Iterator it = ptrs.begin(); it != ptrs.end(); it++) + for(QStringList::Iterator it = ipp_ptrs.begin(); it != ipp_ptrs.end(); it++) { - quint16 port = ports[it.value()]; - QString target = targets[it.value()]; - QString rp = rps[it.value()]; - - for(QMultiMap::Iterator ait = AAs.begin(); ait != AAs.end(); ait++) + if(!_ipp.contains(*it)) { - if(ait.key() == target) - { - QString ip = ait.value(); - QString addr = ip+":"+QString::number(port)+"/"+rp; - if(!_found.contains(addr)) - { - _found.append(addr); - _found.sort(Qt::CaseInsensitive); - } - } + _ipp.append(*it); + } + if(!_ports.contains(*it) || !_targets.contains(*it) || !_rps.contains(*it)) + { // if the PTR doesn't already resolve, ask for everything about it + sendQuery(ALL, it->split('.')); } } + } this->update(); diff --git a/src/ippdiscovery.h b/src/ippdiscovery.h index f988eaa..3dd71dd 100644 --- a/src/ippdiscovery.h +++ b/src/ippdiscovery.h @@ -18,9 +18,20 @@ signals: public slots: void readPendingDatagrams(); - void update(); protected: private: + void sendQuery(quint16 qtype, QStringList addr); + + void update(); + + QStringList _ipp; + QMap _rps; + QMap _ports; + QMap _targets; + + QMultiMap _AAs; + QMultiMap _AAAAs; + QStringList _favourites; QStringList _found; QUdpSocket* socket; From 1b5caf301d74677e471ce01345505a1392378c0a Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Thu, 2 Jan 2020 21:28:35 +0100 Subject: [PATCH 2/4] Make a reset interface for discovery ..WifiChecker still isn't triggering as i'd like still --- qml/pages/FirstPage.qml | 3 +++ src/ippdiscovery.cpp | 25 +++++++++++++++++++------ src/ippdiscovery.h | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 24407b4..1c6b37e 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -31,6 +31,9 @@ Page { } } + onSsidChanged: { + discovery.reset() + } } signal refreshed() diff --git a/src/ippdiscovery.cpp b/src/ippdiscovery.cpp index 9bffa97..823b224 100644 --- a/src/ippdiscovery.cpp +++ b/src/ippdiscovery.cpp @@ -57,11 +57,22 @@ IppDiscovery::~IppDiscovery() { delete socket; } - void IppDiscovery::discover() { sendQuery(PTR, {"_ipp","_tcp","local"}); } +void IppDiscovery::reset() { + _ipp = QStringList(); + _rps = QMap(); + _ports = QMap(); + _targets = QMap(); + + _AAs = QMultiMap(); + _AAAAs = QMultiMap(); + + discover(); +} + void IppDiscovery::sendQuery(quint16 qtype, QStringList addr) { qDebug() << "discovering" << qtype << addr; @@ -82,6 +93,8 @@ void IppDiscovery::sendQuery(quint16 qtype, QStringList addr) { void IppDiscovery::update() { + QStringList found; + for(QStringList::Iterator it = _ipp.begin(); it != _ipp.end(); it++) { quint16 port = _ports[*it]; @@ -94,17 +107,17 @@ void IppDiscovery::update() { QString ip = ait.value(); QString addr = ip+":"+QString::number(port)+"/"+rp; - if(!_found.contains(addr)) + if(!found.contains(addr)) { - _found.append(addr); - _found.sort(Qt::CaseInsensitive); + found.append(addr); + found.sort(Qt::CaseInsensitive); } } } } - qDebug() << _favourites << _found; - this->setStringList(_favourites+_found); + qDebug() << _favourites << found; + this->setStringList(_favourites+found); } void IppDiscovery::readPendingDatagrams() diff --git a/src/ippdiscovery.h b/src/ippdiscovery.h index 3dd71dd..ed109f1 100644 --- a/src/ippdiscovery.h +++ b/src/ippdiscovery.h @@ -12,6 +12,7 @@ public: ~IppDiscovery(); Q_PROPERTY(QStringList favourites MEMBER _favourites NOTIFY favouritesChanged) Q_INVOKABLE void discover(); + Q_INVOKABLE void reset(); signals: void favouritesChanged(); @@ -33,7 +34,6 @@ private: QMultiMap _AAAAs; QStringList _favourites; - QStringList _found; QUdpSocket* socket; }; From ba37531a849caa32ab1b0df427fd0ce93afeefd3 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Thu, 2 Jan 2020 21:58:50 +0100 Subject: [PATCH 3/4] Make update() a slot again --- src/ippdiscovery.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ippdiscovery.h b/src/ippdiscovery.h index ed109f1..d0d59e8 100644 --- a/src/ippdiscovery.h +++ b/src/ippdiscovery.h @@ -19,12 +19,12 @@ signals: public slots: void readPendingDatagrams(); + void update(); + protected: private: void sendQuery(quint16 qtype, QStringList addr); - void update(); - QStringList _ipp; QMap _rps; QMap _ports; From 51ff40b691d206a72fed3d09cb1c1b05b5f08e7b Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Thu, 2 Jan 2020 22:10:58 +0100 Subject: [PATCH 4/4] Handle unnamed printers --- qml/pages/AddPrinterDialog.qml | 11 ++++++----- qml/pages/FirstPage.qml | 4 ++-- translations/harbour-seaprint-de.ts | 12 ++++++++---- translations/harbour-seaprint-fr.ts | 12 ++++++++---- translations/harbour-seaprint-zh_CN.ts | 12 ++++++++---- translations/harbour-seaprint.ts | 12 ++++++++---- 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/qml/pages/AddPrinterDialog.qml b/qml/pages/AddPrinterDialog.qml index e3d21eb..bbc2714 100644 --- a/qml/pages/AddPrinterDialog.qml +++ b/qml/pages/AddPrinterDialog.qml @@ -7,7 +7,8 @@ Dialog { property string value property string ssid - canAccept: printer_label.text != "" + property var printerName: false + canAccept: printerName != false Column { width: parent.width @@ -43,12 +44,12 @@ Dialog { Label { id: found_label - text: printer_label.text != "" ? qsTr("Found:") : qsTr("No printer found") + text: printerName != false ? qsTr("Found:") : qsTr("No printer found") } Label { id: printer_label color: Theme.secondaryColor - text: "" + text: printerName ? printerName : "" } } IppPrinter { @@ -56,11 +57,11 @@ Dialog { url: valueField.text onAttrsChanged: { if(printer.attrs["printer-name"]) { - printer_label.text = printer.attrs["printer-name"].value + printerName = printer.attrs["printer-name"].value == "" ? qsTr("Unknown") : printer.attrs["printer-name"].value } else { - printer_label.text = "" + printerName = false } } diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 1c6b37e..d67eebb 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -32,7 +32,7 @@ Page { } onSsidChanged: { - discovery.reset() + discovery.reset(); } } @@ -87,7 +87,7 @@ Page { visible: false - property string name: printer.attrs["printer-name"] ? printer.attrs["printer-name"].value : qsTr("Unknown") + property string name: printer.attrs["printer-name"].value != "" ? printer.attrs["printer-name"].value : qsTr("Unknown") property bool canPrint: Utils.can_print(printer, selectedFile) Connections { diff --git a/translations/harbour-seaprint-de.ts b/translations/harbour-seaprint-de.ts index 9b5fbea..42ad3c1 100644 --- a/translations/harbour-seaprint-de.ts +++ b/translations/harbour-seaprint-de.ts @@ -78,6 +78,10 @@ No printer found + + Unknown + + ChoiceSetting @@ -167,10 +171,6 @@ Remove printer - - Unknown - - Removing printer @@ -179,6 +179,10 @@ About SeaPrint + + Unknown + + JobsPage diff --git a/translations/harbour-seaprint-fr.ts b/translations/harbour-seaprint-fr.ts index 1b0ae2f..8eba296 100644 --- a/translations/harbour-seaprint-fr.ts +++ b/translations/harbour-seaprint-fr.ts @@ -78,6 +78,10 @@ No printer found Aucune imprimante détectée + + Unknown + Inconnu + ChoiceSetting @@ -167,10 +171,6 @@ Remove printer Supprimer l'imprimante - - Unknown - Inconnu - Removing printer Suppression de l'imprimante @@ -179,6 +179,10 @@ About SeaPrint À propos de SeaPrint + + Unknown + Inconnu + JobsPage diff --git a/translations/harbour-seaprint-zh_CN.ts b/translations/harbour-seaprint-zh_CN.ts index 2b25981..fc113b8 100644 --- a/translations/harbour-seaprint-zh_CN.ts +++ b/translations/harbour-seaprint-zh_CN.ts @@ -78,6 +78,10 @@ No printer found 没有找到打印机 + + Unknown + + ChoiceSetting @@ -163,10 +167,6 @@ About SeaPrint - - Unknown - - View jobs @@ -179,6 +179,10 @@ Removing printer + + Unknown + + JobsPage diff --git a/translations/harbour-seaprint.ts b/translations/harbour-seaprint.ts index 9b5fbea..42ad3c1 100644 --- a/translations/harbour-seaprint.ts +++ b/translations/harbour-seaprint.ts @@ -78,6 +78,10 @@ No printer found + + Unknown + + ChoiceSetting @@ -167,10 +171,6 @@ Remove printer - - Unknown - - Removing printer @@ -179,6 +179,10 @@ About SeaPrint + + Unknown + + JobsPage