diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2013-07-27 21:07:57 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2013-07-27 22:02:24 +0200 |
commit | c63f6f1f324baaff41f8ea543f32479a09a71cd0 (patch) | |
tree | 58601ec5ddd1c3f8ec24d43b911b327d7a12df0e /openbsc/src/libmsc/db.c | |
parent | e7bd863f763809b152fb21655abe7e8bba557561 (diff) |
expiration: Allow to disable the periodic location updating procedure
Disable the periodic LU using "no periodic location update" VTY
command. In that case set the expire_lu to 0 which will then be
translated to a NULL in the database layer. This leads to a bit of
copy and paste in the db_sync_subscriber method but I don't see
how we could easily use 'datetime(%i, 'unixepoch')' and 'NULL'
at the same time.
Change the query to find expired queries to check for NOT NULL
and the time being in the past. This means if there are still
old subscribers in the database they might not be expired. One
would need to execute a query like "UPATE Subscriber SET expire_lu
= 0 WHERE expire_lu is null". The same applies when disabling the
periodic LU. One would need to update the database by hand.
Manual tests executed/passed:
1.) periodic LU enabled:
* use gst LUTest.st to do a LU
* UPDATE Subscriber SET expire_lu=datetime('now');
* observe the subscriber being expired (it was)
2.) periodic LU disabled:
* use gst LUTest.st to do a LU
* verify that the expire_lu is NULL in the database
Diffstat (limited to 'openbsc/src/libmsc/db.c')
-rw-r--r-- | openbsc/src/libmsc/db.c | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c index 8a7ff90ca..21abce9de 100644 --- a/openbsc/src/libmsc/db.c +++ b/openbsc/src/libmsc/db.c @@ -639,7 +639,7 @@ static void db_set_from_query(struct gsm_subscriber *subscr, dbi_conn result) if (!dbi_result_field_is_null(result, "expire_lu")) subscr->expire_lu = dbi_result_get_datetime(result, "expire_lu"); else - subscr->expire_lu = 0; + subscr->expire_lu = GSM_SUBSCRIBER_NO_EXPIRATION; subscr->authorized = dbi_result_get_uint(result, "authorized"); } @@ -766,23 +766,42 @@ int db_sync_subscriber(struct gsm_subscriber *subscriber) } else q_tmsi = strdup("NULL"); - result = dbi_conn_queryf(conn, - "UPDATE Subscriber " - "SET updated = datetime('now'), " - "name = %s, " - "extension = %s, " - "authorized = %i, " - "tmsi = %s, " - "lac = %i, " - "expire_lu = datetime(%i, 'unixepoch') " - "WHERE imsi = %s ", - q_name, - q_extension, - subscriber->authorized, - q_tmsi, - subscriber->lac, - (int) subscriber->expire_lu, - subscriber->imsi); + if (subscriber->expire_lu == GSM_SUBSCRIBER_NO_EXPIRATION) { + result = dbi_conn_queryf(conn, + "UPDATE Subscriber " + "SET updated = datetime('now'), " + "name = %s, " + "extension = %s, " + "authorized = %i, " + "tmsi = %s, " + "lac = %i, " + "expire_lu = NULL " + "WHERE imsi = %s ", + q_name, + q_extension, + subscriber->authorized, + q_tmsi, + subscriber->lac, + subscriber->imsi); + } else { + result = dbi_conn_queryf(conn, + "UPDATE Subscriber " + "SET updated = datetime('now'), " + "name = %s, " + "extension = %s, " + "authorized = %i, " + "tmsi = %s, " + "lac = %i, " + "expire_lu = datetime(%i, 'unixepoch') " + "WHERE imsi = %s ", + q_name, + q_extension, + subscriber->authorized, + q_tmsi, + subscriber->lac, + (int) subscriber->expire_lu, + subscriber->imsi); + } free(q_tmsi); free(q_name); @@ -852,8 +871,8 @@ int db_subscriber_expire(void *priv, void (*callback)(void *priv, long long unsi "SELECT id " "FROM Subscriber " "WHERE lac != 0 AND " - "( expire_lu is NULL " - "OR expire_lu < datetime('now') ) " + "( expire_lu is NOT NULL " + "AND expire_lu < datetime('now') ) " "LIMIT 1"); if (!result) { LOGP(DDB, LOGL_ERROR, "Failed to get expired subscribers\n"); |