Browse Source

Check for PLUGIN duplication

Serj Kalichev 9 years ago
parent
commit
e9f1343abb
6 changed files with 44 additions and 0 deletions
  1. 2 0
      clish/plugin.h
  2. 13 0
      clish/plugin/plugin.c
  3. 1 0
      clish/plugin/private.h
  4. 1 0
      clish/shell.h
  5. 21 0
      clish/shell/shell_plugin.c
  6. 6 0
      clish/shell/shell_xml.c

+ 2 - 0
clish/plugin.h

@@ -101,6 +101,8 @@ char *clish_plugin__get_alias(const clish_plugin_t *instance);
 char *clish_plugin__get_pubname(const clish_plugin_t *instance);
 void clish_plugin__set_file(clish_plugin_t *instance, const char *file);
 char *clish_plugin__get_file(const clish_plugin_t *instance);
+void clish_plugin__set_builtin_flag(clish_plugin_t *instance, bool_t builtin_flag);
+bool_t clish_plugin__get_builtin_flag(const clish_plugin_t *instance);
 void clish_plugin__set_conf(clish_plugin_t *instance, const char *conf);
 char *clish_plugin__get_conf(const clish_plugin_t *instance);
 

+ 13 - 0
clish/plugin/plugin.c

@@ -144,6 +144,7 @@ clish_plugin_t *clish_plugin_new(const char *name)
 	this->conf = NULL;
 	this->alias = NULL;
 	this->file = NULL;
+	this->builtin_flag = BOOL_FALSE; /* The plugin is shared object by default */
 	this->dlhan = NULL;
 	/* Initialise the list of symbols */
 	this->syms = lub_list_new(clish_sym_compare);
@@ -392,6 +393,18 @@ char *clish_plugin__get_file(const clish_plugin_t *this)
 	return this->file;
 }
 
+/*--------------------------------------------------------- */
+void clish_plugin__set_builtin_flag(clish_plugin_t *this, bool_t builtin_flag)
+{
+	this->builtin_flag = builtin_flag;
+}
+
+/*--------------------------------------------------------- */
+bool_t clish_plugin__get_builtin_flag(const clish_plugin_t *this)
+{
+	return this->builtin_flag;
+}
+
 /*--------------------------------------------------------- */
 void clish_plugin__set_conf(clish_plugin_t *this, const char *conf)
 {

+ 1 - 0
clish/plugin/private.h

@@ -21,6 +21,7 @@ struct clish_plugin_s {
 	char *name; /* Plugin name. */
 	char *alias; /* User defined plugin name. Can be used in builtin ref. */
 	char *file; /* Shared object file name. */
+	bool_t builtin_flag; /* If plugin is built into binary */
 	char *conf; /* The content of <PLUGIN>...</PLUGIN> */
 	lub_list_t *syms; /* List of plugin symbols */
 	void *dlhan; /* Handler of dlopen() */

+ 1 - 0
clish/shell.h

@@ -182,6 +182,7 @@ void clish_shell__set_dryrun(clish_shell_t *instance, bool_t dryrun);
 bool_t clish_shell__get_dryrun(const clish_shell_t *instance);
 
 /* Plugin functions */
+clish_plugin_t * clish_shell_find_plugin(clish_shell_t *instance, const char *name);
 int clish_shell_load_plugins(clish_shell_t *instance);
 int clish_shell_link_plugins(clish_shell_t *instance);
 

+ 21 - 0
clish/shell/shell_plugin.c

@@ -12,6 +12,27 @@
 #include "clish/plugin.h"
 #include "clish/view.h"
 
+/*----------------------------------------------------------------------- */
+clish_plugin_t * clish_shell_find_plugin(clish_shell_t *this, const char *name)
+{
+	lub_list_node_t *iter;
+	clish_plugin_t *plugin;
+
+	assert(this);
+
+	if (!name || !name[0])
+		return NULL;
+	/* Iterate elements */
+	for(iter = lub_list__get_head(this->plugins);
+		iter; iter = lub_list_node__get_next(iter)) {
+		plugin = (clish_plugin_t *)lub_list_node__get_data(iter);
+		if (!strcmp(name, clish_plugin__get_name(plugin)))
+			return plugin;
+	}
+
+	return NULL;
+}
+
 /*----------------------------------------------------------------------- */
 /* For all plugins:
  *  * dlopen(plugin)

+ 6 - 0
clish/shell/shell_xml.c

@@ -1143,6 +1143,12 @@ static int process_plugin(clish_shell_t *shell, clish_xmlnode_t *element,
 		goto error;
 	}
 
+	plugin = clish_shell_find_plugin(shell, name);
+	if (plugin) {
+		fprintf(stderr,
+			CLISH_XML_ERROR_STR"PLUGIN %s duplication.\n", name);
+		goto error;
+	}
 	plugin = clish_plugin_new(name);
 	lub_list_add(shell->plugins, plugin);