diff options
| author | dequis <dx@dxzone.com.ar> | 2016-12-25 20:10:58 -0300 | 
|---|---|---|
| committer | dequis <dx@dxzone.com.ar> | 2016-12-25 21:20:09 -0300 | 
| commit | 7486853ca817c0e6d0a5b3d1b702d6bd8e96bf4e (patch) | |
| tree | 13a84508ed9e2416b5583d8f44851376a4d466b5 /protocols | |
| parent | 6908ab747d1eb461c8b8e666113aed47924f5b58 (diff) | |
Refactor: Split plugin info stuff from load_plugin() into two functions
Diffstat (limited to 'protocols')
| -rw-r--r-- | protocols/nogaim.c | 88 | 
1 files changed, 53 insertions, 35 deletions
| diff --git a/protocols/nogaim.c b/protocols/nogaim.c index e4db7024..3fed2728 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -49,16 +49,64 @@ static gint pluginscmp(gconstpointer a, gconstpointer b, gpointer data)  	return g_strcasecmp(ia->name, ib->name);  } -gboolean load_plugin(char *path) +/* semi-private */ +gboolean plugin_info_validate(struct plugin_info *info, const char *path)  {  	GList *l; -	struct plugin_info *i; +	gboolean loaded = FALSE; + +	if (!path) { +		path = "(null)"; +	} + +	if (info->abiver != BITLBEE_ABI_VERSION_CODE) { +		log_message(LOGLVL_ERROR, +			    "`%s' uses ABI %u but %u is required\n", +			    path, info->abiver, +			    BITLBEE_ABI_VERSION_CODE); +		return FALSE; +	} + +	if (!info->name || !info->version) { +		log_message(LOGLVL_ERROR, +			    "Name or version missing from the " +			    "plugin info in `%s'\n", path); +		return FALSE; +	} + +	for (l = plugins; l; l = l->next) { +		struct plugin_info *i = l->data; + +		if (g_strcasecmp(i->name, info->name) == 0) { +			loaded = TRUE; +			break; +		} +	} + +	if (loaded) { +		log_message(LOGLVL_WARNING, +			    "%s plugin already loaded\n", +			    info->name); +		return FALSE; +	} + +	return TRUE; +} + +/* semi-private */ +gboolean plugin_info_add(struct plugin_info *info) +{ +	plugins = g_list_insert_sorted_with_data(plugins, info, pluginscmp, NULL); +	return TRUE; +} + +gboolean load_plugin(char *path) +{  	struct plugin_info *info = NULL;  	struct plugin_info * (*info_function) (void) = NULL;  	void (*init_function) (void);  	GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY); -	gboolean loaded = FALSE;  	if (!mod) {  		log_message(LOGLVL_ERROR, "Error loading plugin `%s': %s\n", path, g_module_error()); @@ -68,36 +116,7 @@ gboolean load_plugin(char *path)  	if (g_module_symbol(mod, "init_plugin_info", (gpointer *) &info_function)) {  		info = info_function(); -		if (info->abiver != BITLBEE_ABI_VERSION_CODE) { -			log_message(LOGLVL_ERROR, -				    "`%s' uses ABI %u but %u is required\n", -				    path, info->abiver, -				    BITLBEE_ABI_VERSION_CODE); -			g_module_close(mod); -			return FALSE; -		} - -		if (!info->name || !info->version) { -			log_message(LOGLVL_ERROR, -				    "Name or version missing from the " -				    "plugin info in `%s'\n", path); -			g_module_close(mod); -			return FALSE; -		} - -		for (l = plugins; l; l = l->next) { -			i = l->data; - -			if (g_strcasecmp(i->name, info->name) == 0) { -				loaded = TRUE; -				break; -			} -		} - -		if (loaded) { -			log_message(LOGLVL_WARNING, -				    "%s plugin already loaded\n", -				    info->name); +		if (!plugin_info_validate(info, path)) {  			g_module_close(mod);  			return FALSE;  		} @@ -112,8 +131,7 @@ gboolean load_plugin(char *path)  	}  	if (info_function) { -		plugins = g_list_insert_sorted_with_data(plugins, info, -		                                         pluginscmp, NULL); +		plugin_info_add(info);  	}  	init_function(); | 
