예제 #1
0
파일: pluginloader.c 프로젝트: junaidk/uhub
struct plugin_handle* plugin_load(const char* filename, const char* config, struct hub_info* hub)
{
	plugin_register_f register_f;
	plugin_unregister_f unregister_f;
	int ret;
	struct plugin_handle* handle = (struct plugin_handle*) hub_malloc_zero(sizeof(struct plugin_handle));
	struct uhub_plugin* plugin = plugin_open(filename);
	struct plugin_hub_internals* internals = (struct plugin_hub_internals*) plugin->internals;

	if (!plugin)
		return NULL;

	if (!handle)
	{
		plugin_close(plugin);
		return NULL;
	}

	handle->handle = plugin;
	register_f = plugin_lookup_symbol(plugin, "plugin_register");
	unregister_f = plugin_lookup_symbol(plugin, "plugin_unregister");

	// register hub internals
	internals->unregister = unregister_f;
	internals->hub = hub;
	internals->callback_data = plugin_callback_data_create();

	// setup callback functions, where the plugin can contact the hub.
	plugin_register_callback_functions(handle);

	if (register_f && unregister_f)
	{
		ret = register_f(handle, config);
		if (ret == 0)
		{
			if (handle->plugin_api_version == PLUGIN_API_VERSION && handle->plugin_funcs_size == sizeof(struct plugin_funcs))
			{
				LOG_INFO("Loaded plugin: %s: %s, version %s.", filename, handle->name, handle->version);
				LOG_PLUGIN("Plugin API version: %d (func table size: " PRINTF_SIZE_T ")", handle->plugin_api_version, handle->plugin_funcs_size);
				return handle;
			}
			else
			{
				LOG_ERROR("Unable to load plugin: %s - API version mistmatch", filename);
			}
		}
		else
		{
			LOG_ERROR("Unable to load plugin: %s - Failed to initialize: %s", filename, handle->error_msg);
		}
	}

	plugin_close(plugin);
	hub_free(handle);
	return NULL;
}
예제 #2
0
파일: pluginloader.c 프로젝트: q3k/uhub
struct plugin_handle* plugin_load(const char* filename, const char* config)
{
	plugin_register_f register_f;
	plugin_unregister_f unregister_f;
	int ret;
	struct plugin_handle* handle = hub_malloc_zero(sizeof(struct plugin_handle));
	struct uhub_plugin* plugin = plugin_open(filename);

	if (!plugin)
		return NULL;

	if (!handle)
	{
		plugin_close(plugin);
		return NULL;
	}

	handle->handle = plugin;
	register_f = plugin_lookup_symbol(plugin, "plugin_register");
	unregister_f = plugin_lookup_symbol(plugin, "plugin_unregister");

	if (register_f && unregister_f)
	{
		ret = register_f(handle, config);
		if (ret == 0)
		{
			if (handle->plugin_api_version == PLUGIN_API_VERSION && handle->plugin_funcs_size == sizeof(struct plugin_funcs))
			{
				LOG_INFO("Loaded plugin: %s: %s, version %s.", filename, handle->name, handle->version);
				LOG_TRACE("Plugin API version: %d (func table size: " PRINTF_SIZE_T ")", handle->plugin_api_version, handle->plugin_funcs_size);
				plugin->unregister = unregister_f;
				return handle;
			}
			else
			{
				LOG_ERROR("Unable to load plugin: %s - API version mistmatch", filename);
			}
		}
		else
		{
			LOG_ERROR("Unable to load plugin: %s - Failed to initialize: %s", filename, handle->error_msg);
		}
	}

	plugin_close(plugin);
	hub_free(handle);
	return NULL;
}
예제 #3
0
파일: HPM.c 프로젝트: DeepBugs/Hercules
struct hplugin *hplugin_load(const char* filename) {
	struct hplugin *plugin;
	struct hplugin_info *info;
	struct HPMi_interface **HPMi;
	bool anyEvent = false;
	void **import_symbol_ref;
	int *HPMDataCheckVer;
	unsigned int *HPMDataCheckLen;
	struct s_HPMDataCheck *HPMDataCheck;
	const char *(*HPMLoadEvent)(int server_type);

