qdnslookup_symbian.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Jeremy Lainé <jeremy.laine@m4x.org>
  4. ** Contact: http://www.qt-project.org/
  5. **
  6. ** This file is part of the QtNetwork module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** GNU Lesser General Public License Usage
  10. ** This file may be used under the terms of the GNU Lesser General Public
  11. ** License version 2.1 as published by the Free Software Foundation and
  12. ** appearing in the file LICENSE.LGPL included in the packaging of this
  13. ** file. Please review the following information to ensure the GNU Lesser
  14. ** General Public License version 2.1 requirements will be met:
  15. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  16. **
  17. ** In addition, as a special exception, Nokia gives you certain additional
  18. ** rights. These rights are described in the Nokia Qt LGPL Exception
  19. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  20. **
  21. ** GNU General Public License Usage
  22. ** Alternatively, this file may be used under the terms of the GNU General
  23. ** Public License version 3.0 as published by the Free Software Foundation
  24. ** and appearing in the file LICENSE.GPL included in the packaging of this
  25. ** file. Please review the following information to ensure the GNU General
  26. ** Public License version 3.0 requirements will be met:
  27. ** http://www.gnu.org/copyleft/gpl.html.
  28. **
  29. ** Other Usage
  30. ** Alternatively, this file may be used in accordance with the terms and
  31. ** conditions contained in a signed written agreement between you and Nokia.
  32. **
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #include "qdnslookup_p.h"
  42. #include <QUrl>
  43. #include <QMutex>
  44. #include <QLibrary>
  45. #include <dns_qry.h>
  46. QT_BEGIN_NAMESPACE
  47. void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, QDnsLookupReply *reply)
  48. {
  49. RHostResolver dnsResolver;
  50. RSocketServ dnsSocket;
  51. // Initialise resolver.
  52. TInt err = dnsSocket.Connect();
  53. err = dnsResolver.Open(dnsSocket, KAfInet, KProtocolInetUdp);
  54. if (err != KErrNone) {
  55. reply->error = QDnsLookup::ResolverError;
  56. reply->errorString = QLatin1String("RHostResolver::Open failed");
  57. return;
  58. }
  59. // Perform DNS query.
  60. TDnsQueryBuf dnsQuery;
  61. TDnsRespSRVBuf dnsResponse;
  62. dnsQuery().SetClass(KDnsRRClassIN);
  63. TPtrC8 queryPtr(reinterpret_cast<const TUint8*>(requestName.constData()), requestName.size());
  64. dnsQuery().SetData(queryPtr);
  65. dnsQuery().SetType(requestType);
  66. err = dnsResolver.Query(dnsQuery, dnsResponse);
  67. if (err != KErrNone) {
  68. reply->error = QDnsLookup::NotFoundError;
  69. reply->errorString = QLatin1String("RHostResolver::Query failed");
  70. return;
  71. }
  72. // Extract results.
  73. while (err == KErrNone) {
  74. const QByteArray aceName((const char*)dnsResponse().Target().Ptr(),
  75. dnsResponse().Target().Length());
  76. QDnsServiceRecord record;
  77. record.d->name = QUrl::fromAce(requestName);
  78. record.d->target = QUrl::fromAce(aceName);
  79. record.d->port = dnsResponse().Port();
  80. record.d->priority = dnsResponse().Priority();
  81. record.d->timeToLive = dnsResponse().RRTtl();
  82. record.d->weight = dnsResponse().Weight();
  83. reply->serviceRecords.append(record);
  84. err = dnsResolver.QueryGetNext(dnsResponse);
  85. }
  86. }
  87. QT_END_NAMESPACE