Changeset 18ff38f
- Timestamp:
- 2008-03-29T23:15:04Z (17 years ago)
- Branches:
- master
- Children:
- 5ecf96b
- Parents:
- a199d33
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
irc.c
ra199d33 r18ff38f 297 297 char conv[IRC_MAX_LINE+1]; 298 298 299 /* [WvG] Because irc_tokenize splits at every newline, the lines[] list 300 should end with an empty string. This is why this actually works. 301 Took me a while to figure out, Maurits. :-P */ 299 /* [WvG] If the last line isn't empty, it's an incomplete line and we 300 should wait for the rest to come in before processing it. */ 302 301 if( lines[i+1] == NULL ) 303 302 { … … 369 368 char **irc_tokenize( char *buffer ) 370 369 { 371 int i, j ;370 int i, j, n = 3; 372 371 char **lines; 373 372 374 /* Count the number of elements we're gonna need. */ 375 for( i = 0, j = 1; buffer[i] != '\0'; i ++ ) 376 { 377 if( buffer[i] == '\n' ) 378 if( buffer[i+1] != '\r' && buffer[i+1] != '\n' ) 379 j ++; 380 } 381 382 /* Allocate j+1 elements. */ 383 lines = g_new( char *, j + 1 ); 373 /* Allocate n+1 elements. */ 374 lines = g_new( char *, n + 1 ); 375 376 lines[0] = buffer; 377 378 /* Split the buffer in several strings, and accept any kind of line endings, 379 * knowing that ERC on Windows may send something interesting like \r\r\n, 380 * and surely there must be clients that think just \n is enough... */ 381 for( i = 0, j = 0; buffer[i] != '\0'; i ++ ) 382 { 383 if( buffer[i] == '\r' || buffer[i] == '\n' ) 384 { 385 while( buffer[i] == '\r' || buffer[i] == '\n' ) 386 buffer[i++] = '\0'; 387 388 lines[++j] = buffer + i; 389 390 if( j >= n ) 391 { 392 n *= 2; 393 lines = g_renew( char *, lines, n + 1 ); 394 } 395 396 if( buffer[i] == '\0' ) 397 break; 398 } 399 } 384 400 385 401 /* NULL terminate our list. */ 386 lines[j] = NULL; 387 388 lines[0] = buffer; 389 390 /* Split the buffer in several strings, using \r\n as our seperator, where \r is optional. 391 * Although this is not in the RFC, some braindead ircds (newnet's) use this, so some clients might too. 392 */ 393 for( i = 0, j = 0; buffer[i] != '\0'; i ++) 394 { 395 if( buffer[i] == '\n' ) 396 { 397 buffer[i] = '\0'; 398 399 if( i > 0 && buffer[i-1] == '\r' ) 400 buffer[i-1] = '\0'; 401 if( buffer[i+1] != '\r' && buffer[i+1] != '\n' ) 402 lines[++j] = buffer + i + 1; 403 } 404 } 405 406 return( lines ); 402 lines[++j] = NULL; 403 404 return lines; 407 405 } 408 406 -
tests/check_irc.c
ra199d33 r18ff38f 37 37 irc = irc_new(g_io_channel_unix_get_fd(ch1)); 38 38 39 fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\ n"40 "USER a a a a\ r\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);39 fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\r\n" 40 "USER a a a a\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL); 41 41 fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL); 42 42
Note: See TracChangeset
for help on using the changeset viewer.