Browse code

siputils: added cmp_hdr_name(hname1, hname2)

Daniel-Constantin Mierla authored on 30/07/2021 14:04:30
Showing 4 changed files
... ...
@@ -921,7 +921,7 @@ if(cmp_uri("$ru", "sip:kamailio@kamailio.org"))
921 921
 		<function moreinfo="none">cmp_aor(str1, str2)</function>
922 922
 		</title>
923 923
 		<para>
924
-		The function returns <emphasis>true</emphasis> if 
924
+		The function returns <emphasis>true</emphasis> if
925 925
 		the two parameters matches as AoR. The parameters have to be SIP
926 926
 		URIs.
927 927
 		</para>
... ...
@@ -937,6 +937,29 @@ if(cmp_aor("$rU@KaMaIlIo.org", "sip:kamailio@$fd"))
937 937
     # do interesting stuff here
938 938
 }
939 939
 ...
940
+</programlisting>
941
+		</example>
942
+	</section>
943
+	<section id="siputils.f.cmp_hdr_name">
944
+		<title>
945
+		<function moreinfo="none">cmp_hdr_name(str1, str2)</function>
946
+		</title>
947
+		<para>
948
+		The function returns <emphasis>true</emphasis> (return code 1) if
949
+		the two parameters matches as header names.
950
+		</para>
951
+		<para>
952
+		This function can be used from ANY_ROUTE.
953
+		</para>
954
+		<example>
955
+		<title><function>cmp_hdr_name</function> usage</title>
956
+		<programlisting format="linespecific">
957
+...
958
+if(cmp_hdr_name("$var(hname)", "From"))
959
+{
960
+    # do interesting stuff here
961
+}
962
+...
940 963
 </programlisting>
941 964
 		</example>
942 965
 	</section>
... ...
@@ -88,6 +88,34 @@ int w_cmp_aor(struct sip_msg *msg, char *uri1, char *uri2)
88 88
 	return -2;
89 89
 }
90 90
 
91
+int ki_cmp_hdr_name(sip_msg_t *msg, str *shname1, str *shname2)
92
+{
93
+	int ret;
94
+
95
+	ret = cmp_hdrname_str(shname1, shname2);
96
+	if(ret==0)
97
+		return 1;
98
+	if(ret>0)
99
+		return -1;
100
+	return -2;
101
+}
102
+
103
+int w_cmp_hdr_name(sip_msg_t *msg, char *hname1, char *hname2)
104
+{
105
+	str shname1;
106
+	str shname2;
107
+
108
+	if(fixup_get_svalue(msg, (gparam_p)hname1, &shname1)!=0) {
109
+		LM_ERR("cannot get first parameter\n");
110
+		return -8;
111
+	}
112
+	if(fixup_get_svalue(msg, (gparam_p)hname2, &shname2)!=0) {
113
+		LM_ERR("cannot get second parameter\n");
114
+		return -8;
115
+	}
116
+	return ki_cmp_hdr_name(msg, &shname1, &shname2);
117
+}
118
+
91 119
 int w_is_gruu(sip_msg_t *msg, char *uri1, char *p2)
92 120
 {
93 121
 	str s1, *s2;
... ...
@@ -36,6 +36,8 @@
36 36
 
37 37
 int w_cmp_uri(struct sip_msg *msg, char *uri1, char *uri2);
38 38
 int w_cmp_aor(struct sip_msg *msg, char *uri1, char *uri2);
39
+int ki_cmp_hdr_name(sip_msg_t *msg, str *shname1, str *shname2);
40
+int w_cmp_hdr_name(sip_msg_t *msg, char *hname1, char *hname2);
39 41
 int w_is_gruu(sip_msg_t *msg, char *uri1, char *p2);
40 42
 int w_is_supported(sip_msg_t *msg, char *_option, char *p2);
41 43
 int w_is_first_hop(sip_msg_t *msg, char *p1, char *p2);
... ...
@@ -166,6 +166,8 @@ static cmd_export_t cmds[]={
166 166
 		0, ANY_ROUTE},
167 167
 	{"cmp_aor",  (cmd_function)w_cmp_aor,                   2, fixup_spve_spve,
168 168
 		0, ANY_ROUTE},
169
+	{"cmp_hdr_name",  (cmd_function)w_cmp_hdr_name,         2, fixup_spve_spve,
170
+		0, ANY_ROUTE},
169 171
 	{"is_rpid_user_e164",   (cmd_function)is_rpid_user_e164, 0, 0,
170 172
 		0, REQUEST_ROUTE},
171 173
 	{"append_rpid_hf",      (cmd_function)append_rpid_hf,    0, 0,
... ...
@@ -738,6 +740,11 @@ static sr_kemi_t sr_kemi_siputils_exports[] = {
738 740
 		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
739 741
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
740 742
 	},
743
+	{ str_init("siputils"), str_init("cmp_hdr_name"),
744
+		SR_KEMIP_INT, ki_cmp_hdr_name,
745
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
746
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
747
+	},
741 748
 
742 749
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
743 750
 };