Harald Welte has submitted this change and it was merged.

Change subject: don't re-implement osmo_talloc_replace_string()
......................................................................


don't re-implement osmo_talloc_replace_string()

osmo_talloc_replace_string() was introducd into libosmocore in 2014, see
commit f3c7e85d05f7b2b7bf093162b776f71b2bc6420d

There's no reason for us to re-implement this as bsc_replace_string
here.

Change-Id: I6d2fcaabbc74730f6f491a2b2d5c784ccafc6602
---
M openbsc/include/openbsc/vty.h
M openbsc/src/libbsc/bsc_vty.c
M openbsc/src/libcommon-cs/common_cs_vty.c
M openbsc/src/libcommon/common_vty.c
M openbsc/src/libmgcp/mgcp_vty.c
M openbsc/src/osmo-bsc/osmo_bsc_main.c
M openbsc/src/osmo-bsc/osmo_bsc_vty.c
M openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
M openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
M openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
M openbsc/tests/mgcp/mgcp_test.c
11 files changed, 42 insertions(+), 51 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/openbsc/include/openbsc/vty.h b/openbsc/include/openbsc/vty.h
index f79eab5..60b7d2d 100644
--- a/openbsc/include/openbsc/vty.h
+++ b/openbsc/include/openbsc/vty.h
@@ -41,7 +41,6 @@
 };
 
 extern int bsc_vty_is_config_node(struct vty *vty, int node);
-extern void bsc_replace_string(void *ctx, char **dst, const char *newstr);
 
 struct log_info;
 int bsc_vty_init(struct gsm_network *network);
diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c
index 0ee2390..b05d3d9 100644
--- a/openbsc/src/libbsc/bsc_vty.c
+++ b/openbsc/src/libbsc/bsc_vty.c
@@ -2946,7 +2946,7 @@
        struct gsm_bts *bts = vty->index;
        int rc;
 
