Module: kamailio
Branch: master
Commit: 797442522a8e996179059de7400332f4e96037b6
URL:
https://github.com/kamailio/kamailio/commit/797442522a8e996179059de7400332f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-01-26T14:54:40+01:00
textops: new function to check if a character in a list is found in string
- str_any_in(txt, clist) - look if any char in clist is inside txt
---
Modified: src/modules/textops/textops.c
---
Diff:
https://github.com/kamailio/kamailio/commit/797442522a8e996179059de7400332f…
Patch:
https://github.com/kamailio/kamailio/commit/797442522a8e996179059de7400332f…
---
diff --git a/src/modules/textops/textops.c b/src/modules/textops/textops.c
index e4de8600d2..8705caa379 100644
--- a/src/modules/textops/textops.c
+++ b/src/modules/textops/textops.c
@@ -139,6 +139,7 @@ static int starts_with_f(struct sip_msg *msg, char *str1, char *str2
);
static int ends_with_f(struct sip_msg *msg, char *str1, char *str2 );
static int str_find_f(sip_msg_t *msg, char *str1, char *str2 );
static int str_ifind_f(sip_msg_t *msg, char *str1, char *str2 );
+static int str_any_in_f(sip_msg_t *msg, char *str1, char *str2 );
static int remove_hf_re_f(struct sip_msg* msg, char* key, char* foo);
static int remove_hf_exp_f(sip_msg_t* msg, char* ematch, char* eskip);
static int is_present_hf_re_f(struct sip_msg* msg, char* key, char* foo);
@@ -340,6 +341,9 @@ static cmd_export_t cmds[]={
{"str_ifind", (cmd_function)str_ifind_f, 2,
fixup_spve_spve, 0,
ANY_ROUTE},
+ {"str_any_in", (cmd_function)str_any_in_f, 2,
+ fixup_spve_spve, 0,
+ ANY_ROUTE},
{"is_audio_on_hold", (cmd_function)is_audio_on_hold_f, 0,
0, 0,
ANY_ROUTE},
@@ -4633,6 +4637,42 @@ static int str_ifind_f(sip_msg_t *msg, char *str1, char *str2 )
return ki_str_ifind(msg, &s1, &s2);
}
+static int ki_str_any_in(sip_msg_t *msg, str *txt, str *clist)
+{
+ int i,j;
+
+ if(txt==NULL || txt->len<=0 || clist==NULL || clist->len<=0) {
+ return -1;
+ }
+
+ for(i=0; i<txt->len; i++) {
+ for(j=0; j<clist->len; j++) {
+ if(txt->s[i] == clist->s[j]) {
+ return 1;
+ }
+ }
+ }
+
+ return -1;
+}
+
+static int str_any_in_f(struct sip_msg *msg, char *str1, char *str2 )
+{
+ str s1;
+ str s2;
+
+ if(fixup_get_svalue(msg, (gparam_p)str1, &s1)!=0) {
+ LM_ERR("cannot get first parameter\n");
+ return -8;
+ }
+ if(fixup_get_svalue(msg, (gparam_p)str2, &s2)!=0) {
+ LM_ERR("cannot get second parameter\n");
+ return -8;
+ }
+
+ return ki_str_any_in(msg, &s1, &s2);
+}
+
static int ki_is_audio_on_hold(sip_msg_t *msg)
{
int sdp_session_num = 0, sdp_stream_num;
@@ -5405,6 +5445,11 @@ static sr_kemi_t sr_kemi_textops_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("textops"), str_init("str_any_in"),
+ SR_KEMIP_INT, ki_str_any_in,
+ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ str_init("textops"), str_init("is_audio_on_hold"),
SR_KEMIP_INT, ki_is_audio_on_hold,
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,