Module: kamailio
Branch: master
Commit: 389224660bc748b7e9f69fadcbbed0faf8a44b5a
URL:
https://github.com/kamailio/kamailio/commit/389224660bc748b7e9f69fadcbbed0f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-03-30T08:50:54+02:00
textops: added functions to find a string inside another one
---
Modified: src/modules/textops/textops.c
---
Diff:
https://github.com/kamailio/kamailio/commit/389224660bc748b7e9f69fadcbbed0f…
Patch:
https://github.com/kamailio/kamailio/commit/389224660bc748b7e9f69fadcbbed0f…
---
diff --git a/src/modules/textops/textops.c b/src/modules/textops/textops.c
index 1b045dc89c..3d90e97a90 100644
--- a/src/modules/textops/textops.c
+++ b/src/modules/textops/textops.c
@@ -137,6 +137,8 @@ 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 );
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 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);
@@ -324,6 +326,12 @@ static cmd_export_t cmds[]={
{"ends_with", (cmd_function)ends_with_f, 2,
fixup_spve_spve, 0,
ANY_ROUTE},
+ {"str_find", (cmd_function)str_find_f, 2,
+ fixup_spve_spve, 0,
+ ANY_ROUTE},
+ {"str_ifind", (cmd_function)str_ifind_f, 2,
+ fixup_spve_spve, 0,
+ ANY_ROUTE},
{"is_audio_on_hold", (cmd_function)is_audio_on_hold_f, 0,
0, 0,
ANY_ROUTE},
@@ -4271,6 +4279,78 @@ static int ki_ends_with(sip_msg_t *msg, str *vstr, str *vsuffix )
return -2;
}
+static int ki_str_find(sip_msg_t *msg, str *txt, str *needle)
+{
+ char *p;
+
+ if(txt==NULL || needle==NULL) {
+ return -1;
+ }
+
+ if(needle->len > txt->len) {
+ return -1;
+ }
+ p = str_search(txt, needle);
+ if(p==NULL) {
+ return -1;
+ }
+
+ return (int)(1 + p - txt->s);
+}
+
+static int str_find_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_find(msg, &s1, &s2);
+}
+
+static int ki_str_ifind(sip_msg_t *msg, str *txt, str *needle)
+{
+ char *p;
+
+ if(txt==NULL || needle==NULL) {
+ return -1;
+ }
+
+ if(needle->len > txt->len) {
+ return -1;
+ }
+ p = str_casesearch(txt, needle);
+ if(p==NULL) {
+ return -1;
+ }
+
+ return (int)(1 + p - txt->s);
+}
+
+static int str_ifind_f(sip_msg_t *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_ifind(msg, &s1, &s2);
+}
+
static int ki_is_audio_on_hold(sip_msg_t *msg)
{
int sdp_session_num = 0, sdp_stream_num;
@@ -5019,6 +5099,16 @@ 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_find"),
+ SR_KEMIP_INT, ki_str_find,
+ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("textops"), str_init("str_ifind"),
+ SR_KEMIP_INT, ki_str_ifind,
+ { 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,