KDELibs4Support

k3resolver.h
1 /* -*- mode: C++; coding: utf-8; -*-
2  * Copyright (C) 2003,2005 Thiago Macieira <[email protected]>
3  *
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef KRESOLVER_H
26 #define KRESOLVER_H
27 
29 // Needed includes
30 #include <QList>
31 #include <QObject>
32 #include <QSharedDataPointer>
33 #include "k3socketaddress.h"
34 #include "kdemacros.h"
35 
37 // Forward declarations
38 struct sockaddr;
39 class QString;
40 class QByteArray;
41 template<typename T> class QSet;
42 
44 // Our definitions
45 
46 namespace KNetwork
47 {
48 
49 namespace Internal
50 {
51 class KResolverManager;
52 }
53 
54 class KResolverEntryPrivate;
72 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KResolverEntry
73 {
74 public:
80 
93  KResolverEntry(const KSocketAddress &addr, int socktype, int protocol,
94  const QString &canonName = QString(),
95  const QByteArray &encodedName = QByteArray());
96 
110  KResolverEntry(const struct sockaddr *sa, quint16 salen, int socktype,
111  int protocol, const QString &canonName = QString(),
112  const QByteArray &encodedName = QByteArray());
113 
119  KResolverEntry(const KResolverEntry &other);
120 
127  ~KResolverEntry();
128 
132  KSocketAddress address() const;
133 
137  quint16 length() const;
138 
142  int family() const;
143 
148  QString canonicalName() const;
149 
160  QByteArray encodedName() const;
161 
165  int socketType() const;
166 
170  int protocol() const;
171 
178  KResolverEntry &operator=(const KResolverEntry &other);
179 
184  KDE_DUMMY_COMPARISON_OPERATOR(KResolverEntry)
185 
186 private:
188 };
189 
190 KDE_DUMMY_QHASH_FUNCTION(KResolverEntry)
191 
192 class KResolverResultsPrivate;
212 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KResolverResults: public QList<KResolverEntry>
213 {
214 public:
221 
228  KResolverResults(const KResolverResults &other);
229 
235  virtual ~KResolverResults();
236 
243  KResolverResults &operator=(const KResolverResults &other);
244 
249  int error() const;
250 
255  int systemError() const;
256 
263  void setError(int errorcode, int systemerror = 0);
264 
268  QString nodeName() const;
269 
273  QString serviceName() const;
274 
278  void setAddress(const QString &host, const QString &service);
279 
280 protected:
282  virtual void virtual_hook(int id, void *data);
283 private:
285 };
286 
287 class KResolverPrivate;
312 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KResolver: public QObject
313 {
314  Q_OBJECT
315 
316 public:
317 
335  UnknownFamily = 0x0001,
336 
337  UnixFamily = 0x0002,
338  LocalFamily = UnixFamily,
339 
340  IPv4Family = 0x0004,
341  IPv6Family = 0x0008,
342  InternetFamily = IPv4Family | IPv6Family,
343  InetFamily = InternetFamily,
344 
345  KnownFamily = ~UnknownFamily,
346  AnyFamily = KnownFamily | UnknownFamily
347  };
348 
366  enum Flags {
367  Passive = 0x01,
368  CanonName = 0x02,
369  NoResolve = 0x04,
370  NoSrv = 0x08,
371  Multiport = 0x10
372  };
373 
395  enum ErrorCodes {
396  // note: if you change this enum, take a look at KResolver::errorString
397  NoError = 0,
398  AddrFamily = -1,
399  TryAgain = -2,
400  NonRecoverable = -3,
401  BadFlags = -4,
402  Memory = -5,
403  NoName = -6,
404  UnsupportedFamily = -7,
405  UnsupportedService = -8,
406  UnsupportedSocketType = -9,
407  UnknownError = -10,
408  SystemError = -11,
409  Canceled = -100
410  };
411 
432  enum StatusCodes {
433  Idle = 0,
434  Queued = 1,
435  InProgress = 5,
436  PostProcessing = 6,
437  Success = 10,
438  //Canceled = -100, // already defined above
439  Failed = -101
440  };
441 
451  KResolver(QObject *parent = nullptr);
452 
464  KDELIBS4SUPPORT_DEPRECATED explicit KResolver(const QString &nodename, const QString &servicename = QString(),
465  QObject *parent = nullptr);
466 
474  virtual ~KResolver();
475 
481  int status() const;
482 
493  int error() const;
494 
502  int systemError() const;
503 
507  QString errorString() const;
508 
512  bool isRunning() const;
513 
517  QString nodeName() const;
518 
522  QString serviceName() const;
523 
530  void setNodeName(const QString &nodename);
531 
538  void setServiceName(const QString &service);
539 
547  void setAddress(const QString &node, const QString &service);
548 
554  int flags() const;
555 
563  int setFlags(int flags);
564 
571  void setFamily(int families);
572 
592  void setSocketType(int type);
593 
618  void setProtocol(int protonum, const char *name = nullptr);
619 
638  bool start();
639 
661  bool wait(int msec = 0);
662 
674  void cancel(bool emitSignal = true);
675 
686  KResolverResults results() const;
687 
696  bool event(QEvent *) override;
697 
698 Q_SIGNALS:
699  // signals
700 
717  void finished(const KNetwork::KResolverResults &results);
718 
719 private:
720  void emitFinished();
721 
722 public:
723  // Static functions
724 
733  static QString errorString(int errorcode, int syserror = 0);
734 
758  static KResolverResults resolve(const QString &host, const QString &service,
759  int flags = 0, int families = KResolver::InternetFamily);
760 
795  static bool resolveAsync(QObject *userObj, const char *userSlot,
796  const QString &host, const QString &service,
797  int flags = 0, int families = KResolver::InternetFamily);
798 
815  static QByteArray domainToAscii(const QString &unicodeDomain);
816 
835  static QString domainToUnicode(const QByteArray &asciiDomain);
836 
844  static QString domainToUnicode(const QString &asciiDomain);
845 
869  static QString normalizeDomain(const QString &domain);
870 
880  static QList<QByteArray> protocolName(int protonum);
881 
889  static QList<QByteArray> protocolName(const char *protoname);
890 
897  static int protocolNumber(const char *protoname);
898 
906  static int servicePort(const char *servname, const char *protoname);
907 
918  static QList<QByteArray> serviceName(const char *servname, const char *protoname);
919 
930  static QList<QByteArray> serviceName(int port, const char *protoname);
931 
937  static QString localHostName();
938 
939 protected:
940 
944  void setError(int errorcode, int systemerror = 0);
945 
947  virtual void virtual_hook(int id, void *data);
948 private:
949  KResolverPrivate *const d;
950  friend class KResolverResults;
951  friend class ::KNetwork::Internal::KResolverManager;
952 };
953 
954 } // namespace KNetwork
955 
956 #endif
ErrorCodes
Error codes.
Definition: k3resolver.h:395
One resolution entry.
Definition: k3resolver.h:72
Name and service resolution class.
Definition: k3resolver.h:312
A generic socket address.
Name and service resolution results.
Definition: k3resolver.h:212
A namespace to store all networking-related (socket) classes.
Flags
Flags for the resolution.
Definition: k3resolver.h:366
SocketFamilies
Address family selection types.
Definition: k3resolver.h:334
StatusCodes
Status codes.
Definition: k3resolver.h:432
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 22:59:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.