The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

dynamic.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 /* $Core */
00015 
00016 #include "inspircd.h"
00017 #include "dynamic.h"
00018 #ifndef WIN32
00019 #include <dlfcn.h>
00020 #endif
00021 
00022 DLLManager::DLLManager(InspIRCd*, const char *fname)
00023 {
00024         err = NULL;
00025 
00026         if (!strstr(fname,".so"))
00027         {
00028                 err = "This doesn't look like a module file to me...";
00029                 return;
00030         }
00031 
00032         h = dlopen(fname, RTLD_NOW|RTLD_LOCAL);
00033         if (!h)
00034         {
00035                 err = (char*)dlerror();
00036                 return;
00037         }
00038 }
00039 
00040 DLLManager::~DLLManager()
00041 {
00042         /* close the library */
00043         if (h)
00044                 dlclose(h);
00045 }
00046 
00047 
00048 
00049 bool DLLManager::GetSymbol(void** v, const char* sym_name)
00050 {
00051         /*
00052          * try extract a symbol from the library
00053          * get any error message is there is any
00054          */
00055         
00056         if (h)
00057         {
00058                 dlerror(); // clear value
00059                 *v = dlsym(h, sym_name);
00060                 err = (char*)dlerror();
00061                 if (!*v || err)
00062                         return false;
00063         }
00064         
00065         /* succeeded :) */
00066         return true;
00067 }