[Freeswitch-users] BUG in FS C-Function: switch_separate_string(-)

Peter Olsson peter.olsson at visionutveckling.se
Sat Sep 10 14:46:21 MSD 2011


Yes, this seems wrong, please add this issue to Jira.

To get around (until it's fixed) it you can use / for the path, for instance C:/test/test.wav - Windows will handle frontslash as well as backslash when entering a path.

/Peter
________________________________________
Från: freeswitch-users-bounces at lists.freeswitch.org [freeswitch-users-bounces at lists.freeswitch.org] för king2kin [xing2kin at yahoo.com]
Skickat: den 10 september 2011 07:02
Till: freeswitch-users at lists.freeswitch.org
Ämne: [Freeswitch-users] BUG in FS C-Function: switch_separate_string(-)

Hi folks,

I think that switch_separate_string(-) has a bug in splitting a string into array by a token:

While parsing a char string into an array, [switch_separate_string(-)] always treats some substrings (which start with backslash char '\') as escaped chars,

for example: even though char '\' has been escaped inside a constant string {"status=10&path=c:\\temp\\log\\&name=tom"}, [switch_separate_string(-)] treats its substring "\t" AS a single tab char; and substring "\&" AS a single char '&'. This result is definitely wrong!

Here is an example that I tried on windows 2003 server:

-- src codes:

int nParams = 0;
char* params[64] = {0};

char mystr[] = "status=10&path=c:\\temp\\log\\&name=tom";

switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mystr: %s\n", mystr);
nParams = switch_separate_string(mystr, '&', params, (sizeof(params) / sizeof(params[0])));
for (i=0; i < nParams; i++)
{
    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%d]: {%s}\n", i, params[i]);
}

-- printed log info:

2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:981 mystr: status=10&path=c:\temp\log\&name=tom
2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:985 [0]: {status=10}
2011-09-10 12:26:42.566383 [DEBUG] mod_xxx.c:985 [1]: {path=c:    emp\log&name=tom}

My comment: the above string 'mystr' is supposed to be parsed into a 3-element array {10, path=c:\temp\log\, tom}; however, [switch_separate_string(-)]parsed it into a 2-element array {10, path=c:    emp\log&name=tom}.


x.k.




FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org

!DSPAM:4e6af00032762055611955!




Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list