Browse Source

Move plugin_load/link to clish_shell_prepare()

Serj Kalichev 9 years ago
parent
commit
906e3d0f65
4 changed files with 42 additions and 41 deletions
  1. 1 6
      bin/clish.c
  2. 40 2
      clish/shell/shell_startup.c
  3. 1 1
      clish/shell/shell_wdog.c
  4. 0 32
      clish/shell/shell_xml.c

+ 1 - 6
bin/clish.c

@@ -293,12 +293,7 @@ int main(int argc, char **argv)
 		histfile_expanded = lub_system_tilde_expand(histfile);
 	if (histfile_expanded)
 		clish_shell__restore_history(shell, histfile_expanded);
-	/* Load plugins */
-	if (clish_shell_load_plugins(shell) < 0)
-		goto end;
-	if (clish_shell_link_plugins(shell) < 0)
-		goto end;
-	/* Link aliases and check access rights */
+	/* Load plugins, link aliases and check access rights */
 	if (clish_shell_prepare(shell) < 0)
 		goto end;
 	/* Dryrun config and log hooks */

+ 40 - 2
clish/shell/shell_startup.c

@@ -6,6 +6,15 @@
 
 #include "lub/string.h"
 
+/* Default hooks */
+const char* clish_plugin_default_hook[] = {
+	NULL,
+	"clish_script@clish",
+	"clish_hook_access@clish",
+	"clish_hook_config@clish",
+	"clish_hook_log@clish"
+};
+
 /*----------------------------------------------------------- */
 int clish_shell_startup(clish_shell_t *this)
 {
@@ -73,9 +82,8 @@ const char * clish_shell__get_default_shebang(const clish_shell_t *this)
 /*-------------------------------------------------------- */
 /* Don't forget:
  *    Global view
- *    startup command
  *    hooks
- *    remove unresolved syms
+ *    remove unresolved syms list
  */
 
 int clish_shell_prepare(clish_shell_t *this)
@@ -88,6 +96,34 @@ int clish_shell_prepare(clish_shell_t *this)
 	lub_bintree_iterator_t cmd_iter, view_iter;
 	lub_list_node_t *nspace_iter;
 	clish_hook_access_fn_t *access_fn = NULL;
+	int i;
+
+	/* Add default plugin to the list of plugins */
+	if (this->default_plugin) {
+		clish_plugin_t *plugin;
+		plugin = clish_plugin_new("clish");
+		lub_list_add(this->plugins, plugin);
+		/* Default hooks */
+		for (i = 0; i < CLISH_SYM_TYPE_MAX; i++) {
+			if (this->hooks_use[i])
+				continue;
+			if (!clish_plugin_default_hook[i])
+				continue;
+			clish_sym__set_name(this->hooks[i],
+				clish_plugin_default_hook[i]);
+		}
+	}
+	/* Add default syms to unresolved table */
+	for (i = 0; i < CLISH_SYM_TYPE_MAX; i++) {
+		if (clish_sym__get_name(this->hooks[i]))
+			lub_list_add(this->syms, this->hooks[i]);
+	}
+
+	/* Load plugins and link symbols */
+	if (clish_shell_load_plugins(this) < 0)
+		return -1;
+	if (clish_shell_link_plugins(this) < 0)
+		return -1;
 
 	access_fn = clish_sym__get_func(clish_shell_get_hook(this, CLISH_SYM_TYPE_ACCESS));
 
@@ -99,6 +135,8 @@ int clish_shell_prepare(clish_shell_t *this)
 		/* Check access rights for the VIEW */
 		if (access_fn && clish_view__get_access(view) &&
 			access_fn(this, clish_view__get_access(view))) {
+			fprintf(stderr, "Warning: Access denied. Remove VIEW %s\n",
+				clish_view__get_name(view));
 			lub_bintree_remove(view_tree, view);
 			clish_view_delete(view);
 			continue;

+ 1 - 1
clish/shell/shell_wdog.c

@@ -1,5 +1,5 @@
 /*
- * shell_startup.c
+ * shell_wdog.c
  */
 #include "private.h"
 #include <assert.h>

+ 0 - 32
clish/shell/shell_xml.c

@@ -18,15 +18,6 @@
 #include <sys/types.h>
 #include <dirent.h>
 
-/* Default hooks */
-const char* clish_plugin_default_hook[] = {
-	NULL,
-	"clish_script@clish",
-	"clish_hook_access@clish",
-	"clish_hook_config@clish",
-	"clish_hook_log@clish"
-	};
-
 typedef int (PROCESS_FN) (clish_shell_t *instance,
 	clish_xmlnode_t *element, void *parent);
 
@@ -89,7 +80,6 @@ int clish_shell_load_scheme(clish_shell_t *this, const char *xml_path)
 	char *dirname;
 	char *saveptr = NULL;
 	int res = 0;
-	int i = 0;
 
 	/* use the default path */
 	if (!path)
@@ -148,28 +138,6 @@ int clish_shell_load_scheme(clish_shell_t *this, const char *xml_path)
 	/* tidy up */
 	lub_string_free(buffer);
 
-	/* Load default plugin */
-	if (this->default_plugin) {
-		clish_plugin_t *plugin;
-		plugin = clish_plugin_new("clish");
-		lub_list_add(this->plugins, plugin);
-		/* Default hooks */
-		for (i = 0; i < CLISH_SYM_TYPE_MAX; i++) {
-			if (this->hooks_use[i])
-				continue;
-			if (!clish_plugin_default_hook[i])
-				continue;
-			clish_sym__set_name(this->hooks[i],
-				clish_plugin_default_hook[i]);
-		}
-	}
-
-	/* Add default syms to unresolved table */
-	for (i = 0; i < CLISH_SYM_TYPE_MAX; i++) {
-		if (clish_sym__get_name(this->hooks[i]))
-			lub_list_add(this->syms, this->hooks[i]);
-	}
-
 #ifdef DEBUG
 	clish_shell_dump(this);
 #endif