Skip to content

Commit

Permalink
htable: map $shtrecord() inner names over integer ids
Browse files Browse the repository at this point in the history
- avoid string comparison at runtime

(cherry picked from commit 8ce1bcd)
  • Loading branch information
miconda committed Aug 29, 2017
1 parent a77351e commit cebcf91
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions src/modules/htable/ht_var.c
Expand Up @@ -368,49 +368,57 @@ int pv_get_ht_dec(struct sip_msg *msg, pv_param_t *param,

int pv_parse_ht_expired_cell(pv_spec_t *sp, str *in)
{
if ((in->len != 3 || strncmp(in->s, "key", in->len) != 0) &&
(in->len != 5 || strncmp(in->s, "value", in->len) != 0))
{
if(sp==NULL || in==NULL || in->len<=0)
return -1;
switch(in->len)
{
case 3:
if(strncmp(in->s, "key", in->len)==0) {
sp->pvp.pvn.u.isname.name.n = 0;
} else {
goto error;
}
break;
case 5:
if(strncmp(in->s, "value", in->len)==0) {
sp->pvp.pvn.u.isname.name.n = 1;
} else {
goto error;
}
break;
default:
goto error;
}

sp->pvp.pvn.u.isname.name.s.s = in->s;
sp->pvp.pvn.u.isname.name.s.len = in->len;
sp->pvp.pvn.u.isname.type = 0;
sp->pvp.pvn.type = PV_NAME_INTSTR;

return 0;

error:
LM_ERR("unknown pv name %.*s\n", in->len, in->s);
return -1;
}

int pv_get_ht_expired_cell(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
if (res == NULL || ht_expired_cell == NULL)
{
if (res == NULL || ht_expired_cell == NULL) {
return -1;
}

if (param->pvn.u.isname.name.s.len == 3 &&
strncmp(param->pvn.u.isname.name.s.s, "key", 3) == 0)
{
res->rs = ht_expired_cell->name;
}
else if (param->pvn.u.isname.name.s.len == 5 &&
strncmp(param->pvn.u.isname.name.s.s, "value", 5) == 0)
switch(param->pvn.u.isname.name.n)
{
if(ht_expired_cell->flags&AVP_VAL_STR) {
return pv_get_strval(msg, param, res, &ht_expired_cell->value.s);
} else {
return pv_get_sintval(msg, param, res, ht_expired_cell->value.n);
}
case 0:
return pv_get_strval(msg, param, res, &ht_expired_cell->name);
case 1:
if(ht_expired_cell->flags&AVP_VAL_STR) {
return pv_get_strval(msg, param, res, &ht_expired_cell->value.s);
} else {
return pv_get_sintval(msg, param, res, ht_expired_cell->value.n);
}
default:
return pv_get_null(msg, param, res);
}

if (res->rs.s == NULL)
res->flags = PV_VAL_NULL;
else
res->flags = PV_VAL_STR;

return 0;
}

int pv_parse_iterator_name(pv_spec_t *sp, str *in)
Expand Down

0 comments on commit cebcf91

Please sign in to comment.