| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: qdns.h 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Definition of QDns class.
|
|---|
| 5 | **
|
|---|
| 6 | ** Created : 991122
|
|---|
| 7 | **
|
|---|
| 8 | ** Copyright (C) 1999-2000 Trolltech AS. All rights reserved.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file is part of the network module of the Qt GUI Toolkit.
|
|---|
| 11 | **
|
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 15 | **
|
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 19 | ** packaging of this file.
|
|---|
| 20 | **
|
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
|---|
| 22 | ** file in accordance with the Qt Commercial License Agreement provided
|
|---|
| 23 | ** with the Software.
|
|---|
| 24 | **
|
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 27 | **
|
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 29 | ** information about Qt Commercial License Agreements.
|
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 32 | **
|
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 34 | ** not clear to you.
|
|---|
| 35 | **
|
|---|
| 36 | **********************************************************************/
|
|---|
| 37 |
|
|---|
| 38 | #ifndef QDNS_H
|
|---|
| 39 | #define QDNS_H
|
|---|
| 40 |
|
|---|
| 41 | #ifndef QT_H
|
|---|
| 42 | #include "qobject.h"
|
|---|
| 43 | #include "qhostaddress.h"
|
|---|
| 44 | #include "qsocketnotifier.h"
|
|---|
| 45 | #include "qstringlist.h"
|
|---|
| 46 | #endif // QT_H
|
|---|
| 47 |
|
|---|
| 48 | #if !defined( QT_MODULE_NETWORK ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_NETWORK )
|
|---|
| 49 | #define QM_EXPORT_DNS
|
|---|
| 50 | #else
|
|---|
| 51 | #define QM_EXPORT_DNS Q_EXPORT
|
|---|
| 52 | #endif
|
|---|
| 53 |
|
|---|
| 54 | #ifndef QT_NO_DNS
|
|---|
| 55 |
|
|---|
| 56 | //#define Q_DNS_SYNCHRONOUS
|
|---|
| 57 |
|
|---|
| 58 | class QDnsPrivate;
|
|---|
| 59 |
|
|---|
| 60 | class QM_EXPORT_DNS QDns: public QObject {
|
|---|
| 61 | Q_OBJECT
|
|---|
| 62 | public:
|
|---|
| 63 | enum RecordType {
|
|---|
| 64 | None,
|
|---|
| 65 | A, Aaaa,
|
|---|
| 66 | Mx, Srv,
|
|---|
| 67 | Cname,
|
|---|
| 68 | Ptr,
|
|---|
| 69 | Txt
|
|---|
| 70 | };
|
|---|
| 71 |
|
|---|
| 72 | QDns();
|
|---|
| 73 | QDns( const QString & label, RecordType rr = A );
|
|---|
| 74 | QDns( const QHostAddress & address, RecordType rr = Ptr );
|
|---|
| 75 | virtual ~QDns();
|
|---|
| 76 |
|
|---|
| 77 | // to set/change the query
|
|---|
| 78 | virtual void setLabel( const QString & label );
|
|---|
| 79 | virtual void setLabel( const QHostAddress & address );
|
|---|
| 80 | QString label() const { return l; }
|
|---|
| 81 |
|
|---|
| 82 | virtual void setRecordType( RecordType rr = A );
|
|---|
| 83 | RecordType recordType() const { return t; }
|
|---|
| 84 |
|
|---|
| 85 | // whether something is happening behind the scenes
|
|---|
| 86 | bool isWorking() const;
|
|---|
| 87 |
|
|---|
| 88 | // to query for replies
|
|---|
| 89 | QValueList<QHostAddress> addresses() const;
|
|---|
| 90 |
|
|---|
| 91 | class QM_EXPORT_DNS MailServer {
|
|---|
| 92 | public:
|
|---|
| 93 | MailServer( const QString & n=QString::null, Q_UINT16 p=0 )
|
|---|
| 94 | :name(n), priority(p) {}
|
|---|
| 95 | QString name;
|
|---|
| 96 | Q_UINT16 priority;
|
|---|
| 97 | Q_DUMMY_COMPARISON_OPERATOR(MailServer)
|
|---|
| 98 | };
|
|---|
| 99 | QValueList<MailServer> mailServers() const;
|
|---|
| 100 |
|
|---|
| 101 | class QM_EXPORT_DNS Server {
|
|---|
| 102 | public:
|
|---|
| 103 | Server(const QString & n=QString::null, Q_UINT16 p=0, Q_UINT16 w=0, Q_UINT16 po=0 )
|
|---|
| 104 | : name(n), priority(p), weight(w), port(po) {}
|
|---|
| 105 | QString name;
|
|---|
| 106 | Q_UINT16 priority;
|
|---|
| 107 | Q_UINT16 weight;
|
|---|
| 108 | Q_UINT16 port;
|
|---|
| 109 | Q_DUMMY_COMPARISON_OPERATOR(Server)
|
|---|
| 110 | };
|
|---|
| 111 | QValueList<Server> servers() const;
|
|---|
| 112 |
|
|---|
| 113 | QStringList hostNames() const;
|
|---|
| 114 |
|
|---|
| 115 | QStringList texts() const;
|
|---|
| 116 |
|
|---|
| 117 | QString canonicalName() const; // ### real-world but uncommon: QStringList
|
|---|
| 118 |
|
|---|
| 119 | QStringList qualifiedNames() const { return n; }
|
|---|
| 120 |
|
|---|
| 121 | #if defined(Q_DNS_SYNCHRONOUS)
|
|---|
| 122 | protected:
|
|---|
| 123 | void connectNotify( const char *signal );
|
|---|
| 124 | #endif
|
|---|
| 125 |
|
|---|
| 126 | signals:
|
|---|
| 127 | void resultsReady();
|
|---|
| 128 |
|
|---|
| 129 | private slots:
|
|---|
| 130 | void startQuery();
|
|---|
| 131 |
|
|---|
| 132 | private:
|
|---|
| 133 | static void doResInit();
|
|---|
| 134 | void setStartQueryTimer();
|
|---|
| 135 | static QString toInAddrArpaDomain( const QHostAddress &address );
|
|---|
| 136 | #if defined(Q_DNS_SYNCHRONOUS)
|
|---|
| 137 | void doSynchronousLookup();
|
|---|
| 138 | #endif
|
|---|
| 139 |
|
|---|
| 140 | QString l;
|
|---|
| 141 | QStringList n;
|
|---|
| 142 | RecordType t;
|
|---|
| 143 | QDnsPrivate * d;
|
|---|
| 144 |
|
|---|
| 145 | friend class QDnsAnswer;
|
|---|
| 146 | friend class QDnsManager;
|
|---|
| 147 | };
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 | // QDnsSocket are sockets that are used for DNS lookup
|
|---|
| 151 |
|
|---|
| 152 | class QDnsSocket: public QObject {
|
|---|
| 153 | Q_OBJECT
|
|---|
| 154 | // note: Private not public. This class contains NO public API.
|
|---|
| 155 | protected:
|
|---|
| 156 | QDnsSocket( QObject *, const char * );
|
|---|
| 157 | virtual ~QDnsSocket();
|
|---|
| 158 |
|
|---|
| 159 | private slots:
|
|---|
| 160 | virtual void cleanCache();
|
|---|
| 161 | virtual void retransmit();
|
|---|
| 162 | virtual void answer();
|
|---|
| 163 | };
|
|---|
| 164 |
|
|---|
| 165 | #endif // QT_NO_DNS
|
|---|
| 166 |
|
|---|
| 167 | #endif // QDNS_H
|
|---|