From 52f2f6ff34ab71714c7c4d06a1548140a6fdfaf3 Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Sun, 22 Feb 2009 15:32:56 +0000 Subject: [PATCH] - Reworked handling of plugin mechanism (libltdl "static" inclusion of plugins should work now). Building under Windows (with Cygwin) does work (build with ./configure --enable-static-libosip2). --- ChangeLog | 4 ++++ config.h.in | 2 +- configure.in | 18 +++++++++++++----- doc/siproxd_guide.sgml | 25 ++++++++++++++++--------- src/Makefile.am | 18 ++++++++++++------ src/plugin_defaulttarget.c | 9 ++++++--- src/plugin_demo.c | 10 +++++++--- src/plugin_fix_bogus_via.c | 9 ++++++--- src/plugin_logcall.c | 9 ++++++--- src/plugin_shortdial.c | 9 ++++++--- src/plugins.c | 2 ++ src/plugins.h | 13 ++++++++++++- 12 files changed, 91 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e01045..ea23354 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 0.7.2 ===== + 22-Feb-2009: - Reworked handling of plugin mechanism (libltdl "static" + inclusion of plugins should work now). Building under + Windows (with Cygwin) does work (build with + ./configure --enable-static-libosip2). 11-Feb-2009: - Don't abort RTP streams on ENOBUFS (Internet upstream saturated and a Packet is dropped) 24-Jan-2009: - fixed an issue with RTP timeouts (on calls with multiple diff --git a/config.h.in b/config.h.in index d9c51ba..0c0edf5 100644 --- a/config.h.in +++ b/config.h.in @@ -304,7 +304,7 @@ /* type osip_MD5_CTX */ #undef osip_MD5_CTX -/* Define to `unsigned' if does not define. */ +/* Define to `unsigned int' if does not define. */ #undef size_t /* typedef socklen_t available */ diff --git a/configure.in b/configure.in index b26dbe5..d0c7a30 100644 --- a/configure.in +++ b/configure.in @@ -40,6 +40,8 @@ dnl 10-Jun-2007 tries test more .h files (DNS resolver related) dnl 18-Dec-2007 tries requires libosip2-3.x.x dnl 02-Feb-2008 tries removed variety of fli4l and static extra dnl build options +dnl 21-Feb-2009 tries --enable-static-libosip2 does search static +dnl libs now in libosip_prefix_dir dnl dnl @@ -278,8 +280,9 @@ else dnl link statically to this lib dnl (this probably only will work on linux yet...) AC_MSG_CHECKING("where I can find libosip2.a") - libosip_static=`find $extra_libs /lib /usr/lib /usr/local/lib \ - -name libosip2.a 2>/dev/null|head -1` + libosip_static=`find $extra_libs $libosip_prefix_dir/lib /lib \ + /usr/lib /usr/local/lib \ + -name libosip2.a 2>/dev/null|head -1` if test "x$libosip_static" != "x"; then LIBS="$libosip_static $LIBS" AC_MSG_RESULT($libosip_static) @@ -287,8 +290,9 @@ else echo "*** ERROR: a static libosip library is required!";exit 1; fi AC_MSG_CHECKING("where I can find libosipparser2.a") - libosip_static=`find $extra_libs /lib /usr/lib /usr/local/lib \ - -name libosipparser2.a 2>/dev/null|head -1` + libosip_static=`find $extra_libs $libosip_prefix_dir/lib /lib \ + /usr/lib /usr/local/lib \ + -name libosipparser2.a 2>/dev/null|head -1` if test "x$libosip_static" != "x"; then LIBS="$libosip_static $LIBS" AC_MSG_RESULT($libosip_static) @@ -344,7 +348,11 @@ AC_CHECK_DECL(SOL_IP, [[$ac_includes_default] [#ifdef HAVE_NETDB_H] [#include ] - [#endif]] + [#endif] + [#ifdef HAVE_SYS_SOCKET_H] + [#include ] + [#endif] + ] ) diff --git a/doc/siproxd_guide.sgml b/doc/siproxd_guide.sgml index 90fa6bd..f1a14a8 100644 --- a/doc/siproxd_guide.sgml +++ b/doc/siproxd_guide.sgml @@ -520,15 +520,22 @@ debug_port = 0 Plug-in API Siproxd plug-ins are dynamic loadable libraries and must provide - 3 functions towards siproxd: + 3 functions towards siproxd. As we make use of some libltdl features + we do some internal macor magic - the PLUGIN_xxx funcation names + are actually CPP macros that will expand in unique names. Th have + this working properly the PLUGIN_NAME must be #defined before + the plugins.h header file is included: -int plugin_init(plugin_def_t *plugin_def); -int plugin_process(int stage, sip_ticket_t *ticket); -int plugin_end(plugin_def_t *plugin_def); +#define PLUGIN_NAME plugin_myplugin +#include "plugins.h" +[...] +int PLUGIN_INIT(plugin_def_t *plugin_def); +int PLUGIN_PROCESS(int stage, sip_ticket_t *ticket); +int PLUGIN_END(plugin_def_t *plugin_def); - The plugin_init function is called when + The PLUGIN_INIT function is called when the plug-in is loaded during startup of siproxd. The plug-in must define the following 4 fields of the plugin_def structure: @@ -557,12 +564,12 @@ plugin_def->desc=strdup("This is just a demo plugin without any purpose"); plugin_def->exe_mask=PLUGIN_DETERMINE_TARGET|PLUGIN_PRE_PROXY; - The plugin_process function is called at + The PLUGIN_PROCESS function is called at the requested SIP processing stages (see 'execution mask'). Your processing will be done here. - The plugin_end function is called at + The PLUGIN_END function is called at shutdown of siproxd and gives the plug-in the opportunity to clean up and properly shutdown itself. Note: The previously allocated 'name' and 'desc' must be @@ -571,7 +578,7 @@ plugin_def->exe_mask=PLUGIN_DETERMINE_TARGET|PLUGIN_PRE_PROXY; Minimum required clean up procedure: -int plugin_end(plugin_def_t *plugin_def){ +int PLUGIN_END(plugin_def_t *plugin_def){ /* free my allocated rescources (if allocated via malloc only) */ if (plugin_def->name) {free(plugin_def->name); plugin_def->name=NULL;} if (plugin_def->desc) {free(plugin_def->desc); plugin_def->desc=NULL;} @@ -647,7 +654,7 @@ plugin_demo_string = This_is_a_string_passed_to_the_demo_plugin none Description: - XXXXXXXXXXXXXXXXxThe numbering starts with "1" ("*01") and every following + The numbering starts with "1" ("*01") and every following "plugin_shortdial_entry" entry will allocate the following position. It is not possible to freely assign the positions. diff --git a/src/Makefile.am b/src/Makefile.am index ccab32e..0c8e9ad 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,7 +27,7 @@ AM_CFLAGS = -Wall -D_GNU_SOURCE \ # sbin_PROGRAMS = siproxd siproxd_LDFLAGS=-export-dynamic -siproxd_LDADD = $(LIBLTDL) +siproxd_LDADD = $(LIBLTDL) $(DLOPENPLUGINS) siproxd_SOURCES = siproxd.c proxy.c register.c sock.c utils.c \ sip_utils.c sip_layer.c log.c readconf.c rtpproxy.c \ rtpproxy_relay.c accessctl.c route_processing.c \ @@ -35,6 +35,7 @@ siproxd_SOURCES = siproxd.c proxy.c register.c sock.c utils.c \ dejitter.c plugins.c # addrcache.c + # # Plugin modules, installed in "pkglib" directory ($prefix/lib/siproxd/) # @@ -43,21 +44,26 @@ pkglib_LTLIBRARIES = plugin_demo.la \ plugin_logcall.la \ plugin_defaulttarget.la \ plugin_fix_bogus_via.la +DLOPENPLUGINS = -dlopen plugin_demo.la \ + -dlopen plugin_shortdial.la \ + -dlopen plugin_logcall.la \ + -dlopen plugin_defaulttarget.la \ + -dlopen plugin_fix_bogus_via.la # plugin_demo_la_SOURCES = plugin_demo.c -plugin_demo_la_LDFLAGS = -module +plugin_demo_la_LDFLAGS = -module -avoid-version -shrext '.so' # plugin_shortdial_la_SOURCES = plugin_shortdial.c -plugin_shortdial_la_LDFLAGS = -module +plugin_shortdial_la_LDFLAGS = -module -avoid-version -shrext '.so' # plugin_logcall_la_SOURCES = plugin_logcall.c -plugin_logcall_la_LDFLAGS = -module +plugin_logcall_la_LDFLAGS = -module -avoid-version -shrext '.so' # plugin_defaulttarget_la_SOURCES = plugin_defaulttarget.c -plugin_defaulttarget_la_LDFLAGS = -module +plugin_defaulttarget_la_LDFLAGS = -module -avoid-version -shrext '.so' # plugin_fix_bogus_via_la_SOURCES = plugin_fix_bogus_via.c -plugin_fix_bogus_via_la_LDFLAGS = -module +plugin_fix_bogus_via_la_LDFLAGS = -module -avoid-version -shrext '.so' # diff --git a/src/plugin_defaulttarget.c b/src/plugin_defaulttarget.c index 7d39d7c..2951414 100644 --- a/src/plugin_defaulttarget.c +++ b/src/plugin_defaulttarget.c @@ -18,6 +18,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* must be defined before including */ +#define PLUGIN_NAME plugin_defaulttarget + #include "config.h" #include @@ -65,7 +68,7 @@ static int plugin_defaulttarget_redirect(sip_ticket_t *ticket); * Initialization. * Called once suring siproxd startup. */ -int plugin_init(plugin_def_t *plugin_def) { +int PLUGIN_INIT(plugin_def_t *plugin_def) { /* API version number of siproxd that this plugin is built against. * This constant will change whenever changes to the API are made @@ -105,7 +108,7 @@ int plugin_init(plugin_def_t *plugin_def) { * Processing. * */ -int plugin_process(int stage, sip_ticket_t *ticket){ +int PLUGIN_PROCESS(int stage, sip_ticket_t *ticket){ /* stage contains the PLUGIN_* value - the stage of SIP processing. */ int sts; @@ -153,7 +156,7 @@ int plugin_process(int stage, sip_ticket_t *ticket){ * to clean up its mess (e.g. dynamic memory allocation, database * connections, whatever the plugin messes around with) */ -int plugin_end(plugin_def_t *plugin_def){ +int PLUGIN_END(plugin_def_t *plugin_def){ return STS_SUCCESS; } diff --git a/src/plugin_demo.c b/src/plugin_demo.c index c628fa2..21ec7dd 100644 --- a/src/plugin_demo.c +++ b/src/plugin_demo.c @@ -18,6 +18,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* must be defined before including */ +#define PLUGIN_NAME plugin_demo + #include "config.h" #include @@ -32,6 +35,7 @@ #include "plugins.h" #include "log.h" + static char const ident[]="$Id$"; /* Plug-in identification */ @@ -57,7 +61,7 @@ static cfgopts_t plugin_cfg_opts[] = { * Initialization. * Called once suring siproxd startup. */ -int plugin_init(plugin_def_t *plugin_def) { +int PLUGIN_INIT(plugin_def_t *plugin_def) { /* API version number of siproxd that this plugin is built against. * This constant will change whenever changes to the API are made * that require adaptions in the plugin. */ @@ -87,7 +91,7 @@ int plugin_init(plugin_def_t *plugin_def) { * Processing. * */ -int plugin_process(int stage, sip_ticket_t *ticket){ +int PLUGIN_PROCESS(int stage, sip_ticket_t *ticket){ /* stage contains the PLUGIN_* value - the stage of SIP processing. */ INFO("plugin_demo: processing - stage %i",stage); return STS_SUCCESS; @@ -99,7 +103,7 @@ int plugin_process(int stage, sip_ticket_t *ticket){ * to clean up its mess (e.g. dynamic memory allocation, database * connections, whatever the plugin messes around with) */ -int plugin_end(plugin_def_t *plugin_def){ +int PLUGIN_END(plugin_def_t *plugin_def){ INFO("plugin_demo ends here"); return STS_SUCCESS; } diff --git a/src/plugin_fix_bogus_via.c b/src/plugin_fix_bogus_via.c index cc867f2..9e6171a 100644 --- a/src/plugin_fix_bogus_via.c +++ b/src/plugin_fix_bogus_via.c @@ -18,6 +18,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* must be defined before including */ +#define PLUGIN_NAME plugin_fix_bogus_via + #include "config.h" #include @@ -60,7 +63,7 @@ static int sip_patch_topvia(sip_ticket_t *ticket); * Initialization. * Called once suring siproxd startup. */ -int plugin_init(plugin_def_t *plugin_def) { +int PLUGIN_INIT(plugin_def_t *plugin_def) { /* API version number of siproxd that this plugin is built against. * This constant will change whenever changes to the API are made * that require adaptions in the plugin. */ @@ -90,7 +93,7 @@ int plugin_init(plugin_def_t *plugin_def) { * Processing. * */ -int plugin_process(int stage, sip_ticket_t *ticket){ +int PLUGIN_PROCESS(int stage, sip_ticket_t *ticket){ /* stage contains the PLUGIN_* value - the stage of SIP processing. */ int type; osip_via_t *via; @@ -129,7 +132,7 @@ DEBUGC(DBCLASS_PLUGIN, "plugin_fix_bogus_via: type=%i", type); * to clean up its mess (e.g. dynamic memory allocation, database * connections, whatever the plugin messes around with) */ -int plugin_end(plugin_def_t *plugin_def){ +int PLUGIN_END(plugin_def_t *plugin_def){ INFO("plugin_fix_bogus_via ends here"); return STS_SUCCESS; } diff --git a/src/plugin_logcall.c b/src/plugin_logcall.c index fbe2943..5955d36 100644 --- a/src/plugin_logcall.c +++ b/src/plugin_logcall.c @@ -18,6 +18,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* must be defined before including */ +#define PLUGIN_NAME plugin_logcall + #include "config.h" #include @@ -46,7 +49,7 @@ extern struct siproxd_config configuration; * Initialization. * Called once suring siproxd startup. */ -int plugin_init(plugin_def_t *plugin_def) { +int PLUGIN_INIT(plugin_def_t *plugin_def) { /* API version number of siproxd that this plugin is built against. * This constant will change whenever changes to the API are made * that require adaptions in the plugin. */ @@ -67,7 +70,7 @@ int plugin_init(plugin_def_t *plugin_def) { * Processing. * */ -int plugin_process(int stage, sip_ticket_t *ticket){ +int PLUGIN_PROCESS(int stage, sip_ticket_t *ticket){ osip_message_t *request; osip_uri_t *from_url = NULL; osip_uri_t *to_url = NULL; @@ -126,7 +129,7 @@ int plugin_process(int stage, sip_ticket_t *ticket){ * to clean up its mess (e.g. dynamic memory allocation, database * connections, whatever the plugin messes around with) */ -int plugin_end(plugin_def_t *plugin_def){ +int PLUGIN_END(plugin_def_t *plugin_def){ return STS_SUCCESS; } diff --git a/src/plugin_shortdial.c b/src/plugin_shortdial.c index 7ddf717..ae67114 100644 --- a/src/plugin_shortdial.c +++ b/src/plugin_shortdial.c @@ -18,6 +18,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* must be defined before including */ +#define PLUGIN_NAME plugin_shortdial + #include "config.h" #include @@ -66,7 +69,7 @@ static int plugin_shortdial(sip_ticket_t *ticket); * Plugin API functions code */ /* Initialization */ -int plugin_init(plugin_def_t *plugin_def) { +int PLUGIN_INIT(plugin_def_t *plugin_def) { plugin_def->api_version=SIPROXD_API_VERSION; plugin_def->name=name; plugin_def->desc=desc; @@ -84,14 +87,14 @@ int plugin_init(plugin_def_t *plugin_def) { } /* Processing */ -int plugin_process(int stage, sip_ticket_t *ticket){ +int PLUGIN_PROCESS(int stage, sip_ticket_t *ticket){ int sts; sts=plugin_shortdial(ticket); return sts; } /* De-Initialization */ -int plugin_end(plugin_def_t *plugin_def){ +int PLUGIN_END(plugin_def_t *plugin_def){ return STS_SUCCESS; } diff --git a/src/plugins.c b/src/plugins.c index 62225e7..56280bd 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -62,6 +62,7 @@ int load_plugins (void) { func_plugin_end_t plugin_end = NULL; /* initialize the libtool dynamic loader */ + LTDL_SET_PRELOADED_SYMBOLS(); sts = lt_dlinit(); if (sts != 0) { ERROR("ltdl (libtool dynamic loader) initialization failed."); @@ -151,6 +152,7 @@ int load_plugins (void) { /* complain and dlclose the handle...*/ ERROR("plugin %s does not provide correct API functions - skipped", configuration.load_plugin.string[i]); + INFO("make sure to specify plugin_.la to load and not the .so!"); lt_dlclose(handle); } } diff --git a/src/plugins.h b/src/plugins.h index 5f4347a..aa7c4f2 100644 --- a/src/plugins.h +++ b/src/plugins.h @@ -58,7 +58,7 @@ typedef struct { lt_ptr dlhandle; /* handle returned by dlopen() */ } plugin_def_t; -#define SIPROXD_API_VERSION 0x0100 +#define SIPROXD_API_VERSION 0x0101 /* The plugin must provide the following entry points */ @@ -80,3 +80,14 @@ typedef struct { int plugin_init(plugin_def_t *plugin_def); int plugin_process(int stage, sip_ticket_t *ticket); int plugin_end(plugin_def_t *plugin_def); + +/* libltdl symbol name magic... + convert plugin_init into _LTX_plugin_init */ + +#if defined (PLUGIN_NAME) +#define JOIN(x, y) JOIN_AGAIN(x, y) +#define JOIN_AGAIN(x, y) x ## y +#define PLUGIN_INIT JOIN(PLUGIN_NAME, _LTX_plugin_init) +#define PLUGIN_PROCESS JOIN(PLUGIN_NAME, _LTX_plugin_process) +#define PLUGIN_END JOIN(PLUGIN_NAME, _LTX_plugin_end) +#endif