qdnslookup_p.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. #ifndef QDNSLOOKUP_P_H
  42. #define QDNSLOOKUP_P_H
  43. //
  44. // W A R N I N G
  45. // -------------
  46. //
  47. // This file is not part of the Qt API. It exists for the convenience
  48. // of the QDnsLookup class. This header file may change from
  49. // version to version without notice, or even be removed.
  50. //
  51. // We mean it.
  52. //
  53. #include <QHostAddress>
  54. #include <QMetaType>
  55. #include <QMutex>
  56. #include <QRunnable>
  57. #include <QSharedPointer>
  58. #include <QThreadPool>
  59. #include "qdnslookup.h"
  60. QT_BEGIN_NAMESPACE
  61. //#define QDNSLOOKUP_DEBUG
  62. class QDnsLookupRunnable;
  63. class QDnsLookupReply
  64. {
  65. public:
  66. QDnsLookupReply()
  67. : error(QDnsLookup::NoError)
  68. { }
  69. QDnsLookup::Error error;
  70. QString errorString;
  71. QList<QDnsDomainNameRecord> canonicalNameRecords;
  72. QList<QDnsHostAddressRecord> hostAddressRecords;
  73. QList<QDnsMailExchangeRecord> mailExchangeRecords;
  74. QList<QDnsDomainNameRecord> nameServerRecords;
  75. QList<QDnsDomainNameRecord> pointerRecords;
  76. QList<QDnsServiceRecord> serviceRecords;
  77. QList<QDnsTextRecord> textRecords;
  78. };
  79. class QDnsLookupPrivate
  80. {
  81. public:
  82. QDnsLookupPrivate(QDnsLookup *qq)
  83. : isFinished(false)
  84. , type(QDnsLookup::A)
  85. , runnable(0)
  86. , q_ptr(qq)
  87. { }
  88. void _q_lookupFinished(const QDnsLookupReply &reply);
  89. bool isFinished;
  90. QString name;
  91. QDnsLookup::Type type;
  92. QDnsLookupReply reply;
  93. QDnsLookupRunnable *runnable;
  94. QDnsLookup *q_ptr;
  95. Q_DECLARE_PUBLIC(QDnsLookup)
  96. };
  97. class QDnsLookupRunnable : public QObject, public QRunnable
  98. {
  99. Q_OBJECT
  100. public:
  101. QDnsLookupRunnable(QDnsLookup::Type type, const QByteArray &name)
  102. : requestType(type)
  103. , requestName(name)
  104. { }
  105. void run();
  106. signals:
  107. void finished(const QDnsLookupReply &reply);
  108. private:
  109. static void query(const int requestType, const QByteArray &requestName, QDnsLookupReply *reply);
  110. QDnsLookup::Type requestType;
  111. QByteArray requestName;
  112. };
  113. class QDnsLookupThreadPool : public QThreadPool
  114. {
  115. Q_OBJECT
  116. public:
  117. QDnsLookupThreadPool();
  118. void start(QRunnable *runnable);
  119. private slots:
  120. void _q_applicationDestroyed();
  121. private:
  122. QMutex signalsMutex;
  123. bool signalsConnected;
  124. };
  125. class QDnsRecordPrivate : public QSharedData
  126. {
  127. public:
  128. QDnsRecordPrivate()
  129. : timeToLive(0)
  130. { }
  131. QString name;
  132. quint32 timeToLive;
  133. };
  134. class QDnsDomainNameRecordPrivate : public QDnsRecordPrivate
  135. {
  136. public:
  137. QDnsDomainNameRecordPrivate()
  138. { }
  139. QString value;
  140. };
  141. class QDnsHostAddressRecordPrivate : public QDnsRecordPrivate
  142. {
  143. public:
  144. QDnsHostAddressRecordPrivate()
  145. { }
  146. QHostAddress value;
  147. };
  148. class QDnsMailExchangeRecordPrivate : public QDnsRecordPrivate
  149. {
  150. public:
  151. QDnsMailExchangeRecordPrivate()
  152. : preference(0)
  153. { }
  154. QString exchange;
  155. quint16 preference;
  156. };
  157. class QDnsServiceRecordPrivate : public QDnsRecordPrivate
  158. {
  159. public:
  160. QDnsServiceRecordPrivate()
  161. : port(0),
  162. priority(0),
  163. weight(0)
  164. { }
  165. QString target;
  166. quint16 port;
  167. quint16 priority;
  168. quint16 weight;
  169. };
  170. class QDnsTextRecordPrivate : public QDnsRecordPrivate
  171. {
  172. public:
  173. QDnsTextRecordPrivate()
  174. { }
  175. QList<QByteArray> values;
  176. };
  177. QT_END_NAMESPACE
  178. Q_DECLARE_METATYPE(QDnsLookupReply)
  179. #endif // QDNSLOOKUP_P_H