plugins: add plugin loader and tests
authorAlexander Kanavin <alex.kanavin@gmail.com>
Mon, 28 Jan 2013 19:49:48 +0000 (21:49 +0200)
committerAlexander Kanavin <alex.kanavin@gmail.com>
Mon, 28 Jan 2013 19:50:42 +0000 (21:50 +0200)
.gitignore
include/gsignond/gsignond-plugin-loader.h [new file with mode: 0644]
src/common/Makefile.am
src/common/gsignond-plugin-loader.c [new file with mode: 0644]
src/plugins/password/Makefile.am
test/passwordplugin/Makefile.am
test/passwordplugin/passwordplugintest.c

index 859e388..3563ea2 100644 (file)
@@ -25,7 +25,7 @@ m4/lt*.m4
 build-aux
 *dbus*gen*
 src/daemon/gsignond
-test/db/testdb
+test/db/dbtest
 test/passwordplugin/passwordplugintest
 stamp-h1
 *service
diff --git a/include/gsignond/gsignond-plugin-loader.h b/include/gsignond/gsignond-plugin-loader.h
new file mode 100644 (file)
index 0000000..f2f7e07
--- /dev/null
@@ -0,0 +1,39 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of gsignond
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _GSIGNOND_PLUGIN_LOADER_H_
+#define _GSIGNOND_PLUGIN_LOADER_H_
+
+#include <gsignond/gsignond-plugin-interface.h>
+#include <gsignond/gsignond-config.h>
+
+G_BEGIN_DECLS
+
+GSignondPlugin*
+gsignond_load_plugin(GSignondConfig* config, gchar* plugin_type);
+
+G_END_DECLS
+
+#endif /* _GSIGNOND_PLUGIN_LOADER_H_ */
\ No newline at end of file
index ecd42c3..eef9c77 100644 (file)
@@ -35,6 +35,7 @@ libgsignond_common_la_SOURCES = \
     gsignond-plugin-interface.c \
     gsignond-dictionary.c \
     gsignond-session-data.c \
+    gsignond-plugin-loader.c \
     $(NULL)
 
 CLEANFILES = 
diff --git a/src/common/gsignond-plugin-loader.c b/src/common/gsignond-plugin-loader.c
new file mode 100644 (file)
index 0000000..b746f0e
--- /dev/null
@@ -0,0 +1,68 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of gsignond
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+
+#include "gsignond/gsignond-plugin-loader.h"
+#include "gsignond/gsignond-log.h"
+#include <gmodule.h>
+
+GSignondPlugin*
+gsignond_load_plugin(GSignondConfig* config, gchar* plugin_type)
+{
+    gchar* plugin_filename = g_module_build_path (
+        gsignond_config_get_string (config, 
+        GSIGNOND_CONFIG_GENERAL_PLUGINS_DIR), 
+        plugin_type);
+    DBG("Loading plugin %s", plugin_filename);
+    GModule* plugin_module = g_module_open (plugin_filename, 
+        G_MODULE_BIND_LOCAL);
+    g_free(plugin_filename);
+    if (plugin_module == NULL) {
+        DBG("Plugin couldn't be opened");
+        return;
+    }
+    
+    gchar* plugin_get_type = g_strdup_printf("gsignond_%s_plugin_get_type",
+        plugin_type);
+    GType (*plugin_get_type_f)(void);
+    DBG("Resolving symbol %s", plugin_get_type);
+    gboolean symfound = g_module_symbol (plugin_module,
+        plugin_get_type, &plugin_get_type_f);
+    g_free(plugin_get_type);
+    g_module_close (plugin_module);
+    if (!symfound) {
+        DBG("Symbol couldn't be resolved");
+        return NULL;
+    }
+    
+    DBG("Creating plugin object");
+    GSignondPlugin* plugin = g_object_new(plugin_get_type_f(), NULL);
+    if (plugin == NULL) {
+        DBG("Plugin couldn't be created");
+        return NULL;
+    }
+    
+    return plugin;
+}
index f117313..770d4b6 100644 (file)
@@ -1,20 +1,20 @@
 include $(top_srcdir)/common.mk
-plugins_LTLIBRARIES = libpasswordplugin.la
+plugins_LTLIBRARIES = libpassword.la
 NULL=
 
