• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

k3resolver.h

Go to the documentation of this file.
00001 /*  -*- mode: C++; coding: utf-8; -*-
00002  *  Copyright (C) 2003,2005 Thiago Macieira <thiago@kde.org>
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 <QtCore/QList>
00031 #include <QtCore/QObject>
00032 #include <QtCore/QSharedDataPointer>
00033 #include "k3socketaddress.h"
00034 
00035 
00037 // Forward declarations
00038 struct sockaddr;
00039 class QString;
00040 class QByteArray;
00041 template<typename T> class QSet;
00042 
00044 // Our definitions
00045 
00046 namespace KNetwork {
00047 
00048   namespace Internal { class KResolverManager; }
00049 
00050 class KResolverEntryPrivate;
00068 class KDECORE_EXPORT KResolverEntry
00069 {
00070 public:
00075   KResolverEntry();
00076 
00089   KResolverEntry(const KSocketAddress& addr, int socktype, int protocol,
00090         const QString& canonName = QString(),
00091         const QByteArray& encodedName = QByteArray());
00092 
00106   KResolverEntry(const struct sockaddr *sa, quint16 salen, int socktype,
00107         int protocol, const QString& canonName = QString(),
00108         const QByteArray& encodedName = QByteArray());
00109 
00115   KResolverEntry(const KResolverEntry &other);
00116 
00123   ~KResolverEntry();
00124 
00128   KSocketAddress address() const;
00129 
00133   quint16 length() const;
00134 
00138   int family() const;
00139 
00144   QString canonicalName() const;
00145 
00156   QByteArray encodedName() const;
00157 
00161   int socketType() const;
00162 
00166   int protocol() const;
00167 
00174   KResolverEntry& operator=(const KResolverEntry& other);
00175 
00176 #ifdef MAKE_KDECORE_LIB
00177 
00181   KDE_DUMMY_COMPARISON_OPERATOR(KResolverEntry)
00182 #endif
00183 
00184 private:
00185   QSharedDataPointer<KResolverEntryPrivate> d;
00186 };
00187 
00188 #ifdef MAKE_KDECORE_LIB
00189 KDE_DUMMY_QHASH_FUNCTION(KResolverEntry)
00190 #endif
00191 
00192 class KResolverResultsPrivate;
00212 class KDECORE_EXPORT KResolverResults: public QList<KResolverEntry>
00213 {
00214 public:
00220   KResolverResults();
00221 
00228   KResolverResults(const KResolverResults& other);
00229 
00235   virtual ~KResolverResults();
00236 
00243   KResolverResults& operator=(const KResolverResults& other);
00244 
00249   int error() const;
00250 
00255   int systemError() const;
00256 
00263   void setError(int errorcode, int systemerror = 0);
00264 
00268   QString nodeName() const;
00269 
00273   QString serviceName() const;
00274 
00278   void setAddress(const QString& host, const QString& service);
00279 
00280 protected:
00282   virtual void virtual_hook( int id, void* data );
00283 private:
00284   QSharedDataPointer<KResolverResultsPrivate> d;
00285 };
00286 
00287 class KResolverPrivate;
00312 class KDECORE_EXPORT KResolver: public QObject
00313 {
00314   Q_OBJECT
00315 
00316 public:
00317 
00334   enum SocketFamilies
00335   {
00336     UnknownFamily = 0x0001,
00337 
00338     UnixFamily = 0x0002,
00339     LocalFamily = UnixFamily,
00340 
00341     IPv4Family = 0x0004,
00342     IPv6Family = 0x0008,
00343     InternetFamily = IPv4Family | IPv6Family,
00344     InetFamily = InternetFamily,
00345 
00346     KnownFamily = ~UnknownFamily,
00347     AnyFamily = KnownFamily | UnknownFamily
00348   };
00349 
00367   enum Flags
00368     {
00369       Passive = 0x01,
00370       CanonName = 0x02,
00371       NoResolve = 0x04,
00372       NoSrv = 0x08,
00373       Multiport = 0x10
00374     };
00375 
00397   enum ErrorCodes
00398     {
00399       // note: if you change this enum, take a look at KResolver::errorString
00400       NoError = 0,
00401       AddrFamily = -1,
00402       TryAgain = -2,
00403       NonRecoverable = -3,
00404       BadFlags = -4,
00405       Memory = -5,
00406       NoName = -6,
00407       UnsupportedFamily = -7,
00408       UnsupportedService = -8,
00409       UnsupportedSocketType = -9,
00410       UnknownError = -10,
00411       SystemError = -11,
00412       Canceled = -100
00413     };
00414 
00435   enum StatusCodes
00436     {
00437       Idle = 0,
00438       Queued = 1,
00439       InProgress = 5,
00440       PostProcessing = 6,
00441       Success = 10,
00442       //Canceled = -100,    // already defined above
00443       Failed = -101
00444     };
00445 
00455   KResolver(QObject *parent = 0L);
00456 
00468   explicit KResolver(const QString& nodename, const QString& servicename = QString(),
00469         QObject *parent = 0L);
00470 
00478   virtual ~KResolver();
00479 
00485   int status() const;
00486 
00497   int error() const;
00498 
00506   int systemError() const;
00507 
00511   QString errorString() const;
00512 
00516   bool isRunning() const;
00517 
00521   QString nodeName() const;
00522 
00526   QString serviceName() const;
00527 
00534   void setNodeName(const QString& nodename);
00535 
00542   void setServiceName(const QString& service);
00543 
00551   void setAddress(const QString& node, const QString& service);
00552 
00558   int flags() const;
00559 
00567   int setFlags(int flags);
00568 
00575   void setFamily(int families);
00576 
00596   void setSocketType(int type);
00597 
00622   void setProtocol(int protonum, const char *name = 0L);
00623 
00642   bool start();
00643 
00665   bool wait(int msec = 0);
00666 
00678   void cancel(bool emitSignal = true);
00679 
00690   KResolverResults results() const;
00691 
00700   virtual bool event(QEvent*);
00701 
00702 Q_SIGNALS:
00703   // signals
00704 
00721   void finished(const KNetwork::KResolverResults& results);
00722 
00723 private:
00724   void emitFinished();
00725 
00726 public:
00727   // Static functions
00728 
00737   static QString errorString(int errorcode, int syserror = 0);
00738 
00762   static KResolverResults resolve(const QString& host, const QString& service,
00763                  int flags = 0, int families = KResolver::InternetFamily);
00764 
00799   static bool resolveAsync(QObject* userObj, const char *userSlot,
00800                const QString& host, const QString& service,
00801                int flags = 0, int families = KResolver::InternetFamily);
00802 
00819   static QByteArray domainToAscii(const QString& unicodeDomain);
00820 
00839   static QString domainToUnicode(const QByteArray& asciiDomain);
00840 
00848   static QString domainToUnicode(const QString& asciiDomain);
00849 
00873   static QString normalizeDomain(const QString& domain);
00874 
00884   static QList<QByteArray> protocolName(int protonum);
00885 
00893   static QList<QByteArray> protocolName(const char *protoname);
00894 
00901   static int protocolNumber(const char *protoname);
00902 
00910   static int servicePort(const char *servname, const char *protoname);
00911 
00922   static QList<QByteArray> serviceName(const char *servname, const char *protoname);
00923 
00934   static QList<QByteArray> serviceName(int port, const char *protoname);
00935 
00941   static QString localHostName();
00942 
00943 protected:
00944 
00948   void setError(int errorcode, int systemerror = 0);
00949 
00951   virtual void virtual_hook( int id, void* data );
00952 private:
00953   KResolverPrivate* const d;
00954   friend class KResolverResults;
00955   friend class ::KNetwork::Internal::KResolverManager;
00956 };
00957 
00958 }               // namespace KNetwork
00959 
00960 #endif

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal