aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2019-04-14 16:39:12 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2019-06-07 08:05:24 +0700
commit570b4c8be244de329b76780a819db425e1c33bb7 (patch)
tree66ce7beb843560bc786df264ad1a616566d2614f /src
parent0d13e8358e376de77610293926d286aa34b9e571 (diff)
libmsc/db.c: get rid of hard-coded SMS expiry threshold
The initial idea of the SMS expiry threshold was to avoid storing SMS messages with too long validity time (e.g. 63 weeks). Unfortunately, neither this feature was properly documented, nor the expiry threshold is configurable. Moreover, it has been implemented in a wrong way, so instead of deleting the oldest expired message, it would delete the youngest one or nothing: SELECT ... FROM SMS ORDER BY created LIMIT 1; while it should be sorted by 'valid_until' in ascending order: SELECT .. FROM SMS ORDER BY valid_until LIMIT 1; Thus, if the oldest message is expired, it gets deleted. If the oldest message is not expired yet, there is nothing to delete. Change-Id: I0ce6b1ab50986dc69a2be4ea62b6a24c7f3f8f0a
Diffstat (limited to 'src')
-rw-r--r--src/libmsc/db.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/libmsc/db.c b/src/libmsc/db.c
index 705af6195..241bc866e 100644
--- a/src/libmsc/db.c
+++ b/src/libmsc/db.c
@@ -1021,20 +1021,15 @@ int db_sms_delete_sent_message_by_id(unsigned long long sms_id)
}
-static int delete_expired_sms(unsigned long long sms_id, time_t created, time_t validity_timestamp)
+static int delete_expired_sms(unsigned long long sms_id, time_t validity_timestamp)
{
dbi_result result;
- time_t now, min_created;
+ time_t now;
now = time(NULL);
- if (validity_timestamp > now)
- return -1;
- /* Our SMS expiry threshold is hard-coded to roughly 2 weeks at the moment. */
- min_created = now - (time_t)(60 * 60 * 24 * 7 * 2);
- if (min_created < 0) /* bogus system clock? */
- return -1;
- if (created >= min_created) /* not yet expired */
+ /* Net yet expired */
+ if (validity_timestamp > now)
return -1;
result = dbi_conn_queryf(conn, "DELETE FROM SMS WHERE id = %llu", sms_id);
@@ -1049,9 +1044,9 @@ static int delete_expired_sms(unsigned long long sms_id, time_t created, time_t
int db_sms_delete_expired_message_by_id(unsigned long long sms_id)
{
dbi_result result;
- time_t created, validity_timestamp;
+ time_t validity_timestamp;
- result = dbi_conn_queryf(conn, "SELECT created,valid_until FROM SMS WHERE id = %llu", sms_id);
+ result = dbi_conn_queryf(conn, "SELECT valid_until FROM SMS WHERE id = %llu", sms_id);
if (!result)
return -1;
if (!next_row(result)) {
@@ -1059,29 +1054,28 @@ int db_sms_delete_expired_message_by_id(unsigned long long sms_id)
return -1;
}
- created = dbi_result_get_datetime(result, "created");
validity_timestamp = dbi_result_get_datetime(result, "valid_until");
dbi_result_free(result);
- return delete_expired_sms(sms_id, created, validity_timestamp);
+ return delete_expired_sms(sms_id, validity_timestamp);
}
void db_sms_delete_oldest_expired_message(void)
{
dbi_result result;
- result = dbi_conn_queryf(conn, "SELECT id,created,valid_until FROM SMS ORDER BY created LIMIT 1");
+ result = dbi_conn_queryf(conn, "SELECT id,valid_until FROM SMS "
+ "ORDER BY valid_until LIMIT 1");
if (!result)
return;
if (next_row(result)) {
unsigned long long sms_id;
- time_t created, validity_timestamp;
+ time_t validity_timestamp;
sms_id = dbi_result_get_ulonglong(result, "id");
- created = dbi_result_get_datetime(result, "created");
validity_timestamp = dbi_result_get_datetime(result, "valid_until");
- delete_expired_sms(sms_id, created, validity_timestamp);
+ delete_expired_sms(sms_id, validity_timestamp);
}
dbi_result_free(result);