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 
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 
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)); 
00093 }