diff --git a/Makefile.obexd b/Makefile.obexd
index 363295d..0e50b1f 100644
--- a/Makefile.obexd
+++ b/Makefile.obexd
$(ICAL_LIBS) $(DBUS_LIBS) $(LIBEBOOK_LIBS) \
$(LIBEDATASERVER_LIBS) $(GLIB_LIBS) -ldl
+if EXTERNAL_PLUGINS
obexd_src_obexd_LDFLAGS = $(AM_LDFLAGS) -Wl,--export-dynamic
+endif
obexd_src_obexd_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) \
$(ICAL_CFLAGS) -DOBEX_PLUGIN_BUILTIN \
diff --git a/obexd/src/obexd.h b/obexd/src/obexd.h
index fe312a6..af5265d 100644
--- a/obexd/src/obexd.h
+++ b/obexd/src/obexd.h
#define OBEX_MAS (1 << 8)
#define OBEX_MNS (1 << 9)
-gboolean plugin_init(const char *pattern, const char *exclude);
+void plugin_init(const char *pattern, const char *exclude);
void plugin_cleanup(void);
gboolean manager_init(void);
diff --git a/obexd/src/plugin.c b/obexd/src/plugin.c
index a3eb247..1432778 100644
--- a/obexd/src/plugin.c
+++ b/obexd/src/plugin.c
#define PLUGINFLAG (RTLD_NOW)
#endif
+#define IS_ENABLED(x) (x)
+
static GSList *plugins = NULL;
struct obex_plugin {
const struct obex_plugin_desc *desc;
};
-static gboolean add_plugin(void *handle, const struct obex_plugin_desc *desc)
+static gboolean add_external_plugin(void *handle,
+ const struct obex_plugin_desc *desc)
{
struct obex_plugin *plugin;
return TRUE;
}
+static void add_plugin(const struct obex_plugin_desc *desc)
+{
+ struct obex_plugin *plugin;
+
+ plugin = g_try_new0(struct obex_plugin, 1);
+ if (plugin == NULL)
+ return;
+
+ plugin->desc = desc;
+
+ if (desc->init() < 0) {
+ g_free(plugin);
+ return;
+ }
+
+ plugins = g_slist_append(plugins, plugin);
+ DBG("Plugin %s loaded", desc->name);
+}
+
static gboolean check_plugin(const struct obex_plugin_desc *desc,
char **patterns, char **excludes)
{
}
-#include "builtin.h"
-
-gboolean plugin_init(const char *pattern, const char *exclude)
+static void external_plugin_init(char **patterns, char **excludes)
{
- char **patterns = NULL;
- char **excludes = NULL;
GDir *dir;
const char *file;
- unsigned int i;
- if (strlen(PLUGINDIR) == 0)
- return FALSE;
+ info("Using external plugins is not officially supported.\n");
+ info("Consider upstreaming your plugins into the BlueZ project.");
- if (pattern)
- patterns = g_strsplit_set(pattern, ":, ", -1);
-
- if (exclude)
- excludes = g_strsplit_set(exclude, ":, ", -1);
-
- DBG("Loading builtin plugins");
-
- for (i = 0; __obex_builtin[i]; i++) {
- if (check_plugin(__obex_builtin[i],
- patterns, excludes) == FALSE)
- continue;
-
- add_plugin(NULL, __obex_builtin[i]);
- }
+ if (strlen(PLUGINDIR) == 0)
+ return;
DBG("Loading plugins %s", PLUGINDIR);
dir = g_dir_open(PLUGINDIR, 0, NULL);
if (!dir) {
- g_strfreev(patterns);
- g_strfreev(excludes);
- return FALSE;
+ return;
}
while ((file = g_dir_read_name(dir)) != NULL) {
continue;
}
- if (add_plugin(handle, desc) == FALSE)
+ if (add_external_plugin(handle, desc) == FALSE)
dlclose(handle);
}
g_dir_close(dir);
+}
+
+#include "builtin.h"
+
+void plugin_init(const char *pattern, const char *exclude)
+{
+ char **patterns = NULL;
+ char **excludes = NULL;
+ unsigned int i;
+
+ if (pattern)
+ patterns = g_strsplit_set(pattern, ":, ", -1);
+
+ if (exclude)
+ excludes = g_strsplit_set(exclude, ":, ", -1);
+
+ DBG("Loading builtin plugins");
+
+ for (i = 0; __obex_builtin[i]; i++) {
+ if (check_plugin(__obex_builtin[i],
+ patterns, excludes) == FALSE)
+ continue;
+
+ add_plugin(__obex_builtin[i]);
+ }
+
+ if IS_ENABLED(EXTERNAL_PLUGINS)
+ external_plugin_init(patterns, excludes);
+
g_strfreev(patterns);
g_strfreev(excludes);
-
- return TRUE;
}
void plugin_cleanup(void)
diff --git a/obexd/src/plugin.h b/obexd/src/plugin.h
index a91746c..e1756b9 100644
--- a/obexd/src/plugin.h
+++ b/obexd/src/plugin.h
#name, init, exit \
};
#else
+#if EXTERNAL_PLUGINS
#define OBEX_PLUGIN_DEFINE(name,init,exit) \
extern struct obex_plugin_desc obex_plugin_desc \
__attribute__ ((visibility("default"))); \
const struct obex_plugin_desc obex_plugin_desc = { \
#name, init, exit \
};
+#else
+#error "Requested non built-in plugin, while external plugins is disabled"
+#endif
#endif