[PATCH] osmo-hlr[master]: Update DB routines

Max gerrit-no-reply at lists.osmocom.org
Thu Feb 16 12:00:52 UTC 2017


Review at  https://gerrit.osmocom.org/1840

Update DB routines

* add SQL queries to change nam_ps value
* move common cleanup code into separate function
* fix printf security warning

Change-Id: I24fb79e084b2dfa6a81b52f448b94a86e47014ef
---
M src/db.c
M src/db.h
M src/db_hlr.c
3 files changed, 29 insertions(+), 30 deletions(-)


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

diff --git a/src/db.c b/src/db.c
index 1385502..8e52293 100644
--- a/src/db.c
+++ b/src/db.c
@@ -19,6 +19,7 @@
 
 #include <osmocom/core/utils.h>
 
+#include <stdbool.h>
 #include <sqlite3.h>
 
 #include "logging.h"
@@ -32,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)
@@ -46,7 +49,7 @@
 		LOGP(DDB, LOGL_DEBUG, "Opened database\n");
 		break;
 	case 1:
-		LOGP(DDB, LOGL_DEBUG, stmt);
+		LOGP(DDB, LOGL_DEBUG, "%s\n", stmt);
 		break;
 	case 2:
 		LOGP(DDB, LOGL_DEBUG, "Closed database\n");
@@ -57,6 +60,23 @@
 	}
 }
 
+/* remove bindings and reset statement to be re-executed */
+bool db_remove_reset(sqlite3_stmt *stmt)
+{
+	int rc = sqlite3_clear_bindings(stmt);
+	if (rc != SQLITE_OK) {
+		LOGP(DDB, LOGL_ERROR, "Error clerearing bindings: %d\n", rc);
+		return false;
+	}
+
+	rc = sqlite3_reset(stmt);
+	if (rc != SQLITE_OK) {
+		LOGP(DDB, LOGL_ERROR, "Error in sqlite3_reset: %d\n", rc);
+		return false;
+	}
+	return true;
+}
+
 void db_close(struct db_context *dbc)
 {
 	unsigned int i;
diff --git a/src/db.h b/src/db.h
index d569fb0..86c6aed 100644
--- a/src/db.h
+++ b/src/db.h
@@ -9,8 +9,10 @@
 	UPD_SGSN_BY_ID	= 2,
 	AUC_BY_IMSI	= 3,
 	AUC_UPD_SQN	= 4,
-	UPD_PURGE_CS_BY_IMSI,
-	UPD_PURGE_PS_BY_IMSI,
+	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
 };
 
@@ -20,6 +22,7 @@
 	sqlite3_stmt *stmt[_NUM_STMT];
 };
 
+bool db_remove_reset(sqlite3_stmt *stmt);
 void db_close(struct db_context *dbc);
 struct db_context *db_open(void *ctx, const char *fname);
 
diff --git a/src/db_hlr.c b/src/db_hlr.c
index 1b95556..4f1e0d5 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -73,15 +73,7 @@
 	subscr->ms_purged_ps = sqlite3_column_int(stmt, 12);
 
 out:
-	/* remove bindings and reset statement to be re-executed */
-	rc = sqlite3_clear_bindings(stmt);
-	if (rc != SQLITE_OK) {
-		LOGP(DAUC, LOGL_ERROR, "Error clerearing bindings: %d\n", rc);
-	}
-	rc = sqlite3_reset(stmt);
-	if (rc != SQLITE_OK) {
-		LOGP(DAUC, LOGL_ERROR, "Error in sqlite3_reset: %d\n", rc);
-	}
+	db_remove_reset(stmt);
 
 	return ret;
 }
@@ -123,15 +115,7 @@
 		goto out;
 	}
 out:
-	/* remove bindings and reset statement to be re-executed */
-	rc = sqlite3_clear_bindings(stmt);
-	if (rc != SQLITE_OK) {
-		LOGP(DAUC, LOGL_ERROR, "Error clerearing bindings: %d\n", rc);
-	}
-	rc = sqlite3_reset(stmt);
-	if (rc != SQLITE_OK) {
-		LOGP(DAUC, LOGL_ERROR, "Error in sqlite3_reset: %d\n", rc);
-	}
+	db_remove_reset(stmt);
 
 	return ret;
 }
@@ -162,15 +146,7 @@
 	}
 	/* FIXME: return 0 in case IMSI not known */
 out:
-	/* remove bindings and reset statement to be re-executed */
-	rc = sqlite3_clear_bindings(stmt);
-	if (rc != SQLITE_OK) {
-		LOGP(DAUC, LOGL_ERROR, "Error clearing bindings: %d\n", rc);
-	}
-	rc = sqlite3_reset(stmt);
-	if (rc != SQLITE_OK) {
-		LOGP(DAUC, LOGL_ERROR, "Error in sqlite3_reset: %d\n", rc);
-	}
+	db_remove_reset(stmt);
 
 	return ret;
 }

-- 
To view, visit https://gerrit.osmocom.org/1840
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I24fb79e084b2dfa6a81b52f448b94a86e47014ef
Gerrit-PatchSet: 1
Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>


More information about the gerrit-log mailing list