コード例 #1
0
QDnsLookup::Type QDnsLookupProto::type() const
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    return item->type();
  return QDnsLookup::Type();
}
コード例 #2
0
QHostAddress QDnsLookupProto::nameserver() const
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    return item->nameserver();
  return QHostAddress();
}
コード例 #3
0
QList<QDnsDomainNameRecord> QDnsLookupProto::pointerRecords() const
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    return item->pointerRecords();
  return QList<QDnsDomainNameRecord>();
}
コード例 #4
0
bool QDnsLookupProto::isFinished() const
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    return item->isFinished();
  return false;
}
コード例 #5
0
QList<QDnsMailExchangeRecord> QDnsLookupProto::mailExchangeRecords() const
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    return item->mailExchangeRecords();
  return QList<QDnsMailExchangeRecord>();
}
コード例 #6
0
QList<QDnsHostAddressRecord> QDnsLookupProto::hostAddressRecords() const
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    return item->hostAddressRecords();
  return QList<QDnsHostAddressRecord>();
}
コード例 #7
0
QDnsLookup::Error QDnsLookupProto::error() const
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    return item->error();
  return QDnsLookup::Error();
}
コード例 #8
0
QString QDnsLookupProto::toString() const
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    return item->name();
  return QString();
}
コード例 #9
0
QList<QDnsTextRecord> QDnsLookupProto::textRecords() const
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    return item->textRecords();
  return QList<QDnsTextRecord>();
}
コード例 #10
0
ファイル: directconnection.cpp プロジェクト: Hamper/jreen
void DirectConnectionPrivate::lookupResultsReady()
{
	QDnsLookup *dns = qobject_cast<QDnsLookup*>(sender());
	dns->deleteLater();
	Q_ASSERT(dns);

	QList<QDnsServiceRecord> results = dns->serviceRecords();
	dns_records.clear();

	if (results.isEmpty()) {
		Record record;
		record.host = host_name;
		dns_records << record;
	} else {
		foreach (const QDnsServiceRecord &result, results) {
			Record record;
			record.host = result.target();
			// may be it's a reason of connection problems of some users
			if (record.host.endsWith(QLatin1Char('.')))
				record.host.chop(1);
			record.port = result.port();
			record.weight = result.weight();
			record.priority = result.priority();
			dns_records << record;
		}
	}
コード例 #11
0
ファイル: toxdns.cpp プロジェクト: bianle/qTox
QByteArray ToxDNS::fetchLastTextRecord(const QString& record, bool silent)
{
    QByteArray result;

    QDnsLookup dns;
    dns.setType(QDnsLookup::TXT);
    dns.setName(record);
    dns.lookup();

    int timeout;
    for (timeout = 0; timeout<30 && !dns.isFinished(); ++timeout)
    {
        qApp->processEvents();
        QThread::msleep(100);
    }
    if (timeout >= 30)
    {
        dns.abort();
        if (!silent)
            showWarning(tr("The connection timed out","The DNS gives the Tox ID associated to toxme.se addresses"));

        return result;
    }

    if (dns.error() == QDnsLookup::NotFoundError)
    {
        if (!silent)
            showWarning(tr("This address does not exist","The DNS gives the Tox ID associated to toxme.se addresses"));

        return result;
    }
    else if (dns.error() != QDnsLookup::NoError)
    {
        if (!silent)
            showWarning(tr("Error while looking up DNS","The DNS gives the Tox ID associated to toxme.se addresses"));

        return result;
    }

    const QList<QDnsTextRecord> textRecords = dns.textRecords();
    if (textRecords.isEmpty())
    {
        if (!silent)
            showWarning(tr("No text record found", "Error with the DNS"));

        return result;
    }

    const QList<QByteArray> textRecordValues = textRecords.last().values();
    if (textRecordValues.length() != 1)
    {
        if (!silent)
            showWarning(tr("Unexpected number of values in text record", "Error with the DNS"));

        return result;
    }

    result = textRecordValues.first();
    return result;
}
コード例 #12
0
ファイル: directconnection.cpp プロジェクト: Hamper/jreen
void DirectConnectionPrivate::doLookup()
{
	jreenDebug() << "doLookup";
	emit stateChanged(QAbstractSocket::HostLookupState);

	QDnsLookup *dns = new QDnsLookup(this);
	connect(dns, SIGNAL(finished()), this, SLOT(lookupResultsReady()));

	dns->setType(QDnsLookup::SRV);
	dns->setName(QString::fromLatin1("_xmpp-client._tcp." + QUrl::toAce(host_name)));
	dns->lookup();
}
コード例 #13
0
ファイル: EwsEngine.cpp プロジェクト: lemuri/litteras
void EwsEngine::checkDNSFinished()
{
    QDnsLookup *dns = qobject_cast<QDnsLookup*>(sender());
    qDebug() << Q_FUNC_INFO << dns << dns->name() << dns->error() << dns->errorString();
    if (dns->property("host").toString() == m_internalUri.host()) {
        if (dns->error()) {
            m_connection->setUri(m_externalUri);
            update();
        }
    } else {
        if (dns->error()) {
            m_connection->setUri(m_internalUri);
            update();
        }
    }
    dns->deleteLater();
}
コード例 #14
0
ファイル: EwsEngine.cpp プロジェクト: lemuri/litteras
void EwsEngine::checkDNS()
{
    qDebug() << Q_FUNC_INFO << m_internalUri.host() << m_externalUri.host();
    QDnsLookup *dns = new QDnsLookup(this);
    connect(dns, &QDnsLookup::finished,
            this, &EwsEngine::checkDNSFinished);

    dns->setProperty("host", m_internalUri.host());
    dns->setType(QDnsLookup::ANY);
    dns->setName(m_internalUri.host());
    dns->lookup();

    dns = new QDnsLookup(this);
    connect(dns, &QDnsLookup::finished,
            this, &EwsEngine::checkDNSFinished);

    dns->setProperty("host", m_externalUri.host());
    dns->setType(QDnsLookup::ANY);
    dns->setName(m_externalUri.host());
    dns->lookup();
}
コード例 #15
0
void QDnsLookupProto::setName(const QString &name)
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    item->setName(name);
}
コード例 #16
0
void QDnsLookupProto::lookup()
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    item->lookup();
}
コード例 #17
0
void tst_QDnsLookup::lookupAbortRetry()
{
    QDnsLookup lookup;

    // try and abort the lookup
    lookup.setType(QDnsLookup::A);
    lookup.setName(domainName("a-single"));
    lookup.lookup();
    lookup.abort();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QCOMPARE(int(lookup.error()), int(QDnsLookup::OperationCancelledError));
    QVERIFY(lookup.hostAddressRecords().isEmpty());

    // retry a different lookup
    lookup.setType(QDnsLookup::AAAA);
    lookup.setName(domainName("aaaa-single"));
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QCOMPARE(int(lookup.error()), int(QDnsLookup::NoError));
    QVERIFY(!lookup.hostAddressRecords().isEmpty());
    QCOMPARE(lookup.hostAddressRecords().first().name(), domainName("aaaa-single"));
    QCOMPARE(lookup.hostAddressRecords().first().value(), QHostAddress("2001:db8::1"));
}
コード例 #18
0
void tst_QDnsLookup::lookup()
{
    QFETCH(int, type);
    QFETCH(QString, domain);
    QFETCH(int, error);
    QFETCH(QString, cname);
    QFETCH(QString, host);
    QFETCH(QString, mx);
    QFETCH(QString, ns);
    QFETCH(QString, ptr);
    QFETCH(QString, srv);
    QFETCH(QString, txt);

    // transform the inputs
    domain = domainName(domain);
    cname = domainName(cname);
    ns = domainNameList(ns);
    ptr = domainNameList(ptr);

    // SRV and MX have reply entries that can change order
    // and we can't sort
    QStringList mx_alternatives = domainNameListAlternatives(mx);
    QStringList srv_alternatives = domainNameListAlternatives(srv);

    QDnsLookup lookup;
    lookup.setType(static_cast<QDnsLookup::Type>(type));
    lookup.setName(domain);
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());

