KInit
kioslave.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <kdebug.h>
00023 #include <config.h>
00024
00025 #include <stdlib.h>
00026 #include <stdio.h>
00027 #include <errno.h>
00028 #include <locale.h>
00029
00030 #include <QtCore/QString>
00031 #include <QtCore/QLibrary>
00032 #include <QtCore/QFile>
00033 #ifdef Q_WS_WIN
00034 #include <QtCore/QDir>
00035 #include <QtCore/QProcess>
00036 #include <QtCore/QStringList>
00037 #include <windows.h>
00038 #include <process.h>
00039 #include "kstandarddirs.h"
00040 #endif
00041
00042 #ifndef Q_WS_WIN
00043
00044 #include <kio/authinfo.h>
00045 extern "C" KIO::AuthInfo* _kioslave_init_kio() { return new KIO::AuthInfo(); }
00046 #endif
00047
00048 int main(int argc, char **argv)
00049 {
00050 if (argc < 5)
00051 {
00052 fprintf(stderr, "Usage: kioslave <slave-lib> <protocol> <klauncher-socket> <app-socket>\n\nThis program is part of KDE.\n");
00053 exit(1);
00054 }
00055 setlocale(LC_ALL, "");
00056 QString libpath = QFile::decodeName(argv[1]);
00057
00058 if (libpath.isEmpty())
00059 {
00060 fprintf(stderr, "library path is empty.\n");
00061 exit(1);
00062 }
00063
00064 QLibrary lib(libpath);
00065 #ifdef Q_WS_WIN
00066 qDebug("trying to load '%s'", qPrintable(libpath));
00067 #endif
00068 if ( !lib.load() || !lib.isLoaded() )
00069 {
00070 #ifdef Q_WS_WIN
00071 libpath = KStandardDirs::installPath("module") + QFileInfo(libpath).fileName();
00072 lib.setFileName( libpath );
00073 if(!lib.load() || !lib.isLoaded())
00074 {
00075 QByteArray kdedirs = qgetenv("KDEDIRS");
00076 if (!kdedirs.size()) {
00077 qDebug("not able to find '%s' because KDEDIRS environment variable is not set.\n"
00078 "Set KDEDIRS to the KDE installation root dir and restart klauncher to fix this problem.",
00079 qPrintable(libpath));
00080 exit(1);
00081 }
00082 QString paths = QString::fromLocal8Bit(kdedirs);
00083 QStringList pathlist = paths.split(';');
00084 Q_FOREACH(const QString &path, pathlist) {
00085 QString slave_path = path + QLatin1String("/lib/kde4/") + QFileInfo(libpath).fileName();
00086 qDebug("trying to load '%s'",slave_path.toAscii().data());
00087 lib.setFileName(slave_path);
00088 if (lib.load() && lib.isLoaded() )
00089 break;
00090 }
00091 if (!lib.isLoaded())
00092 {
00093 qWarning("could not open %s: %s", libpath.data(), qPrintable (lib.errorString()) );
00094 exit(1);
00095 }
00096 }
00097 #else
00098 fprintf(stderr, "could not open %s: %s", qPrintable(libpath),
00099 qPrintable (lib.errorString()) );
00100 exit(1);
00101 #endif
00102 }
00103
00104 void* sym = lib.resolve("kdemain");
00105 if (!sym )
00106 {
00107 fprintf(stderr, "Could not find kdemain: %s\n", qPrintable(lib.errorString() ));
00108 exit(1);
00109 }
00110
00111 #ifdef Q_WS_WIN
00112
00113 QString slaveDebugWait( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_WAIT") ) );
00114 if (slaveDebugWait == QLatin1String("all") || slaveDebugWait == argv[2])
00115 {
00116 # ifdef Q_CC_MSVC
00117
00118 DebugBreak();
00119 # else
00120
00121 WCHAR buf[1024];
00122 GetModuleFileName(NULL,buf, 1024);
00123 QStringList params;
00124 params << QString::fromUtf16((const unsigned short*)buf);
00125 params << QString::number(GetCurrentProcessId());
00126 QProcess::startDetached("gdb",params);
00127 Sleep(1000);
00128 # endif
00129 }
00130 # ifdef Q_CC_MSVC
00131 else {
00132 QString slaveDebugPopup( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_POPUP") ) );
00133 if (slaveDebugPopup == QLatin1String("all") || slaveDebugPopup == argv[2]) {
00134
00135
00136 MessageBoxA(NULL,
00137 QString("Please attach the debugger to process #%1 (%2)").arg(getpid()).arg(argv[0]).toLatin1(),
00138 QString("\"%1\" KIO Slave Debugging").arg(argv[2]).toLatin1(), MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);
00139 }
00140 }
00141 # endif
00142 #endif // Q_WS_WIN
00143
00144 int (*func)(int, char *[]) = (int (*)(int, char *[])) sym;
00145
00146 exit( func(argc-1, argv+1));
00147 }