kresolver.h
/* -*- mode: C++; coding: utf-8; -*-
* Copyright (C) 2003,2005 Thiago Macieira <thiago.macieira@kdemail.net>
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef KRESOLVER_H
#define KRESOLVER_H
// Needed includes
#include <qvaluelist.h>
#include <qobject.h>
#include "ksocketaddress.h"
// Forward declarations
struct sockaddr;
class QString;
class QCString;
class QStrList;
// Our definitions
namespace KNetwork {
namespace Internal { class KResolverManager; }
class KResolverEntryPrivate;
class KDECORE_EXPORT KResolverEntry
{
public:
KResolverEntry();
KResolverEntry(const KSocketAddress& addr, int socktype, int protocol,
const QString& canonName = QString::null,
const QCString& encodedName = QCString());
KResolverEntry(const struct sockaddr *sa, Q_UINT16 salen, int socktype,
int protocol, const QString& canonName = QString::null,
const QCString& encodedName = QCString());
KResolverEntry(const KResolverEntry &other);
~KResolverEntry();
KSocketAddress address() const;
Q_UINT16 length() const;
int family() const;
QString canonicalName() const;
QCString encodedName() const;
int socketType() const;
int protocol() const;
KResolverEntry& operator=(const KResolverEntry& other);
private:
KResolverEntryPrivate* d;
};
class KResolverResultsPrivate;
class KDECORE_EXPORT KResolverResults: public QValueList<KResolverEntry>
{
public:
KResolverResults();
KResolverResults(const KResolverResults& other);
virtual ~KResolverResults();
KResolverResults& operator=(const KResolverResults& other);
int error() const;
int systemError() const;
void setError(int errorcode, int systemerror = 0);
QString nodeName() const;
QString serviceName() const;
void setAddress(const QString& host, const QString& service);
protected:
virtual void virtual_hook( int id, void* data );
private:
KResolverResultsPrivate* d;
};
class KResolverPrivate;
class KDECORE_EXPORT KResolver: public QObject
{
Q_OBJECT
public:
enum SocketFamilies
{
UnknownFamily = 0x0001,
UnixFamily = 0x0002,
LocalFamily = UnixFamily,
IPv4Family = 0x0004,
IPv6Family = 0x0008,
InternetFamily = IPv4Family | IPv6Family,
InetFamily = InternetFamily,
KnownFamily = ~UnknownFamily,
AnyFamily = KnownFamily | UnknownFamily
};
enum Flags
{
Passive = 0x01,
CanonName = 0x02,
NoResolve = 0x04,
NoSrv = 0x08,
Multiport = 0x10,
UseSrv = 0x20
};
enum ErrorCodes
{
// note: if you change this enum, take a look at KResolver::errorString
NoError = 0,
AddrFamily = -1,
TryAgain = -2,
NonRecoverable = -3,
BadFlags = -4,
Memory = -5,
NoName = -6,
UnsupportedFamily = -7,
UnsupportedService = -8,
UnsupportedSocketType = -9,
UnknownError = -10,
SystemError = -11,
Canceled = -100
};
enum StatusCodes
{
Idle = 0,
Queued = 1,
InProgress = 5,
PostProcessing = 6,
Success = 10,
//Canceled = -100, // already defined above
Failed = -101
};
KResolver(QObject * = 0L, const char * = 0L);
KResolver(const QString& nodename, const QString& servicename = QString::null,
QObject * = 0L, const char * = 0L);
virtual ~KResolver();
int status() const;
int error() const;
int systemError() const;
inline QString errorString() const
{ return errorString(error(), systemError()); }
bool isRunning() const;
QString nodeName() const;
QString serviceName() const;
void setNodeName(const QString& nodename);
void setServiceName(const QString& service);
void setAddress(const QString& node, const QString& service);
int flags() const;
int setFlags(int flags);
void setFamily(int families);
void setSocketType(int type);
void setProtocol(int protonum, const char *name = 0L);
bool start();
bool wait(int msec = 0);
void cancel(bool emitSignal = true);
KResolverResults results() const;
virtual bool event(QEvent*);
signals:
// signals
void finished(KResolverResults results);
private:
void emitFinished();
public:
// Static functions
static QString errorString(int errorcode, int syserror = 0);
static KResolverResults resolve(const QString& host, const QString& service,
int flags = 0, int families = KResolver::InternetFamily);
static bool resolveAsync(QObject* userObj, const char *userSlot,
const QString& host, const QString& service,
int flags = 0, int families = KResolver::InternetFamily);
static QCString domainToAscii(const QString& unicodeDomain);
static QString domainToUnicode(const QCString& asciiDomain);
static QString domainToUnicode(const QString& asciiDomain);
static QString normalizeDomain(const QString& domain);
static QStrList protocolName(int protonum);
static QStrList protocolName(const char *protoname);
static int protocolNumber(const char *protoname);
static int servicePort(const char *servname, const char *protoname);
static QStrList serviceName(const char *servname, const char *protoname);
static QStrList serviceName(int port, const char *protoname);
static QString localHostName();
protected:
void setError(int errorcode, int systemerror = 0);
virtual void virtual_hook( int id, void* data );
private:
KResolverPrivate* d;
friend class KResolverResults;
friend class ::KNetwork::Internal::KResolverManager;
static QStringList *idnDomains;
};
} // namespace KNetwork
#endif
KNetwork::KResolver::ErrorCodes
ErrorCodes
Error codes.
Definition: kresolver.h:382
KNetwork::KResolverEntry
One resolution entry.
Definition: kresolver.h:66
KNetwork::KResolver
Name and service resolution class.
Definition: kresolver.h:295
KNetwork::KSocketAddress
A generic socket address.
Definition: ksocketaddress.h:423
KNetwork::KResolverResults
Name and service resolution results.
Definition: kresolver.h:197
KNetwork::KResolver::errorString
QString errorString() const
Returns the textual representation of the error in this object.
Definition: kresolver.h:493
KNetwork::KResolver::Flags
Flags
Flags for the resolution.
Definition: kresolver.h:351
KNetwork::KResolver::SocketFamilies
SocketFamilies
Address family selection types.
Definition: kresolver.h:317
KNetwork::KResolver::StatusCodes
StatusCodes
Status codes.
Definition: kresolver.h:420

KDE Home | KDE Accessibility Home | Description of Access Keys