#if defined(Q_OS_ANDROID)
    if (lookup.errorString() == QStringLiteral("Not yet supported on Android"))
        QEXPECT_FAIL("", "Not yet supported on Android", Abort);
#endif

    QVERIFY2(int(lookup.error()) == error,
             msgDnsLookup(lookup.error(), error, domain, cname, host, srv, mx, ns, ptr, lookup.errorString()));
    if (error == QDnsLookup::NoError)
        QVERIFY(lookup.errorString().isEmpty());
    QCOMPARE(int(lookup.type()), type);
    QCOMPARE(lookup.name(), domain);

    // canonical names
    if (!cname.isEmpty()) {
        QVERIFY(!lookup.canonicalNameRecords().isEmpty());
        const QDnsDomainNameRecord cnameRecord = lookup.canonicalNameRecords().first();
        QCOMPARE(cnameRecord.name(), domain);
        QCOMPARE(cnameRecord.value(), cname);
    } else {
        QVERIFY(lookup.canonicalNameRecords().isEmpty());
    }

    // host addresses
    const QString hostName = cname.isEmpty() ? domain : cname;
    QStringList addresses;
    foreach (const QDnsHostAddressRecord &record, lookup.hostAddressRecords()) {
        //reply may include A & AAAA records for nameservers, ignore them and only look at records matching the query
        if (record.name() == hostName)
            addresses << record.value().toString().toLower();
    }
    addresses.sort();
    QCOMPARE(addresses.join(';'), host);

    // mail exchanges
    QStringList mailExchanges;
    foreach (const QDnsMailExchangeRecord &record, lookup.mailExchangeRecords()) {
        QCOMPARE(record.name(), domain);
        mailExchanges << QString("%1 %2").arg(QString::number(record.preference()), record.exchange());
    }
    QVERIFY2(mx_alternatives.contains(mailExchanges.join(';')),
             qPrintable("Actual: " + mailExchanges.join(';') + "\nExpected one of:\n" + mx_alternatives.join('\n')));

    // name servers
    QStringList nameServers;
    foreach (const QDnsDomainNameRecord &record, lookup.nameServerRecords()) {
        //reply may include NS records for authoritative nameservers, ignore them and only look at records matching the query
        if (record.name() == domain)
            nameServers << record.value();
    }
    nameServers.sort();
    QCOMPARE(nameServers.join(';'), ns);

    // pointers
    if (!ptr.isEmpty()) {
        QVERIFY(!lookup.pointerRecords().isEmpty());
        const QDnsDomainNameRecord ptrRecord = lookup.pointerRecords().first();
        QCOMPARE(ptrRecord.name(), domain);
        QCOMPARE(ptrRecord.value(), ptr);
    } else {
        QVERIFY(lookup.pointerRecords().isEmpty());
    }

    // services
    QStringList services;
    foreach (const QDnsServiceRecord &record, lookup.serviceRecords()) {
        QCOMPARE(record.name(), domain);
        services << QString("%1 %2 %3 %4").arg(
                QString::number(record.priority()),
                QString::number(record.weight()),
                QString::number(record.port()),
                record.target());
    }
    QVERIFY2(srv_alternatives.contains(services.join(';')),
             qPrintable("Actual: " + services.join(';') + "\nExpected one of:\n" + srv_alternatives.join('\n')));

    // text
    QStringList texts;
    foreach (const QDnsTextRecord &record, lookup.textRecords()) {
        QCOMPARE(record.name(), domain);
        QString text;
        foreach (const QByteArray &ba, record.values()) {
            if (!text.isEmpty())
                text += '\0';
            text += QString::fromLatin1(ba);
        }
        texts << text;
    }
    texts.sort();
    QCOMPARE(texts.join(';'), txt);
}
コード例 #19
0
void tst_QDnsLookup::lookupReuse()
{
    QDnsLookup lookup;

    // first lookup
    lookup.setType(QDnsLookup::A);
    lookup.setName(domainName("a-single"));
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QCOMPARE(int(lookup.error()), int(QDnsLookup::NoError));
    QVERIFY(!lookup.hostAddressRecords().isEmpty());
    QCOMPARE(lookup.hostAddressRecords().first().name(), domainName("a-single"));
    QCOMPARE(lookup.hostAddressRecords().first().value(), QHostAddress("192.0.2.1"));

    // second lookup
    lookup.setType(QDnsLookup::AAAA);
    lookup.setName(domainName("aaaa-single"));
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QCOMPARE(int(lookup.error()), int(QDnsLookup::NoError));
    QVERIFY(!lookup.hostAddressRecords().isEmpty());
    QCOMPARE(lookup.hostAddressRecords().first().name(), domainName("aaaa-single"));
    QCOMPARE(lookup.hostAddressRecords().first().value(), QHostAddress("2001:db8::1"));
}
コード例 #20
0
void QDnsLookupProto::setNameserver(const QHostAddress &nameserver)
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    item->setNameserver(nameserver);
}
コード例 #21
0
void QDnsLookupProto::setType(QDnsLookup::Type type)
{
  QDnsLookup *item = qscriptvalue_cast<QDnsLookup*>(thisObject());
  if (item)
    item->setType(type);
}
コード例 #22
0
void tst_QDnsLookup::lookupAbortRetry()
{
    QDnsLookup lookup;

    // try and abort the lookup
    lookup.setType(QDnsLookup::A);
    lookup.setName(domainName("a-single"));
    lookup.lookup();
    lookup.abort();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QCOMPARE(int(lookup.error()), int(QDnsLookup::OperationCancelledError));
    QVERIFY(lookup.hostAddressRecords().isEmpty());

    // retry a different lookup
    lookup.setType(QDnsLookup::AAAA);
    lookup.setName(domainName("aaaa-single"));
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());

