void KWebPage::downloadResponse(QNetworkReply *reply) { Q_ASSERT(reply); if (!reply) return; // Put the job on hold only for the protocols we know about (read: http). KIO::Integration::AccessManager::putReplyOnHold(reply); QString mimeType; KIO::MetaData metaData; if (handleReply(reply, &mimeType, &metaData)) { return; } const KUrl replyUrl (reply->url()); // Ask KRun to handle the response when mimetype is unknown if (mimeType.isEmpty()) { (void)new KRun(replyUrl, d->windowWidget(), 0 , replyUrl.isLocalFile()); return; } // Ask KRun::runUrl to handle the response when mimetype is inode/* if (mimeType.startsWith(QL1S("inode/"), Qt::CaseInsensitive) && KRun::runUrl(replyUrl, mimeType, d->windowWidget(), false, false, metaData.value(QL1S("content-disposition-filename")))) { return; } }
KIO::MetaData Settings::accountData() const { KConfig config("scalixadminrc"); KConfigGroup group(&config, "Account"); KIO::MetaData data; data.insert("auth", group.readEntry("auth")); data.insert("tls", group.readBoolEntry("use-tls") ? "on" : "off"); return data; }
bool KIO::Integration::sslConfigFromMetaData(const KIO::MetaData& metadata, QSslConfiguration& sslconfig) { bool success = false; if (metadata.contains(QL1S("ssl_in_use"))) { const QSsl::SslProtocol sslProto = qSslProtocolFromString(metadata.value(QL1S("ssl_protocol_version"))); QList<QSslCipher> cipherList; cipherList << QSslCipher(metadata.value(QL1S("ssl_cipher_name")), sslProto); sslconfig.setCaCertificates(QSslCertificate::fromData(metadata.value(QL1S("ssl_peer_chain")).toUtf8())); sslconfig.setCiphers(cipherList); sslconfig.setProtocol(sslProto); success = sslconfig.isNull(); } return success; }
void AccessManagerReply::readHttpResponseHeaders(KIO::Job *job) { if (!job || m_metaDataRead) return; KIO::MetaData metaData (job->metaData()); if (metaData.isEmpty()) { // Allow handling of local resources such as man pages and file url... if (isLocalRequest(url())) { setHeader(QNetworkRequest::ContentLengthHeader, job->totalAmount(KJob::Bytes)); setAttribute(QNetworkRequest::HttpStatusCodeAttribute, "200"); emit metaDataChanged(); } return; } setHeaderFromMetaData(metaData); m_metaDataRead = true; emit metaDataChanged(); }
void UIServer::showSSLInfoDialog(const QString &url, const KIO::MetaData &meta, int mainwindow) { KSSLInfoDlg *kid = new KSSLInfoDlg(meta["ssl_in_use"].upper() == "TRUE", 0L /*parent?*/, 0L, true); KSSLCertificate *x = KSSLCertificate::fromString(meta["ssl_peer_certificate"].local8Bit()); if(x) { // Set the chain back onto the certificate QStringList cl = QStringList::split(QString("\n"), meta["ssl_peer_chain"]); QPtrList< KSSLCertificate > ncl; ncl.setAutoDelete(true); for(QStringList::Iterator it = cl.begin(); it != cl.end(); ++it) { KSSLCertificate *y = KSSLCertificate::fromString((*it).local8Bit()); if(y) ncl.append(y); } if(ncl.count() > 0) x->chain().setChain(ncl); kdDebug(7024) << "ssl_cert_errors=" << meta["ssl_cert_errors"] << endl; kid->setCertState(meta["ssl_cert_errors"]); QString ip = meta.contains("ssl_proxied") ? "" : meta["ssl_peer_ip"]; kid->setup(x, ip, url, // the URL meta["ssl_cipher"], meta["ssl_cipher_desc"], meta["ssl_cipher_version"], meta["ssl_cipher_used_bits"].toInt(), meta["ssl_cipher_bits"].toInt(), KSSLCertificate::KSSLValidation(meta["ssl_cert_state"].toInt())); kdDebug(7024) << "Showing SSL Info dialog" << endl; if(mainwindow != 0) KWin::setMainWindow(kid, mainwindow); kid->exec(); delete x; kdDebug(7024) << "SSL Info dialog closed" << endl; } else { KMessageBox::information(0L, // parent ? i18n("The peer SSL certificate appears to be corrupt."), i18n("SSL")); } // Don't delete kid!! }
static bool downloadResource (const KUrl& srcUrl, const QString& suggestedName = QString(), QWidget* parent = 0, const KIO::MetaData& metaData = KIO::MetaData()) { const KUrl& destUrl = promptUser(parent, srcUrl, suggestedName); if (!destUrl.isValid()) return false; KIO::Job *job = KIO::file_copy(srcUrl, destUrl); if (!metaData.isEmpty()) job->setMetaData(metaData); job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. job->ui()->setWindow((parent ? parent->window() : 0)); job->ui()->setAutoErrorHandlingEnabled(true); return true; }
static bool downloadResource (const KUrl& srcUrl, const QString& suggestedName = QString(), QWidget* parent = 0, const KIO::MetaData& metaData = KIO::MetaData()) { const QString fileName = suggestedName.isEmpty() ? srcUrl.fileName() : suggestedName; // convert filename to URL using fromPath to avoid trouble with ':' in filenames (#184202) KUrl destUrl = KFileDialog::getSaveFileName(KUrl::fromPath(fileName), QString(), parent); if (!destUrl.isValid()) return false; // Using KIO::copy rather than file_copy, to benefit from "dest already exists" dialogs. KIO::Job *job = KIO::copy(srcUrl, destUrl); if (!metaData.isEmpty()) job->setMetaData(metaData); job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. job->ui()->setWindow((parent ? parent->window() : 0)); job->ui()->setAutoErrorHandlingEnabled(true); return true; }
void AccessManager::AccessManagerPrivate::setMetaDataForRequest(QNetworkRequest request, KIO::MetaData& metaData) { // Add any meta data specified within request... QVariant userMetaData = request.attribute (static_cast<QNetworkRequest::Attribute>(MetaData)); if (userMetaData.isValid() && userMetaData.type() == QVariant::Map) metaData += userMetaData.toMap(); metaData.insert(QL1S("PropagateHttpHeader"), QL1S("true")); if (request.hasRawHeader("User-Agent")) { metaData.insert(QL1S("UserAgent"), request.rawHeader("User-Agent")); request.setRawHeader("User-Agent", QByteArray()); } if (request.hasRawHeader("Accept")) { metaData.insert(QL1S("accept"), request.rawHeader("Accept")); request.setRawHeader("Accept", QByteArray()); } if (request.hasRawHeader("Accept-Charset")) { metaData.insert(QL1S("Charsets"), request.rawHeader("Accept-Charset")); request.setRawHeader("Accept-Charset", QByteArray()); } if (request.hasRawHeader("Accept-Language")) { metaData.insert(QL1S("Languages"), request.rawHeader("Accept-Language")); request.setRawHeader("Accept-Language", QByteArray()); } if (request.hasRawHeader("Referer")) { metaData.insert(QL1S("referrer"), request.rawHeader("Referer")); request.setRawHeader("Referer", QByteArray()); } if (request.hasRawHeader("Content-Type")) { metaData.insert(QL1S("content-type"), request.rawHeader("Content-Type")); request.setRawHeader("Content-Type", QByteArray()); } if (request.attribute(QNetworkRequest::AuthenticationReuseAttribute) == QNetworkRequest::Manual) { metaData.insert(QL1S("no-preemptive-auth-reuse"), QL1S("true")); } request.setRawHeader("Content-Length", QByteArray()); request.setRawHeader("Connection", QByteArray()); request.setRawHeader("If-None-Match", QByteArray()); request.setRawHeader("If-Modified-Since", QByteArray()); request.setRawHeader("x-kdewebkit-ignore-disposition", QByteArray()); QStringList customHeaders; Q_FOREACH(const QByteArray &key, request.rawHeaderList()) { const QByteArray value = request.rawHeader(key); if (value.length()) customHeaders << (key + QL1S(": ") + value); } if (!customHeaders.isEmpty()) { metaData.insert(QL1S("customHTTPHeader"), customHeaders.join("\r\n")); } // Append per request meta data, if any... if (!requestMetaData.isEmpty()) { metaData += requestMetaData; // Clear per request meta data... requestMetaData.clear(); } // Append per session meta data, if any... if (!sessionMetaData.isEmpty()) { metaData += sessionMetaData; } }
QNetworkReply *AccessManager::createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData) { const KUrl reqUrl (req.url()); if (!d->externalContentAllowed && !KDEPrivate::AccessManagerReply::isLocalRequest(reqUrl) && reqUrl.scheme() != QL1S("data")) { kDebug( 7044 ) << "Blocked: " << reqUrl; return new KDEPrivate::AccessManagerReply(op, req, QNetworkReply::ContentAccessDenied, i18n("Blocked request."), this); } // Check if the internal ignore content disposition header is set. const bool ignoreContentDisposition = req.hasRawHeader("x-kdewebkit-ignore-disposition"); // Retrieve the KIO meta data... KIO::MetaData metaData; d->setMetaDataForRequest(req, metaData); KIO::SimpleJob *kioJob = 0; switch (op) { case HeadOperation: { //kDebug( 7044 ) << "HeadOperation:" << reqUrl; kioJob = KIO::mimetype(reqUrl, KIO::HideProgressInfo); break; } case GetOperation: { //kDebug( 7044 ) << "GetOperation:" << reqUrl; if (!reqUrl.path().isEmpty() || reqUrl.host().isEmpty()) kioJob = KIO::get(reqUrl, KIO::NoReload, KIO::HideProgressInfo); else kioJob = KIO::stat(reqUrl, KIO::HideProgressInfo); // WORKAROUND: Avoid the brain damaged stuff QtWebKit does when a POST // operation is redirected! See BR# 268694. metaData.remove(QL1S("content-type")); // Remove the content-type from a GET/HEAD request! break; } case PutOperation: { //kDebug( 7044 ) << "PutOperation:" << reqUrl; if (outgoingData) kioJob = KIO::storedPut(outgoingData->readAll(), reqUrl, -1, KIO::HideProgressInfo); else kioJob = KIO::put(reqUrl, -1, KIO::HideProgressInfo); break; } case PostOperation: { kioJob = KIO::http_post(reqUrl, outgoingData, sizeFromRequest(req), KIO::HideProgressInfo); if (!metaData.contains(QL1S("content-type"))) { const QVariant header = req.header(QNetworkRequest::ContentTypeHeader); if (header.isValid()) { metaData.insert(QL1S("content-type"), (QL1S("Content-Type: ") + header.toString())); } else { metaData.insert(QL1S("content-type"), QL1S("Content-Type: application/x-www-form-urlencoded")); } } break; } case DeleteOperation: { //kDebug(7044) << "DeleteOperation:" << reqUrl; kioJob = KIO::http_delete(reqUrl, KIO::HideProgressInfo); break; } case CustomOperation: { const QByteArray& method = req.attribute(QNetworkRequest::CustomVerbAttribute).toByteArray(); //kDebug(7044) << "CustomOperation:" << reqUrl << "method:" << method << "outgoing data:" << outgoingData; if (method.isEmpty()) { return new KDEPrivate::AccessManagerReply(op, req, QNetworkReply::ProtocolUnknownError, i18n("Unknown HTTP verb."), this); } if (outgoingData) kioJob = KIO::http_post(reqUrl, outgoingData, sizeFromRequest(req), KIO::HideProgressInfo); else kioJob = KIO::get(reqUrl, KIO::NoReload, KIO::HideProgressInfo); metaData.insert(QL1S("CustomHTTPMethod"), method); break; } default: { kWarning(7044) << "Unsupported KIO operation requested! Defering to QNetworkAccessManager..."; return QNetworkAccessManager::createRequest(op, req, outgoingData); } } // Set the job priority switch (req.priority()) { case QNetworkRequest::HighPriority: KIO::Scheduler::setJobPriority(kioJob, -5); break; case QNetworkRequest::LowPriority: KIO::Scheduler::setJobPriority(kioJob, 5); break; default: break; } KDEPrivate::AccessManagerReply *reply; /* NOTE: Here we attempt to handle synchronous XHR requests. Unfortunately, due to the fact that QNAM is both synchronous and multi-thread while KIO is completely the opposite (asynchronous and not thread safe), the code below might cause crashes like the one reported in bug# 287778 (nested event loops are inherently dangerous). Unfortunately, all attempts to address the crash has so far failed due to the many regressions they caused, e.g. bug# 231932 and 297954. Hence, until a solution is found, we have to live with the side effects of creating nested event loops. */ if (req.attribute(gSynchronousNetworkRequestAttribute).toBool()) { KUrl finalURL; QByteArray data; if (KIO::NetAccess::synchronousRun(kioJob, d->window, &data, &finalURL, &metaData)) { reply = new KDEPrivate::AccessManagerReply(op, req, data, finalURL, metaData, this); kDebug(7044) << "Synchronous XHR:" << reply << reqUrl; } else { kWarning(7044) << "Failed to create a synchronous XHR for" << reqUrl; reply = new KDEPrivate::AccessManagerReply(op, req, QNetworkReply::UnknownNetworkError, kioJob->errorText(), this); } } else { // Set the window on the the KIO ui delegate if (d->window) { kioJob->ui()->setWindow(d->window); } // Disable internal automatic redirection handling kioJob->setRedirectionHandlingEnabled(false); // Set the job priority switch (req.priority()) { case QNetworkRequest::HighPriority: KIO::Scheduler::setJobPriority(kioJob, -5); break; case QNetworkRequest::LowPriority: KIO::Scheduler::setJobPriority(kioJob, 5); break; default: break; } // Set the meta data for this job... kioJob->setMetaData(metaData); // Create the reply... reply = new KDEPrivate::AccessManagerReply(op, req, kioJob, d->emitReadyReadOnMetaDataChange, this); //kDebug(7044) << reply << reqUrl; } if (ignoreContentDisposition && reply) { //kDebug(7044) << "Content-Disposition WILL BE IGNORED!"; reply->setIgnoreContentDisposition(ignoreContentDisposition); } return reply; }
bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) { if (_isOnRekonqPage) { WebView *view = qobject_cast<WebView *>(parent()); WebTab *tab = qobject_cast<WebTab *>(view->parent()); _isOnRekonqPage = false; tab->setPart(0, KUrl()); // re-enable the view page } // reset webpage values _suggestedFileName.clear(); _loadingUrl = request.url(); KIO::AccessManager *manager = qobject_cast<KIO::AccessManager*>(networkAccessManager()); KIO::MetaData metaData = manager->requestMetaData(); // Get the SSL information sent, if any... if (metaData.contains(QL1S("ssl_in_use"))) { WebSslInfo info; info.restoreFrom(metaData.toVariant(), request.url()); info.setUrl(request.url()); _sslInfo = info; } if (frame) { if (_protHandler.preHandling(request, frame)) { return false; } switch (type) { case QWebPage::NavigationTypeLinkClicked: if (_sslInfo.isValid()) { setRequestMetaData("ssl_was_in_use", "TRUE"); } break; case QWebPage::NavigationTypeFormSubmitted: break; case QWebPage::NavigationTypeFormResubmitted: if (KMessageBox::warningContinueCancel(view(), i18n("Are you sure you want to send your data again?"), i18n("Resend form data") ) == KMessageBox::Cancel) { return false; } break; case QWebPage::NavigationTypeReload: case QWebPage::NavigationTypeBackOrForward: case QWebPage::NavigationTypeOther: break; default: break; } } return KWebPage::acceptNavigationRequest(frame, request, type); }
static bool downloadResource(const KUrl& srcUrl, const KIO::MetaData& metaData = KIO::MetaData(), QWidget * parent = 0, const QString & suggestedName = QString()) { KUrl destUrl; int result = KIO::R_OVERWRITE; const QString fileName((suggestedName.isEmpty() ? srcUrl.fileName() : suggestedName)); do { // follow bug:184202 fixes destUrl = KFileDialog::getSaveFileName(KUrl(KGlobalSettings::downloadPath().append(fileName)), QString(), parent); if (destUrl.isEmpty()) return false; if (destUrl.isLocalFile()) { QFileInfo finfo(destUrl.toLocalFile()); if (finfo.exists()) { QDateTime now = QDateTime::currentDateTime(); QPointer<KIO::RenameDialog> dlg = new KIO::RenameDialog(parent, i18n("Overwrite File?"), srcUrl, destUrl, KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP), -1, finfo.size(), now.toTime_t(), finfo.created().toTime_t(), now.toTime_t(), finfo.lastModified().toTime_t() ); result = dlg->exec(); delete dlg; } } } while (result == KIO::R_CANCEL && destUrl.isValid()); // Save download history DownloadItem *item = rApp->downloadManager()->addDownload(srcUrl.pathOrUrl(), destUrl.pathOrUrl()); if (!KStandardDirs::findExe("kget").isNull() && ReKonfig::kgetDownload()) { //KGet integration: if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget")) { KToolInvocation::kdeinitExecWait("kget"); } QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main"); if (!kget.isValid()) return false; QDBusMessage transfer = kget.call(QL1S("addTransfer"), srcUrl.prettyUrl(), destUrl.prettyUrl(), true); if (transfer.arguments().isEmpty()) return true; const QString transferPath = transfer.arguments().first().toString(); item->setKGetTransferDbusPath(transferPath); return true; } KIO::Job *job = KIO::file_copy(srcUrl, destUrl, -1, KIO::Overwrite); if (item) { QObject::connect(job, SIGNAL(percent(KJob *,unsigned long)), item, SLOT(updateProgress(KJob *,unsigned long))); QObject::connect(job, SIGNAL(finished(KJob *)), item, SLOT(onFinished(KJob*))); } if (!metaData.isEmpty()) job->setMetaData(metaData); job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. job->uiDelegate()->setAutoErrorHandlingEnabled(true); return true; }
void EMailThread::send() { QStringList listTo; QString mQuery; KIO::MetaData slaveConfig; KURL destination; int i, count; _sendOk = false; KIO::Scheduler::connect(SIGNAL(slaveError(KIO::Slave *, int, const QString &)), this, SLOT(slaveError(KIO::Slave *, int, const QString &))); _strBody.insert( 0, QString("Subject:%1\n\n").arg(_strSubject).latin1()); _strBody.insert( 0, QString("To:%1\n").arg(_strTo).latin1()); _bodyOffset = 0; _bodyLength = _strBody.length(); mQuery = "headers=0&from="; mQuery += KURL::encode_string(_strFrom); listTo = QStringList::split(QRegExp("[ ,;]"), _strTo); count = listTo.count(); if (count > 0) { for (i=0; i<count; i++) { mQuery += "&to="; mQuery += KURL::encode_string(listTo[i]); } } else { mQuery += "&to="; mQuery += KURL::encode_string(_strTo); } mQuery += "&size="; mQuery += QString::number(_bodyLength); if (_encryption == EMailEncryptionSSL) { destination.setProtocol("smtps"); } else { destination.setProtocol("smtp"); } destination.setHost(_strSMTPServer); destination.setPort((short)_iPort); destination.setPath("/send"); destination.setQuery(mQuery); if (_useAuthentication) { destination.setUser(_strUsername); destination.setPass(_strPassword); } if (_encryption == EMailEncryptionTLS) { slaveConfig.insert("tls", "on"); } else { slaveConfig.insert("tls", "off"); } if (_useAuthentication) { switch (_authentication) { case EMailAuthenticationPLAIN: slaveConfig.insert("sasl", "PLAIN"); break; case EMailAuthenticationLOGIN: slaveConfig.insert("sasl", "LOGIN"); break; case EMailAuthenticationCRAMMD5: slaveConfig.insert("sasl", "CRAM-MD5"); break; case EMailAuthenticationDIGESTMD5: slaveConfig.insert("sasl", "DIGEST-MD5"); break; default: slaveConfig.insert("sasl", "PLAIN"); break; } } _slave = KIO::Scheduler::getConnectedSlave(destination, slaveConfig); if (_slave) { _job = KIO::put(destination, -1, false, false, false); if (_job) { _job->addMetaData("lf2crlf+dotstuff", "slave"); connect(_job, SIGNAL(result(KIO::Job *)), this, SLOT(result(KIO::Job *))); connect(_job, SIGNAL(dataReq(KIO::Job *, QByteArray &)), this, SLOT(dataReq(KIO::Job *, QByteArray &))); KIO::Scheduler::assignJobToSlave(_slave, _job); _sendOk = true; } } }