diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-12-02 19:46:46 +0100 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2018-12-02 20:16:31 +0100 |
commit | a820ea1f67bab68136fbaae0108bb90c94b77b22 (patch) | |
tree | b9f94dd6ef8e4a1b3ee3388f52bdb32d1eeb2925 /src | |
parent | 8aa780bf80fa4ffde8a5df9d8b87a2e919193f1f (diff) |
implement removal of MSISDN
Add the first "official" way to remove the MSISDN from a subscriber entry, to
go back to 'MSISDN: none' like just after 'subscriber create'.
Add VTY command 'subscriber <ID> update msisdn none' to drop the MSISDN from
the subscriber. (Like 'subscriber <ID> update aud3g none')
Add DB_STMT_DELETE_MSISDN_BY_IMSI.
In db_subscr_update_msisdn_by_imsi(), allow passing a NULL msisdn, and if NULL,
call above delete SQL statement.
Change-Id: I15419105ea461137776adb92d384d8985210c90e
Diffstat (limited to 'src')
-rw-r--r-- | src/db.c | 1 | ||||
-rw-r--r-- | src/db.h | 1 | ||||
-rw-r--r-- | src/db_hlr.c | 13 | ||||
-rw-r--r-- | src/hlr_vty_subscr.c | 42 |
4 files changed, 37 insertions, 20 deletions
@@ -62,6 +62,7 @@ static const char *stmt_sql[] = { [DB_STMT_SUBSCR_CREATE] = "INSERT INTO subscriber (imsi) VALUES ($imsi)", [DB_STMT_DEL_BY_ID] = "DELETE FROM subscriber WHERE id = $subscriber_id", [DB_STMT_SET_MSISDN_BY_IMSI] = "UPDATE subscriber SET msisdn = $msisdn WHERE imsi = $imsi", + [DB_STMT_DELETE_MSISDN_BY_IMSI] = "UPDATE subscriber SET msisdn = NULL WHERE imsi = $imsi", [DB_STMT_AUC_2G_INSERT] = "INSERT INTO auc_2g (subscriber_id, algo_id_2g, ki)" " VALUES($subscriber_id, $algo_id_2g, $ki)", @@ -20,6 +20,7 @@ enum stmt_idx { DB_STMT_SUBSCR_CREATE, DB_STMT_DEL_BY_ID, DB_STMT_SET_MSISDN_BY_IMSI, + DB_STMT_DELETE_MSISDN_BY_IMSI, DB_STMT_AUC_2G_INSERT, DB_STMT_AUC_2G_DELETE, DB_STMT_AUC_3G_INSERT, diff --git a/src/db_hlr.c b/src/db_hlr.c index c4d4974..2bccc38 100644 --- a/src/db_hlr.c +++ b/src/db_hlr.c @@ -135,7 +135,7 @@ int db_subscr_delete_by_id(struct db_context *dbc, int64_t subscr_id) /*! Set a subscriber's MSISDN in the HLR database. * \param[in,out] dbc database context. - * \param[in] imsi ASCII string of IMSI digits. + * \param[in] imsi ASCII string of IMSI digits, or NULL to remove the MSISDN. * \param[in] msisdn ASCII string of MSISDN digits. * \returns 0 on success, -EINVAL in case of invalid MSISDN string, -EIO on * database failure, -ENOENT if no such subscriber exists. @@ -146,19 +146,22 @@ int db_subscr_update_msisdn_by_imsi(struct db_context *dbc, const char *imsi, int rc; int ret = 0; - if (!osmo_msisdn_str_valid(msisdn)) { + if (msisdn && !osmo_msisdn_str_valid(msisdn)) { LOGHLR(imsi, LOGL_ERROR, "Cannot update subscriber: invalid MSISDN: '%s'\n", msisdn); return -EINVAL; } - sqlite3_stmt *stmt = dbc->stmt[DB_STMT_SET_MSISDN_BY_IMSI]; + sqlite3_stmt *stmt = dbc->stmt[ + msisdn ? DB_STMT_SET_MSISDN_BY_IMSI : DB_STMT_DELETE_MSISDN_BY_IMSI]; if (!db_bind_text(stmt, "$imsi", imsi)) return -EIO; - if (!db_bind_text(stmt, "$msisdn", msisdn)) - return -EIO; + if (msisdn) { + if (!db_bind_text(stmt, "$msisdn", msisdn)) + return -EIO; + } /* execute the statement */ rc = sqlite3_step(stmt); diff --git a/src/hlr_vty_subscr.c b/src/hlr_vty_subscr.c index ddbaf26..bc6f6a5 100644 --- a/src/hlr_vty_subscr.c +++ b/src/hlr_vty_subscr.c @@ -142,6 +142,7 @@ static int get_subscr_by_argv(struct vty *vty, const char *type, const char *id, #define SUBSCR_UPDATE SUBSCR "update " #define SUBSCR_UPDATE_HELP SUBSCR_HELP "Set or update subscriber data\n" +#define SUBSCR_MSISDN_HELP "Set MSISDN (phone number) of the subscriber\n" DEFUN(subscriber_show, subscriber_show_cmd, @@ -228,9 +229,9 @@ DEFUN(subscriber_delete, DEFUN(subscriber_msisdn, subscriber_msisdn_cmd, - SUBSCR_UPDATE "msisdn MSISDN", - SUBSCR_UPDATE_HELP - "Set MSISDN (phone number) of the subscriber\n" + SUBSCR_UPDATE "msisdn (none|MSISDN)", + SUBSCR_UPDATE_HELP SUBSCR_MSISDN_HELP + "Remove MSISDN (phone number)\n" "New MSISDN (phone number)\n") { struct hlr_subscriber subscr; @@ -238,15 +239,19 @@ DEFUN(subscriber_msisdn, const char *id = argv[1]; const char *msisdn = argv[2]; - if (strlen(msisdn) > sizeof(subscr.msisdn) - 1) { - vty_out(vty, "%% MSISDN is too long, max. %zu characters are allowed%s", - sizeof(subscr.msisdn)-1, VTY_NEWLINE); - return CMD_WARNING; - } - - if (!osmo_msisdn_str_valid(msisdn)) { - vty_out(vty, "%% MSISDN invalid: '%s'%s", msisdn, VTY_NEWLINE); - return CMD_WARNING; + if (strcmp(msisdn, "none") == 0) + msisdn = NULL; + else { + if (strlen(msisdn) > sizeof(subscr.msisdn) - 1) { + vty_out(vty, "%% MSISDN is too long, max. %zu characters are allowed%s", + sizeof(subscr.msisdn)-1, VTY_NEWLINE); + return CMD_WARNING; + } + + if (!osmo_msisdn_str_valid(msisdn)) { + vty_out(vty, "%% MSISDN invalid: '%s'%s", msisdn, VTY_NEWLINE); + return CMD_WARNING; + } } if (get_subscr_by_argv(vty, id_type, id, &subscr)) @@ -258,11 +263,18 @@ DEFUN(subscriber_msisdn, return CMD_WARNING; } - vty_out(vty, "%% Updated subscriber IMSI='%s' to MSISDN='%s'%s", - subscr.imsi, msisdn, VTY_NEWLINE); + if (msisdn) { + vty_out(vty, "%% Updated subscriber IMSI='%s' to MSISDN='%s'%s", + subscr.imsi, msisdn, VTY_NEWLINE); + + if (db_subscr_get_by_msisdn(g_hlr->dbc, msisdn, &subscr) == 0) + osmo_hlr_subscriber_update_notify(&subscr); + } else { + vty_out(vty, "%% Updated subscriber IMSI='%s': removed MSISDN%s", + subscr.imsi, VTY_NEWLINE); - if (db_subscr_get_by_msisdn(g_hlr->dbc, msisdn, &subscr) == 0) osmo_hlr_subscriber_update_notify(&subscr); + } return CMD_SUCCESS; } |