void NetCacheSwap
::start_Get( const QUrl url
) {
CacheInfo havingram = take_Url(url);
if (havingram.pending) {
/* request ist start */
return;
}
if (havingram.valid) {
/* request and data live on swap cache */
emit incomming(url);
return;
}
CacheInfo newrequest;
QNetworkRequest need(url);
need.setRawHeader( "User-Agent", "Mozilla/5.0 (X11; U; Linux i686 (x86_64); "
"en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1" );
need.setRawHeader( "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7" );
need.setRawHeader( "Accept-Encoding", "gzip,deflate,qcompress" ); ////////gzip,deflate,qcompress
need.setRawHeader( "Connection", "keep-alive" );
if (cookie_host[url.host()].size() > 0) {
qDebug() << "### > send cookie ->" << cookie_host[url.host()].toAscii();
need.setRawHeader( "Cookie",cookie_host[url.host()].toAscii());
}
QNetworkReply *reps = get(need);
/* mark it as pending request! */
newrequest.pending = true;
cache_ram.insert(fastmd5(url.toString()),newrequest);
connect(reps, SIGNAL(downloadProgress (qint64,qint64)),
SLOT(progress(qint64,qint64)));
connect(reps, SIGNAL(error(QNetworkReply::NetworkError)),
SLOT(url_error(QNetworkReply::NetworkError)));
connect(reps, SIGNAL(finished()),SLOT(incomming_cache()));
}
void NetCacheSwap::start_Get( const QUrl url )
{
CacheInfo havingram = take_Url(url);
if (havingram.pending) {
/* request ist start */
return;
}
if (havingram.valid) {
/* request and data live on swap cache */
emit incomming(url);
return;
}
CacheInfo newrequest;
QNetworkRequest need(url);
need.setRawHeader( "User-Agent", "Mozilla/5.0 (X11; U; Linux i686 (x86_64); "
"en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1" );
need.setRawHeader( "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7" );
need.setRawHeader( "Accept-Encoding", "gzip,deflate,qcompress" ); ////////gzip,deflate,qcompress
need.setRawHeader( "Connection", "keep-alive" );
if (cookie_host[url.host()].size() > 0) {
qDebug() << "### > send cookie ->" << cookie_host[url.host()].toAscii();
need.setRawHeader( "Cookie",cookie_host[url.host()].toAscii());
}
QNetworkReply *reps = get(need);
/* mark it as pending request! */
newrequest.pending = true;
cache_ram.insert(fastmd5(url.toString()),newrequest);
connect(reps, SIGNAL(downloadProgress (qint64,qint64)),
SLOT(progress(qint64,qint64)));
connect(reps, SIGNAL(error(QNetworkReply::NetworkError)),
SLOT(url_error(QNetworkReply::NetworkError)));
connect(reps, SIGNAL(finished()),SLOT(incomming_cache()));
}
To copy to clipboard, switch view to plain text mode
{
QChar letter
('A' + (qrand
() % 26));
/* must not go on file solution gunzip buffer ? go cache from net location */
const QString tmpfiler
= QString("%1/http_%2.gz").
arg(location
).
arg(letter
);
file.write(chunk);
file.close();
gzFile filegunzip;
filegunzip = gzopen(tmpfiler.toUtf8().data(),"rb");
if(!filegunzip) {
qDebug() << "### Unable to work on tmp file ... ";
}
char buffer[1024];
while(int readBytes =gzread(filegunzip, buffer, 1024))
{
}
gzclose(filegunzip);
file.remove();
}
return input;
}
QByteArray NetCacheSwap::deflate( const QByteArray chunk )
{
QChar letter('A' + (qrand() % 26));
/* must not go on file solution gunzip buffer ? go cache from net location */
const QString tmpfiler = QString("%1/http_%2.gz").arg(location).arg(letter);
QByteArray input;
QFile file(tmpfiler);
if ( file.open(QIODevice::WriteOnly) ) {
file.write(chunk);
file.close();
gzFile filegunzip;
filegunzip = gzopen(tmpfiler.toUtf8().data(),"rb");
if(!filegunzip) {
qDebug() << "### Unable to work on tmp file ... ";
return QByteArray();
}
char buffer[1024];
while(int readBytes =gzread(filegunzip, buffer, 1024))
{
input.append(QByteArray(buffer, readBytes));
}
gzclose(filegunzip);
file.remove();
}
return input;
}
To copy to clipboard, switch view to plain text mode
Bookmarks