summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-10-27 02:57:51 +0200
committerHarald Welte <laforge@gnumonks.org>2017-10-28 16:49:33 +0000
commitdbced93b5f988d370db6ea628d1d2fcdaba93f14 (patch)
tree82ca1be8ce17bf84114abbebfbcb795f0513d489
parent88c91f6fb233e4400ee781d63ffb2bdb5599e58d (diff)
cosmetic: rename SL3_TXT macro, use osmo_strlcpy()
Rename SL3_TXT to more accurate copy_sqlite3_text_to_buf(), and use osmo_strlcpy() instead of essentially dup'ing it. The macro will also be used by hlr_db_tool.c in upcoming patch. This patch prepares for a move to db.h. Change-Id: I1dadeddddcfe0109195c09c0e706201b0df009cc
-rw-r--r--src/db_hlr.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/db_hlr.c b/src/db_hlr.c
index ef01428..bae9a5a 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -35,12 +35,15 @@
#define LOGHLR(imsi, level, fmt, args ...) LOGP(DAUC, level, "IMSI='%s': " fmt, imsi, ## args)
-#define SL3_TXT(x, stmt, idx) \
- do { \
- const char *_txt = (const char *) sqlite3_column_text(stmt, idx);\
- if (_txt) \
- strncpy(x, _txt, sizeof(x)); \
- x[sizeof(x)-1] = '\0'; \
+/*! Call sqlite3_column_text() and copy result to a char[].
+ * \param[out] buf A char[] used as sizeof() arg(!) and osmo_strlcpy() target.
+ * \param[in] stmt An sqlite3_stmt*.
+ * \param[in] idx Index in stmt's returned columns.
+ */
+#define copy_sqlite3_text_to_buf(buf, stmt, idx) \
+ do { \
+ const char *_txt = (const char *) sqlite3_column_text(stmt, idx); \
+ osmo_strlcpy(buf, _txt, sizeof(buf)); \
} while (0)
/*! Add new subscriber record to the HLR database.
@@ -410,12 +413,12 @@ static int db_sel(struct db_context *dbc, sqlite3_stmt *stmt, struct hlr_subscri
/* obtain the various columns */
subscr->id = sqlite3_column_int64(stmt, 0);
- SL3_TXT(subscr->imsi, stmt, 1);
- SL3_TXT(subscr->msisdn, stmt, 2);
+ copy_sqlite3_text_to_buf(subscr->imsi, stmt, 1);
+ copy_sqlite3_text_to_buf(subscr->msisdn, stmt, 2);
/* FIXME: These should all be BLOBs as they might contain NUL */
- SL3_TXT(subscr->vlr_number, stmt, 3);
- SL3_TXT(subscr->sgsn_number, stmt, 4);
- SL3_TXT(subscr->sgsn_address, stmt, 5);
+ copy_sqlite3_text_to_buf(subscr->vlr_number, stmt, 3);
+ copy_sqlite3_text_to_buf(subscr->sgsn_number, stmt, 4);
+ copy_sqlite3_text_to_buf(subscr->sgsn_address, stmt, 5);
subscr->periodic_lu_timer = sqlite3_column_int(stmt, 6);
subscr->periodic_rau_tau_timer = sqlite3_column_int(stmt, 7);
subscr->nam_cs = sqlite3_column_int(stmt, 8);