Added module loading capabilities
Added basic module loading capabilities. Created very basic modules Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
parent
4da2c703dc
commit
8216a42444
@ -1 +1,2 @@
|
|||||||
SUBDIRS = src
|
SUBDIRS = src modules
|
||||||
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
12
configure.ac
12
configure.ac
@ -3,11 +3,15 @@ AM_INIT_AUTOMAKE
|
|||||||
AC_CONFIG_SRCDIR([src/wxmppd.c])
|
AC_CONFIG_SRCDIR([src/wxmppd.c])
|
||||||
AC_CONFIG_HEADERS([config.h])
|
AC_CONFIG_HEADERS([config.h])
|
||||||
AC_CONFIG_FILES([Makefile
|
AC_CONFIG_FILES([Makefile
|
||||||
src/Makefile])
|
src/Makefile
|
||||||
|
modules/Makefile])
|
||||||
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AC_FUNC_MMAP
|
AM_PROG_LIBTOOL
|
||||||
PKG_CHECK_MODULES([LIBXML2], [libxml-2.0])
|
PKG_CHECK_MODULES([LIBXML2], [libxml-2.0])
|
||||||
PKG_CHECK_MODULES([GLIB], [glib-2.0])
|
PKG_CHECK_MODULES([GLIB], [glib-2.0])
|
||||||
LIBS="$LIBXML2_LIBS $GLIB_LIBS $LIBS"
|
PKG_CHECK_MODULES([GMODULE], [gmodule-2.0])
|
||||||
CFLAGS="$LIBXML2_CFLAGS $GLIB_CFLAGS $CFLAGS"
|
LIBS="$LIBXML2_LIBS $GLIB_LIBS $GMODULE_LIBS $LIBS"
|
||||||
|
CFLAGS="$LIBXML2_CFLAGS $GLIB_CFLAGS $GMODULE_CFLAGS $CFLAGS"
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
||||||
|
9
modules/Makefile.am
Normal file
9
modules/Makefile.am
Normal file
@ -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
|
16
modules/auth-gsasl.c
Normal file
16
modules/auth-gsasl.c
Normal file
@ -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" */
|
||||||
|
}
|
||||||
|
|
16
modules/layer-gnutls.c
Normal file
16
modules/layer-gnutls.c
Normal file
@ -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" */
|
||||||
|
}
|
||||||
|
|
16
modules/roster-sqlite3.c
Normal file
16
modules/roster-sqlite3.c
Normal file
@ -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" */
|
||||||
|
}
|
||||||
|
|
16
modules/users-sqlite3.c
Normal file
16
modules/users-sqlite3.c
Normal file
@ -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" */
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
|||||||
bin_PROGRAMS = wxmppd
|
bin_PROGRAMS = wxmppd
|
||||||
wxmppd_SOURCES = wxmppd.c configfiles.c modules.c
|
wxmppd_SOURCES = wxmppd.c configfiles.c modules.c
|
||||||
|
AM_CFLAGS = -Wall -O2
|
||||||
AM_CPPFLAGS = -DSYSCONFDIR='"$(sysconfdir)"' -DLIBDIR='"$(libdir)"'
|
AM_CPPFLAGS = -DSYSCONFDIR='"$(sysconfdir)"' -DLIBDIR='"$(libdir)"'
|
||||||
|
12
src/module.h
Normal file
12
src/module.h
Normal file
@ -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 */
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <gmodule.h>
|
||||||
|
|
||||||
|
#include "wxmppd.h"
|
||||||
#include "modules.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
|
int
|
||||||
wxmppd_loadModule(char *moduleName, gboolean dryRun)
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef __WXMPPD_MODULES_H
|
#ifndef __WXMPPD_MODULES_H
|
||||||
# define __WXMPPD_MODULES_H
|
# define __WXMPPD_MODULES_H
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user