# kdecore Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kresolver.h

    00001 /*  -*- mode: C++; coding: utf-8; -*-
    00002  *  Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
    00003  *
    00004  *
    00005  *  Permission is hereby granted, free of charge, to any person obtaining
    00006  *  a copy of this software and associated documentation files (the
    00007  *  "Software"), to deal in the Software without restriction, including
    00008  *  without limitation the rights to use, copy, modify, merge, publish,
    00009  *  distribute, sublicense, and/or sell copies of the Software, and to
    00010  *  permit persons to whom the Software is furnished to do so, subject to
    00011  *  the following conditions:
    00012  *
    00013  *  The above copyright notice and this permission notice shall be included
    00014  *  in all copies or substantial portions of the Software.
    00015  *
    00016  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    00017  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    00018  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    00019  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    00020  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    00021  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    00022  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00023  */
    00024
    00025 #ifndef KRESOLVER_H
    00026 #define KRESOLVER_H
    00027
    00029 // Needed includes
    00030 #include <qvaluelist.h>
    00031 #include <qobject.h>
    00032 #include "ksocketaddress.h"
    00033
    00034
    00036 // Forward declarations
    00037 struct sockaddr;
    00038 class QString;
    00039 class QCString;
    00040 class QStrList;
    00041
    00043 // Our definitions
    00044
    00045 namespace KNetwork {
    00046
    00047   namespace Internal { class KResolverManager; }
    00048
    00049 class KResolverEntryPrivate;
    00066 class KDECORE_EXPORT KResolverEntry
    00067 {
    00068 public:
    00073   KResolverEntry();
    00074
    00087   KResolverEntry(const KSocketAddress& addr, int socktype, int protocol,
    00088         const QString& canonName = QString::null,
    00089         const QCString& encodedName = QCString());
    00090
    00104   KResolverEntry(const struct sockaddr *sa, Q_UINT16 salen, int socktype,
    00105         int protocol, const QString& canonName = QString::null,
    00106         const QCString& encodedName = QCString());
    00107
    00113   KResolverEntry(const KResolverEntry &other);
    00114
    00121   ~KResolverEntry();
    00122
    00126   KSocketAddress address() const;
    00127
    00131   Q_UINT16 length() const;
    00132
    00136   int family() const;
    00137
    00142   QString canonicalName() const;
    00143
    00154   QCString encodedName() const;
    00155
    00159   int socketType() const;
    00160
    00164   int protocol() const;
    00165
    00172   KResolverEntry& operator=(const KResolverEntry& other);
    00173
    00174 private:
    00175   KResolverEntryPrivate* d;
    00176 };
    00177
    00178 class KResolverResultsPrivate;
    00197 class KDECORE_EXPORT KResolverResults: public QValueList<KResolverEntry>
    00198 {
    00199 public:
    00205   KResolverResults();
    00206
    00213   KResolverResults(const KResolverResults& other);
    00214
    00220   virtual ~KResolverResults();
    00221
    00228   KResolverResults& operator=(const KResolverResults& other);
    00229
    00234   int error() const;
    00235
    00240   int systemError() const;
    00241
    00248   void setError(int errorcode, int systemerror = 0);
    00249
    00253   QString nodeName() const;
    00254
    00258   QString serviceName() const;
    00259
    00263   void setAddress(const QString& host, const QString& service);
    00264
    00265 protected:
    00266   virtual void virtual_hook( int id, void* data );
    00267 private:
    00268   KResolverResultsPrivate* d;
    00269 };
    00270
    00271 class KResolverPrivate;
    00295 class KDECORE_EXPORT KResolver: public QObject
    00296 {
    00297   Q_OBJECT
    00298
    00299 public:
    00300
    00317   enum SocketFamilies
    00318   {
    00319     UnknownFamily = 0x0001,
    00320
    00321     UnixFamily = 0x0002,
    00322     LocalFamily = UnixFamily,
    00323
    00324     IPv4Family = 0x0004,
    00325     IPv6Family = 0x0008,
    00326     InternetFamily = IPv4Family | IPv6Family,
    00327     InetFamily = InternetFamily,
    00328
    00329     KnownFamily = ~UnknownFamily,
    00330     AnyFamily = KnownFamily | UnknownFamily
    00331   };
    00332
    00350   enum Flags
    00351     {
    00352       Passive = 0x01,
    00353       CanonName = 0x02,
    00354       NoResolve = 0x04,
    00355       NoSrv = 0x08,
    00356       Multiport = 0x10
    00357     };
    00358
    00380   enum ErrorCodes
    00381     {
    00382       // note: if you change this enum, take a look at KResolver::errorString
    00383       NoError = 0,
    00384       AddrFamily = -1,
    00385       TryAgain = -2,
    00386       NonRecoverable = -3,
    00387       BadFlags = -4,
    00388       Memory = -5,
    00389       NoName = -6,
    00390       UnsupportedFamily = -7,
    00391       UnsupportedService = -8,
    00392       UnsupportedSocketType = -9,
    00393       UnknownError = -10,
    00394       SystemError = -11,
    00395       Canceled = -100
    00396     };
    00397
    00418   enum StatusCodes
    00419     {
    00420       Idle = 0,
    00421       Queued = 1,
    00422       InProgress = 5,
    00423       PostProcessing = 6,
    00424       Success = 10,
    00425       //Canceled = -100,    // already defined above
    00426       Failed = -101
    00427     };
    00428
    00436   KResolver(QObject * = 0L, const char * = 0L);
    00437
    00448   KResolver(const QString& nodename, const QString& servicename = QString::null,
    00449         QObject * = 0L, const char * = 0L);
    00450
    00458   virtual ~KResolver();
    00459
    00465   int status() const;
    00466
    00477   int error() const;
    00478
    00486   int systemError() const;
    00487
    00491   inline QString errorString() const
    00492   { return errorString(error(), systemError()); }
    00493
    00497   bool isRunning() const;
    00498
    00502   QString nodeName() const;
    00503
    00507   QString serviceName() const;
    00508
    00515   void setNodeName(const QString& nodename);
    00516
    00523   void setServiceName(const QString& service);
    00524
    00532   void setAddress(const QString& node, const QString& service);
    00533
    00539   int flags() const;
    00540
    00548   int setFlags(int flags);
    00549
    00556   void setFamily(int families);
    00557
    00577   void setSocketType(int type);
    00578
    00603   void setProtocol(int protonum, const char *name = 0L);
    00604
    00623   bool start();
    00624
    00646   bool wait(int msec = 0);
    00647
    00659   void cancel(bool emitSignal = true);
    00660
    00671   KResolverResults results() const;
    00672
    00681   virtual bool event(QEvent*);
    00682
    00683 signals:
    00684   // signals
    00685
    00702   void finished(KResolverResults results);
    00703
    00704 private:
    00705   void emitFinished();
    00706
    00707 public:
    00708   // Static functions
    00709
    00718   static QString errorString(int errorcode, int syserror = 0);
    00719
    00743   static KResolverResults resolve(const QString& host, const QString& service,
    00744                  int flags = 0, int families = KResolver::InternetFamily);
    00745
    00780   static bool resolveAsync(QObject* userObj, const char *userSlot,
    00781                const QString& host, const QString& service,
    00782                int flags = 0, int families = KResolver::InternetFamily);
    00783
    00800   static QCString domainToAscii(const QString& unicodeDomain);
    00801
    00820   static QString domainToUnicode(const QCString& asciiDomain);
    00821
    00829   static QString domainToUnicode(const QString& asciiDomain);
    00830
    00854   static QString normalizeDomain(const QString& domain);
    00855
    00865   static QStrList protocolName(int protonum);
    00866
    00874   static QStrList protocolName(const char *protoname);
    00875
    00882   static int protocolNumber(const char *protoname);
    00883
    00891   static int servicePort(const char *servname, const char *protoname);
    00892
    00903   static QStrList serviceName(const char *servname, const char *protoname);
    00904
    00915   static QStrList serviceName(int port, const char *protoname);
    00916
    00917 protected:
    00918
    00922   void setError(int errorcode, int systemerror = 0);
    00923
    00924   virtual void virtual_hook( int id, void* data );
    00925 private:
    00926   KResolverPrivate* d;
    00927   friend class KResolverResults;
    00928   friend class ::KNetwork::Internal::KResolverManager;
    00929
    00930   static QStringList *idnDomains;
    00931 };
    00932
    00933 }               // namespace KNetwork
    00934
    00935 #endif

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:10 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003