Browse Source

Separate functions to load builtin/shared plugins

Serj Kalichev 10 years ago
parent
commit
c1a1d6328f
2 changed files with 30 additions and 9 deletions
  1. 30 8
      clish/plugin/plugin.c
  2. 0 1
      clish/shell/shell_xml.c

+ 30 - 8
clish/plugin/plugin.c

@@ -267,17 +267,12 @@ clish_sym_t *clish_plugin_get_sym(clish_plugin_t *this, const char *name, int ty
 }
 
 /*--------------------------------------------------------- */
-int clish_plugin_load(clish_plugin_t *this, void *userdata)
+static int clish_plugin_load_shared(clish_plugin_t *this)
 {
-	int res;
+#ifdef HAVE_DLFCN_H
 	char *file = NULL; /* Plugin so file name */
 	char *init_name = NULL; /* Init function name */
 
-	if (!this)
-		return -1;
-	assert(this->name);
-
-#ifdef HAVE_DLFCN_H
 	if (this->file) {
 		file = lub_string_dup(this->file);
 	} else {
@@ -307,11 +302,38 @@ int clish_plugin_load(clish_plugin_t *this, void *userdata)
 		return -1;
 	}
 
+	return 0;
 #else /* HAVE_DLFCN_H */
 	/* We have no any dl functions. */
 
-
+	return -1;
 #endif /* HAVE_DLFCN_H */
+}
+
+/*--------------------------------------------------------- */
+static int clish_plugin_load_builtin(clish_plugin_t *this)
+{
+	return -1;
+}
+
+/*--------------------------------------------------------- */
+int clish_plugin_load(clish_plugin_t *this, void *userdata)
+{
+	int res;
+	char *file = NULL; /* Plugin so file name */
+	char *init_name = NULL; /* Init function name */
+
+	if (!this)
+		return -1;
+	assert(this->name);
+
+	/* Firstly try to find builtin plugin and if there is
+	   no such builtin plugin then try to find plugin 
+	   shared object */
+	if (clish_plugin_load_builtin(this) < 0) {
+		if (clish_load_plugin_shared(this) < 0)
+			return -1;
+	}
 
 	/* Execute init function */
 	if ((res = this->init(userdata, this)))

+ 0 - 1
clish/shell/shell_xml.c

@@ -19,7 +19,6 @@
 #include <dirent.h>
 
 /* Default hooks */
-#define CLISH_PLUGIN_DEFAULT "clish_plugin_clish.so"
 const char* clish_plugin_default_hook[] = {
 	NULL,
 	"clish_script@clish",