Change in osmo-hlr[master]: db_hlr.c: db_subscr_create(): nam_cs, nam_ps args

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Sat Apr 20 09:35:15 UTC 2019


Vadim Yanitskiy has uploaded this change for review. ( https://gerrit.osmocom.org/13711


Change subject: db_hlr.c: db_subscr_create(): nam_cs, nam_ps args
......................................................................

db_hlr.c: db_subscr_create(): nam_cs, nam_ps args

Allow creating new subscribers without giving them access to CS or PS.
This will be used by the create-subscriber-on-demand feature.

Related: OS#2542
Change-Id: I1a6dd85387723dab5487c53b33d2d9ec6d05d006
---
M src/db.c
M src/db.h
M src/db_hlr.c
M src/hlr_db_tool.c
M src/hlr_vty_subscr.c
M tests/db/db_test.c
M tests/db/db_test.err
7 files changed, 96 insertions(+), 37 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/11/13711/1

diff --git a/src/db.c b/src/db.c
index 09e1776..770c3a4 100644
--- a/src/db.c
+++ b/src/db.c
@@ -66,7 +66,7 @@
 	[DB_STMT_UPD_PURGE_PS_BY_IMSI] = "UPDATE subscriber SET ms_purged_ps = $val WHERE imsi = $imsi",
 	[DB_STMT_UPD_NAM_CS_BY_IMSI] = "UPDATE subscriber SET nam_cs = $val WHERE imsi = $imsi",
 	[DB_STMT_UPD_NAM_PS_BY_IMSI] = "UPDATE subscriber SET nam_ps = $val WHERE imsi = $imsi",
-	[DB_STMT_SUBSCR_CREATE] = "INSERT INTO subscriber (imsi) VALUES ($imsi)",
+	[DB_STMT_SUBSCR_CREATE] = "INSERT INTO subscriber (imsi, nam_cs, nam_ps) VALUES ($imsi, $nam_cs, $nam_ps)",
 	[DB_STMT_DEL_BY_ID] = "DELETE FROM subscriber WHERE id = $subscriber_id",
 	[DB_STMT_SET_MSISDN_BY_IMSI] = "UPDATE subscriber SET msisdn = $msisdn WHERE imsi = $imsi",
 	[DB_STMT_DELETE_MSISDN_BY_IMSI] = "UPDATE subscriber SET msisdn = NULL WHERE imsi = $imsi",
diff --git a/src/db.h b/src/db.h
index c438b8d..7187bb3 100644
--- a/src/db.h
+++ b/src/db.h
@@ -118,7 +118,7 @@
 	} u;
 };
 
