qdnslookup.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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_H
  42. #define QDNSLOOKUP_H
  43. #include <QList>
  44. #include <QObject>
  45. #include <QSharedData>
  46. #include <QSharedPointer>
  47. #include <QString>
  48. #include "QXmppGlobal.h"
  49. QT_BEGIN_HEADER
  50. QT_BEGIN_NAMESPACE
  51. QT_MODULE(Network)
  52. class QHostAddress;
  53. class QDnsLookupPrivate;
  54. class QDnsDomainNameRecordPrivate;
  55. class QDnsHostAddressRecordPrivate;
  56. class QDnsMailExchangeRecordPrivate;
  57. class QDnsServiceRecordPrivate;
  58. class QDnsTextRecordPrivate;
  59. class QXMPP_EXPORT QDnsDomainNameRecord
  60. {
  61. public:
  62. QDnsDomainNameRecord();
  63. QDnsDomainNameRecord(const QDnsDomainNameRecord &other);
  64. ~QDnsDomainNameRecord();
  65. QString name() const;
  66. quint32 timeToLive() const;
  67. QString value() const;
  68. QDnsDomainNameRecord &operator=(const QDnsDomainNameRecord &other);
  69. private:
  70. QSharedDataPointer<QDnsDomainNameRecordPrivate> d;
  71. friend class QDnsLookupRunnable;
  72. };
  73. class QXMPP_EXPORT QDnsHostAddressRecord
  74. {
  75. public:
  76. QDnsHostAddressRecord();
  77. QDnsHostAddressRecord(const QDnsHostAddressRecord &other);
  78. ~QDnsHostAddressRecord();
  79. QString name() const;
  80. quint32 timeToLive() const;
  81. QHostAddress value() const;
  82. QDnsHostAddressRecord &operator=(const QDnsHostAddressRecord &other);
  83. private:
  84. QSharedDataPointer<QDnsHostAddressRecordPrivate> d;
  85. friend class QDnsLookupRunnable;
  86. };
  87. class QXMPP_EXPORT QDnsMailExchangeRecord
  88. {
  89. public:
  90. QDnsMailExchangeRecord();
  91. QDnsMailExchangeRecord(const QDnsMailExchangeRecord &other);
  92. ~QDnsMailExchangeRecord();
  93. QString exchange() const;
  94. QString name() const;
  95. quint16 preference() const;
  96. quint32 timeToLive() const;
  97. QDnsMailExchangeRecord &operator=(const QDnsMailExchangeRecord &other);
  98. private:
  99. QSharedDataPointer<QDnsMailExchangeRecordPrivate> d;
  100. friend class QDnsLookupRunnable;
  101. };
  102. class QXMPP_EXPORT QDnsServiceRecord
  103. {
  104. public:
  105. QDnsServiceRecord();
  106. QDnsServiceRecord(const QDnsServiceRecord &other);
  107. ~QDnsServiceRecord();
  108. QString name() const;
  109. quint16 port() const;
  110. quint16 priority() const;
  111. QString target() const;
  112. quint32 timeToLive() const;
  113. quint16 weight() const;
  114. QDnsServiceRecord &operator=(const QDnsServiceRecord &other);
  115. private:
  116. QSharedDataPointer<QDnsServiceRecordPrivate> d;
  117. friend class QDnsLookupRunnable;
  118. };
  119. class QXMPP_EXPORT QDnsTextRecord
  120. {
  121. public:
  122. QDnsTextRecord();
  123. QDnsTextRecord(const QDnsTextRecord &other);
  124. ~QDnsTextRecord();
  125. QString name() const;
  126. quint32 timeToLive() const;
  127. QList<QByteArray> values() const;
  128. QDnsTextRecord &operator=(const QDnsTextRecord &other);
  129. private:
  130. QSharedDataPointer<QDnsTextRecordPrivate> d;
  131. friend class QDnsLookupRunnable;
  132. };
  133. class QXMPP_EXPORT QDnsLookup : public QObject
  134. {
  135. Q_OBJECT
  136. Q_ENUMS(Error Type)
  137. Q_PROPERTY(Error error READ error NOTIFY finished)
  138. Q_PROPERTY(QString errorString READ errorString NOTIFY finished)
  139. Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
  140. Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged)
  141. public:
  142. enum Error
  143. {
  144. NoError = 0,
  145. ResolverError,
  146. OperationCancelledError,
  147. InvalidRequestError,
  148. InvalidReplyError,
  149. ServerFailureError,
  150. ServerRefusedError,
  151. NotFoundError
  152. };
  153. enum Type
  154. {
  155. A = 1,
  156. AAAA = 28,
  157. ANY = 255,
  158. CNAME = 5,
  159. MX = 15,
  160. NS = 2,
  161. PTR = 12,
  162. SRV = 33,
  163. TXT = 16
  164. };
  165. QDnsLookup(QObject *parent = 0);
  166. QDnsLookup(Type type, const QString &name, QObject *parent = 0);
  167. ~QDnsLookup();
  168. Error error() const;
  169. QString errorString() const;
  170. bool isFinished() const;
  171. QString name() const;
  172. void setName(const QString &name);
  173. Type type() const;
  174. void setType(QDnsLookup::Type);
  175. QList<QDnsDomainNameRecord> canonicalNameRecords() const;
  176. QList<QDnsHostAddressRecord> hostAddressRecords() const;
  177. QList<QDnsMailExchangeRecord> mailExchangeRecords() const;
  178. QList<QDnsDomainNameRecord> nameServerRecords() const;
  179. QList<QDnsDomainNameRecord> pointerRecords() const;
  180. QList<QDnsServiceRecord> serviceRecords() const;
  181. QList<QDnsTextRecord> textRecords() const;
  182. public Q_SLOTS:
  183. void abort();
  184. void lookup();
  185. Q_SIGNALS:
  186. void finished();
  187. void nameChanged(const QString &name);
  188. void typeChanged(Type type);
  189. private:
  190. QDnsLookupPrivate *d_ptr;
  191. Q_DECLARE_PRIVATE(QDnsLookup)
  192. Q_PRIVATE_SLOT(d_func(), void _q_lookupFinished(const QDnsLookupReply &reply))
  193. };
  194. QT_END_NAMESPACE
  195. QT_END_HEADER
  196. #include "qdnslookup_p.h"
  197. #endif // QDNSLOOKUP_H