[sr-dev] git:master:988b70c6: siputils: added cmp_hdr_name(hname1, hname2)

Daniel-Constantin Mierla miconda at gmail.com
Fri Jul 30 20:23:41 CEST 2021


Module: kamailio
Branch: master
Commit: 988b70c6a8653b39753f09e8003477eadae36740
URL: https://github.com/kamailio/kamailio/commit/988b70c6a8653b39753f09e8003477eadae36740

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-07-30T16:04:30+02:00

siputils: added cmp_hdr_name(hname1, hname2)

---

Modified: src/modules/siputils/doc/siputils_admin.xml
Modified: src/modules/siputils/sipops.c
Modified: src/modules/siputils/sipops.h
Modified: src/modules/siputils/siputils.c

---

Diff:  https://github.com/kamailio/kamailio/commit/988b70c6a8653b39753f09e8003477eadae36740.diff
Patch: https://github.com/kamailio/kamailio/commit/988b70c6a8653b39753f09e8003477eadae36740.patch

---

diff --git a/src/modules/siputils/doc/siputils_admin.xml b/src/modules/siputils/doc/siputils_admin.xml
index b1dffa1c3e..2b7ac27951 100644
--- a/src/modules/siputils/doc/siputils_admin.xml
+++ b/src/modules/siputils/doc/siputils_admin.xml
@@ -921,7 +921,7 @@ if(cmp_uri("$ru", "sip:kamailio at kamailio.org"))
 		<function moreinfo="none">cmp_aor(str1, str2)</function>
 		</title>
 		<para>
-		The function returns <emphasis>true</emphasis> if 
+		The function returns <emphasis>true</emphasis> if
 		the two parameters matches as AoR. The parameters have to be SIP
 		URIs.
 		</para>
@@ -937,6 +937,29 @@ if(cmp_aor("$rU at KaMaIlIo.org", "sip:kamailio@$fd"))
     # do interesting stuff here
 }
 ...
+</programlisting>
+		</example>
+	</section>
+	<section id="siputils.f.cmp_hdr_name">
+		<title>
+		<function moreinfo="none">cmp_hdr_name(str1, str2)</function>
+		</title>
+		<para>
+		The function returns <emphasis>true</emphasis> (return code 1) if
+		the two parameters matches as header names.
+		</para>
+		<para>
+		This function can be used from ANY_ROUTE.
+		</para>
+		<example>
+		<title><function>cmp_hdr_name</function> usage</title>
+		<programlisting format="linespecific">
+...
+if(cmp_hdr_name("$var(hname)", "From"))
+{
+    # do interesting stuff here
+}
+...
 </programlisting>
 		</example>
 	</section>
diff --git a/src/modules/siputils/sipops.c b/src/modules/siputils/sipops.c
index fb1040c6ba..4cba3c3181 100644
--- a/src/modules/siputils/sipops.c
+++ b/src/modules/siputils/sipops.c
@@ -88,6 +88,34 @@ int w_cmp_aor(struct sip_msg *msg, char *uri1, char *uri2)
 	return -2;
 }
 
+int ki_cmp_hdr_name(sip_msg_t *msg, str *shname1, str *shname2)
+{
+	int ret;
+
+	ret = cmp_hdrname_str(shname1, shname2);
+	if(ret==0)
+		return 1;
+	if(ret>0)
+		return -1;
+	return -2;
+}
+
+int w_cmp_hdr_name(sip_msg_t *msg, char *hname1, char *hname2)
+{
+	str shname1;
+	str shname2;
+
+	if(fixup_get_svalue(msg, (gparam_p)hname1, &shname1)!=0) {
+		LM_ERR("cannot get first parameter\n");
+		return -8;
+	}
+	if(fixup_get_svalue(msg, (gparam_p)hname2, &shname2)!=0) {
+		LM_ERR("cannot get second parameter\n");
+		return -8;
+	}
+	return ki_cmp_hdr_name(msg, &shname1, &shname2);
+}
+
 int w_is_gruu(sip_msg_t *msg, char *uri1, char *p2)
 {
 	str s1, *s2;
diff --git a/src/modules/siputils/sipops.h b/src/modules/siputils/sipops.h
index 97d885c71c..9926358e0a 100644
--- a/src/modules/siputils/sipops.h
+++ b/src/modules/siputils/sipops.h
@@ -36,6 +36,8 @@
 
 int w_cmp_uri(struct sip_msg *msg, char *uri1, char *uri2);
 int w_cmp_aor(struct sip_msg *msg, char *uri1, char *uri2);
+int ki_cmp_hdr_name(sip_msg_t *msg, str *shname1, str *shname2);
+int w_cmp_hdr_name(sip_msg_t *msg, char *hname1, char *hname2);
 int w_is_gruu(sip_msg_t *msg, char *uri1, char *p2);
 int w_is_supported(sip_msg_t *msg, char *_option, char *p2);
 int w_is_first_hop(sip_msg_t *msg, char *p1, char *p2);
diff --git a/src/modules/siputils/siputils.c b/src/modules/siputils/siputils.c
index 3dc7188fa8..a23408ab79 100644
--- a/src/modules/siputils/siputils.c
+++ b/src/modules/siputils/siputils.c
@@ -166,6 +166,8 @@ static cmd_export_t cmds[]={
 		0, ANY_ROUTE},
 	{"cmp_aor",  (cmd_function)w_cmp_aor,                   2, fixup_spve_spve,
 		0, ANY_ROUTE},
+	{"cmp_hdr_name",  (cmd_function)w_cmp_hdr_name,         2, fixup_spve_spve,
+		0, ANY_ROUTE},
 	{"is_rpid_user_e164",   (cmd_function)is_rpid_user_e164, 0, 0,
 		0, REQUEST_ROUTE},
 	{"append_rpid_hf",      (cmd_function)append_rpid_hf,    0, 0,
@@ -738,6 +740,11 @@ static sr_kemi_t sr_kemi_siputils_exports[] = {
 		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
+	{ str_init("siputils"), str_init("cmp_hdr_name"),
+		SR_KEMIP_INT, ki_cmp_hdr_name,
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };




More information about the sr-dev mailing list