Browse Source

Get content of <PLUGIN>...</PLUGIN>

Serj Kalichev 11 years ago
parent
commit
e7c62e0a80

+ 2 - 0
clish/plugin.h

@@ -106,6 +106,8 @@ void clish_plugin__set_alias(clish_plugin_t *instance, const char *alias);
 char *clish_plugin__get_alias(const clish_plugin_t *instance);
 char *clish_plugin__get_pubname(const clish_plugin_t *instance);
 char *clish_plugin__get_file(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);
 
 #endif				/* _clish_plugin_h */
 /** @} clish_plugin */

+ 14 - 0
clish/plugin/plugin.c

@@ -135,6 +135,7 @@ clish_plugin_t *clish_plugin_new(const char *file, const char *alias)
 
 	this->file = lub_string_dup(file);
 	this->name = NULL;
+	this->conf = NULL;
 	this->alias = lub_string_dup(alias);
 	this->dlhan = NULL;
 	/* Initialise the list of symbols */
@@ -321,3 +322,16 @@ char *clish_plugin__get_file(const clish_plugin_t *this)
 }
 
 /*--------------------------------------------------------- */
+void clish_plugin__set_conf(clish_plugin_t *this, const char *conf)
+{
+	lub_string_free(this->conf);
+	this->conf = lub_string_dup(conf);
+}
+
+/*--------------------------------------------------------- */
+char *clish_plugin__get_conf(const clish_plugin_t *this)
+{
+	return this->conf;
+}
+
+/*--------------------------------------------------------- */

+ 4 - 0
clish/plugin/plugin_dump.c

@@ -60,8 +60,12 @@ void clish_plugin_dump(const clish_plugin_t *this)
 	lub_dump_printf("plugin(%p)\n", this);
 	lub_dump_indent();
 	lub_dump_printf("name  : %s\n", this->name);
+	lub_dump_printf("alias : %s\n", this->alias);
+	lub_dump_printf("conf  : %s\n", this->conf);
 	lub_dump_printf("file  : %s\n", this->file);
 	lub_dump_printf("dlhan : %p\n", this->dlhan);
+	lub_dump_printf("init  : %p\n", this->init);
+	lub_dump_printf("fini  : %p\n", this->fini);
 	lub_dump_indent();
 	/* Iterate child elements */
 	for(iter = lub_list__get_head(this->syms);

+ 1 - 0
clish/plugin/private.h

@@ -21,6 +21,7 @@ struct clish_plugin_s {
 	char *file; /* Plugin file name. Must be unique. */
 	char *name; /* Plugin name defined by plugin itself. */
 	char *alias; /* User defined plugin name. Can be used in builtin ref. */
+	char *conf; /* The content of <PLUGIN>...</PLUGIN> */
 	lub_list_t *syms; /* List of plugin symbols */
 	void *dlhan; /* Handler of dlopen() */
 	clish_plugin_init_t *init; /* Init function (constructor) != NULL */

+ 9 - 1
clish/shell/shell_xml.c

@@ -1169,6 +1169,7 @@ process_plugin(clish_shell_t *shell, clish_xmlnode_t* element, void *parent)
 	char *file = clish_xmlnode_fetch_attr(element, "file");
 	char *name = clish_xmlnode_fetch_attr(element, "name");
 	int res = -1;
+	char *text;
 
 	/* Check syntax */
 	if (!file) {
@@ -1176,9 +1177,16 @@ process_plugin(clish_shell_t *shell, clish_xmlnode_t* element, void *parent)
 		goto error;
 	}
 
-	plugin = clish_plugin_new(file, name); /* Really the name is alias */
+	plugin = clish_plugin_new(file, name); /* Really - the name is alias */
 	lub_list_add(shell->plugins, plugin);
 
+	/* Get PLUGIN body content */
+	text = clish_xmlnode_get_all_content(element);
+	if (text && *text)
+		clish_plugin__set_conf(plugin, text);
+	if (text)
+		free(text);
+
 	res = 0;
 error:
 	clish_xml_release(file);

+ 7 - 0
examples/explugin/anplug.c

@@ -10,10 +10,17 @@ CLISH_PLUGIN_SYM(anplug_fn)
 
 CLISH_PLUGIN_INIT
 {
+	char *conf;
+
 	printf("anplug: INIT shell = %p\n", clish_shell);
 	/* Set a name of plugin to use in sym@plugin */
 	clish_plugin__set_name(plugin, "another_plug");
+	/* Add symbols */
 	clish_plugin_add_sym(plugin, anplug_fn, "an_fn");
+	/* Show plugin config from <PLUGIN>...</PLUGIN> */
+	conf = clish_plugin__get_conf(plugin);
+	if (conf)
+		printf("%s", conf);
 
 	return 0;
 }