Changeset 269580c
- Timestamp:
- 2014-07-24T03:51:07Z (10 years ago)
- Branches:
- master
- Children:
- 59e66ff
- Parents:
- 1783ab6
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
irc_commands.c
r1783ab6 r269580c 365 365 cmd[2][strlen(cmd[2])-1] = '\0'; 366 366 367 ctcp = split_command_parts( cmd[2] + 1 );367 ctcp = split_command_parts( cmd[2] + 1, 0 ); 368 368 iu->f->ctcp( iu, ctcp ); 369 369 } -
lib/misc.c
r1783ab6 r269580c 682 682 white\ space in 'various ways'. Returns a NULL-terminated static 683 683 char** so watch out with nested use! Definitely not thread-safe. */ 684 char **split_command_parts( char *command )684 char **split_command_parts( char *command, int limit ) 685 685 { 686 686 static char *cmd[IRC_MAX_ARGS+1]; … … 692 692 k = 1; 693 693 for( s = command; *s && k < IRC_MAX_ARGS; s ++ ) 694 { 694 695 if( *s == ' ' && !q ) 695 696 { 696 697 *s = 0; 697 698 while( *++s == ' ' ); 698 if( *s == '"' || *s == '\'')699 if( k != limit && (*s == '"' || *s == '\'') ) 699 700 { 700 701 q = *s; … … 704 705 { 705 706 cmd[k++] = s; 707 if (limit && k > limit) { 708 break; 709 } 706 710 s --; 707 711 } … … 722 726 q = *s = 0; 723 727 } 728 } 724 729 725 730 /* Full zero-padding for easier argc checking. */ -
lib/misc.h
r1783ab6 r269580c 67 67 G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl ); 68 68 G_MODULE_EXPORT int md5_verify_password( char *password, char *hash ); 69 G_MODULE_EXPORT char **split_command_parts( char *command );69 G_MODULE_EXPORT char **split_command_parts( char *command, int limit ); 70 70 G_MODULE_EXPORT char *get_rfc822_header( const char *text, const char *header, int len ); 71 71 -
protocols/twitter/twitter.c
r1783ab6 r269580c 602 602 603 603 cmds = g_strdup(message); 604 cmd = split_command_parts(cmds );604 cmd = split_command_parts(cmds, 2); 605 605 606 606 if (cmd[0] == NULL) { … … 662 662 goto eof; 663 663 } 664 message = new = g_strdup_printf("@%s %s", bu->handle, message + (cmd[2] - cmd[0]));664 message = new = g_strdup_printf("@%s %s", bu->handle, cmd[2]); 665 665 in_reply_to = id; 666 666 allow_post = TRUE; -
root_commands.c
r1783ab6 r269580c 32 32 void root_command_string( irc_t *irc, char *command ) 33 33 { 34 root_command( irc, split_command_parts( command ) );34 root_command( irc, split_command_parts( command, 0 ) ); 35 35 } 36 36 -
tests/check_util.c
r1783ab6 r269580c 167 167 http_encode( s ); 168 168 fail_unless( strcmp( s, "ee%C3%ABee%21%21..." ) == 0 ); 169 END_TEST 170 171 struct { 172 int limit; 173 char *command; 174 char *expected[IRC_MAX_ARGS+1]; 175 } split_tests[] = { 176 { 177 0, "account add etc \"user name with spaces\" 'pass\\ word'", 178 {"account", "add", "etc", "user name with spaces", "pass\\ word", NULL}, 179 }, 180 { 181 0, "channel set group Close\\ friends", 182 {"channel", "set", "group", "Close friends", NULL}, 183 }, 184 { 185 2, "reply wilmer \"testing in C is a PITA\", you said.", 186 {"reply", "wilmer", "\"testing in C is a PITA\", you said.", NULL}, 187 }, 188 { 189 4, "one space two spaces limit limit", 190 {"one", "space", "two", "spaces", "limit limit", NULL}, 191 }, 192 { 193 0, NULL, 194 {NULL} 195 }, 196 }; 197 198 START_TEST(test_split_command_parts) 199 int i; 200 for (i = 0; split_tests[i].command; i++) { 201 char *cmd = g_strdup(split_tests[i].command); 202 char **split = split_command_parts(cmd, split_tests[i].limit); 203 char **expected = split_tests[i].expected; 204 205 int j; 206 for (j = 0; split[j] && expected[j]; j++) { 207 fail_unless (strcmp(split[j], expected[j]) == 0, 208 "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)", 209 i, split_tests[i].command, j, split[j], expected[j]); 210 } 211 g_free(cmd); 212 } 169 213 END_TEST 170 214 … … 183 227 tcase_add_test (tc_core, test_word_wrap); 184 228 tcase_add_test (tc_core, test_http_encode); 229 tcase_add_test (tc_core, test_split_command_parts); 185 230 return s; 186 231 }
Note: See TracChangeset
for help on using the changeset viewer.