Add routines to update nam_ps
Add SQL queries to change nam_ps value and function which uses them.
Change-Id: I24fb79e084b2dfa6a81b52f448b94a86e47014ef
diff --git a/src/db.c b/src/db.c
index d20b8b6..aa4726c 100644
--- a/src/db.c
+++ b/src/db.c
@@ -33,6 +33,8 @@
[AUC_UPD_SQN] = "UPDATE auc_3g SET sqn = ? WHERE subscriber_id = ?",
[UPD_PURGE_CS_BY_IMSI] = "UPDATE subscriber SET ms_purged_cs=1 WHERE imsi = ?",
[UPD_PURGE_PS_BY_IMSI] = "UPDATE subscriber SET ms_purged_ps=1 WHERE imsi = ?",
+ [SET_NAM_PS_BY_IMSI] = "UPDATE subscriber SET nam_ps=1 WHERE imsi = ?",
+ [UNSET_NAM_PS_BY_IMSI] = "UPDATE subscriber SET nam_ps=0 WHERE imsi = ?",
};
static void sql3_error_log_cb(void *arg, int err_code, const char *msg)
diff --git a/src/db.h b/src/db.h
index 0fb76a0..0b3df88 100644
--- a/src/db.h
+++ b/src/db.h
@@ -4,13 +4,15 @@
#include <sqlite3.h>
enum stmt_idx {
- SEL_BY_IMSI = 0,
- UPD_VLR_BY_ID = 1,
- UPD_SGSN_BY_ID = 2,
- AUC_BY_IMSI = 3,
- AUC_UPD_SQN = 4,
- UPD_PURGE_CS_BY_IMSI,
- UPD_PURGE_PS_BY_IMSI,
+ SEL_BY_IMSI = 0,
+ UPD_VLR_BY_ID = 1,
+ UPD_SGSN_BY_ID = 2,
+ AUC_BY_IMSI = 3,
+ AUC_UPD_SQN = 4,
+ UPD_PURGE_CS_BY_IMSI = 5,
+ UPD_PURGE_PS_BY_IMSI = 6,
+ SET_NAM_PS_BY_IMSI = 7,
+ UNSET_NAM_PS_BY_IMSI = 8,
_NUM_STMT
};
@@ -70,7 +72,7 @@
int db_subscr_get(struct db_context *dbc, const char *imsi,
struct hlr_subscriber *subscr);
-
+int db_subscr_ps(struct db_context *dbc, const char *imsi, bool enable);
int db_subscr_lu(struct db_context *dbc,
const struct hlr_subscriber *subscr,
const char *vlr_or_sgsn_number,
diff --git a/src/db_hlr.c b/src/db_hlr.c
index b7485f0..2c6b243 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -76,6 +76,32 @@
return ret;
}
+int db_subscr_ps(struct db_context *dbc, const char *imsi, bool enable)
+{
+ sqlite3_stmt *stmt =
+ dbc->stmt[enable ? SET_NAM_PS_BY_IMSI : UNSET_NAM_PS_BY_IMSI];
+ int rc;
+
+ if (!db_bind_imsi(stmt, imsi))
+ return -EINVAL;
+
+ rc = sqlite3_step(stmt); /* execute the statement */
+ if (rc != SQLITE_DONE) {
+ LOGHLR(imsi, LOGL_ERROR, "Error executing SQL: %d\n", rc);
+ rc = -ENOEXEC;
+ }
+
+ rc = sqlite3_changes(dbc->db); /* verify execution result */
+ if (rc != 1) {
+ LOGHLR(imsi, LOGL_ERROR, "SQL modified %d rows (expected 1)\n",
+ rc);
+ rc = -EINVAL;
+ }
+
+ db_remove_reset(stmt);
+ return rc;
+}
+
int db_subscr_lu(struct db_context *dbc,
const struct hlr_subscriber *subscr,
const char *vlr_or_sgsn_number, bool lu_is_ps)