@ -23,6 +23,8 @@
# include <dlfcn.h>
# include <dlfcn.h>
typedef SCPlugin * ( * SCPluginRegisterFunc ) ( void ) ;
typedef struct PluginListNode_ {
typedef struct PluginListNode_ {
SCPlugin * plugin ;
SCPlugin * plugin ;
void * lib ;
void * lib ;
@ -49,29 +51,37 @@ static void InitPlugin(char *path)
SCLogNotice ( " Failed to open %s as a plugin: %s " , path , dlerror ( ) ) ;
SCLogNotice ( " Failed to open %s as a plugin: %s " , path , dlerror ( ) ) ;
} else {
} else {
SCLogNotice ( " Loading plugin %s " , path ) ;
SCLogNotice ( " Loading plugin %s " , path ) ;
SCPlugin * plugin = dlsym ( lib , " PluginSpec " ) ;
SCPluginRegisterFunc plugin_register = dlsym ( lib , " SCPluginRegister " ) ;
if ( plugin_register = = NULL ) {
SCLogError ( SC_ERR_PLUGIN , " Plugin does not export SCPluginRegister function: %s " , path ) ;
dlclose ( lib ) ;
return ;
}
SCPlugin * plugin = ( * plugin_register ) ( ) ;
if ( plugin = = NULL ) {
if ( plugin = = NULL ) {
SCLogError ( SC_ERR_PLUGIN , " Plugin does not export a plugin specification: %s " , path ) ;
SCLogError ( SC_ERR_PLUGIN , " Plugin registration failed : %s" , path ) ;
dlclose ( lib ) ;
dlclose ( lib ) ;
} else {
return ;
BUG_ON ( plugin - > name = = NULL ) ;
}
BUG_ON ( plugin - > author = = NULL ) ;
BUG_ON ( plugin - > license = = NULL ) ;
BUG_ON ( plugin - > name = = NULL ) ;
BUG_ON ( plugin - > Init = = NULL ) ;
BUG_ON ( plugin - > author = = NULL ) ;
BUG_ON ( plugin - > license = = NULL ) ;
PluginListNode * node = SCCalloc ( 1 , sizeof ( * node ) ) ;
BUG_ON ( plugin - > Init = = NULL ) ;
if ( node = = NULL ) {
SCLogError ( SC_ERR_MEM_ALLOC , " Failed to allocated memory for plugin " ) ;
PluginListNode * node = SCCalloc ( 1 , sizeof ( * node ) ) ;
dlclose ( lib ) ;
if ( node = = NULL ) {
return ;
SCLogError ( SC_ERR_MEM_ALLOC , " Failed to allocated memory for plugin " ) ;
}
dlclose ( lib ) ;
node - > plugin = plugin ;
return ;
node - > lib = lib ;
TAILQ_INSERT_TAIL ( & plugins , node , entries ) ;
SCLogNotice ( " Initializing plugin %s; author=%s; license=%s " ,
plugin - > name , plugin - > author , plugin - > license ) ;
( * plugin - > Init ) ( ) ;
}
}
node - > plugin = plugin ;
node - > lib = lib ;
TAILQ_INSERT_TAIL ( & plugins , node , entries ) ;
SCLogNotice ( " Initializing plugin %s; author=%s; license=%s " , plugin - > name , plugin - > author ,
plugin - > license ) ;
( * plugin - > Init ) ( ) ;
}
}
}
}