Module: sip-router Branch: master Commit: fcd13777bab83eeedc7628145b8e4f7430668372 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=fcd13777...
Author: Elena-Ramona Modroiu ramona@asipto.com Committer: Elena-Ramona Modroiu ramona@asipto.com Date: Mon Sep 8 18:39:36 2014 +0200
htable: new config function sht_reset("tname")
- remove all items in the hash table
---
modules/htable/ht_api.c | 32 ++++++++++++++++++++++++++++++++ modules/htable/ht_api.h | 1 + modules/htable/htable.c | 30 +++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/modules/htable/ht_api.c b/modules/htable/ht_api.c index 2bd049d..af227c0 100644 --- a/modules/htable/ht_api.c +++ b/modules/htable/ht_api.c @@ -1148,6 +1148,38 @@ int ht_rm_cell_re(str *sre, ht_t *ht, int mode) return 0; }
+int ht_reset_content(ht_t *ht) +{ + ht_cell_t *it; + ht_cell_t *it0; + int i; + + if(ht==NULL) + return -1; + + for(i=0; i<ht->htsize; i++) + { + /* free entries */ + lock_get(&ht->entries[i].lock); + it = ht->entries[i].first; + while(it) + { + it0 = it->next; + if(it->prev==NULL) + ht->entries[i].first = it->next; + else + it->prev->next = it->next; + if(it->next) + it->next->prev = it->prev; + ht->entries[i].esize--; + ht_cell_free(it); + it = it0; + } + lock_release(&ht->entries[i].lock); + } + return 0; +} + int ht_count_cells_re(str *sre, ht_t *ht, int mode) { ht_cell_t *it; diff --git a/modules/htable/ht_api.h b/modules/htable/ht_api.h index e1024dc..924b4b2 100644 --- a/modules/htable/ht_api.h +++ b/modules/htable/ht_api.h @@ -102,5 +102,6 @@ int ht_get_cell_expire(ht_t *ht, str *name, unsigned int *val); int ht_rm_cell_re(str *sre, ht_t *ht, int mode); int ht_count_cells_re(str *sre, ht_t *ht, int mode); ht_t *ht_get_root(void); +int ht_reset_content(ht_t *ht);
#endif diff --git a/modules/htable/htable.c b/modules/htable/htable.c index 0dfdcda..563773e 100644 --- a/modules/htable/htable.c +++ b/modules/htable/htable.c @@ -1,7 +1,5 @@ /** - * $Id$ - * - * Copyright (C) 2008 Elena-Ramona Modroiu (asipto.com) + * Copyright (C) 2008-2014 Elena-Ramona Modroiu (asipto.com) * * This file is part of Kamailio, a free SIP server. * @@ -33,6 +31,7 @@ #include "../../route.h" #include "../../dprint.h" #include "../../hashes.h" +#include "../../mod_fix.h" #include "../../ut.h" #include "../../rpc.h" #include "../../rpc_lookup.h" @@ -66,6 +65,7 @@ static int ht_rm_name_re(struct sip_msg* msg, char* key, char* foo); static int ht_rm_value_re(struct sip_msg* msg, char* key, char* foo); static int ht_slot_lock(struct sip_msg* msg, char* key, char* foo); static int ht_slot_unlock(struct sip_msg* msg, char* key, char* foo); +static int ht_reset(struct sip_msg* msg, char* htname, char* foo);
int ht_param(modparam_t type, void* val);
@@ -111,6 +111,8 @@ static cmd_export_t cmds[]={ ANY_ROUTE}, {"sht_unlock", (cmd_function)ht_slot_unlock, 1, fixup_ht_key, 0, ANY_ROUTE}, + {"sht_reset", (cmd_function)ht_reset, 1, fixup_spve_null, 0, + ANY_ROUTE}, {"bind_htable", (cmd_function)bind_htable, 0, 0, 0, ANY_ROUTE}, {0,0,0,0,0,0} @@ -356,6 +358,28 @@ static int ht_rm_value_re(struct sip_msg* msg, char* key, char* foo) return 1; }
+static int ht_reset(struct sip_msg* msg, char* htname, char* foo) +{ + ht_t *ht; + str sname; + + if(fixup_get_svalue(msg, (gparam_t*)htname, &sname)<0 || sname.len<=0) + { + LM_ERR("cannot get hash table name\n"); + return -1; + } + ht = ht_get_table(&sname); + if(ht==NULL) + { + LM_ERR("cannot get hash table [%.*s]\n", sname.len, sname.s); + return -1; + } + if(ht_reset_content(ht)<0) + return -1; + return 1; +} + + /** * lock the slot for a given key in a hash table */