Module: sip-router
Branch: master
Commit: bbecaa597aa4fb3fa08773cd6cd9b8558c7ce3a8
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=bbecaa5…
Author: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Committer: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Date: Wed Aug 21 11:04:08 2013 +0200
avpops: allow use of avps as second parameter on re operation at avp_check function
---
modules/avpops/avpops.c | 35 +++++++++++++++--------------------
modules/avpops/avpops_impl.c | 20 ++++++++++++++++----
2 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/modules/avpops/avpops.c b/modules/avpops/avpops.c
index 4de02a1..674469b 100644
--- a/modules/avpops/avpops.c
+++ b/modules/avpops/avpops.c
@@ -683,28 +683,23 @@ static int fixup_check_avp(void** param, int param_no)
/* if REGEXP op -> compile the expresion */
if (ap->ops&AVPOPS_OP_RE)
{
- if ( (ap->opd&AVPOPS_VAL_STR)==0 )
+ if ( (ap->opd&AVPOPS_VAL_STR)!=0 )
{
- LM_ERR("regexp operation requires string value\n");
- return E_UNSPEC;
- }
- re = pkg_malloc(sizeof(regex_t));
- if (re==0)
- {
- LM_ERR("no more pkg mem\n");
- return E_OUT_OF_MEM;
- }
- LM_DBG("compiling regexp <%.*s>\n", ap->u.s.len, ap->u.s.s);
- if (regcomp(re, ap->u.s.s,
- REG_EXTENDED|REG_ICASE|REG_NEWLINE))
- {
- pkg_free(re);
- LM_ERR("bad re <%.*s>\n", ap->u.s.len, ap->u.s.s);
- return E_BAD_RE;
+ re = (regex_t*) pkg_malloc(sizeof(regex_t));
+ if (re==0)
+ {
+ LM_ERR("no more pkg mem\n");
+ return E_OUT_OF_MEM;
+ }
+ LM_DBG("compiling regexp <%.*s>\n", ap->u.s.len, ap->u.s.s);
+ if (regcomp(re, ap->u.s.s,REG_EXTENDED|REG_ICASE|REG_NEWLINE))
+ {
+ pkg_free(re);
+ LM_ERR("bad re <%.*s>\n", ap->u.s.len, ap->u.s.s);
+ return E_BAD_RE;
+ }
+ ap->u.s.s = (char*)re;
}
- /* free the string and link the regexp */
- // pkg_free(ap->sval.p.s);
- ap->u.s.s = (char*)re;
} else if (ap->ops&AVPOPS_OP_FM) {
if ( !( ap->opd&AVPOPS_VAL_PVAR ||
(!(ap->opd&AVPOPS_VAL_PVAR) && ap->opd&AVPOPS_VAL_STR) ) )
diff --git a/modules/avpops/avpops_impl.c b/modules/avpops/avpops_impl.c
index 81a8053..7dcd371 100644
--- a/modules/avpops/avpops_impl.c
+++ b/modules/avpops/avpops_impl.c
@@ -1069,6 +1069,8 @@ int ops_check_avp( struct sip_msg* msg, struct fis_param* src,
int flags;
pv_value_t xvalue;
char backup;
+ regex_t re_temp;
+ regex_t *re;
/* look if the required avp(s) is/are present */
if(src->u.sval.type==PVT_AVP)
@@ -1228,14 +1230,24 @@ cycle2:
if (strncasecmp(avp_val.s.s,check_val.s.s,n)>=0)
return 1;
} else if (val->ops&AVPOPS_OP_RE) {
+ if (val->opd&AVPOPS_VAL_PVAR) {
+ LM_DBG("compiling regexp <%.*s>\n", check_val.s.len, check_val.s.s);
+ if (regcomp(&re_temp, check_val.s.s,REG_EXTENDED|REG_ICASE|REG_NEWLINE))
+ {
+ LM_ERR("bad re <%.*s>\n", check_val.s.len, check_val.s.s);
+ goto next;
+ }
+ re = &re_temp;
+ }
+ else re = (regex_t*)check_val.s.s;
backup = avp_val.s.s[avp_val.s.len];
avp_val.s.s[avp_val.s.len] = '\0';
- if (regexec((regex_t*)check_val.s.s, avp_val.s.s, 1, &pmatch,0)==0)
- {
- avp_val.s.s[avp_val.s.len] = backup;
- return 1;
+ rt=regexec(re, avp_val.s.s, 1, &pmatch,0);
+ if (val->opd&AVPOPS_VAL_PVAR) {
+ regfree(re);
}
avp_val.s.s[avp_val.s.len] = backup;
+ if (rt==0) return 1;
} else if (val->ops&AVPOPS_OP_FM){
backup = avp_val.s.s[avp_val.s.len];
avp_val.s.s[avp_val.s.len] = '\0';