28 #include <sys/types.h>
29 #include <sys/socket.h>
36 #include <tqapplication.h>
39 #include "kreverseresolver.h"
40 #include "kresolver_p.h"
41 #include "kresolverworkerbase.h"
42 #include "tdesocketaddress.h"
44 #ifndef HAVE_GETNAMEINFO
51 using namespace KNetwork::Internal;
55 class ReverseThread:
public KResolverWorkerBase
59 : m_addr(addr), m_flags(flags), m_parent(0L)
62 virtual ~ReverseThread()
65 virtual bool preprocess()
68 virtual bool postprocess();
81 class KReverseResolverEvent:
public TQEvent
84 static const int myType = TQEvent::User + 63;
89 KReverseResolverEvent(
const TQString& _node,
const TQString& _service,
91 : TQEvent((Type)myType), node(_node),
92 service(_service), success(_success)
97 class KNetwork::KReverseResolverPrivate
105 ReverseThread* worker;
109 : addr(_addr), worker(0L), success(false)
114 TQObject *parent,
const char* name)
115 : TQObject(parent, name), d(new KReverseResolverPrivate(addr))
123 d->worker->m_parent = 0L;
128 return d->worker != 0L;
161 d->worker =
new ReverseThread(d->addr, d->flags);
162 d->worker->m_parent =
this;
164 RequestData *req =
new RequestData;
168 req->worker = d->worker;
169 KResolverManager::manager()->dispatch(req);
175 if (e->type() != KReverseResolverEvent::myType)
176 return TQObject::event(e);
178 KReverseResolverEvent *re =
static_cast<KReverseResolverEvent*
>(e);
180 d->service = re->service;
181 d->success = re->success;
194 TQString& serv,
int flags)
196 ReverseThread th(addr, flags);
207 TQString& node, TQString& serv,
int flags)
212 bool ReverseThread::run()
215 char h[NI_MAXHOST], s[NI_MAXSERV];
220 if (m_flags & KReverseResolver::NumericHost)
221 niflags |= NI_NUMERICHOST;
222 if (m_flags & KReverseResolver::NumericService)
223 niflags |= NI_NUMERICSERV;
224 if (m_flags & KReverseResolver::NodeNameOnly)
225 niflags |= NI_NOFQDN;
226 if (m_flags & KReverseResolver::Datagram)
228 if (m_flags & KReverseResolver::ResolutionRequired)
229 niflags |= NI_NAMEREQD;
233 TQMutexLocker locker(&::getXXbyYYmutex);
235 err = ::getnameinfo(m_addr, m_addr.length(),
236 h,
sizeof(h) - 1, s,
sizeof(s) - 1, niflags);
242 service = TQString::fromLatin1(s);
247 node = service = TQString::null;
254 bool ReverseThread::postprocess()
258 TQApplication::postEvent(m_parent,
259 new KReverseResolverEvent(node, service, success));
263 #include "kreverseresolver.moc"
static TQString domainToUnicode(const TQCString &asciiDomain)
Does the inverse of domainToAscii and return an Unicode domain name from the given ACE-encoded domain...
Run a reverse-resolution on a socket address.
bool failure() const
This function returns true if the processing has finished with failure, false if it's still running o...
static bool resolve(const TDESocketAddress &addr, TQString &node, TQString &serv, int flags=0)
Resolves a socket address to its textual representation.
bool success() const
This function returns true if the processing has finished with success, false if it's still running o...
TQString service() const
Returns the resolved service name, if the resolution has finished successfully, or TQString::null oth...
KReverseResolver(const TDESocketAddress &addr, int flags=0, TQObject *=0L, const char *=0L)
Constructs this object to resolve the given socket address.
TQString node() const
Returns the resolved node name, if the resolution has finished successfully, or TQString::null otherw...
bool start()
Starts the resolution.
const TDESocketAddress & address() const
Returns the socket address which was subject to resolution.
virtual bool event(TQEvent *)
Overrides event handling.
bool isRunning() const
This function returns 'true' if the processing is still running.
void finished(const KReverseResolver &obj)
This signal is emitted when the resolution has finished.
virtual ~KReverseResolver()
Destructor.
A generic socket address.
A namespace to store all networking-related (socket) classes.