Module: kamailio
Branch: master
Commit: d8fa1ae396305f6f05607f5bc0914913adc6bf7d
URL:
https://github.com/kamailio/kamailio/commit/d8fa1ae396305f6f05607f5bc091491…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-03-29T12:41:41+02:00
pv: new variable - $hdrc(HName)
- return the number of headers matching the name with HName
- e.g., $hdrc(Via)
---
Modified: src/modules/pv/pv.c
Modified: src/modules/pv/pv_core.c
Modified: src/modules/pv/pv_core.h
---
Diff:
https://github.com/kamailio/kamailio/commit/d8fa1ae396305f6f05607f5bc091491…
Patch:
https://github.com/kamailio/kamailio/commit/d8fa1ae396305f6f05607f5bc091491…
---
diff --git a/src/modules/pv/pv.c b/src/modules/pv/pv.c
index f1e1f41..4d0df10 100644
--- a/src/modules/pv/pv.c
+++ b/src/modules/pv/pv.c
@@ -97,6 +97,8 @@ static pv_export_t mod_pvs[] = {
pv_parse_avp_name, pv_parse_index, 0, 0},
{{"hdr", (sizeof("hdr")-1)}, PVT_HDR, pv_get_hdr, 0,
pv_parse_hdr_name,
pv_parse_index, 0, 0},
+ {{"hdrc", (sizeof("hdrc")-1)}, PVT_HDRC, pv_get_hdrc, 0,
pv_parse_hdr_name,
+ 0, 0, 0},
{{"var", (sizeof("var")-1)}, PVT_SCRIPTVAR, pv_get_scriptvar,
pv_set_scriptvar, pv_parse_scriptvar_name, 0, 0, 0},
{{"vz", (sizeof("vz")-1)}, PVT_SCRIPTVAR, pv_get_scriptvar,
diff --git a/src/modules/pv/pv_core.c b/src/modules/pv/pv_core.c
index f1d264b..40a9952 100644
--- a/src/modules/pv/pv_core.c
+++ b/src/modules/pv/pv_core.c
@@ -1797,6 +1797,70 @@ int pv_get_hdr(struct sip_msg *msg, pv_param_t *param, pv_value_t
*res)
}
+/**
+ *
+ */
+int pv_get_hdrc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
+{
+ int idx;
+ int idxf;
+ pv_value_t tv;
+ struct hdr_field *hf;
+ struct hdr_field *hf0;
+ char *p, *p_ini;
+ int n, p_size;
+ int hcount;
+
+ if(msg==NULL || res==NULL || param==NULL)
+ return -1;
+
+ hcount = 0;
+
+ /* get the name */
+ if(param->pvn.type == PV_NAME_PVAR)
+ {
+ if(pv_get_spec_name(msg, param, &tv)!=0 || (!(tv.flags&PV_VAL_STR)))
+ {
+ LM_ERR("invalid name\n");
+ return pv_get_sintval(msg, param, res, hcount);
+ }
+ } else {
+ if(param->pvn.u.isname.type == AVP_NAME_STR)
+ {
+ tv.flags = PV_VAL_STR;
+ tv.rs = param->pvn.u.isname.name.s;
+ } else {
+ tv.flags = 0;
+ tv.ri = param->pvn.u.isname.name.n;
+ }
+ }
+ /* we need to be sure we have parsed all headers */
+ if(parse_headers(msg, HDR_EOH_F, 0)<0)
+ {
+ LM_ERR("error parsing headers\n");
+ return pv_get_sintval(msg, param, res, hcount);
+ }
+
+
+ for (hf=msg->headers; hf; hf=hf->next)
+ {
+ if(tv.flags == 0)
+ {
+ if (tv.ri==hf->type) {
+ hcount++;
+ }
+ } else {
+ if (cmp_hdrname_str(&hf->name, &tv.rs)==0) {
+ hcount++;
+ }
+ }
+ }
+ return pv_get_sintval(msg, param, res, hcount);
+}
+
+/**
+ *
+ */
int pv_get_scriptvar(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
diff --git a/src/modules/pv/pv_core.h b/src/modules/pv/pv_core.h
index 27c13bb..98e6b56 100644
--- a/src/modules/pv/pv_core.h
+++ b/src/modules/pv/pv_core.h
@@ -14,8 +14,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -28,10 +28,10 @@
int pv_get_msgid(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
-int pv_get_udp(struct sip_msg *msg, pv_param_t *param,
+int pv_get_udp(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
-int pv_get_5060(struct sip_msg *msg, pv_param_t *param,
+int pv_get_5060(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
int pv_get_return_code(struct sip_msg *msg, pv_param_t *param,
@@ -203,6 +203,8 @@ int pv_get_avp(struct sip_msg *msg, pv_param_t *param, pv_value_t
*res);
int pv_get_hdr(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+int pv_get_hdrc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+
int pv_get_scriptvar(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);