예제 #1
0
QDebug operator<<(QDebug s, const QNetworkCookie &cookie)
{
    QDebugStateSaver saver(s);
    s.resetFormat().nospace();
    s << "QNetworkCookie(" << cookie.toRawForm(QNetworkCookie::Full) << ')';
    return s;
}
예제 #2
0
void NResponse::setSessionCookie(const QString & sessionId, bool secured)
{
    QNetworkCookie sessionCookie;
    sessionCookie.setHttpOnly (true);
    sessionCookie.setName ("nawis_sessionId");
    sessionCookie.setPath ("/");
    sessionCookie.setSecure(secured);
    sessionCookie.setValue(sessionId.toAscii());

    m_httpHeader.setValue("Set-Cookie", sessionCookie.toRawForm(QNetworkCookie::Full));
}
예제 #3
0
bool CookieStore::insertCookie(const QNetworkCookie& cookie, const QUrl& firstUrl)
{
    sqlite3_stmt* stmt;
    int rc;
    
    QByteArray domain = cookie.domain().toLatin1();
    QByteArray path = cookie.path().toLatin1();
    QByteArray name = cookie.name();
    QByteArray fdomain = firstUrl.host().toLower().toLatin1();
    QByteArray expiration;
    if (cookie.isSessionCookie()) {
        expiration = "0";
    } else {
        expiration = cookie.expirationDate().toString().toLatin1();
    }
    QByteArray content = cookie.toRawForm();

    rc = sqlite3_prepare(m_db,
                         "insert into thirdPartyCookies (domain, path, name, fdomain, expiration, content) values (?, ?, ?, ?, ?, ?)",
                         -1, &stmt, 0);
    if (rc != SQLITE_OK) {
        qDebug() << "insertCookie prepare fail:" << rc;
        return false;
    }

    QByteArray text[6] = {domain, path, name, fdomain, expiration, content};
    
    for (int i = 0; i < 6; ++i) {
        rc = sqlite3_bind_text(stmt, i + 1, text[i].constData(), text[i].size(), SQLITE_TRANSIENT);
        if (rc != SQLITE_OK) {
            qDebug() << "insertCookie bind fail:" << i;
            sqlite3_finalize(stmt);
            return false;
        }
    }

    rc = sqlite3_step(stmt);
    if (rc != SQLITE_DONE) {
        qDebug() << "insertCookie step (execute) fail";
        sqlite3_finalize(stmt);
        return false;
    }

    sqlite3_finalize(stmt);
    return true;
}
예제 #4
0
QScriptValue MyWebView::cookiesFormUrl(QScriptValue url)
{
    QUrl targetUrl;
    if (url.isUndefined()) {
        targetUrl = this->url();
    } else if (url.toString().toLower().trimmed().indexOf("http://") == 0) {
        targetUrl = QUrl(url.toString().toLower().trimmed());
    } else {
        targetUrl = this->url();
    }

    QByteArray str;

    QNetworkCookie cookie;
    QList<QNetworkCookie> list = cookieJar->cookiesForUrl(targetUrl);
    foreach (cookie, list)
    {
        str += cookie.toRawForm() + "\n";
    }
예제 #5
0
QVariant NicoLiveManager::makePostData(QString session_id)
{
    QVariant postData;

    // make cookies
    QList <QNetworkCookie> cookies;
    QNetworkCookie ck;
    ck.toRawForm(QNetworkCookie::NameAndValueOnly);
    ck.setName("user_session");

    QByteArray user_id_ba;
    user_id_ba.append(session_id);

    ck.setValue(user_id_ba);
    cookies.append(ck);

    postData.setValue(cookies);
    return postData;
}
예제 #6
0
QDebug operator<<(QDebug s, const QNetworkCookie &cookie)
{
    s.nospace() << "QNetworkCookie(" << cookie.toRawForm(QNetworkCookie::Full) << ')';
    return s.space();
}
void SourcesSettingsWindow::save()
{
	m_site->setSetting("name", ui->lineSiteName->text(), m_site->url());
	QStringList referers = QStringList() << "none" << "host" << "page" << "image";
	QStringList referers_preview = QStringList() << "" << "none" << "host" << "page" << "image";
	QStringList referers_image = QStringList() << "" << "none" << "host" << "page" << "details" << "image";
	m_site->setSetting("referer", referers[ui->comboReferer->currentIndex()], "none");
	m_site->setSetting("referer_preview", referers_preview[ui->comboRefererPreview->currentIndex()], "");
	m_site->setSetting("referer_image", referers_image[ui->comboRefererImage->currentIndex()], "");
	m_site->setSetting("ignore/always", ui->spinIgnoreAlways->value(), 0);
	m_site->setSetting("ignore/1", ui->spinIgnore1->value(), 0);
	m_site->setSetting("ssl", ui->checkSsl->isChecked(), false);

	m_site->setSetting("download/imagesperpage", ui->spinImagesPerPage->value(), 200);
	m_site->setSetting("download/simultaneous", ui->spinSimultaneousDownloads->value(), 10);
	m_site->setSetting("download/throttle_details", ui->spinThrottleDetails->value(), 0);
	m_site->setSetting("download/throttle_image", ui->spinThrottleImage->value(), 0);
	m_site->setSetting("download/throttle_page", ui->spinThrottlePage->value(), 0);
	m_site->setSetting("download/throttle_retry", ui->spinThrottleRetry->value(), 0);
	m_site->setSetting("download/throttle_thumbnail", ui->spinThrottleThumbnail->value(), 0);

	QStringList sources = QStringList() << "" << "xml" << "json" << "regex" << "rss";
	m_site->setSetting("sources/usedefault", ui->checkSourcesDefault->isChecked(), true);
	m_site->setSetting("sources/source_1", sources[qMax(0, ui->comboSources1->currentIndex())], m_globalSettings->value("source_1", sources[0]).toString());
	m_site->setSetting("sources/source_2", sources[qMax(0, ui->comboSources2->currentIndex())], m_globalSettings->value("source_2", sources[1]).toString());
	m_site->setSetting("sources/source_3", sources[qMax(0, ui->comboSources3->currentIndex())], m_globalSettings->value("source_3", sources[2]).toString());
	m_site->setSetting("sources/source_4", sources[qMax(0, ui->comboSources4->currentIndex())], m_globalSettings->value("source_4", sources[3]).toString());


	m_site->setSetting("auth/pseudo", ui->lineAuthPseudo->text(), "");
	m_site->setSetting("auth/password", ui->lineAuthPassword->text(), "");

	// Login
	QStringList types = QStringList() << "url" << "get" << "post" << "oauth1" << "oauth2";
	m_site->setSetting("login/type", types[ui->comboLoginType->currentIndex()], "url");
	m_site->setSetting("login/get/url", ui->lineLoginGetUrl->text(), "");
	m_site->setSetting("login/get/pseudo", ui->lineLoginGetPseudo->text(), "");
	m_site->setSetting("login/get/password", ui->lineLoginGetPassword->text(), "");
	m_site->setSetting("login/get/cookie", ui->lineLoginGetCookie->text(), "");
	m_site->setSetting("login/post/url", ui->lineLoginPostUrl->text(), "");
	m_site->setSetting("login/post/pseudo", ui->lineLoginPostPseudo->text(), "");
	m_site->setSetting("login/post/password", ui->lineLoginPostPassword->text(), "");
	m_site->setSetting("login/post/cookie", ui->lineLoginPostCookie->text(), "");
	m_site->setSetting("login/oauth1/requestTokenUrl", ui->lineLoginOAuth1RequestTokenUrl->text(), "");
	m_site->setSetting("login/oauth1/authorizeUrl", ui->lineLoginOAuth1AuthorizeUrl->text(), "");
	m_site->setSetting("login/oauth1/accessTokenUrl", ui->lineLoginOAuth1AccessTokenUrl->text(), "");
	m_site->setSetting("login/oauth2/requestUrl", ui->lineLoginOAuth2RequestUrl->text(), "");
	m_site->setSetting("login/oauth2/tokenUrl", ui->lineLoginOAuth2TokenUrl->text(), "");
	m_site->setSetting("login/oauth2/refreshTokenUrl", ui->lineLoginOAuth2RefreshTokenUrl->text(), "");
	m_site->setSetting("login/oauth2/scope", ui->lineLoginOAuth2Scope->text(), "");
	m_site->setSetting("login/maxPage", ui->spinLoginMaxPage->value(), 0);

	// Cookies
	QList<QVariant> cookies;
	for (int i = 0; i < ui->tableCookies->rowCount(); ++i)
	{
		if (ui->tableCookies->item(i, 0)->text().isEmpty())
			continue;

		QNetworkCookie cookie;
		cookie.setName(ui->tableCookies->item(i, 0)->text().toLatin1());
		cookie.setValue(ui->tableCookies->item(i, 1)->text().toLatin1());
		cookies.append(cookie.toRawForm());
	}
	m_site->setSetting("cookies", cookies, QList<QVariant>());

	// Headers
	QMap<QString, QVariant> headers;
	for (int i = 0; i < ui->tableHeaders->rowCount(); ++i)
	{
		if (ui->tableHeaders->item(i, 0)->text().isEmpty())
			continue;

		headers.insert(ui->tableHeaders->item(i, 0)->text(), ui->tableHeaders->item(i, 1)->text());
	}
	m_site->setSetting("headers", headers, QMap<QString, QVariant>());

	m_site->syncSettings();

	m_site->loadConfig();
}