From 927223b12b38a433d9e339af46d81fe563b021d9 Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Thu, 2 Jul 2015 10:20:33 +0000 Subject: [PATCH] plugin_stripheader: may now strip just a particular value from the headers --- ChangeLog | 3 ++ doc/siproxd.conf.example | 6 +++ src/plugin_stripheader.c | 96 ++++++++++++++++++++++++++-------------- 3 files changed, 73 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index ec301ca..09a2993 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 0.8.2 ===== + 02-Jul-2015: - fixed a possible SEGV in sip_find_direction() + - plugin_stripheader: may now strip just a particular value + from the headers 26-Jan-2015: - added plugin_codecfilter (remove particular codecs in SDP payloads) 20-Jan-2015: - added plugin_stripheader (remove particular SIP headers diff --git a/doc/siproxd.conf.example b/doc/siproxd.conf.example index b3ee70e..445864e 100644 --- a/doc/siproxd.conf.example +++ b/doc/siproxd.conf.example @@ -431,8 +431,14 @@ plugin_regex_replace = \1:001 # May be used to workaround IP fragmentation by removing "unimportant" # SIP headers - this is clearly a ugly hack but sometimes saves on # from headache. +# Format is
[:], the : part is optional - if not +# present the full header will be removed. +# +# remove entire header (all values attached to this header) plugin_stripheader_remove = Allow plugin_stripheader_remove = User-Agent +# remove only a particular value from a header (no spaces allowed) +plugin_stripheader_remove = Supported:100rel ###################################################################### # Plugin_codecfilter diff --git a/src/plugin_stripheader.c b/src/plugin_stripheader.c index 5a4a8f6..98c48e6 100644 --- a/src/plugin_stripheader.c +++ b/src/plugin_stripheader.c @@ -94,57 +94,89 @@ int PLUGIN_PROCESS(int stage, sip_ticket_t *ticket){ /* stage contains the PLUGIN_* value - the stage of SIP processing. */ int i; int pos; + char *header_remove=NULL; + char *header_remove_args=NULL; + int dlc=65535; /* deadlock counter... - just a life insurance */ for (i=0; isipmsg->headers)); - - - - while (osip_list_size(&ticket->sipmsg->headers) > j) { - tmp = (osip_header_t *) osip_list_get(&ticket->sipmsg->headers, j); -DEBUGC(DBCLASS_PLUGIN, "%s: header list j=%i, hname=%s, hvalue=%s", name, - j, tmp->hname, tmp->hvalue); -// if (osip_strcasecmp(tmp->hname, hname) == 0) { -// *dest = tmp; -// return i; -// } - j++; - } -#endif /* special case Allow header */ - if (strcasecmp(plugin_cfg.header_remove.string[i], "allow") == 0) { + if (strcasecmp(header_remove, "allow") == 0) { osip_allow_t *allow=NULL; + pos=0; while ((pos = osip_message_get_allow(ticket->sipmsg, - 0, &allow)) != -1) { - DEBUGC(DBCLASS_PLUGIN, "%s: removing Allow header pos=%i, val=%s", name, - pos, allow->value); - osip_list_remove(&ticket->sipmsg->allows, pos); - osip_allow_free(allow); - allow=NULL; + pos, &allow)) != -1) { + if (--dlc <= 0) { ERROR("deadlock counter has triggered. Likely a bug in code."); return STS_FAILURE;} + if (header_remove_args == NULL) { + /* remova all values for header */ + DEBUGC(DBCLASS_PLUGIN, "%s: removing Allow header pos=%i, val=%s", name, + pos, allow->value); + osip_list_remove(&ticket->sipmsg->allows, pos); + osip_allow_free(allow); + allow=NULL; + } else { + /* remove only values "header_remove_args" */ + if (osip_strcasecmp(header_remove_args, allow->value) == 0) { + DEBUGC(DBCLASS_PLUGIN, "%s: removing Allow header value pos=%i, val=%s", name, + pos, allow->value); + osip_list_remove(&ticket->sipmsg->allows, pos); + osip_allow_free(allow); + allow=NULL; + } else { + pos++; + } + } } /* generic headers */ } else { osip_header_t *h=NULL; + pos=0; 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); + header_remove, pos, &h)) != -1) { + if (--dlc <= 0) { ERROR("deadlock counter has triggered. Likely a bug in code."); return STS_FAILURE;} + if (header_remove_args == NULL) { + /* remova all values for header */ + 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); + } else { + /* remove only values "header_remove_args" */ + if (osip_strcasecmp(header_remove_args, h->hvalue) == 0) { + DEBUGC(DBCLASS_PLUGIN, "%s: removing header value pos=%i, name=%s, val=%s", name, + pos, h->hname, h->hvalue); + osip_list_remove(&ticket->sipmsg->headers, pos); + osip_header_free(h); + h=NULL; + } else { + pos++; + } + } // if header_remove_args } } + + /* free resources */ + if (header_remove_args) { + free (header_remove_args); + header_remove_args = NULL; + } + if (header_remove) { + free (header_remove); + header_remove = NULL; + } } return STS_SUCCESS;