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
This commit is contained in:
parent
8cfd928abf
commit
162f2a3dd9
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue