2
* Copyright (C) 2010 Barracuda Networks, Inc.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
#include "addressresolver.h"
22
#include "objectsession.h"
27
class AddressResolver::Private : public QObject
45
QList<QHostAddress> addrs6;
46
QList<QHostAddress> addrs4;
49
Private(AddressResolver *_q) :
56
connect(&req6, SIGNAL(resultsReady(const QList<XMPP::NameRecord> &)), SLOT(req6_resultsReady(const QList<XMPP::NameRecord> &)));
57
connect(&req6, SIGNAL(error(XMPP::NameResolver::Error)), SLOT(req6_error(XMPP::NameResolver::Error)));
59
connect(&req4, SIGNAL(resultsReady(const QList<XMPP::NameRecord> &)), SLOT(req4_resultsReady(const QList<XMPP::NameRecord> &)));
60
connect(&req4, SIGNAL(error(XMPP::NameResolver::Error)), SLOT(req4_error(XMPP::NameResolver::Error)));
62
opTimer = new QTimer(this);
63
connect(opTimer, SIGNAL(timeout()), SLOT(op_timeout()));
64
opTimer->setSingleShot(true);
69
opTimer->disconnect(this);
70
opTimer->setParent(0);
71
opTimer->deleteLater();
74
void start(const QByteArray &hostName)
78
// was an IP address used as input?
80
if(addr.setAddress(QString::fromLatin1(hostName)))
82
// use this as the result, no need to perform dns query
85
if(addr.protocol() == QAbstractSocket::IPv6Protocol)
90
sess.defer(this, "ipAddress_input");
97
// wait at least 5 seconds for one of AAAA or A, to be
98
// consistent with netnames_jdns' dns-sd resolves
101
req6.start(hostName, NameRecord::Aaaa);
102
req4.start(hostName, NameRecord::A);
125
if((done6 && done4) || (state == AddressFirstCome && (done6 || done4)))
127
QList<QHostAddress> results = addrs6 + addrs4;
130
if(!results.isEmpty())
131
emit q->resultsReady(results);
133
emit q->error(ErrorGeneric);
142
void req6_resultsReady(const QList<XMPP::NameRecord> &results)
144
foreach(const NameRecord &rec, results)
145
addrs6 += rec.address();
151
void req6_error(XMPP::NameResolver::Error e)
159
void req4_resultsReady(const QList<XMPP::NameRecord> &results)
161
foreach(const NameRecord &rec, results)
162
addrs4 += rec.address();
168
void req4_error(XMPP::NameResolver::Error e)
178
state = AddressFirstCome;
184
void ipAddress_input()
190
AddressResolver::AddressResolver(QObject *parent) :
193
d = new Private(this);
196
AddressResolver::~AddressResolver()
201
void AddressResolver::start(const QByteArray &hostName)
206
void AddressResolver::stop()
213
#include "addressresolver.moc"