Esempio n. 1
0
DNSUpdater::DNSUpdater(QObject *parent) :
  QObject(parent), m_state(OK), m_service(DNS::NONE)
{
  updateCredentials();

  // Load saved settings from previous session
  const Preferences* const pref = Preferences::instance();
  m_lastIPCheckTime = pref->getDNSLastUpd();
  m_lastIP = QHostAddress(pref->getDNSLastIP());

  // Start IP checking timer
  m_ipCheckTimer.setInterval(IP_CHECK_INTERVAL_MS);
  connect(&m_ipCheckTimer, SIGNAL(timeout()), SLOT(checkPublicIP()));
  m_ipCheckTimer.start();

  // Check lastUpdate to avoid flooding
  if (!m_lastIPCheckTime.isValid() ||
      m_lastIPCheckTime.secsTo(QDateTime::currentDateTime())*1000 > IP_CHECK_INTERVAL_MS) {
    checkPublicIP();
  }
}
Esempio n. 2
0
DNSUpdater::DNSUpdater(QObject *parent) :
  QObject(parent), m_state(OK), m_service(DNS::NONE)
{
  updateCredentials();

  // Load saved settings from previous session
  QIniSettings settings;
  m_lastIPCheckTime = settings.value("DNSUpdater/lastUpdateTime").toDateTime();
  m_lastIP = QHostAddress(settings.value("DNSUpdater/lastIP").toString());

  // Start IP checking timer
  m_ipCheckTimer.setInterval(IP_CHECK_INTERVAL_MS);
  connect(&m_ipCheckTimer, SIGNAL(timeout()), SLOT(checkPublicIP()));
  m_ipCheckTimer.start();

  // Check lastUpdate to avoid flooding
  if (!m_lastIPCheckTime.isValid() ||
      m_lastIPCheckTime.secsTo(QDateTime::currentDateTime())*1000 > IP_CHECK_INTERVAL_MS) {
    checkPublicIP();
  }
}
Esempio n. 3
0
void QAuthenticatorPrivate::parseHttpResponse(const QList<QPair<QByteArray, QByteArray> > &values, bool isProxy)
{
    const char *search = isProxy ? "proxy-authenticate" : "www-authenticate";

    method = None;
    /*
      Fun from the HTTP 1.1 specs, that we currently ignore:

      User agents are advised to take special care in parsing the WWW-
      Authenticate field value as it might contain more than one challenge,
      or if more than one WWW-Authenticate header field is provided, the
      contents of a challenge itself can contain a comma-separated list of
      authentication parameters.
    */

    QByteArray headerVal;
    for (int i = 0; i < values.size(); ++i) {
        const QPair<QByteArray, QByteArray> &current = values.at(i);
        if (current.first.toLower() != search)
            continue;
        QByteArray str = current.second.toLower();
        if (method < Basic && str.startsWith("basic")) {
            method = Basic;
            headerVal = current.second.mid(6);
        } else if (method < Ntlm && str.startsWith("ntlm")) {
            method = Ntlm;
            headerVal = current.second.mid(5);
        } else if (method < DigestMd5 && str.startsWith("digest")) {
            method = DigestMd5;
            headerVal = current.second.mid(7);
        }
    }

    // Reparse credentials since we know the method now
    updateCredentials();
    challenge = headerVal.trimmed();
    QHash<QByteArray, QByteArray> options = parseDigestAuthenticationChallenge(challenge);

    switch(method) {
    case Basic:
        this->options[QLatin1String("realm")] = realm = QString::fromLatin1(options.value("realm"));
        if (user.isEmpty() && password.isEmpty())
            phase = Done;
        break;
    case Ntlm:
        // #### extract from header
        if (user.isEmpty() && password.isEmpty())
            phase = Done;
        break;
    case DigestMd5: {
        this->options[QLatin1String("realm")] = realm = QString::fromLatin1(options.value("realm"));
        if (options.value("stale").toLower() == "true")
            phase = Start;
        if (user.isEmpty() && password.isEmpty())
            phase = Done;
        break;
    }
    default:
        realm.clear();
        challenge = QByteArray();
        phase = Invalid;
    }
}