db_hlr.c: db_subscr_create(): add flags argument
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
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..3cb42e4 100644
--- a/src/db.h
+++ b/src/db.h
@@ -118,7 +118,10 @@
} u;
};
-int db_subscr_create(struct db_context *dbc, const char *imsi);
+#define DB_SUBSCR_FLAG_NAM_CS (1 << 1)
+#define DB_SUBSCR_FLAG_NAM_PS (1 << 2)
+
+int db_subscr_create(struct db_context *dbc, const char *imsi, uint8_t flags);
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..40209c5 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -44,9 +44,10 @@
/*! 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] flags Bitmask of DB_SUBSCR_FLAG_*.
* \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, uint8_t flags)
{
sqlite3_stmt *stmt;
int rc;
@@ -61,6 +62,10 @@
if (!db_bind_text(stmt, "$imsi", imsi))
return -EIO;
+ if (!db_bind_int(stmt, "$nam_cs", (flags & DB_SUBSCR_FLAG_NAM_CS) != 0))
+ return -EIO;
+ if (!db_bind_int(stmt, "$nam_ps", (flags & DB_SUBSCR_FLAG_NAM_PS) != 0))
+ 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..fcef597 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, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS);
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..3078577 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, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS);
if (rc) {
if (rc == -EEXIST)