String cookies(const Document* document, const KURL& url)
{
    NetworkingContext* context = networkingContext(document);
    if (!context)
        return String();
    QNetworkCookieJar* jar = context->networkAccessManager()->cookieJar();

    QUrl urlForCookies(url);
    QUrl firstPartyUrl(document->firstPartyForCookies());
    if (!thirdPartyCookiePolicyPermits(context, urlForCookies, firstPartyUrl))
        return String();

    QList<QNetworkCookie> cookies = jar->cookiesForUrl(urlForCookies);
    if (cookies.isEmpty())
        return String();

    QStringList resultCookies;
    foreach (const QNetworkCookie& networkCookie, cookies) {
        if (networkCookie.isHttpOnly())
            continue;
        resultCookies.append(QString::fromLatin1(networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
    }

    return resultCookies.join(QLatin1String("; "));
}
String cookies(const Document* document, const KURL& url)
{
    QUrl u(url);
#if QT_VERSION >= 0x040400
    QNetworkCookieJar* jar = cookieJar(document);
    if (!jar)
        return String();

    QList<QNetworkCookie> cookies = jar->cookiesForUrl(u);
    if (cookies.isEmpty())
        return String();

    QStringList resultCookies;
    foreach (QNetworkCookie networkCookie, cookies) {
#if QT_VERSION >= 0x040500
        if (networkCookie.isHttpOnly())
            continue;
#endif
        resultCookies.append(QString::fromAscii(
                             networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
    }

    return resultCookies.join(QLatin1String("; "));
#else
    QString cookies = QCookieJar::cookieJar()->cookies(u);
    int idx = cookies.indexOf(QLatin1Char(';'));
    if (idx > 0)
        cookies = cookies.left(idx);
    return cookies;
#endif
}
NetworkAccessManager::NetworkAccessManager(QObject *parent) :
    QNetworkAccessManager(parent)
{
    QNetworkCookieJar* cookieJar = NetworkCookieJar::GetInstance();
    setCookieJar(cookieJar);
    cookieJar->setParent(0);
}
Beispiel #4
0
void Account::setCredentials(AbstractCredentials *cred)
{
    // set active credential manager
    QNetworkCookieJar *jar = 0;
    if (_am) {
        jar = _am->cookieJar();
        jar->setParent(0);

        _am->deleteLater();
    }

    if (_credentials) {
        credentials()->deleteLater();
    }

    // The order for these two is important! Reading the credential's
    // settings accesses the account as well as account->_credentials
    _credentials = cred;
    cred->setAccount(this);

    _am = _credentials->getQNAM();
    if (jar) {
        _am->setCookieJar(jar);
    }
    connect(_am, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
            SLOT(slotHandleErrors(QNetworkReply*,QList<QSslError>)));
    connect(_credentials, SIGNAL(fetched()),
            SLOT(slotCredentialsFetched()));
}
Beispiel #5
0
void MainWindow::finished_loading(bool ok)
{
	if(!ok)
std::cout << "LOAD FINISH NOT OK!\n\n";
	QString output;
	QWebElement body;
	progress = 100;
	adjust_title();
	QWebFrame *frame = uimw->webView->page()->mainFrame();
	QWebElement document = frame->documentElement();
	QWebElement element = document.firstChild();
	while(!element.isNull())
	{
		if(element.tagName() == "BODY")
		{
			output = element.toInnerXml();
			if(output == "ok\n")
			{
				QNetworkCookieJar *cj = uimw->webView->page()->networkAccessManager()->cookieJar();
				QList<QNetworkCookie> cookies = cj->cookiesForUrl(testauth);
				for(QList<QNetworkCookie>::const_iterator i = cookies.begin() ; i != cookies.end() ; i++ )
				{
					std::cout << "Set-Cookie: ";
					QByteArray ba = i->toRawForm();
					std::cout.write(ba.data(), ba.count());
					std::cout << "\r\n";
				}
				exit(0);
			}
		}
		element = element.nextSibling();
	}
	this->show();
}
QNetworkAccessManager* TBNetworkAccessManagerFactory::create(QObject *parent)
{
    QMutexLocker lock(&mutex);
    Q_UNUSED(lock);
    QNetworkAccessManager* manager = new TBNetworkAccessManager(parent);

#ifdef Q_OS_SYMBIAN
    bool useDiskCache = Utility::Instance()->qtVersion() >= 0x040800;
#else
    bool useDiskCache = true;
#endif
    if (useDiskCache){
        QNetworkDiskCache* diskCache = new QNetworkDiskCache(parent);
        QString dataPath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
        QDir dir(dataPath);
        if (!dir.exists()) dir.mkpath(dir.absolutePath());

        diskCache->setCacheDirectory(dataPath);
        diskCache->setMaximumCacheSize(3*1024*1024);
        manager->setCache(diskCache);
    }

    QNetworkCookieJar* cookieJar = TBNetworkCookieJar::GetInstance();
    manager->setCookieJar(cookieJar);
    cookieJar->setParent(0);

    return manager;
}
Beispiel #7
0
	void YafOAuth::handleUnsupportedContent(QNetworkReply *reply)
	{
		if (reply->error() == QNetworkReply::NoError) {
			return;
		}

		QString url = reply->url().toString();
		if(url.contains("webmounter://token#access_token="))
		{
            m_token = Data::RegExp::getByPattern("webmounter://token#access_token=(.*)&state", url);
            QNetworkCookieJar *cookie = m_view->page()->networkAccessManager()->cookieJar();
			QUrl yafUrl ("https://oauth.yandex.ru");
			QString login;
			for (int i=0; i < cookie->cookiesForUrl(yafUrl).count(); i++)
			{
				if (cookie->cookiesForUrl(yafUrl).at(i).name() == "yandex_login")
				{
					login = cookie->cookiesForUrl(yafUrl).at(i).value();
					break;
				}
			}

            delete m_view;
            m_view = NULL;

            emit authFinished(eNO_ERROR, login, m_token);
		}
	}
void CookiesContentsWidget::removeDomainCookies()
{
	const QModelIndexList indexes = m_ui->cookiesView->selectionModel()->selectedIndexes();

	if (indexes.isEmpty())
	{
		return;
	}

	QNetworkCookieJar *cookieJar = NetworkManagerFactory::getCookieJar();
	QList<QNetworkCookie> cookies;

	for (int i = 0; i < indexes.count(); ++i)
	{
		QStandardItem *domainItem = ((indexes.at(i).isValid() && indexes.at(i).parent() == m_model->invisibleRootItem()->index()) ? findDomain(indexes.at(i).sibling(indexes.at(i).row(), 0).data(Qt::ToolTipRole).toString()) : m_model->itemFromIndex(indexes.at(i).parent()));

		if (domainItem)
		{
			for (int j = 0; j < domainItem->rowCount(); ++j)
			{
				QStandardItem *cookieItem = domainItem->child(j, 0);

				if (cookieItem)
				{
					const QNetworkCookie cookie = getCookie(cookieItem->index());

					if (!cookies.contains(cookie))
					{
						cookies.append(cookie);
					}
				}
			}
		}
	}

	if (cookies.isEmpty())
	{
		return;
	}

	QMessageBox messageBox;
	messageBox.setWindowTitle(tr("Question"));
	messageBox.setText(tr("You are about to delete %n cookies.", "", cookies.count()));
	messageBox.setInformativeText(tr("Do you want to continue?"));
	messageBox.setIcon(QMessageBox::Question);
	messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
	messageBox.setDefaultButton(QMessageBox::Yes);

	if (messageBox.exec() == QMessageBox::Yes)
	{
		for (int i = 0; i < cookies.count(); ++i)
		{
			cookieJar->deleteCookie(cookies.at(i));
		}
	}
}
Beispiel #9
0
void AccessManager::setRawCookie(const QByteArray &rawCookie, const  QUrl &url)
{
    QNetworkCookie cookie(rawCookie.left(rawCookie.indexOf('=')),
                          rawCookie.mid(rawCookie.indexOf('=')+1));
    qDebug() << Q_FUNC_INFO << cookie.name() << cookie.value();
    QList<QNetworkCookie> cookieList;
    cookieList.append(cookie);

    QNetworkCookieJar *jar = cookieJar();
    jar->setCookiesFromUrl(cookieList, url);
}
void CookiesContentsWidget::removeCookies()
{
	const QModelIndexList indexes = m_ui->cookiesView->selectionModel()->selectedIndexes();

	if (indexes.isEmpty())
	{
		return;
	}

	QNetworkCookieJar *cookieJar = NetworkManagerFactory::getCookieJar();
	QList<QNetworkCookie> cookies;

	for (int i = 0; i < indexes.count(); ++i)
	{
		if (!indexes.at(i).isValid())
		{
			continue;
		}

		if (indexes.at(i).data(Qt::UserRole).toString().isEmpty())
		{
			QStandardItem *domainItem = m_model->itemFromIndex(indexes.at(i));

			if (!domainItem)
			{
				continue;
			}

			for (int j = 0; j < domainItem->rowCount(); ++j)
			{
				QStandardItem *cookieItem = domainItem->child(j, 0);

				if (cookieItem)
				{
					cookies.append(getCookie((cookieItem->index())));
				}
			}
		}
		else
		{
			QStandardItem *cookieItem = m_model->itemFromIndex(indexes.at(i));

			if (cookieItem)
			{
				cookies.append(getCookie(cookieItem->index()));
			}
		}
	}

	for (int i = 0; i < cookies.count(); ++i)
	{
		cookieJar->deleteCookie(cookies.at(i));
	}
}
QNetworkAccessManager* ACNetworkAccessManagerFactory::create(QObject *parent)
{
    QMutexLocker lock(&mutex);
    Q_UNUSED(lock);
    QNetworkAccessManager* manager = new ACNetworkAccessManager(parent);

    QNetworkCookieJar* cookieJar = ACNetworkCookieJar::GetInstance();
    manager->setCookieJar(cookieJar);
    cookieJar->setParent(0);

    return manager;
}
Beispiel #12
0
    void testCorrectHttpHeader()
    {
        HttpServerThread server(countryResponse(), HttpServerThread::Public);
        KDSoapClientInterface client(server.endPoint(), countryMessageNamespace());
        KDSoapAuthentication auth;

        auth.setUser(QLatin1String("kdab"));
        auth.setPassword(QLatin1String("unused"));
        client.setAuthentication(auth); // unused...

        QNetworkCookieJar myJar;
        QList<QNetworkCookie> myCookies;
        myCookies.append(QNetworkCookie("biscuits", "are good"));
        myJar.setCookiesFromUrl(myCookies, QUrl(server.endPoint()));
        client.setCookieJar(&myJar);

        QByteArray expectedRequestXml = expectedCountryRequest();
        client.setSoapVersion(KDSoapClientInterface::SOAP1_1);
        {
            KDSoapMessage ret = client.call(QLatin1String("getEmployeeCountry"), countryMessage());
            // Check what we sent
            QVERIFY(xmlBufferCompare(server.receivedData(), expectedRequestXml));
            QVERIFY(!ret.isFault());

            QCOMPARE(server.header("Content-Type").constData(), "text/xml;charset=utf-8");
            QCOMPARE(server.header("SoapAction").constData(), "\"http://www.kdab.com/xml/MyWsdl/getEmployeeCountry\"");
#if QT_VERSION >= 0x040800
            QCOMPARE(server.header("Cookie").constData(), "biscuits=are good");
#elif QT_VERSION >= 0x040700
            QCOMPARE(server.header("Cookie").constData(), "biscuits=\"are good\"");
#endif
            QCOMPARE(ret.arguments().child(QLatin1String("employeeCountry")).value().toString(), QString::fromLatin1("France"));

        }
        client.setSoapVersion(KDSoapClientInterface::SOAP1_2);
        {
            KDSoapMessage ret = client.call(QLatin1String("getEmployeeCountry"), countryMessage());
            // Check what we sent
            QByteArray expectedRequestXml12 = expectedRequestXml;
            expectedRequestXml12.replace("http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/2003/05/soap-envelope");
            expectedRequestXml12.replace("http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/2003/05/soap-encoding");
            QVERIFY(xmlBufferCompare(server.receivedData(), expectedRequestXml12));
            QVERIFY(!ret.isFault());
            QCOMPARE(server.header("Content-Type").constData(), "application/soap+xml;charset=utf-8;action=http://www.kdab.com/xml/MyWsdl/getEmployeeCountry");
            QCOMPARE(ret.arguments().child(QLatin1String("employeeCountry")).value().toString(), QString::fromLatin1("France"));
#if QT_VERSION >= 0x040800
            QCOMPARE(server.header("Cookie").constData(), "biscuits=are good");
#elif QT_VERSION >= 0x040700
            QCOMPARE(server.header("Cookie").constData(), "biscuits=\"are good\"");
#endif
        }
    }
Beispiel #13
0
void QNetworkReplyImplPrivate::metaDataChanged()
{
    Q_Q(QNetworkReplyImpl);
    // do we have cookies?
    if (cookedHeaders.contains(QNetworkRequest::SetCookieHeader) && !manager.isNull()) {
        QList<QNetworkCookie> cookies =
            qvariant_cast<QList<QNetworkCookie> >(cookedHeaders.value(QNetworkRequest::SetCookieHeader));
        QNetworkCookieJar *jar = manager->cookieJar();
        if (jar)
            jar->setCookiesFromUrl(cookies, url);
    }
    emit q->metaDataChanged();
}
Beispiel #14
0
void setCookies(Document* document, const KURL& url, const KURL& policyURL, const String& value)
{
    QUrl u(url);
    QUrl p(policyURL);
#if QT_VERSION >= 0x040400
    QNetworkCookieJar* jar = cookieJar(document);
    if (!jar)
        return;

    QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(QString(value).toAscii());
    jar->setCookiesFromUrl(cookies, p);
#else
    QCookieJar::cookieJar()->setCookies(u, p, (QString)value);
#endif
}
Beispiel #15
0
InfoExtractor::InfoExtractor(QObject *parent) :
    QObject(parent), m_queue(), m_url(), m_replyTimer(new QTimer(this)),
    m_accessManager(new QNetworkAccessManager(this)), m_reply(NULL)
{
    //Définition du cookie pour avoir la page en anglais
    QNetworkCookieJar *jar = new QNetworkCookieJar(this);
    QNetworkCookie cookie("l", "en");
    QList<QNetworkCookie> liste;
    liste << cookie;
    jar->setCookiesFromUrl(liste, MEGAUPLOAD);
    m_accessManager->setCookieJar(jar);

    m_replyTimer->setSingleShot(true);
    m_replyTimer->setInterval(INFO_EXTRACTION_TIMEOUT);
    connect(m_replyTimer, SIGNAL(timeout()), this, SLOT(replyTimeout()));
}
Beispiel #16
0
String cookieRequestHeaderFieldValue(const Document* document, const KURL &url)
{
    QUrl u(url);
    QNetworkCookieJar* jar = cookieJar(document);
    if (!jar)
        return String();

    QList<QNetworkCookie> cookies = jar->cookiesForUrl(u);
    if (cookies.isEmpty())
        return String();

    QStringList resultCookies;
    foreach (QNetworkCookie networkCookie, cookies) {
        resultCookies.append(QString::fromAscii(
                             networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
    }
Beispiel #17
0
String cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const KURL& /*firstParty*/, const KURL& url)
{
    QNetworkCookieJar* jar = session.context() ? session.context()->networkAccessManager()->cookieJar() : SharedCookieJarQt::shared();
    if (!jar)
        return String();

    QList<QNetworkCookie> cookies = jar->cookiesForUrl(QUrl(url));
    if (cookies.isEmpty())
        return String();

    QStringList resultCookies;
    foreach (QNetworkCookie networkCookie, cookies)
        resultCookies.append(QString::fromLatin1(networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));

    return resultCookies.join(QLatin1String("; "));
}
Beispiel #18
0
String cookieRequestHeaderFieldValue(const Document* document, const KURL &url)
{
    NetworkingContext* context = networkingContext(document);
    if (!context)
        return String();
    QNetworkCookieJar* jar = context->networkAccessManager()->cookieJar();

    QList<QNetworkCookie> cookies = jar->cookiesForUrl(QUrl(url));
    if (cookies.isEmpty())
        return String();

    QStringList resultCookies;
    foreach (QNetworkCookie networkCookie, cookies)
        resultCookies.append(QString::fromLatin1(networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));

    return resultCookies.join(QLatin1String("; "));
}
Beispiel #19
0
	void YafOAuth::finished(QNetworkReply *reply) 
	{
		int attr = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

		if(attr == 302) // redirect
		{
            m_oAuthTimer->stop();

			QString url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
			if(url.contains("http://passport-ckicheck.yandex.ru/passport?mode=ckicheck")
				|| url.contains("https://oauth.yandex.ru/authorize?allow=True&request_id"))
			{
                m_view->load(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl());
                if (!m_oAuthTimer->isActive())
                    m_oAuthTimer->start(10*1000);
			}
			else if(url.contains("webmounter://token#access_token="))
			{
                m_token = Data::RegExp::getByPattern("webmounter://token#access_token=(.*)&state", url);
                QNetworkCookieJar *cookie = m_view->page()->networkAccessManager()->cookieJar();
				QUrl yafUrl ("https://oauth.yandex.ru");
				QString login;
				for (int i=0; i < cookie->cookiesForUrl(yafUrl).count(); i++)
				{
					if (cookie->cookiesForUrl(yafUrl).at(i).name() == "yandex_login")
					{
						login = cookie->cookiesForUrl(yafUrl).at(i).value();
						login = login.replace(".", "-");
						break;
					}
				}

                delete m_view;
                m_view = NULL;

                emit authFinished(eNO_ERROR, login, m_token);
			}
			else if(url.contains("error=access_denied"))
			{
                delete m_view;
                m_view = NULL;

				emit authFinished(eERROR_CANCEL, "", "");
			}
		}
	}
Beispiel #20
0
void QNetworkReplyImplPrivate::metaDataChanged()
{
    Q_Q(QNetworkReplyImpl);
    // 1. do we have cookies?
    // 2. are we allowed to set them?
    if (cookedHeaders.contains(QNetworkRequest::SetCookieHeader) && !manager.isNull()
        && (static_cast<QNetworkRequest::LoadControl>
            (request.attribute(QNetworkRequest::CookieSaveControlAttribute,
                               QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Automatic)) {
        QList<QNetworkCookie> cookies =
            qvariant_cast<QList<QNetworkCookie> >(cookedHeaders.value(QNetworkRequest::SetCookieHeader));
        QNetworkCookieJar *jar = manager->cookieJar();
        if (jar)
            jar->setCookiesFromUrl(cookies, url);
    }
    emit q->metaDataChanged();
}
Beispiel #21
0
String cookies(const Document* document, const KURL& url)
{
    QUrl u(url);
    QNetworkCookieJar* jar = cookieJar(document);
    if (!jar)
        return String();

    QList<QNetworkCookie> cookies = jar->cookiesForUrl(u);
    if (cookies.isEmpty())
        return String();

    QStringList resultCookies;
    foreach (QNetworkCookie networkCookie, cookies) {
        if (networkCookie.isHttpOnly())
            continue;
        resultCookies.append(QString::fromAscii(
                             networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
    }

    return resultCookies.join(QLatin1String("; "));
}
Beispiel #22
0
void setCookies(Document* document, const KURL& url, const KURL& policyURL, const String& value)
{
    QUrl u(url);
    QUrl p(policyURL);
#if QT_VERSION >= 0x040400
    QNetworkCookieJar* jar = cookieJar(document);
    if (!jar)
        return;

    QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(QString(value).toAscii());
#if QT_VERSION >= 0x040500
    QList<QNetworkCookie>::Iterator it = cookies.begin();
    while (it != cookies.end()) {
        if (it->isHttpOnly())
            it = cookies.erase(it);
        else
            ++it;
    }
#endif
    jar->setCookiesFromUrl(cookies, p);
#else
    QCookieJar::cookieJar()->setCookies(u, p, (QString)value);
#endif
}
Beispiel #23
0
String cookiesForDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
{
    QNetworkCookieJar* jar = session.context() ? session.context()->networkAccessManager()->cookieJar() : SharedCookieJarQt::shared();
    if (!jar)
        return String();

    QUrl urlForCookies(url);
    QUrl firstPartyUrl(firstParty);
    if (!thirdPartyCookiePolicyPermits(session.context(), urlForCookies, firstPartyUrl))
        return String();

    QList<QNetworkCookie> cookies = jar->cookiesForUrl(urlForCookies);
    if (cookies.isEmpty())
        return String();

    QStringList resultCookies;
    foreach (const QNetworkCookie& networkCookie, cookies) {
        if (networkCookie.isHttpOnly())
            continue;
        resultCookies.append(QString::fromLatin1(networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData()));
    }

    return resultCookies.join(QLatin1String("; "));
}
void auto_dirvers_fatie::AutoFatie()
{
	//DailConnector connector("VPN", "ycc1", "111");

	QString adsl = ui.comboBox_adsl->currentText();
	QString account = ui.lineEdit_account->text();
	QString pwd = ui.lineEdit_password->text();

	DailConnector connector(adsl, account, pwd);

	while (!m_control_stop)
	{
		//1. 换VPN
		QNetworkCookieJar* cookie = new QNetworkCookieJar(this);

		network.GetManager().setCookieJar(cookie);

#ifdef NDEBUG
 		emitMsgBar(QStringLiteral("拨号中..."));
 		QString dial_msg;
 		while (!connector.ReConnect(dial_msg))
 		{
 			emitMsgBar(QStringLiteral("拨号中失败:") + dial_msg);
 			WaitforSeconds(3);
 			emitMsgBar(QStringLiteral("拨号中..."));
 		}
 
 		emitMsgBar(QStringLiteral("拨号成功..."));

 		int ncount = 0;
 		while (!GetContent() && ncount < 15)
 		{
 			connector.ReConnect(dial_msg);
 			WaitforSeconds(3);
 			ncount++;
 		}
 
 		if (ncount >= 15)
 		{
 			emitMsgBar(QStringLiteral("网站连接失败...,请检查网络连接"));
 			break;
 		}
#else
//        GetContent();
#endif
		//2. 登录
		bool login_status = false;
		while (m_account_order < m_account_list.size())
		{
			AccountParam ac = m_account_list.at(m_account_order);
			int ndepth = 1;
			if (!Login(ac._id, ac._password, ndepth))
			{
				emitMsgBar(QStringLiteral("登陆失败..."));
				//m_account_row_list.at(m_account_order)->setCheckState(Qt::Checked);
				ui.tableWidget_account_id->item(m_account_order, 0)->setBackgroundColor(QColor(255, 0, 0, 180));
				m_account_order++;
				continue;
			}
			else
			{
				emitMsgBar(QStringLiteral("登陆成功"));
				m_account_row_list.at(m_account_order)->setCheckState(Qt::Checked);
				ui.tableWidget_account_id->item(m_account_order, 0)->setBackgroundColor(QColor(0, 255, 0, 180));
				m_account_order++;
				login_status = true;
				break;
			}
		}

		if (!login_status)
		{
			emitMsgBar(QStringLiteral("1、网络无连接 \n 2、号登陆不成功,无法继续"));
			return;
		}

		//3. 发贴
		for (int k = 0; k < m_work_list.size(); ++k)
		{
			if (!m_work_list[k].isFinished())
			{
				if (m_work_list[k].doWork())
				{
					int current_id = m_work_list.at(k).getCurrentIndex();
					QString msg = QStringLiteral("第%1篇,第%2条,已完成").arg(k+1).arg(current_id);
					emitMsgBar(msg);
				}
				else
				{
					int current_id = m_work_list.at(k).getCurrentIndex();
					QString msg = QStringLiteral("第%1篇,第%2条,失败").arg(k+1).arg(current_id);
					emitMsgBar(msg);
				}

				// 如果全部完成,则退出
				if (isAllFinished())
				{
					logout();
					cookie->deleteLater();
					connector.DisConnect();
					emitMsgBar(QStringLiteral("已完成"));
					return;
				}

				//等待
				QElapsedTimer t1;
				t1.start();
				while (t1.elapsed() < m_interval*1000)
					QCoreApplication::processEvents();
			}	
		}

		//4. 登出
		logout();

		//5. 删除cookies
		cookie->deleteLater();
	}

 	connector.DisConnect();
 	emitMsgBar(QStringLiteral("已完成"));
}
void MediaPlayerPrivate::load(const String& url)
{
    // We are now loading
    if (m_networkState != MediaPlayer::Loading) {
        m_networkState = MediaPlayer::Loading;
        m_player->networkStateChanged();
    }

    // And we don't have any data yet
    if (m_readyState != MediaPlayer::HaveNothing) {
        m_readyState = MediaPlayer::HaveNothing;
        m_player->readyStateChanged();
    }

    const QUrl rUrl = QUrl(QString(url));
    const QString scheme = rUrl.scheme().toLower();

    // Grab the client media element
    HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());

    // Construct the media content with a network request if the resource is http[s]
    if (scheme == "http" || scheme == "https") {
        QNetworkRequest request = QNetworkRequest(rUrl);

        // Grab the current document
        Document* document = element->document();
        if (!document)
            document = element->ownerDocument();

        // Grab the frame and network manager
        Frame* frame = document ? document->frame() : 0;
        FrameLoaderClientQt* frameLoader =  frame ? static_cast<FrameLoaderClientQt*>(frame->loader()->client()) : 0;
        QNetworkAccessManager* manager = frameLoader ? frameLoader->webFrame()->page()->networkAccessManager() : 0;

        if (document && manager) {
            // Set the cookies
            QNetworkCookieJar* jar = manager->cookieJar();
            QList<QNetworkCookie> cookies = jar->cookiesForUrl(rUrl);

            // Don't set the header if there are no cookies.
            // This prevents a warning from being emitted.
            if (!cookies.isEmpty())
                request.setHeader(QNetworkRequest::CookieHeader, qVariantFromValue(cookies));

            // Set the refferer, but not when requesting insecure content from a secure page
            QUrl documentUrl = QUrl(QString(document->documentURI()));
            if (documentUrl.scheme().toLower() == "http" || scheme == "https")
                request.setRawHeader("Referer", documentUrl.toEncoded());

            // Set the user agent
            request.setRawHeader("User-Agent", frameLoader->userAgent(rUrl).utf8().data());
        }

        m_mediaPlayer->setMedia(QMediaContent(request));
    } else {
        // Otherwise, just use the URL
        m_mediaPlayer->setMedia(QMediaContent(rUrl));
    }

    // Set the current volume and mute status
    // We get these from the element, rather than the player, in case we have
    // transitioned from a media engine which doesn't support muting, to a media
    // engine which does.
    m_mediaPlayer->setMuted(element->muted());
    m_mediaPlayer->setVolume(static_cast<int>(element->volume() * 100.0));
}
Beispiel #26
0
bool autobots_toutiao::DoWork()
{
  if (m_comment_order >= m_comment_list.size())
  {
    UpdateData();
  }

  QNetworkCookieJar* cookie = new QNetworkCookieJar();

  network.GetManager().setCookieJar(cookie);

  // 尝试登陆
  bool login_status = false;
  while (m_account_order < m_account_list.size())
  {
    // 获取CSRF TOKEN

    if (!GetContent())
    {
      ui.lineEdit_msg->setText(QStringLiteral("网站连接失败...,请检查网络连接"));
      break;;
    }

    //if (!RequestForLogin())
    //{
    //  ui.lineEdit_msg->setText(QStringLiteral("请求失败..."));
    //  continue;
    //}

    AccountParam ac = m_account_list.at(m_account_order);

    if (!LoginWY(ac._id, ac._password))
    {
      ui.lineEdit_msg->setText(QStringLiteral("登陆失败..."));
      ui.tableWidget_account_id->item(m_account_order, 0)->setBackgroundColor(QColor(255,0,0, 180));
      m_account_order++;
      continue;
    }
    else
    {
      ui.lineEdit_msg->setText(QStringLiteral("登陆成功"));
      ui.tableWidget_account_id->item(m_account_order, 0)->setBackgroundColor(QColor(0,255,0, 180));
      m_account_order++;
      login_status = true;
      break;
    }
  }

  if (!login_status)
  {
    ui.lineEdit_msg->setText(QStringLiteral("账号登陆不成功,无法继续"));
    return false;
  }

  QString msg;
  msg.setNum(m_comment_order);

  QElapsedTimer t2;
  t2.start();
  while(t2.elapsed()<1000 )  
    QCoreApplication::processEvents();

  if (DoPostFatie(m_comment_list[m_comment_order]))
  {
    m_comment_item_list[m_comment_order]->setCheckState(Qt::Checked);
    ui.lineEdit_msg->setText(QStringLiteral("第") + msg + QStringLiteral("条,已完成"));
    m_comment_order++;
  }
  else
  {
    ui.lineEdit_msg->setText(QStringLiteral("第") + msg + QStringLiteral("条,失败"));
    m_comment_order++;
  }

  t2.restart();
  while(t2.elapsed()<1000 )  
    QCoreApplication::processEvents();

  if (login_status)
  {
      Logout(m_account_list.at(m_account_order-1)._id);
  }

  cookie->deleteLater();

  return true;
}
void MediaPlayerPrivateQt::commitLoad(const String& url)
{
    // We are now loading
    if (m_networkState != MediaPlayer::Loading) {
        m_networkState = MediaPlayer::Loading;
        m_webCorePlayer->networkStateChanged();
    }

    // And we don't have any data yet
    if (m_readyState != MediaPlayer::HaveNothing) {
        m_readyState = MediaPlayer::HaveNothing;
        m_webCorePlayer->readyStateChanged();
    }

    KURL kUrl(ParsedURLString, url);
    const QUrl rUrl = kUrl;
    const QString scheme = rUrl.scheme().toLower();

    // Grab the client media element
    HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_webCorePlayer->mediaPlayerClient());

    // Construct the media content with a network request if the resource is http[s]
    if (scheme == QString::fromLatin1("http") || scheme == QString::fromLatin1("https")) {
        QNetworkRequest request = QNetworkRequest(rUrl);

        // Grab the current document
        Document* document = element->document();
        if (!document)
            document = element->ownerDocument();

        // Grab the frame and network manager
        Frame* frame = document ? document->frame() : 0;
        FrameLoader* frameLoader = frame ? frame->loader() : 0;
        QNetworkAccessManager* manager = frameLoader ? frameLoader->networkingContext()->networkAccessManager() : 0;

        if (manager) {
            // Set the cookies
            QNetworkCookieJar* jar = manager->cookieJar();
            QList<QNetworkCookie> cookies = jar->cookiesForUrl(rUrl);

            // Don't set the header if there are no cookies.
            // This prevents a warning from being emitted.
            if (!cookies.isEmpty())
                request.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue(cookies));

            // Set the refferer, but not when requesting insecure content from a secure page
            QUrl documentUrl = QUrl(QString(document->documentURI()));
            if (documentUrl.scheme().toLower() == QString::fromLatin1("http") || scheme == QString::fromLatin1("https"))
                request.setRawHeader("Referer", documentUrl.toEncoded());

            // Set the user agent
            request.setRawHeader("User-Agent", frameLoader->userAgent(rUrl).utf8().data());
        }

        m_mediaPlayer->setMedia(QMediaContent(request));
    } else {
        // Otherwise, just use the URL
        m_mediaPlayer->setMedia(QMediaContent(rUrl));
    }

    // Set the current volume and mute status
    // We get these from the element, rather than the player, in case we have
    // transitioned from a media engine which doesn't support muting, to a media
    // engine which does.
    m_mediaPlayer->setMuted(element->muted());
    m_mediaPlayer->setVolume(static_cast<int>(element->volume() * 100.0));

    // Don't send PlaybackChanged notification for pre-roll.
    m_suppressNextPlaybackChanged = true;

    // Setting a media source will start loading the media, but we need
    // to pre-roll as well to get video size-hints and buffer-status
    if (element->paused())
        m_mediaPlayer->pause();
    else
        m_mediaPlayer->play();
}
Beispiel #28
0
int auto_smzdm::smzdm_run()
{
  QNetworkCookieJar* cookie = new QNetworkCookieJar(this);

  network.GetManager().setCookieJar(cookie);

  QString str_url_1 = "http://digi.tech.qq.com/original/pyp/pro.html";

  QUrl url_1(str_url_1);
  HttpParamList header_list1;
  header_list1.push_back(HttpParamItem("Accept",	"application/json, text/javascript, */*; q=0.01"));
  header_list1.push_back(HttpParamItem("Connection","Keep-Alive"));
  header_list1.push_back(HttpParamItem("Accept-Encoding","deflate"));
  header_list1.push_back(HttpParamItem("Accept-Language","zh-cn"));
  header_list1.push_back(HttpParamItem("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"));

  header_list1.push_back(HttpParamItem("Cache-Control", "no-cache"));
  //header_list.push_back(HttpParamItem("X-CSRFToken", "20c9e1fc22618a31cbfcd42218e96dd0"));
  header_list1.push_back(HttpParamItem("Host", "digi.tech.qq.com"));
  header_list1.push_back(HttpParamItem("Referer", "http://digi.tech.qq.com/original/pyp/pro.html"));
  header_list1.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"));
 
  QNetworkReply* rp1 = network.GetRequest(url_1, header_list1);

   QTime _t;
   _t.start();
 
   bool _timeout = false;
 
   while (rp1 &&!rp1->isFinished())
   {
     QCoreApplication::processEvents();
     if (_t.elapsed() >= TIMEOUT) {
       _timeout = true;
       break;
     }
   }

   QString str = rp1->readAll();
   rp1->deleteLater();

  //投票
  QString str_url1 = "http://panshi.qq.com/v2/vote/10615080/submit";

  QUrl url1(str_url1);

  HttpParamList header_list2;
  header_list2.push_back(HttpParamItem("Accept", "text/html, application/xhtml+xml, */*"));
  header_list2.push_back(HttpParamItem("Referer", "http://digi.tech.qq.com/original/pyp/pro.html"));
  header_list2.push_back(HttpParamItem("Cache-Control","no-cache"));
  header_list2.push_back(HttpParamItem("Connection","keep-alive"));
  //header_list2.push_back(HttpParamItem("Accept-Encoding","gzip, deflate"));
  header_list2.push_back(HttpParamItem("Accept-Language","zh-CN"));
  header_list2.push_back(HttpParamItem("Host", "panshi.qq.com"));
  header_list2.push_back(HttpParamItem("X-Requested-With", "XMLHttpRequest"));
  header_list2.push_back(HttpParamItem("Content-Type", "application/x-www-form-urlencoded"));
  header_list2.push_back(HttpParamItem("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0"));

  HttpParamList post_data;
  post_data.push_back(HttpParamItem("answer","{\"673646\":{\"selected\":[1560346]}}"));
  post_data.push_back(HttpParamItem("callback","parent.AppPlatform.Survey.Digg.ReceiveDiggResult"));
  post_data.push_back(HttpParamItem("format","script"));
  post_data.push_back(HttpParamItem("g_tk","2013"));
  post_data.push_back(HttpParamItem("login","1"));
  post_data.push_back(HttpParamItem("source","1"));
  QNetworkReply* rp2 = network.PostRequest(url1, header_list2, post_data);

  _t.restart();

  _timeout = false;

  while (rp2 &&!rp2->isFinished())
  {
    QCoreApplication::processEvents();
    if (_t.elapsed() >= TIMEOUT) {
      _timeout = true;
      break;
    }
  }

  str = rp2->readAll();
  rp2->deleteLater();

  cookie->deleteLater();

  return 0;
}
Beispiel #29
0
void autobots_toutiao::onStart()
{
	// 检查输入
	if (!CheckInput())
	{
		return;
	}

	// 更新界面输入
	UpdateData();

	//   if (m_account_list.size() < m_comment_list.size())
	//   {
	//     QMessageBox::critical(this, QStringLiteral("提示"), QStringLiteral("用户账户太少")); 
	//     return;
	//   }

	control_status = true;

	// 循环发帖
	for (int i = 0; i < m_account_list.size(); ++i)
	{
		if (!control_status)
		{
			break;
		}

		// 尝试登陆

		network.GetManager().clearAccessCache();

		QNetworkCookieJar* cookie = new QNetworkCookieJar();

		network.GetManager().setCookieJar(cookie);

		if (!RequestForRenren())
		{
			ui.lineEdit_msg->setText(QStringLiteral("请求失败..."));
			cookie->deleteLater();
			continue;
		}

		AccountParam ac = m_account_list.at(i);

		if (!AuthorByRenren(ac._id, ac._password))
		{
			ui.lineEdit_msg->setText(QStringLiteral("登陆失败..."));
			ui.tableWidget_account_id->item(i, 0)->setBackgroundColor(QColor(255, 0, 0, 180));
			continue;
		}
		else
		{
			ui.lineEdit_msg->setText(QStringLiteral("登陆成功"));
			ui.tableWidget_account_id->item(i, 0)->setBackgroundColor(QColor(0, 255, 0, 180));
		}

		QElapsedTimer t2;
		t2.start();
		while (t2.elapsed()<1000)
			QCoreApplication::processEvents();

		DoSupport();

		t2.restart();
		while (t2.elapsed()<1000)
			QCoreApplication::processEvents();

		Logout();
		m_device_order++;

		if (m_device_order >= m_devices_list.size())
		{
			m_device_order = 0;
		}

		QString msg;
		msg.setNum(i + 1);

		ui.lineEdit_msg->setText(QStringLiteral("第") + msg + QStringLiteral("次完成"));

		t2.restart();
		while (t2.elapsed()< m_interval * 1000)  // 时间间隔
		{
			ui.lineEdit_msg->setText(QString::number(t2.elapsed()));
			QCoreApplication::processEvents();
		}
	}

	ui.lineEdit_msg->setText(QStringLiteral("已完成"));
}