[PATCH 3/3] Implement a better sending of pending SMS

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/OpenBSC@lists.osmocom.org/.

Sylvain Munaut 246tnt at gmail.com
Sun Dec 20 17:16:46 UTC 2009


From: Sylvain Munaut <tnt at 246tNt.com>

The previous implementation had some shortcomings:
 - If the MIN ID given was not the exact id of the first unsent SMS,
 it would try to submit the same sms several time until id++ finally
 made id go to the next one.
 - If a subscriber had several SMS pending it would try to submit
 them individually (only to get rejected because a paging for that
 subscriber was already in progress)

Signed-off-by: Sylvain Munaut <tnt at 246tNt.com>
---
 openbsc/src/db.c                   |   27 +++++++++++++++++++++++++++
 openbsc/src/vty_interface_layer3.c |   17 +++++++----------
 2 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index ebfe923..b796350 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -788,6 +788,33 @@ struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, int min_id)
 	return sms;
 }
 
+struct gsm_sms *db_sms_get_unsent_by_subscr(struct gsm_network *net, int min_subscr_id)
+{
+	dbi_result result;
+	struct gsm_sms *sms;
+
+	result = dbi_conn_queryf(conn,
+		"SELECT * FROM SMS,Subscriber "
+		"WHERE sms.receiver_id >= %llu AND sms.sent is NULL "
+			"AND sms.receiver_id = subscriber.id " 
+			"AND subscriber.lac > 0 "
+		"ORDER BY sms.receiver_id, id LIMIT 1",
+		min_subscr_id);
+	if (!result)
+		return NULL;
+
+	if (!dbi_result_next_row(result)) {
+		dbi_result_free(result);
+		return NULL;
+	}
+
+	sms = sms_from_result(net, result);
+
+	dbi_result_free(result);
+
+	return sms;
+}
+
 /* retrieve the next unsent SMS for a given subscriber */
 struct gsm_sms *db_sms_get_unsent_for_subscr(struct gsm_subscriber *subscr)
 {
diff --git a/openbsc/src/vty_interface_layer3.c b/openbsc/src/vty_interface_layer3.c
index 4cc08c2..70e8445 100644
--- a/openbsc/src/vty_interface_layer3.c
+++ b/openbsc/src/vty_interface_layer3.c
@@ -143,23 +143,20 @@ DEFUN(show_subscr_cache,
 
 DEFUN(sms_send_pend,
       sms_send_pend_cmd,
-      "sms send pending MIN_ID",
-      "Send all pending SMS starting from MIN_ID")
+      "sms send pending",
+      "Send all pending SMS")
 {
 	struct gsm_sms *sms;
-	int id = atoi(argv[0]);
+	int id = 0;
 
 	while (1) {
-		sms = db_sms_get_unsent(gsmnet, id++);
+		sms = db_sms_get_unsent_by_subscr(gsmnet, id);
 		if (!sms)
-			return CMD_WARNING;
-
-		if (!sms->receiver) {
-			sms_free(sms);
-			continue;
-		}
+			break;
 
 		gsm411_send_sms_subscr(sms->receiver, sms);
+
+		id = sms->receiver->id + 1;
 	}
 
 	return CMD_SUCCESS;
-- 
1.6.5.1





More information about the OpenBSC mailing list