Module: sip-router
Branch: master
Commit: cfea4b3d26d34fb436763516262159023873c473
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=cfea4b3…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sun Aug 14 00:04:25 2011 +0200
htable: control load/save of expires value from db via parameter
- db_expires - a new paramter to control if the expires of the items in
the hash table should be loaded/saved to database
- default is 0 - do not load/save expires value - backward
compatibility, since there might be hash tables loaded form database
but without expires
- if the hash table definition does not have an auto-expires, even
if db_expires=1, the expires column is not selected since it is not
needed
---
modules_k/htable/ht_db.c | 34 +++++++++++++++++++++++-----------
modules_k/htable/ht_db.h | 1 +
modules_k/htable/htable.c | 2 ++
3 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/modules_k/htable/ht_db.c b/modules_k/htable/ht_db.c
index 2a349c3..e1a46b2 100644
--- a/modules_k/htable/ht_db.c
+++ b/modules_k/htable/ht_db.c
@@ -141,6 +141,7 @@ int ht_db_load_table(ht_t *ht, str *dbtable, int mode)
int ret;
int cnt;
int now;
+ int ncols;
if(ht_db_con==NULL)
{
@@ -157,9 +158,12 @@ int ht_db_load_table(ht_t *ht, str *dbtable, int mode)
LM_DBG("=============== loading hash table [%.*s] from database [%.*s]\n",
ht->name.len, ht->name.s, dbtable->len, dbtable->s);
cnt = 0;
+ ncols = 4;
+ if(ht->htexpire > 0 && ht_db_expires_flag!=0)
+ ncols = 5;
if (DB_CAPABILITY(ht_dbf, DB_CAP_FETCH)) {
- if(ht_dbf.query(ht_db_con,0,0,0,db_cols,0,5,db_ord,0) < 0)
+ if(ht_dbf.query(ht_db_con,0,0,0,db_cols,0,ncols,db_ord,0) < 0)
{
LM_ERR("Error while querying db\n");
return -1;
@@ -179,7 +183,7 @@ int ht_db_load_table(ht_t *ht, str *dbtable, int mode)
}
} else {
if((ret=ht_dbf.query(ht_db_con, NULL, NULL, NULL, db_cols,
- 0, 5, db_ord, &db_res))!=0
+ 0, ncols, db_ord, &db_res))!=0
|| RES_ROW_N(db_res)<=0 )
{
if( ret==0)
@@ -208,10 +212,14 @@ int ht_db_load_table(ht_t *ht, str *dbtable, int mode)
}
kname.len = strlen(kname.s);
- expires.n = RES_ROWS(db_res)[i].values[4].val.int_val;
- if (expires.n > 0 && expires.n < now) {
- LM_DBG("skipping expired entry [%.*s] (%d)\n", kname.len, kname.s,
expires.n-now);
- continue;
+ expires.n = 0;
+ if(ht->htexpire > 0 && ht_db_expires_flag!=0) {
+ expires.n = RES_ROWS(db_res)[i].values[4].val.int_val;
+ if (expires.n > 0 && expires.n < now) {
+ LM_DBG("skipping expired entry [%.*s] (%d)\n", kname.len,
+ kname.s, expires.n-now);
+ continue;
+ }
}
cnt++;
@@ -328,6 +336,7 @@ int ht_db_save_table(ht_t *ht, str *dbtable)
str tmp;
int i;
time_t now;
+ int ncols;
if(ht_db_con==NULL)
{
@@ -390,12 +399,15 @@ int ht_db_save_table(ht_t *ht, str *dbtable)
db_vals[3].val.str_val.s = tmp.s;
db_vals[3].val.str_val.len = tmp.len;
}
+ ncols = 4;
- db_vals[4].type = DB1_INT;
- db_vals[4].nul = 0;
- db_vals[4].val.int_val = (int)it->expire;
-
- if(ht_dbf.insert(ht_db_con, db_cols, db_vals, 5) < 0)
+ if(ht_db_expires_flag!=0 && ht->htexpire > 0) {
+ db_vals[4].type = DB1_INT;
+ db_vals[4].nul = 0;
+ db_vals[4].val.int_val = (int)it->expire;
+ ncols = 5;
+ }
+ if(ht_dbf.insert(ht_db_con, db_cols, db_vals, ncols) < 0)
{
LM_ERR("failed to store key [%.*s] in table [%.*s]\n",
it->name.len, it->name.s,
diff --git a/modules_k/htable/ht_db.h b/modules_k/htable/ht_db.h
index e205743..40a37c8 100644
--- a/modules_k/htable/ht_db.h
+++ b/modules_k/htable/ht_db.h
@@ -33,6 +33,7 @@ extern str ht_db_value_column;
extern str ht_db_expires_column;
extern str ht_array_size_suffix;
extern int ht_fetch_rows;
+extern int ht_db_expires_flag;
int ht_db_init_params(void);
int ht_db_init_con(void);
diff --git a/modules_k/htable/htable.c b/modules_k/htable/htable.c
index adb357f..58e9755 100644
--- a/modules_k/htable/htable.c
+++ b/modules_k/htable/htable.c
@@ -48,6 +48,7 @@
MODULE_VERSION
int ht_timer_interval = 20;
+int ht_db_expires_flag = 0;
static int htable_init_rpc(void);
@@ -113,6 +114,7 @@ static param_export_t params[]={
{"array_size_suffix", STR_PARAM, &ht_array_size_suffix.s},
{"fetch_rows", INT_PARAM, &ht_fetch_rows},
{"timer_interval", INT_PARAM, &ht_timer_interval},
+ {"db_expires", INT_PARAM, &ht_db_expires_flag},
{0,0,0}
};