Autodetect downloaded mime type and compare against category; if wallpaper downloads something other than image abort

This relates to Bug 2127
pull/16/head
Timothy Pearson 10 years ago
parent e5f898219a
commit 30c2b7e4bd

@ -165,9 +165,13 @@ int KMimeMagic::apprentice( const TQString& magicfile ) {
TQString maindatabase = magicfile;
if (maindatabase == "") {
maindatabase = magic_getpath(0, FILE_LOAD);
if (maindatabase == "") {
kdWarning() << k_funcinfo << "Unable to locate system mime magic database; mime type detection will not function correctly!" << endl;
}
}
conf->databases.clear();
conf->databases.append(maindatabase);
printf("[RAJA DEBUG 342.0] Loading database '%s'\n\r", conf->databases[0].ascii()); fflush(stdout);
return magic_load(conf->magic, conf->databases[0].latin1());
}
@ -186,6 +190,7 @@ void process(struct config_rec* conf, const TQString & fn) {
}
magic_setflags(conf->magic, magic_flags);
conf->resultBuf = TQString(magic_file(conf->magic, fileName));
printf("[RAJA DEBUG 340.0] fileName: '%s' conf->resultBuf: '%s'\n\r", fileName.data(), conf->resultBuf.ascii()); fflush(stdout);
conf->resultBuf = fixupMagicOutput(conf->resultBuf);
if ( conf->utimeConf && conf->utimeConf->restoreAccessTime( fn ) ) {
@ -253,6 +258,7 @@ bool KMimeMagic::mergeConfig(const TQString & _configfile) {
TQString merged_databases = conf->databases.join(":");
int magicvers = magic_version();
if ((magicvers < 512) || (magicvers >= 518)) {
printf("[RAJA DEBUG 342.1] Loading database(s) '%s'\n\r", merged_databases.ascii()); fflush(stdout);
if (magic_load(conf->magic, merged_databases.latin1()) == 0) {
return true;
}
@ -261,7 +267,7 @@ bool KMimeMagic::mergeConfig(const TQString & _configfile) {
}
}
else {
kdWarning(7018) << "KMimeMagic::mergeConfig disabled due to buggy libmagic version " << magicvers << endl;
kdWarning(7018) << k_funcinfo << "KMimeMagic::mergeConfig disabled due to buggy libmagic version " << magicvers << endl;
return false;
}
}
@ -289,6 +295,7 @@ KMimeMagicResult *KMimeMagic::findBufferType(const TQByteArray &array) {
}
magic_setflags(conf->magic, magic_flags);
conf->resultBuf = TQString(magic_buffer(conf->magic, array.data(), nbytes));
printf("[RAJA DEBUG 340.1] conf->resultBuf: '%s'\n\r", conf->resultBuf.ascii()); fflush(stdout);
conf->resultBuf = fixupMagicOutput(conf->resultBuf);
}
/* if we have any results, put them in the request structure */

@ -46,6 +46,7 @@
#include <tqtimer.h> // hack
#define OPENDESKTOP_REDIRECT_URL "opendesktop.org/content/download.php?content="
#define OPENDESKTOP_REDIRECT_TEXT "If the download does not start in 3 seconds:</span><span class=\"defaulttext\">&nbsp;<a href=\""
using namespace KNS;
@ -609,7 +610,7 @@ void DownloadDialog::slotInstallPhase2()
}
else
{
m_s = new TDENewStuffGeneric(e->type(), this);
m_s = new TDENewStuffGeneric(m_filter, this);
m_entry = e;
KURL source = e->payload();
KURL dest = KURL(m_s->downloadDestination(e));
@ -650,6 +651,12 @@ void DownloadDialog::slotJobResult( TDEIO::Job *job )
realURL = e->payload().protocol() + "://opendesktop.org" + realURL;
e->setPayload(realURL);
}
else if ((pos = mJobData.find(OPENDESKTOP_REDIRECT_TEXT)) > 0) {
pos = pos + strlen(OPENDESKTOP_REDIRECT_TEXT);
TQString realURL = mJobData.mid(pos);
realURL = realURL.mid(0, realURL.find("\">"));
e->setPayload(realURL);
}
}
slotInstallPhase2();

@ -343,6 +343,7 @@ void Entry::parseDomElement( const TQDomElement &element )
}
if ( e.tagName() == "score" ) setRating( e.text().toInt() );
if ( e.tagName() == "downloads" ) setDownloads( e.text().toInt() );
// if ( e.tagName() == "typename" ) setType( e.text() );
}
}

@ -29,6 +29,7 @@
#include <tdeconfig.h>
#include <kstandarddirs.h>
#include <tdemessagebox.h>
#include <kmimemagic.h>
#include <ktar.h>
#include "entry.h"
@ -49,6 +50,18 @@ TDENewStuffGeneric::~TDENewStuffGeneric()
bool TDENewStuffGeneric::install( const TQString &fileName )
{
// Try to detect the most common cases where (usually adware) Web pages are downloaded
// instead of the desired file and abort
KMimeMagicResult *res = KMimeMagic::self()->findFileType( fileName );
if ( res->isValid() && res->accuracy() > 40 ) {
if (type().lower().contains("wallpaper")) {
if (!res->mimeType().startsWith("image/")) {
TQFile::remove(fileName);
return false;
}
}
}
kdDebug() << "TDENewStuffGeneric::install(): " << fileName << endl;
TQStringList list, list2;

Loading…
Cancel
Save