db: Rename AuthTuples to AuthLastTuples

Ultimately, we'll need to store both the last used tuple by a
subscriber and a list of known tuples (for unknown Ki). What's
currently implemented for AuthTuples is the former behavior, so
reflect that.

The second use case will be added as a separate table with separate
accessors later on.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
diff --git a/openbsc/include/openbsc/db.h b/openbsc/include/openbsc/db.h
index 1782efb..c4fc28a 100644
--- a/openbsc/include/openbsc/db.h
+++ b/openbsc/include/openbsc/db.h
@@ -48,10 +48,10 @@
                            struct gsm_subscriber *subscr);
 int set_authinfo_for_subscr(struct gsm_auth_info *ainfo,
                             struct gsm_subscriber *subscr);
-int get_authtuple_by_subscr(struct gsm_auth_tuple *atuple,
-                            struct gsm_subscriber *subscr);
-int set_authtuple_for_subscr(struct gsm_auth_tuple *atuple,
-                             struct gsm_subscriber *subscr);
+int get_lastauthtuple_by_subscr(struct gsm_auth_tuple *atuple,
+                                struct gsm_subscriber *subscr);
+int set_lastauthtuple_for_subscr(struct gsm_auth_tuple *atuple,
+                                 struct gsm_subscriber *subscr);
 
 /* SMS store-and-forward */
 int db_sms_store(struct gsm_sms *sms);
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 7f3c221..ad46d98 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -140,7 +140,7 @@
 		"algorithm_id INTEGER NOT NULL, "
 		"a3a8_ki BLOB "
 		")",
-	"CREATE TABLE IF NOT EXISTS AuthTuples ("
+	"CREATE TABLE IF NOT EXISTS AuthLastTuples ("
 		"id INTEGER PRIMARY KEY AUTOINCREMENT, "
 		"subscriber_id NUMERIC UNIQUE NOT NULL, "
 		"issued TIMESTAMP NOT NULL, "
@@ -435,15 +435,15 @@
 	return 0;
 }
 
-int get_authtuple_by_subscr(struct gsm_auth_tuple *atuple,
-			    struct gsm_subscriber *subscr)
+int get_lastauthtuple_by_subscr(struct gsm_auth_tuple *atuple,
+                                struct gsm_subscriber *subscr)
 {
 	dbi_result result;
 	int len;
 	const unsigned char *blob;
 
 	result = dbi_conn_queryf(conn,
-			"SELECT * FROM AuthTuples WHERE subscriber_id=%u",
+			"SELECT * FROM AuthLastTuples WHERE subscriber_id=%u",
 			subscr->id);
 	if (!result)
 		return -EIO;
@@ -488,8 +488,8 @@
 	return -EIO;
 }
 
-int set_authtuple_for_subscr(struct gsm_auth_tuple *atuple,
-			     struct gsm_subscriber *subscr)
+int set_lastauthtuple_for_subscr(struct gsm_auth_tuple *atuple,
+                                 struct gsm_subscriber *subscr)
 {
 	dbi_result result;
 	int rc, upd;
@@ -499,7 +499,7 @@
 	/* Deletion ? */
 	if (atuple == NULL) {
 		result = dbi_conn_queryf(conn,
-			"DELETE FROM AuthTuples WHERE subscriber_id=%u",
+			"DELETE FROM AuthLastTuples WHERE subscriber_id=%u",
 			subscr->id);
 
 		if (!result)
@@ -511,7 +511,7 @@
 	}
 
 	/* Check if already existing */
-	rc = get_authtuple_by_subscr(&atuple_old, subscr);
+	rc = get_lastauthtuple_by_subscr(&atuple_old, subscr);
 	if (rc && rc != -ENOENT)
 		return rc;
 	upd = rc ? 0 : 1;
@@ -526,7 +526,7 @@
 
 	if (!upd) {
 		result = dbi_conn_queryf(conn,
-				"INSERT INTO AuthTuples "
+				"INSERT INTO AuthLastTuples "
 				"(subscriber_id, issued, use_count, "
 				 "key_seq, rand, sres, kc) "
 				"VALUES (%u, datetime('now'), %u, "
diff --git a/openbsc/src/vty_interface_layer3.c b/openbsc/src/vty_interface_layer3.c
index 807e165..0b6da04 100644
--- a/openbsc/src/vty_interface_layer3.c
+++ b/openbsc/src/vty_interface_layer3.c
@@ -100,7 +100,7 @@
 			VTY_NEWLINE);
 	}
 
-	rc = get_authtuple_by_subscr(&atuple, subscr);
+	rc = get_lastauthtuple_by_subscr(&atuple, subscr);
 	if (!rc) {
 		vty_out(vty, "    A3A8 last tuple (used %d times):%s",
 			atuple.use_count, VTY_NEWLINE);