Module: kamailio
Branch: master
Commit: 8ce1bcd52cd5117f920acce5f78683e974d4a3a4
URL: 
https://github.com/kamailio/kamailio/commit/8ce1bcd52cd5117f920acce5f78683e974d4a3a4

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2017-06-24T08:18:18+02:00

htable: map $shtrecord() inner names over integer ids

- avoid string comparison at runtime

---

Modified: src/modules/htable/ht_var.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/8ce1bcd52cd5117f920acce5f78683e974d4a3a4.diff
Patch: 
https://github.com/kamailio/kamailio/commit/8ce1bcd52cd5117f920acce5f78683e974d4a3a4.patch

---

diff --git a/src/modules/htable/ht_var.c b/src/modules/htable/ht_var.c
index c928bf1b49..2713f41ddd 100644
--- a/src/modules/htable/ht_var.c
+++ b/src/modules/htable/ht_var.c
@@ -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)


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to