Add a VTY command which deletes all expired SMS.

We already delete SMS which have been sent successfully. However, there
are plans to accept SMS for any subscriber in order to fix the problem
described in https://osmocom.org/issues/2354 ("SMSC: Store&Forward not
working for subscribed but unregistered MS").

This means we may end up storing SMS which never get sent, e.g. because
the B subscriber doesn't actually exist. This could lead to a higher
degree of SMS database growth over time, and therefore we need a way
to keep database size under control.

As a first step, introduce a DB function which removes an expired SMS,
and add a VTY command which removes all expired SMS from the DB.

Later commits will build upon this to remove expired SMS automatically.

The SMS expiry time period is currently hard-coded to 2 weeks.
We could make this configurable in the future if desired.

Change-Id: Icd6093b7b5d8db84b19a0aa47c68182566113ee2
Related: OS#2354
diff --git a/src/libmsc/sms_queue.c b/src/libmsc/sms_queue.c
index 3d39a0e..193d023 100644
--- a/src/libmsc/sms_queue.c
+++ b/src/libmsc/sms_queue.c
@@ -72,21 +72,21 @@
 static int sms_sms_cb(unsigned int, unsigned int, void *, void *);
 
 static struct gsm_sms_pending *sms_find_pending(struct gsm_sms_queue *smsq,
-						struct gsm_sms *sms)
+						unsigned long long sms_id)
 {
 	struct gsm_sms_pending *pending;
 
 	llist_for_each_entry(pending, &smsq->pending_sms, entry) {
-		if (pending->sms_id == sms->id)
+		if (pending->sms_id == sms_id)
 			return pending;
 	}
 
 	return NULL;
 }
 
-static int sms_is_in_pending(struct gsm_sms_queue *smsq, struct gsm_sms *sms)
+int sms_queue_sms_is_pending(struct gsm_sms_queue *smsq, unsigned long long sms_id)
 {
-	return sms_find_pending(smsq, sms) != NULL;
+	return sms_find_pending(smsq, sms_id) != NULL;
 }
 
 static struct gsm_sms_pending *sms_subscriber_find_pending(
@@ -286,7 +286,7 @@
 		}
 
 		/* no need to send a pending sms */
-		if (sms_is_in_pending(smsq, sms)) {
+		if (sms_queue_sms_is_pending(smsq, sms->id)) {
 			LOGP(DLSMS, LOGL_DEBUG,
 			     "SMSqueue with pending sms: %llu. Skipping\n", sms->id);
 			sms_free(sms);
@@ -337,7 +337,7 @@
 		goto no_pending_sms;
 
 	/* The sms should not be scheduled right now */
-	OSMO_ASSERT(!sms_is_in_pending(smsq, sms));
+	OSMO_ASSERT(!sms_queue_sms_is_pending(smsq, sms->id));
 
 	/* Remember that we deliver this SMS and send it */
 	pending = sms_pending_from(smsq, sms);
@@ -472,7 +472,7 @@
 	 * sms that are not in our control as we just have a channel
 	 * open anyway.
 	 */
-	pending = sms_find_pending(network->sms_queue, sig_sms->sms);
+	pending = sms_find_pending(network->sms_queue, sig_sms->sms->id);
 	if (!pending)
 		return 0;