summaryrefslogtreecommitdiffstats
path: root/src/network/kernel
diff options
context:
space:
mode:
authorJason Barron <jbarron@trolltech.com>2009-08-20 14:58:58 (GMT)
committerJason Barron <jbarron@trolltech.com>2009-08-20 14:58:58 (GMT)
commit851a858fcd28c35dff2ffbeffdb40f7ee69f45b4 (patch)
treef76f604982f127af7ef66d904038cdfa705ff3af /src/network/kernel
parentefea248b4b725ca429793874eb168ad4b43c7994 (diff)
parentc0b24b7ce12387aff6e74b05b4060c61a58d87e0 (diff)
downloadQt-851a858fcd28c35dff2ffbeffdb40f7ee69f45b4.zip
Qt-851a858fcd28c35dff2ffbeffdb40f7ee69f45b4.tar.gz
Qt-851a858fcd28c35dff2ffbeffdb40f7ee69f45b4.tar.bz2
Merge commit 'qt/master'
Conflicts: examples/painting/svgviewer/files/bubbles.svg src/corelib/kernel/qobject.cpp src/network/kernel/qhostinfo.cpp tests/auto/qhostinfo/tst_qhostinfo.cpp
Diffstat (limited to 'src/network/kernel')
-rw-r--r--src/network/kernel/qhostinfo.cpp15
-rw-r--r--src/network/kernel/qhostinfo_unix.cpp23
-rw-r--r--src/network/kernel/qhostinfo_win.cpp22
3 files changed, 41 insertions, 19 deletions
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp
index c8def4a..44e6b3a 100644
--- a/src/network/kernel/qhostinfo.cpp
+++ b/src/network/kernel/qhostinfo.cpp
@@ -163,16 +163,13 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver,
QWindowsSockInit bust; // makes sure WSAStartup was callled
#endif
- // Support for IDNA
- QString lookup = QString::fromLatin1(QUrl::toAce(name));
-
QScopedPointer<QHostInfoResult> result(new QHostInfoResult);
result.data()->autoDelete = false;
QObject::connect(result.data(), SIGNAL(resultsReady(QHostInfo)),
receiver, member);
int id = result.data()->lookupId = theIdCounter.fetchAndAddRelaxed(1);
- if (lookup.isEmpty()) {
+ if (name.isEmpty()) {
QHostInfo info(id);
info.setError(QHostInfo::HostNotFound);
info.setErrorString(QObject::tr("No host name given"));
@@ -183,7 +180,7 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver,
}
QHostInfoAgent *agent = theAgent();
- agent->addHostName(lookup, result.take());
+ agent->addHostName(name, result.take());
#if !defined QT_NO_THREAD
if (!agent->isRunning())
@@ -227,13 +224,7 @@ QHostInfo QHostInfo::fromName(const QString &name)
qDebug("QHostInfo::fromName(\"%s\")",name.toLatin1().constData());
#endif
- if (!name.isEmpty())
- return QHostInfoAgent::fromName(QLatin1String(QUrl::toAce(name)));
-
- QHostInfo retval;
- retval.d->err = HostNotFound;
- retval.d->errorStr = QObject::tr("No host name given");
- return retval;
+ return QHostInfoAgent::fromName(name);
}
/*!
diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp
index 39ea72c..2f96f1b 100644
--- a/src/network/kernel/qhostinfo_unix.cpp
+++ b/src/network/kernel/qhostinfo_unix.cpp
@@ -122,7 +122,6 @@ static void resolveLibrary()
QHostInfo QHostInfoAgent::fromName(const QString &hostName)
{
QHostInfo results;
- results.setHostName(hostName);
#if defined(QHOSTINFO_DEBUG)
qDebug("QHostInfoAgent::fromName(%s) looking up...",
@@ -192,6 +191,22 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
#endif
}
+ // IDN support
+ QByteArray aceHostname;
+ if (results.hostName().isEmpty()) {
+ // it's a hostname resolution
+ aceHostname = QUrl::toAce(hostName);
+ results.setHostName(hostName);
+ if (aceHostname.isEmpty()) {
+ results.setError(QHostInfo::HostNotFound);
+ results.setErrorString(hostName.isEmpty() ? QObject::tr("No host name given") : QObject::tr("Invalid hostname"));
+ return results;
+ }
+ } else {
+ // it's an IP reverse resolution
+ aceHostname = results.hostName().toLatin1();
+ }
+
#if !defined (QT_NO_GETADDRINFO)
// Call getaddrinfo, and place all IPv4 addresses at the start and
// the IPv6 addresses at the end of the address list in results.
@@ -203,12 +218,12 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
hints.ai_flags = Q_ADDRCONFIG;
#endif
- int result = getaddrinfo(hostName.toLatin1().constData(), 0, &hints, &res);
+ int result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
# ifdef Q_ADDRCONFIG
if (result == EAI_BADFLAGS) {
// if the lookup failed with AI_ADDRCONFIG set, try again without it
hints.ai_flags = 0;
- result = getaddrinfo(hostName.toLatin1().constData(), 0, &hints, &res);
+ result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
}
# endif
@@ -262,7 +277,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
// use one QHostInfoAgent, but if more agents are introduced, locking
// must be provided.
QMutexLocker locker(::getHostByNameMutex());
- hostent *result = gethostbyname(hostName.toLatin1().constData());
+ hostent *result = gethostbyname(aceHostname.constData());
if (result) {
if (result->h_addrtype == AF_INET) {
QList<QHostAddress> addresses;
diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp
index 93dc720..c5dc2d2 100644
--- a/src/network/kernel/qhostinfo_win.cpp
+++ b/src/network/kernel/qhostinfo_win.cpp
@@ -52,6 +52,7 @@
#include <qlibrary.h>
#include <qtimer.h>
#include <qmutex.h>
+#include <qurl.h>
#include <private/qmutexpool_p.h>
QT_BEGIN_NAMESPACE
@@ -129,7 +130,6 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
}
QHostInfo results;
- results.setHostName(hostName);
#if defined(QHOSTINFO_DEBUG)
qDebug("QHostInfoAgent::fromName(%p): looking up \"%s\" (IPv6 support is %s)",
@@ -178,12 +178,28 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
}
}
+ // IDN support
+ QByteArray aceHostname;
+ if (results.hostName().isEmpty()) {
+ // it's a hostname resolution
+ aceHostname = QUrl::toAce(hostName);
+ results.setHostName(hostName);
+ if (aceHostname.isEmpty()) {
+ results.setError(QHostInfo::HostNotFound);
+ results.setErrorString(hostName.isEmpty() ? QObject::tr("No host name given") : QObject::tr("Invalid hostname"));
+ return results;
+ }
+ } else {
+ // it's an IP reverse resolution
+ aceHostname = results.hostName().toLatin1();
+ }
+
if (local_getaddrinfo && local_freeaddrinfo) {
// Call getaddrinfo, and place all IPv4 addresses at the start
// and the IPv6 addresses at the end of the address list in
// results.
qt_addrinfo *res;
- int err = local_getaddrinfo(hostName.toLatin1().constData(), 0, 0, &res);
+ int err = local_getaddrinfo(aceHostname.constData(), 0, 0, &res);
if (err == 0) {
QList<QHostAddress> addresses;
for (qt_addrinfo *p = res; p != 0; p = p->ai_next) {
@@ -218,7 +234,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
}
} else {
// Fall back to gethostbyname, which only supports IPv4.
- hostent *ent = gethostbyname(hostName.toLatin1().constData());
+ hostent *ent = gethostbyname(aceHostname.constData());
if (ent) {
char **p;
QList<QHostAddress> addresses;