Browse code

- two new functions: - cmp_str(s1, s2) - compare case sensitive two strings - cmp_istr(s1, s2) - compare case insensitive two strings

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5395 689a6050-402a-0410-94f2-e92a70836424

Daniel-Constantin Mierla authored on 29/12/2008 20:02:12
Showing 3 changed files
... ...
@@ -65,6 +65,8 @@ Daniel-Constantin Mierla
65 65
               1.3.25. remove_hf(hname)
66 66
               1.3.26. has_body(), has_body(mime)
67 67
               1.3.27. is_privacy(privacy_type)
68
+              1.3.28. cmp_str(str1, str2)
69
+              1.3.29. cmp_istr(str1, str2)
68 70
 
69 71
         1.4. Known Limitations
70 72
 
... ...
@@ -103,6 +105,8 @@ Daniel-Constantin Mierla
103 105
    1.25. remove_hf usage
104 106
    1.26. has_body usage
105 107
    1.27. is_privacy usage
108
+   1.28. cmp_str usage
109
+   1.29. cmp_str usage
106 110
 
107 111
 Chapter 1. Admin Guide
108 112
 
... ...
@@ -688,6 +692,38 @@ if(is_privacy("id"))
688 692
 }
689 693
 ...
690 694
 
695
+1.3.28.  cmp_str(str1, str2)
696
+
697
+   The function returns true if the two parameters matches as
698
+   string case sensitive comparison.
699
+
700
+   This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
701
+   FAILURE_ROUTE and BRANCH_ROUTE.
702
+
703
+   Example 1.28. cmp_str usage
704
+...
705
+if(cmp_str("$rU", "kamailio"))
706
+{
707
+    # do interesting stuff here
708
+}
709
+...
710
+
711
+1.3.29.  cmp_istr(str1, str2)
712
+
713
+   The function returns true if the two parameters matches as
714
+   string case insensitive comparison.
715
+
716
+   This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
717
+   FAILURE_ROUTE and BRANCH_ROUTE.
718
+
719
+   Example 1.29. cmp_str usage
720
+...
721
+if(cmp_istr("$rU@you", "kamailio@YOU"))
722
+{
723
+    # do interesting stuff here
724
+}
725
+...
726
+
691 727
 1.4. Known Limitations
692 728
 
693 729
    Search functions are applied to the original request, i.e.,
... ...
@@ -1050,6 +1050,56 @@ if(is_privacy("id"))
1050 1050
 		</example>
1051 1051
 	</section>
1052 1052
 
1053
+	<section>
1054
+		<title>
1055
+		<function moreinfo="none">cmp_str(str1, str2)</function>
1056
+		</title>
1057
+		<para>
1058
+		The function returns <emphasis>true</emphasis> if 
1059
+		the two parameters matches as string case sensitive comparison.
1060
+		</para>
1061
+   		<para>
1062
+		This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, 
1063
+		FAILURE_ROUTE and BRANCH_ROUTE.
1064
+		</para>
1065
+		<example>
1066
+		<title><function>cmp_str</function> usage</title>
1067
+		<programlisting format="linespecific">
1068
+...
1069
+if(cmp_str("$rU", "kamailio"))
1070
+{
1071
+    # do interesting stuff here
1072
+}
1073
+...
1074
+</programlisting>
1075
+		</example>
1076
+	</section>
1077
+
1078
+	<section>
1079
+		<title>
1080
+		<function moreinfo="none">cmp_istr(str1, str2)</function>
1081
+		</title>
1082
+		<para>
1083
+		The function returns <emphasis>true</emphasis> if 
1084
+		the two parameters matches as string case insensitive comparison.
1085
+		</para>
1086
+   		<para>
1087
+		This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, 
1088
+		FAILURE_ROUTE and BRANCH_ROUTE.
1089
+		</para>
1090
+		<example>
1091
+		<title><function>cmp_str</function> usage</title>
1092
+		<programlisting format="linespecific">
1093
+...
1094
+if(cmp_istr("$rU@you", "kamailio@YOU"))
1095
+{
1096
+    # do interesting stuff here
1097
+}
1098
+...
1099
+</programlisting>
1100
+		</example>
1101
+	</section>
1102
+
1053 1103
 	</section>
