From 162f2a3dd9498061d2d86842ef8bb502511bf3a8 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 23 Jun 2011 14:09:06 -0400 Subject: [PATCH] freetdm: change CLI parsing (ftdm_separate_string) to properly ignore white space (fixes Sangoma issue #778) minor change into SS7 CLI to use ftdm_array_len() instead of duplicating it --- libs/freetdm/src/ftdm_io.c | 18 +++++++----------- .../ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index f7b4bb9a1c..1824fce04a 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -5771,6 +5771,9 @@ FT_DECLARE(uint32_t) ftdm_separate_string(char *buf, char delim, char **array, i ptr = buf; + /* we swallow separators that are contiguous */ + while (*ptr == delim) ptr++; + for (argc = 0; *ptr && (argc < arraylen - 1); argc++) { array[argc] = ptr; for (; *ptr; ptr++) { @@ -5782,6 +5785,8 @@ FT_DECLARE(uint32_t) ftdm_separate_string(char *buf, char delim, char **array, i } } else if ((*ptr == delim) && !quot) { *ptr++ = '\0'; + /* we swallow separators that are contiguous */ + while (*ptr == delim) ptr++; break; } } @@ -5791,22 +5796,13 @@ FT_DECLARE(uint32_t) ftdm_separate_string(char *buf, char delim, char **array, i array[argc++] = ptr; } - /* strip quotes and leading / trailing spaces */ + /* strip quotes */ for (x = 0; x < argc; x++) { - char *p; - - while(*(array[x]) == ' ') { - (array[x])++; - } - p = array[x]; + char *p = array[x]; while((p = strchr(array[x], qc))) { memmove(p, p+1, strlen(p)); p++; } - p = array[x] + (strlen(array[x]) - 1); - while(*p == ' ') { - *p-- = '\0'; - } } return argc; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c index baed57e561..710b0c37a6 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c @@ -106,7 +106,7 @@ ftdm_status_t ftdm_sngss7_handle_cli_cmd(ftdm_stream_handle_t *stream, const cha if (data) { mycmd = ftdm_strdup(data); - argc = ftdm_separate_string(mycmd,' ',argv,(sizeof(argv) / sizeof(argv[0]))); + argc = ftdm_separate_string(mycmd, ' ', argv, ftdm_array_len(argv)); } if (check_arg_count(argc, 1)) goto handle_cli_error_argc;