introduce lookup of subscribers based on their extension number
diff --git a/src/db.c b/src/db.c
index 50459cf..b538d5d 100644
--- a/src/db.c
+++ b/src/db.c
@@ -119,6 +119,7 @@
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"created TIMESTAMP NOT NULL, "
"updated TIMESTAMP NOT NULL, "
+ "name TEXT, "
"imei NUMERIC UNIQUE NOT NULL"
")"
);
@@ -219,6 +220,15 @@
);
free(quoted);
break;
+ case GSM_SUBSCRIBER_EXTENSION:
+ dbi_conn_quote_string_copy(conn, id, "ed);
+ result = dbi_conn_queryf(conn,
+ "SELECT * FROM Subscriber "
+ "WHERE extension = %s ",
+ quoted
+ );
+ free(quoted);
+ break;
default:
printf("DB: Unknown query selector for Subscriber.\n");
return NULL;
diff --git a/src/gsm_subscriber.c b/src/gsm_subscriber.c
index 390979b..d4dfea4 100644
--- a/src/gsm_subscriber.c
+++ b/src/gsm_subscriber.c
@@ -78,6 +78,18 @@
return db_get_subscriber(GSM_SUBSCRIBER_IMSI, imsi);
}
+struct gsm_subscriber *subscr_get_by_extension(const char *ext)
+{
+ struct gsm_subscriber *subscr;
+
+ llist_for_each_entry(subscr, &active_subscribers, entry) {
+ if (strcmp(subscr->extension, ext) == 0)
+ return subscr_get(subscr);
+ }
+
+ return db_get_subscriber(GSM_SUBSCRIBER_EXTENSION, ext);
+}
+
int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts)
{
return db_sync_subscriber(s);