fuse_kafka
src/plugin.c
00001 #ifndef FK_PLUGIN_C
00002 #define FK_PLUGIN_C
00003 #include "input.h"
00004 #include <dlfcn.h>
00005 void* load_plugin(char* plugin_prefix, char* plugin_name)
00006 {
00007     char*  lib = malloc(strlen(plugin_prefix) + strlen(plugin_name) + 4);
00008     strcpy(lib, plugin_prefix);
00009     strcpy(lib + strlen(plugin_prefix), plugin_name);
00010     strcpy(lib + strlen(plugin_prefix) + strlen(plugin_name), ".so");
00011     trace_debug("load_plugin: trying to open %s", lib);
00012     void* handle = dlopen(lib, RTLD_LAZY);
00013     free(lib);
00014     trace_debug("load_plugin: got handle %p", handle);
00015     if(handle == NULL) trace_error("load_plugin: %s", dlerror());
00016     return handle;
00017 }
00018 void* load_function_from_plugin(void* handle, char* function_name)
00019 {
00020     void* f = NULL;
00021     if(handle != NULL)
00022     {
00023         trace_debug("load_plugin_function: loading %s()", function_name);
00024         f = dlsym(handle, function_name);
00025         if(f == NULL)
00026         {
00027             trace_debug("load_plugin_function: loading setup function failed");
00028             trace_error("load_plugin_function: %s", dlerror());
00029         }
00030     }
00031     return f;
00032 }
00033 void* load_plugin_function(char* plugin_prefix, char* plugin_name, char* function_name)
00034 {
00035     void* handle = load_plugin(plugin_prefix, plugin_name);
00036     if(handle == NULL) return NULL;
00037     return load_function_from_plugin(handle, function_name);
00038 }
00039 #endif
 All Data Structures Files Functions Variables Defines