summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2015-03-12 14:11:18 +0100
committerJiří Klimeš <jklimes@redhat.com>2015-03-12 15:32:39 +0100
commit661ef3cd46f0d68018d2556ab4c24bf1824919d5 (patch)
tree22b1dbe4b220e9385d010a8a19b38d06f6c552be
parent65729cb740badc75c89d403fea77b892f0eed440 (diff)
downloadNetworkManager-661ef3cd46f0d68018d2556ab4c24bf1824919d5.tar.gz
cli: don't return empty strings in nmc_string_to_arg_array()
and unquote strings in the array if required.
-rw-r--r--clients/cli/connections.c4
-rw-r--r--clients/cli/utils.c29
-rw-r--r--clients/cli/utils.h3
3 files changed, 27 insertions, 9 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index 3e5ed4f5d4..416a4eea79 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -2472,7 +2472,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
if (argc == 0) {
if (nmc->ask) {
line = nmc_readline (PROMPT_CONNECTION);
- nmc_string_to_arg_array (line, "", &arg_arr, &arg_num);
+ nmc_string_to_arg_array (line, "", TRUE, &arg_arr, &arg_num);
arg_ptr = arg_arr;
}
if (arg_num == 0) {
@@ -8869,7 +8869,7 @@ do_connection_delete (NmCli *nmc, int argc, char **argv)
if (argc == 0) {
if (nmc->ask) {
line = nmc_readline (PROMPT_CONNECTION);
- nmc_string_to_arg_array (line, "", &arg_arr, &arg_num);
+ nmc_string_to_arg_array (line, "", TRUE, &arg_arr, &arg_num);
arg_ptr = arg_arr;
}
if (arg_num == 0) {
diff --git a/clients/cli/utils.c b/clients/cli/utils.c
index ab591d9563..1cbf611e25 100644
--- a/clients/cli/utils.c
+++ b/clients/cli/utils.c
@@ -547,17 +547,34 @@ nmc_get_user_input (const char *ask_str)
* Split string in 'line' according to 'delim' to (argument) array.
*/
int
-nmc_string_to_arg_array (const char *line, const char *delim, char ***argv, int *argc)
+nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote,
+ char ***argv, int *argc)
{
- int i = 0;
char **arr;
- arr = g_strsplit_set (line ? line : "", delim ? delim : " \t", 0);
- while (arr && arr[i])
- i++;
+ arr = nmc_strsplit_set (line ? line : "", delim ? delim : " \t", 0);
+
+ if (unquote) {
+ int i = 0;
+ char *s;
+ size_t l;
+ const char *quotes = "\"'";
+
+ while (arr && arr[i]) {
+ s = arr[i];
+ l = strlen (s);
+ if (l >= 2) {
+ if (strchr (quotes, s[0]) && s[l-1] == s[0]) {
+ memmove (s, s+1, l-2);
+ s[l-2] = '\0';
+ }
+ }
+ i++;
+ }
+ }
- *argc = i;
*argv = arr;
+ *argc = g_strv_length (arr);
return 0;
}
diff --git a/clients/cli/utils.h b/clients/cli/utils.h
index 949867f0ab..3088846e5d 100644
--- a/clients/cli/utils.h
+++ b/clients/cli/utils.h
@@ -72,7 +72,8 @@ char *nmc_colorize (NmcTermColor color, NmcTermFormat format, const char * fmt,
void nmc_filter_out_colors_inplace (char *str);
char *nmc_filter_out_colors (const char *str);
char *nmc_get_user_input (const char *ask_str);
-int nmc_string_to_arg_array (const char *line, const char *delim, char ***argv, int *argc);
+int nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote,
+ char ***argv, int *argc);
const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error);
GSList *nmc_util_strv_to_slist (char **strv);
char * nmc_util_strv_for_display (const char **strv);