added plugin_stripheader
This commit is contained in:
parent
5a8837077a
commit
b4f3a24c00
@ -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
|
||||
|
||||
@ -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'
|
||||
|
||||
|
||||
#
|
||||
|
||||
@ -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";
|
||||
|
||||
124
src/plugin_stripheader.c
Normal file
124
src/plugin_stripheader.c
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright (C) 2015 Thomas Ries <tries@gmx.net>
|
||||
|
||||
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 <plugin.h> */
|
||||
#define PLUGIN_NAME plugin_stripheader
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <osipparser2/osip_parser.h>
|
||||
#include <osipparser2/sdp_message.h>
|
||||
|
||||
#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; i<plugin_cfg.header_remove.used; i++) {
|
||||
DEBUGC(DBCLASS_PLUGIN, "%s: looking for header [%s]", name,
|
||||
plugin_cfg.header_remove.string[i]);
|
||||
|
||||
while ((pos = osip_message_header_get_byname(ticket->sipmsg,
|
||||
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;
|
||||
}
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user