virtual const unsigned char *GetDataForUrl(const WCHAR *url, size_t *len) { ScopedCritSec scope(&docAccess); ScopedMem<WCHAR> plainUrl(url::GetFullPath(url)); ScopedMem<char> urlUtf8(str::conv::ToUtf8(plainUrl)); data.Append(doc->GetData(urlUtf8, len)); return data.Last(); }
PageDestination *ChmEngineImpl::GetNamedDest(const WCHAR *name) { ScopedMem<WCHAR> plainUrl(str::ToPlainUrl(name)); int pageNo = pages.Find(plainUrl) + 1; if (pageNo > 0) return new ChmTocItem(NULL, pageNo, str::Dup(name)); return NULL; }
PageDestination *ChmModel::GetNamedDest(const WCHAR *name) { ScopedMem<WCHAR> plainUrl(url::GetFullPath(name)); int pageNo = pages.Find(plainUrl) + 1; if (pageNo > 0) return new ChmNamedDest(name, pageNo); return NULL; }
// We fake page numbers by doing a depth-first traversal of // toc tree and considering each unique html page in toc tree // as a page int CreatePageNoForURL(const WCHAR *url) { if (!url || IsExternalUrl(url)) return 0; ScopedMem<WCHAR> plainUrl(str::ToPlainUrl(url)); int pageNo = pages->Find(plainUrl) + 1; if (pageNo > 0) return pageNo; pages->Append(plainUrl.StealData()); return pages->Count(); }
int CreatePageNoForURL(const WCHAR *url) { if (!url || IsExternalUrl(url)) return 0; ScopedMem<WCHAR> plainUrl(str::ToPlainUrl(url)); int pageNo = pages->Count() + 1; bool inserted = urlsSet.Insert(plainUrl, pageNo, &pageNo); if (inserted) { pages->Append(plainUrl.StealData()); CrashIf(pageNo != pages->Count()); } else { CrashIf(pageNo == pages->Count() + 1); } return pageNo; }
// Load and cache data for a given url inside CHM file. bool ChmEngineImpl::GetDataForUrl(const WCHAR *url, char **data, size_t *len) { ScopedMem<WCHAR> plainUrl(str::ToPlainUrl(url)); ChmCacheEntry *e = FindDataForUrl(plainUrl); if (!e) { e = new ChmCacheEntry(plainUrl); ScopedMem<char> urlUtf8(str::conv::ToUtf8(plainUrl)); e->data = (char *)doc->GetData(urlUtf8, &e->size); if (!e->data) { delete e; return false; } urlDataCache.Append(e); } *data = e->data; *len = e->size; return true; }
// Load and cache data for a given url inside CHM file. const unsigned char *ChmModel::GetDataForUrl(const WCHAR *url, size_t *len) { ScopedMem<WCHAR> plainUrl(url::GetFullPath(url)); ChmCacheEntry *e = FindDataForUrl(plainUrl); if (!e) { e = new ChmCacheEntry(Allocator::StrDup(&poolAlloc, plainUrl)); ScopedMem<char> urlUtf8(str::conv::ToUtf8(plainUrl)); e->data = doc->GetData(urlUtf8, &e->size); if (!e->data) { delete e; return NULL; } urlDataCache.Append(e); } if (len) *len = e->size; return e->data; }
// // There have been problems with the finish-signal coming from the networkmanager. // To avoid that, the reply-signals were connected and the data is taken from the // sender() method. // void ownCloudInfo::slotReplyFinished() { QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender()); if( ! reply ) { qDebug() << "ownCloudInfo: Reply empty!"; return; } // Detect redirect url QVariant possibleRedirUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); /* We'll deduct if the redirection is valid in the redirectUrl function */ _urlRedirectedTo = redirectUrl( possibleRedirUrl.toUrl(), _urlRedirectedTo ); if(!_urlRedirectedTo.isEmpty()) { QString configHandle; qDebug() << "Redirected to " << possibleRedirUrl; // We'll do another request to the redirection url. // an empty config handle is ok for the default config. if( _configHandleMap.contains(reply) ) { configHandle = _configHandleMap[reply]; qDebug() << "Redirect: Have a custom config handle: " << configHandle; } QString path = _directories[reply]; qDebug() << "This path was redirected: " << path; MirallConfigFile cfgFile( configHandle ); QString newUrl = _urlRedirectedTo.toString(); if( newUrl.endsWith( path )) { // cut off the trailing path newUrl.chop( path.length() ); cfgFile.setOwnCloudUrl( _connection, newUrl ); qDebug() << "Update the config file url to " << newUrl; getRequest( path, false ); // FIXME: Redirect for webdav! reply->deleteLater(); return; } else { qDebug() << "WRN: Path is not part of the redirect URL. NO redirect."; } } _urlRedirectedTo.clear(); // TODO: check if this is always the correct encoding const QString version = QString::fromUtf8( reply->readAll() ); const QString url = reply->url().toString(); QString plainUrl(url); plainUrl.remove( QLatin1String("/status.php")); QString info( version ); if( url.endsWith( QLatin1String("status.php")) ) { // it was a call to status.php if( reply->error() == QNetworkReply::NoError && info.isEmpty() ) { // This seems to be a bit strange behaviour of QNetworkAccessManager. // It calls the finised slot multiple times but only the first read wins. // That happend when the code connected the finished signal of the manager. // It did not happen when the code connected to the reply finish signal. qDebug() << "WRN: NetworkReply with not content but also no error! " << reply; reply->deleteLater(); return; } qDebug() << "status.php returns: " << info << " " << reply->error() << " Reply: " << reply; if( info.contains(QLatin1String("installed")) && info.contains(QLatin1String("version")) && info.contains(QLatin1String("versionstring")) ) { info.remove(0,1); // remove first char which is a "{" info.remove(-1,1); // remove the last char which is a "}" QStringList li = info.split( QLatin1Char(',') ); QString versionStr; QString version; QString edition; foreach ( const QString& infoString, li ) { QStringList touple = infoString.split( QLatin1Char(':')); QString key = touple[0]; key.remove(QLatin1Char('"')); QString val = touple[1]; val.remove(QLatin1Char('"')); if( key == QLatin1String("versionstring") ) { // get the versionstring out. versionStr = val; } else if( key == QLatin1String( "version") ) { // get version out version = val; } else if( key == QLatin1String( "edition") ) { // get version out edition = val; } else { qDebug() << "Unknown info from ownCloud status.php: "<< key << "=" << val; } } emit ownCloudInfoFound( plainUrl, versionStr, version, edition ); } else {
// // There have been problems with the finish-signal coming from the networkmanager. // To avoid that, the reply-signals were connected and the data is taken from the // sender() method. // void ownCloudInfo::slotReplyFinished() { QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender()); QSslConfiguration sslConfig = reply->sslConfiguration(); if (!sslConfig.isNull()) { QMutexLocker lock(&_certChainMutex); _certificateChain = sslConfig.peerCertificateChain(); } if( ! reply ) { qDebug() << "ownCloudInfo: Reply empty!"; return; } // Detect redirect url QUrl possibleRedirUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); /* We'll deduct if the redirection is valid in the redirectUrl function */ if (!possibleRedirUrl.isEmpty() && _redirectCount++ > 10) { // Are we in a redirect loop qDebug() << "Redirect loop while redirecting to" << possibleRedirUrl; possibleRedirUrl.clear(); } if(!possibleRedirUrl.isEmpty()) { QString configHandle; qDebug() << "Redirected to " << possibleRedirUrl; // We'll do another request to the redirection url. // an empty config handle is ok for the default config. if( _configHandleMap.contains(reply) ) { configHandle = _configHandleMap[reply]; qDebug() << "Redirect: Have a custom config handle: " << configHandle; } QString path = _directories[reply]; if (path.isEmpty()) { path = QLatin1String("status.php"); } else { path.prepend( QLatin1String(WEBDAV_PATH) ); } qDebug() << "This path was redirected: " << path; QString newUrl = possibleRedirUrl.toString(); if( !path.isEmpty() && newUrl.endsWith( path )) { // cut off the trailing path newUrl.chop( path.length() ); _urlRedirectedTo = newUrl; qDebug() << "Updated url to" << newUrl; getRequest( possibleRedirUrl ); } else { qDebug() << "WRN: Path is not part of the redirect URL. NO redirect."; } reply->deleteLater(); _directories.remove(reply); _configHandleMap.remove(reply); return; } // TODO: check if this is always the correct encoding const QString version = QString::fromUtf8( reply->readAll() ); const QString url = reply->url().toString(); QString plainUrl(url); plainUrl.remove( QLatin1String("/status.php")); QString info( version ); if( url.endsWith( QLatin1String("status.php")) ) { // it was a call to status.php if( reply->error() == QNetworkReply::NoError && info.isEmpty() ) { // This seems to be a bit strange behaviour of QNetworkAccessManager. // It calls the finised slot multiple times but only the first read wins. // That happend when the code connected the finished signal of the manager. // It did not happen when the code connected to the reply finish signal. qDebug() << "WRN: NetworkReply with not content but also no error! " << reply; reply->deleteLater(); return; } qDebug() << "status.php returns: " << info << " " << reply->error() << " Reply: " << reply; if( info.contains(QLatin1String("installed")) && info.contains(QLatin1String("version")) && info.contains(QLatin1String("versionstring")) ) { info.remove(0,1); // remove first char which is a "{" info.remove(-1,1); // remove the last char which is a "}" QStringList li = info.split( QLatin1Char(',') ); QString versionStr; QString version; QString edition; foreach ( const QString& infoString, li ) { QStringList touple = infoString.split( QLatin1Char(':')); QString key = touple[0]; key.remove(QLatin1Char('"')); QString val = touple[1]; val.remove(QLatin1Char('"')); if( key == QLatin1String("versionstring") ) { // get the versionstring out. versionStr = val; } else if( key == QLatin1String( "version") ) { // get version out version = val; } else if( key == QLatin1String( "edition") ) { // get version out edition = val; } else if(key == QLatin1String("installed")) { // Silently ignoring "installed = true" information } else { qDebug() << "Unknown info from ownCloud status.php: "<< key << "=" << val; } } emit ownCloudInfoFound( plainUrl, versionStr, version, edition ); } else {