Ver código fonte

Parse PLUGIN tag

Serj Kalichev 11 anos atrás
pai
commit
c271da522c
4 arquivos alterados com 41 adições e 2 exclusões
  1. 1 1
      clish/plugin/private.h
  2. 3 0
      clish/shell/private.h
  3. 16 0
      clish/shell/shell_new.c
  4. 21 1
      clish/shell/shell_xml.c

+ 1 - 1
clish/plugin/private.h

@@ -18,5 +18,5 @@ struct clish_plugin_s {
 	char *file; /* Plugin file name. Must be unique. */
 	char *name; /* Local plugin name. Can be used in builtin ref. */
 	lub_list_t *syms; /* List of plugin symbols */
-	void *dlhan;
+	void *dlhan; /* Handler of dlopen() */
 };

+ 3 - 0
clish/shell/private.h

@@ -2,11 +2,13 @@
  * shell.h - private interface to the shell class
  */
 #include "lub/bintree.h"
+#include "lub/list.h"
 #include "tinyrl/tinyrl.h"
 #include "clish/shell.h"
 #include "clish/pargv.h"
 #include "clish/var.h"
 #include "clish/action.h"
+#include "clish/plugin.h"
 
 /*-------------------------------------
  * PRIVATE TYPES
@@ -64,6 +66,7 @@ struct clish_shell_s {
 	bool_t interactive; /* Is shell interactive. */
 	bool_t log; /* If command logging is enabled */
 	struct passwd *user; /* Current user information */
+	lub_list_t *plugins; /* List of plugins */
 
 	/* Static params for var expanding. The refactoring is needed. */
 	clish_param_t *param_depth;

+ 16 - 0
clish/shell/shell_new.c

@@ -10,6 +10,8 @@
 
 #include "lub/string.h"
 #include "lub/db.h"
+#include "lub/list.h"
+#include "clish/plugin.h"
 
 /*-------------------------------------------------------- */
 static void clish_shell_init(clish_shell_t * this,
@@ -35,6 +37,9 @@ static void clish_shell_init(clish_shell_t * this,
 		clish_var_bt_offset(),
 		clish_var_bt_compare, clish_var_bt_getkey);
 
+	/* Initialize plugin list */
+	this->plugins = lub_list_new(NULL);
+
 	assert((NULL != hooks) && (NULL != hooks->script_fn));
 
 	/* set up defaults */
@@ -98,6 +103,7 @@ static void clish_shell_fini(clish_shell_t * this)
 	clish_ptype_t *ptype;
 	clish_var_t *var;
 	unsigned i;
+	lub_list_node_t *iter;
 
 	/* delete each VIEW held  */
 	while ((view = lub_bintree_findfirst(&this->view_tree))) {
@@ -117,6 +123,16 @@ static void clish_shell_fini(clish_shell_t * this)
 		clish_var_delete(var);
 	}
 
+	/* Free all loaded plugins */
+	while ((iter = lub_list__get_head(this->plugins))) {
+		/* Remove the symbol from the list */
+		lub_list_del(this->plugins, iter);
+		/* Free the instance */
+		clish_plugin_free((clish_plugin_t *)lub_list_node__get_data(iter));
+		lub_list_node_free(iter);
+	}
+	lub_list_free(this->plugins);
+
 	/* free the textual details */
 	lub_string_free(this->overview);
 

+ 21 - 1
clish/shell/shell_xml.c

@@ -43,7 +43,8 @@ static PROCESS_FN
 	process_config,
 	process_var,
 	process_wdog,
-	process_hotkey;
+	process_hotkey,
+	process_plugin;
 
 static clish_xml_cb_t xml_elements[] = {
 	{"CLISH_MODULE", process_clish_module},
@@ -60,6 +61,7 @@ static clish_xml_cb_t xml_elements[] = {
 	{"VAR", process_var},
 	{"WATCHDOG", process_wdog},
 	{"HOTKEY", process_hotkey},
+	{"PLUGIN", process_plugin},
 	{NULL, NULL}
 };
 
@@ -966,6 +968,24 @@ process_hotkey(clish_shell_t *shell, clish_xmlnode_t* element, void *parent)
 	clish_xml_release(cmd);
 }
 
+/* ------------------------------------------------------ */
+static void
+process_plugin(clish_shell_t *shell, clish_xmlnode_t* element, void *parent)
+{
+	clish_plugin_t *plugin;
+	char *file = clish_xmlnode_fetch_attr(element, "file");
+	char *name = clish_xmlnode_fetch_attr(element, "name");
+
+	assert(file);
+
+	plugin = clish_plugin_new(name, file);
+	assert(plugin);
+	lub_list_add(shell->plugins, plugin);
+
+	clish_xml_release(file);
+	clish_xml_release(name);
+}
+
 /* ------------------------------------------------------ */
 int clish_shell_xml_read(clish_shell_t * shell, const char *filename)
 {