summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2017-02-20 11:18:04 +0100
committerMax <msuraev@sysmocom.de>2017-02-21 11:45:08 +0100
commit3ce368676849b54f40fc426bf3eb136e17091416 (patch)
tree4cc9745881d6ba2798fd2fbaa463e31db1b02aa3 /src
parent58d4a84a3198bc6c30f5fc9f2182ec2de5deb446 (diff)
Add routines to update nam_ps
Add SQL queries to change nam_ps value and function which uses them. Change-Id: I24fb79e084b2dfa6a81b52f448b94a86e47014ef
Diffstat (limited to 'src')
-rw-r--r--src/db.c2
-rw-r--r--src/db.h18
-rw-r--r--src/db_hlr.c26
3 files changed, 38 insertions, 8 deletions
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 @@ static const char *stmt_sql[] = {
[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 @@ struct hlr_subscriber {
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 @@ out:
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)