QT_BEGIN_NAMESPACE QNetworkAccessBackend * QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op, const QNetworkRequest &request) const { // is it an operation we know of? switch (op) { case QNetworkAccessManager::GetOperation: case QNetworkAccessManager::PutOperation: break; default: // no, we can't handle this operation return 0; } QUrl url = request.url(); if (url.scheme() == QLatin1String("qrc") || !url.toLocalFile().isEmpty()) return new QNetworkAccessFileBackend; else if (!url.isEmpty() && url.authority().isEmpty()) { // check if QFile could, in theory, open this URL QFileInfo fi(url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery)); if (fi.exists() || (op == QNetworkAccessManager::PutOperation && fi.dir().exists())) return new QNetworkAccessFileBackend; } return 0; }
/** * Supports only rendering of local files and resources that can be downloaded over * the http protocol. In the latter case the download gets started. */ void TextBrowser::setSource (const QUrl& url) { bool relativeUrl = url.isRelative(); if (!relativeUrl) d->source = url; // last set absolute url QString name = url.toString(); if (url.scheme() == QLatin1String("http")) { // start the download but do not call setSource() of the base // class because we must wait until the data are available. // The slot done() is invoked automatically then. d->http->setHost(url.host()); d->http->get(url.path(), 0); } else if (d->source.scheme() == QLatin1String("http")) { // relative hyperlink in previously downloaded a HTML page d->source = d->source.resolved(url); d->http->get(url.path(), 0); } else { QUrl resolved = url; #if defined (Q_OS_WIN) if (url.scheme() == QLatin1String("file") && !url.isRelative()) { QString auth = url.authority(); QString path = url.path(); //If we click on a hyperlink with a reference to an absolute file name //then we get a string that cannot be used to open the file. So we try //to reproduce the original url. if (!auth.isEmpty() && !path.isEmpty()) { QString fileName = auth + QLatin1Char(':') + path; resolved = QUrl::fromLocalFile(fileName); } } #endif QTextBrowser::setSource(resolved); } }
QString QUrlProto::authority() const { QUrl *item = qscriptvalue_cast<QUrl*>(thisObject()); if (item) return item->authority(); return QString(); }
QString MybbFeedRequest::getRedirect(const QNetworkReply *reply) { QString redirect = QString::fromUtf8(reply->rawHeader("Location")); if ((!redirect.isEmpty()) && (!redirect.startsWith("http"))) { const QUrl url = reply->url(); if (redirect.startsWith("/")) { redirect.prepend(url.scheme() + "://" + url.authority()); } else { redirect.prepend(url.scheme() + "://" + url.authority() + "/"); } } return redirect; }
bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) { if (lookupUrl.scheme() == HIFI_URL_SCHEME) { qCDebug(networking) << "Trying to go to URL" << lookupUrl.toString(); DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::LookupAddress); // there are 4 possible lookup strings // 1. global place name (name of domain or place) - example: sanfrancisco // 2. user name (prepended with @) - example: @philip // 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ) // 4. domain network address (IP or dns resolvable hostname) // use our regex'ed helpers to figure out what we're supposed to do with this if (!handleUsername(lookupUrl.authority())) { // we're assuming this is either a network address or global place name // check if it is a network address first bool hostChanged; if (handleNetworkAddress(lookupUrl.host() + (lookupUrl.port() == -1 ? "" : ":" + QString::number(lookupUrl.port())), trigger, hostChanged)) { // If the host changed then we have already saved to history if (hostChanged) { trigger = Internal; } // if we were not passed a path, use the index path auto path = lookupUrl.path(); if (path.isEmpty()) { path = INDEX_PATH; } // we may have a path that defines a relative viewpoint - if so we should jump to that now handlePath(path, trigger); } else if (handleDomainID(lookupUrl.host())){ // no place name - this is probably a domain ID // try to look up the domain ID on the metaverse API attemptDomainIDLookup(lookupUrl.host(), lookupUrl.path(), trigger); } else { // wasn't an address - lookup the place name // we may have a path that defines a relative viewpoint - pass that through the lookup so we can go to it after attemptPlaceNameLookup(lookupUrl.host(), lookupUrl.path(), trigger); } } return true; } else if (lookupUrl.toString().startsWith('/')) { qCDebug(networking) << "Going to relative path" << lookupUrl.path(); // if this is a relative path then handle it as a relative viewpoint handlePath(lookupUrl.path(), trigger, true); emit lookupResultsFinished(); return true; } return false; }
void SidebarPrivate::linkClickedFinished() { QNetworkReply * reply = static_cast< QNetworkReply * >(sender()); QString target = reply->property("__target").toString(); QVariant redirectsVariant = reply->property("__redirects"); int redirects = redirectsVariant.isNull() ? 20 : redirectsVariant.toInt(); // Redirect? QUrl redirectedUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); if (redirectedUrl.isValid()) { if (redirectedUrl.isRelative()) { QUrl oldUrl = reply->url(); redirectedUrl.setScheme(oldUrl.scheme()); redirectedUrl.setAuthority(oldUrl.authority()); } if (redirects > 0) { QNetworkRequest request = reply->request(); request.setUrl(redirectedUrl); QNetworkReply * reply = networkAccessManager()->get(request); reply->setProperty("__target", target); connect(reply, SIGNAL(finished()), this, SLOT(linkClickedFinished())); } else { // TOO MANY REDIRECTS } reply->deleteLater(); return; } // Check headers... if PDF then launch a new window, otherwise give it to the OS QString contentType(reply->header(QNetworkRequest::ContentTypeHeader).toString()); if (contentType.contains("application/pdf")) { emit urlRequested(reply->request().url(), "tab"); } else { QUrl href(reply->request().url()); if (href.isValid()) { if (href.scheme() == "http" || href.scheme() == "https") { if (target == "sidebar") { webView->setUrl(href); slideLayout->push("web"); return; } } QDesktopServices::openUrl(href); } // FIXME error } reply->deleteLater(); }
void Shotgun::setBaseUrl(const QUrl url) { if (m_baseUrl != url) { m_baseUrl = url; m_config.apiUrl.setScheme(url.scheme()); m_config.apiUrl.setHost(url.host()); m_config.apiUrl.setPath(url.path() + "/" + m_config.apiVer + "/json"); m_config.authorization = QString("Basic " + url.authority()).toUtf8().toBase64(); emit baseUrlChanged(m_baseUrl); } }
bool Folder::init() { Account *account = AccountManager::instance()->account(); if (!account) { // Normaly this should not happen, but it could be that there is something // wrong with the config and it is better not to crash. qWarning() << "WRN: No account configured, can't sync"; return false; } // We need to reconstruct the url because the path need to be fully decoded, as csync will re-encode the path: // Remember that csync will just append the filename to the path and pass it to the vio plugin. // csync_owncloud will then re-encode everything. #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QUrl url = remoteUrl(); QString url_string = url.scheme() + QLatin1String("://") + url.authority(QUrl::EncodeDelimiters) + url.path(QUrl::FullyDecoded); #else // Qt4 was broken anyway as it did not encode the '#' as it should have done (it was actually a provlem when parsing the path from QUrl::setPath QString url_string = remoteUrl().toString(); #endif url_string = Utility::toCSyncScheme(url_string); QString localpath = path(); if( csync_create( &_csync_ctx, localpath.toUtf8().data(), url_string.toUtf8().data() ) < 0 ) { qDebug() << "Unable to create csync-context!"; slotSyncError(tr("Unable to create csync-context")); _csync_ctx = 0; } else { csync_set_log_callback( csyncLogCatcher ); csync_set_log_level( 11 ); if (Account *account = AccountManager::instance()->account()) { account->credentials()->syncContextPreInit(_csync_ctx); } else { qDebug() << Q_FUNC_INFO << "No default Account object, huh?"; } if( csync_init( _csync_ctx ) < 0 ) { qDebug() << "Could not initialize csync!" << csync_get_status(_csync_ctx) << csync_get_status_string(_csync_ctx); QString errStr = SyncEngine::csyncErrorToString(CSYNC_STATUS(csync_get_status(_csync_ctx))); const char *errMsg = csync_get_status_string(_csync_ctx); if( errMsg ) { errStr += QLatin1String("<br/>"); errStr += QString::fromUtf8(errMsg); } slotSyncError(errStr); csync_destroy(_csync_ctx); _csync_ctx = 0; } } return _csync_ctx; }
void DeviceFinder::findDevice(const QUrl &descriptionDocumentURL) { if (m_searching) { qDebug() << "DeviceFinder: already searching"; return; } m_baseURL.clear(); m_baseURL.setScheme(descriptionDocumentURL.scheme()); m_baseURL.setAuthority(descriptionDocumentURL.authority()); m_networkAccess.get(QNetworkRequest(descriptionDocumentURL)); }
void Downloader::downloadFiles() { this->statusLabelText = ""; this->downloadFailures = 0; this->downloadSuccesses = 0; this->downloadAborts = 0; for (unsigned int i = 0; i < urlLineEditVector.size(); ++i) { QUrl url = QUrl(urlLineEditVector.at(i)->text()); QString fullUrlString = url.scheme() + "://" + url.authority() + url.path(); DEBUG("url : " << fullUrlString.toStdString().c_str()); DEBUG("savePaths->at(" << i << ") : " << savePaths->at(i).toStdString().c_str()); if (!this->silent) { DEBUG(QObject::tr("Downloading %1").arg(fullUrlString).toStdString().c_str()); DEBUG(QObject::tr("Saving to %1").arg(this->savePaths->at(i)).toStdString().c_str()); } this->httpClients.at(i) = new HttpWindow(this, url, this->savePaths->at(i)); this->httpClients.at(i)->exec(); if (this->httpClients.at(i)->downloadSuccessful()) { this->downloadSuccesses++; DEBUG(tr("Download of %1 succeded.").arg(QFileInfo(this->savePaths->at(i)).fileName()).toStdString()); if (!this->silent) { //LOG(INFO, tr("Scaricato %1").arg(QFileInfo(this->savePaths->at(i)).fileName())); } } else if(this->httpClients.at(i)->aborted()) { this->downloadAborts++; DEBUG(tr("Download of %1 aborted.").arg(QFileInfo(this->savePaths->at(i)).fileName()).toStdString()); LOG(WARN, tr("Scaricamento di %1 interrotto.").arg(QFileInfo(this->savePaths->at(i)).fileName())); } else { this->downloadFailures++; DEBUG(tr("Download of %1 failed.").arg(QFileInfo(this->savePaths->at(i)).fileName()).toStdString()); LOG(ERR, tr("Scaricamento di %1 fallito.").arg(QFileInfo(this->savePaths->at(i)).fileName())); } DEBUG(tr("Download successes : %1").arg(my::toQString<unsigned int>(this->downloadSuccesses)).toStdString().c_str()); DEBUG(tr("Download failures : %1").arg(my::toQString<unsigned int>(this->downloadFailures)).toStdString().c_str()); if (this->downloadSuccesses == this->savePaths->size()) { this->close(); } else { /* * TODO */ } } }
HttpWindow::HttpWindow(QWidget *parent, QUrl _url, QString _savePath) : QDialog(parent) { this->setFont(THE_REPO->fontVariableWidthSmall); this->fullUrlString = _url.scheme() + "://" + _url.authority() + _url.path(); this->downloadSuccess = false; this->uploadFlag = false; this->savePath = _savePath; progressDialog = new QProgressDialog(this); connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*))); connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); this->downloadFile(); }
bool Folder::init() { // We need to reconstruct the url because the path needs to be fully decoded, as csync will re-encode the path: // Remember that csync will just append the filename to the path and pass it to the vio plugin. // csync_owncloud will then re-encode everything. #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QUrl url = remoteUrl(); QString url_string = url.scheme() + QLatin1String("://") + url.authority(QUrl::EncodeDelimiters) + url.path(QUrl::FullyDecoded); #else // Qt4 was broken anyway as it did not encode the '#' as it should have done (it was actually a problem when parsing the path from QUrl::setPath QString url_string = remoteUrl().toString(); #endif url_string = Utility::toCSyncScheme(url_string); QString localpath = path(); if( csync_create( &_csync_ctx, localpath.toUtf8().data(), url_string.toUtf8().data() ) < 0 ) { qDebug() << "Unable to create csync-context!"; slotSyncError(tr("Unable to create csync-context")); _csync_ctx = 0; } else { csync_set_log_callback( csyncLogCatcher ); csync_set_log_level( Logger::instance()->isNoop() ? 0 : 11 ); Q_ASSERT( _accountState ); if( csync_init( _csync_ctx ) < 0 ) { qDebug() << "Could not initialize csync!" << csync_get_status(_csync_ctx) << csync_get_status_string(_csync_ctx); QString errStr = SyncEngine::csyncErrorToString(CSYNC_STATUS(csync_get_status(_csync_ctx))); const char *errMsg = csync_get_status_string(_csync_ctx); if( errMsg ) { errStr += QLatin1String("<br/>"); errStr += QString::fromUtf8(errMsg); } slotSyncError(errStr); csync_destroy(_csync_ctx); _csync_ctx = 0; } } return _csync_ctx; }
bool AddressManager::handleUrl(const QUrl& lookupUrl) { if (lookupUrl.scheme() == HIFI_URL_SCHEME) { qDebug() << "Trying to go to URL" << lookupUrl.toString(); // there are 4 possible lookup strings // 1. global place name (name of domain or place) - example: sanfrancisco // 2. user name (prepended with @) - example: @philip // 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ) // 4. domain network address (IP or dns resolvable hostname) // use our regex'ed helpers to figure out what we're supposed to do with this if (!handleUsername(lookupUrl.authority())) { // we're assuming this is either a network address or global place name // check if it is a network address first if (handleNetworkAddress(lookupUrl.host() + (lookupUrl.port() == -1 ? "" : ":" + QString::number(lookupUrl.port())))) { // we may have a path that defines a relative viewpoint - if so we should jump to that now handleRelativeViewpoint(lookupUrl.path()); } else { // wasn't an address - lookup the place name // we may have a path that defines a relative viewpoint - pass that through the lookup so we can go to it after attemptPlaceNameLookup(lookupUrl.host(), lookupUrl.path()); } } return true; } else if (lookupUrl.toString().startsWith('/')) { qDebug() << "Going to relative path" << lookupUrl.path(); // if this is a relative path then handle it as a relative viewpoint handleRelativeViewpoint(lookupUrl.path()); emit lookupResultsFinished(); } return false; }
QT_BEGIN_NAMESPACE QNetworkAccessBackend * QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op, const QNetworkRequest &request) const { // is it an operation we know of? switch (op) { case QNetworkAccessManager::GetOperation: case QNetworkAccessManager::PutOperation: break; default: // no, we can't handle this operation return 0; } QUrl url = request.url(); if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0 || url.isLocalFile()) { return new QNetworkAccessFileBackend; } else if (!url.isEmpty() && url.authority().isEmpty()) { // check if QFile could, in theory, open this URL via the file engines // it has to be in the format: // prefix:path/to/file // or prefix:/path/to/file // // this construct here must match the one below in open() QFileInfo fi(url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery)); // On Windows and Symbian the drive letter is detected as the scheme. if (fi.exists() && (url.scheme().isEmpty() || (url.scheme().length() == 1))) qWarning("QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files"); if (fi.exists() || (op == QNetworkAccessManager::PutOperation && fi.dir().exists())) return new QNetworkAccessFileBackend; } return 0; }
QNetworkAccessBackend * QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op, const QNetworkRequest &request) const { // is it an operation we know of? switch (op) { case QNetworkAccessManager::GetOperation: case QNetworkAccessManager::PutOperation: break; default: // no, we can't handle this operation return 0; } QUrl url = request.url(); if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0 #if defined(Q_OS_ANDROID) || url.scheme().compare(QLatin1String("assets"), Qt::CaseInsensitive) == 0 #endif || url.isLocalFile()) { return new QNetworkAccessFileBackend; } else if (!url.scheme().isEmpty() && url.authority().isEmpty() && (url.scheme().length() > 1)) { // check if QFile could, in theory, open this URL via the file engines // it has to be in the format: // prefix:path/to/file // or prefix:/path/to/file // // this construct here must match the one below in open() QFileInfo fi(url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery)); if (fi.exists() || (op == QNetworkAccessManager::PutOperation && fi.dir().exists())) return new QNetworkAccessFileBackend; } return 0; }
bool MybbFeedRequest::getFeed(const QVariantMap &settings) { if (status() == Active) { return false; } setStatus(Active); m_settings = settings; m_results = 0; const QUrl url = settings.value("url").toString(); if (settings.value("performLogin").toBool()) { const QString username = settings.value("username").toString(); const QString password = settings.value("password").toString(); if ((!username.isEmpty()) && (!password.isEmpty())) { login(QString("%1://%2/member.php").arg(url.scheme()).arg(url.authority()), username, password); return true; } } getPage(url); return true; }
int Url::authority ( lua_State * L )// const : QString { QUrl* lhs = ValueInstaller2<QUrl>::check( L, 1 ); lua_pushstring(L, lhs->authority().toLatin1() ); return 1; }
void MybbFeedRequest::checkPage() { QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); if (!reply) { setErrorString(tr("Network error")); setStatus(Error); emit finished(this); return; } QString redirect = getRedirect(reply); if (!redirect.isEmpty()) { reply->deleteLater(); if (m_redirects < MAX_REDIRECTS) { followRedirect(redirect, SLOT(checkPage())); } else { setErrorString(tr("Maximum redirects reached")); setStatus(Error); emit finished(this); } return; } switch (reply->error()) { case QNetworkReply::NoError: break; case QNetworkReply::OperationCanceledError: setErrorString(QString()); setStatus(Canceled); emit finished(this); return; default: setErrorString(reply->errorString()); setStatus(Error); emit finished(this); return; } const QUrl url = reply->url(); const QString baseUrl = url.scheme() + "://" + url.authority(); QString page = QString::fromUtf8(reply->readAll()); reply->deleteLater(); fixRelativeUrls(page, baseUrl); const QHtmlDocument document(page); const QHtmlElement html = document.htmlElement(); if (m_results == 0) { QString redirect = getLatestPageUrl(html); if (!redirect.isEmpty()) { if (m_redirects < MAX_REDIRECTS) { followRedirect(redirect, SLOT(checkPage())); } else { setErrorString(tr("Maximum redirects reached")); setStatus(Error); emit finished(this); } return; } #ifdef MYBB_DEBUG qDebug() << "MybbFeedRequest::checkPage(). Writing start of feed"; #endif writeStartFeed(); writeFeedTitle(html); writeFeedUrl(baseUrl); } const QHtmlElementList items = getItems(html); if (items.isEmpty()) { #ifdef MYBB_DEBUG qDebug() << "MybbFeedRequest::checkPage(). No items found. Writing end of feed"; #endif writeEndFeed(); setErrorString(QString()); setStatus(Ready); emit finished(this); return; } const int max = m_settings.value("maxResults", 20).toInt(); int i = items.size() - 1; while ((i >= 0) && (m_results < max)) { const QHtmlElement &item = items.at(i); --i; ++m_results; #ifdef MYBB_DEBUG qDebug() << "MybbFeedRequest::checkPage(). Writing item" << m_results << "of" << max; #endif writeStartItem(); writeItemAuthor(item); writeItemBody(item); writeItemDate(item); writeItemTitle(item); writeItemUrl(item); writeEndItem(); } if (m_results < max) { const QString next = getNextPageUrl(html); if (!next.isEmpty()) { getPage(next); return; } } #ifdef MYBB_DEBUG qDebug() << "MybbFeedRequest::checkPage(). Writing end of feed"; #endif writeEndFeed(); setErrorString(QString()); setStatus(Ready); emit finished(this); }
void QDeclarativeGeoMapPixmapObject::load() { // need to deal with absolute / relative local / remote files QUrl url = QDeclarativeEngine::contextForObject(this)->resolvedUrl(m_source); QString path; if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0) { if (url.authority().isEmpty()) path = QLatin1Char(':') + url.path(); } else if (url.scheme().compare(QLatin1String("file"), Qt::CaseInsensitive) == 0) { path = url.toLocalFile(); } if (!path.isEmpty()) { QFile f(path); if (f.open(QIODevice::ReadOnly)) { QImage image; QImageReader imageReader(&f); if (imageReader.read(&image)) { setPixmap(QPixmap::fromImage(image)); setStatus(QDeclarativeGeoMapPixmapObject::Ready); } else { setPixmap(QPixmap()); setStatus(QDeclarativeGeoMapPixmapObject::Error); //qWarning() << "image read fail"; } } else { setPixmap(QPixmap()); setStatus(QDeclarativeGeoMapPixmapObject::Error); //qWarning() << "file open fail"; } } else { if (m_reply) { m_reply->abort(); m_reply->deleteLater(); m_reply = 0; } QDeclarativeEngine *engine = QDeclarativeEngine::contextForObject(this)->engine(); if (engine) { QNetworkAccessManager *nam = engine->networkAccessManager(); m_reply = nam->get(QNetworkRequest(url)); if (m_reply->isFinished()) { if (m_reply->error() == QNetworkReply::NoError) { finished(); } else { error(m_reply->error()); } delete m_reply; m_reply = 0; return; } setStatus(QDeclarativeGeoMapPixmapObject::Loading); connect(m_reply, SIGNAL(finished()), this, SLOT(finished())); connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError))); } else { setPixmap(QPixmap()); setStatus(QDeclarativeGeoMapPixmapObject::Error); //qWarning() << "null engine fail"; } } }
void PollJob::start() { setTimeout(120 * 1000); QUrl accountUrl = account()->url(); QUrl finalUrl = QUrl::fromUserInput(accountUrl.scheme() + QLatin1String("://") + accountUrl.authority() + (path().startsWith('/') ? QLatin1String("") : QLatin1String("/")) + path()); setReply(getRequest(finalUrl)); setupConnections(reply()); connect(reply(), SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(resetTimeout())); AbstractNetworkJob::start(); }
inline bool isLocationUrl(const QUrl& url) const{ return url.authority() == "webgis.usc.edu"; }