Browse code

textopsx: added hf_iterator_rm()

- remove the header at the current iterator position

Daniel-Constantin Mierla authored on 11/07/2021 12:02:07
Showing 1 changed files
... ...
@@ -76,6 +76,7 @@ static int assign_hf_value2_fixup(void **param, int param_no);
76 76
 static int w_hf_iterator_start(sip_msg_t *msg, char *piname, char *p2);
77 77
 static int w_hf_iterator_next(sip_msg_t *msg, char *piname, char *p2);
78 78
 static int w_hf_iterator_end(sip_msg_t *msg, char *piname, char *p2);
79
+static int w_hf_iterator_rm(sip_msg_t *msg, char *piname, char *p2);
79 80
 
80 81
 static int bind_textopsx(textopsx_api_t *tob);
81 82
 
... ...
@@ -136,6 +137,8 @@ static cmd_export_t cmds[] = {
136 137
 			fixup_free_spve_null, ANY_ROUTE},
137 138
 	{"hf_iterator_end", w_hf_iterator_end, 1, fixup_spve_null,
138 139
 			fixup_free_spve_null, ANY_ROUTE},
140
+	{"hf_iterator_rm", w_hf_iterator_rm, 1, fixup_spve_null,
141
+			fixup_free_spve_null, ANY_ROUTE},
139 142
 
140 143
 	{"bind_textopsx", (cmd_function)bind_textopsx, 1, 0, 0, ANY_ROUTE},
141 144
 
... ...
@@ -1993,6 +1996,67 @@ static int w_hf_iterator_end(sip_msg_t *msg, char *piname, char *p2)
1993 1996
 	return ki_hf_iterator_end(msg, &iname);
1994 1997
 }
1995 1998
 
1999
+/**
2000
+ *
2001
+ */
2002
+static int ki_hf_iterator_index(sip_msg_t *msg, str *iname)
2003
+{
2004
+	int i;
2005
+	int k;
2006
+
2007
+	k = -1;
2008
+	for(i=0; i<HF_ITERATOR_SIZE; i++) {
2009
+		if(_hf_iterators[i].name.len>0) {
2010
+			if(_hf_iterators[i].name.len==iname->len
2011
+					&& strncmp(_hf_iterators[i].name.s, iname->s, iname->len)==0) {
2012
+				k = i;
2013
+				break;
2014
+			}
2015
+		}
2016
+	}
2017
+	if(k==-1) {
2018
+		LM_ERR("iterator not available [%.*s]\n", iname->len, iname->s);
2019
+		return -1;
2020
+	}
2021
+
2022
+	return k;
2023
+}
2024
+
2025
+/**
2026
+ *
2027
+ */
2028
+static int ki_hf_iterator_rm(sip_msg_t *msg, str *iname)
2029
+{
2030
+	int k;
2031
+	sr_lump_t *anchor;
2032
+
2033
+	k = ki_hf_iterator_index(msg, iname);
2034
+	if(k<0 || _hf_iterators[k].it==NULL) {
2035
+		return -1;
2036
+	}
2037
+	anchor = del_lump(msg, _hf_iterators[k].it->name.s - msg->buf,
2038
+			_hf_iterators[k].it->len, 0);
2039
+	if (anchor==0) {
2040
+		LM_ERR("cannot remove hdr %.*s\n", _hf_iterators[k].it->name.len,
2041
+				_hf_iterators[k].it->name.s);
2042
+		return -1;
2043
+	}
2044
+	return 1;
2045
+}
2046
+
2047
+/**
2048
+ *
2049
+ */
2050
+static int w_hf_iterator_rm(sip_msg_t *msg, char *piname, char *p2)
2051
+{
2052
+	str iname = STR_NULL;
2053
+	if(fixup_get_svalue(msg, (gparam_t*)piname, &iname)<0) {
2054
+		LM_ERR("failed to get iterator name\n");
2055
+		return -1;
2056
+	}
2057
+	return ki_hf_iterator_rm(msg, &iname);
2058
+}
2059
+
1996 2060
 /**
1997 2061
  *
1998 2062
  */
... ...
@@ -2606,6 +2670,11 @@ static sr_kemi_t sr_kemi_textopsx_exports[] = {
2606 2670
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
2607 2671
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2608 2672
 	},
2673
+	{ str_init("textopsx"), str_init("hf_iterator_rm"),
2674
+		SR_KEMIP_INT, ki_hf_iterator_rm,
2675
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
2676
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
2677
+	},
2609 2678
 
2610 2679
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
2611 2680
 };