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