diff options
author | Keith <keith@rhizomatica.org> | 2022-06-10 16:35:18 -0500 |
---|---|---|
committer | Keith Whyte <keith@rhizomatica.org> | 2022-10-23 00:17:54 +0100 |
commit | 6ea0065e46ec07a2990a41d35bf8292beb1803ca (patch) | |
tree | a3321030e2331e4fd3c162b6c5178fac61e50e72 | |
parent | 24e5dc698c30f3c6932081f014d18dceb71b7685 (diff) |
Move VLR check to db.c
Change-Id: Ibd07b9d200b48108d705ed4c461cc4ddfa421fd2
-rw-r--r-- | src/libmsc/db.c | 17 | ||||
-rw-r--r-- | src/libmsc/sms_queue.c | 17 |
2 files changed, 25 insertions, 9 deletions
diff --git a/src/libmsc/db.c b/src/libmsc/db.c index d12f04c13..cc61c9152 100644 --- a/src/libmsc/db.c +++ b/src/libmsc/db.c @@ -867,6 +867,8 @@ struct gsm_sms *db_sms_get_next_unsent_rr_msisdn(struct gsm_network *net, OSMO_ASSERT(g_dbc); sqlite3_stmt *stmt = g_dbc->stmt[DB_STMT_SMS_GET_NEXT_UNSENT_RR_MSISDN]; struct gsm_sms *sms; + struct vlr_subscr *receiver; + const char *daddr; int rc; db_bind_text(stmt, "$dest_addr", last_msisdn); @@ -878,6 +880,21 @@ struct gsm_sms *db_sms_get_next_unsent_rr_msisdn(struct gsm_network *net, return NULL; } + daddr = (const char *)sqlite3_column_text(stmt, COL_DEST_ADDR); + receiver = vlr_subscr_find_by_msisdn(net->vlr, daddr, VSUB_USE_SMS_RECEIVER); + if (!receiver || !receiver->lu_complete) { + sms = sms_alloc(); + sms->receiver = receiver; + if (daddr) + OSMO_STRLCPY_ARRAY(sms->dst.addr, daddr); + LOGP(DLSMS, LOGL_DEBUG, + "Subscriber %s%s is not attached, skipping SMS.\n", + sms->receiver ? "" : "MSISDN-", + sms->receiver ? vlr_subscr_msisdn_or_name(sms->receiver) : daddr); + db_remove_reset(stmt); + return sms; + } + sms = sms_from_result(net, stmt); db_remove_reset(stmt); diff --git a/src/libmsc/sms_queue.c b/src/libmsc/sms_queue.c index 9f18f4feb..363e86ab3 100644 --- a/src/libmsc/sms_queue.c +++ b/src/libmsc/sms_queue.c @@ -301,11 +301,15 @@ struct gsm_sms *smsq_take_next_sms(struct gsm_network *net, while (wrapped < 2 && (--sanity)) { /* If we wrapped around and passed the first msisdn, we're * through the entire SMS DB; end it. */ - if (wrapped && strcmp(last_msisdn, started_with_msisdn) >= 0) + if (wrapped && strcmp(last_msisdn, started_with_msisdn) >= 0) { + DEBUGP(DLSMS, "SMS queue: Reached end of DB.\n"); break; - + } + /* Here we do the query + all the sqlite3_column_xxx() parsing, creating the + * SMS in memory, only to free it if the subscriber is not atttached */ sms = db_sms_get_next_unsent_rr_msisdn(net, last_msisdn, 9); if (!sms) { + DEBUGP(DLSMS, "SMS queue: Got no SMS\n"); last_msisdn[0] = '\0'; wrapped++; continue; @@ -316,12 +320,7 @@ struct gsm_sms *smsq_take_next_sms(struct gsm_network *net, osmo_strlcpy(last_msisdn, sms->dst.addr, last_msisdn_buflen); /* Is the subscriber attached? If not, go to next SMS */ - if (!sms->receiver || !sms->receiver->lu_complete) { - LOGP(DLSMS, LOGL_DEBUG, - "Subscriber %s%s is not attached, skipping SMS %llu\n", - sms->receiver ? "" : "MSISDN-", - sms->receiver ? vlr_subscr_msisdn_or_name(sms->receiver) - : sms->dst.addr, sms->id); + if (!sms->id) { sms_free(sms); continue; } @@ -329,7 +328,7 @@ struct gsm_sms *smsq_take_next_sms(struct gsm_network *net, return sms; } - DEBUGP(DLSMS, "SMS queue: no SMS to be sent\n"); + DEBUGP(DLSMS, "SMS queue: no SMS to be sent, tried %d times.\n", sanity+100); return NULL; } |