summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Chemeris <alexander.chemeris@gmail.com>2013-10-08 03:17:32 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-04-30 15:31:57 +0200
commitca7ed2d2df55e8c1811d9dab13a2ada68ea1e9a3 (patch)
tree36796e219b6454bd3403ab38edd8152c56bd4fc9
parent73bc51deeab1eb38049614d67cd57f89275d7ad3 (diff)
sms: Do not store received id in the SMS database.
That was a bad idea from the very beginning. A visible result of this is a wrong SMS routing when you change subscriber extensions, while having queued SMS. It's also a very wrong thing from the code layering perspective. I think the next logical step should be to remove "receiver" pointer from the gsm_sms structure into a structure, special for the internal SMS queue.
-rw-r--r--openbsc/src/libmsc/db.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c
index df26b04d4..88bd9adc3 100644
--- a/openbsc/src/libmsc/db.c
+++ b/openbsc/src/libmsc/db.c
@@ -95,7 +95,6 @@ static char *create_stmts[] = {
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"created TIMESTAMP NOT NULL, "
"sent TIMESTAMP, "
- "receiver_id INTEGER NOT NULL, "
"deliver_attempts INTEGER NOT NULL DEFAULT 0, "
/* data directly copied/derived from SMS */
"valid_until TIMESTAMP, "
@@ -1233,19 +1232,19 @@ int db_sms_store(struct gsm_sms *sms)
/* FIXME: correct validity period */
result = dbi_conn_queryf(conn,
"INSERT INTO SMS "
- "(created, receiver_id, valid_until, "
+ "(created, valid_until, "
"reply_path_req, status_rep_req, protocol_id, "
"data_coding_scheme, ud_hdr_ind, "
"user_data, text, "
"dest_addr, dest_ton, dest_npi, "
"src_addr, src_ton, src_npi) VALUES "
- "(datetime('now'), %llu, %u, "
+ "(datetime('now'), %u, "
"%u, %u, %u, "
"%u, %u, "
"%s, %s, "
"%s, %u, %u, "
"%s, %u, %u)",
- sms->receiver ? sms->receiver->id : 0, validity_timestamp,
+ validity_timestamp,
sms->reply_path_req, sms->status_rep_req, sms->protocol_id,
sms->data_coding_scheme, sms->ud_hdr_ind,
q_udata, q_text,
@@ -1266,7 +1265,6 @@ int db_sms_store(struct gsm_sms *sms)
static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result result)
{
struct gsm_sms *sms = sms_alloc();
- long long unsigned int receiver_id;
const char *text, *daddr, *saddr;
const unsigned char *user_data;
@@ -1275,16 +1273,6 @@ static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result resul
sms->id = dbi_result_get_ulonglong(result, "id");
- receiver_id = dbi_result_get_ulonglong(result, "receiver_id");
- sms->receiver = subscr_get_by_id(net, receiver_id);
- if (!sms->receiver) {
- LOGP(DLSMS, LOGL_ERROR,
- "Failed to find receiver(%llu) for id(%llu)\n",
- receiver_id, sms->id);
- sms_free(sms);
- return NULL;
- }
-
/* FIXME: validity */
/* FIXME: those should all be get_uchar, but sqlite3 is braindead */
sms->reply_path_req = dbi_result_get_uint(result, "reply_path_req");
@@ -1302,6 +1290,7 @@ static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result resul
strncpy(sms->dst.addr, daddr, sizeof(sms->dst.addr));
sms->dst.addr[sizeof(sms->dst.addr)-1] = '\0';
}
+ sms->receiver = subscr_get_by_extension(net, sms->dst.addr);
sms->src.npi = dbi_result_get_uint(result, "src_npi");
sms->src.ton = dbi_result_get_uint(result, "src_ton");
@@ -1356,7 +1345,7 @@ struct gsm_sms *db_sms_get_unsent(struct gsm_network *net, unsigned long long mi
result = dbi_conn_queryf(conn,
"SELECT SMS.* "
"FROM SMS JOIN Subscriber ON "
- "SMS.receiver_id = Subscriber.id "
+ "SMS.dest_addr = Subscriber.extension "
"WHERE SMS.id >= %llu AND SMS.sent IS NULL "
"AND Subscriber.lac > 0 "
"ORDER BY SMS.id LIMIT 1",
@@ -1386,10 +1375,10 @@ struct gsm_sms *db_sms_get_unsent_by_subscr(struct gsm_network *net,
result = dbi_conn_queryf(conn,
"SELECT SMS.* "
"FROM SMS JOIN Subscriber ON "
- "SMS.receiver_id = Subscriber.id "
- "WHERE SMS.receiver_id >= %llu AND SMS.sent IS NULL "
+ "SMS.dest_addr = Subscriber.extension "
+ "WHERE Subscriber.id >= %llu AND SMS.sent IS NULL "
"AND Subscriber.lac > 0 AND SMS.deliver_attempts < %u "
- "ORDER BY SMS.receiver_id, SMS.id LIMIT 1",
+ "ORDER BY Subscriber.id, SMS.id LIMIT 1",
min_subscr_id, failed);
if (!result)
return NULL;
@@ -1415,8 +1404,8 @@ struct gsm_sms *db_sms_get_unsent_for_subscr(struct gsm_subscriber *subscr)
result = dbi_conn_queryf(conn,
"SELECT SMS.* "
"FROM SMS JOIN Subscriber ON "
- "SMS.receiver_id = Subscriber.id "
- "WHERE SMS.receiver_id = %llu AND SMS.sent IS NULL "
+ "SMS.dest_addr = Subscriber.extension "
+ "WHERE Subscriber.id = %llu AND SMS.sent IS NULL "
"AND Subscriber.lac > 0 "
"ORDER BY SMS.id LIMIT 1",
subscr->id);