AtomicURL::AtomicURL( const KURL &url ) { if( url.isEmpty() ) return; QString s = url.protocol() + "://"; QString host = url.host(); if( url.hasUser() ) { s += url.user(); host.prepend("@"); } if( url.hasPass() ) s += ':' + url.pass(); if( url.port() ) host += QString(":") + QString::number( url.port() ); m_beginning = s + host; m_directory = url.directory(); m_filename = url.fileName(); m_end = url.query(); if( url.hasRef() ) m_end += QString("#") + url.ref(); if (url != this->url()) { debug() << "from: " << url << endl; debug() << "to: " << this->url() << endl; } }
static String originStringFromURL(const KURL& url) { if (url.port()) return url.protocol() + "://" + url.host() + ':' + String::number(url.port()) + '/'; return url.protocol() + "://" + url.host() + '/'; }
bool protocolHostAndPortAreEqual(const KURL& a, const KURL& b) { if (a.parsed().scheme.end() != b.parsed().scheme.end()) return false; int hostStartA = a.hostStart(); int hostLengthA = a.hostEnd() - hostStartA; int hostStartB = b.hostStart(); int hostLengthB = b.hostEnd() - b.hostStart(); if (hostLengthA != hostLengthB) return false; // Check the scheme for (int i = 0; i < a.parsed().scheme.end(); ++i) if (a.string()[i] != b.string()[i]) return false; // And the host for (int i = 0; i < hostLengthA; ++i) if (a.string()[hostStartA + i] != b.string()[hostStartB + i]) return false; if (a.port() != b.port()) return false; return true; }
bool protocolHostAndPortAreEqual(const KURL& a, const KURL& b) { if (a.parsed().scheme.end() != b.parsed().scheme.end()) return false; int hostStartA = a.hostStart(); int hostStartB = b.hostStart(); if (a.hostEnd() - hostStartA != b.hostEnd() - hostStartB) return false; // Check the scheme for (int i = 0; i < a.parsed().scheme.end(); ++i) if (a.string()[i] != b.string()[i]) return false; // And the host for (int i = hostStartA; i < static_cast<int>(a.hostEnd()); ++i) if (a.string()[i] != b.string()[i]) return false; if (a.port() != b.port()) return false; return true; }
QString Groupwise::soapUrl(const KURL &url) { // FIXME: Get SSL from parameter bool useSsl = url.protocol() == "groupwises"; QString u; if(useSsl) u = "https"; else u = "http"; u += "://" + url.host() + ":"; if(url.port()) u += QString::number(url.port()); else { u += "7191"; } // check for a soap path in the URL // assume that if a path to soap is included in the URL, // it will be at the start of the path, eg. // groupwise://host:port/soap2/freebusy if(!(url.path().startsWith("/freebusy/") || url.path().startsWith("/calendar/") || url.path().startsWith("/addressbook/"))) { QString soapPath = QString("/") + QStringList::split('/', url.path())[0]; u += soapPath; } else u += "/soap"; return u; }
String DOMURLUtilsReadOnly::host(const KURL& kurl) { if (kurl.hostEnd() == kurl.pathStart()) return kurl.host(); if (isDefaultPortForProtocol(kurl.port(), kurl.protocol())) return kurl.host(); return kurl.host() + ":" + String::number(kurl.port()); }
bool protocolHostAndPortAreEqual(const KURL& a, const KURL& b) { if (!a.isValid() || !b.isValid()) return false; return a.protocol() == b.protocol() && a.host() == b.host() && a.port() == b.port(); }
static String hostName(const KURL& url, bool secure) { ASSERT(url.protocolIs("wss") == secure); StringBuilder builder; builder.append(url.host().lower()); if (url.port() && ((!secure && url.port() != 80) || (secure && url.port() != 443))) { builder.append(':'); builder.append(String::number(url.port())); } return builder.toString(); }
SocketStreamHandle::SocketStreamHandle(const KURL& url, Page* page, SocketStreamHandleClient* client) : SocketStreamHandleBase(url, client) { String host = url.host(); bool ssl = url.protocolIs("wss"); int port = url.hasPort() ? url.port() : (ssl ? 443 : 80); JNIEnv* env = WebCore_GetJavaEnv(); static jmethodID mid = env->GetStaticMethodID( GetSocketStreamHandleClass(env), "fwkCreate", "(Ljava/lang/String;IZLcom/sun/webkit/WebPage;J)" "Lcom/sun/webkit/network/SocketStreamHandle;"); ASSERT(mid); m_ref = JLObject(env->CallStaticObjectMethod( GetSocketStreamHandleClass(env), mid, (jstring) host.toJavaString(env), port, bool_to_jbool(ssl), (jobject) WebPage::jobjectFromPage(page), ptr_to_jlong(this))); CheckAndClearException(env); }
void KIO_Delete::deleteItem( const KornMailId *item, KURL kurl, KIO::MetaData metadata, const KIO_Protocol *& protocol ) { KIO::Job* job = 0; kurl = dynamic_cast<const KornStringId*>( item )->getId(); protocol->deleteMailKURL( kurl, metadata ); if( kurl.port() == 0 ) kurl.setPort( protocol->defaultPort( _kio->_ssl ) ); if( protocol->deleteFunction() == KIO_Protocol::get ) { job = KIO::get( kurl, true, false ); if( protocol->connectionBased() ) KIO::Scheduler::assignJobToSlave( _slave, dynamic_cast< KIO::SimpleJob* >( job ) ); else KIO::Scheduler::scheduleJob( dynamic_cast< KIO::SimpleJob* >( job ) ); } else if( protocol->deleteFunction() == KIO_Protocol::del ) { job = KIO::del( kurl, false, false ); } else return; //Unknown deleteFunction connect( job, SIGNAL( result( KIO::Job* ) ), this, SLOT( slotResult( KIO::Job* ) ) ); job->addMetaData( metadata ); _jobs->append( dynamic_cast< KIO::Job* >( job ) ); }
void FrameFetchContext::upgradeInsecureRequest(FetchRequest& fetchRequest) { KURL url = fetchRequest.resourceRequest().url(); // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational requests, as described in // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect if (fetchRequest.resourceRequest().frameType() != WebURLRequest::FrameTypeNone) fetchRequest.mutableResourceRequest().addHTTPHeaderField("Upgrade-Insecure-Requests", "1"); if (m_document && m_document->insecureRequestsPolicy() == SecurityContext::InsecureRequestsUpgrade && url.protocolIs("http")) { ASSERT(m_document->insecureNavigationsToUpgrade()); // We always upgrade requests that meet any of the following criteria: // // 1. Are for subresources (including nested frames). // 2. Are form submissions. // 3. Whose hosts are contained in the document's InsecureNavigationSet. const ResourceRequest& request = fetchRequest.resourceRequest(); if (request.frameType() == WebURLRequest::FrameTypeNone || request.frameType() == WebURLRequest::FrameTypeNested || request.requestContext() == WebURLRequest::RequestContextForm || (!url.host().isNull() && m_document->insecureNavigationsToUpgrade()->contains(url.host().impl()->hash()))) { UseCounter::count(m_document, UseCounter::UpgradeInsecureRequestsUpgradedRequest); url.setProtocol("https"); if (url.port() == 80) url.setPort(443); fetchRequest.mutableResourceRequest().setURL(url); } } }
bool portMatches(const KURL& url) const { if (m_portHasWildcard) return true; int port = url.port(); return port ? port == m_port : isDefaultPortForProtocol(m_port, url.protocol()); }
IconURL IconController::defaultURL(IconType iconType) { // Don't return a favicon iconURL unless we're http or https KURL documentURL = m_frame->document()->url(); if (!documentURL.protocolIsInHTTPFamily()) return IconURL(); KURL url; bool couldSetProtocol = url.setProtocol(documentURL.protocol()); ASSERT_UNUSED(couldSetProtocol, couldSetProtocol); url.setHost(documentURL.host()); if (documentURL.hasPort()) url.setPort(documentURL.port()); if (iconType == Favicon) { url.setPath("/favicon.ico"); return IconURL::defaultIconURL(url, Favicon); } #if ENABLE(TOUCH_ICON_LOADING) if (iconType == TouchPrecomposedIcon) { url.setPath("/apple-touch-icon-precomposed.png"); return IconURL::defaultIconURL(url, TouchPrecomposedIcon); } if (iconType == TouchIcon) { url.setPath("/apple-touch-icon.png"); return IconURL::defaultIconURL(url, TouchIcon); } #endif return IconURL(); }
String DOMURLUtilsReadOnly::port(const KURL& kurl) { if (kurl.hasPort()) return String::number(kurl.port()); return emptyString(); }
KProtocolProxyFTP::KProtocolProxyFTP () { use_proxy = 0; int port = 80; QString proxyStr; QString tmp; KURL proxyURL; // All right. Now read the proxy settings // KSimpleConfig prxcnf(KApplication::localconfigdir() + "/kfmrc"); // Read Only KSimpleConfig prxcnf(KApplication::localconfigdir() + "/kfmrc", true ); prxcnf.setGroup("Browser Settings/Proxy"); noProxyForStr = prxcnf.readEntry("NoProxyFor"); tmp = prxcnf.readEntry( "UseProxy" ); if ( tmp == "Yes" ) { // Do we need proxy? proxyStr = prxcnf.readEntry( "FTP-Proxy" ); proxyURL = proxyStr.data(); // printf( "Using ftp proxy %s on port %d\n", proxyURL.host(), proxyURL.port() ); port = proxyURL.port(); if ( port == 0 ) port = 80; proxy_user = prxcnf.readEntry( "Proxy-User" ); proxy_pass = prxcnf.readEntry( "Proxy-Pass" ); init_sockaddr(&proxy_name, proxyURL.host(), port); use_proxy = 1; } }
void FrameFetchContext::upgradeInsecureRequest(FetchRequest& fetchRequest) { KURL url = fetchRequest.resourceRequest().url(); // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational requests, as described in // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect if (fetchRequest.resourceRequest().frameType() != WebURLRequest::FrameTypeNone) fetchRequest.mutableResourceRequest().addHTTPHeaderField("Upgrade-Insecure-Requests", "1"); // If we don't yet have an |m_document| (because we're loading an iframe, for instance), check the FrameLoader's policy. WebInsecureRequestPolicy relevantPolicy = m_document ? m_document->getInsecureRequestPolicy() : frame()->loader().getInsecureRequestPolicy(); SecurityContext::InsecureNavigationsSet* relevantNavigationSet = m_document ? m_document->insecureNavigationsToUpgrade() : frame()->loader().insecureNavigationsToUpgrade(); if (url.protocolIs("http") && relevantPolicy & kUpgradeInsecureRequests) { // We always upgrade requests that meet any of the following criteria: // // 1. Are for subresources (including nested frames). // 2. Are form submissions. // 3. Whose hosts are contained in the document's InsecureNavigationSet. const ResourceRequest& request = fetchRequest.resourceRequest(); if (request.frameType() == WebURLRequest::FrameTypeNone || request.frameType() == WebURLRequest::FrameTypeNested || request.requestContext() == WebURLRequest::RequestContextForm || (!url.host().isNull() && relevantNavigationSet->contains(url.host().impl()->hash()))) { UseCounter::count(m_document, UseCounter::UpgradeInsecureRequestsUpgradedRequest); url.setProtocol("https"); if (url.port() == 80) url.setPort(443); fetchRequest.mutableResourceRequest().setURL(url); } } }
KURL SiteSettings::effectiveURL() const { KURL url = KURL::fromPathOrURL(mUrl); if(url.port() == 0) { url.setPort(80); } return url; }
KURL Proxy::realStreamUrl( KURL fakeStream, int sessionId ) { KURL realStream; realStream.setProtocol( "http" ); realStream.setHost(fakeStream.host()); realStream.setPort(fakeStream.port()); realStream.setPath( "/databases" + fakeStream.directory() + "/items/" + fakeStream.fileName() ); realStream.setQuery( QString("?session-id=") + QString::number(sessionId) ); return realStream; }
/* bundle->setUrl( Amarok::QStringx("http://%1:3689/databases/%2/items/%3.%4?%5").args( QStringList() << m_host << m_databaseId << QString::number( (*it).asMap()["miid"].asList()[0].asInt() ) << (*it).asMap()["asfm"].asList()[0].asString() << m_loginString ) ); */ Proxy::Proxy(KURL stream, DaapClient* client, const char* name) : QObject(client, name) , m_proxy( new Amarok::ProcIO() ) { DEBUG_BLOCK //find the request id and increment it const QString hostKey = stream.host() + ':' + QString::number(stream.port()); const int revisionId = client->incRevision( hostKey ); const int sessionId = client->getSession( hostKey ); //compose URL KURL realStream = realStreamUrl( stream, sessionId ); //get hash char hash[33] = {0}; GenerateHash( 3 , reinterpret_cast<const unsigned char*>((realStream.path() + realStream.query()).ascii()) , 2 , reinterpret_cast<unsigned char*>(hash) , revisionId ); // Find free port MyServerSocket* socket = new MyServerSocket(); const int port = socket->port(); debug() << "Proxy server using port: " << port << endl; delete socket; m_proxyUrl = KURL( QString("http://localhost:%1/daap.mp3").arg( port ) ); //start proxy m_proxy->setComm( KProcess::Communication( KProcess::AllOutput ) ); *m_proxy << "amarok_proxy.rb"; *m_proxy << "--daap"; *m_proxy << QString::number( port ); *m_proxy << realStream.url(); *m_proxy << AmarokConfig::soundSystem(); *m_proxy << hash; *m_proxy << QString::number( revisionId ); *m_proxy << Amarok::proxyForUrl( realStream.url() ); if( !m_proxy->start( KProcIO::NotifyOnExit, true ) ) { error() << "Failed to start amarok_proxy.rb" << endl; return; } QString line; while( true ) { kapp->processEvents(); m_proxy->readln( line ); if( line == "AMAROK_PROXY: startup" ) break; } debug() << "started amarok_proxy.rb --daap " << QString::number( port ) << ' ' << realStream.url() << ' ' << AmarokConfig::soundSystem() << ' ' << hash << ' ' << revisionId << endl; connect( m_proxy, SIGNAL( processExited( KProcess* ) ), this, SLOT( playbackStopped() ) ); connect( m_proxy, SIGNAL( readReady( KProcIO* ) ), this, SLOT( readProxy() ) ); }
bool CSPSource::matches(const KURL& url, ResourceRequest::RedirectStatus redirectStatus) const { bool schemesMatch = m_scheme.isEmpty() ? m_policy->protocolMatchesSelf(url) : schemeMatches(url.protocol()); if (!schemesMatch) return false; if (isSchemeOnly()) return true; bool pathsMatch = (redirectStatus == RedirectStatus::FollowedRedirect) || pathMatches(url.path()); return hostMatches(url.host()) && portMatches(url.port(), url.protocol()) && pathsMatch; }
SocketStreamHandle::SocketStreamHandle(const KURL& url, SocketStreamHandleClient* client) : SocketStreamHandleBase(url, client) , m_readBuffer(0) { unsigned int port = url.hasPort() ? url.port() : (url.protocolIs("wss") ? 443 : 80); m_id = activateHandle(this); GRefPtr<GSocketClient> socketClient = adoptGRef(g_socket_client_new()); if (url.protocolIs("wss")) g_socket_client_set_tls(socketClient.get(), TRUE); g_socket_client_connect_to_host_async(socketClient.get(), url.host().utf8().data(), port, 0, reinterpret_cast<GAsyncReadyCallback>(connectedCallback), m_id); }
RemoteService::RemoteService(const KURL& url) { d = new RemoteServicePrivate(); if (!url.isValid()) return; if (url.protocol()!="invitation") return; if (!url.hasPath()) return; m_hostName = url.host(); m_port = url.port(); m_type = url.path().section('/',1,1); m_serviceName = url.path().section('/',2); m_textData = url.queryItems(); d->m_resolved=true; }
PrintcapEntry* LprHandler::createEntry(KMPrinter *prt) { // this default handler only supports local parallel and remote lpd URIs KURL uri ( prt->device() ); QString prot = uri.protocol(); if (!prot.isEmpty() && prot != "parallel" && prot != "file" && prot != "lpd" && prot != "socket") { manager()->setErrorMsg(i18n("Unsupported backend: %1.").arg(prot)); return NULL; } PrintcapEntry *entry = new PrintcapEntry; entry->comment = "# Default handler"; if (prot == "lpd") { entry->addField("rm", Field::String, uri.host()); QString rp = uri.path(); if (rp[0] == '/') rp = rp.mid(1); entry->addField("rp", Field::String, rp); // force this entry to null (otherwise it seems it's redirected // to /dev/lp0 by default) entry->addField("lp", Field::String, QString::null); } else if ( prot == "socket" ) { QString lp = uri.host(); if ( uri.port() == 0 ) lp.append( "%9100" ); else lp.append( "%" ).append( QString::number( uri.port() ) ); entry->addField("lp", Field::String, lp); } else { entry->addField("lp", Field::String, uri.path()); } return entry; }
IconURL IconURL::defaultFavicon(const KURL& documentURL) { DCHECK(documentURL.protocolIsInHTTPFamily()); KURL url; bool couldSetProtocol = url.setProtocol(documentURL.protocol()); DCHECK(couldSetProtocol); url.setHost(documentURL.host()); if (documentURL.hasPort()) url.setPort(documentURL.port()); url.setPath("/favicon.ico"); IconURL result(url, Vector<IntSize>(), emptyString(), Favicon); result.m_isDefaultIcon = true; return result; }
bool XMLHttpRequest::urlMatchesDocumentDomain(const KURL& url) const { KURL documentURL(m_doc->URL()); // a local file can load anything if (documentURL.protocol().lower() == "file") return true; // but a remote document can only load from the same port on the server if (documentURL.protocol().lower() == url.protocol().lower() && documentURL.host().lower() == url.host().lower() && documentURL.port() == url.port()) return true; return false; }
bool KIO_Delete::setupSlave( KURL kurl, KIO::MetaData metadata, const KIO_Protocol *& protocol ) { protocol->deleteMailConnectKURL( kurl, metadata ); if( kurl.port() == 0 ) kurl.setPort( protocol->defaultPort( _kio->_ssl ) ); if( ! ( _slave = KIO::Scheduler::getConnectedSlave( kurl, metadata ) ) ) { kdWarning() << i18n( "Could not get a connected slave; I cannot delete this way..." ) << endl; _valid = false; return false; } return true; }
SocketStreamHandlePrivate::SocketStreamHandlePrivate(SocketStreamHandle* streamHandle, const KURL& url) :m_streamHandle(streamHandle) ,m_maxPendingSendingAllowed(0) ,m_pendingAmountSent(0) { m_isSecure = url.protocolIs("wss"); m_port = url.hasPort() ? url.port() : (m_isSecure ? 443 : 80); m_url = std::string(url.string().utf8().data(), url.string().utf8().length()); net::WebSocketJob::EnsureInit(); m_sockhost = new SocketStreamHost(this, 0); connect(); }
void KMWIppSelect::initPrinter(KMPrinter *p) { // storage variables QString host, login, password; int port; // save config host = CupsInfos::self()->host(); login = CupsInfos::self()->login(); password = CupsInfos::self()->password(); port = CupsInfos::self()->port(); m_list->clear(); // retrieve printer list KURL url = p->device(); CupsInfos::self()->setHost(url.host()); CupsInfos::self()->setLogin(url.user()); CupsInfos::self()->setPassword(url.pass()); CupsInfos::self()->setPort(url.port()); IppRequest req; QString uri; req.setOperation(CUPS_GET_PRINTERS); uri = QString::fromLatin1("ipp://%1/printers/").arg(CupsInfos::self()->hostaddr()); req.addURI(IPP_TAG_OPERATION,"printer-uri",uri); req.addKeyword(IPP_TAG_OPERATION,"requested-attributes",QString::fromLatin1("printer-name")); if (req.doRequest("/printers/")) { ipp_attribute_t *attr = req.first(); while (attr) { if (attr->name && strcmp(attr->name,"printer-name") == 0) m_list->insertItem(SmallIcon("kdeprint_printer"),QString::fromLatin1(attr->values[0].string.text)); attr = attr->next; } m_list->sort(); } // restore config CupsInfos::self()->setHost(host); CupsInfos::self()->setLogin(login); CupsInfos::self()->setPassword(password); CupsInfos::self()->setPort(port); }
/* * Some protocols needs to a command to commit protocols. */ void KIO_Delete::commitDelete( KURL kurl, KIO::MetaData metadata, const KIO_Protocol *& protocol ) { protocol->deleteCommitKURL( kurl, metadata ); if( kurl.port() == 0 ) kurl.setPort( protocol->defaultPort( _kio->_ssl ) ); KIO::TransferJob *job = KIO::get( kurl, true, false ); job->addMetaData( metadata ); connect( job, SIGNAL( result( KIO::Job* ) ), this, SLOT( slotResult( KIO::Job* ) ) ); _jobs->append( dynamic_cast< KIO::Job* >( job ) ); if( protocol->connectionBased() ) KIO::Scheduler::assignJobToSlave( _slave, job ); else KIO::Scheduler::scheduleJob( job ); _total++; }
IconURL IconController::defaultURL(IconType iconType) { // Don't return a favicon iconURL unless we're http or https KURL documentURL = m_frame->document()->url(); if (!documentURL.protocolIsInHTTPFamily()) return IconURL(); KURL url; bool couldSetProtocol = url.setProtocol(documentURL.protocol()); ASSERT_UNUSED(couldSetProtocol, couldSetProtocol); url.setHost(documentURL.host()); if (documentURL.hasPort()) url.setPort(documentURL.port()); if (iconType == Favicon) { url.setPath("/favicon.ico"); return IconURL::defaultIconURL(url, Favicon); } return IconURL(); }