summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2017-02-20 11:23:20 +0100
committerHarald Welte <laforge@gnumonks.org>2017-03-05 12:25:37 +0000
commitadc6648841d50f459fe2ef5b044146838a7a3b21 (patch)
tree3d7ce485f3df21b8cead0d81b4f84a9ee13cc4d8 /src
parentd4bebbd8554ff221453fade22371646f941184f0 (diff)
Make subscr parameter to db_subscr_get() optional
This allows to check for subscriber's presence in DB without the need to bother with unused structure allocation. While at it also call to db_remove_reset() and return explicitly instead of using goto to make it a bit easier to follow the code. Change-Id: I83b0f4a5dacb97614721690ef55bc1311624a58e
Diffstat (limited to 'src')
-rw-r--r--src/db_hlr.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/db_hlr.c b/src/db_hlr.c
index 2c6b243..340e7ce 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -41,7 +41,7 @@ int db_subscr_get(struct db_context *dbc, const char *imsi,
struct hlr_subscriber *subscr)
{
sqlite3_stmt *stmt = dbc->stmt[SEL_BY_IMSI];
- int rc, ret = 0;
+ int rc;
if (!db_bind_imsi(stmt, imsi))
return -EINVAL;
@@ -50,8 +50,13 @@ int db_subscr_get(struct db_context *dbc, const char *imsi,
rc = sqlite3_step(stmt);
if (rc != SQLITE_ROW) {
LOGHLR(imsi, LOGL_ERROR, "Error executing SQL: %d\n", rc);
- ret = -ENOEXEC;
- goto out;
+ db_remove_reset(stmt);
+ return -ENOEXEC;
+ }
+
+ if (!subscr) {
+ db_remove_reset(stmt);
+ return 0;
}
/* obtain the various columns */
@@ -70,10 +75,9 @@ int db_subscr_get(struct db_context *dbc, const char *imsi,
subscr->ms_purged_cs = sqlite3_column_int(stmt, 11);
subscr->ms_purged_ps = sqlite3_column_int(stmt, 12);
-out:
db_remove_reset(stmt);
- return ret;
+ return 0;
}
int db_subscr_ps(struct db_context *dbc, const char *imsi, bool enable)