kresolver.h

来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C头文件 代码 · 共 946 行 · 第 1/2 页

H
946
字号
/*  -*- 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 declarationsstruct sockaddr;class QString;class QCString;class QStrList;//////////////////// Our definitionsnamespace KNetwork {  namespace Internal { class KResolverManager; }class KResolverEntryPrivate;/** @class KResolverEntry kresolver.h kresolver.h *  @brief One resolution entry. * * This class is one element in the resolution results list. * It contains the socket address for connecting, as well as * a bit more of information: the socket type, address family * and protocol numbers. * * This class contains all the information required for creating, * binding and connecting a socket. * * KResolverEntry objects implicitly share data, so copying them * is quite efficient. * * @author Thiago Macieira <thiago.macieira@kdemail.net> */class KDECORE_EXPORT KResolverEntry{public:  /**   * Default constructor   *   */  KResolverEntry();  /**   * Constructs a new KResolverEntry from a KSocketAddress   * and other data.   *   * The KSocketAddress @p addr parameter will be deep-copied.   *   * @param addr	the address that was resolved   * @param socktype	the socket type of the resolved address   * @param protocol	the protocol of the resolved address   * @param canonName	the canonical name of the resolved hostname   * @param encodedName	the ASCII-compatible encoding of the hostname   */  KResolverEntry(const KSocketAddress& addr, int socktype, int protocol,		const QString& canonName = QString::null,		const QCString& encodedName = QCString());  /**   * Constructs a new KResolverEntry from raw forms of   * socket addresses and other data.   *   * This constructor instead creates an internal KSocketAddress object.   *   * @param sa		the sockaddr structure containing the raw address   * @param salen	the length of the sockaddr structure   * @param socktype	the socket type of the resolved address   * @param protocol	the protocol of the resolved address   * @param canonName	the canonical name of the resolved hostname   * @param encodedName	the ASCII-compatible encoding of the hostname   */  KResolverEntry(const struct sockaddr *sa, Q_UINT16 salen, int socktype,		int protocol, const QString& canonName = QString::null,		const QCString& encodedName = QCString());  /**   * Copy constructor.   *   * This constructor performs a shallow-copy of the other object.   */  KResolverEntry(const KResolverEntry &other);  /**   * Destructor.   *   * The destructor frees associated resources with this object. It does   * not destroy shared data.   */  ~KResolverEntry();  /**   * Retrieves the socket address associated with this entry.   */  KSocketAddress address() const;  /**   * Retrieves the length of the socket address structure.   */  Q_UINT16 length() const;  /**   * Retrieves the family associated with this socket address.   */  int family() const;  /**   * Retrieves the canonical name associated with this entry, if there is any.   * If the canonical name was not found, this function returns QString::null.   */  QString canonicalName() const;  /**   * Retrieves the encoded domain name associated with this entry, if there is   * any. If this domain has been resolved through DNS, this will be the   * the ACE-encoded hostname.   *   * Returns a null QCString if such information is not available.   *   * Please note that this information is NOT to be presented to the user,   * unless requested.   */  QCString encodedName() const;  /**   * Retrieves the socket type associated with this entry.   */  int socketType() const;  /**   * Retrieves the protocol associated with this entry.   */  int protocol() const;  /**   * Assignment operator   *   * This function copies the contents of the other object into this one.   * Data will be shared between the two of them.   */  KResolverEntry& operator=(const KResolverEntry& other);private:  KResolverEntryPrivate* d;};class KResolverResultsPrivate;/** * @class KResolverResults kresolver.h kresolver.h * @brief Name and service resolution results. * * This object contains the results of a name and service resolution, as * those performed by @ref KResolver. It is also a descendant of QValueList, so * you may use all its member functions here to access the elements. * * A KResolverResults object is associated with a resolution, so, in addition * to the resolved elements, you can also retrieve information about the  * resolution process itself, like the nodename that was resolved or an error * code. * * Note Resolver also uses KResolverResults objects to indicate failure, so * you should test for failure. * * @author Thiago Macieira <thiago.macieira@kdemail.net> */class KDECORE_EXPORT KResolverResults: public QValueList<KResolverEntry>{public:  /**   * Default constructor.   *   * Constructs an empty list.   */  KResolverResults();  /**   * Copy constructor   *   * Creates a new object with the contents of the other one. Data will be   * shared by the two objects, like QValueList   */  KResolverResults(const KResolverResults& other);  /**   * Destructor   *   * Destroys the object and frees associated resources.   */  virtual ~KResolverResults();  /**   * Assignment operator   *   * Copies the contents of the other container into this one, discarding   * our current values.   */  KResolverResults& operator=(const KResolverResults& other);  /**   * Retrieves the error code associated with this resolution. The values   * here are the same as in @ref KResolver::ErrorCodes.   */  int error() const;  /**   * Retrieves the system error code, if any.   * @see KResolver::systemError for more information   */  int systemError() const;  /**   * Sets the error codes   *   * @param errorcode		the error code in @ref KResolver::ErrorCodes   * @param systemerror	the system error code associated, if any   */  void setError(int errorcode, int systemerror = 0);  /**   * The nodename to which the resolution was performed.   */  QString nodeName() const;  /**   * The service name to which the resolution was performed.   */  QString serviceName() const;  /**   * Sets the new nodename and service name   */  void setAddress(const QString& host, const QString& service);protected:  virtual void virtual_hook( int id, void* data );private:  KResolverResultsPrivate* d;};class KResolverPrivate;/** * @class KResolver kresolver.h kresolver.h * @brief Name and service resolution class. * * This class provides support for doing name-to-binary resolution * for nodenames and service ports. You should use this class if you * need specific resolution techniques when creating a socket or if you * want to inspect the results before calling the socket functions. * * You can either create an object and set the options you want in it * or you can simply call the static member functions, which will create * standard Resolver objects and dispatch the resolution for you. Normally, * the static functions will be used, except in cases where specific options * must be set. * * A Resolver object defaults to the following: * @li address family: any address family * @li socket type: streaming socket * @li protocol: implementation-defined. Generally, TCP * @li host and service: unset * * @author Thiago Macieira <thiago.macieira@kdemail.net> */class KDECORE_EXPORT KResolver: public QObject{  Q_OBJECTpublic:  /**   * Address family selection types   *   * These values can be OR-ed together to form a composite family selection.   *   * @li UnknownFamily: a family that is unknown to the current implementation   * @li KnownFamily: a family that is known to the implementation (the exact   *		opposite of UnknownFamily)   * @li AnyFamilies: any address family is acceptable   * @li InternetFamily: an address for connecting to the Internet   * @li InetFamily: alias for InternetFamily   * @li IPv6Family: an IPv6 address only   * @li IPv4Family: an IPv4 address only   * @li UnixFamily: an address for the local Unix namespace (i.e., Unix sockets)   * @li LocalFamily: alias for UnixFamily   */  enum SocketFamilies  {    UnknownFamily = 0x0001,    UnixFamily = 0x0002,    LocalFamily = UnixFamily,    IPv4Family = 0x0004,    IPv6Family = 0x0008,    InternetFamily = IPv4Family | IPv6Family,    InetFamily = InternetFamily,    KnownFamily = ~UnknownFamily,    AnyFamily = KnownFamily | UnknownFamily  };  /**   * Flags for the resolution.   *   * These flags are used for setting the resolution behaviour for this   * object:   * @li Passive: resolve to a passive socket (i.e., one that can be used for   *		binding to a local interface)   * @li CanonName: request that the canonical name for the given nodename   *		be found and recorded   * @li NoResolve: request that no external resolution be performed. The given   *		nodename and servicename will be resolved locally only.   * @li NoSrv: don't try to use SRV-based name-resolution. (deprecated)   * @li UseSrv: use SRV-based name resolution.   * @li Multiport: the port/service argument is a list of port numbers and   *		ranges. (future extension)   *   * @note SRV-based lookup and Multiport are not implemented yet.   */  enum Flags    {      Passive = 0x01,      CanonName = 0x02,      NoResolve = 0x04,      NoSrv = 0x08,      Multiport = 0x10,      UseSrv = 0x20    };  /**   * Error codes   *   * These are the possible error values that objects of this class   * may return. See \ref errorString() for getting a string representation   * for these errors.   *   * @li AddrFamily: Address family for the given nodename is not supported.   * @li TryAgain: Temporary failure in name resolution. You should try again.   * @li NonRecoverable: Non-recoverable failure in name resolution.   * @li BadFlags: Invalid flags were given.   * @li Memory: Memory allocation failure.   * @li NoName: The specified name or service doesn't exist.   * @li UnsupportedFamily: The requested socket family is not supported.   * @li UnsupportedService: The requested service is not supported for this   *		socket type (i.e., a datagram service in a streaming socket).   * @li UnsupportedSocketType: The requested socket type is not supported.   * @li UnknownError: An unknown, unexpected error occurred.   * @li SystemError: A system error occurred. See @ref systemError.   * @li Canceled: This request was cancelled by the user.   */  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    };  /**   * Status codes.   *   * These are the possible status for a Resolver object. A value   * greater than zero indicates normal behaviour, while negative   * values either indicate failure or error.   *   * @li Idle: resolution has not yet been started.   * @li Queued: resolution is queued but not yet in progress.   * @li InProgress: resolution is in progress.   * @li PostProcessing: resolution is in progress.   * @li Success: resolution is done; you can retrieve the results.   * @li Canceled: request cancelled by the user.   * @li Failed: resolution is done, but failed.   *   * Note: the status Canceled and the error code Canceled are the same.   *   * Note 2: the status Queued and InProgress might not be distinguishable.   * Some implementations might not differentiate one from the other.   */  enum StatusCodes    {      Idle = 0,      Queued = 1,      InProgress = 5,      PostProcessing = 6,      Success = 10,      //Canceled = -100,	// already defined above      Failed = -101    };  /**   * Default constructor.   *   * Creates an empty Resolver object. You should set the wanted   * names and flags using the member functions before starting   * the name resolution.   */  KResolver(QObject * = 0L, const char * = 0L);  /**   * Constructor with host and service names.   *   * Creates a Resolver object with the given host and   * service names. Flags are initialised to 0 and any address family   * will be accepted.   *   * @param nodename	The host name we want resolved.   * @param servicename	The service name associated, like "http".   */  KResolver(const QString& nodename, const QString& servicename = QString::null,	    QObject * = 0L, const char * = 0L);  /**   * Destructor.   *   * When this object is deleted, it'll destroy all associated   * resources. If the resolution is still in progress, it will be   * cancelled and the signal will \b not be emitted.   */  virtual ~KResolver();  /**   * Retrieve the current status of this object.   *   * @see StatusCodes for the possible status codes.   */  int status() const;  /**   * Retrieve the error code in this object.   *   * This function will return NoError if we are not in   * an error condition. See @ref status and @ref StatusCodes to

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?