From 7456a25e214658bbbfb420d8401366b34c6a285c Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Mon, 5 Oct 2015 07:41:12 +0200 Subject: [PATCH] textopsx: if no param is given to keep_hf(re), then keep only mandatory headers --- modules/textopsx/textopsx.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/modules/textopsx/textopsx.c b/modules/textopsx/textopsx.c index b170eb85eae..564e9ac76e8 100644 --- a/modules/textopsx/textopsx.c +++ b/modules/textopsx/textopsx.c @@ -84,6 +84,8 @@ static cmd_export_t cmds[] = { change_reply_status_fixup, ONREPLY_ROUTE }, {"remove_body", (cmd_function)w_remove_body_f, 0, 0, ANY_ROUTE }, + {"keep_hf", (cmd_function)w_keep_hf_f, 0, + fixup_regexp_null, ANY_ROUTE }, {"keep_hf", (cmd_function)w_keep_hf_f, 1, fixup_regexp_null, ANY_ROUTE }, {"fnmatch", (cmd_function)w_fnmatch2_f, 2, @@ -356,7 +358,11 @@ static int w_keep_hf_f(struct sip_msg* msg, char* key, char* foo) char c; struct lump* l; - re = (regex_t*)key; + if(key) { + re = (regex_t*)key; + } else { + re = NULL; + } /* we need to be sure we have seen all HFs */ parse_headers(msg, HDR_EOH_F, 0); @@ -380,20 +386,32 @@ static int w_keep_hf_f(struct sip_msg* msg, char* key, char* foo) ; } - c = hf->name.s[hf->name.len]; - hf->name.s[hf->name.len] = '\0'; - if (regexec(re, hf->name.s, 1, &pmatch, 0)!=0) - { - /* no match => remove */ - hf->name.s[hf->name.len] = c; + if(re==NULL) { + /* no regex to match => remove all */ l=del_lump(msg, hf->name.s-msg->buf, hf->len, 0); if (l==0) { - LM_ERR("cannot remove header\n"); + LM_ERR("cannot remove header [%.*s]\n", + hf->name.len, hf->name.s); return -1; } } else { - hf->name.s[hf->name.len] = c; + c = hf->name.s[hf->name.len]; + hf->name.s[hf->name.len] = '\0'; + if (regexec(re, hf->name.s, 1, &pmatch, 0)!=0) + { + /* no match => remove */ + hf->name.s[hf->name.len] = c; + l=del_lump(msg, hf->name.s-msg->buf, hf->len, 0); + if (l==0) + { + LM_ERR("cannot remove header [%.*s]\n", + hf->name.len, hf->name.s); + return -1; + } + } else { + hf->name.s[hf->name.len] = c; + } } }