Module: sip-router
Branch: master
Commit: f4f9bf6f33feee9efbd38944c45e4fad0db594ae
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f4f9bf6…
Author: Juha Heinanen <jh(a)tutpro.com>
Committer: Juha Heinanen <jh(a)tutpro.com>
Date: Sat Oct 29 18:57:50 2011 +0300
modules_k/textops: added missing in_list() implementation
- For some reason merge from jh/32plus branch to master missed in_list()
implementation.
---
modules_k/textops/textops.c | 96 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/modules_k/textops/textops.c b/modules_k/textops/textops.c
index 8d2a2a7..4fabd22 100644
--- a/modules_k/textops/textops.c
+++ b/modules_k/textops/textops.c
@@ -123,6 +123,8 @@ static int set_body_f(struct sip_msg* msg, char*, char *);
static int set_rpl_body_f(struct sip_msg* msg, char*, char *);
static int is_method_f(struct sip_msg* msg, char* , char *);
static int has_body_f(struct sip_msg *msg, char *type, char *str2 );
+static int in_list_f(struct sip_msg* _msg, char* _subject, char* _list,
+ char* _sep);
static int cmp_str_f(struct sip_msg *msg, char *str1, char *str2 );
static int cmp_istr_f(struct sip_msg *msg, char *str1, char *str2 );
static int starts_with_f(struct sip_msg *msg, char *str1, char *str2 );
@@ -135,6 +137,8 @@ static int free_hname_fixup(void** param, int param_no);
static int fixup_method(void** param, int param_no);
static int add_header_fixup(void** param, int param_no);
static int fixup_body_type(void** param, int param_no);
+static int fixup_in_list(void** param, int param_no);
+static int fixup_free_in_list(void** param, int param_no);
int fixup_regexpNL_none(void** param, int param_no);
static int mod_init(void);
@@ -240,6 +244,9 @@ static cmd_export_t cmds[]={
{"is_privacy", (cmd_function)is_privacy_f, 1,
fixup_privacy, 0,
ANY_ROUTE},
+ {"in_list", (cmd_function)in_list_f, 3, fixup_in_list,
+ fixup_free_in_list,
+ ANY_ROUTE},
{"cmp_str", (cmd_function)cmp_str_f, 2,
fixup_spve_spve, 0,
ANY_ROUTE},
@@ -1770,6 +1777,42 @@ int fixup_privacy(void** param, int param_no)
return 0;
}
+/*
+ * Fix in_list params: subject and list (strings that may contain pvars),
+ * separator (string)
+ */
+static int fixup_in_list(void** param, int param_no)
+{
+ if ((param_no == 1) || (param_no == 2)) return fixup_spve_null(param, 1);
+
+ if (param_no == 3) {
+ if ((strlen((char *)*param) != 1) || (*((char *)(*param)) == 0)) {
+ LM_ERR("invalid separator parameter\n");
+ return -1;
+ }
+ return 0;
+ }
+
+ LM_ERR("invalid parameter number <%d>\n", param_no);
+ return -1;
+}
+
+/*
+ * Free in_list params
+ */
+static int fixup_free_in_list(void** param, int param_no)
+{
+ if ((param_no == 1) || (param_no == 2)) {
+ LM_WARN("free function has not been defined for spve\n");
+ return 0;
+ }
+
+ if (param_no == 3) return 0;
+
+ LM_ERR("invalid parameter number <%d>\n", param_no);
+ return -1;
+}
+
static int add_header_fixup(void** param, int param_no)
{
if(param_no==1)
@@ -1861,6 +1904,59 @@ int is_privacy_f(struct sip_msg *msg, char *_privacy, char *str2 )
}
+/*
+ * Checks if subject is found in list
+ */
+int in_list_f(struct sip_msg* _m, char* _subject, char* _list, char* _sep)
+{
+ str subject, list;
+ int sep;
+ char *at, *past, *s;
+
+ if (fixup_get_svalue(_m, (gparam_p)_subject, &subject) != 0) {
+ LM_ERR("cannot get subject value\n");
+ return -1;
+ } else {
+ if (subject.len == 0) {
+ LM_ERR("subject cannot be empty string\n");
+ return -1;
+ }
+ }
+
+ if (fixup_get_svalue(_m, (gparam_p)_list, &list) != 0) {
+ LM_ERR("cannot get list value\n");
+ return -1;
+ } else {
+ if (list.len == 0) return -1;
+ }
+
+ sep = _sep[0];
+
+ at = list.s;
+ past = list.s + list.len;
+
+ while (at < past) {
+ s = index(at, sep);
+ if (s == NULL) {
+ if ((subject.len == (past - at)) &&
+ strncmp(at, subject.s, subject.len) == 0) {
+ return 1;
+ } else {
+ return -1;
+ }
+ } else {
+ if ((subject.len == (s - at)) &&
+ strncmp(at, subject.s, subject.len) == 0) {
+ return 1;
+ } else {
+ at = s + 1;
+ }
+ }
+ }
+
+ return -1;
+}
+
static int cmp_str_f(struct sip_msg *msg, char *str1, char *str2 )
{
str s1;