Skip to content

Commit

Permalink
textops: added ends_with(str, suffix) function
Browse files Browse the repository at this point in the history
- exported to kemi
  • Loading branch information
miconda committed Jan 6, 2021
1 parent aff06f6 commit 88c25b3
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/modules/textops/textops.c
Expand Up @@ -136,6 +136,7 @@ static int in_list_prefix_f(struct sip_msg* _msg, char* _subject, char* _list,
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 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);
Expand Down Expand Up @@ -316,6 +317,9 @@ static cmd_export_t cmds[]={
{"starts_with", (cmd_function)starts_with_f, 2,
fixup_spve_spve, 0,
ANY_ROUTE},
{"ends_with", (cmd_function)ends_with_f, 2,
fixup_spve_spve, 0,
ANY_ROUTE},
{"is_audio_on_hold", (cmd_function)is_audio_on_hold_f, 0,
0, 0,
ANY_ROUTE},
Expand Down Expand Up @@ -4220,6 +4224,49 @@ static int ki_starts_with(sip_msg_t *msg, str *s1, str *s2 )
return -2;
}

static int ends_with_f(struct sip_msg *msg, char *str1, char *str2 )
{
str s1;
str s2;
int ret;

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;
}
if(s2.len > s1.len) {
return -1;
}
ret = strncmp(s1.s + s1.len - s2.len, s2.s, s2.len);
if(ret==0)
return 1;
if(ret>0)
return -1;
return -2;
}

static int ki_ends_with(sip_msg_t *msg, str *vstr, str *vsuffix )
{
int ret;

if(vstr==NULL || vsuffix==NULL) {
return -1;
}
if(vsuffix->len > vstr->len) {
return -1;
}
ret = strncmp(vstr->s + vstr->len - vsuffix->len, vsuffix->s, vsuffix->len);
if(ret==0)
return 1;
if(ret>0)
return -1;
return -2;
}

static int ki_is_audio_on_hold(sip_msg_t *msg)
{
int sdp_session_num = 0, sdp_stream_num;
Expand Down Expand Up @@ -4903,6 +4950,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("ends_with"),
SR_KEMIP_INT, ki_ends_with,
{ 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,
Expand Down

0 comments on commit 88c25b3

Please sign in to comment.