Skip to content

Commit

Permalink
pv: exported pvx.evalx() to kemi framework
Browse files Browse the repository at this point in the history
- the equivalent of pv_evalx()
  • Loading branch information
miconda committed Sep 18, 2017
1 parent 24e09ee commit e97c7c8
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/modules/pv/pv.c
Expand Up @@ -906,6 +906,9 @@ int pv_evalx_fixup(void** param, int param_no)
return 0;
}

/**
*
*/
int w_pv_evalx(struct sip_msg *msg, char *dst, str *fmt)
{
pv_spec_t *ispec=NULL;
Expand Down Expand Up @@ -940,6 +943,41 @@ int w_pv_evalx(struct sip_msg *msg, char *dst, str *fmt)
return -1;
}

/**
*
*/
int ki_pv_evalx(sip_msg_t *msg, str *dst, str *fmt)
{
pv_value_t val;
pv_spec_t *ispec=NULL;

if(dst==NULL || dst->s==NULL || dst->len<=0) {
LM_ERR("invalid destination var name\n");
return -1;
}
ispec = pv_cache_get(dst);
if(ispec==NULL) {
LM_ERR("cannot get pv spec for [%.*s]\n", dst->len, dst->s);
return -1;
}

memset(&val, 0, sizeof(pv_value_t));
if(pv_eval_str(msg, &val.rs, fmt)<0) {
LM_ERR("cannot eval reparsed value of second parameter\n");
return -1;
}

val.flags = PV_VAL_STR;
if(ispec->setf(msg, &ispec->pvp, EQ_T, &val)<0) {
LM_ERR("setting PV failed\n");
goto error;
}

return 1;
error:
return -1;
}

/**
*
*/
Expand Down Expand Up @@ -1010,6 +1048,11 @@ static sr_kemi_t sr_kemi_pvx_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
{ str_init("pvx"), str_init("evalx"),
SR_KEMIP_INT, ki_pv_evalx,
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},

{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};
Expand All @@ -1027,4 +1070,4 @@ int mod_register(char *path, int *dlflags, void *p1, void *p2)
return -1;
}
return register_trans_mod(path, mod_trans);
}
}

0 comments on commit e97c7c8

Please sign in to comment.