diff options
author | Aaron Tunney <aaron.tunney@accenture.com> | 2010-12-09 18:03:58 (GMT) |
---|---|---|
committer | Aaron Tunney <aaron.tunney@accenture.com> | 2010-12-09 18:08:39 (GMT) |
commit | 9a565b61fc8fdb7dd786072a78e6ae903b59ded2 (patch) | |
tree | 45bde59e787c091d8edb9d136b51d139d3b09c69 /src/network/kernel/qhostinfo_symbian.cpp | |
parent | 931b3189d727f25f97c84f33c1d5fddaf0538777 (diff) | |
download | Qt-9a565b61fc8fdb7dd786072a78e6ae903b59ded2.zip Qt-9a565b61fc8fdb7dd786072a78e6ae903b59ded2.tar.gz Qt-9a565b61fc8fdb7dd786072a78e6ae903b59ded2.tar.bz2 |
QHostInfo: Symbian implementation for fromName()
Reviewed-By: Markus Goetz
Diffstat (limited to 'src/network/kernel/qhostinfo_symbian.cpp')
-rw-r--r-- | src/network/kernel/qhostinfo_symbian.cpp | 106 |
1 files changed, 91 insertions, 15 deletions
diff --git a/src/network/kernel/qhostinfo_symbian.cpp b/src/network/kernel/qhostinfo_symbian.cpp index e70f2ce..fbd7fe9 100644 --- a/src/network/kernel/qhostinfo_symbian.cpp +++ b/src/network/kernel/qhostinfo_symbian.cpp @@ -40,19 +40,44 @@ ****************************************************************************/ //#define QHOSTINFO_DEBUG + +// Symbian Headers +#include <es_sock.h> +#include <in_sock.h> + +// Qt Headers #include <QByteArray> #include <QUrl> +#include <QList> #include "qplatformdefs.h" #include "qhostinfo_p.h" +#include <private/qcore_symbian_p.h> QT_BEGIN_NAMESPACE + QHostInfo QHostInfoAgent::fromName(const QString &hostName) { QHostInfo results; + // Connect to ESOCK + RSocketServ socketServ(qt_symbianGetSocketServer()); + RHostResolver hostResolver; + + // Will return both IPv4 and IPv6 + // TODO: Pass RHostResolver.Open() the global RConnection + int err = hostResolver.Open(socketServ, KAfInet, KProtocolInetUdp); + if (err) { + results.setError(QHostInfo::UnknownError); + results.setErrorString(tr("Symbian error code: %1").arg(err)); + + return results; + } + + TNameEntry nameResult; + #if defined(QHOSTINFO_DEBUG) qDebug("QHostInfoAgent::fromName(%s) looking up...", hostName.toLatin1().constData()); @@ -61,8 +86,26 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) QHostAddress address; if (address.setAddress(hostName)) { // Reverse lookup - // TODO - results.setHostName("assume.it.works"); + + TInetAddr IpAdd; + IpAdd.Input(qt_QString2TPtrC(hostName)); + + // Synchronous request. nameResult returns Host Name. + hostResolver.GetByAddress(IpAdd, nameResult); + if (err) { + // TODO - Could there be other errors? Symbian docs don't say. + if (err = KErrNotFound) { + results.setError(QHostInfo::HostNotFound); + results.setErrorString(tr("Host not found")); + } else { + results.setError(QHostInfo::UnknownError); + results.setErrorString(tr("Symbian error code: %1").arg(err)); + } + + return results; + } + + results.setHostName(qt_TDesC2QString(nameResult().iName)); results.setAddresses(QList<QHostAddress>() << address); return results; } @@ -78,32 +121,65 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) return results; } - // Call getaddrinfo, and place all IPv4 addresses at the start and + + // Call RHostResolver::GetByAddress, and place all IPv4 addresses at the start and // the IPv6 addresses at the end of the address list in results. - /* - results.setError(QHostInfo::HostNotFound); - results.setErrorString(tr("Host not found")); - } else { - results.setError(QHostInfo::UnknownError); - results.setErrorString(QString::fromLocal8Bit(gai_strerror(result))); + + // Synchronous request. + err = hostResolver.GetByName(qt_QString2TPtrC(aceHostname), nameResult); + if (err) { + // TODO - Could there be other errors? Symbian docs don't say. + if (err = KErrNotFound) { + results.setError(QHostInfo::HostNotFound); + results.setErrorString(tr("Host not found")); + } else { + results.setError(QHostInfo::UnknownError); + results.setErrorString(tr("Symbian error code: %1").arg(err)); + } + + return results; } - */ - //TODO: HACK to return qt-test-server's ip - QList<QHostAddress> addresses; - addresses.append(QHostAddress("192.168.1.8")); - results.setHostName(hostName); - results.setAddresses(addresses); + QList<QHostAddress> hostAddresses; + + TInetAddr hostAdd = nameResult().iAddr; + TBuf<16> ipAddr; + // Fill ipAddr with the IP address from hostAdd + hostAdd.Output(ipAddr); + if (ipAddr.Length() > 0) + hostAddresses.append(QHostAddress(qt_TDesC2QString(ipAddr))); + + // Check if there's more than one IP address linkd to this name + while (hostResolver.Next(nameResult) == KErrNone) { + hostAdd = nameResult().iAddr; + hostAdd.Output(ipAddr); + + if (ipAddr.Length() > 0) { + if (nameResult().iAddr.Family() == KAfInet) { + // IPv4 - prepend + hostAddresses.prepend(QHostAddress(qt_TDesC2QString(ipAddr))); + } else { + // IPv6 - append + hostAddresses.append(QHostAddress(qt_TDesC2QString(ipAddr))); + } + } + } + + hostResolver.Close(); + + results.setAddresses(hostAddresses); return results; } QString QHostInfo::localHostName() { + // TODO - fill with code. return QString(); } QString QHostInfo::localDomainName() { + // TODO - fill with code. return QString(); } |