diff --git a/src/modules/htable/ht_api.c b/src/modules/htable/ht_api.c index e8c27c426e0..4812e8aacdb 100644 --- a/src/modules/htable/ht_api.c +++ b/src/modules/htable/ht_api.c @@ -851,6 +851,46 @@ ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old) return NULL; } +int ht_cell_exists(ht_t *ht, str *name) +{ + unsigned int idx; + unsigned int hid; + ht_cell_t *it; + + if(ht==NULL || ht->entries==NULL) + return 0; + + hid = ht_compute_hash(name); + + idx = ht_get_entry(hid, ht->htsize); + + /* head test and return */ + if(ht->entries[idx].first==NULL) + return 0; + + ht_slot_lock(ht, idx); + it = ht->entries[idx].first; + while(it!=NULL && it->cellid < hid) + it = it->next; + while(it!=NULL && it->cellid == hid) { + if(name->len==it->name.len + && strncmp(name->s, it->name.s, name->len)==0) { + /* found */ + if(ht->htexpire>0 && it->expire!=0 && it->expirenext; + } + ht_slot_unlock(ht, idx); + return 0; +} + + int ht_dbg(void) { int i; diff --git a/src/modules/htable/ht_api.h b/src/modules/htable/ht_api.h index d1e9d2383ee..65f821a266e 100644 --- a/src/modules/htable/ht_api.h +++ b/src/modules/htable/ht_api.h @@ -92,6 +92,7 @@ int ht_destroy(void); int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode); int ht_del_cell(ht_t *ht, str *name); ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, ht_cell_t *old); +int ht_cell_exists(ht_t *ht, str *name); int ht_dbg(void); ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old); diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c index 443502078d3..afb22fe2414 100644 --- a/src/modules/htable/htable.c +++ b/src/modules/htable/htable.c @@ -998,6 +998,31 @@ static sr_kemi_xval_t* ki_ht_getw(sip_msg_t *msg, str *htname, str *itname) } +/** + * + */ +static int ki_ht_is_null(sip_msg_t *msg, str *htname, str *itname) +{ + ht_t *ht = NULL; + + /* find the hash htable */ + ht = ht_get_table(htname); + if (ht == NULL) { + return 2; + } + + if(ht->flags==PV_VAL_INT) { + /* htable defined with default value */ + return -2; + } + + if(ht_cell_exists(ht, itname)>0) { + return -1; + } + + return 1; +} + /** * */ @@ -1816,6 +1841,11 @@ static sr_kemi_t sr_kemi_htable_exports[] = { { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE } }, + { str_init("htable"), str_init("sht_is_null"), + SR_KEMIP_INT, ki_ht_is_null, + { 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 } } };