void XMLHttpRequest::makeCrossSiteAccessRequestWithPreflight(ExceptionCode& ec) { String origin = accessControlOrigin(); KURL url = m_url; url.setUser(String()); url.setPass(String()); m_inPreflight = true; ResourceRequest preflightRequest(url); preflightRequest.setHTTPMethod("OPTIONS"); preflightRequest.setHTTPHeaderField("Access-Control-Origin", origin); if (m_async) { loadRequestAsynchronously(preflightRequest); return; } loadRequestSynchronously(preflightRequest, ec); m_inPreflight = false; // Send the actual request. ResourceRequest request(url); request.setHTTPMethod(m_method); request.setHTTPHeaderField("Access-Control-Origin", origin); if (m_crossSiteRequestHeaders.size() > 0) request.addHTTPHeaderFields(m_crossSiteRequestHeaders); if (m_requestEntityBody) { ASSERT(m_method != "GET"); request.setHTTPBody(m_requestEntityBody.release()); } loadRequestSynchronously(request, ec); }
bool PreviewJob::statResultThumbnail() { if ( d->thumbPath.isEmpty() ) return false; KURL url = d->currentItem.item->url(); // Don't include the password if any url.setPass(TQString::null); // The TMS defines local files as file:///path/to/file instead of KDE's // way (file:/path/to/file) #ifdef KURL_TRIPLE_SLASH_FILE_PROT d->origName = url.url(); #else if (url.protocol() == "file") d->origName = "file://" + url.path(); else d->origName = url.url(); #endif KMD5 md5( TQFile::encodeName( d->origName ).data() ); d->thumbName = TQFile::encodeName( md5.hexDigest() ) + ".png"; TQImage thumb; if ( !thumb.load( d->thumbPath + d->thumbName ) ) return false; if ( thumb.text( "Thumb::URI", 0 ) != d->origName || thumb.text( "Thumb::MTime", 0 ).toInt() != d->tOrig ) return false; // Found it, use it emitPreview( thumb ); d->succeeded = true; determineNextFile(); return true; }
void XMLHttpRequest::handleAsynchronousPreflightResult() { ASSERT(m_inPreflight); ASSERT(m_async); m_inPreflight = false; KURL url = m_url; url.setUser(String()); url.setPass(String()); ResourceRequest request(url); request.setHTTPMethod(m_method); request.setHTTPHeaderField("Access-Control-Origin", accessControlOrigin()); if (m_crossSiteRequestHeaders.size() > 0) request.addHTTPHeaderFields(m_crossSiteRequestHeaders); if (m_requestEntityBody) { ASSERT(m_method != "GET"); request.setHTTPBody(m_requestEntityBody.release()); } loadRequestAsynchronously(request); }
void XMLHttpRequest::makeSimpleCrossOriginAccessRequest(ExceptionCode& ec) { ASSERT(isSimpleCrossOriginAccessRequest(m_method, m_requestHeaders)); // Cross-origin requests are only defined for HTTP. We would catch this when checking response headers later, but there is no reason to send a request that's guaranteed to be denied. if (!m_url.protocolInHTTPFamily()) { ec = XMLHttpRequestException::NETWORK_ERR; networkError(); return; } KURL url = m_url; url.setUser(String()); url.setPass(String()); ResourceRequest request(url); request.setHTTPMethod(m_method); request.setAllowHTTPCookies(m_includeCredentials); request.setHTTPOrigin(scriptExecutionContext()->securityOrigin()->toString()); if (m_requestHeaders.size() > 0) request.addHTTPHeaderFields(m_requestHeaders); if (m_requestEntityBody) { ASSERT(m_method != "GET"); ASSERT(m_method != "HEAD"); request.setHTTPBody(m_requestEntityBody.release()); } if (m_async) loadRequestAsynchronously(request); else loadRequestSynchronously(request, ec); }
void XMLHttpRequest::handleAsynchronousPreflightResult() { ASSERT(m_inPreflight); ASSERT(m_async); m_inPreflight = false; KURL url = m_url; url.setUser(String()); url.setPass(String()); ResourceRequest request(url); request.setHTTPMethod(m_method); request.setAllowHTTPCookies(m_includeCredentials); request.setHTTPOrigin(scriptExecutionContext()->securityOrigin()->toString()); if (m_requestHeaders.size() > 0) request.addHTTPHeaderFields(m_requestHeaders); if (m_requestEntityBody) { ASSERT(m_method != "GET"); request.setHTTPBody(m_requestEntityBody.release()); } loadRequestAsynchronously(request); }
bool KMLpdManager::completePrinterShort(KMPrinter *printer) { PrintcapEntry *entry = m_entries.find(printer->name()); if (entry) { QString type(entry->comment(2)), driver(entry->comment(7)), lp(entry->arg("lp")); printer->setDescription(i18n("Local printer queue (%1)").arg(type.isEmpty() ? i18n("Unknown type of local printer queue", "Unknown") : type)); printer->setLocation(i18n("<Not available>")); printer->setDriverInfo(driver.isEmpty() ? i18n("Unknown Driver", "Unknown") : driver); // device KURL url; if (!entry->arg("rm").isEmpty()) { url = QString::fromLatin1("lpd://%1/%2").arg(entry->arg("rm")).arg(entry->arg("rp")); printer->setDescription(i18n("Remote LPD queue %1@%2").arg(entry->arg("rp")).arg(entry->arg("rm"))); } else if (!lp.isEmpty() && lp != "/dev/null") url = QString::fromLatin1("parallel:%1").arg(lp); else if (QFile::exists(entry->arg("sd")+"/.config")) { QMap<QString,QString> map = loadPrinttoolCfgFile(entry->arg("sd")+"/.config"); if (type == "SMB") { QStringList l = QStringList::split('\\',map["share"],false); if (map["workgroup"].isEmpty()) url = QString::fromLatin1("smb://%1/%2").arg(l[0]).arg(l[1]); else url = QString::fromLatin1("smb://%1/%2/%3").arg(map["workgroup"]).arg(l[0]).arg(l[1]); url.setUser(map["user"]); url.setPass(map["password"]); } else if (type == "DIRECT") url = QString::fromLatin1("socket://%1:%2").arg(map["printer_ip"]).arg(map["port"]); else if (type == "NCP") { url = QString::fromLatin1("ncp://%1/%2").arg(map["server"]).arg(map["queue"]); url.setUser(map["user"]); url.setPass(map["password"]); } } printer->setDevice(url); return true; } else return false; }
void ResourceSlox::uploadContacts() { QDomDocument doc; QDomElement root = WebdavHandler::addDavElement( doc, doc, "propertyupdate" ); QDomElement set = WebdavHandler::addDavElement( doc, root, "set" ); QDomElement prop = WebdavHandler::addDavElement( doc, set, "prop" ); bool isDelete = false; KABC::Addressee::List addedAddr = addedAddressees(); KABC::Addressee::List changedAddr = changedAddressees(); KABC::Addressee::List deletedAddr = deletedAddressees(); if ( !addedAddr.isEmpty() ) { mUploadAddressee = addedAddr.first(); WebdavHandler::addSloxElement( this, doc, prop, fieldName( ClientId ), mUploadAddressee.uid() ); } else if ( !changedAddr.isEmpty() ) { mUploadAddressee = changedAddr.first(); WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectId ), mUploadAddressee.uid().remove( 0, sizeof("kresources_slox_kabc_") - 1) ); } else if ( !deletedAddr.isEmpty() ) { mUploadAddressee = deletedAddr.first(); isDelete = true; } else { kdDebug() << k_funcinfo << "Upload finished." << endl; emit savingFinished( this ); return; } if ( !isDelete ) { createAddresseeFields( doc, prop, mUploadAddressee ); } else { QString tmp_uid = mUploadAddressee.uid().remove( 0, sizeof("kresources_slox_kabc_") - 1); // remove prefix from uid WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectId ), tmp_uid ); WebdavHandler::addSloxElement( this, doc, prop, "method", "DELETE" ); } kdDebug() << k_funcinfo << doc.toString() << endl; KURL url = mPrefs->url(); url.setPath( "/servlet/webdav.contacts/" ); url.setUser( mPrefs->user() ); url.setPass( mPrefs->password() ); mUploadJob = KIO::davPropPatch( url, doc, false ); connect( mUploadJob, SIGNAL( result( KIO::Job * ) ), SLOT( slotUploadResult( KIO::Job * ) ) ); connect( mUploadJob, SIGNAL( percent( KIO::Job *, unsigned long ) ), SLOT( slotProgress( KIO::Job *, unsigned long ) ) ); mUploadProgress = KPIM::ProgressManager::instance()->createProgressItem( KPIM::ProgressManager::getUniqueID(), i18n("Uploading contacts") ); connect( mUploadProgress, SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), SLOT( cancelUpload() ) ); }
KURL NetworkAccount::getUrl() const { KURL url; url.setProtocol(protocol()); url.setUser(login()); url.setPass(passwd()); url.setHost(host()); url.setPort(port()); return url; }
void KMWIpp::updatePrinter(KMPrinter *p) { KURL url; url.setProtocol("ipp"); url.setHost(text(0)); url.setPort(text(1).toInt()); if (!p->option("kde-login").isEmpty()) url.setUser(p->option("kde-login")); if (!p->option("kde-password").isEmpty()) url.setPass(p->option("kde-password")); p->setDevice(url.url()); }
bool ResourceSlox::asyncLoad() { kdDebug() << "KABC::ResourceSlox::asyncLoad()" << endl; if ( mDownloadJob ) { kdDebug() << "KABC::ResourceSlox::asyncLoad(): Loading still in progress." << endl; return true; } loadCache(); clearChanges(); KURL url = mPrefs->url(); url.setPath( "/servlet/webdav.contacts/" ); url.setUser( mPrefs->user() ); url.setPass( mPrefs->password() ); QString lastsync = "0"; if ( mPrefs->useLastSync() ) { QDateTime dt = mPrefs->lastSync(); if ( dt.isValid() ) lastsync = WebdavHandler::qDateTimeToSlox( dt.addDays( -1 ) ); } QDomDocument doc; QDomElement root = WebdavHandler::addDavElement( doc, doc, "propfind" ); QDomElement prop = WebdavHandler::addDavElement( doc, root, "prop" ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( LastSync ), lastsync ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( FolderId ), mPrefs->folderId() ); if ( type() == "ox" ) { WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "NEW_AND_MODIFIED" ); WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "DELETED" ); } else WebdavHandler::addSloxElement( this, doc, prop, fieldName( ObjectType ), "all" ); kdDebug() << "REQUEST CONTACTS: \n" << doc.toString( 2 ) << endl; mDownloadJob = KIO::davPropFind( url, doc, "0", false ); connect( mDownloadJob, SIGNAL( result( KIO::Job * ) ), SLOT( slotResult( KIO::Job * ) ) ); connect( mDownloadJob, SIGNAL( percent( KIO::Job *, unsigned long ) ), SLOT( slotProgress( KIO::Job *, unsigned long ) ) ); mDownloadProgress = KPIM::ProgressManager::instance()->createProgressItem( KPIM::ProgressManager::getUniqueID(), i18n("Downloading contacts") ); connect( mDownloadProgress, SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ), SLOT( cancelDownload() ) ); mPrefs->setLastSync( QDateTime::currentDateTime() ); return true; }
void KSnapshot::closeEvent( QCloseEvent * e ) { KConfig *conf=KGlobal::config(); conf->setGroup("GENERAL"); conf->writeEntry("delay",mainWidget->delay()); conf->writeEntry("mode",mainWidget->mode()); conf->writeEntry("includeDecorations",mainWidget->includeDecorations()); KURL url = filename; url.setPass( QString::null ); conf->writePathEntry("filename",url.url()); e->accept(); }
void KNNetAccess::startJobSmtp() { if(smtpJobQueue.isEmpty()) return; currentSmtpJob = smtpJobQueue.first(); smtpJobQueue.remove(smtpJobQueue.begin()); currentSmtpJob->prepareForExecution(); if(currentSmtpJob->success()) { KNLocalArticle *art = static_cast<KNLocalArticle *>(currentSmtpJob->data()); // create url query part QString query("headers=0&from="); query += KURL::encode_string(art->from()->email()); QStrList emails; art->to()->emails(&emails); for(char *e = emails.first(); e; e = emails.next()) { query += "&to=" + KURL::encode_string(e); } // create url KURL destination; KNServerInfo *account = currentSmtpJob->account(); if(account->encryption() == KNServerInfo::SSL) destination.setProtocol("smtps"); else destination.setProtocol("smtp"); destination.setHost(account->server()); destination.setPort(account->port()); destination.setQuery(query); if(account->needsLogon()) { destination.setUser(account->user()); destination.setPass(account->pass()); } KIO::Job *job = KIO::storedPut(art->encodedContent(true), destination, -1, false, false, false); connect(job, SIGNAL(result(KIO::Job *)), SLOT(slotJobResult(KIO::Job *))); if(account->encryption() == KNServerInfo::TLS) job->addMetaData("tls", "on"); else job->addMetaData("tls", "off"); currentSmtpJob->setJob(job); kdDebug(5003) << "KNNetAccess::startJobSmtp(): job started" << endl; } else { threadDoneSmtp(); } }
KURL Settings::accountUrl() const { KConfig config("scalixadminrc"); KConfigGroup group(&config, "Account"); KURL url; url.setProtocol(group.readBoolEntry("use-ssl") ? "imaps" : "imap"); url.setUser(group.readEntry("user")); url.setPass(KStringHandler::obscure(group.readEntry("pass"))); url.setHost(group.readEntry("host")); url.setPort(group.readNumEntry("port")); return url; }
void KSnapshot::slotOk() { KConfig *conf=KGlobal::config(); conf->setGroup("GENERAL"); conf->writeEntry("delay",mainWidget->delay()); conf->writeEntry("mode",mainWidget->mode()); conf->writeEntry("includeDecorations",mainWidget->includeDecorations()); KURL url = filename; url.setPass( QString::null ); conf->writePathEntry("filename",url.url()); emit screenGrabbed(); accept(); }
void ProjectNewGeneral::slotLinePrjFile( const QString & ) { bool valid = !(linePrjFile->text().isEmpty() || linePrjName->text().isEmpty() || linePrjDir ->text().isEmpty() || linePrjTmpl->text().isEmpty() || linePrjToolbar->text().isEmpty()); KURL url; QString s = lineHost->text(); if (! s.isEmpty()) url.setHost(s); s = lineUser->text(); if (! s.isEmpty()) url.setUser(s); s = linePasswd->text(); if (! s.isEmpty()) url.setPass(s); s = linePort->text(); if (! s.isEmpty()) url.setPort(linePort->text().toInt()); url.setProtocol(comboProtocol->currentText()); if (url.protocol() == i18n("Local")) url.setProtocol("file"); url.setPath(linePrjDir->text()); url.adjustPath(1); if (!url.path().startsWith("/")) url.setPath("/"+url.path()); if (url.isValid()) { emit setBaseURL(url); baseUrl = url; if (baseUrl.isLocalFile()) { s = QExtFileInfo::canonicalPath(baseUrl.path()); if (!s.isEmpty()) baseUrl.setPath(s); } } emit enableNextButton( this, valid ); }
void XMLHttpRequest::makeSimpleCrossSiteAccessRequest(ExceptionCode& ec) { ASSERT(isSimpleCrossSiteAccessRequest()); KURL url = m_url; url.setUser(String()); url.setPass(String()); ResourceRequest request(url); request.setHTTPMethod(m_method); request.setHTTPHeaderField("Access-Control-Origin", accessControlOrigin()); if (m_crossSiteRequestHeaders.size() > 0) request.addHTTPHeaderFields(m_crossSiteRequestHeaders); if (m_async) loadRequestAsynchronously(request); else loadRequestSynchronously(request, ec); }
void XMLHttpRequest::makeSimpleCrossSiteAccessRequest(ExceptionCode& ec) { ASSERT(isSimpleCrossSiteAccessRequest()); KURL url = m_url; url.setUser(String()); url.setPass(String()); ResourceRequest request(url); request.setHTTPMethod(m_method); request.setAllowHTTPCookies(m_includeCredentials); request.setHTTPOrigin(scriptExecutionContext()->securityOrigin()->toString()); if (m_requestHeaders.size() > 0) request.addHTTPHeaderFields(m_requestHeaders); if (m_async) loadRequestAsynchronously(request); else loadRequestSynchronously(request, ec); }
static KURL findUrlForAccount(const KMail::ImapAccountBase *a) { assert(a); const KMail::SieveConfig sieve = a->sieveConfig(); if(!sieve.managesieveSupported()) return KURL(); if(sieve.reuseConfig()) { // assemble Sieve url from the settings of the account: KURL u; u.setProtocol("sieve"); u.setHost(a->host()); u.setUser(a->login()); u.setPass(a->passwd()); u.setPort(sieve.port()); // Translate IMAP LOGIN to PLAIN: u.setQuery("x-mech=" + (a->auth() == "*" ? "PLAIN" : a->auth())); return u; } else { return sieve.alternateURL(); } }
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; } } }
void Project::slotRemove(const KURL& urlToRemove) { emit statusMsg(i18n("Removing files...")); progressBar->setTotalSteps(d->m_projectFiles.count()); progressBar->setValue(0); progressBar->setTextEnabled(true); KURL url; bool isFolder = d->m_projectFiles.isFolder(urlToRemove); ProjectList projectFiles = d->m_projectFiles; ProjectList::Iterator it(projectFiles); for ( ; it.current(); ++it) { url = *(it.current()); if (urlToRemove == url || (isFolder && urlToRemove.isParentOf(url)) ) { d->m_projectFiles.removeFromListAndXML(url); d->m_modified = true; emit eventHappened("after_project_remove", url.url(), QString::null); if (!isFolder) break; } progressBar->advance(1); } progressBar->setTotalSteps(1); progressBar->setValue(0); progressBar->setTextEnabled(false); emit statusMsg(QString::null); if (d->m_modified) setModified(); // there happens more than setting the flag ! emit reloadTree( &(d->m_projectFiles), false, QStringList() ); emit newStatus(); QString urlPath = QExtFileInfo::toRelative(urlToRemove, d->baseURL).path(); QString nice = urlPath; nice = KStringHandler::lsqueeze(nice, 60); if (KMessageBox::warningContinueCancel(d->m_mainWindow, i18n("<qt>Do you want to remove <br><b>%1</b><br> from the server(s) as well?</qt>").arg(nice), i18n("Remove From Server"), KStdGuiItem::remove(), "RemoveFromServer") == KMessageBox::Continue ) { QDomNode profilesNode = d->m_sessionDom.firstChild().firstChild().namedItem("uploadprofiles"); QDomNodeList profileList = profilesNode.toElement().elementsByTagName("profile"); QDomElement e; QString s; for (uint i = 0; i < profileList.count(); i++) { e = profileList.item(i).toElement(); QString path = e.attribute("remote_path",""); if (!path.startsWith("/")) path.prepend("/"); KURL baseUrl; baseUrl.setProtocol(e.attribute("remote_protocol","ftp")); baseUrl.setPort(e.attribute("remote_port","").toInt()); baseUrl.setHost(e.attribute("remote_host","")); baseUrl.setPath(path); baseUrl.setUser(e.attribute("user","")); QString passwd = password(e.attribute("remote_protocol") + "://" + e.attribute("user") + "@" + e.attribute("remote_host")); baseUrl.setPass(passwd); baseUrl.addPath(urlPath); KIO::NetAccess::del(baseUrl, d->m_mainWindow); } } }
void XMLHttpRequest::makeCrossSiteAccessRequestWithPreflight(ExceptionCode& ec) { String origin = scriptExecutionContext()->securityOrigin()->toString(); KURL url = m_url; url.setUser(String()); url.setPass(String()); if (!PreflightResultCache::shared().canSkipPreflight(origin, url, m_includeCredentials, m_method, m_requestHeaders)) { m_inPreflight = true; ResourceRequest preflightRequest(url); preflightRequest.setHTTPMethod("OPTIONS"); preflightRequest.setHTTPHeaderField("Origin", origin); preflightRequest.setHTTPHeaderField("Access-Control-Request-Method", m_method); if (m_requestHeaders.size() > 0) { Vector<UChar> headerBuffer; HTTPHeaderMap::const_iterator it = m_requestHeaders.begin(); append(headerBuffer, it->first); ++it; HTTPHeaderMap::const_iterator end = m_requestHeaders.end(); for (; it != end; ++it) { headerBuffer.append(','); headerBuffer.append(' '); append(headerBuffer, it->first); } preflightRequest.setHTTPHeaderField("Access-Control-Request-Headers", String::adopt(headerBuffer)); preflightRequest.addHTTPHeaderFields(m_requestHeaders); } if (m_async) { loadRequestAsynchronously(preflightRequest); return; } loadRequestSynchronously(preflightRequest, ec); m_inPreflight = false; if (ec) return; } // Send the actual request. ResourceRequest request(url); request.setHTTPMethod(m_method); request.setAllowHTTPCookies(m_includeCredentials); request.setHTTPHeaderField("Origin", origin); if (m_requestHeaders.size() > 0) request.addHTTPHeaderFields(m_requestHeaders); if (m_requestEntityBody) { ASSERT(m_method != "GET"); request.setHTTPBody(m_requestEntityBody.release()); } if (m_async) { loadRequestAsynchronously(request); return; } loadRequestSynchronously(request, ec); }