-libpasswordplugin_la_CPPFLAGS = \
+libpassword_la_CPPFLAGS = \
     -I$(top_srcdir) \
     -I$(top_srcdir)/src \
     -I$(top_srcdir)/include \
     $(GSIGNOND_CFLAGS) \
     $(NULL)
 
-libpasswordplugin_la_LIBADD = \
+libpassword_la_LIBADD = \
     $(top_builddir)/src/common/libgsignond-common.la \
     $(GSIGNOND_LIBS) \
     $(NULL)
 
-libpasswordplugin_la_SOURCES = \
+libpassword_la_SOURCES = \
     gsignond-password-plugin.c \
     $(NULL)
 
index 10f5e93..d91b568 100644 (file)
@@ -1,4 +1,6 @@
 TESTS = passwordplugintest
+TESTS_ENVIRONMENT= SSO_PLUGINS_DIR=$(top_builddir)/src/plugins/password/.libs
+
 check_PROGRAMS = passwordplugintest
 passwordplugintest_SOURCES = passwordplugintest.c
 passwordplugintest_CFLAGS = \
@@ -9,6 +11,6 @@ passwordplugintest_CFLAGS = \
 
 passwordplugintest_LDADD = \
     $(top_builddir)/src/common/libgsignond-common.la \
-    $(top_builddir)/src/plugins/password/libpasswordplugin.la \
+    $(top_builddir)/src/plugins/password/libpassword.la \
     $(GSIGNOND_LIBS) \
-    $(CHECK_LIBS)
\ No newline at end of file
+    $(CHECK_LIBS)
index c1b5384..e1993cf 100644 (file)
@@ -29,7 +29,8 @@
 #include <gsignond/gsignond-session-data.h>
 #include <gsignond/gsignond-plugin-interface.h>
 #include <gsignond/gsignond-error.h>
-
+#include <gsignond/gsignond-plugin-loader.h>
+#include <gsignond/gsignond-config.h>
 
 START_TEST (test_session_data)
 {
@@ -91,13 +92,11 @@ START_TEST (test_session_data)
 }
 END_TEST
 
-START_TEST (test_passwordplugin_create)
+static void check_plugin(GSignondPlugin* plugin)
 {
-    gpointer plugin;
     gchar* type;
     gchar** mechanisms;
-    
-    plugin = g_object_new(GSIGNOND_TYPE_PASSWORD_PLUGIN, NULL);
+
     fail_if(plugin == NULL);
     
     g_object_get(plugin, "type", &type, "mechanisms", &mechanisms, NULL);
@@ -108,6 +107,14 @@ START_TEST (test_passwordplugin_create)
     
     g_free(type);
     g_strfreev(mechanisms);
+}
+
+START_TEST (test_passwordplugin_create)
+{
+    gpointer plugin;
+    
+    plugin = g_object_new(GSIGNOND_TYPE_PASSWORD_PLUGIN, NULL);
+    check_plugin(plugin);
     g_object_unref(plugin);
 }
 END_TEST
@@ -301,6 +308,21 @@ START_TEST (test_passwordplugin_refresh)
 }
 END_TEST
 
+START_TEST (test_passwordplugin_loader)
+{
+    GSignondConfig* config = gsignond_config_new();
+    fail_if(config == NULL);
+
+    GSignondPlugin* absent_plugin = gsignond_load_plugin(config, "absentplugin");
+    fail_if(absent_plugin != NULL);
+    
+    GSignondPlugin* plugin = gsignond_load_plugin(config, "password");
+    check_plugin(plugin);    
+    
+    g_object_unref(plugin);
+    g_object_unref(config);
+}
+END_TEST
 
 Suite* passwordplugin_suite (void)
 {
@@ -313,6 +335,7 @@ Suite* passwordplugin_suite (void)
     tcase_add_test (tc_core, test_passwordplugin_process);
     tcase_add_test (tc_core, test_passwordplugin_user_action_finished);
     tcase_add_test (tc_core, test_passwordplugin_refresh);
+    tcase_add_test (tc_core, test_passwordplugin_loader);
     suite_add_tcase (s, tc_core);
     return s;
 }
@@ -330,4 +353,4 @@ int main (void)
     srunner_free(sr);
     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-  
\ No newline at end of file
+