[MERGED] osmo-msc[master]: Store/retrieve SMS validity time in the SMS datebase

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sat Jan 20 15:02:41 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: Store/retrieve SMS validity time in the SMS datebase
......................................................................


Store/retrieve SMS validity time in the SMS datebase

Compute a validity timestamp based on SMS validity time.
Store the computed value in the database and recompute the validity
time when an SMS is read from the database.

Change-Id: Id27c250d3a64cd109416450e8ca155b18a8b9568
---
M src/libmsc/db.c
1 file changed, 11 insertions(+), 8 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/libmsc/db.c b/src/libmsc/db.c
index e80ef53..4bf9b1f 100644
--- a/src/libmsc/db.c
+++ b/src/libmsc/db.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <time.h>
 #include <dbi/dbi.h>
 
 #include <osmocom/msc/gsm_data.h>
@@ -690,9 +691,7 @@
 	dbi_result result;
 	char *q_text, *q_daddr, *q_saddr;
 	unsigned char *q_udata;
-	char *validity_timestamp = "2222-2-2";
-
-	/* FIXME: generate validity timestamp based on validity_minutes */
+	time_t now, validity_timestamp;
 
 	dbi_conn_quote_string_copy(conn, (char *)sms->text, &q_text);
 	dbi_conn_quote_string_copy(conn, (char *)sms->dst.addr, &q_daddr);
@@ -700,7 +699,9 @@
 	dbi_conn_quote_binary_copy(conn, sms->user_data, sms->user_data_len,
 				   &q_udata);
 
-	/* FIXME: correct validity period */
+	now = time(NULL);
+	validity_timestamp = now + sms->validity_minutes * 60;
+
 	result = dbi_conn_queryf(conn,
 		"INSERT INTO SMS "
 		"(created, valid_until, "
@@ -710,14 +711,14 @@
 		 "user_data, text, "
 		 "dest_addr, dest_ton, dest_npi, "
 		 "src_addr, src_ton, src_npi) VALUES "
-		"(datetime('now'), %u, "
+		"(datetime('%lld', 'unixepoch'), datetime(%lld, 'unixepoch'), "
 		"%u, %u, %u, "
 		"%u, %u, %u, "
 		"%u, "
 		"%s, %s, "
 		"%s, %u, %u, "
 		"%s, %u, %u)",
-		validity_timestamp,
+		(int64_t)now, (int64_t)validity_timestamp,
 		sms->reply_path_req, sms->status_rep_req, sms->is_report,
 		sms->msg_ref, sms->protocol_id, sms->data_coding_scheme,
 		sms->ud_hdr_ind,
@@ -741,15 +742,17 @@
 	struct gsm_sms *sms = sms_alloc();
 	const char *text, *daddr, *saddr;
 	const unsigned char *user_data;
+	time_t validity_timestamp;
 
 	if (!sms)
 		return NULL;
 
 	sms->id = dbi_result_get_ulonglong(result, "id");
 
-	/* FIXME: validity */
-	/* FIXME: those should all be get_uchar, but sqlite3 is braindead */
 	sms->created = dbi_result_get_datetime(result, "created");
+	validity_timestamp = dbi_result_get_datetime(result, "valid_until");
+	sms->validity_minutes = (validity_timestamp - sms->created) / 60;
+	/* FIXME: those should all be get_uchar, but sqlite3 is braindead */
 	sms->reply_path_req = dbi_result_get_ulonglong(result, "reply_path_req");
 	sms->status_rep_req = dbi_result_get_ulonglong(result, "status_rep_req");
 	sms->is_report = dbi_result_get_ulonglong(result, "is_report");

-- 
To view, visit https://gerrit.osmocom.org/5875
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id27c250d3a64cd109416450e8ca155b18a8b9568
Gerrit-PatchSet: 2
Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-Owner: Stefan Sperling <ssperling at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list