[sr-dev] git:master:7456a25e: textopsx: if no param is given to keep_hf(re), then keep only mandatory headers

Daniel-Constantin Mierla miconda at gmail.com
Mon Oct 5 07:42:22 CEST 2015


Module: kamailio
Branch: master
Commit: 7456a25e214658bbbfb420d8401366b34c6a285c
URL: https://github.com/kamailio/kamailio/commit/7456a25e214658bbbfb420d8401366b34c6a285c

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-10-05T07:42:10+02:00

textopsx: if no param is given to keep_hf(re), then keep only mandatory headers

---

Modified: modules/textopsx/textopsx.c

---

Diff:  https://github.com/kamailio/kamailio/commit/7456a25e214658bbbfb420d8401366b34c6a285c.diff
Patch: https://github.com/kamailio/kamailio/commit/7456a25e214658bbbfb420d8401366b34c6a285c.patch

---

diff --git a/modules/textopsx/textopsx.c b/modules/textopsx/textopsx.c
index b170eb8..564e9ac 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;
+			}
 		}
 	}
 




More information about the sr-dev mailing list