Module: sip-router Branch: master Commit: e65f0b69d2ea832d5ff0878c0d78758e88f3fe27 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e65f0b69...
Author: Elena-Ramona Modroiu ramona@rosdev.ro Committer: Elena-Ramona Modroiu ramona@rosdev.ro Date: Tue May 19 11:13:00 2009 +0300
htable: added pv to count items by value matching regexp
- $shtcv(ht=>regexp) - to count items in ht matching regexp
---
modules_k/htable/ht_var.c | 26 ++++++++++++++++++++++++++ modules_k/htable/ht_var.h | 3 +++ modules_k/htable/htable.c | 2 ++ 3 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/modules_k/htable/ht_var.c b/modules_k/htable/ht_var.c index fae9fc5..3f7ecba 100644 --- a/modules_k/htable/ht_var.c +++ b/modules_k/htable/ht_var.c @@ -262,4 +262,30 @@ int pv_get_ht_cn(struct sip_msg *msg, pv_param_t *param, return pv_get_sintval(msg, param, res, cnt); }
+int pv_get_ht_cv(struct sip_msg *msg, pv_param_t *param, + pv_value_t *res) +{ + str htname; + ht_pv_t *hpv; + int cnt = 0; + + hpv = (ht_pv_t*)param->pvn.u.dname; + + if(hpv->ht==NULL) + { + hpv->ht = ht_get_table(&hpv->htname); + if(hpv->ht==NULL) + return pv_get_null(msg, param, res); + } + if(pv_printf_s(msg, hpv->pve, &htname)!=0) + { + LM_ERR("cannot get $ht name\n"); + return -1; + } + + cnt = ht_count_cells_re(&htname, hpv->ht, 1); + + /* integer */ + return pv_get_sintval(msg, param, res, cnt); +}
diff --git a/modules_k/htable/ht_var.h b/modules_k/htable/ht_var.h index 4f4f021..e6856b2 100644 --- a/modules_k/htable/ht_var.h +++ b/modules_k/htable/ht_var.h @@ -36,5 +36,8 @@ int pv_set_ht_cell_expire(struct sip_msg* msg, pv_param_t *param, int op, pv_value_t *val); int pv_get_ht_cn(struct sip_msg *msg, pv_param_t *param, pv_value_t *res); +int pv_get_ht_cv(struct sip_msg *msg, pv_param_t *param, + pv_value_t *res); +
#endif diff --git a/modules_k/htable/htable.c b/modules_k/htable/htable.c index cdc77c0..4dc7f4e 100644 --- a/modules_k/htable/htable.c +++ b/modules_k/htable/htable.c @@ -64,6 +64,8 @@ static pv_export_t mod_pvs[] = { pv_parse_ht_name, 0, 0, 0 }, { {"shtcn", sizeof("shtcn")-1}, PVT_OTHER, pv_get_ht_cn, 0, pv_parse_ht_name, 0, 0, 0 }, + { {"shtcv", sizeof("shtcv")-1}, PVT_OTHER, pv_get_ht_cv, 0, + pv_parse_ht_name, 0, 0, 0 }, { {0, 0}, 0, 0, 0, 0, 0, 0, 0 } };