-       bsc_replace_string(bts, &bts->pcu_sock_path, argv[0]);
+       osmo_talloc_replace_string(bts, &bts->pcu_sock_path, argv[0]);
        pcu_sock_exit(bts);
        rc = pcu_sock_init(bts->pcu_sock_path, bts);
        if (rc < 0) {
diff --git a/openbsc/src/libcommon-cs/common_cs_vty.c 
b/openbsc/src/libcommon-cs/common_cs_vty.c
index 76336a1..bcc001d 100644
--- a/openbsc/src/libcommon-cs/common_cs_vty.c
+++ b/openbsc/src/libcommon-cs/common_cs_vty.c
@@ -88,7 +88,7 @@
 {
        struct gsm_network *gsmnet = gsmnet_from_vty(vty);
 
-       bsc_replace_string(gsmnet, &gsmnet->name_short, argv[0]);
+       osmo_talloc_replace_string(gsmnet, &gsmnet->name_short, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -99,7 +99,7 @@
 {
        struct gsm_network *gsmnet = gsmnet_from_vty(vty);
 
-       bsc_replace_string(gsmnet, &gsmnet->name_long, argv[0]);
+       osmo_talloc_replace_string(gsmnet, &gsmnet->name_long, argv[0]);
        return CMD_SUCCESS;
 }
 
diff --git a/openbsc/src/libcommon/common_vty.c 
b/openbsc/src/libcommon/common_vty.c
index 834da51..6e1c10b 100644
--- a/openbsc/src/libcommon/common_vty.c
+++ b/openbsc/src/libcommon/common_vty.c
@@ -143,11 +143,3 @@
                return 1;
        }
 }
-
-/* a talloc string replace routine */
-void bsc_replace_string(void *ctx, char **dst, const char *newstr)
-{
-       if (*dst)
-               talloc_free(*dst);
-       *dst = talloc_strdup(ctx, newstr);
-}
diff --git a/openbsc/src/libmgcp/mgcp_vty.c b/openbsc/src/libmgcp/mgcp_vty.c
index 13f66c5..7d4b2da 100644
--- a/openbsc/src/libmgcp/mgcp_vty.c
+++ b/openbsc/src/libmgcp/mgcp_vty.c
@@ -261,7 +261,7 @@
       IP_STR
       "IPv4 Address to use in SDP record\n")
 {
-       bsc_replace_string(g_cfg, &g_cfg->local_ip, argv[0]);
+       osmo_talloc_replace_string(g_cfg, &g_cfg->local_ip, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -272,7 +272,7 @@
       IP_STR
       "IPv4 Address of the BTS\n")
 {
-       bsc_replace_string(g_cfg, &g_cfg->bts_ip, argv[0]);
+       osmo_talloc_replace_string(g_cfg, &g_cfg->bts_ip, argv[0]);
        inet_aton(g_cfg->bts_ip, &g_cfg->bts_in);
        return CMD_SUCCESS;
 }
@@ -285,7 +285,7 @@
       IP_STR
       "IPv4 Address to bind to\n")
 {
-       bsc_replace_string(g_cfg, &g_cfg->source_addr, argv[0]);
+       osmo_talloc_replace_string(g_cfg, &g_cfg->source_addr, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -403,7 +403,7 @@
       "rtp bts-bind-ip A.B.C.D",
       RTP_STR "Bind endpoints facing the BTS\n" "Address to bind to\n")
 {
-       bsc_replace_string(g_cfg, &g_cfg->bts_ports.bind_addr, argv[0]);
+       osmo_talloc_replace_string(g_cfg, &g_cfg->bts_ports.bind_addr, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -422,7 +422,7 @@
       "rtp net-bind-ip A.B.C.D",
       RTP_STR "Bind endpoints facing the Network\n" "Address to bind to\n")
 {
-       bsc_replace_string(g_cfg, &g_cfg->net_ports.bind_addr, argv[0]);
+       osmo_talloc_replace_string(g_cfg, &g_cfg->net_ports.bind_addr, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -483,7 +483,7 @@
        if (!txt)
                return CMD_WARNING;
 
-       bsc_replace_string(g_cfg, &g_cfg->trunk.audio_fmtp_extra, txt);
+       osmo_talloc_replace_string(g_cfg, &g_cfg->trunk.audio_fmtp_extra, txt);
        talloc_free(txt);
        return CMD_SUCCESS;
 }
@@ -529,7 +529,7 @@
       "sdp audio-payload name NAME",
       SDP_STR AUDIO_STR "Name\n" "Payload name\n")
 {
-       bsc_replace_string(g_cfg, &g_cfg->trunk.audio_name, argv[0]);
+       osmo_talloc_replace_string(g_cfg, &g_cfg->trunk.audio_name, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -714,7 +714,7 @@
       CALL_AGENT_STR IP_STR
       "IPv4 Address of the callagent\n")
 {
-       bsc_replace_string(g_cfg, &g_cfg->call_agent_addr, argv[0]);
+       osmo_talloc_replace_string(g_cfg, &g_cfg->call_agent_addr, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -730,7 +730,7 @@
       "Use a MGW to detranscoder RTP\n"
       "The IP address of the MGW")
 {
-       bsc_replace_string(g_cfg, &g_cfg->transcoder_ip, argv[0]);
+       osmo_talloc_replace_string(g_cfg, &g_cfg->transcoder_ip, argv[0]);
        inet_aton(g_cfg->transcoder_ip, &g_cfg->transcoder_in);
 
        return CMD_SUCCESS;
@@ -838,7 +838,7 @@
        if (!txt)
                return CMD_WARNING;
 
-       bsc_replace_string(g_cfg, &trunk->audio_fmtp_extra, txt);
+       osmo_talloc_replace_string(g_cfg, &trunk->audio_fmtp_extra, txt);
        talloc_free(txt);
        return CMD_SUCCESS;
 }
@@ -866,7 +866,7 @@
 {
        struct mgcp_trunk_config *trunk = vty->index;
 
-       bsc_replace_string(g_cfg, &trunk->audio_name, argv[0]);
+       osmo_talloc_replace_string(g_cfg, &trunk->audio_name, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -1289,7 +1289,7 @@
       "osmux bind-ip A.B.C.D",
       OSMUX_STR IP_STR "IPv4 Address to bind to\n")
 {
-       bsc_replace_string(g_cfg, &g_cfg->osmux_addr, argv[0]);
+       osmo_talloc_replace_string(g_cfg, &g_cfg->osmux_addr, argv[0]);
        return CMD_SUCCESS;
 }
 
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c 
b/openbsc/src/osmo-bsc/osmo_bsc_main.c
index 2f0b96d..ee094d6 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_main.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c
@@ -253,7 +253,7 @@
 
        data = bsc_gsmnet->bsc_data;
        if (rf_ctrl)
-               bsc_replace_string(data, &data->rf_ctrl_name, rf_ctrl);
+               osmo_talloc_replace_string(data, &data->rf_ctrl_name, rf_ctrl);
 
        data->rf_ctrl = osmo_bsc_rf_create(data->rf_ctrl_name, bsc_gsmnet);
        if (!data->rf_ctrl) {
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_vty.c 
b/openbsc/src/osmo-bsc/osmo_bsc_vty.c
index 2336669..2e2e99b 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_vty.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_vty.c
@@ -230,7 +230,7 @@
 {
        struct bsc_msc_data *data = bsc_msc_data(vty);
 
-       bsc_replace_string(osmo_bsc_data(vty), &data->bsc_token, argv[0]);
+       osmo_talloc_replace_string(osmo_bsc_data(vty), &data->bsc_token, 
argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -490,7 +490,7 @@
        if (!str)
                return CMD_WARNING;
 
-       bsc_replace_string(osmo_bsc_data(vty), &data->ussd_welcome_txt, str);
+       osmo_talloc_replace_string(osmo_bsc_data(vty), &data->ussd_welcome_txt, 
str);
        talloc_free(str);
        return CMD_SUCCESS;
 }
@@ -518,7 +518,7 @@
        if (!str)
                return CMD_WARNING;
 
-       bsc_replace_string(osmo_bsc_data(vty), &data->ussd_msc_lost_txt, str);
+       osmo_talloc_replace_string(osmo_bsc_data(vty), 
&data->ussd_msc_lost_txt, str);
        talloc_free(str);
        return CMD_SUCCESS;
 }
@@ -546,7 +546,7 @@
        if (!str)
                return CMD_WARNING;
 
-       bsc_replace_string(osmo_bsc_data(vty), &data->ussd_grace_txt, str);
+       osmo_talloc_replace_string(osmo_bsc_data(vty), &data->ussd_grace_txt, 
str);
        talloc_free(str);
        return CMD_SUCCESS;
 }
@@ -574,7 +574,7 @@
        if (!txt)
                return CMD_WARNING;
 
-       bsc_replace_string(data, &data->ussd_no_msc_txt, txt);
+       osmo_talloc_replace_string(data, &data->ussd_no_msc_txt, txt);
        talloc_free(txt);
        return CMD_SUCCESS;
 }
@@ -666,7 +666,7 @@
 {
        struct bsc_msc_data *msc = bsc_msc_data(vty);
 
-       bsc_replace_string(msc, &msc->acc_lst_name, argv[0]);
+       osmo_talloc_replace_string(msc, &msc->acc_lst_name, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -695,7 +695,7 @@
        if (!txt)
                return CMD_WARNING;
 
-       bsc_replace_string(data, &data->mid_call_txt, txt);
+       osmo_talloc_replace_string(data, &data->mid_call_txt, txt);
        talloc_free(txt);
        return CMD_SUCCESS;
 }
@@ -717,7 +717,7 @@
 {
        struct osmo_bsc_data *data = osmo_bsc_data(vty);
 
-       bsc_replace_string(data, &data->rf_ctrl_name, argv[0]);
+       osmo_talloc_replace_string(data, &data->rf_ctrl_name, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -749,7 +749,7 @@
 {
        struct osmo_bsc_data *bsc = osmo_bsc_data(vty);
 
-       bsc_replace_string(bsc, &bsc->acc_lst_name, argv[0]);
+       osmo_talloc_replace_string(bsc, &bsc->acc_lst_name, argv[0]);
        return CMD_SUCCESS;
 }
 
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c 
b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
index 3453758..128ea65 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
@@ -362,7 +362,7 @@
                return CTRL_CMD_ERROR;
 
        if (strcmp(bsc_variable, "access-list-name") == 0) {
-               bsc_replace_string(bsc_cfg, &bsc_cfg->acc_lst_name, cmd->value);
+               osmo_talloc_replace_string(bsc_cfg, &bsc_cfg->acc_lst_name, 
cmd->value);
                cmd->reply = talloc_asprintf(cmd, "%s",
                                bsc_cfg->acc_lst_name ? bsc_cfg->acc_lst_name : 
"");
                return CTRL_CMD_REPLY;
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c 
b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
index bb0f4c4..c12b29f 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
@@ -139,7 +139,7 @@
 
 void bsc_nat_set_msc_ip(struct bsc_nat *nat, const char *ip)
 {
-       bsc_replace_string(nat, &nat->main_dest->ip, ip);
+       osmo_talloc_replace_string(nat, &nat->main_dest->ip, ip);
 }
 
 struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat)
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c 
b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
index deb98fc..a11ae15 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
@@ -479,7 +479,7 @@
       "Authentication token configuration\n"
       "Token of the BSC, currently transferred in cleartext\n")
 {
-       bsc_replace_string(_nat, &_nat->token, argv[0]);
+       osmo_talloc_replace_string(_nat, &_nat->token, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -502,7 +502,7 @@
       "Set the name of the access list to use.\n"
       "The name of the to be used access list.")
 {
-       bsc_replace_string(_nat, &_nat->acc_lst_name, argv[0]);
+       osmo_talloc_replace_string(_nat, &_nat->acc_lst_name, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -518,11 +518,11 @@
        struct bsc_connection *con1, *con2;
 
        if ('/' == argv[0][0])
-               bsc_replace_string(_nat, &_nat->resolved_path, argv[0]);
+               osmo_talloc_replace_string(_nat, &_nat->resolved_path, argv[0]);
        else {
                path = talloc_asprintf(_nat, "%s/%s", _nat->include_base,
                                       argv[0]);
-               bsc_replace_string(_nat, &_nat->resolved_path, path);
+               osmo_talloc_replace_string(_nat, &_nat->resolved_path, path);
                talloc_free(path);
        }
 
@@ -538,7 +538,7 @@
                return CMD_WARNING;
        }
 
-       bsc_replace_string(_nat, &_nat->include_file, argv[0]);
+       osmo_talloc_replace_string(_nat, &_nat->include_file, argv[0]);
 
        llist_for_each_entry_safe(con1, con2, &_nat->bsc_connections,
                                  list_entry) {
@@ -574,7 +574,7 @@
       "IMSI black listing\n" "Filename IMSI and reject-cause\n")
 {
 
-       bsc_replace_string(_nat, &_nat->imsi_black_list_fn, argv[0]);
+       osmo_talloc_replace_string(_nat, &_nat->imsi_black_list_fn, argv[0]);
        if (_nat->imsi_black_list_fn) {
                int rc;
                struct osmo_config_list *rewr = NULL;
@@ -609,7 +609,7 @@
 {
        struct osmo_config_list *rewr = NULL;
 
-       bsc_replace_string(nat, name, file);
+       osmo_talloc_replace_string(nat, name, file);
        if (*name) {
                rewr = osmo_config_list_parse(nat, *name);
                bsc_nat_num_rewr_entry_adapt(nat, head, rewr);
@@ -740,7 +740,7 @@
        _nat->num_rewr_trie = NULL;
 
        /* replace the file name */
-       bsc_replace_string(_nat, &_nat->num_rewr_trie_name, argv[0]);
+       osmo_talloc_replace_string(_nat, &_nat->num_rewr_trie_name, argv[0]);
        if (!_nat->num_rewr_trie_name) {
                vty_out(vty, "%% prefix-tree no filename is present.%s", 
VTY_NEWLINE);
                return CMD_WARNING;
@@ -789,7 +789,7 @@
       "Set the name of the access list to check for IMSIs for USSD message\n"
       "The name of the access list for HLR USSD handling")
 {
-       bsc_replace_string(_nat, &_nat->ussd_lst_name, argv[0]);
+       osmo_talloc_replace_string(_nat, &_nat->ussd_lst_name, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -809,7 +809,7 @@
       "ussd-token TOKEN",
       "Set the token used to identify the USSD module\n" "Secret key\n")
 {
-       bsc_replace_string(_nat, &_nat->ussd_token, argv[0]);
+       osmo_talloc_replace_string(_nat, &_nat->ussd_token, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -818,7 +818,7 @@
       "ussd-local-ip A.B.C.D",
       "Set the IP to listen for the USSD Provider\n" "IP Address\n")
 {
-       bsc_replace_string(_nat, &_nat->ussd_local, argv[0]);
+       osmo_talloc_replace_string(_nat, &_nat->ussd_local, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -884,7 +884,7 @@
        if (strncmp(conf->token, argv[0], 128) != 0)
                conf->token_updated = true;
 
-       bsc_replace_string(conf, &conf->token, argv[0]);
+       osmo_talloc_replace_string(conf, &conf->token, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -983,7 +983,7 @@
 {
        struct bsc_config *conf = vty->index;
 
-       bsc_replace_string(conf, &conf->acc_lst_name, argv[0]);
+       osmo_talloc_replace_string(conf, &conf->acc_lst_name, argv[0]);
        return CMD_SUCCESS;
 }
 
@@ -1035,7 +1035,7 @@
 {
        struct bsc_config *conf = vty->index;
 
-       bsc_replace_string(conf, &conf->description, argv[0]);
+       osmo_talloc_replace_string(conf, &conf->description, argv[0]);
        return CMD_SUCCESS;
 }
 
diff --git a/openbsc/tests/mgcp/mgcp_test.c b/openbsc/tests/mgcp/mgcp_test.c
index b2d237e..43a453a 100644
--- a/openbsc/tests/mgcp/mgcp_test.c
+++ b/openbsc/tests/mgcp/mgcp_test.c
@@ -532,7 +532,7 @@
                last_endpoint = -1;
                dummy_packets = 0;
 
-               bsc_replace_string(cfg, &cfg->trunk.audio_fmtp_extra, 
t->extra_fmtp);
+               osmo_talloc_replace_string(cfg, &cfg->trunk.audio_fmtp_extra, 
t->extra_fmtp);
 
                inp = create_msg(t->req);
                msg = mgcp_handle_message(cfg, inp);

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6d2fcaabbc74730f6f491a2b2d5c784ccafc6602
Gerrit-PatchSet: 2
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder

Reply via email to