|
@@ -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;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|