forked from hexagon-geo-surv/qtbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QDnsLookup: add a number of functions to simply setting error conditions
This also updates a few messages and transfers the translation context from QDnsLookupRunnable to QDnsLookup. Change-Id: I3e3bfef633af4130a03afffd175e86715e4a25e3 Reviewed-by: Mårten Nordheim <[email protected]>
- Loading branch information
1 parent
c5c7712
commit 029e0bf
Showing
4 changed files
with
118 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// Copyright (C) 2012 Jeremy Lainé <[email protected]> | ||
// Copyright (C) 2023 Intel Corporation. | ||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | ||
|
||
#ifndef QDNSLOOKUP_P_H | ||
|
@@ -39,11 +40,7 @@ class QDnsLookupRunnable; | |
class QDnsLookupReply | ||
{ | ||
public: | ||
QDnsLookupReply() | ||
: error(QDnsLookup::NoError) | ||
{ } | ||
|
||
QDnsLookup::Error error; | ||
QDnsLookup::Error error = QDnsLookup::NoError; | ||
QString errorString; | ||
|
||
QList<QDnsDomainNameRecord> canonicalNameRecords; | ||
|
@@ -53,6 +50,70 @@ class QDnsLookupReply | |
QList<QDnsDomainNameRecord> pointerRecords; | ||
QList<QDnsServiceRecord> serviceRecords; | ||
QList<QDnsTextRecord> textRecords; | ||
|
||
// helper methods | ||
void setError(QDnsLookup::Error err, QString &&msg) | ||
{ | ||
error = err; | ||
errorString = std::move(msg); | ||
} | ||
|
||
void makeResolverSystemError(int code = -1) | ||
{ | ||
Q_ASSERT(allAreEmpty()); | ||
setError(QDnsLookup::ResolverError, qt_error_string(code)); | ||
} | ||
|
||
void makeDnsRcodeError(quint8 rcode) | ||
{ | ||
Q_ASSERT(allAreEmpty()); | ||
switch (rcode) { | ||
case 1: // FORMERR | ||
error = QDnsLookup::InvalidRequestError; | ||
errorString = QDnsLookup::tr("Server could not process query"); | ||
return; | ||
case 2: // SERVFAIL | ||
case 4: // NOTIMP | ||
error = QDnsLookup::ServerFailureError; | ||
errorString = QDnsLookup::tr("Server failure"); | ||
return; | ||
case 3: // NXDOMAIN | ||
error = QDnsLookup::NotFoundError; | ||
errorString = QDnsLookup::tr("Non existent domain"); | ||
return; | ||
case 5: // REFUSED | ||
error = QDnsLookup::ServerRefusedError; | ||
errorString = QDnsLookup::tr("Server refused to answer"); | ||
return; | ||
default: | ||
error = QDnsLookup::InvalidReplyError; | ||
errorString = QDnsLookup::tr("Invalid reply received (rcode %1)") | ||
.arg(rcode); | ||
return; | ||
} | ||
} | ||
|
||
void makeInvalidReplyError(QString &&msg = QString()) | ||
{ | ||
if (msg.isEmpty()) | ||
msg = QDnsLookup::tr("Invalid reply received"); | ||
else | ||
msg = QDnsLookup::tr("Invalid reply received (%1)").arg(std::move(msg)); | ||
*this = QDnsLookupReply(); // empty our lists | ||
setError(QDnsLookup::InvalidReplyError, std::move(msg)); | ||
} | ||
|
||
private: | ||
bool allAreEmpty() const | ||
{ | ||
return canonicalNameRecords.isEmpty() | ||
&& hostAddressRecords.isEmpty() | ||
&& mailExchangeRecords.isEmpty() | ||
&& nameServerRecords.isEmpty() | ||
&& pointerRecords.isEmpty() | ||
&& serviceRecords.isEmpty() | ||
&& textRecords.isEmpty(); | ||
} | ||
}; | ||
|
||
class QDnsLookupPrivate : public QObjectPrivate | ||
|
@@ -63,10 +124,8 @@ class QDnsLookupPrivate : public QObjectPrivate | |
, type(QDnsLookup::A) | ||
, runnable(nullptr) | ||
{ } | ||
|
||
void _q_lookupFinished(const QDnsLookupReply &reply); | ||
|
||
static const char *msgNoIpV6NameServerAdresses; | ||
|
||
bool isFinished; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.