diff mbox

[3/5] Simplify subscriber creation

Message ID 1462293833-29141-3-git-send-email-msuraev@sysmocom.de
State New
Headers show

Commit Message

Max May 3, 2016, 4:43 p.m. UTC
From: Max <msuraev@sysmocom.de>

Move common code to wrapper function.
---
 openbsc/src/libmsc/gsm_04_08.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/openbsc/src/libmsc/gsm_04_08.c b/openbsc/src/libmsc/gsm_04_08.c
index 05cb886..bb1b49a 100644
--- a/openbsc/src/libmsc/gsm_04_08.c
+++ b/openbsc/src/libmsc/gsm_04_08.c
@@ -507,6 +507,14 @@  static int mm_tx_identity_req(struct gsm_subscriber_connection *conn, uint8_t id
 	return gsm48_conn_sendmsg(msg, conn, NULL);
 }
 
+static struct gsm_subscriber *subscr_create(const struct gsm_network *net,
+					    const char *imsi)
+{
+	if (GSM_SUBSCR_DONT_CREATE == net->create_subscriber)
+		return NULL;
+
+	return subscr_create_subscriber(net->subscr_group, imsi);
+}
 
 /* Parse Chapter 9.2.11 Identity Response */
 static int mm_rx_id_resp(struct gsm_subscriber_connection *conn, struct msgb *msg)
@@ -530,9 +538,8 @@  static int mm_rx_id_resp(struct gsm_subscriber_connection *conn, struct msgb *ms
 		if (!conn->subscr) {
 			conn->subscr = subscr_get_by_imsi(net->subscr_group,
 							  mi_string);
-			if (!conn->subscr && net->create_subscriber)
-				conn->subscr = subscr_create_subscriber(
-					net->subscr_group, mi_string);
+			if (!conn->subscr)
+				conn->subscr = subscr_create(net, mi_string);
 		}
 		if (!conn->subscr && conn->loc_operation) {
 			gsm0408_loc_upd_rej(conn, bts->network->reject_cause);
@@ -641,9 +648,8 @@  static int mm_rx_loc_upd_req(struct gsm_subscriber_connection *conn, struct msgb
 
 		/* look up subscriber based on IMSI, create if not found */
 		subscr = subscr_get_by_imsi(bts->network->subscr_group, mi_string);
-		if (!subscr && bts->network->create_subscriber) {
-			subscr = subscr_create_subscriber(
-				bts->network->subscr_group, mi_string);
+		if (!subscr) {
+			subscr = subscr_create(bts->network, mi_string);
 		}
 		if (!subscr) {
 			gsm0408_loc_upd_rej(conn, bts->network->reject_cause);