File indexing completed on 2025-01-05 04:37:19

0001 /*
0002     SPDX-FileCopyrightText: 2011 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef NET_ADDRESSRESOLVER_H
0008 #define NET_ADDRESSRESOLVER_H
0009 
0010 #include <QHostInfo>
0011 #include <ktorrent_export.h>
0012 #include <net/address.h>
0013 
0014 namespace net
0015 {
0016 /**
0017  * Resolves hostnames into net::Address objects.
0018  * This class will clean itself up, after it is done using deleteLater.
0019  **/
0020 class KTORRENT_EXPORT AddressResolver : public QObject
0021 {
0022     Q_OBJECT
0023 public:
0024     /**
0025      * Constructor, initializer the lookup.
0026      * @param host Hostname
0027      * @param port Port number
0028      * @param parent Parent
0029      * @param slot Slot of parent to connect to
0030      **/
0031     AddressResolver(const QString &host, bt::Uint16 port, QObject *parent, const char *slot);
0032     ~AddressResolver() override;
0033 
0034     /// Did the resolver succeed ?
0035     bool succeeded() const
0036     {
0037         return succesfull;
0038     }
0039 
0040     /// Get the resulting address
0041     const net::Address &address() const
0042     {
0043         return result;
0044     }
0045 
0046     /**
0047      * Convenience method to resolve a hostname.
0048      * @param host Hostname
0049      * @param port Port number
0050      * @param parent Parent
0051      * @param slot Slot of parent to connect to
0052      * @return void
0053      **/
0054     static void resolve(const QString &host, bt::Uint16 port, QObject *parent, const char *slot);
0055 
0056     /**
0057      * Synchronous resolve
0058      * @param host Hostname
0059      * @param port Port number
0060      * @return :Address
0061      **/
0062     static net::Address resolve(const QString &host, bt::Uint16 port);
0063 
0064 Q_SIGNALS:
0065     /**
0066      * Emitted when hostname lookup succeeded
0067      * @param ar This AddressResolver
0068      **/
0069     void resolved(net::AddressResolver *ar);
0070 
0071 private Q_SLOTS:
0072     void hostResolved(const QHostInfo &res);
0073 
0074 private:
0075     int lookup_id;
0076     net::Address result;
0077     bool succesfull;
0078     bool ongoing;
0079 };
0080 
0081 }
0082 
0083 #endif // NET_ADDRESSRESOLVER_H