|
|
|
|
@ -18,8 +18,8 @@ |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <sys/stat.h> |
|
|
|
|
|
|
|
|
|
#include <kapplication.h> |
|
|
|
|
#include <QDebug> |
|
|
|
|
#include <qcoreapplication.h> |
|
|
|
|
#include "kio_mits_debug.h" |
|
|
|
|
#include <QUrl> |
|
|
|
|
#include <QMimeType> |
|
|
|
|
#include <QMimeDatabase> |
|
|
|
|
@ -38,20 +38,21 @@ extern "C" |
|
|
|
|
{ |
|
|
|
|
int Q_DECL_EXPORT kdemain( int argc, char **argv ) |
|
|
|
|
{ |
|
|
|
|
kDebug() << "*** kio_msits Init"; |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "*** kio_msits Init"; |
|
|
|
|
|
|
|
|
|
KComponentData instance( "kio_msits" ); |
|
|
|
|
QCoreApplication app(argc, argv); |
|
|
|
|
app.setApplicationName(QLatin1String("kio_msits")); |
|
|
|
|
|
|
|
|
|
if ( argc != 4 ) |
|
|
|
|
{ |
|
|
|
|
kDebug() << "Usage: kio_msits protocol domain-socket1 domain-socket2"; |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "Usage: kio_msits protocol domain-socket1 domain-socket2"; |
|
|
|
|
exit (-1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ProtocolMSITS slave ( argv[2], argv[3] ); |
|
|
|
|
slave.dispatchLoop(); |
|
|
|
|
|
|
|
|
|
kDebug() << "*** kio_msits Done"; |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "*** kio_msits Done"; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -84,30 +85,30 @@ void ProtocolMSITS::get( const QUrl& url ) |
|
|
|
|
chmUnitInfo ui; |
|
|
|
|
QByteArray buf; |
|
|
|
|
|
|
|
|
|
kDebug() << "kio_msits::get() " << url.path(); |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "kio_msits::get() " << url.path(); |
|
|
|
|
|
|
|
|
|
if ( !parseLoadAndLookup ( url, fileName ) ) |
|
|
|
|
return; // error() has been called by parseLoadAndLookup
|
|
|
|
|
|
|
|
|
|
kDebug() << "kio_msits::get: parseLoadAndLookup returned " << fileName; |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "kio_msits::get: parseLoadAndLookup returned " << fileName; |
|
|
|
|
|
|
|
|
|
if ( LCHMUrlFactory::handleFileType( url.path(), htmdata ) ) |
|
|
|
|
{ |
|
|
|
|
buf = htmdata.toUtf8(); |
|
|
|
|
kDebug() << "Using special handling for image pages: " << htmdata; |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "Using special handling for image pages: " << htmdata; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if ( isDirectory (fileName) ) |
|
|
|
|
{ |
|
|
|
|
error( KIO::ERR_IS_DIRECTORY, url.prettyUrl() ); |
|
|
|
|
error( KIO::ERR_IS_DIRECTORY, url.toString() ); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( !ResolveObject ( fileName, &ui) ) |
|
|
|
|
{ |
|
|
|
|
kDebug() << "kio_msits::get: could not resolve filename " << fileName; |
|
|
|
|
error( KIO::ERR_DOES_NOT_EXIST, url.prettyUrl() ); |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "kio_msits::get: could not resolve filename " << fileName; |
|
|
|
|
error( KIO::ERR_DOES_NOT_EXIST, url.toString() ); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -115,17 +116,20 @@ void ProtocolMSITS::get( const QUrl& url ) |
|
|
|
|
|
|
|
|
|
if ( RetrieveObject (&ui, (unsigned char*) buf.data(), 0, ui.length) == 0 ) |
|
|
|
|
{ |
|
|
|
|
kDebug() << "kio_msits::get: could not retrieve filename " << fileName; |
|
|
|
|
error( KIO::ERR_NO_CONTENT, url.prettyUrl() ); |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "kio_msits::get: could not retrieve filename " << fileName; |
|
|
|
|
error( KIO::ERR_NO_CONTENT, url.toString() ); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
totalSize( buf.size() ); |
|
|
|
|
#if 0 //PORT QT5
|
|
|
|
|
QMimeDatabase db; |
|
|
|
|
QMimeType result = db.mimeTypeForNameAndData( fileName, buf ); |
|
|
|
|
kDebug() << "Emitting mimetype " << result->name(); |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "Emitting mimetype " << result.name(); |
|
|
|
|
|
|
|
|
|
mimeType( result->name() ); |
|
|
|
|
mimeType( result.name() ); |
|
|
|
|
#endif |
|
|
|
|
data( buf ); |
|
|
|
|
processedSize( buf.size() ); |
|
|
|
|
|
|
|
|
|
@ -135,13 +139,13 @@ void ProtocolMSITS::get( const QUrl& url ) |
|
|
|
|
|
|
|
|
|
bool ProtocolMSITS::parseLoadAndLookup ( const QUrl& url, QString& abspath ) |
|
|
|
|
{ |
|
|
|
|
kDebug() << "ProtocolMSITS::parseLoadAndLookup (const KUrl&) " << url.path(); |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "ProtocolMSITS::parseLoadAndLookup (const KUrl&) " << url.path(); |
|
|
|
|
|
|
|
|
|
int pos = url.path().indexOf ("::"); |
|
|
|
|
|
|
|
|
|
if ( pos == -1 ) |
|
|
|
|
{ |
|
|
|
|
error( KIO::ERR_MALFORMED_URL, url.prettyUrl() ); |
|
|
|
|
error( KIO::ERR_MALFORMED_URL, url.toString() ); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -152,11 +156,11 @@ bool ProtocolMSITS::parseLoadAndLookup ( const QUrl& url, QString& abspath ) |
|
|
|
|
if ( abspath.startsWith( "ms-its:" ) ) |
|
|
|
|
abspath = abspath.mid( 7 ); |
|
|
|
|
|
|
|
|
|
kDebug() << "ProtocolMSITS::parseLoadAndLookup: filename " << filename << ", path " << abspath; |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "ProtocolMSITS::parseLoadAndLookup: filename " << filename << ", path " << abspath; |
|
|
|
|
|
|
|
|
|
if ( filename.isEmpty() ) |
|
|
|
|
{ |
|
|
|
|
error( KIO::ERR_MALFORMED_URL, url.prettyUrl() ); |
|
|
|
|
error( KIO::ERR_MALFORMED_URL, url.toString() ); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -164,14 +168,14 @@ bool ProtocolMSITS::parseLoadAndLookup ( const QUrl& url, QString& abspath ) |
|
|
|
|
if ( m_chmFile && filename == m_openedFile ) |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
kDebug() << "Opening a new CHM file " << QFile::encodeName( QDir::toNativeSeparators( filename ) ); |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "Opening a new CHM file " << QFile::encodeName( QDir::toNativeSeparators( filename ) ); |
|
|
|
|
|
|
|
|
|
// First try to open a temporary file
|
|
|
|
|
chmFile * tmpchm; |
|
|
|
|
|
|
|
|
|
if( (tmpchm = chm_open ( QFile::encodeName( QDir::toNativeSeparators( filename) ) ) ) == 0 ) |
|
|
|
|
if( (tmpchm = chm_open ( QFile::encodeName( QDir::toNativeSeparators( filename) ).constData() ) ) == 0 ) |
|
|
|
|
{ |
|
|
|
|
error( KIO::ERR_COULD_NOT_READ, url.prettyUrl() ); |
|
|
|
|
error( KIO::ERR_COULD_NOT_READ, url.toString() ); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -182,7 +186,7 @@ bool ProtocolMSITS::parseLoadAndLookup ( const QUrl& url, QString& abspath ) |
|
|
|
|
m_chmFile = tmpchm; |
|
|
|
|
m_openedFile = filename; |
|
|
|
|
|
|
|
|
|
kDebug() << "A CHM file " << filename << " has beed opened successfully"; |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "A CHM file " << filename << " has beed opened successfully"; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -225,18 +229,18 @@ void ProtocolMSITS::stat (const QUrl &url) |
|
|
|
|
QString fileName; |
|
|
|
|
chmUnitInfo ui; |
|
|
|
|
|
|
|
|
|
kDebug() << "kio_msits::stat (const KUrl& url) " << url.path(); |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "kio_msits::stat (const KUrl& url) " << url.path(); |
|
|
|
|
|
|
|
|
|
if ( !parseLoadAndLookup ( url, fileName ) ) |
|
|
|
|
return; // error() has been called by parseLoadAndLookup
|
|
|
|
|
|
|
|
|
|
if ( !ResolveObject ( fileName, &ui ) ) |
|
|
|
|
{ |
|
|
|
|
error( KIO::ERR_DOES_NOT_EXIST, url.prettyUrl() ); |
|
|
|
|
error( KIO::ERR_DOES_NOT_EXIST, url.toString() ); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
kDebug() << "kio_msits::stat: adding an entry for " << fileName; |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "kio_msits::stat: adding an entry for " << fileName; |
|
|
|
|
UDSEntry entry; |
|
|
|
|
|
|
|
|
|
if ( isDirectory ( fileName ) ) |
|
|
|
|
@ -262,7 +266,7 @@ void ProtocolMSITS::listDir (const QUrl & url) |
|
|
|
|
{ |
|
|
|
|
QString filepath; |
|
|
|
|
|
|
|
|
|
kDebug() << "kio_msits::listDir (const KUrl& url) " << url.path(); |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "kio_msits::listDir (const KUrl& url) " << url.path(); |
|
|
|
|
|
|
|
|
|
if ( !parseLoadAndLookup ( url, filepath ) ) |
|
|
|
|
return; // error() has been called by parseLoadAndLookup
|
|
|
|
|
@ -275,12 +279,12 @@ void ProtocolMSITS::listDir (const QUrl & url) |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
kDebug() << "kio_msits::listDir: enumerating directory " << filepath; |
|
|
|
|
qCDebug(KIO_MITS_LOG) << "kio_msits::listDir: enumerating directory " << filepath; |
|
|
|
|
|
|
|
|
|
QVector<QString> listing; |
|
|
|
|
|
|
|
|
|
if ( chm_enumerate_dir ( m_chmFile, |
|
|
|
|
filepath.toLocal8Bit(), |
|
|
|
|
filepath.toLocal8Bit().constData(), |
|
|
|
|
CHM_ENUMERATE_NORMAL | CHM_ENUMERATE_FILES | CHM_ENUMERATE_DIRS, |
|
|
|
|
chmlib_enumerator, |
|
|
|
|
&listing ) != 1 ) |
|
|
|
|
|