#if defined(Q_OS_ANDROID)
    if (lookup.errorString() == QStringLiteral("Not yet supported on Android"))
        QEXPECT_FAIL("", "Not yet supported on Android", Abort);
#endif

    QCOMPARE(int(lookup.error()), int(QDnsLookup::NoError));
    QVERIFY(!lookup.hostAddressRecords().isEmpty());
    QCOMPARE(lookup.hostAddressRecords().first().name(), domainName("aaaa-single"));
    QCOMPARE(lookup.hostAddressRecords().first().value(), QHostAddress("2001:db8::1"));
}
コード例 #23
0
void tst_QDnsLookup::lookup()
{
    QFETCH(int, type);
    QFETCH(QString, domain);
    QFETCH(int, error);
    QFETCH(QString, cname);
    QFETCH(QString, host);
    QFETCH(QString, mx);
    QFETCH(QString, ns);
    QFETCH(QString, ptr);
    QFETCH(QString, srv);
    QFETCH(QByteArray, txt);

    // transform the inputs
    domain = domainName(domain);
    cname = domainName(cname);
    mx = domainNameList(mx);
    ns = domainNameList(ns);
    ptr = domainNameList(ptr);
    srv = domainNameList(srv);

    QDnsLookup lookup;
    lookup.setType(static_cast<QDnsLookup::Type>(type));
    lookup.setName(domain);
    lookup.lookup();
    QVERIFY(waitForDone(&lookup));
    QVERIFY(lookup.isFinished());
    QVERIFY2(int(lookup.error()) == error, qPrintable(lookup.errorString()));
    if (error == QDnsLookup::NoError)
        QVERIFY(lookup.errorString().isEmpty());
    QCOMPARE(int(lookup.type()), type);
    QCOMPARE(lookup.name(), domain);

    // canonical names
    if (!cname.isEmpty()) {
        QVERIFY(!lookup.canonicalNameRecords().isEmpty());
        const QDnsDomainNameRecord cnameRecord = lookup.canonicalNameRecords().first();
        QCOMPARE(cnameRecord.name(), domain);
        QCOMPARE(cnameRecord.value(), cname);
    } else {
        QVERIFY(lookup.canonicalNameRecords().isEmpty());
    }

    // host addresses
    const QString hostName = cname.isEmpty() ? domain : cname;
    QStringList addresses;
    foreach (const QDnsHostAddressRecord &record, lookup.hostAddressRecords()) {
        //reply may include A & AAAA records for nameservers, ignore them and only look at records matching the query
        if (record.name() == hostName)
            addresses << record.value().toString().toLower();
    }
    addresses.sort();
    QCOMPARE(addresses.join(';'), host);

    // mail exchanges
    QStringList mailExchanges;
    foreach (const QDnsMailExchangeRecord &record, lookup.mailExchangeRecords()) {
        QCOMPARE(record.name(), domain);
        mailExchanges << QString("%1 %2").arg(QString::number(record.preference()), record.exchange());
    }
    QCOMPARE(mailExchanges.join(';'), mx);

    // name servers
    QStringList nameServers;
    foreach (const QDnsDomainNameRecord &record, lookup.nameServerRecords()) {
        //reply may include NS records for authoritative nameservers, ignore them and only look at records matching the query
        if (record.name() == domain)
            nameServers << record.value();
    }
    nameServers.sort();
    QCOMPARE(nameServers.join(';'), ns);

    // pointers
    if (!ptr.isEmpty()) {
        QVERIFY(!lookup.pointerRecords().isEmpty());
        const QDnsDomainNameRecord ptrRecord = lookup.pointerRecords().first();
        QCOMPARE(ptrRecord.name(), domain);
        QCOMPARE(ptrRecord.value(), ptr);
    } else {
        QVERIFY(lookup.pointerRecords().isEmpty());
    }

    // services
    QStringList services;
    foreach (const QDnsServiceRecord &record, lookup.serviceRecords()) {
        QCOMPARE(record.name(), domain);
        services << QString("%1 %2 %3 %4").arg(
                QString::number(record.priority()),
                QString::number(record.weight()),
                QString::number(record.port()),
                record.target());
    }
    QCOMPARE(services.join(';'), srv);

    // text
    if (!txt.isEmpty()) {
        QVERIFY(!lookup.textRecords().isEmpty());
        const QDnsTextRecord firstRecord = lookup.textRecords().first();
        QCOMPARE(firstRecord.name(), domain);
        QCOMPARE(firstRecord.values().size(), 1);
        QCOMPARE(firstRecord.values().first(), txt);
    } else {
        QVERIFY(lookup.textRecords().isEmpty());
    }
}