-int db_subscr_create(struct db_context *dbc, const char *imsi);
+int db_subscr_create(struct db_context *dbc, const char *imsi, int nam_cs, int nam_ps);
 int db_subscr_delete_by_id(struct db_context *dbc, int64_t subscr_id);
 
 int db_subscr_update_msisdn_by_imsi(struct db_context *dbc, const char *imsi,
diff --git a/src/db_hlr.c b/src/db_hlr.c
index 3ba457c..e879ae8 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -44,9 +44,11 @@
 /*! Add new subscriber record to the HLR database.
  * \param[in,out] dbc  database context.
  * \param[in] imsi  ASCII string of IMSI digits, is validated.
+ * \param[in] nam_cs  CS Network access mode (1: enable, 0: disable)
+ * \param[in] nam_ps  PS Network access mode (1: enable, 0: disable)
  * \returns 0 on success, -EINVAL on invalid IMSI, -EIO on database error.
  */
-int db_subscr_create(struct db_context *dbc, const char *imsi)
+int db_subscr_create(struct db_context *dbc, const char *imsi, int nam_cs, int nam_ps)
 {
 	sqlite3_stmt *stmt;
 	int rc;
@@ -61,6 +63,10 @@
 
 	if (!db_bind_text(stmt, "$imsi", imsi))
 		return -EIO;
+	if (!db_bind_int(stmt, "$nam_cs", nam_cs))
+		return -EIO;
+	if (!db_bind_int(stmt, "$nam_ps", nam_ps))
+		return -EIO;
 
 	/* execute the statement */
 	rc = sqlite3_step(stmt);
diff --git a/src/hlr_db_tool.c b/src/hlr_db_tool.c
index 516b91e..93fd49b 100644
--- a/src/hlr_db_tool.c
+++ b/src/hlr_db_tool.c
@@ -302,7 +302,7 @@
 
 	snprintf(imsi_str, sizeof(imsi_str), "%" PRId64, imsi);
 
-	rc = db_subscr_create(dbc, imsi_str);
+	rc = db_subscr_create(dbc, imsi_str, 1, 1);
 	if (rc < 0) {
 		LOGP(DDB, LOGL_ERROR, "OsmoNITB DB import to %s: failed to create IMSI %s: %d: %s\n",
 		     dbc->fname,
diff --git a/src/hlr_vty_subscr.c b/src/hlr_vty_subscr.c
index 998d1be..89dcaff 100644
--- a/src/hlr_vty_subscr.c
+++ b/src/hlr_vty_subscr.c
@@ -220,7 +220,7 @@
 		return CMD_WARNING;
 	}
 
-	rc = db_subscr_create(g_hlr->dbc, imsi);
+	rc = db_subscr_create(g_hlr->dbc, imsi, 1, 1);
 
 	if (rc) {
 		if (rc == -EEXIST)
diff --git a/tests/db/db_test.c b/tests/db/db_test.c
index 56905a9..0ec366b 100644
--- a/tests/db/db_test.c
+++ b/tests/db/db_test.c
@@ -221,37 +221,37 @@
 
 	comment("Create with valid / invalid IMSI");
 
-	ASSERT_RC(db_subscr_create(dbc, imsi0), 0);
+	ASSERT_RC(db_subscr_create(dbc, imsi0, 1, 1), 0);
 	ASSERT_SEL(imsi, imsi0, 0);
 	id0 = g_subscr.id;
-	ASSERT_RC(db_subscr_create(dbc, imsi1), 0);
+	ASSERT_RC(db_subscr_create(dbc, imsi1, 1, 1), 0);
 	ASSERT_SEL(imsi, imsi1, 0);
 	id1 = g_subscr.id;
-	ASSERT_RC(db_subscr_create(dbc, imsi2), 0);
+	ASSERT_RC(db_subscr_create(dbc, imsi2, 1, 1), 0);
 	ASSERT_SEL(imsi, imsi2, 0);
 	id2 = g_subscr.id;
-	ASSERT_RC(db_subscr_create(dbc, imsi0), -EIO);
+	ASSERT_RC(db_subscr_create(dbc, imsi0, 1, 1), -EIO);
 	ASSERT_SEL(imsi, imsi0, 0);
-	ASSERT_RC(db_subscr_create(dbc, imsi1), -EIO);
-	ASSERT_RC(db_subscr_create(dbc, imsi1), -EIO);
+	ASSERT_RC(db_subscr_create(dbc, imsi1, 1, 1), -EIO);
+	ASSERT_RC(db_subscr_create(dbc, imsi1, 1, 1), -EIO);
 	ASSERT_SEL(imsi, imsi1, 0);
-	ASSERT_RC(db_subscr_create(dbc, imsi2), -EIO);
-	ASSERT_RC(db_subscr_create(dbc, imsi2), -EIO);
+	ASSERT_RC(db_subscr_create(dbc, imsi2, 1, 1), -EIO);
+	ASSERT_RC(db_subscr_create(dbc, imsi2, 1, 1), -EIO);
 	ASSERT_SEL(imsi, imsi2, 0);
 
-	ASSERT_RC(db_subscr_create(dbc, "123456789 000003"), -EINVAL);
+	ASSERT_RC(db_subscr_create(dbc, "123456789 000003", 1, 1), -EINVAL);
 	ASSERT_SEL(imsi, "123456789000003", -ENOENT);
 
-	ASSERT_RC(db_subscr_create(dbc, "123456789000002123456"), -EINVAL);
+	ASSERT_RC(db_subscr_create(dbc, "123456789000002123456", 1, 1), -EINVAL);
 	ASSERT_SEL(imsi, "123456789000002123456", -ENOENT);
 
-	ASSERT_RC(db_subscr_create(dbc, "foobar123"), -EINVAL);
+	ASSERT_RC(db_subscr_create(dbc, "foobar123", 1, 1), -EINVAL);
 	ASSERT_SEL(imsi, "foobar123", -ENOENT);
 
-	ASSERT_RC(db_subscr_create(dbc, "123"), -EINVAL);
+	ASSERT_RC(db_subscr_create(dbc, "123", 1, 1), -EINVAL);
 	ASSERT_SEL(imsi, "123", -ENOENT);
 
-	ASSERT_RC(db_subscr_create(dbc, short_imsi), 0);
+	ASSERT_RC(db_subscr_create(dbc, short_imsi, 1, 1), 0);
 	ASSERT_SEL(imsi, short_imsi, 0);
 	id_short = g_subscr.id;
 
@@ -452,6 +452,22 @@
 	ASSERT_RC(db_subscr_delete_by_id(dbc, id_short), 0);
 	ASSERT_SEL(imsi, short_imsi, -ENOENT);
 
+	comment("Create and delete subscribers with non-default nam_cs and nam_ps");
+
+	ASSERT_RC(db_subscr_create(dbc, imsi0, 0, 0), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	id0 = g_subscr.id;
+	ASSERT_RC(db_subscr_create(dbc, imsi1, 0, 1), 0);
+	ASSERT_SEL(imsi, imsi1, 0);
+	id1 = g_subscr.id;
+	ASSERT_RC(db_subscr_create(dbc, imsi2, 1, 0), 0);
+	ASSERT_SEL(imsi, imsi2, 0);
+	id2 = g_subscr.id;
+
+	ASSERT_RC(db_subscr_delete_by_id(dbc, id0), 0);
+	ASSERT_RC(db_subscr_delete_by_id(dbc, id1), 0);
+	ASSERT_RC(db_subscr_delete_by_id(dbc, id2), 0);
+
 	comment_end();
 }
 
@@ -495,7 +511,7 @@
 
 	comment("Create subscriber");
 
-	ASSERT_RC(db_subscr_create(dbc, imsi0), 0);
+	ASSERT_RC(db_subscr_create(dbc, imsi0, 1, 1), 0);
 	ASSERT_SEL(imsi, imsi0, 0);
 
 	id = g_subscr.id;
@@ -707,7 +723,7 @@
 
 	comment("Re-add subscriber and verify auth data didn't come back");
 
-	ASSERT_RC(db_subscr_create(dbc, imsi0), 0);
+	ASSERT_RC(db_subscr_create(dbc, imsi0, 1, 1), 0);
 	ASSERT_SEL(imsi, imsi0, 0);
 
 	/* For this test to work, we want to get the same subscriber ID back,
@@ -739,7 +755,7 @@
 
 	comment("Create subscriber");
 
-	ASSERT_RC(db_subscr_create(dbc, imsi0), 0);
+	ASSERT_RC(db_subscr_create(dbc, imsi0, 1, 1), 0);
 	ASSERT_SEL(imsi, imsi0, 0);
 
 	id = g_subscr.id;
diff --git a/tests/db/db_test.err b/tests/db/db_test.err
index 6ebdae2..bfab345 100644
--- a/tests/db/db_test.err
+++ b/tests/db/db_test.err
@@ -3,7 +3,7 @@
 
 --- Create with valid / invalid IMSI
 
-db_subscr_create(dbc, imsi0) --> 0
+db_subscr_create(dbc, imsi0, 1, 1) --> 0
 
 db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
 struct hlr_subscriber {
@@ -11,7 +11,7 @@
   .imsi = '123456789000000',
 }
 
-db_subscr_create(dbc, imsi1) --> 0
+db_subscr_create(dbc, imsi1, 1, 1) --> 0
 
 db_subscr_get_by_imsi(dbc, imsi1, &g_subscr) --> 0
 struct hlr_subscriber {
@@ -19,7 +19,7 @@
   .imsi = '123456789000001',
 }
 
-db_subscr_create(dbc, imsi2) --> 0
+db_subscr_create(dbc, imsi2, 1, 1) --> 0
 
 db_subscr_get_by_imsi(dbc, imsi2, &g_subscr) --> 0
 struct hlr_subscriber {
@@ -27,7 +27,7 @@
   .imsi = '123456789000002',
 }
 
-db_subscr_create(dbc, imsi0) --> -EIO
+db_subscr_create(dbc, imsi0, 1, 1) --> -EIO
 DAUC IMSI='123456789000000': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
@@ -36,10 +36,10 @@
   .imsi = '123456789000000',
 }
 
-db_subscr_create(dbc, imsi1) --> -EIO
+db_subscr_create(dbc, imsi1, 1, 1) --> -EIO
 DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
-db_subscr_create(dbc, imsi1) --> -EIO
+db_subscr_create(dbc, imsi1, 1, 1) --> -EIO
 DAUC IMSI='123456789000001': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_get_by_imsi(dbc, imsi1, &g_subscr) --> 0
@@ -48,10 +48,10 @@
   .imsi = '123456789000001',
 }
 
-db_subscr_create(dbc, imsi2) --> -EIO
+db_subscr_create(dbc, imsi2, 1, 1) --> -EIO
 DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
-db_subscr_create(dbc, imsi2) --> -EIO
+db_subscr_create(dbc, imsi2, 1, 1) --> -EIO
 DAUC IMSI='123456789000002': Cannot create subscriber: SQL error: (2067) UNIQUE constraint failed: subscriber.imsi
 
 db_subscr_get_by_imsi(dbc, imsi2, &g_subscr) --> 0
@@ -60,31 +60,31 @@
   .imsi = '123456789000002',
 }
 
-db_subscr_create(dbc, "123456789 000003") --> -EINVAL
+db_subscr_create(dbc, "123456789 000003", 1, 1) --> -EINVAL
 DAUC Cannot create subscriber: invalid IMSI: '123456789 000003'
 
 db_subscr_get_by_imsi(dbc, "123456789000003", &g_subscr) --> -ENOENT
 DAUC Cannot read subscriber from db: IMSI='123456789000003': No such subscriber
 
-db_subscr_create(dbc, "123456789000002123456") --> -EINVAL
+db_subscr_create(dbc, "123456789000002123456", 1, 1) --> -EINVAL
 DAUC Cannot create subscriber: invalid IMSI: '123456789000002123456'
 
 db_subscr_get_by_imsi(dbc, "123456789000002123456", &g_subscr) --> -ENOENT
 DAUC Cannot read subscriber from db: IMSI='123456789000002123456': No such subscriber
 
-db_subscr_create(dbc, "foobar123") --> -EINVAL
+db_subscr_create(dbc, "foobar123", 1, 1) --> -EINVAL
 DAUC Cannot create subscriber: invalid IMSI: 'foobar123'
 
 db_subscr_get_by_imsi(dbc, "foobar123", &g_subscr) --> -ENOENT
 DAUC Cannot read subscriber from db: IMSI='foobar123': No such subscriber
 
-db_subscr_create(dbc, "123") --> -EINVAL
+db_subscr_create(dbc, "123", 1, 1) --> -EINVAL
 DAUC Cannot create subscriber: invalid IMSI: '123'
 
 db_subscr_get_by_imsi(dbc, "123", &g_subscr) --> -ENOENT
 DAUC Cannot read subscriber from db: IMSI='123': No such subscriber
 
-db_subscr_create(dbc, short_imsi) --> 0
+db_subscr_create(dbc, short_imsi, 1, 1) --> 0
 
 db_subscr_get_by_imsi(dbc, short_imsi, &g_subscr) --> 0
 struct hlr_subscriber {
@@ -752,6 +752,43 @@
 db_subscr_get_by_imsi(dbc, short_imsi, &g_subscr) --> -ENOENT
 DAUC Cannot read subscriber from db: IMSI='123456': No such subscriber
 
+
+--- Create and delete subscribers with non-default nam_cs and nam_ps
+
+db_subscr_create(dbc, imsi0, 0, 0) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
+struct hlr_subscriber {
+  .id = 1,
+  .imsi = '123456789000000',
+  .nam_cs = false,
+  .nam_ps = false,
+}
+
+db_subscr_create(dbc, imsi1, 0, 1) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi1, &g_subscr) --> 0
+struct hlr_subscriber {
+  .id = 2,
+  .imsi = '123456789000001',
+  .nam_cs = false,
+}
+
+db_subscr_create(dbc, imsi2, 1, 0) --> 0
+
+db_subscr_get_by_imsi(dbc, imsi2, &g_subscr) --> 0
+struct hlr_subscriber {
+  .id = 3,
+  .imsi = '123456789000002',
+  .nam_ps = false,
+}
+
+db_subscr_delete_by_id(dbc, id0) --> 0
+
+db_subscr_delete_by_id(dbc, id1) --> 0
+
+db_subscr_delete_by_id(dbc, id2) --> 0
+
 ===== test_subscr_create_update_sel_delete: SUCCESS
 
 
@@ -769,7 +806,7 @@
 
 --- Create subscriber
 
-db_subscr_create(dbc, imsi0) --> 0
+db_subscr_create(dbc, imsi0, 1, 1) --> 0
 
 db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
 struct hlr_subscriber {
@@ -1259,7 +1296,7 @@
 
 --- Re-add subscriber and verify auth data didn't come back
 
-db_subscr_create(dbc, imsi0) --> 0
+db_subscr_create(dbc, imsi0, 1, 1) --> 0
 
 db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
 struct hlr_subscriber {
@@ -1306,7 +1343,7 @@
 
 --- Create subscriber
 
-db_subscr_create(dbc, imsi0) --> 0
+db_subscr_create(dbc, imsi0, 1, 1) --> 0
 
 db_subscr_get_by_imsi(dbc, imsi0, &g_subscr) --> 0
 struct hlr_subscriber {

-- 
To view, visit https://gerrit.osmocom.org/13711
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a6dd85387723dab5487c53b33d2d9ec6d05d006
Gerrit-Change-Number: 13711
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190420/a9de6c7d/attachment.html>


More information about the gerrit-log mailing list