KVIrc  4.9.2
DeveloperAPIs
KviDnsResolver.h
Go to the documentation of this file.
1 #ifndef _KVI_DNS_H_
2 #define _KVI_DNS_H_
3 
4 //=============================================================================
5 //
6 // File : KviDnsResolver.h
7 // Creation date : Sat Jul 21 2000 13:59:11 by Szymon Stefanek
8 //
9 // This file is part of the KVIrc IRC client distribution
10 // Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net)
11 //
12 // This program is FREE software. You can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the HOPE that it will be USEFUL,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 // See the GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program. If not, write to the Free Software Foundation,
24 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 //
26 //=============================================================================
27 
28 #include "kvi_settings.h"
29 #include "KviHeapObject.h"
30 #include "KviQString.h"
31 #include "KviError.h"
32 #include "KviPointerList.h"
33 
35 
37 {
38  friend class KviDnsResolver;
39  friend class KviDnsResolverThread;
40 
41 protected:
43 
44 public:
46 
47 protected:
51  QString m_szQuery;
52 
53 public:
55  {
56  return m_eError;
57  }
58 
59  // never store nor delete these pointers!
60  // (these are NEVER 0)
62  {
63  return m_pHostnameList;
64  }
65 
67  {
68  return m_pIpAddressList;
69  }
70 
71  const QString & query()
72  {
73  return m_szQuery;
74  }
75 
76 protected:
77  void setError(KviError::Code eError)
78  {
79  m_eError = eError;
80  }
81 
82  void setQuery(const QString & szQuery)
83  {
84  m_szQuery = szQuery;
85  }
86 
87  void appendHostname(const QString & szHost);
88  void appendAddress(const QString & szAddr);
89 };
90 
91 #include <QObject>
92 
93 class KVILIB_API KviDnsResolver : public QObject, public KviHeapObject
94 {
95  Q_OBJECT
96  Q_PROPERTY(bool blockingDelete READ isRunning)
97 public:
99  virtual ~KviDnsResolver();
100 
101 public:
103  {
106  Any
107  };
108  enum State
109  {
114  };
115 
116 protected:
117  void * m_pAuxData;
121 
122 public:
124  //
125  // Public interface
126  //
127 
128  // Lookup start
129  bool lookup(const QString & szQuery, QueryType type);
130 
131  // Current object state
132  State state() { return m_state; };
133 
134  // Results (return always non null-data..but valid results only if state() == Success or Failure)
135  KviError::Code error();
136  QString errorString();
137  const QString & firstHostname();
138  const QString & hostName()
139  {
140  return firstHostname();
141  }
142  const QString & firstIpAddress();
143  int hostnameCount();
144  int ipAddressCount();
145  KviPointerList<QString> * hostnameList();
146  KviPointerList<QString> * ipAddressList();
147  const QString & query();
148  bool isRunning() const;
149 
150  // Auxiliary data store
151  void setAuxData(void * pAuxData) { m_pAuxData = pAuxData; };
152  void * releaseAuxData()
153  {
154  void * pData = m_pAuxData;
155  m_pAuxData = 0;
156  return pData;
157  };
158 
159 protected:
160  virtual bool event(QEvent * e);
161 
162 private:
163  KviDnsResolverResult * result();
164 signals:
165  void lookupDone(KviDnsResolver *);
166 };
167 
169 // INTERNAL CLASSES
170 //
171 
172 #include <QThread>
173 #include <QEvent>
174 
175 #include "kvi_debug.h"
176 
177 class KviDnsResolverThreadEvent : public QEvent
178 {
179 private:
181 
182 public:
184  : QEvent(QEvent::User), m_pResult(pResult)
185  {
186  KVI_ASSERT(pResult);
187  }
188 
190  {
191  if(m_pResult)
192  delete m_pResult;
193  }
194 
195 public:
197  {
198  KviDnsResolverResult * pResult = m_pResult;
199  m_pResult = NULL;
200  return pResult;
201  }
202 };
203 
204 class KviDnsResolverThread : public QThread
205 {
206  friend class KviDnsResolver;
207 
208 protected:
210  virtual ~KviDnsResolverThread();
211 
212 protected:
213  QString m_szQuery;
216 
217 public:
218  void setQuery(const QString & szQuery, KviDnsResolver::QueryType type)
219  {
220  m_szQuery = szQuery;
221  m_queryType = type;
222  };
223 
224 protected:
225  virtual void run();
228 };
229 
230 #endif //_KVI_DNS_H_
Definition: KviDnsResolver.h:110
Definition: KviDnsResolver.h:177
KviDnsResolverResult * releaseResult()
Definition: KviDnsResolver.h:196
Definition: KviDnsResolver.h:36
Definition: KviHeapObject.h:124
This file contains the definition of the debug macros;.
KviError::Code error()
Definition: KviDnsResolver.cpp:424
char * NULL
Definition: KviIrcNumericCodes.h:391
const QString & query()
Definition: KviDnsResolver.h:71
KviPointerList< QString > * m_pIpAddressList
Definition: KviDnsResolver.h:50
State state()
Definition: KviDnsResolver.h:132
Definition: KviDnsResolver.h:104
void * m_pAuxData
Definition: KviDnsResolver.h:117
QString m_szQuery
Definition: KviDnsResolver.h:51
KviError::Code error()
Definition: KviDnsResolver.h:54
KviPointerList< QString > * hostnameList()
Definition: KviDnsResolver.h:61
KviDnsResolver * m_pParentDns
Definition: KviDnsResolver.h:215
KviDnsResolverThread * m_pSlaveThread
Definition: KviDnsResolver.h:118
void setAuxData(void *pAuxData)
Definition: KviDnsResolver.h:151
QString type()
Definition: KviRuntimeInfo.cpp:646
#define e
Definition: detector.cpp:69
virtual void run()
Definition: KviDnsResolver.cpp:158
Definition: KviDnsResolver.h:204
KviPointerList< QString > * m_pHostnameList
Definition: KviDnsResolver.h:49
void setQuery(const QString &szQuery)
Definition: KviDnsResolver.h:82
KviDnsResolverResult * m_pResult
Definition: KviDnsResolver.h:180
QString szHost
Definition: libkvisetup.cpp:45
KviDnsResolverResult * m_pDnsResult
Definition: KviDnsResolver.h:119
void setError(KviError::Code eError)
Definition: KviDnsResolver.h:77
Code
Contains all error codes.
Definition: KviError.h:47
void * releaseAuxData()
Definition: KviDnsResolver.h:152
KviDnsResolverThreadEvent(KviDnsResolverResult *pResult)
Definition: KviDnsResolver.h:183
void setQuery(const QString &szQuery, KviDnsResolver::QueryType type)
Definition: KviDnsResolver.h:218
Definition: KviDnsResolver.h:112
KviDnsResolver::QueryType m_queryType
Definition: KviDnsResolver.h:214
virtual ~KviDnsResolverThread()
The KviDnsResolver class.
Definition: KviDnsResolver.h:93
#define KVI_ASSERT(__condition__)
GNUC
Definition: kvi_debug.h:138
State m_state
Definition: KviDnsResolver.h:120
QString m_szQuery
Definition: KviDnsResolver.h:213
C++ Template based double linked pointer list class.
void postDnsError(KviDnsResolverResult *pDns, KviError::Code error)
Definition: KviDnsResolver.cpp:150
Definition: KviDnsResolver.h:105
Heap Object.
Error List.
QueryType
Definition: KviDnsResolver.h:102
KviPointerList< QString > * ipAddressList()
Definition: KviDnsResolver.h:66
KviError::Code translateDnsError(int iErr)
Definition: KviDnsResolver.cpp:93
virtual ~KviDnsResolverThreadEvent()
Definition: KviDnsResolver.h:189
KviError::Code m_eError
Definition: KviDnsResolver.h:48
KviDnsResolverThread(KviDnsResolver *pDns)
Definition: KviDnsResolver.cpp:84
const QString & hostName()
Definition: KviDnsResolver.h:138
Definition: KviDnsResolver.h:111
This file contains compile time settings.
#define KVILIB_API
Definition: kvi_settings.h:125
Helper functions for the QString class.
const QString & firstIpAddress()
State
Definition: KviDnsResolver.h:108
Definition: KviError.h:49