aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/db.c
diff options
context:
space:
mode:
authorJan Luebbe <jluebbe@debian.org>2009-08-12 19:45:37 +0200
committerHarald Welte <laforge@gnumonks.org>2009-08-12 22:22:20 +0200
commitebcce2aae13952283fa5519fa7f31958c7c696d6 (patch)
treeedb11ce029cc7fc8f059d0a5d840ad0378b025e7 /openbsc/src/db.c
parent31bef49be2dffdeb28d0b4d0ee5f6df3c06ff960 (diff)
allocate an extension when creating the subscriber
Diffstat (limited to 'openbsc/src/db.c')
-rw-r--r--openbsc/src/db.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 601726096..f610bfc4e 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -248,6 +248,7 @@ struct gsm_subscriber* db_create_subscriber(struct gsm_network *net, char *imsi)
strncpy(subscr->imsi, imsi, GSM_IMSI_LENGTH-1);
dbi_result_free(result);
printf("DB: New Subscriber: ID %llu, IMSI %s\n", subscr->id, subscr->imsi);
+ db_subscriber_alloc_exten(subscr);
return subscr;
}
@@ -419,6 +420,34 @@ int db_subscriber_alloc_tmsi(struct gsm_subscriber* subscriber) {
return 0;
}
+int db_subscriber_alloc_exten(struct gsm_subscriber* subscriber) {
+ dbi_result result=NULL;
+ u_int32_t try;
+ for (;;) {
+ try = (rand()%(GSM_MAX_EXTEN+1)+GSM_MIN_EXTEN)%(GSM_MAX_EXTEN+1);
+ result = dbi_conn_queryf(conn,
+ "SELECT * FROM Subscriber "
+ "WHERE extension = %llu",
+ try
+ );
+ if (result==NULL) {
+ printf("DB: Failed to query Subscriber while allocating new extension.\n");
+ return 1;
+ }
+ if (dbi_result_get_numrows(result)){
+ dbi_result_free(result);
+ continue;
+ }
+ if (!dbi_result_next_row(result)) {
+ dbi_result_free(result);
+ break;
+ }
+ dbi_result_free(result);
+ }
+ sprintf(subscriber->extension, "%i", try);
+ printf("DB: Allocated extension %i for IMSI %s.\n", try, subscriber->imsi);
+ return db_sync_subscriber(subscriber);
+}
/*
* try to allocate a new unique token for this subscriber and return it
* via a parameter. if the subscriber already has a token, return