pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-hlr/+/28319 )

Change subject: ctrl: Introduce CTRL command subscriber.by-*.msisdn
......................................................................

ctrl: Introduce CTRL command subscriber.by-*.msisdn

This command provides getter and setter to set and retrieve the MSISDN
of a subscriber.

Related: SYS#5993
Change-Id: I5f2e807859f7e28e0984c8dc37edc69319fd8e10
---
M src/ctrl.c
M tests/test_subscriber.ctrl
M tests/test_subscriber_errors.ctrl
3 files changed, 101 insertions(+), 0 deletions(-)

Approvals:
  pespin: Verified
  osmith: Looks good to me, approved
  fixeria: Looks good to me, but someone else must approve
  laforge: Looks good to me, but someone else must approve



diff --git a/src/ctrl.c b/src/ctrl.c
index 5b091f8..aa02a0e 100644
--- a/src/ctrl.c
+++ b/src/ctrl.c
@@ -388,6 +388,57 @@
        return set_subscr_cs_ps_enabled(cmd, data, false);
 }

+CTRL_CMD_DEFINE(subscr_msisdn, "msisdn");
+static int verify_subscr_msisdn(struct ctrl_cmd *cmd, const char *value, void 
*data)
+{
+       struct hlr_subscriber subscr;
+       if (!value)
+               return 1;
+       if (strlen(value) > sizeof(subscr.msisdn) - 1)
+               return 1;
+       if (strcmp(value, "none") != 0 && !osmo_msisdn_str_valid(value))
+               return 1;
+       return 0;
+}
+static int get_subscr_msisdn(struct ctrl_cmd *cmd, void *data)
+{
+       struct hlr_subscriber subscr;
+       struct hlr *hlr = data;
+       const char *by_selector = cmd->node;
+
+       if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
+               return CTRL_CMD_ERROR;
+
+       if (strlen(subscr.msisdn) == 0)
+               snprintf(subscr.msisdn, sizeof(subscr.msisdn), "none");
+
+       cmd->reply = talloc_asprintf(cmd, "%s", subscr.msisdn);
+       return CTRL_CMD_REPLY;
+}
+static int set_subscr_msisdn(struct ctrl_cmd *cmd, void *data)
+{
+       struct hlr_subscriber subscr;
+       struct hlr *hlr = data;
+       const char *by_selector = cmd->node;
+       const char *msisdn;
+
+       if (!get_subscriber(hlr->dbc, by_selector, &subscr, cmd))
+               return CTRL_CMD_ERROR;
+
+       if (strcmp(cmd->value, "none") == 0)
+               msisdn = NULL;
+       else
+               msisdn = cmd->value;
+
+       if (db_subscr_update_msisdn_by_imsi(g_hlr->dbc, subscr.imsi, msisdn)) {
+               cmd->reply = "Update MSISDN failed";
+               return CTRL_CMD_ERROR;
+       }
+
+       cmd->reply = "OK";
+       return CTRL_CMD_REPLY;
+}
+
 static int hlr_ctrl_node_lookup(void *data, vector vline, int *node_type,
                                void **node_data, int *i)
 {
@@ -424,6 +475,7 @@
        rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_all);
        rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_ps_enabled);
        rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_cs_enabled);
+       rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_msisdn);

        return rc;
 }
diff --git a/tests/test_subscriber.ctrl b/tests/test_subscriber.ctrl
index 8d3c9dc..5b49702 100644
--- a/tests/test_subscriber.ctrl
+++ b/tests/test_subscriber.ctrl
@@ -624,3 +624,49 @@
 periodic_lu_timer      0
 periodic_rau_tau_timer 0
 lmsi   00000000
+
+GET 103 subscriber.by-imsi-901991234567891.msisdn
+GET_REPLY 103 subscriber.by-imsi-901991234567891.msisdn none
+
+SET 104 subscriber.by-imsi-901991234567891.msisdn 555666
+SET_REPLY 104 subscriber.by-imsi-901991234567891.msisdn OK
+
+GET 105 subscriber.by-imsi-901991234567891.msisdn
+GET_REPLY 105 subscriber.by-imsi-901991234567891.msisdn 555666
+
+SET 106 subscriber.by-imsi-901991234567891.msisdn 888000
+SET_REPLY 106 subscriber.by-imsi-901991234567891.msisdn OK
+
+GET 107 subscriber.by-imsi-901991234567891.msisdn
+GET_REPLY 107 subscriber.by-imsi-901991234567891.msisdn 888000
+
+GET 108 subscriber.by-imsi-901991234567891.info
+GET_REPLY 108 subscriber.by-imsi-901991234567891.info
+id     124
+imsi   901991234567891
+msisdn 888000
+nam_cs 1
+nam_ps 1
+ms_purged_cs   0
+ms_purged_ps   0
+periodic_lu_timer      0
+periodic_rau_tau_timer 0
+lmsi   00000000
+
+SET 109 subscriber.by-imsi-901991234567891.msisdn none
+SET_REPLY 109 subscriber.by-imsi-901991234567891.msisdn OK
+
+GET 110 subscriber.by-imsi-901991234567891.msisdn
+GET_REPLY 110 subscriber.by-imsi-901991234567891.msisdn none
+
+GET 111 subscriber.by-imsi-901991234567891.info
+GET_REPLY 111 subscriber.by-imsi-901991234567891.info
+id     124
+imsi   901991234567891
+nam_cs 1
+nam_ps 1
+ms_purged_cs   0
+ms_purged_ps   0
+periodic_lu_timer      0
+periodic_rau_tau_timer 0
+lmsi   00000000
diff --git a/tests/test_subscriber_errors.ctrl 
b/tests/test_subscriber_errors.ctrl
index 425b0df..8309e61 100644
--- a/tests/test_subscriber_errors.ctrl
+++ b/tests/test_subscriber_errors.ctrl
@@ -114,3 +114,6 @@

 SET 50 subscriber.create 901990000000001
 ERROR 50 Subscriber already exists.
+
+SET 51 subscriber.by-imsi-1234567890123456.msisdn hellobadmsisdn
+ERROR 51 Value failed verification.

--
To view, visit https://gerrit.osmocom.org/c/osmo-hlr/+/28319
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Change-Id: I5f2e807859f7e28e0984c8dc37edc69319fd8e10
Gerrit-Change-Number: 28319
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to