• Skip to content
  • Skip to link menu
KDE 4.1 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;
00067 class KDECORE_EXPORT KResolverEntry
00068 {
00069 public:
00074   KResolverEntry();
00075 
00088   KResolverEntry(const KSocketAddress& addr, int socktype, int protocol,
00089         const QString& canonName = QString(),
00090         const QByteArray& encodedName = QByteArray());
00091 
00105   KResolverEntry(const struct sockaddr *sa, quint16 salen, int socktype,
00106         int protocol, const QString& canonName = QString(),
00107         const QByteArray& encodedName = QByteArray());
00108 
00114   KResolverEntry(const KResolverEntry &other);
00115 
00122   ~KResolverEntry();
00123 
00127   KSocketAddress address() const;
00128 
00132   quint16 length() const;
00133 
00137   int family() const;
00138 
00143   QString canonicalName() const;
00144 
00155   QByteArray encodedName() const;
00156 
00160   int socketType() const;
00161 
00165   int protocol() const;
00166 
00173   KResolverEntry& operator=(const KResolverEntry& other);
00174 
00175 #ifdef MAKE_KDECORE_LIB
00176 
00180   KDE_DUMMY_COMPARISON_OPERATOR(KResolverEntry)
00181 #endif
00182 
00183 private:
00184   QSharedDataPointer<KResolverEntryPrivate> d;
00185 };
00186 
00187 #ifdef MAKE_KDECORE_LIB
00188 KDE_DUMMY_QHASH_FUNCTION(KResolverEntry)
00189 #endif
00190 
00191 class KResolverResultsPrivate;
00210 class KDECORE_EXPORT KResolverResults: public QList<KResolverEntry>
00211 {
00212 public:
00218   KResolverResults();
00219 
00226   KResolverResults(const KResolverResults& other);
00227 
00233   virtual ~KResolverResults();
00234 
00241   KResolverResults& operator=(const KResolverResults& other);
00242 
00247   int error() const;
00248 
00253   int systemError() const;
00254 
00261   void setError(int errorcode, int systemerror = 0);
00262 
00266   QString nodeName() const;
00267 
00271   QString serviceName() const;
00272 
00276   void setAddress(const QString& host, const QString& service);
00277 
00278 protected:
00280   virtual void virtual_hook( int id, void* data );
00281 private:
00282   QSharedDataPointer<KResolverResultsPrivate> d;
00283 };
00284 
00285 class KResolverPrivate;
00309 class KDECORE_EXPORT KResolver: public QObject
00310 {
00311   Q_OBJECT
00312 
00313 public:
00314 
00331   enum SocketFamilies
00332   {
00333     UnknownFamily = 0x0001,
00334 
00335     UnixFamily = 0x0002,
00336     LocalFamily = UnixFamily,
00337 
00338     IPv4Family = 0x0004,
00339     IPv6Family = 0x0008,
00340     InternetFamily = IPv4Family | IPv6Family,
00341     InetFamily = InternetFamily,
00342 
00343     KnownFamily = ~UnknownFamily,
00344     AnyFamily = KnownFamily | UnknownFamily
00345   };
00346 
00364   enum Flags
00365     {
00366       Passive = 0x01,
00367       CanonName = 0x02,
00368       NoResolve = 0x04,
00369       NoSrv = 0x08,
00370       Multiport = 0x10
00371     };
00372 
00394   enum ErrorCodes
00395     {
00396       // note: if you change this enum, take a look at KResolver::errorString
00397       NoError = 0,
00398       AddrFamily = -1,
00399       TryAgain = -2,
00400       NonRecoverable = -3,
00401       BadFlags = -4,
00402       Memory = -5,
00403       NoName = -6,
00404       UnsupportedFamily = -7,
00405       UnsupportedService = -8,
00406       UnsupportedSocketType = -9,
00407       UnknownError = -10,
00408       SystemError = -11,
00409       Canceled = -100
00410     };
00411 
00432   enum StatusCodes
00433     {
00434       Idle = 0,
00435       Queued = 1,
00436       InProgress = 5,
00437       PostProcessing = 6,
00438       Success = 10,
00439       //Canceled = -100,    // already defined above
00440       Failed = -101
00441     };
00442 
00450   KResolver(QObject * = 0L);
00451 
00462   explicit KResolver(const QString& nodename, const QString& servicename = QString(),
00463         QObject * = 0L);
00464 
00472   virtual ~KResolver();
00473 
00479   int status() const;
00480 
00491   int error() const;
00492 
00500   int systemError() const;
00501 
00505   QString errorString() const;
00506 
00510   bool isRunning() const;
00511 
00515   QString nodeName() const;
00516 
00520   QString serviceName() const;
00521 
00528   void setNodeName(const QString& nodename);
00529 
00536   void setServiceName(const QString& service);
00537 
00545   void setAddress(const QString& node, const QString& service);
00546 
00552   int flags() const;
00553 
00561   int setFlags(int flags);
00562 
00569   void setFamily(int families);
00570 
00590   void setSocketType(int type);
00591 
00616   void setProtocol(int protonum, const char *name = 0L);
00617 
00636   bool start();
00637 
00659   bool wait(int msec = 0);
00660 
00672   void cancel(bool emitSignal = true);
00673 
00684   KResolverResults results() const;
00685 
00694   virtual bool event(QEvent*);
00695 
00696 Q_SIGNALS:
00697   // signals
00698 
00715   void finished(const KNetwork::KResolverResults& results);
00716 
00717 private:
00718   void emitFinished();
00719 
00720 public:
00721   // Static functions
00722 
00731   static QString errorString(int errorcode, int syserror = 0);
00732 
00756   static KResolverResults resolve(const QString& host, const QString& service,
00757                  int flags = 0, int families = KResolver::InternetFamily);
00758 
00793   static bool resolveAsync(QObject* userObj, const char *userSlot,
00794                const QString& host, const QString& service,
00795                int flags = 0, int families = KResolver::InternetFamily);
00796 
00813   static QByteArray domainToAscii(const QString& unicodeDomain);
00814 
00833   static QString domainToUnicode(const QByteArray& asciiDomain);
00834 
00842   static QString domainToUnicode(const QString& asciiDomain);
00843 
00867   static QString normalizeDomain(const QString& domain);
00868 
00878   static QList<QByteArray> protocolName(int protonum);
00879 
00887   static QList<QByteArray> protocolName(const char *protoname);
00888 
00895   static int protocolNumber(const char *protoname);
00896 
00904   static int servicePort(const char *servname, const char *protoname);
00905 
00916   static QList<QByteArray> serviceName(const char *servname, const char *protoname);
00917 
00928   static QList<QByteArray> serviceName(int port, const char *protoname);
00929 
00935   static QString localHostName();
00936 
00937 protected:
00938 
00942   void setError(int errorcode, int systemerror = 0);
00943 
00945   virtual void virtual_hook( int id, void* data );
00946 private:
00947   KResolverPrivate* const d;
00948   friend class KResolverResults;
00949   friend class ::KNetwork::Internal::KResolverManager;
00950 };
00951 
00952 }               // namespace KNetwork
00953 
00954 #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
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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