	if( HPM->exists(filename) ) {
		ShowWarning("HPM:plugin_load: attempting to load duplicate '"CL_WHITE"%s"CL_RESET"', skipping...\n", filename);
		return NULL;
	}

	plugin = HPM->create();

	if (!(plugin->dll = plugin_open(filename))) {
		char buf[1024];
		ShowFatalError("HPM:plugin_load: failed to load '"CL_WHITE"%s"CL_RESET"' (error: %s)!\n", filename, plugin_geterror(buf));
		exit(EXIT_FAILURE);
	}

	if( !( info = plugin_import(plugin->dll, "pinfo",struct hplugin_info*) ) ) {
		ShowFatalError("HPM:plugin_load: failed to retrieve 'plugin_info' for '"CL_WHITE"%s"CL_RESET"'!\n", filename);
		exit(EXIT_FAILURE);
	}

	if( !(info->type & SERVER_TYPE) ) {
		HPM->unload(plugin);
		return NULL;
	}

	if( !HPM->iscompatible(info->req_version) ) {
		ShowFatalError("HPM:plugin_load: '"CL_WHITE"%s"CL_RESET"' incompatible version '%s' -> '%s'!\n", filename, info->req_version, HPM_VERSION);
		exit(EXIT_FAILURE);
	}

	plugin->info = info;
	plugin->filename = aStrdup(filename);

	if( !( import_symbol_ref = plugin_import(plugin->dll, "import_symbol",void **) ) ) {
		ShowFatalError("HPM:plugin_load: failed to retrieve 'import_symbol' for '"CL_WHITE"%s"CL_RESET"'!\n", filename);
		exit(EXIT_FAILURE);
	}
예제 #4
0
파일: plugins.c 프로젝트: itaka/hurricane
void plugin_load(const char* filename)
{
	plugin_open(filename);
}
예제 #5
0
void plugins_init() {
    GString* module_name = NULL;
    GModule* module;

    gchar* audio_output;

    char** search_path;
    gsize search_path_size;
    char** plugins;
    gsize plugins_size;
    void (*plugin_init)();
    void (*plugin_close)();

    int i;

    module_name = g_string_sized_new(80);
    if (!module_name)
        g_error("Can't allocate memory.");

    search_path = config_get_string_list("plugins_search_path", &search_path_size);

    /* Load audio plugin */
    audio_output = config_get_string("audio_output");
    g_string_printf(module_name, "libspop_audio_%s", audio_output);

    module = plugin_open(module_name->str, search_path, search_path_size);
    if (!module)
        g_error("Can't load %s audio plugin: %s", audio_output, g_module_error());

    if (!g_module_symbol(module, "audio_delivery", (void**) &g_audio_delivery_func))
        g_error("Can't find symbol in audio plugin: %s", g_module_error());

    /* Now load other plugins */
    plugins = config_get_string_list("plugins", &plugins_size);
    for (i=0; i < plugins_size; i++) {
        g_strstrip(plugins[i]);
        g_info("Loading plugin %s...", plugins[i]);

        /* Load the module and the symbols (spop_<module>_init and spop_<module>_close) */
        g_string_printf(module_name, "libspop_plugin_%s", plugins[i]);
        module = plugin_open(module_name->str, search_path, search_path_size);
        if (!module) {
            g_warning("Can't load plugin \"%s\": %s", plugins[i], g_module_error());
            continue;
        }

        g_string_printf(module_name, "spop_%s_init", plugins[i]);
        if (!g_module_symbol(module, module_name->str, (void**) &plugin_init)) {
            g_warning("Can't find symbol \"%s\" in module \"%s\": %s", module_name->str, plugins[i], g_module_error());
            continue;
        }

        g_string_printf(module_name, "spop_%s_close", plugins[i]);
        if (g_module_symbol(module, module_name->str, (void**) &plugin_close))
            g_plugins_close_functions = g_list_prepend(g_plugins_close_functions, plugin_close);
        else
            g_info("Module \"%s\" does not have a \"%s\" symbol: %s", plugins[i], module_name->str, g_module_error());

        /* Really init the plugin (hoping it will not blow up) */
        plugin_init();

        g_debug("Plugin %s loaded and initialized", plugins[i]);
    }
    g_string_free(module_name, TRUE);
    g_strfreev(plugins);
    g_strfreev(search_path);
}