kioslave.cpp
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 1999-2000 Waldo Bastian <bastian@kde.org> 00004 * (c) 1999 Mario Weilguni <mweilguni@sime.com> 00005 * (c) 2001 Lubos Lunak <l.lunak@kde.org> 00006 * 00007 * $Id: kioslave.cpp 465272 2005-09-29 09:47:40Z mueller $ 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Library General Public 00011 * License version 2 as published by the Free Software Foundation. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Library General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Library General Public License 00019 * along with this library; see the file COPYING.LIB. If not, write to 00020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 * Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #ifdef HAVE_CONFIG_H 00025 #include <config.h> 00026 #endif 00027 00028 #include <stdlib.h> 00029 #include <stdio.h> 00030 #include <errno.h> 00031 00032 #include <qstring.h> 00033 00034 #include "ltdl.h" 00035 00036 #ifdef HAVE_DLFCN_H 00037 # include <dlfcn.h> 00038 #endif 00039 00040 #ifdef RTLD_GLOBAL 00041 # define LTDL_GLOBAL RTLD_GLOBAL 00042 #else 00043 # ifdef DL_GLOBAL 00044 # define LTDL_GLOBAL DL_GLOBAL 00045 # else 00046 # define LTDL_GLOBAL 0 00047 # endif 00048 #endif 00049 00050 /* These are to link libkio even if 'smart' linker is used */ 00051 #include <kio/authinfo.h> 00052 extern "C" KIO::AuthInfo* _kioslave_init_kio() { return new KIO::AuthInfo(); } 00053 00054 int main(int argc, char **argv) 00055 { 00056 if (argc < 5) 00057 { 00058 fprintf(stderr, "Usage: kioslave <slave-lib> <protocol> <klauncher-socket> <app-socket>\n\nThis program is part of KDE.\n"); 00059 exit(1); 00060 } 00061 QCString libpath = argv[1]; 00062 00063 if (libpath.isEmpty()) 00064 { 00065 fprintf(stderr, "library path is empty.\n"); 00066 exit(1); 00067 } 00068 lt_dlinit(); 00069 00070 lt_dlhandle handle = lt_dlopen( libpath.data() ); 00071 if (!handle ) 00072 { 00073 const char * ltdlError = lt_dlerror(); 00074 fprintf(stderr, "could not open %s: %s", libpath.data(), ltdlError != 0 ? ltdlError : "(null)" ); 00075 exit(1); 00076 } 00077 00078 lt_ptr sym = lt_dlsym( handle, "kdemain"); 00079 if (!sym ) 00080 { 00081 sym = lt_dlsym( handle, "main"); 00082 if (!sym ) 00083 { 00084 const char * ltdlError = lt_dlerror(); 00085 fprintf(stderr, "Could not find main: %s\n", ltdlError != 0 ? ltdlError : "(null)" ); 00086 exit(1); 00087 } 00088 } 00089 00090 int (*func)(int, char *[]) = (int (*)(int, char *[])) sym; 00091 00092 exit( func(argc-1, argv+1)); /* Launch! */ 00093 }