diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2015-10-05 15:12:14 +0200 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2015-11-09 16:17:39 +0100 |
commit | cd217db21cf166537e38ff971f518ac3f3905288 (patch) | |
tree | 4ad9b81610eefc2a78045eda4f609122db481a45 | |
parent | cfa4195e0c972a8ceb2fc9cc5920139ab14b0661 (diff) | |
download | NetworkManager-cd217db21cf166537e38ff971f518ac3f3905288.tar.gz |
cli: move unique_connection_name() to common.c as nmc_unique_connection_name()
-rw-r--r-- | clients/cli/common.c | 23 | ||||
-rw-r--r-- | clients/cli/common.h | 3 | ||||
-rw-r--r-- | clients/cli/connections.c | 30 |
3 files changed, 29 insertions, 27 deletions
diff --git a/clients/cli/common.c b/clients/cli/common.c index b988679ff9..8317764e3a 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -1011,6 +1011,29 @@ nmc_secrets_requested (NMSecretAgentSimple *agent, } } +char * +nmc_unique_connection_name (const GPtrArray *connections, const char *try_name) +{ + NMConnection *connection; + const char *name; + char *new_name; + unsigned int num = 1; + int i = 0; + + new_name = g_strdup (try_name); + while (i < connections->len) { + connection = NM_CONNECTION (connections->pdata[i]); + + name = nm_connection_get_id (connection); + if (g_strcmp0 (new_name, name) == 0) { + g_free (new_name); + new_name = g_strdup_printf ("%s-%d", try_name, num++); + i = 0; + } else + i++; + } + return new_name; +} /** * nmc_cleanup_readline: diff --git a/clients/cli/common.h b/clients/cli/common.h index bb3f44e851..c7acb653da 100644 --- a/clients/cli/common.h +++ b/clients/cli/common.h @@ -57,6 +57,9 @@ void nmc_secrets_requested (NMSecretAgentSimple *agent, GPtrArray *secrets, gpointer user_data); +char *nmc_unique_connection_name (const GPtrArray *connections, + const char *try_name); + void nmc_cleanup_readline (void); char *nmc_readline (const char *prompt_fmt, ...) G_GNUC_PRINTF (1, 2); char *nmc_rl_gen_func_basic (const char *text, int state, const char **words); diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 94d0ff73c2..cb95694b07 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -5810,30 +5810,6 @@ cleanup_bridge_slave: return TRUE; } -static char * -unique_connection_name (const GPtrArray *connections, const char *try_name) -{ - NMConnection *connection; - const char *name; - char *new_name; - unsigned int num = 1; - int i = 0; - - new_name = g_strdup (try_name); - while (i < connections->len) { - connection = NM_CONNECTION (connections->pdata[i]); - - name = nm_connection_get_id (connection); - if (g_strcmp0 (new_name, name) == 0) { - g_free (new_name); - new_name = g_strdup_printf ("%s-%d", try_name, num++); - i = 0; - } else - i++; - } - return new_name; -} - typedef struct { NmCli *nmc; char *con_name; @@ -6180,7 +6156,7 @@ do_connection_add (NmCli *nmc, int argc, char **argv) char *try_name = ifname ? g_strdup_printf ("%s-%s", get_name_alias (setting_name, nmc_valid_connection_types), ifname) : g_strdup (get_name_alias (setting_name, nmc_valid_connection_types)); - default_name = unique_connection_name (nmc->connections, try_name); + default_name = nmc_unique_connection_name (nmc->connections, try_name); g_free (try_name); } @@ -9015,8 +8991,8 @@ do_connection_edit (NmCli *nmc, int argc, char **argv) if (con_name) default_name = g_strdup (con_name); else - default_name = unique_connection_name (nmc->connections, - get_name_alias (connection_type, nmc_valid_connection_types)); + default_name = nmc_unique_connection_name (nmc->connections, + get_name_alias (connection_type, nmc_valid_connection_types)); g_object_set (s_con, NM_SETTING_CONNECTION_ID, default_name, |