Delete SMS from the database once they were sent successfully

Currently the SMS database keeps accumulating entries for each SMS.
These entries are never deleted automatically. With this change, we
start deleting SMS which have successfully been sent to subscriber B.

Change-Id: I3749855fe25d9d4e37ec96b0c2bffbc692b66a78
diff --git a/src/libmsc/db.c b/src/libmsc/db.c
index 7007c7a..e80ef53 100644
--- a/src/libmsc/db.c
+++ b/src/libmsc/db.c
@@ -970,6 +970,22 @@
 	return 0;
 }
 
+int db_sms_delete_sent_message_by_id(unsigned long long sms_id)
+{
+	dbi_result result;
+
+	result = dbi_conn_queryf(conn,
+			"DELETE FROM SMS WHERE id = %llu AND sent is NOT NULL",
+			 sms_id);
+	if (!result) {
+		LOGP(DDB, LOGL_ERROR, "Failed to delete SMS %llu.\n", sms_id);
+		return 1;
+	}
+
+	dbi_result_free(result);
+	return 0;
+}
+
 int db_store_counter(struct osmo_counter *ctr)
 {
 	dbi_result result;