From b4f3a24c001b0d8f7de491f97738b6f71facc434 Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Tue, 20 Jan 2015 20:26:48 +0000 Subject: [PATCH] added plugin_stripheader --- doc/siproxd.conf.example | 11 ++++ src/Makefile.am | 14 ++++- src/plugin_regex.c | 2 +- src/plugin_stripheader.c | 124 +++++++++++++++++++++++++++++++++++++++ src/proxy.c | 2 +- 5 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 src/plugin_stripheader.c diff --git a/doc/siproxd.conf.example b/doc/siproxd.conf.example index a6ba169..2efca71 100644 --- a/doc/siproxd.conf.example +++ b/doc/siproxd.conf.example @@ -334,6 +334,7 @@ load_plugin=plugin_logcall.la #load_plugin=plugin_stun.la #load_plugin=plugin_prefix.la #load_plugin=plugin_regex.la +#load_plugin=plugin_stripheader.la ###################################################################### @@ -421,3 +422,13 @@ plugin_regex_replace = \1+a plugin_regex_desc = Test Regex 3 plugin_regex_pattern = ^(sips?:)01 plugin_regex_replace = \1:001 + +###################################################################### +# Plugin_stripheader +# +# unconditionally strip the specified SIP header from the packet. +# May be used to workaround IP fragmentation by removing "unimportant" +# SIP headers - this is clearly a ugly hack but sometimes saves on +# from headache. +plugin_stripheader_remove = Accept +plugin_stripheader_remove = User-Agent diff --git a/src/Makefile.am b/src/Makefile.am index adc85c4..d23bb10 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,7 +36,9 @@ pkglib_LTLIBRARIES = plugin_demo.la \ plugin_fix_bogus_via.la \ plugin_stun.la \ plugin_prefix.la \ - plugin_regex.la + plugin_regex.la \ + plugin_codecfilter.la \ + plugin_stripheader.la DLOPENPLUGINS = -dlopen plugin_demo.la \ -dlopen plugin_shortdial.la \ -dlopen plugin_logcall.la \ @@ -44,7 +46,9 @@ DLOPENPLUGINS = -dlopen plugin_demo.la \ -dlopen plugin_fix_bogus_via.la \ -dlopen plugin_stun.la \ -dlopen plugin_prefix.la \ - -dlopen plugin_regex.la + -dlopen plugin_regex.la \ + -dlopen plugin_codecfilter.la \ + -dlopen plugin_stripheader.la # plugin_demo_la_SOURCES = plugin_demo.c plugin_demo_la_LDFLAGS = -module -avoid-version -shrext '.so' @@ -69,6 +73,12 @@ plugin_prefix_la_LDFLAGS = -module -avoid-version -shrext '.so' # plugin_regex_la_SOURCES = plugin_regex.c plugin_regex_la_LDFLAGS = -module -avoid-version -shrext '.so' +# +plugin_codecfilter_la_SOURCES = plugin_codecfilter.c +plugin_codecfilter_la_LDFLAGS = -module -avoid-version -shrext '.so' +# +plugin_stripheader_la_SOURCES = plugin_stripheader.c +plugin_stripheader_la_LDFLAGS = -module -avoid-version -shrext '.so' # diff --git a/src/plugin_regex.c b/src/plugin_regex.c index d9f4b48..3603ac6 100644 --- a/src/plugin_regex.c +++ b/src/plugin_regex.c @@ -45,7 +45,7 @@ #include "redirect_cache.h" #include "log.h" -static char const ident[]="$Id: plugin_regex.c 471 2011-05-28 10:03:49Z hb9xar $"; +static char const ident[]="$Id$"; /* Plug-in identification */ static char name[]="plugin_regex"; diff --git a/src/plugin_stripheader.c b/src/plugin_stripheader.c new file mode 100644 index 0000000..485b4d2 --- /dev/null +++ b/src/plugin_stripheader.c @@ -0,0 +1,124 @@ +/* + Copyright (C) 2015 Thomas Ries + + This file is part of Siproxd. + + Siproxd 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 2 of the License, or + (at your option) any later version. + + Siproxd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warrantry 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 Siproxd; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* must be defined before including */ +#define PLUGIN_NAME plugin_stripheader + +#include "config.h" + +#include + +#include +#include +#include + +#include +#include + +#include "siproxd.h" +#include "plugins.h" +#include "log.h" + +static char const ident[]="$Id$"; + +/* Plug-in identification */ +static char name[]="plugin_stripheader"; +static char desc[]="Allows removing SIP headers"; + +/* global configuration storage - required for config file location */ +extern struct siproxd_config configuration; + +/* plugin configuration storage */ +static struct plugin_config { + stringa_t header_remove; +} plugin_cfg; + +/* Instructions for config parser */ +static cfgopts_t plugin_cfg_opts[] = { + { "plugin_stripheader_remove", TYP_STRINGA, &plugin_cfg.header_remove, {0, NULL} }, + {0, 0, 0} +}; + +/* + * Initialization. + * Called once suring siproxd startup. + */ +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. */ + plugin_def->api_version=SIPROXD_API_VERSION; + + /* Name and descriptive text of the plugin */ + plugin_def->name=name; + plugin_def->desc=desc; + + /* Execution mask - during what stages of SIP processing shall + * the plugin be called. */ + plugin_def->exe_mask=PLUGIN_PRE_PROXY; + + /* read the config file */ + if (read_config(configuration.configfile, + configuration.config_search, + plugin_cfg_opts, name) == STS_FAILURE) { + ERROR("Plugin '%s': could not load config file", name); + return STS_FAILURE; + } + + INFO("%s is initialized", name); + return STS_SUCCESS; +} + +/* + * Processing. + * + */ +int PLUGIN_PROCESS(int stage, sip_ticket_t *ticket){ + /* stage contains the PLUGIN_* value - the stage of SIP processing. */ + int i; + int pos; + osip_header_t *h; + + for (i=0; isipmsg, + plugin_cfg.header_remove.string[i], 0, &h)) != -1) { + DEBUGC(DBCLASS_PLUGIN, "%s: removing header pos=%i, name=%s, val=%s", name, + pos, h->hname, h->hvalue); + osip_list_remove(&ticket->sipmsg->headers, pos); + osip_header_free(h); + } + } + + return STS_SUCCESS; +} + +/* + * De-Initialization. + * Called during shutdown of siproxd. Gives the plugin the chance + * 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){ + INFO("%s ends here", name); + return STS_SUCCESS; +} diff --git a/src/proxy.c b/src/proxy.c index b50f1ec..9f7fe17 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1153,7 +1153,7 @@ if (configuration.debuglevel) sprintf(clen,"%ld",(long)buflen); sts = osip_message_set_content_length(mymsg, clen); - /* free old body */ + /* free new body string*/ osip_free(buff); if (configuration.debuglevel)