]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
freetdm: change CLI parsing (ftdm_separate_string) to properly ignore white space...
authorMoises Silva <moy@sangoma.com>
Thu, 23 Jun 2011 18:09:06 +0000 (14:09 -0400)
committerMoises Silva <moy@sangoma.com>
Thu, 23 Jun 2011 22:43:15 +0000 (18:43 -0400)
         minor change into SS7 CLI to use ftdm_array_len() instead of duplicating it

libs/freetdm/src/ftdm_io.c
libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c

index f7b4bb9a1c1c80e2488961a0c03ef4306d2fd0c5..1824fce04ab626cea6a4e53626740976e6a73924 100644 (file)
@@ -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;
index baed57e561812ae388e4e0ee0f4e390862d2dcdd..710b0c37a6d5d120eecd4cb5283670eb27deebec 100644 (file)
@@ -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;