Ejemplo n.º 1
1
int QHostInfoProto::lookupId() const
{
    QHostInfo *item = qscriptvalue_cast<QHostInfo*>(thisObject());
    if (item)
        return item->lookupId();
    return 0;
}
Ejemplo n.º 2
0
  void ExitTunnel::UdpDnsLookupFinished(const QHostInfo &host_info)
  {
    UdpPendingDnsData value = _udp_pending_dns[host_info.lookupId()];
    _udp_pending_dns.remove(host_info.lookupId());

    bool okay = (host_info.error() == QHostInfo::NoError) && host_info.addresses().count();

    qDebug() << "SOCKS UDP hostname" << host_info.hostName() << "resolved:" << okay;
    if(okay && _table.ContainsConnection(value.socket)) {
      qDebug() << "SOCKS Write data" << value.datagram.count();
      value.socket->writeDatagram(value.datagram, host_info.addresses()[0], value.port);
    } else {
      CloseSocket(value.socket);
    }
  }
Ejemplo n.º 3
0
  void ExitTunnel::TcpDnsLookupFinished(const QHostInfo &host_info)
  {
    TcpPendingDnsData value = _tcp_pending_dns[host_info.lookupId()];
    _tcp_pending_dns.remove(host_info.lookupId());

    bool okay = (host_info.error() == QHostInfo::NoError) && host_info.addresses().count();

    qDebug() << "SOCKS hostname" << host_info.hostName() << "resolved:" << okay;
    if(okay && _table.ContainsConnection(value.socket)) {
      qDebug() << "SOCKS connecting to hostname" << host_info.hostName();
      value.socket->connectToHost(host_info.addresses()[0], value.port);
    } else {
      qDebug() << "SOCKS aborting failed or closed connection:" << host_info.hostName();
      //CloseSocket(value.socket);
    }
  }
Ejemplo n.º 4
0
static QScriptValue qhostinfo_fromName(QScriptContext *context, QScriptEngine *engine)
{
    QHostInfo obj;
    QScriptValue scriptlist = engine->newObject();

    if (context->argumentCount() == 1 && context->argument(0).isString()) {
        obj = QHostInfo::fromName(context->argument(0).toString());
        QScriptValue addressList = engine->newObject();
        QList<QHostAddress> qlist = obj.addresses();
        for (int i = 0; i < qlist.size(); i += 1) {
            addressList.setProperty(i, qlist[i].toString());
        }
        scriptlist.setProperty("addresses",   addressList);
        scriptlist.setProperty("error",       obj.error());
        if (obj.error() > 0) {
            scriptlist.setProperty("errorString", obj.errorString());
        }
        else {
            scriptlist.setProperty("errorString", "No Error");
        }
        scriptlist.setProperty("hostName",    obj.hostName());
        scriptlist.setProperty("lookupId",    obj.lookupId());
    }

    return scriptlist;
}
Ejemplo n.º 5
0
void HifiSockAddr::handleLookupResult(const QHostInfo& hostInfo) {
    if (hostInfo.error() != QHostInfo::NoError) {
        qCDebug(networking) << "Lookup failed for" << hostInfo.lookupId() << ":" << hostInfo.errorString();
        emit lookupFailed();
    }

    foreach(const QHostAddress& address, hostInfo.addresses()) {
        // just take the first IPv4 address
        if (address.protocol() == QAbstractSocket::IPv4Protocol) {
            _address = address;
            qCDebug(networking) << "QHostInfo lookup result for"
                << hostInfo.hostName() << "with lookup ID" << hostInfo.lookupId() << "is" << address.toString();
            emit lookupCompleted();
            break;
        }
    }
}
Ejemplo n.º 6
0
// ----------------------------------------------------------------------------
// getHostAddress (static)
// ----------------------------------------------------------------------------
QHostAddress NetworkTools::getHostAddress(const QHostInfo &in_host_info)
{
    if (in_host_info.lookupId() == -1) return QHostAddress();
    if (in_host_info.error() != QHostInfo::NoError) return QHostAddress();
    if (in_host_info.addresses().isEmpty()) return QHostAddress();

    return in_host_info.addresses().first();
}
Ejemplo n.º 7
0
void ScriptEngine::hostInfo_Ready(const QHostInfo &myInfo)
{
    QScriptValue myVal = myHostLookups.take(myInfo.lookupId());
    if(myVal.isString()) {
        QString info = myInfo.hostName();
        eval("var name = '"+info+"';"+myVal.toString());
    } else {
        if(myVal.isFunction()) {
            QScriptValueList arguments;
            arguments << QString(myInfo.hostName());
            myVal.call(QScriptValue(), arguments);
        }
    }
}
Ejemplo n.º 8
0
void ReverseResolution::hostResolved(const QHostInfo &host)
{
    const QString ip = m_lookups.take(host.lookupId());
    Q_ASSERT(!ip.isNull());

    if (host.error() != QHostInfo::NoError) {
        qDebug() << "DNS Reverse resolution error: " << host.errorString();
        return;
    }

    const QString hostname = host.hostName();

    qDebug() << Q_FUNC_INFO << ip << QString("->") << hostname;
    m_cache.insert(ip, new QString(hostname));
    if (isUsefulHostName(hostname, ip))
        emit ipResolved(ip, hostname);
}
//private slot
void Socks5UDPAssociateState::handleDomainLookupResult(const QHostInfo &info)
{
    if (info.lookupId() != _dnsLookupID)
        return;

    //See if there were any results
    if (info.addresses().isEmpty())
    {
        QSharedPointer<Socks5ReplyMessage> msg(new Socks5ReplyMessage(Socks5ReplyMessage::GeneralError,
                                                                      QHostAddress::Any,
                                                                      0));
        QString sendError;
        if (!_parent->sendMessage(msg,&sendError))
            qWarning() << this << "failed to inform client of failed DNS lookup. Error:" << sendError;
        _parent->close();
        return;
    }

    //Choose a result at random and send it to handleIP
    QHostAddress chosen = info.addresses()[qrand() % info.addresses().size()];
    _request->setAddress(chosen);
    this->handleIP();
}