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/") + libpath;
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 fprintf(stderr, "could not open %s: %s", libpath.data(),
00091 qPrintable (lib.errorString()) );
00092 exit(1);
00093 }
00094 }
00095 #else
00096 fprintf(stderr, "could not open %s: %s", qPrintable(libpath),
00097 qPrintable (lib.errorString()) );
00098 exit(1);
00099 #endif
00100 }
00101
00102 void* sym = lib.resolve("kdemain");
00103 if (!sym )
00104 {
00105 sym = lib.resolve("main");
00106 if (!sym )
00107 {
00108 fprintf(stderr, "Could not find main: %s\n", qPrintable(lib.errorString() ));
00109 exit(1);
00110 }
00111 }
00112
00113 #ifdef Q_WS_WIN
00114
00115 QString slaveDebugWait( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_WAIT") ) );
00116 if (slaveDebugWait == QLatin1String("all") || slaveDebugWait == argv[2])
00117 {
00118 # ifdef Q_CC_MSVC
00119
00120 DebugBreak();
00121 # else
00122
00123 QByteArray buf(1024,0);
00124 GetModuleFileName(NULL,buf.data(),buf.size());
00125 QStringList params;
00126 params << buf;
00127 params << QString::number(GetCurrentProcessId());
00128 QProcess::startDetached("gdb",params);
00129 Sleep(1000);
00130 # endif
00131 }
00132 # ifdef Q_CC_MSVC
00133 else {
00134 QString slaveDebugPopup( QString::fromLocal8Bit( qgetenv("KDE_SLAVE_DEBUG_POPUP") ) );
00135 if (slaveDebugPopup == QLatin1String("all") || slaveDebugPopup == argv[2]) {
00136
00137
00138 MessageBoxA(NULL,
00139 QString("Please attach the debugger to process #%1 (%2)").arg(getpid()).arg(argv[0]).toLatin1(),
00140 QString("\"%1\" KIO Slave Debugging").arg(argv[2]).toLatin1(), MB_OK|MB_ICONINFORMATION|MB_TASKMODAL);
00141 }
00142 }
00143 # endif
00144 #endif // Q_WS_WIN
00145
00146 int (*func)(int, char *[]) = (int (*)(int, char *[])) sym;
00147
00148 exit( func(argc-1, argv+1));
00149 }