diff --git a/Makefile.am b/Makefile.am
index af437a6..c528e7b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1 +1,2 @@
-SUBDIRS = src
+SUBDIRS = src modules
+ACLOCAL_AMFLAGS = -I m4
diff --git a/configure.ac b/configure.ac
index 5735f1e..8e41b52 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,11 +3,15 @@ AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/wxmppd.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile
-src/Makefile])
+src/Makefile
+modules/Makefile])
+AC_CONFIG_MACRO_DIR([m4])
AC_PROG_CC
-AC_FUNC_MMAP
+AM_PROG_LIBTOOL
PKG_CHECK_MODULES([LIBXML2], [libxml-2.0])
PKG_CHECK_MODULES([GLIB], [glib-2.0])
-LIBS="$LIBXML2_LIBS $GLIB_LIBS $LIBS"
-CFLAGS="$LIBXML2_CFLAGS $GLIB_CFLAGS $CFLAGS"
+PKG_CHECK_MODULES([GMODULE], [gmodule-2.0])
+LIBS="$LIBXML2_LIBS $GLIB_LIBS $GMODULE_LIBS $LIBS"
+CFLAGS="$LIBXML2_CFLAGS $GLIB_CFLAGS $GMODULE_CFLAGS $CFLAGS"
AC_OUTPUT
+
diff --git a/modules/Makefile.am b/modules/Makefile.am
new file mode 100644
index 0000000..d68626b
--- /dev/null
+++ b/modules/Makefile.am
@@ -0,0 +1,9 @@
+lib_LTLIBRARIES = libmod-layer-gnutls.la libmod-auth-gsasl.la libmod-users-sqlite3.la libmod-roster-sqlite3.la
+libmod_layer_gnutls_la_SOURCES = layer-gnutls.c
+libmod_layer_gnutls_la_CPPFLAGS = -I ../src
+libmod_auth_gsasl_la_SOURCES = auth-gsasl.c
+libmod_auth_gsasl_la_CPPFLAGS = -I ../src
+libmod_users_sqlite3_la_SOURCES = users-sqlite3.c
+libmod_users_sqlite3_la_CPPFLAGS = -I ../src
+libmod_roster_sqlite3_la_SOURCES = roster-sqlite3.c
+libmod_roster_sqlite3_la_CPPFLAGS = -I ../src
diff --git a/modules/auth-gsasl.c b/modules/auth-gsasl.c
new file mode 100644
index 0000000..7e6bb4d
--- /dev/null
+++ b/modules/auth-gsasl.c
@@ -0,0 +1,16 @@
+#include "module.h"
+
+int wxmppd_mod_auth_gsasl_load(funcptr *);
+
+const wxmppd_module_data_t module_data = {
+ "auth-gsasl",
+ "GNU SASL authentication extension",
+ (funcptr)wxmppd_mod_auth_gsasl_load,
+};
+
+int
+wxmppd_mod_auth_gsasl_load(funcptr *global_functions)
+{
+ /* Register authentication extension "auth-gsasl" */
+}
+
diff --git a/modules/layer-gnutls.c b/modules/layer-gnutls.c
new file mode 100644
index 0000000..ae091b0
--- /dev/null
+++ b/modules/layer-gnutls.c
@@ -0,0 +1,16 @@
+#include "module.h"
+
+int wxmppd_mod_layer_gnutls_load(funcptr *);
+
+const wxmppd_module_data_t module_data = {
+ "layer-gnutls",
+ "GnuTLS interface extension",
+ (funcptr)wxmppd_mod_layer_gnutls_load,
+};
+
+int
+wxmppd_mod_layer_gnutls_load(funcptr *global_functions)
+{
+ /* Register interface extension "layer-tls" */
+}
+
diff --git a/modules/roster-sqlite3.c b/modules/roster-sqlite3.c
new file mode 100644
index 0000000..19ae46d
--- /dev/null
+++ b/modules/roster-sqlite3.c
@@ -0,0 +1,16 @@
+#include "module.h"
+
+int wxmppd_mod_roster_sqlite3_load(funcptr *);
+
+const wxmppd_module_data_t module_data = {
+ "roster-sqlite3",
+ "SQLite3 storage module for roster data storage",
+ (funcptr)wxmppd_mod_roster_sqlite3_load,
+};
+
+int
+wxmppd_mod_roster_sqlite3_load(funcptr *global_functions)
+{
+ /* Register roster storage extension "sqlite3" */
+}
+
diff --git a/modules/users-sqlite3.c b/modules/users-sqlite3.c
new file mode 100644
index 0000000..cb59ac7
--- /dev/null
+++ b/modules/users-sqlite3.c
@@ -0,0 +1,16 @@
+#include "module.h"
+
+int wxmppd_mod_users_sqlite3_load(funcptr *);
+
+const wxmppd_module_data_t module_data = {
+ "users-sqlite3",
+ "SQLite3 storage module for user data storage",
+ (funcptr)wxmppd_mod_users_sqlite3_load,
+};
+
+int
+wxmppd_mod_users_sqlite3_load(funcptr *global_functions)
+{
+ /* Register user storage extension "sqlite3" */
+}
+
diff --git a/src/Makefile.am b/src/Makefile.am
index 2642b12..1f38e56 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,3 +1,4 @@
bin_PROGRAMS = wxmppd
wxmppd_SOURCES = wxmppd.c configfiles.c modules.c
+AM_CFLAGS = -Wall -O2
AM_CPPFLAGS = -DSYSCONFDIR='"$(sysconfdir)"' -DLIBDIR='"$(libdir)"'
diff --git a/src/module.h b/src/module.h
new file mode 100644
index 0000000..aaa51fa
--- /dev/null
+++ b/src/module.h
@@ -0,0 +1,12 @@
+#ifndef __WXMPPD_MODULE_H
+# define __WXMPPD_MODULE_H
+
+typedef int * (*funcptr) ();
+
+typedef struct _wxmppd_module_data_t {
+ char *name;
+ char *description;
+ funcptr *load_func;
+} wxmppd_module_data_t;
+
+#endif /* __WXMPPD_MODULE_H */
diff --git a/src/modules.c b/src/modules.c
index 31c3876..c7d864b 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -1,11 +1,85 @@
+/* wXMPPd - (Trying to be) full featured XMPP daemon
+ * Copyright (C) 2011 Gergely Polonkai
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
#include
#include
+#include
+#include "wxmppd.h"
#include "modules.h"
+#include "module.h"
+
+funcptr wxmppd_functionTable[] = {
+};
+
+static void
+loadModuleFromList(gpointer data, gpointer user_data)
+{
+ (void)wxmppd_loadModule((char *)data, FALSE);
+}
+
+int
+wxmppd_setActiveModules(void)
+{
+ g_slist_foreach(activeConfig->modules_to_load, loadModuleFromList, NULL);
+}
int
wxmppd_loadModule(char *moduleName, gboolean dryRun)
{
- printf("Will load module %s\n", moduleName);
+ gchar *moduleFile;
+ GModule *module;
+ wxmppd_module_data_t *module_data;
+
+ moduleFile = g_strdup_printf("%s/lib%s.so", activeConfig->modules_dir, moduleName);
+
+ if ((module = g_module_open(moduleFile, G_MODULE_BIND_LAZY)) == NULL)
+ {
+ g_printf("Unable to load module: %s\n", g_module_error());
+ return 1;
+ }
+
+ if (!g_module_symbol(module, "module_data", (gpointer *)&module_data))
+ {
+ g_printf("Bad module: %s\n", g_module_error());
+ if (!g_module_close(module))
+ {
+ g_printf("Unable to close module: %s\n", g_module_error());
+ }
+
+ return 1;
+ }
+
+ if (module_data == NULL)
+ {
+ g_printf("Bad module, it contains no module data structure!\n");
+ if (!g_module_close(module))
+ {
+ g_printf("Unable to close module: %s\n", g_module_error());
+ }
+
+ return 1;
+ }
+
+ printf("Loaded module named '%s'\n", module_data->name);
+
+ if (!g_module_close(module))
+ {
+ g_printf("Unable to close module: %s\n", g_module_error());
+ }
}
diff --git a/src/modules.h b/src/modules.h
index 5acb1d7..8721f00 100644
--- a/src/modules.h
+++ b/src/modules.h
@@ -1,3 +1,20 @@
+/* wXMPPd - (Trying to be) full featured XMPP daemon
+ * Copyright (C) 2011 Gergely Polonkai
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
#ifndef __WXMPPD_MODULES_H
# define __WXMPPD_MODULES_H