aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/db.c
diff options
context:
space:
mode:
authorHarald Welte (local) <laflocal@hanuman.gnumonks.org>2009-08-15 20:15:14 +0200
committerHarald Welte (local) <laflocal@hanuman.gnumonks.org>2009-08-15 20:15:14 +0200
commitdb552c56bb276a0105b1b1377d2eee2e4ed39b88 (patch)
treeffb4067fd2a7a357a7df26d3f829d5104398cde0 /openbsc/src/db.c
parent0abaf33297d79af507c82a2dcafaa83bcb9b54ae (diff)
don't try to deliver sms to a subscriber that's not registered
Diffstat (limited to 'openbsc/src/db.c')
-rw-r--r--openbsc/src/db.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 0704bca2b..d5e924db7 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -88,6 +88,7 @@ static char *create_stmts[] = {
"sent TIMESTAMP, "
"sender_id INTEGER NOT NULL, "
"receiver_id INTEGER NOT NULL, "
+ "deliver_attempts INTEGER NOT NULL DEFAULT 0, "
/* data directly copied/derived from SMS */
"valid_until TIMESTAMP, "
"reply_path_req INTEGER NOT NULL, "
@@ -688,8 +689,10 @@ struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, int min_id)
struct gsm_sms *sms;
result = dbi_conn_queryf(conn,
- "SELECT * FROM SMS "
- "WHERE id >= %llu AND sent is NULL ORDER BY id",
+ "SELECT * FROM SMS,Subscriber "
+ "WHERE sms.id >= %llu AND sms.sent is NULL "
+ "AND subscriber.lac > 0 "
+ "ORDER BY id",
min_id);
if (!result)
return NULL;
@@ -713,8 +716,10 @@ struct gsm_sms *db_sms_get_unsent_for_subscr(struct gsm_subscriber *subscr)
struct gsm_sms *sms;
result = dbi_conn_queryf(conn,
- "SELECT * FROM SMS "
- "WHERE receiver_id = %llu AND sent is NULL ORDER BY id",
+ "SELECT * FROM SMS,Subscriber "
+ "WHERE sms.receiver_id = %llu AND sms.sent is NULL "
+ "AND subscriber.lac > 0 "
+ "ORDER BY id",
subscr->id);
if (!result)
return NULL;
@@ -748,3 +753,21 @@ int db_sms_mark_sent(struct gsm_sms *sms)
dbi_result_free(result);
return 0;
}
+
+/* increase the number of attempted deliveries */
+int db_sms_inc_deliver_attempts(struct gsm_sms *sms)
+{
+ dbi_result result;
+
+ result = dbi_conn_queryf(conn,
+ "UPDATE SMS "
+ "SET deliver_attempts = deliver_attempts + 1 "
+ "WHERE id = %llu", sms->id);
+ if (!result) {
+ printf("DB: Failed to inc deliver attempts for SMS %llu.\n", sms->id);
+ return 1;
+ }
+
+ dbi_result_free(result);
+ return 0;
+}