1054 1104
 	<section>
1055 1105
 		<title>Known Limitations</title>
... ...
@@ -66,6 +66,7 @@
66 66
 #include "../../parser/parse_privacy.h"
67 67
 #include "../../mod_fix.h"
68 68
 #include "../../ut.h"
69
+#include "../../cmpapi.h"
69 70
 #include <stdio.h>
70 71
 #include <stdlib.h>
71 72
 #include <string.h>
... ...
@@ -115,6 +116,8 @@ static int insert_body_f(struct sip_msg* msg, char*, char *);
115 116
 static int is_method_f(struct sip_msg* msg, char* , char *);
116 117
 static int has_body_f(struct sip_msg *msg, char *type, char *str2 );
117 118
 static int is_privacy_f(struct sip_msg *msg, char *privacy, char *str2 );
119
+static int cmp_str_f(struct sip_msg *msg, char *str1, char *str2 );
120
+static int cmp_istr_f(struct sip_msg *msg, char *str1, char *str2 );
118 121
 
119 122
 static int fixup_substre(void**, int);
120 123
 static int hname_fixup(void** param, int param_no);
... ...
@@ -218,6 +221,13 @@ static cmd_export_t cmds[]={
218 221
 	{"is_privacy",       (cmd_function)is_privacy_f,      1,
219 222
 		fixup_privacy, 0,
220 223
 		REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
224
+	{"cmp_str",  (cmd_function)cmp_str_f, 2,
225
+		fixup_spve_spve, 0,
226
+		REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
227
+	{"cmp_istr",  (cmd_function)cmp_istr_f, 2,
228
+		fixup_spve_spve, 0,
229
+		REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
230
+
221 231
 	{0,0,0,0,0,0}
222 232
 };
223 233
 
... ...
@@ -1545,3 +1555,52 @@ static int is_privacy_f(struct sip_msg *msg, char *_privacy, char *str2 )
1545 1555
     return get_privacy_values(msg) & ((unsigned int)(long)_privacy) ? 1 : -1;
1546 1556
 
1547 1557
 }
1558
+
1559
+static int cmp_str_f(struct sip_msg *msg, char *str1, char *str2 )
1560
+{
1561
+	str s1;
1562
+	str s2;
1563
+	int ret;
1564
+
1565
+	if(fixup_get_svalue(msg, (gparam_p)str1, &s1)!=0)
1566
+	{
1567
+		LM_ERR("cannot get first parameter\n");
1568
+		return -8;
1569
+	}
1570
+	if(fixup_get_svalue(msg, (gparam_p)str2, &s2)!=0)
1571
+	{
1572
+		LM_ERR("cannot get second parameter\n");
1573
+		return -8;
1574
+	}
1575
+	ret = cmp_str(&s1, &s2);
1576
+	if(ret==0)
1577
+		return 1;
1578
+	if(ret>0)
1579
+		return -1;
1580
+	return -2;
1581
+}
1582
+
1583
+static int cmp_istr_f(struct sip_msg *msg, char *str1, char *str2)
1584
+{
1585
+	str s1;
1586
+	str s2;
1587
+	int ret;
1588
+
1589
+	if(fixup_get_svalue(msg, (gparam_p)str1, &s1)!=0)
1590
+	{
1591
+		LM_ERR("cannot get first parameter\n");
1592
+		return -8;
1593
+	}
1594
+	if(fixup_get_svalue(msg, (gparam_p)str2, &s2)!=0)
1595
+	{
1596
+		LM_ERR("cannot get second parameter\n");
1597
+		return -8;
1598
+	}
1599
+	ret = cmpi_str(&s1, &s2);
1600
+	if(ret==0)
1601
+		return 1;
1602
+	if(ret>0)
1603
+		return -1;
1604
+	return -2;
1605
+}
1606
+