Module: sip-router
Branch: master
Commit: cb6e934a591451c23f7736bd88ea5953cacd9ebf
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=cb6e934…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Mon Sep 8 22:36:30 2014 +0200
usrloc: option to set datetime columns as bigint
- should handle better daylight shifting, reported by Alistair
Cunningham
- new parameter expires_type - if set to 1, it expects expires and last
modified columns to be bigint
- the change to the type of columns has to be done manually to the
database server
- default values is 0, expecting to work with datetime columns (existing
behavior)
---
modules/usrloc/ucontact.c | 27 +++++++++------------------
modules/usrloc/udomain.c | 10 ++++------
modules/usrloc/ul_mod.c | 2 ++
modules/usrloc/ul_mod.h | 14 ++++++++++++++
4 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/modules/usrloc/ucontact.c b/modules/usrloc/ucontact.c
index f426c27..e16cee3 100644
--- a/modules/usrloc/ucontact.c
+++ b/modules/usrloc/ucontact.c
@@ -494,9 +494,8 @@ int db_insert_ucontact(ucontact_t* _c)
vals[1].val.str_val.len = _c->c.len;
keys[2] = &expires_col;
- vals[2].type = DB1_DATETIME;
vals[2].nul = 0;
- vals[2].val.time_val = _c->expires;
+ UL_DB_EXPIRES_SET(&vals[2], _c->expires);
keys[3] = &q_col;
vals[3].type = DB1_DOUBLE;
@@ -567,9 +566,8 @@ int db_insert_ucontact(ucontact_t* _c)
}
keys[nr_cols] = &last_mod_col;
- vals[nr_cols].type = DB1_DATETIME;
vals[nr_cols].nul = 0;
- vals[nr_cols].val.time_val = _c->last_modified;
+ UL_DB_EXPIRES_SET(&vals[nr_cols], _c->last_modified);
nr_cols++;
@@ -692,9 +690,8 @@ int db_update_ucontact_addr(ucontact_t* _c)
LM_DBG("callid:%.*s\n", vals1[n1].val.str_val.len, vals1[n1].val.str_val.s);
n1++;
- vals2[0].type = DB1_DATETIME;
vals2[0].nul = 0;
- vals2[0].val.time_val = _c->expires;
+ UL_DB_EXPIRES_SET(&vals2[0], _c->expires);
vals2[1].type = DB1_DOUBLE;
vals2[1].nul = 0;
@@ -748,9 +745,8 @@ int db_update_ucontact_addr(ucontact_t* _c)
vals2[9].nul = 0;
}
- vals2[10].type = DB1_DATETIME;
vals2[10].nul = 0;
- vals2[10].val.time_val = _c->last_modified;
+ UL_DB_EXPIRES_SET(&vals2[10], _c->last_modified);
nr_cols2 = 11;
if(_c->ruid.len>0)
@@ -877,9 +873,8 @@ int db_update_ucontact_ruid(ucontact_t* _c)
n2 = 0;
keys2[n2] = &expires_col;
- vals2[n2].type = DB1_DATETIME;
vals2[n2].nul = 0;
- vals2[n2].val.time_val = _c->expires;
+ UL_DB_EXPIRES_SET(&vals2[n2], _c->expires);
n2++;
keys2[n2] = &q_col;
@@ -953,9 +948,8 @@ int db_update_ucontact_ruid(ucontact_t* _c)
n2++;
keys2[n2] = &last_mod_col;
- vals2[n2].type = DB1_DATETIME;
vals2[n2].nul = 0;
- vals2[n2].val.time_val = _c->last_modified;
+ UL_DB_EXPIRES_SET(&vals2[n2], _c->last_modified);
n2++;
keys2[n2] = &callid_col;
@@ -1089,9 +1083,8 @@ int db_update_ucontact_instance(ucontact_t* _c)
n2 = 0;
keys2[n2] = &expires_col;
- vals2[n2].type = DB1_DATETIME;
vals2[n2].nul = 0;
- vals2[n2].val.time_val = _c->expires;
+ UL_DB_EXPIRES_SET(&vals2[n2], _c->expires);
n2++;
keys2[n2] = &q_col;
@@ -1165,9 +1158,8 @@ int db_update_ucontact_instance(ucontact_t* _c)
n2++;
keys2[n2] = &last_mod_col;
- vals2[n2].type = DB1_DATETIME;
vals2[n2].nul = 0;
- vals2[n2].val.time_val = _c->last_modified;
+ UL_DB_EXPIRES_SET(&vals2[n2], _c->last_modified);
n2++;
keys2[n2] = &callid_col;
@@ -1636,9 +1628,8 @@ int uldb_insert_attrs(str *_dname, str *_user, str *_domain,
vals[1].nul = 0;
vals[1].val.str_val = *_ruid;
- vals[2].type = DB1_DATETIME;
vals[2].nul = 0;
- vals[2].val.time_val = time(NULL);
+ UL_DB_EXPIRES_SET(&vals[2], time(NULL));
if (use_domain && _domain!=NULL && _domain->s!=NULL) {
nr_cols = 7;
diff --git a/modules/usrloc/udomain.c b/modules/usrloc/udomain.c
index 4178906..bf00b63 100644
--- a/modules/usrloc/udomain.c
+++ b/modules/usrloc/udomain.c
@@ -245,7 +245,7 @@ static inline ucontact_info_t* dbrow2info( db_val_t *vals, str
*contact)
LM_CRIT("empty expire\n");
return 0;
}
- ci.expires = VAL_TIME(vals+1);
+ ci.expires = UL_DB_EXPIRES_GET(vals+1);
if (VAL_NULL(vals+2)) {
LM_CRIT("empty q\n");
@@ -331,7 +331,7 @@ static inline ucontact_info_t* dbrow2info( db_val_t *vals, str
*contact)
/* last modified time */
if (!VAL_NULL(vals+12)) {
- ci.last_modified = VAL_TIME(vals+12);
+ ci.last_modified = UL_DB_EXPIRES_GET(vals+12);
}
/* record internal uid */
@@ -770,15 +770,13 @@ int db_timer_udomain(udomain_t* _d)
keys[0] = &expires_col;
ops[0] = "<";
- vals[0].type = DB1_DATETIME;
vals[0].nul = 0;
- vals[0].val.time_val = act_time + 1;
+ UL_DB_EXPIRES_SET(&vals[0], act_time + 1);
keys[1] = &expires_col;
ops[1] = "!=";
- vals[1].type = DB1_DATETIME;
vals[1].nul = 0;
- vals[1].val.time_val = 0;
+ UL_DB_EXPIRES_SET(&vals[1], 0);
if (ul_dbf.use_table(ul_dbh, _d->name) < 0) {
LM_ERR("use_table failed\n");
diff --git a/modules/usrloc/ul_mod.c b/modules/usrloc/ul_mod.c
index 7d61391..b51675e 100644
--- a/modules/usrloc/ul_mod.c
+++ b/modules/usrloc/ul_mod.c
@@ -119,6 +119,7 @@ int ul_db_check_update = 0;
int ul_keepalive_timeout = 0;
int ul_db_ops_ruid = 0;
+int ul_expires_type = 0;
str ul_xavp_contact_name = {0};
@@ -222,6 +223,7 @@ static param_export_t params[] = {
{"db_check_update", INT_PARAM, &ul_db_check_update},
{"xavp_contact", PARAM_STR, &ul_xavp_contact_name},
{"db_ops_ruid", INT_PARAM, &ul_db_ops_ruid},
+ {"expires_type", PARAM_INT, &ul_expires_type},
{0, 0, 0}
};
diff --git a/modules/usrloc/ul_mod.h b/modules/usrloc/ul_mod.h
index 5cd010c..9064cfc 100644
--- a/modules/usrloc/ul_mod.h
+++ b/modules/usrloc/ul_mod.h
@@ -108,4 +108,18 @@ extern int matching_mode;
extern int ul_db_ops_ruid;
+extern int ul_expires_type;
+
+#define UL_DB_EXPIRES_SET(r, v) do { \
+ if(ul_expires_type==1) { \
+ (r)->type = DB1_BIGINT; \
+ (r)->val.ll_val = (long long)(v); \
+ } else { \
+ (r)->type = DB1_DATETIME; \
+ (r)->val.time_val = (time_t)(v); \
+ } \
+ } while(0)
+
+#define UL_DB_EXPIRES_GET(r) ((ul_expires_type==1)?(time_t)VAL_BIGINT(r):VAL_TIME(r))
+
#endif /* UL_MOD_H */